From 5fc416a15c8e61a82fbcb7a11de5cfc9297985c5 Mon Sep 17 00:00:00 2001
From: lixiaojun <1287241240@qq.com>
Date: 星期四, 07 十一月 2024 09:44:25 +0800
Subject: [PATCH] 颜色分级优化

---
 WinFrmUI/HStation.WinFrmUI.Xhs.Core/03-simulation/06-simulation/XhsProjectSimulationCorePage.cs |  464 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 437 insertions(+), 27 deletions(-)

diff --git a/WinFrmUI/HStation.WinFrmUI.Xhs.Core/03-simulation/06-simulation/XhsProjectSimulationCorePage.cs b/WinFrmUI/HStation.WinFrmUI.Xhs.Core/03-simulation/06-simulation/XhsProjectSimulationCorePage.cs
index 9e7d1ae..06abb3b 100644
--- a/WinFrmUI/HStation.WinFrmUI.Xhs.Core/03-simulation/06-simulation/XhsProjectSimulationCorePage.cs
+++ b/WinFrmUI/HStation.WinFrmUI.Xhs.Core/03-simulation/06-simulation/XhsProjectSimulationCorePage.cs
@@ -232,6 +232,7 @@
                         return;
                     }
                     UpdateParterListProperty(parter);
+                    AutoApplyGrading();
                 };
                 _propertyCtrl.ViewParterEvent += (parter) =>
                 {
@@ -660,6 +661,7 @@
                 _parterListCtrl.HydroChangedEvent += (parterList) =>
                 {
                     UpdateSelectedParterProperty();
+                    AutoApplyGrading();
                 };
             }
             return _parterListCtrl;
@@ -2147,9 +2149,9 @@
             {
                 _allGradingList = list;
             };
-            dlg.ApplyDataEvent += () =>
+            dlg.ApplyDataEvent += (catalog, propName) =>
             {
-                ShowApplyGradingDlg();
+                ApplyGrading(catalog, propName);
             };
             dlg.ShowDialog();
         }
@@ -2205,9 +2207,6 @@
             return _allGradingApplyList;
         }
 
-        //棰滆壊鍒嗙骇搴旂敤缁撴灉鍒楄〃
-        private List<HydroGradingApplyResultViewModel> _allGradingApplyResultList = null;
-
         //鑾峰彇棰滆壊鍒嗙骇搴旂敤缁撴灉鍒楄〃
         private async Task<List<HydroGradingApplyResultViewModel>> GetGradingApplyResultList()
         {
@@ -2230,9 +2229,11 @@
                 return default;
             }
 
+            //鎵�鏈夎绠楃粨鏋滃垪琛�
             var allCalcuResultList = GetCalcuResultList();
 
-            _allGradingApplyResultList = new List<HydroGradingApplyResultViewModel>();
+            //鎵�鏈夊簲鐢ㄧ粨鏋滃垪琛�
+            var allGradingApplyResultList = new List<HydroGradingApplyResultViewModel>();
             allGradingApplyList.ForEach(x =>
             {
                 var allCatalogGradingList = allGradingList.Where(t => t.Catalog == x.Code).ToList();
@@ -2261,7 +2262,7 @@
                                                                 Code = pump.Code,
                                                                 Color = grading.Color
                                                             };
-                                                            _allGradingApplyResultList.Add(result);
+                                                            allGradingApplyResultList.Add(result);
                                                         }
                                                     }
                                                 }
@@ -2284,7 +2285,7 @@
                                                                         Code = pump.Code,
                                                                         Color = grading.Color
                                                                     };
-                                                                    _allGradingApplyResultList.Add(result);
+                                                                    allGradingApplyResultList.Add(result);
                                                                 }
                                                             }
                                                         }
@@ -2309,7 +2310,7 @@
                                                                         Code = pump.Code,
                                                                         Color = grading.Color
                                                                     };
-                                                                    _allGradingApplyResultList.Add(result);
+                                                                    allGradingApplyResultList.Add(result);
                                                                 }
                                                             }
                                                         }
@@ -2334,7 +2335,7 @@
                                                                         Code = pump.Code,
                                                                         Color = grading.Color
                                                                     };
