using Mapster;
using System.Data;
namespace HStation.WinFrmUI
{
public partial class EditXhsSchemeDlg : DevExpress.XtraEditors.XtraForm
{
public EditXhsSchemeDlg()
{
InitializeComponent();
this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon;
this.layoutControl1.SetupLayoutControl();
this.generalOkAndCancelCtrl1.OkEvent += GeneralOkAndCancelCtrl1_OkEvent;
}
///
///
///
public event Action ReloadDataEvent;
private XhsSchemeVmo _vmo = null;
///
///
///
public async void SetBindingData(XhsSchemeVmo vmo, Yw.Model.HydroModelInfo hydroInfo)
{
if (vmo == null)
{
return;
}
_vmo = vmo.Adapt();
this.txtName.EditValue = vmo.Name;
this.txtNO.EditValue = vmo.NO;
var flags = await BLLFactory.Instance.GetBySysType(HStation.Xhs.DataType.XhsScheme);
this.setFlagsEditCtrl1.SetBindingData(flags?.Select(x => x.Name).Distinct().ToList(), vmo.Flags);
this.ckAllowCustom.Checked = vmo.AllowCustom;
this.xhsSchemeChangeTypeCheckedListHorizCtrl1.SetBindingData(hydroInfo, vmo.ChangeTypes);
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;
}
return true;
}
//确定
private async void GeneralOkAndCancelCtrl1_OkEvent()
{
if (_vmo == null)
{
return;
}
if (!Valid())
{
return;
}
_vmo.Name = this.txtName.Text.Trim();
_vmo.NO = this.txtNO.Text.Trim();
_vmo.Flags = this.setFlagsEditCtrl1.SelectedFlagList;
_vmo.AllowCustom = this.ckAllowCustom.Checked;
_vmo.ChangeTypes = this.xhsSchemeChangeTypeCheckedListHorizCtrl1.GetCheckedList();
_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();
}
}
}