using Yw;
namespace HStation.WinFrmUI
{
public partial class EditAssetsCompressorFactorDlg : DevExpress.XtraEditors.XtraForm
{
public EditAssetsCompressorFactorDlg()
{
InitializeComponent();
this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon;
this.layoutControl1.SetupLayoutControl();
this.generalOkAndCancelCtrl1.OkEvent += GeneralOkAndCancelCtrl1_OkEvent;
}
///
/// 返回数据事件
///
public event Action ReloadDataEvent;
private HStation.Vmo.AssetsCompressorFactorVmo _vmo = null;
///
/// 绑定数据
///
public void SetBindingData(HStation.Vmo.AssetsCompressorFactorVmo vmo)
{
if (vmo == null)
{
return;
}
_vmo = new Vmo.AssetsCompressorFactorVmo(vmo);
this.txtName.EditValue = vmo.Name;
this.txtMaterial.EditValue = vmo.Material;
this.txtDiameter.EditValue = vmo.Diameter;
this.txtMinorLoss.EditValue = vmo.MinorLoss;
this.txtDescription.EditValue = vmo.Description;
}
//验证
private bool Valid()
{
this.dxErrorProvider1.ClearErrors();
if (string.IsNullOrEmpty(this.txtName.Text.Trim()))
{
this.dxErrorProvider1.SetError(this.txtName, "必填项");
return false;
}
if (string.IsNullOrEmpty(this.txtMaterial.Text.Trim()))
{
this.dxErrorProvider1.SetError(this.txtMaterial, "必填项");
return false;
}
if (string.IsNullOrEmpty(this.txtMinorLoss.Text.Trim()))
{
this.dxErrorProvider1.SetError(this.txtMinorLoss, "必填项");
return false;
}
return true;
}
//确定
private async void GeneralOkAndCancelCtrl1_OkEvent()
{
if (_vmo == null)
{
return;
}
if (!Valid())
{
return;
}
_vmo.Name = this.txtName.Text.Trim();
_vmo.Material = this.txtMaterial.Text.Trim();
_vmo.Diameter = this.txtDiameter.EditValue == null ? null : double.Parse(this.txtDiameter.EditValue?.ToString());
_vmo.MinorLoss = double.Parse(this.txtMinorLoss.EditValue?.ToString());
_vmo.Description = this.txtDescription.Text.Trim();
var bol = await BLLFactory.Instance.Update(_vmo);
if (!bol)
{
TipFormHelper.ShowError("更新失败!");
return;
}
var vmo = await BLLFactory.Instance.GetByID(_vmo.ID);
this.ReloadDataEvent?.Invoke(vmo);
this.DialogResult = DialogResult.OK;
this.Close();
}
}
}