Browse Source

修改 参照库 组分类不存在报错的bug

cxs 2 years ago
parent
commit
4ea48f8a65
1 changed files with 30 additions and 4 deletions
  1. 30 4
      OTSPartA_STDEditor/ReferenceLibrary.cs

+ 30 - 4
OTSPartA_STDEditor/ReferenceLibrary.cs

@@ -19,7 +19,7 @@ namespace OTSPartA_STDEditor
         List<STDEditor.STDXray> ReferenceXrayList = null;
         byte[] ReferencexrayByteData = null;
         System.Collections.Hashtable table_ReferenceLibrary;
-
+        Dictionary<int, string> ReferenceGroup = new Dictionary<int, string>();
 
         public ReferenceLibrary(SubMidWindow SubMidWindow)
         {
@@ -136,6 +136,7 @@ namespace OTSPartA_STDEditor
                             new_STDdata.KeyElementList = item["KeyElementList"].ToString();
                             new_STDdata.SubElementList = item["SubElementList"].ToString();
                             new_STDdata.GroupId = item["GroupId"].ToString();
+
                             STDDictionary.Add(int.Parse(item["STDId"].ToString()), new_STDdata);
                         }
                     }
@@ -159,9 +160,25 @@ namespace OTSPartA_STDEditor
                         }
                     }
                 }
+
+                System.Data.SQLite.SQLiteDataAdapter m_dataAdapterGroup = new System.Data.SQLite.SQLiteDataAdapter("select Id,name from STDGroups", m_dbConnection);
+                DataSet dsGroup = new DataSet();
+                m_dataAdapterGroup.Fill(dsGroup);
+                DataTable dtGroup = dsGroup.Tables[0];
+                if (dtGroup != null)
+                {
+                    if (dtGroup.Rows.Count > 0)
+                    {
+                        foreach (DataRow item in dtGroup.Rows)
+                        {
+                            ReferenceGroup.Add(int.Parse(item["Id"].ToString()), item["name"].ToString());
+                        }
+                    }
+                }
+
                 return true;
             }
-            catch /*(Exception ee)*/
+            catch (Exception ee)
             {
                 MessageBox.Show("Reference library format error, please open the correct reference library!", "Tip");
 
@@ -207,7 +224,7 @@ namespace OTSPartA_STDEditor
                 PropGrid[i, 8] = new SourceGrid.Cells.Cell(kv.Value.BSE, typeof(string));
                 PropGrid[i, 9] = new SourceGrid.Cells.Cell(kv.Value.Formula, typeof(string));
                 PropGrid[i, 10] = new SourceGrid.Cells.Cell(kv.Value.Element, typeof(string));
-                PropGrid[i, 11] = new SourceGrid.Cells.Cell(m_SubMidWindow.m_MainForm.GroupIdDictionaryFromId[int.Parse(kv.Value.GroupId)], typeof(string));
+                PropGrid[i, 11] = new SourceGrid.Cells.Cell(ReferenceGroup[int.Parse(kv.Value.GroupId)], typeof(string));
                 i++;
             }
 
@@ -465,6 +482,10 @@ namespace OTSPartA_STDEditor
                 }
 
             }
+            else
+            {
+                AddIntoMainLab();
+            }
         }
 
         #region 因为复制容易引起用户误操作,故取消
@@ -538,7 +559,12 @@ namespace OTSPartA_STDEditor
             sT.SubElementList = ReferenceDictionary[STDnum].SubElementList;
             sT.Electrical_conductivity = ReferenceDictionary[STDnum].Electrical_conductivity;
             sT.Element = ReferenceDictionary[STDnum].Element;
-            sT.GroupId = ReferenceDictionary[STDnum].GroupId;
+            if (m_SubMidWindow.m_MainForm.GroupIdDictionaryFromId.ContainsKey(int.Parse(ReferenceDictionary[STDnum].GroupId)))
+            { sT.GroupId = ReferenceDictionary[STDnum].GroupId; }
+            else
+            {
+                MessageBox.Show("As this classification group is not defined, it has been adjusted to the default grouping!");
+            }
 
             m_SubMidWindow.m_MainForm.STDDictionary.Add(STDId + 1, sT);