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 ZYOaDutyManageHandler : IHttpHandler { private FangYar.BLL.OA.OA_DUTYMANAGE bll = new FangYar.BLL.OA.OA_DUTYMANAGE(); public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string action = context.Request.Params["Action"]; string returnstr = ""; switch (action) { case "ListByOrgId": returnstr = GetDutyManageListByOrgId(context); break; case "ListByDutyDate": returnstr = GetDutyManageListByDutyDate(context); break; case "Add": returnstr = AddDutyManage(context); break; case "Edit": returnstr = EditDutyManage(context); break; case "Del": returnstr = DelDutyManage(context); break; case "GetTree": returnstr = GetTree(context); break; case "getStaDutyHoliday": returnstr = getStaDutyHoliday(context); break; case "htmlToWord": HtmlToWord(context); break; } context.Response.Write(returnstr); } //根据机构ID查询 private string GetDutyManageListByOrgId(HttpContext context) { string returnstr = ""; try { string OrgId = context.Request.Params["OrgId"]; 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 = ""; if (!string.IsNullOrEmpty(OrgId)) { where = " ORG_ID ='" + OrgId + "' GROUP BY DUTY_DATE "; } else { return "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}"; } DataTable list = bll.GetDutyManageListByOrgId(pageIndex, pageSize, OrgId); returnstr = "{\"code\":0,\"msg\":\"\","; returnstr += "\"count\":" + list.Rows.Count + ",\"data\":"; returnstr += FangYar.Common.JsonHelper.ToJson(list); returnstr += "}"; } catch (Exception e) { returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}"; } return returnstr; } //根据值班日期查询 private string GetDutyManageListByDutyDate(HttpContext context) { string returnstr = ""; try { string DutyDate = context.Request.Params["DutyDate"]; string OrgId = context.Request.Params["OrgId"]; string where = ""; if (!string.IsNullOrEmpty(DutyDate)) { where = " DUTY_DATE ='" + DutyDate + "' GROUP BY DUTY_DATE "; } else { return "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}"; } returnstr = "{\"code\":0,\"msg\":\"\",\"data\":"; { DataTable list = bll.GetDutyManageListByDutyDate(OrgId, DutyDate); returnstr += FangYar.Common.JsonHelper.ToJson(list); } returnstr += "}"; } catch { returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}"; } return returnstr; } //添加值班管理 private string AddDutyManage(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string arrStr = context.Request.Params["arrStr"]; //string ID = Guid.NewGuid().ToString("N"); ////判断是工作日还是节假期周末 FangYar.BLL.OA.OA_HOLIDAY bll_d = new BLL.OA.OA_HOLIDAY(); List list = FangYar.Common.JsonHelper.FromJSON>(arrStr); int addCount = 0; for (int i = 0; i < list.Count; i++) { var model = list[i]; model.ID = Guid.NewGuid().ToString("N"); List itemList = bll_d.GetModelList(" HDATE = '" + model.DUTY_DATE + "'"); if (itemList.Count > 0) { model.EXTENDCODE3 = itemList[0].REST; } else { model.EXTENDCODE3 = "-1"; } if (bll.AddTran(model)) { addCount++; } } if (addCount == list.Count) { msg = "添加成功!"; code = 1; } else { msg = "部分添加成功!"; } //string EMP_ID = context.Request.Params["EMP_ID"]; //string EMP_NAME = context.Request.Params["EMP_NAME"]; //string EMP_PHONE = context.Request.Params["EMP_PHONE"]; //string PROF = context.Request.Params["PROF"]; //string DUTY_DATE = context.Request.Params["DUTY_DATE"]; //string EXTENDCODE1 = context.Request.Params["EXTENDCODE1"]; //string EXTENDCODE2 = context.Request.Params["EXTENDCODE2"]; //string EXTENDCODE4 = context.Request.Params["EXTENDCODE4"]; //string EXTENDCODE5 = context.Request.Params["EXTENDCODE5"]; //string ORG_ID = context.Request.Params["ORG_ID"]; //string SORT = context.Request.Params["SORT"]; //string taskType = context.Request.Params["taskType"]; //string PHOTO = context.Request.Params["PHOTO"]; ////值班管理表 //FangYar.Model.OA.OA_DUTYMANAGE model = new FangYar.Model.OA.OA_DUTYMANAGE(); //model.ID = ID; //model.EMP_ID = EMP_ID; //model.EMP_NAME = EMP_NAME; //model.EMP_PHONE = EMP_PHONE; //model.PROF = PROF; //model.DUTY_DATE = DUTY_DATE; //string time1 = ""; //string time2 = ""; //if (!string.IsNullOrEmpty(DUTY_DATE)) //{ // DateTime time = Convert.ToDateTime(DUTY_DATE); // time1 = time.ToString("yyyy-MM-dd HH:mm:ss"); // time2 = time.AddDays(1).AddSeconds(-1).ToString("yyyy-MM-dd HH:mm:ss"); //} //model.EXTENDCODE1 = time1; //model.EXTENDCODE2 = time2; //model.EXTENDCODE4 = EXTENDCODE4; //model.EXTENDCODE5 = EXTENDCODE5; //model.ORG_ID = ORG_ID; ////model.TASKTYPE = taskType; //model.PHOTO = PHOTO; //if (!string.IsNullOrEmpty(SORT)) //{ // model.SORT = int.Parse(SORT); //} ////判断是工作日还是节假期周末 //FangYar.BLL.OA.OA_HOLIDAY bll_d = new BLL.OA.OA_HOLIDAY(); //List list = bll_d.GetModelList(" HDATE = '" + DUTY_DATE + "'"); //if (list.Count > 0) //{ // model.EXTENDCODE3 = list[0].REST; //} //else //{ // model.EXTENDCODE3 = "-1"; //} //if (bll.AddTran(model)) //{ // msg = "添加成功!"; // code = 1; // //app推送消息 // try // { // FangYar.FYMQTT.MessagePush mp = new FYMQTT.MessagePush(); // mp.AloneMsgPush(EMP_ID, "值班管理", "您有一条值班任务,日期:" + DUTY_DATE + "!"); // } // catch (Exception e) { } //} //else { msg = "添加失败!"; } } catch { msg = "添加失败"; } returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}"; return returnstr; } //修改值班管理 private string EditDutyManage(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string ID = context.Request.Params["ID"]; string EMP_ID = context.Request.Params["EMP_ID"]; string EMP_NAME = context.Request.Params["EMP_NAME"]; string EMP_PHONE = context.Request.Params["EMP_PHONE"]; string PROF = context.Request.Params["PROF"]; string DUTY_DATE = context.Request.Params["DUTY_DATE"]; string EXTENDCODE1 = context.Request.Params["EXTENDCODE1"]; string EXTENDCODE2 = context.Request.Params["EXTENDCODE2"]; string EXTENDCODE3 = context.Request.Params["EXTENDCODE3"]; string EXTENDCODE4 = context.Request.Params["EXTENDCODE4"]; string EXTENDCODE5 = context.Request.Params["EXTENDCODE5"]; string ORG_ID = context.Request.Params["ORG_ID"]; string SORT = context.Request.Params["SORT"]; //string taskType = context.Request.Params["taskType"]; //值班管理表 FangYar.Model.OA.OA_DUTYMANAGE model = new FangYar.Model.OA.OA_DUTYMANAGE(); model.ID = ID; model.EMP_ID = EMP_ID; model.EMP_NAME = EMP_NAME; model.EMP_PHONE = EMP_PHONE; model.PROF = PROF; model.DUTY_DATE = DUTY_DATE; model.EXTENDCODE1 = EXTENDCODE1; model.EXTENDCODE2 = EXTENDCODE2; model.EXTENDCODE3 = EXTENDCODE3; model.EXTENDCODE4 = EXTENDCODE4; model.EXTENDCODE5 = EXTENDCODE5; model.ORG_ID = ORG_ID; //model.TASKTYPE = taskType; if (!string.IsNullOrEmpty(SORT)) { model.SORT = int.Parse(SORT); } if (bll.Update(model)) { msg = "修改成功!"; code = 1; } else { msg = "修改失败!"; } } catch { msg = "修改失败!"; } returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}"; return returnstr; } //删除 private string DelDutyManage(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 { msg = "删除失败!"; } returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}"; return returnstr; } //机构人员Tree private string GetTree(HttpContext context) { string returnstr = ""; try { string orgId = context.Request.Params["OrgId"]; returnstr = "{\"code\":0,\"msg\":\"\",\"data\":"; DataTable data = bll.GetTree(orgId); returnstr += Common.JsonHelper.ToJson(data); returnstr += "}"; } catch (Exception e) { returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}"; } return returnstr; } //统计 private string getStaDutyHoliday(HttpContext context) { string returnstr = ""; try { string OrgId = context.Request.Params["OrgId"]; string STime = (context.Request.Params["STime"] + "").Trim(); string ETime = (context.Request.Params["ETime"] + "").Trim(); ; string whereStr = ""; if (!string.IsNullOrEmpty(OrgId)) { whereStr = " ORG_ID ='" + OrgId + "' "; } if (!string.IsNullOrEmpty(STime) && !string.IsNullOrEmpty(ETime)) { //whereStr += " and date_format(duty_date ,'%Y-%m-%d')>= date_format('" + STime + "','%Y-%m') and date_format(duty_date ,'%Y-%m-%d')< add_months(date_format('" + ETime + "', '%Y-%m'), 1)"; whereStr += " and date(duty_date) between '" + STime + "-01' and '" + ETime + "-01' "; } else { return "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}"; } returnstr = "{\"code\":0,\"msg\":\"\",\"data\":"; { DataTable dt = bll.getStaDutyHoliday(whereStr); returnstr += FangYar.Common.JsonHelper.ToJson(dt); } returnstr += "}"; } catch (Exception e) { returnstr = "{\"code\":0,\"msg\":\"" + e.Message + "\",\"count\":0,\"data\":[]}"; } return returnstr; } private void HtmlToWord(HttpContext context) { try { string OrgId = context.Request.Params["OrgId"]; string STime = (context.Request.Params["STime"] + "").Trim(); string ETime = (context.Request.Params["ETime"] + "").Trim(); ; string whereStr = ""; if (!string.IsNullOrEmpty(OrgId)) { whereStr = " ORG_ID ='" + OrgId + "' "; } if (!string.IsNullOrEmpty(STime) && !string.IsNullOrEmpty(ETime)) { //whereStr += " and date_format(duty_date ,'%Y-%m-%d')>= date_format('" + STime + "','%Y-%m') and date_format(duty_date ,'%Y-%m-%d')< add_months(date_format('" + ETime + "', '%Y-%m'), 1)"; whereStr += " and date(duty_date) between '" + STime + "-01' and '" + ETime + "-01' "; } DataTable dt = bll.getStaDutyHoliday(whereStr); if (dt.Rows.Count == 0) { } else { dt.Columns.Remove("EMP_ID"); dt.Columns.Add("TOATLE", Type.GetType("System.Int32")); for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["TOATLE"] = Convert.ToInt32(dt.Rows[i]["WEEKDAYS"].ToString()) + Convert.ToInt32(dt.Rows[i]["WEEKEND"].ToString()) + Convert.ToInt32(dt.Rows[i]["HOLIDAY"].ToString()); } System.Collections.Generic.Dictionary cellHeaders = new System.Collections.Generic.Dictionary(); cellHeaders.Add("EMP_NAME", "姓名"); cellHeaders.Add("WEEKDAYS", "工作日"); cellHeaders.Add("WEEKEND", "周末"); cellHeaders.Add("HOLIDAY", "节假日"); cellHeaders.Add("TOATLE", "总计"); FangYar.Common.NPOIExcelHelper.ExportByWeb(dt, null, cellHeaders, DateTime.Now.ToString("yyyyMMddHHmmss") + "值班人员统计数据表.xls"); } } catch (Exception e) { } } //private FangYar.BLL.OA.OA_DUTYMANAGE bll = new FangYar.BLL.OA.OA_DUTYMANAGE(); //public void ProcessRequest(HttpContext context) //{ // context.Response.ContentType = "text/plain"; // string action = context.Request.Params["Action"]; // string returnstr = ""; // switch (action) // { // case "ListByOrgId": // returnstr = GetDutyManageListByOrgId(context); // break; // case "ListByDutyDate": // returnstr = GetDutyManageListByDutyDate(context); // break; // case "Add": // returnstr = AddDutyManage(context); // break; // case "Edit": // returnstr = EditDutyManage(context); // break; // case "Del": // returnstr = DelDutyManage(context); // break; // case "GetTree": // returnstr = GetTree(context); // break; // } // context.Response.Write(returnstr); //} ////根据机构ID查询 //private string GetDutyManageListByOrgId(HttpContext context) //{ // string returnstr = ""; // try // { // string OrgId = context.Request.Params["OrgId"]; // 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 = ""; // if (!string.IsNullOrEmpty(OrgId)) // { // where = " ORG_ID ='" + OrgId + "' GROUP BY DUTY_DATE "; // } // else // { // return "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}"; // } // DataTable list = bll.GetDutyManageListByOrgId(pageIndex, pageSize, OrgId); // returnstr = "{\"code\":0,\"msg\":\"\","; // returnstr += "\"count\":" + list.Rows.Count + ",\"data\":"; // returnstr += FangYar.Common.JsonHelper.ToJson(list); // returnstr += "}"; // } // catch (Exception e) // { // returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}"; // } // return returnstr; //} ////根据值班日期查询 //private string GetDutyManageListByDutyDate(HttpContext context) //{ // string returnstr = ""; // try // { // string DutyDate = context.Request.Params["DutyDate"]; // string where = ""; // if (!string.IsNullOrEmpty(DutyDate)) // { // where = " DUTY_DATE ='" + DutyDate + "' GROUP BY DUTY_DATE "; // } // else // { // return "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}"; // } // returnstr = "{\"code\":0,\"msg\":\"\",\"data\":"; // { // DataTable list = bll.GetDutyManageListByDutyDate(DutyDate); // returnstr += FangYar.Common.JsonHelper.ToJson(list); // } // returnstr += "}"; // } // catch // { // returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}"; // } // return returnstr; //} ////添加值班管理 //private string AddDutyManage(HttpContext context) //{ // string returnstr = ""; // int code = -1; // string msg = ""; // try // { // string ID = Guid.NewGuid().ToString("N"); // string EMP_ID = context.Request.Params["EMP_ID"]; // string EMP_NAME = context.Request.Params["EMP_NAME"]; // string EMP_PHONE = context.Request.Params["EMP_PHONE"]; // string PROF = context.Request.Params["PROF"]; // string DUTY_DATE = context.Request.Params["DUTY_DATE"]; // string EXTENDCODE1 = context.Request.Params["EXTENDCODE1"]; // string EXTENDCODE2 = context.Request.Params["EXTENDCODE2"]; // string EXTENDCODE3 = context.Request.Params["EXTENDCODE3"]; // string EXTENDCODE4 = context.Request.Params["EXTENDCODE4"]; // string EXTENDCODE5 = context.Request.Params["EXTENDCODE5"]; // string ORG_ID = context.Request.Params["ORG_ID"]; // string SORT = context.Request.Params["SORT"]; // string taskType = context.Request.Params["taskType"]; // string PHOTO = context.Request.Params["PHOTO"]; // //值班管理表 // FangYar.Model.OA.OA_DUTYMANAGE model = new FangYar.Model.OA.OA_DUTYMANAGE(); // model.ID = ID; // model.EMP_ID = EMP_ID; // model.EMP_NAME = EMP_NAME; // model.EMP_PHONE = EMP_PHONE; // model.PROF = PROF; // model.DUTY_DATE = DUTY_DATE; // string time1 = ""; // string time2 = ""; // if (!string.IsNullOrEmpty(DUTY_DATE)) // { // DateTime time = Convert.ToDateTime(DUTY_DATE); // time1 = time.ToString("yyyy-MM-dd HH:mm:ss"); // time2 = time.AddDays(2).ToString("yyyy-MM-dd HH:mm:ss"); // } // model.EXTENDCODE1 = time1; // model.EXTENDCODE2 = time2; // model.EXTENDCODE3 = EXTENDCODE3; // model.EXTENDCODE4 = EXTENDCODE4; // model.EXTENDCODE5 = EXTENDCODE5; // model.ORG_ID = ORG_ID; // model.TASKTYPE = taskType; // model.PHOTO = PHOTO; // if (!string.IsNullOrEmpty(SORT)) // { // model.SORT = int.Parse(SORT); // } // if (bll.AddTran(model)) // { // msg = "添加成功!"; // code = 1; // } // else { msg = "添加失败!"; } // } // catch // { // msg = "添加失败"; // } // returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}"; // return returnstr; //} ////修改值班管理 //private string EditDutyManage(HttpContext context) //{ // string returnstr = ""; // int code = -1; // string msg = ""; // try // { // string ID = context.Request.Params["ID"]; // string EMP_ID = context.Request.Params["EMP_ID"]; // string EMP_NAME = context.Request.Params["EMP_NAME"]; // string EMP_PHONE = context.Request.Params["EMP_PHONE"]; // string PROF = context.Request.Params["PROF"]; // string DUTY_DATE = context.Request.Params["DUTY_DATE"]; // string EXTENDCODE1 = context.Request.Params["EXTENDCODE1"]; // string EXTENDCODE2 = context.Request.Params["EXTENDCODE2"]; // string EXTENDCODE3 = context.Request.Params["EXTENDCODE3"]; // string EXTENDCODE4 = context.Request.Params["EXTENDCODE4"]; // string EXTENDCODE5 = context.Request.Params["EXTENDCODE5"]; // string ORG_ID = context.Request.Params["ORG_ID"]; // string SORT = context.Request.Params["SORT"]; // string taskType = context.Request.Params["taskType"]; // //值班管理表 // FangYar.Model.OA.OA_DUTYMANAGE model = new FangYar.Model.OA.OA_DUTYMANAGE(); // model.ID = ID; // model.EMP_ID = EMP_ID; // model.EMP_NAME = EMP_NAME; // model.EMP_PHONE = EMP_PHONE; // model.PROF = PROF; // model.DUTY_DATE = DUTY_DATE; // model.EXTENDCODE1 = EXTENDCODE1; // model.EXTENDCODE2 = EXTENDCODE2; // model.EXTENDCODE3 = EXTENDCODE3; // model.EXTENDCODE4 = EXTENDCODE4; // model.EXTENDCODE5 = EXTENDCODE5; // model.ORG_ID = ORG_ID; // model.TASKTYPE = taskType; // if (!string.IsNullOrEmpty(SORT)) // { // model.SORT = int.Parse(SORT); // } // if (bll.Update(model)) // { // msg = "修改成功!"; // code = 1; // } // else { msg = "修改失败!"; } // } // catch // { // msg = "修改失败!"; // } // returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}"; // return returnstr; //} ////删除 //private string DelDutyManage(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 // { // msg = "删除失败!"; // } // returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}"; // return returnstr; //} ////机构人员Tree //private string GetTree(HttpContext context) //{ // string returnstr = ""; // try // { // string orgId = context.Request.Params["OrgId"]; // returnstr = "{\"code\":0,\"msg\":\"\",\"data\":"; // DataTable data = bll.GetTree(orgId); // returnstr += Common.JsonHelper.ToJson(data); // returnstr += "}"; // } // catch (Exception e) // { // returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}"; // } // return returnstr; //} public bool IsReusable { get { return false; } } } }