using DevExpress.XtraEditors; using System; using System.Collections.Generic; using System.IO; using System.Text; using System.Windows.Forms; namespace IStation.WinFrmUI.Basic { public class ExportInpHelper { public static void INPFile(string filePath, string curveCode, Model.CurveExpress qhCurveExpress, Model.CurveExpress qeCurveExpress) { if (qhCurveExpress == null) return; //均匀插值点,计算点坐标 var fitPointNumQH = 15; double space = (qhCurveExpress.Max - qhCurveExpress.Min) / (fitPointNumQH - 1); double Q = qhCurveExpress.Min; var qhStr = new StringBuilder(); var qeStr = new StringBuilder(); for (var i = 0; i < fitPointNumQH; i++) { var H = Model.FitCurveHelper.GetFitPointY(qhCurveExpress, Q); qhStr.AppendLine(Q + " " + H); if (qeCurveExpress != null) { var E = Model.FitCurveHelper.GetFitPointY(qeCurveExpress, Q); qeStr.AppendLine(Q + " " + E); } Q = Q + space; if (Q > qhCurveExpress.Max * 0.9999) Q = qhCurveExpress.Max * 0.9999; } var qhFilePath = filePath.Insert(filePath.LastIndexOf("."), "水泵"); if (File.Exists(qhFilePath)) File.Delete(qhFilePath); WriteToFile(curveCode, qhFilePath, qhStr, "水泵"); if (qeStr.Length > 0) { var qeFilePath = filePath.Insert(filePath.LastIndexOf("."), "效率"); if (File.Exists(qeFilePath)) File.Delete(qeFilePath); WriteToFile(curveCode, qeFilePath, qeStr, "效率"); } XtraMessageBox.Show("导出成功!"); } public static void INPDefaultFile(string filePath, string curveCode, Model.CurveExpress curveQH, Model.CurveExpress curveQE) { if (curveQH == null) return; //均匀插值点,计算点坐标 var qhStr = new StringBuilder(); List pointQH = curveQH.GetFitPoints(12); if (curveQH.DefinePoints != null) pointQH = curveQH.DefinePoints; for (var i = 0; i < pointQH.Count; i++) { var point = pointQH[i]; var Q = point.X; var H = point.Y; qhStr.AppendLine(Q + " " + H); } var qeStr = new StringBuilder(); List pointQE = curveQE.GetFitPoints(12); if (curveQE.DefinePoints != null) pointQE = curveQE.DefinePoints; for (var i = 0; i < pointQE.Count; i++) { var point = pointQE[i]; var Q = point.X; var E = point.Y; qeStr.AppendLine(Q + " " + E); } WriteToFile(curveCode, filePath, qhStr, "水泵"); if (qeStr.Length > 0) { var qeFilePath = filePath.Insert(filePath.LastIndexOf("."), "效率"); if (File.Exists(qeFilePath)) File.Delete(qeFilePath); WriteToFile(curveCode, qeFilePath, qeStr, "效率"); } } //写入文件 private static void WriteToFile(string curveCode, string filePath, StringBuilder curveStr, string fileType) { StreamWriter sw = new StreamWriter(new FileStream(filePath, FileMode.CreateNew), Encoding.GetEncoding("GB2312")); StringBuilder strQhFile = new StringBuilder(); strQhFile.AppendLine("EPANETH曲线数据"); strQhFile.AppendLine(fileType); var describe = $"{curveCode + "-" + DateTime.Now}"; strQhFile.AppendLine(describe); strQhFile.AppendLine(curveStr.ToString()); sw.Write(strQhFile); sw.Close(); } } }