tangxu
2025-01-02 881182e372e563646c01802b90a00bc03d495ac0
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DPumpHydr.WinFrmUI.RLT.Controls; 
using DPumpHydr.WinFrmUI.Volute.ViewModel; 
 
namespace DPumpHydr.WinFrmUI.Volute
{
    /// <summary>
    /// 断面基本信息(形状等)
    /// </summary>
    public partial class ctrlSectionBundleInfo : ParasInfoBaseCtrl
    {
        public ctrlSectionBundleInfo()
        {
            InitializeComponent();
            BuildAllTips();
            BuildIcon();
        }
        ViewModel.SectionBundleInfo _sectionBundleInfo = null;
        ViewModel.HdrBaseInfo _hdrBaseInfo = null;
        ViewModel.GeomBaseInfo _geomBaseInfo = null;
 
 
        public void ShowPage(
            ViewModel.HdrBaseInfo BaseInfo,
            ViewModel.GeomBaseInfo geom_info,
            DPumpHydr.ViewModel.eWizardStepDiretion step_direction)
        {
            if (step_direction == DPumpHydr.ViewModel.eWizardStepDiretion.后退) {
                return; 
            }
            this._hdrBaseInfo = BaseInfo;
            this._geomBaseInfo = geom_info;
 
            if (_sectionBundleInfo == null)
            {
                _sectionBundleInfo = new ViewModel.SectionBundleInfo();
 
                _sectionBundleInfo.BaseWidth = _geomBaseInfo.B3;
                _sectionBundleInfo.BaseCircleRadius = _geomBaseInfo.D3 / 2;
 
                _sectionBundleInfo.ResetAllParas(_hdrBaseInfo, _geomBaseInfo); 
            }
            else
            {
                _sectionBundleInfo.BaseWidth = _geomBaseInfo.B3;
                _sectionBundleInfo.BaseCircleRadius = _geomBaseInfo.D3 / 2;
                return;
            }
 
 
            RefreshAllSectPara(_sectionBundleInfo);
 
            this.OnRefreshShape(_sectionBundleInfo);
        }
        
