tx
2025-04-09 fa7510e1ed63df0366787fa4ed1b3db6426d2b46
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
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Grid;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
 
namespace TProduct.WinFrmUI.Data4Factory
{
    /// <summary>
    /// 泵
    /// </summary>
    public partial class ProductPumpAndPartMgrPage : DocumentPage
    {
        protected Eventech.Model.UnitQ flow_unit = Eventech.Model.UnitQ.M3H;
        public ProductPumpAndPartMgrPage()
        {
            InitializeComponent();
            this.PageTitle.Caption = "泵管理";
            this._pageOperateInfo = "泵列表";
            this.gridView1.SetNormalView();
            this.gridView1.SetGridMianViewColor();
            this.gridView1.RegistCustomDrawRowIndicator();
            this.gridView1.OptionsView.ShowViewCaption = false;
            this.gridView1.OptionsView.ShowDetailButtons = true;
 
            this.gridView2.SetNormalView();
            this.gridView2.SetGridSubViewColor();
            this.gridView1.OptionsView.EnableAppearanceOddRow = true;   // 使能 // 和和上面绑定 同时使用有效
            this.gridView1.Appearance.EvenRow.BackColor = Color.LightGray; // 设置偶数行颜色
            this.gridView1.OptionsView.EnableAppearanceEvenRow = true;
            this.gridView1.Appearance.OddRow.BackColor = Color.White; // 设置偶数行颜色
 
            this.gridView2.OptionsView.EnableAppearanceOddRow = true;   // 使能 // 和和上面绑定 同时使用有效
            this.gridView2.Appearance.EvenRow.BackColor = Color.White; // 设置偶数行颜色
            this.gridView2.OptionsView.EnableAppearanceEvenRow = true;
            this.gridView2.Appearance.OddRow.BackColor = Color.White; // 设置偶数行颜色
 
            this.colSdName.Visible = TProduct.UserSetting.Setting.Disp.IsShowSender;
            this.colMfName.Visible = TProduct.UserSetting.Setting.Disp.IsShowManufacturer;
 
            flow_unit = TProduct.UserSetting.Setting.PumpTest.UnitFlow;
            colQ.Caption = string.Format("流量({0})", Eventech.Common.UnitQHelper.GetEnUnitName(flow_unit));
 
        }
 
        #region 当前视图
 
        public class CurrentViewModel : Model.ProductMainExPump
        {
            Eventech.Model.UnitQ _flow_unit;
            public CurrentViewModel() { }
            public CurrentViewModel(Eventech.Model.UnitQ flow_unit, Model.ProductMainExPump rhs) : base(rhs)
            {
 
                _flow_unit = flow_unit;
            }
 
            public override void Reset(Model.ProductMainExPump rhs)
            {
                base.Reset(rhs);
            }
            #region 泵界面参数
 
            public string strQ
            {
                get
                {
                    var m3h = Model.RatedParas4Pump.ToModel(RatedParas).Q;
                    return m3h > 0 ?
                        Math.Round(Eventech.Common.UnitQHelper.fromM3H(
                            _flow_unit, m3h), 4).ToString() : "";
                }
            }
            public string strH
            {
                get
                {
                    return Model.RatedParas4Pump.ToModel(RatedParas).H > 0 ? Model.RatedParas4Pump.ToModel(RatedParas).H.ToString() : "";
                }
            }
 
            public string strN
            {
                get
                {
                    if (this.Ratedn > -1)
                        return this.Ratedn.ToString();
                    else
                        return "";
                }
            }
            public string strD2
            {
                get
                {
                    if (this.D2 > -1)
                        return this.D2.ToString();
                    else
                        return "";
                }
            }
            public string strPosiAngle
            {
                get
                {
                    if (this.PosiAngle > -1)
                        return this.PosiAngle.ToString();
                    else
                        return "";
                }
            }
 
            public string MainCreateTime
            {
                get
                {
                    var A = DateTime.Compare(this.CreateTime, Convert.ToDateTime("2008-8-8"));
                    if (A > 0)
                    {
                        return this.CreateTime.ToString("yyyy-MM-dd HH:mm");
                    }
                    else
                        return "";
                }
            }
            public string MianUpdateTime
            {
                get
                {
                    var A = DateTime.Compare(this.UpdateTime, Convert.ToDateTime("2008-8-8"));
                    if (A > 0)
                    {
                        return this.UpdateTime.ToString("yyyy-MM-dd HH:mm");
                    }
                    else
                        return "";
                }
            }
            public List<CurrentViewModelSub> CurrentViewModelSubList { get; set; }
 
