using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Windows.Forms; namespace IStation.WinFrmUI.Basic { public class PumpsSchedule { public static void Out(Model.Station station) { var products = new BLL.Equipment().GetByBelongTypeAndBelongID(IStation.ObjectType.Station, station.ID); var ePumps = products?.Where(x => x.ParentIds == null || !x.ParentIds.Any()).ToList(); if (ePumps == null) return; var children = products?.Where(x => x.ParentIds != null && x.ParentIds.Any()).ToList(); var calcuParams = new PumpSchedulingParams(); calcuParams.Pumps = new List(); foreach (var ep in ePumps) { var pump = children.Find(x => x.Catalog == IStation.Equipment.Pump && x.ParentIds.Contains(ep.ID)); var motor = children.Find(x => x.Catalog == IStation.Equipment.Motor && x.ParentIds.Contains(ep.ID)); if (pump == null || motor == null) continue; var p = new Model.Equipment(pump).RatedParas; var m = new Model.Equipment(motor).RatedParas; var pumpCurve = new BLL.PumpCurve().GetDefaultWorkingByPumpID(pump.ID); var inPumpParams = new InPumpParam(); inPumpParams.PumpNum = pump.Name; inPumpParams.RatedParam = new InPumpRatedParam(p, m, pumpCurve.CurveInfo.CurveQE); calcuParams.Pumps.Add(inPumpParams); } calcuParams.Operations = new List { new InPumpSchedulingOperation { OperationNum=station.Name, Pumps = new List() { "17#泵", "13#泵", "12#泵", "11#泵" }, InPressure = 5.4691, OutPressure = 19.9272, OutFlow = 7433.9692 + 4761.4771 + 4208.6392, Electrovalence = 1 } }; var dlg = new SaveFileDialog(); dlg.Title = "导出inp曲线文件"; dlg.FileName = $"{station.Name}.json"; dlg.Filter = "json (*.json)|*.json"; if (dlg.ShowDialog() != DialogResult.OK) return; var json = JsonHelper.Object2FormatJson(calcuParams); File.WriteAllText(dlg.FileName, json); } } internal class PumpSchedulingParams { public List Pumps { get; set; } public List Operations { get; set; } } internal class InPumpParam { public string PumpNum { get; set; } public InPumpRatedParam RatedParam { get; set; } } class InPumpRatedParam { public InPumpRatedParam() { } public InPumpRatedParam(Model.Pump pump, Model.Motor motor, Model.CurveExpress express) { this.RatedFlow = pump.Qr; this.RatedHead = pump.Hr; this.RatedSpeed = pump.Nr; this.MinSpeed = pump.Nr * 0.5; this.MaxSpeed = pump.Nr; this.MaxPower = motor.Pr; this.MinPower = motor.Pr * Math.Pow(this.MinSpeed / this.RatedSpeed, 3.00); this.EMPower = motor.Pr; this.EMEfficiency = motor.Er; if (express != null) { var fitPoints = express.GetFitPoints(); this.PumpEfficiencyCurve = fitPoints.Select(x => new InCurvePoint(x.X, x.Y)).ToList(); } if (pump.IsBp) { this.VFDEfficency = 0.98; } } public double RatedFlow { get; set; } public double RatedHead { get; set; } public double RatedSpeed { get; set; } public double MinSpeed { get; set; } public double MaxSpeed { get; set; } public double MinPower { get; set; } public double MaxPower { get; set; } public double EMPower { get; set; } public double EMEfficiency { get; set; } = 0.85; public List PumpEfficiencyCurve { get; set; } public double VFDEfficency { get; set; } = 1.0; } internal class InCurvePoint { public InCurvePoint() { } public InCurvePoint(double x, double y) { this.X = x; this.Y = y; } public double X { get; set; } public double Y { get; set; } } internal class InPumpSchedulingOperation { public string OperationNum { get; set; } public double InPressure { get; set; } public double OutPressure { get; set; } public double OutFlow { get; set; } public List Pumps { get; set; } public double Electrovalence { get; set; } } }