using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace FangYar.WebUI.ashx { /// /// ZYCameraHandler 的摘要说明 /// public class ZYCameraHandler : IHttpHandler { private FangYar.BLL.TBL_CAMERA bll = new FangYar.BLL.TBL_CAMERA(); 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 += "( C_NAME like '%" + keyword + "%' or INS_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, ""); //string pic1 = Convert.ToBase64String((byte[])list[i].PICTURE); //returnstr += FangYar.Common.JsonHelper.ToJson(list); returnstr += "["; for (int i = 0; i < list.Count; i++) { string pic1 = ""; if (list[i].PICTURE != null && list[i].PICTURE.ToString() != "") { pic1 = Convert.ToBase64String((byte[])list[i].PICTURE); } returnstr += "{\"ID\":\"" + list[i].ID + "\",\"C_NO\":\"" + list[i].C_NO + "\",\"C_NAME\":\"" + list[i].C_NAME + "\",\"C_IP\":\"" + list[i].C_IP + "\",\"NVR_ID\":\"" + list[i].NVR_ID + "\",\"NVR_IP\":\"" + list[i].NVR_IP + "\",\"NVR_PORT\":\"" + list[i].NVR_PORT + "\",\"NVR_USER\":\"" + list[i].NVR_USER + "\","; returnstr += "\"NVR_PWD\":\"" + list[i].NVR_PWD + "\",\"NVR_CHANNEL\":\"" + list[i].NVR_CHANNEL + "\",\"C_FUN\":\"" + list[i].C_FUN + "\",\"C_TYPE\":\"" + list[i].C_TYPE + "\",\"C_FAC\":\"" + list[i].C_FAC + "\",\"C_MODEL\":\"" + list[i].C_MODEL + "\",\"C_TIME\":\"" + list[i].C_TIME + "\","; returnstr += "\"C_STATE\":\"" + list[i].C_STATE + "\",\"INS_ADDR\":\"" + list[i].INS_ADDR + "\",\"ORG_ID\":\"" + list[i].ORG_ID + "\",\"ORG_NAME\":\"" + list[i].ORG_NAME + "\",\"STA_ID\":\"" + list[i].STA_ID + "\",\"STA_NAME\":\"" + list[i].STA_NAME + "\",\"CPY_AREA\":\"" + list[i].CPY_AREA + "\","; returnstr += "\"C_USER\":\"" + list[i].C_USER + "\",\"C_PWD\":\"" + list[i].C_PWD + "\",\"C_POST\":\"" + list[i].C_POST + "\",\"PLAYURL\":\"" + list[i].PLAYURL + "\",\"STOPURL\":\"" + list[i].STOPURL + "\",\"LON\":\"" + list[i].LON + "\",\"LAT\":\"" + list[i].LAT + "\","; returnstr += "\"HEI\":\"" + list[i].HEI + "\",\"PICTURE\":\"" + pic1 + "\","; returnstr += "\"EXTEND1\":\"" + list[i].EXTEND1.ToString() + "\",\"EXTEND2\":\"" + list[i].EXTEND2 + "\",\"EXTEND3\":\"" + list[i].EXTEND3 + "\",\"EXTEND4\":\"" + list[i].EXTEND4 + "\"}"; if (i != list.Count - 1) { returnstr += ","; } } returnstr += "]"; } returnstr += "}"; } catch { 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");//摄像头表id string c_no = context.Request.Params["c_no"];//设备编号 string c_name = context.Request.Params["c_name"];//设备名称 string c_ip = context.Request.Params["c_ip"]; //摄像机ip string nvr_id = context.Request.Params["nvr_id"]; //连接nvr编号 string nvr_ip = context.Request.Params["nvr_ip"];//ip地址 string nvr_port = context.Request.Params["nvr_port"];//nvr控制端口 string nvr_user = context.Request.Params["nvr_user"];//nvr登录用户名 string nvr_pwd = context.Request.Params["nvr_pwd"];//nvr密码 string nvr_channel = context.Request.Params["nvr_channel"];//nvr通道号 //string c_fun = context.Request.Params["c_fun"];//摄像机功能 //string c_type = context.Request.Params["c_type"];//摄像机类型 string c_model = context.Request.Params["c_model"]; //摄像机型号 string c_time = context.Request.Params["c_time"]; //启用时间 string ins_addr = context.Request.Params["ins_addr"];//安装位置 string org_id = context.Request.Params["org_id"];//机构id string org_name = context.Request.Params["org_name"];//机构名称 string sta_id = context.Request.Params["sta_id"];//消防站id string sta_name = context.Request.Params["sta_name"];//消防站名称 string cpy_area = context.Request.Params["cpy_area"]; //行政区域 string c_user = context.Request.Params["c_user"]; //摄像头用户名 string c_pwd = context.Request.Params["c_pwd"];//摄像头密码 string c_post = context.Request.Params["c_post"];//摄像头端口号 string playurl = context.Request.Params["playurl"];//云播放地址 string stopurl = context.Request.Params["stopurl"];//云停放地址 string lon = context.Request.Params["lon"]; //经度 string lat = context.Request.Params["lat"];//纬度 string hei = context.Request.Params["hei"];//高程 string picture = context.Request.Params["picture"];//图片 string c_fac = context.Request.Params["c_fac"];//摄像机厂家 string c_state = context.Request.Params["c_state"];//状态 // FangYar.Model.TBL_CAMERA model = new Model.TBL_CAMERA(); model.ID = id; model.C_NO = c_no; model.C_NAME = c_name; model.C_IP = c_ip; model.NVR_ID = nvr_id; model.NVR_IP = nvr_ip; if (!string.IsNullOrEmpty(nvr_port)) { model.NVR_PORT = Convert.ToDecimal(nvr_port); } model.NVR_USER = nvr_user; model.NVR_PWD = nvr_pwd; if (!string.IsNullOrEmpty(nvr_channel)) { model.NVR_CHANNEL = Convert.ToDecimal(nvr_channel); } //if (!string.IsNullOrEmpty(c_fun)) //{ // model.C_FUN = Convert.ToDecimal(c_fun); //} //if (!string.IsNullOrEmpty(c_type)) //{ // model.C_TYPE = Convert.ToDecimal(c_type); //} model.C_MODEL = c_model; if (!string.IsNullOrEmpty(c_time)) { model.C_TIME = Convert.ToDateTime(c_time); } model.INS_ADDR = ins_addr; model.ORG_ID = org_id; model.ORG_NAME = org_name; model.STA_ID = sta_id; model.STA_NAME = sta_name; model.CPY_AREA = cpy_area; model.C_USER = c_user; model.C_PWD = c_pwd; if (!string.IsNullOrEmpty(c_post)) { model.C_POST = Convert.ToDecimal(c_post); } model.PLAYURL = playurl; model.STOPURL = stopurl; model.LON = lon; model.LAT = lat; model.HEI = hei; if (!string.IsNullOrEmpty(picture)) { String p1 = picture.Substring(picture.IndexOf(',') + 1); model.PICTURE = Convert.FromBase64String(p1); } model.C_FAC = c_fac; model.C_STATE = Convert.ToDecimal(c_state); 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"];//摄像头表id string c_no = context.Request.Params["c_no"];//设备编号 string c_name = context.Request.Params["c_name"];//设备名称 string c_ip = context.Request.Params["c_ip"]; //摄像机ip string nvr_id = context.Request.Params["nvr_id"]; //连接nvr编号 string nvr_ip = context.Request.Params["nvr_port"];//ip地址 string nvr_port = context.Request.Params["nvr_port"];//nvr控制端口 string nvr_user = context.Request.Params["nvr_user"];//nvr登录用户名 string nvr_pwd = context.Request.Params["nvr_pwd"];//nvr密码 string nvr_channel = context.Request.Params["nvr_channel"];//nvr通道号 //string c_fun = context.Request.Params["c_fun"];//摄像机功能 //string c_type = context.Request.Params["c_type"];//摄像机类型 string c_model = context.Request.Params["c_model"]; //摄像机型号 string c_time = context.Request.Params["c_time"]; //启用时间 string ins_addr = context.Request.Params["ins_addr"];//安装位置 string org_id = context.Request.Params["org_id"];//机构id string org_name = context.Request.Params["org_name"];//机构名称 string sta_id = context.Request.Params["sta_id"];//消防站id string sta_name = context.Request.Params["sta_name"];//消防站名称 string cpy_area = context.Request.Params["cpy_area"]; //行政区域 string c_user = context.Request.Params["c_user"]; //摄像头用户名 string c_pwd = context.Request.Params["c_pwd"];//摄像头密码 string c_post = context.Request.Params["c_post"];//摄像头端口号 string playurl = context.Request.Params["playurl"];//云播放地址 string stopurl = context.Request.Params["stopurl"];//云停放地址 string lon = context.Request.Params["lon"]; //经度 string lat = context.Request.Params["lat"];//纬度 string hei = context.Request.Params["hei"];//高程 string picture = context.Request.Params["picture"];//图片 string c_fac = context.Request.Params["c_fac"];//摄像机厂家 string c_state = context.Request.Params["c_state"]; //状态 // FangYar.Model.TBL_CAMERA model = new Model.TBL_CAMERA(); model.ID = id; model.C_NO = c_no; model.C_NAME = c_name; model.C_IP = c_ip; model.NVR_ID = nvr_id; model.NVR_IP = nvr_ip; if (!string.IsNullOrEmpty(nvr_port)) { model.NVR_PORT = Convert.ToDecimal(nvr_port); } model.NVR_USER = nvr_user; model.NVR_PWD = nvr_pwd; if (!string.IsNullOrEmpty(nvr_channel)) { model.NVR_CHANNEL = Convert.ToDecimal(nvr_channel); } //if (!string.IsNullOrEmpty(c_fun)) //{ // model.C_FUN = Convert.ToDecimal(c_fun); //} //if (!string.IsNullOrEmpty(c_type)) //{ // model.C_TYPE = Convert.ToDecimal(c_type); //} model.C_MODEL = c_model; if (!string.IsNullOrEmpty(c_time)) { model.C_TIME = Convert.ToDateTime(c_time); } model.INS_ADDR = ins_addr; model.ORG_ID = org_id; model.ORG_NAME = org_name; model.STA_ID = sta_id; model.STA_NAME = sta_name; model.CPY_AREA = cpy_area; model.C_USER = c_user; model.C_PWD = c_pwd; if (!string.IsNullOrEmpty(c_post)) { model.C_POST = Convert.ToDecimal(c_post); } model.PLAYURL = playurl; model.STOPURL = stopurl; model.LON = lon; model.LAT = lat; model.HEI = hei; if (!string.IsNullOrEmpty(picture)) { String p1 = picture.Substring(picture.IndexOf(',') + 1); model.PICTURE = Convert.FromBase64String(p1); } model.C_FAC = c_fac; if (!string.IsNullOrEmpty(c_state)) { model.C_STATE = Convert.ToDecimal(c_state); } if (bll.Update(model)) { msg = "修改成功!"; code = 1; } 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] + "'"; } } if (bll.DeleteList(EmpListString)) { msg = "删除成功!"; code = 1; } else { msg = "删除失败!"; } } catch { msg = "删除失败!"; } returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}"; return returnstr; } //查询 private string AppGetList(HttpContext context) { string returnstr = ""; try { string ORG_ID = context.Request.Params["OrgId"]; string c_fun = context.Request.Params["c_fun"]; 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"; //where += " and (ORG_ID ='" + ORG_ID + "' or ORG_ID in (select o.org_id from fire_org o where o.pid = '" + ORG_ID + "') )"; where += " and ORG_ID ='" + ORG_ID + "'"; if (!string.IsNullOrEmpty(c_fun)) { where += " and C_FUN='" + c_fun + "' "; } where += " order by (extend2) "; returnstr = "{\"code\":0,\"msg\":\"\","; int count = bll.GetRecordCount(where); returnstr += "\"count\":" + count + ",\"data\":"; if (count == 0) { returnstr += "[]"; } else { string data = "["; List list = bll.QueryList(pageIndex, pageSize, where, ""); for (int i = 0; i < list.Count; i++) { string pic1 = ""; if (list[i].PICTURE != null && list[i].PICTURE.ToString() != "") { pic1 = Convert.ToBase64String((byte[])list[i].PICTURE); } data += "{\"ID\":\"" + list[i].ID + "\",\"NAME\":\"" + list[i].C_NAME.Replace("\0", "") + "\",\"ORG_ID\":\"" + list[i].ORG_ID + "\",\"ORG_NAME\":\"" + list[i].ORG_NAME + "\",\"PLAYURL\":\"" + list[i].PLAYURL + "\","; data += "\"PICTURE\":\"" + pic1 + "\"}"; if (i != list.Count - 1) { data += ","; } } returnstr += data + "]"; //returnstr += FangYar.Common.JsonHelper.ToJson(list); } returnstr += "}"; } catch { 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\":"; if (bll.Exists(id)) { FangYar.Model.TBL_CAMERA model = bll.GetModel(id); returnstr += FangYar.Common.JsonHelper.ToJson(model); } else { returnstr += "[]"; } returnstr += "}"; } catch { returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]"; } return returnstr; } public bool IsReusable { get { return false; } } } }