-                                                                    _allGradingApplyResultList.Add(result);
+                                                                    allGradingApplyResultList.Add(result);
                                                                 }
                                                             }
                                                         }
@@ -2368,7 +2369,7 @@
                                                                 Code = valve.Code,
                                                                 Color = grading.Color
                                                             };
-                                                            _allGradingApplyResultList.Add(result);
+                                                            allGradingApplyResultList.Add(result);
                                                         }
                                                     }
                                                 }
@@ -2391,7 +2392,7 @@
                                                                         Code = valve.Code,
                                                                         Color = grading.Color
                                                                     };
-                                                                    _allGradingApplyResultList.Add(result);
+                                                                    allGradingApplyResultList.Add(result);
                                                                 }
                                                             }
                                                         }
@@ -2416,7 +2417,7 @@
                                                                         Code = valve.Code,
                                                                         Color = grading.Color
                                                                     };
-                                                                    _allGradingApplyResultList.Add(result);
+                                                                    allGradingApplyResultList.Add(result);
                                                                 }
                                                             }
                                                         }
@@ -2441,7 +2442,7 @@
                                                                         Code = valve.Code,
                                                                         Color = grading.Color
                                                                     };
-                                                                    _allGradingApplyResultList.Add(result);
+                                                                    allGradingApplyResultList.Add(result);
                                                                 }
                                                             }
                                                         }
@@ -2480,7 +2481,7 @@
                                                                         Code = pipe.Code,
                                                                         Color = grading.Color
                                                                     };
-                                                                    _allGradingApplyResultList.Add(result);
+                                                                    allGradingApplyResultList.Add(result);
                                                                 }
                                                             }
                                                         }
@@ -2505,7 +2506,7 @@
                                                                         Code = pipe.Code,
                                                                         Color = grading.Color
                                                                     };
-                                                                    _allGradingApplyResultList.Add(result);
+                                                                    allGradingApplyResultList.Add(result);
                                                                 }
                                                             }
                                                         }
@@ -2530,7 +2531,7 @@
                                                                         Code = pipe.Code,
                                                                         Color = grading.Color
                                                                     };
-                                                                    _allGradingApplyResultList.Add(result);
+                                                                    allGradingApplyResultList.Add(result);
                                                                 }
                                                             }
                                                         }
@@ -2548,11 +2549,365 @@
                 }
             });
 
-            return _allGradingApplyResultList;
+            return allGradingApplyResultList;
         }
 
