Thứ Tư, 15 tháng 8, 2012

làm thế nào để nhommua, cungmua, hotdeal xác định location của thành viên

làm thế nào để nhommua, cungmua, hotdeal xác định location của thành viên:
Giới thiệu:

Các trang deal hiện nay cung cấp deal không chỉ 1 nơi, mà giờ chúng mở rộng ra khắp nhiều nơi chẳng hạn như TPHCM, Hà Nội, Cần Thơ, hoặc Đà Nẵng.

Thay vì phải buộc thành viên chọn nơi ở của mình, để cho việc mua deal hay vouchor dễ dàng hơn, các website như nhommua, cungmua, hoặc hotdeal.... Sẽ tự động xác định location của thành viên từ  địa chỉ IP mà họ vào site, còn nếu các IP đó không thuộc vào các địa điểm nói trên thì các web đó sẽ chuyển hướng user sang location mặc định.


Các bước thực hiện:

Việc các bạn cần làm là tìm ra cho bằng được 1 service để xác định location từ địa chỉ IP của thành viên, cũng có thể là free hoặc 1 database dạng *.dat đầy đủ.

Chú ý: Free service có thể thiếu thông tin và độ đáng tin cập sẽ không bằng 1 số service hoặc database IPToLocation.

Trong bài này mình sẽ hướng dẫn mọi người từng bưới để hoàn thành task này sử dụng: C#.Net, thư viện HttpClient và free service http://freegeoip.net/static/index.html

Để đơn giản mình sẽ sử dụng Console Application

Giới thiệu về lớp HttpClient

HttpClient là 1 HttpClient mới nhất dành cho .Net, Nó cung cấp API mở rộng để có thể truy xuất mọi thứ được truyền tải qua giao thức HTTP, HttpClient là 1 phần của WCF Web API preview 6 và bây giờ nó đã hiện hữu trong thư viện của ASP.NET Web API và trong .Net 4.5, bạn có thể tải nó về sử dụng NuGet, nhưng chúng ta chỉ sử dụng 3 gói sau đây trong ví dụ này:

1. System.Net.Http: Gói NuGet chính gồm lớp cơ bản HttpClient và các lớp liên quan
2. System.Net.Http.Formatting: Hỗ trợ serialization và deserialization và một số các tính năng xây dựng dựa trên System.Net.Http
3. System.Json: hỗ trợ kỹ thuật JsonValue cho việc đọc và sinh các tài liệu JSON.

HttpClient là lớp chính cho việc gửi và nhận HttpRequestMessages và HttpResponseMessages , nếu bạn đã từng sử dụng WebClient hoặc HttpWebRequest thì lớp HttpClient chẳng khác gì, và sau đây là 1 số tính năng nổi bật:

1. Khi 1 instance của HttpClient được tạo ra, chúng ta có thể bắt đầu cấu hình các extensions, set header mặc định, cancel outstanding requests và còn nhiều hơn nữa.
2. Bạn có thể tạo ra bao nhiêu request mà bạn muốn chỉ với 1 khởi tạo HttpClient duy nhất.
3. HttpClients không có gắn với bất kỳ Http máy chủ hay host nào, nên bạn có thể submit bất cứ request nào sử dụng cùng 1 khởi tạo HttpClient.
4. Bạn có thể kế thừa từ HttpClient để tạo ra client đặc biệt cho các site hoặc các mẫu đặc thù.
5. HttpClient sử dụng pattern hướng nhiệm vụ (Task-oriented) cho việc xử lý các request bất đồng bộ.

Bắt đầu với 1 simple console application:
Ở ví dụ này chúng ta sẽ request lên 1 free service để nhận về thông tin location based trên IP của client

using System;
using System.Json;
using System.Net.Http;
 
namespace IPToLocation
{
    /// <summary>     
    /// Sample download list of location's properties from the Free GEO Ip Data sources at http://freegeoip.net     
    /// </summary>     
    internal class Program
    {
        private static string _address = "http://freegeoip.net/json/115.78.237.241";
 
