using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace FangYar.WebUI.ashx { /// /// SysSocietyHandler 的摘要说明 /// public class SysSocietyHandler : IHttpHandler { FangYar.BLL.TBL.SysSocietyBLL bll = new BLL.TBL.SysSocietyBLL(); public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string action = context.Request.Params["Action"]; string returnstr = ""; switch (action) { case "List": returnstr = GetModelList(context); break; case "Del": returnstr = DelModel(context); break; case "Add": returnstr = AddModel(context); break; case "Edit": returnstr = EditModel(context); break; } context.Response.Write(returnstr); } //查询 private string GetModelList(HttpContext context) { string returnstr = ""; try { string keywords = context.Request.Params["keywords"]; string limit = context.Request.Params["limit"]; string page = context.Request.Params["page"]; int pageIndex = 1; int pageSize = 10; if (!string.IsNullOrEmpty(limit)) { pageIndex = int.Parse(page); } if (!string.IsNullOrEmpty(limit)) { pageSize = int.Parse(limit); } string where = null; if (!string.IsNullOrEmpty(keywords)) { where = "ORG_ID like '" + keywords + "' or SOC_NAME like '" + keywords + "' "; } returnstr = "{\"code\":0,\"msg\":\"\","; int count = bll.Count(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 { returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]"; } return returnstr; } //删除 private string DelModel(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string UIDList = context.Request.Params["UIDList"]; UIDList = UIDList.Replace(",", "','"); if (bll.Delete(UIDList)) { msg = "删除成功!"; code = 1; } else { msg = "删除失败!"; } } catch { msg = "删除失败!"; } returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}"; return returnstr; } //添加 private string AddModel(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string OrgID = context.Request.Params["OrgID"]; string AreaID = context.Request.Params["AreaID"]; string AreaIDS = context.Request.Params["AreaIDS"]; string SocLevle = context.Request.Params["SocLevle"]; string SocName = context.Request.Params["SocName"]; string IsDel = context.Request.Params["IsDel"]; string SocProp = context.Request.Params["SocProp"]; string SocClass = context.Request.Params["SocClass"]; string SocIndustry = context.Request.Params["SocIndustry"]; string SocCode = context.Request.Params["SocCode"]; string SocIsRisk = context.Request.Params["SocIsRisk"]; string SocAddr = context.Request.Params["SocAddr"]; string SocLoc = context.Request.Params["SocLoc"]; string SocAcreage = context.Request.Params["SocAcreage"]; string SocPcount = context.Request.Params["SocPcount"]; string SocCHS1 = context.Request.Params["SocCHS1"]; string SocCHSTEL1 = context.Request.Params["SocCHSTEL1"]; string SocCHS2 = context.Request.Params["SocCHS2"]; string SocCHSTEL2 = context.Request.Params["SocCHSTEL2"]; string SocInsurer = context.Request.Params["SocInsurer"]; string SocExts = context.Request.Params["SocExts"]; if (string.IsNullOrEmpty(SocName)) { msg = "单位名称不能为空!"; } else { FangYar.Model.TBL.TBL_SYS_SOCIETY_Model model = new Model.TBL.TBL_SYS_SOCIETY_Model(); model.ORG_ID = OrgID; model.AREA_ID = AreaID; model.AREA_IDS = AreaIDS; model.SOC_LEVLE = SocLevle; model.SOC_NAME = SocName; model.IS_DEL = IsDel; model.SOC_PROP = SocProp; model.SOC_CLASS = SocClass; model.SOC_INDUSTRY = SocIndustry; model.SOC_CODE = SocCode; model.SOC_ISRISK = SocIsRisk; model.SOC_ADDR = SocAddr; model.SOC_LOC = SocLoc; model.SOC_ACREAGE = SocAcreage; model.SOC_PCOUNT = SocPcount; model.SOC_CHS1 = SocCHS1; model.SOC_CHSTEL1 = SocCHSTEL1; model.SOC_CHS2 = SocCHS2; model.SOC_CHSTEL2 = SocCHSTEL2; model.SOC_INSURER = SocInsurer; model.SOC_EXTS = SocExts; if (bll.Add(model)) { msg = "添加成功!"; code = 1; } else { msg = "添加失败!"; } } } catch { msg = "添加失败!"; } returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}"; return returnstr; } private string EditModel(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string ID = context.Request.Params["ID"]; string OrgID = context.Request.Params["OrgID"]; string AreaID = context.Request.Params["AreaID"]; string AreaIDS = context.Request.Params["AreaIDS"]; string SocLevle = context.Request.Params["SocLevle"]; string SocName = context.Request.Params["SocName"]; string IsDel = context.Request.Params["IsDel"]; string SocProp = context.Request.Params["SocProp"]; string SocClass = context.Request.Params["SocClass"]; string SocIndustry = context.Request.Params["SocIndustry"]; string SocCode = context.Request.Params["SocCode"]; string SocIsRisk = context.Request.Params["SocIsRisk"]; string SocAddr = context.Request.Params["SocAddr"]; string SocLoc = context.Request.Params["SocLoc"]; string SocAcreage = context.Request.Params["SocAcreage"]; string SocPcount = context.Request.Params["SocPcount"]; string SocCHS1 = context.Request.Params["SocCHS1"]; string SocCHSTEL1 = context.Request.Params["SocCHSTEL1"]; string SocCHS2 = context.Request.Params["SocCHS2"]; string SocCHSTEL2 = context.Request.Params["SocCHSTEL2"]; string SocInsurer = context.Request.Params["SocInsurer"]; string SocExts = context.Request.Params["SocExts"]; if (string.IsNullOrEmpty(SocName)) { msg = "单位名称不能为空!"; } else { FangYar.Model.TBL.TBL_SYS_SOCIETY_Model model = bll.GetModelByID(ID); if (model == null) { msg = "用户记录不存在!"; } else { model.ORG_ID = OrgID; model.AREA_ID = AreaID; model.AREA_IDS = AreaIDS; model.SOC_LEVLE = SocLevle; model.SOC_NAME = SocName; model.IS_DEL = IsDel; model.SOC_PROP = SocProp; model.SOC_CLASS = SocClass; model.SOC_INDUSTRY = SocIndustry; model.SOC_CODE = SocCode; model.SOC_ISRISK = SocIsRisk; model.SOC_ADDR = SocAddr; model.SOC_LOC = SocLoc; model.SOC_ACREAGE = SocAcreage; model.SOC_PCOUNT = SocPcount; model.SOC_CHS1 = SocCHS1; model.SOC_CHSTEL1 = SocCHSTEL1; model.SOC_CHS2 = SocCHS2; model.SOC_CHSTEL2 = SocCHSTEL2; model.SOC_INSURER = SocInsurer; if (bll.Edit(model)) { msg = "修改成功!"; code = 1; } else { msg = "修改失败!"; } } } } catch { msg = "修改失败!"; } returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}"; return returnstr; } public bool IsReusable { get { return false; } } } }