<%@ WebHandler Language="C#" Class="SysDictDataHandler" %>
|
using Common;
|
using Dao;
|
using Model;
|
// using Newtonsoft.Json;
|
//using Newtonsoft.Json.Linq;
|
using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using System.Text.RegularExpressions;
|
using System.Web;
|
using System.IO;
|
using System.Diagnostics;
|
|
public class SysDictDataHandler : PageHandler<SysUser>
|
{
|
private SysDictDataDao _Dao = new SysDictDataDao();
|
|
private List<SysDictType> _SysDictTypeList;
|
private List<SysUser> _SysUserList;
|
|
public override JsonPageResult ProcessRequestInternal(PageContext<SysUser> context)
|
{
|
string @string = context.GetString("action");
|
switch (@string)
|
{
|
case "delete":
|
return this.Delete(context); //删除
|
case "update":
|
return this.Update(context); //修改
|
case "add":
|
return this.Add(context); //添加
|
case "list":
|
return this.List(context); //查询
|
case "getByDictId":
|
return this.GetByDictId(context); //获取记录信息
|
case "getByDictValue":
|
return this.GetByDictValue(context); //获取记录信息
|
case "updateStatus":
|
return this.UpdateStatus(context); //启用或停用
|
|
default:
|
throw new Exception("Invalid Action=" + @string);
|
}
|
}
|
|
//加载信息
|
private JsonPageResult List(PageContext<SysUser> context)
|
{
|
string dictLabel = context.GetString("dictLabel");
|
string dictType = context.GetString("dictType");
|
|
int recordCount = 0;
|
int pageSize = context.GetInt("pageSize", 50);
|
int pageIndex = context.GetInt("pageIndex", 1);
|
|
List<SysDictData> list = _Dao.LoadInfoList(dictLabel, dictType, pageSize, pageIndex, out recordCount);
|
|
string str1 = "";
|
if (list != null && list.Count > 0)
|
{
|
|
int num = 0;
|
foreach (SysDictData bean in list)
|
{
|
++num;
|
str1 += "<tr>";
|
str1 += "<td>" + bean.DictValue + "</td>";
|
str1 += "<td>" + bean.DictLabel + "</td>";
|
str1 += "<td>" + bean.DictType + "</td>";
|
str1 += "<td>" + bean.DictSort + "</td>";
|
str1 += "<td>" + SysUserName(string.IsNullOrEmpty(bean.CreateBy)? 0: int.Parse(bean.CreateBy) ) + "</td>";
|
str1 += "<td>" + bean.CreateTime + "</td>";
|
str1 += "<td>" + (bean.Status == 1 ? "<span class='label label-primary'>正常</span>" : "<span class='label label-default'>停用</span>") + "</td>";
|
str1 += "<td class=\"text-center \">";
|
str1 = bean.Status != 0 ? str1 + string.Format("<a href=\"javascript:;\" data-id=\"{0}\" data-status=\"0\" class=\"action-update-status btn btn-default btn-xs\"><i class=\"fa fa-toggle-off\"></i> 停用</a> ", (object) bean.DictId ) : str1 + string.Format("<a href=\"javascript:;\" data-id=\"{0}\" data-status=\"1\" class=\"action-update-status btn btn-primary btn-xs\"><i class=\"fa fa-toggle-on\"/></i> 启用</a> ", (object) bean.DictId );
|
str1 += string.Format("<a href=\"javascript:;\" data-id=\"{0}\" class=\"action-modal-edit btn btn-success btn-xs\"><i class=\"fa fa-edit\"></i> 编辑</a> ", (object) bean.DictId);
|
str1 += string.Format("<a href=\"javascript:;\" data-id=\"{0}\" class=\"action-delete btn btn-default btn-xs\"><i class=\"fa fa-trash\"></i> 删除</a> ", (object) bean.DictId);
|
str1 += "</td>";
|
str1 += "</tr>";
|
}
|
}
|
else
|
str1 += "<tr><td colspan=\"8\" style=\"padding-left:5px; text-align: center;\">暂无信息</td></tr>";
|
|
return new JsonPageResult(true, new
|
{
|
Table = str1.ToString(),
|
TotalCount = recordCount
|
});
|
}
|
|
|
//删除信息
|
private JsonPageResult Delete(PageContext<SysUser> context)
|
{
|
string dictId = context.GetString("dictId");
|
SysDictData sysDictData = new SysDictData();
|
|
string updateBy = context.SessionObject.UserID.ToString();
|
sysDictData = new SysDictData();
|
sysDictData.DictId = dictId;
|
sysDictData.UpdateBy = updateBy;
|
sysDictData.UpdateTime = DateTime.Now; //当前时间
|
|
this._Dao.Delete(sysDictData);
|
return new JsonPageResult(true, "删除信息成功!");
|
|
}
|
|
//添加
|
private JsonPageResult Add(PageContext<SysUser> context)
|
{
|
string dictValue = context.GetString("dictValue");
|
string dictLabel = context.GetString("dictLabel");
|
string dictType = context.GetString("dictType");
|
string dictSort = context.GetString("dictSort", "1");
|
string remark = context.GetString("remark", "");
|
|
if (string.IsNullOrEmpty(dictValue) ) {
|
throw new ArgumentException("字典数据键值不能为空,请输入!");
|
}
|
if (string.IsNullOrEmpty(dictLabel) ) {
|
throw new ArgumentException("字典数据标签不能为空,请输入!");
|
}
|
if (string.IsNullOrEmpty(dictType) ) {
|
throw new ArgumentException("字典类型编码不能为空,请输入!");
|
}
|
|
int status = 1; //设置默认状态:1-启用
|
|
DateTime nowTime = DateTime.Now; //当前时间
|
|
string creatBy = context.SessionObject.UserID.ToString();
|
DateTime createTime = nowTime;
|
string updateBy = context.SessionObject.UserID.ToString();
|
DateTime updateTime = nowTime;
|
|
string dictId = DataConverter.getRandom(32); //获取生成ID
|
this._Dao.Add(new SysDictData()
|
{
|
DictId = dictId,
|
DictValue = dictValue,
|
DictLabel = dictLabel,
|
DictType = dictType,
|
DictSort = int.Parse(dictSort),
|
//DelFlag = 0,
|
Status = status,
|
CreateBy = creatBy,
|
CreateTime = createTime,
|
UpdateBy = updateBy,
|
UpdateTime = updateTime,
|
Remark = remark
|
|
});
|
return new JsonPageResult(true, "信息添加成功!");
|
}
|
|
//更新
|
private JsonPageResult Update(PageContext<SysUser> context)
|
{
|
string dictId = context.GetString("dictId"); //获取生成ID
|
string dictValue = context.GetString("dictValue");
|
string dictLabel = context.GetString("dictLabel");
|
string dictType = context.GetString("dictType");
|
string dictSort = context.GetString("dictSort", "1");
|
string remark = context.GetString("remark", "");
|
|
if (string.IsNullOrEmpty(dictValue) ) {
|
throw new ArgumentException("字典数据键值不能为空,请输入!");
|
}
|
if (string.IsNullOrEmpty(dictLabel) ) {
|
throw new ArgumentException("字典数据标签不能为空,请输入!");
|
}
|
if (string.IsNullOrEmpty(dictType) ) {
|
throw new ArgumentException("字典类型编码不能为空,请输入!");
|
}
|
|
int status = context.GetInt("status", 0); //设置默认状态:1-启用
|
|
DateTime nowTime = DateTime.Now; //当前时间
|
|
|
string updateBy = context.SessionObject.UserID.ToString();
|
DateTime updateTime = nowTime;
|
|
SysDictData sysDictData = _Dao.GetByDictId(dictId);
|
string creatBy = sysDictData.CreateBy;
|
DateTime createTime = sysDictData.CreateTime;
|
|
this._Dao.Update(new SysDictData()
|
{
|
DictId = dictId,
|
DictValue = dictValue,
|
DictLabel = dictLabel,
|
DictType = dictType,
|
DictSort = int.Parse(dictSort),
|
//DelFlag = 0,
|
Status = status,
|
CreateBy = creatBy,
|
CreateTime = createTime,
|
UpdateBy = updateBy,
|
UpdateTime = updateTime,
|
Remark = remark
|
|
});
|
|
|
return new JsonPageResult(true, "信息更新成功!");
|
}
|
|
//根据主键获取信息
|
private JsonPageResult GetByDictId(PageContext<SysUser> context)
|
{
|
return new JsonPageResult(true, this._Dao.GetByDictId(context.GetString("dictId")));
|
}
|
|
//根据主键获取信息
|
private JsonPageResult GetByDictValue(PageContext<SysUser> context)
|
{
|
return new JsonPageResult(true, this._Dao.GetByDictValue(context.GetString("dictType"), context.GetString("dictValue")));
|
}
|
|
//加载字典类型信息
|
private List<SysDictType> SysDictTypeAllList()
|
{
|
SysDictType bean = new SysDictType();
|
bean.Status = -1;
|
|
List<SysDictType> list = new SysDictTypeDao().getAllList(bean);
|
|
return list;
|
}
|
|
//获取字典类型信息列表
|
private List<SysDictType> SysDictTypeList
|
{
|
get
|
{
|
if (this._SysDictTypeList == null)
|
{
|
this._SysDictTypeList = this.SysDictTypeAllList();
|
}
|
return this._SysDictTypeList;
|
}
|
}
|
|
//主键ID转换名称
|
private string SysDictTypeToName(string dictType)
|
{
|
if (this.SysDictTypeList == null)
|
return string.Empty;
|
SysDictType bean = this.SysDictTypeList.Find((Predicate<SysDictType>)(sysDictType => sysDictType.DictType == dictType));
|
if (bean != null)
|
return string.Format("{0}", (object)bean.DictName);
|
return string.Empty;
|
}
|
|
//更新信息启用或停用
|
private JsonPageResult UpdateStatus(PageContext<SysUser> context)
|
{
|
string dictId = context.GetString("dictId");
|
int status = context.GetInt("status");
|
SysDictData sysDictData = new SysDictData();
|
|
string updateBy = context.SessionObject.UserID.ToString();
|
sysDictData.DictId = dictId;
|
sysDictData.Status = status;
|
sysDictData.UpdateBy = updateBy;
|
sysDictData.UpdateTime = DateTime.Now; //当前时间
|
|
this._Dao.UpdateStatus(sysDictData);
|
return new JsonPageResult(true, "更新信息状态成功!");
|
|
}
|
|
//获取管理端账户列表
|
private List<SysUser> SysUserList
|
{
|
get
|
{
|
if (this._SysUserList == null)
|
{
|
|
using (UserDao sysUserDao = new UserDao())
|
{
|
int recordCount = 0;
|
int int1 = 999999999;
|
int int2 = 1;
|
this._SysUserList = sysUserDao.LoadInfoList(out recordCount, int1, int2);
|
}
|
}
|
return this._SysUserList;
|
}
|
}
|
|
//启用停用转换名称
|
private string StatusToName(int status)
|
{
|
if (status == -1)
|
return string.Empty;
|
else if(status == 0)
|
return "<span class='label label-default'>停用</span>";
|
else if(status == 1)
|
return "<span class='label label-primary'>正常</span>";
|
|
return string.Empty;
|
}
|
|
//管理端用户ID转名称
|
private string SysUserName(int userId)
|
{
|
if (this.SysUserList == null)
|
return string.Empty;
|
SysUser sysUser = this._SysUserList.Find((Predicate<SysUser>)(bean => bean.UserID == userId));
|
if (sysUser != null)
|
return string.Format("{0}", (object)sysUser.UserName);
|
return string.Empty;
|
}
|
|
}
|