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 Newtonsoft.Json; using Newtonsoft.Json.Linq; namespace FangYar.WebUI.ashx { /// /// FireLeaveHandler 的摘要说明 /// public class FirePatrolPlanHandler : IHttpHandler { private FangYar.BLL.FIRE_PATROL_PLAN bll = new FangYar.BLL.FIRE_PATROL_PLAN(); public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string action = context.Request.Params["Action"]; string returnstr = ""; switch (action) { case "List": returnstr = getPlanlist(context); break; case "Add": returnstr = AddPlan(context); break; case "Edit": returnstr = EditPlan(context); break; case "Del": returnstr = DelPlan(context); break; } context.Response.Write(returnstr); } //查询 private string getPlanlist(HttpContext context) { string returnstr = ""; try { string orgId = context.Request.Params["orgId"]; 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; 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) )"; if (!string.IsNullOrEmpty(keyword)) { where += " and NAME like '%" + keyword + "%' or USERS_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, null); returnstr += FangYar.Common.JsonHelper.ToJson(list); } returnstr += "}"; } catch { returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]"; } return returnstr; } //添加巡查计划 private string AddPlan(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string planId = Guid.NewGuid().ToString("N"); string USER_ID = context.Request.Params["UserId"]; string orgId = context.Request.Params["orgId"]; string CITY = context.Request.Params["CITY"]; string NAME = context.Request.Params["NAME"]; string CYCLE = context.Request.Params["CYCLE"]; string WORK_DAY = context.Request.Params["WORK_DAY"]; string S_TIME = context.Request.Params["S_TIME"]; string E_TIME = context.Request.Params["E_TIME"]; string USERS_UID = context.Request.Params["USERS_UID"]; string USERS_NAME = context.Request.Params["USERS_NAME"]; string SPOTS = context.Request.Params["SPOTS"]; string SPOT_IDS = context.Request.Params["SPOT_IDS"]; string SPOT_NAMES = context.Request.Params["SPOT_NAMES"]; string STATE = context.Request.Params["STATE"]; //巡查计划表 FangYar.Model.FIRE_PATROL_PLAN model = new Model.FIRE_PATROL_PLAN(); model.ID = planId; model.NAME = NAME; model.CYCLE = CYCLE; model.WORK_DAY = WORK_DAY; model.S_TIME = S_TIME; model.E_TIME = E_TIME; model.USERS_UID = USERS_UID; model.USERS_NAME = USERS_NAME; model.SPOTS = SPOTS; model.SPOT_IDS = SPOT_IDS; model.SPOT_NAMES = SPOT_NAMES; model.A_PER = USER_ID; model.ORG_ID = orgId; model.CITY = CITY; model.STATE = STATE; if (bll.Add(model)) { msg = "添加成功!"; code = 1; } else { msg = "添加失败!"; } } catch (Exception e) { msg = "添加失败!"; } returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}"; return returnstr; } //修改巡查计划 private string EditPlan(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string ID = context.Request.Params["ID"]; string USER_ID = context.Request.Params["UserId"]; string orgId = context.Request.Params["orgId"]; string CITY = context.Request.Params["CITY"]; string NAME = context.Request.Params["NAME"]; string CYCLE = context.Request.Params["CYCLE"]; string WORK_DAY = context.Request.Params["WORK_DAY"]; string S_TIME = context.Request.Params["S_TIME"]; string E_TIME = context.Request.Params["E_TIME"]; string USERS_UID = context.Request.Params["USERS_UID"]; string USERS_NAME = context.Request.Params["USERS_NAME"]; string SPOTS = context.Request.Params["SPOTS"]; string SPOT_IDS = context.Request.Params["SPOT_IDS"]; string SPOT_NAMES = context.Request.Params["SPOT_NAMES"]; string STATE = context.Request.Params["STATE"]; //巡查计划表 FangYar.Model.FIRE_PATROL_PLAN model = new Model.FIRE_PATROL_PLAN(); model.ID = ID; model.NAME = NAME; model.CYCLE = CYCLE; model.WORK_DAY = WORK_DAY; model.S_TIME = S_TIME; model.E_TIME = E_TIME; model.USERS_UID = USERS_UID; model.USERS_NAME = USERS_NAME; model.SPOTS = SPOTS; model.SPOT_IDS = SPOT_IDS; model.SPOT_NAMES = SPOT_NAMES; model.ORG_ID = orgId; model.CITY = CITY; model.STATE = STATE; model.U_PER = USER_ID; if (bll.Update(model)) { msg = "修改成功!"; code = 1; } else { msg = "修改失败!"; } } catch { msg = "修改失败!"; } returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}"; return returnstr; } //删除巡查计划 private string DelPlan(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string PlanList = context.Request.Params["PlanList"]; string[] PlanArray = PlanList.Split(','); string PlanListString = ""; for (int i = 0; i < PlanArray.Length; i++) { if (i == 0) { PlanListString = "'" + PlanArray[i] + "'"; } else { PlanListString += ",'" + PlanArray[i] + "'"; } } if (bll.DeleteList(PlanListString)) { msg = "删除成功!"; code = 1; } else { msg = "删除失败!"; } } catch { msg = "删除失败!"; } returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}"; return returnstr; } public bool IsReusable { get { return false; } } } }