namespace HStation.WinFrmUI { public partial class AddXhsProjectSimulationSchemeDlg : DevExpress.XtraEditors.XtraForm { public AddXhsProjectSimulationSchemeDlg() { InitializeComponent(); this.dataLayoutControl1.SetupLayoutControl(); } /// /// /// public event Action ReloadDataEvent; private HStation.Vmo.XhsSchemeVmo _scheme = null; /// /// 绑定数据 /// public async Task SetBindingData(long projectSiteId) { _scheme = new Vmo.XhsSchemeVmo(); _scheme.SiteID = projectSiteId; _scheme.UseStatus = Yw.Model.eUseStatus.Enable; _scheme.SchemeType = eSchemeType.Common; InitialSchemeType(); await InitialFlags(); } //初始化文件格式 private void InitialSchemeType() { this.imgCmbSchemeType.Properties.BeginUpdate(); this.imgCmbSchemeType.Properties.Items.Clear(); this.imgCmbSchemeType.Properties.Items.AddEnum(typeof(HStation.Xhs.eSchemeType), false); this.imgCmbSchemeType.EditValue = eSchemeType.Common; this.imgCmbSchemeType.Properties.EndUpdate(); } //初始化标签 private async Task InitialFlags() { var allFlagList = await BLLFactory.Instance.GetBySysType(HStation.Xhs.DataType.XhsScheme); var allFlagNameList = allFlagList?.Select(x => x.Name).ToList(); this.setFlagsEditCtrl1.SetBindingData(allFlagNameList, null); } //验证 private bool Valid() { this.dxErrorProvider1.ClearErrors(); if (string.IsNullOrEmpty(this.txtName.Text.Trim())) { this.dxErrorProvider1.SetError(this.txtName, "必填项"); return false; } if (string.IsNullOrEmpty(this.imgCmbSchemeType.Text.Trim())) { this.dxErrorProvider1.SetError(this.imgCmbSchemeType, "必选项"); return false; } return true; } //确定 private async void btnOk_Click(object sender, EventArgs e) { if (!Valid()) { return; } _scheme.NO = this.txtNO.Text.Trim(); _scheme.Name = this.txtName.Text.Trim(); _scheme.SchemeType = (eSchemeType)this.imgCmbSchemeType.EditValue; _scheme.Flags = this.setFlagsEditCtrl1.SelectedFlagList; _scheme.Description = this.txtDescription.Text.Trim(); var id = await BLLFactory.Instance.Insert(_scheme); if (id < 1) { XtraMessageBox.Show("添加失败!"); return; } var scheme = await BLLFactory.Instance.GetByID(id); this.ReloadDataEvent?.Invoke(scheme); TipFormHelper.ShowSucceed("方案添加成功"); this.DialogResult = DialogResult.OK; this.Close(); } } }