From 3a8ca9cfb9312444b7cbe9c1988829432c4ba80d Mon Sep 17 00:00:00 2001
From: Shuxia Ning <NingShuxia0927@outlook.com>
Date: 星期三, 11 十二月 2024 17:13:46 +0800
Subject: [PATCH]  ExportToImage

---
 WinFrmUI/HStation.WinFrmUI.Xhs.Core/03-simulation/06-simulation/XhsProjectSimulationCorePage.cs |  413 ++++++++++++++++++++++++++++++++++++----------------------
 1 files changed, 258 insertions(+), 155 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 56ad3e6..cadbba4 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
@@ -4,6 +4,7 @@
 using DevExpress.XtraMap;
 using HStation.WinFrmUI.PhartRelation;
 using Mapster;
+using NPOI.OpenXmlFormats.Dml;
 using NPOI.SS.Formula.Functions;
 using System.Diagnostics;
 using Yw.EPAnet;
@@ -29,6 +30,24 @@
         /// 鏂板宸ュ喌浜嬩欢
         /// </summary>
         public event Action<HydroWorkingVmo> AppendWorkingEvent;
+        /// <summary>
+        /// 淇濆瓨妯″瀷浜嬩欢
+        /// </summary>
+        public event Func<Yw.Model.HydroModelInfo, Task<Yw.Model.HydroModelInfo>> SaveModelEvent;
+        /// <summary>
+        /// 鍒锋柊妯″瀷浜嬩欢
+        /// </summary>
+        public event Func<Task<Yw.Model.HydroModelInfo>> RefreshModelEvent;
+        /// <summary>
+        /// 鏇存柊鏂规浜嬩欢
+        /// </summary>
+        public event Action<XhsSchemeVmo> UpdateSchemeEvent;
+        /// <summary>
+        /// 绉婚櫎鏂规浜嬩欢
+        /// </summary>
+        public event Action<XhsSchemeVmo> RemoveSchemeEvent;
+
+
 
         private HStation.Vmo.XhsProjectVmo _project = null;//椤圭洰
         private HStation.Vmo.XhsProjectSiteVmo _projectSite = null;//椤圭洰绔�
@@ -54,6 +73,16 @@
             _hydroInfo = hydroInfo;
             _allWorkingCheckedListDict = allWorkingCheckedListDict;
             ResetMonitorValue();
+            if (_scheme == null)
+            {
+                this.ribPageGroupForScheme.Visible = false;
+                this.PageTitle.Caption = $"姘村姏妯℃嫙";
+            }
+            else
+            {
+                this.ribPageGroupForScheme.Visible = true;
+                this.PageTitle.Caption = $"妯℃嫙鏂规\r\n{_scheme.Name}";
+            }
         }
 
         /// <summary>
@@ -95,7 +124,7 @@
                 {//榧犳爣宸﹂敭鐐瑰嚮浜嬩欢
                     var visualListHelper = GetVisualListHelper();
                     var visual = visualListHelper.GetVisual(code);
-                    SelectVisual(visual, eVisualSource.Bimface);
+                    SelectVisual(visual, eSimulationVisualSource.Bimface);
                 };
             }
             return _bimfaceCtrl;
@@ -132,7 +161,7 @@
                 {
                     var visualListHelper = GetVisualListHelper();
                     var visuals = visualListHelper.GetVisualList(codes);
-                    SelectVisual(visuals?.LastOrDefault(), eVisualSource.Q3d);
+                    SelectVisual(visuals?.LastOrDefault(), eSimulationVisualSource.Q3d);
                 };
             }
             return _q3dCtrl;
