duheng
2024-10-09 f4bf35513c50f86556d5e3c75a037052f53c971d
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
namespace HStation.WinFrmUI.PhartRelation
{
    public partial class XhsPumpMainPhartPanel : DocumentPage
    {
        public XhsPumpMainPhartPanel()
        {
            InitializeComponent();
            this.PageTitle.Caption = "泵型号曲线";
 
            this.xhsPumpMainPhartListCtrl1.FocusedChangedEvent += XhsPumpMainPhartListCtrl1_FocusedChangedEvent;
        }
 
        private long _pump_main_id;
        private Vmo.XhsPumpMainPhartMappingExtensions _xhs_phart_diagram_ex_std_dto = null;
        private readonly BLL.XhsPumpMainPhartMappingExtensions _bll_ex = new();
 
        /// <summary>
        /// 初始化数据
        /// </summary>
        public void InitialDataSource(long pump_main_id)
        {
            _pump_main_id = pump_main_id;
            if (_pump_main_id < 1)
            {
                this.xhsPumpMainPhartListCtrl1.Clear();
                return;
            }
            this.xhsPumpMainPhartListCtrl1.SetBindingData(pump_main_id);
        }
 
        //选择曲线变换事件
        private void XhsPumpMainPhartListCtrl1_FocusedChangedEvent(Vmo.XhsPumpMainPhartMappingExtensions obj)
        {
            _xhs_phart_diagram_ex_std_dto = obj;
            InitChart(_xhs_phart_diagram_ex_std_dto);
        }
 
        #region 图表
 
        //初始化图表数据
        private void InitChart(Vmo.XhsPumpMainPhartMappingExtensions dto)
        {
            if (dto == null)
            {
                return;
            }
            var diagram = dto.Diagram;
            if (diagram == null)
            {
                return;
            }
            var graph_list = diagram.GraphList;
            if (graph_list == null || !graph_list.Any())
            {
                return;
            }
 
            var graph_qh = graph_list.Find(x => x.GraphType == HStation.PhartRelation.eGraphType.PumpQH);
            var graph_qe = graph_list.Find(x => x.GraphType == HStation.PhartRelation.eGraphType.PumpQE);
            var graph_qp = graph_list.Find(x => x.GraphType == HStation.PhartRelation.eGraphType.PumpQP);
 
            if (graph_qh == null)
            {
                return;
            }
 
            List<Yw.Geometry.Point2d> points_qh = null, points_qe = null, points_qp = null;
            points_qh = PhartPerformCurveHelper.GetFeatPointList(graph_qh.GraphType, graph_qh.GeometryInfo, 12, null);
            if (graph_qe != null)
                points_qe = PhartPerformCurveHelper.GetFeatPointList(graph_qe.GraphType, graph_qe.GeometryInfo, 12, null);
            if (graph_qp != null)
                points_qp = PhartPerformCurveHelper.GetFeatPointList(graph_qp.GraphType, graph_qp.GeometryInfo, 12, null);
 
            var cubic_spline_qh = new Yw.Geometry.CubicSpline2d(points_qh);
            var cubic_spline_qe = new Yw.Geometry.CubicSpline2d(points_qe);
            var cubic_spline_qp = new Yw.Geometry.CubicSpline2d(points_qp);
 
            var disp_paras = diagram.DispParas;
            var is_calc_disp_paras = string.IsNullOrWhiteSpace(disp_paras);
            this.xtrPerform2dChart1.SetBindingData(cubic_spline_qh, cubic_spline_qe, cubic_spline_qp, disp_paras, is_calc_disp_paras);
            var temp_q = cubic_spline_qh.MaxX / 2;
            this.xtrPerform2dChart1.CalcWorkPointByQ(temp_q);
            this.xtrPerform2dChart1.CalcActionSpotByQ(temp_q);
        }
 
        //清空图表数据
        private void ClearChart()
        {
            this.xtrPerform2dChart1.InitialChartData();
        }
 
        #endregion 图表
 
        #region 导入
 
        //Excel 导入
        private void barBtnImportByExcel_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var dlg = new Yw.WinFrmUI.Phart.ImportPumpPerform2dByExcelDlg();
            dlg.ReloadDataEvent += async (other_name, qh, qe, qp) =>
            {
                var bol = await Import(other_name, qh, qe, qp);
                return bol;
            };
            dlg.ShowDialog();
        }
 