        //
        public void RefreshAllSectPara(ViewModel.SectionBundleInfo paras)
        {
            this._sectionBundleInfo = paras;
 
            this.textBoxK3.Text = _sectionBundleInfo.K3.ToString();
            this.textBoxV3.Text = _sectionBundleInfo.V3.ToString();
 
            if (_sectionBundleInfo.ShapeType == eSectionShapeType.对称)
            {
                RBtn断面对称梯形.Checked = true;
                RBtn不对称梯形.Checked = false;
                RBtn矩形.Checked = false;
            }
            if (_sectionBundleInfo.ShapeType == eSectionShapeType.不对称)
            {
                RBtn断面对称梯形.Checked = false;
                RBtn不对称梯形.Checked = true;
                RBtn矩形.Checked = false;
            }
            if (_sectionBundleInfo.ShapeType == eSectionShapeType.矩形)
            {
                RBtn断面对称梯形.Checked = false;
                RBtn不对称梯形.Checked = false;
                RBtn矩形.Checked = true;
            }
 
            RefrehPara();
        }
        //
        public void RefreshSingleSectPara(ViewModel.SectionBundleInfo paras, int selectedPointIndex)
        {
            this._sectionBundleInfo = paras;
            paras.CalcHeightByArea(_geomBaseInfo, selectedPointIndex); 
            RefrehPara();
        }
 
 
        private void RefrehPara()
        {
            for (var argument = 1; argument <= 8; argument++)
            {
                var controlnameGama1 = $"skyTextBox断面y1{argument}";
                var controlnameRia1 = $"skyTextBox断面r1{argument}";
                var controlname断面面积 = $"skyTextBox断面面积{argument}";
                var controlnameHeight = $"skyTextBox断面H1{argument}";
 
                SkyTextBox controly1 = this.Controls.Find(controlnameGama1, true).FirstOrDefault() as SkyTextBox;
                SkyTextBox controly2 = this.Controls.Find(controlnameRia1, true).FirstOrDefault() as SkyTextBox;
                SkyTextBox control断面面积 = this.Controls.Find(controlname断面面积, true).FirstOrDefault() as SkyTextBox;
                SkyTextBox controH1 = this.Controls.Find(controlnameHeight, true).FirstOrDefault() as SkyTextBox;
 
                if (controly1 != null)
                    controly1.Text = _sectionBundleInfo.GaMa_Left[argument].ToString();
                if (controly2 != null)
                    controly2.Text = _sectionBundleInfo.R_Left[argument].ToString();
                if (control断面面积 != null)
                    control断面面积.Text = _sectionBundleInfo.Area[argument].ToString();
                if (controH1 != null)
                    controH1.Text = _sectionBundleInfo.H[argument].ToString();
            }
        }
        public ViewModel.SectionBundleInfo GetBindingData(out string error)
        {
            if (!Verify(out error))
            {
                return null;
            }
            error = null;
            if (_sectionBundleInfo == null)
            {
                _sectionBundleInfo = new ViewModel.SectionBundleInfo();
            }
 
            if (RBtn断面对称梯形.Checked)
            {
                _sectionBundleInfo.ShapeType = eSectionShapeType.对称;
            }
            if (RBtn不对称梯形.Checked)
            {
                _sectionBundleInfo.ShapeType = eSectionShapeType.不对称;
            }
            if (RBtn矩形.Checked)
            {
                _sectionBundleInfo.ShapeType = eSectionShapeType.矩形;
            }
 
            _sectionBundleInfo.V3 = Convert.ToDouble(this.textBoxV3.Text);
            for (var argument = 1; argument <= 8; argument++)
            {
                var controlname_y1 = $"skyTextBox断面y1{argument}";
                var controlname_r1 = $"skyTextBox断面r1{argument}";
                var controlname断面面积 = $"skyTextBox断面面积{argument}";
                SkyTextBox controlY1 = this.Controls.Find(controlname_y1, true).FirstOrDefault() as SkyTextBox;
                SkyTextBox controlR1 = this.Controls.Find(controlname_r1, true).FirstOrDefault() as SkyTextBox;
                SkyTextBox control断面面积 = this.Controls.Find(controlname断面面积, true).FirstOrDefault() as SkyTextBox;
                if (controlY1 != null)
                {
                    _sectionBundleInfo.GaMa_Left[argument] = Convert.ToDouble(controlY1.Text);
                    _sectionBundleInfo.GaMa_Right[argument] = _sectionBundleInfo.GaMa_Left[argument];
                }
 
                if (controlR1 != null)
                {
                    _sectionBundleInfo.R_Left[argument] = Convert.ToDouble(controlR1.Text);
                    _sectionBundleInfo.R_Right[argument] = _sectionBundleInfo.R_Left[argument];
                }
 
                if (control断面面积 != null)
                    _sectionBundleInfo.Area[argument] = Convert.ToDouble(control断面面积.Text);
            }
 
 
            return _sectionBundleInfo;
        }
        public bool Verify(out string error)
        {
            error = "";
            bool isOk = true;
            double v3 = 0;
            if (string.IsNullOrEmpty(textBoxV3.Text) || !double.TryParse(textBoxV3.Text, out v3) || v3 <= 0.1)
            {
                error = "请输入必填项!";
                isOk = false;
            }
            if (string.IsNullOrEmpty(skyTextBox断面y18.Text) || double.Parse(skyTextBox断面y18.Text) <= 0)
            {
                error = "请输入必填项!";
                isOk = false;
 
            }
            if (string.IsNullOrEmpty(skyTextBox断面r18.Text) || double.Parse(skyTextBox断面r18.Text) <= 0)
            {
                error = "请输入必填项!";
                isOk = false;
            }
            return isOk;
        }
 
        public bool IsParameterChange()
        {
            if (double.Parse(textBoxV3.Text) != this._sectionBundleInfo.V3)
            {
                return true;
            }
            if (RBtn断面对称梯形.Checked && this._sectionBundleInfo.ShapeType == eSectionShapeType.对称)
            {
                return true;
            }
            if (RBtn不对称梯形.Checked && this._sectionBundleInfo.ShapeType == eSectionShapeType.不对称)
            {
                return true;
            }
            if (RBtn矩形.Checked && this._sectionBundleInfo.ShapeType == eSectionShapeType.矩形)
            {
                return true;
            }
            if (double.Parse(skyTextBox断面y18.Text) != this._sectionBundleInfo.GaMa_Left[8])
            {
                return true;
            }
            if (double.Parse(skyTextBox断面r18.Text) != this._sectionBundleInfo.GaMa_Right[8])
            {
                return true;
            }
            return false;
        }
 
 
        private void BuildIcon()
        {
            //断面形状图片
            metroTile对称梯形.BackgroundImage = GlobalResource.BuildImage("duichentixing.png", 97, 88);
            metroTile不对称梯形.BackgroundImage = GlobalResource.BuildImage("buduichentixing.png", 97, 88);
            metroTile矩形.BackgroundImage = GlobalResource.BuildImage("juxing.png", 97, 88);
        }
 
        private void BuildAllTips()
        {
            metroToolTip第三步提示.SetToolTip(this.metroTile对称梯形, "对称梯形");
            metroToolTip第三步提示.SetToolTip(this.metroTile不对称梯形, "不对称梯形");
            metroToolTip第三步提示.SetToolTip(this.metroTile矩形, "矩形");
            metroToolTip第三步提示.SetToolTip(this.skyTextBox断面y18, "y1 解释");
            metroToolTip第三步提示.SetToolTip(this.skyTextBox断面r18, "y2 解释");
        }
        private void metroTile断面形状1_Click(object sender, EventArgs e)
        {
            RBtn断面对称梯形.Checked = true;
            RBtn不对称梯形.Checked = false;
            RBtn矩形.Checked = false;
        }
 
