Browse Source

添加通用查询接口

master
王瑞 9 months ago
parent
commit
3b1507787c
  1. 1
      Code/智慧营区/DOCManageAPP(阿克苏)/ashx/A_CommonHandler.ashx
  2. 331
      Code/智慧营区/DOCManageAPP(阿克苏)/ashx/A_CommonHandler.ashx.cs

1
Code/智慧营区/DOCManageAPP(阿克苏)/ashx/A_CommonHandler.ashx

@ -0,0 +1 @@
<%@ WebHandler Language="C#" CodeBehind="A_CommonHandler.ashx.cs" Class="FangYar.WebUI.ashx.A_CommonHandler" %>

331
Code/智慧营区/DOCManageAPP(阿克苏)/ashx/A_CommonHandler.ashx.cs

@ -0,0 +1,331 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
namespace FangYar.WebUI.ashx
{
/// <summary>
/// A_CommonHandler 的摘要说明
/// </summary>
public class A_CommonHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string action = context.Request.Params["Action"];
string returnstr = "";
switch (action)
{
case "InsInfo":
returnstr = InsInfo(context);
break;
case "UpdInfo":
returnstr = UpdInfo(context);
break;
case "DelInfo":
returnstr = DelInfo(context);
break;
case "SelInfo":
returnstr = SelInfo(context);
break;
case "SelInfoPage":
returnstr = SelInfoPage(context);
break;
}
context.Response.Write(returnstr);
}
/// <summary>
/// 添加信息
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
private string InsInfo(HttpContext context)
{
string returnstr = "";
int code = 0;
string msg = "";
try
{
//表名
string tbName = context.Request.Params["tbName"];
//列名
string columns = context.Request.Params["columns"];
//内容
string values = context.Request.Params["values"];
StringBuilder strsql = new StringBuilder();
strsql.Append(" insert into " + tbName + " (" + columns + ") values (" + values + ") ");
int i = FangYar.Common.MySqlHelper.Execute(strsql.ToString());
if (i > 0)
{
msg = "保存成功!";
code = 1;
}
else { msg = "保存失败!"; }
}
catch (Exception e)
{
code = 2;
msg = e.Message;
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "消防要事日记操作请求", "保存异常:" + e);
}
returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}";
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Add, "消防要事日记操作请求", "保存");
return returnstr;
}
/// <summary>
/// 更新信息
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
private string UpdInfo(HttpContext context)
{
string returnstr = "";
int code = 0;
string msg = "";
try
{
//表名
string tbName = context.Request.Params["tbName"];
//设置信息
string sets = context.Request.Params["sets"];
//条件
string wheres = context.Request.Params["wheres"];
StringBuilder strsql = new StringBuilder();
strsql.Append(" update " + tbName + " set " + sets + " where " + wheres);
int i = FangYar.Common.MySqlHelper.Execute(strsql.ToString());
if (i > 0)
{
msg = "保存成功!";
code = 1;
}
else { msg = "保存失败!"; }
}
catch (Exception e)
{
code = 2;
msg = e.Message;
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "消防要事日记操作请求", "保存异常:" + e);
}
returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}";
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Add, "消防要事日记操作请求", "保存");
return returnstr;
}
/// <summary>
/// 删除信息
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
private string DelInfo(HttpContext context)
{
string returnstr = "";
int code = 0;
string msg = "";
try
{
//表名
string tbName = context.Request.Params["tbName"];
//条件
string wheres = context.Request.Params["wheres"];
StringBuilder strsql = new StringBuilder();
strsql.Append(" delete FROM " + tbName + " where " + wheres);
int i = FangYar.Common.MySqlHelper.Execute(strsql.ToString());
if (i > 0)
{
msg = "保存成功!";
code = 1;
}
else { msg = "保存失败!"; }
}
catch (Exception e)
{
code = 2;
msg = e.Message;
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "消防要事日记操作请求", "保存异常:" + e);
}
returnstr = "{\"msg\":\"" + msg + "\",\"code\":" + code + "}";
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Add, "消防要事日记操作请求", "保存");
return returnstr;
}
/// <summary>
/// 分页查询信息
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
private string SelInfoPage(HttpContext context)
{
string returnstr = "";
try
{
//表名
string tbName = context.Request.Params["tbName"];
//列名
string columns = context.Request.Params["columns"];
//条件
string wheres = context.Request.Params["wheres"];
//排序
string orderBy = context.Request.Params["orderBy"];
if (string.IsNullOrWhiteSpace(orderBy))
{
orderBy = " ID ";
}
if (string.IsNullOrWhiteSpace(columns))
{
columns = " * ";
}
if (string.IsNullOrWhiteSpace(wheres))
{
wheres = " 1=1 ";
}
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;
pageSize = pageSize < 1 ? 1 : pageSize;
int startnum = (pageIndex - 1) * pageSize;
string sqlCount = " SELECT count(1) from " + tbName + " WHERE " + wheres;
string sqlStr = " SELECT " + columns + " from " + tbName + " WHERE " + wheres + " order by " + orderBy + " limit " + startnum + ", " + pageSize;
var dtCount = FangYar.Common.MySqlHelper.QueryTable(sqlCount);
int rowCount = 0;
if (dtCount.Rows.Count > 0)
{
int.TryParse(dtCount.Rows[0][0] + "", out rowCount);
}
returnstr = "{\"code\":0,\"msg\":\"\",";
var dtList = FangYar.Common.MySqlHelper.QueryTable(sqlStr);
returnstr += "\"count\":" + rowCount + ",\"data\":";
returnstr += FangYar.Common.JsonHelper.ToJson(dtList);
returnstr += "}";
}
catch (Exception e)
{
returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}";
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "消防要事日记操作请求", "分页查询异常:" + e);
}
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "消防要事日记操作请求", "分页查询");
return returnstr;
}
/// <summary>
/// 查询全部信息
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
private string SelInfo(HttpContext context)
{
string returnstr = "";
try
{
//表名
string tbName = context.Request.Params["tbName"];
//列名
string columns = context.Request.Params["columns"];
//条件
string wheres = context.Request.Params["wheres"];
//排序
string orderBy = context.Request.Params["orderBy"];
if (string.IsNullOrWhiteSpace(orderBy))
{
orderBy = " ID ";
}
if (string.IsNullOrWhiteSpace(columns))
{
columns = " * ";
}
if (string.IsNullOrWhiteSpace(wheres))
{
wheres = " 1=1 ";
}
string sqlCount = " SELECT count(1) from " + tbName + " WHERE " + wheres;
string sqlStr = " SELECT " + columns + " from " + tbName + " WHERE " + wheres + " order by " + orderBy;
var dtCount = FangYar.Common.MySqlHelper.QueryTable(sqlCount);
int rowCount = 0;
if (dtCount.Rows.Count > 0)
{
int.TryParse(dtCount.Rows[0][0] + "", out rowCount);
}
returnstr = "{\"code\":0,\"msg\":\"\",";
var dtList = FangYar.Common.MySqlHelper.QueryTable(sqlStr);
returnstr += "\"count\":" + rowCount + ",\"data\":";
returnstr += FangYar.Common.JsonHelper.ToJson(dtList);
returnstr += "}";
}
catch (Exception e)
{
returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}";
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "消防要事日记操作请求", "分页查询异常:" + e);
}
// 记录操作日志
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "消防要事日记操作请求", "分页查询");
return returnstr;
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
Loading…
Cancel
Save