using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data; using System.Text; using System.Collections; using System.Reflection; using System.Web.Script.Serialization; using FangYar.Model; using FangYar.BLL; namespace FangYar.WebUI.ashx { /// /// OaLeaveHandler 的摘要说明 /// public class ZYFireEpuHandler : IHttpHandler { private FangYar.BLL.FIRE.FIRE_EPUIP bll = new FangYar.BLL.FIRE.FIRE_EPUIP(); private FangYar.BLL.FIRE.FIRE_STATION sbll = new FangYar.BLL.FIRE.FIRE_STATION(); private FangYar.BLL.TBL.SysEmpBLL ebll = new FangYar.BLL.TBL.SysEmpBLL(); public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string action = context.Request.Params["Action"]; string returnstr = ""; switch (action) { case "EpuList": returnstr = GetEpuList(context); break; case "Add": returnstr = AddEpu(context); break; case "Edit": returnstr = EditEpu(context); break; case "StaList": returnstr = getStaList(context); break; case "Del": returnstr = DelEpu(context); break; } context.Response.Write(returnstr); } //查询 private string GetEpuList(HttpContext context) { string returnstr = ""; try { string OrgId = context.Request.Params["OrgId"]; string is_content = context.Request.Params["is_content"]; string keyword = context.Request.Params["keywords"]; string treeID = context.Request.Params["treeID"]; string page = context.Request.Params["page"]; string limit = context.Request.Params["limit"]; int pageIndex = 1; int pageSize = 10; if (!string.IsNullOrEmpty(page)) { pageIndex = int.Parse(page); } if (!string.IsNullOrEmpty(limit)) { pageSize = int.Parse(limit); } string where = null; if (!string.IsNullOrEmpty(treeID) && treeID != OrgId) { if (is_content == "1") { where = " org_id in ( select o.org_id from fire_org o,(select get_Org_child_list('" + treeID + "') cids ) s where find_in_set(org_id,cids) ) "; } else { where = " ORG_ID = '" + treeID + "'"; } } else { if (is_content == "1") { where = " org_id in ( select o.org_id from fire_org o,(select get_Org_child_list('" + OrgId + "') cids ) s where find_in_set(org_id,cids) ) "; } else { where = "ORG_ID = '" + OrgId + "'"; } } if (!string.IsNullOrEmpty(keyword)) { if (where != null) { where += " and "; } where += "( name like '%" + keyword + "%' or sta_name like '%" + keyword + "%')"; } returnstr = "{\"code\":0,\"msg\":\"\","; int count = bll.GetRecordCount(where); returnstr += "\"count\":" + count + ",\"data\":"; if (count == 0) { returnstr += "[]"; } else { List list = bll.QueryList(pageIndex, pageSize, where, ""); returnstr += FangYar.Common.JsonHelper.ToJson(list); } returnstr += "}"; } catch { returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}"; } return returnstr; } //获取所属消防机关列表 private string getStaList(HttpContext context) { string returnstr = ""; try { string orgId = context.Request.Params["OrgId"]; returnstr = "{\"code\":0,\"msg\":\"\",\"data\":"; DataTable data = sbll.getStaList(orgId); returnstr += FangYar.Common.JsonHelper.ToJson(data); returnstr += "}"; } catch { returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}"; } return returnstr; } //添加消防装备 private string AddEpu(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string USER_ID = context.Request.Params["USER_ID"]; string ID = Guid.NewGuid().ToString("N"); string TYPE_ID = context.Request.Params["TYPE_ID"]; string ORG_ID = context.Request.Params["ORG_ID"]; string ORG_NAME = context.Request.Params["ORG_NAME"]; string EQ_NUM = context.Request.Params["EQ_NUM"]; string SENSOR = context.Request.Params["SENSOR"]; string TRADEMARK = context.Request.Params["TRADEMARK"]; string GB_CODE = context.Request.Params["GB_CODE"]; string MANUFACTOR = context.Request.Params["MANUFACTOR"]; string LIABLE = context.Request.Params["LIABLE"]; string STATE = context.Request.Params["STATE"]; //消防装备表 FangYar.Model.FIRE.FIRE_EPUIP model = new Model.FIRE.FIRE_EPUIP(); model.ID = ID; model.TYPE_ID = TYPE_ID; model.ORG_ID = ORG_ID; model.ORG_NAME = ORG_NAME; model.EQ_NUM = int.Parse(EQ_NUM); model.SENSOR = SENSOR; model.TRADEMARK = TRADEMARK; model.GB_CODE = GB_CODE; model.MANUFACTOR = MANUFACTOR; model.LIABLE = LIABLE; model.STATE = STATE; model.A_PER = USER_ID; if (bll.AddEpu(model)) { msg = "添加成功!"; code = 1; } else { msg = "添加失败!"; } } catch { msg = "添加失败:装备编码有重复数据"; } returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}"; return returnstr; } //修改消防装备 private string EditEpu(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string USER_ID = context.Request.Params["USER_ID"]; string ID = context.Request.Params["ID"]; string TYPE_ID = context.Request.Params["TYPE_ID"]; string ORG_ID = context.Request.Params["ORG_ID"]; string ORG_NAME = context.Request.Params["ORG_NAME"]; string EQ_NUM = context.Request.Params["EQ_NUM"]; string SENSOR = context.Request.Params["SENSOR"]; string TRADEMARK = context.Request.Params["TRADEMARK"]; string GB_CODE = context.Request.Params["GB_CODE"]; string MANUFACTOR = context.Request.Params["MANUFACTOR"]; string LIABLE = context.Request.Params["LIABLE"]; string STATE = context.Request.Params["STATE"]; //消防装备表 FangYar.Model.FIRE.FIRE_EPUIP model = bll.GetModel(ID); if (model != null) { model.ID = ID; model.TYPE_ID = TYPE_ID; model.ORG_ID = ORG_ID; model.ORG_NAME = ORG_NAME; model.EQ_NUM = int.Parse(EQ_NUM); model.SENSOR = SENSOR; model.TRADEMARK = TRADEMARK; model.GB_CODE = GB_CODE; model.MANUFACTOR = MANUFACTOR; model.LIABLE = LIABLE; model.STATE = STATE; model.U_PER = USER_ID; } if (bll.EditEpu(model)) { msg = "修改成功!"; code = 1; } else { msg = "修改失败!"; } } catch { msg = "修改失败!"; } returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}"; return returnstr; } //删除消防装备 private string DelEpu(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string EpuList = context.Request.Params["EpuList"]; string[] EpuArray = EpuList.Split(','); string EpuListString = ""; for (int i = 0; i < EpuArray.Length; i++) { if (i == 0) { EpuListString = "'" + EpuArray[i] + "'"; } else { EpuListString += ",'" + EpuArray[i] + "'"; } } if (bll.DeleteList(EpuListString)) { msg = "删除成功!"; code = 1; } else { msg = "删除失败!"; } } catch { msg = "删除失败!"; } returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}"; return returnstr; } public bool IsReusable { get { return false; } } } }