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
using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Windows.Forms;
 
namespace TProduct.WinFrmUI.TestBench
{
    public partial class MgrWorkBenchMainValvePage : DocumentPage
    {
        public MgrWorkBenchMainValvePage()
        {
            InitializeComponent();
 
 
            this.PageTitle.Caption = "测试台信息(阀)";
            this._pageOperateInfo = "测试台信息列表";
            this.gridViewMain.SetNormalEditView(35);
            this.gridViewMain.SetGridMianViewColor();
            this.gridViewMain.RegistCustomDrawRowIndicator();
        }
 
        private class CurrentViewModel : Model.WorkBenchBase
        {
            public CurrentViewModel() { }
            public CurrentViewModel(
                Model.WorkBenchBase work) : base(work)
            {
                Reset(work);
            }
 
            public override void Reset(
                Model.WorkBenchBase work)
            {
                base.Reset(work);
                this.ID = work.ID;
                this.CreateUserID = work.CreateUserID;
                this.CreateTime = work.CreateTime;
                this.UpdateUserID = work.UpdateUserID;
                this.UpdateTime = work.UpdateTime;
                this.Code = work.Code;
                this.Name = work.Name;
                this.ProductStyleID = work.ProductStyleID;
                this.LastUseTime = work.LastUseTime;
                this.LastUseUserID = work.LastUseUserID;
                this.UseStatus = work.UseStatus;
                this.PipeParas = work.PipeParas;
 
                var pipeParas = new Model.PipeParas4Valve(work.PipeParas);
                if (pipeParas != null)
                {
                    if (pipeParas.DiaP1 != null)
                        this.DiaP1 = pipeParas.DiaP1.ToString();
                    if (pipeParas.DiaP2 != null)
                        this.DiaP2 = pipeParas.DiaP2.ToString();
                    if (pipeParas.DiaP3 != null)
                        this.DiaP3 = pipeParas.DiaP3.ToString();
                }
 
                if (work.LinkType == Model.eLinkType.ShunZhou)
                {
                    LinkTypeName = "无线 (SZ)";
                }
                if (work.LinkType == Model.eLinkType.KeDi)
                {
                    LinkTypeName = "有线 (KD)";// string.Format("有线 KD ({0})", work.LinkTag);
                }
            }
 
            public string DiaP1 { get; set; }
            public string DiaP2 { get; set; }
            public string DiaP3 { get; set; }
 
            public string ProductStyleName { get; set; }
            public string LastUseUserName { get; set; }
            public string TestTypeName { get; set; }
            public string LinkTypeName { get; set; }
 
            public void SetProductStyle(IEnumerable<Model.ProductStyle> styles)
            {
                if (styles == null || styles.Count() == 0)
                    this.ProductStyleName = "";
                else
                    this.ProductStyleName = String.Join(",", from x in styles select x.Name);
            }
        }
 
        private List<CurrentViewModel> _bindList = null;
        private List<Model.ProductStyle> _allProductStyle = null;
 
        /// <summary>
        /// 初始化
        /// </summary>
        public override void InitialDataSource()
        {
            WaitFrmHelper.ShowWaitForm();
            _allProductStyle = new BLL.ProductStyle().GetByProductType(Model.eProductType.Valve);
            var works = new BLL.WorkBenchBase().GetByProductType(Model.eProductType.Valve);
            if (works == null)
                works = new List<Model.WorkBenchBase>();
 
            var mans = new BLL.LoginUser().GetAll();
 
            _bindList = new List<CurrentViewModel>();
            foreach (var work in works)
            {
                var v = new CurrentViewModel(work);
                if (work.LastUseUserID > 0)
                    v.LastUseUserName = (from x in mans where x.ID == work.LastUseUserID select x.RealName).FirstOrDefault();
                if (work.ProductStyleID != null)
                {
                    v.SetProductStyle(
                    _allProductStyle.
                    Where(s => work.ProductStyleID.Contains(s.ID)).
                    Select(x => x));
                }
 
                _bindList.Add(v);
            }
            this.bindingSource1.DataSource = _bindList;
            this.bindingSource1.ResetBindings(false);
            WaitFrmHelper.HideWaitForm();
        }
 
        #region 按钮事件
        //添加
        private void barBtnAddPump_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
 
            AddWorkBench();
        }
 
 
        private void AddWorkBench()
        {
            WaitFrmHelper.ShowWaitForm();
            var dlg = new AddWorkBench4ValveDlg();
            dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
            dlg.SetBindingData();
            dlg.ReloadDataEvent += (work) =>
            {
                var vm = new CurrentViewModel(work);
                if (_bindList == null)
                    _bindList = new List<CurrentViewModel>();
                if (work.ProductStyleID != null)
                {
                    vm.SetProductStyle(
    _allProductStyle.
    Where(s => work.ProductStyleID.Contains(s.ID)).
    Select(x => x)
);
                }
                _bindList.Add(vm);
                this.bindingSource1.ResetBindings(false);
 
                XtraMessageBox.Show("添加成功!");
            };
            ShowCmdOperateInfo("添加测试台");
            dlg.ShowDialog();
            ShowCmdOperateInfo(_pageOperateInfo);
        }
 
