using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data; namespace FangYar.WebUI.ashx { /// /// ZYBuildingHandler 的摘要说明 /// public class ZYBuildingHandler : IHttpHandler { private FangYar.BLL.FIRE.FIRE_BUILDING bll = new BLL.FIRE.FIRE_BUILDING(); public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string action = context.Request.Params["Action"]; string returnstr = ""; switch (action) { case "BuildingList": 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 = ""; try { string OrgId = context.Request.Params["OrgId"]; string keyword = context.Request.Params["keywords"]; string BUILDING_STA = context.Request.Params["BUILDING_STA"]; 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); } pageIndex = pageIndex < 1 ? 1 : pageIndex; int startnum = (pageIndex - 1) * pageSize; startnum = startnum < 0 ? 0 : startnum; string where = " 1=1"; if (!string.IsNullOrEmpty(OrgId)) { where += " and ORG_ID = '" + OrgId + "'"; } if (!string.IsNullOrEmpty(keyword)) { if (where != null) { where += " and "; } where += "( BUILDING_NAME like '%" + keyword + "%' or BUILDING_ADDR like '%" + keyword + "%')"; } if (!string.IsNullOrEmpty(BUILDING_STA)) { where += " and BUILDING_STA = '" + BUILDING_STA + "'"; } returnstr = "{\"code\":0,\"msg\":\"\","; int count = bll.GetRecordCount(where); returnstr += "\"count\":" + count + ",\"data\":"; if (count == 0) { returnstr += "[]"; } else { DataTable dt = bll.GetListByPage(where, "", startnum, pageSize).Tables[0]; returnstr += FangYar.Common.JsonHelper.ToJson(dt); } returnstr += "}"; } catch { returnstr = "{\"code\":-1,\"msg\":\"error\",\"count\":0,\"data\":[]"; } return returnstr; } //添加 private string Add(HttpContext context) { string returnstr = ""; try { string USER_ID = context.Request.Params["USER_ID"]; string BUILDING_ID = context.Request.Params["BUILDING_ID"]; string BUILDING_NAME = context.Request.Params["BUILDING_NAME"]; string BUILDING_ADDR = context.Request.Params["BUILDING_ADDR"]; string BUILDING_DEC = context.Request.Params["BUILDING_DEC"]; string R_PHOTO_PATH = context.Request.Params["R_PHOTO_PATH"]; string BUILDING_LON = context.Request.Params["BUILDING_LON"]; string BUILDING_LAT = context.Request.Params["BUILDING_LAT"]; string BUILDING_STA = context.Request.Params["BUILDING_STA"]; string BUILDING_FINISH = context.Request.Params["BUILDING_FINISH"]; string BUILDING_RIGHTANDUSE = context.Request.Params["BUILDING_RIGHTANDUSE"]; string WORKING_NUM = context.Request.Params["WORKING_NUM"]; string MAX_NUM = context.Request.Params["MAX_NUM"]; string IS_CONTROLROOM = context.Request.Params["IS_CONTROLROOM"]; string CONTROLROOM_ADDR = context.Request.Params["CONTROLROOM_ADDR"]; string BUILDING_AREA = context.Request.Params["BUILDING_AREA"]; string BUILDING_HEIGHT = context.Request.Params["BUILDING_HEIGHT"]; string COVERED_AREA = context.Request.Params["COVERED_AREA"]; string STANDARD_AREA = context.Request.Params["STANDARD_AREA"]; string ABOVE_LEVEL = context.Request.Params["ABOVE_LEVEL"]; string ABOVE_AREA = context.Request.Params["ABOVE_AREA"]; string UNDER_LEVEL = context.Request.Params["UNDER_LEVEL"]; string UNDER_AREA = context.Request.Params["UNDER_AREA"]; string REFUGE_LEVEL = context.Request.Params["REFUGE_LEVEL"]; string REFUGE_AREA = context.Request.Params["REFUGE_AREA"]; string REFUGE_ADDR = context.Request.Params["REFUGE_ADDR"]; string ELEVATOR_NUM = context.Request.Params["ELEVATOR_NUM"]; string ELEVATOR_CON = context.Request.Params["ELEVATOR_CON"]; string ELEVATOR_ADDR = context.Request.Params["ELEVATOR_ADDR"]; string BUIDING_USE_CHARACTER = context.Request.Params["BUIDING_USE_CHARACTER"]; string BUIDING_CLASS = context.Request.Params["BUIDING_CLASS"]; string BUIDING_TYPE = context.Request.Params["BUIDING_TYPE"]; string BUIDING_STRUCTURE_TYPE = context.Request.Params["BUIDING_STRUCTURE_TYPE"]; string FIRE_RESISTANCE_GRADE = context.Request.Params["FIRE_RESISTANCE_GRADE"]; string FIRE_RISK = context.Request.Params["FIRE_RISK"]; string FIRE_INSTALLATION = context.Request.Params["FIRE_INSTALLATION"]; string BORDER_SITUATION = context.Request.Params["BORDER_SITUATION"]; string REMARK = context.Request.Params["REMARK"]; string ORG_ID = context.Request.Params["ORG_ID"]; string CITY = context.Request.Params["CITY"]; Model.FIRE.FIRE_BUILDING buildingmodel = new Model.FIRE.FIRE_BUILDING(); buildingmodel.ID = Guid.NewGuid().ToString("N"); buildingmodel.BUILDING_ID = BUILDING_ID; buildingmodel.BUILDING_NAME = BUILDING_NAME; buildingmodel.BUILDING_ADDR = BUILDING_ADDR; buildingmodel.BUILDING_DEC = BUILDING_DEC; buildingmodel.BUILDING_PIC = R_PHOTO_PATH; buildingmodel.BUILDING_LON = BUILDING_LON; buildingmodel.BUILDING_LAT = BUILDING_LAT; buildingmodel.BUILDING_STA = BUILDING_STA; if (!string.IsNullOrEmpty(BUILDING_FINISH)) { buildingmodel.BUILDING_FINISH = DateTime.Parse(BUILDING_FINISH); } buildingmodel.BUILDING_RIGHTANDUSE = BUILDING_RIGHTANDUSE; if (!string.IsNullOrEmpty(WORKING_NUM)) { decimal a = 0; decimal.TryParse(WORKING_NUM, out a); buildingmodel.WORKING_NUM = a; } if (!string.IsNullOrEmpty(MAX_NUM)) { decimal a = 0; decimal.TryParse(MAX_NUM, out a); buildingmodel.MAX_NUM = a; } //buildingmodel.MAX_NUM = decimal.Parse(MAX_NUM); buildingmodel.IS_CONTROLROOM = IS_CONTROLROOM; buildingmodel.CONTROLROOM_ADDR = CONTROLROOM_ADDR; if (!string.IsNullOrEmpty(BUILDING_AREA)) { decimal a = 0; decimal.TryParse(BUILDING_AREA, out a); buildingmodel.BUILDING_AREA = a; } //buildingmodel.BUILDING_AREA = decimal.Parse(BUILDING_AREA); if (!string.IsNullOrEmpty(BUILDING_HEIGHT)) { decimal a = 0; decimal.TryParse(BUILDING_HEIGHT, out a); buildingmodel.BUILDING_HEIGHT = a; } //buildingmodel.BUILDING_HEIGHT = decimal.Parse(BUILDING_HEIGHT); if (!string.IsNullOrEmpty(COVERED_AREA)) { decimal a = 0; decimal.TryParse(COVERED_AREA, out a); buildingmodel.COVERED_AREA = a; } //buildingmodel.COVERED_AREA = decimal.Parse(COVERED_AREA); if (!string.IsNullOrEmpty(STANDARD_AREA)) { decimal a = 0; decimal.TryParse(STANDARD_AREA, out a); buildingmodel.STANDARD_AREA = a; } //buildingmodel.STANDARD_AREA = decimal.Parse(STANDARD_AREA); if (!string.IsNullOrEmpty(ABOVE_LEVEL)) { decimal a = 0; decimal.TryParse(ABOVE_LEVEL, out a); buildingmodel.ABOVE_LEVEL = a; } //buildingmodel.ABOVE_LEVEL = decimal.Parse(ABOVE_LEVEL); if (!string.IsNullOrEmpty(ABOVE_AREA)) { decimal a = 0; decimal.TryParse(ABOVE_AREA, out a); buildingmodel.ABOVE_AREA = a; } //buildingmodel.ABOVE_AREA = decimal.Parse(ABOVE_AREA); if (!string.IsNullOrEmpty(UNDER_LEVEL)) { decimal a = 0; decimal.TryParse(UNDER_LEVEL, out a); buildingmodel.UNDER_LEVEL = a; } //buildingmodel.UNDER_LEVEL = decimal.Parse(UNDER_LEVEL); if (!string.IsNullOrEmpty(UNDER_AREA)) { decimal a = 0; decimal.TryParse(UNDER_AREA, out a); buildingmodel.UNDER_AREA = a; } //buildingmodel.UNDER_AREA = decimal.Parse(UNDER_AREA); if (!string.IsNullOrEmpty(REFUGE_LEVEL)) { decimal a = 0; decimal.TryParse(REFUGE_LEVEL, out a); buildingmodel.REFUGE_LEVEL = a; } //buildingmodel.REFUGE_LEVEL = decimal.Parse(REFUGE_LEVEL); buildingmodel.REFUGE_AREA = REFUGE_AREA; buildingmodel.REFUGE_ADDR = REFUGE_ADDR; if (!string.IsNullOrEmpty(ELEVATOR_NUM)) { decimal a = 0; decimal.TryParse(ELEVATOR_NUM, out a); buildingmodel.ELEVATOR_NUM = a; } //buildingmodel.ELEVATOR_NUM = decimal.Parse(ELEVATOR_NUM); if (!string.IsNullOrEmpty(ELEVATOR_CON)) { decimal a = 0; decimal.TryParse(ELEVATOR_CON, out a); buildingmodel.ELEVATOR_CON = a; } //buildingmodel.ELEVATOR_CON = decimal.Parse(ELEVATOR_CON); buildingmodel.ELEVATOR_ADDR = ELEVATOR_ADDR; buildingmodel.BUIDING_USE_CHARACTER = BUIDING_USE_CHARACTER; buildingmodel.BUIDING_CLASS = BUIDING_CLASS; buildingmodel.BUIDING_TYPE = BUIDING_TYPE; buildingmodel.BUIDING_STRUCTURE_TYPE = BUIDING_STRUCTURE_TYPE; buildingmodel.FIRE_RESISTANCE_GRADE = FIRE_RESISTANCE_GRADE; buildingmodel.FIRE_RISK = FIRE_RISK; buildingmodel.FIRE_INSTALLATION = FIRE_INSTALLATION; buildingmodel.BORDER_SITUATION = BORDER_SITUATION; buildingmodel.REMARK = REMARK; buildingmodel.ORG_ID = ORG_ID; buildingmodel.EXTEND1 = CITY; if (bll.Add(buildingmodel)) { returnstr = "{\"code\":1,\"msg\":\"添加成功\",\"count\":0,\"data\":[]}"; } else { returnstr = "{\"code\":0,\"msg\":\"添加失败\",\"count\":0,\"data\":[]}"; } } catch (Exception e) { returnstr = "{\"code\":-1,\"msg\":\"" + e.Message + "\",\"count\":0,\"data\":[]}"; } return returnstr; } //更新 private string Edit(HttpContext context) { string returnstr = ""; try { string ID = context.Request.Params["ID"]; string BUILDING_ID = context.Request.Params["BUILDING_ID"]; string BUILDING_NAME = context.Request.Params["BUILDING_NAME"]; string BUILDING_ADDR = context.Request.Params["BUILDING_ADDR"]; string BUILDING_DEC = context.Request.Params["BUILDING_DEC"]; string R_PHOTO_PATH = context.Request.Params["R_PHOTO_PATH"]; string BUILDING_LON = context.Request.Params["BUILDING_LON"]; string BUILDING_LAT = context.Request.Params["BUILDING_LAT"]; string BUILDING_STA = context.Request.Params["BUILDING_STA"]; string BUILDING_FINISH = context.Request.Params["BUILDING_FINISH"]; string BUILDING_RIGHTANDUSE = context.Request.Params["BUILDING_RIGHTANDUSE"]; string WORKING_NUM = context.Request.Params["WORKING_NUM"]; string MAX_NUM = context.Request.Params["MAX_NUM"]; string IS_CONTROLROOM = context.Request.Params["IS_CONTROLROOM"]; string CONTROLROOM_ADDR = context.Request.Params["CONTROLROOM_ADDR"]; string BUILDING_AREA = context.Request.Params["BUILDING_AREA"]; string BUILDING_HEIGHT = context.Request.Params["BUILDING_HEIGHT"]; string COVERED_AREA = context.Request.Params["COVERED_AREA"]; string STANDARD_AREA = context.Request.Params["STANDARD_AREA"]; string ABOVE_LEVEL = context.Request.Params["ABOVE_LEVEL"]; string ABOVE_AREA = context.Request.Params["ABOVE_AREA"]; string UNDER_LEVEL = context.Request.Params["UNDER_LEVEL"]; string UNDER_AREA = context.Request.Params["UNDER_AREA"]; string REFUGE_LEVEL = context.Request.Params["REFUGE_LEVEL"]; string REFUGE_AREA = context.Request.Params["REFUGE_AREA"]; string REFUGE_ADDR = context.Request.Params["REFUGE_ADDR"]; string ELEVATOR_NUM = context.Request.Params["ELEVATOR_NUM"]; string ELEVATOR_CON = context.Request.Params["ELEVATOR_CON"]; string ELEVATOR_ADDR = context.Request.Params["ELEVATOR_ADDR"]; string BUIDING_USE_CHARACTER = context.Request.Params["BUIDING_USE_CHARACTER"]; string BUIDING_CLASS = context.Request.Params["BUIDING_CLASS"]; string BUIDING_TYPE = context.Request.Params["BUIDING_TYPE"]; string BUIDING_STRUCTURE_TYPE = context.Request.Params["BUIDING_STRUCTURE_TYPE"]; string FIRE_RESISTANCE_GRADE = context.Request.Params["FIRE_RESISTANCE_GRADE"]; string FIRE_RISK = context.Request.Params["FIRE_RISK"]; string FIRE_INSTALLATION = context.Request.Params["FIRE_INSTALLATION"]; string BORDER_SITUATION = context.Request.Params["BORDER_SITUATION"]; string REMARK = context.Request.Params["REMARK"]; string ORG_ID = context.Request.Params["ORG_ID"]; string CITY = context.Request.Params["CITY"]; Model.FIRE.FIRE_BUILDING buildingmodel = bll.GetModel(ID); if (buildingmodel != null) { buildingmodel.ID = ID; buildingmodel.BUILDING_ID = BUILDING_ID; buildingmodel.BUILDING_NAME = BUILDING_NAME; buildingmodel.BUILDING_ADDR = BUILDING_ADDR; buildingmodel.BUILDING_DEC = BUILDING_DEC; buildingmodel.BUILDING_PIC = R_PHOTO_PATH; buildingmodel.BUILDING_LON = BUILDING_LON; buildingmodel.BUILDING_LAT = BUILDING_LAT; buildingmodel.BUILDING_STA = BUILDING_STA; if (!string.IsNullOrEmpty(BUILDING_FINISH)) { buildingmodel.BUILDING_FINISH = DateTime.Parse(BUILDING_FINISH); } buildingmodel.BUILDING_RIGHTANDUSE = BUILDING_RIGHTANDUSE; if (!string.IsNullOrEmpty(WORKING_NUM)) { decimal a = 0; decimal.TryParse(WORKING_NUM, out a); buildingmodel.WORKING_NUM = a; } //buildingmodel.WORKING_NUM = decimal.Parse(WORKING_NUM); if (!string.IsNullOrEmpty(MAX_NUM)) { decimal a = 0; decimal.TryParse(MAX_NUM, out a); buildingmodel.MAX_NUM = a; } //buildingmodel.MAX_NUM = decimal.Parse(MAX_NUM); buildingmodel.IS_CONTROLROOM = IS_CONTROLROOM; buildingmodel.CONTROLROOM_ADDR = CONTROLROOM_ADDR; if (!string.IsNullOrEmpty(BUILDING_AREA)) { decimal a = 0; decimal.TryParse(BUILDING_AREA, out a); buildingmodel.BUILDING_AREA = a; } //buildingmodel.BUILDING_AREA = decimal.Parse(BUILDING_AREA); if (!string.IsNullOrEmpty(BUILDING_HEIGHT)) { decimal a = 0; decimal.TryParse(BUILDING_HEIGHT, out a); buildingmodel.BUILDING_HEIGHT = a; } //buildingmodel.BUILDING_HEIGHT = decimal.Parse(BUILDING_HEIGHT); if (!string.IsNullOrEmpty(COVERED_AREA)) { decimal a = 0; decimal.TryParse(COVERED_AREA, out a); buildingmodel.COVERED_AREA = a; } //buildingmodel.COVERED_AREA = decimal.Parse(COVERED_AREA); if (!string.IsNullOrEmpty(STANDARD_AREA)) { decimal a = 0; decimal.TryParse(STANDARD_AREA, out a); buildingmodel.STANDARD_AREA = a; } //buildingmodel.STANDARD_AREA = decimal.Parse(STANDARD_AREA); if (!string.IsNullOrEmpty(ABOVE_LEVEL)) { decimal a = 0; decimal.TryParse(ABOVE_LEVEL, out a); buildingmodel.ABOVE_LEVEL = a; } //buildingmodel.ABOVE_LEVEL = decimal.Parse(ABOVE_LEVEL); if (!string.IsNullOrEmpty(ABOVE_AREA)) { decimal a = 0; decimal.TryParse(ABOVE_AREA, out a); buildingmodel.ABOVE_AREA = a; } //buildingmodel.ABOVE_AREA = decimal.Parse(ABOVE_AREA); if (!string.IsNullOrEmpty(UNDER_LEVEL)) { decimal a = 0; decimal.TryParse(UNDER_LEVEL, out a); buildingmodel.UNDER_LEVEL = a; } //buildingmodel.UNDER_LEVEL = decimal.Parse(UNDER_LEVEL); if (!string.IsNullOrEmpty(UNDER_AREA)) { decimal a = 0; decimal.TryParse(UNDER_AREA, out a); buildingmodel.UNDER_AREA = a; } //buildingmodel.UNDER_AREA = decimal.Parse(UNDER_AREA); if (!string.IsNullOrEmpty(REFUGE_LEVEL)) { decimal a = 0; decimal.TryParse(REFUGE_LEVEL, out a); buildingmodel.REFUGE_LEVEL = a; } //buildingmodel.REFUGE_LEVEL = decimal.Parse(REFUGE_LEVEL); buildingmodel.REFUGE_AREA = REFUGE_AREA; buildingmodel.REFUGE_ADDR = REFUGE_ADDR; if (!string.IsNullOrEmpty(ELEVATOR_NUM)) { decimal a = 0; decimal.TryParse(ELEVATOR_NUM, out a); buildingmodel.ELEVATOR_NUM = a; } //buildingmodel.ELEVATOR_NUM = decimal.Parse(ELEVATOR_NUM); if (!string.IsNullOrEmpty(ELEVATOR_CON)) { decimal a = 0; decimal.TryParse(ELEVATOR_CON, out a); buildingmodel.ELEVATOR_CON = a; } //buildingmodel.ELEVATOR_CON = decimal.Parse(ELEVATOR_CON); buildingmodel.ELEVATOR_ADDR = ELEVATOR_ADDR; buildingmodel.BUIDING_USE_CHARACTER = BUIDING_USE_CHARACTER; buildingmodel.BUIDING_CLASS = BUIDING_CLASS; buildingmodel.BUIDING_TYPE = BUIDING_TYPE; buildingmodel.BUIDING_STRUCTURE_TYPE = BUIDING_STRUCTURE_TYPE; buildingmodel.FIRE_RESISTANCE_GRADE = FIRE_RESISTANCE_GRADE; buildingmodel.FIRE_RISK = FIRE_RISK; buildingmodel.FIRE_INSTALLATION = FIRE_INSTALLATION; buildingmodel.BORDER_SITUATION = BORDER_SITUATION; buildingmodel.REMARK = REMARK; buildingmodel.ORG_ID = ORG_ID; buildingmodel.EXTEND1 = CITY; if (bll.Update(buildingmodel)) { returnstr = "{\"code\":1,\"msg\":\"更新成功\",\"count\":0,\"data\":[]}"; } else { returnstr = "{\"code\":0,\"msg\":\"更新失败\",\"count\":0,\"data\":[]}"; } } else { returnstr = "{\"code\":0,\"msg\":\"不存在该条数据\",\"count\":0,\"data\":[]}"; } } catch (Exception e) { returnstr = "{\"code\":-1,\"msg\":\"" + e.Message + "\",\"count\":0,\"data\":[]}"; } return returnstr; } //删除 private string Del(HttpContext context) { string returnstr = ""; int code = -1; string msg = ""; try { string DelList = context.Request.Params["BuildingList"]; string[] DelArray = DelList.Split(','); string DelListString = ""; for (int i = 0; i < DelArray.Length; i++) { if (i == 0) { DelListString = "'" + DelArray[i] + "'"; } else { DelListString += ",'" + DelArray[i] + "'"; } } if (bll.DeleteList(DelListString)) { msg = "删除成功!"; code = 1; } else { msg = "删除失败!"; } } catch { msg = "删除失败!"; } returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}"; return returnstr; } public bool IsReusable { get { return false; } } } }