bklLiudl
2024-07-23 675b8bcc4a3630d95e3d0b97d933e63442075ecb
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
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
 
using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using Common;
using System.Collections;
 
namespace BLL
{
    public class DALUserInfo : IDALUserInfo
    {
        public bool IsExist(string name, string value)
        {
            bool result = false;
            try
            {
                string[] para = new string[] { value };
                int dt = DataFactory.SqlDataBase().IsExist("UserInfo", name, para);
                if (dt > 0) result = true;
                return result;
            }
            catch
            {
                throw new NotImplementedException();
            }
        }
        public bool IsExist(Hashtable ht)
        {
            bool result = false;
            try
            {
                int dt = DataFactory.SqlDataBase().IsExist("UserInfo", ht);
                if (dt > 0) result = true;
                return result;
            }
            catch
            {
                throw new NotImplementedException();
            }
        }
        public bool Add(UserInfo model, string loginUser)
        {
            bool result = false;
            try
            {
                Hashtable ht = new Hashtable();
 
                ht["UserCode"] = "'" + model.UserCode + "'";
                ht["Username"] = "'" + model.Username + "'";
                ht["Pwd"] = "'" + Md5Helper.Md5(model.Pwd, 32) + "'";
                ht["RealName"] = "'" + model.RealName + "'";
                ht["RoleNum"] = "'" + model.RoleName + "'";
                ht["DepartNum"] = "'" + model.DepartName + "'";
                ht["Mobile"] = "'" + model.Mobile + "'";
                ht["Phone"] = "'" + model.Phone + "'";
                ht["Email"] = "'" + model.email + "'";
                ht["Ord"] = "(select isnull(Max(Ord),0) from UserInfo) + 1";
                ht["IsDel"] = 0;
                ht["CreatUser"] = "'" + model.CreatUser + "'";
                ht["UpdateTime"] = "GetDate()";
                ht["CreatTime"] = "GetDate()";
                ht["Demo"] = "'" + model.Demo + "'";
                ht["UpdateUser"] = "'" + model.CreatUser + "'";
                ht["Sex"] = "" + model.Sex + "";
                ht["IDcard"] = "'" + model.IDcard + "'";
                ht["Address"] = "'" + model.Address + "'";
 
                int _ret = DataFactory.SqlDataBase().InsertByHashtableNullParam("UserInfo", ht);
 
                if (_ret == 1) result = true;
 
                return result;
 
            }
            catch
            {
                return result;
            }
        }
 
        public bool Update(UserInfo model)
        {
            bool result = false;
            try
            {
                Hashtable ht = new Hashtable();
 
                ht["RealName"] = string.IsNullOrEmpty(model.RealName) ? "''" : "'" + model.RealName + "'";
                ht["RoleNum"] = "'" + model.RoleName + "'";
                ht["DepartNum"] = "'" + model.DepartName + "'";
                ht["Mobile"] = string.IsNullOrEmpty(model.Mobile) ? "''" : "'" + model.Mobile + "'";
                ht["Phone"] = string.IsNullOrEmpty(model.Phone) ? "''" : "'" + model.Phone + "'";
                ht["Email"] = string.IsNullOrEmpty(model.email) ? "''" : "'" + model.email + "'";
                ht["UpdateTime"] = "GetDate()";
                ht["UpdateUser"] = string.IsNullOrEmpty(model.UpdateUser) ? "''" : "'" + model.UpdateUser + "'";
                ht["Demo"] = string.IsNullOrEmpty(model.Demo) ? "''" : "'" + model.Demo + "'";
                ht["Sex"] = "'" + model.Sex + "'";
                ht["IDcard"] = string.IsNullOrEmpty(model.IDcard) ? "''" : "'" + model.IDcard + "'";
                ht["Address"] = string.IsNullOrEmpty(model.Address) ? "''" : "'" + model.Address + "'";
 
                string UserCode = "'" + model.UserCode + "'";
 
                int _ret = DataFactory.SqlDataBase().UpdateByHashtable("UserInfo", "UserCode", UserCode, ht);
 
                if (_ret == 1) result = true;
 
                return result;
 
            }
            catch
            {
                return result;
            }
        }
        public bool Update(string UserCode, string Pwd, string UpdateUser)
        {
            bool result = false;
            try
            {
                Hashtable ht = new Hashtable();
 
                ht["Pwd"] = string.IsNullOrEmpty(Pwd) ? "''" : "'" + Md5Helper.Md5(Pwd, 32) + "'";
                if (UserCode != null)
                {
                    ht["UpdateUser"] = "'" + UserCode + "'";
                    ht["UpdateTime"] = "getdate()";
                    UserCode = "'" + UserCode + "'";
                }
                int _ret = DataFactory.SqlDataBase().UpdateByHashtable("UserInfo", "UserCode", UserCode, ht);
 
                if (_ret == 1) result = true;
 
                return result;
 
            }
            catch
            {
                return result;
            }
        }
        public UserInfo DataRowToModel(DataRow row)
        {
            throw new NotImplementedException();
        }
 
