lixiaojun
2024-12-05 f5cdfeae3594e3e6e1461300e93c266ce79c1a8a
WinFrmUI/Yw.WinFrmUI.Hydro.Core/04-viewmodel/04-link/03-valve/HydroValveViewModel.cs
@@ -1,6 +1,4 @@
using Yw.Model;
namespace Yw.WinFrmUI
namespace Yw.WinFrmUI
{
    /// <summary>
    /// 阀门视图
@@ -29,6 +27,8 @@
            this.UpdatePropStatus(nameof(this.OpeningDegree), rhs, nameof(rhs.OpeningDegree));
            this.ValveSetting = rhs.ValveSetting;
            this.UpdatePropStatus(nameof(this.ValveSetting), rhs, nameof(rhs.ValveSetting));
            this.Vmo = rhs;
            UpdateValveSetting();
        }
@@ -37,7 +37,8 @@
        /// </summary>
        [Category("数据")]
        [DisplayName("阀门状态")]
        [PropertyOrder(13)]
        [Description("[默认]使用阀门设置;[开启]使用局阻系数")]
        [PropertyOrder(1003)]
        [Browsable(true)]
        [TypeConverter(typeof(HydroValveStatusConverter))]
        public override string LinkStatus { get; set; }
@@ -47,7 +48,7 @@
        /// </summary>
        [Category("数据")]
        [DisplayName("材料")]
        [PropertyOrder(100)]
        [PropertyOrder(2001)]
        [Browsable(true)]
        public string Material { get; set; }
@@ -56,7 +57,7 @@
        /// </summary>
        [Category("数据")]
        [DisplayName("直径")]
        [PropertyOrder(101)]
        [PropertyOrder(2002)]
        [Browsable(true)]
        [DisplayUnit("mm")]
        public double Diameter { get; set; }
@@ -66,7 +67,7 @@
        /// </summary>
        [Category("数据")]
        [DisplayName("局阻系数")]
        [PropertyOrder(102)]
        [PropertyOrder(2003)]
        [Browsable(true)]
        public double MinorLoss { get; set; }
@@ -75,7 +76,7 @@
        /// </summary>
        [Category("数据")]
        [DisplayName("阀门类型")]
        [PropertyOrder(103)]
        [PropertyOrder(2004)]
        [Browsable(true)]
        [TypeConverter(typeof(HydroValveTypeConverter))]
        public string ValveType { get; set; }
@@ -85,7 +86,7 @@
        /// </summary>
        [Category("数据")]
        [DisplayName("阀门开度")]
        [PropertyOrder(104)]
        [PropertyOrder(2005)]
        [Browsable(true)]
        public double OpeningDegree { get; set; }
@@ -94,14 +95,86 @@
        /// </summary>
        [Category("数据")]
        [DisplayName("阀门设置")]
        [PropertyOrder(105)]
        [IsHydroCurvePro(HydroCurve.ValveQL)]
        [PropertyOrder(2006)]
        [Browsable(true)]
        public string ValveSetting { get; set; }
        /// <summary>
        /// 压强设置
        /// </summary>
        [Category("数据")]
        [DisplayName("压强设置")]
        [Display(Name = "压强设置(m)")]
        [DisplayUnit("m")]
        [HydroRealPro("ValveSetting")]
        [PropertyOrder(2007)]
        [Browsable(true)]
        public double? ValvePress { get; set; }
        /// <summary>
        /// 压强设置
        /// </summary>
        [Category("数据")]
        [DisplayName("流量设置")]
        [Display(Name = "流量设置(m³/h)")]
        [DisplayUnit("m³/h")]
        [HydroRealPro("ValveSetting")]
        [PropertyOrder(2008)]
        [Browsable(true)]
        public double? ValveFlow { get; set; }
        /// <summary>
        /// 开度损失曲线
        /// </summary>
        [Category("数据")]
        [DisplayName("开度损失曲线")]
        [HydroRealPro("ValveSetting")]
        [HydroCurvePro(HydroCurve.ValveOL, HydroCurveType.CurveOL)]
        [PropertyOrder(2009)]
        [Browsable(true)]
        public string ValveOL { get; set; }
        /// <summary>
        /// 水头损失曲线
        /// </summary>
        [Category("数据")]
        [DisplayName("水头损失曲线")]
        [HydroRealPro("ValveSetting")]
        [HydroCurvePro(HydroCurve.ValveQL, HydroCurveType.CurveQL)]
        [PropertyOrder(2010)]
        [Browsable(true)]
        public string ValveQL { get; set; }
        /// <summary>
        /// 水头损失
        /// </summary>
        [Category("计算结果")]
        [DisplayName("水头损失")]
        [Display(Name = "水头损失(m)")]
        [PropertyOrder(10003)]
        [DisplayUnit("m")]
        [HydroCalcuPro]
        [ShowEditor(false)]
        [Browsable(false)]
        public override double? CalcuHeadLoss { get; set; }
        /// <summary>
        /// 沿程损失
        /// </summary>
        [Category("计算结果")]
        [DisplayName("沿程损失")]
        [Display(Name = "沿程损失(m)")]
        [PropertyOrder(10005)]
        [DisplayUnit("m")]
        [HydroCalcuPro]
        [ShowEditor(false)]
        [Browsable(false)]
        public override double? CalcuFrictionLoss { get; set; }
        /// <summary>
        /// 
        /// </summary>
        [Browsable(false)]
        public new Yw.Model.HydroValveInfo Vmo { get; set; }
