From 6936ebf1dfbd0025d3e86ae7dde316b6a6e43b9b Mon Sep 17 00:00:00 2001
From: duheng <2784771470@qq.com>
Date: 星期二, 24 十二月 2024 16:40:23 +0800
Subject: [PATCH] Merge branch 'master' of http://47.103.154.90:83/r/HStation/XHS.V1.0

---
 WinFrmUI/HStation.WinFrmUI.Xhs.Core/03-simulation/05-function/SimulationFunctionCtrl.cs |  348 +++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 299 insertions(+), 49 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 58dba41..dc49fe8 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,5 +1,9 @@
-锘縰sing DevExpress.Utils.Extensions;
+锘縰sing DevExpress.CodeParser;
+using DevExpress.DataAccess.Native;
+using DevExpress.Utils.Extensions;
 using DevExpress.Utils.Svg;
+using DevExpress.XtraCharts;
+using System.Collections.Concurrent;
 using Yw.DAL.Basic;
 using Yw.Vmo;
 
@@ -30,6 +34,10 @@
         /// </summary>
         public event Action<XhsProjectVmo, XhsProjectSiteVmo, XhsSchemeVmo, HydroWorkingVmo, bool> ProjectSiteWorkingCheckedEvent;
         /// <summary>
+        /// 椤圭洰绔欏伐鍐靛鍔犱簨浠�
+        /// </summary>
+        public event Action<XhsProjectVmo, XhsProjectSiteVmo, XhsSchemeVmo, HydroWorkingVmo> ProjectSiteWorkingAppendEvent;
+        /// <summary>
         /// 椤圭洰绔欏伐鍐垫洿鏂颁簨浠�
         /// </summary>
         public event Action<XhsProjectVmo, XhsProjectSiteVmo, XhsSchemeVmo, HydroWorkingVmo> ProjectSiteWorkingUpdateEvent;
@@ -41,6 +49,18 @@
         /// 鍒涘缓椤圭洰绔欐柟妗堜簨浠�
         /// </summary>
         public event Action<XhsProjectVmo, XhsProjectSiteVmo, Yw.Model.HydroModelInfo, 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 +68,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>
         /// 缁戝畾鏁版嵁
@@ -87,7 +108,78 @@
                     });
                 }
             });
+            await ShowInfo();
             overlay.Close();
+        }
+
+        //椤圭洰绔欐鍐�
+        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]);
+        }
+
+        //鍙抽敭寮瑰嚭
+        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 閫氱敤鏂规硶
@@ -101,7 +193,10 @@
             Yw.Model.HydroModelInfo hydroInfo = null;
             if (!useCache)
             {
-                hydroInfo = await GetHydroInfo(scheme);
+                if (hydroInfo == null)
+                {
+                    hydroInfo = await GetHydroInfo(scheme);
+                }
                 if (hydroInfo == null)
                 {
                     return default;
@@ -114,7 +209,15 @@
                 {
                     if (_hydroInfo == null)
                     {
-                        _hydroInfo = await GetHydroInfo(null);
+                        hydroInfo = await GetHydroInfo(null);
+                        if (hydroInfo == null)
+                        {
+                            return default;
+                        }
+                        if (_hydroInfo == null)
+                        {
+                            _hydroInfo = hydroInfo;
+                        }
                     }
                     return _hydroInfo;
                 }
@@ -132,9 +235,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))
@@ -146,7 +256,7 @@
                 _allSchemeHydroInfoDict.Add(scheme, hydroInfo);
             }
 
-            return hydroInfo;
+            return _allSchemeHydroInfoDict[scheme];
         }
 
         //鑾峰彇姘村姏淇℃伅
@@ -159,6 +269,20 @@
             if (_projectSite == null)
             {
                 return default;
+            }
+            string key = $"{_project.ID}-{_projectSite.ID}-{scheme?.ID}";
+            if (_gettingHydroInfoDict.TryGetValue(key, out bool getting))
+            {
+                if (getting)
+                {
+                    return default;
+                }
+            }
+
+            var overlay = this.ShowOverlay();
+            if (!_gettingHydroInfoDict.TryAdd(key, true))
+            {
+                _gettingHydroInfoDict[key] = true;
             }
 
             HydroModelRelationVmo relation = null;
@@ -176,12 +300,17 @@
             {
                 return default;
             }
-            var hydroInfo = await BLLFactory<Yw.BLL.HydroModelInfo>.Instance.GetByID(relation.ModelID);
+            //var hydroInfo = await BLLFactory<Yw.BLL.HydroModelInfo>.Instance.GetByID(relation.ModelID);
+            var hydroInfo = await HStation.BLL.XhsHydroInfo.GetByID(relation.ModelID);
+            _gettingHydroInfoDict[key] = false;
+            overlay.Close();
+
             return hydroInfo;
         }
 
         /// <summary>
         /// 娣诲姞鏂规
