1
yhj
2024-07-24 5e5d945e91568b973faa27d8ab0bcef99fc4a6c5
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
#region
 
using System;
using System.Collections.Generic;
using System.Data;
using CSFramework.DB;
using CSFrameworkV5.Common;
using CSFrameworkV5.Core;
using CSFrameworkV5.Core.CodeGenerator;
using CSFrameworkV5.Interfaces;
using CSFrameworkV5.Models;
using tb_MyGroupUser = CSFrameworkV5.Interfaces.tb_MyGroupUser;
 
///*************************************************************************/
///*
///* 文件名    :dalUserGroup.cs                                
///* 程序说明  : 用户组数据字典的DAL层
///* 原创作者  :www.csframework.com 
///* 
///* Copyright 2006-2021 wwww.csframework.com, 保留所有权利.
///*
///**************************************************************************/
 
#endregion
 
namespace CSFrameworkV5.DataAccess
{
    /// <summary>
    ///     用户组数据字典的DAL层
    /// </summary>
    [DefaultORM_UpdateMode(typeof(tb_MyGroup), true)]
    public class dalUserGroup : dalBaseDataDict, IBridge_UserGroup
    {
        public dalUserGroup(Loginer loginer)
            : base(loginer)
        {
            _KeyName = tb_MyGroup.__KeyName;
            _TableName = tb_MyGroup.__TableName;
            _ModelType = typeof(tb_MyGroup);
            _Database = DatabaseProvider.SystemDatabase;
        }
 
        /// <summary>
        ///     添加对象
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public int Add(List<tb_MyGroupUser> data)
        {
            var db = new DbFramework(_Database);
            var i = db.AddList(data, "isid");
            return i;
        }
 
        public bool DeleteGroupData(string groupCode)
        {
            var sp = _Database.CreateSqlProc("usp_DeleteGroupData");
            sp.AddParam("GroupCode", DbType.String, groupCode);
            sp.AddParam("DataSetID", DbType.String, _Loginer.DBID);
            object o = _Database.ExecuteCommand(sp.Command);
            return true;
        }
 
        public bool DeleteGroupRights(string groupCode)
        {
            var sp = _Database.CreateSqlProc("usp_DeleteGroupRights");
            sp.AddParam("GroupCode", DbType.String, groupCode);
            sp.AddParam("DataSetID", DbType.String, _Loginer.DBID);
            object o = _Database.ExecuteCommand(sp.Command);
            return true;
        }
 
        public bool DeleteGroupUser(string groupCode, string account)
        {
            var sp = _Database.CreateSqlProc("usp_DeleteGroupUser");
            sp.AddParam("GroupCode", DbType.String, groupCode);
            sp.AddParam("Account", DbType.String, account);
            sp.AddParam("DataSetID", DbType.String, _Loginer.DBID);
            var i = _Database.ExecuteCommand(sp.Command);
            return i > 0;
        }
 
        public DataTable GetGroup4Picker()
        {
            var sql =
                $"SELECT GroupCode,GroupName FROM tb_MyGroup WHERE DataSetID={_Database.ParamSymboName}DataSetID ORDER BY GroupCode";
 
            var cmd = _Database.CreateCommand(sql);
            cmd.AddParam("DataSetID", _Loginer.DBID);
            return _Database.GetTable(cmd.Command, tb_MyGroup.__TableName);
        }
 
        public DataTable GetGroupActions(string groupCode)
        {
            var sp = _Database.CreateSqlProc("usp_GetGroupActions");
            sp.AddParam("GroupCode", DbType.String, groupCode);
            sp.AddParam("DataSetID", DbType.String, _Loginer.DBID);
            return _Database.GetTable(sp.Command, "usp_GetGroupActions");
        }
 
        public DataTable GetGroupByUser(string account)
        {
            var sql =
                $"SELECT * FROM tb_MyGroupUser WHERE DataSetID={_Database.ParamSymboName}DataSetID AND Account={_Database.ParamSymboName}Account";
            var cmd = _Database.CreateSqlProc("usp_GetGroup");
            cmd.AddParam("DatasetID", _Loginer.DBID);
            cmd.AddParam("Account", account);
            return _Database.GetTable(cmd.Command, tb_MyGroup.__TableName);
        }
 
        /// <summary>
        ///     获取指定用户组的角色
        /// </summary>
        /// <param name="groupCode">组编号</param>
        /// <returns></returns>
        public DataTable GetGroupRoles(string groupCode)
        {
            var sp = _Database.CreateSqlProc("usp_GetGroupRoles");
            sp.AddParam("GroupCode", DbType.String, groupCode);
            sp.AddParam("DataSetID", DbType.String, _Loginer.DBID);
            return _Database.GetTable(sp.Command, tb_MyGroupRole.__TableName);
        }
 
        /// <summary>
        ///     取当前用户所属的角色
        /// </summary>
        /// <param name="currentGroupCode">组名,作为一个返回字段</param>
        /// <param name="currentUser">当前用户</param>
        /// <returns></returns>
        public DataTable GetGroupRoles4Picker(string currentGroupCode,
            string currentUser)
        {
            var sp = _Database.CreateSqlProc("usp_GetGroupRoles4Picker");
            sp.AddParam("GroupCode", DbType.String, currentGroupCode);
            sp.AddParam("UserAccount", DbType.String, currentUser);
            sp.AddParam("DataSetID", DbType.String, _Loginer.DBID);
            return _Database.GetTable(sp.Command, tb_MyGroupRole.__TableName);
        }
 