        public bool Delete(string UserCode)
        {
            bool result = false;
            try
            {
                Hashtable ht = new Hashtable();
 
                int _ret = DataFactory.SqlDataBase().DeleteData("UserInfo", "UserCode", UserCode);
 
                if (_ret == 1) result = true;
 
                return result;
 
            }
            catch
            {
                return result;
            }
        }
 
        public bool BatchDelete(string[] UserCode)
        {
            bool result = false;
            try
            {
                int dt = DataFactory.SqlDataBase().IsExist("UserInfo", "UserCode", UserCode);
                if (dt >= UserCode.Length)
                {
                    StringBuilder sql = new StringBuilder();
                    foreach (string code in UserCode)
                    {
                        sql.Append("update UserInfo set IsDel=1 where UserCode='" + code + "';");
                    }
 
                    int _ret = DataFactory.SqlDataBase().ExecuteBySql(sql);
                    if (_ret > UserCode.Length) result = true;
                }
                return result;
 
            }
            catch
            {
                return result;
            }
        }
 
        public bool StartUser(string[] UserCode)
        {
            bool result = false;
            try
            {
                int dt = DataFactory.SqlDataBase().IsExist("UserInfo", "UserCode", UserCode);
                if (dt >= UserCode.Length)
                {
                    StringBuilder sql = new StringBuilder();
                    foreach (string code in UserCode)
                    {
                        sql.Append("update UserInfo set IsDel=0 where UserCode='" + code + "';");
                    }
 
                    int _ret = DataFactory.SqlDataBase().ExecuteBySql(sql);
                    if (_ret > UserCode.Length) result = true;
                }
                return result;
 
            }
            catch
            {
                return result;
            }
        }
 
        public IList<UserInfo> GetList(string strWhere)
        {
            throw new NotImplementedException();
        }
 
        public IList<UserInfo> GetList(AjaxUserList Json,ref PageInfo pageInfo)
        {
            try {
 
                IList<UserInfo> list = new List<UserInfo>();
                StringBuilder strSql = new StringBuilder();
                List<SqlParam> para = new List<SqlParam>();
                strSql.Append("Select UserCode,UserName,RealName,Phone,Sex,IDcard,Mobile, ");
                strSql.Append("Email,RoleName,DepartName,CreatUser,CreatTime,UpdateUser,UpdateTime,");
                strSql.Append("Demo,Ord,IsDel,case when IsDel = 0 then '启用' else '停用' end as Statu ");
                strSql.Append("from View_UserInfo ");
 
                if (Json.UserCode != null && Json.UserCode != "")
                {
                    if (para.Count <1 ) strSql.Append("where "); else strSql.Append(" and ");
                    strSql.Append("UserCode like '%' + @UserCode + '%' ");
                    para.Add(new SqlParam("@UserCode", Json.UserCode));
                }
 
                if (Json.UserName != null && Json.UserName != "")
                {
                    if (para.Count < 1) strSql.Append("where "); else strSql.Append(" and ");
                    strSql.Append("Username like '%' + @Username + '%'  ");
                    para.Add(new SqlParam("@Username", Json.UserName));
                }
 
                if (Json.RoleNum != null && Json.RoleNum != "")
                {
                    string RoleName = Json.RoleNum;
                    if (para.Count <1) strSql.Append("where "); else strSql.Append(" and ");
                    strSql.Append("RoleNum = '" + RoleName + "' ");
                    para.Add(new SqlParam("@RoleNum", Json.RoleNum));
                }
 
                if (Json.DepartNum != null && Json.DepartNum != "")
                {
                    string DepartMent = Json.DepartNum;
                    if (para.Count <1) strSql.Append("where ");else strSql.Append(" and ");
                    strSql.Append("DepartNum = '" + DepartMent +" '");
                    para.Add(new SqlParam("@DepartMent", Json.DepartNum));
                }
                if (Json.IsDel != "-1") 
                {
                    string IsDel = Json.IsDel;
                    if (para.Count < 1) strSql.Append("where "); else strSql.Append(" and ");
                    strSql.Append("IsDel = '" + IsDel + " '");
                    para.Add(new SqlParam("@IsDel", Json.IsDel));
                }
                if (para.Count < 1 )
                {
                    strSql.Append(" Where UserCode <> 'SuperUser'");
                }
                else
                {
                    strSql.Append(" and UserCode <> 'SuperUser'");
                }
 
 
                SqlParam[] param = null; 
                if (para != null)
                     param = para.ToArray();
               
 
                DataTable dt = DataFactory.SqlDataBase().GetPageList(strSql.ToString(), param, "isdel", "ASC", ref pageInfo);
                list = ModelConvertHelper<UserInfo>.DataTableToModel(dt);
 
                return list;
            }
            catch
            {
                throw new NotImplementedException();
            }
        }
 
