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
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
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
#region
 
using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using CSFrameworkV5.Business.BLL_Permission;
using CSFrameworkV5.Common;
using CSFrameworkV5.Core;
using CSFrameworkV5.Library.CommonClass;
using CSFrameworkV5.Models;
using DevExpress.XtraEditors;
using DevExpress.XtraTreeList;
 
#endregion
 
namespace CSFrameworkV5.Library.PermissionForms
{
    /// <summary>
    ///     组管理及分配权限窗体。
    /// </summary>
    public partial class frmGroupPermission : frmBaseDataForm
    {
        private DataTable _AvaliableRole; //当前组可选的角色
        private DataTable _AvaliableUser; //当前组可选的用户
        private bllGroup _BLL;
        private GroupActionsView _GroupActionsView;
        private bllPermission _Permission;
 
        public frmGroupPermission()
        {
            InitializeComponent();
        }
 
        //显示组的权限
        private void btnAuthLoad_Click(object sender, EventArgs e)
        {
            AssertFocusedRow();
 
            try
            {
                frmWaitingEx.ShowMe(this);
                var groupCode =
                    gvSummary.GetFocusedRowCellDisplayText(colGroupCode);
                LoadGroupPermission(groupCode);
                if (chkExpandGroupRights.Checked) tlGroup.ExpandAll();
            }
            finally
            {
                frmWaitingEx.HideMe(this);
            }
        }
 
        private void btnEmpty_Click(object sender, EventArgs e)
        {
            ClearContainerEditorText(pnlSearch);
        }
 
        private void btnFindRole_Click(object sender, EventArgs e)
        {
            if (_AvaliableRole != null)
            {
                var dt = _AvaliableRole.Copy();
                dt.DefaultView.RowFilter =
                    "RoleID LIKE '%" + txtRoleText.Text +
                    "%' OR RoleName LIKE '%" +
                    txtRoleText.Text + "%'";
                dt = dt.DefaultView.ToTable();
                var groupCode = GetCurrentGroupCode();
                DragDropDataSourceBase availableRoles =
                    new GroupRoleDataSource(dt, groupCode, false);
                lbAllRole.DataSource = availableRoles;
                lbAllRole.DisplayMember = "Name";
                lbAllRole.ValueMember = "Code";
            }
        }
 
        private void btnFindUser_Click(object sender, EventArgs e)
        {
            if (_AvaliableUser != null)
            {
                var dt = _AvaliableUser.Copy();
                dt.DefaultView.RowFilter =
                    "Account LIKE '%" + txtUserText.Text +
                    "%' OR UserName LIKE '%" +
                    txtUserText.Text + "%'";
                dt = dt.DefaultView.ToTable();
                var groupCode = GetCurrentGroupCode();
                DragDropDataSourceBase availableUsers =
                    new GroupUserDataSource(dt, groupCode, false);
                lbAllUser.DataSource = availableUsers;
                lbAllUser.DisplayMember = "Name";
                lbAllUser.ValueMember = "Code";
            }
        }
 
        private void btnQuery_Click(object sender, EventArgs e)
        {
            //搜索数据     
            try
            {
                frmWaitingEx.ShowMe(this);
                var dt = _BLL.Search(
                    ConvertEx.ToString(txt_GroupCode.EditValue),
                    ConvertEx.ToString(txt_GroupName.EditValue), "",
                    ConvertEx.ToString(txt_Owner1.EditValue),
                    ConvertEx.ToString(txt_OwnerTel1.EditValue));
                DoBindingSummaryGrid(dt); //绑定主表的Grid            
            }
            finally
            {
                frmWaitingEx.HideMe(this);
            }
 
            if (gvSummary.RowCount == 0) Msg.Warning("没有找到数据!");
        }
 
        public override bool ButtonAuthorized(int authorityValue)
        {
            if (authorityValue == ButtonAuthority.ADD) return false;
 
            return base.ButtonAuthorized(authorityValue);
        }
 
        protected override void ButtonStateChanged(UpdateType currentState)
        {
            base.ButtonStateChanged(currentState);
            SetDetailEditorsAccessable(_DetailGroupControl, DataChanged);
 
            tlGroup.Enabled = IsViewMode;
        }
 
        private void chkExpandGroupRights_CheckedChanged(object sender,
            EventArgs e)
        {
            //扩展、收缩组权限树视图
            if (chkExpandGroupRights.Checked)
                tvRoleActions.ExpandAll();
            else
                tvRoleActions.CollapseAll();
        }
 
