using Yw;
|
using Yw.WinFrmUI;
|
|
namespace HStation.WinFrmUI
|
{
|
public partial class EditUserDlg : DevExpress.XtraEditors.XtraForm
|
{
|
public EditUserDlg()
|
{
|
InitializeComponent();
|
this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon;
|
this.generalOkAndCancelCtrl1.OkEvent += GeneralOkAndCancelCtrl1_OkEvent;
|
}
|
|
/// <summary>
|
/// 返回数据事件
|
/// </summary>
|
public event Action<Yw.Vmo.User> ReloadDataEvent;
|
|
private Yw.Vmo.User _vmo = null;
|
|
/// <summary>
|
/// 绑定数据
|
/// </summary>
|
public async void SetBindingData(Yw.Vmo.User vmo)
|
{
|
if (vmo == null)
|
{
|
return;
|
}
|
_vmo = vmo;
|
this.txtName.EditValue = vmo.Name;
|
this.txtDescription.EditValue = vmo.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.txtLoginName.Text.Trim()))
|
{
|
this.dxErrorProvider1.SetError(this.txtLoginName, "必填项");
|
return false;
|
}
|
return true;
|
}
|
|
//确定
|
private async void GeneralOkAndCancelCtrl1_OkEvent()
|
{
|
if (_vmo == null)
|
{
|
return;
|
}
|
if (!await Valid())
|
{
|
return;
|
}
|
_vmo.Name = this.txtName.Text.Trim();
|
_vmo.Description = this.txtDescription.Text.Trim();
|
_vmo.LoginName = this.txtLoginName.Text.Trim();
|
_vmo.Tag = this.txtTagName.Text.Trim();
|
var bol = await BLLFactory<Yw.BLL.User>.Instance.Update(_vmo);
|
if (!bol)
|
{
|
TipFormHelper.ShowError("更新失败!");
|
return;
|
}
|
var vmo = await BLLFactory<Yw.BLL.User>.Instance.GetByID(_vmo.ID);
|
this.ReloadDataEvent?.Invoke(vmo);
|
this.DialogResult = DialogResult.OK;
|
this.Close();
|
}
|
}
|
}
|