duheng
2024-12-05 492fbc0052225864e97cceb66d86d3fdf9dee961
WinFrmUI/HStation.WinFrmUI.Assets.Core/10-exchanger/02-main/AddExchangerMainDlg.cs
@@ -1,4 +1,5 @@
using 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();
        }
    }
}