From 1a2bcaa7bec4f0bc681e55d1ccc61b14427c98ce Mon Sep 17 00:00:00 2001
From: lixiaojun <1287241240@qq.com>
Date: 星期六, 25 一月 2025 12:45:20 +0800
Subject: [PATCH] 增加构件自定义参数

---
 WinFrmUI/HStation.WinFrmUI.Xhs.Core/03-simulation/05-function/SimulationFunctionCtrl.cs |  338 ++++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 265 insertions(+), 73 deletions(-)

diff --git a/WinFrmUI/HStation.WinFrmUI.Xhs.Core/03-simulation/05-function/SimulationFunctionCtrl.cs b/WinFrmUI/HStation.WinFrmUI.Xhs.Core/03-simulation/05-function/SimulationFunctionCtrl.cs
index 32f0e88..4ac3b54 100644
--- a/WinFrmUI/HStation.WinFrmUI.Xhs.Core/03-simulation/05-function/SimulationFunctionCtrl.cs
+++ b/WinFrmUI/HStation.WinFrmUI.Xhs.Core/03-simulation/05-function/SimulationFunctionCtrl.cs
@@ -1,6 +1,5 @@
-锘縰sing DevExpress.Utils.Extensions;
-using DevExpress.Utils.Svg;
-using Yw.DAL.Basic;
+锘縰sing DevExpress.Utils.Svg;
+using System.Collections.Concurrent;
 using Yw.Vmo;
 
 namespace HStation.WinFrmUI
@@ -22,13 +21,13 @@
         /// </summary>
         public event Action<XhsProjectVmo, XhsProjectSiteVmo, XhsSchemeVmo, Yw.Model.HydroModelInfo, Dictionary<HydroWorkingVmo, bool>, SvgImage> ShowProjectSiteSimulationEvent;
         /// <summary>
-        /// 鏄剧ず椤圭洰绔欏伐鍐典簨浠�
-        /// </summary>
-        public event Action<XhsProjectVmo, XhsProjectSiteVmo, XhsSchemeVmo, Yw.Model.HydroModelInfo, HydroWorkingVmo, SvgImage> ShowProjectSiteWorkingEvent;
-        /// <summary>
         /// 椤圭洰绔欏伐鍐甸�夋嫨鏀瑰彉浜嬩欢
         /// </summary>
         public event Action<XhsProjectVmo, XhsProjectSiteVmo, XhsSchemeVmo, HydroWorkingVmo, bool> ProjectSiteWorkingCheckedEvent;
+        /// <summary>
+        /// 椤圭洰绔欏伐鍐靛鍔犱簨浠�
+        /// </summary>
+        public event Action<XhsProjectVmo, XhsProjectSiteVmo, XhsSchemeVmo, HydroWorkingVmo> ProjectSiteWorkingAppendEvent;
         /// <summary>
         /// 椤圭洰绔欏伐鍐垫洿鏂颁簨浠�
         /// </summary>
@@ -40,7 +39,19 @@
         /// <summary>
         /// 鍒涘缓椤圭洰绔欐柟妗堜簨浠�
         /// </summary>
-        public event Action<XhsProjectVmo, XhsProjectSiteVmo, Yw.Model.HydroModelInfo, SvgImage> CreateProjectSiteSchemeEvent;
+        public event Action<XhsProjectVmo, XhsProjectSiteVmo, Yw.Model.HydroModelInfo, List<XhsSchemeVmo>, SvgImage> CreateProjectSiteSchemeEvent;
+        /// <summary>
+        /// 椤圭洰绔欐柟妗堝鍔犱簨浠�
+        /// </summary>
+        public event Action<XhsProjectVmo, XhsProjectSiteVmo, XhsSchemeVmo> ProjectSiteSchemeAppendEvent;
+        /// <summary>
+        /// 椤圭洰绔欐柟妗堟洿鏂颁簨浠�
+        /// </summary>
+        public event Action<XhsProjectVmo, XhsProjectSiteVmo, XhsSchemeVmo> ProjectSiteSchemeUpdateEvent;
+        /// <summary>
+        /// 椤圭洰绔欐柟妗堢Щ闄や簨浠�
+        /// </summary>
+        public event Action<XhsProjectVmo, XhsProjectSiteVmo, XhsSchemeVmo> ProjectSiteSchemeRemoveEvent;
 
         private XhsProjectVmo _project = null;//椤圭洰
         private XhsProjectSiteVmo _projectSite = null;//椤圭洰绔�
