| | |
| | | using DevExpress.XtraEditors; |
| | | using DevExpress.XtraBars; |
| | | using DevExpress.XtraEditors; |
| | | using Gs.DevApp.Entity; |
| | | using Gs.DevApp.ToolBox; |
| | | using Newtonsoft.Json; |
| | | using System; |
| | | |
| | | using System.Collections.Generic; |
| | | using System.Data; |
| | | using System.Linq; |
| | | using System.Windows.Forms; |
| | | |
| | | namespace Gs.DevApp.UserControl |
| | | { |
| | | public partial class ToolBarMenu : DevExpress.XtraEditors.XtraUserControl |
| | | { |
| | | public bool isSetBtn { get; set; } |
| | | public List<string> actions { get; set; } |
| | | /// <summary> |
| | | /// 新增 |
| | | /// </summary> |
| | |
| | | public event EventHandler btnSaveClick; |
| | | |
| | | /// <summary> |
| | | /// 取消 |
| | | /// </summary> |
| | | public event EventHandler btnEscClick; |
| | | |
| | | /// <summary> |
| | | /// 开工 |
| | | /// </summary> |
| | | public event EventHandler btnKGClick; |
| | | |
| | | /// <summary> |
| | | /// 权限 |
| | | /// </summary> |
| | | public event EventHandler btnRoleClick; |
| | | |
| | | |
| | | public ToolBarMenu() |
| | |
| | | this.btnLoad.ItemClick += BtnLoad_ItemClick; |
| | | this.btnSave.ItemClick += BtnSave_ItemClick; |
| | | this.btnKG.ItemClick += BtnKG_ItemClick; |
| | | this.btnEsc.ItemClick += BtnEsc_ItemClick; |
| | | this.btnRole.ItemClick += BtnRole_ItemClick; |
| | | initialization(); |
| | | List<string> lst = new List<string>(); |
| | | foreach (BarItem item in barManager1.Items) |
| | | { |
| | | if (item is BarLargeButtonItem largeButtonItem) |
| | | { |
| | | lst.Add(item.Caption); |
| | | } |
| | | } |
| | | this.actions = lst; |
| | | } |
| | | protected override void OnCreateControl() |
| | | { |
| | | base.OnCreateControl(); |
| | | if (this.Parent != null) |
| | | { |
| | | getNamespace(); |
| | | } |
| | | } |
| | | private void initialization() |
| | | { |
| | | List<string> lst = new List<string>(); |
| | | lst.Add(btnAdd.Name); |
| | | lst.Add(btnEdit.Name); |
| | | lst.Add(btnLoad.Name); |
| | | lst.Add(btnDel.Name); |
| | | lst.Add(btnRole.Name); |
| | | setBtn(lst); |
| | | |
| | | } |
| | | |
| | | private void BtnEsc_ItemClick(object sender, ItemClickEventArgs e) |
| | | { |
| | | if (MsgHelper.AskQuestion("确定要要取消吗?")) |
| | | { |
| | | List<string> lst = new List<string>(); |
| | | lst.Add(btnAdd.Name); |
| | | lst.Add(btnEdit.Name); |
| | | lst.Add(btnLoad.Name); |
| | | lst.Add(btnDel.Name); |
| | | lst.Add(btnRole.Name); |
| | | setBtn(lst); |
| | | if (btnEscClick != null) |
| | | { |
| | | btnEscClick(this, e); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void BtnKG_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) |
| | |
| | | if (btnSaveClick != null) |
| | | { |
| | | btnSaveClick(this, e); |
| | | if (isSetBtn == true) |
| | | { |
| | | List<string> lst = new List<string>(); |
| | | lst.Add(btnAdd.Name); |
| | | lst.Add(btnEdit.Name); |
| | | lst.Add(btnEsc.Name); |
| | | setBtn(lst); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void BtnLoad_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) |
| | | { |
| | | |
| | | if (btnLoadClick != null) |
| | | { |
| | | //List<string> lst = new List<string>(); |
| | | //lst.Add(btnRole.Name); |
| | | //setBtn(lst); |
| | | btnLoadClick(this, e); |
| | | } |
| | | |
| | | } |
| | | |
| | | private void BtnEdit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) |
| | | { |
| | | List<string> lst = new List<string>(); |
| | | lst.Add(btnSave.Name); |
| | | lst.Add(btnEsc.Name); |
| | | |
| | | setBtn(lst); |
| | | if (btnEdtClick != null) |
| | | { |
| | | btnEdtClick(this, e); |
| | |
| | | |
| | | private void BtnDel_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) |
| | | { |
| | | if (btnDelClick != null) { |
| | | if (btnDelClick != null) |
| | | { |
| | | btnDelClick(this, e); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <param name="sender"></param> |
| | | /// <param name="e"></param> |
| | | private void BtnAdd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) |
| | | { |
| | | List<string> lst = new List<string>(); |
| | | lst.Add(btnSave.Name); |
| | | lst.Add(btnEsc.Name); |
| | | setBtn(lst); |
| | | if (btnAddClick != null) |
| | | { |
| | | btnAddClick(this, e); |
| | | } |
| | | |
| | | } |
| | | |
| | | private void BtnRole_ItemClick(object sender, ItemClickEventArgs e) |
| | | { |
| | | //List<string> lst = new List<string>(); |
| | | //lst.Add(btnSave.Name); |
| | | //lst.Add(btnEsc.Name); |
| | | //setBtn(lst); |
| | | if (btnRoleClick != null) |
| | | { |
| | | btnRoleClick(this, e); |
| | | } |
| | | } |
| | | private void setBtn(List<string> lstBtn) |
| | | { |
| | | foreach (BarItem item in barManager1.Items) |
| | | { |
| | | if (item is BarLargeButtonItem largeButtonItem) |
| | | { |
| | | if (lstBtn.Contains(item.Name)) |
| | | largeButtonItem.Enabled = true; |
| | | else |
| | | largeButtonItem.Enabled = false; |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据命名空间,读取该窗体下面的按钮集合 |
| | | /// </summary> |
| | | private void getNamespace() |
| | | { |
| | | string _formNamespace = ""; |
| | | Control parentControl = this; |
| | | while (parentControl.Parent != null) |
| | | { |
| | | if (parentControl.Parent is Form parentForm) |
| | | { |
| | | Type formType = parentForm.GetType(); |
| | | _formNamespace = formType.FullName; |
| | | break; |
| | | } |
| | | parentControl = parentControl.Parent; |
| | | } |
| | | var _obj = new |
| | | { |
| | | userGuid = LoginInfoModel.CurrentUser.LoginUserGuid, |
| | | orgGuid = LoginInfoModel.CurrentUser.LoginOrgGuid, |
| | | formNamespace = _formNamespace, |
| | | }; |
| | | string strReturn = ""; |
| | | try |
| | | { |
| | | strReturn = UtilityHelper.HttpPost("", "MenuAction/GetListByUserOrgSpace", JsonConvert.SerializeObject(_obj)); |
| | | ReturnModel<DataTable> dd = UtilityHelper.GetNoPageTableByJson(strReturn); |
| | | DataTable dt = dd.rtnData; |
| | | foreach (BarItem item in barManager1.Items) |
| | | { |
| | | if (item.Caption == "取消" || item.Caption == "刷新" || item.Caption == "保存") |
| | | { |
| | | item.Visibility = BarItemVisibility.Always; |
| | | continue; |
| | | } |
| | | bool exists = dt.AsEnumerable().Any(row => row.Field<string>("name") == item.Caption); |
| | | if (exists == false) |
| | | item.Visibility = BarItemVisibility.Never; |
| | | else |
| | | item.Visibility = BarItemVisibility.Always; |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | ToolBox.MsgHelper.Warning("提示:" + ex.Message); |
| | | } |
| | | } |
| | | } |
| | | } |