namespace HStation.WinFrmUI
{
public partial class AddXhsProjectDlg : DevExpress.XtraEditors.XtraForm
{
public AddXhsProjectDlg()
{
InitializeComponent();
this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon;
this.layoutControl1.SetupLayoutControl();
this.generalOkAndCancelCtrl1.OkEvent += GeneralOkAndCancelCtrl1_OkEvent;
}
///
/// 重载数据
///
public event Action ReloadDataEvent;
private XhsProjectExtensionsVmo _project = null;//项目
///
/// 绑定数据
///
public async void SetBindingData()
{
_project = new XhsProjectExtensionsVmo();
_project.SiteList = new List()
{
new XhsProjectSiteVmo()
};
var allFlagsList = await BLLFactory.Instance.GetBySysType(HStation.Xhs.DataType.XhsProject);
this.setFlagsEditCtrl1.SetBindingData(allFlagsList?.Select(x => x.Name).Distinct().ToList(), null);
}
//数据验证
private async Task Valid()
{
this.dxErrorProvider1.ClearErrors();
if (string.IsNullOrEmpty(txtName.Text.Trim()))
{
this.dxErrorProvider1.SetError(this.txtName, "必填项");
return false;
}
var tagname = this.txtTagName.Text.Trim();
if (!string.IsNullOrEmpty(tagname))
{
if (await BLLFactory.Instance.IsExistTagName(tagname))
{
this.dxErrorProvider1.SetError(this.txtTagName, "重复");
return false;
}
}
return true;
}
//确定
private async void GeneralOkAndCancelCtrl1_OkEvent()
{
if (_project == null)
{
return;
}
if (!await Valid())
{
return;
}
_project.Name = this.txtName.Text.Trim();
_project.NO = this.txtNO.Text.Trim();
_project.Customer = this.txtCustomer.Text.Trim();
_project.Flags = this.setFlagsEditCtrl1.SelectedFlagList;
_project.Address = this.txtAddress.Text.Trim();
_project.TagName = this.txtTagName.Text.Trim();
_project.Description = this.txtDescription.Text.Trim();
_project.SiteList.First().Name = _project.Name;
_project.SiteList.First().Description = _project.Description;
_project.ID = await BLLFactory.Instance.Insert(_project);
if (_project.ID < 1)
{
TipFormHelper.ShowError("添加失败!");
return;
}
var project = await BLLFactory.Instance.GetByID(_project.ID);
this.ReloadDataEvent?.Invoke(project);
this.DialogResult = DialogResult.OK;
this.Close();
}
}
}