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 FireExpertHandler : IHttpHandler { private FangYar.BLL.FIRE.FIRE_EXPERT bll = new FangYar.BLL.FIRE.FIRE_EXPERT(); public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string action = context.Request.Params["Action"]; string returnstr = ""; switch (action) { case "ExpertList": returnstr = GetExpertList(context); break; case "Add": returnstr = AddExpert(context); break; case "Edit": returnstr = EditExpert(context); break; case "Del": returnstr = DelExpert(context); break; } context.Response.Write(returnstr); } //查询 private string GetExpertList(HttpContext context) { string returnstr = ""; try { string OrgId = context.Request.Params["OrgId"]; string keyword = context.Request.Params["keywords"]; string FIELD = context.Request.Params["FIELD"]; 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; if (!string.IsNullOrEmpty(OrgId)) { where = " ORG_ID = '" + OrgId + "' "; } if (!string.IsNullOrEmpty(FIELD)) { if (where != null) { where += " and "; } where += " FIELD = '" + FIELD + "' "; } if (!string.IsNullOrEmpty(keyword)) { if (where != null) { where += " and "; } where += "( name like '%" + keyword + "%' or UNIT_NAME like '%" + keyword + "%' or UNIT_ADDR 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, ""); returnstr += FangYar.Common.JsonHelper.ToJson(list); } returnstr += "}"; } catch { returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]"; } return returnstr; } //添加专家 private string AddExpert(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string USER_ID = context.Request.Params["USER_ID"]; string ID = Guid.NewGuid().ToString("N"); string NAME = context.Request.Params["NAME"]; string FIELD = context.Request.Params["FIELD"]; string PROF = context.Request.Params["PROF"]; string UNIT_NAME = context.Request.Params["UNIT_NAME"]; string UNIT_ADDR = context.Request.Params["UNIT_ADDR"]; string M_PHONE = context.Request.Params["M_PHONE"]; string F_PHONE = context.Request.Params["F_PHONE"]; string ORG_ID = context.Request.Params["ORG_ID"]; //专家信息表 FangYar.Model.FIRE.FIRE_EXPERT model = new Model.FIRE.FIRE_EXPERT(); model.ID = ID; model.NAME = NAME; model.FIELD = FIELD; model.PROF = PROF; model.UNIT_NAME = UNIT_NAME; model.UNIT_ADDR = UNIT_ADDR; model.M_PHONE = M_PHONE; model.F_PHONE = F_PHONE; model.ORG_ID = ORG_ID; model.A_PER = USER_ID; if (bll.Add(model)) { msg = "添加成功!"; code = 1; } else { msg = "添加失败!"; } } catch { msg = "添加失败"; } returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}"; return returnstr; } //修改专家 private string EditExpert(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string USER_ID = context.Request.Params["USER_ID"]; string ID = context.Request.Params["ID"]; string NAME = context.Request.Params["NAME"]; string FIELD = context.Request.Params["FIELD"]; string PROF = context.Request.Params["PROF"]; string UNIT_NAME = context.Request.Params["UNIT_NAME"]; string UNIT_ADDR = context.Request.Params["UNIT_ADDR"]; string M_PHONE = context.Request.Params["M_PHONE"]; string F_PHONE = context.Request.Params["F_PHONE"]; string ORG_ID = context.Request.Params["ORG_ID"]; //专家信息表 FangYar.Model.FIRE.FIRE_EXPERT model = new Model.FIRE.FIRE_EXPERT(); model.ID = ID; model.NAME = NAME; model.FIELD = FIELD; model.PROF = PROF; model.UNIT_NAME = UNIT_NAME; model.UNIT_ADDR = UNIT_ADDR; model.M_PHONE = M_PHONE; model.F_PHONE = F_PHONE; model.ORG_ID = ORG_ID; 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 DelExpert(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string ExpertList = context.Request.Params["ExpertList"]; string[] ExpertArray = ExpertList.Split(','); string ExpertListString = ""; for (int i = 0; i < ExpertArray.Length; i++) { if (i == 0) { ExpertListString = "'" + ExpertArray[i] + "'"; } else { ExpertListString += ",'" + ExpertArray[i] + "'"; } } if (bll.DeleteList(ExpertListString)) { msg = "删除成功!"; code = 1; } else { msg = "删除失败!"; } } catch { msg = "删除失败!"; } returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}"; return returnstr; } public bool IsReusable { get { return false; } } } }