using Yw;
using Yw.WinFrmUI;
namespace HStation.WinFrmUI
{
public partial class AddRoleDlg : DevExpress.XtraEditors.XtraForm
{
public AddRoleDlg()
{
InitializeComponent();
this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon;
this.generalOkAndCancelCtrl1.OkEvent += GeneralOkAndCancelCtrl1_OkEvent;
}
///
/// 返回数据事件
///
public event Action ReloadDataEvent;
//验证
private async Task Valid()
{
this.dxErrorProvider1.ClearErrors();
if (string.IsNullOrEmpty(this.txtName.Text.Trim()))
{
this.dxErrorProvider1.SetError(this.txtName, "必填项");
return false;
}
if (string.IsNullOrEmpty(this.txtCode.Text.Trim()))
{
this.dxErrorProvider1.SetError(this.txtCode, "必填项");
return false;
}
return true;
}
//确定
private async void GeneralOkAndCancelCtrl1_OkEvent()
{
var vmo = new Yw.Vmo.RoleExVmo();
if (!await Valid())
{
return;
}
vmo.Name = this.txtName.Text.Trim();
vmo.Code = this.txtCode.Text.Trim();
vmo.Description = this.txtDescription.Text.Trim();
vmo.ProjectID = GlobalParas._GlobalParas.ProjectID;
vmo.CorpID = GlobalParas._GlobalParas.CorpID;
var id = await BLLFactory.Instance.InsertEx(vmo);
if (id < 1)
{
TipFormHelper.ShowError("添加失败!");
return;
}
var model = await BLLFactory.Instance.GetByID(id);
this.ReloadDataEvent?.Invoke(model);
this.DialogResult = DialogResult.OK;
this.Close();
}
}
}