        /// <summary>
        ///     新增记录
        /// </summary>
        public override void DoAdd(IButtonInfo sender)
        {
            //
        }
 
        public override void DoCancel(IButtonInfo sender)
        {
            if (Msg.AskQuestion("要取消修改吗?"))
            {
                InitGroupTreeList(); //初始化树视图
                _UpdateType = UpdateType.None;
                SetViewMode();
                DoViewContent(null);
            }
        }
 
        /// <summary>
        ///     删除记录
        /// </summary>
        /// <param name="sender"></param>
        public override void DoDelete(IButtonInfo sender)
        {
            AssertFocusedRow(); //检查是否选择一条记录
            //调用业务逻辑类删除记录            
            var groupCode = GetCurrentGroupCode();
            var groupName =
                gvSummary.GetFocusedRowCellDisplayText(colGroupName);
 
            if (!Msg.AskQuestion("确定要删除当前组 " + groupName + " 的用户及角色资料?"))
                return;
 
            var b = _BLL.DeleteGroupRights(groupCode);
            AssertEqual(b, true, "删除记录时发生错误!");
            if (b)
            {
                if (_SummaryView.FocusedRowHandle < 0) //删除了最後一条记录. 显示Summary页面.
                    ShowSummaryPage(true);
                else
                    DoViewContent(
                        _buttons.GetButtonByName(ButtonNameList.btnView));
 
                Msg.ShowInformation("系统已删除当前组 " + groupName + " 的权限!");
            }
        }
 
        public override void DoEdit(IButtonInfo sender)
        {
            AssertFocusedRow();
            base.DoEdit(sender);
            DoViewContent(sender);
            ShowDetailPage(true);
            tcBusiness.SelectedTabPage = tpDetail;
        }
 
        public virtual void DoInitPermission(IButtonInfo sender)
        {
            if (Msg.AskQuestion("初始化操作将删除所有系统权限数据,确定要初始化吗?"))
                if (_Permission.Init())
                    InitGroupTreeList(); //预设加载组的资料
        }
 
        public override void DoSave(IButtonInfo sender)
        {
            var success = false;
 
            UpdateLastControl(); //更新最后一个输入控件的数据
 
            var dtGroupUsers =
                (lbGroupUser.DataSource as DragDropDataSourceBase).GetChanges();
            var dtGroupRoles =
                (lbGroupRole.DataSource as DragDropDataSourceBase).GetChanges();
 
            //保存数据
            success =
                _BLL.Update(_UpdateType, dtGroupUsers,
                    dtGroupRoles); //调用业务逻辑层的Update方法提交数据
 
            if (success)
            {
                LoadGroupUser(GetCurrentGroupCode());
                LoadGroupRoleData(GetCurrentGroupCode());
 
                base.DoSave(sender);
                Msg.ShowInformation("保存成功!");
            }
            else
            {
                Msg.Warning("保存失败!");
            }
        }
 
        public override void DoViewContent(IButtonInfo sender)
        {
            AssertFocusedRow(); //检查有无记录.                
            _BLL.CreateDataBinder(
                _SummaryView.GetDataRow(_SummaryView.FocusedRowHandle));
 
            //显示编号,名称
            txtGroupCode.Text =
                gvSummary.GetFocusedRowCellDisplayText(colGroupCode);
            txtGroupName.Text =
                gvSummary.GetFocusedRowCellDisplayText(colGroupName);
 
            LoadGroupDetails();
            base.DoViewContent(sender);
            ShowDetailPage(false); //用户点击ViewContent按钮可以显示Summary页       
            ButtonStateChanged(_UpdateType);
        }
 
        private void frmGroupManagement_Load(object sender, EventArgs e)
        {
            InitializeForm();
            SetLanguage();
        }
 
        private string GetCurrentGroupCode()
        {
            var code =
                Convert.ToString(
                    gvSummary.GetFocusedRowCellValue(colGroupCode));
            if (string.IsNullOrEmpty(code)) throw new Exception("您没有选择操作的组!");
 
            return code;
        }
 
        public override void InitButtons()
        {
            base.InitButtons();
            _buttons.RemoveButton(ButtonNameList.btnAdd); //删除"新增"按钮
            //_buttons.GetButtonByName(ButtonNameList.btnAdd).Enable = false;
 
            //管理员,显示“初始化按钮”
            if (Loginer.CurrentUser.IsAdmin())
            {
                var _MyButtons = new IButtonInfo[1];
                _MyButtons[0] = ToolbarRegister.CreateButton(
                    "btnInitPermission", "初始化权限", ToolBarGroup.扩展功能1,
                    Globals.LoadBitmap("32_InitPermission.png"),
                    new Size(57, 28), true, true, DoInitPermission);
 
                _buttons.AddRange(_MyButtons);
            }
        }
 
