lixiaojun
2024-11-15 1aa330646ad9f88abc580e17d08d727a0ecaae48
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
using HStation.WinFrmUI.Xhs;
using Yw.Model;
 
namespace HStation.WinFrmUI
{
    public partial class SetSchemePumpListCtrl : DevExpress.XtraEditors.XtraUserControl, ISetSchemeParterList
    {
        public SetSchemePumpListCtrl()
        {
            InitializeComponent();
            this.layoutControl1.SetupLayoutControl();
            this.gridView1.SetNormalView(30);
            this.gridView1.RegistCustomDrawRowIndicator(40);
            this.gridView1.BorderStyle = BorderStyles.NoBorder;
            this.generalSearchAndSelectCtrl1.SearchEvent += () =>
            {
                Search();
            };
            this.generalSearchAndSelectCtrl1.ClearEvent += () =>
            {
                Clear();
            };
            this.generalSearchAndSelectCtrl1.SelectEvent += () =>
            {
                TipFormHelper.Show(eTipStatus.Info, "批量选择待更新");
            };
        }
 
        /// <summary>
        /// 水力点击事件
        /// </summary>
        public event Action<Yw.Model.HydroParterInfo> HydroClickEvent;
        /// <summary>
        /// 水力改变事件
        /// </summary>
        public event Action<List<HydroParterInfo>> HydroChangedEvent;
 
        /// <summary>
        /// 水力记录改变事件
        /// </summary>
        public event  Action<SetSchemeParterRecord> HydroRecordChangedEvent;
 
        /// <summary>
        /// 显示查询面板
        /// </summary>
        [Browsable(true)]
        [Description("显示查询面板")]
        [DefaultValue(true)]
        public bool ShowFindPanel
        {
            get { return this.gridView1.OptionsFind.AlwaysVisible; }
            set { this.gridView1.OptionsFind.AlwaysVisible = value; }
        }
 
        /// <summary>
        /// 是否拥有水利列表
        /// </summary>
        public bool HasHydroList
        {
            get { return _allList != null && _allList.Count > 0; }
        }
 
 
        //水力信息
        private Yw.Model.HydroModelInfo _hydroInfo = null;
        //水力信息(备份)
        private Yw.Model.HydroModelInfo _hydroInfo_bak = null;
        //所有列表
        private List<HydroPumpViewModel> _allList = null;
        //所有绑定列表
        private List<HydroPumpViewModel> _allBindingList = null;
    
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void SetBindingData(Yw.Model.HydroModelInfo hydroInfo)
        {
            _hydroInfo = hydroInfo; 
            _allList = new List<HydroPumpViewModel>();
            if (hydroInfo != null && hydroInfo.Pumps != null && hydroInfo.Pumps.Count > 0)
            {
                foreach (var pump in hydroInfo.Pumps)
                {
                    var vm = new HydroPumpViewModel(pump, hydroInfo);
                    _allList.Add(vm);
                }
            }
            Search();
        }
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void SetBindingData(Yw.Model.HydroModelInfo hydroInfo, List<HydroCalcuVisualResult> allCalcuResultList)
        {
            _allList = new List<HydroPumpViewModel>();
            if (hydroInfo != null && hydroInfo.Pumps != null && hydroInfo.Pumps.Count > 0)
            {
                foreach (var pump in hydroInfo.Pumps)
                {
                    var vm = new HydroPumpViewModel(pump, hydroInfo);
                    var calcuResult = allCalcuResultList?.Find(x => x.Code == pump.Code);
                    if (calcuResult != null)
                    {
                        vm.UpdateCalcuProperty(calcuResult);
                    }
                    _allList.Add(vm);
                }
            }
            Search();
        }
 
        /// <summary>
        /// 更新属性
        /// </summary>
        public void UpdateProperty()
        {
            if (_allList == null || _allList.Count < 1)
            {
                return;
            }
            _allList.ForEach(x => x.UpdateProperty());
            this.hydroPumpViewModelBindingSource.ResetBindings(false);
        }
 
        /// <summary>
        /// 更新属性
        /// </summary>
        public void UpdateProperty(Yw.Model.HydroParterInfo parter)
        {
            if (_allList == null || _allList.Count < 1)
            {
                return;
            }
            if (parter == null)
            {
                return;
            }
            var vm = _allList.Find(x => x.Code == parter.Code);
            if (vm == null)
            {
                return;
            }
            vm.UpdateProperty();
            this.hydroPumpViewModelBindingSource.ResetBindings(false);
        }
 
        /// <summary>
        /// 更新属性
        /// </summary>
        public void UpdateProperty(List<Yw.Model.HydroParterInfo> parterList)
        {
            if (_allList == null || _allList.Count < 1)
            {
                return;
            }
            if (parterList == null || parterList.Count < 1)
            {
                return;
            }
            parterList.ForEach(x =>
            {
                var vm = _allList.Find(t => x.Code == x.Code);
                if (vm != null)
                {
                    vm.UpdateProperty();
                }
            });
            this.hydroPumpViewModelBindingSource.ResetBindings(false);
        }
 
