Shuxia Ning
2025-01-08 687a3dfd095bc8c099b7fa6e65f0dc699fdc8f1d
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
using DevExpress.Utils.DragDrop;
using DevExpress.XtraBars.Docking2010;
using DevExpress.XtraEditors;
using DevExpress.XtraTreeList.Nodes;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using Yw;
using Yw.WinFrmUI;
 
namespace HStation.WinFrmUI.Organize
{
    /// <summary>
    /// 菜单管理界面
    /// </summary>
    public partial class MenuMgrPage : DocumentPage
    {
        public MenuMgrPage()
        {
            InitializeComponent();
            this.treeList1.InitialMultiColSettings(30);
        }
 
        private List<MenuViewModel> _allBindingList = null;//绑定列表
 
        private Yw.BLL.ProjectMenu _bll = new Yw.BLL.ProjectMenu();
 
        /// <summary>
        /// 初始化数据
        /// </summary>
        public override async void InitialDataSource()
        {
            var allList = await new Yw.BLL.ProjectMenu().GetByProjectID(1);
            _allBindingList = new List<MenuViewModel>();
            if (allList != null)
            {
                foreach (var item in allList)
                {
                    var model = new MenuViewModel(item);
                    _allBindingList.Add(model);
                }
            }
            this.menuViewModelBindingSource.DataSource = _allBindingList;
            this.menuViewModelBindingSource.ResetBindings(false);
            //  this.treeList1.ForceInitialize();
            //this.treeList1.CollapseAll();
        }
 
        //添加
        private void barBtnAdd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_allBindingList == null)
                return;
            var dlg = new AddMenuDlg();
            dlg.SetBindingData();
            dlg.ReloadDataEvent += async (rhs) =>
            {
                var id = await _bll.Insert(rhs);
                if (id > 0)
                {
                    rhs.ID = id;
                    this._allBindingList.Add(new MenuViewModel(rhs));
                    this.menuViewModelBindingSource.ResetBindings(false);
                    //this.treeList1.Refresh();
                    return true;
                }
                return false;
            };
            dlg.ShowDialog();
        }
 
        //编辑
        private async void barBtnEdit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_allBindingList == null)
                return;
            var row = this.treeList1.GetCurrentViewModel(_allBindingList);
            if (row == null)
                return;
            var dlg = new EditMenuDlg();
            var model = await _bll.GetByID(row.ID);
            if (model == null)
                return;
            dlg.SetBindingData(model);
            dlg.ReloadDataEvent += async (rhs) =>
            {
                if (await _bll.Update(rhs))
                {
                    row.Reset(rhs);
                    this.treeList1.RefreshNode(this.treeList1.FocusedNode);
                    return true;
                }
                return false;
            };
 
            dlg.ShowDialog();
        }
 
        //显示详细信息
        private void barBtnInfo_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_allBindingList == null)
                return;
            var row = this.treeList1.GetCurrentViewModel(_allBindingList);
            if (row == null)
                return;
            var dlg = new ViewMenuDlg();
            dlg.SetBindingData(row);
            dlg.ShowDialog();
        }
 
        //删除
        private async void barBtnDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_allBindingList == null)
                return;
            var row = this.treeList1.GetCurrentViewModel(_allBindingList);
            if (row == null)
                return;
            if (XtraMessageBox.Show($"确认删除数据行?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) != DialogResult.OK)
                return;
 
            if (!await new Yw.BLL.ProjectMenu().DeleteByID(row.ID))
            {
                XtraMessageBox.Show($"删除失败!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            _allBindingList.Remove(row);
            this.menuViewModelBindingSource.ResetBindings(false);
            //this.treeList1.RefreshDataSource();
            XtraMessageBox.Show($"删除成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
 
        //设置菜单功能点
        private void SetFuncList()
        {
            /*  if (_allBindingList == null)
                  return;
              var row = this.treeList1.GetCurrentViewModel(_allBindingList);
              if (row == null)
                  return;
              var page = new FuncMgrPage();
              page.SetBindingData(row);
              page.AuthTree = this.AuthTree?.Children?.Find(x => x.Code == "func");
              this.ToNextPage(page);*/
        }
 
        //搜索的显示与隐藏
        private void SetSearchPanel()
        {
            this.treeList1.OptionsFind.AlwaysVisible = !this.treeList1.OptionsFind.AlwaysVisible;
        }
 
        /*        /// <summary>
                /// 刷新数据
                /// </summary>
                public override void RefreshDataSource()
                {
                    WaitFrmHelper.ShowWaitForm("正在加载菜单列表...");
                    _allBindingList = new BLL.Menu().GetAll();
                    this.treeList1.DataSource = _allBindingList;
                    this.treeList1.ForceInitialize();
                    this.treeList1.CollapseAll();
                    WaitFrmHelper.HideWaitForm();
                }*/
 
        private void barCkDrag_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SetDragEnable(this.barCkDrag.Checked);
        }
 
        //设置拖拽可用性
        private void SetDragEnable(bool allowArag)
        {
            var be = this.behaviorManager1.GetBehavior<DevExpress.Utils.DragDrop.DragDropBehavior>(this.treeList1);
            be.Properties.AllowDrag = allowArag;
        }
 
        private void barBtnSearch_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.treeList1.OptionsFind.AlwaysVisible = !this.treeList1.OptionsFind.AlwaysVisible;
        }
 
        private void barBtnRefresh_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.InitialDataSource();
        }
    }
}