        private static void Main(string[] args)
        {
            // Create an HttpClient instance             
            var client = new HttpClient();
            // Send a request asynchronously continue when complete             
            client.GetAsync(_address).ContinueWith((requestTask) =>
                                                       {
                                                           // Get HTTP response from completed task.                         
                                                           var response = requestTask.Result;
                                                           // Check that response was successful or throw exception                         
                                                           response.EnsureSuccessStatusCode();
                                                           response.Content.ReadAsAsync<JsonObject>().ContinueWith(
                                                               (readTask) =>
                                                                   {
                                                                       var city = readTask.Result["city"];
                                                                       var regionCode = readTask.Result["region_code"];
                                                                       var regionName = readTask.Result["region_name"];
                                                                       var metroCode = readTask.Result["metrocode"];
                                                                       var zipCode = readTask.Result["zipcode"];
                                                                       var longitude = readTask.Result["longitude"];
                                                                       var latitude = readTask.Result["latitude"];
                                                                       var countryCode = readTask.Result["country_code"];
                                                                       var ip = readTask.Result["ip"];
                                                                       var countryName = readTask.Result["country_name"];
                                                                       Console.WriteLine(city);
                                                                   });
                                                       });
            Console.WriteLine("Press Enter to exit...");
            Console.ReadLine();
        }
    }
}

HttpResponseMessage chứa tất cả các response bao gồm: status code, header, và bất kỳ nội dụng nào, Body hay còn gọi là nội dung được gói gọn trong HttpContent, nó chưa content header chẳng hạn như Content-Type, Content-Encoding….cũng như là nội dung thực của nó. Nội dung có thể được đọc với bất kỳ phương thức ReadAS* nào phụ thuộc vào việc bạn muốn sử dụng data như thế nào. Ví dụ trên chúng ta đọc Content dạng Json, rất dễ dàng cho việc chọn và lấy dữ liệu.


Thông tin thêm về HttpClienet các bạn xem ơn đây: http://blogs.msdn.com/b/henrikn/archive/2012/02/11/httpclient-is-here.aspx

http://support.microsoft.com/kb/2695606/vi-vn
http://code.msdn.microsoft.com/Introduction-to-HttpClient-4a2d9cee
 

HttpClientDemo.rar (699,27 kb)

Thứ Tư, 8 tháng 8, 2012

Canon PowerShot 510 HS xách tay cần bán

Người nhà mới mang về cái máy chụp hình mới nhất của Canon, nay cần bán lại



Thông tin chi tiết:
+ Độ phân giải : 12.1 Megapixels
+ Cảm biến : 1/2.3" back-illuminated CMOS
+ Zoom quang : 12x (28 -336mm)
+ Zoom kĩ thuật số : 4x
+ Định dạng tập tin : JPEG (EXIF 2.2), AVI
+ ISO : Tự động, ISO 100 / 200 / 400 / 800 / 1600 / 3200 (khi ở chế độ P) 
+ Màn hình LCD : 3.2" TFT (461.000 pixels)
+ Thẻ nhớ: SD, SDHC, SDXC
+ Quay phim: FULL HD 1080, 1280 x 720, 640 x 480, 30fps/30fps(LP)
+ Chế độ tự động chụp: 2 hay 10 giây
+ Khẩu độ: F2.0 – F5.3
+ Tốc độ chụp nhanh nhất: 1 - 1/4000 giây, 15-1/4000 giây

+ Phạm vi đèn flash: 30cm - 3,1m (W), 1,0 - 1,7m (T)
+ Canh nét gần: 3 cm
+ Chống mắt đỏ, chống rung quang học, chế độ nhận dạng khuôn mặt
+ Chuẩn kết nối : USB 2.0/Video/HDMI 
+ Nguồn: pin sạc Li-ion Battery NB-9L(170 tấm) 
+ Kích thước : 99,0 x 58,9 x 21,9 mm
+ Trọng lượng : 206g


Đặc điểm nổi bật:
Hệ thống HS System giúp chụp những tấm ảnh ban đêm rất rỏ nét
Màn hình cảm ứng đa chạm, chụp hình chỉ bằng 1 cái chạm
Quay film Full HS
Thẻ nhớ 16G tha hồ chụp hình lẫn quay flim
Siêu Zoom
.................

