forked from jackieli123723/JavaScript.Utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseHandler.ashx.cs
More file actions
157 lines (148 loc) · 6.9 KB
/
BaseHandler.ashx.cs
File metadata and controls
157 lines (148 loc) · 6.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;
using YanZhiwei.DotNet.NPOI2.Utilities;
using YanZhiwei.DotNet2.Utilities.Collection;
using YanZhiwei.DotNet2.Utilities.Common;
using YanZhiwei.DotNet2.Utilities.DataOperator;
using YanZhiwei.DotNet2.Utilities.Enum;
using YanZhiwei.DotNet2.Utilities.Model;
using YanZhiwei.DotNet3._5.Utilities.Common;
using YanZhiwei.DotNet3._5.Utilities.Mapper;
using YanZhiwei.DotNet3._5.Utilities.Model;
using YanZhiwei.DotNet3._5.Utilities.WebForm;
using YanZhiwei.DotNet3._5.Utilities.WebForm.JqueryPlugin;
using YanZhiwei.JavaScript.Utilities.Model;
namespace YanZhiwei.JavaScript.Utilities.BackHandler
{
/// <summary>
/// Summary description for BaseHandler
/// </summary>
public class BaseHandler : IHttpHandler
{
public static IEnumerable<Person> GetPersons()
{
for(int i = 0; i < 57; i++)
{
yield return new Person
{
Id = i,
Name = "name " + i
};
}
}
public void ProcessRequest(HttpContext context)
{
string _actionType = context.Request.Params["action"].ToStringOrDefault("UnKown");
if(_actionType.CompareIgnoreCase("getLocationList"))
{
int _pageIndex = context.Request.Params["PageIndex"].ToInt32OrDefault(1),
_pageSize = context.Request.Params["PageSize"].ToInt32OrDefault(10);
SqlServerDataOperator _helper = new SqlServerDataOperator(@"Server=YANZHIWEI-IT-PC\SQLEXPRESS;database=Northwind;user id=sa;Password=sasa");
PagedList<Order> _pageResult = _helper.ExecutePageQuery<Order>("[Orders]", "*", "OrderID", OrderType.Desc, string.Empty, _pageSize, _pageIndex);
AjaxResult _result = new AjaxResult(string.Empty, AjaxResultType.Success, _pageResult);
string _json = SerializeHelper.JsonSerialize(new JsonPagedList<Order>(_pageResult)).ParseJsonDateTime();
context.Response.Write(_json);
}
else if(_actionType.CompareIgnoreCase("exportLocationExcel"))
{
SqlServerDataOperator _helper = new SqlServerDataOperator(@"Server=YANZHIWEI-IT-PC\SQLEXPRESS;database=JooWMS;user id=sa;Password=sasa");
PagedList<Location> _pageResult = _helper.ExecutePageQuery<Location>("[Location]", "*", "ID", OrderType.Desc, string.Empty, 10, 1);
DataTable _result = GeneralMapper.ToDataTable<Location>(_pageResult, new string[4] { "LocalNum", "LocalBarCode", "LocalName", "StorageNum" });
string _filePath = context.Server.MapPath("~/UploadFiles/");
if(!Directory.Exists(_filePath))
{
Directory.CreateDirectory(_filePath);
}
string _filename = string.Format("库位管理{0}.xls", DateTime.Now.ToString("yyyyMMddHHmmss"));
NPOIExcel.ToExcel(_result, "库位管理", "库位", Path.Combine(_filePath, _filename));
context.CreateResponse(("/UploadFiles/" + _filename).Escape(), AjaxResultType.Success, string.Empty);
}
else
{
context.ExecutePageQuery<Person>((pageLength, pageIndex, orderIndex, orderBy) =>
{
var persons = GetPersons();
Func<Person, object> order = p =>
{
if(orderIndex == 0)
{
return p.Id;
}
return p.Name;
};
if("desc" == orderBy)
{
persons = persons.OrderByDescending(order);
}
else
{
persons = persons.OrderBy(order);
}
//错误测试
//DataTablePageResult result = new DataTablePageResult();
//result.ExecuteMessage = "测试错误";
//result.ExecuteState = HttpStatusCode.BadGateway;
//正确测试
DataTablePageResult result = new DataTablePageResult();
result.iTotalDisplayRecords = persons.Count();
List<Person> _personList = new List<Person>();
result.iTotalRecords = persons.Count();
result.aaData = persons.Skip(pageIndex).Take(pageLength);
result.ExecuteState = HttpStatusCode.OK;
return result;
});
// // Those parameters are sent by the plugin
// var iDisplayLength = int.Parse(context.Request["iDisplayLength"]);
// var iDisplayStart = int.Parse(context.Request["iDisplayStart"]);
// var iSortCol = int.Parse(context.Request["iSortCol_0"]);
// var iSortDir = context.Request["sSortDir_0"];
// // Fetch the data from a repository (in my case in-memory)
// var persons = GetPersons();
// // Define an order function based on the iSortCol parameter
// Func<Person, object> order = p =>
// {
// if (iSortCol == 0)
// {
// return p.Id;
// }
// return p.Name;
// };
// // Define the order direction based on the iSortDir parameter
// if ("desc" == iSortDir)
// {
// persons = persons.OrderByDescending(order);
// }
// else
// {
// persons = persons.OrderBy(order);
// }
// // prepare an anonymous object for JSON serialization
// var result = new
// {
// iTotalRecords = persons.Count(),
// iTotalDisplayRecords = persons.Count(),
// aaData = persons
// .Skip(iDisplayStart)
// .Take(iDisplayLength)
// };
// //var serializer = new JavaScriptSerializer();
//// var json = SerializationHelper.JsonSerialize(result);// serializer.Serialize(result);
// context.CreateResponse(result, System.Net.HttpStatusCode.OK);
// //context.Response.ContentType = "application/json";
// //context.Response.Write(json);
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}