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
using System;
using System.Collections.Generic;
using System.Text;
using Model;
using System.Data;
using Common;
using System.Collections;
using Commom.Utility;
 
namespace BLL
{
    public class DALDepartMent:IDALDepartMent
    {
        public IList<DepartMent> GetList()
        {
            try
            {
                IList<DepartMent> ls = new List<DepartMent>();
                StringBuilder strSql = new StringBuilder();
                strSql.Append("Select guid,(DepartNum+'-'+DepartName) as DepartName from DepartMent where IsDel != 1;");
 
                IDataReader dt = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql);        
 
                ls = ModelConvertHelper<DepartMent>.DataReaderToModel(dt);
 
                return ls;
            }
            catch
            {
                throw new NotImplementedException();
            }
        }
        public IList<DepartMent> GetList(AjaxDepartList Json, ref PageInfo page)
        {
            try
            {
 
                IList<DepartMent> list = new List<DepartMent>();
                StringBuilder strSql = new StringBuilder();
                List<SqlParam> para = new List<SqlParam>();
                strSql.Append("Select * from View_GetDepart ");
 
                if (Json.DepartNum != null && Json.DepartNum != "")
                {
                    if (para.Count < 1) strSql.Append("where "); else strSql.Append(" and ");
                    strSql.Append("DepartNum like '%' + @DepartNum + '%' ");
                    para.Add(new SqlParam("@DepartNum", Json.DepartNum));
                }
 
                if (Json.DepartName != null && Json.DepartName != "")
                {
                    if (para.Count < 1) strSql.Append("where "); else strSql.Append(" and ");
                    strSql.Append("DepartName like '%' + @DepartName + '%'  ");
                    para.Add(new SqlParam("@DepartName", Json.DepartName));
                }
 
                if (para.Count < 1)
                {
                    strSql.Append(" Where  IsDel!=1");
                }
                else
                {
                    strSql.Append(" and IsDel!=1");
                }
 
                SqlParam[] param = null;
                if (para != null)
                    param = para.ToArray();
 
                DataTable dt = DataFactory.SqlDataBase().GetPageList(strSql.ToString(), param, "Ord", "DESC", ref page);
                list = ModelConvertHelper<DepartMent>.DataTableToModel(dt);
 
                return list;
            }
            catch
            {
                throw new NotImplementedException();
            }
 
        }
        public DepartMent GetModel(string DepartNum)
        {
            try
            {
                DepartMent us = null;
                StringBuilder strSql = new StringBuilder();
                strSql.Append("Select DepartNum,DepartName,AccessCode,IsDel,Demo from View_GetDepart where ");
                strSql.Append("DepartNum = @DepartNum ");
                strSql.Append("and IsDel != 1");
                SqlParam[] para = new SqlParam[]
                {
                    new SqlParam("@DepartNum", DepartNum),
                };
 
                IDataReader dt = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql, para);
 
                us = ModelConvertHelper<DepartMent>.ReaderToModel(dt);
 
                return us;
            }
            catch
            {
                throw new NotImplementedException();
            }
        }
        public bool Add(DepartMent model)
        {
            bool result = false;
            try
            {
                Hashtable ht = new Hashtable();
                ht["DepartNum"] = model.DepartNum.AddQuotes();
                ht["DepartName"] = model.DepartName.AddQuotes();
                ht["AccessCode"] = model.AccessCode.AddQuotes();
                ht["Ord"] = "(select isnull(Max(Ord),0) from DepartMent) + 1";
                ht["IsDel"] = 0;
                ht["CreatUser"] = "'" + model.CreatUser + "'";
                ht["UpdateTime"] = "GetDate()";
                ht["CreatTime"] = "GetDate()";
                ht["Demo"] = "'" + model.Demo + "'";
                ht["UpdateUser"] = "'" + model.CreatUser + "'";
 
                int _ret = DataFactory.SqlDataBase().InsertByHashtableNullParam("DepartMent", ht);
                if (_ret == 1) 
                {
                    result = true;
                } 
 
                return result;
            }
            catch
            {
                return result;
            }
        }
        public bool Update(DepartMent model)
        {
            bool result = false;
            try
            {
                Hashtable ht = new Hashtable();
                ht["DepartName"] = string.IsNullOrEmpty(model.DepartName) ? "''" : "'" + model.DepartName + "'";
                ht["DepartNum"] = string.IsNullOrEmpty(model.DepartName) ? "''" : "'" + model.DepartNum + "'";
                ht["AccessCode"] = model.AccessCode.AddQuotes();
                ht["UpdateTime"] = "GetDate()";
                ht["UpdateUser"] = string.IsNullOrEmpty(model.UpdateUser) ? "''" : "'" + model.UpdateUser + "'";
                ht["Demo"] = string.IsNullOrEmpty(model.Demo) ? "''" : "'" + model.Demo + "'";
                string ID = "'" + model.ID + "'";
 
                int _ret = DataFactory.SqlDataBase().UpdateByHashtable("DepartMent", nameof(model.ID), ID, ht);
                if (_ret == 1) 
                {
                    result = true;
                } 
 
                return result;
            }
            catch
            {
                return result;
            }
        }
        public bool IsExist(AjaxDepartInfo model)
        {
            bool result = false;
            try
            {
                StringBuilder sbStr = new StringBuilder();
                sbStr.Append("select count(id) from DepartMent");
                sbStr.Append(" where isdel = 0 and (DepartNum  = "+model.DepartNum.AddQuotes());
                sbStr.Append(" or DepartName = " + model.DepartName.AddQuotes() + ") ");
                if (model.Operation == "Edit") 
                {
                    sbStr.Append("and DepartNum != " + model.DepartNum.AddQuotes() + ";");
                }
 
                DataRow row = DataFactory.SqlDataBase().GetDataRowBySQL(sbStr);
                if (row[0].ToString() != "0")
                {
                    result = true;
                } 
 
                return result;
            }
            catch
            {
                return result;
            }
        }
        public DataTable GetDataTable(string[] strWhere)
        {
            DataTable dt = null;
            try
            {
                int index = 0;
                string str = "@DepartNum" + index;
                SqlParam[] param = new SqlParam[strWhere.Length];
                StringBuilder sql = new StringBuilder();
                sql.Append("Select DepartNum as 角色编号, DepartName as 角色名,CreatUser as 创建人,CreatTime as 创建时间,UpdateUser as 更新人,UpdateTime as 更新时间,Demo as 备注 FROM View_GetDepart where DepartNum in (");
 
                for (int i = 0; i < param.Length - 1; i++)
                {
                    string obj2 = strWhere[i];
                    str = "@DepartNum" + index;
                    sql.Append(str).Append(",");
                    param[index] = new SqlParam(str, obj2);
                    index++;
                }
                str = "@DepartNum" + 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 bool BatchDelete(string[] DepartNum)
        {
            bool result = false;
            try
            {
                //int dt = DataFactory.SqlDataBase().IsExist("DepartMent", "ID", DepartNum);
                //if (dt >= DepartNum.Length)
                //{
                    StringBuilder sql = new StringBuilder();
                    foreach (string departNum in DepartNum) 
                    {
                        sql.Append("update DepartMent set IsDel=1 where ID='" + departNum + "';");
                    }
 
                    int _ret = DataFactory.SqlDataBase().ExecuteBySql(sql);
                    if (_ret >= DepartNum.Length) 
                    {
                        result = true;
                    }
                //}
                return result;
            }
            catch
            {
                return result;
            }
        }
 
        /// <summary>
        /// 验证该部门是否包含员工
        /// </summary>
        /// <param name="DepartNum"></param>
        /// <returns></returns>
        public string IsChecks(string[] DepartNum)
        {
            try
            {
                string result = "";
                foreach (string departNum in DepartNum)
                {
                    StringBuilder sql = new StringBuilder();
                    // 验证是否存在获取部门信息
                    sql.Append("select guid,DepartNum+DepartName as name,isdel from DepartMent where id = '" + departNum + "';");
                    DataRow row = DataFactory.SqlDataBase().GetDataRowBySQL(sql);
                    if (row["guid"].ToString() == "1") 
                    {
                        result += row["name"].ToString() + ":已删除!";
                        continue;
                    }
 
                    sql.Clear();
                    sql.Append("select count(*) from userinfo where DepartNum = '"+ row["guid"].ToString()+"';");       
                    DataRow rowUser = DataFactory.SqlDataBase().GetDataRowBySQL(sql);
                    if (rowUser[0].ToString() != "0")
                    {
                        result += row["name"].ToString() + ":请先移除所属员工。";
                    }
                }
 
                return result;
            }
            catch
            {
                return "错误";
            }
        }
    }
}