@@ -167,7 +196,7 @@
                 _propertyCtrl.AllowEdit = true;
                 _propertyCtrl.HydroViewEvent += (visual) =>
                 {
-                    SelectVisual(visual, eVisualSource.Property);
+                    SelectVisual(visual, eSimulationVisualSource.Property);
                 };
                 _propertyCtrl.BlinkLinkNodeEvent += async (link, linkNodeCode) =>
                 { //寮鸿皟杩炴帴鑺傜偣
@@ -296,100 +325,84 @@
 
         #region 閫夋嫨鏋勪欢
 
-        //鍙鏉ユ簮
-        protected enum eVisualSource
-        {
-            None,
-            Bimface,
-            Q3d,
-            Property,
-            List,
-            Set,
-            Search,
-            Monitor,
-            Check,
-            Calcu,
-            Warning,
-        }
-
         //閫夋嫨鏋勪欢
         private Yw.Model.HydroVisualInfo _visual = null;
 
         //閫夋嫨鏋勪欢
-        private void SelectVisual(HydroVisualInfo visual, eVisualSource source)
+        private void SelectVisual(HydroVisualInfo visual, eSimulationVisualSource source)
         {
             _visual = visual;
             switch (source)
             {
-                case eVisualSource.None:
+                case eSimulationVisualSource.None:
                     {
                         _bimfaceCtrl?.ZoomAndSelectComponent(visual?.Code);
                         this.barBtnSetMonitor.Enabled = visual != null;
                         SetPropertyCtrl(visual);
                     }
                     break;
-                case eVisualSource.Bimface:
+                case eSimulationVisualSource.Bimface:
                     {
                         this.barBtnSetMonitor.Enabled = visual != null;
                         SetPropertyCtrl(visual);
                     }
                     break;
-                case eVisualSource.Q3d:
+                case eSimulationVisualSource.Q3d:
                     {
                         _bimfaceCtrl?.ZoomAndSelectComponent(visual?.Code);
                         this.barBtnSetMonitor.Enabled = visual != null;
                         SetPropertyCtrl(visual);
                     }
                     break;
-                case eVisualSource.Property:
+                case eSimulationVisualSource.Property:
                     {
                         _bimfaceCtrl?.ZoomAndSelectComponent(visual?.Code);
                         this.barBtnSetMonitor.Enabled = visual != null;
                     }
                     break;
-                case eVisualSource.List:
+                case eSimulationVisualSource.List:
                     {
                         _bimfaceCtrl?.ZoomAndSelectComponent(visual?.Code);
                         this.barBtnSetMonitor.Enabled = visual != null;
                         SetPropertyCtrl(visual);
                     }
                     break;
-                case eVisualSource.Set:
+                case eSimulationVisualSource.Set:
                     {
                         _bimfaceCtrl?.ZoomAndSelectComponent(visual?.Code);
                         this.barBtnSetMonitor.Enabled = visual != null;
                         SetPropertyCtrl(visual);
                     }
                     break;
-                case eVisualSource.Search:
+                case eSimulationVisualSource.Search:
                     {
                         _bimfaceCtrl?.ZoomAndSelectComponent(visual?.Code);
                         this.barBtnSetMonitor.Enabled = visual != null;
                         SetPropertyCtrl(visual);
                     }
                     break;
-                case eVisualSource.Monitor:
+                case eSimulationVisualSource.Monitor:
                     {
                         _bimfaceCtrl?.ZoomAndSelectComponent(visual?.Code);
                         this.barBtnSetMonitor.Enabled = visual != null;
                         SetPropertyCtrl(visual);
                     }
                     break;
-                case eVisualSource.Check:
+                case eSimulationVisualSource.Check:
                     {
                         _bimfaceCtrl?.ZoomAndSelectComponent(visual?.Code);
                         this.barBtnSetMonitor.Enabled = visual != null;
                         SetPropertyCtrl(visual);
                     }
                     break;
-                case eVisualSource.Calcu:
+                case eSimulationVisualSource.Calcu:
                     {
                         _bimfaceCtrl?.ZoomAndSelectComponent(visual?.Code);
                         this.barBtnSetMonitor.Enabled = visual != null;
                         SetPropertyCtrl(visual);
                     }
                     break;
-                case eVisualSource.Warning:
+                case eSimulationVisualSource.Warning:
                     {
                         _bimfaceCtrl?.ZoomAndSelectComponent(visual?.Code);
                         this.barBtnSetMonitor.Enabled = visual != null;
@@ -401,7 +414,7 @@
         }
 
         //閫夋嫨鏋勪欢
-        private void SelectVisual(string code, eVisualSource source)
+        private void SelectVisual(string code, eSimulationVisualSource source)
         {
             var visual = GetVisual(code);
             SelectVisual(visual, source);
@@ -425,6 +438,13 @@
                 _visualListHelper.InitialData(_hydroInfo);
             }
             return _visualListHelper;
+        }
+
+        //閲嶇疆鍙鍒楄〃
+        private void ResetVisualList()
+        {
+            var helper = GetVisualListHelper();
+            helper.InitialData(_hydroInfo);
         }
 
         //鑾峰彇鍙鏋勪欢
@@ -495,11 +515,11 @@
                 _visualListCtrl.Dock = DockStyle.Fill;
                 _visualListCtrl.HydroClickInfoEvent += (visual) =>
                 {
-                    SelectVisual(visual, eVisualSource.List);
+                    SelectVisual(visual, eSimulationVisualSource.List);
                 };
                 _visualListCtrl.HydroChangedInfoEvent += (visualList) =>
                 {
-                    SelectVisual(_visual, eVisualSource.List);
+                    SelectVisual(_visual, eSimulationVisualSource.List);
                 };
             }
             return _visualListCtrl;
@@ -665,24 +685,27 @@
             {
                 return;
             }
-            Stopwatch sw = new Stopwatch();
-            sw.Start();
-
-
-            var id = await BLLFactory<Yw.BLL.HydroModelInfo>.Instance.Save(_hydroInfo);
-
-            //鑰楁椂宸ㄥぇ鐨勪唬鐮�  
-
-            sw.Stop();
-            TimeSpan ts2 = sw.Elapsed;
-            Console.WriteLine("Stopwatch鎬诲叡鑺辫垂{0}ms.", ts2.TotalMilliseconds);
-            if (id < 1)
+            if (this.SaveModelEvent == null)
+            {
+                return;
+            }
+            var hydroInfo = await this.SaveModelEvent.Invoke(_hydroInfo);
+            if (hydroInfo == null)
             {
                 TipFormHelper.ShowError("淇濆瓨澶辫触锛�");
                 return;
             }
-            _hydroInfo = await BLLFactory<Yw.BLL.HydroModelInfo>.Instance.GetByID(id);
+            _hydroInfo = hydroInfo;
+
             TipFormHelper.ShowSucceed("淇濆瓨鎴愬姛锛�");
+
+
+            //Stopwatch sw = new Stopwatch();
+            //sw.Start();
+            //鑰楁椂宸ㄥぇ鐨勪唬鐮�  
+            //sw.Stop();
+            //TimeSpan ts2 = sw.Elapsed;
+            //Console.WriteLine("Stopwatch鎬诲叡鑺辫垂{0}ms.", ts2.TotalMilliseconds);
         }
 
         #endregion