            public string MotorName { get; set; }
            public string UpadteName { get; set; }
            public string CreateName { get; set; }
            #endregion 
        }
 
        public class CurrentViewModelSub : Model.PartBase
        {
            public CurrentViewModelSub(Model.PartBase rhs) : base(rhs) { }
 
            public override void Reset(Model.PartBase rhs)
            {
                base.Reset(rhs);
            }
            #region 产品界面参数
            public string strLastTestTime
            {
                get
                {
                    if (this.LastTestTime != null)
                    {
                        return this.LastTestTime.Value.ToString("yyyy-MM-dd");
                    }
                    else
                        return "";
                }
            }
            public string PartCreateTime
            {
                get
                {
                    var A = DateTime.Compare(this.CreateTime, Convert.ToDateTime("2008-8-8"));
                    if (A > 0)
                    {
                        return this.CreateTime.ToString("yyyy-MM-dd HH:mm");
                    }
                    else
                        return "";
                }
            }
            public string PartUpdateTime
            {
                get
                {
                    var A = DateTime.Compare(this.UpdateTime, Convert.ToDateTime("2008-8-8"));
                    if (A > 0)
                    {
                        return this.UpdateTime.ToString("yyyy-MM-dd HH:mm");
                    }
                    else
                        return "";
                }
            }
            public string MfName { get; set; }
            public string SdName { get; set; }
            public string LastRealName { get; set; }
            public string UpadteName { get; set; }
            public string CreateName { get; set; }
            #endregion
        }
 
        #endregion
 
        private List<CurrentViewModel> _bindList = null;//所有列表 
        private Model.ProductSeries _series = null;
 
        /// <summary>
        /// 初始化数据
        /// </summary>
        public override void InitialDataSource()
        {
            this.productTypeListCtr.SetBindData(Model.eProductType.Pump);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="SeriesID"></param>
        public void SetBindingData(long SeriesID)
        {
            _bindList = new List<CurrentViewModel>();
            var allPumps = new BLL.ProductPump().GetExBySeriesID(SeriesID);
            if (allPumps == null || allPumps.Count() == 0)
            {
                this.currentViewModelBindingSource.DataSource = _bindList;
                this.currentViewModelBindingSource.ResetBindings(false);
                return;
            }
 
            foreach (var pumpitem in allPumps)
            {
                var vm = new CurrentViewModel(flow_unit, pumpitem);
                BuildViewModel(vm);
                _bindList.Add(vm);
            }
            this.currentViewModelBindingSource.DataSource = _bindList;
            this.currentViewModelBindingSource.ResetBindings(false);
        }
 
        #region 基础功能
 
        //添加
        private void barBtnAdd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_series  == null)
            {
                XtraMessageBox.Show("您必须选择一个设备系列才能进行此项操作");
                ShowCmdOperateInfo("您必须选择一个设备系列才能进行此项操作");
                return;
            }
            if (_bindList == null)
                _bindList = new List<CurrentViewModel>();
            int max_sortCode = 1;
            if (_bindList.Count() > 0)
                max_sortCode = _bindList.Max(x => x.SortCode) + 1;
            WaitFrmHelper.ShowWaitForm();
            var dlg = new AddProductPumpDlg();
            dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
            dlg.SetBindingData(_series, max_sortCode);
 
            dlg.ReloadDataEvent += (pump, motor) =>
            {
                _allPartList = new BLL.PartBase().GetAll();
                _allProductMainList = new BLL.ProductMain().GetAll();
 
                _bindList.Add(BuildViewModel(new CurrentViewModel(flow_unit, pump)));
                ShowCmdOperateInfo("添加成功!");
                XtraMessageBox.Show("添加成功!");
                this.currentViewModelBindingSource.ResetBindings(false);
                this.gridView1.RefreshData();
            };
            ShowCmdOperateInfo("添加泵信息");
            dlg.ShowDialog();
            ShowCmdOperateInfo(_pageOperateInfo);
        }
 
