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; using FangYar.BLL.FIRE; namespace FangYar.WebUI.ashx { /// /// OaLeaveHandler 的摘要说明 /// public class ZYFireUnitHandler : IHttpHandler { private FangYar.BLL.FIRE.FIRE_E_L_UNIT bll = new FangYar.BLL.FIRE.FIRE_E_L_UNIT(); public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string action = context.Request.Params["Action"]; string returnstr = ""; switch (action) { case "UnitList": returnstr = GetUnitList(context); break; case "Add": returnstr = AddUnit(context); break; case "Edit": returnstr = EditUnit(context); break; case "Del": returnstr = DelUnit(context); break; case "homepageUnit"://首页右下角 returnstr = QueryTopUnitByOrgId(context); break; } context.Response.Write(returnstr); } //查询 private string GetUnitList(HttpContext context) { string returnstr = ""; try { string OrgId = context.Request.Params["OrgId"]; string Type = context.Request.Params["Type"]; string keyword = context.Request.Params["keywords"]; 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, mod_code = null; if (Type == "0") { mod_code = "EUNITTYPE"; } else if (Type == "1") { mod_code = "LUNITTYPE"; } if (!string.IsNullOrEmpty(Type)) { if (where != null) { where += " and "; } where += "TYPE = '" + Type + "'"; } if (!string.IsNullOrEmpty(OrgId)) { if (where != null) { where += " and "; } where += "ORG_ID = '" + OrgId + "'"; } if (!string.IsNullOrEmpty(keyword)) { if (where != null) { where += " and "; } where += "( name like '%" + keyword + "%' or ADDR 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, "", mod_code); returnstr += FangYar.Common.JsonHelper.ToJson(list); } returnstr += "}"; } catch (Exception e) { returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}"; } return returnstr; } /// /// 查询若干条应急联动单位,供首页展示用 /// /// /// public string QueryTopUnitByOrgId(HttpContext context) { string orgId = context.Request.Params["OrgId"]+""; string condition = string.Empty; string returnStr = string.Empty; if (!String.IsNullOrEmpty(orgId)) { condition += string.Format("ORG_ID='{0}'", orgId); } returnStr = "{\"code\":0,\"msg\":\"\","; ZYFireExpertHandler expertHandler = new ZYFireExpertHandler(); try { List list = bll.QueryTopUnitByOrgId(condition); if (list.Count > 0) { returnStr += "\"count\":" + list.Count + ",\"data\":"; returnStr += Common.JsonHelper.ToJson(list); } else { returnStr += "[]"; } returnStr += "}"; } catch (Exception e) { returnStr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}"; } return returnStr; } //添加应急联动联勤保障单位 private string AddUnit(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 = context.Request.Params["TYPE"]; string NAME = context.Request.Params["NAME"]; string UNIT_TYPE = context.Request.Params["UNIT_TYPE"]; string ADDR = context.Request.Params["ADDR"]; string PHONE = context.Request.Params["PHONE"]; string UNIT_PER = context.Request.Params["UNIT_PER"]; string ORG_ID = context.Request.Params["ORG_ID"]; string BelongToArea = context.Request.Params["BelongToAreaId"]; //应急联动联勤保障单位表 FangYar.Model.FIRE.FIRE_E_L_UNIT model = new Model.FIRE.FIRE_E_L_UNIT(); model.ID = ID; model.TYPE = TYPE; model.NAME = NAME; model.UNIT_TYPE = UNIT_TYPE; model.ADDR = ADDR; model.PHONE = PHONE; model.UNIT_PER = UNIT_PER; model.ORG_ID = ORG_ID; model.A_PER = USER_ID; model.EXTENDCODE1 = BelongToArea.Trim(); if (bll.Add(model)) { msg = "添加成功!"; code = 1; } else { msg = "添加失败!"; } } catch { msg = "添加失败"; } returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}"; return returnstr; } //修改应急联动联勤保障单位 private string EditUnit(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 = context.Request.Params["TYPE"]; string NAME = context.Request.Params["NAME"]; string UNIT_TYPE = context.Request.Params["UNIT_TYPE"]; string ADDR = context.Request.Params["ADDR"]; string PHONE = context.Request.Params["PHONE"]; string UNIT_PER = context.Request.Params["UNIT_PER"]; string ORG_ID = context.Request.Params["ORG_ID"]; string BelongToArea = context.Request.Params["BelongToAreaId"]; //应急联动联勤保障单位表 FangYar.Model.FIRE.FIRE_E_L_UNIT model = new Model.FIRE.FIRE_E_L_UNIT(); model.ID = ID; model.TYPE = TYPE; model.NAME = NAME; model.UNIT_TYPE = UNIT_TYPE; model.ADDR = ADDR; model.PHONE = PHONE; model.UNIT_PER = UNIT_PER; model.ORG_ID = ORG_ID; model.U_PER = USER_ID; model.EXTENDCODE1 = BelongToArea.Trim(); if (bll.Update(model)) { msg = "修改成功!"; code = 1; } else { msg = "修改失败!"; } } catch (Exception e) { msg = "修改失败!"; } returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}"; return returnstr; } //删除应急联动联勤保障单位 private string DelUnit(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string UnitList = context.Request.Params["UnitList"]; string[] UnitArray = UnitList.Split(','); string UnitListString = ""; for (int i = 0; i < UnitArray.Length; i++) { if (i == 0) { UnitListString = "'" + UnitArray[i] + "'"; } else { UnitListString += ",'" + UnitArray[i] + "'"; } } if (bll.DeleteList(UnitListString)) { msg = "删除成功!"; code = 1; } else { msg = "删除失败!"; } } catch { msg = "删除失败!"; } returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}"; return returnstr; } public bool IsReusable { get { return false; } } } }