You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
550 lines
21 KiB
550 lines
21 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
|
|
namespace FangYar.WebUI.ashx
|
|
{
|
|
/// <summary>
|
|
/// DeviceHandler 的摘要说明
|
|
/// </summary>
|
|
public class ZYDeviceHandler : IHttpHandler
|
|
{
|
|
|
|
private FangYar.BLL.DeviceInfoBLL bll = new BLL.DeviceInfoBLL();
|
|
public void ProcessRequest(HttpContext context)
|
|
{
|
|
context.Response.ContentType = "text/json";
|
|
string action = context.Request.Params["Action"];
|
|
string returnstr = "";
|
|
switch (action)
|
|
{
|
|
case "List":
|
|
returnstr = GetDeviceList(context);
|
|
break;
|
|
case "UserDeviceList":
|
|
returnstr = GetUserDeviceList(context);
|
|
break;
|
|
case "OrgDeviceList":
|
|
returnstr = GetOrgDeviceList(context);
|
|
break;
|
|
case "TreeList":
|
|
returnstr = GetTreeDeviceList(context);
|
|
break;
|
|
case "Add":
|
|
returnstr = AddDevice(context);
|
|
break;
|
|
case "Edit":
|
|
returnstr = EditDevice(context);
|
|
break;
|
|
case "Del":
|
|
returnstr = DelDevice(context);
|
|
break;
|
|
case "SZORG":
|
|
returnstr = EditDevice_ORG(context);
|
|
break;
|
|
case "SZHY":
|
|
returnstr = EditDevice_HY(context);
|
|
break;
|
|
case "SZFolder":
|
|
returnstr = EditDevice_Folder(context);
|
|
break;
|
|
}
|
|
|
|
context.Response.Write(returnstr);
|
|
}
|
|
//查询
|
|
private string GetTreeDeviceList(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
try
|
|
{
|
|
string keywords = context.Request.Params["keywords"];
|
|
string treeID = context.Request.Params["treeID"];
|
|
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 = " (DEV_CODE like '" + keywords + "' or DEV_NAME like '" + keywords + "' ) ";
|
|
}
|
|
if (!string.IsNullOrEmpty(treeID))
|
|
{
|
|
if (where != null)
|
|
{
|
|
where += " and ";
|
|
}
|
|
where += " FOLDER_ID ='" + treeID + "' ";
|
|
}
|
|
returnstr = "{\"code\":0,\"msg\":\"\",";
|
|
int count = bll.Count(where);
|
|
returnstr += "\"count\":" + count + ",\"data\":";
|
|
if (count == 0)
|
|
{
|
|
returnstr += "[]";
|
|
}
|
|
else
|
|
{
|
|
List<FangYar.Model.ZHSQ.ZHSQ_DEVICE_INFO_Model> 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 GetDeviceList(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 += " and (DEV_CODE like '%" + keywords + "%' or DEV_NAME like '%" + keywords
|
|
+ "%' or DEV_FACTORY like '%" + keywords + "%' or DEV_MODEL like '%" + keywords
|
|
+ "%' or DEV_ADDR like '%" + keywords + "%' or DEV_LXR like '%" + keywords + "%') ";
|
|
}
|
|
returnstr = "{\"code\":0,\"msg\":\"\",";
|
|
int count = bll.Count(where);
|
|
returnstr += "\"count\":" + count + ",\"data\":";
|
|
if (count == 0)
|
|
{
|
|
returnstr += "[]";
|
|
}
|
|
else
|
|
{
|
|
List<FangYar.Model.ZHSQ.ZHSQ_DEVICE_INFO_Model> 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 GetOrgDeviceList(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
try
|
|
{
|
|
string keywords = context.Request.Params["keywords"];
|
|
string limit = context.Request.Params["limit"];
|
|
string treeId = context.Request.Params["treeID"];
|
|
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 = " 1=1 ";
|
|
if (!string.IsNullOrEmpty(treeId))
|
|
{
|
|
if (treeId == "0")
|
|
{
|
|
where = "ORG_CODE is null ";
|
|
}
|
|
else if (treeId == "-1")
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
where = "ORG_CODE=(select ID from tbl_sys_org where org_code='" + treeId + "') ";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//where = " ORG_CODE is null ";
|
|
}
|
|
if (!string.IsNullOrEmpty(keywords))
|
|
{
|
|
where += " and (DEV_CODE like '%" + keywords + "%' or DEV_NAME like '%" + keywords
|
|
+ "%' or DEV_FACTORY like '%" + keywords + "%' or DEV_MODEL like '%" + keywords
|
|
+ "%' or DEV_ADDR like '%" + keywords + "%' or DEV_LXR like '%" + keywords + "%') ";
|
|
}
|
|
returnstr = "{\"code\":0,\"msg\":\"\",";
|
|
int count = bll.Count(where);
|
|
returnstr += "\"count\":" + count + ",\"data\":";
|
|
if (count == 0)
|
|
{
|
|
returnstr += "[]";
|
|
}
|
|
else
|
|
{
|
|
List<FangYar.Model.ZHSQ.ZHSQ_DEVICE_INFO_Model> 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 GetUserDeviceList(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
try
|
|
{
|
|
FangYar.Model.LoginUserModel user = FangYar.Common.UserHelper.GetUser(context);
|
|
|
|
|
|
if (user != null)
|
|
{
|
|
string keywords = context.Request.Params["keywords"];
|
|
string limit = context.Request.Params["limit"];
|
|
string page = context.Request.Params["page"];
|
|
string treeID = context.Request.Params["treeID"];
|
|
int pageIndex = 1;
|
|
int pageSize = 10;
|
|
if (!string.IsNullOrEmpty(limit)) { pageIndex = int.Parse(page); }
|
|
if (!string.IsNullOrEmpty(limit)) { pageSize = int.Parse(limit); }
|
|
string where = " ORG_CODE = '" + user.OrgID + "' ";
|
|
if (!string.IsNullOrEmpty(keywords))
|
|
{
|
|
where += " and (DEV_CODE like '%" + keywords + "%' or DEV_NAME like '%" + keywords
|
|
+ "%' or DEV_FACTORY like '%" + keywords + "%' or DEV_MODEL like '%" + keywords
|
|
+ "%' or DEV_ADDR like '%" + keywords + "%' or DEV_LXR like '%" + keywords + "%') ";
|
|
}
|
|
if (!string.IsNullOrEmpty(treeID) && treeID != "-1" && treeID != "0")
|
|
{
|
|
if (where != null)
|
|
{
|
|
where += " and ";
|
|
}
|
|
where += " FOLDER_ID ='" + treeID + "'";
|
|
}
|
|
returnstr = "{\"code\":0,\"msg\":\"\",";
|
|
int count = bll.Count(where);
|
|
returnstr += "\"count\":" + count + ",\"data\":";
|
|
if (count == 0)
|
|
{
|
|
returnstr += "[]";
|
|
}
|
|
else
|
|
{
|
|
List<FangYar.Model.ZHSQ.ZHSQ_DEVICE_INFO_Model> list = bll.QueryList(pageIndex, pageSize, where, null);
|
|
returnstr += FangYar.Common.JsonHelper.ToJson(list);
|
|
}
|
|
returnstr += "}";
|
|
}
|
|
else { returnstr = "{\"code\":-2,\"msg\":\"登录超时\",\"count\":0,\"data\":[]}"; }
|
|
}
|
|
catch
|
|
{
|
|
returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}";
|
|
}
|
|
return returnstr;
|
|
}
|
|
//添加
|
|
private string AddDevice(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
int code = -1;
|
|
string msg = "";
|
|
try
|
|
{
|
|
FangYar.Model.LoginUserModel user = FangYar.Common.UserHelper.GetUser(context);
|
|
|
|
|
|
if (user != null)
|
|
{
|
|
string devcode = context.Request.Params["devcode"];
|
|
string devname = context.Request.Params["devname"];
|
|
string devtype = context.Request.Params["devtype"];
|
|
string devfactory = context.Request.Params["devfactory"];
|
|
string devloc = context.Request.Params["devloc"];
|
|
string devaddr = context.Request.Params["devaddr"];
|
|
string devtime = context.Request.Params["devtime"];
|
|
string devcpy = context.Request.Params["devcpy"];
|
|
string devlxr = context.Request.Params["devlxr"];
|
|
string devtel = context.Request.Params["devtel"];
|
|
string devhy = context.Request.Params["devhy"];
|
|
string devfolder = context.Request.Params["devfolder"];
|
|
string orgcode = user.OrgID;
|
|
if (string.IsNullOrEmpty(devcode))
|
|
{
|
|
msg = "设备编号不能为空!";
|
|
}
|
|
else if (string.IsNullOrEmpty(devname))
|
|
{
|
|
msg = "设备名称不能为空!";
|
|
}
|
|
else if (string.IsNullOrEmpty(devloc))
|
|
{
|
|
msg = "经纬度不能为空!";
|
|
}
|
|
else
|
|
{
|
|
FangYar.Model.ZHSQ.ZHSQ_DEVICE_INFO_Model model = new Model.ZHSQ.ZHSQ_DEVICE_INFO_Model();
|
|
model.DEV_CODE = devcode;
|
|
model.DEV_NAME = devname;
|
|
model.DEV_MODEL = devtype;
|
|
model.DEV_FACTORY = devfactory;
|
|
model.DEV_LOC = devloc;
|
|
model.DEV_ADDR = devaddr;
|
|
model.DEV_TIME = new DateTime?(Convert.ToDateTime(devtime));
|
|
model.CPY_ID = devcpy;
|
|
model.DEV_LXR = devlxr;
|
|
model.DEV_LXRTEL = devtel;
|
|
model.DEV_HY = devhy;
|
|
model.FOLDER_ID = devfolder;
|
|
model.ORG_CODE = orgcode;
|
|
if (bll.AddDevice(model))
|
|
{
|
|
msg = "添加成功!";
|
|
code = 1;
|
|
}
|
|
else
|
|
{
|
|
msg = "添加失败!";
|
|
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
msg = "未登录或登录超时!";
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
msg = "添加失败!";
|
|
}
|
|
returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}";
|
|
return returnstr;
|
|
}
|
|
//修改
|
|
private string EditDevice(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
int code = -1;
|
|
string msg = "";
|
|
try
|
|
{
|
|
FangYar.Model.LoginUserModel user = FangYar.Common.UserHelper.GetUser(context);
|
|
|
|
|
|
if (user != null)
|
|
{
|
|
string id = context.Request.Params["ID"];
|
|
string devcode = context.Request.Params["devcode"];
|
|
string devname = context.Request.Params["devname"];
|
|
string devtype = context.Request.Params["devtype"];
|
|
string devfactory = context.Request.Params["devfactory"];
|
|
string devloc = context.Request.Params["devloc"];
|
|
string devaddr = context.Request.Params["devaddr"];
|
|
string devtime = context.Request.Params["devtime"];
|
|
string devcpy = context.Request.Params["devcpy"];
|
|
string devlxr = context.Request.Params["devlxr"];
|
|
string devtel = context.Request.Params["devtel"];
|
|
string devhy = context.Request.Params["devhy"];
|
|
string devfolder = context.Request.Params["devfolder"];
|
|
string orgcode = user.OrgID;
|
|
if (string.IsNullOrEmpty(devcode))
|
|
{
|
|
msg = "设备编号不能为空!";
|
|
}
|
|
else if (string.IsNullOrEmpty(devname))
|
|
{
|
|
msg = "设备名称不能为空!";
|
|
}
|
|
else if (string.IsNullOrEmpty(devloc))
|
|
{
|
|
msg = "经纬度不能为空!";
|
|
}
|
|
else
|
|
{
|
|
FangYar.Model.ZHSQ.ZHSQ_DEVICE_INFO_Model model = bll.GetModelByID(id);
|
|
model.ID = id;
|
|
model.DEV_CODE = devcode;
|
|
model.DEV_NAME = devname;
|
|
model.DEV_MODEL = devtype;
|
|
model.DEV_FACTORY = devfactory;
|
|
model.DEV_LOC = devloc;
|
|
model.DEV_ADDR = devaddr;
|
|
model.DEV_TIME = new DateTime?(Convert.ToDateTime(devtime));
|
|
model.CPY_ID = devcpy;
|
|
model.DEV_LXR = devlxr;
|
|
model.DEV_LXRTEL = devtel;
|
|
model.DEV_HY = devhy;
|
|
model.FOLDER_ID = devfolder;
|
|
model.ORG_CODE = orgcode;
|
|
model.DEV_STATE = "1";
|
|
if (bll.EditDevice(model))
|
|
{
|
|
msg = "修改成功!";
|
|
code = 1;
|
|
}
|
|
else
|
|
{
|
|
msg = "修改失败!";
|
|
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
msg = "未登录或登录超时!";
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
msg = "修改失败!";
|
|
}
|
|
returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}";
|
|
return returnstr;
|
|
}
|
|
//修改机构
|
|
private string EditDevice_ORG(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
int code = -1;
|
|
string msg = "";
|
|
try
|
|
{
|
|
string ID = context.Request.Params["ID"];
|
|
string orgcode = context.Request.Params["orgcode"];
|
|
FangYar.Model.TBL.TBL_SYS_ORG_Model org = new BLL.TBL.SysOrgBLL().GetModelByOrgCode(orgcode);
|
|
string UIDList = context.Request.Params["UIDList"];
|
|
UIDList = "'" + UIDList.Replace(",", "','") + "'";
|
|
if (bll.Edit_ORG(org.ID, UIDList))
|
|
{
|
|
msg = "修改成功!";
|
|
code = 1;
|
|
}
|
|
else
|
|
{
|
|
msg = "修改失败!";
|
|
|
|
}
|
|
|
|
}
|
|
catch
|
|
{
|
|
msg = "修改失败!";
|
|
}
|
|
returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}";
|
|
return returnstr;
|
|
}
|
|
//修改行业
|
|
private string EditDevice_HY(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
int code = -1;
|
|
string msg = "";
|
|
try
|
|
{
|
|
string ID = context.Request.Params["ID"];
|
|
string hycode = context.Request.Params["hycode"];
|
|
|
|
string UIDList = context.Request.Params["UIDList"];
|
|
UIDList = "'" + UIDList.Replace(",", "','") + "'";
|
|
if (bll.Edit_HY(hycode, UIDList))
|
|
{
|
|
msg = "修改成功!";
|
|
code = 1;
|
|
}
|
|
else
|
|
{
|
|
msg = "修改失败!";
|
|
|
|
}
|
|
|
|
}
|
|
catch
|
|
{
|
|
msg = "修改失败!";
|
|
}
|
|
returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}";
|
|
return returnstr;
|
|
}
|
|
//修改目录
|
|
private string EditDevice_Folder(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
int code = -1;
|
|
string msg = "";
|
|
try
|
|
{
|
|
string ID = context.Request.Params["ID"];
|
|
string foldercode = context.Request.Params["foldercode"];
|
|
|
|
string UIDList = context.Request.Params["UIDList"];
|
|
UIDList = "'" + UIDList.Replace(",", "','") + "'";
|
|
if (bll.Edit_Folder(foldercode, UIDList))
|
|
{
|
|
msg = "修改成功!";
|
|
code = 1;
|
|
}
|
|
else
|
|
{
|
|
msg = "修改失败!";
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
msg = "修改失败!";
|
|
}
|
|
returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}";
|
|
return returnstr;
|
|
}
|
|
//删除
|
|
private string DelDevice(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
int code = -1;
|
|
string msg = "";
|
|
try
|
|
{
|
|
string UIDList = context.Request.Params["UIDList"];
|
|
UIDList = "'" + UIDList.Replace(",", "','") + "'";
|
|
if (bll.DeleteDevice(UIDList))
|
|
{
|
|
msg = "删除成功!";
|
|
code = 1;
|
|
}
|
|
else
|
|
{
|
|
msg = "删除失败!";
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
msg = "删除失败!";
|
|
}
|
|
returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}";
|
|
return returnstr;
|
|
}
|
|
|
|
|
|
public bool IsReusable
|
|
{
|
|
get
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|