软测单独项目
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.
 
 
 
 
 
 

360 lines
13 KiB

using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Web;
namespace FangYar.WebUI.ashx
{
/// <summary>
/// AlarmDataHandler1 的摘要说明
/// </summary>
public class ZYAlarmDataHandler : IHttpHandler
{
private FangYar.BLL.TBL_ALARMDATA bll = new FangYar.BLL.TBL_ALARMDATA();
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string action = context.Request.Params["Action"];
string returnstr = "";
switch (action)
{
case "List":
returnstr = alarmList(context);
break;
case "expListCar":
expListCar(context);
break;
case "expListPerson":
expListPerson(context);
break;
case "alarmSta":
returnstr = alarmSta(context);
break;
case "getAlarmInfo":
returnstr = getAlarmInfo(context);
break;
case "homeAlarmSta":
returnstr = homeAlarmSta(context);
break;
case "addCameraAlarm":
returnstr = addCameraAlarm(context);
break;
}
context.Response.Write(returnstr);
}
//查询
private string alarmList(HttpContext context)
{
string returnstr = "";
try
{
string OrgId = context.Request.Params["OrgId"];
string alarmType = context.Request.Params["ALARM_TYPE"];
string searchName = context.Request.Params["searchName"];
string searchTime = context.Request.Params["searchTime"];
string searchType = context.Request.Params["searchType"];
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 + "' or ORG_ID in (select o.org_id from fire_org o where o.pid = '" + OrgId + "') )";
}
if (!string.IsNullOrEmpty(alarmType))
{
where += " and ALARM_TYPE='" + alarmType + "'";
}
if (!string.IsNullOrEmpty(searchName))
{
where += " and ALARM_DES like '%" + searchName + "%' ";
}
if (!string.IsNullOrEmpty(searchTime))
{
where += " and date_format(TIME,'%Y-%m-%d') =date_format('" + searchTime + "','%Y-%m-%d')";
}
if (!string.IsNullOrEmpty(searchType))
{
where += " and EXTENDCODE1='" + searchType + "'";
}
returnstr = "{\"code\":0,\"msg\":\"\",";
int count = bll.GetRecordCount(where);
returnstr += "\"count\":" + count + ",\"data\":";
if (count == 0)
{
returnstr += "[]";
}
else
{
DataTable dt = bll.GetListByPage(where, " TIME desc ", (pageIndex - 1) * pageSize , pageSize).Tables[0];
returnstr += FangYar.Common.JsonHelper.ToJson(dt);
}
returnstr += "}";
}
catch
{
returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]";
}
return returnstr;
}
//导出
private void expListCar(HttpContext context)
{
try
{
string OrgId = context.Request.Params["OrgId"];
string alarmType = context.Request.Params["ALARM_TYPE"];
string searchTime = context.Request.Params["searchTime"];
string searchType = context.Request.Params["searchType"];
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 + "' or ORG_ID in (select o.org_id from fire_org o where o.pid = '" + OrgId + "') )";
}
if (!string.IsNullOrEmpty(alarmType))
{
where += " and ALARM_TYPE='" + alarmType + "'";
}
if (!string.IsNullOrEmpty(searchTime))
{
where += " and date_format(TIME,'%Y-%m-%d') =date_format('" + searchTime + "','%Y-%m-%d')";
}
if (!string.IsNullOrEmpty(searchType))
{
where += " and EXTENDCODE1='" + searchType + "'";
}
int count = bll.GetRecordCount(where);
if (count == 0)
{
}
else
{
//访客出入记录表
DataTable dt = bll.expListCar(0, count, where, " time desc ");
Dictionary<string, string> cellHeaders = new System.Collections.Generic.Dictionary<string, string>();
cellHeaders.Add("CAR_NUM", "车牌号");
cellHeaders.Add("ORG_NAME", "机构");
cellHeaders.Add("EXTENDCODE1", "类型");
cellHeaders.Add("TIME", "时间");
cellHeaders.Add("ALARM_DES", "描述");
FangYar.Common.NPOIExcelHelper.ExportByWeb(dt, null, cellHeaders, DateTime.Now.ToString("yyyyMMddHHmmss") + "车辆报警表.xls");
}
}
catch
{
}
}
private void expListPerson(HttpContext context)
{
try
{
string OrgId = context.Request.Params["OrgId"];
string alarmType = context.Request.Params["ALARM_TYPE"];
string searchTime = context.Request.Params["searchTime"];
string searchType = context.Request.Params["searchType"];
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 + "' or ORG_ID in (select o.org_id from fire_org o where o.pid = '" + OrgId + "') )";
}
if (!string.IsNullOrEmpty(alarmType))
{
where += " and ALARM_TYPE='" + alarmType + "'";
}
if (!string.IsNullOrEmpty(searchTime))
{
where += " and date_format(TIME,'%Y-%m-%d') =date_format('" + searchTime + "','%Y-%m-%d')";
}
if (!string.IsNullOrEmpty(searchType))
{
where += " and EXTENDCODE1='" + searchType + "'";
}
int count = bll.GetRecordCount(where);
if (count == 0)
{
}
else
{
//访客出入记录表
DataTable dt = bll.expListPerson(0, count, where, " time desc ");
Dictionary<string, string> cellHeaders = new System.Collections.Generic.Dictionary<string, string>();
cellHeaders.Add("EMP_NAME", "姓名");
cellHeaders.Add("ORG_NAME", "机构");
cellHeaders.Add("EXTENDCODE1", "类型");
cellHeaders.Add("TIME", "时间");
cellHeaders.Add("ALARM_DES", "描述");
FangYar.Common.NPOIExcelHelper.ExportByWeb(dt, null, cellHeaders, DateTime.Now.ToString("yyyyMMddHHmmss") + "人员报警表.xls");
}
}
catch
{
}
}
private string alarmSta(HttpContext context)
{
string returnstr = "";
int code = -1;
string msg = "";
string data = "";
string strWhere = " 1=1";
try
{
string ORG_ID = context.Request.Params["Org_Id"];
string S_Time = context.Request.Params["S_Time"];
string E_Time = context.Request.Params["E_Time"];
if (!string.IsNullOrEmpty(ORG_ID))
{
code = 1;
strWhere += " and ORG_ID='" + ORG_ID + "'";
if (!string.IsNullOrEmpty(S_Time) && !string.IsNullOrEmpty(E_Time))
{
strWhere += " and date_format('" + S_Time + "','%Y-%m-%d') < TIME";
strWhere += " and date_format('" + E_Time + "','%Y-%m-%d')> TIME";
}
else
{
strWhere += " and date_format(now(),'%Y-%m-%d') = date_format(TIME,'%Y-%m-%d')";
}
DataTable dt = bll.alarmSta(strWhere);
data = FangYar.Common.JsonHelper.ToJson(dt);
}
}
catch
{
msg = "获取失败!";
}
returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\",\"data\":" + data + "}";
return returnstr;
}
private string getAlarmInfo(HttpContext context)
{
string returnstr = "";
int code = -1;
string msg = "";
string data = "";
try
{
string taskId = context.Request.Params["taskId"];
if (!string.IsNullOrEmpty(taskId))
{
Model.OA.TBL_ALARMDATA model = bll.GetModel(taskId);
data = Common.JsonHelper.ToJson(model);
code = 1;
}
}
catch
{
msg = "获取失败!";
}
returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\",\"data\":" + data + "}";
return returnstr;
}
/// <summary>
/// 首页报警统计
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
private string homeAlarmSta(HttpContext context)
{
string returnstr = "";
int code = -1;
string msg = "";
string data = "";
string strWhere = " 1=1";
try
{
string ORG_ID = context.Request.Params["Org_Id"];
if (!string.IsNullOrEmpty(ORG_ID))
{
code = 1;
strWhere += " and ORG_ID='" + ORG_ID + "'";
strWhere += " and date_format(time,'%Y-%m-%d') = date_format(now(),'%Y-%m-%d')";
DataTable dt = bll.homeAlarmSta(strWhere);
data = FangYar.Common.JsonHelper.ToJson(dt);
}
}
catch
{
msg = "获取失败!";
}
returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\",\"data\":" + data + "}";
return returnstr;
}
//添加
private string addCameraAlarm(HttpContext context)
{
HttpRequest request = context.Request;
Stream stream = request.InputStream;
string returnstr = "";
int code = -1;
string msg = "";
try
{
string car_name = context.Request.Params["car_name"];//车辆名称
//报警表
FangYar.Model.OA.TBL_ALARMDATA model = new FangYar.Model.OA.TBL_ALARMDATA();
if (bll.Add(model))
{
msg = "添加成功!";
code = 1;
}
else { msg = "添加失败!"; }
}
catch
{
msg = "添加失败!";
}
returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}";
return returnstr;
}
public bool IsReusable
{
get
{
return false;
}
}
}
}