using DevExpress.XtraEditors;
|
using System;
|
using System.Windows.Forms;
|
using TProduct.Model;
|
|
namespace TProduct.WinFrmUI.Data4Factory
|
{
|
public partial class AddProductMotorDlg : BaseForm
|
{
|
public AddProductMotorDlg()
|
{
|
InitializeComponent();
|
this.Text = "添加电机信息";
|
this.TextEditPowerFactor.IsEmptyContent = true;
|
this.TextEditPowerFactor.MinValue = 0;
|
|
this.simpleBtnOK.SetConfirmButtonColor();
|
this.simpleBtnCancel.SetCancelButtonColor();
|
|
selMotorSeriesCtrl.SetProductType(eProductType.Motor);
|
|
if (TProduct.UserSetting.Setting.Product.SupplyCurrentType == (int)Model.eSupplyCurrentType.直流)
|
{
|
imageComboBox供电方式.SelectedIndex = 1;
|
}
|
else
|
{
|
imageComboBox供电方式.SelectedIndex = 0;
|
}
|
|
selMotorSeriesCtrl.FocusedDataChangedEvent += (s) =>
|
{
|
if (s.Paras.SupplyCurrentType != null)
|
{
|
imageComboBox供电方式.EditValue = (int)s.Paras.SupplyCurrentType;
|
}
|
};
|
}
|
|
//回调
|
public event Action<Model.ProductMainExMotor> ReloadDataEvent;
|
public void SetBindingData(long SeriesID, int SortCode)
|
{
|
this.ckCode.Checked = true;
|
this.layoutCtrlCode.Enabled = false;
|
|
this.spinEditSortCode.EditValue = SortCode;
|
this.selMotorSeriesCtrl.SetBindingData( SeriesID);
|
this.motorEtaCurveSetCtrl1.SetBindingData(null);
|
|
|
this.partBaseCtrl1.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.ImgPhaseNum.Text.Trim()))
|
{
|
this.dxErrorProvider1.SetError(this.ImgPhaseNum, "必填项");
|
return false;
|
}
|
if (string.IsNullOrEmpty(this.txtE_Self.Text.Trim()))
|
{
|
this.dxErrorProvider1.SetError(this.txtE_Self, "必填项");
|
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 (this.selMotorSeriesCtrl.SelectProductSeries == null)
|
{
|
XtraMessageBox.Show("您必须选择一个系列才能继续此项操作");
|
return false;
|
}
|
return true;
|
}
|
|
private void simpleBtnOK_Click(object sender, EventArgs e)
|
{
|
if (!Valid())
|
return;
|
Model.ProductMainExMotor motorModel = new Model.ProductMainExMotor();
|
motorModel.SortCode = Convert.ToInt32(this.spinEditSortCode.EditValue);
|
if (selMotorSeriesCtrl.SelectProductSeries == null)
|
motorModel.SeriesID = 0;
|
else
|
motorModel.SeriesID = selMotorSeriesCtrl.SelectProductSeries.ID;
|
motorModel.PowerFactor = this.TextEditPowerFactor.GetNumber(-1, "功率因子数字不合理");
|
motorModel.Name = this.TextEditName.Text.Trim();
|
|
if (this.TextEditCode.EditValue != null)
|
motorModel.Code = this.TextEditCode.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.TextEditRatedPower.Text.Trim()))
|
{
|
var RatedU = Convert.ToDouble(this.TextEditRatedU.EditValue);
|
motorModel.RatedU = RatedU == 0 ? -1 : RatedU;
|
}
|
|
if (!string.IsNullOrEmpty(this.TextEditRatedn.Text.Trim()))
|
{
|
var Ratedn = Convert.ToDouble(this.TextEditRatedn.EditValue);
|
motorModel.Ratedn = Ratedn == 0 ? -1 : Ratedn;
|
}
|
|
motorModel.PhaseNum = (eSupplyCurrentPhase)this.ImgPhaseNum.EditValue;
|
motorModel.CreateUserID = TProduct.WinFrmUI.GlobeParas.CurrentLoginUser.ID;
|
motorModel.CreateTime = DateTime.Now;
|
motorModel.UpdateUserID = TProduct.WinFrmUI.GlobeParas.CurrentLoginUser.ID;
|
motorModel.UpdateTime = DateTime.Now;
|
motorModel.RatedParas = this.GetRatedParas().ToJson();
|
motorModel.EtaCurve = this.motorEtaCurveSetCtrl1.GetBindingData();
|
|
var bll = new BLL.ProductMotor();
|
var motor_id = bll.InsertEx(motorModel);
|
if (motor_id <= 0)
|
{
|
XtraMessageBox.Show("添加失败");
|
return;
|
}
|
|
var partlist = this.partBaseCtrl1.GetAllPartList();
|
if (partlist != null && partlist.Count > 0)
|
{
|
var partbll = new BLL.PartBase();
|
foreach (var item in partlist)
|
{
|
|
item.ProductMainID = motor_id;
|
|
}
|
|
partbll.Inserts(partlist);
|
}
|
|
var newMotorModel = new BLL.ProductMotor().GetExByProductID(motor_id);
|
this.ReloadDataEvent?.Invoke(newMotorModel);
|
this.DialogResult = DialogResult.OK;
|
this.Close();
|
}
|
|
private void ckCode_EditValueChanging(object sender, DevExpress.XtraEditors.Controls.ChangingEventArgs e)
|
{
|
if (ckCode.Checked == true)
|
{
|
layoutCtrlCode.Enabled = false;
|
}
|
else
|
{
|
if (ckCode.Checked == false)
|
layoutCtrlCode.Enabled = true;
|
}
|
}
|
|
private void AddProductMotorDlg_Load(object sender, EventArgs e)
|
{
|
|
ImgPhaseNum.EditValue = TProduct.UserSetting.Setting.Product.SupplyCurrentPhase;
|
if (!string.IsNullOrEmpty(TProduct.UserSetting.Setting.Product.Voltages))
|
{
|
var ss = TProduct.UserSetting.Setting.Product.Voltages.Split(',');
|
foreach (var s in ss)
|
{
|
TextEditRatedU.Properties.Items.Add(s);
|
}
|
TextEditRatedU.SelectedIndex = 0;
|
}
|
|
}
|
|
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 AddProductMotorDlg_Activated(object sender, EventArgs e)
|
{
|
this.TextEditName.Focus();
|
}
|
}
|
}
|