tx
8 天以前 e0b138b3e057de6f57021e6c8963868f5c5acc5a
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
using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.Linq;
 
namespace TProduct.WinFrmUI.Data4Factory
{
    public partial class SelectPumpComboxContentCtrl : DevExpress.XtraEditors.XtraUserControl
    {
        protected Eventech.Model.UnitQ flow_unit = Eventech.Model.UnitQ.M3H;
        public SelectPumpComboxContentCtrl()
        {
            InitializeComponent();
 
            this.layoutControl1.SetupLayoutControl();
 
            this.gridViewMain.SetNormalView(30);
            this.gridViewMain.SetGridMianViewColor();
            this.gridViewMain.RegistCustomDrawRowIndicator();
            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.PumpTest.UnitFlow;
            colQ.Caption = string.Format("流量({0})", Eventech.Common.UnitQHelper.GetEnUnitName(flow_unit));
 
        }
 
 
 
        public event Action<Model.ProductMainExPump> FocusedDataChangedEvent = null;
        public event Action<Model.ProductMainExPump> AddDataChanedEvent = null;
        public event Action<Model.ProductMainExPump> EditDataChanedEvent = null;
 
        private List<CurrentViewModel> _bindList = null; 
        private Model.ProductSeries _series = null;
 
        public class CurrentViewModel : Model.ProductMainExPump
        {
            public CurrentViewModel() { }
            public CurrentViewModel(Eventech.Model.UnitQ flow_unit, Model.ProductMainExPump rhs) : base(rhs)
            {
                var pumpparas = Model.RatedParas4Pump.ToModel(rhs.RatedParas);
                this.Q = pumpparas.Q > 0 ? Math.Round(Eventech.Common.UnitQHelper.fromM3H(
                            flow_unit, pumpparas.Q), 4).ToString() : "";
                //pumpparas.Q.ToString():"";
                this.H = pumpparas.H > 0 ? pumpparas.H.ToString() : "";
                this.N = rhs.Ratedn > 0 ? rhs.Ratedn.ToString() : "";
            }
            public string Q { get; set; }
            public string H { get; set; }
            public string N { get; set; }
        }
        public Model.ProductMainExPump SetBindingData4Series(Model.ProductSeries Series , long ProductID)
        {
            if (Series == null)
                return null;
            _series = Series;
            var productPumpList = new BLL.ProductPump().GetExBySeriesID(Series.ID);
            if (productPumpList == null || productPumpList.Count < 1)
            {
                return null;
            }
            _bindList = new List<CurrentViewModel>();
            productPumpList.ForEach(x => _bindList.Add(new CurrentViewModel(flow_unit, x)));
 
            this.bindingSource1.DataSource = _bindList;
            this.bindingSource1.ResetBindings(false);
 
 
            Model.ProductMainExPump find = null;
            if (ProductID > 0)
            {
                find = this._bindList.Find(x => x.ID == ProductID);
            }
            if (find == null)
                find = _bindList.First();
 
            SetFocusedData(find);
 
 
 
            this.FocusedDataChangedEvent?.Invoke(find);
 
 
            return find;
        }
 
 
        public void SetReadOnly()
        {
            this.barButAdd.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
            this.barButEdit.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
        }
 
        /// <summary>
        /// 初始化并设置默认值
        /// </summary>
        /// <param name="sel"></param>
        public bool SetFocusedData(Model.ProductMainExPump sel)
        {
            if (sel == null) { return false; }
            var find_index = this._bindList.FindIndex(x => x.ID == sel.ID);
            this.gridViewMain.SelectRow(find_index);
 
            this.gridViewMain.FocusedRowHandle = find_index;
            return true;
        }
        private void barButCopy_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_series == null)
                return;
            var row = this.gridViewMain.GetCurrentViewModel(_bindList);
            if (row == null)
            {
                XtraMessageBox.Show("请选择一行数据!");
                return;
            }
 
            WaitFrmHelper.ShowWaitForm();
            var dlg = new AddProductPumpDlg();
            dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
            dlg.SetBindingData(_series, row);
            dlg.ReloadDataEvent += (pump, motor) =>
            {
                if (_bindList == null)
                    _bindList = new List<CurrentViewModel>();
 
                _bindList.Add(new CurrentViewModel(flow_unit, pump));
                this.bindingSource1.ResetBindings(false);
                this.AddDataChanedEvent?.Invoke(pump);
                this.FocusedDataChangedEvent?.Invoke(pump);
                XtraMessageBox.Show("添加成功!");
                _isChangeList = true;
            };
            dlg.ShowDialog();
        }
        private void barButAdd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Add();
        }
 
        private void barButEdit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var row = this.gridViewMain.GetCurrentViewModel(_bindList);
            if (row == null)
            {
                XtraMessageBox.Show("请选择一行数据!");
                return;
            }
            WaitFrmHelper.ShowWaitForm();
            var dlg = new EditProductPumpDlg();
            dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
            dlg.SetBindingData(row,0);
            dlg.ReloadDataEvent += (isChangePart, pump, motor, part) =>
            {
                row.Reset(pump);
                this.bindingSource1.ResetBindings(false);
                EditDataChanedEvent?.Invoke(pump);
                XtraMessageBox.Show("修改成功!");
                _isChangeList = true;
            };
            dlg.ShowDialog();
        }
 
        private void barButSearch_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.gridViewMain.OptionsFind.AlwaysVisible = this.barCkSelect.Checked;
        }
 
        private bool _isChangeList = false;//是否修改了数组成员
 
        public bool IsChangeList { get => _isChangeList; set => _isChangeList = value; }
 
 
 
 
        private void Add()
        {
            if (_series == null)
                return;
            WaitFrmHelper.ShowWaitForm();
            var dlg = new AddProductPumpDlg();
            dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
            dlg.SetBindingData(_series, _bindList?.Count() + 1 ?? 0);
            dlg.ReloadDataEvent += (pump, motor) =>
            {
                if (_bindList == null)
                    _bindList = new List<CurrentViewModel>();
 
                _bindList.Add(new CurrentViewModel(flow_unit, pump));
                this.bindingSource1.ResetBindings(false);
                this.AddDataChanedEvent?.Invoke(pump);
                this.FocusedDataChangedEvent?.Invoke(pump);
                XtraMessageBox.Show("添加成功!");
                _isChangeList = true;
            };
            dlg.ShowDialog();
        }
 
        private void GridViewMain_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            var row = this.gridViewMain.GetFocusedRow() as Model.ProductMainExPump;
            if (row == null)
                return;
            this.FocusedDataChangedEvent?.Invoke(row);
        }
 
        private void bar1_VisibleChanged(object sender, EventArgs e)
        {
 
        }
 
 
    }
}