Thông tin về máy: mọi người tham khảo tại:
http://www.canon.co.uk/For_Home/Prod...S/IXUS_510_HS/

http://www.pcworld.com.vn/articles/s...en-ke-tu-16-4/

http://www.vatgia.com/319/1735372/ca...s-ixy-51s.html

Giá hiện tại trên 1 số website là gần 6trieu (chưa kèm thẻ nhớ)
Giá bán tại thảo nhiên là 6tr nhé:
http://sanphammoi.canbannhanh.com/ca...s-P382034.aspx

Mình cần bán gấp với giá: 5tr8 (kèm thẻ nhớ 16G)
Hàng xách tay có hóa hơn bên US và Phiếu bảo hành Canon
Màu: Trắng

Liên hệ: Quách Nguyên 0919..123.960
Địa Chỉ: 247 Lê Niệm, Phú Thạnh, Tân Phú HCM

Call hay SMS vô tư
(thank ae đã quan tâm, đá qua đá lại, trả lễ hậu hỷ cho ae)

Thứ Tư, 11 tháng 7, 2012

tạo groupon time counter giống nhommua, cungmua, hotdeal

tạo groupon time counter giống nhommua, cungmua, hotdeal:
Nếu các bạn là người dùng Việt Nam chắc chắn ai ai cũng biết đến 3 website nổi tiếng nhất hiện nay đó là nhommua, cungmua, và hotdeal, chúng là 1 website cung cấp các deal, coupon, và vouchor.

Khi một bài viết (deal) được publish chúng ta sẽ thường thấy 1 đồng hồ tick và thời gian nó sẽ giảm dần cho đến khi hết hạn, và sau khi hết hạn thì deal đó trong trạng thái close đi

Mặc dùng là các site cung cấp deal khác nhau nhưng nhìn chung, tất cả đều tương đồng đến 90%.
nhommua

H1: Timer counter của nhommua
cungmua
H2: Timer counter của cungmua
hotdeal
H3: Timer counter của hotdeal
Trong bài này chúng ta sẽ tiếp cận với cách làm timer counter đó sử dụng asp.net và javascript.

Đầu tiên tạo 1 dự án asp.net empty website bằng Visual Studio 2010
Thêm 1 item mới named default.aspx
Copy và paste đoạn javascript sau vào Visual Studio
function Timer(container, timeLeft) {
  // get hour, minute and second element using jQuery selector
  var hoursContainer = $(container).find('.hour');
  var minsContainer  = $(container).find('.min');
  var secsContainer  = $(container).find('.sec');
   
  // hold time left
  var currentTimeLeft = timeLeft;
  // 1 second = 1000 ms
  var secondsForTimer = 1000;  
  // hold ID value return by setInterval()
  var timerInterval;
  
  // call setInteval() only when timeLeft is greater than 0
  if (currentTimeLeft == 0) {
   return;
  } else {
   //Call setInterval()function and store ID value to timerInterval. 
   timerInterval = setInterval(countdown, secondsForTimer);
  }
  
  //function being passed to setInterval()
  function countdown() {
    currentTimeLeft = parseInt(currentTimeLeft - secondsForTimer);    
    if (currentTimeLeft == 0) {
       //stop calling countdown function by calling clearInterval()
       clearInterval(timerInterval);
       return;
    } else {     
       //calculate hours left
       var wholeSeconds = parseInt(currentTimeLeft / 1000,10);
       var wholeMinutes = parseInt(currentTimeLeft / 60000,10);
       var wholeHours   = parseInt(wholeMinutes / 60,10);
       //calculate minutes left
       var minutes = parseInt(wholeMinutes % 60,10);
       //calculate seconds left
       var seconds = parseInt(wholeSeconds % 60,10);
       //prefix 0 to hour, min and second counter
       $(hoursContainer).text((wholeHours < 10 ? "0" : "") + wholeHours + (wholeHours <=0 ? " hr" : " hrs"));
       $(minsContainer).text((minutes < 10 ? "0" : "") + minutes  + (minutes <=0 ? " min" : " mins"));
       $(secsContainer).text((seconds < 10 ? "0" : "") + seconds  + (seconds <=0 ? " sec" : " secs"));
    }
  }
}
Đặt tên nó là timer.js sau đó reference nó vào trang default.aspx look like:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="timer.js" type="text/javascript"></script>
<script type="text/javascript" language="javascript">
    $(document).ready(function () {
        var timeLeft = '<%=remaingTime%>';         
        var timer = new Timer($('#counter'), timeLeft);
    });
