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
using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.Windows.Forms;
 
 
namespace TProduct.WinFrmUI.Data4Factory
{
    public partial class EditProductPumpDlg : DevExpress.XtraEditors.XtraForm
    {
        public EditProductPumpDlg()
        {
            InitializeComponent();
 
            this.Text = "编辑泵信息";
 
            this.simpleBtnOK.SetConfirmButtonColor();
            this.simpleBtnCancel.SetCancelButtonColor();
 
            selMotorSeriesCtrl.SetProductType(Model.eProductType.Motor);
            selPumpSeriesCtrl.SetProductType(Model.eProductType.Pump);
 
            selPumpSeriesCtrl.FocusedDataChangedEvent += (s) =>
            {
                if (s.IsInnerMotor == 1)
                {
                    layoutCtrlMotorGourp.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
                }
                else
                {
                    layoutCtrlMotorGourp.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
                }
                if (s.Paras.SupplyCurrentType != null)
                {
                    setPumpRatedParasCtrl1.SetBindingData(s);
                    selMotorSeriesCtrl.SetSupplyCurrentType(s.Paras.SupplyCurrentType.Value);
                    imageComboBox供电方式Motor.EditValue = (int)s.Paras.SupplyCurrentType.Value;
                }
            };
 
        }
        private bool _isUpdatePart = false;
        private Model.ProductMainExPump _modelPump = null;
        //回调
        public event Action<Model.ProductMainExPump, bool, Model.ProductMainExMotor> ReloadDataEvent;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="pump"></param>
        public void SetBindingData(Model.ProductMainExPump pump)
        {
            _modelPump = pump;
 
            //初始化额定参数列表
            this.setPumpRatedParasCtrl1.SetBindingData(_modelPump);
 
            //绑定泵系列
            var pump_series = this.selPumpSeriesCtrl.SetBindingData(pump.SeriesID);
 
            //初始化控件
            this.TextEditName.Text = _modelPump.Name;
            this.TextEditCode.Text = _modelPump.Code;
            this.spinEditSortCode.EditValue = _modelPump.SortCode;
 
            //绑定产品列表
            this.partBaseCtrl1.SetBindingData(pump.ID);
 
            //如果已经绑定电机则初始化电机信息
            if (pump.MotorMainID > 0)
            {
                var motor_id = Convert.ToInt64(pump.MotorMainID);
                var motor_series_id = new BLL.ProductMain().GetByID(motor_id).SeriesID;
 
                if (pump_series != null && pump_series.Paras.SupplyCurrentType != null)
                    this.selMotorSeriesCtrl.SetBindingData(pump_series.Paras.SupplyCurrentType.Value, motor_series_id);
                else
                    this.selMotorSeriesCtrl.SetBindingData( motor_series_id);
 
                this.selectMotorCtrl.SetBindingData(motor_series_id, motor_id);
            }
            else
            {
              
                if (pump_series != null && pump_series.Paras.SupplyCurrentType != null)
                    this.selMotorSeriesCtrl.SetBindingData( pump_series.Paras.SupplyCurrentType.Value, 0);
                else
                    this.selMotorSeriesCtrl.SetBindingData( 0);
            }
        }
        /// <summary>
        /// 验证
        /// </summary> 
        private bool Valid()
        {
            this.dxErrorProvider1.ClearErrors();
            if (string.IsNullOrEmpty(this.TextEditName.Text.Trim()))
            {
                this.dxErrorProvider1.SetError(this.TextEditName, "必填项");
                return false;
            }
 
            if (string.IsNullOrEmpty(this.TextEditCode.Text.Trim()))
            {
                this.dxErrorProvider1.SetError(this.TextEditCode, "必填项");
                return false;
            }
            if (_modelPump.SeriesID < 1)
            {
                XtraMessageBox.Show("请选择一个系列");
                return false;
            }
            return this.setPumpRatedParasCtrl1.Valid();
 
        }
        private void simpleBtnOK_Click(object sender, EventArgs e)
        {
            if (!Valid())
                return;
            var pump_series = this.selPumpSeriesCtrl.SelectProductSeries;
            if (pump_series != null)
                _modelPump.SeriesID = pump_series.ID;
            else
                return;
 
            _modelPump.Name = this.TextEditName.Text.Trim();
            _modelPump.Code = this.TextEditCode.Text.Trim();
            Model.ProductMainExMotor motor_model = null;
            if (pump_series.IsInnerMotor == 1)
            {
                _modelPump.MotorMainID = -1;
            }
            else
            {
                motor_model = this.selectMotorCtrl.SelectMotor;
                if (motor_model == null)
                {
                    _modelPump.MotorMainID = -1;
                }
                else
                {
                    _modelPump.MotorMainID = motor_model.ID;
                }
                if (_modelPump.MotorMainID == 0)
                {
                    _modelPump.MotorMainID = -1;
                }
            
            }
 
 
            this.setPumpRatedParasCtrl1.GetBindingData(ref _modelPump);
            var pumpParas = TProduct.Model.RatedParas4Pump.ToModel(_modelPump.RatedParas);
            if (pumpParas.CurrentType == Model.eSupplyCurrentType.直流
                && pump_series.IsInnerMotor != 1)
            {
                if (string.IsNullOrEmpty(this.TextEditRatedUMotor.Text.Trim()))
                {
                    this.dxErrorProvider1.SetError(this.TextEditRatedUMotor, "必填项");
                    return;
                }
                if (motor_model != null)
                {
                    var motorParas = TProduct.Model.RatedParas4Motor.ToModel(motor_model.RatedParas);
                    if (motorParas.CurrentType != pumpParas.CurrentType)
                    {
                        MessageBox.Show("泵供电方式和电机不一致");
                        return;
                    }
                    if (motor_model.RatedU.HasValue && pumpParas.Voltage != motor_model.RatedU)
                    {
                        pumpParas.Voltage = motor_model.RatedU.Value;
                        motor_model.RatedParas = pumpParas.ToJson();
                    }
                }
            }
            _modelPump.UpdateUserID = TProduct.WinFrmUI.GlobeParas.CurrentLoginUser.ID;
            _modelPump.UpdateTime = DateTime.Now;
            _modelPump.SortCode = Convert.ToInt32(this.spinEditSortCode.EditValue);
 
 
 
 
               
            var bll = new BLL.ProductPump();
            if (!bll.UpdateEx(_modelPump))
            {
                XtraMessageBox.Show("修改失败!");
                return;
            }
 
            _isUpdatePart = partBaseCtrl1.IsUpdate;
            var partlist = this.partBaseCtrl1.GetAllPartList();
            if (partlist != null && partlist.Count > 0)
            {
                var partbll = new BLL.PartBase();
                var AddpartList = new List<Model.PartBase>();
                foreach (var item in partlist)
                {
                    if (item.ID < 1)
                    {
                        item.ProductMainID = _modelPump.ID;
                        AddpartList.Add(item);
                    }
                }
                if (AddpartList != null && AddpartList.Count > 0)
                    partbll.Inserts(AddpartList);
                _isUpdatePart = true;
            }
 
            //修改电机
            if (motor_model != null)
            {
                motor_model.Code = this.TextEditCodeMotor.Text.Trim();
                motor_model.Name = this.TextEditNameMotor.Text.Trim();
                if (!string.IsNullOrEmpty(this.TextEditRatedPowerMotor.Text.Trim()))
                {
                    var RatedPower = Convert.ToDouble(this.TextEditRatedPowerMotor.EditValue);
                    motor_model.RatedPower = RatedPower == 0 ? -1 : RatedPower;
                }
                if (!string.IsNullOrEmpty(this.TextEditPowerFactorMotor.Text.Trim()))
                {
                    var PowerFactor = Convert.ToDouble(this.TextEditPowerFactorMotor.EditValue);
                    motor_model.PowerFactor = PowerFactor == 0 ? -1 : PowerFactor;
                }
                if (!string.IsNullOrEmpty(this.TextEditRatedIMotor.Text.Trim()))
                {
                    var RatedI = Convert.ToDouble(this.TextEditRatedIMotor.EditValue);
                    motor_model.RatedI = RatedI == 0 ? -1 : RatedI;
                }
                if (!string.IsNullOrEmpty(this.TextEditRatedUMotor.Text.Trim()))
                {
                    var RatedU = Convert.ToDouble(this.TextEditRatedUMotor.EditValue);
                    motor_model.RatedU = RatedU == 0 ? -1 : RatedU;
                }
                if (!string.IsNullOrEmpty(this.TextEditRatednMotor.Text.Trim()))
                {
                    var speed = Convert.ToDouble(this.TextEditRatednMotor.EditValue);
                    motor_model.Ratedn = speed == 0 ? -1 : speed;
                }
 
                motor_model.PhaseNum = (Model.eSupplyCurrentPhase)this.ImgPhaseNumMotor.EditValue;
 
                Model.RatedParas4Motor ratedparas_motor = new Model.RatedParas4Motor();
                ratedparas_motor.E_Self = Convert.ToDouble(this.TextEditE_SelfMotor.EditValue);
                ratedparas_motor.E_PLC = Convert.ToDouble(this.TextEditE_PLCMotor.EditValue);
                ratedparas_motor.IsFrequency = this.cekIsFrequency.Checked;
                ratedparas_motor.CurrentType = (Model.eSupplyCurrentType)Convert.ToInt32(imageComboBox供电方式Motor.EditValue);
                motor_model.RatedParas = ratedparas_motor.ToJson();
 
                motor_model.UpdateUserID = TProduct.WinFrmUI.GlobeParas.CurrentLoginUser.ID;
                motor_model.UpdateTime = DateTime.Now;
 
                if (pump_series.IsInnerMotor != 1 && motor_model.Ratedn != null && _modelPump.Ratedn != null)
                {
                    if (Math.Abs(motor_model.Ratedn.Value - _modelPump.Ratedn.Value) / _modelPump.Ratedn > 0.1)
                    {
                        XtraMessageBox.Show("请确认电机转速和泵转速是否匹配!");
                    };
                }
 
                var motorbll = new BLL.ProductMotor();
                if (!motorbll.UpdateEx(motor_model))
                {
                    XtraMessageBox.Show("电机修改失败!");
                    return;
                }
            }
 
            this.ReloadDataEvent?.Invoke(_modelPump, _isUpdatePart, motor_model);
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
 
 
        private void selectMotorSeriesCtrl_FocusedDataChangedEvent(Model.ProductSeries obj)
        {
            if (obj == null)
                return;
            if (_modelPump.MotorMainID != null)
                this.selectMotorCtrl.SetBindingData(obj.ID, (long)_modelPump.MotorMainID);
            else
                this.selectMotorCtrl.SetBindingData(obj.ID, 0);
        }
 
        private void selMotorCtrl_FocusedDataChangedEvent(Model.ProductMainExMotor motor)
        {
            this.ImgPhaseNumMotor.Properties.Items.Clear();
            if (motor == null)
                return;
 
            this.TextEditCodeMotor.EditValue = motor.Code;
            this.TextEditNameMotor.EditValue = motor.Name;
            this.TextEditRatedPowerMotor.EditValue = motor.RatedPower < 0 ? null : motor.RatedPower;
            this.TextEditPowerFactorMotor.EditValue = motor.PowerFactor < 0 ? null : motor.PowerFactor;
            this.TextEditRatedIMotor.EditValue = motor.RatedI < 0 ? null : motor.RatedI;
            this.TextEditRatedUMotor.EditValue = motor.RatedU < 0 ? null : motor.RatedU;
            this.TextEditRatednMotor.EditValue = motor.Ratedn < 0 ? null : motor.Ratedn;
            this.ImgPhaseNumMotor.Properties.AddEnum(typeof(Model.eSupplyCurrentPhase), false);
            this.ImgPhaseNumMotor.SelectedIndex = (int)motor.PhaseNum == 1 ? 0 : 1;
            if (!string.IsNullOrEmpty(motor.RatedParas))
            {
                var ratedparas_motor = Model.RatedParas4Motor.ToModel(motor.RatedParas);
                this.TextEditE_SelfMotor.EditValue = ratedparas_motor.E_Self == -1 ? null : ratedparas_motor?.E_Self;
                this.TextEditE_PLCMotor.EditValue = ratedparas_motor.E_PLC == -1 ? null : ratedparas_motor?.E_PLC;
                this.cekIsFrequency.EditValue = ratedparas_motor.IsFrequency;
                imageComboBox供电方式Motor.EditValue = (int)ratedparas_motor.CurrentType;
            }
        }
 
        private void selPumpSeriesCtrl_FocusedDataChangedEvent(Model.ProductSeries obj)
        {
            if (obj == null)
                return;
 
            _modelPump.SeriesID = obj.ID;
        }
 
        private void EditProductPumpDlg_Activated(object sender, EventArgs e)
        {
            this.TextEditName.Focus();
        }
 
        private void simpleBtnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
    }
}