-        //棰滆壊鍒嗙骇缂栫爜鍒楄〃
-        private List<string> _allGradingCodeList = null;
+        //鑾峰彇棰滆壊鍒嗙骇搴旂敤缁撴灉鍒楄〃
+        private async Task<List<HydroGradingApplyResultViewModel>> GetGradingApplyResultList(string catalog, string propName)
+        {
+            if (_hydroInfo == null)
+            {
+                return default;
+            }
+
+            //鎵�鏈夊垎绾у垪琛�
+            var allGradingList = await GetGradingList();
+            if (allGradingList == null || allGradingList.Count < 1)
+            {
+                return default;
+            }
+            var currentGradingList = allGradingList.Where(x => x.Catalog == catalog).ToList();
+            if (currentGradingList.Count < 1)
+            {
+                return default;
+            }
+
+            //鎵�鏈夊垎绾у簲鐢ㄥ垪琛�
+            var allGradingApplyList = GetGradingApplyList();
+            if (allGradingApplyList == null || allGradingApplyList.Count < 1)
+            {
+                return default;
+            }
+
+            //褰撳墠鍒嗙骇搴旂敤
+            var gradingApply = allGradingApplyList.Find(x => x.Code == catalog);
+            if (gradingApply == null)
+            {
+                return default;
+            }
+            gradingApply.PropName = propName;
+
+            //鎵�鏈夎绠楃粨鏋�
+            var allCalcuResultList = GetCalcuResultList();
+
+            //搴旂敤缁撴灉鍒楄〃
+            var gradingApplyResultList = new List<HydroGradingApplyResultViewModel>();
+
+            switch (catalog)
+            {
+                case Yw.Hydro.ParterCatalog.Pump:
+                    {
+                        if (_hydroInfo.Pumps != null && _hydroInfo.Pumps.Count > 0)
+                        {
+                            foreach (var pump in _hydroInfo.Pumps)
+                            {
+                                switch (propName)
+                                {
+                                    case Yw.Hydro.ParterProp.LinkStatus:
+                                        {
+                                            var gradingList = currentGradingList.Where(x => x.PropName == Yw.Hydro.ParterProp.LinkStatus).OrderBy(t => t.SortCode).ToList();
+                                            if (gradingList != null && gradingList.Count > 0)
+                                            {
+                                                var grading = gradingList.Meet(pump.LinkStatus);
+                                                if (grading != null)
+                                                {
+                                                    var result = new HydroGradingApplyResultViewModel()
+                                                    {
+                                                        Code = pump.Code,
+                                                        Color = grading.Color
+                                                    };
+                                                    gradingApplyResultList.Add(result);
+                                                }
+                                            }
+                                        }
+                                        break;
+                                    case Yw.Hydro.ParterProp.CalcuFlow:
+                                        {
+                                            var gradingList = currentGradingList.Where(x => x.PropName == Yw.Hydro.ParterProp.CalcuFlow).OrderBy(t => t.SortCode).ToList();
+                                            if (gradingList != null && gradingList.Count > 0)
+                                            {
+                                                var calcuResult = allCalcuResultList?.Find(t => t.Code == pump.Code);
+                                                if (calcuResult is HydroCalcuLinkResult calcuLinkResult)
+                                                {
+                                                    if (calcuLinkResult.CalcuFlow.HasValue)
+                                                    {
+                                                        var grading = gradingList.Meet(Math.Abs(calcuLinkResult.CalcuFlow.Value));
+                                                        if (grading != null)
+                                                        {
+                                                            var result = new HydroGradingApplyResultViewModel()
+                                                            {
+                                                                Code = pump.Code,
+                                                                Color = grading.Color
+                                                            };
+                                                            gradingApplyResultList.Add(result);
+                                                        }
+                                                    }
+                                                }
+                                            }
+                                        }
+                                        break;
+                                    case Yw.Hydro.ParterProp.CalcuVelocity:
+                                        {
+                                            var gradingList = currentGradingList.Where(x => x.PropName == Yw.Hydro.ParterProp.CalcuVelocity).OrderBy(t => t.SortCode).ToList();
+                                            if (gradingList != null && gradingList.Count > 0)
+                                            {
+                                                var calcuResult = allCalcuResultList?.Find(t => t.Code == pump.Code);
+                                                if (calcuResult is HydroCalcuLinkResult calcuLinkResult)
+                                                {
+                                                    if (calcuLinkResult.CalcuVelocity.HasValue)
+                                                    {
+                                                        var grading = gradingList.Meet(Math.Abs(calcuLinkResult.CalcuVelocity.Value));
+                                                        if (grading != null)
+                                                        {
+                                                            var result = new HydroGradingApplyResultViewModel()
+                                                            {
+                                                                Code = pump.Code,
+                                                                Color = grading.Color
+                                                            };
+                                                            gradingApplyResultList.Add(result);
+                                                        }
+                                                    }
+                                                }
+                                            }
+                                        }
+                                        break;
+                                    case Yw.Hydro.ParterProp.CalcuHeadLoss:
+                                        {
+                                            var gradingList = currentGradingList.Where(x => x.PropName == Yw.Hydro.ParterProp.CalcuHeadLoss).OrderBy(t => t.SortCode).ToList();
+                                            if (gradingList != null && gradingList.Count > 0)
+                                            {
+                                                var calcuResult = allCalcuResultList?.Find(t => t.Code == pump.Code);
+                                                if (calcuResult is HydroCalcuLinkResult calcuLinkResult)
+                                                {
+                                                    if (calcuLinkResult.CalcuHeadLoss.HasValue)
+                                                    {
+                                                        var grading = gradingList.Meet(Math.Abs(calcuLinkResult.CalcuHeadLoss.Value));
+                                                        if (grading != null)
+                                                        {
+                                                            var result = new HydroGradingApplyResultViewModel()
+                                                            {
+                                                                Code = pump.Code,
+                                                                Color = grading.Color
+                                                            };
+                                                            gradingApplyResultList.Add(result);
+                                                        }
+                                                    }
+                                                }
+                                            }
+                                        }
+                                        break;
+                                    default: break;
+                                }
+                            }
+                        }
+                    }
+                    break;
+                case Yw.Hydro.ParterCatalog.Valve:
+                    {
+                        if (_hydroInfo.Valves != null && _hydroInfo.Valves.Count > 0)
+                        {
+                            foreach (var valve in _hydroInfo.Valves)
+                            {
+                                switch (propName)
+                                {
+                                    case Yw.Hydro.ParterProp.LinkStatus:
+                                        {
+                                            var gradingList = currentGradingList.Where(x => x.PropName == Yw.Hydro.ParterProp.LinkStatus).OrderBy(t => t.SortCode).ToList();
+                                            if (gradingList != null && gradingList.Count > 0)
+                                            {
+                                                var grading = gradingList.Meet(valve.LinkStatus);
+                                                if (grading != null)
+                                                {
+                                                    var result = new HydroGradingApplyResultViewModel()
+                                                    {
+                                                        Code = valve.Code,
+                                                        Color = grading.Color
+                                                    };
+                                                    gradingApplyResultList.Add(result);
+                                                }
+                                            }
+                                        }
+                                        break;
+                                    case Yw.Hydro.ParterProp.CalcuFlow:
+                                        {
+                                            var gradingList = currentGradingList.Where(x => x.PropName == Yw.Hydro.ParterProp.CalcuFlow).OrderBy(t => t.SortCode).ToList();
+                                            if (gradingList != null && gradingList.Count > 0)
+                                            {
+                                                var calcuResult = allCalcuResultList?.Find(t => t.Code == valve.Code);
+                                                if (calcuResult is HydroCalcuLinkResult calcuLinkResult)
+                                                {
+                                                    if (calcuLinkResult.CalcuFlow.HasValue)
+                                                    {
+                                                        var grading = gradingList.Meet(Math.Abs(calcuLinkResult.CalcuFlow.Value));
+                                                        if (grading != null)
+                                                        {
+                                                            var result = new HydroGradingApplyResultViewModel()
+                                                            {
+                                                                Code = valve.Code,
+                                                                Color = grading.Color
+                                                            };
+                                                            gradingApplyResultList.Add(result);
+                                                        }
+                                                    }
+                                                }
+                                            }
+                                        }
+                                        break;
+                                    case Yw.Hydro.ParterProp.CalcuVelocity:
+                                        {
+                                            var gradingList = currentGradingList.Where(x => x.PropName == Yw.Hydro.ParterProp.CalcuVelocity).OrderBy(t => t.SortCode).ToList();
+                                            if (gradingList != null && gradingList.Count > 0)
+                                            {
+                                                var calcuResult = allCalcuResultList?.Find(t => t.Code == valve.Code);
+                                                if (calcuResult is HydroCalcuLinkResult calcuLinkResult)
+                                                {
+                                                    if (calcuLinkResult.CalcuVelocity.HasValue)
+                                                    {
+                                                        var grading = gradingList.Meet(Math.Abs(calcuLinkResult.CalcuVelocity.Value));
+                                                        if (grading != null)
+                                                        {
+                                                            var result = new HydroGradingApplyResultViewModel()
+                                                            {
+                                                                Code = valve.Code,
+                                                                Color = grading.Color
+                                                            };
+                                                            gradingApplyResultList.Add(result);
+                                                        }
+                                                    }
+                                                }
+                                            }
+                                        }
+                                        break;
+                                    case Yw.Hydro.ParterProp.CalcuHeadLoss:
+                                        {
+                                            var gradingList = currentGradingList.Where(x => x.PropName == Yw.Hydro.ParterProp.CalcuHeadLoss).OrderBy(t => t.SortCode).ToList();
+                                            if (gradingList != null && gradingList.Count > 0)
+                                            {
+                                                var calcuResult = allCalcuResultList?.Find(t => t.Code == valve.Code);
+                                                if (calcuResult is HydroCalcuLinkResult calcuLinkResult)
+                                                {
+                                                    if (calcuLinkResult.CalcuHeadLoss.HasValue)
+                                                    {
+                                                        var grading = gradingList.Meet(Math.Abs(calcuLinkResult.CalcuHeadLoss.Value));
+                                                        if (grading != null)
+                                                        {
+                                                            var result = new HydroGradingApplyResultViewModel()
+                                                            {
+                                                                Code = valve.Code,
+                                                                Color = grading.Color
+                                                            };
+                                                            gradingApplyResultList.Add(result);
+                                                        }
+                                                    }
+                                                }
+                                            }
+                                        }
+                                        break;
+                                    default: break;
+                                }
+                            }
+                        }
+                    }
+                    break;
+                case Yw.Hydro.ParterCatalog.Pipe:
+                    {
+                        if (_hydroInfo.Pipes != null && _hydroInfo.Pipes.Count > 0)
+                        {
+                            foreach (var pipe in _hydroInfo.Pipes)
+                            {
+                                switch (propName)
+                                {
+                                    case Yw.Hydro.ParterProp.CalcuFlow:
+                                        {
+                                            var gradingList = currentGradingList.Where(x => x.PropName == Yw.Hydro.ParterProp.CalcuFlow).OrderBy(t => t.SortCode).ToList();
+                                            if (gradingList != null && gradingList.Count > 0)
+                                            {
+                                                var calcuResult = allCalcuResultList?.Find(t => t.Code == pipe.Code);
+                                                if (calcuResult is HydroCalcuLinkResult calcuLinkResult)
+                                                {
+                                                    if (calcuLinkResult.CalcuFlow.HasValue)
+                                                    {
+                                                        var grading = gradingList.Meet(Math.Abs(calcuLinkResult.CalcuFlow.Value));
+                                                        if (grading != null)
+                                                        {
+                                                            var result = new HydroGradingApplyResultViewModel()
+                                                            {
+                                                                Code = pipe.Code,
+                                                                Color = grading.Color
+                                                            };
+                                                            gradingApplyResultList.Add(result);
+                                                        }
+                                                    }
+                                                }
+                                            }
+                                        }
+                                        break;
+                                    case Yw.Hydro.ParterProp.CalcuVelocity:
+                                        {
+                                            var gradingList = currentGradingList.Where(x => x.PropName == Yw.Hydro.ParterProp.CalcuVelocity).OrderBy(t => t.SortCode).ToList();
+                                            if (gradingList != null && gradingList.Count > 0)
+                                            {
+                                                var calcuResult = allCalcuResultList?.Find(t => t.Code == pipe.Code);
+                                                if (calcuResult is HydroCalcuLinkResult calcuLinkResult)
+                                                {
+                                                    if (calcuLinkResult.CalcuVelocity.HasValue)
+                                                    {
+                                                        var grading = gradingList.Meet(Math.Abs(calcuLinkResult.CalcuVelocity.Value));
+                                                        if (grading != null)
+                                                        {
+                                                            var result = new HydroGradingApplyResultViewModel()
+                                                            {
+                                                                Code = pipe.Code,
+                                                                Color = grading.Color
+                                                            };
+                                                            gradingApplyResultList.Add(result);
+                                                        }
+                                                    }
+                                                }
+                                            }
+                                        }
+                                        break;
+                                    case Yw.Hydro.ParterProp.CalcuHeadLoss:
+                                        {
+                                            var gradingList = currentGradingList.Where(x => x.PropName == Yw.Hydro.ParterProp.CalcuHeadLoss).OrderBy(t => t.SortCode).ToList();
+                                            if (gradingList != null && gradingList.Count > 0)
+                                            {
+                                                var calcuResult = allCalcuResultList?.Find(t => t.Code == pipe.Code);
+                                                if (calcuResult is HydroCalcuLinkResult calcuLinkResult)
+                                                {
+                                                    if (calcuLinkResult.CalcuHeadLoss.HasValue)
+                                                    {
+                                                        var grading = gradingList.Meet(Math.Abs(calcuLinkResult.CalcuHeadLoss.Value));
+                                                        if (grading != null)
+                                                        {
+                                                            var result = new HydroGradingApplyResultViewModel()
+                                                            {
+                                                                Code = pipe.Code,
+                                                                Color = grading.Color
+                                                            };
+                                                            gradingApplyResultList.Add(result);
+                                                        }
+                                                    }
+                                                }
+                                            }
+                                        }
+                                        break;
+                                    default: break;
+                                }
+                            }
+                        }
+                    }
+                    break;
+                default: break;
+            }
+
+            return gradingApplyResultList;
+        }
+
+        //棰滆壊鍒嗙骇鏄惁搴旂敤浜�
+        private bool _isGradingApply = false;
+        //棰滆壊鍒嗙骇搴旂敤缂栫爜鍒楄〃
+        private List<string> _allGradingApplyCodeList = null;
 
         //搴旂敤棰滆壊鍒嗙骇
         private async void ApplyGrading()
