From 21c97aab9153758bebfc9b3944859b0eec271c76 Mon Sep 17 00:00:00 2001 From: lixiaojun <1287241240@qq.com> Date: 星期三, 25 九月 2024 16:31:19 +0800 Subject: [PATCH] 一些简单的尝试 --- WinFrmUI/HStation.WinFrmUI.Xhs.Core/04-simulation/06-simulation/01-AutoMatching/02-AsstesFormCtrl/PumpMatchingCtrl.cs | 105 ++++++++++++++++++++++------------------------------ 1 files changed, 45 insertions(+), 60 deletions(-) diff --git a/WinFrmUI/HStation.WinFrmUI.Xhs.Core/04-simulation/06-simulation/01-AutoMatching/02-AsstesFormCtrl/PumpMatchingCtrl.cs b/WinFrmUI/HStation.WinFrmUI.Xhs.Core/04-simulation/06-simulation/01-AutoMatching/02-AsstesFormCtrl/PumpMatchingCtrl.cs index 5e1b2dd..8163e8a 100644 --- a/WinFrmUI/HStation.WinFrmUI.Xhs.Core/04-simulation/06-simulation/01-AutoMatching/02-AsstesFormCtrl/PumpMatchingCtrl.cs +++ b/WinFrmUI/HStation.WinFrmUI.Xhs.Core/04-simulation/06-simulation/01-AutoMatching/02-AsstesFormCtrl/PumpMatchingCtrl.cs @@ -1,6 +1,4 @@ -锘縰sing DevExpress.Dialogs.Core.View; - -namespace HStation.WinFrmUI +锘縩amespace HStation.WinFrmUI { public partial class PumpMatchingCtrl : DevExpress.XtraEditors.XtraUserControl { @@ -12,73 +10,60 @@ this.gridView1.OptionsView.ShowGroupPanel = false; } - private List<PumpMatchingViewModel> _allBindingList = null; - private BLL.PumpMain _pumpMainBll = null; + private List<PumpFormViewModel> _allBindingList = new List<PumpFormViewModel>(); - public List<PumpMatchingViewModel> SetBindingData(List<PumpMatchingViewModel> pumpMatchingViewModel, out List<PumpMatchingViewModel> errorList) + /// <summary> + /// 鐐瑰嚮浜嬩欢 + /// </summary> + public event Action<string> RowClickEvent; + + public void SetBindingData(List<PumpMatchingViewModel> pumpMatchingViewModel) { - _pumpMainBll = new BLL.PumpMain(); - errorList = null; - _allBindingList = new List<PumpMatchingViewModel>(); - if (pumpMatchingViewModel == null) - return null; - var alllist = _pumpMainBll.GetAll().Result; - const double speedTolerance = 100; - const double flowTolerance = 10; - const double headTolerance = 5; - const double efficiencyTolerance = 0.05; - foreach (var viewModel in pumpMatchingViewModel) + if (pumpMatchingViewModel != null) { - foreach (var pumpMain in alllist) + foreach (var item in pumpMatchingViewModel) { - // 灏濊瘯缁濆鍖归厤 - var absoluteMatch = alllist.FirstOrDefault(item => - viewModel.RatedN == item.RatedSpeed && - viewModel.RatedQ == item.RatedFlow && - viewModel.RatedH == item.RatedHead && - viewModel.RatedP == item.RatedPower); - if (absoluteMatch != null) - { - } - else - { - // 灏濊瘯鍖洪棿鍖归厤 - var rangeMatch = alllist.Where(item => - (viewModel.RatedN.HasValue ? Math.Abs(viewModel.RatedN.Value - item.RatedSpeed) <= speedTolerance : true) && - (viewModel.RatedQ.HasValue ? Math.Abs(viewModel.RatedQ.Value - item.RatedFlow) <= flowTolerance : true) && - (viewModel.RatedH.HasValue ? Math.Abs(viewModel.RatedH.Value - item.RatedHead) <= headTolerance : true) && - (Math.Abs(viewModel.RatedP - item.RatedPower) <= efficiencyTolerance)).ToList(); - if (rangeMatch != null) - { - var vmo = new Vmo.PumpMainVmo(); - int firstCount = 0; - foreach (var item in rangeMatch) - { - int commonCount = CountCommonCharacters(viewModel.ModelType, item.Name); - if (commonCount > firstCount) - { - vmo = item; - firstCount = commonCount; - } - } - } - } + _allBindingList.Add(new PumpFormViewModel(item)); } } - this.pumpMatchingViewModelBindingSource.DataSource = _allBindingList; - return new List<PumpMatchingViewModel>(); + this.pumpFormViewModelBindingSource.DataSource = _allBindingList; } - private static int CountCommonCharacters(string baseString, string comparisonString) + public async Task<List<PumpMatchingViewModel>> SetMatching(List<PumpMatchingViewModel> pumpMatchingViewModel, List<PumpMainVmo> pumpMainVmos) { - // 灏嗗瓧绗︿覆杞崲涓哄瓧绗﹂泦鍚� - HashSet<char> baseChars = new HashSet<char>(baseString); - HashSet<char> comparisonChars = new HashSet<char>(comparisonString); + var finishList = new List<PumpMatchingViewModel>(); + if (pumpMatchingViewModel == null) + return null; + foreach (var item in pumpMatchingViewModel) + { + var result = await AssetsMatchingHelper.MatchingPumps(item, pumpMainVmos); + if (result != null) + { + finishList.Add(result); + } + else + { + finishList.Add(item); + } + } + _allBindingList.Clear(); + foreach (var item in finishList) + { + _allBindingList.Add(new PumpFormViewModel(item)); + } + this.pumpFormViewModelBindingSource.ResetBindings(false); + return finishList; + } - // 璁$畻涓や釜闆嗗悎鐨勪氦闆� - int commonCount = baseChars.Intersect(comparisonChars).Count(); - - return commonCount; + //琛岀偣鍑讳簨浠� + private void gridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e) + { + var row = this.gridView1.GetCurrentViewModel(_allBindingList); + if (row == null) + { + return; + } + this.RowClickEvent?.Invoke(row.Code); } } } \ No newline at end of file -- Gitblit v1.9.3