-
Notifications
You must be signed in to change notification settings - Fork 0
/
Handler.ashx
321 lines (283 loc) · 11.1 KB
/
Handler.ashx
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
<%@ WebHandler Language="C#" Class="Handler" %>
using Newtonsoft.Json;
using System;
using System.Web;
using System.Data;
using System.Web.Script.Serialization;
using System.Collections.Generic;
using System.Configuration;
public class Handler : IHttpHandler
{
public void ProcessRequest (HttpContext context)
{
context.Response.AddHeader("Access-Control-Allow-Origin", "*");
context.Response.ContentType = "text/plain";
if (string.IsNullOrEmpty(context.Request.QueryString["method"]))
{
context.Response.Write("[]");
return;
}
string method = context.Request.QueryString["method"].ToString();
if (method.ToUpper() == "GetCategory".ToUpper()) // 返回筛选类别 ok
{
GetCategory(context);
}
else if (method.ToUpper() == "GetTrend".ToUpper()) // 根据鲜花类型、鲜花级别、鲜花系列、开始时间、结束时间查询报价 ok
{
GetTrend(context);
}
else if (method.ToUpper() == "GetFlowerPrice".ToUpper()) //ok 只接受id
{
GetFlowerPrice(context);
}
else if (method.ToUpper() == "GetRemarks".ToUpper()) // 获取备注信息
{
GetRemarks(context);
}
else if(method.ToUpper() == "GetUrl".ToUpper())
{
string uri = context.Request.Url.Authority;
context.Response.Write(uri);
}
else
{
context.Response.Write("{'error':1}");
}
}
public bool IsReusable
{
get
{
return false;
}
}
public void GetRemarks (HttpContext context) // 获取备注信息
{
string sql = "select * from remarks";
DataSet ds = DBHelperAccess.GetList(sql);
context.Response.Write(DataTableToJsonWithJavaScriptSerializer(ds.Tables[0]));
}
public void GetFlowerPrice (HttpContext context)
{
string where = " 1=1 ";
if (!string.IsNullOrEmpty(context.Request.QueryString["id"])) //每日报价id
{
where += " and priceInfoId=" + context.Request.QueryString["id"].ToString();
}
if (!string.IsNullOrEmpty(context.Request.QueryString["lb"])) //类别
{
where += " and f.lx=" + context.Request.QueryString["lb"].ToString();
}
string host = HttpContext.Current.Request.Url.Host + "/img/";
// string path = ConfigurationManager.AppSettings["url"].ToString() + "/img/";
string path = "http://" + context.Request.Url.Authority + "/img/";
string sql = "select p.id,f.lx,t.lxmc as jb,f.zl,f.mc,'" + path + "'+f.tp as tp,f.gg,p.cd,p.bz,p.jg as price,p.trend from (price p inner join flower f on f.id=p.flowerid) inner join type t on f.zl=t.id where " + where+" order by f.lx,f.zl,f.id";
DataSet ds = DBHelperAccess.GetList(sql);
if (ds == null || ds.Tables.Count == 0)
{
context.Response.Write("[]");
}
else
{
DataTable dt = ds.Tables[0];
context.Response.Write(DataTableToJsonWithJavaScriptSerializer(dt));
}
}
/// <summary>
/// 获得鲜花分类
/// </summary>
/// <param name="context"></param>
public void GetCategory (HttpContext context)
{
string id = context.Request.QueryString["id"];
if (id == null || id=="") // 如果没有参数返回3个类
{
id = "0";
}
string sql = "select id,lxmc,lx,zl from type where lx ='" + id+"'";
DataSet ds = DBHelperAccess.GetList(sql);
if (ds == null || ds.Tables.Count == 0)
{
context.Response.Write("[]");
}
else
{
DataTable dt = ds.Tables[0];
context.Response.Write(DataTableToJsonWithJavaScriptSerializer(dt));
}
}
///// <summary>
///// 按条件返回报价
///// </summary>
///// <param name="context"></param>
//public void GetCategoryFlower (HttpContext context)
//{
// string where = " 1=1 ";
// if (!string.IsNullOrEmpty(context.Request.QueryString["lx"])) // 类型
// {
// where += " and lx=" + context.Request.QueryString["lx"].ToString();
// }
// if (!string.IsNullOrEmpty(context.Request.QueryString["jb"])) // 级别
// {
// where += " and jb=" + context.Request.QueryString["jb"].ToString();
// }
// if (!string.IsNullOrEmpty(context.Request.QueryString["zl"])) //系列
// {
// where += " and zl=" + context.Request.QueryString["zl"].ToString();
// }
// string sql = "select * from flower where " + where;
// DataSet ds = DBHelperAccess.GetList(sql);
// if (ds == null || ds.Tables.Count == 0)
// {
// context.Response.Write("[]");
// }
// else
// {
// DataTable dt = ds.Tables[0];
// context.Response.Write(DataTableToJsonWithJavaScriptSerializer(dt));
// }
//}
///// <summary>
///// 根据日期查询报价信息
///// </summary>
///// <param name="context"></param>
//public void GetOneDayPrice (HttpContext context)
//{
// string where = " 1=1 ";
// if (!string.IsNullOrEmpty(context.Request.QueryString["bjrq"])) //报价日期
// {
// where += " and bjrq= #" + context.Request.QueryString["bjrq"].ToString() + "#";
// }
// string sql = "select bjmc,bjrq from price where " + where;
// DataSet ds = DBHelperAccess.GetList(sql);
// if (ds == null || ds.Tables.Count == 0)
// {
// context.Response.Write("[]");
// }
// else
// {
// DataTable dt = ds.Tables[0];
// context.Response.Write(DataTableToJsonWithJavaScriptSerializer(dt));
// }
//}
///// <summary>
///// 查询所有报价列表
///// </summary>
///// <param name="context"></param>
//public void GetPrice (HttpContext context)
//{
// string sql = "select distinct bjmc,bjrq from price";
// DataSet ds = DBHelperAccess.GetList(sql);
// if (ds == null || ds.Tables.Count == 0)
// {
// context.Response.Write("[]");
// }
// else
// {
// DataTable dt = ds.Tables[0];
// context.Response.Write(DataTableToJsonWithJavaScriptSerializer(dt));
// }
//}
public void GetTrend (HttpContext context)
{
List<Model.GetTrendModel> models = new List<Model.GetTrendModel>();
string priceInfoWhere = " 1=1 ";
if (!string.IsNullOrEmpty(context.Request.QueryString["startDate"])) // 开始日期
{
priceInfoWhere += " and cdate(bjDate)>= #" + context.Request.QueryString["startDate"].ToString() + "# ";
}
if (!string.IsNullOrEmpty(context.Request.QueryString["endDate"])) // 结束日期
{
priceInfoWhere += " and cdate(bjDate)<= #" + context.Request.QueryString["endDate"].ToString() + "# ";
}
if (!string.IsNullOrEmpty(context.Request.QueryString["lx"])) // 类型
{
priceInfoWhere += " and lxName='" + context.Request.QueryString["lx"].ToString() + "' ";
}
string pageSize = "100000";
if (!string.IsNullOrEmpty(context.Request.QueryString["pagesize"])) // 查出条数
{
pageSize = context.Request.QueryString["pagesize"].ToString();
}
string priceInfoSql = "select top " + pageSize + " * from priceInfo where" + priceInfoWhere + " order by cdate(bjDate) desc ";
DataSet ds = DBHelperAccess.GetList(priceInfoSql);
if (ds == null || ds.Tables.Count == 0)
{
context.Response.Write("[]");
}
else // 查询子数据
{
DataTable dt = ds.Tables[0];
foreach (DataRow dr in dt.Rows)
{
Model.GetTrendModel model = new Model.GetTrendModel();
string priceWhere = " p.priceInfoId = " + dr["id"];
if (!string.IsNullOrEmpty(context.Request.QueryString["lx"])) // 类型
{
priceWhere += " and f.lx=" + context.Request.QueryString["lx"].ToString();
}
if (!string.IsNullOrEmpty(context.Request.QueryString["jb"])) // 级别
{
priceWhere += " and p.dj='" + context.Request.QueryString["jb"].ToString()+"'";
}
if (!string.IsNullOrEmpty(context.Request.QueryString["zl"])) //系列
{
priceWhere += " and f.zl=" + context.Request.QueryString["zl"].ToString();
}
if (!string.IsNullOrEmpty(context.Request.QueryString["isRecommend"])) // 是否推荐
{
priceWhere += " and f.tj=" + context.Request.QueryString["isRecommend"].ToString();
}
string priceSql = "";
string jb = context.Request.QueryString["jb"];
//if (string.IsNullOrEmpty(jb))
//{
priceSql = "select f.mc,f.id,p.jg as price,t.lxmc as jb,p.cd,p.bz " +
"from (flower f inner join type t on t.id=f.zl) " +
"inner join price p on f.id=p.flowerid where " + priceWhere + " order by f.lx, f.zl,f.id";
//}
//else
//{
// priceSql = "select f.mc,f.id,p.dj," +
// "iif(p.dj='"+jb+"',p.jg,0) as price ," +
// "t.lxmc as jb,p.cd,p.bz from (flower f inner join type t on t.id=f.zl) inner join price p on f.id=p.flowerid where " + priceWhere + " order by f.lx, f.zl,f.id";
//}
DataSet priceDs = DBHelperAccess.GetList(priceSql);
model.title = dr["bjName"].ToString(); // 报价名
model.date = dr["bjdate"].ToString(); // 报价日期
model.id = dr["id"].ToString();
if (priceDs == null || priceDs.Tables.Count == 0)
{
model.list = null;
}
else
{
model.list = priceDs.Tables[0];
}
models.Add(model);
}
context.Response.Write(JsonConvert.SerializeObject(models));
}
}
/// <summary>
/// datatable转json
/// </summary>
/// <param name="table"></param>
/// <returns></returns>
public string DataTableToJsonWithJavaScriptSerializer (DataTable table)
{
JavaScriptSerializer jsSerializer = new JavaScriptSerializer();
List<Dictionary<string, object>> parentRow = new List<Dictionary<string, object>>();
Dictionary<string, object> childRow;
foreach (DataRow row in table.Rows)
{
childRow = new Dictionary<string, object>();
foreach (DataColumn col in table.Columns)
{
childRow.Add(col.ColumnName, row[col]);
}
parentRow.Add(childRow);
}
return jsSerializer.Serialize(parentRow);
}
}