using DevExpress.XtraEditors;
|
using System;
|
using System.Windows.Forms;
|
|
|
namespace TProduct.WinFrmUI.Data4Factory
|
{
|
public partial class AddProductPumpDlg : DevExpress.XtraEditors.XtraForm
|
{
|
public AddProductPumpDlg()
|
{
|
InitializeComponent();
|
this.Text = "添加泵信息";
|
|
this.ImgPhaseNumMotor.Properties.Items.Clear();
|
this.ImgPhaseNumMotor.Properties.AddEnum(typeof(Model.eSupplyCurrentPhase), false);
|
this.ImgPhaseNumMotor.SelectedIndex = 0;
|
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;
|
}
|
|
};
|
}
|
|
//回调
|
public event Action<Model.ProductMainExPump,
|
Model.ProductMainExMotor> ReloadDataEvent;
|
|
/// <summary>
|
///
|
/// </summary>
|
/// <param name="SeriesID"></param>
|
public void SetBindingData(TProduct.Model.ProductSeries Series , int SortCode)
|
{
|
if (Series == null)
|
return;
|
|
this.ckCode.Checked = true;
|
|
if (Series.Paras.SupplyCurrentType != null)
|
this.selMotorSeriesCtrl.SetBindingData( Series.Paras.SupplyCurrentType.Value, 0);
|
else
|
this.selMotorSeriesCtrl.SetBindingData(0);
|
|
this.selPumpSeriesCtrl.SetBindingData(Series.ID);
|
this.setPumpRatedParasCtrl1.SetBindingData(Series);
|
this.partBaseCtrl1.SetBindingData(0);
|
this.spinEditSortCode.EditValue = SortCode;
|
}
|
|
/// <summary>
|
/// 复制
|
/// </summary>
|
/// <param name="SeriesID"></param>
|
public void SetBindingData(TProduct.Model.ProductSeries pumpSeries, TProduct.Model.ProductMainExPump pump)
|
{
|
this.ckCode.Checked = true;
|
this.selPumpSeriesCtrl.SetBindingData( pumpSeries.ID);
|
//this.partBaseCtrl1.SetBindingData(pump);
|
|
|
this.spinEditSortCode.EditValue = pump.SortCode;
|
this.TextEditName.Text = pump.Name + "(复制)";
|
//如果已经绑定电机则初始化电机信息
|
if (pump.MotorMainID > 0)
|
{
|
var motor_id = Convert.ToInt64(pump.MotorMainID);
|
var motor_series_id = new BLL.ProductMain().GetByID(motor_id).SeriesID;
|
if (pumpSeries.Paras.SupplyCurrentType != null)
|
this.selMotorSeriesCtrl.SetBindingData(pumpSeries.Paras.SupplyCurrentType.Value, motor_series_id);
|
else
|
this.selMotorSeriesCtrl.SetBindingData( motor_series_id);
|
|
//this.selectMotorCtrl.SetBindingData(motor_series_id, motor_id);
|
}
|
else
|
{
|
if (pumpSeries.Paras.SupplyCurrentType != null)
|
this.selMotorSeriesCtrl.SetBindingData( pumpSeries.Paras.SupplyCurrentType.Value,0);
|
else
|
this.selMotorSeriesCtrl.SetBindingData(0);
|
}
|
///初始化额定参数列表
|
this.setPumpRatedParasCtrl1.SetBindingData(pump);
|
}
|
|
/// <summary>
|
/// 验证
|
/// </summary>
|
private bool Valid()
|
{
|
this.dxErrorProvider1.ClearErrors();
|
if (string.IsNullOrEmpty(this.TextEditName.Text.Trim()))
|
{
|
this.dxErrorProvider1.SetError(this.TextEditName, "必填项");
|
return false;
|
}
|
|
if (this.selPumpSeriesCtrl.SelectProductSeries == null)
|
{
|
XtraMessageBox.Show("您必须选择一个系列才能继续此项操作");
|
return false;
|
}
|
|
return this.setPumpRatedParasCtrl1.Valid();
|
}
|
private void simpleBtnOK_Click(object sender, EventArgs e)
|
{
|
if (!Valid())
|
return;
|
Model.ProductMainExPump model_pump = new Model.ProductMainExPump();
|
if (this.TextEditCode.EditValue != null)
|
model_pump.Code = this.TextEditCode.Text.Trim();
|
var pump_series = this.selPumpSeriesCtrl.SelectProductSeries;
|
if (pump_series != null)
|
model_pump.SeriesID = pump_series.ID;
|
else
|
return;
|
Model.ProductMainExMotor motor_model = null;
|
if (pump_series.IsInnerMotor == 1)
|
{
|
model_pump.MotorMainID = -1;
|
}
|
else
|
{
|
motor_model = this.selectProductMotorCtrl1.SelectMotor;
|
if (motor_model != null)
|
model_pump.MotorMainID = motor_model.ID;
|
else
|
model_pump.MotorMainID = -1;
|
}
|
|
|
model_pump.Name = this.TextEditName.Text.Trim();
|
|
if (this.TextEditCode.Text != "")
|
model_pump.Code = this.TextEditCode.Text.Trim();
|
|
this.setPumpRatedParasCtrl1.GetBindingData(ref model_pump);
|
|
var pumpParas = TProduct.Model.RatedParas4Pump.ToModel(model_pump.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();
|
}
|
}
|
|
}
|
|
model_pump.CreateUserID = TProduct.WinFrmUI.GlobeParas.CurrentLoginUser.ID;
|
model_pump.CreateTime = DateTime.Now;
|
model_pump.UpdateUserID = TProduct.WinFrmUI.GlobeParas.CurrentLoginUser.ID;
|
model_pump.UpdateTime = DateTime.Now;
|
var bll = new BLL.ProductPump();
|
var pump_id = bll.InsertEx(model_pump);
|
if (pump_id <= 0)
|
{
|
XtraMessageBox.Show("添加失败");
|
return;
|
}
|
|
var partlist = this.partBaseCtrl1.GetAllPartList();
|
if (partlist != null && partlist.Count > 0)
|
{
|
foreach (var item in partlist)
|
{
|
item.ProductMainID = pump_id;
|
}
|
|
var partbll = new BLL.PartBase();
|
partbll.Inserts(partlist);
|
}
|
|
|
//修改电机
|
if (motor_model != null)
|
{
|
motor_model.Code = this.TextEditCodeMotor.Text.Trim();
|
motor_model.Name = this.TextEditNameMontor.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
|
(this.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 && model_pump.Ratedn != null)
|
{
|
if (Math.Abs(motor_model.Ratedn.Value - model_pump.Ratedn.Value) / model_pump.Ratedn > 0.1)
|
{
|
XtraMessageBox.Show("请确认电机转速和泵转速是否匹配!");
|
};
|
}
|
var motorbll = new BLL.ProductMotor();
|
if (!motorbll.UpdateEx(motor_model))
|
{
|
XtraMessageBox.Show("电机修改失败!");
|
return;
|
}
|
}
|
|
|
|
model_pump = new BLL.ProductPump().GetExByProductID(pump_id);
|
|
this.ReloadDataEvent?.Invoke(model_pump, motor_model);
|
this.DialogResult = DialogResult.OK;
|
this.Close();
|
}
|
|
private void ckCode_EditValueChanged(object sender, EventArgs e)
|
{
|
if (ckCode.Checked == true)
|
layoutCtrlCode.Enabled = false;
|
else
|
layoutCtrlCode.Enabled = true;
|
}
|
|
|
private void selectMotorSeriesCtrl_FocusedDataChangedEvent(Model.ProductSeries obj)
|
{
|
if (obj == null)
|
return;
|
this.selectProductMotorCtrl1.SetBindingData(obj.ID, 0);
|
}
|
|
private void selMotorCtrl_FocusedDataChangedEvent(Model.ProductMainExMotor motor)
|
{
|
if (motor == null)
|
return;
|
|
this.TextEditCodeMotor.EditValue = motor.Code;
|
this.TextEditNameMontor.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.SelectedIndex = (int)motor.PhaseNum == 1 ? 0 : 1;
|
if (!string.IsNullOrEmpty(motor.RatedParas))
|
{
|
var rateParas_motor = Model.RatedParas4Motor.ToModel(motor.RatedParas);
|
|
this.imageComboBox供电方式Motor.EditValue = (int)rateParas_motor.CurrentType;
|
this.TextEditE_SelfMotor.EditValue = rateParas_motor.E_Self == -1 ? null : rateParas_motor?.E_Self;
|
this.TextEditE_PLCMotor.EditValue = rateParas_motor.E_PLC == -1 ? null : rateParas_motor?.E_PLC;
|
this.cekIsFrequency.EditValue = rateParas_motor.IsFrequency;
|
}
|
}
|
|
private void AddProductPumpDlg_Activated(object sender, EventArgs e)
|
{
|
this.TextEditName.Focus();
|
}
|
|
private void AddProductPumpDlg_Load(object sender, EventArgs e)
|
{
|
|
}
|
|
private void simpleBtnCancel_Click(object sender, EventArgs e)
|
{
|
this.DialogResult = DialogResult.Cancel;
|
this.Close();
|
}
|
}
|
}
|