@@ -48,6 +59,7 @@
         private Dictionary<HydroWorkingVmo, bool> _allWorkingCheckedListDict = null;//鎵�鏈夊伐鍐甸�夋嫨鍒楄〃瀛楀吀
         private Dictionary<XhsSchemeVmo, Yw.Model.HydroModelInfo> _allSchemeHydroInfoDict = null;//鎵�鏈夋柟妗堟按鍔涗俊鎭垪琛�
         private Dictionary<XhsSchemeVmo, Dictionary<HydroWorkingVmo, bool>> _allSchemeWorkingCheckedListDict = null;//鎵�鏈夋柟妗堝伐鍐甸�夋嫨鍒楄〃瀛楀吀
+        private ConcurrentDictionary<string, bool> _gettingHydroInfoDict = new ConcurrentDictionary<string, bool>();//鑾峰彇姘村姏淇℃伅瀛楀吀
 
         /// <summary>
         /// 缁戝畾鏁版嵁
@@ -89,6 +101,78 @@
             });
             await ShowInfo();
             overlay.Close();
+            this.accordionControl1.ExpandAll();
+        }
+
+        //椤圭洰绔欐鍐�
+        private async void elementProjectSiteInfo_Click(object sender, EventArgs e)
+        {
+            await ShowInfo();
+        }
+
+        //椤圭洰绔欐按鍔涙ā鎷�
+        private async void elementProjectSiteSimulation_Click(object sender, EventArgs e)
+        {
+            if (_project == null)
+            {
+                return;
+            }
+            if (_projectSite == null)
+            {
+                return;
+            }
+            var hydroInfo = await GetHydroInfo(null, true);
+            if (hydroInfo == null)
+            {
+                return;
+            }
+            this.ShowProjectSiteSimulationEvent?.Invoke(_project, _projectSite, null, hydroInfo, _allWorkingCheckedListDict, this.svgImg32[1]);
+        }
+
+        //鍒涘缓椤圭洰绔欐柟妗�
+        private async void accordionControl1_ContextButtonClick(object sender, DevExpress.Utils.ContextItemClickEventArgs e)
+        {
+            if (_project == null)
+            {
+                return;
+            }
+            if (_projectSite == null)
+            {
+                return;
+            }
+            var element = e.DataItem as DevExpress.XtraBars.Navigation.AccordionControlElement;
+            if (element != this.elementProjectSiteSchemeList)
+            {
+                return;
+            }
+            var hydroInfo = await GetHydroInfo(null, true);
+            if (hydroInfo == null)
+            {
+                return;
+            }
+            var allSchemeList = _allSchemeHydroInfoDict?.Keys.ToList();
+            this.CreateProjectSiteSchemeEvent?.Invoke(_project, _projectSite, hydroInfo, allSchemeList, this.svgImg32[3]);
+        }
+
+        //鍙抽敭寮瑰嚭
+        private void accordionControl1_MouseClick(object sender, MouseEventArgs e)
+        {
+            if (e.Button == MouseButtons.Right)
+            {
+                this.popupMenu1.ShowPopup(MousePosition);
+            }
+        }
+
+        //鍏ㄩ儴鎶樺彔
+        private void barBtnCollpseAll_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
+        {
+            this.accordionControl1.CollapseAll();
+        }
+
+        //鍏ㄩ儴灞曞紑
+        private void barBtnExpandAll_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
+        {
+            this.accordionControl1.ExpandAll();
         }
 
         #region 閫氱敤鏂规硶
