1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . Linq ;
4+ using System . Net ;
5+ using System . Web ;
6+ using YanZhiwei . DotNet3 . _5 . Utilities . Model ;
7+ using YanZhiwei . DotNet3 . _5 . Utilities . WebForm . Jquery ;
8+
9+ namespace YanZhiwei . JavaScript . Utilities . BackHandler
10+ {
11+ /// <summary>
12+ /// Summary description for BaseHandler
13+ /// </summary>
14+ public class BaseHandler : IHttpHandler
15+ {
16+ public static IEnumerable < Person > GetPersons ( )
17+ {
18+ for ( int i = 0 ; i < 57 ; i ++ )
19+ {
20+ yield return new Person
21+ {
22+ Id = i ,
23+ Name = "name " + i
24+ } ;
25+ }
26+ }
27+
28+ public void ProcessRequest ( HttpContext context )
29+ {
30+ context . ExecutePageQuery < Person > ( ( pageLength , pageIndex , orderIndex , orderBy ) =>
31+ {
32+ var persons = GetPersons ( ) ;
33+ Func < Person , object > order = p =>
34+ {
35+ if ( orderIndex == 0 )
36+ {
37+ return p . Id ;
38+ }
39+ return p . Name ;
40+ } ;
41+ if ( "desc" == orderBy )
42+ {
43+ persons = persons . OrderByDescending ( order ) ;
44+ }
45+ else
46+ {
47+ persons = persons . OrderBy ( order ) ;
48+ }
49+ //错误测试
50+ //DataTablePageResult result = new DataTablePageResult();
51+ //result.ExecuteMessage = "测试错误";
52+ //result.ExecuteState = HttpStatusCode.BadGateway;
53+ //正确测试
54+ DataTablePageResult result = new DataTablePageResult ( ) ;
55+ result . iTotalDisplayRecords = persons . Count ( ) ;
56+ List < Person > _personList = new List < Person > ( ) ;
57+ result . iTotalRecords = persons . Count ( ) ;
58+ result . aaData = persons . Skip ( pageIndex ) . Take ( pageLength ) ;
59+ result . ExecuteState = HttpStatusCode . OK ;
60+ return result ;
61+ } ) ;
62+ // // Those parameters are sent by the plugin
63+ // var iDisplayLength = int.Parse(context.Request["iDisplayLength"]);
64+ // var iDisplayStart = int.Parse(context.Request["iDisplayStart"]);
65+ // var iSortCol = int.Parse(context.Request["iSortCol_0"]);
66+ // var iSortDir = context.Request["sSortDir_0"];
67+
68+ // // Fetch the data from a repository (in my case in-memory)
69+ // var persons = GetPersons();
70+
71+ // // Define an order function based on the iSortCol parameter
72+ // Func<Person, object> order = p =>
73+ // {
74+ // if (iSortCol == 0)
75+ // {
76+ // return p.Id;
77+ // }
78+ // return p.Name;
79+ // };
80+
81+ // // Define the order direction based on the iSortDir parameter
82+ // if ("desc" == iSortDir)
83+ // {
84+ // persons = persons.OrderByDescending(order);
85+ // }
86+ // else
87+ // {
88+ // persons = persons.OrderBy(order);
89+ // }
90+
91+ // // prepare an anonymous object for JSON serialization
92+ // var result = new
93+ // {
94+ // iTotalRecords = persons.Count(),
95+ // iTotalDisplayRecords = persons.Count(),
96+ // aaData = persons
97+ // .Skip(iDisplayStart)
98+ // .Take(iDisplayLength)
99+ // };
100+
101+ // //var serializer = new JavaScriptSerializer();
102+ //// var json = SerializationHelper.JsonSerialize(result);// serializer.Serialize(result);
103+ // context.CreateResponse(result, System.Net.HttpStatusCode.OK);
104+ // //context.Response.ContentType = "application/json";
105+ // //context.Response.Write(json);
106+ }
107+
108+ public bool IsReusable
109+ {
110+ get
111+ {
112+ return false ;
113+ }
114+ }
115+ }
116+
117+ public class Person
118+ {
119+ public int Id { get ; set ; }
120+ public string Name { get ; set ; }
121+ }
122+ }
0 commit comments