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
#region
 
using System;
using System.Collections.Generic;
using System.Data;
using CSFrameworkV5.Common;
using CSFrameworkV5.Core;
using CSFrameworkV5.DataAccess;
using CSFrameworkV5.Interfaces;
using CSFrameworkV5.Models;
using CSFrameworkV5.WebRef.SystemModule;
using tb_MyGroupUser = CSFrameworkV5.Interfaces.tb_MyGroupUser;
 
#endregion
 
namespace CSFrameworkV5.Business.BLL_Permission
{
    public class bllGroup : bllBaseDataDict
    {
        private IBridge_UserGroup _Bridge;
 
        private DataTable _GroupRoles;
 
        private DataTable _GroupUsers;
 
        public bllGroup()
        {
            _KeyFieldName = tb_MyGroup.__KeyName; //主键字段
            _SummaryTableName = tb_MyGroup.__TableName; //表名
            _DataDictBridge =
                BridgeFactory.CreateDataDictBridge(typeof(tb_MyGroup));
            _Bridge = CreateBridge(); //实例化桥接功能
        }
 
        public DataTable GroupRoles
        {
            get => _GroupRoles;
            set => _GroupRoles = value;
        }
 
        public DataTable GroupUsers
        {
            get => _GroupUsers;
            set => _GroupUsers = value;
        }
 
        public int Add(List<tb_MyGroupUser> data)
        {
            return _Bridge.Add(data);
        }
 
        private IBridge_UserGroup CreateBridge()
        {
            if (BridgeFactory.IsADODirect)
                return new dalUserGroup(Loginer.CurrentUser);
 
            if (BridgeFactory.IsWCFBridge) return new WCF_UserGroup();
 
            throw new CustomException(BridgeFactory.UNKNOW_BRIDGE_TYPE);
        }
 
        public override void CreateDataBinder(DataRow sourceRow)
        {
            base.CreateDataBinder(sourceRow);
 
            //新增记录,给帐套编号预设值
            if (_DataBinder.Rows[0].RowState == DataRowState.Added)
            {
                _DataBinder.Rows[0][tb_MyGroup.IsVisible] = 'Y';
                _DataBinder.Rows[0][tb_MyGroup.RowID] = Globals.NewRowID();
                _DataBinder.Rows[0][tb_MyGroup.DataSetID] =
                    Loginer.CurrentUser.DBID;
            }
        }
 
        //删除资料
        public override bool Delete(string keyValue)
        {
            return _Bridge.DeleteGroupData(keyValue);
        }
 
        public bool DeleteGroupData(string groupCode)
        {
            return _Bridge.DeleteGroupData(groupCode);
        }
 
        public bool DeleteGroupRights(string groupCode)
        {
            return _Bridge.DeleteGroupRights(groupCode);
        }
 
        public bool DeleteGroupUser(string groupCode, string account)
        {
            return _Bridge.DeleteGroupUser(groupCode, account);
        }
 
        private DataTable GetGroup4Picker(bool firstRowEmpty)
        {
            var dt = _Bridge.GetGroup4Picker();
            if (firstRowEmpty)
            {
                var row = dt.NewRow();
                row[tb_MyGroup.GroupCode] = "";
                row[tb_MyGroup.GroupName] = "";
                dt.Rows.InsertAt(row, 0);
                dt.AcceptChanges();
            }
 
            return dt;
        }
 
        public DataTable GetGroupByUser(string account)
        {
            return _Bridge.GetGroupByUser(account);
        }
 
        public DataTable GetGroupRoles(string groupCode)
        {
            return _Bridge.GetGroupRoles(groupCode);
        }
 
        public DataTable GetGroupRoles4Picker(string currentGroupCode,
            string currentUser)
        {
            return _Bridge.GetGroupRoles4Picker(currentGroupCode, currentUser);
        }
 
        public DataTable GetGroupUsers(string groupCode)
        {
            return _Bridge.GetGroupUsers(groupCode);
        }
 
        public DataTable GetGroupUsers4Picker(string groupCode)
        {
            return _Bridge.GetGroupUsers4Picker(groupCode);
        }
 
        public DataTable GetGroupUsers4TreeList()
        {
            return _Bridge.GetGroupUsers4TreeList();
        }
 
        public DataTable GetMyGroups4Picker(string account)
        {
            return _Bridge.GetMyGroups4Picker(account);
        }
 
        public DataTable Search(string GroupCode, string GroupName,
            string AttributeCodes, string Owner1,
            string OwnerTel1)
        {
            var dt = _Bridge.Search(GroupCode, GroupName, AttributeCodes,
                Owner1, OwnerTel1);
            _SummaryTable = dt;
            return dt;
        }
 
        public bool SetOwner(string ownerType, string groupCode, string account)
        {
            return _Bridge.SetOwner(ownerType, groupCode, account);
        }
 
        public bool Update(UpdateType updateType, DataTable dtGroupUsers,
            DataTable dtGroupRoles)
        {
            //创建一个副本用于保存
            var data = new DataSet();
 
            if (updateType == UpdateType.Add)
            {
                var groupCode =
                    ConvertEx.ToString(
                        _DataBinder.Rows[0][tb_MyGroup.GroupCode]);
 
                if (dtGroupUsers != null)
                    for (var i = 0; i <= dtGroupUsers.Rows.Count - 1; i++)
                        dtGroupUsers.Rows[i][Models.tb_MyGroupUser.GroupCode] =
                            groupCode;
 
                if (dtGroupRoles != null)
                    for (var i = 0; i <= dtGroupRoles.Rows.Count - 1; i++)
                        dtGroupRoles.Rows[i][tb_MyGroupRole.GroupCode] =
                            groupCode;
            }
 
            if (dtGroupUsers != null) data.Tables.Add(dtGroupUsers);
 
            if (dtGroupRoles != null) data.Tables.Add(dtGroupRoles);
 
            //调用数据层的方法提交数据
            if (data.Tables.Count > 0) return _DataDictBridge.Update(data);
 
            throw new Exception("您没有修改数据,不需要保存!");
        }
 
        #region 父级组参考数据
 
        private DataTable _GroupLookupData;
 
        /// <summary>
        ///     父级组参考数据
        /// </summary>
        public DataTable GroupLookupData
        {
            get
            {
                if (_GroupLookupData == null) ReloadGroupLookupData();
 
                return _GroupLookupData;
            }
        }
 
        public void ReloadGroupLookupData()
        {
            _GroupLookupData = GetGroup4Picker(true);
        }
 
        #endregion
    }
}