schangxiang@126.com
2025-08-27 f0e8a2a8bb05e1cd234856853f3ba755acb3ba18
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WZ.Useful.Commons;
using WMS.EnumDefine;
using sunui.forms;
 
namespace WMS.UI.Basic
{
    public partial class FrmPermissionManage : Form
    {
       // public static addUser modifiUser = new addUser();
        //List<RoleSrv.RoleEntity> ROLELst = new List<RoleSrv.RoleEntity>();
        //RoleSrv.RoleEntity oneRole = new RoleSrv.RoleEntity();
        List<User> userlist = new List<User>();
        WMS.yunneiWCS.resMsgOfroleFj0h9u9J roles = new yunneiWCS.resMsgOfroleFj0h9u9J();
        WMS.yunneiWCS.resMsgOfroleFj0h9u9J rolename = new WMS.yunneiWCS.resMsgOfroleFj0h9u9J();
        string[] wmsUser = { "入库", "出库", "库存查询", "任务管理", "状态预览", "出入库记录", "报警记录查询", "清理库存查询", "权限管理", "库位维护", "物料维护" };
        string[] PdaUser = { "缸体下线", "刚盖下线", "任务管理" };
        public FrmPermissionManage()
        {
            InitializeComponent();
        }
        private void btnFind_Click(object sender, EventArgs e)
        {
            try
            {
                yunneiWCS.paging papg = new yunneiWCS.paging();
                papg.pagenum = 1;
                papg.pagesize = 10000;
                string name = tBFind.Text.Trim();
                WMS.yunneiWCS.resMsgOfuserAndRoleFj0h9u9J user = FLogin.wcsWcf.findUser(papg, name);
                if (user.status == 200)
                {
                    dGVPeopleInfo.DataSource = null;
                    dGVPeopleInfo.DataSource = user.date;
                }
            }
            catch (Exception ex)
            {
                WZ.Useful.Commons.LogTextHelper.WriteLine("FrmPermissionManage", "btnFind_Click", ex.ToString());
            }
            //string keyword = tBFind.Text.Trim();
            //List<URPSrv.USER_ROLE_VIEW> lst = new List<URPSrv.USER_ROLE_VIEW>();
            //lst = WMSFrmMain.urpSrv.GetAllUserRolePERMISSIONByKeyword(keyword).ToList();
            //if (lst == null || lst.Count == 0)
            //return;
        }
 
        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
 
        private void btnDelete_Click(object sender, EventArgs e)
        {
 
            #region 增加校验
            try
            {
                MessageBoxButtons messButton = MessageBoxButtons.OKCancel;
                DialogResult dr = MessageBox.Show("确定要删除该用户吗?", "确认删除", messButton);
                if (dr == DialogResult.OK)//如果点击“确定”按钮
                {
                    var row = dGVPeopleInfo.SelectedRows[0];
                    string creator = FLogin.user.UserName;
                    WMS.yunneiWCS.user data = new WMS.yunneiWCS.user
                    {
                        WorkNo = row.Cells["WorkNo"].Value.ToString(),
                        UserName = row.Cells["UserName"].Value.ToString()
                    };
                    WMS.yunneiWCS.resMsgOfstring res = FLogin.wcsWcf.addUser(data, creator, 2);
                    if (res.status != 200)
                    {
                        MessageBox.Show(res.msg);
                    }
                    else
                    {
 
                        MessageBox.Show("删除成功");
                    }
                }
                else//如果点击“取消”按钮
                {
                    return;
                }
            }
            catch (Exception ex)
            {
                WZ.Useful.Commons.LogTextHelper.WriteLine("FrmPermissionManage", "btnDelete_Click", ex.ToString());
            }
 
            btnFind_Click(null, null);
 
            #endregion
 
        }
 