        //编辑
        private void barBtnEdit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var row = this.gridViewMain.GetCurrentViewModel(_bindList);
            if (row == null)
            {
                XtraMessageBox.Show("未选择数据!");
                ShowCmdOperateInfo("未选择数据!");
                return;
            }
            if (row.ProductType != Model.eProductType.Valve)
            {
                return;
            }
            WaitFrmHelper.ShowWaitForm();
            var dlg = new EditWorkBench4ValveDlg();
            dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
            dlg.SetBindingData(row);
            dlg.ReloadDataEvent += (work) =>
            {
                row.Reset(work);
                if (work.ProductStyleID != null)
                {
                    row.SetProductStyle(
_allProductStyle.
Where(s => work.ProductStyleID.Contains(s.ID)).
Select(x => x)
);
                }
                this.gridViewMain.RefreshData();
                XtraMessageBox.Show("更新成功!");
            };
            ShowCmdOperateInfo("编辑测试台信息");
            dlg.ShowDialog();
            ShowCmdOperateInfo(_pageOperateInfo);
 
        }
 
        //删除
        private void barBtnDel_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var row = this.gridViewMain.GetCurrentViewModel(_bindList);
            if (row == null)
            {
                XtraMessageBox.Show("未选择数据!");
                ShowCmdOperateInfo("未选择数据!");
                return;
            }
            if (row.LastUseTime != null)
            {
                XtraMessageBox.Show("该数据已经被使用,无法删除!");
                ShowCmdOperateInfo("该数据已经被使用,无法删除!");
                return;
            }
            ShowCmdOperateInfo("删除测试台:" + row.Name);
            DialogResult dr = XtraMessageBox.Show("是否删除测试台:" + row.Name, "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
            if (dr != DialogResult.Yes)
            {
                ShowCmdOperateInfo(_pageOperateInfo);
                return;
            }
            WaitFrmHelper.ShowWaitForm();
            var result = new BLL.WorkBenchBase().Delete(row);
            if (result)
            {
                _bindList.Remove(row);
                this.bindingSource1.ResetBindings(false);
                WaitFrmHelper.HideWaitForm();
                XtraMessageBox.Show("删除成功!");
                ShowCmdOperateInfo("删除成功!");
            }
            else
            {
                WaitFrmHelper.HideWaitForm();
                XtraMessageBox.Show("删除失败!");
                ShowCmdOperateInfo("删除失败!");
            }
 
        }
 
        //设置仪器
        private void barButSetInstrument_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var row = this.gridViewMain.GetCurrentViewModel(_bindList);
            if (row == null)
            {
                XtraMessageBox.Show("未选择数据!");
                return;
            }
 
            if (row.LinkType == Model.eLinkType.ShunZhou)
            {
                WaitFrmHelper.ShowWaitForm();
                var dlg = new TProduct.WinFrmUI.TestBench.SetAllInstruments4ShunDlg();
                dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
                dlg.SetBindingData(row);
                ShowCmdOperateInfo("设置仪器");
                dlg.ShowDialog();
                ShowCmdOperateInfo(_pageOperateInfo);
            }
            else if (row.LinkType == Model.eLinkType.KeDi)
            {
                WaitFrmHelper.ShowWaitForm();
 
                    var dlg = new TProduct.WinFrmUI.TestBench.SetAllInstruments4KeDiDlg();
                    dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
                    dlg.SetBindingData(row);
                    ShowCmdOperateInfo("设置仪器");
                    dlg.ShowDialog();
                    ShowCmdOperateInfo(_pageOperateInfo);
                
 
            }
 
        }
 
        //设置测点
        private void barButPoint_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var row = this.gridViewMain.GetCurrentViewModel(_bindList);
            if (row == null)
            {
                XtraMessageBox.Show("未选择数据!");
                ShowCmdOperateInfo("未选择数据!");
                return;
            }
 
            var dlg = new MgrWorkBenchMonitorPointDlg();
            dlg.SetBindingData(row);
            ShowCmdOperateInfo("设置测点");
            dlg.ShowDialog();
            ShowCmdOperateInfo(_pageOperateInfo);
        }
 
        // 刷新
        private void barButReset_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.InitialDataSource();
            MessageBox.Show("已刷新");
            ShowCmdOperateInfo(_pageOperateInfo + ":数据已刷新");
        }
 
        #endregion
 
        private void barBtnCopy_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var row = this.gridViewMain.GetCurrentViewModel(_bindList);
            if (row == null)
            {
                XtraMessageBox.Show("未选择数据!");
                ShowCmdOperateInfo("未选择数据!");
                return;
            }
            ShowCmdOperateInfo("复制测试台:" + row.Name);
            DialogResult dr = XtraMessageBox.Show("是否复制测试台:" + row.Name, "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
            if (dr != DialogResult.Yes)
            {
                ShowCmdOperateInfo(_pageOperateInfo);
                return;
            }
            new BLL.WorkBenchBase().Copy(row);
 
            this.InitialDataSource();
 
            MessageBox.Show("已复制");
            ShowCmdOperateInfo(_pageOperateInfo);
        }
 
        private void barButSetModel3d_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var row = this.gridViewMain.GetCurrentViewModel(_bindList);
            if (row == null)
            {
                XtraMessageBox.Show("未选择数据!");
                return;
            }
            if (row.ProductType != Model.eProductType.Valve)
            {
                return;
            }
 
            WaitFrmHelper.ShowWaitForm();
            var dlg = new EditWorkBench4Mode3dDlg();
            dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
            dlg.SetBindingData(row);
            dlg.ReloadDataEvent += (work) =>
            {
                row.Reset(work);
                this.gridViewMain.RefreshData();
                ShowCmdOperateInfo("更新成功!");
            };
            ShowCmdOperateInfo("编辑测试台信息!");
            dlg.ShowDialog();
            ShowCmdOperateInfo(_pageOperateInfo);
        }
    }
}