        private void InitGroupTreeList()
        {
            var treeData = _BLL.GetSummaryData(true);
            tlGroup.LookAndFeel.UseDefaultLookAndFeel = false;
            tlGroup.LookAndFeel.UseWindowsXPTheme = true;
            tlGroup.OptionsSelection.EnableAppearanceFocusedCell = false;
            tlGroup.KeyFieldName = tb_MyGroup.GroupCode; //设置主键 
            tlGroup.ParentFieldName = tb_MyGroup.ParentGroupCode; //设置父级主键 
            tlGroup.RootValue = ""; //顶级树结点的值 
            tlGroup.BeginUpdate();
            tlGroup.DataSource = treeData;
            DevTreeListView.SetImageIndex(tlGroup, null, 1, 0);
            DevStyle.SetTreeListSelectStyle(tlGroup);
            tlGroup.EndUpdate();
            tlGroup.ExpandAll();
        }
 
        /// <summary>
        ///     初始化窗体
        /// </summary>
        protected override void InitializeForm()
        {
            _BLL = new bllGroup();
            _Permission = new bllPermission();
            _GroupActionsView = new GroupActionsView(tvRoleActions);
            _SummaryView = new DevGridView(gvSummary);
 
            frmGridCustomize.RegisterGrid(gvSummary);
 
            gvSummary.DoubleClick += OnGridViewDoubleClick; //主表DoubleClict
            BindingSummaryNavigator(controlNavigatorSummary,
                gvSummary.GridControl); //Summary导航条.
            base.InitializeForm();
 
            PermissionBinder.BoundUser(txt_Owner1);
            PermissionBinder.BoundUser(repM_Owner1);
 
            InitGroupTreeList(); //预设加载组的资料
        }
 
        private void lbAllRole_DoubleClick(object sender, EventArgs e)
        {
            if (IsAddOrEditMode)
                MoveItem(lbAllRole, lbGroupRole); //将可选角色移动到已选角色
        }
 
        private void lbAllUser_DoubleClick(object sender, EventArgs e)
        {
            if (IsAddOrEditMode)
                MoveItem(lbAllUser, lbGroupUser); //将可选用户移动到已选用户
        }
 
        private void lbGroupRole_DoubleClick(object sender, EventArgs e)
        {
            if (IsAddOrEditMode)
                MoveItem(lbGroupRole, lbAllRole); //将已选角色移动到可选角色           
        }
 
        private void lbGroupUser_DoubleClick(object sender, EventArgs e)
        {
            if (IsAddOrEditMode)
                MoveItem(lbGroupUser, lbAllUser); //将已选用户移动到可选用户           
        }
 
        private void LoadDataByTree()
        {
            if (tlGroup.FocusedNode != null)
            {
                var groupCode =
                    ConvertEx.ToString(
                        tlGroup.FocusedNode.GetValue(tb_MyGroup.GroupCode));
                btnEmpty_Click(btnEmpty, new EventArgs());
                txt_GroupCode.EditValue = groupCode;
                btnQuery_Click(btnQuery, new EventArgs()); //执行查询
                //gcSummary.RefreshDataSource();
                if (gvSummary.RowCount > 0)
                {
                    var H = gvSummary.LocateByValue(tb_MyGroup.GroupCode,
                        groupCode);
                    if (H >= 0) gvSummary.FocusedRowHandle = H;
                }
            }
        }
 
        /// <summary>
        ///     显示组的明细数据
        /// </summary>
        public void LoadGroupDetails()
        {
            var groupCode = GetCurrentGroupCode();
            LoadGroupUser(groupCode);
            LoadGroupRoleData(groupCode);
            LoadGroupPermission(groupCode);
        }
 
        /// <summary>
        ///     移动项目
        /// </summary>
        /// <param name="sourceControl"></param>
        /// <param name="destControl"></param>
        private void MoveItem(ImageListBoxControl sourceControl,
            ImageListBoxControl destControl)
        {
            var source = sourceControl.DataSource as DragDropDataSourceBase;
            var dest = destControl.DataSource as DragDropDataSourceBase;
 
            if (source.Count == 0) return;
 
            var o = sourceControl.SelectedItem as ItemExtend;
            if (o != null)
            {
                dest.AddToListAndTable(o);
                source.Remove(o);
 
                destControl.DataSource = null;
                destControl.DataSource = dest;
                destControl.SelectedIndex =
                    destControl.ItemCount - 1; //目的地定位到最后一条记录
                destControl.Focus();
 
                sourceControl.Update();
            }
        }
 
