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