@@ -2561,13 +2916,70 @@
             {
                 return;
             }
+            _isGradingApply = true;
             var allGradingApplyResultList = await GetGradingApplyResultList();
-            _allGradingCodeList = allGradingApplyResultList?.Select(x => x.Code).Distinct().ToList();
-            var objGroupList = allGradingApplyResultList?.GroupBy(x => x.Color).ToList();
-            objGroupList?.ForEach(async x =>
+            if (allGradingApplyResultList == null || allGradingApplyResultList.Count < 1)
+            {
+                CancelApplyGrading();
+                return;
+            }
+            var objGroupList = allGradingApplyResultList.GroupBy(x => x.Color).ToList();
+            objGroupList.ForEach(async x =>
             {
                 await _bimfaceCtrl?.OverrideComponentsColor(x.Select(t => t.Code).Distinct().ToList(), x.Key, 1);
             });
+            _allGradingApplyCodeList = allGradingApplyResultList.Select(x => x.Code).Distinct().ToList();
+        }
+
+        //搴旂敤棰滆壊鍒嗙骇
+        private async void ApplyGrading(string catalog, string propName)
+        {
+            if (_hydroInfo == null)
+            {
+                return;
+            }
+            _isGradingApply = true;
+            var allGradingApplyResultList = await GetGradingApplyResultList(catalog, propName);
+            if (allGradingApplyResultList == null || allGradingApplyResultList.Count < 1)
+            {
+                return;
+            }
+            var objGroupList = allGradingApplyResultList.GroupBy(x => x.Color).ToList();
+            objGroupList.ForEach(async x =>
+            {
+                await _bimfaceCtrl?.OverrideComponentsColor(x.Select(t => t.Code).Distinct().ToList(), x.Key, 1);
+            });
+            var codeList = allGradingApplyResultList.Select(x => x.Code);
+            if (_allGradingApplyCodeList == null)
+            {
+                _allGradingApplyCodeList = new List<string>();
+            }
+            _allGradingApplyCodeList.AddRange(codeList);
+            _allGradingApplyCodeList = _allGradingApplyCodeList.Distinct().ToList();
+        }
+
+        //鑷姩搴旂敤棰滆壊鍒嗙骇
+        private void AutoApplyGrading()
+        {
+            if (!_isGradingApply)
+            {
+                return;
+            }
+            ApplyGrading();
+        }
+
+        //鍙栨秷搴旂敤棰滆壊鍒嗙骇
+        private async void CancelApplyGrading()
+        {
+            if (_hydroInfo == null)
+            {
+                return;
+            }
+            _isGradingApply = false;
+            if (_allGradingApplyCodeList != null && _allGradingApplyCodeList.Count > 0)
+            {
+                await _bimfaceCtrl?.RestoreComponentsColor(_allGradingApplyCodeList);
+            }
         }
 
         //鏄剧ず搴旂敤棰滆壊鍒嗙骇绐椾綋
@@ -2584,7 +2996,7 @@
             }
             var dlg = new ApplyHydroGradingDlg();
             dlg.SetBindingData(allGradingApplyList);
-            dlg.ReloadDataEvent += async (obj) =>
+            dlg.ReloadDataEvent += (obj) =>
             {
                 _allGradingApplyList = obj;
                 ApplyGrading();
@@ -2601,12 +3013,10 @@
         //鍙栨秷搴旂敤鍒嗙骇
         private void batBtnCancelGradingApply_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
         {
-
+            CancelApplyGrading();
         }
 
         #endregion
-
-
 
         #endregion
 

--
Gitblit v1.9.3