        //编辑
        private void barBtnEdit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_bindList == null || _bindList.Count < 1)
                return;
            var vm = this.gridView1.GetCurrentViewModel(_bindList);
            if (vm == null)
            {
                XtraMessageBox.Show("您必须选择一个泵才能进行此项操作.");
                ShowCmdOperateInfo("您必须选择一个泵才能进行此项操作");
                return;
            }
            WaitFrmHelper.ShowWaitForm();
            var dlg = new EditProductPumpDlg();
            dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
            dlg.SetBindingData(vm);
            dlg.ReloadDataEvent += (pump, isChangePart, motor) =>
            {
                if (isChangePart)
                {
                    _allPartList = new BLL.PartBase().GetAll();
                    _allProductMainList = new BLL.ProductMain().GetAll();
                }
 
                vm.Reset(pump);
 
                BuildViewModel(vm);
                ShowCmdOperateInfo("更新成功!");
                XtraMessageBox.Show("更新成功!");
                this.currentViewModelBindingSource.ResetBindings(false);
                this.gridView1.RefreshData();
            };
            ShowCmdOperateInfo("编辑泵信息");
            dlg.ShowDialog();
            ShowCmdOperateInfo(_pageOperateInfo);
        }
 
 
        //详情
        private void barBtnDictTypeView_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
        }
 
        //删除
        private void barBtnDictTypeDel_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_bindList == null || _bindList.Count < 1)
                return;
            WaitFrmHelper.ShowWaitForm();
            var row = this.gridView1.GetCurrentViewModel(_bindList);
            if (row == null)
            {
                WaitFrmHelper.ShowWaitForm();
                XtraMessageBox.Show("请选择一行数据!");
                ShowCmdOperateInfo("请选择一行数据!");
                return;
            }
 
            ShowCmdOperateInfo("删除数据:" + row.Name);
            DialogResult dr = XtraMessageBox.Show("您确定要删除'" + row.Name + "'这条数据吗?\n(注:如果当前选中设备下仍有产品数据则不能将其删除.)", "删除提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
            if (dr != DialogResult.OK)
            {
                ShowCmdOperateInfo(_pageOperateInfo);
                return;
            }
            var partList = new BLL.PartBase().GetByProductMainID(row.ID);
            if (partList.Count() > 0)
            {
                XtraMessageBox.Show("删除失败,当前选中项下仍有产品数据!");
                ShowCmdOperateInfo("删除失败,当前选中项下仍有产品数据!");
                return;
            }
            if (!new BLL.ProductPump().DeleteEx(row.ID))
            {
                XtraMessageBox.Show("Error:340,删除失败!");
                ShowCmdOperateInfo("Error:340,删除失败!");
                return;
            }
            SetBindingData(this._series.ID);
            XtraMessageBox.Show("删除成功!");
            ShowCmdOperateInfo(_pageOperateInfo);
        }
 
 
        #endregion
 
        #region GridView  
 
        //设备列表
        private GridView SysDataView = new GridView();
 
        private void gridView1_MasterRowExpanded(object sender, CustomMasterRowEventArgs e)
        {
            this.SysDataView = this.gridView1.GetDetailView(e.RowHandle, e.RelationIndex) as GridView;
            this.SysDataView.HorzScrollStep = this.SysDataView.RowCount;
        }
        private void barBtnExcelDown_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ShowCmdOperateInfo("导出信息到Excel");
            var path = ExcelSaveFilePathHelper.SaveFilePathName();
            ShowCmdOperateInfo(_pageOperateInfo);
            if (string.IsNullOrEmpty(path)) return;
            gridView1.OptionsPrint.PrintDetails = true;//导出明细
            gridView1.OptionsPrint.ExpandAllDetails = true;//导出所有明细,false的话,只会导出展开的明细
            gridControl1.ExportToXlsx(path, new DevExpress.XtraPrinting.XlsxExportOptionsEx() { ExportType = DevExpress.Export.ExportType.WYSIWYG, TextExportMode = DevExpress.XtraPrinting.TextExportMode.Text });
            DialogResult dr = XtraMessageBox.Show("导出成功!是否打开刚刚保存的Excel文件?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
            if (dr != DialogResult.OK)
                return;
            System.Diagnostics.Process.Start(path);
        }
 
        #endregion
 
        private void seriesListCtrl_FocusedDataChangedEvent(Model.ProductSeries obj)
        {
            if (obj == null)
                return;
            SetBindingData(obj.ID);
            if (obj.IsInnerMotor == 1)
            {
                colMotorName.Visible = false;
            }
            else
            {
                colMotorName.Visible = true;
            }
            _series = obj ;
        }
        List<Model.Senderbase> _allSenderList = null;
        List<Model.ManufacturerBase> _allManufacturerList = null;
        List<Model.LoginUser> _allUserList = null;
        List<Model.PartBase> _allPartList = null;
        List<Model.ProductMain> _allProductMainList = null;
        private CurrentViewModel BuildViewModel(CurrentViewModel viewmodel)
        {
            if (_allManufacturerList == null)
            {
                _allManufacturerList = new BLL.ManufacturerBase().GetAll();
            }
            if (_allSenderList == null)
            {
                _allSenderList = new BLL.Senderbase().GetAll();
            }
            if (_allUserList == null)
            {
                _allUserList = new BLL.LoginUser().GetAll();
            }
            if (_allPartList == null)
            {
                _allPartList = new BLL.PartBase().GetAll();
            }
            if (_allProductMainList == null)
                _allProductMainList = new BLL.ProductMain().GetAll();
 
            viewmodel.UpadteName = _allUserList.Find(x => x.ID == viewmodel.UpdateUserID)?.RealName;
            viewmodel.CreateName = _allUserList.Find(x => x.ID == viewmodel.UpdateUserID)?.RealName;
 
            if (viewmodel.MotorMainID == null || viewmodel.MotorMainID < 1)
            {
                viewmodel.MotorName = "未设置电机";
            }
            else
            {
                var motor = _allProductMainList.Find(x => x.ID == viewmodel.MotorMainID);
                if (motor == null)
                {
                    viewmodel.MotorName = "电机数据已丢失";
                }
                else
                {
                    viewmodel.MotorName = motor.Name;
                }
            }
 
            var parts = _allPartList.Where(x => x.ProductMainID == viewmodel.ID);
            if (parts != null && parts.Count() > 0)
            {
                viewmodel.CurrentViewModelSubList = new List<CurrentViewModelSub>();
                foreach (var part in parts)
                {
                    var vm_part = new CurrentViewModelSub(part);
                    if (part.ManufacturerID > 0)
                    {
                        var Manufacturer = _allManufacturerList.Find(m => m.ID == part.ManufacturerID);
                        vm_part.MfName = Manufacturer?.ShortName == "" ? Manufacturer?.FullName : Manufacturer?.ShortName;
                    }
                    if (part.SenderID > 0)
                    {
                        var Sender = _allSenderList.Find(s => s.ID == part.SenderID);
                        vm_part.SdName = Sender?.ShortName == "" ? Sender?.FullName : Sender?.ShortName;
                    }
                    if (part.LastTestUserID > 0)
                        vm_part.LastRealName = _allUserList.Find(x => x.ID == part.LastTestUserID)?.RealName;
                    viewmodel.CurrentViewModelSubList.Add(vm_part);
                }
            }
 
            return viewmodel;
        }
 
 
        private void ProductPumpAndPartMgrPage_Load(object sender, EventArgs e)
        {
            //ShowCmdOperateInfo(_pageOperateInfo);
        }
 
        private void bbiImport样本曲线_EXCEL_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var vm = this.gridView1.GetCurrentViewModel(_bindList);
            if (vm == null)
            {
                XtraMessageBox.Show("您必须选择一个泵才能进行此项操作.");
                ShowCmdOperateInfo("您必须选择一个泵才能进行此项操作");
                return;
            }
            SampleCurveByExcelDlg frm = new SampleCurveByExcelDlg();
            frm.SetBindingData(vm.ID);
            frm.ShowDialog();
        }
 
        private void bbiImport样本曲线_IMAGE_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var vm = this.gridView1.GetCurrentViewModel(_bindList);
            if (vm == null)
            {
                XtraMessageBox.Show("您必须选择一个泵才能进行此项操作.");
                ShowCmdOperateInfo("您必须选择一个泵才能进行此项操作");
                return;
            }
            SampleCurveByPictureDlg frm = new SampleCurveByPictureDlg();
            frm.SetBindingData(vm.ID);
            frm.ShowDialog();
        }
 
        private void bbiViewSampleCurve_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var vm = this.gridView1.GetCurrentViewModel(_bindList);
            if (vm == null)
            {
                XtraMessageBox.Show("您必须选择一个泵才能进行此项操作.");
                ShowCmdOperateInfo("您必须选择一个泵才能进行此项操作");
                return;
            }
            var model = new BLL.PumpSampleCurve().GetDefaultByPumpID(vm.ID);
            if (model == null)
            {
                XtraMessageBox.Show("当前泵未定义样本曲线.");
                return;
            }
            ViewSampleCurveDlg frm = new ViewSampleCurveDlg();
            frm.SetBindingData(model);
            frm.ShowDialog();
 
        }
    }
}