@@ -700,11 +723,11 @@
                 dlg.SetBindingData(allVisualViewModelList);
                 dlg.HydroClickInfoEvent += (visual) =>
                 {
-                    SelectVisual(visual, eVisualSource.Set);
+                    SelectVisual(visual, eSimulationVisualSource.Set);
                 };
                 dlg.HydroChangedInfoEvent += visuals =>
                 {
-                    SelectVisual(visuals?.FirstOrDefault(), eVisualSource.Set);
+                    SelectVisual(visuals?.FirstOrDefault(), eSimulationVisualSource.Set);
                     UpdateVisualListCtrl();
                 };
                 dlg.ShowDialog();
@@ -717,11 +740,11 @@
                 dlg.SetBindingData(allVisualViewModelList);
                 dlg.HydroClickInfoEvent += (visual) =>
                 {
-                    SelectVisual(visual, eVisualSource.Set);
+                    SelectVisual(visual, eSimulationVisualSource.Set);
                 };
                 dlg.HydroChangedInfoEvent += visuals =>
                 {
-                    SelectVisual(visuals?.FirstOrDefault(), eVisualSource.Set);
+                    SelectVisual(visuals?.FirstOrDefault(), eSimulationVisualSource.Set);
                     UpdateVisualListCtrl();
                 };
                 dlg.ShowDialog();
@@ -734,11 +757,11 @@
                 dlg.SetBindingData(allVisualViewModelList);
                 dlg.HydroClickInfoEvent += (visual) =>
                 {
-                    SelectVisual(visual, eVisualSource.Set);
+                    SelectVisual(visual, eSimulationVisualSource.Set);
                 };
                 dlg.HydroChangedInfoEvent += visuals =>
                 {
-                    SelectVisual(visuals?.FirstOrDefault(), eVisualSource.Set);
+                    SelectVisual(visuals?.FirstOrDefault(), eSimulationVisualSource.Set);
                     UpdateVisualListCtrl();
                 };
                 dlg.ShowDialog();
@@ -751,11 +774,11 @@
                 dlg.SetBindingData(allVisualViewModelList);
                 dlg.HydroClickInfoEvent += (visual) =>
                 {
-                    SelectVisual(visual, eVisualSource.Set);
+                    SelectVisual(visual, eSimulationVisualSource.Set);
                 };
                 dlg.HydroChangedInfoEvent += visuals =>
                 {
-                    SelectVisual(visuals?.FirstOrDefault(), eVisualSource.Set);
+                    SelectVisual(visuals?.FirstOrDefault(), eSimulationVisualSource.Set);
                     UpdateVisualListCtrl();
                 };
                 dlg.ShowDialog();
@@ -768,11 +791,11 @@
                 dlg.SetBindingData(allVisualViewModelList);
                 dlg.HydroClickInfoEvent += (visual) =>
                 {
-                    SelectVisual(visual, eVisualSource.Set);
+                    SelectVisual(visual, eSimulationVisualSource.Set);
                 };
                 dlg.HydroChangedInfoEvent += visuals =>
                 {
-                    SelectVisual(visuals?.FirstOrDefault(), eVisualSource.Set);
+                    SelectVisual(visuals?.FirstOrDefault(), eSimulationVisualSource.Set);
                     UpdateVisualListCtrl();
                 };
                 dlg.ShowDialog();
