using Mapster; using Yw.DAL.Basic; using Yw.Dto; namespace HStation.WinFrmUI { public partial class SetExchangerCoefficientDlg : DevExpress.XtraEditors.XtraForm { public SetExchangerCoefficientDlg() { InitializeComponent(); this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon; } private BLL.AssetsExchangerCoefficient _bll = null; private List _allBindingList = null; public async void SetBindingData() { _bll = new BLL.AssetsExchangerCoefficient(); var alllist = await _bll.GetAll(); _allBindingList = new List(); if (alllist != null) { foreach (var item in alllist) { _allBindingList.Add(new ExchangerCoefficientViewModel(item)); } } this.exchangerCoefficientViewModelBindingSource.DataSource = _allBindingList; this.exchangerCoefficientViewModelBindingSource.ResetBindings(false); } //完成 private async void BtnOk_Click(object sender, EventArgs e) { var allList = new List(); foreach (var item in _allBindingList) { allList.Add(new Vmo.AssetsExchangerCoefficientVmo { ID = item.ID, Name = item.Name, Material = item.Material, MinorLoss = item.MinorLoss }); } if (await _bll.DeleteAll()) { if (allList.Count > 0) { if (await _bll.Inserts(allList)) { MessageBoxHelper.ShowSuccess("设置成功!"); } else { MessageBoxHelper.ShowError("设置失败!"); } } else { MessageBoxHelper.ShowSuccess("设置成功!"); } } else { MessageBoxHelper.ShowError("设置失败!"); }; this.DialogResult = DialogResult.OK; this.Close(); } //删除 private void gridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e) { if (_allBindingList == null || _allBindingList.Count < 1) return; var row = this.gridView1.GetCurrentViewModel(_allBindingList); if (row == null) return; if (e.Column == this.ColDelete) _allBindingList.Remove(row); this.exchangerCoefficientViewModelBindingSource.DataSource = _allBindingList; this.exchangerCoefficientViewModelBindingSource.ResetBindings(false); } } }