</script>
Trước tiên reference Jquery để bind function onload (.ready) cho page
Chú ý biến remaingTime chúng ta sẽ handle nó trong sự kiện page_load của trang default như sau:
using System;
using System.Web.UI;
 
public partial class _Default : Page
{
    protected string remaingTime = String.Empty;
 
    protected void Page_Load(object sender, EventArgs e)
    {
        var expiredDate = new DateTime(2012, 07, 11,16,0,0);
        var timeLeft = expiredDate.Subtract(TimeZoneInfo.ConvertTimeBySystemTimeZoneId(DateTime.Now, "SE Asia Standard Time"));
        remaingTime = timeLeft.TotalMilliseconds.ToString();
    }
}

Đầu tiên mình khai báo biến remaingTime với giá trị là rỗng
Sau đó mình
khởi tạo biến expiredDate với giá trị lớn hơn ngày hiện tại mình viết bài 24h.
Dùng hàm Subtract để tính số thời gian chênh lệch giữa 2 biến.
Dùng hàm ConvertBySystemTimeZoneId để convert time đúng theo múi giờ mà mình muốn, trong trường hợp server đặt ở 1 location không phải là Việt Nam.

Khi có khoảng thời gian chệnh lệch rồi thì mình sẽ có được tổng số Millisecond
Chạy ứng dụng lên chúng ta sẽ thấy màn hình như sau:
Hỉnh 4: Timer counter

Và đây là demo: deal timer counter, coupon timer counter
Mọi thắc mắc góp ý về bài viết vui lòng liên hệ: mr_ha_hcm@yahoo.com

Trong các bài viết sắp tới mình sẽ hướng dẫn tiếp cách mà 3 websites này rewrite url

Thứ Bảy, 28 tháng 4, 2012

lacoste men's sandal

2 đôi sandal cần bán, hàng VNXK giá rẻ nhất thị trường hiện nay









Hình mình lượm bên shop khác về edit lại (sorry nếu đòi bản quyền) mục đích để ae có thể so sánh sản phẩm và giá trong thời buổi kinh tế đang leo thang như hiện nay.

Địa chỉ: 247 Lê Niệm, Phú Thạnh, Tân Phú, TPHCM
Phone: 0919.123.960 (A.Nguyên)
Free ship khu vực TPHCM
Giá bán là: 400K (giá củ 500K) ae shop khác bán hơn >500K
Hàng đảm bảo chất lượng bao xài...AE đi ngang đá 2 đôi sandal em lên dùm 1 cái, hứa sẽ trã lễ

Thứ Bảy, 23 tháng 7, 2011

Apply Highlighting Keywords Found In Search Results in BlogEngine

Apply Highlighting Keywords Found In Search Results in BlogEngine: "

After reading the blog post: “Highlighting Keywords Found In Search Results”. I realize that I should apply this utility for my existing code2code.info blog, you also do it for you by following my below instruction:

Prerequisite:
- BlogEngine (BE) source code version 2.5
- Visual Studio 2010

Note:Because I’ve been using BlogEngine v2.5 with .net 4.0 so I have to use Visual Studio 2010 to customize my existing blog. But you also can do it with using Visual Studio 2008 if you are using older version of BE

Step 1: Open Util.cs in BlogEngine.Core and paste the code below (end of line to easy to tracking or maintain)

