lixiaojun
2024-10-23 5dac45fe6402027f1a19f331045c811c9e96b729
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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
using DevExpress.XtraBars;
using HStation.WinFrmUI.PhartRelation;
using Yw.WinFrmUI.Phart;
 
namespace HStation.WinFrmUI
{
    public partial class PumpFullInfoViewDlg : XtraForm
    {
        #region 构造
 
        public PumpFullInfoViewDlg()
        {
            InitializeComponent();
            this._isMaxWindowStatus = true;//最大化窗体覆盖任务栏
            this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.OnFrmClosing);
            this.Load += new System.EventHandler(this.OnFrmLoad);
            this.Shown += new System.EventHandler(this.OnFrmShown);
            this.bbi下载BIM文件.Visibility = BarItemVisibility.Never;
            this.bsiPromptInfo.Caption = "";
            this.bsiPromptInfo.Caption = "";
        }
 
        private Vmo.XhsPumpMainPhartMappingExtensions _xhs_phart_diagram_ex_std_dto = null;
        private readonly BLL.XhsPumpMainPhartMappingExtensions _bll_ex = new();
 
        private bool _isMaxWindowStatus = true;//最大化窗体覆盖任务栏
        private PumpFullInfoCtrl thePumpCtrl = null;
 
        private void OnFrmLoad(object sender, EventArgs e)
        {
            //手机页面
            navBtn手机页面.Visible = false;
            LocationDialog();
            SetNavTileControlMoveAble();
            this.SetMaxWindowStatus();
        }
 
        private PumpMatchingViewModel _pumpMatchingView;
 
        public event Action<PumpMatchingViewModel> ReloadDataEvent;
 
        private long _PumpId;
 
        public async void SetBindindData(PumpMatchingViewModel pumpMatchingViewModel)
        {
            _pumpMatchingView = pumpMatchingViewModel;
            this.navBtnTitle.Caption = $"泵型号:{pumpMatchingViewModel.ModelType}";
            pumpFullInfoCtrl1.SetBindingData(pumpMatchingViewModel);
            if (long.TryParse(pumpMatchingViewModel.DbId, out long pumpId))
            {
                _PumpId = pumpId;
            }
            var list = await _bll_ex.GetByPumpMainID(_PumpId);
            if (list != null && list.Any())
            {
                //list= list.OrderBy(x => x.Importance).ToList();
                /*      foreach (var item in list)
                      {
                          var vm = new CurrentViewModel(item);
                          _allBindingList.Add(vm);
                      }*/
                _xhs_phart_diagram_ex_std_dto = list.First();
            }
        }
 
        private void OnFrmShown(object sender, EventArgs e)
        {
        }
 
        private void OnFrmClosing(object sender, FormClosingEventArgs e)
        {
        }
 
        private void LocationDialog()
        {
        }
 
        #endregion 构造
 
        #region 按钮显示设置
 
        //窗体尺寸:注意默认是不显示的
        public void IsDispBtn窗体尺寸(bool isDisp)
        {
            navBtnMin.Visible = navBtnbutton9.Visible = navBtnbutton10.Visible = isDisp;
            //设置tileNav可移动
            if (isDisp == true)
                SetNavTileControlMoveAble();
        }
 
        //设置界面可移动
        protected void SetNavTileControlMoveAble()
        {
            this.tileNavPaneTop.OptionsPrimaryDropDown.CloseOnOuterClick = DevExpress.Utils.DefaultBoolean.False;
            this.tileNavPaneTop.MouseDown += new System.Windows.Forms.MouseEventHandler(this.tileNavPane_MouseDown);
            this.tileNavPaneTop.MouseMove += new System.Windows.Forms.MouseEventHandler(this.tileNavPane_MouseMove);
            this.tileNavPaneTop.MouseUp += new System.Windows.Forms.MouseEventHandler(this.tileNavPane_MouseUp);
            this.tileNavPaneTop.DoubleClick += new System.EventHandler(this.tileNavPane_DoubleClick);
        }
 
        #endregion 按钮显示设置
 
        private void navBtn导出_ElementClick(object sender, DevExpress.XtraBars.Navigation.NavElementEventArgs e)
        {
            this.popupMenu1.ShowPopup(MousePosition);
        }
 
        #region 最大最小按钮操作
 
