فهرست منبع

报告重复样品名称添加

CXS 3 سال پیش
والد
کامیت
6bce2affb0
1فایلهای تغییر یافته به همراه34 افزوده شده و 12 حذف شده
  1. 34 12
      OTSIncAReportApp/2-CommonFunction/OTSDataMgrFunction/ResultDataMgr.cs

+ 34 - 12
OTSIncAReportApp/2-CommonFunction/OTSDataMgrFunction/ResultDataMgr.cs

@@ -80,44 +80,66 @@ namespace OTSIncAReportApp.OTSDataMgrFunction
         }
         public bool AddDataResult(string str_path)
         {
-               
-            if (str_path == "")
-            {
-                return false;
-            }
-
             //加载测量结果文件
             Dictionary<string, object> suggestions = DataOperation.DataAccess.XMLoperate.GetXMLAllInfo(str_path);
 
             string name = System.IO.Path.GetFileName(str_path);
             int workingid = (ResultFileId++);
             string path = System.IO.Path.GetDirectoryName(str_path);
-            if (ResultFilesList.Find(s => s.FileName == name) != null)
+            if (ResultFilesList.Find(s => s.FilePath == path) != null)
+            {
+                MessageBox.Show("Already have the same result!");
+                return false;
+            }
+            string strname = UpdateName(name, ResultFilesList);
+            if (strname == "")
             {
                 MessageBox.Show("Already have the same result!");
                 return false;
             }
 
+
             DataOperation.Model.ResultFile result = new DataOperation.Model.ResultFile()
             {
                 FileId = workingid.ToString(),
-                FileName = name,
+                FileName = strname,
                 FilePath = path,
                 ResultInfo = suggestions
             };
             ResultFilesList.Add(result);
-          
+
             SetWorkingResult(ResultFilesList.IndexOf(result));
-          
+
             FieldData fieldData = new FieldData(path);
             List<Field> fieldlist = fieldData.GetFieldList();
             CurResultFile.List_OTSField = fieldlist;
-          
 
-           
+
+
             return true;
         }
 
+        private string UpdateName(string name, List<ResultFile> ResultFilesList)
+        {
+            int reg = 51;
+            if (ResultFilesList.Find(s => s.FileName == name) != null)
+            {
+                for (int i = 1; i < reg; i++)
+                {
+                    string str = name.Split('.')[0].ToString() + "(" + i.ToString() + ")" + name.Split('.')[1].ToString();
+                    if (ResultFilesList.Find(s => s.FileName == str) == null)
+                    {
+                        return name.Split('.')[0].ToString() + "(" + i.ToString() + ")" + name.Split('.')[1].ToString();
+
+                    }
+                }
+            }
+            else
+            {
+                return name;
+            }
+            return "";
+        }
         #endregion
 
         #region 获取组合项相关方法