@@ -785,11 +808,11 @@
                 dlg.SetBindingData(allVisualVmList);
                 dlg.HydroClickInfoEvent += (visual) =>
                 {
-                    SelectVisual(visual, eVisualSource.Set);
+                    SelectVisual(visual, eSimulationVisualSource.Set);
                 };
                 dlg.HydroChangedInfoEvent += visuals =>
                 {
-                    SelectVisual(visuals?.FirstOrDefault(), eVisualSource.Set);
+                    SelectVisual(visuals?.FirstOrDefault(), eSimulationVisualSource.Set);
                     UpdateVisualListCtrl();
                 };
                 dlg.ShowDialog();
@@ -802,11 +825,11 @@
                 dlg.SetBindingData(allVisualViewModelList);
                 dlg.HydroClickInfoEvent += (visual) =>
                 {
-                    SelectVisual(visual, eVisualSource.Set);
+                    SelectVisual(visual, eSimulationVisualSource.Set);
                 };
                 dlg.HydroChangedInfoEvent += visuals =>
                 {
-                    SelectVisual(visuals?.FirstOrDefault(), eVisualSource.Set);
+                    SelectVisual(visuals?.FirstOrDefault(), eSimulationVisualSource.Set);
                     UpdateVisualListCtrl();
                 };
                 dlg.ShowDialog();
@@ -819,11 +842,11 @@
                 dlg.SetBindingData(allVisualViewModelList);
                 dlg.HydroClickInfoEvent += (visual) =>
                 {
-                    SelectVisual(visual, eVisualSource.Set);
+                    SelectVisual(visual, eSimulationVisualSource.Set);
                 };
                 dlg.HydroChangedInfoEvent += visuals =>
                 {
-                    SelectVisual(visuals?.FirstOrDefault(), eVisualSource.Set);
+                    SelectVisual(visuals?.FirstOrDefault(), eSimulationVisualSource.Set);
                     UpdateVisualListCtrl();
                 };
                 dlg.ShowDialog();
@@ -836,11 +859,11 @@
                 dlg.SetBindingData(allVisualViewModelList);
                 dlg.HydroClickInfoEvent += (visual) =>
                 {
-                    SelectVisual(visual, eVisualSource.Set);
+                    SelectVisual(visual, eSimulationVisualSource.Set);
                 };
                 dlg.HydroChangedInfoEvent += visuals =>
                 {
-                    SelectVisual(visuals?.FirstOrDefault(), eVisualSource.Set);
+                    SelectVisual(visuals?.FirstOrDefault(), eSimulationVisualSource.Set);
                     UpdateVisualListCtrl();
                 };
                 dlg.ShowDialog();
@@ -853,11 +876,11 @@
                 dlg.SetBindingData(allVisualViewModelList);
                 dlg.HydroClickInfoEvent += (visual) =>
                 {
-                    SelectVisual(visual, eVisualSource.Set);
+                    SelectVisual(visual, eSimulationVisualSource.Set);
                 };
                 dlg.HydroChangedInfoEvent += visuals =>
                 {
-                    SelectVisual(visuals?.FirstOrDefault(), eVisualSource.Set);
+                    SelectVisual(visuals?.FirstOrDefault(), eSimulationVisualSource.Set);
                     UpdateVisualListCtrl();
                 };
                 dlg.ShowDialog();
@@ -870,11 +893,11 @@
                 dlg.SetBindingData(allVisualViewModelList);
                 dlg.HydroClickInfoEvent += (visual) =>
                 {
-                    SelectVisual(visual, eVisualSource.Set);
+                    SelectVisual(visual, eSimulationVisualSource.Set);
                 };
                 dlg.HydroChangedInfoEvent += visuals =>
                 {
-                    SelectVisual(visuals?.FirstOrDefault(), eVisualSource.Set);
+                    SelectVisual(visuals?.FirstOrDefault(), eSimulationVisualSource.Set);
                     UpdateVisualListCtrl();
                 };
                 dlg.ShowDialog();
@@ -887,11 +910,11 @@
                 dlg.SetBindingData(allVisualViewModelList);
                 dlg.HydroClickInfoEvent += (visual) =>
                 {
-                    SelectVisual(visual, eVisualSource.Set);
+                    SelectVisual(visual, eSimulationVisualSource.Set);
                 };
                 dlg.HydroChangedInfoEvent += visuals =>
                 {
-                    SelectVisual(visuals?.FirstOrDefault(), eVisualSource.Set);
+                    SelectVisual(visuals?.FirstOrDefault(), eSimulationVisualSource.Set);
                     UpdateVisualListCtrl();
                 };
                 dlg.ShowDialog();
