namespace HStation.WinFrmUI
|
{
|
public partial class EditXhsProjectDlg : DevExpress.XtraEditors.XtraForm
|
{
|
public EditXhsProjectDlg()
|
{
|
InitializeComponent();
|
this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon;
|
this.layoutControl1.SetupLayoutControl();
|
this.generalOkAndCancelCtrl1.OkEvent += GeneralOkAndCancelCtrl1_OkEvent;
|
}
|
|
/// <summary>
|
/// 重载数据
|
/// </summary>
|
public event Action<XhsProjectExtensionsVmo> ReloadDataEvent;
|
|
private XhsProjectExtensionsVmo _project = null;//项目
|
|
/// <summary>
|
/// 绑定数据
|
/// </summary>
|
public async void SetBindingData(XhsProjectExtensionsVmo project)
|
{
|
if (project == null)
|
{
|
return;
|
}
|
_project = project;
|
this.txtName.EditValue = project.Name;
|
this.txtNO.EditValue = project.NO;
|
this.txtCustomer.EditValue = project.Customer;
|
var allFlagsList = await BLLFactory<Yw.BLL.SysFlag>.Instance.GetBySysType(HStation.Xhs.DataType.XhsProject);
|
this.setFlagsEditCtrl1.SetBindingData(allFlagsList?.Select(x => x.Name).Distinct().ToList(), project.Flags);
|
this.txtTagName.EditValue = project.TagName;
|
this.txtAddress.EditValue = project.Address;
|
this.txtDescription.EditValue = project.Description;
|
}
|
|
//数据验证
|
private async Task<bool> 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<HStation.BLL.XhsProject>.Instance.IsExistTagNameExceptID(tagname, _project.ID))
|
{
|
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();
|
|
var bol = await BLLFactory<HStation.BLL.XhsProjectExtensions>.Instance.Update(_project);
|
if (!bol)
|
{
|
TipFormHelper.ShowError("更新失败!");
|
return;
|
}
|
|
var project = await BLLFactory<HStation.BLL.XhsProjectExtensions>.Instance.GetByID(_project.ID);
|
this.ReloadDataEvent?.Invoke(project);
|
this.DialogResult = DialogResult.OK;
|
this.Close();
|
}
|
|
|
}
|
}
|