///<summary>
/// Wraps matched strings in HTML span elements styled with a background-color
///</summary>
///<param name="text"></param>
///<param name="keywords">Comma-separated list of strings to be highlighted</param>
///<param name="cssClass">The Css color to apply</param>
///<param name="fullMatch">false for returning all matches, true for whole word matches only</param>
///<returns>string</returns>
public static string HighlightKeyWords(this string text, string keywords, string cssClass, bool fullMatch)
{
if (text == String.Empty || keywords == String.Empty || cssClass == String.Empty)
return text;
var words = keywords.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
if (!fullMatch)
return words.Select(word => word.Trim()).Aggregate(text,
(current, pattern) =>
Regex.Replace(current,
pattern,
string.Format("<span style=\"background-color:{0}\">{1}</span>",
cssClass,
'$0'),
RegexOptions.IgnoreCase));
return words.Select(word => '\\b' + word.Trim() + '\\b')
.Aggregate(text, (current, pattern) =>
Regex.Replace(current,
pattern,
string.Format("<span style=\"background-color:{0}\">{1}</span>",
cssClass,
'$0'),
RegexOptions.IgnoreCase));
}



Press F5 to Build BlogEngine.Core project.

Step 2: Open search.aspx and add the code like below:

<asp:repeater runat='server' id="rep">
<ItemTemplate>
<div class="searchresult">
<a href='<%# Eval('RelativeLink') %>"><%# Eval('Title').ToString().HighlightKeyWords(Request.QueryString['q'], 'yellow', true)%></a>
<span class="text"><%# GetContent((string)Eval('Description'), (string)Eval('Content')).HighlightKeyWords(Request.QueryString['q'], 'yellow', true)%></span>
<span class='type' runat='server' id='type' />
<span class="url"><%# ShortenUrl((String)Eval('RelativeLink')) %></span>
</div>
</ItemTemplate>
</asp:repeater>




Note: The 2nd parameter is style sheet class name, you have to define it by your refer color.

Step 3: Testing and deployment.
I have apply the highlight for title and content if it matches. Then you will see the result output like screenshot below:





Happy BE-ing...

"

Chủ Nhật, 3 tháng 7, 2011

Sử dụng control Ext.Net GridPanel và phân trang với Entity Framework

Sử dụng control Ext.Net GridPanel và phân trang với Entity Framework: "

Gần đây Ext.Net vừa chính thức cho ra đời version 1.0 cho cả Community và Pro, với nhiều tính năng và các fix bugs đã được cải thiện, cũng giống như tất cả các bộ thư viện control khác. Và cũng giống như ASP.NET GridView control, Ext.Net cũng cung cấp control dữ liệu (tabular) được đặt tên là GridPanel.

Trong bài viết này mình sẽ hướng dẫn bà con, các sử dụng Ext.Net GridPanel để binding data từ CSDL sử dụng Entity Framework và phân trang.

Yêu cầu trước tiên:
Download và cài đặt:
- Download version mới nhất của Ext.NET tại: http://www.ext.net/download
- Hướng dẫn cài đặt: lập trình ext.net với visual studio 2010

Tạo 1 website ASP.NET C# (VB.NET tùy ý) và kéo control GridPanel vào sau đó set các thuộc tính như:
Height='400'
Title='Customer List'
AutoExpandColumn='Address'

Định nghĩa Store (data source) cho GridPanel, ở đây mình sẽ kết nối với CSDL Northwind và lấy danh sách Customers lên:

<%@ Page Language='C#' AutoEventWireup='true' CodeFile='Default.aspx.cs' Inherits='_Default' %>



<%@ Register Assembly='Ext.Net' Namespace='Ext.Net' TagPrefix='ext' %>


<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">


<head runat="server">


<title>Using Ext.Net GridPanel with Paging in Entity Framework</title>


</head>


<body>


<form id='form1' runat="server">


<div>


<ext:ResourceManager ID='ResourceManager1' runat='server' />


<ext:GridPanel ID='GridPanel1' runat='server' Height='400' Title='Customer List'


AutoExpandColumn="Address">


<Store>


<ext:Store ID='dsCustomers' runat='server' OnRefreshData='Store1_Refresh' RemoteSort="true">


