From c78ffe15080b3218671f03c7d85a5e8edd484b62 Mon Sep 17 00:00:00 2001
From: lg <999544862qq.com>
Date: 星期日, 22 九月 2024 20:54:15 +0800
Subject: [PATCH] 仓库管理

---
 DevApp/Gs.DevApp/UserControl/ToolBarMenu.cs |  192 ++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 171 insertions(+), 21 deletions(-)

diff --git a/DevApp/Gs.DevApp/UserControl/ToolBarMenu.cs b/DevApp/Gs.DevApp/UserControl/ToolBarMenu.cs
index 8d815e0..c1db253 100644
--- a/DevApp/Gs.DevApp/UserControl/ToolBarMenu.cs
+++ b/DevApp/Gs.DevApp/UserControl/ToolBarMenu.cs
@@ -1,15 +1,19 @@
 锘縰sing 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; }
         /// <summary>
         /// 鏂板
         /// </summary>
@@ -50,6 +54,16 @@
         /// </summary>
         public event EventHandler btnRoleClick;
 
+        /// <summary>
+        /// 鏉冮檺
+        /// </summary>
+        public event EventHandler btnReportClick;
+
+        /// <summary>
+        /// 鏉冮檺
+        /// </summary>
+        public event EventHandler btnQueryClick;
+
 
         public ToolBarMenu()
         {
@@ -62,17 +76,47 @@
             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)
+                {
+                    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 initialization() {
-            List<string> lst = new List<string>();
-            lst.Add(btnAdd.Name);
-            lst.Add(btnEdit.Name);
-            lst.Add(btnLoad.Name);
-            lst.Add(btnDel.Name);
-            setBtn(lst);
+        private void BtnReport_ItemClick(object sender, ItemClickEventArgs e)
+        {
+            if (btnReportClick != null)
+            {
+                btnReportClick(this, e);
+            }
+        }
+        /// <summary>
+        /// 鍒濆鍖栨寜閽姸鎬�
+        /// </summary>
+        protected override void OnCreateControl()
+        {
+            base.OnCreateControl();
+            if (this.Parent != null)
+            {
+                getNamespace();
+            }
         }
 
         private void BtnEsc_ItemClick(object sender, ItemClickEventArgs e)
@@ -84,7 +128,8 @@
                 lst.Add(btnEdit.Name);
                 lst.Add(btnLoad.Name);
                 lst.Add(btnDel.Name);
-                setBtn(lst);
+                lst.Add(btnRole.Name);
+                _enabledBtn(lst);
                 if (btnEscClick != null)
                 {
                     btnEscClick(this, e);
@@ -105,24 +150,25 @@
             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);
                     lst.Add(btnEsc.Name);
-                    setBtn(lst);
+                    _enabledBtn(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);
+                //List<string> lst = new List<string>();
+                //lst.Add(btnRole.Name);
+                //setBtn(lst);
                 btnLoadClick(this, e);
             }
 
@@ -133,8 +179,8 @@
             List<string> lst = new List<string>();
             lst.Add(btnSave.Name);
             lst.Add(btnEsc.Name);
-          
-            setBtn(lst);
+
+            _enabledBtn(lst);
             if (btnEdtClick != null)
             {
                 btnEdtClick(this, e);
@@ -159,7 +205,7 @@
             List<string> lst = new List<string>();
             lst.Add(btnSave.Name);
             lst.Add(btnEsc.Name);
-            setBtn(lst);
+            _enabledBtn(lst);
             if (btnAddClick != null)
             {
                 btnAddClick(this, e);
@@ -178,7 +224,7 @@
                 btnRoleClick(this, e);
             }
         }
-        private void setBtn(List<string> lstBtn)
+        private void _enabledBtn(List<string> lstBtn)
         {
             foreach (BarItem item in barManager1.Items)
             {
@@ -191,5 +237,109 @@
                 }
             }
         }
+
+        /// <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("", "Role/GetListByUserOrgSpace", JsonConvert.SerializeObject(_obj));
+                ReturnModel<DataTable> dd = UtilityHelper.ReturnToList(strReturn);
+                DataTable dt = dd.rtnData;
+                List<string> _enabledList = new List<string>();
+                foreach (BarItem item in barManager1.Items)
+                {
+                    ///鍏锋湁鑱斿姩鍏崇郴鐨勬寜閽�(澧炲姞)锛�
+                    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;
+                        //鍑嗗鍚敤
+                        string _btnName = _FindBarLargeButtonItemByCaption(item.Caption);
+                        if (!string.IsNullOrEmpty(_btnName))
+                            _enabledList.Add(_btnName);
+                    }
+                }
+                _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;
+        }
     }
 }

--
Gitblit v1.9.3