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
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using Model;
using Common;
using System.Collections;
 
namespace BLL
{
    public class DALResMenu : IDALResMenu
    {
        public IList<ResMenu> GetParentList()
        {
            try
            {
                IList<ResMenu> ls = new List<ResMenu>();
                StringBuilder strSql = new StringBuilder();
                strSql.Append("select ResNum, case ParentNum when '' then '>'+ ResName else '&nbsp;&nbsp;' + ResName end as ParentName,IsDel,[level] from dbo.ResMenu where IsDel !=1 and [level] in ('1','2') order by ord");
 
                IDataReader dt = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql);
                ls = ModelConvertHelper<ResMenu>.DataReaderToModel(dt);
 
                return ls;
            }
            catch
            {
                throw new NotImplementedException();
            }
        }
 
        public IList<ResMenu> GetList(AjaxResMenuList Json, ref PageInfo page)
        {
            try
            {
 
                IList<ResMenu> list = new List<ResMenu>();
                StringBuilder strSql = new StringBuilder();
                List<SqlParam> para = new List<SqlParam>();
                strSql.Append("Select ResNum,ResName,ParentName,ResType,CssName,Url,CreatUser,CreatTime,UpdateUser,UpdateTime,Ord,IsDel from View_GetResMenu where IsDel = 0 ");
 
                if (Json.ResNum != null && Json.ResNum != "")
                {
                    //if (para.Count < 1) strSql.Append("where "); else strSql.Append(" and ");
                    strSql.Append(" and ResNum like '%' + @ResNum + '%' ");
                    para.Add(new SqlParam("@ResNum", Json.ResNum));
                }
 
                if (Json.ResName != null && Json.ResName != "")
                {
                    //if (para.Count < 1) strSql.Append("where "); else strSql.Append(" and ");
                    strSql.Append(" and ResName like '%' + @ResName + '%'  ");
                    para.Add(new SqlParam("@ResName", Json.ResName));
                }
 
                if (Json.ParentNum != null && Json.ParentNum != "") 
                {
                    //if (para.Count < 1) strSql.Append("where "); else strSql.Append(" and ");
                    strSql.Append(" and ( ParentNum = @ParentNum  or ResNum = @ParentNumto )");
                    para.Add(new SqlParam("@ParentNum", Json.ParentNum));
                    para.Add(new SqlParam("@ParentNumto", Json.ParentNum));
                }
 
 
                //strSql.Append("Order By ResNum");
                SqlParam[] param = null;
                if (para != null)
                    param = para.ToArray();
 
                DataTable dt = DataFactory.SqlDataBase().GetPageList(strSql.ToString(), param, "Ord", "ASC", ref page);
                list = ModelConvertHelper<ResMenu>.DataTableToModel(dt);
 
                return list;
            }
            catch
            {
                throw new NotImplementedException();
            }
 
        }
 
        public IList<AjaxResMenuInfo> GetList()
        {
            try
            {
 
                IList<AjaxResMenuInfo> list = new List<AjaxResMenuInfo>();
                StringBuilder strSql = new StringBuilder();
              
                strSql.Append("Select ResNum,ResName,ParentNum,CssName,Url,IsDel from ResMenu where IsDel != 1 order by ord asc");
              
                DataTable dt = DataFactory.SqlDataBase().GetDataTableBySQL(strSql);
                list = ModelConvertHelper<AjaxResMenuInfo>.DataTableToModel(dt);
 
                return list;
            }
            catch
            {
                throw new NotImplementedException();
            }
 
        }
        public ResMenu GetModel(string ResNum)
        {
            try
            {
                ResMenu us = null;
                StringBuilder strSql = new StringBuilder();
                strSql.Append("Select ResNum,ResName,ParentName,ResType,CssName,Url,IsDel from View_GetResMenu where ");
                strSql.Append("ResNum = @ResNum ");
                strSql.Append("and IsDel != 1");
                SqlParam[] para = new SqlParam[]
                {
                    new SqlParam("@ResNum", ResNum),
                };
 
                IDataReader dt = DataFactory.SqlDataBase().GetDataReaderBySQL(strSql, para);
 
                us = ModelConvertHelper<ResMenu>.ReaderToModel(dt);
 
                return us;
            }
            catch
            {
                throw new NotImplementedException();
            }
        }
 
