duheng
2025-03-31 be65218617cab71a90a9a05cf488fbb6e206b5c5
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
using Yw;
using Yw.WinFrmUI;
 
namespace HStation.WinFrmUI
{
    public partial class RoleProjectMenuPage : DocumentPage
    {
        public RoleProjectMenuPage()
        {
            InitializeComponent();
            this.treeList1.InitialMultiColSettings();
            this.PageTitle.Caption = "角色菜单管理";
            this.PageTitle.SvgImageSize = new Size(24, 24);
            this.roleTreeListCtrl1.FocusedChangedEvent += RoleTreeListCtrl1_FocusedChangedEvent;
        }
 
        public override void InitialDataSource()
        {
            this.roleTreeListCtrl1.InitialData();
        }
 
        private List<RoleProjcetMenuViewModel> _allBindingList;
 
        private Yw.Vmo.RoleVmo _lastRole;
 
        /// <summary>
        /// 聚焦改变事件
        /// </summary>
        private async void RoleTreeListCtrl1_FocusedChangedEvent(Yw.Vmo.RoleVmo obj)
        {
            _lastRole = obj;
            _allBindingList = new List<RoleProjcetMenuViewModel>();
            var allList = await BLLFactory<Yw.BLL.RoleProjectMenuMapping>.Instance.GetAuthorizeMenuList(LoginUserInfo.ProjectID, obj.ID);
            foreach (var item in allList)
            {
                _allBindingList.Add(new RoleProjcetMenuViewModel(item));
            }
            this.roleProjcetMenuViewModelBindingSource.DataSource = _allBindingList;
            this.roleProjcetMenuViewModelBindingSource.ResetBindings(false);
        }
 
        //保存
        private async void BtnSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var menuList = new List<long>();
            foreach (var item in _allBindingList)
            {
                if (item.Have)
                {
                    menuList.Add(item.ID);
                }
            }
            var vmo = new Yw.Vmo.SetRoleProjectMenuVmo();
            vmo.ProjectID = LoginUserInfo.ProjectID;
            vmo.RoleID = _lastRole.ID;
            vmo.MenuIds = menuList;
            var bol = await BLLFactory<Yw.BLL.RoleProjectMenuMapping>.Instance.Set(vmo);
            if (bol)
            {
                TipFormHelper.ShowSucceed("保存成功!");
            }
            else
            {
                TipFormHelper.ShowError("保存失败!");
            }
        }
 
        private void barBtnSearch_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.treeList1.OptionsFind.AlwaysVisible = !this.treeList1.OptionsFind.AlwaysVisible;
        }
 
        private void treeList1_AfterCheckNode(object sender, DevExpress.XtraTreeList.NodeEventArgs e)
        {
            // 获取父节点
            var parentNode = e.Node.ParentNode;
            if (parentNode != null)
            {
                parentNode.Checked = _isCheck;
            }
        }
 
        private bool _isCheck = false;
 
        private void treeList1_BeforeCheckNode(object sender, DevExpress.XtraTreeList.CheckNodeEventArgs e)
        {
            var parentNode = e.Node.ParentNode;
            if (parentNode != null)
            {
                _isCheck = parentNode.Checked;
            }
        }
 
        private void barBtnRefresh_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            RoleTreeListCtrl1_FocusedChangedEvent(_lastRole);
        }
    }
}