        protected override void ShowDetailPage(bool disableSummaryPage)
        {
            try
            {
                SuspendLayout();
                tpDetail.PageEnabled = true;
                tpAllRights.PageEnabled = true;
                if (tcBusiness.SelectedTabPage == tpSummary)
                    tcBusiness.SelectedTabPage = tpDetail;
 
                tpSummary.PageEnabled = !disableSummaryPage;
                FocusEditor(); //第一个编辑框获得焦点.
                ResumeLayout();
            }
            catch (Exception ex)
            {
                ResumeLayout();
                Msg.ShowException(ex);
            }
        }
 
        protected override void ShowSummaryPage(bool disableDetailPage)
        {
            try
            {
                SuspendLayout();
                tpSummary.PageEnabled = true;
                tcBusiness.SelectedTabPage = tpSummary;
                tpDetail.PageEnabled = !disableDetailPage;
                tpAllRights.PageEnabled = !disableDetailPage;
                if (_SummaryView != null) _SummaryView.SetFocus();
 
                ResumeLayout();
            }
            catch (Exception ex)
            {
                ResumeLayout();
                Msg.ShowException(ex);
            }
        }
 
        private void tlGroup_FocusedNodeChanged(object sender,
            FocusedNodeChangedEventArgs e)
        {
            try
            {
                frmWaitingEx.ShowMe(this);
                SuspendLayout();
                LoadDataByTree();
                DoViewContent(null);
            }
            finally
            {
                ResumeLayout();
                frmWaitingEx.HideMe(this);
            }
        }
 
        private void tvRoleActions_MouseDown(object sender, MouseEventArgs e)
        {
            //按下鼠标,设结点为焦点状态
            var info = tvRoleActions.HitTest(e.Location);
            tvRoleActions.SelectedNode = info.Node;
        }
 
        #region DragOver拖放User,Role操作的公共事件
 
        private void OnList_MouseMove(object sender, MouseEventArgs e)
        {
            //移动鼠标,进入拖拉状态.
            var list = sender as ImageListBoxControl;
            if (list.AllowDrop == false) return;
 
            if (MouseButtons.Left == e.Button && list.SelectedItem != null)
                list.DoDragDrop(list.SelectedItem, DragDropEffects.Move);
 
            if (MouseButtons.Right == e.Button)
                list.DoDragDrop(list.SelectedItems, DragDropEffects.Move);
        }
 
        private void OnList_MouseDown(object sender, MouseEventArgs e)
        {
            //点鼠标右键,一次性拖放多个对象.
            var list = sender as ImageListBoxControl;
            if (list.AllowDrop == false) return;
 
            if (e.Button == MouseButtons.Right && list.SelectedItems.Count > 1)
                list.DoDragDrop(list.SelectedItems, DragDropEffects.Move);
        }
 
        private void OnList_DragOver(object sender, DragEventArgs e)
        {
            if (!IsAddOrEditMode) return;
 
            //拖放到目标控件上触发的事件.
            var list = sender as ImageListBoxControl;
            if (list.AllowDrop == false) return;
 
            var source = list.DataSource as DragDropDataSourceBase;
            ItemExtend tag = null;
 
            if (e.Data.GetDataPresent(
                    typeof(BaseListBoxControl.SelectedItemCollection)))
            {
                BaseListBoxControl.SelectedItemCollection listSelected;
                listSelected =
                    e.Data.GetData(
                            typeof(BaseListBoxControl.SelectedItemCollection))
                        as
                        BaseListBoxControl.SelectedItemCollection;
                tag = listSelected[0] as ItemExtend;
            }
 
            if (e.Data.GetDataPresent(typeof(ItemExtend)))
                tag = e.Data.GetData(typeof(ItemExtend)) as ItemExtend;
 
            if (tag == null || source.IndexOf(tag) >= 0)
                e.Effect = DragDropEffects.None;
            else
                e.Effect = DragDropEffects.Move;
        }
 
        #endregion
 
        #region DragDrop拖放User,Role操作
 
