using System; using System.Collections.Generic; using System.Web; namespace FangYar.WebUI.ashx { /// /// OaLeaveHandler 的摘要说明 /// public class OaPatrolPlanHandler : IHttpHandler { private FangYar.BLL.OA_PATROL_PLAN bll = new FangYar.BLL.OA_PATROL_PLAN(); public void ProcessRequest(HttpContext context) { // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Other, "巡查计划操作请求", ""); 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"]; string treeID = context.Request.Params["treeID"]; 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)) { orgId = treeID; } where = "ORG_ID = '" + orgId + "' "; if (!string.IsNullOrEmpty(keyword)) { where += " and NAME like '%" + keyword + "%' or EMP_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 (Exception e) { returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "巡查计划操作请求", "查询异常:" + e); } // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "巡查计划操作请求", "查询"); 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 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 EMP_ID = context.Request.Params["EMP_ID"]; string EMP_NAME = context.Request.Params["EMP_NAME"]; string SPOT_IDS = context.Request.Params["SPOT_IDS"]; string SPOT_NAMES = context.Request.Params["SPOT_NAMES"]; string STATE = context.Request.Params["STATE"]; string SPOT_ID_S = context.Request.Params["SPOT_ID_S"]; //巡查计划表 FangYar.Model.OA_PATROL_PLAN model = new Model.OA_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.EMP_ID = EMP_ID; model.EMP_NAME = EMP_NAME; model.SPOT_IDS = SPOT_IDS; model.SPOT_NAMES = SPOT_NAMES; model.A_PER = USER_ID; model.ORG_ID = orgId; model.STATE = STATE; model.EXTENDCODE1 = SPOT_ID_S; if (bll.Add(model)) { msg = "添加成功!"; code = 1; } else { msg = "添加失败!"; } } catch (Exception e) { msg = "添加失败!"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "巡查计划操作请求", "添加巡查计划异常:" + e); } returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Add, "巡查计划操作请求", "添加巡查计划"); 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 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 EMP_ID = context.Request.Params["EMP_ID"]; string EMP_NAME = context.Request.Params["EMP_NAME"]; string SPOT_IDS = context.Request.Params["SPOT_IDS"]; string SPOT_NAMES = context.Request.Params["SPOT_NAMES"]; string STATE = context.Request.Params["STATE"]; string SPOT_ID_S = context.Request.Params["SPOT_ID_S"]; //巡查计划表 FangYar.Model.OA_PATROL_PLAN model = new Model.OA_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.EMP_ID = EMP_ID; model.EMP_NAME = EMP_NAME; model.SPOT_IDS = SPOT_IDS; model.SPOT_NAMES = SPOT_NAMES; model.ORG_ID = orgId; model.STATE = STATE; model.EXTENDCODE1 = SPOT_ID_S; model.U_PER = USER_ID; if (bll.Update(model)) { msg = "修改成功!"; code = 1; } else { msg = "修改失败!"; } } catch (Exception e) { msg = "修改失败!"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "巡查计划操作请求", "修改巡查计划异常:" + e); } returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Update, "巡查计划操作请求", "修改巡查计划"); 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 (Exception e) { msg = "删除失败!"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "巡查计划操作请求", "删除巡查计划异常:" + e); } returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Delete, "巡查计划操作请求", "删除巡查计划"); return returnstr; } public bool IsReusable { get { return false; } } } }