using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace FangYar.WebUI.ashx { /// /// WarnHandler 的摘要说明 /// public class WarnHandler : IHttpHandler { private FangYar.BLL.ZHSQ.WarnRecordBLL bll = new BLL.ZHSQ.WarnRecordBLL(); public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/json"; string action = context.Request.Params["Action"]; string returnstr = ""; switch (action) { case "List": returnstr = GetList(context); break; case "TreeList": returnstr = GetTreeList(context); break; case "UserList": returnstr = GetUserList(context); break; case "Add": returnstr = Add(context); break; case "Edit": returnstr = Edit(context); break; case "Del": returnstr = Del(context); break; } context.Response.Write(returnstr); } //查询 private string GetTreeList(HttpContext context) { string returnstr = ""; try { string keywords = context.Request.Params["keywords"]; string treeID = context.Request.Params["treeID"]; string limit = context.Request.Params["limit"]; string page = context.Request.Params["page"]; int pageIndex = 1; int pageSize = 10; if (!string.IsNullOrEmpty(limit)) { pageIndex = int.Parse(page); } if (!string.IsNullOrEmpty(limit)) { pageSize = int.Parse(limit); } string where = null; if (!string.IsNullOrEmpty(keywords)) { where = " DEV_ID like '%" + keywords + "%' "; } if (!string.IsNullOrEmpty(treeID)) { if (where != null) { where += " and "; } where += " FOLDER_ID ='" + treeID + "' "; } returnstr = "{\"code\":0,\"msg\":\"\","; int count = bll.Count(where); returnstr += "\"count\":" + count + ",\"data\":"; if (count == 0) { returnstr += "[]"; } else { List list = bll.QueryList(pageIndex, pageSize, where, null); returnstr += FangYar.Common.JsonHelper.ToJson(list); } returnstr += "}"; } catch { returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]"; } return returnstr; } //查询 private string GetList(HttpContext context) { string returnstr = ""; try { string Dev = context.Request.Params["Dev"]; string Wtime = context.Request.Params["Wtime"]; string limit = context.Request.Params["limit"]; string page = context.Request.Params["page"]; int pageIndex = 1; int pageSize = 10; if (!string.IsNullOrEmpty(limit)) { pageIndex = int.Parse(page); } if (!string.IsNullOrEmpty(limit)) { pageSize = int.Parse(limit); } string where = " 1=1 "; if (!string.IsNullOrEmpty(Dev)) { where += " and DEV_ID like '%" + Dev + "%' "; } if (!string.IsNullOrEmpty(Wtime)) { string[] times = Wtime.Split('-'); where += " and RECORD_TIME between date_format('" + times[0].Trim(' ') + "','%Y-%m-%d %H:%i:%s') and date_format('" + times[1].Trim(' ') + "','%Y-%m-%d %H:%i:%s') "; } returnstr = "{\"code\":0,\"msg\":\"\","; int count = bll.Count(where); returnstr += "\"count\":" + count + ",\"data\":"; if (count == 0) { returnstr += "[]"; } else { List list = bll.QueryList(pageIndex, pageSize, where, null); returnstr += FangYar.Common.JsonHelper.ToJson(list); } returnstr += "}"; } catch { returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]"; } return returnstr; } //查询 private string GetUserList(HttpContext context) { string returnstr = ""; try { FangYar.Model.LoginUserModel user = FangYar.Common.UserHelper.GetUser(context); if (user != null) { string Dev = context.Request.Params["Dev"]; string Wtime = context.Request.Params["Wtime"]; string limit = context.Request.Params["limit"]; string page = context.Request.Params["page"]; int pageIndex = 1; int pageSize = 10; if (!string.IsNullOrEmpty(limit)) { pageIndex = int.Parse(page); } if (!string.IsNullOrEmpty(limit)) { pageSize = int.Parse(limit); } string where = " and DEV_CODE = '" + user.OrgID + "' "; if (!string.IsNullOrEmpty(Dev)) { where += " and DEV_ID like '%" + Dev + "%' "; } if (!string.IsNullOrEmpty(Wtime)) { string[] times = Wtime.Split('-'); where += " and RECORD_TIME between date_format('" + times[0].Trim(' ') + "','%Y-%m-%d %H:%i:%s') and date_format('" + times[1].Trim(' ') + "','%Y-%m-%d %H:%i:%s') "; } returnstr = "{\"code\":0,\"msg\":\"\","; int count = bll.Count(where); returnstr += "\"count\":" + count + ",\"data\":"; if (count == 0) { returnstr += "[]"; } else { List list = bll.QueryList(pageIndex, pageSize, where, null); returnstr += FangYar.Common.JsonHelper.ToJson(list); } returnstr += "}"; } else { returnstr = "{\"code\":-2,\"msg\":\"登录超时\",\"count\":0,\"data\":[]}"; } } catch { returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}"; } return returnstr; } //添加 private string Add(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string userUID = context.Request.Params["userUID"]; string userPwd = context.Request.Params["userPwd"]; string userType = context.Request.Params["userType"]; string userName = context.Request.Params["userName"]; if (string.IsNullOrEmpty(userUID)) { msg = "账号不能为空!"; } else if (userUID.Length < 4) { msg = "账号长度最少为4个字符!"; } else if (string.IsNullOrEmpty(userPwd)) { msg = "密码不能为空!"; } else if (userUID.Length < 4) { msg = "密码长度最少为4个字符!"; } else if (string.IsNullOrEmpty(userName)) { msg = "名称不能为空!"; } else { FangYar.Model.ZHSQ.ZHSQ_WARN_RECORD_Model model = new Model.ZHSQ.ZHSQ_WARN_RECORD_Model(); if (bll.Add(model)) { msg = "添加成功!"; code = 1; } else { msg = "添加失败!"; } } } catch { msg = "添加失败!"; } returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}"; return returnstr; } //修改 private string Edit(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string ID = context.Request.Params["ID"]; string userUID = context.Request.Params["userUID"]; string userPwd = context.Request.Params["userPwd"]; string userType = context.Request.Params["userType"]; string userName = context.Request.Params["userName"]; FangYar.Model.ZHSQ.ZHSQ_WARN_RECORD_Model model = bll.GetModelByID(ID); if (model == null) { msg = "用户不存在!"; } else { if (bll.Edit(model)) { msg = "修改成功!"; code = 1; } else { msg = "修改失败!"; } } } catch { msg = "修改失败!"; } returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}"; return returnstr; } //删除 private string Del(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string UIDList = context.Request.Params["UIDList"]; UIDList = "'" + UIDList.Replace(",", "','") + "'"; if (bll.Delete(UIDList)) { msg = "删除成功!"; code = 1; } else { msg = "删除失败!"; } } catch { msg = "删除失败!"; } returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}"; return returnstr; } public bool IsReusable { get { return false; } } } }