        private void lbGroupRole_DragDrop(object sender, DragEventArgs e)
        {
            //拖拉可选角色到组的角色.
 
            var dest = lbGroupRole.DataSource as DragDropDataSourceBase;
            var source = lbAllRole.DataSource as DragDropDataSourceBase;
 
            if (e.Data.GetDataPresent(typeof(ItemExtend)))
            {
                var tag = e.Data.GetData(typeof(ItemExtend)) as ItemExtend;
                dest.AddToListAndTable(tag);
                source.Remove(tag);
            }
 
            if (e.Data.GetDataPresent(
                    typeof(BaseListBoxControl.SelectedItemCollection)))
            {
                BaseListBoxControl.SelectedItemCollection list;
 
                list =
                    e.Data.GetData(
                            typeof(BaseListBoxControl.SelectedItemCollection))
                        as
                        BaseListBoxControl.SelectedItemCollection;
 
                foreach (ItemExtend tag in list) dest.AddToListAndTable(tag);
 
                //反向删除
                var c = list.Count - 1;
                while (c >= 0)
                {
                    source.Remove(list[c]); //删除选择记录
                    c--;
                }
            }
 
            //重置数据源
            lbGroupRole.DataSource = null;
            lbGroupRole.DataSource = dest;
 
            lbGroupRole.SelectedIndex =
                lbGroupRole.ItemCount - 1; //目的地定位到最后一条记录
            lbGroupRole.Focus();
            lbGroupRole.Refresh();
 
            lbAllRole.Refresh();
        }
 
        private void lbAllRole_DragDrop(object sender, DragEventArgs e)
        {
            //拖拉组的角色到可选角色.           
 
            var dest = lbAllRole.DataSource as DragDropDataSourceBase;
            var source = lbGroupRole.DataSource as DragDropDataSourceBase;
 
            if (e.Data.GetDataPresent(typeof(ItemExtend)))
            {
                var tag = e.Data.GetData(typeof(ItemExtend)) as ItemExtend;
                dest.AddToListAndTable(tag);
                source.Remove(tag);
            }
 
            if (e.Data.GetDataPresent(
                    typeof(BaseListBoxControl.SelectedItemCollection)))
            {
                BaseListBoxControl.SelectedItemCollection list;
 
                list =
                    e.Data.GetData(
                            typeof(BaseListBoxControl.SelectedItemCollection))
                        as
                        BaseListBoxControl.SelectedItemCollection;
 
                foreach (ItemExtend tag in list) dest.AddToListAndTable(tag);
 
                //反向删除
                var c = list.Count - 1;
                while (c >= 0)
                {
                    source.Remove(list[c]); //删除选择记录
                    c--;
                }
            }
 
            lbAllRole.DataSource = null;
            lbAllRole.DataSource = dest;
 
            lbGroupRole.DataSource = null;
            lbGroupRole.DataSource = source;
 
            lbAllRole.SelectedIndex = lbAllRole.ItemCount - 1; //目的地定位到最后一条记录
        }
 
        private void lbGroupUser_DragDrop(object sender, DragEventArgs e)
        {
            //拖拉可选用户到组的用户
 
            var dest = lbGroupUser.DataSource as DragDropDataSourceBase;
            var source = lbAllUser.DataSource as DragDropDataSourceBase;
 
            if (e.Data.GetDataPresent(typeof(ItemExtend)))
            {
                var tag = e.Data.GetData(typeof(ItemExtend)) as ItemExtend;
                dest.AddToListAndTable(tag);
                source.Remove(tag);
            }
 
            if (e.Data.GetDataPresent(
                    typeof(BaseListBoxControl.SelectedItemCollection)))
            {
                BaseListBoxControl.SelectedItemCollection list;
 
                list =
                    e.Data.GetData(
                            typeof(BaseListBoxControl.SelectedItemCollection))
                        as
                        BaseListBoxControl.SelectedItemCollection;
 
                foreach (ItemExtend tag in list) dest.AddToListAndTable(tag);
 
                //反向删除
                var c = list.Count - 1;
                while (c >= 0)
                {
                    source.Remove(list[c]); //删除选择记录
                    c--;
                }
            }
 
            //重置数据源
            lbGroupUser.DataSource = null;
            lbGroupUser.DataSource = dest;
 
            lbGroupUser.SelectedIndex =
                lbGroupUser.ItemCount - 1; //目的地定位到最后一条记录
            lbGroupUser.Focus();
 
            lbAllUser.Refresh();
            lbGroupUser.Refresh();
        }
 