@@ -904,11 +927,11 @@
                 dlg.SetBindingData(allVisualViewModelList);
                 dlg.HydroClickInfoEvent += (visual) =>
                 {
-                    SelectVisual(visual, eVisualSource.Set);
+                    SelectVisual(visual, eSimulationVisualSource.Set);
                 };
                 dlg.HydroChangedInfoEvent += visuals =>
                 {
-                    SelectVisual(visuals?.FirstOrDefault(), eVisualSource.Set);
+                    SelectVisual(visuals?.FirstOrDefault(), eSimulationVisualSource.Set);
                     UpdateVisualListCtrl();
                 };
                 dlg.ShowDialog();
@@ -921,11 +944,11 @@
                 dlg.SetBindingData(allVisualViewModelList);
                 dlg.HydroClickInfoEvent += (visual) =>
                 {
-                    SelectVisual(visual, eVisualSource.Set);
+                    SelectVisual(visual, eSimulationVisualSource.Set);
                 };
                 dlg.HydroChangedInfoEvent += visuals =>
                 {
-                    SelectVisual(visuals?.FirstOrDefault(), eVisualSource.Set);
+                    SelectVisual(visuals?.FirstOrDefault(), eSimulationVisualSource.Set);
                     UpdateVisualListCtrl();
                 };
                 dlg.ShowDialog();
@@ -938,11 +961,11 @@
                 dlg.SetBindingData(allVisualViewModelList);
                 dlg.HydroClickInfoEvent += (visual) =>
                 {
-                    SelectVisual(visual, eVisualSource.Set);
+                    SelectVisual(visual, eSimulationVisualSource.Set);
                 };
                 dlg.HydroChangedInfoEvent += visuals =>
                 {
-                    SelectVisual(visuals?.FirstOrDefault(), eVisualSource.Set);
+                    SelectVisual(visuals?.FirstOrDefault(), eSimulationVisualSource.Set);
                     UpdateVisualListCtrl();
                 };
                 dlg.ShowDialog();
@@ -955,11 +978,11 @@
                 dlg.SetBindingData(allVisualViewModelList);
                 dlg.HydroClickInfoEvent += (visual) =>
                 {
-                    SelectVisual(visual, eVisualSource.Set);
+                    SelectVisual(visual, eSimulationVisualSource.Set);
                 };
                 dlg.HydroChangedInfoEvent += visuals =>
                 {
-                    SelectVisual(visuals?.FirstOrDefault(), eVisualSource.Set);
+                    SelectVisual(visuals?.FirstOrDefault(), eSimulationVisualSource.Set);
                     UpdateVisualListCtrl();
                 };
                 dlg.ShowDialog();
@@ -972,11 +995,11 @@
                 dlg.SetBindingData(allVisualViewModelList);
                 dlg.HydroClickInfoEvent += (visual) =>
                 {
-                    SelectVisual(visual, eVisualSource.Set);
+                    SelectVisual(visual, eSimulationVisualSource.Set);
                 };
                 dlg.HydroChangedInfoEvent += visuals =>
                 {
-                    SelectVisual(visuals?.FirstOrDefault(), eVisualSource.Set);
+                    SelectVisual(visuals?.FirstOrDefault(), eSimulationVisualSource.Set);
                     UpdateVisualListCtrl();
                 };
                 dlg.ShowDialog();
@@ -1210,12 +1233,12 @@
                 _searchCtrl.InitialData(allVisualVmList);
                 _searchCtrl.HydroClickInfoEvent += (visual) =>
                 {
-                    SelectVisual(visual, eVisualSource.Check);
+                    SelectVisual(visual, eSimulationVisualSource.Check);
                 };
                 _searchCtrl.HydroSearchInfoEvent += (list) =>
                 {
                     var visual = list?.FirstOrDefault();
-                    SelectVisual(visual, eVisualSource.Search);
+                    SelectVisual(visual, eSimulationVisualSource.Search);
                 };
             }
             return _searchCtrl;
