duheng
2024-11-19 ca5f300a7cef85d22b5e0f9d59d117c49f9909b3
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
using DevExpress.XtraLayout;
using Furion.DataValidation;
using NetTaste;
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;
 
namespace HStation.WinFrmUI.Auth
{
    public partial class MenuInfoCtrl : UserControl
    {
        public MenuInfoCtrl()
        {
            InitializeComponent();
        }
        Yw.BLL.ProjectMenu _sever = new Yw.BLL.ProjectMenu();
        string error;
        Yw.Vmo.ProjectMenu _Menu;
        long pjid = 0;
        public async void SetimageComboBoxEditParentName()
        {
            List<Yw.Dto.ProjectMenuDto>  AllMenu = await _sever.GetByProjectID(pjid);
            if (imageComboBoxEditType.SelectedIndex == 1)
            {
                imageComboBoxEditParentName.Properties.Items.Clear();
                imageComboBoxEditParentName.Properties.Items.Add("无", 0, -1);
                foreach (var item in AllMenu)
                {
                    if(item.Type == 0)
                    {
                        imageComboBoxEditParentName.EditValue = null;
                        imageComboBoxEditParentName.Properties.Items.Add(item.Name, item.ID, -1);
                    }
                    
                }
                imageComboBoxEditParentName.SelectedIndex = 0;
            }
            else
            {
                imageComboBoxEditParentName.Properties.Items.Clear();
                foreach (var item in AllMenu)
                {
                    if (item.Type == 1)
                    {
                        imageComboBoxEditParentName.EditValue = null;
                        imageComboBoxEditParentName.Properties.Items.Add(item.Name, item.ID, -1);
                    }
                }
                imageComboBoxEditParentName.SelectedIndex = 0;
            }
           
        }
        public async Task<string> SetProjectMenu(Yw.Vmo.ProjectMenu projectMenu)
        {
            error = "";
            if (projectMenu.ID == 0)
            {
                return error = "入参为空!";
            }
            this._Menu = projectMenu;
            if (_Menu.ParentID == 0)
            {
                imageComboBoxEditParentName.SelectedItem = 0;
            }
            imageComboBoxEditType.SelectedIndex = this._Menu.Type;
            if (!this._Menu.IsHide)
            {
                imageComboBoxEditIsHide.SelectedIndex = 0;
            }
            else
            {
                imageComboBoxEditIsHide.SelectedIndex = 1;
            }
            textEditPermission.Text = this._Menu.Permission;
            if (this._Menu.Weight == Yw.Vmo.eAuthWeight.Normal)
            {
                radioGroupWeight.SelectedIndex = 0;
            }
            else if (this._Menu.Weight == Yw.Vmo.eAuthWeight.Admin)
            {
                radioGroupWeight.SelectedIndex = 1;
            }
            else
            {
                radioGroupWeight.SelectedIndex = 2;
            }
            textEditDescription.Text = this._Menu.Description;
            var _AllMenu =await _sever.GetByProjectID(pjid);
            textEditName.Text = this._Menu.Name;
            foreach (var item in _AllMenu)
            {
                if (item.ID == this._Menu.ParentID)
                {
                    imageComboBoxEditParentName.SelectedItem = item.Name;
                    break;
                }
            }
            
            return error;
        }
 
        public Yw.Vmo.ProjectMenu GetProjectMenu(Yw.Vmo.ProjectMenu projectMenu, out string error)
        {
            error = "";
            Yw.Vmo.ProjectMenu menu = projectMenu;
            dxValidationProviderIsNotBlank.Validate();
            if (textEditName.Name == null)
            {
                error = "名称为空!";
                return null;
            }
            if (imageComboBoxEditType.SelectedIndex != 0 && imageComboBoxEditParentName.SelectedIndex == 0)
            {
                error = "没有选择父节点!";
                return null;
            }
            menu.Name = textEditName.Text;
            menu.Description = textEditDescription.Text;
            menu.Permission = textEditPermission.Text;
            menu.Type = imageComboBoxEditType.SelectedIndex;
            menu.ParentID = Convert.ToInt64(imageComboBoxEditParentName.EditValue);
            menu.IsHide = Convert.ToInt64(imageComboBoxEditIsHide.EditValue) == 0 ? false : true;
            if (radioGroupWeight.SelectedIndex == 0)
            {
                menu.Weight = Yw.Vmo.eAuthWeight.Normal;
            }
            else if (radioGroupWeight.SelectedIndex == 1)
            {
                menu.Weight = Yw.Vmo.eAuthWeight.Admin;
            }
            else
            {
                menu.Weight = Yw.Vmo.eAuthWeight.System;
            }
 
            return menu;
        }
        public Yw.Vmo.ProjectMenu OperateData(Yw.Vmo.ProjectMenu projectMenu, out string error)
        {
            error = "";
            this._Menu = projectMenu;
            if (this._Menu.ID == 0)
            {
                this._Menu = GetProjectMenu(this._Menu, out error);
                if (!string.IsNullOrEmpty(error))
                {
                    return null;
                }
                return this._Menu;
            }
            else
            {
                this._Menu = GetProjectMenu(this._Menu, out error);
                
                if (!string.IsNullOrEmpty(error))
                {
                    return null;
                }
                if (this._Menu.ID == 0)
                {
                    error = "出现错误!";
                    return null;
                }
                return this._Menu;
            }
 
        }
 
        private void imageComboBoxEditType_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (imageComboBoxEditType.SelectedIndex == 0)
            {
                layoutControlItem.Text = "父节点:";
                imageComboBoxEditParentName.Enabled = false;
            }
            else
            {
                layoutControlItem.Text = "*父节点:";
                SetimageComboBoxEditParentName();
                imageComboBoxEditParentName.Enabled = true;
            }
        }
    }
}