yzh
2022-06-20 97aa542d1a1cdcb46b2942026d28b7e5dca6c6c0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
<%@ 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");
        string source = context.GetString("source");
 
        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>" + SysDictTypeToName(bean.DictType) + "</td>";
                str1 += "<td>" + bean.DictSort + "</td>";
                str1 += "<td>" + (bean.ParanSource == 0 ? "系统内置" : "用户添加") + "</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 \">";
                if(bean.ParanSource == 1) {
                    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>&nbsp;停用</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>&nbsp;启用</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>&nbsp;编辑</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>&nbsp;删除</a> ", (object) bean.DictId);
                }
 
                //根据入口源显示【角色权限】
                if(source.Equals("SysRoleMenu"))
                    str1 += string.Format("<a href=\"javascript:;\" data-id=\"{0}\" class=\"action-permission btn  btn-primary btn-xs\"><i class=\"fa fa-cog\"></i>&nbsp;角色权限</a> ", (object) bean.DictValue);
                str1 += "</td>";
                str1 += "</tr>";
            }
        }
        else
            str1 += "<tr><td colspan=\"9\" 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) ) {
            if (dictType.Equals("USER_ROLE"))
            {
                throw new ArgumentException("角色编码不能为空,请输入!");
            }
            else
            {
                throw new ArgumentException("字典数据键值不能为空,请输入!");
            }
        }
        if (string.IsNullOrEmpty(dictLabel) ) {
            if (dictType.Equals("USER_ROLE"))
            {
                throw new ArgumentException("角色名称不能为空,请输入!");
            }
            else
            {
                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) ) {
            if (dictType.Equals("USER_ROLE"))
            {
                throw new ArgumentException("角色编码不能为空,请输入!");
            }
            else
            {
                throw new ArgumentException("字典数据键值不能为空,请输入!");
            }
        }
        if (string.IsNullOrEmpty(dictLabel) ) {
            if (dictType.Equals("USER_ROLE"))
            {
                throw new ArgumentException("角色名称不能为空,请输入!");
            }
            else
            {
                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;
    }
 
}