        private void tileNavPane1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
            }
        }
 
        private void navBtnClose_ElementClick(object sender, DevExpress.XtraBars.Navigation.NavElementEventArgs e)
        {
            this.Close();
        }
 
        private void navBtnSize_ElementClick(object sender, DevExpress.XtraBars.Navigation.NavElementEventArgs e)
        {
            if (_isMaxWindowStatus)
            {
                this.SetNormalWindowStatus();
            }
            else
            {
                this.SetMaxWindowStatus();
            }
        }
 
        private void navBtnMin_ElementClick(object sender, DevExpress.XtraBars.Navigation.NavElementEventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }
 
        //设置窗体最大化,全屏
        private void SetMaxWindowStatus()
        {
            this.WindowState = FormWindowState.Maximized;
            this.navBtnbutton9.Glyph = HStation.WinFrmUI.Xhs.Core.Properties.Resources.SizeNormal32;
            (this.navBtnbutton9.SuperTip.Items[0] as DevExpress.Utils.ToolTipItem).Text = "向下还原";
            this._isMaxWindowStatus = true;//最大化窗体状态
            this.Location = new Point(0, 0);
            //Rectangle rect = System.Windows.Forms.SystemInformation.VirtualScreen;
            //this.Size = new System.Drawing.Size(rect.Width, rect.Height - 35);
            this.Size = new System.Drawing.Size(System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width, System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height);
        }
 
        //设置窗体(小窗)
        private void SetNormalWindowStatus()
        {
            this.WindowState = FormWindowState.Normal;
            this.navBtnbutton9.Glyph = HStation.WinFrmUI.Xhs.Core.Properties.Resources.Square32;
            (this.navBtnbutton9.SuperTip.Items[0] as DevExpress.Utils.ToolTipItem).Text = "最大化";
            this._isMaxWindowStatus = false;
            var sq_width = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width / 8;
            var sq_height = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height / 8;
            this.Location = new Point(sq_width, sq_height);
            this.Size = new System.Drawing.Size(sq_width * 6, sq_height * 6);
            //this.Location = new Point(0, 0);
            //this.Size = new System.Drawing.Size(900,600);//rect.Width/2, rect.Height/2);
        }
 
        #endregion 最大最小按钮操作
 
        #region 鼠标操作
 
        private static Point downPosition;   //记录鼠标按下时的坐标
        private bool isMouseDown = false;                   //判断鼠标是状态 True:按下 False:抬起
 
        private void tileNavPane_MouseDown(object sender, MouseEventArgs e)
        {
            if (this._isMaxWindowStatus)
                return;
            downPosition = new Point(e.X, e.Y);
            isMouseDown = true;
        }
 
        private void tileNavPane_MouseMove(object sender, MouseEventArgs e)
        {
            if (isMouseDown && e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                if (this._isMaxWindowStatus)
                    return;   //此处还需要更多的考虑,这一句是为了当窗体最大化时拖拽标题栏可以切换到Normal状态,但是效果不是很理想
                Point currentPosition = Control.MousePosition;
                currentPosition.Offset(-downPosition.X, -downPosition.Y);
                this.Location = currentPosition;
            }
        }
 
        private void tileNavPane_MouseUp(object sender, MouseEventArgs e)
        {
            isMouseDown = false;
        }
 
        private void tileNavPane_DoubleClick(object sender, EventArgs e)
        {
            if (_isMaxWindowStatus)
            {
                this.SetNormalWindowStatus();
            }
            else
            {
                this.SetMaxWindowStatus();
            }
        }
 
        #endregion 鼠标操作
 
        #region 可拖动缩放
 
        private const int WM_NCHITTEST = 0x0084;
        private const int HTLEFT = 10;    //左边界
        private const int HTRIGHT = 11;   //右边界
        private const int HTTOP = 12; //上边界
        private const int HTTOPLEFT = 13; //左上角
        private const int HTTOPRIGHT = 14;    //右上角
        private const int HTBOTTOM = 15;  //下边界
        private const int HTBOTTOMLEFT = 0x10;    //左下角
        private const int HTBOTTOMRIGHT = 17; //右下角
 
        protected override void WndProc(ref System.Windows.Forms.Message m)
        {
            base.WndProc(ref m);
            switch (m.Msg)
            {
                case WM_NCHITTEST:
                    {
                        Point vPoint = new Point((int)m.LParam & 0xFFFF, (int)m.LParam >> 16 & 0xFFFF);
                        vPoint = PointToClient(vPoint);
                        //判断:仅当当前窗体状态不是最大化时,相关鼠标事件生效
                        if (!this._isMaxWindowStatus)
                        {
                            if (vPoint.X < 10)
                            {
                                if (vPoint.Y < 10)
                                {
                                    m.Result = (IntPtr)HTTOPLEFT;
                                }
                                else if (vPoint.Y > this.Height - 10)
                                {
                                    m.Result = (IntPtr)HTBOTTOMLEFT;
                                }
                                else
                                {
                                    m.Result = (IntPtr)HTLEFT;
                                }
                            }
                            else if (vPoint.X > this.Width - 10)
                            {
                                if (vPoint.Y < 10)
                                {
                                    m.Result = (IntPtr)HTTOPRIGHT;
                                }
                                else if (vPoint.Y > this.Height - 10)
                                {
                                    m.Result = (IntPtr)HTBOTTOMRIGHT;
                                }
                                else
                                {
                                    m.Result = (IntPtr)HTRIGHT;
                                }
                            }
                            else if (10 < vPoint.X && vPoint.X < this.Width - 10)
                            {
                                if (vPoint.Y < 10)
                                {
                                    m.Result = (IntPtr)HTTOP;
                                }
                                else if (vPoint.Y > this.Height - 10)
                                {
                                    m.Result = (IntPtr)HTBOTTOM;
                                }
                            }
                        }
                        break;
                    }
            }
        }
 
        #endregion 可拖动缩放
 
        #region 功能点击事件
 
        private void navButton询价_ElementClick(object sender, DevExpress.XtraBars.Navigation.NavElementEventArgs e)
        {
        }
 
        private void bsiWindowInfo_ElementClick(object sender, DevExpress.XtraBars.Navigation.NavElementEventArgs e)
        {
        }
 
        private void navBtnTitle_ElementClick(object sender, DevExpress.XtraBars.Navigation.NavElementEventArgs e)
        {
            this.popupMenu2.ShowPopup(MousePosition);
        }
 
        private void bbi复制泵型号文字_ItemClick(object sender, ItemClickEventArgs e)
        {
        }
 
        private void ShowTipInfo(int delay_time, string info)
        {
            var alertControl1 = new DevExpress.XtraBars.Alerter.AlertControl();
            alertControl1.AutoFormDelay = delay_time;//毫秒
            alertControl1.AutoHeight = false;
            alertControl1.AllowHtmlText = true;
            alertControl1.Show(this, "tip", info);
        }
 
        #endregion 功能点击事件
 
        public static event Action<PumpFullInfoCtrl> JumpPumpFullInfoCtrl;
 
        //停靠
        private void navBtnDock_ElementClick(object sender, DevExpress.XtraBars.Navigation.NavElementEventArgs e)
        {
            this.Close();
            JumpPumpFullInfoCtrl.Invoke(this.pumpFullInfoCtrl1);
        }
 
        private void navBtnEdit_ElementClick(object sender, DevExpress.XtraBars.Navigation.NavElementEventArgs e)
        {
            this.popupMenuEdit.ShowPopup(MousePosition);
        }
 
        //表格编辑
        private void BarButtonItem1_ItemClick(object sender, 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 BarBtnEditProp_ItemClick(object sender, ItemClickEventArgs e)
        {
            var dlg = new EditPumpPartPropDlg();
            dlg.SetBindingData(PumpPropViewCtrl.GetPumpMainVmo());
            dlg.ShowDialog();
            this.pumpFullInfoCtrl1.RefreshPropData();
        }
 
        //泵型号重新匹配
        private void BarBtnRefreshMatching_ItemClick(object sender, ItemClickEventArgs e)
        {
            var dlg = new PumpSingleMatchingDlg();
            dlg.SetBindingData(_pumpMatchingView);
            dlg.ReloadDataEvent += (matching) =>
            {
                _pumpMatchingView = matching;
                ReloadDataEvent.Invoke(_pumpMatchingView);
                this.SetBindindData(_pumpMatchingView);
            };
            dlg.ShowDialog();
        }
 
        //单点编辑
        private void BarButtonItemOnePoint_ItemClick(object sender, 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 void BarButtonItemEdit_ItemClick(object sender, 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,
                };
                Yw.Geometry.Point2d point2D = new Yw.Geometry.Point2d();
                var bol = await _bll_ex.Update(_xhs_phart_diagram_ex_std_dto);
                if (bol)
                {
                }
                return bol;
            };
            dlg.ShowDialog();
        }
 
        //图片编辑
        private void BarButtonItemPicture_ItemClick(object sender, ItemClickEventArgs e)
        {
        }
 
        // 导入
        private async Task<bool> Import(string other_name, Yw.Pump.CurveQH qh, Yw.Pump.CurveQE qe, Yw.Pump.CurveQP qp)
        {
            if (_PumpId < 1)
            {
                XtraMessageBox.Show("PumpMain is null!");
                return false;
            }
 
            var input = new Vmo.XhsPumpMainPhartMappingExtensions();
            input.PumpMainID = _PumpId;
            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);
            return true;
        }
    }
}