@@ -102,7 +186,10 @@
             Yw.Model.HydroModelInfo hydroInfo = null;
             if (!useCache)
             {
-                hydroInfo = await GetHydroInfo(scheme);
+                if (hydroInfo == null)
+                {
+                    hydroInfo = await GetHydroInfo(scheme);
+                }
                 if (hydroInfo == null)
                 {
                     return default;
@@ -115,7 +202,15 @@
                 {
                     if (_hydroInfo == null)
                     {
-                        _hydroInfo = await GetHydroInfo(null);
+                        hydroInfo = await GetHydroInfo(null);
+                        if (hydroInfo == null)
+                        {
+                            return default;
+                        }
+                        if (_hydroInfo == null)
+                        {
+                            _hydroInfo = hydroInfo;
+                        }
                     }
                     return _hydroInfo;
                 }
@@ -133,9 +228,16 @@
                 if (!_allSchemeHydroInfoDict.ContainsKey(scheme))
                 {
                     hydroInfo = await GetHydroInfo(scheme);
-                    _allSchemeHydroInfoDict.Add(scheme, hydroInfo);
-                    return hydroInfo;
+                    if (hydroInfo == null)
+                    {
+                        return default;
+                    }
+                    if (!_allSchemeHydroInfoDict.ContainsKey(scheme))
+                    {
+                        _allSchemeHydroInfoDict.Add(scheme, hydroInfo);
+                    }
                 }
+                return _allSchemeHydroInfoDict[scheme];
             }
 
             if (_allSchemeHydroInfoDict.ContainsKey(scheme))
@@ -147,7 +249,7 @@
                 _allSchemeHydroInfoDict.Add(scheme, hydroInfo);
             }
 
-            return hydroInfo;
+            return _allSchemeHydroInfoDict[scheme];
         }
 
         //鑾峰彇姘村姏淇℃伅
@@ -160,6 +262,21 @@
             if (_projectSite == null)
             {
                 return default;
+            }
+            string key = $"{_project.ID}-{_projectSite.ID}-{scheme?.ID}";
+            if (_gettingHydroInfoDict.TryGetValue(key, out bool getting))
+            {
+                if (getting)
+                {
+                    return default;
+                }
+            }
+
+            WaitFormHelper.ShowWaitForm(this.FindForm(), "姝e湪鍔犺浇妯″瀷鏁版嵁锛岃绋嶅悗...");
+            //var overlay = this.ShowOverlay();
+            if (!_gettingHydroInfoDict.TryAdd(key, true))
+            {
+                _gettingHydroInfoDict[key] = true;
             }
 
             HydroModelRelationVmo relation = null;
@@ -178,11 +295,15 @@
                 return default;
             }
             var hydroInfo = await BLLFactory<Yw.BLL.HydroModelInfo>.Instance.GetByID(relation.ModelID);
+            _gettingHydroInfoDict[key] = false;
+            //overlay.Close();
+            WaitFormHelper.HideWaitForm();
             return hydroInfo;
         }
 
         /// <summary>
         /// 娣诲姞鏂规