<Proxy>


<ext:PageProxy />


</Proxy>


<Reader>


<ext:JsonReader IDProperty="CustomerID">


<Fields>


<ext:RecordField Name='CustomerID' SortDir='ASC' />


<ext:RecordField Name='CompanyName' />


<ext:RecordField Name='ContactName' />


<ext:RecordField Name='Address' />


<ext:RecordField Name='City' />


<ext:RecordField Name='Phone' />


<ext:RecordField Name='Fax' />


<ext:RecordField Name='Region' />


</Fields>


</ext:JsonReader>


</Reader>


<BaseParams>


<ext:Parameter Name='start' Value='0' Mode='Raw' />


<ext:Parameter Name='limit' Value='15' Mode='Raw' />


<ext:Parameter Name='dir' Value='ASC' />


<ext:Parameter Name='sort' Value='CustomerID' />


</BaseParams>


<SortInfo Field='CustomerID' Direction='ASC' />


</ext:Store>


</Store>


<ColumnModel ID='ColumnModel1' runat="server">


<Columns>


<ext:Column ColumnID='CustomerID' DataIndex='CustomerID' Header="ID">


</ext:Column>


<ext:Column ColumnID='CompanyName' DataIndex='CompanyName' Header='Company Name'


Width="250">


</ext:Column>


<ext:Column ColumnID='ContactName' DataIndex='ContactName' Header='Contact Name'


Width="150">


</ext:Column>


<ext:Column ColumnID='Address' DataIndex='Address' Header='Address' Width="150">


</ext:Column>


<ext:Column ColumnID='City' DataIndex='City' Header="City">


</ext:Column>


<ext:Column ColumnID='Phone' DataIndex='Phone' Header="Phone">


</ext:Column>


<ext:Column ColumnID='Fax' DataIndex='Fax' Header="Fax">


</ext:Column>


<ext:Column ColumnID='Region' DataIndex='Region' Header="Region">


</ext:Column>


</Columns>


</ColumnModel>


<BottomBar>


<ext:PagingToolbar ID='PagingToolbar1' runat='server' PageSize='15' />


</BottomBar>


</ext:GridPanel>


</div>


</form>


</body>


</html>

Giải thích:
Sự kiện OnRefreshData của Store xử lý mỗi lần data source của store được update (cách xử lý trong code behind).
Thuộc tính RemoteSort="true": Cho phép sắp xếp sử dụng server code.
IDProperty="CustomerID" của JsonReader: thiết lập trường khóa chính dùng trong mục đích insert, delete và update.
ext:Parameter : Các parameters được truyền về mỗi lần store được referesh.
ColumnModel: Định nghĩa các field được bind lên từ CSDL.
ext:PagingToolbar: Control phân trang build-in của Ext.Net.
......

C# code:

using System.Linq;


using Ext.Net;


using NorthwindModel;



public partial class _Default : System.Web.UI.Page


{


protected void Store1_Refresh(object sender, StoreRefreshDataEventArgs e)


{


int start = int.Parse(e.Parameters['start']);


int limit = int.Parse(e.Parameters['limit']);


string dir = e.Parameters['dir'];


string sort = e.Parameters['sort'];


using (NorthwindEntities entities = new NorthwindEntities())


{


var customers = entities.Customers.OrderBy(string.Concat('it.' + sort, ' ', dir));


e.Total = customers.ToList().Count;


dsCustomers.DataSource = customers.Skip(start).Take(limit).ToList();


dsCustomers.DataBind();


}


}


}



Press F5 và xem kết quả:





Note: Việc paging cho GridPanel cũng như các control support paging khác là rất quan trọng trong ứng dụng đòi hỏi sự khéo léo trong vấn đề tối ưu hóa tốc độ thực thi của ứng dụng, Ext.Net take care hầu hết các thiếu sót trong giao diện xây dựng sẳn của .NET, thế vấn đề còn lại của các bạn là feel, thì mới xây dựng được 1 ứng dụng chuyên nghiệp cho cả look and feel.

Hope this help!


ExtGirdDemo.rar (3.67 mb)

"