From 492fbc0052225864e97cceb66d86d3fdf9dee961 Mon Sep 17 00:00:00 2001
From: duheng <2784771470@qq.com>
Date: 星期四, 05 十二月 2024 16:18:36 +0800
Subject: [PATCH] 修改匹配方法以及单独匹配

---
 WinFrmUI/HStation.WinFrmUI.Assets.Core/10-exchanger/02-main/AddExchangerMainDlg.cs |   61 ++++++++++++++++++++++++++++--
 1 files changed, 57 insertions(+), 4 deletions(-)

diff --git a/WinFrmUI/HStation.WinFrmUI.Assets.Core/10-exchanger/02-main/AddExchangerMainDlg.cs b/WinFrmUI/HStation.WinFrmUI.Assets.Core/10-exchanger/02-main/AddExchangerMainDlg.cs
index 0b80e3a..53701b4 100644
--- a/WinFrmUI/HStation.WinFrmUI.Assets.Core/10-exchanger/02-main/AddExchangerMainDlg.cs
+++ b/WinFrmUI/HStation.WinFrmUI.Assets.Core/10-exchanger/02-main/AddExchangerMainDlg.cs
@@ -1,4 +1,5 @@
 锘縰sing DevExpress.XtraEditors.Controls;
+using HStation.Vmo;
 
 namespace HStation.WinFrmUI.Assets
 {
@@ -7,13 +8,19 @@
         public AddExchangerMainDlg()
         {
             InitializeComponent();
+            this.treeList1.InitialMultiColSettings();
             this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon;
         }
 
         private Vmo.AssetsExchangerMainVmo _ExchangerVmo = null;
 
+        private List<Vmo.AssetsExchangerCoefficientVmo> _AssetsExchangerCoefficient;
+
         public async void SetBindingData(long SeriesID)
         {
+            var bll = new BLL.AssetsExchangerCoefficient();
+            _AssetsExchangerCoefficient = await bll.GetAll();
+            this.exchangerCoefficientViewModelBindingSource.DataSource = _AssetsExchangerCoefficient;
             _ExchangerVmo = new Vmo.AssetsExchangerMainVmo();
             _ExchangerVmo.SeriesID = SeriesID;
             var allMaterial = await new Yw.BLL.SysDictData().GetByTypeCode("3");
@@ -48,6 +55,44 @@
             return true;
         }
 
+        //鏉愭枡閫夋嫨鍙樺寲浜嬩欢
+        private void TextEditMaterial_SelectedIndexChanged(object sender, EventArgs e)
+        {
+            if (_AssetsExchangerCoefficient == null)
+                return;
+            var select = GetCoefficientByMaterial(TextEditMaterial.Text);
+            if (select == null)
+            {
+                this.TextEditCoefficient.Text = string.Empty;
+                return;
+            }
+            this.TextEditCoefficient.Text = select.MinorLoss.ToString();
+        }
+
+        //鎵惧埌鏈�鐩歌繎鐨勬潗鏂�
+        private AssetsExchangerCoefficientVmo GetCoefficientByMaterial(string name)
+        {
+            AssetsExchangerCoefficientVmo select = null;
+            int maxMatchedChars = 0;
+            foreach (var item in _AssetsExchangerCoefficient)
+            {
+                int matchedChars = GetIntersect(item.Material, name);
+                if (matchedChars > maxMatchedChars)
+                {
+                    maxMatchedChars = matchedChars;
+                    select = item;
+                    return select;
+                }
+            }
+            return select;
+        }
+
+        private int GetIntersect(string str1, string str2)
+        {
+            if (str1 == null || str2 == null) return 0;
+            return string.Join("", str1.Intersect(str2)).Count();
+        }
+
         //瀹屾垚
         private async void BtnOk_ClickAsync(object sender, EventArgs e)
         {
@@ -55,14 +100,14 @@
                 return;
             _ExchangerVmo.Description = DescriptionTextEdit.Text.Trim();
             _ExchangerVmo.Name = TextEditName.Text.Trim();
-            _ExchangerVmo.KeyWord = TextEditKeyWorld.Text.Trim();
+            _ExchangerVmo.KeyWord = this.TextEditKeyWord.Text.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
             if (TextEditMaterial.Text != "榛樿")
             {
-                _ExchangerVmo.MaterialName = TextEditMaterial.Text.Trim();
+                _ExchangerVmo.Material = TextEditMaterial.Text.Trim();
             }
-            if (double.TryParse(TextEditCoefficient.Text, out double Coefficient))
+            if (double.TryParse(TextEditCoefficient.Text, out double MinorLoss))
             {
-                _ExchangerVmo.Coefficient = Coefficient;
+                _ExchangerVmo.MinorLoss = MinorLoss;
             }
             if (await this.ReloadDataEvent.Invoke(_ExchangerVmo))
             {
@@ -75,5 +120,13 @@
             this.DialogResult = DialogResult.OK;
             this.Close();
         }
+
+        private void treeList1_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e)
+        {
+            var vm = this.treeList1.GetCurrentViewModel(_AssetsExchangerCoefficient);
+            if (vm == null)
+                return;
+            this.TextEditCoefficient.Text = vm.MinorLoss.ToString();
+        }
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3