| | |
| | | public partial class ToolBarMenu : DevExpress.XtraEditors.XtraUserControl |
| | | { |
| | | public bool isSetBtn { get; set; } |
| | | public List<string> actions { get; set; } |
| | | public List<string> actions { get; } |
| | | /// <summary> |
| | | /// 新增 |
| | | /// </summary> |
| | |
| | | /// </summary> |
| | | public event EventHandler btnRoleClick; |
| | | |
| | | /// <summary> |
| | | /// 权限 |
| | | /// </summary> |
| | | public event EventHandler btnReportClick; |
| | | |
| | | /// <summary> |
| | | /// 权限 |
| | | /// </summary> |
| | | public event EventHandler btnQueryClick; |
| | | |
| | | |
| | | public ToolBarMenu() |
| | | { |
| | |
| | | this.btnKG.ItemClick += BtnKG_ItemClick; |
| | | this.btnEsc.ItemClick += BtnEsc_ItemClick; |
| | | this.btnRole.ItemClick += BtnRole_ItemClick; |
| | | initialization(); |
| | | this.btnReport.ItemClick += BtnReport_ItemClick; |
| | | this.btnQuery.ItemClick += BtnQuery_ItemClick; |
| | | List<string> lst = new List<string>(); |
| | | foreach (BarItem item in barManager1.Items) |
| | | { |
| | | if (item is BarLargeButtonItem largeButtonItem) |
| | | { |
| | | lst.Add(item.Caption); |
| | | if (!string.IsNullOrEmpty(item.Caption)) |
| | | lst.Add(item.Caption); |
| | | } |
| | | } |
| | | this.actions = lst; |
| | | //初始化按钮状态 |
| | | // initialization(); |
| | | } |
| | | |
| | | private void BtnQuery_ItemClick(object sender, ItemClickEventArgs e) |
| | | { |
| | | if (btnQueryClick != null) |
| | | { |
| | | btnQueryClick(this, e); |
| | | } |
| | | } |
| | | |
| | | private void BtnReport_ItemClick(object sender, ItemClickEventArgs e) |
| | | { |
| | | if (btnReportClick != null) |
| | | { |
| | | btnReportClick(this, e); |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// 初始化按钮状态 |
| | | /// </summary> |
| | | protected override void OnCreateControl() |
| | | { |
| | | base.OnCreateControl(); |
| | |
| | | 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 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); |
| | | // //lst.Add(btnReport.Name); |
| | | // //lst.Add(btnQuery.Name); |
| | | // setBtn(lst); |
| | | //} |
| | | |
| | | private void BtnEsc_ItemClick(object sender, ItemClickEventArgs e) |
| | | { |
| | |
| | | lst.Add(btnLoad.Name); |
| | | lst.Add(btnDel.Name); |
| | | lst.Add(btnRole.Name); |
| | | setBtn(lst); |
| | | _enabledBtn(lst); |
| | | if (btnEscClick != null) |
| | | { |
| | | btnEscClick(this, e); |
| | |
| | | lst.Add(btnAdd.Name); |
| | | lst.Add(btnEdit.Name); |
| | | lst.Add(btnEsc.Name); |
| | | setBtn(lst); |
| | | _enabledBtn(lst); |
| | | } |
| | | } |
| | | } |
| | |
| | | lst.Add(btnSave.Name); |
| | | lst.Add(btnEsc.Name); |
| | | |
| | | setBtn(lst); |
| | | _enabledBtn(lst); |
| | | if (btnEdtClick != null) |
| | | { |
| | | btnEdtClick(this, e); |
| | |
| | | List<string> lst = new List<string>(); |
| | | lst.Add(btnSave.Name); |
| | | lst.Add(btnEsc.Name); |
| | | setBtn(lst); |
| | | _enabledBtn(lst); |
| | | if (btnAddClick != null) |
| | | { |
| | | btnAddClick(this, e); |
| | |
| | | btnRoleClick(this, e); |
| | | } |
| | | } |
| | | private void setBtn(List<string> lstBtn) |
| | | private void _enabledBtn(List<string> lstBtn) |
| | | { |
| | | foreach (BarItem item in barManager1.Items) |
| | | { |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据命名空间,读取该窗体下面的按钮集合 |
| | | /// 根据命名空间和权限,读取该窗体下面的按钮集合 |
| | | /// </summary> |
| | | private void getNamespace() |
| | | { |
| | |
| | | strReturn = UtilityHelper.HttpPost("", "MenuAction/GetListByUserOrgSpace", JsonConvert.SerializeObject(_obj)); |
| | | ReturnModel<DataTable> dd = UtilityHelper.GetNoPageTableByJson(strReturn); |
| | | DataTable dt = dd.rtnData; |
| | | List<string> _enabledList = new List<string>(); |
| | | foreach (BarItem item in barManager1.Items) |
| | | { |
| | | if (item.Caption == "取消" || item.Caption == "刷新" || item.Caption == "保存") |
| | | ///具有联动关系的按钮(增加), |
| | | if (item.Caption == "增加") |
| | | { |
| | | bool ld1 = dt.AsEnumerable().Any(row => row.Field<string>("name") == "增加" |
| | | //|| row.Field<string>("name") == "修改" |
| | | ); |
| | | if (ld1 == true) |
| | | { |
| | | btnEsc.Visibility = btnSave.Visibility = btnLoad.Visibility = BarItemVisibility.Always; |
| | | btnAdd.Visibility = BarItemVisibility.Always; |
| | | _enabledList.Add(item.Name); |
| | | continue; |
| | | } |
| | | } |
| | | ///具有联动关系的按钮(修改), |
| | | if (item.Caption == "修改") |
| | | { |
| | | bool ld1 = dt.AsEnumerable().Any(row => row.Field<string>("name") == "修改" |
| | | ); |
| | | if (ld1 == true) |
| | | { |
| | | btnEsc.Visibility = btnSave.Visibility = btnLoad.Visibility = BarItemVisibility.Always; |
| | | btnEdit.Visibility = BarItemVisibility.Always; |
| | | _enabledList.Add(item.Name); |
| | | continue; |
| | | } |
| | | } |
| | | ///具有联动关系的按钮(查询), |
| | | bool ld2 = dt.AsEnumerable().Any(row => row.Field<string>("name") == "查询" |
| | | ); |
| | | if (ld2 == true) |
| | | { |
| | | if (item.Caption == "刷新") |
| | | { |
| | | item.Visibility = BarItemVisibility.Always; |
| | | //准备启用 |
| | | _enabledList.Add(item.Name); |
| | | continue; |
| | | } |
| | | } |
| | | //按钮是否在权限表中 |
| | | bool exists = dt.AsEnumerable().Any(row => row.Field<string>("name") == item.Caption); |
| | | if (exists == true) |
| | | { |
| | | item.Visibility = BarItemVisibility.Always; |
| | | continue; |
| | | //准备启用 |
| | | string _btnName = _FindBarLargeButtonItemByCaption(item.Caption); |
| | | if (!string.IsNullOrEmpty(_btnName)) |
| | | _enabledList.Add(_btnName); |
| | | } |
| | | bool exists = dt.AsEnumerable().Any(row => row.Field<string>("name") == item.Caption); |
| | | if (exists == false) |
| | | item.Visibility = BarItemVisibility.Never; |
| | | else |
| | | item.Visibility = BarItemVisibility.Always; |
| | | } |
| | | _enabledBtn(_enabledList); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | ToolBox.MsgHelper.Warning("提示:" + ex.Message); |
| | | } |
| | | } |
| | | |
| | | |
| | | private string _FindBarLargeButtonItemByCaption(string caption) |
| | | { |
| | | foreach (BarItem item in barManager1.Items) |
| | | { |
| | | if (item is BarLargeButtonItem largeButtonItem && largeButtonItem.Caption == caption) |
| | | { |
| | | return largeButtonItem.Name; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | } |
| | | } |