namespace HStation.WinFrmUI { /// /// 资产匹配参数辅助类 /// public class AssetsMatchingParasHelper { #region 创建 /// /// 创建资产自动匹配ViewModel /// public static AssetsMatchingViewModel Create(Yw.Model.HydroModelInfo hydroInfo) { if (hydroInfo == null) { return default; } var input = new AssetsMatchingViewModel(); //水泵 input.PumpMatchingList = hydroInfo.Pumps?.Select(x => Create(hydroInfo, x)).ToList(); //阀门 input.ValveMatchingList = hydroInfo.Valves?.Select(x => Create(hydroInfo, x)).ToList(); //管道 input.PipeMatchingList = hydroInfo.Pipes?.Select(x => Create(hydroInfo, x)).ToList(); //弯头 input.ElbowMatchingList = hydroInfo.Elbows?.Select(x => Create(hydroInfo, x)).ToList(); //三通 input.ThreelinkMatchingList = hydroInfo.Threelinks?.Select(x => Create(hydroInfo, x)).ToList(); //四通 input.FourlinkMatchingList = hydroInfo.Fourlinks?.Select(x => Create(hydroInfo, x)).ToList(); return input; } /// /// 创建泵自动匹配ViewModel /// public static PumpMatchingViewModel Create(Yw.Model.HydroModelInfo hydroInfo, Yw.Model.HydroPumpInfo pumpInfo) { if (hydroInfo == null) { return default; } if (pumpInfo == null) { return default; } return new PumpMatchingViewModel() { ID = pumpInfo.ID, Code = pumpInfo.Code, Name = pumpInfo.Name, DbLocked = pumpInfo.DbLocked, ModelType = pumpInfo.ModelType, DbId = pumpInfo.DbId, CurveDbId = hydroInfo.Curves?.Find(t => t.Code == pumpInfo.CurveQH)?.DbId, RatedP = pumpInfo.RatedP, RatedH = pumpInfo.RatedH, RatedN = pumpInfo.RatedN, RatedQ = pumpInfo.RatedQ, }; } /// /// 创建阀门自动匹配ViewModel /// public static ValveMatchingViewModel Create(Yw.Model.HydroModelInfo hydroInfo, Yw.Model.HydroValveInfo valveInfo) { if (hydroInfo == null) { return default; } if (valveInfo == null) { return default; } return new ValveMatchingViewModel() { ID = valveInfo.ID, Code = valveInfo.Code, Name = valveInfo.Name, DbLocked = valveInfo.DbLocked, ModelType = valveInfo.ModelType, DbId = valveInfo.DbId, Diameter = valveInfo.Diameter, Material = valveInfo.Material, MinorLoss = valveInfo.MinorLoss, ValveType = valveInfo.ValveType }; } /// /// 创建管道自动匹配ViewModel /// public static PipeMatchingViewModel Create(Yw.Model.HydroModelInfo hydroInfo, Yw.Model.HydroPipeInfo pipeInfo) { if (hydroInfo == null) { return default; } if (pipeInfo == null) { return default; } return new PipeMatchingViewModel() { ID = pipeInfo.ID, Code = pipeInfo.Code, Name = pipeInfo.Name, DbLocked = pipeInfo.DbLocked, ModelType = pipeInfo.ModelType, DbId = pipeInfo.DbId, Diameter = pipeInfo.Diameter, Material = pipeInfo.Material, Roughness = pipeInfo.Roughness, MinorLoss = pipeInfo.MinorLoss, eAlgorithmType = HStation.Assets.eAlgorithmType.Hazen }; } /// /// 创建弯头自动匹配ViewModel /// public static ElbowMatchingViewModel Create(Yw.Model.HydroModelInfo hydroInfo, Yw.Model.HydroElbowInfo elbowInfo) { if (hydroInfo == null) { return default; } if (elbowInfo == null) { return default; } return new ElbowMatchingViewModel() { ID = elbowInfo.ID, Code = elbowInfo.Code, Name = elbowInfo.Name, DbLocked = elbowInfo.DbLocked, ModelType = elbowInfo.ModelType, DbId = elbowInfo.DbId, Caliber = elbowInfo.Caliber, Material = elbowInfo.Material, MinorLoss = elbowInfo.MinorLoss }; } /// /// 创建三通自动匹配ViewModel /// public static ThreelinkMatchingViewModel Create(Yw.Model.HydroModelInfo hydroInfo, Yw.Model.HydroThreelinkInfo threelinkInfo) { if (hydroInfo == null) { return default; } if (threelinkInfo == null) { return default; } return new ThreelinkMatchingViewModel() { ID = threelinkInfo.ID, Code = threelinkInfo.Code, Name = threelinkInfo.Name, DbLocked = threelinkInfo.DbLocked, ModelType = threelinkInfo.ModelType, DbId = threelinkInfo.DbId, Caliber = threelinkInfo.Caliber, Material = threelinkInfo.Material, MinorLoss = threelinkInfo.MinorLoss }; } /// /// 创建四通自动匹配ViewModel /// public static FourlinkMatchingViewModel Create(Yw.Model.HydroModelInfo hydroInfo, Yw.Model.HydroFourlinkInfo fourlinkInfo) { if (hydroInfo == null) { return default; } if (fourlinkInfo == null) { return default; } return new FourlinkMatchingViewModel() { ID = fourlinkInfo.ID, Code = fourlinkInfo.Code, Name = fourlinkInfo.Name, DbLocked = fourlinkInfo.DbLocked, ModelType = fourlinkInfo.ModelType, DbId = fourlinkInfo.DbId, Caliber = fourlinkInfo.Caliber, Material = fourlinkInfo.Material, MinorLoss = fourlinkInfo.MinorLoss }; } #endregion #region 应用 /// /// 应用资产自动匹配ViewModel /// public static bool Apply(Yw.Model.HydroModelInfo hydroInfo, AssetsMatchingViewModel output) { if (hydroInfo == null) { return false; } if (output == null) { return false; } bool result = false; //水泵 output.PumpMatchingList?.ForEach(x => { if (Apply(hydroInfo, x)) { result = true; } }); //阀门 output.ValveMatchingList?.ForEach(x => { if (Apply(hydroInfo, x)) { result = true; } }); //管道 output.PipeMatchingList?.ForEach(x => { if (Apply(hydroInfo, x)) { result = true; } }); //弯头 output.ElbowMatchingList?.ForEach(x => { if (Apply(hydroInfo, x)) { result = true; } }); //三通 output.ThreelinkMatchingList?.ForEach(x => { if (Apply(hydroInfo, x)) { result = true; } }); //四通 output.FourlinkMatchingList?.ForEach(x => { if (Apply(hydroInfo, x)) { result = true; } }); return result; } /// /// 应用泵自动匹配ViewModel /// public static bool Apply(Yw.Model.HydroModelInfo hydroInfo, PumpMatchingViewModel matching) { if (hydroInfo == null) { return false; } if (matching == null) { return false; } bool result = false; var pump = hydroInfo.Pumps?.Find(x => x.Code == matching.Code); if (pump != null) { pump.DbLocked = matching.DbLocked; pump.ModelType = matching.ModelType; pump.RatedP = matching.RatedP; pump.RatedQ = matching.RatedQ; pump.RatedH = matching.RatedH; pump.RatedN = matching.RatedN; if (!pump.DbLocked) { if (!string.IsNullOrEmpty(matching.MatchingModelType)) { pump.ModelType = matching.MatchingModelType; } if (!string.IsNullOrEmpty(matching.MatchingDbId)) { pump.DbId = matching.MatchingDbId; } if (matching.MatchingRatedP.HasValue) { pump.RatedP = matching.MatchingRatedP.Value; } if (matching.MatchingRatedQ.HasValue) { pump.RatedQ = matching.MatchingRatedQ.Value; } if (matching.MatchingRatedH.HasValue) { pump.RatedH = matching.MatchingRatedH.Value; } if (matching.MatchingRatedN.HasValue) { pump.RatedN = matching.MatchingRatedN.Value; } if (!string.IsNullOrEmpty(matching.MatchingCurveDbId)) { //流量扬程曲线 var curveqh = hydroInfo.Curves?.Find(x => x.Code == pump.CurveQH); if (curveqh == null) { curveqh = new Yw.Model.HydroCurveInfo(); curveqh.Catalog = Yw.Hydro.ParterCatalog.Curve; curveqh.Code = Yw.Untity.UniqueHelper.CreateFromFirst("curve", GetAllCodeList(hydroInfo)); curveqh.Name = "匹配"; curveqh.ModelType = string.Empty; curveqh.DbLocked = false; curveqh.DbId = matching.MatchingCurveDbId; curveqh.CurveType = Yw.WinFrmUI.HydroCurve.PumpQH; curveqh.CurveData = matching.MatchingCurveQH?.Select(x => new Yw.Model.Hydro.CurvePoint(x.X, x.Y)).ToList(); if (hydroInfo.Curves == null) { hydroInfo.Curves = new List(); } hydroInfo.Curves.Add(curveqh); pump.CurveQH = curveqh.Code; } else { if (!curveqh.DbLocked) { curveqh.DbId = matching.MatchingDbId; curveqh.CurveData = matching.MatchingCurveQH?.Select(x => new Yw.Model.Hydro.CurvePoint(x.X, x.Y)).ToList(); } } //流量功率曲线 var curveqp = hydroInfo.Curves?.Find(x => x.Code == pump.CurveQP); if (curveqp == null) { curveqp = new Yw.Model.HydroCurveInfo(); curveqp.Catalog = Yw.Hydro.ParterCatalog.Curve; curveqp.Code = Yw.Untity.UniqueHelper.CreateFromFirst("curve", GetAllCodeList(hydroInfo)); curveqp.Name = "匹配"; curveqp.ModelType = string.Empty; curveqp.DbLocked = false; curveqp.DbId = matching.MatchingCurveDbId; curveqp.CurveType = Yw.WinFrmUI.HydroCurve.PumpQP; curveqp.CurveData = matching.MatchingCurveQP?.Select(x => new Yw.Model.Hydro.CurvePoint(x.X, x.Y)).ToList(); if (hydroInfo.Curves == null) { hydroInfo.Curves = new List(); } hydroInfo.Curves.Add(curveqp); pump.CurveQP = curveqp.Code; } else { if (!curveqp.DbLocked) { curveqp.DbId = matching.MatchingDbId; curveqp.CurveData = matching.MatchingCurveQP?.Select(x => new Yw.Model.Hydro.CurvePoint(x.X, x.Y)).ToList(); } } //流量效率曲线 var curveqe = hydroInfo.Curves?.Find(x => x.Code == pump.CurveQE); if (curveqe == null) { curveqe = new Yw.Model.HydroCurveInfo(); curveqe.Catalog = Yw.Hydro.ParterCatalog.Curve; curveqe.Code = Yw.Untity.UniqueHelper.CreateFromFirst("curve", GetAllCodeList(hydroInfo)); curveqe.Name = "匹配"; curveqe.ModelType = string.Empty; curveqe.DbLocked = false; curveqe.DbId = matching.MatchingCurveDbId; curveqe.CurveType = Yw.WinFrmUI.HydroCurve.PumpQE; curveqe.CurveData = matching.MatchingCurveQE?.Select(x => new Yw.Model.Hydro.CurvePoint(x.X, x.Y)).ToList(); if (hydroInfo.Curves == null) { hydroInfo.Curves = new List(); } hydroInfo.Curves.Add(curveqe); pump.CurveQE = curveqe.Code; } else { if (!curveqe.DbLocked) { curveqe.DbId = matching.MatchingDbId; curveqe.CurveData = matching.MatchingCurveQE?.Select(x => new Yw.Model.Hydro.CurvePoint(x.X, x.Y)).ToList(); } } } result = true; } } return result; } /// /// 应用阀门自动匹配ViewModel /// public static bool Apply(Yw.Model.HydroModelInfo hydroInfo, ValveMatchingViewModel matching) { if (hydroInfo == null) { return false; } if (matching == null) { return false; } bool result = false; var valve = hydroInfo.Valves?.Find(x => x.Code == matching.Code); if (valve != null) { valve.DbLocked = matching.DbLocked; valve.ModelType = matching.ModelType; valve.Diameter = matching.Diameter; valve.Material = matching.Material; valve.MinorLoss = matching.MinorLoss; valve.ValveType = matching.ValveType; //valve.ValveSetting = matching.ValveSetting; if (!valve.DbLocked) { if (!string.IsNullOrEmpty(matching.MatchingModelType)) { valve.ModelType = matching.MatchingModelType; } if (!string.IsNullOrEmpty(matching.MatchingDbId)) { valve.DbId = matching.MatchingDbId; } if (matching.MatchingDiameter.HasValue) { valve.Diameter = matching.MatchingDiameter.Value; } if (!string.IsNullOrEmpty(matching.MatchingMaterial)) { valve.Material = matching.MatchingMaterial; } if (matching.MatchingMinorLoss.HasValue) { valve.MinorLoss = matching.MatchingMinorLoss.Value; } if (!string.IsNullOrEmpty(matching.MatchingValveType)) { valve.ValveType = matching.MatchingValveType; } if (!string.IsNullOrEmpty(matching.MatchingValveSetting)) { valve.ValveSetting = matching.MatchingValveSetting; } result = true; } } return result; } /// /// 应用管道自动匹配ViewModel /// public static bool Apply(Yw.Model.HydroModelInfo hydroInfo, PipeMatchingViewModel matching) { if (hydroInfo == null) { return false; } if (matching == null) { return false; } bool result = false; var pipe = hydroInfo.Pipes?.Find(x => x.Code == matching.Code); if (pipe != null) { pipe.DbLocked = matching.DbLocked; pipe.ModelType = matching.ModelType; pipe.Diameter = matching.Diameter; pipe.Material = matching.Material; pipe.Roughness = matching.Roughness; pipe.MinorLoss = matching.MinorLoss; if (!pipe.DbLocked) { if (!string.IsNullOrEmpty(matching.MatchingModelType)) { pipe.ModelType = matching.MatchingModelType; } if (!string.IsNullOrEmpty(matching.MatchingDbId)) { pipe.DbId = matching.MatchingDbId; } if (matching.MatchingDiameter.HasValue) { pipe.Diameter = matching.MatchingDiameter.Value; } if (!string.IsNullOrEmpty(matching.MatchingMaterial)) { pipe.Material = matching.MatchingMaterial; } if (matching.MatchingRoughness.HasValue) { pipe.Roughness = matching.MatchingRoughness.Value; } if (matching.MatchingMinorLoss.HasValue) { pipe.MinorLoss = matching.MatchingMinorLoss.Value; } result = true; } } return result; } /// /// 应用弯头自动匹配ViewModel /// public static bool Apply(Yw.Model.HydroModelInfo hydroInfo, ElbowMatchingViewModel matching) { if (hydroInfo == null) { return false; } if (matching == null) { return false; } bool result = false; var elbow = hydroInfo.Elbows?.Find(x => x.Code == matching.Code); if (elbow != null) { elbow.DbLocked = matching.DbLocked; elbow.ModelType = matching.ModelType; elbow.Caliber = matching.Caliber; elbow.Material = matching.Material; elbow.MinorLoss = matching.MinorLoss; if (!elbow.DbLocked) { if (!string.IsNullOrEmpty(matching.MatchingModelType)) { elbow.ModelType = matching.MatchingModelType; } if (!string.IsNullOrEmpty(matching.MatchingDbId)) { elbow.DbId = matching.MatchingDbId; } if (matching.MatchingCaliber.HasValue) { elbow.Caliber = matching.MatchingCaliber.Value; } if (!string.IsNullOrEmpty(matching.MatchingMaterial)) { elbow.Material = matching.MatchingMaterial; } if (matching.MatchingMinorLoss.HasValue) { elbow.MinorLoss = matching.MatchingMinorLoss.Value; } result = true; } } return result; } /// /// 应用三通自动匹配ViewModel /// public static bool Apply(Yw.Model.HydroModelInfo hydroInfo, ThreelinkMatchingViewModel matching) { if (hydroInfo == null) { return false; } if (matching == null) { return false; } bool result = false; var threelink = hydroInfo.Threelinks?.Find(x => x.Code == matching.Code); if (threelink != null) { threelink.DbLocked = matching.DbLocked; threelink.ModelType = matching.ModelType; threelink.Caliber = matching.Caliber; threelink.Material = matching.Material; threelink.MinorLoss = matching.MinorLoss; if (!threelink.DbLocked) { if (!string.IsNullOrEmpty(matching.MatchingModelType)) { threelink.ModelType = matching.MatchingModelType; } if (!string.IsNullOrEmpty(matching.MatchingDbId)) { threelink.DbId = matching.MatchingDbId; } if (matching.MatchingCaliber.HasValue) { threelink.Caliber = matching.MatchingCaliber.Value; } if (!string.IsNullOrEmpty(matching.MatchingMaterial)) { threelink.Material = matching.MatchingMaterial; } if (matching.MatchingMinorLoss.HasValue) { threelink.MinorLoss = matching.MatchingMinorLoss.Value; } result = true; } } return result; } /// /// 应用四通自动匹配ViewModel /// public static bool Apply(Yw.Model.HydroModelInfo hydroInfo, FourlinkMatchingViewModel matching) { if (hydroInfo == null) { return false; } if (matching == null) { return false; } bool result = false; var fourlink = hydroInfo.Fourlinks?.Find(x => x.Code == matching.Code); if (fourlink != null) { fourlink.DbLocked = matching.DbLocked; fourlink.ModelType = matching.ModelType; fourlink.Caliber = matching.Caliber; fourlink.Material = matching.Material; fourlink.MinorLoss = matching.MinorLoss; if (!fourlink.DbLocked) { if (!string.IsNullOrEmpty(matching.MatchingModelType)) { fourlink.ModelType = matching.MatchingModelType; } if (!string.IsNullOrEmpty(matching.MatchingDbId)) { fourlink.DbId = matching.MatchingDbId; } if (matching.MatchingCaliber.HasValue) { fourlink.Caliber = matching.MatchingCaliber.Value; } if (!string.IsNullOrEmpty(matching.MatchingMaterial)) { fourlink.Material = matching.MatchingMaterial; } if (matching.MatchingMinorLoss.HasValue) { fourlink.MinorLoss = matching.MatchingMinorLoss.Value; } result = true; } } return result; } #endregion //获取所有编码列表 private static List GetAllCodeList(Yw.Model.HydroModelInfo hydroInfo) { if (hydroInfo == null) { return default; } var allParterList = hydroInfo.GetAllParters(); return allParterList?.Select(x => x.Code).Distinct().ToList(); } } }