        public DataTable GetGroupUsers(string groupCode)
        {
            var sp = _Database.CreateSqlProc("usp_GetGroupUsers");
            sp.AddParam("GroupCode", DbType.String, groupCode);
            sp.AddParam("DataSetID", DbType.String, _Loginer.DBID);
            return _Database.GetTable(sp.Command,
                Models.tb_MyGroupUser.__TableName);
        }
 
        public DataTable GetGroupUsers4Picker(string groupCode)
        {
            var sp = _Database.CreateSqlProc("usp_GetGroupUsers4Picker");
            sp.AddParam("GroupCode", DbType.String, groupCode);
            sp.AddParam("DataSetID", DbType.String, _Loginer.DBID);
            return _Database.GetTable(sp.Command,
                Models.tb_MyGroupUser.__TableName);
        }
 
        public DataTable GetGroupUsers4TreeList()
        {
            var sp = _Database.CreateSqlProc("usp_GetGroupUsers4TreeList");
            sp.AddParam("DataSetID", DbType.String, _Loginer.DBID);
            return _Database.GetTable(sp.Command,
                Models.tb_MyGroupUser.__TableName);
        }
 
        public DataTable GetMyGroups4Picker(string account)
        {
            var cmd = _Database.CreateSqlProc("usp_GetMyGroups4Picker");
            cmd.AddParam("Account", account);
            cmd.AddParam("DatasetID", _Loginer.DBID);
            return _Database.GetTable(cmd.Command, tb_MyGroup.__TableName);
        }
 
        public DataTable Search(string GroupCode, string GroupName,
            string AttributeCodes, string Owner1,
            string OwnerTel1)
        {
            var cmd = _Database.CreateSqlProc("usp_GetGroup");
            cmd.AddParam("DatasetID", _Loginer.DBID);
            cmd.AddParam("GroupCode", GroupCode);
            cmd.AddParam("GroupName", GroupName);
            cmd.AddParam("AttributeCodes", AttributeCodes);
            cmd.AddParam("Owner1", Owner1);
            cmd.AddParam("OwnerTel1", OwnerTel1);
            return _Database.GetTable(cmd.Command, tb_MyGroup.__TableName);
        }
 
        public bool SetOwner(string ownerType, string groupCode, string account)
        {
            var sql =
                $"UPDATE tb_MyGroup SET {ownerType}={_Database.ParamSymboName}Account WHERE DataSetID={_Database.ParamSymboName}DataSetID AND GroupCode={_Database.ParamSymboName}GroupCode";
            var sp = _Database.CreateCommand(sql);
            sp.AddParam("Account", DbType.String, account);
            sp.AddParam("DataSetID", DbType.String, _Loginer.DBID);
            sp.AddParam("GroupCode", DbType.String, groupCode);
            var i = _Database.ExecuteCommand(sp.Command);
            return i == 1;
        }
 
        /// <summary>
        ///     根据表名获取该表的SQL命令生成器
        /// </summary>
        /// <param name="tableName">表名</param>
        /// <returns></returns>
        protected override IGenerateSqlCommand CreateSqlGenerator(
            DataTable table)
        {
            Type ORM = null;
 
            if (table.TableName == tb_MyGroup.__TableName)
                ORM = typeof(tb_MyGroup);
 
            if (table.TableName == Models.tb_MyGroupUser.__TableName)
                ORM = typeof(Models.tb_MyGroupUser);
 
            if (table.TableName == tb_MyGroupRole.__TableName)
                ORM = typeof(tb_MyGroupRole);
 
            if (table.TableName == tb_MyRoleActions.__TableName)
                ORM = typeof(tb_MyRoleActions);
 
            if (table.TableName == tb_MyFormTagName.__TableName)
                ORM = typeof(tb_MyFormTagName);
 
            if (ORM == null) throw new Exception(table.TableName + "表没有ORM模型!");
 
            //支持两种SQL命令生成器
            return new GenerateSqlCmdByTableFields(ORM, table,
                GeneratorFactory);
        }
 
        /// <summary>
        ///     删除用户组
        /// </summary>
        /// <param name="keyValue">用户组编号</param>
        /// <returns></returns>
        public override bool Delete(string keyValue)
        {
            throw new CustomException(
                "当前功能不支持此方法!请使用DeleteGroupData或DeleteGroupRights");
        }
 
        public override DataTable GetLookupData()
        {
            var sql =
                $"SELECT RowID,DataSetID,GroupCode,GroupName,ParentGroupCode,Owner1,Owner2 FROM tb_MyGroup WHERE DataSetID={_Database.ParamSymboName}DataSetID ORDER BY GroupName";
            var cmd = _Database.CreateCommand(sql);
            cmd.AddParam("DataSetID", _Loginer.DBID);
            return _Database.GetTable(cmd.Command, tb_MyGroup.__TableName);
        }
 
        /// <summary>
        ///     获取所有用户组
        /// </summary>
        /// <returns></returns>
        public override DataTable GetSummaryData()
        {
            AssertTableName();
 
            var sql =
                $"SELECT * FROM tb_MyGroup WHERE DataSetID={_Database.ParamSymboName}DataSetID ORDER BY GroupCode";
            var cmd = _Database.CreateCommand(sql);
            cmd.AddParam("DataSetID", _Loginer.DBID);
            return _Database.GetTable(cmd.Command, TableName);
        }
    }
}