+        /// 瑙﹀彂椤圭洰绔欐柟妗堝鍔犱簨浠�
         /// </summary>
         public void AppendScheme(XhsSchemeVmo scheme)
         {
@@ -236,11 +357,127 @@
             {
                 _allSchemeWorkingCheckedListDict.Add(scheme, new Dictionary<HydroWorkingVmo, bool>());
             }
+            this.ProjectSiteSchemeAppendEvent?.Invoke(_project, _projectSite, scheme);
+        }
+
+        /// <summary>
+        /// 鏇存柊鏂规
+        /// 瑙﹀彂椤圭洰绔欐柟妗堟洿鏂颁簨浠�
+        /// </summary>
+        public void UpdateScheme(XhsSchemeVmo scheme)
+        {
+            if (_project == null)
+            {
+                return;
+            }
+            if (_projectSite == null)
+            {
+                return;
+            }
+            if (scheme == null)
+            {
+                return;
+            }
+
+            var elementScheme = this.elementProjectSiteSchemeList.Elements
+                   .FirstOrDefault(x => (x.Tag is XhsSchemeVmo) && (x.Tag as XhsSchemeVmo).ID == scheme.ID);
+            if (elementScheme == null)
+            {
+                return;
+            }
+            elementScheme.Text = scheme.Name;
+            elementScheme.Hint = scheme.Description;
+            elementScheme.Tag = scheme;
+            if (_allSchemeHydroInfoDict != null && _allSchemeHydroInfoDict.Count > 0)
+            {
+                var schemeKey = _allSchemeHydroInfoDict.Keys.FirstOrDefault(x => x.ID == scheme.ID);
+                if (schemeKey != null)
+                {
+                    var hydroInfoValue = _allSchemeHydroInfoDict[schemeKey];
+                    _allSchemeHydroInfoDict.Remove(schemeKey);
+                    _allSchemeHydroInfoDict.Add(scheme, hydroInfoValue);
+                }
+            }
+            if (_allSchemeWorkingCheckedListDict != null && _allSchemeWorkingCheckedListDict.Count > 0)
+            {
+                var schemeKey = _allSchemeWorkingCheckedListDict.Keys.FirstOrDefault(x => x.ID == scheme.ID);
+                if (schemeKey != null)
+                {
+                    var workingCheckedValue = _allSchemeWorkingCheckedListDict[schemeKey];
+                    _allSchemeWorkingCheckedListDict.Remove(schemeKey);
+                    _allSchemeWorkingCheckedListDict.Add(scheme, workingCheckedValue);
+                }
+            }
+
+            this.ProjectSiteSchemeUpdateEvent?.Invoke(_project, _projectSite, scheme);
+        }
+
+        /// <summary>
+        /// 绉婚櫎鏂规
+        /// </summary>
+        public void RemoveScheme(XhsSchemeVmo scheme)
+        {
+            if (_project == null)
+            {
+                return;
+            }
+            if (_projectSite == null)
+            {
+                return;
+            }
+            if (scheme == null)
+            {
+                return;
+            }
+
+            var elementScheme = this.elementProjectSiteSchemeList.Elements
+                   .FirstOrDefault(x => (x.Tag is XhsSchemeVmo) && (x.Tag as XhsSchemeVmo).ID == scheme.ID);
+            if (elementScheme == null)
+            {
+                return;
+            }
+            if (elementScheme.Elements != null && elementScheme.Elements.Count > 0)
+            {
+                var workingElementList = elementScheme.Elements.ToList();
+                foreach (var workingElement in workingElementList)
+                {
+                    if (workingElement.HeaderControl != null)
+                    {
+                        this.accordionControl1.Controls.Remove(workingElement.HeaderControl);
+                    }
+                    elementScheme.Elements.Remove(workingElement);
+                }
+            }
+            this.elementProjectSiteSchemeList.Elements.Remove(elementScheme);
+
+            if (this.elementProjectSiteSchemeList.Elements.Count < 1)
+            {
+                this.elementProjectSiteSchemeList.Style = DevExpress.XtraBars.Navigation.ElementStyle.Item;
+            }
+
+            if (_allSchemeHydroInfoDict != null && _allSchemeHydroInfoDict.Count > 0)
+            {
+                var schemeKey = _allSchemeHydroInfoDict.Keys.FirstOrDefault(x => x.ID == scheme.ID);
+                if (schemeKey != null)
+                {
+                    _allSchemeHydroInfoDict.Remove(schemeKey);
+                }
+            }
+            if (_allSchemeWorkingCheckedListDict != null && _allSchemeWorkingCheckedListDict.Count > 0)
+            {
+                var schemeKey = _allSchemeWorkingCheckedListDict.Keys.FirstOrDefault(x => x.ID == scheme.ID);
+                if (schemeKey != null)
+                {
+                    _allSchemeWorkingCheckedListDict.Remove(schemeKey);
+                }
+            }
+
+            this.ProjectSiteSchemeRemoveEvent?.Invoke(_project, _projectSite, scheme);
         }
 
         /// <summary>
         /// 娣诲姞宸ュ喌