        public UserInfo GetModel(string username, string pwd)
        {
            try
            {
                UserInfo us = null;
                StringBuilder strSql = new StringBuilder();
                strSql.Append("SELECT ui.*,dm.AccessCode FROM UserInfo ui LEFT JOIN dbo.DepartMent dm ON ui.DepartNum=dm.guid WHERE ");
                strSql.Append("ui.Username = @Username ");
                strSql.Append("and ui.Pwd = @Pwd ");
                strSql.Append("and ui.IsDel != 1");
                SqlParam[] para = new SqlParam[]
                {
                new SqlParam("@Username", username),
                new SqlParam("@Pwd", Md5Helper.Md5(pwd, 32))
                };
 
                IDataReader dt = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql, para);
 
                //IList<UserInfo> Lu = ModelConvertHelper<UserInfo>.DataReaderToModel(dt);
 
                us = ModelConvertHelper<UserInfo>.ReaderToModel(dt);  
                
                return us; 
            }
            catch(Exception e)
            {
                throw new NotImplementedException();
            }
        }
        public UserInfo GetModel(string usercode)
        {
            try
            {
                UserInfo us = null;
                StringBuilder strSql = new StringBuilder();
                strSql.Append("Select UserCode,UserName,RealName,Phone,Mobile,Email,RoleName,RoleNum,DepartName,DepartNum,");
                strSql.Append("CreatUser,CreatTime,UpdateUser,UpdateTime,Demo,Ord,IsDel,Sex,IDcard,Address from View_UserInfo where ");
                strSql.Append("UserCode = @UserCode ");
                //strSql.Append("and IsDel != 1");
                SqlParam[] para = new SqlParam[]
                {
                    new SqlParam("@UserCode", usercode),
                };
 
                IDataReader dt = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql, para);
 
                us = ModelConvertHelper<UserInfo>.ReaderToModel(dt);
 
                return us;
            }
            catch
            {
                throw new NotImplementedException();
            }
        }
 
 
        public DataTable GetDataTable(string[] strWhere)
        {
            DataTable dt = null;
            try
            {
                int index = 0;
                string str = "@UserCode" + index;
                SqlParam[] param = new SqlParam[strWhere.Length];
                StringBuilder sql = new StringBuilder();
                sql.Append("Select Username as 用户名,UserCode as 员工编号,RealName as 真名,Email as 邮箱,Mobile as 手机,Phone as 固话,CreatTime as 创建时间,DepartName as 部门,RoleName as 角色,Demo as 备注 FROM View_UserInfo where UserCode in (");
 
                for (int i = 0; i < param.Length - 1; i++)
                {
                    string obj2 = strWhere[i];
                    str = "@UserCode" + index;
                    sql.Append(str).Append(",");
                    param[index] = new SqlParam(str, obj2);
                    index++;
                }
                str = "@UserCode" + index;
                sql.Append(str);
                param[index] = new SqlParam(str, strWhere[index]);
                sql.Append(")");
 
                dt = DataFactory.SqlDataBase().GetDataTableBySQL(sql, param,"");
 
                return dt;
 
            }
            catch
            {
                throw new NotImplementedException();
            }
          
        }
 
        public DataTable GetDataTable(int PageSize, int PageIndex, string strWhere)
        {
            throw new NotImplementedException();
        }
 
        public List<LoginLog> GetLogInUserRecordList()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select Top(1000) * from Login_Log order by LoginTime desc");
 
            strSql.Append("Select Top(1000) Username as 用户名,UserCode as 员工编号,RealName as 真名,Email as 邮箱,Mobile as 手机,Phone as 固话,CreatTime as 创建时间,DepartName as 部门,RoleName as 角色,Demo as 备注 FROM Login_Log order by LoginTime desc ");
 
            List<LoginLog> list = new List<LoginLog>();
            //DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(strSql);
            //list = (List<LoginLog>)ModelConvertHelper<LoginLog>.DataTableToModel(dt);
            return list;
        }
 
 
    }
}