From 65927056612a7ffef20708aefda33d09be51ef6b Mon Sep 17 00:00:00 2001 From: lg <999544862qq.com> Date: 星期日, 08 九月 2024 22:16:00 +0800 Subject: [PATCH] 权限整理 --- DevApp/Gs.DevApp/UserControl/ToolBarMenu.cs | 94 ++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 84 insertions(+), 10 deletions(-) diff --git a/DevApp/Gs.DevApp/UserControl/ToolBarMenu.cs b/DevApp/Gs.DevApp/UserControl/ToolBarMenu.cs index 8d815e0..2387192 100644 --- a/DevApp/Gs.DevApp/UserControl/ToolBarMenu.cs +++ b/DevApp/Gs.DevApp/UserControl/ToolBarMenu.cs @@ -1,15 +1,20 @@ 锘縰sing DevExpress.XtraBars; using DevExpress.XtraEditors; +using Gs.DevApp.Models; 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> @@ -63,16 +68,34 @@ 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; } - - - private void initialization() { + 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) @@ -84,6 +107,7 @@ lst.Add(btnEdit.Name); lst.Add(btnLoad.Name); lst.Add(btnDel.Name); + lst.Add(btnRole.Name); setBtn(lst); if (btnEscClick != null) { @@ -105,7 +129,8 @@ if (btnSaveClick != null) { btnSaveClick(this, e); - if (isSetBtn == true) { + if (isSetBtn == true) + { List<string> lst = new List<string>(); lst.Add(btnAdd.Name); lst.Add(btnEdit.Name); @@ -117,12 +142,12 @@ 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); + //List<string> lst = new List<string>(); + //lst.Add(btnRole.Name); + //setBtn(lst); btnLoadClick(this, e); } @@ -133,7 +158,7 @@ List<string> lst = new List<string>(); lst.Add(btnSave.Name); lst.Add(btnEsc.Name); - + setBtn(lst); if (btnEdtClick != null) { @@ -191,5 +216,54 @@ } } } + + /// <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); + } + } } } -- Gitblit v1.9.3