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 OaHolidayHandler : IHttpHandler { private FangYar.BLL.OA.OA_HOLIDAY bll = new FangYar.BLL.OA.OA_HOLIDAY(); 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 = List(context); break; case "Add": returnstr = Add(context); break; case "Edit": returnstr = Edit(context); break; case "Del": returnstr = Del(context); break; } context.Response.Write(returnstr); } //根据值班日期查询 private string List(HttpContext context) { string returnstr = ""; string whereStr = ""; try { string DutyDate = context.Request.Params["DutyDate"]; string searchTime = context.Request.Params["searchTime"]; string searchRest = context.Request.Params["searchRest"]; whereStr = " HDATE like '%" + searchTime + "%' "; if (!string.IsNullOrEmpty(searchRest)) { whereStr += " and REST = '" + searchRest + "'"; } whereStr += " order by HDATE asc "; returnstr = "{\"code\":0,\"msg\":\"\",\"data\":"; DataTable list = bll.GetList(whereStr).Tables[0]; 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 Add(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string ID = Guid.NewGuid().ToString("N"); string hdate = context.Request.Params["hdate"]; string name = context.Request.Params["name"]; string rest = context.Request.Params["rest"]; FangYar.Model.OA.OA_HOLIDAY model = new FangYar.Model.OA.OA_HOLIDAY(); model.ID = ID; model.HDATE = hdate; model.NAME = name; model.REST = rest; model.HOLIDAY = "true"; string whereStr = " HDATE='" + hdate + "'"; DataTable dt = bll.GetList(whereStr).Tables[0]; if (dt.Rows.Count > 0) { msg = "添加失败,请在列表中修改!"; } else { 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 Edit(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string ID = context.Request.Params["ID"]; string hdate = context.Request.Params["hdate"]; string name = context.Request.Params["name"]; string rest = context.Request.Params["rest"]; FangYar.Model.OA.OA_HOLIDAY model = new FangYar.Model.OA.OA_HOLIDAY(); model.ID = ID; model.HDATE = hdate; model.NAME = name; model.REST = rest; if (bll.Update(model)) { msg = "编辑成功!"; code = 1; } else { msg = "编辑失败!"; } } catch (Exception e) { msg = e.Message; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "节假日和周末表操作请求", "修改异常:" + e); } returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Update, "节假日和周末表操作请求", "修改"); return returnstr; } //删除 private string Del(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string ID = context.Request.Params["ID"]; if (bll.Delete(ID)) { msg = "删除成功!"; code = 1; } else { msg = "删除失败!"; } } catch (Exception e) { msg = e.Message; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "节假日和周末表操作请求", "删除异常:" + e); } returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}"; // 记录操作日志 BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Delete, "节假日和周末表操作请求", "删除"); return returnstr; } public bool IsReusable { get { return false; } } } }