        private void metroTile断面形状2_Click(object sender, EventArgs e)
        {
            RBtn断面对称梯形.Checked = false;
            RBtn不对称梯形.Checked = true;
            RBtn矩形.Checked = false;
        }
 
        private void metroTile断面形状3_Click(object sender, EventArgs e)
        {
            RBtn断面对称梯形.Checked = false;
            RBtn不对称梯形.Checked = false;
            RBtn矩形.Checked = true;
        }
 
 
 
 
 
        private void skyTextBox断面VIIIy1_TextChanged(object sender, EventArgs e)
        {
            {
                if (!double.TryParse(skyTextBox断面y18.Text, out double result) && !string.IsNullOrEmpty(skyTextBox断面y18.Text))
                {
                    skyTextBox断面y18.Text = _sectionBundleInfo.GaMa_Left[8].ToString();
                }
            }
        }
 
        private void skyTextBox断面VIIIy2_TextChanged(object sender, EventArgs e)
        {
            {
                if (!double.TryParse(skyTextBox断面r18.Text, out double result) && !string.IsNullOrEmpty(skyTextBox断面r18.Text))
                {
                    skyTextBox断面r18.Text = _sectionBundleInfo.GaMa_Right[8].ToString();
                }
            }
        }
 
 
 
        private void mBtn计算断面面积_Click(object sender, EventArgs e)
        {
            double v3 = 0;
            if (string.IsNullOrEmpty(textBoxV3.Text) || !double.TryParse(textBoxV3.Text, out v3) || v3 <= 0.1)
            {
                MessageBox.Show("请先输入蜗室平均速度!");
                return;
            }
            if (_sectionBundleInfo == null)
            {
                _sectionBundleInfo = new ViewModel.SectionBundleInfo();
            }
            _sectionBundleInfo.V3 = v3;
            _sectionBundleInfo.CalcParaV3(this._hdrBaseInfo, this._geomBaseInfo);
 
            RefrehPara();
 
 
            if (OnRefreshShape != null)
            {
                ViewModel.SectionBundleInfo paras = GetBindingData(out string error);
                if (paras == null)
                    return;
                //textBox割舌角度
                OnRefreshShape.Invoke(paras);
            }
 
        }
 
        private void mlBtn更改断面角度_Click(object sender, EventArgs e)
        {
            if (!RBtn断面对称梯形.Checked && !RBtn不对称梯形.Checked && !RBtn矩形.Checked)
            {
                MessageBox.Show("请先选择断面类型!");
                return;
            }
            if (string.IsNullOrEmpty(skyTextBox断面y18.Text) || string.IsNullOrEmpty(skyTextBox断面r18.Text))
            {
                //skyLabel提示y2.Visible = false;
                //skyLabel提示y1.Visible = false;
                //skyLabely1.Visible = true;
                //skyLabely2.Visible = true;
                //MessageBox.Show("请先输入y1、y2!");
                return;
            }
        }
 
        private void RBtn断面对称梯形_CheckedChanged(object sender)
        {
            if (RBtn断面对称梯形.Checked)
            {
                skyTextBox断面y18.Enabled = true;
                skyTextBox断面r18.Enabled = false;
            }
        }
 
        private void RBtn不对称梯形_CheckedChanged(object sender)
        {
            if (RBtn不对称梯形.Checked)
            {
                skyTextBox断面y18.Enabled = true;
                skyTextBox断面r18.Enabled = true;
            }
        }
    
 
        private void textBoxK3_TextChanged(object sender, EventArgs e)
        {
            double K3 = 0;
            if (string.IsNullOrEmpty(textBoxK3.Text))
                return;
            if (!double.TryParse(textBoxK3.Text, out K3))
                return;
            if (K3 < 0.1)
                return;
 
            var g = 9.81;
            this.textBoxV3.Text = Math.Round(K3 * Math.Sqrt(2 * g * _hdrBaseInfo.Q), 2).ToString();
        }
 
        public Action<ViewModel.SectionBundleInfo> OnRefreshShape = null;
        private void mBtn更新模型_Click(object sender, EventArgs e)
        {
            ViewModel.SectionBundleInfo paras = GetBindingData(out string error);
            if (paras == null)
                return;
            if (OnRefreshShape == null)
                return;
            //paras.InitialAllParameters(this._hdrBaseInfo,this._geomBaseInfo);
            OnRefreshShape.Invoke(paras);
        }
    }
}