        /// <summary>
        /// 更新计算属性
        /// </summary>
        public void UpdateCalcuProperty(List<HydroCalcuVisualResult> allCalcuResultList)
        {
            if (allCalcuResultList != null && allCalcuResultList.Count > 0)
            {
                if (_allList != null && _allList.Count > 0)
                {
                    foreach (var parter in _allList)
                    {
                        var calcuResult = allCalcuResultList.Find(x => x.Code == parter.Code);
                        if (calcuResult != null)
                        {
                            parter.UpdateCalcuProperty(calcuResult);
                        }
                    }
                    this.hydroPumpViewModelBindingSource.ResetBindings(false);
                }
            }
        }
 
        //查询
        private void Search()
        {
            if (_allList == null || _allList.Count < 1)
            {
                return;
            }
            var name = this.txtName.Text.Trim();
            var code = this.txtCode.Text.Trim();
            var modelType = this.txtModelType.Text.Trim();
            _allBindingList = _allList;
            if (!string.IsNullOrEmpty(name))
            {
                _allBindingList = _allBindingList.Where(x => !string.IsNullOrEmpty(x.Name) && x.Name.Contains(name)).ToList();
            }
            if (!string.IsNullOrEmpty(code))
            {
                _allBindingList = _allBindingList.Where(x => !string.IsNullOrEmpty(x.Code) && x.Code.Contains(code)).ToList();
            }
            if (!string.IsNullOrEmpty(modelType))
            {
                _allBindingList = _allBindingList.Where(x => !string.IsNullOrEmpty(x.ModelType) && x.ModelType.Contains(modelType)).ToList();
            }
            this.hydroPumpViewModelBindingSource.DataSource = _allBindingList;
            this.hydroPumpViewModelBindingSource.ResetBindings(false);
        }
 
        //重置
        private void Clear()
        {
            this.txtName.EditValue = null;
            this.txtCode.EditValue = null;
            this.txtModelType.EditValue = null;
            Search();
        }
 
        //选择
        private void SelectChange()
        {
            if (_hydroInfo == null)
            {
                XtraMessageBox.Show("无水力信息");
                return;
            }
            Search();
            var row = this.gridView1.GetFocusedRow() as HydroPumpViewModel;
            if (row == null)
            {
                XtraMessageBox.Show("无可设置水泵数据");
                return;
            }
 
            var input = AssetsMatchingParasHelper.Create(_hydroInfo, row.Vmo, null);
            var dlg = new PumpMatchingDlg();
            dlg.SetBindingData(input);
            dlg.ReloadDataEvent += (output) =>
            {
                var bol = AssetsMatchingParasHelper.Apply(_hydroInfo, output);
                if (bol)
                {
                    UpdateProperty();
                }
            };
            dlg.ShowDialog();
        }
          
 
        private void gridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
        {
            var row = this.gridView1.GetRow(e.RowHandle) as HydroPumpViewModel;
            if (row == null)
            {
                return;
            }
 
            if (e.Column == this.colSelect)
            {
                var input = AssetsMatchingParasHelper.Create(_hydroInfo, row.Vmo, null);
                var dlg = new PumpMatchingDlg();
                dlg.SetBindingData(input);
                dlg.ReloadDataEvent += (output) =>
                {
                
                    var bol = AssetsMatchingParasHelper.Apply(_hydroInfo, output);
                    if (bol)
                    {
                        row.UpdateProperty();
                        this.gridView1.RefreshRow(e.RowHandle);
                        this.HydroChangedEvent?.Invoke(new List<Yw.Model.HydroParterInfo>() { row.Vmo });
 
                        var record = new SetSchemeParterRecord();
                        record.Name = row.Vmo.Name;
                        record.Code = row.Vmo.Code;
                        record.Catalog = Yw.Hydro.ParterCatalog.Pump; 
                        record.MatchingModel = output;
 
                        record.Items = new List<SetSchemeParterRecordItem>() {
                        new() {Name="型号",BeforeValue=$"{output.ModelType}",AfterValue=$"{output.MatchingModelType}"},
                        new() {Name="额定功率",BeforeValue=$"{output.RatedP}",AfterValue=$"{output.MatchingRatedP}"},
                        new() {Name="额定流量",BeforeValue=$"{output.RatedQ}",AfterValue=$"{output.MatchingRatedQ}"},
                        new() {Name="额定扬程",BeforeValue=$"{output.RatedH}",AfterValue=$"{output.MatchingRatedH}"},
                        new() {Name="额定转速",BeforeValue=$"{output.RatedN}",AfterValue=$"{output.MatchingRatedN}"},
                        new() {Name="额定频率",BeforeValue=$"{output.RatedHz}",AfterValue=$"{output.MatchingRatedHz}"}
                        }; 
                        this.HydroRecordChangedEvent?.Invoke(record);
                    }
                };
                dlg.ShowDialog();
            }
            else
            {
                this.HydroClickEvent?.Invoke(row.Vmo);
            }
        }
 
 
 
      
    }
}