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();
|
}
|
}
|
}
|