using Mapster; namespace HStation.WinFrmUI.Basic { public partial class SetSysPropChoiceDlg : DevExpress.XtraEditors.XtraForm { public SetSysPropChoiceDlg() { InitializeComponent(); this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon; } private Yw.BLL.SysPropChoice _bll = null; private List _allBindingList = null; private long _PropID; public async void SetBindingData(long PropID) { _PropID = PropID; _bll = new Yw.BLL.SysPropChoice(); var alllist = await _bll.GetByPropID(PropID); _allBindingList = new List(); foreach (var item in alllist) { _allBindingList.Add(new SysPropChoiceViewModel(item)); } this.sysPropChoiceViewModelBindingSource.DataSource = _allBindingList; this.sysPropChoiceViewModelBindingSource.ResetBindings(false); } //完成 private async void BtnOk_Click(object sender, EventArgs e) { var AddSysPropChoices = new List(); foreach (var item in _allBindingList) { var choiceitem = item.Adapt(); choiceitem.PropID = _PropID; AddSysPropChoices.Add(choiceitem); } var alllist = await _bll.GetByPropID(_PropID); foreach (var item in alllist) { await _bll.DeleteByID(item.ID); } if (AddSysPropChoices.Count == 0) { MessageBoxHelper.ShowSuccess("设置成功!"); } else if (await _bll.Inserts(AddSysPropChoices)) { 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.sysPropChoiceViewModelBindingSource.DataSource = _allBindingList; this.sysPropChoiceViewModelBindingSource.ResetBindings(false); } } }