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 EditPhartDiagramRelationDlg : DevExpress.XtraEditors.XtraForm
{
public EditPhartDiagramRelationDlg()
{
InitializeComponent();
this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon;
this.layoutControl1.SetupLayoutControl();
this.generalOkAndCancelCtrl1.OkEvent += GeneralOkAndCancelCtrl1_OkEvent; ;
}
///
///
///
public event Action ReloadDataEvent;
private PhartDiagramRelationVmo _vmo = null;
///
///
///
public void SetBindingData(PhartDiagramRelationVmo vmo)
{
if (vmo == null)
{
return;
}
_vmo = new PhartDiagramRelationVmo(vmo);
this.txtName.EditValue = vmo.OtherName;
this.txtImportance.EditValue = vmo.Importance;
this.txtDescription.EditValue = vmo.Description;
}
//验证
private bool Valid()
{
this.dxErrorProvider1.ClearErrors();
var name = this.txtName.Text.Trim();
if (string.IsNullOrEmpty(name))
{
this.dxErrorProvider1.SetError(this.txtName, "必填项");
return false;
}
return true;
}
//确定
private async void GeneralOkAndCancelCtrl1_OkEvent()
{
if (_vmo == null)
{
return;
}
if (!Valid())
{
return;
}
_vmo.OtherName = this.txtName.Text.Trim();
_vmo.Importance = int.Parse(this.txtImportance.Text.Trim());
_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();
}
}
}