duheng
2024-11-17 a2a57963e160a319276c5c8499f16c9809056e4c
WinFrmUI/HStation.WinFrmUI.Assets.Core/10-exchanger/02-main/EditExchangerMainDlg.cs
@@ -1,5 +1,6 @@
using DevExpress.Utils;
using DevExpress.XtraEditors.Controls;
using HStation.Vmo;
namespace HStation.WinFrmUI.Assets
{
@@ -13,8 +14,14 @@
        private Vmo.AssetsExchangerMainVmo _ExchangerVmo = null;
        private List<Vmo.AssetsExchangerCoefficientVmo> _AssetsExchangerCoefficient;
        public async void SetBindingData(Vmo.AssetsExchangerMainVmo ExchangerVmo)
        {
            var bll = new BLL.AssetsExchangerCoefficient();
            _AssetsExchangerCoefficient = await bll.GetAll();
            this.exchangerCoefficientViewModelBindingSource.DataSource = _AssetsExchangerCoefficient;
            _ExchangerVmo = ExchangerVmo;
            var allMaterial = await new Yw.BLL.SysDictData().GetByTypeCode("3");
            if (allMaterial != null)
@@ -53,6 +60,45 @@
            return true;
        }
        //材料选择变化事件
        private void TextEditMaterial_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (_AssetsExchangerCoefficient == null)
                return;
            var select = GetCoefficientByMaterial(TextEditMaterial.Text);
            if (select == null)
            {
                this.TextEditMinorLoss.Text = string.Empty;
                return;
            }
            this.TextEditMinorLoss.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)
        {