From 6e1306ab578ed1ad79fc33b0bb7e496b897bf4a4 Mon Sep 17 00:00:00 2001
From: lixiaojun <1287241240@qq.com>
Date: 星期一, 20 一月 2025 10:48:03 +0800
Subject: [PATCH] 冲突处理

---
 WinFrmUI/Yw.WinFrmUI.Phart.Core/00-core/01-helper/PhartExcelHelper.cs |  621 +++++++++++++++++++++++++++++---------------------------
 1 files changed, 323 insertions(+), 298 deletions(-)

diff --git a/WinFrmUI/Yw.WinFrmUI.Phart.Core/00-core/01-helper/PhartExcelHelper.cs b/WinFrmUI/Yw.WinFrmUI.Phart.Core/00-core/01-helper/PhartExcelHelper.cs
index 88e5759..1e316de 100644
--- a/WinFrmUI/Yw.WinFrmUI.Phart.Core/00-core/01-helper/PhartExcelHelper.cs
+++ b/WinFrmUI/Yw.WinFrmUI.Phart.Core/00-core/01-helper/PhartExcelHelper.cs
@@ -5,6 +5,7 @@
     /// </summary>
     public class PhartExcelHelper
     {
+
         #region Export
 
         public static void ExportUniversalTemplate(string file_path, Yw.Ahart.eCurveType curve_type)
@@ -76,82 +77,88 @@
 
         public static string ParseUniversalExcel(string file_path, out List<Yw.Geometry.Point2d> list)
         {
-            list = new List<Geometry.Point2d>(); ;
-            if (!File.Exists(file_path))
-                return "鏂囦欢涓嶅瓨鍦�";
-
-            //鍒濆鍖栨枃浠�
-            NPOI.HSSF.UserModel.HSSFWorkbook theBook = null;
-            using (FileStream file = new FileStream(file_path, FileMode.Open, FileAccess.Read))
+            list = new List<Geometry.Point2d>();
+            try
             {
-                theBook = new NPOI.HSSF.UserModel.HSSFWorkbook(file);
-            }
+                if (!File.Exists(file_path))
+                    return "鏂囦欢涓嶅瓨鍦�";
 
-            //妫�鏌ヨ〃鏍兼槸鍚︾鍚�
-            NPOI.SS.UserModel.ISheet sheet1 = theBook.GetSheet("Sheet1");
-            if (sheet1 == null)
-            {
-                sheet1 = theBook.GetSheetAt(0);
+                //鍒濆鍖栨枃浠�
+                NPOI.HSSF.UserModel.HSSFWorkbook theBook = null;
+                using (FileStream file = new FileStream(file_path, FileMode.Open, FileAccess.ReadWrite))
+                {
+                    theBook = new NPOI.HSSF.UserModel.HSSFWorkbook(file);
+                }
+
+                //妫�鏌ヨ〃鏍兼槸鍚︾鍚�
+                NPOI.SS.UserModel.ISheet sheet1 = theBook.GetSheet("Sheet1");
                 if (sheet1 == null)
-                    return ("鏃燬heet鏁版嵁");
+                {
+                    sheet1 = theBook.GetSheetAt(0);
+                    if (sheet1 == null)
+                        return ("鏃燬heet鏁版嵁");
+                }
+
+                //鏍囬琛�
+                int title_line_index = 0;
+                //x 鍒�
+                int col_index_x = 1;
+                //y 鍒�
+                int col_index_y = 2;
+
+                var row_title = sheet1.GetRow(title_line_index);
+                if (row_title == null)
+                {
+                    return ("绗竴琛岀涓�鍒椾笉鑳界┖");
+                }
+
+                //寮�濮嬭鍙栫殑琛�
+                int start_line = title_line_index + 1;
+                var cell_0 = row_title.GetCell(0);
+                if (cell_0 == null)
+                {
+                    return ("鏃犳硶璇诲彇琛ㄥご鏂囦欢");
+                }
+                else if (cell_0.StringCellValue.Contains("搴忓彿"))
+                {
+                    col_index_x = 1;
+                    col_index_y = 2;
+                }
+                else if (cell_0.StringCellValue.Contains("娴侀噺"))
+                {
+                    col_index_x = 0;
+                    col_index_y = 1;
+                }
+
+                NPOI.SS.UserModel.IRow row_temp;
+                NPOI.SS.UserModel.ICell cell;
+
+                int line = 0;
+                for (line = start_line; line < 1000; line++)
+                {
+                    row_temp = sheet1.GetRow(line);
+                    if (row_temp == null)
+                        break;
+
+                    cell = row_temp.GetCell(col_index_x);
+                    if (cell == null)
+                        break;
+                    if (!ParseCellValue(cell, out double x))
+                        break;
+
+                    cell = row_temp.GetCell(col_index_y);
+                    if (cell == null)
+                        break;
+                    if (!ParseCellValue(cell, out double y))
+                        break;
+
+                    list.Add(new(x, y));
+                }
             }
-
-            //鏍囬琛�
-            int title_line_index = 0;
-            //x 鍒�
-            int col_index_x = 1;
-            //y 鍒�
-            int col_index_y = 2;
-
-            var row_title = sheet1.GetRow(title_line_index);
-            if (row_title == null)
+            catch (Exception ex)
             {
-                return ("绗竴琛岀涓�鍒椾笉鑳界┖");
+                return "鏂囦欢寮傚父!";
             }
-
-            //寮�濮嬭鍙栫殑琛�
-            int start_line = title_line_index + 1;
-            var cell_0 = row_title.GetCell(0);
-            if (cell_0 == null)
-            {
-                return ("鏃犳硶璇诲彇琛ㄥご鏂囦欢");
-            }
-            else if (cell_0.StringCellValue.Contains("搴忓彿"))
-            {
-                col_index_x = 1;
-                col_index_y = 2;
-            }
-            else if (cell_0.StringCellValue.Contains("娴侀噺"))
-            {
-                col_index_x = 0;
-                col_index_y = 1;
-            }
-
-            NPOI.SS.UserModel.IRow row_temp;
-            NPOI.SS.UserModel.ICell cell;
-
-            int line = 0;
-            for (line = start_line; line < 1000; line++)
-            {
-                row_temp = sheet1.GetRow(line);
-                if (row_temp == null)
-                    break;
-
-                cell = row_temp.GetCell(col_index_x);
-                if (cell == null)
-                    break;
-                if (!ParseCellValue(cell, out double x))
-                    break;
-
-                cell = row_temp.GetCell(col_index_y);
-                if (cell == null)
-                    break;
-                if (!ParseCellValue(cell, out double y))
-                    break;
-
-                list.Add(new(x, y));
-            }
-
             return "";
         }
 
@@ -160,160 +167,40 @@
             qh = new List<Geometry.Point2d>();
             qe = new List<Geometry.Point2d>();
             qp = new List<Geometry.Point2d>();
-
-            if (!File.Exists(fileName))
-                return "鏂囦欢涓嶅瓨鍦�";
-            int line = 0;
-
-            //鍒濆鍖栨枃浠�
-            NPOI.HSSF.UserModel.HSSFWorkbook theBook = null;
-            using (FileStream file = new FileStream(fileName, FileMode.Open, FileAccess.Read))
+            try
             {
-                theBook = new NPOI.HSSF.UserModel.HSSFWorkbook(file);
-            }
+                if (!File.Exists(fileName))
+                    return "鏂囦欢涓嶅瓨鍦�";
+                int line = 0;
 
-            //妫�鏌ヨ〃鏍兼槸鍚︾鍚�
-            NPOI.SS.UserModel.ISheet sheet1 = theBook.GetSheet("Sheet1");
-            if (sheet1 == null)
-            {
-                sheet1 = theBook.GetSheetAt(0);
+                //鍒濆鍖栨枃浠�
+                NPOI.HSSF.UserModel.HSSFWorkbook theBook = null;
+                using (FileStream file = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite))
+                {
+                    theBook = new NPOI.HSSF.UserModel.HSSFWorkbook(file);
+                }
+
+                //妫�鏌ヨ〃鏍兼槸鍚︾鍚�
+                NPOI.SS.UserModel.ISheet sheet1 = theBook.GetSheet("Sheet1");
                 if (sheet1 == null)
-                    return ("鏃燬heet鏁版嵁");
-            }
-
-            //鏍囬琛�
-            int title_line_index = 0;
-            //娴侀噺鍒�
-            int col_index_q = 1;
-            //鎵▼鍒�
-            int col_index_h = 2;
-            //鏁堢巼鍒�
-            int col_index_e = 3;
-            //鍔熺巼鍒�
-            int col_index_p = 4;
-
-            var row_title = sheet1.GetRow(title_line_index);
-            if (row_title == null)
-            {
-                return ("绗竴琛岀涓�鍒椾笉鑳界┖");
-            }
-
-            //寮�濮嬭鍙栫殑琛�
-            int start_line = title_line_index + 1;
-            var cell_0 = row_title.GetCell(0);
-            if (cell_0 == null)
-            {
-                return ("鏃犳硶璇诲彇琛ㄥご鏂囦欢");
-            }
-            else if (cell_0.StringCellValue.Contains("搴忓彿"))
-            {
-                col_index_q = 1;
-                col_index_h = 2;
-                col_index_e = 3;
-                col_index_p = 4;
-            }
-            else if (cell_0.StringCellValue.Contains("娴侀噺"))
-            {
-                col_index_q = 0;
-                col_index_h = 1;
-                col_index_e = 2;
-                col_index_p = 3;
-            }
-
-
-            NPOI.SS.UserModel.IRow row_temp = null;
-            NPOI.SS.UserModel.ICell cell;
-
-            var list = new List<(double Q, double H, double P, double E)>();
-            for (line = start_line; line < 1000; line++)
-            {
-
-                row_temp = sheet1.GetRow(line);
-                if (row_temp == null)
-                    break;
-
-                cell = row_temp.GetCell(col_index_q);
-                if (cell == null)
-                    break;
-                if (!ParseCellValue(cell, out double flow))
-                    break;
-                if (flow < 0)
-                    break;
-
-                cell = row_temp.GetCell(col_index_h);
-                if (cell == null)
-                    break;
-                if (!ParseCellValue(cell, out double head))
-                    break;
-                if (head < 0)
-                    break;
-
-                cell = row_temp.GetCell(col_index_e);
-                if (cell == null)
-                    break;
-                if (!ParseCellValue(cell, out double eff))
                 {
-                    eff = -1;
+                    sheet1 = theBook.GetSheetAt(0);
+                    if (sheet1 == null)
+                        return ("鏃燬heet鏁版嵁");
                 }
 
-
-                cell = row_temp.GetCell(col_index_p);
-                if (cell == null)
-                    break;
-                if (!ParseCellValue(cell, out double power))
-                {
-                    power = -1;
-                }
-
-                if (eff > 0)
-                {
-                    power = Yw.Pump.CalculationHelper.CalcuP(flow, head, eff);
-                }
-                else
-                {
-                    eff = Yw.Pump.CalculationHelper.CalcuE(flow, head, power);
-                }
-
-                if (eff > 99)
-                {
-                    throw new Exception("鏁堢巼澶т簬100%");
-                }
-
-                qh.Add(new Geometry.Point2d(flow, head));
-                qe.Add(new Geometry.Point2d(flow, eff));
-                qp.Add(new Geometry.Point2d(flow, power));
-            }
-
-            return "";
-        }
-
-        public static string ParseValveExcel(string fileName, out List<(Yw.Ahart.eCurveType CurveType, List<Yw.Geometry.Point2d> DefPointList, int Opening)> list)
-        {
-            list = new List<(Ahart.eCurveType CurveType, List<Geometry.Point2d> DefPointList, int Opening)>();
-            if (!File.Exists(fileName))
-                return "鏂囦欢涓嶅瓨鍦�";
-            int line = 0;
-
-            //鍒濆鍖栨枃浠�
-            NPOI.HSSF.UserModel.HSSFWorkbook theBook = null;
-            using (FileStream file = new(fileName, FileMode.Open, FileAccess.Read))
-                theBook = new NPOI.HSSF.UserModel.HSSFWorkbook(file);
-
-
-            //妫�鏌ヨ〃鏍兼槸鍚︾鍚�
-            NPOI.SS.UserModel.ISheet sheet_ql = theBook.GetSheet("娴侀噺鎹熷け");
-            if (sheet_ql != null)
-            {
                 //鏍囬琛�
                 int title_line_index = 0;
-                //寮�搴﹀垪
-                int col_index_opening = 0;
                 //娴侀噺鍒�
-                int col_index_flow = 1;
-                //姘村ご鎹熷け鍒�
-                int col_index_head_loss = 2;
+                int col_index_q = 1;
+                //鎵▼鍒�
+                int col_index_h = 2;
+                //鏁堢巼鍒�
+                int col_index_e = 3;
+                //鍔熺巼鍒�
+                int col_index_p = 4;
 
-                var row_title = sheet_ql.GetRow(title_line_index);
+                var row_title = sheet1.GetRow(title_line_index);
                 if (row_title == null)
                 {
                     return ("绗竴琛岀涓�鍒椾笉鑳界┖");
@@ -326,28 +213,34 @@
                 {
                     return ("鏃犳硶璇诲彇琛ㄥご鏂囦欢");
                 }
-            
+                else if (cell_0.StringCellValue.Contains("搴忓彿"))
+                {
+                    col_index_q = 1;
+                    col_index_h = 2;
+                    col_index_e = 3;
+                    col_index_p = 4;
+                }
+                else if (cell_0.StringCellValue.Contains("娴侀噺"))
+                {
+                    col_index_q = 0;
+                    col_index_h = 1;
+                    col_index_e = 2;
+                    col_index_p = 3;
+                }
 
 
                 NPOI.SS.UserModel.IRow row_temp = null;
                 NPOI.SS.UserModel.ICell cell;
 
-                var cell_value_list = new List<(double Opening, double Flow, double HeadLoss)>();
+                var list = new List<(double Q, double H, double P, double E)>();
                 for (line = start_line; line < 1000; line++)
                 {
-                    row_temp = sheet_ql.GetRow(line);
+
+                    row_temp = sheet1.GetRow(line);
                     if (row_temp == null)
                         break;
 
-                    cell = row_temp.GetCell(col_index_opening);
-                    if (cell == null)
-                        break;
-                    if (!ParseCellValue(cell, out double opening))
-                        break;
-                    if (opening < 0 || opening > 100)
-                        break;
-
-                    cell = row_temp.GetCell(col_index_flow);
+                    cell = row_temp.GetCell(col_index_q);
                     if (cell == null)
                         break;
                     if (!ParseCellValue(cell, out double flow))
@@ -355,91 +248,222 @@
                     if (flow < 0)
                         break;
 
-                    cell = row_temp.GetCell(col_index_head_loss);
+                    cell = row_temp.GetCell(col_index_h);
                     if (cell == null)
                         break;
-                    if (!ParseCellValue(cell, out double head_loss))
+                    if (!ParseCellValue(cell, out double head))
                         break;
-                    if (head_loss < 0)
+                    if (head < 0)
                         break;
 
-                    cell_value_list.Add((opening, flow, head_loss));
+                    cell = row_temp.GetCell(col_index_e);
+                    if (cell == null)
+                        break;
+                    if (!ParseCellValue(cell, out double eff))
+                    {
+                        eff = -1;
+                    }
+
+
+                    cell = row_temp.GetCell(col_index_p);
+                    if (cell == null)
+                        break;
+                    if (!ParseCellValue(cell, out double power))
+                    {
+                        power = -1;
+                    }
+
+                    if (eff > 0)
+                    {
+                        power = Yw.Pump.CalculationHelper.CalcuP(flow, head, eff);
+                    }
+                    else
+                    {
+                        eff = Yw.Pump.CalculationHelper.CalcuE(flow, head, power);
+                    }
+
+                    if (eff > 99)
+                    {
+                        throw new Exception("鏁堢巼澶т簬100%");
+                    }
+
+                    qh.Add(new Geometry.Point2d(flow, head));
+                    qe.Add(new Geometry.Point2d(flow, eff));
+                    qp.Add(new Geometry.Point2d(flow, power));
                 }
 
-                var opening_group = cell_value_list.GroupBy(x => x.Opening);
-                foreach (var item in opening_group)
-                {
-                    var pt_list = item.Select(x => new Yw.Geometry.Point2d(x.Flow, x.HeadLoss));
-                    list.Add((Yw.Ahart.eCurveType.QL, pt_list.ToList(), (int)item.Key));
-                }
+                return "";
+
             }
-
-
-            //妫�鏌ヨ〃鏍兼槸鍚︾鍚�
-            NPOI.SS.UserModel.ISheet sheet_ol = theBook.GetSheet("寮�搴︽崯澶�");
-            if (sheet_ol != null)
+            catch (Exception ex)
             {
-                //鏍囬琛�
-                int title_line_index = 0;
-                //寮�搴﹀垪
-                int col_index_opening = 0;
-                //鎹熷け绯绘暟鍒�
-                int col_index_k = 1;
-
-                var row_title = sheet_ol.GetRow(title_line_index);
-                if (row_title == null)
-                {
-                    return ("绗竴琛岀涓�鍒椾笉鑳界┖");
-                }
-
-                //寮�濮嬭鍙栫殑琛�
-                int start_line = title_line_index + 1;
-                var cell_0 = row_title.GetCell(0);
-                if (cell_0 == null)
-                {
-                    return ("鏃犳硶璇诲彇琛ㄥご鏂囦欢");
-                }
-              
-
-
-                NPOI.SS.UserModel.IRow row_temp = null;
-                NPOI.SS.UserModel.ICell cell;
-
-                var pt_list = new List<Yw.Geometry.Point2d>();
-                for (line = start_line; line < 1000; line++)
-                {
-                    row_temp = sheet_ol.GetRow(line);
-                    if (row_temp == null)
-                        break;
-
-                    cell = row_temp.GetCell(col_index_opening);
-                    if (cell == null)
-                        break;
-                    if (!ParseCellValue(cell, out double opening))
-                        break;
-                    if (opening < 0 || opening > 100)
-                        break;
-
-                    cell = row_temp.GetCell(col_index_k);
-                    if (cell == null)
-                        break;
-                    if (!ParseCellValue(cell, out double k))
-                        break;
-                    if (k < 0)
-                        break;
-
-                    pt_list.Add(new Geometry.Point2d(opening, k));
-                }
-
-                list.Add((Yw.Ahart.eCurveType.OL, pt_list.ToList(), 100));
+                return "鏂囦欢寮傚父!";
             }
+        }
 
-            if (list == null || !list.Any())
+        public static string ParseValveExcel(string fileName, out List<(Yw.Ahart.eCurveType CurveType, List<Yw.Geometry.Point2d> DefPointList, int Opening)> list)
+        {
+            list = new List<(Ahart.eCurveType CurveType, List<Geometry.Point2d> DefPointList, int Opening)>();
+            try
             {
-                return ("琛ㄦ牸涓嶇鍚堟牸寮�");
-            }
+                if (!File.Exists(fileName))
+                    return "鏂囦欢涓嶅瓨鍦�";
+                int line = 0;
 
-            return "";
+                //鍒濆鍖栨枃浠�
+                NPOI.HSSF.UserModel.HSSFWorkbook theBook = null;
+                using (FileStream file = new(fileName, FileMode.Open, FileAccess.ReadWrite))
+                    theBook = new NPOI.HSSF.UserModel.HSSFWorkbook(file);
+
+
+                //妫�鏌ヨ〃鏍兼槸鍚︾鍚�
+                NPOI.SS.UserModel.ISheet sheet_ql = theBook.GetSheet("娴侀噺鎹熷け");
+                if (sheet_ql != null)
+                {
+                    //鏍囬琛�
+                    int title_line_index = 0;
+                    //寮�搴﹀垪
+                    int col_index_opening = 0;
+                    //娴侀噺鍒�
+                    int col_index_flow = 1;
+                    //姘村ご鎹熷け鍒�
+                    int col_index_head_loss = 2;
+
+                    var row_title = sheet_ql.GetRow(title_line_index);
+                    if (row_title == null)
+                    {
+                        return ("绗竴琛岀涓�鍒椾笉鑳界┖");
+                    }
+
+                    //寮�濮嬭鍙栫殑琛�
+                    int start_line = title_line_index + 1;
+                    var cell_0 = row_title.GetCell(0);
+                    if (cell_0 == null)
+                    {
+                        return ("鏃犳硶璇诲彇琛ㄥご鏂囦欢");
+                    }
+
+
+
+                    NPOI.SS.UserModel.IRow row_temp = null;
+                    NPOI.SS.UserModel.ICell cell;
+
+                    var cell_value_list = new List<(double Opening, double Flow, double HeadLoss)>();
+                    for (line = start_line; line < 1000; line++)
+                    {
+                        row_temp = sheet_ql.GetRow(line);
+                        if (row_temp == null)
+                            break;
+
+                        cell = row_temp.GetCell(col_index_opening);
+                        if (cell == null)
+                            break;
+                        if (!ParseCellValue(cell, out double opening))
+                            break;
+                        if (opening < 0 || opening > 100)
+                            break;
+
+                        cell = row_temp.GetCell(col_index_flow);
+                        if (cell == null)
+                            break;
+                        if (!ParseCellValue(cell, out double flow))
+                            break;
+                        if (flow < 0)
+                            break;
+
+                        cell = row_temp.GetCell(col_index_head_loss);
+                        if (cell == null)
+                            break;
+                        if (!ParseCellValue(cell, out double head_loss))
+                            break;
+                        if (head_loss < 0)
+                            break;
+
+                        cell_value_list.Add((opening, flow, head_loss));
+                    }
+
+                    var opening_group = cell_value_list.GroupBy(x => x.Opening);
+                    foreach (var item in opening_group)
+                    {
+                        var pt_list = item.Select(x => new Yw.Geometry.Point2d(x.Flow, x.HeadLoss));
+                        list.Add((Yw.Ahart.eCurveType.QL, pt_list.ToList(), (int)item.Key));
+                    }
+                }
+
+
+                //妫�鏌ヨ〃鏍兼槸鍚︾鍚�
+                NPOI.SS.UserModel.ISheet sheet_ol = theBook.GetSheet("寮�搴︽崯澶�");
+                if (sheet_ol != null)
+                {
+                    //鏍囬琛�
+                    int title_line_index = 0;
+                    //寮�搴﹀垪
+                    int col_index_opening = 0;
+                    //鎹熷け绯绘暟鍒�
+                    int col_index_k = 1;
+
+                    var row_title = sheet_ol.GetRow(title_line_index);
+                    if (row_title == null)
+                    {
+                        return ("绗竴琛岀涓�鍒椾笉鑳界┖");
+                    }
+
+                    //寮�濮嬭鍙栫殑琛�
+                    int start_line = title_line_index + 1;
+                    var cell_0 = row_title.GetCell(0);
+                    if (cell_0 == null)
+                    {
+                        return ("鏃犳硶璇诲彇琛ㄥご鏂囦欢");
+                    }
+
+
+
+                    NPOI.SS.UserModel.IRow row_temp = null;
+                    NPOI.SS.UserModel.ICell cell;
+
+                    var pt_list = new List<Yw.Geometry.Point2d>();
+                    for (line = start_line; line < 1000; line++)
+                    {
+                        row_temp = sheet_ol.GetRow(line);
+                        if (row_temp == null)
+                            break;
+
+                        cell = row_temp.GetCell(col_index_opening);
+                        if (cell == null)
+                            break;
+                        if (!ParseCellValue(cell, out double opening))
+                            break;
+                        if (opening < 0 || opening > 100)
+                            break;
+
+                        cell = row_temp.GetCell(col_index_k);
+                        if (cell == null)
+                            break;
+                        if (!ParseCellValue(cell, out double k))
+                            break;
+                        if (k < 0)
+                            break;
+
+                        pt_list.Add(new Geometry.Point2d(opening, k));
+                    }
+
+                    if (pt_list.Any())
+                        list.Add((Yw.Ahart.eCurveType.OL, pt_list.ToList(), 100));
+                }
+
+                if (list == null || !list.Any())
+                {
+                    return ("琛ㄦ牸涓嶇鍚堟牸寮�");
+                }
+
+                return "";
+
+
+            }
+            catch (Exception ex)
+            {
+                return "鏂囦欢寮傚父!";
+            }
         }
 
         private static bool ParseCellValue(NPOI.SS.UserModel.ICell cell, out double cell_value)
@@ -464,5 +488,6 @@
         }
 
         #endregion
+
     }
 }

--
Gitblit v1.9.3