using System.Data; namespace HStation.WinFrmUI { public partial class AssetsFlowmeterSingleMatchingCtrl : DevExpress.XtraEditors.XtraUserControl { public AssetsFlowmeterSingleMatchingCtrl() { InitializeComponent(); this.layoutControl1.SetupLayoutControl(); this.gridView1.SetLimitView(); this.gridView1.RegistCustomDrawCell(); this.generalSearchCtrl1.SearchEvent += Search; this.generalSearchCtrl1.ClearEvent += Clear; } public List _allList = null; private List _allBindingList = null; private AssetsFlowmeterMainVmo _selected = null; /// /// 绑定数据 /// public async void SetBindingData(string dbId) { var allList = await BLLFactory.Instance.GetAll(); if (allList != null) { _allList = new List(); allList.ForEach(x => _allList.Add(new AssetsFlowmeterSingleMatchingViewModel(x))); if (long.TryParse(dbId, out long id)) { var item = allList?.Find(x => x.ID == id); _selected = item; } Search(); } await Task.Delay(300); if (_selected != null) { if (_allBindingList != null && _allBindingList.Count > 0) { var dataSourceIndex = _allBindingList.FindIndex(x => x.Vmo == _selected); if (dataSourceIndex >= 0) { var rowIndex = this.gridView1.GetRowHandle(dataSourceIndex); this.gridView1.FocusedRowHandle = rowIndex; } } } } private void Search() { _allBindingList = _allList; var name = this.txtName.Text.Trim(); if (!string.IsNullOrEmpty(this.txtName.Text.Trim())) { _allBindingList = _allBindingList.Where(x => !string.IsNullOrEmpty(x.Name) && x.Name.Contains(name)).ToList(); } this.assetsFlowmeterSingleMatchingViewModelBindingSource.DataSource = _allBindingList; this.assetsFlowmeterSingleMatchingViewModelBindingSource.ResetBindings(false); } private void Clear() { this.txtName.EditValue = null; Search(); } /// /// 获取 /// public AssetsFlowmeterMainVmo Get() { var vm = this.gridView1.GetFocusedRow() as AssetsFlowmeterSingleMatchingViewModel; if (vm == null) { return default; } return vm.Vmo; } } }