using DevExpress.XtraEditors;
|
using DevExpress.XtraScheduler.Outlook.Interop;
|
using HStation.Service.Assets;
|
using HStation.Vmo;
|
using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Data;
|
using System.Drawing;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using System.Windows.Forms;
|
using Yw;
|
|
namespace HStation.WinFrmUI
|
{
|
public partial class AddAssetsCoolingMainDlg : DevExpress.XtraEditors.XtraForm
|
{
|
public AddAssetsCoolingMainDlg()
|
{
|
InitializeComponent();
|
this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon;
|
this.layoutControl1.SetupLayoutControl();
|
this.generalOkAndCancelCtrl1.OkEvent += GeneralOkAndCancelCtrl1_OkEvent;
|
}
|
|
private static AssetsCoolingMainVmo _last = null;
|
|
/// <summary>
|
/// 返回数据事件
|
/// </summary>
|
public event Action<HStation.Vmo.AssetsCoolingMainVmo> ReloadDataEvent;
|
|
private HStation.Vmo.AssetsCoolingSeriesVmo _series = null;
|
private HStation.Vmo.AssetsCoolingMainVmo _vmo = null;
|
|
/// <summary>
|
/// 绑定数据
|
/// </summary>
|
public async void SetBindingData(HStation.Vmo.AssetsCoolingSeriesVmo series)
|
{
|
if (series == null)
|
{
|
return;
|
}
|
_series = series;
|
_vmo = new Vmo.AssetsCoolingMainVmo();
|
_vmo.SeriesID = series.ID;
|
var flags = await BLLFactory<Yw.BLL.SysFlag>.Instance.GetBySysType(HStation.Assets.DataType.CoolingMain);
|
this.setFlagsEditCtrl1.SetBindingData(flags?.Select(x => x.Name).ToList(), null);
|
if (_last != null)
|
{
|
this.txtName.EditValue = _last.Name;
|
this.txtMaterial.EditValue = _last.Material;
|
this.txtKeyWord.EditValue = KeyWordHelper.ToString(_last.KeyWords);
|
this.txtCaliber.EditValue = _last.Caliber;
|
this.txtCoefficient.EditValue = _last.Coefficient;
|
this.txtLowerLimit.EditValue = _last.LowerLimit;
|
this.setFlagsEditCtrl1.SetBindingData(flags?.Select(x => x.Name).ToList(), _last.Flags);
|
this.txtTagName.EditValue = _last.TagName;
|
this.txtDescription.EditValue = _last.Description;
|
}
|
}
|
|
//验证
|
private async Task<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.txtCoefficient.Text.Trim()))
|
{
|
this.dxErrorProvider1.SetError(this.txtCoefficient, "必填项");
|
return false;
|
}
|
if (string.IsNullOrEmpty(this.txtLowerLimit.Text.Trim()))
|
{
|
this.dxErrorProvider1.SetError(this.txtLowerLimit, "必填项");
|
return false;
|
}
|
var tagname = this.txtTagName.Text.Trim();
|
if (!string.IsNullOrEmpty(tagname))
|
{
|
if (await BLLFactory<HStation.BLL.AssetsCoolingMain>.Instance.IsExistTagName(tagname))
|
{
|
this.dxErrorProvider1.SetError(this.txtTagName, "重复");
|
return false;
|
}
|
}
|
return true;
|
}
|
|
//确定
|
private async void GeneralOkAndCancelCtrl1_OkEvent()
|
{
|
if (_series == null)
|
{
|
return;
|
}
|
if (_vmo == null)
|
{
|
return;
|
}
|
if (!await Valid())
|
{
|
return;
|
}
|
_vmo.Name = this.txtName.Text.Trim();
|
_vmo.Material = this.txtMaterial.Text.Trim();
|
_vmo.Caliber = this.txtCaliber.EditValue == null ? null : double.Parse(this.txtCaliber.EditValue?.ToString());
|
_vmo.Coefficient = double.Parse(this.txtCoefficient.EditValue?.ToString());
|
_vmo.LowerLimit = double.Parse(this.txtLowerLimit.EditValue?.ToString());
|
_vmo.KeyWords = HStation.Service.Assets.KeyWordHelper.ToList(this.txtKeyWord.Text.Trim());
|
_vmo.Flags = this.setFlagsEditCtrl1.SelectedFlagList;
|
_vmo.TagName = this.txtTagName.Text.Trim();
|
_vmo.Description = this.txtDescription.Text.Trim();
|
|
var id = await BLLFactory<HStation.BLL.AssetsCoolingMain>.Instance.Insert(_vmo);
|
if (id < 1)
|
{
|
TipFormHelper.ShowError("添加失败!");
|
return;
|
}
|
var vmo = await BLLFactory<HStation.BLL.AssetsCoolingMain>.Instance.GetByID(id);
|
_last = vmo;
|
this.ReloadDataEvent?.Invoke(vmo);
|
this.DialogResult = DialogResult.OK;
|
this.Close();
|
}
|
|
}
|
}
|