@@ -1423,31 +1446,24 @@
         //鍒锋柊
         private async void barBtnRefresh_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
         {
+            if (this.RefreshModelEvent == null)
+            {
+                return;
+            }
             if (XtraMessageBox.Show("鍒锋柊鍚庡皢涓㈠け褰撳墠姘村姏淇℃伅鏇存敼锛屾槸鍚︾户缁埛鏂帮紵", "璇㈤棶", MessageBoxButtons.YesNo) == DialogResult.Yes)
             {
-                if (_project == null)
-                {
-                    return;
-                }
-                if (_projectSite == null)
-                {
-                    return;
-                }
-                var hydroRelation = await BLLFactory<Yw.BLL.HydroModelRelation>.Instance
-                    .GetDefaultByObjectTypeAndObjectIDOfPurpose(HStation.Xhs.DataType.XhsProjectSite, _projectSite.ID, HStation.Xhs.Purpose.Simulation);
-                Stopwatch sw = new Stopwatch();
-                sw.Start();
-                _hydroInfo = await BLLFactory<Yw.BLL.HydroModelInfo>.Instance.GetByID(hydroRelation.ModelID);
-                sw.Stop();
-                TimeSpan ts2 = sw.Elapsed;
-                Console.WriteLine("Stopwatch鎬诲叡鑺辫垂{0}ms.", ts2.TotalMilliseconds);
-                _visual = null;
-                await _bimfaceCtrl?.ZoomAndSelectComponents(null);
-                //ShowSelectedProperty();
-                TipFormHelper.ShowSucceed("鏁版嵁宸插埛鏂�");
 
-                var visualListHelper = GetVisualListHelper();
-                visualListHelper.InitialData(_hydroInfo);
+                var hydroInfo = await this.RefreshModelEvent.Invoke();
+                if (hydroInfo == null)
+                {
+                    TipFormHelper.ShowError("鍒锋柊澶辫触锛�");
+                    return;
+                }
+                _hydroInfo = hydroInfo;
+                SelectVisual(visual: null, eSimulationVisualSource.None);
+
+                ResetVisualList();
+                TipFormHelper.ShowSucceed("鍒锋柊鎴愬姛锛�");
             }
         }
 
@@ -1506,6 +1522,13 @@
                 _monitorHelper = new SimulationMonitorHelper(visualListHelper);
             }
             return _monitorHelper;
+        }
+
+        //鑾峰彇鐩戞祴鐐瑰垪琛�
+        private async Task<List<HydroMonitorVmo>> GetMonitorList()
+        {
+            var helper = GetMonitorHelper();
+            return await helper.Get();
         }
 
         //璁剧疆鐩戞祴鐐瑰垪琛�
@@ -1567,7 +1590,7 @@
         private void ResetMonitorValue()
         {
             var allWorkingList = GetWorkingList();
-            var working = allWorkingList?.Last(x => !string.IsNullOrEmpty(x.MonitorInfo));
+            var working = allWorkingList?.LastOrDefault(x => !string.IsNullOrEmpty(x.MonitorInfo));
             if (working != null)
             {
                 var helper = GetMonitorValueHelper();
@@ -1594,7 +1617,7 @@
                 {
                     var visualListHelper = GetVisualListHelper();
                     var visual = visualListHelper.GetVisual(code);
-                    SelectVisual(visual, eVisualSource.Monitor);
+                    SelectVisual(visual, eSimulationVisualSource.Monitor);
                 };
             }
             return _monitorValueListCtrl;
@@ -1693,7 +1716,7 @@
                 {
                     var visualListHelper = GetVisualListHelper();
                     var visual = visualListHelper.GetVisual(code);
-                    SelectVisual(visual, eVisualSource.Check);
+                    SelectVisual(visual, eSimulationVisualSource.Check);
                 };
             }
             return _checkCtrl;
@@ -1857,7 +1880,7 @@
                 {
                     var visualListHelper = GetVisualListHelper();
                     var visual = visualListHelper.GetVisual(code);
-                    SelectVisual(visual, eVisualSource.Warning);
+                    SelectVisual(visual, eSimulationVisualSource.Warning);
                 };
             }
             return _calcuWarningCtrl;
@@ -2050,7 +2073,7 @@
                 pumps.ForEach(x => x.UpdateWorkingInfo(list));
                 var visualVmListHelper = GetVisualVmListHelper();
                 visualVmListHelper.UpdateProperty(pumps.Select(x => x as Yw.Model.HydroVisualInfo).ToList());
-                SelectVisual(_visual, eVisualSource.None);
+                SelectVisual(_visual, eSimulationVisualSource.None);
                 var gradingHelper = await GetGradingHelper();
                 gradingHelper.Set();
             };
@@ -2091,7 +2114,7 @@
                 });
                 var visualVmListHelper = GetVisualVmListHelper();
                 visualVmListHelper.UpdateProperty(pumps.Select(x => x as Yw.Model.HydroVisualInfo).ToList());
-                SelectVisual(_visual, eVisualSource.None);
+                SelectVisual(_visual, eSimulationVisualSource.None);
                 var gradingHelper = await GetGradingHelper();
                 gradingHelper.Set();
             };
