using DevExpress.XtraEditors.Controls; namespace HStation.WinFrmUI.Assets { public partial class AddExchangerMainDlg : DevExpress.XtraEditors.XtraForm { public AddExchangerMainDlg() { InitializeComponent(); this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon; } private Vmo.AssetsExchangerMainVmo _ExchangerVmo = null; public async void SetBindingData(long SeriesID) { _ExchangerVmo = new Vmo.AssetsExchangerMainVmo(); _ExchangerVmo.SeriesID = SeriesID; var allMaterial = await new Yw.BLL.SysDictData().GetByTypeCode("3"); if (allMaterial != null) { foreach (var item in allMaterial) { var imageItem = new ImageComboBoxItem(item.Name, item.ID); TextEditMaterial.Properties.Items.Add(imageItem); } } TextEditMaterial.SelectedIndex = 0; } public event Func> ReloadDataEvent = null; //数据验证 private bool Valid() { this.dxErrorProvider1.ClearErrors(); if (string.IsNullOrEmpty(TextEditName.Text.Trim())) { this.dxErrorProvider1.SetError(this.TextEditName, "必填项"); return false; } if (string.IsNullOrEmpty(TextEditCoefficient.Text.Trim())) { this.dxErrorProvider1.SetError(this.TextEditCoefficient, "必填项"); return false; } return true; } //完成 private async void BtnOk_ClickAsync(object sender, EventArgs e) { if (!(Valid())) return; _ExchangerVmo.Description = DescriptionTextEdit.Text.Trim(); _ExchangerVmo.Name = TextEditName.Text.Trim(); _ExchangerVmo.KeyWord = TextEditKeyWorld.Text.Trim(); if (TextEditMaterial.Text != "默认") { _ExchangerVmo.MaterialName = TextEditMaterial.Text.Trim(); } if (double.TryParse(TextEditCoefficient.Text, out double Coefficient)) { _ExchangerVmo.Coefficient = Coefficient; } if (await this.ReloadDataEvent.Invoke(_ExchangerVmo)) { TipFormHelper.ShowSucceed("添加成功!"); } else { TipFormHelper.ShowError("添加失败!"); } this.DialogResult = DialogResult.OK; this.Close(); } } }