        private void lbAllUser_DragDrop(object sender, DragEventArgs e)
        {
            //拖拉组的用户到可选用户
 
            var dest = lbAllUser.DataSource as DragDropDataSourceBase;
            var source = lbGroupUser.DataSource as DragDropDataSourceBase;
 
            if (e.Data.GetDataPresent(typeof(ItemExtend)))
            {
                var tag = e.Data.GetData(typeof(ItemExtend)) as ItemExtend;
                dest.AddToListAndTable(tag); //目的地增加对象
                source.Remove(tag); //删除来源对象
            }
 
            if (e.Data.GetDataPresent(
                    typeof(BaseListBoxControl.SelectedItemCollection)))
            {
                BaseListBoxControl.SelectedItemCollection list;
 
                list =
                    e.Data.GetData(
                            typeof(BaseListBoxControl.SelectedItemCollection))
                        as
                        BaseListBoxControl.SelectedItemCollection;
 
                foreach (ItemExtend tag in list) dest.AddToListAndTable(tag);
 
                //反向删除
                var c = list.Count - 1;
                while (c >= 0)
                {
                    source.Remove(list[c]); //删除选择记录
                    c--;
                }
            }
 
            lbAllUser.DataSource = null;
            lbAllUser.DataSource = dest;
 
            lbGroupUser.DataSource = null;
            lbGroupUser.DataSource = source;
 
            lbAllUser.SelectedIndex = lbAllUser.ItemCount - 1; //目的地定位到最后一条记录
        }
 
        #endregion
 
        #region Load数据
 
        /// <summary>
        ///     显示组的权限
        /// </summary>
        private void LoadGroupPermission(string groupCode)
        {
            _GroupActionsView.MenuData = _Permission.GetMenuData();
            _GroupActionsView.ActionsData = _Permission.GetActionData();
            _GroupActionsView.ActionCustomNameData =
                _Permission.GetFormTagName();
            _GroupActionsView.InitTree("", groupCode);
            _GroupActionsView.OnViewMode = true; //设为查看模块,禁止操作树视图
 
            tvRoleActions.Update();
        }
 
        //加载组的角色数据.
        private void btnRoleLoad_Click(object sender, EventArgs e)
        {
            try
            {
                frmWaitingEx.ShowMe(this);
                var groupCode = GetCurrentGroupCode();
                LoadGroupRoleData(groupCode);
            }
            finally
            {
                frmWaitingEx.HideMe(this);
            }
        }
 
        //加载组的角色数据
        private void LoadGroupRoleData(string groupCode)
        {
            var currentUser = Loginer.CurrentUser.Account;
            //string currentUser = "cs";//for test
 
            _AvaliableRole = _BLL.GetGroupRoles4Picker(groupCode, currentUser);
            _BLL.GroupRoles = _BLL.GetGroupRoles(groupCode); //组的角色,交易数据
 
            DragDropDataSourceBase availableRoles =
                new GroupRoleDataSource(_AvaliableRole, groupCode, false);
            DragDropDataSourceBase groupRoles =
                new GroupRoleDataSource(_BLL.GroupRoles, groupCode, true);
 
            lbAllRole.DataSource = availableRoles;
            lbAllRole.DisplayMember = "Name";
            lbAllRole.ValueMember = "Code";
 
            lbGroupRole.DataSource = groupRoles;
            lbGroupRole.DisplayMember = "Name";
            lbGroupRole.ValueMember = "Code";
        }
 
        //加载组的用户数据.
        private void btnGroupUserLoad_Click(object sender, EventArgs e)
        {
            try
            {
                frmWaitingEx.ShowMe(this);
 
                var groupCode = GetCurrentGroupCode();
                LoadGroupUser(groupCode);
            }
            finally
            {
                frmWaitingEx.HideMe(this);
            }
        }
 
        private void LoadGroupUser(string groupCode)
        {
            _AvaliableUser = _BLL.GetGroupUsers4Picker(groupCode);
            _BLL.GroupUsers = _BLL.GetGroupUsers(groupCode); //组的用户,交易数据
 
            DragDropDataSourceBase availableUsers =
                new GroupUserDataSource(_AvaliableUser, groupCode, false);
            DragDropDataSourceBase groupUsers =
                new GroupUserDataSource(_BLL.GroupUsers, groupCode, true);
 
            lbAllUser.DataSource = availableUsers;
            lbAllUser.DisplayMember = "Name";
            lbAllUser.ValueMember = "Code";
 
            lbGroupUser.DataSource = groupUsers;
            lbGroupUser.DisplayMember = "Name";
            lbGroupUser.ValueMember = "Code";
        }
 
        #endregion
    }
}