namespace HStation.WinFrmUI.Assets { public partial class PumpProductListBox : DevExpress.XtraEditors.XtraUserControl { public PumpProductListBox() { InitializeComponent(); listBoxControl1.DisplayMember = "Name"; listBoxControl1.ValueMember = "ID"; } public List _allBindingList = null; public BLL.AssetsPumpPartMain _Bll; public event Action MouseUp; public async void SetBindingData(Vmo.AssetsPumpMainVmo AssetsPumpMain) { _allBindingList = new List(); _Bll = new BLL.AssetsPumpPartMain(); var allpartlist = await _Bll.GetByPumpMainID(AssetsPumpMain.ID); //获取所有产品 var series = await new BLL.AssetsPumpSeries().GetByID(AssetsPumpMain.SeriesID); //获取系列 if (allpartlist != null) { foreach (var item in allpartlist) { var model = new CurrentPartMainViewModel(item); _allBindingList.Add(model); } } this.listBoxControl1.DataSource = _allBindingList; this.listBoxControl1.Refresh(); } public event Action AddReloadEvent = null; public event Action SelectReloadEvent = null; private void BtnAddProductProp_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { AddReloadEvent.Invoke(); } public CurrentPartMainViewModel GetCurrentVm() { return this.listBoxControl1.GetCurrentViewModel(_allBindingList); } private void listBoxControl1_SelectedIndexChanged(object sender, EventArgs e) { SelectReloadEvent.Invoke(); } private void listBoxControl1_MouseUp(object sender, MouseEventArgs e) { MouseUp.Invoke(sender, e); } //删除属性 private async void barBtnDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { var vm = this.listBoxControl1.GetCurrentViewModel(_allBindingList); if (vm == null) { TipFormHelper.ShowWarn("请选择数据行!"); return; } if (MessageBoxHelper.IsClickOk($"确认删除数据行?", "提示")) return; if (await _Bll.DeleteEx(vm.ID)) { _allBindingList.Remove(vm); this.listBoxControl1.Refresh(); TipFormHelper.ShowSucceed("删除成功!"); } else { TipFormHelper.ShowError("删除失败!"); } } } }