using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace FangYar.WebUI.ashx { /// /// ZYCameraHandler 的摘要说明 /// public class OAMeetingHandler : IHttpHandler { BLL.OA.OA_MEETING_MEMO bLL = new BLL.OA.OA_MEETING_MEMO(); public void ProcessRequest(HttpContext context) { 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; case "AppGetList": returnstr = AppGetList(context); break; case "AppGetModel": returnstr = AppGetModel(context); break; } context.Response.Write(returnstr); } //查询 private string List(HttpContext context) { string returnstr = ""; try { string OrgId = context.Request.Params["OrgId"]; string keyword = context.Request.Params["keywords"]; string type = context.Request.Params["type"]; 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 = "1=1"; if (!string.IsNullOrEmpty(OrgId)) { where += " and ORG_ID = '" + OrgId + "'"; } if (!string.IsNullOrEmpty(keyword)) { if (where != null) { where += " and "; } where += "( MSUBJECT like '%" + keyword + "%' or mADDR like '%" + keyword + "%')"; } returnstr = "{\"code\":0,\"msg\":\"\","; int count = 0; List list = bLL.PageList(pageIndex, pageSize, where, " mdate desc", ref count); returnstr += "\"count\":" + count + ",\"data\":"; if (count == 0) { returnstr += "[]"; } else { returnstr += FangYar.Common.JsonHelper.ToJson(list); } returnstr += "}"; } catch (Exception ex) { returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]"; } return returnstr; } //添加 private string Add(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string id = Guid.NewGuid().ToString("N");// string ORG_ID = context.Request.Params["ORG_ID"];// string mno = context.Request.Params["mno"];// string msub = context.Request.Params["msub"];// string mzc = context.Request.Params["mzc"]; // string mdate = context.Request.Params["mdate"]; // string mtype = context.Request.Params["mtype"]; // string maddr = context.Request.Params["maddr"];// string musers = context.Request.Params["musers"];// string mcontents = context.Request.Params["mcontents"];// string mbz = context.Request.Params["mbz"];// string mfj = context.Request.Params["mfj"];// FangYar.Model.OA_MEETING_MEMO model = new Model.OA_MEETING_MEMO(); model.ID = id; model.MCODE = mno; model.MCONTENT = mcontents; if (!string.IsNullOrEmpty(mdate)) { model.MDATE = DateTime.Parse(mdate); } model.MENCLOSURE = mfj; model.MHOST = mzc; model.MTYPE = mtype; model.MPARTICIPANT = musers; model.MADDR = maddr; model.MREMARKS = mbz; model.MSUBJECT = msub; model.ORG_ID = ORG_ID; model.A_PER = ""; model.A_TIME = DateTime.Now; if (bLL.Add(model)) { msg = "添加成功!"; code = 1; } else { msg = "添加失败!"; } } catch (Exception e) { msg = "添加失败!"; } returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}"; return returnstr; } //修改 private string Edit(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string ID = context.Request.Params["ID"];// string ORG_ID = context.Request.Params["ORG_ID"];// string mno = context.Request.Params["mno"];// string msub = context.Request.Params["msub"];// string mzc = context.Request.Params["mzc"]; // string mdate = context.Request.Params["mdate"]; // string mtype = context.Request.Params["mtype"]; // string maddr = context.Request.Params["maddr"];// string musers = context.Request.Params["musers"];// string mcontents = context.Request.Params["mcontents"];// string mbz = context.Request.Params["mbz"];// string mfj = context.Request.Params["mfj"];// // FangYar.Model.OA_MEETING_MEMO model = bLL.GetModel(ID); if (model != null) { model.MCODE = mno; model.MCONTENT = mcontents; if (!string.IsNullOrEmpty(mdate)) { model.MDATE = DateTime.Parse(mdate); } model.MADDR = maddr; model.MENCLOSURE = mfj; model.MHOST = mzc; model.MTYPE = mtype; model.MPARTICIPANT = musers; model.MREMARKS = mbz; model.MSUBJECT = msub; model.ORG_ID = ORG_ID; if (bLL.Update(model)) { msg = "修改成功!"; code = 1; } else { msg = "修改失败!"; } } else { msg = "记录不存在!"; } } catch (Exception e) { msg = "修改失败!"; } returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}"; return returnstr; } //删除 private string Del(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string EmpList = context.Request.Params["cameraList"]; string[] EmpArray = EmpList.Split(','); string EmpListString = ""; for (int i = 0; i < EmpArray.Length; i++) { if (i == 0) { EmpListString = "'" + EmpArray[i] + "'"; } else { EmpListString += ",'" + EmpArray[i] + "'"; } } string where = " ID in (" + EmpListString + ")"; if (bLL.DeleteWhere(where)) { msg = "删除成功!"; code = 1; } else { msg = "删除失败!"; } } catch { msg = "删除失败!"; } returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}"; return returnstr; } //查询 private string AppGetList(HttpContext context) { string returnstr = ""; try { string OrgId = context.Request.Params["OrgId"]; string keyword = context.Request.Params["keywords"]; string type = context.Request.Params["type"]; 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 = "1=1"; if (!string.IsNullOrEmpty(OrgId)) { where += " and ORG_ID = '" + OrgId + "'"; } if (!string.IsNullOrEmpty(keyword)) { if (where != null) { where += " and "; } where += "( mtitle like '%" + keyword + "%' or mADDR like '%" + keyword + "%')"; } returnstr = "{\"code\":0,\"msg\":\"\","; int count = 0; List list = bLL.PageList(pageIndex, pageSize, where, " mdate desc", ref count); returnstr += "\"count\":" + count + ",\"data\":"; if (count == 0) { returnstr += "[]"; } else { returnstr += FangYar.Common.JsonHelper.ToJson(list); } returnstr += "}"; } catch (Exception ex) { returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]"; } return returnstr; } //查询 private string AppGetModel(HttpContext context) { string returnstr = ""; try { string id = context.Request.Params["id"]; returnstr = "{\"code\":0,\"msg\":\"\","; returnstr += "\"count\": 1,\"data\":"; FangYar.Model.OA_MEETING_MEMO model = bLL.GetModel(id); returnstr += FangYar.Common.JsonHelper.ToJson(model); returnstr += "}"; } catch { returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]"; } return returnstr; } public bool IsReusable { get { return false; } } } }