Browse Source

Handle the error issue of blank selection of elements in zero-element rules

cxs 2 weeks ago
parent
commit
4bd731078b
1 changed files with 24 additions and 22 deletions
  1. 24 22
      OTSPartA_STDEditor/UI/Form_ZeroElementRules.cs

+ 24 - 22
OTSPartA_STDEditor/UI/Form_ZeroElementRules.cs

@@ -30,7 +30,7 @@ namespace OTSPartA_STDEditor
         {
             InitializeComponent();
             STDDBAddress = DBAddress;
-                                                                                                                                                                            
+
             X = this.Width;
             Y = this.Height;
             setTag(this);
@@ -110,14 +110,14 @@ namespace OTSPartA_STDEditor
                 PeriodicTableSwitch.Text = "元素周期表";
             }
 
-            
+
 
             Size size = Screen.PrimaryScreen.WorkingArea.Size;
             Left = (size.Width - Width) / 2;
             Top = (size.Height - Height) / 2;
             WindowState = FormWindowState.Normal;
 
-           
+
 
             //panel_OTSPeriodicTable.Visible = true;
             //this.Width = this.Width - panel_OTSPeriodicTable.Width - 5;
@@ -130,12 +130,12 @@ namespace OTSPartA_STDEditor
                 XmlTree_ZeroElementRules_AfterSelect(XmlTree_ZeroElementRules, new TreeViewEventArgs(XmlTree_ZeroElementRules.SelectedNode));
             }
 
-          
+
 
         }
 
 
-        
+
 
         void LoadZeroElementRulesToTreeControl(string DBAddress, TreeNodeCollection XmlTree_ZeroElementRules)
         {
@@ -384,7 +384,8 @@ namespace OTSPartA_STDEditor
             }
         }
 
-        //新建
+        
+
         private void AddTreeNode_Click(object sender, EventArgs e)
         {
             try
@@ -411,13 +412,11 @@ namespace OTSPartA_STDEditor
                     XmlTree_ZeroElementRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
                 }
 
-                TreeNode new_child = new TreeNode();//定义一个TreeNode节点对象
-                TreeView XmlTree = (TreeView)XmlTreeMenuStrip.SourceControl;
 
 
 
 
-                
+
                 if (XmlTreeMenuStrip.SourceControl.Name == "XmlTree_ZeroElementRules")
                 {
                     //打开编辑元素列表窗体
@@ -428,20 +427,23 @@ namespace OTSPartA_STDEditor
                     //----------------------------------------------------------------------------------------
                     opts.StartPosition = FormStartPosition.CenterScreen;
                     opts.ShowDialog();
-
-                    List<string> PeriodicFH = new List<string>();
-                    for (int j = 0; j < opts.m_List_Periodic.Count; j++)
+                    if (opts.m_List_Periodic.Count > 0)
                     {
-                        PeriodicFH.Add(opts.m_List_Periodic[j].Symbol);
+                        TreeNode new_child = new TreeNode();//定义一个TreeNode节点对象
+                        TreeView XmlTree = (TreeView)XmlTreeMenuStrip.SourceControl;
+                        List<string> PeriodicFH = new List<string>();
+                        for (int j = 0; j < opts.m_List_Periodic.Count; j++)
+                        {
+                            PeriodicFH.Add(opts.m_List_Periodic[j].Symbol);
+                        }
+                        new_child.Text = opts.m_List_Periodic[0].Symbol + "=0";
+                        new_child.Tag = opts.m_List_Periodic[0].Symbol + ">0";
+                        textbox_STDEditor.Text = opts.m_List_Periodic[0].Symbol + ">0";
+                        XmlTree.Nodes.Add(new_child);
+                        XmlTree.SelectedNode = null;
+                        XmlTree.SelectedNode = new_child;
                     }
-                    new_child.Text = opts.m_List_Periodic[0].Symbol+"=0";
-                    new_child.Tag = opts.m_List_Periodic[0].Symbol + ">0";
-                    textbox_STDEditor.Text = opts.m_List_Periodic[0].Symbol + ">0";
                 }
-
-                XmlTree.Nodes.Add(new_child);
-                XmlTree.SelectedNode = null;
-                XmlTree.SelectedNode = new_child;
             }
             catch (Exception ex)
             {
@@ -449,7 +451,7 @@ namespace OTSPartA_STDEditor
             }
         }
 
-  
+
         void SaveXmlTreeDataToZeroElementRules(string DBAddress)
         {
             System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + DBAddress + "'");
@@ -1171,7 +1173,7 @@ namespace OTSPartA_STDEditor
         {
             foreach (Control con in cons.Controls)
             {
-                if(con.Name== "Form_ZeroElementRules")
+                if (con.Name == "Form_ZeroElementRules")
                 {
                     continue;
                 }