duheng
2024-10-14 3b08b5c772ffc0c10644c1aaa9f7b2447582c858
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
namespace Yw.WinFrmUI.Phart
{
    public partial class PumpVariableSpeedInfoCtrl : DevExpress.XtraEditors.XtraUserControl
    {
        public PumpVariableSpeedInfoCtrl()
        {
            InitializeComponent();
            this.gridView1.SetNormalEditView();
            this.gridView2.SetNormalView();
            this.repColor.ColorChanged += RepColor_ColorChanged;
            this.repColor.ColorAlignment = DevExpress.Utils.HorzAlignment.Center;
            this.repColor.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
            this.repColor.ButtonsStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
 
        }
         
         
        /// <summary>
        /// 设置曲线
        /// </summary> 
        public event Action<string, Yw.Geometry.CubicSpline2d, Yw.Geometry.CubicSpline2d, Yw.Geometry.CubicSpline2d> SetEvent;
 
        /// <summary>
        /// 设置曲线信息
        /// </summary> 
        public event Action<string, string, Color> SetInfoEvent;
 
        /// <summary>
        /// 设置设计点
        /// </summary> 
        public event Action<double, double> SetDesignPointEvent;
 
        private List<PumpVariableSpeedInfoViewModel> _all_binding_list = null;
 
        public void SetBindingData(PumpVariableSpeedInfoViewModel item, Yw.Geometry.Point2d design_pt = null)
        {
            _all_binding_list = new List<PumpVariableSpeedInfoViewModel>();
            if (item != null)
            {  
                _all_binding_list.Add(item); 
            }
 
            this.txtDesignQ.EditValue = design_pt?.X;
            this.txtDesignH.EditValue = design_pt?.Y;
 
            this.pumpSerialParallelInfoViewModelBindingSource.DataSource = _all_binding_list;
            this.pumpSerialParallelInfoViewModelBindingSource.ResetBindings(false);
            this.gridView1.BestFitColumns();
 
        }
 
        public void SetBindingData(List<PumpVariableSpeedInfoViewModel> vm_list, Yw.Geometry.Point2d design_pt = null)
        {
            _all_binding_list = new List<PumpVariableSpeedInfoViewModel>();
            if (vm_list != null && vm_list.Any())
            {
                for (int i = 0; i < vm_list.Count; i++)
                {
                    var item = vm_list[i];
                    var vm = new PumpVariableSpeedInfoViewModel();
                    vm.Id = item.Id;
                    vm.Name = item.Name;
                    vm.Color = item.Color;
                    vm.IsBp = item.IsBp;
                    vm.RatedSpeed = item.RatedSpeed;
                    vm.CurrentSpeed = item.CurrentSpeed;
                    vm.CurrentHz = Math.Round(item.CurrentSpeed / item.RatedSpeed * 50, 2);
                    vm.Qh = new Geometry.CubicSpline2d(item.Qh);
                    vm.Qe = new Geometry.CubicSpline2d(item.Qe);
                    vm.Qp = new Geometry.CubicSpline2d(item.Qp);
                    vm.ExtendRatio = 100;
                    vm.Calc();
                    _all_binding_list.Add(vm);
                }
            }
 
            this.txtDesignQ.EditValue = design_pt?.X;
            this.txtDesignH.EditValue = design_pt?.Y;
 
            this.pumpSerialParallelInfoViewModelBindingSource.DataSource = _all_binding_list;
            this.pumpSerialParallelInfoViewModelBindingSource.ResetBindings(false);
            this.gridView1.BestFitColumns();
 
        }
 
        public void Add(PumpVariableSpeedInfoViewModel vm)
        {
            if (_all_binding_list == null)
                _all_binding_list = new List<PumpVariableSpeedInfoViewModel>();
             
            _all_binding_list.Add(vm);
            this.pumpSerialParallelInfoViewModelBindingSource.DataSource = _all_binding_list;
            this.pumpSerialParallelInfoViewModelBindingSource.ResetBindings(false);
            this.gridView1.BestFitColumns();
 
        }
 
        public void SetSectPoint(List<PumpVariableSpeedInfoViewModel> vm_list)
        {
            var pt_vm_list = new List<PumpSectPointViewModel>();
            if (vm_list != null && vm_list.Any())
            {
                foreach (var vm in vm_list)
                {
                    var sect_pt = vm.SectPoint;
                    var pt_vm = new PumpSectPointViewModel();
                    pt_vm.Id = vm.Id;
                    pt_vm.Name = vm.Name;
                    if (sect_pt != null)
                    {
                        pt_vm.QueryQ = $"{sect_pt.X:N1}";
                        pt_vm.QueryH = $"{sect_pt.Y:N1}";
 
                        if (vm.QeCalc != null)
                        {
                            pt_vm.QueryE = $"{vm.QeCalc.GetPointY(sect_pt.X):N1}";
                        }
                        if (vm.QpCalc != null)
                        {
                            pt_vm.QueryP = $"{vm.QpCalc.GetPointY(sect_pt.X):N1}";
                        }
                    }
                    pt_vm_list.Add(pt_vm);
                }
            }
            this.pumpSectPointViewModelBindingSource.DataSource = pt_vm_list;
            this.pumpSectPointViewModelBindingSource.ResetBindings(false);
            this.gridView2.BestFitColumns();
        }
         
