Shuxia Ning
2024-12-17 907a1579fecf2c160852cf99b3ea77c08eb481cc
WinFrmUI/HStation.WinFrmUI.Assets.Core/22-cooling/02-main/AddAssetsCoolingMainDlg.cs
@@ -1,4 +1,7 @@
using DevExpress.XtraEditors;
using DevExpress.XtraScheduler.Outlook.Interop;
using HStation.Service.Assets;
using HStation.Vmo;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@@ -22,6 +25,8 @@
            this.generalOkAndCancelCtrl1.OkEvent += GeneralOkAndCancelCtrl1_OkEvent;
        }
        private static AssetsCoolingMainVmo _last = null;
        /// <summary>
        /// 返回数据事件
        /// </summary>
@@ -44,6 +49,18 @@
            _vmo.SeriesID = series.ID;
            var flags = await BLLFactory<Yw.BLL.SysFlag>.Instance.GetBySysType(HStation.Assets.DataType.CoolingMain);
            this.setFlagsEditCtrl1.SetBindingData(flags?.Select(x => x.Name).ToList(), null);
            if (_last != null)
            {
                this.txtName.EditValue = _last.Name;
                this.txtMaterial.EditValue = _last.Material;
                this.txtKeyWord.EditValue = KeyWordHelper.ToString(_last.KeyWords);
                this.txtCaliber.EditValue = _last.Caliber;
                this.txtCoefficient.EditValue = _last.Coefficient;
                this.txtLowerLimit.EditValue = _last.LowerLimit;
                this.setFlagsEditCtrl1.SetBindingData(flags?.Select(x => x.Name).ToList(), _last.Flags);
                this.txtTagName.EditValue = _last.TagName;
                this.txtDescription.EditValue = _last.Description;
            }
        }
        //验证
@@ -114,10 +131,66 @@
                return;
            }
            var vmo = await BLLFactory<HStation.BLL.AssetsCoolingMain>.Instance.GetByID(id);
            _last = vmo;
            this.ReloadDataEvent?.Invoke(vmo);
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
        //获取所有系数列表
        private async Task<List<AssetsCoolingFactorVmo>> GetAllFactorList()
        {
            if (_allFactorList == null)
            {
                _allFactorList = await BLLFactory<HStation.BLL.AssetsCoolingFactor>.Instance.GetAll();
                if (_allFactorList == null)
                {
                    _allFactorList = new List<AssetsCoolingFactorVmo>();
                }
            }
            return _allFactorList;
        }
        private List<AssetsCoolingFactorVmo> _allFactorList = null;
        //匹配系数
        private async void MatchingFactor()
        {
            if (this.txtCoefficient.EditValue == null && this.txtLowerLimit.EditValue == null)
            {
                var allFactorList = await GetAllFactorList();
                if (allFactorList != null && allFactorList.Count > 0)
                {
                    var material = this.txtMaterial.Text.Trim();
                    double? caliber = this.txtCaliber.EditValue == null ? null : double.Parse(this.txtCaliber.EditValue.ToString());
                    var factorList = allFactorList.ToList();
                    if (!string.IsNullOrEmpty(material))
                    {
                        factorList = factorList.Where(x => !string.IsNullOrEmpty(x.Material) && x.Material.Contains(material)).ToList();
                    }
                    if (caliber.HasValue)
                    {
                        factorList = factorList.Where(x => x.Caliber.HasValue && x.Caliber.Value == caliber.Value).ToList();
                    }
                    var factor = factorList.FirstOrDefault();
                    if (factor != null)
                    {
                        this.txtCoefficient.EditValue = factor.Coefficient;
                        this.txtLowerLimit.EditValue = factor.LowerLimit;
                    }
                }
            }
        }
        private void txtMaterial_EditValueChanged(object sender, EventArgs e)
        {
            MatchingFactor();
        }
        private void txtCaliber_EditValueChanged(object sender, EventArgs e)
        {
            MatchingFactor();
        }
    }
}