        //图片 导入
        private void barBtnImportByPicture_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            XtraMessageBox.Show("待补充!");
        }
 
        //单点 导入
        private void barBtnImportByOnePoint_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var dlg = new Yw.WinFrmUI.Phart.ImportPumpPerform2dByOnePointDlg();
            dlg.ReloadDataEvent += async (other_name, qh, qe, qp) =>
            {
                var bol = await Import(other_name, qh, qe, qp);
                return bol;
            };
            dlg.ShowDialog();
        }
 
        // 导入
        private async Task<bool> Import(string other_name, Yw.Pump.CurveQH qh, Yw.Pump.CurveQE qe, Yw.Pump.CurveQP qp)
        {
            if (_pump_main_id < 1)
            {
                XtraMessageBox.Show("PumpMain is null!");
                return false;
            }
 
            var input = new Vmo.XhsPumpMainPhartMappingExtensions();
            input.PumpMainID = _pump_main_id;
            input.Importance = 0;
            input.OtherName = other_name;
            input.Diagram = new Vmo.PhartDiagramExGraphList()
            {
                DiagramType = HStation.PhartRelation.eDiagramType.Feat,
                Name = other_name,
                GraphList = new List<Vmo.PhartGraph>()
                {
                    new ()
                    {
                        Name = other_name+"-QH",
                        GeometryStyle=  HStation.PhartRelation.eGeometryStyle.FeatCurve,
                        GraphType= HStation.PhartRelation.eGraphType.PumpQH,
                        GeometryInfo=qh.ToDbString()
                    },
                    new ()
                    {
                        Name = other_name+"-QE",
                        GeometryStyle= HStation.PhartRelation.eGeometryStyle.FeatCurve,
                        GraphType= HStation.PhartRelation.eGraphType.PumpQE,
                        GeometryInfo=qe.ToDbString()
                    },
                    new ()
                    {
                        Name = other_name+"-QP",
                        GeometryStyle=  HStation.PhartRelation.eGeometryStyle.FeatCurve,
                        GraphType= HStation.PhartRelation.eGraphType.PumpQP,
                        GeometryInfo=qp.ToDbString()
                    },
                }
            };
             
            var mapping_id = await _bll_ex.Insert(input);
            if (mapping_id < 1)
            {
                return false;
            }
            var xhs_phart_diagram_ex_std_dto = await _bll_ex.GetByID(mapping_id);
            this.xhsPumpMainPhartListCtrl1.Add(xhs_phart_diagram_ex_std_dto);
            return true;
        }
 
        #endregion 导入
         
        #region 操作
 
        //编辑
        private void barBtnEditChart_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_xhs_phart_diagram_ex_std_dto == null)
            {
                return;
            }
            var diagram = _xhs_phart_diagram_ex_std_dto.Diagram;
            if (diagram == null)
            {
                return;
            }
            var graph_list = diagram.GraphList;
            if (graph_list == null || !graph_list.Any())
            {
                return;
            }
 
            var graph_qh = graph_list.Find(x => x.GraphType == HStation.PhartRelation.eGraphType.PumpQH);
            var graph_qe = graph_list.Find(x => x.GraphType == HStation.PhartRelation.eGraphType.PumpQE);
            var graph_qp = graph_list.Find(x => x.GraphType == HStation.PhartRelation.eGraphType.PumpQP);
 
            if (graph_qh == null)
            {
                return;
            }
            Yw.Pump.CurveQH qh = null;
            Yw.Pump.CurveQE qe = null;
            Yw.Pump.CurveQP qp = null;
            List<Yw.Geometry.Point2d> points_qh = null, points_qe = null, points_qp = null;
            points_qh = PhartPerformCurveHelper.GetFeatPointList(graph_qh.GraphType, graph_qh.GeometryInfo, 12, null);
            qh = new Yw.Pump.CurveQH(Yw.Pump.eFeatType.Cubic, points_qh);
            if (graph_qe != null)
            {
                points_qe = PhartPerformCurveHelper.GetFeatPointList(graph_qe.GraphType, graph_qe.GeometryInfo, 12, null);
                qe = new Yw.Pump.CurveQE(Yw.Pump.eFeatType.Cubic, points_qe);
            }
            if (graph_qp != null)
            {
                points_qp = PhartPerformCurveHelper.GetFeatPointList(graph_qp.GraphType, graph_qp.GeometryInfo, 12, null);
                qp = new Yw.Pump.CurveQP(Yw.Pump.eFeatType.Cubic, points_qp);
            }
 
            var dlg = new Yw.WinFrmUI.Phart.PumpPerform2dEditDlg();
            dlg.SetBindingData(qh, qe, qp);
            dlg.ReloadDataEvent += async (new_qh, new_qe, new_qp) =>
            {
                var new_points_qh = new_qh.GetPointList();
                var new_points_qe = new_qe.GetPointList();
                var new_points_qp = new_qp.GetPointList();
 
                graph_qh.GeometryInfo = new Yw.Pump.CurveQH(Yw.Pump.eFeatType.Cubic, new_points_qh).ToDbString();
                graph_qe.GeometryInfo = new Yw.Pump.CurveQE(Yw.Pump.eFeatType.Cubic, new_points_qe).ToDbString();
                graph_qp.GeometryInfo = new Yw.Pump.CurveQP(Yw.Pump.eFeatType.Cubic, new_points_qp).ToDbString();
 
                _xhs_phart_diagram_ex_std_dto.Diagram.GraphList = new List<Vmo.PhartGraph>()
                {
                    graph_qh,
                    graph_qe,
                    graph_qp,
                };
                var bol = await _bll_ex.Update(_xhs_phart_diagram_ex_std_dto);
                if (bol)
                {
                    InitChart(_xhs_phart_diagram_ex_std_dto);
                }
                return bol;
            };
            dlg.ShowDialog();
        }
 
        //别名
        private void barBtnOtherName_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_xhs_phart_diagram_ex_std_dto == null)
            {
                return;
            }
            var dlg = new SetOtherNameDlg();
            dlg.SetBindingData(_xhs_phart_diagram_ex_std_dto.OtherName);
            dlg.VerifyValueChanged += async (value) =>
            {
                _xhs_phart_diagram_ex_std_dto.OtherName = value;
                var bol = await _bll_ex.Update(_xhs_phart_diagram_ex_std_dto);
                if (!bol)
                {
                    XtraMessageBox.Show("更新失败!");
                    return false;
                }
                this.xhsPumpMainPhartListCtrl1.UpdateOtherName(_xhs_phart_diagram_ex_std_dto.ID, value);
                XtraMessageBox.Show("更新成功!");
                return true;
            };
 
            dlg.ShowDialog();
        }
 
        //重要度
        private void barBtnUpdateimportance_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var dlg = new SetImportanceDlg();
            dlg.SetBindingData(_xhs_phart_diagram_ex_std_dto.Importance);
            dlg.VerifyValueChanged += async (value) =>
            {
                _xhs_phart_diagram_ex_std_dto.Importance = value;
                var bol = await _bll_ex.Update(_xhs_phart_diagram_ex_std_dto);
                if (!bol)
                {
                    XtraMessageBox.Show("更新失败!");
                    return false;
                }
                this.xhsPumpMainPhartListCtrl1.UpdateImportance(_xhs_phart_diagram_ex_std_dto.ID, value);
                XtraMessageBox.Show("更新成功!");
                return true;
            };
 
            dlg.ShowDialog();
        }
 
        #region 删除
 
        //删除
        private async void barBtnDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            await Delete();
        }
 
        //删除
        private async Task<bool> Delete()
        {
            if (_xhs_phart_diagram_ex_std_dto == null)
            {
                return false;
            }
            var diagramId = _xhs_phart_diagram_ex_std_dto.Diagram.ID;
            var bol = await _bll_ex.DeleteByDiagramID(diagramId);
            if (!bol)
            {
                XtraMessageBox.Show("删除失败!");
                return false;
            }
            XtraMessageBox.Show("删除成功!");
            ClearChart();
            this.xhsPumpMainPhartListCtrl1.Delete(_xhs_phart_diagram_ex_std_dto.ID);
 
            return true;
        }
 
        #endregion 删除
 
        #endregion 操作
 
    }
}