using DevExpress.XtraEditors;
|
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 EditAssetsTranslationMainDlg : DevExpress.XtraEditors.XtraForm
|
{
|
public EditAssetsTranslationMainDlg()
|
{
|
InitializeComponent();
|
this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon;
|
this.layoutControl1.SetupLayoutControl();
|
this.generalOkAndCancelCtrl1.OkEvent += GeneralOkAndCancelCtrl1_OkEvent;
|
}
|
|
/// <summary>
|
/// 返回数据事件
|
/// </summary>
|
public event Action<HStation.Vmo.AssetsTranslationMainVmo> ReloadDataEvent;
|
|
private HStation.Vmo.AssetsTranslationMainVmo _vmo = null;
|
|
/// <summary>
|
/// 绑定数据
|
/// </summary>
|
public async void SetBindingData(HStation.Vmo.AssetsTranslationMainVmo vmo)
|
{
|
if (vmo == null)
|
{
|
return;
|
}
|
_vmo = new Vmo.AssetsTranslationMainVmo(vmo);
|
this.txtName.EditValue = vmo.Name;
|
this.TextEditMinorLoss.EditValue = vmo.MinorLoss;
|
this.txtKeyWord.EditValue = HStation.Service.Assets.KeyWordHelper.ToString(vmo.KeyWords);
|
var flags = await BLLFactory<Yw.BLL.SysFlag>.Instance.GetBySysType(HStation.Assets.DataType.TranslationMain);
|
this.setFlagsEditCtrl1.SetBindingData(flags?.Select(x => x.Name).ToList(), vmo.Flags);
|
this.txtTagName.EditValue = vmo.TagName;
|
this.txtDescription.EditValue = vmo.Description;
|
this.txtMaterial.EditValue = vmo.Material;
|
this.txtCaliber.EditValue = vmo.Diameter;
|
this.textEditAlgorithmType.Properties.AddEnum(typeof(HStation.Assets.eAlgorithmType));
|
this.textEditAlgorithmType.EditValue = vmo.eAlgorithmType;
|
this.textEditStartDiameter.EditValue = vmo.StartDiameter;
|
this.textEditEndDiameter.EditValue = vmo.EndDiameter;
|
}
|
|
//验证
|
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.TextEditMinorLoss.Text.Trim()))
|
{
|
this.dxErrorProvider1.SetError(this.TextEditMinorLoss, "必填项");
|
return false;
|
}
|
var tagname = this.txtTagName.Text.Trim();
|
if (!string.IsNullOrEmpty(tagname))
|
{
|
if (await BLLFactory<HStation.BLL.AssetsTranslationMain>.Instance.IsExistTagNameExceptID(tagname, _vmo.ID))
|
{
|
this.dxErrorProvider1.SetError(this.txtTagName, "重复");
|
return false;
|
}
|
}
|
return true;
|
}
|
|
//确定
|
private async void GeneralOkAndCancelCtrl1_OkEvent()
|
{
|
if (_vmo == null)
|
{
|
return;
|
}
|
if (!await Valid())
|
{
|
return;
|
}
|
_vmo.Name = this.txtName.Text.Trim();
|
_vmo.MinorLoss = double.Parse(this.TextEditMinorLoss.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();
|
_vmo.Material = this.txtMaterial.Text.Trim();
|
_vmo.Diameter = double.Parse(this.txtCaliber.EditValue?.ToString());
|
_vmo.StartDiameter = double.Parse(this.textEditStartDiameter.EditValue?.ToString());
|
_vmo.EndDiameter = double.Parse(this.textEditEndDiameter.EditValue?.ToString());
|
_vmo.eAlgorithmType = (HStation.Assets.eAlgorithmType)this.textEditAlgorithmType.EditValue;
|
|
var bol = await BLLFactory<HStation.BLL.AssetsTranslationMain>.Instance.Update(_vmo);
|
if (!bol)
|
{
|
TipFormHelper.ShowError("更新失败!");
|
return;
|
}
|
var vmo = await BLLFactory<HStation.BLL.AssetsTranslationMain>.Instance.GetByID(_vmo.ID);
|
this.ReloadDataEvent?.Invoke(vmo);
|
this.DialogResult = DialogResult.OK;
|
this.Close();
|
}
|
}
|
}
|