        public bool Add(ResMenu model)
        {
            bool result = false;
            try
            {
                Hashtable ht = new Hashtable();
 
                ht["ResNum"] = string.IsNullOrEmpty(model.ResNum) ? "''" : "'" + model.ResNum + "'";
                ht["ResName"] = string.IsNullOrEmpty(model.ResName) ? "''" : "'" + model.ResName + "'";
                ht["ParentNum"] = string.IsNullOrEmpty(model.ParentName) ? "''" : "(select ResNum from ResMenu where ResName = '" + model.ParentName + "')";
                ht["Ord"] = 0;
                ht["IsDel"] = 0;
                ht["CreatUser"] = "'" + model.CreatUser + "'";
                ht["UpdateTime"] = "GetDate()";
                ht["CreatTime"] = "GetDate()";
                ht["Url"] = string.IsNullOrEmpty(model.Url) ? "''" : "'" + model.Url + "'";
                ht["UpdateUser"] = "'" + model.CreatUser + "'";
                ht["CssName"] = string.IsNullOrEmpty(model.CssName) ? "''" : "'" + model.CssName + "'";
                ht["ResType"] = string.IsNullOrEmpty(model.ResType) ? "''" : "'" + model.ResType + "'";
 
                int _ret = DataFactory.SqlDataBase().InsertByHashtableNullParam("ResMenu", ht);
 
                if (_ret == 1) result = true;
                return result;
            }
            catch
            {
                return result;
            }
        }
 
        public bool Update(ResMenu model)
        {
            bool result = false;
            try
            {
                Hashtable ht = new Hashtable();
 
                //ht["ResNum"] = string.IsNullOrEmpty(model.ResNum) ? "''" : "'" + model.ResNum + "'";
                ht["ResName"] = string.IsNullOrEmpty(model.ResName) ? "''" : "'" + model.ResName + "'";
                ht["ParentNum"] = string.IsNullOrEmpty(model.ParentName) ? "''" : "(select ResNum from ResMenu where ResName = '" + model.ParentName + "')";
                ht["CssName"] = string.IsNullOrEmpty(model.CssName) ? "''" : "'" + model.CssName + "'";
                ht["ResType"] = string.IsNullOrEmpty(model.ResType) ? "''" : "'" + model.ResType + "'";
                ht["UpdateTime"] = "GetDate()";
                ht["UpdateUser"] = string.IsNullOrEmpty(model.UpdateUser) ? "''" : "'" + model.UpdateUser + "'";
                ht["Url"] = string.IsNullOrEmpty(model.Url) ? "''" : "'" + model.Url + "'";
 
                string ResNum = "'" + model.ResNum + "'";
 
                int _ret = DataFactory.SqlDataBase().UpdateByHashtable("ResMenu", nameof(model.ResNum), ResNum, ht);
 
                if (_ret == 1) result = true;
 
                return result;
 
            }
            catch
            {
                return result;
            }
        }
        public bool IsExist(string name, string value)
        {
            bool result = false;
            try
            {
                string[] para = new string[] { value };
                int dt = DataFactory.SqlDataBase().IsExist("ResMenu", name, para);
                if (dt > 0) result = true;
                return result;
            }
            catch
            {
                return result;
            }
 
        }
 
        public DataTable GetDataTable(string[] strWhere)
        {
            DataTable dt = null;
            try
            {
                int index = 0;
                string str = "@ResNum" + index;
                SqlParam[] param = new SqlParam[strWhere.Length];
                StringBuilder sql = new StringBuilder();
                sql.Append("Select ResNum as 菜单编号, ResName as 菜单名称,ParentName as 父级菜单,ResType as 类型,CssName as 样式,Url as 路径,CreatUser as 创建人,CreatTime as 创建时间,UpdateUser as 更新人,UpdateTime as 更新时间 FROM View_GetResMenu where ResNum in (");
 
                for (int i = 0; i < param.Length - 1; i++)
                {
                    string obj2 = strWhere[i];
                    str = "@ResNum" + index;
                    sql.Append(str).Append(",");
                    param[index] = new SqlParam(str, obj2);
                    index++;
                }
                str = "@ResNum" + 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[] ResNum)
        {
            bool result = false;
            try
            {
                int dt = DataFactory.SqlDataBase().IsExist("ResMenu", "ResNum", ResNum);
                if (dt >= ResNum.Length)
                {
                    int _ret = DataFactory.SqlDataBase().BatchDeleteData("ResMenu", "ResNum", ResNum);
                    if (_ret >= ResNum.Length) 
                    {
                        result = true;
                    } 
                }
                return result;
            }
            catch
            {
                return result;
            }
        }
    }
}