@@ -2125,7 +2148,7 @@
             dlg.SetBindingData(_hydroInfo, allWorkingList, allMonitorValueList);
             dlg.HydroViewEvent += (visual) =>
             {
-                SelectVisual(visual, eVisualSource.Calcu);
+                SelectVisual(visual, eSimulationVisualSource.Calcu);
             };
             dlg.HydroCalcuEvent += async (vm) =>
             {
@@ -2138,7 +2161,11 @@
                 working.ModelID = vm.ModelID;
                 working.Name = vm.Name;
                 working.WorkingInfo = JsonHelper.Object2Json(vm.WorkingInfo);
-                working.MonitorInfo = JsonHelper.Object2Json(vm.MonitorInfo);
+                var useWorkingMonitorInfo = vm.MonitorInfo?.Where(x => x.PropValue.HasValue).ToList();
+                if (useWorkingMonitorInfo != null && useWorkingMonitorInfo.Count > 0)
+                {
+                    working.MonitorInfo = JsonHelper.Object2Json(useWorkingMonitorInfo);
+                }
                 working.SortCode = vm.SortCode;
                 working.Description = vm.Description;
 
@@ -2165,6 +2192,7 @@
                         ShowCalcuWarningCtrl(calcuResult);
                     }
                     this.barBtnAddWorking.Enabled = true;
+                    this.barBtnExportWord.Enabled = true;
                     TipFormHelper.ShowSucceed("璁$畻鎴愬姛锛�");
                 }
                 else
@@ -2182,7 +2210,7 @@
 
                 #region 褰撳墠鏋勪欢
 
-                SelectVisual(_visual, eVisualSource.Calcu);
+                SelectVisual(_visual, eSimulationVisualSource.Calcu);
 
                 #endregion
 
@@ -2207,15 +2235,31 @@
                 #endregion
 
             };
-
             dlg.ShowDialog();
-
         }
 
         //姘村姏璁$畻
         private void barBtnCalcu_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
         {
             Calcu();
+        }
+
+        #endregion
+
+        #region 瀵煎嚭鎶ュ憡
+
+        private void barBtnExportWord_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
+        {
+            var fileName = FileDialogHelper.SaveWordDoc("瀵煎嚭Word鎶ュ憡");
+            if (string.IsNullOrEmpty(fileName))
+            {
+                return;
+            }
+            var vm = new ReportViewModel();
+            vm.ProjectName = _project.Name;
+            vm.Description = _project.Description;
+            SimulationWordReport word = new SimulationWordReport();
+            word.Create(fileName, vm);
         }
 
         #endregion
@@ -2335,6 +2379,27 @@
 
         #region 宸ュ喌鍒嗘瀽
 
+        //閫夋嫨杩涘彛姘存簮
+        private void SelectInputSource()
+        {
+            var sources = GetSourceList();
+            if (sources != null)
+            {
+                if (sources.Count == 1)
+                {
+                    SelectVisual(sources[0], eSimulationVisualSource.None);
+                }
+                else
+                {
+                    var source = sources.FirstOrDefault(x => x.Flags.Contains(HStation.Xhs.Flags.杩涘彛));
+                    if (source != null)
+                    {
+                        SelectVisual(source, eSimulationVisualSource.None);
+                    }
+                }
+            }
+        }
+
         //绮惧害璇勪及
         private async void barBtnWorkingEvaluation_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
         {
@@ -2389,8 +2454,9 @@
         }
 
         //鑳芥晥鍒嗘瀽
-        private void barBtnWorkingPower_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
+        private async void barBtnWorkingPower_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
         {
+            var allMonitorList = await GetMonitorList();
             var workingCheckedListHelper = GetWorkingCheckedListHelper();
             var allCheckedWorkingList = workingCheckedListHelper.GetCheckedWorkingList();
             if (allCheckedWorkingList == null || allCheckedWorkingList.Count < 1)
@@ -2402,13 +2468,14 @@
                     return;
                 }
                 var dlg = new SimulationSingleWorkingEnergyDlg();
-                dlg.SetBindingData(workingHelper.HydroInfo, workingHelper.CalcuResult);
+                dlg.SetBindingData(workingHelper.Working, workingHelper.HydroInfo, allMonitorList, workingHelper.CalcuResult);
                 dlg.ShowDialog();
             }
             else
             {
+
                 var dlg = new SimulationMultiWorkingEnergyDlg();
-                dlg.SetBindingData(_hydroInfo, allCheckedWorkingList);
+                dlg.SetBindingData(_hydroInfo, allMonitorList, allCheckedWorkingList);
                 dlg.ShowDialog();
             }
         }