-        /// 绾坊鍔狅紝涓嶄細瑙﹀彂浜嬩欢
+        /// 瑙﹀彂椤圭洰绔欏伐鍐靛鍔犱簨浠�
         /// </summary>
         public void AppendWorking(XhsSchemeVmo scheme, Yw.Vmo.HydroWorkingVmo working)
         {
@@ -280,10 +517,9 @@
                 elementWorking.Text = working.Name;
                 elementWorking.Hint = working.Description;
                 elementWorking.Tag = working;
-                elementWorking.Click += async (sender, e) =>
+                elementWorking.Click += (sender, e) =>
                 {
-                    var hydroInfo = await GetHydroInfo(null, true);
-                    this.ShowProjectSiteWorkingEvent?.Invoke(_project, _projectSite, null, hydroInfo, working, this.svgImg32[4]);
+
                 };
                 this.elementProjectSiteSimulation.Elements.Add(elementWorking);
                 this.elementProjectSiteSimulation.Style = DevExpress.XtraBars.Navigation.ElementStyle.Group;
@@ -330,10 +566,9 @@
                 elementWorking.Text = working.Name;
                 elementWorking.Hint = working.Description;
                 elementWorking.Tag = working;
-                elementWorking.Click += async (sender, e) =>
+                elementWorking.Click += (sender, e) =>
                 {
-                    var hydroInfo = await GetHydroInfo(scheme, true);
-                    this.ShowProjectSiteWorkingEvent?.Invoke(_project, _projectSite, scheme, hydroInfo, working, this.svgImg32[4]);
+
                 };
                 elementScheme.Elements.Add(elementWorking);
                 elementScheme.Style = DevExpress.XtraBars.Navigation.ElementStyle.Group;
@@ -353,6 +588,8 @@
                     }
                 }
             }
+
+            this.ProjectSiteWorkingAppendEvent?.Invoke(_project, _projectSite, scheme, working);
         }
 
         /// <summary>
@@ -543,59 +780,14 @@
             this.ShowProjectSiteInfoEvent?.Invoke(_project, _projectSite, hydroInfo, this.svgImg32[0]);
         }
 
+        /// <summary>
+        /// 鍒锋柊
+        /// </summary>
+        public async Task<Yw.Model.HydroModelInfo> RefreshModel(XhsSchemeVmo scheme)
+        {
+            return await GetHydroInfo(scheme, false);
+        }
+
         #endregion
-
-        //椤圭洰绔欐鍐�
-        private async void elementProjectSiteInfo_Click(object sender, EventArgs e)
-        {
-            await ShowInfo();
-        }
-
-        //椤圭洰绔欐按鍔涙ā鎷�
-        private async void elementProjectSiteSimulation_Click(object sender, EventArgs e)
-        {
-            if (_project == null)
-            {
-                return;
-            }
-            if (_projectSite == null)
-            {
-                return;
-            }
-            var hydroInfo = await GetHydroInfo(null, true);
-            if (hydroInfo == null)
-            {
-                return;
-            }
-            this.ShowProjectSiteSimulationEvent?.Invoke(_project, _projectSite, null, hydroInfo, _allWorkingCheckedListDict, this.svgImg32[1]);
-        }
-
-        //鍒涘缓椤圭洰绔欐柟妗�
-        private async void accordionControl1_ContextButtonClick(object sender, DevExpress.Utils.ContextItemClickEventArgs e)
-        {
-            if (_project == null)
-            {
-                return;
-            }
-            if (_projectSite == null)
-            {
-                return;
-            }
-            var element = e.DataItem as DevExpress.XtraBars.Navigation.AccordionControlElement;
-            if (element != this.elementProjectSiteSchemeList)
-            {
-                return;
-            }
-            var hydroInfo = await GetHydroInfo(null, true);
-            if (hydroInfo == null)
-            {
-                return;
-            }
-            this.CreateProjectSiteSchemeEvent?.Invoke(_project, _projectSite, hydroInfo, this.svgImg32[3]);
-        }
-
-
-
-
     }
 }

--
Gitblit v1.9.3