using DevExpress.XtraEditors; using System; using System.Collections.Generic; using System.Windows.Forms; using TProduct.Model; namespace TProduct.WinFrmUI.Data4Factory { public partial class EditProductMotorDlg : BaseForm { public EditProductMotorDlg() { InitializeComponent(); this.Text = "编辑电机信息"; this.ImgPhaseNum.Properties.AddEnum(typeof(Model.eSupplyCurrentPhase), false); this.ImgPhaseNum.SelectedIndex = 0; this.simpleBtnOK.SetConfirmButtonColor(); this.simpleBtnCancel.SetCancelButtonColor(); selMotorSeriesCtrl.SetProductType(eProductType.Motor); selMotorSeriesCtrl.FocusedDataChangedEvent += (s) => { if (s.Paras.SupplyCurrentType != null) { imageComboBox供电方式.EditValue = (int)s.Paras.SupplyCurrentType; } }; } private Model.ProductMainExMotor _motormodel = null; private bool _IsUpdatePart = false; //回调 public event Action ReloadDataEvent; public void SetBindingData(Model.ProductMainExMotor obj) { _motormodel = obj; this.selMotorSeriesCtrl.SetBindingData( obj.SeriesID); this.TextEditCode.EditValue = _motormodel.Code; this.TextEditName.EditValue = _motormodel.Name; this.TextEditRatedPower.EditValue = _motormodel.RatedPower == -1 ? null : _motormodel?.RatedPower; this.TextEditPowerFactor.EditValue = _motormodel.PowerFactor == -1 ? null : _motormodel?.PowerFactor; this.TextEditRatedI.EditValue = _motormodel.RatedI == -1 ? null : _motormodel?.RatedI; this.TextEditRatedU.EditValue = _motormodel.RatedU == -1 ? null : _motormodel?.RatedU; this.TextEditRatedn.EditValue = _motormodel.Ratedn == -1 ? null : _motormodel?.Ratedn; this.ImgPhaseNum.EditValue = _motormodel.PhaseNum; this.spinEditSortCode.EditValue = obj.SortCode; if (!string.IsNullOrEmpty(_motormodel.RatedParas)) { var ratedparas_motor = RatedParas4Motor.ToModel(_motormodel.RatedParas); this.txtE_Self.EditValue = ratedparas_motor.E_Self == -1 ? null : ratedparas_motor?.E_Self; this.txtE_PLC.EditValue = ratedparas_motor.E_PLC == -1 ? null : ratedparas_motor?.E_PLC; this.cekIsFrequency.EditValue = ratedparas_motor.IsFrequency; imageComboBox供电方式.EditValue = (int)ratedparas_motor.CurrentType; } motorEtaCurveSetCtrl.SetBindingData(_motormodel.EtaCurve); //绑定产品列表 this.partBaseCtrl1.SetBindingData(_motormodel.ID); } /// /// 验证 /// 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 (string.IsNullOrEmpty(this.txtE_Self.Text.Trim())) { this.dxErrorProvider1.SetError(this.txtE_Self, "必填项"); return false; } if (string.IsNullOrEmpty(this.ImgPhaseNum.Text.Trim())) { this.dxErrorProvider1.SetError(this.ImgPhaseNum, "必填项"); return false; } if (string.IsNullOrEmpty(this.TextEditRatedPower.Text.Trim())) { this.dxErrorProvider1.SetError(this.TextEditRatedPower, "必填项"); return false; } if (string.IsNullOrEmpty(this.TextEditRatedI.Text.Trim())) { this.dxErrorProvider1.SetError(this.TextEditRatedI, "必填项"); return false; } if (string.IsNullOrEmpty(this.TextEditRatedn.Text.Trim())) { this.dxErrorProvider1.SetError(this.TextEditRatedn, "必填项"); return false; } if (_motormodel.SeriesID < 1) { XtraMessageBox.Show("您必须选择一个设备系列才能进行此项操作"); return false; } return true; } private void simpleBtnOK_Click(object sender, EventArgs e) { if (!Valid()) return; _motormodel.Code = this.TextEditCode.Text.Trim(); _motormodel.Name = this.TextEditName.Text.Trim(); if (!string.IsNullOrEmpty(this.TextEditRatedPower.Text.Trim())) { var RatedPower = Convert.ToDouble(this.TextEditRatedPower.EditValue); _motormodel.RatedPower = RatedPower == 0 ? -1 : RatedPower; } if (!string.IsNullOrEmpty(this.TextEditPowerFactor.Text.Trim())) { var PowerFactor = Convert.ToDouble(this.TextEditPowerFactor.EditValue); _motormodel.PowerFactor = PowerFactor == 0 ? -1 : PowerFactor; } if (!string.IsNullOrEmpty(this.TextEditRatedI.Text.Trim())) { var RatedI = Convert.ToDouble(this.TextEditRatedI.EditValue); _motormodel.RatedI = RatedI == 0 ? -1 : RatedI; } if (!string.IsNullOrEmpty(this.TextEditRatedU.Text.Trim())) { var RatedU = Convert.ToDouble(this.TextEditRatedU.EditValue); _motormodel.RatedU = RatedU == 0 ? -1 : RatedU; } if (!string.IsNullOrEmpty(this.TextEditRatedn.Text.Trim())) { var speed = Convert.ToDouble(this.TextEditRatedn.EditValue); _motormodel.Ratedn = speed == 0 ? -1 : speed; } _motormodel.SortCode = Convert.ToInt32(this.spinEditSortCode.EditValue); _motormodel.PhaseNum = (eSupplyCurrentPhase)this.ImgPhaseNum.EditValue; _motormodel.RatedParas = this.GetRatedParas().ToJson(); _motormodel.UpdateUserID = TProduct.WinFrmUI.GlobeParas.CurrentLoginUser.ID; _motormodel.UpdateTime = DateTime.Now; _motormodel.EtaCurve = motorEtaCurveSetCtrl.GetBindingData(); _IsUpdatePart = this.partBaseCtrl1.IsUpdate; var partlist = this.partBaseCtrl1.GetAllPartList(); if (partlist != null && partlist.Count > 0) { var partbll = new BLL.PartBase(); var AddpartList = new List(); foreach (var item in partlist) { if (item.ID < 1) { item.ProductMainID = _motormodel.ID; AddpartList.Add(item); } } if (AddpartList != null && AddpartList.Count > 0) partbll.Inserts(AddpartList); _IsUpdatePart = true; } var bll = new BLL.ProductMotor(); if (!bll.UpdateEx(_motormodel)) { XtraMessageBox.Show("修改失败!"); return; } this.ReloadDataEvent?.Invoke(_motormodel, _IsUpdatePart); this.DialogResult = DialogResult.OK; this.Close(); } private void selectProductSeriesCtrl1_FocusedDataChangedEvent(Model.ProductSeries obj) { if (obj == null) return; _motormodel.SeriesID = obj.ID; } private RatedParas4Motor GetRatedParas() { RatedParas4Motor ratedparas_motor = new RatedParas4Motor(); if (!string.IsNullOrEmpty(this.txtE_Self.Text.Trim())) { ratedparas_motor.E_Self = Convert.ToDouble(this.txtE_Self.EditValue); } if (string.IsNullOrEmpty(this.txtE_Self.Text.Trim())) { ratedparas_motor.E_Self = -1; } if (!string.IsNullOrEmpty(this.txtE_PLC.Text.Trim())) { ratedparas_motor.E_PLC = Convert.ToDouble(this.txtE_PLC.EditValue); } if (string.IsNullOrEmpty(this.txtE_PLC.Text.Trim())) { ratedparas_motor.E_PLC = -1; } ratedparas_motor.IsFrequency = this.cekIsFrequency.Checked; ratedparas_motor.CurrentType = (eSupplyCurrentType)Convert.ToInt32(imageComboBox供电方式.EditValue); return ratedparas_motor; } private void EditProductMotorDlg_Activated(object sender, EventArgs e) { this.TextEditName.Focus(); } } }