@@ -2418,22 +2485,7 @@
         {
             if (_visual == null)
             {
-                var sources = GetSourceList();
-                if (sources != null)
-                {
-                    if (sources.Count == 1)
-                    {
-                        SelectVisual(sources[0], eVisualSource.None);
-                    }
-                    else
-                    {
-                        var source = sources.FirstOrDefault(x => x.Flags.Contains(HStation.Xhs.Flags.杩涘彛));
-                        if (source != null)
-                        {
-                            SelectVisual(source, eVisualSource.None);
-                        }
-                    }
-                }
+                SelectInputSource();
                 if (_visual == null)
                 {
                     TipFormHelper.ShowWarn("璇烽�夋嫨鏋勪欢鍚庨噸璇曪紒");
@@ -2460,7 +2512,7 @@
                 var dlg = new HydroSingleWorkingLossCurveDlg();
                 dlg.HydroClickEvent += (code) =>
                 {
-                    SelectVisual(code, eVisualSource.None);
+                    SelectVisual(code, eSimulationVisualSource.None);
                 };
                 dlg.SetBindingData(workingHelper.HydroInfo, workingHelper.CalcuResult, visual);
                 dlg.ShowDialog();
@@ -2470,7 +2522,7 @@
                 var dlg = new HydroMultiWorkingLossCurveDlg();
                 dlg.HydroClickEvent += (code) =>
                 {
-                    SelectVisual(code, eVisualSource.None);
+                    SelectVisual(code, eSimulationVisualSource.None);
                 };
                 dlg.SetBindingData(_hydroInfo, allCheckedWorkingList, visual);
                 dlg.ShowDialog();
@@ -2507,26 +2559,14 @@
         {
             if (_visual == null)
             {
-                var sources = GetSourceList();
-                if (sources != null)
-                {
-                    if (sources.Count == 1)
-                    {
-                        SelectVisual(sources[0], eVisualSource.None);
-                    }
-                    else
-                    {
-                        var source = sources.FirstOrDefault(x => x.Flags.Contains(HStation.Xhs.Flags.杩涘彛));
-                        if (source != null)
-                        {
-                            SelectVisual(source, eVisualSource.None);
-                        }
-                    }
-                }
                 if (_visual == null)
                 {
-                    TipFormHelper.ShowWarn("璇烽�夋嫨鏋勪欢鍚庨噸璇曪紒");
-                    return;
+                    SelectInputSource();
+                    if (_visual == null)
+                    {
+                        TipFormHelper.ShowWarn("璇烽�夋嫨鏋勪欢鍚庨噸璇曪紒");
+                        return;
+                    }
                 }
             }
             HydroVisualInfo visual = _visual;
@@ -2563,11 +2603,74 @@
 
         #endregion
 
+        #region 鏂规绠$悊
 
+        //鏇存柊鏂规
+        private void UpdateScheme()
+        {
+            if (_scheme == null)
+            {
+                return;
+            }
+            if (_hydroInfo == null)
+            {
+                return;
+            }
 
+            var dlg = new EditXhsSchemeDlg();
+            dlg.SetBindingData(_scheme, _hydroInfo);
+            dlg.ReloadDataEvent += (rhs) =>
+            {
+                _scheme = rhs;
+                this.PageTitle.Caption = $"妯℃嫙鏂规\r\n{_scheme.Name}";
+                UpdatePageTitle(this.PageGuid, this.PageTitle);
+                this.UpdateSchemeEvent?.Invoke(_scheme);
+            };
+            dlg.ShowDialog();
+        }
 
+        //缂栬緫鏂规
+        private void barBtnEditScheme_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
+        {
+            UpdateScheme();
+        }
 
+        //鍒犻櫎鏂规
+        private async void DeleteScheme()
+        {
+            if (_scheme == null)
+            {
+                return;
+            }
+            var relation = await BLLFactory<Yw.BLL.HydroModelRelation>.Instance
+                .GetDefaultByObjectTypeAndObjectIDOfPurpose(HStation.Xhs.DataType.XhsScheme, _scheme.ID, HStation.Xhs.Purpose.Simulation);
+            if (relation == null)
+            {
+                TipFormHelper.ShowError("姘村姏妯℃嫙鏂规鍒犻櫎澶辫触锛岃閲嶈瘯锛�");
+                return;
+            }
+            if (!await BLLFactory<Yw.BLL.HydroModelRelation>.Instance.DeleteAllByID(relation.ID))
+            {
+                TipFormHelper.ShowError("姘村姏妯℃嫙鏂规鍒犻櫎澶辫触锛岃閲嶈瘯锛�");
+                return;
+            }
 
+            if (!await BLLFactory<HStation.BLL.XhsScheme>.Instance.DeleteByID(_scheme.ID))
+            {
+                TipFormHelper.ShowError("姘村姏妯℃嫙鏂规鍒犻櫎澶辫触锛岃閲嶈瘯锛�");
+                return;
+            }
+            this.RemoveSchemeEvent?.Invoke(_scheme);
+            TipFormHelper.ShowSucceed("姘村姏妯℃嫙鏂规鍒犻櫎鎴愬姛锛�");
+            ClosePage(this.PageGuid);
+        }
 
+        //鍒犻櫎鏂规
+        private void barBtnDeleteScheme_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
+        {
+            DeleteScheme();
+        }
+
+        #endregion
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3