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.
356 lines
14 KiB
356 lines
14 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Data;
|
|
|
|
namespace FangYar.WebUI.ashx
|
|
{
|
|
/// <summary>
|
|
/// SysUsersRulesHandler 的摘要说明
|
|
/// </summary>
|
|
public class SysUsersUkeyHandler : IHttpHandler
|
|
{
|
|
private FangYar.BLL.TBL.SysUSerRulesBLL bll = new BLL.TBL.SysUSerRulesBLL();
|
|
public void ProcessRequest(HttpContext context)
|
|
{
|
|
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Other, "用户Ukey绑定操作请求", "");
|
|
|
|
context.Response.ContentType = "text/json";
|
|
string action = context.Request.Params["Action"];
|
|
string returnstr = "";
|
|
switch (action)
|
|
{
|
|
case "List":
|
|
returnstr = GetModelList(context);
|
|
break;
|
|
case "Add":
|
|
returnstr = AddModel(context);
|
|
break;
|
|
case "Edit":
|
|
returnstr = EditModel(context);
|
|
break;
|
|
case "ForceEdit":
|
|
returnstr = ForceEditModel(context);
|
|
break;
|
|
case "Del":
|
|
returnstr = DelModel(context);
|
|
break;
|
|
case "getUserUkey":
|
|
returnstr = getUserUkey(context);
|
|
break;
|
|
}
|
|
context.Response.Write(returnstr);
|
|
|
|
}
|
|
//查询
|
|
private string GetModelList(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
try
|
|
{
|
|
string ukey = context.Request.Params["ukey"];
|
|
string empName = context.Request.Params["empName"];
|
|
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(ukey))
|
|
{
|
|
where = "u.ukey like '%" + ukey + "%'";
|
|
}
|
|
if (!string.IsNullOrEmpty(empName))
|
|
{
|
|
if (where != null)
|
|
{
|
|
where += " and ";
|
|
}
|
|
where += "u.emp_name like '%" + empName + "%' ";
|
|
}
|
|
returnstr = "{\"code\":0,\"data\":";
|
|
|
|
int startnum = (pageIndex - 1) * pageSize;
|
|
string sql = "select u.*,(select org_name from fire_org o where o.org_id = u.org_id) as org_name from tbl_sys_emp_ukey u ";
|
|
if (where != null && where != "")
|
|
{
|
|
sql += " where " + where;
|
|
}
|
|
sql += " order by u.updatetime desc";
|
|
startnum = startnum < 0 ? 0 : startnum;
|
|
sql += " limit " + startnum + ", " + pageSize;
|
|
DataTable dt = FangYar.Common.MySqlHelper.QueryTable(sql);
|
|
if (dt.Rows.Count > 0)
|
|
{
|
|
returnstr += FangYar.Common.JsonHelper.ToJson(dt);
|
|
}
|
|
else
|
|
{
|
|
returnstr += "[]";
|
|
}
|
|
returnstr += "}";
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
returnstr = "{\"code\":0,\"msg\":\"error\",\"count\":0,\"data\":[]}";
|
|
}
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "用户ukey操作请求", "查询");
|
|
return returnstr;
|
|
|
|
}
|
|
// 添加
|
|
private string AddModel(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
int code = -1;
|
|
string msg = "";
|
|
try
|
|
{
|
|
string id = Guid.NewGuid().ToString("N");
|
|
string empId = context.Request.Params["empId"];
|
|
string usersUid = context.Request.Params["usersUid"];
|
|
string empName = context.Request.Params["empName"];
|
|
string ukey = context.Request.Params["ukey"];
|
|
string lockTime = context.Request.Params["lockTime"];
|
|
string orgId = context.Request.Params["orgId"];
|
|
|
|
if (string.IsNullOrEmpty(usersUid))
|
|
{
|
|
return "{\"code\":" + code + ",\"msg\":\"登录账户不能为空!\"}";
|
|
}
|
|
if (string.IsNullOrEmpty(empId))
|
|
{
|
|
return "{\"code\":" + code + ",\"msg\":\"用户ID不能为空!\"}";
|
|
}
|
|
|
|
string isOnlyUkeySql = "select id,emp_name from tbl_sys_emp_ukey where ukey = '" + ukey + "'";
|
|
DataTable isOnlyUkeyDt = FangYar.Common.MySqlHelper.QueryTable(isOnlyUkeySql);
|
|
if (isOnlyUkeyDt != null && isOnlyUkeyDt.Rows.Count > 0)
|
|
{
|
|
string emp_name = isOnlyUkeyDt.Rows[0]["emp_name"].ToString();
|
|
if (!string.IsNullOrEmpty(emp_name))
|
|
{
|
|
string editId = isOnlyUkeyDt.Rows[0]["id"].ToString();
|
|
return "{\"code\":-2,\"id\":\""+ editId + "\",\"msg\":\"当前ukey:" + ukey + ",已经绑定给了【" + emp_name + "】,是否替换\"}";
|
|
}
|
|
}
|
|
|
|
string sql = "insert into tbl_sys_emp_ukey(id,emp_id,users_uid,emp_name,ukey,lock_time,org_id) values ('" + id + "','" + empId + "','" + usersUid + "','" + empName + "','" + ukey + "','" + lockTime + "','" + orgId + "')";
|
|
if (FangYar.Common.MySqlHelper.Execute(sql) > 0)
|
|
{
|
|
msg = "添加成功!";
|
|
code = 1;
|
|
}
|
|
else
|
|
{
|
|
msg = "添加失败!";
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
msg = "添加失败!";
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "用户ukey操作请求", "添加异常:" + e);
|
|
}
|
|
returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}";
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Add, "用户ukey操作请求", "添加");
|
|
return returnstr;
|
|
|
|
}
|
|
//修改
|
|
private string EditModel(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
int code = -1;
|
|
string msg = "";
|
|
try
|
|
{
|
|
string id = context.Request.Params["id"];
|
|
string empId = context.Request.Params["empId"];
|
|
string usersUid = context.Request.Params["usersUid"];
|
|
string empName = context.Request.Params["empName"];
|
|
string ukey = context.Request.Params["ukey"];
|
|
string lockTime = context.Request.Params["lockTime"];
|
|
string orgId = context.Request.Params["orgId"];
|
|
|
|
if (string.IsNullOrEmpty(usersUid))
|
|
{
|
|
return "{\"code\":" + code + ",\"msg\":\"登录账户不能为空!\"}";
|
|
}
|
|
if (string.IsNullOrEmpty(empId))
|
|
{
|
|
return "{\"code\":" + code + ",\"msg\":\"用户ID不能为空!\"}";
|
|
}
|
|
|
|
string isOnlyUkeySql = "select id,emp_name from tbl_sys_emp_ukey where ukey = '" + ukey + "'";
|
|
DataTable isOnlyUkeyDt = FangYar.Common.MySqlHelper.QueryTable(isOnlyUkeySql);
|
|
if (isOnlyUkeyDt != null && isOnlyUkeyDt.Rows.Count > 0)
|
|
{
|
|
string emp_name = isOnlyUkeyDt.Rows[0]["emp_name"].ToString();
|
|
if (!string.IsNullOrEmpty(emp_name))
|
|
{
|
|
string editId = isOnlyUkeyDt.Rows[0]["id"].ToString();
|
|
return "{\"code\":-2,\"id\":\"" + editId + "\",\"msg\":\"当前ukey:" + ukey + ",已经绑定给了【"+ emp_name + "】,是否替换\"}";
|
|
}
|
|
}
|
|
|
|
string sql = "update tbl_sys_emp_ukey set emp_id = '" + empId+ "',users_uid = '" + usersUid + "',emp_name = '" + empName + "',ukey = '" + ukey + "',lock_time = '" + lockTime + "',org_id = '" + orgId + "' where id = '" + id + "'";
|
|
if (FangYar.Common.MySqlHelper.Execute(sql) > 0)
|
|
{
|
|
msg = "修改成功!";
|
|
code = 1;
|
|
}
|
|
else
|
|
{
|
|
msg = "修改失败!";
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
msg = "修改失败!";
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "用户ukey操作请求", "修改异常:" + e);
|
|
}
|
|
returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}";
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Update, "用户ukey操作请求", "修改");
|
|
return returnstr;
|
|
}
|
|
//强制修改
|
|
private string ForceEditModel(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
int code = -1;
|
|
string msg = "";
|
|
try
|
|
{
|
|
string id = context.Request.Params["id"];
|
|
string empId = context.Request.Params["empId"];
|
|
string usersUid = context.Request.Params["usersUid"];
|
|
string empName = context.Request.Params["empName"];
|
|
string ukey = context.Request.Params["ukey"];
|
|
string lockTime = context.Request.Params["lockTime"];
|
|
string orgId = context.Request.Params["orgId"];
|
|
|
|
if (string.IsNullOrEmpty(usersUid))
|
|
{
|
|
return "{\"code\":" + code + ",\"msg\":\"登录账户不能为空!\"}";
|
|
}
|
|
if (string.IsNullOrEmpty(empId))
|
|
{
|
|
return "{\"code\":" + code + ",\"msg\":\"用户ID不能为空!\"}";
|
|
}
|
|
|
|
string sql = "update tbl_sys_emp_ukey set emp_id = '" + empId + "',users_uid = '" + usersUid + "',emp_name = '" + empName + "',ukey = '" + ukey + "',lock_time = '" + lockTime + "',org_id = '" + orgId + "' where id = '" + id + "'";
|
|
if (FangYar.Common.MySqlHelper.Execute(sql) > 0)
|
|
{
|
|
msg = "修改成功!";
|
|
code = 1;
|
|
}
|
|
else
|
|
{
|
|
msg = "修改失败!";
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
msg = "修改失败!";
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "用户ukey操作请求", "修改异常:" + e);
|
|
}
|
|
returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}";
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Update, "用户ukey操作请求", "修改");
|
|
return returnstr;
|
|
}
|
|
|
|
//删除
|
|
private string DelModel(HttpContext context)
|
|
{
|
|
string returnstr = "";
|
|
int code = -1;
|
|
string msg = "";
|
|
try
|
|
{
|
|
string UIDList = context.Request.Params["UIDList"];
|
|
UIDList = UIDList.Replace(",", "','");
|
|
|
|
string sql = "delete from tbl_sys_emp_ukey where ID in('" + UIDList + "')";
|
|
try
|
|
{
|
|
if (FangYar.Common.MySqlHelper.ExecuteSql(sql) > 0)
|
|
{
|
|
msg = "删除成功!";
|
|
code = 1;
|
|
}
|
|
else
|
|
{
|
|
msg = "删除失败!";
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
msg = "删除失败!";
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
msg = "删除失败!";
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "用户ukey操作请求", "删除异常:" + e);
|
|
}
|
|
returnstr = "{\"code\":" + code + ",\"msg\":\"" + msg + "\"}";
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Delete, "用户ukey操作请求", "删除");
|
|
return returnstr;
|
|
}
|
|
//获取用户ukey(根据用户登录账号)
|
|
private string getUserUkey(HttpContext context)
|
|
{
|
|
|
|
string usersUid = context.Request.Params["usersUid"];
|
|
|
|
string returnstr = "";
|
|
try
|
|
{
|
|
returnstr = "{\"code\":0,\"data\":";
|
|
|
|
string sql = @"SELECT * FROM tbl_sys_emp_ukey WHERE users_uid = '" + usersUid + @"'";
|
|
|
|
DataTable dt = FangYar.Common.MySqlHelper.QueryTable(sql);
|
|
if (dt.Rows.Count > 0)
|
|
{
|
|
returnstr += FangYar.Common.JsonHelper.ToJson(dt);
|
|
}
|
|
else
|
|
{
|
|
returnstr += "[]";
|
|
}
|
|
returnstr += "}";
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
returnstr = "{\"code\":-1,\"msg\":\"操作失败!\",\"data\":[]}";
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Error, "用户ukey操作请求", "获取当前用户ukey异常:" + e);
|
|
}
|
|
// 记录操作日志
|
|
BLL.SysOperationLogHelp.AddSysOperationLog(context, Common.EnumOperationLogType.Query, "用户ukey操作请求", "获取当前用户ukey");
|
|
return returnstr;
|
|
|
|
}
|
|
public bool IsReusable
|
|
{
|
|
get
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|