tx
2025-04-10 2538101febc78f525945da72c7cdcb2589f9e6ea
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
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.TValve
{
    public partial class GridFeatMonitorRecordCtrl : UserControl
    {
        public GridFeatMonitorRecordCtrl()
        {
            InitializeComponent();
 
            this.gridViewMain.OptionsDetail.ShowDetailTabs = false;//不显示TAB名
            this.gridViewMain.OptionsView.ShowGroupPanel = false;//隐藏最上面的GroupPanel
            this.gridViewMain.OptionsSelection.MultiSelect = false;//单选
            this.gridViewMain.OptionsBehavior.Editable = false;//只读
            this.gridViewMain.BestFitColumns();
 
            this.gridViewMain.IndicatorWidth = 40;
            this.gridViewMain.RowHeight = 35;
 
            this.gridViewMain.OptionsView.EnableAppearanceEvenRow = true;
            this.gridViewMain.OptionsView.EnableAppearanceOddRow = true;
            this.gridViewMain.Appearance.OddRow.BackColor = Color.AliceBlue;
            this.gridViewMain.Appearance.EvenRow.BackColor = Color.White;
 
            this.gridViewMain.RowClick += new DevExpress.XtraGrid.Views.Grid.RowClickEventHandler(this.GridViewMain_RowClick);
            this.gridViewMain.CustomDrawRowIndicator += new DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventHandler(this.GridViewMain_CustomDrawRowIndicator);
            this.gridViewMain.CustomUnboundColumnData += new DevExpress.XtraGrid.Views.Base.CustomColumnDataEventHandler(this.GridViewMain_CustomUnboundColumnData);
            //this.gridViewMain.DoubleClick += new System.EventHandler(this.GridViewMain_DoubleClick);
            this.gridViewMain.RowCellClick += new DevExpress.XtraGrid.Views.Grid.RowCellClickEventHandler(this.GridViewMain_RowCellClick);
 
 
            flow_unit = TProduct.UserSetting.Setting.ValveTest.UnitFlow;
            press_unit = TProduct.UserSetting.Setting.ValveTest.UnitPress;
        }
        Eventech.Model.UnitP power_unit = Eventech.Model.UnitP.KW;
        Eventech.Model.UnitQ flow_unit = Eventech.Model.UnitQ.M3H;
        Eventech.Model.UnitH press_unit = Eventech.Model.UnitH.MPa;
 
        public Action<TProduct.Model.ValveFeatTestRecordViewModel> OnEditRecord = null;
        public Action<TProduct.Model.ValveFeatTestRecordViewModel> OnDeleteRecord = null;
        public Action OnAddRecordManu = null;
 
        private DataTable _recordTable = null;
        private List<TProduct.Model.WorkBenchMonitorPoint> _allMonitorList = null;
        /// <summary>
        /// 设置
        /// </summary>
        /// <param name="seriesEntity"></param>
        /// <param name="pumpEntitys"></param>
        /// <returns></returns>
        public bool SetBindingData(List<TProduct.Model.WorkBenchMonitorPoint> allMonitorList)
        {
            if (allMonitorList == null || allMonitorList.Count() == 0)
                return false;
            this._allMonitorList = allMonitorList;
 
            _recordTable = new DataTable("RecordTable");
            _recordTable.Columns.Add("ID", typeof(long));
            _recordTable.Columns.Add("RecordTime", typeof(string));
            _recordTable.Columns.Add("Degree", typeof(double));
            _recordTable.Columns.Add("Density", typeof(double));
            _recordTable.Columns.Add("Flow", typeof(double));
            _recordTable.Columns.Add("Viscosity", typeof(double));
            _recordTable.Columns.Add("P1", typeof(double));
            _recordTable.Columns.Add("P2", typeof(double));
            _recordTable.Columns.Add("P3", typeof(double));
 
            _recordTable.Columns.Add("V", typeof(double));
            _recordTable.Columns.Add("Re", typeof(double));
            _recordTable.Columns.Add("DeltaP", typeof(double));
            _recordTable.Columns.Add("Kv", typeof(double));
            _recordTable.Columns.Add("Rc", typeof(double));
 
            #region 设置GridView列
 
 
            //DevExpress.XtraGrid.Views.BandedGrid.GridBand gridBandMonitor;
            //gridBandMonitor = new DevExpress.XtraGrid.Views.BandedGrid.GridBand();
 
            //gridBandMonitor.AppearanceHeader.Options.UseTextOptions = true;
            //gridBandMonitor.AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
            //gridBandMonitor.Caption = "原始数据";
 
            //gridBandMonitor.Name = "gridBandMmonitor";
            //gridBandMonitor.VisibleIndex = 1;
            //gridBandMonitor.Width = 150;
 
            for (int i = this.gridBandMonitor.Columns.Count - 1; i >= 0; i--)
            {
                var col = this.gridBandMonitor.Columns[i];
                this.gridBandMonitor.Columns.Remove(col);
                this.gridViewMain.Columns.Remove(col);
            }
            foreach (var p in allMonitorList)
            {
                DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn grid_col;
                grid_col = new DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn();
                grid_col.AppearanceHeader.Options.UseTextOptions = true;
                grid_col.AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
                grid_col.AppearanceCell.Options.UseTextOptions = true;
                grid_col.AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
                if (p.MonitorType == Model.eMonitorType.功率)
                {
                    grid_col.Caption = string.Format("{0}({1})", p.Name,
                      Eventech.Common.UnitPHelper.GetEnUnitName(power_unit));
                }
                else if (p.MonitorType == Model.eMonitorType.流量)
                {
                    grid_col.Caption = string.Format("{0}({1})", p.Name,
                      Eventech.Common.UnitQHelper.GetEnUnitName(flow_unit));
                }
                else if (p.MonitorType == Model.eMonitorType.压力)
                {
                    grid_col.Caption = string.Format("{0}({1})", p.Name,
                      Eventech.Common.UnitHHelper.GetEnUnitName(press_unit));
                }
                else
                {
                    grid_col.Caption = p.Name;
                }
                grid_col.Name = "bandedGridColumn" + p.ID;
                grid_col.Visible = true;
                grid_col.FieldName = string.Format("M{0}", p.ID);
                gridBandMonitor.Columns.Add(grid_col);
                this.gridViewMain.Columns.Add(grid_col);
 
                _recordTable.Columns.Add(string.Format("M{0}", p.ID), typeof(string));
            }
 
 
            #endregion
 
 
            this.bindingSource1.DataSource = _recordTable;
 
            return true;
        }
 
        // 清空数据
        public bool ClearData()
        {
            _recordTable.Clear();
 
            this.bindingSource1.DataSource = _recordTable;
            this.bindingSource1.ResetBindings(false);
            return true;
        }
 
        public void ExportExcel()
        {
            SaveFileDialog dlg = new SaveFileDialog();
            dlg.Title = "记录数据列表";
            dlg.FileName = "记录数据列表.xls";
            dlg.Filter = "excel文件 (*.xls)|*.xls";
            if (dlg.ShowDialog() == DialogResult.OK)
                this.gridControl1.ExportToXls(dlg.FileName);
        }
        List<TProduct.Model.ValveFeatTestRecordViewModel> _allRecords = null;
        //刷新数据源       
        public bool RefreshData(List<TProduct.Model.ValveFeatTestRecordViewModel> allRecords)
        {
            this._allRecords = allRecords;
            _recordTable.Clear();
            if (allRecords == null || allRecords.Count == 0)
            {
                return true;
            }
 
            var rowTemplate = _recordTable.NewRow();
            foreach (TProduct.Model.ValveFeatTestRecordViewModel record in allRecords)
            {
                var rowGrid = _recordTable.NewRow();
                rowGrid.ItemArray = rowTemplate.ItemArray;
                rowGrid["ID"] = record.ID;
                rowGrid["RecordTime"] = record.Time.ToString("yyyy-MM-dd HH:mm:ss");
 
                rowGrid["Degree"] = record.Degree;
                rowGrid["Density"] = record.Density;
                rowGrid["Viscosity"] = record.Viscosity;
 
                rowGrid["Flow"] = Eventech.Common.UnitQHelper.fromM3H(flow_unit, record.Flow);
                rowGrid["P1"] = Eventech.Common.UnitHHelper.fromMPa(press_unit, record.P1);
                rowGrid["P2"] = Eventech.Common.UnitHHelper.fromMPa(press_unit, record.P2);
                rowGrid["P3"] = Eventech.Common.UnitHHelper.fromMPa(press_unit, record.P3);
                rowGrid["DeltaP"] = Eventech.Common.UnitHHelper.fromMPa(press_unit, record.DeltaP);
 
                rowGrid["V"] = record.V;
                rowGrid["Re"] = record.Re;
                rowGrid["Kv"] = record.Kv;
                rowGrid["Rc"] = record.Rc;
 
                foreach (var p in this._allMonitorList)
                {
                    var col = string.Format("M{0}", p.ID);
                    var r = record.MonitorRecordList.Find(x => x.ID == p.ID);
                    if (r != null)
                    {
                        if (string.IsNullOrEmpty(r.Value))
                        {
                            rowGrid[col] = "";
                            continue;
                        }
                        if (p.MonitorType == Model.eMonitorType.功率)
                        {
                            rowGrid[col] = Eventech.Common.UnitPHelper.fromKW(
                        power_unit, Convert.ToDouble(r.Value)).ToString();
                        }
                        else if (p.MonitorType == Model.eMonitorType.流量)
                        {
                            rowGrid[col] = Eventech.Common.UnitQHelper.fromM3H(
                                flow_unit, Convert.ToDouble(r.Value)).ToString();
                        }
                        else if (p.MonitorType == Model.eMonitorType.压力)
                        {
                            rowGrid[col] = Eventech.Common.UnitHHelper.fromMPa(
                                press_unit, Convert.ToDouble(r.Value)).ToString();
                        }
                        else
                        {
                            rowGrid[col] = r.Value;
                        }
                    }
                }
 
                _recordTable.Rows.Add(rowGrid);
            }
 
            this.bindingSource1.DataSource = _recordTable;
            this.bindingSource1.ResetBindings(false);
            return true;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public long GetFocusRowRecordID()
        {
            var row = (this.gridViewMain.GetRow(gridViewMain.GetFocusedDataSourceRowIndex()) as
                System.Data.DataRowView).Row;
            if (row == null)
                return 0;
            return Convert.ToInt64(row["ID"]);
        }
        #region GridViewMain
        // TProduct.Model.ValveFeatTestRecordViewModel _clickProjectRow = null;
        private void GridViewMain_RowClick(object sender, RowClickEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                // _clickProjectRow = gridViewMain.GetRow(e.RowHandle) as TProduct.Model.ValveFeatTestRecordViewModel;
                //_rightClickProject = (gridViewMain.GetRow(e.RowHandle) as System.Data.DataRowView).Row as TProduct.WinFrmUI.Sale.DataSetUI.SaleProjectRow;
                // _rightClickProject = gridViewMain.GetFocusedDataRow() as TProduct.WinFrmUI.Sale.DataSetUI.SaleProjectRow;
                //if (_clickProjectRow != null)
                //{
                //    if (_clickProjectRow.ProjectStyle == 1)
                //    { //简易项目 
                //        MenuItem转为简易项目.Visible = false; 
                //    }
                //    else
                //    {
                //        MenuItem转为简易项目.Visible = true ; 
                //    }
 
                //    GidViewMenuStrip.Show(gridControl1, e.Location);
                //}
            }
        }
 
        //
        private void GridViewMain_DoubleClick(object sender, EventArgs e)
        {
            //var view = sender as GridView;
            //if (view != null)
            //{
            //    var point = view.GridControl.PointToClient(MousePosition);
            //    var pumpStr = view.CalcHitInfo(point);
            //    if (pumpStr.InRow || pumpStr.InRowCell)
            //    {
            //       // _clickPrjItem = gridViewAttach.GetRow(pumpStr.RowHandle) as MotorInfoExCatalogName;
            //       //// _clickPrjItem = (gridViewAttach.GetRow(pumpStr.RowHandle) as System.Data.DataRowView).Row as DAL.DataSetCustomer.CustomerVipInfoRow;
            //       // if (_clickPrjItem != null)
            //       // {
            //       //     if (_clickPrjItem.RecordGID == Guid.Empty)
            //       //         return;
            //       // }
            //    }
            //}
        }
 
 
        private void GridViewMain_RowCellClick(object sender, RowCellClickEventArgs e)
        {
            //if (e.Column == colDelete)
            //{
            //    var prjEntity =
            //       this.gridViewMain.GetRow(e.RowHandle) as TProduct.Model.ValveFeatTestRecordViewModel;
 
            //    OnDeleteRecord(prjEntity);
            //}
            //if (e.Column == colEdit)
            //{
            //    var prjEntity =
            //       this.gridViewMain.GetRow(e.RowHandle) as TProduct.Model.ValveFeatTestRecordViewModel;
 
            //    OnEditRecord(prjEntity);
            //}
        }
 
 
        private void GridViewMain_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e)
        {
            if (e.Info.IsRowIndicator && e.RowHandle >= 0)
            {
                e.Info.DisplayText = (e.RowHandle + 1).ToString();
            }
        }
 
        private void GridViewMain_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
        {
            //if (e.Column == colCreateTime)
            //{
            //    var prj = e.Row as TProduct.Model.SaleProject;
            //    if (prj == null)
            //        return;
 
            //    e.Value = prj.GetCreateTime();
            //}
 
 
        }
        #endregion
 
        private void bbi手动输入记录_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (this.OnAddRecordManu != null)
            {
                this.OnAddRecordManu.Invoke();
            }
        }
 
        private void bbiEditRecord_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var row = gridViewMain.GetFocusedDataRow();
            if (row == null)
                return;
            var record_id = Convert.ToInt64(row["ID"]);
            var record = this._allRecords.Find(x => x.ID == record_id);
            if (record != null && OnEditRecord != null)
            {
                OnEditRecord(record);
            }
        }
 
        private void bbiDeleteRecord_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var row = gridViewMain.GetFocusedDataRow();
            if (row == null)
                return;
            var record_id = Convert.ToInt64(row["ID"]);
            var record = this._allRecords.Find(x => x.ID == record_id);
            if (record != null && OnDeleteRecord != null)
            {
                OnDeleteRecord(record);
            }
        }
 
        private void bbiExportExcel_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ExportExcel();
        }
        public Action OnEmptyAllRecord = null;
        private void bbi清空所有数据_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (OnEmptyAllRecord == null)
                return;
            OnEmptyAllRecord.Invoke();
        }
    }
}