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 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 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; } } } }