        private void btnAddNew_Click(object sender, EventArgs e)
        {
            AddUser form = new AddUser("","","");
            form.ShowDialog();
            //刷新列表
            btnFind_Click(null, null);
        }
 
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                if (dGVPeopleInfo.SelectedRows.Count > 0)
                {
                    var row = dGVPeopleInfo.SelectedRows[0];
 
                    string workno = row.Cells["WorkNo"].Value.ToString();
                    string username = row.Cells["UserName"].Value.ToString();
                    string rolename = row.Cells["name_role"].Value.ToString();
                    AddUser f = new AddUser(workno, username, rolename);
                    //f.Show();
                    f.ShowDialog();
                    // btnFind_Click(null, null);
                }
            }
            catch (Exception)
            {
            }
           
 
        }
 
        private void FrmPermissionManage_Load(object sender, EventArgs e)
        {
           
            dGVPeopleInfo.AutoGenerateColumns = false;
            InitalLsV_Group();//初始化组列表
            //InialGroupVsFunction();//初始化组功能
            //InitalcmB_PW();//初始化功能下拉框
            //Inial_lsB_r_User();
            //刷新列表
            btnFind_Click(null, null);
        }
 
        /// <summary>
        /// 刷新组功能表
        /// </summary>
        private void InialGroupVsFunction()
        {
            
        }
 
      
 
        /// <summary>
        /// 初始化组列表
        /// </summary>
        private void InitalLsV_Group()
        {
 
            lsV_r_Group.Clear();
            WMS.yunneiWCS.paging papg = new yunneiWCS.paging();
            papg.pagenum = 1;
            papg.pagesize = 10000;
            roles = FLogin.wcsWcf.findRole(papg, "");
            if (roles.status == 200)
            {
            
                role_box.Enabled = true;
 
                lsB_r_PW.Enabled = true;
                int i = roles.date.Length;
                lsV_r_Group.BeginUpdate();  //避免更新时产生闪烁现象
                foreach (var p in roles.date)
                {
                    ListViewItem lvi = new ListViewItem();
                    lvi.ImageIndex = 0;
                    lvi.Text = p.roleName;
                    lsV_r_Group.Items.Add(lvi);
                }
                lsV_r_Group.EndUpdate();
            }
 
        }
 
      
 
        private void lsV_r_Group_SelectedIndexChanged(object sender, EventArgs e)
        {
 
            this.lsB_r_PW.Items.Clear();
            if (lsV_r_Group.SelectedItems.Count == 0)
            {
                comboBox1.SelectedIndex = -1;
                role_box.Text = ""; return;
            }
            if (lsV_r_Group.SelectedItems[0].Text=="admin")
    {
        WMS.EnumDefine.messages ms = new WMS.EnumDefine.messages(2, "管理角色不可编辑");
        ms.Show();
        return;
    }
           
            WMS.yunneiWCS.paging papg = new yunneiWCS.paging();
            papg.pagenum = 1;
            papg.pagesize = 10000;
            rolename = FLogin.wcsWcf.findRole(papg, lsV_r_Group.SelectedItems[0].Text);
            if (rolename.status != 200)
            {
                return;
            }
            role_box.Text = rolename.date[0].roleName;
            comboBox1.SelectedIndex = rolename.date[0].area == 1 ? 0 : 1;
            cmB_PW.DataSource = rolename.date[0].area == 1 ? wmsUser : PdaUser;
            var roleModule = FLogin.wcsWcf.findRoleModule(papg, rolename.date[0].roleName);
            if (roleModule.status == 200)
            {
 
                if (roleModule.date.Length > 0)
                {
                    foreach (var item in roleModule.date)
                    {
                        this.lsB_r_PW.Items.Add(item.value);
                    }
 
                }
            }
            //if (ROLELst.Count > 0)
            //{
            //    oneRole = ROLELst.Find(x => x.ROLENAME == roleName || x.ROLENAMEENG == roleName);
            //}
 
            //tb_r_GroupName.Text = oneRole.ROLENAME;
            //rTB_r_GroupDesc.Text = oneRole.ROLEDESC;
 
            //tb_r_GroupNameENG.Text = oneRole.ROLENAMEENG;
            //rTB_r_GroupDescENG.Text = oneRole.ROLEDESCENG;
 
            InialGroupVsFunction();//刷新组功能表
            //Inial_lsB_r_User();//刷新用户
        }
 
 
        /// <summary>删除角色
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_r_RemoveGroup_Click(object sender, EventArgs e)
        {
            if (lsV_r_Group.Items.Count == 0 || lsV_r_Group.SelectedItems.Count == 0)
                return;
            string groupname = lsV_r_Group.SelectedItems[0].Text;//选中需要删除的行
            if (groupname == "admin")
            {
                WMS.EnumDefine.messages ms = new WMS.EnumDefine.messages(2, "管理员角色不允许删除");
                ms.Show();
                return;
            }
            var res = FLogin.wcsWcf.addRole(groupname, 1, 2);
            int success = 0;
            if (res.status == 200)
            {
                success = 1;
                role_box.Text = null;
                role_box.Enabled = false;
                lsB_r_PW.Items.Clear();
                lsB_r_PW.Enabled = false;
                InitalLsV_Group();
            }
            else
            {
                success = 2;
            }
            WMS.EnumDefine.messages mss = new WMS.EnumDefine.messages(success, res.msg);
            mss.Show();
        }
 
        private void btn_r_Pw_Remove_Click(object sender, EventArgs e)
        {
            if (lsB_r_PW.SelectedItem == null)
            {
                WMS.EnumDefine.messages ms = new WMS.EnumDefine.messages(2, "请选择要移除菜单");
                ms.Show();
                return;
            }
 
            try
            {
                if (rolename.status != 200)
                {
                    return;
                }
                FLogin.wcsWcf.addModule(lsB_r_PW.SelectedItem.ToString(), rolename.date[0].roleName, 2);
                InialGroupVsFunction();
                lsB_r_PW.Items.Remove(lsB_r_PW.SelectedItem);
            }
            catch (Exception)
            {
                WMS.EnumDefine.messages ms = new WMS.EnumDefine.messages(2, "移除失败");
                ms.Show();
            }
 
        }
 
        private void btn_r_PW_Add_Click(object sender, EventArgs e)
        {
            bool have = lsB_r_PW.Items.Contains(cmB_PW.SelectedItem);
            if (role_box.Text.Trim() == "")
            {
                WMS.EnumDefine.messages ms = new WMS.EnumDefine.messages(2, "请选择角色");
                ms.Show();
                return;
            }
            if (have)
            {
                WMS.EnumDefine.messages ms = new WMS.EnumDefine.messages(2, "已有该功能");
                ms.Show();
                return;
            }
            lsB_r_PW.Items.Add(cmB_PW.SelectedItem);
            if (rolename.status != 200)
            {
                return;
            }
            FLogin.wcsWcf.addModule(cmB_PW.SelectedItem.ToString(), rolename.date[0].roleName, 1);
            InialGroupVsFunction();
 
        }
 
        private void addRole_Click(object sender, EventArgs e)
        {
            if (role_box.Text.Trim() == "")
            {
                WMS.EnumDefine.messages ms = new WMS.EnumDefine.messages(2, "角色名称不能为空!");
                ms.Show();
 
                return;
            }
            if (comboBox1.SelectedItem == null)
            {
                WMS.EnumDefine.messages ms = new WMS.EnumDefine.messages(2, "请选择功能模块");
                ms.Show();
 
                return;
            }
            int area = 1;
            if (comboBox1.SelectedItem.ToString() == "PDA用户")
            {
                area = 2;
            }
            var addrole = FLogin.wcsWcf.addRole(role_box.Text.Trim(), area, 1);
            if (addrole.status == 400)
            {
                WMS.EnumDefine.messages ms = new WMS.EnumDefine.messages(2, addrole.msg);
                ms.Show();
 
            }
            InitalLsV_Group();
            //    string  createName=FLogin.user.UserName;
            //WMS.yunneiWCS.resMsgOfstring res=  FLogin.wcsWcf.addRole(role_box.Text.Trim(), createName);
            //    MessageBox.
 
        }
 
        private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {
            InitalLsV_Group();
        }
 
    }
 
}