@@ -123,6 +196,120 @@
            this.UpdatePropStatus(nameof(this.OpeningDegree), this.Vmo, nameof(this.Vmo.OpeningDegree));
            this.ValveSetting = this.Vmo.ValveSetting;
            this.UpdatePropStatus(nameof(this.ValveSetting), this.Vmo, nameof(this.Vmo.ValveSetting));
            UpdateValveSetting();
        }
        /// <summary>
        ///
        /// </summary>
        public override void UpdateVmoProperty()
        {
            base.UpdateVmoProperty();
            this.Vmo.Material = this.Material;
            this.Vmo.UpdatePropStatus(nameof(this.Vmo.Material), this, nameof(this.Material));
            this.Vmo.Diameter = this.Diameter;
            this.Vmo.UpdatePropStatus(nameof(this.Vmo.Diameter), this, nameof(this.Diameter));
            this.Vmo.MinorLoss = this.MinorLoss;
            this.Vmo.UpdatePropStatus(nameof(this.Vmo.MinorLoss), this, nameof(this.MinorLoss));
            this.Vmo.ValveType = HydroValveTypeHelper.GetTypeCode(this.ValveType);
            this.Vmo.UpdatePropStatus(nameof(this.Vmo.ValveType), this, nameof(this.ValveType));
            this.Vmo.OpeningDegree = this.OpeningDegree;
            this.Vmo.UpdatePropStatus(nameof(this.Vmo.OpeningDegree), this, nameof(this.OpeningDegree));
            UpdateVmoValveSetting();
            this.Vmo.ValveSetting = this.ValveSetting;
            this.Vmo.UpdatePropStatus(nameof(this.Vmo.ValveSetting), this, nameof(this.ValveSetting));
        }
        //更新阀门设置
        //使用vmo更新自身属性时,再度更新阀门设置的其他属性
        private void UpdateValveSetting()
        {
            switch (this.Vmo.ValveType)
            {
                case Yw.Hydro.ValveType.PSV:
                    {
                        if (double.TryParse(this.ValveSetting, out double press))
                        {
                            this.ValvePress = press;
                        }
                    }
                    break;
                case Yw.Hydro.ValveType.PBV:
                    {
                        if (double.TryParse(this.ValveSetting, out double press))
                        {
                            this.ValvePress = press;
                        }
                    }
                    break;
                case Yw.Hydro.ValveType.PRV:
                    {
                        if (double.TryParse(this.ValveSetting, out double press))
                        {
                            this.ValvePress = press;
                        }
                    }
                    break;
                case Yw.Hydro.ValveType.FCV:
                    {
                        if (double.TryParse(this.ValveSetting, out double flow))
                        {
                            this.ValveFlow = flow;
                        }
                    }
                    break;
                case Yw.Hydro.ValveType.TCV:
                    {
                        this.ValveOL = this.ValveSetting;
                    }
                    break;
                case Yw.Hydro.ValveType.GPV:
                    {
                        this.ValveQL = this.ValveSetting;
                    }
                    break;
                default: break;
            }
        }
        //更新vmo阀门设置
        //使用自身属性,更新vmo阀门设置
        private void UpdateVmoValveSetting()
        {
            switch (this.Vmo.ValveType)
            {
                case Yw.Hydro.ValveType.PSV:
                    {
                        this.ValveSetting = this.ValvePress?.ToString();
                    }
                    break;
                case Yw.Hydro.ValveType.PBV:
                    {
                        this.ValveSetting = this.ValvePress?.ToString();
                    }
                    break;
                case Yw.Hydro.ValveType.PRV:
                    {
                        this.ValveSetting = this.ValvePress?.ToString();
                    }
                    break;
                case Yw.Hydro.ValveType.FCV:
                    {
                        this.ValveSetting = this.ValveFlow?.ToString();
                    }
                    break;
                case Yw.Hydro.ValveType.TCV:
                    {
                        this.ValveSetting = this.ValveOL;
                    }
                    break;
                case Yw.Hydro.ValveType.GPV:
                    {
                        this.ValveSetting = this.ValveQL;
                    }
                    break;
                default: break;
            }
        }