using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace FangYar.WebUI.ashx { /// /// DicModHandler 的摘要说明 /// public class DicModHandler : IHttpHandler { private FangYar.BLL.TBL.SysDicmoBLL bll = new BLL.TBL.SysDicmoBLL(); public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/json"; string action = context.Request.Params["Action"]; string returnstr = ""; switch (action) { case "List": returnstr = GetModelList(context); break; case "Add": returnstr = AddModel(context); break; case "Edit": returnstr = EditModel(context); break; case "Del": returnstr = DelModel(context); break; } context.Response.Write(returnstr); } //查询 private string GetModelList(HttpContext context) { string returnstr = ""; try { string keywords = context.Request.Params["keywords"]; 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 = "MOD_CODE like '" + keywords + "' or MOD_NAME like '" + keywords + "' "; } 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 AddModel(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string dicmodCode = context.Request.Params["dicmodCode"]; string dicmodName = context.Request.Params["dicmodName"]; if (string.IsNullOrEmpty(dicmodCode)) { msg = "编号不能为空!"; } else if (string.IsNullOrEmpty(dicmodName)) { msg = "名称不能为空!"; } else { FangYar.Model.TBL.TBL_SYS_DICMOD_Model model = new Model.TBL.TBL_SYS_DICMOD_Model(); model.MOD_CODE = dicmodCode; model.MOD_NAME = dicmodName; if (bll.Add(model)) { msg = "添加成功!"; code = 1; } else { msg = "添加失败!"; } } } catch { msg = "添加失败!"; } returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}"; return returnstr; } //修改 private string EditModel(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string ID = context.Request.Params["ID"]; string dicmodCode = context.Request.Params["dicmodCode"]; string dicmodName = context.Request.Params["dicmodName"]; if (string.IsNullOrEmpty(dicmodCode)) { msg = "编号不能为空!"; } else if (string.IsNullOrEmpty(dicmodName)) { msg = "名称不能为空!"; } else { FangYar.Model.TBL.TBL_SYS_DICMOD_Model model = bll.GetModelByID(dicmodCode); if (model == null) { msg = "该记录不存在!"; } else { model.MOD_CODE = dicmodCode; model.MOD_NAME = dicmodName; if (bll.Edit(model)) { msg = "修改成功!"; code = 1; } else { msg = "修改失败!"; } } } } catch { msg = "修改失败!"; } returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}"; return returnstr; } //删除 private string DelModel(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; } } } }