        /// <summary>
        /// 获取列表
        /// </summary> 
        public List<PumpVariableSpeedInfoViewModel> GetList()
        {
            if (_all_binding_list == null || !_all_binding_list.Any())
            {
                return default;
            }
            return _all_binding_list.Select(x => new PumpVariableSpeedInfoViewModel(x)).ToList();
        }
 
        /// <summary>
        /// 获取
        /// </summary> 
        public  Yw.Geometry.Point2d GetDesignPoint()
        { 
             
            if (!double.TryParse(this.txtDesignQ.Text,out double x))
            {
                return default;
            }
            if (!double.TryParse(this.txtDesignH.Text, out double y))
            {
                return default;
            }
            return new Geometry.Point2d(x,y);
        }
 
        #region Color
 
        private List<Color> _color_array = new List<Color>()
        {
            Color.Red, Color.Blue, Color.Green,Color.DodgerBlue,
            Color.Fuchsia, Color.MidnightBlue,  Color.Maroon, Color.Aquamarine,
            Color.Bisque,Color.BurlyWood
        };
 
        /// <summary>
        /// 获取随机颜色
        /// </summary>
        /// <returns></returns>
        private Color GetRandomColor(int count)
        {
            if (count < _color_array.Count)
            {
                return _color_array[count];
            }
 
            var _random = new Random();
            int r = _random.Next(1, 256);
            int g = _random.Next(1, 256);
            int b = _random.Next(1, 256);
            return Color.FromArgb(r, g, b);
        }
 
        #endregion
 
        //颜色变换
        private void RepColor_ColorChanged(object sender, EventArgs e)
        {
            if (this.gridView1.GetCurrentViewModel(_all_binding_list) is not PumpVariableSpeedInfoViewModel vm)
                return;
            vm.Color = (sender as DevExpress.XtraEditors.ColorEdit).Color;
            this.SetInfoEvent?.Invoke(vm.Id, vm.Name, vm.Color);
        }
 
        //值变换
        private void gridView1_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            if (e.Column == this.colName)
            {
                var vm = this.gridView1.GetRow(e.RowHandle) as PumpVariableSpeedInfoViewModel;
                this.SetInfoEvent?.Invoke(vm.Id, vm.Name, vm.Color);
            }
            else
            if (e.Column == this.colCurrentHz)
            {
                var vm = this.gridView1.GetRow(e.RowHandle) as PumpVariableSpeedInfoViewModel;
                if (vm.CurrentHz < 10 || vm.CurrentHz > 50)
                {
                    return;
                }
                vm.Calc();
                this.SetEvent?.Invoke(vm.Id, vm.QhCalc, vm.QeCalc, vm.QpCalc);
            }
            else if (e.Column == this.colExtendRatio)
            {
                var vm = this.gridView1.GetRow(e.RowHandle) as PumpVariableSpeedInfoViewModel;
                vm.Calc();
                this.SetEvent?.Invoke(vm.Id, vm.QhCalc, vm.QeCalc, vm.QpCalc);
            }
        }
 
        /// <summary>
        /// 设置查询信息
        /// </summary>
        /// <param name="id"></param>
        /// <param name="query_pt"></param>
        public void SetQueryInfo(string id, PumpGroupPt query_pt)
        {
            if (query_pt == null)
                return;
            if (_all_binding_list == null || !_all_binding_list.Any())
                return;
            var vm = _all_binding_list.Find(x => x.Id == id);
            if (vm == null)
                return;
            vm.QueryQ = query_pt.Q > 0 ? $"{query_pt.Q:N1}" : string.Empty;
            vm.QueryH = query_pt.H > 0 ? $"{query_pt.H:N1}" : string.Empty;
            vm.QueryE = query_pt.E > 0 ? $"{query_pt.E:N1}" : string.Empty;
            vm.QueryP = query_pt.P > 0 ? $"{query_pt.P:N1}" : string.Empty;
            this.pumpSerialParallelInfoViewModelBindingSource.ResetBindings(false);
        }
 
        //设置设计点
        private void btnSetDesignPoint_Click(object sender, EventArgs e)
        {
            if (!double.TryParse(this.txtDesignQ.Text, out double design_q))
                return;
            if (!double.TryParse(this.txtDesignH.Text, out double design_h))
                return;
 
            this.SetDesignPointEvent?.Invoke(design_q, design_h);
        }
 
 
    }
}