lixiaojun
2024-12-10 d7837329e5d2ca8938f4939fa58db2295c7ed88c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Yw.Geometry;
using Yw.Pump;
using Yw.WinFrmUI.Phart;
 
namespace HStation.WinFrmUI
{
    public partial class SimulationPumpFeatCtrl : DevExpress.XtraEditors.XtraUserControl
    {
        public SimulationPumpFeatCtrl()
        {
            InitializeComponent();
            this.layoutControl1.SetupLayoutControl();
            this.hydroPumpListStateEditCtrl1.SelectedChangedEvent += HydroPumpListStateEditCtrl1_SelectedChangedEvent;
        }
 
        /// <summary>
        /// 保存事件
        /// </summary>
        public event Action<List<HydroWorkingPumpViewModel>> SaveEvent;
 
        /// <summary>
        /// 
        /// </summary>
        public void SetBindingData(Yw.Model.HydroModelInfo hydroInfo)
        {
            this.hydroPumpListStateEditCtrl1.SetBindingData(hydroInfo);
        }
 
 
        private void HydroPumpListStateEditCtrl1_SelectedChangedEvent(HydroPumpListItemStateViewModel obj)
        {
            var vm = CreateViewModel(obj);
            this.pumpOperationChart1.SetBindingData(vm);
        }
 
        //创建
        private PumpOperationViewModel CreateViewModel(HydroPumpListItemStateViewModel state)
        {
            var vm = new PumpOperationViewModel();
            vm.Id = state.Code;
            vm.Name = state.Name;
            vm.RatedQ = state.Vmo.RatedQ.HasValue ? state.Vmo.RatedQ.Value : 0;
            vm.RatedH = state.Vmo.RatedH.HasValue ? state.Vmo.RatedH.Value : 0;
            vm.RatedP = state.Vmo.RatedP;
            vm.RatedN = state.Vmo.RatedN.HasValue ? state.Vmo.RatedN.Value : 0;
            vm.RatedHz = state.Vmo.RatedHz;
            vm.CurrentHz = state.CurrentHz;
            vm.CurrentN = Math.Round(state.CurrentHz / state.Vmo.RatedHz * vm.RatedN, 1);
            vm.CurrentStatus = state.LinkStatus == Yw.Hydro.PumpStatus.Open;
 
            var curveqh = state.HydroInfo.Curves?.Find(x => x.Code == state.Vmo.CurveQH);
            if (curveqh != null)
            {
                var qh_pts = curveqh.CurveData?.Select(x => new Yw.Geometry.Point2d(x.X, x.Y)).ToList();
                if (qh_pts != null && qh_pts.Count > 3)
                {
                    vm.CurveQH = new CubicSpline2d(qh_pts);
                    var qh_current_pts = qh_pts.GetQHPointListByN(state.Vmo.RatedHz, state.CurrentHz);
                    vm.CurrentCurveQH = new CubicSpline2d(qh_current_pts);
                }
            }
 
            var curveqp = state.HydroInfo.Curves?.Find(x => x.Code == state.Vmo.CurveQP);
            if (curveqp != null)
            {
                var qppts = curveqp.CurveData?.Select(x => new Yw.Geometry.Point2d(x.X, x.Y)).ToList();
                if (qppts != null && qppts.Count > 3)
                {
                    vm.CurveQP = new CubicSpline2d(qppts);
                    var sqppts = qppts.GetQHPointListByN(state.Vmo.RatedHz, state.CurrentHz);
                    vm.CurrentCurveQP = new CubicSpline2d(sqppts);
                }
            }
 
            var curveqe = state.HydroInfo.Curves?.Find(x => x.Code == state.Vmo.CurveQE);
            if (curveqe != null)
            {
                var qepts = curveqe.CurveData?.Select(x => new Yw.Geometry.Point2d(x.X, x.Y)).ToList();
                if (qepts != null && qepts.Count > 3)
                {
                    vm.CurveQE = new CubicSpline2d(qepts);
                    var sqepts = qepts.GetQHPointListByN(state.Vmo.RatedHz, state.CurrentHz);
                    vm.CurrentCurveQE = new CubicSpline2d(sqepts);
                }
            }
 
            return vm;
        }
 
        /// <summary>
        /// 保存
        /// </summary>
        public void Save()
        {
            if (this.hydroPumpListStateEditCtrl1.HasChanged)
            {
                var result = XtraMessageBox.Show("是否使用现有水泵状态更新模型?", "询问", MessageBoxButtons.YesNo) == DialogResult.Yes;
                if (result)
                {
                    var allWorkingList = this.hydroPumpListStateEditCtrl1.GetWorkingList();
                    this.SaveEvent?.Invoke(allWorkingList);
                }
            }
        }
 
    }
}