+        /// 瑙﹀彂椤圭洰绔欐柟妗堝鍔犱簨浠�
         /// </summary>
         public void AppendScheme(XhsSchemeVmo scheme)
         {
@@ -235,11 +364,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)
         {
@@ -282,6 +527,10 @@
                 elementWorking.Click += async (sender, e) =>
                 {
                     var hydroInfo = await GetHydroInfo(null, true);
+                    if (hydroInfo == null)
+                    {
+                        return;
+                    }
                     this.ShowProjectSiteWorkingEvent?.Invoke(_project, _projectSite, null, hydroInfo, working, this.svgImg32[4]);
                 };
                 this.elementProjectSiteSimulation.Elements.Add(elementWorking);
@@ -332,6 +581,10 @@
                 elementWorking.Click += async (sender, e) =>
                 {
                     var hydroInfo = await GetHydroInfo(scheme, true);
+                    if (hydroInfo == null)
+                    {
+                        return;
+                    }
                     this.ShowProjectSiteWorkingEvent?.Invoke(_project, _projectSite, scheme, hydroInfo, working, this.svgImg32[4]);
                 };
                 elementScheme.Elements.Add(elementWorking);
@@ -352,6 +605,8 @@
                     }
                 }
             }
+
+            this.ProjectSiteWorkingAppendEvent?.Invoke(_project, _projectSite, scheme, working);
         }
 
         /// <summary>
@@ -523,10 +778,8 @@
             this.ProjectSiteWorkingRemoveEvent?.Invoke(_project, _projectSite, scheme, working);
         }
 
-        #endregion
-
-        //椤圭洰绔欐鍐�
-        private async void elementProjectSiteInfo_Click(object sender, EventArgs e)
+        //鏄剧ず淇℃伅
+        private async Task ShowInfo()
         {
             if (_project == null)
             {
@@ -544,51 +797,48 @@
             this.ShowProjectSiteInfoEvent?.Invoke(_project, _projectSite, hydroInfo, this.svgImg32[0]);
         }
 
-        //椤圭洰绔欐按鍔涙ā鎷�
-        private async void elementProjectSiteSimulation_Click(object sender, EventArgs e)
+        /// <summary>
+        /// 淇濆瓨
+        /// </summary>
+        public async Task<Yw.Model.HydroModelInfo> SaveModel(XhsSchemeVmo scheme, Yw.Model.HydroModelInfo hydroInfo)
         {
-            if (_project == null)
-            {
-                return;
-            }
-            if (_projectSite == null)
-            {
-                return;
-            }
-            var hydroInfo = await GetHydroInfo(null, true);
             if (hydroInfo == null)
             {
-                return;
+                return default;
             }
-            this.ShowProjectSiteSimulationEvent?.Invoke(_project, _projectSite, null, hydroInfo, _allWorkingCheckedListDict, this.svgImg32[1]);
+            //var id = await BLLFactory<Yw.BLL.HydroModelInfo>.Instance.Save(hydroInfo);
+            var id = await HStation.BLL.XhsHydroInfo.Save(hydroInfo);
+            if (id < 1)
+            {
+                return default;
+            }
+            var db = await BLLFactory<Yw.BLL.HydroModelInfo>.Instance.GetByID(id);
+            if (scheme == null)
+            {
+                _hydroInfo = db;
+                return _hydroInfo;
+            }
+            if (_allSchemeHydroInfoDict == null || _allSchemeHydroInfoDict.Count < 1)
+            {
+                return default;
+            }
+            var schemeKey = _allSchemeHydroInfoDict.Keys.FirstOrDefault(x => x.ID == scheme.ID);
+            if (schemeKey == null)
+            {
+                return default;
+            }
+            _allSchemeHydroInfoDict[schemeKey] = db;
+            return db;
         }
 
-        //鍒涘缓椤圭洰绔欐柟妗�
-        private async void accordionControl1_ContextButtonClick(object sender, DevExpress.Utils.ContextItemClickEventArgs e)
+        /// <summary>
+        /// 鍒锋柊
+        /// </summary>
+        public async Task<Yw.Model.HydroModelInfo> RefreshModel(XhsSchemeVmo scheme)
         {
-            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]);
+            return await GetHydroInfo(scheme, false);
         }
 
-
-
-
+        #endregion
     }
 }

--
Gitblit v1.9.3