Sfoglia il codice sorgente

编辑器删除rule的视图

cxs 3 mesi fa
parent
commit
8d09c82b8c

+ 1 - 0
Bin/x64/Debug/Resources/XMLData/AppResource_ZH.xml

@@ -960,6 +960,7 @@
 	  <Control name="InclusionAreaRatio" text="颗粒面积比" />
 	  <Control name="IncaAreascale" text="颗粒面积比" />
 	  <Control name="InitialRatingLevel" text="起评级别" />
+	  <Control name="classifyGroupDisplay" text="按组显示图" />
     </Controls>
  </Form>
  <Form>

+ 19 - 16
OTSPartA_STDEditor/BaseClass/STDInfo.cs

@@ -132,7 +132,7 @@ namespace OTSPartA_STDEditor.BaseClass
                     STDGroups new_data = new STDGroups();
                     new_data.name = "Default";
                     new_data.color = "#C9C9C9";
-                    new_data.iorder = 999;
+                    new_data.iorder = 10000;
                     GroupDictionary.Add(0, new_data);
                     if (dt.Select("id='0'").Length == 0)
                     {
@@ -240,7 +240,7 @@ namespace OTSPartA_STDEditor.BaseClass
                 return false;
             }
         }
-        public int AddSTDDictionaryItem()
+        public STDdata AddSTDDictionaryItem()
         {
             STDdata new_STDdata = new STDdata();//定义一个TreeNode节点对象
             new_STDdata.Hardness = "1";
@@ -255,18 +255,8 @@ namespace OTSPartA_STDEditor.BaseClass
             new_STDdata.SubElementList = "";
             Random random = new Random();
             new_STDdata.Color = ColorGroup[random.Next(ColorGroup.Length)];
-            int STDId = 40000;
-            foreach (KeyValuePair<int, STDdata> kv in STDDictionary)
-            {
-                if (STDId < kv.Key)
-                {
-                    STDId = kv.Key;
-                }
-            }
-
-            new_STDdata.STDId=STDId + 1;
-            STDDictionary.Add(STDId + 1, new_STDdata);
-            return STDId + 1;
+            
+            return new_STDdata;
         }
         object Clone(Dictionary<int, STDdata> STDDictionary)
         {
@@ -461,8 +451,12 @@ namespace OTSPartA_STDEditor.BaseClass
                     newRow["id"] = kv.id;
                     newRow["name"] = kv.name;
                     newRow["color"] = kv.color;
-
                     newRow["iorder"] = kv.iorder;
+                    if (kv.name == "Default")
+                    {
+                        newRow["iorder"] = 10000;
+                        newRow["color"] = "#C9C9C9";
+                    }
                     dt_grp.Rows.Add(newRow);
                 }
                 m_dataAdapter_grp.Update(ds_grp, "STDGroups");
@@ -477,6 +471,12 @@ namespace OTSPartA_STDEditor.BaseClass
         }
 
 
+
+
+
+
+
+
         public bool SaveAsDictionaryToClassify(string DBAddress)
         {
             ////保存列表顺序
@@ -645,8 +645,11 @@ namespace OTSPartA_STDEditor.BaseClass
                     newRow["id"] = kv.id;
                     newRow["name"] = kv.name;
                     newRow["color"] = kv.color;
-
                     newRow["iorder"] = 0;
+                    if (kv.name == "Default")
+                    {
+                        newRow["iorder"] = 10000;
+                    }
                     dt_grp.Rows.Add(newRow);
                 }
                 m_dataAdapter_grp.Update(ds_grp, "STDGroups");

+ 18 - 28
OTSPartA_STDEditor/UI/Attributes.cs

@@ -37,13 +37,8 @@ namespace OTSPartA_STDEditor
                 return System.Drawing.Color.FromArgb(255, 255, 204);
             }
         }
-        /// <summary>
-        /// [颜色:RGB转成16进制]
-        /// </summary>
-        /// <param name="R">红 int</param>
-        /// <param name="G">绿 int</param>
-        /// <param name="B">蓝 int</param>
-        /// <returns></returns>
+
+
         public static string colorRGBtoHx16(int R, int G, int B)
         {
             return System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.FromArgb(R, G, B));
@@ -75,15 +70,23 @@ namespace OTSPartA_STDEditor
         private void EditorEvent_EditEnded(object sender, EventArgs e)
         {
             SourceGrid.CellContext context = (SourceGrid.CellContext)sender;
-            //if(Grid_Attributes[context.Position.Row, context.Position.Column].Value==null)
-            //{
-            //    MessageBox.Show("The name of rule cannot be null!", "warnning");
-            //    return;
-            //}
+            
             m_MainForm.ChangeSTDRuleName(Convert.ToString( Grid_Attributes[context.Position.Row, context.Position.Column].Value));
         }
 
 
+
+
+
+
+
+
+
+
+
+
+        
+        
         private class MyHeader : SourceGrid.Cells.ColumnHeader
         {
             public MyHeader(object value) : base(value)
@@ -198,15 +201,12 @@ namespace OTSPartA_STDEditor
 
             AddSTDGroupsToAttribute();
             Grid_Attributes.Selection.FocusStyle = SourceGrid.FocusStyle.None;
-            //SourceGrid.Position po = new SourceGrid.Position(1, 0);
-            //Grid_Attributes[1, 0].Grid.Select();
-            //Grid_Attributes.Selection.Focus(po, true);
         }
 
-        public void SetDatatoGrid_Attributes(int STDId)
+        public void SetDatatoGrid_Attributes(STDdata ddata)
         {
-            STDdata sTDdata = m_MainForm._sTDEditor.STDDictionary[STDId];
-            Grid_Attributes[1, 1].Value = STDId;
+            STDdata sTDdata = ddata;
+            Grid_Attributes[1, 1].Value = sTDdata.STDId;
             Grid_Attributes[2, 1].Value = sTDdata.StrName;
             SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
             view.BackColor = colorHx16toRGB(sTDdata.Color);
@@ -220,13 +220,8 @@ namespace OTSPartA_STDEditor
             Grid_Attributes[9, 1].Value = sTDdata.Formula;
             Grid_Attributes[10, 1].Value = sTDdata.Element;
 
-            //m_MainForm.AddSTDGroupsToAttribute();
             Grid_Attributes[11, 1].Value = m_MainForm._sTDEditor.GroupIdDictionaryFromId[sTDdata.GroupId];
 
-            //SourceGrid.Position po = new SourceGrid.Position(1, 0);
-            //Grid_Attributes[1, 0].Grid.Select();
-            //Grid_Attributes.Selection.Focus(po, true);
-
             Grid_Attributes.Refresh();
         }
 
@@ -246,13 +241,8 @@ namespace OTSPartA_STDEditor
             Grid_Attributes[9, 1].Value = sTDdata.Formula;
             Grid_Attributes[10, 1].Value = sTDdata.Element;
 
-            //m_MainForm.AddSTDGroupsToAttribute();
             Grid_Attributes[11, 1].Value = m_MainForm._sTDEditor.GroupIdDictionaryFromId[sTDdata.GroupId];
 
-            //SourceGrid.Position po = new SourceGrid.Position(1, 0);
-            //Grid_Attributes[1, 0].Grid.Select();
-            //Grid_Attributes.Selection.Focus(po, true);
-
             Grid_Attributes.Refresh();
         }
 

+ 177 - 192
OTSPartA_STDEditor/UI/Form_Main.cs

@@ -10,6 +10,7 @@ using System.Linq;
 using System.Windows.Forms;
 using System.Xml;
 using System.Xml.Linq;
+using static System.Windows.Forms.VisualStyles.VisualStyleElement;
 
 namespace OTSPartA_STDEditor
 {
@@ -59,40 +60,46 @@ namespace OTSPartA_STDEditor
                 this.Text = this.Text.Split(' ')[0] + "   " + STDDBAddress;
                 IsModified = false;
 
-                if (ImportArgs.Count > 1)
-                {
-                    ImportStandardLibraryTypeSelection m_importStandardLibraryTypeSelection = new ImportStandardLibraryTypeSelection();
-                    var result = m_importStandardLibraryTypeSelection.ShowDialog();
-                    if (m_importStandardLibraryTypeSelection.SelectEvent == "expression")
-                    {
-                        int STDId = _sTDEditor.AddSTDDictionaryItem();
-                        m_STDRuleslist.AddNewRow(STDId, "NewClassify", Attributes.colorHx16toRGB(_sTDEditor.STDDictionary[STDId].Color));
-                    }
-                }
+                //if (ImportArgs.Count > 1)
+                //{
+                //    ImportStandardLibraryTypeSelection m_importStandardLibraryTypeSelection = new ImportStandardLibraryTypeSelection();
+                //    var result = m_importStandardLibraryTypeSelection.ShowDialog();
+                //    if (m_importStandardLibraryTypeSelection.SelectEvent == "expression")
+                //    {
+                //        int STDId = _sTDEditor.AddSTDDictionaryItem();
+                //        m_STDRuleslist.AddNewRow(STDId, "NewClassify", Attributes.colorHx16toRGB(ddata.Color));
+                //    }
+                //}
             }
         }
 
-        public void ChangeSTDEditorAndGrid_Attributes(int STDId)
+        public void ChangeSTDEditorAndGrid_Attributes(STDdata ddata)
         {
-            m_SubMidWindow.ChangeText_textbox_STDEditor(STDId);
-            m_Attributes.SetDatatoGrid_Attributes(STDId);
+            m_SubMidWindow.ChangeText_textbox_STDEditor(ddata);
+            m_Attributes.SetDatatoGrid_Attributes(ddata);
         }
 
 
+
+
+
+
+
+
+
+
+
         private void rbBackup_Click(object sender, EventArgs e)
         {
-            if (m_STDRuleslist.tabControl1.SelectedIndex == 0)
+            if (m_STDRuleslist.treeView_G.SelectedNode != null && m_STDRuleslist.treeView_G.SelectedNode.Level == 1)
             {
-                m_STDRuleslist.ConvertToRuleViewDic();
-            }
-            else
-            {
-                if (m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row > 0)
+                STDdata sTDdata = (STDdata)m_STDRuleslist.treeView_G.SelectedNode.Tag;
+                if (sTDdata != null)
                 {
-                    STDdata sTDdata = (STDdata)m_STDRuleslist.Grid_Minerals[m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0].Tag;
                     SaveDataOfSelRule(sTDdata.STDId);
                 }
             }
+            m_STDRuleslist.ConvertToRuleViewDic();
             try
             {
                 SaveFileDialog saveFile = new SaveFileDialog();
@@ -137,20 +144,22 @@ namespace OTSPartA_STDEditor
                 MessageBox.Show(ex.Message);
             }
         }
+
+
+
+
+
         private void rbSave_Click(object sender, EventArgs e)
         {
-            if (m_STDRuleslist.tabControl1.SelectedIndex == 0)
+            if (m_STDRuleslist.treeView_G.SelectedNode != null && m_STDRuleslist.treeView_G.SelectedNode.Level == 1)
             {
-                m_STDRuleslist.ConvertToRuleViewDic();
-            }
-            else
-            {
-                if (m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row > 0)
+                STDdata sTDdata = (STDdata)m_STDRuleslist.treeView_G.SelectedNode.Tag;
+                if (sTDdata != null)
                 {
-                    STDdata sTDdata = (STDdata)m_STDRuleslist.Grid_Minerals[m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0].Tag;
                     SaveDataOfSelRule(sTDdata.STDId);
                 }
             }
+            m_STDRuleslist.ConvertToRuleViewDic();
             if (Ruleformatcheck())
             {
                 FormForWaiting forWaiting = new FormForWaiting();
@@ -185,20 +194,19 @@ namespace OTSPartA_STDEditor
                 }
                 else
                 {
-                    int Id = 0;
-                    for (int i = 1; i < m_STDRuleslist.Grid_Minerals.RowsCount; i++)
+                    foreach (TreeNode treeNode in m_STDRuleslist.treeView_G.Nodes)
                     {
-                        if(((STDdata)m_STDRuleslist.Grid_Minerals[i, 0].Tag).STDId == ite.Key)
+                        foreach (TreeNode treeNode1 in treeNode.Nodes)
                         {
-                            Id = i;break;
+                            if (((STDdata)treeNode1.Tag).STDId == ite.Key)
+                            {
+                                m_STDRuleslist.treeView_G.SelectedNode = treeNode1;
+                                ChangeSTDEditorAndGrid_Attributes(ite.Value);
+                                m_STDRuleslist.Predata = ite.Value;
+                                break;
+                            }
                         }
                     }
-                    Position pos = new Position(Id, 0);
-                    m_STDRuleslist.Grid_Minerals[Id, 0].Grid.Select();
-                    m_STDRuleslist.Grid_Minerals.Selection.Focus(pos, true);
-                    m_STDRuleslist.Grid_Minerals.Refresh();
-                    ChangeSTDEditorAndGrid_Attributes(ite.Key);
-                    m_STDRuleslist.Predata = ite.Value;
                     return false;
                 }
             }
@@ -392,104 +400,81 @@ namespace OTSPartA_STDEditor
             {
                 MessageBox.Show("Rule name can not be null !", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
-            //if (string.IsNullOrEmpty(ddata.g)
-            //{
-            //    if (!GroupIdDictionaryFromName.ContainsKey(m_Attributes.Grid_Attributes[11, 1].Value.ToString()))
-            //    {
-            //        Position pos = new Position(11, 1);
-            //        m_Attributes.Grid_Attributes.Selection.Focus(pos, true);
-            //        MessageBox.Show("This group name is not included, please fill in again!", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
-            //        return false;
-            //    }
-            //}
-            #region 化学式和元素暂无限制
-            //if (m_Attributes.Grid_Attributes[7, 1].Value.ToString())
-            //{
-            //    Position pos = new Position(7, 1);
-            //    m_Attributes.Grid_Attributes.Selection.Focus(pos, true);
-            //    MessageBox.Show(table["message10"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
-            //    return false;
-            //}
-
-            //if (m_Attributes.Grid_Attributes[8, 1].Value.ToString())
-            //{
-            //    Position pos = new Position(8, 1);
-            //    m_Attributes.Grid_Attributes.Selection.Focus(pos, true);
-            //    MessageBox.Show(table["message10"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
-            //    return false;
-            //}
-            #endregion
             return true;
         }
-
-
-
-
-
-
         public void SaveDataOfSelRule(int stdid)
         {
-            _sTDEditor.STDDictionary[stdid].StrName = Convert.ToString(m_Attributes.Grid_Attributes[2, 1].Value);
-            _sTDEditor.STDDictionary[stdid].Color = colorRGBtoHx16(m_Attributes.Grid_Attributes[3, 1].View.BackColor.R, m_Attributes.Grid_Attributes[3, 1].View.BackColor.G, m_Attributes.Grid_Attributes[3, 1].View.BackColor.B);
-            _sTDEditor.STDDictionary[stdid].IfElementAnalysis = Convert.ToBoolean(m_Attributes.Grid_Attributes[4, 1].Value);
-            _sTDEditor.STDDictionary[stdid].Hardness = Convert.ToString(m_Attributes.Grid_Attributes[5, 1].Value);
-            _sTDEditor.STDDictionary[stdid].Density = Convert.ToString(m_Attributes.Grid_Attributes[6, 1].Value);
-            _sTDEditor.STDDictionary[stdid].Electrical_conductivity = Convert.ToString(m_Attributes.Grid_Attributes[7, 1].Value);
-            _sTDEditor.STDDictionary[stdid].BSE = Convert.ToString(m_Attributes.Grid_Attributes[8, 1].Value);
+            foreach (int grpid in m_STDRuleslist.GroupViewDic.Keys)
+            {
+                foreach (STDdata ddata in m_STDRuleslist.GroupViewDic[grpid].ContainSTD)
+                {
+                    if (ddata.STDId == stdid)
+                    {
 
+                        ddata.StrName = Convert.ToString(m_Attributes.Grid_Attributes[2, 1].Value);
+                        ddata.Color = colorRGBtoHx16(m_Attributes.Grid_Attributes[3, 1].View.BackColor.R, m_Attributes.Grid_Attributes[3, 1].View.BackColor.G, m_Attributes.Grid_Attributes[3, 1].View.BackColor.B);
+                        ddata.IfElementAnalysis = Convert.ToBoolean(m_Attributes.Grid_Attributes[4, 1].Value);
+                        ddata.Hardness = Convert.ToString(m_Attributes.Grid_Attributes[5, 1].Value);
+                        ddata.Density = Convert.ToString(m_Attributes.Grid_Attributes[6, 1].Value);
+                        ddata.Electrical_conductivity = Convert.ToString(m_Attributes.Grid_Attributes[7, 1].Value);
+                        ddata.BSE = Convert.ToString(m_Attributes.Grid_Attributes[8, 1].Value);
 
-            if (m_Attributes.Grid_Attributes[9, 1].Value != null)
-            {
-                _sTDEditor.STDDictionary[stdid].Formula = Convert.ToString(m_Attributes.Grid_Attributes[9, 1].Value);
-            }
-            else
-            {
-                _sTDEditor.STDDictionary[stdid].Formula = "";
-            }
-            if (m_Attributes.Grid_Attributes[10, 1].Value != null)
-            {
-                _sTDEditor.STDDictionary[stdid].Element = Convert.ToString(m_Attributes.Grid_Attributes[10, 1].Value);
-            }
-            else
-            {
-                _sTDEditor.STDDictionary[stdid].Element = "";
-            }
 
-            if (m_Attributes.Grid_Attributes[11, 1].Value != null)
-            {
-                _sTDEditor.STDDictionary[stdid].GroupId = _sTDEditor.GroupIdDictionaryFromName[Convert.ToString(m_Attributes.Grid_Attributes[11, 1].Value)];
-            }
-            else
-            {
-                _sTDEditor.STDDictionary[stdid].GroupId = -1;
-            }
+                        if (m_Attributes.Grid_Attributes[9, 1].Value != null)
+                        {
+                            ddata.Formula = Convert.ToString(m_Attributes.Grid_Attributes[9, 1].Value);
+                        }
+                        else
+                        {
+                            ddata.Formula = "";
+                        }
+                        if (m_Attributes.Grid_Attributes[10, 1].Value != null)
+                        {
+                            ddata.Element = Convert.ToString(m_Attributes.Grid_Attributes[10, 1].Value);
+                        }
+                        else
+                        {
+                            ddata.Element = "";
+                        }
 
-            _sTDEditor.STDDictionary[stdid].Expression = m_SubMidWindow.m_STDEditor.textbox_STDEditor.Text.ToString();
+                        if (m_Attributes.Grid_Attributes[11, 1].Value != null)
+                        {
+                            ddata.GroupId = _sTDEditor.GroupIdDictionaryFromName[Convert.ToString(m_Attributes.Grid_Attributes[11, 1].Value)];
+                        }
+                        else
+                        {
+                            ddata.GroupId = -1;
+                        }
 
-            string sKeyElements = "";
-            for (int i = 0; i < m_SubMidWindow.m_STDEditor.dataGridView_KeyElements.Columns.Count; i++)
-            {
-                sKeyElements += m_SubMidWindow.m_STDEditor.dataGridView_KeyElements.Rows[0].Cells[i].Value.ToString() + ",";
-            }
-            if (sKeyElements.Length > 0)
-            {
-                sKeyElements = sKeyElements.Substring(0, sKeyElements.Length - 1);
-            }
+                        ddata.Expression = m_SubMidWindow.m_STDEditor.textbox_STDEditor.Text.ToString();
 
-            string sSubElements = "";
-            for (int i = 0; i < m_SubMidWindow.m_STDEditor.dataGridView_SubElements.Columns.Count; i++)
-            {
-                sSubElements += m_SubMidWindow.m_STDEditor.dataGridView_SubElements.Rows[0].Cells[i].Value.ToString() + ",";
-            }
-            if (sSubElements.Length > 0)
-            {
-                sSubElements = sSubElements.Substring(0, sSubElements.Length - 1);
-            }
+                        string sKeyElements = "";
+                        for (int i = 0; i < m_SubMidWindow.m_STDEditor.dataGridView_KeyElements.Columns.Count; i++)
+                        {
+                            sKeyElements += m_SubMidWindow.m_STDEditor.dataGridView_KeyElements.Rows[0].Cells[i].Value.ToString() + ",";
+                        }
+                        if (sKeyElements.Length > 0)
+                        {
+                            sKeyElements = sKeyElements.Substring(0, sKeyElements.Length - 1);
+                        }
+
+                        string sSubElements = "";
+                        for (int i = 0; i < m_SubMidWindow.m_STDEditor.dataGridView_SubElements.Columns.Count; i++)
+                        {
+                            sSubElements += m_SubMidWindow.m_STDEditor.dataGridView_SubElements.Rows[0].Cells[i].Value.ToString() + ",";
+                        }
+                        if (sSubElements.Length > 0)
+                        {
+                            sSubElements = sSubElements.Substring(0, sSubElements.Length - 1);
+                        }
 
-            _sTDEditor.STDDictionary[stdid].KeyElementList = sKeyElements;
-            _sTDEditor.STDDictionary[stdid].SubElementList = sSubElements;
+                        ddata.KeyElementList = sKeyElements;
+                        ddata.SubElementList = sSubElements;
 
-            _sTDEditor.STDDictionary[stdid].ListNum = "0";
+                        //ddata.ListNum = "0";   
+                    }
+                }
+            }
         }
 
         public void RemoveSTDDictionaryItem(int STDId)
@@ -499,21 +484,59 @@ namespace OTSPartA_STDEditor
 
         public void ChangeStrName(int RowNum, string NewStrName)
         {
-            _sTDEditor.STDDictionary[((STDdata)m_STDRuleslist.Grid_Minerals[RowNum, 0].Tag).STDId].StrName = NewStrName;
-            m_Attributes.Grid_Attributes[2, 1].Value = NewStrName;
+            //_sTDEditor.STDDictionary[((STDdata)m_STDRuleslist.Grid_Minerals[RowNum, 0].Tag).STDId].StrName = NewStrName;
+            //m_Attributes.Grid_Attributes[2, 1].Value = NewStrName;
         }
 
+        
+        
+        
+        
+        
         public void ChangeSTDRulesLISTBackColor()
         {
             int stdid = m_STDRuleslist.ChangeSTDRulesLISTBackColor();
+            m_STDRuleslist.treeView_G.Focus();
         }
         public void ChangeSTDRuleName(String RuleName)
         {
-            m_STDRuleslist.Grid_Minerals[m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0].Value = RuleName;
+            if(m_STDRuleslist.treeView_G.SelectedNode==null)
+            {
+                return;
+            }
+            if (m_STDRuleslist.treeView_G.SelectedNode.Level == 0)
+            {
+                return;
+            }
+            else
+            {
+                if (RuleName == null || RuleName == "")
+                {
+                    MessageBox.Show("RuleName Cannot Be Null!", "Tip");
+                    m_Attributes.Grid_Attributes[2, 1].Value= ((STDdata)m_STDRuleslist.treeView_G.SelectedNode.Tag).StrName;
+                    return;
+                }
+
+                STDdata sT = (STDdata)m_STDRuleslist.treeView_G.SelectedNode.Tag;
+                foreach (int grpid in m_STDRuleslist.GroupViewDic.Keys)
+                {
+                    foreach (STDdata ddata in m_STDRuleslist.GroupViewDic[grpid].ContainSTD)
+                    {
+                        if (ddata.STDId == ((STDdata)m_STDRuleslist.treeView_G.SelectedNode.Tag).STDId)
+                        {
+                            ddata.StrName = RuleName;
+                            m_STDRuleslist.treeView_G.SelectedNode.Text = RuleName;
+                            break;
+                        }
+                    }
+                }
+            }
+            m_STDRuleslist.treeView_G.Focus();
         }
 
 
         
+        
         public void SetNull()
         {
             m_SubMidWindow.m_STDEditor.textbox_STDEditor.Text = "";
@@ -534,8 +557,6 @@ namespace OTSPartA_STDEditor
                     }
                 }
             }
-
-
             m_Attributes.Grid_Attributes.Refresh();
             m_SubMidWindow.m_STDEditor.dataGridView_KeyElements.Rows.Clear();
             m_SubMidWindow.m_STDEditor.dataGridView_KeyElements.Columns.Clear();
@@ -543,6 +564,9 @@ namespace OTSPartA_STDEditor
             m_SubMidWindow.m_STDEditor.dataGridView_SubElements.Columns.Clear();
         }
 
+
+
+
         private void ribbon_ESDMaxRules_Click(object sender, EventArgs e)
         {
             Form_MaxEDSRules form_MaxEDSRules = new Form_MaxEDSRules(STDDBAddress);
@@ -591,7 +615,6 @@ namespace OTSPartA_STDEditor
         {
             this.Close();
         }
-
         private void rbClose_Click(object sender, EventArgs e)
         {
             if (!_sTDEditor.Isoldversion)
@@ -601,39 +624,30 @@ namespace OTSPartA_STDEditor
                     DialogResult dr = MessageBox.Show("Whether to save the current modification?", "Tip", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                     if (dr == DialogResult.Yes)
                     {
-                        if (m_STDRuleslist.Grid_Minerals.RowsCount > 1)
-                        {
-                            if ((m_STDRuleslist.Grid_Minerals[m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0].Value.ToString().Replace(" ", "").Trim() != ""))
-                            {
-                                if (m_STDRuleslist.Predata != null)
-                                {
-                                    int id = m_STDRuleslist.Predata.STDId;
-                                    SaveDataOfSelRule(id);
-                                }
-                            }
-                            else
-                            {
-                                return;
-                            }
-
-                        }
-                        //else
-                        //{
-                        //    STDDictionaryInitial.Clear();
-                        //}
-                        FormForWaiting forWaiting = new FormForWaiting();
-                        forWaiting.Show();
-                        bool result = _sTDEditor.SaveDictionaryToClassify();
-                        if (result)
+                        if (m_STDRuleslist.Predata != null)
                         {
-                            forWaiting.Close();
-                        }
-                        else
-                        {
-                            forWaiting.Close();
-                            MessageBox.Show("Save failed!", "Tip");
+                            int id = m_STDRuleslist.Predata.STDId;
+                            SaveDataOfSelRule(id);
                         }
                     }
+                    else
+                    {
+                        return;
+                    }
+                    FormForWaiting forWaiting = new FormForWaiting();
+                    forWaiting.Show();
+
+
+                    bool result = _sTDEditor.SaveDictionaryToClassify();
+                    if (result)
+                    {
+                        forWaiting.Close();
+                    }
+                    else
+                    {
+                        forWaiting.Close();
+                        MessageBox.Show("Save failed!", "Tip");
+                    }
                 }
             }
             m_Attributes.Close();
@@ -685,8 +699,6 @@ namespace OTSPartA_STDEditor
             ribbon_UserConstants.Enabled = true;
             ribbon_GroupNameMaintenance.Enabled = false;
         }
-
-
         void ButtonStatusClose()
         {
             rbOpen.Enabled = true;
@@ -726,22 +738,8 @@ namespace OTSPartA_STDEditor
                m_SubMidWindow.m_STDEditor.comboBox_Constants.Items.AddRange(_sTDEditor.ConstantsStr);
             }
             m_SubMidWindow.m_STDEditor.textbox_STDEditor.Text = "";
-            if (m_STDRuleslist.Grid_Minerals.RowsCount > 1)
-            {
-                m_STDRuleslist.button_UpOrder.Enabled = false;
-                if (m_STDRuleslist.Grid_Minerals.RowsCount == 2)       //就一条时向下按钮置灰
-                {
-                    m_STDRuleslist.button_DownOrder.Enabled = false;
-                }
-                ChangeSTDEditorAndGrid_Attributes(((STDdata)m_STDRuleslist.Grid_Minerals[1, 0].Tag).STDId);
-                Position pos = new Position(1, 0);
-                m_STDRuleslist.Grid_Minerals[1, 0].Grid.Select();
-                m_STDRuleslist.Grid_Minerals.Selection.Focus(pos, true);
-            }
+            m_STDRuleslist.InitGroupEditorView();
         }
-
-        
-
         private void Form_ConstantsEditor2_FormClosing(object sender, FormClosingEventArgs e)
         {
             if(_sTDEditor==null)
@@ -759,24 +757,11 @@ namespace OTSPartA_STDEditor
                     DialogResult dr = MessageBox.Show("Whether to save the current modification", "Tip", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                     if (dr == DialogResult.Yes)
                     {
-                        if (m_STDRuleslist.Grid_Minerals.RowsCount > 1)
+                        if (m_STDRuleslist.Predata!=null)
                         {
-                            if (m_STDRuleslist.Grid_Minerals[m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0].Value.ToString().Replace(" ", "").Trim() != "")
-                            {
-                                int id = m_STDRuleslist.Predata.STDId;
-                                SaveDataOfSelRule(id);
-                            }
-                            else
-                            {
-                                e.Cancel = true;
-                                return;
-                            }
-
+                            int id = m_STDRuleslist.Predata.STDId;
+                            SaveDataOfSelRule(id);
                         }
-                        //else
-                        //{
-                        //    STDDictionaryInitial.Clear();
-                        //}
                         FormForWaiting forWaiting = new FormForWaiting();
                         forWaiting.Show();
                         bool result = _sTDEditor.SaveDictionaryToClassify();

+ 2 - 1
OTSPartA_STDEditor/UI/ReferenceLibrary.Designer.cs

@@ -168,7 +168,8 @@
             this.insertToolStripMenuItem.Size = new System.Drawing.Size(189, 22);
             this.insertToolStripMenuItem.Tag = "insertToolStripMenuItem";
             this.insertToolStripMenuItem.Text = "Insert into main lab";
-            this.insertToolStripMenuItem.Click += new System.EventHandler(this.insertToolStripMenuItem_Click);
+            this.insertToolStripMenuItem.Visible = false;
+            this.insertToolStripMenuItem.Click += new System.EventHandler(this.InsertToolStripMenuItem_Click);
             // 
             // addIntoMainLabToolStripMenuItem
             // 

+ 155 - 140
OTSPartA_STDEditor/UI/ReferenceLibrary.cs

@@ -8,6 +8,7 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using System.Windows.Forms;
+using static System.Windows.Forms.VisualStyles.VisualStyleElement;
 
 namespace OTSPartA_STDEditor
 {
@@ -17,7 +18,7 @@ namespace OTSPartA_STDEditor
         protected SourceGrid.Cells.Views.Cell m_CellGroupType = null;
         public Dictionary<int, STDdata> ReferenceDictionary = new Dictionary<int, STDdata>();
         System.Collections.Hashtable table_ReferenceLibrary;
-        Dictionary<int, string> ReferenceGroup = new Dictionary<int, string>();
+        readonly Dictionary<int, string> ReferenceGroup = new Dictionary<int, string>();
 
         public ReferenceLibrary(SubMidWindow SubMidWindow)
         {
@@ -121,20 +122,22 @@ namespace OTSPartA_STDEditor
                     {
                         foreach (DataRow item in dt.Rows)
                         {
-                            STDdata new_STDdata = new STDdata();
-                            new_STDdata.STDId = (int)item["STDId"];
-                            new_STDdata.Hardness = item["Hardness"].ToString();
-                            new_STDdata.Density = item["Density"].ToString();
-                            new_STDdata.Electrical_conductivity = item["Electrical_conductivity"].ToString();
-                            new_STDdata.BSE = item["BSE"].ToString();
-                            new_STDdata.Formula = item["Formula"].ToString();
-                            new_STDdata.Element = item["Formula"].ToString();
-                            new_STDdata.StrName = item["StrName"].ToString();
-                            new_STDdata.Expression = item["Expression"].ToString();
-                            new_STDdata.Color = item["Color"].ToString();
-                            new_STDdata.KeyElementList = item["KeyElementList"].ToString();
-                            new_STDdata.SubElementList = item["SubElementList"].ToString();
-                            new_STDdata.GroupId = (int)item["GroupId"];
+                            STDdata new_STDdata = new STDdata
+                            {
+                                STDId = int.Parse(item["STDId"].ToString()),
+                                Hardness = item["Hardness"].ToString(),
+                                Density = item["Density"].ToString(),
+                                Electrical_conductivity = item["Electrical_conductivity"].ToString(),
+                                BSE = item["BSE"].ToString(),
+                                Formula = item["Formula"].ToString(),
+                                Element = item["Formula"].ToString(),
+                                StrName = item["StrName"].ToString(),
+                                Expression = item["Expression"].ToString(),
+                                Color = item["Color"].ToString(),
+                                KeyElementList = item["KeyElementList"].ToString(),
+                                SubElementList = item["SubElementList"].ToString(),
+                                GroupId = (int)item["GroupId"]
+                            };
 
                             STDDictionary.Add(int.Parse(item["STDId"].ToString()), new_STDdata);
                         }
@@ -192,13 +195,17 @@ namespace OTSPartA_STDEditor
                 PropGrid.Rows[i].Height = 25;
                 PropGrid.Rows[i].Tag = kv.Value;
 
-                PropGrid[i, 1] = new SourceGrid.Cells.Cell(kv.Value.StrName, typeof(string));
-                PropGrid[i, 1].Tag = kv.Value;
+                PropGrid[i, 1] = new SourceGrid.Cells.Cell(kv.Value.StrName, typeof(string))
+                {
+                    Tag = kv.Value
+                };
 
                 PropGrid[i, 2] = new SourceGrid.Cells.Cell("", typeof(string));
 
-                SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
-                view.BackColor = STDRuleslist.colorHx16toRGB(kv.Value.Color);
+                SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell
+                {
+                    BackColor = STDRuleslist.colorHx16toRGB(kv.Value.Color)
+                };
                 PropGrid[i, 2].View = view;
                 PropGrid[i, 3] = new SourceGrid.Cells.Cell(kv.Value.Expression, typeof(string));
                 PropGrid[i, 4] = new SourceGrid.Cells.Cell(kv.Value.KeyElementList, typeof(string));
@@ -271,8 +278,6 @@ namespace OTSPartA_STDEditor
                 }
                 else
                 {
-                    int r = PropGrid.Selection.ActivePosition.Row;
-
                     MakeCheckboxUnchecked();
                     PropGrid[PropGrid.Selection.ActivePosition.Row, 0].Value = true;
                 }
@@ -282,8 +287,10 @@ namespace OTSPartA_STDEditor
 
         private void TSLoad_Click(object sender, EventArgs e)
         {
-            OpenFileDialog fileSel = new OpenFileDialog();
-            fileSel.Filter = "(*.db)|*.db";
+            OpenFileDialog fileSel = new OpenFileDialog
+            {
+                Filter = "(*.db)|*.db"
+            };
             if (DialogResult.OK == fileSel.ShowDialog())
             {
                 ReferenceDictionary.Clear();
@@ -336,7 +343,7 @@ namespace OTSPartA_STDEditor
 
                     // 判断左侧区域是否已经选中了某个stdmineral
                     bool bEnable = false;
-                    bEnable = (null == m_SubMidWindow.m_MainForm.m_STDRuleslist.Predata) ? false : true;
+                    bEnable = null != m_SubMidWindow.m_MainForm.m_STDRuleslist.Predata;
                     this.insertToolStripMenuItem.Enabled = bEnable;
                 }
             }
@@ -346,65 +353,65 @@ namespace OTSPartA_STDEditor
             }
         }
 
-        private void insertToolStripMenuItem_Click(object sender, EventArgs e)
+        private void InsertToolStripMenuItem_Click(object sender, EventArgs e)
         {
-            if (m_SubMidWindow.m_MainForm.m_STDRuleslist.tabControl1.SelectedIndex == 0)
-            {
-                MessageBox.Show("Please do not operate the reference library in the grouping interface!");
-                return;
-            }
-            m_SubMidWindow.m_MainForm.m_STDRuleslist.Grid_Minerals.Focus(true);
-            int i = m_SubMidWindow.m_MainForm.m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row;
-            int j = m_SubMidWindow.m_MainForm.m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Column;
-            /// 保证鼠标点击的GRID行和列是有效的
-            if (i >= 0 && j >= 0)
-            {
-                //规则名称不为空
-                if (m_SubMidWindow.m_MainForm.m_STDRuleslist.Grid_Minerals[i, 0].Value.ToString().Replace(" ", "").Trim() != "")
-                {
-                    int id = ((STDdata)m_SubMidWindow.m_MainForm.m_STDRuleslist.Grid_Minerals[i, 0].Tag).STDId;
-                    m_SubMidWindow.m_MainForm.SaveDataOfSelRule(id);
-
-                    PropGrid.Focus(true);
-                    int selrow = PropGrid.Selection.ActivePosition.Row;
-                    int STDnum = ((STDdata)PropGrid[selrow, 1].Tag).STDId;
-                    int STDId = 1;
-                    foreach (KeyValuePair<int, STDdata> kv in m_SubMidWindow.m_MainForm._sTDEditor.STDDictionary)
-                    {
-                        if (STDId < kv.Key)
-                        {
-                            STDId = kv.Key;
-                        }
-                    }
-                    STDdata sT = new STDdata();
-                    sT.BSE = ReferenceDictionary[STDnum].BSE;
-                    sT.StrName = ReferenceDictionary[STDnum].StrName;
-                    sT.Color = ReferenceDictionary[STDnum].Color;
-                    sT.Density = ReferenceDictionary[STDnum].Density;
-                    sT.Expression = ReferenceDictionary[STDnum].Expression;
-                    sT.Formula = ReferenceDictionary[STDnum].Formula;
-                    sT.Hardness = ReferenceDictionary[STDnum].Hardness;
-                    sT.UsingImgPropertyList = ReferenceDictionary[STDnum].UsingImgPropertyList;
-                    sT.UsingOtherPropertyList = ReferenceDictionary[STDnum].UsingOtherPropertyList;
-                    sT.KeyElementList = ReferenceDictionary[STDnum].KeyElementList;
-                    sT.SubElementList = ReferenceDictionary[STDnum].SubElementList;
-                    sT.Electrical_conductivity = ReferenceDictionary[STDnum].Electrical_conductivity;
-                    sT.Element = ReferenceDictionary[STDnum].Element;
-                    sT.GroupId = ReferenceDictionary[STDnum].GroupId;
-                    sT.STDId = STDnum;
-                    m_SubMidWindow.m_MainForm._sTDEditor.STDDictionary.Add(STDId + 1, sT);
-
-                    m_SubMidWindow.m_MainForm.m_STDRuleslist.InsertNewRow(STDId + 1, sT.StrName, STDRuleslist.colorHx16toRGB(sT.Color));
-                    m_SubMidWindow.m_MainForm.m_STDRuleslist.Refresh();
-
-                    m_SubMidWindow.m_MainForm.m_STDRuleslist.Predata = (STDdata)m_SubMidWindow.m_MainForm.m_STDRuleslist.Grid_Minerals[i, 0].Tag;
-                }
-
-            }
-            else
-            {
-                AddIntoMainLab();
-            }
+            //if (m_SubMidWindow.m_MainForm.m_STDRuleslist.tabControl1.SelectedIndex == 0)
+            //{
+            //    MessageBox.Show("Please do not operate the reference library in the grouping interface!");
+            //    return;
+            //}
+            //m_SubMidWindow.m_MainForm.m_STDRuleslist.Grid_Minerals.Focus(true);
+            //int i = m_SubMidWindow.m_MainForm.m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row;
+            //int j = m_SubMidWindow.m_MainForm.m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Column;
+            ///// 保证鼠标点击的GRID行和列是有效的
+            //if (i >= 0 && j >= 0)
+            //{
+            //    //规则名称不为空
+            //    if (m_SubMidWindow.m_MainForm.m_STDRuleslist.Grid_Minerals[i, 0].Value.ToString().Replace(" ", "").Trim() != "")
+            //    {
+            //        int id = ((STDdata)m_SubMidWindow.m_MainForm.m_STDRuleslist.Grid_Minerals[i, 0].Tag).STDId;
+            //        m_SubMidWindow.m_MainForm.SaveDataOfSelRule(id);
+
+            //        PropGrid.Focus(true);
+            //        int selrow = PropGrid.Selection.ActivePosition.Row;
+            //        int STDnum = ((STDdata)PropGrid[selrow, 1].Tag).STDId;
+            //        int STDId = 1;
+            //        foreach (KeyValuePair<int, STDdata> kv in m_SubMidWindow.m_MainForm._sTDEditor.STDDictionary)
+            //        {
+            //            if (STDId < kv.Key)
+            //            {
+            //                STDId = kv.Key;
+            //            }
+            //        }
+            //        STDdata sT = new STDdata();
+            //        sT.BSE = ReferenceDictionary[STDnum].BSE;
+            //        sT.StrName = ReferenceDictionary[STDnum].StrName;
+            //        sT.Color = ReferenceDictionary[STDnum].Color;
+            //        sT.Density = ReferenceDictionary[STDnum].Density;
+            //        sT.Expression = ReferenceDictionary[STDnum].Expression;
+            //        sT.Formula = ReferenceDictionary[STDnum].Formula;
+            //        sT.Hardness = ReferenceDictionary[STDnum].Hardness;
+            //        sT.UsingImgPropertyList = ReferenceDictionary[STDnum].UsingImgPropertyList;
+            //        sT.UsingOtherPropertyList = ReferenceDictionary[STDnum].UsingOtherPropertyList;
+            //        sT.KeyElementList = ReferenceDictionary[STDnum].KeyElementList;
+            //        sT.SubElementList = ReferenceDictionary[STDnum].SubElementList;
+            //        sT.Electrical_conductivity = ReferenceDictionary[STDnum].Electrical_conductivity;
+            //        sT.Element = ReferenceDictionary[STDnum].Element;
+            //        sT.GroupId = ReferenceDictionary[STDnum].GroupId;
+            //        sT.STDId = STDnum;
+            //        m_SubMidWindow.m_MainForm._sTDEditor.STDDictionary.Add(STDId + 1, sT);
+
+            //        m_SubMidWindow.m_MainForm.m_STDRuleslist.InsertNewRow(STDId + 1, sT.StrName, STDRuleslist.colorHx16toRGB(sT.Color));
+            //        m_SubMidWindow.m_MainForm.m_STDRuleslist.Refresh();
+
+            //        m_SubMidWindow.m_MainForm.m_STDRuleslist.Predata = (STDdata)m_SubMidWindow.m_MainForm.m_STDRuleslist.Grid_Minerals[i, 0].Tag;
+            //    }
+
+            //}
+            //else
+            //{
+            //    AddIntoMainLab();
+            //}
         }
 
         #region 因为复制容易引起用户误操作,故取消
@@ -419,77 +426,85 @@ namespace OTSPartA_STDEditor
             //m_SubMidWindow.m_MainForm.m_STDRuleslist.Grid_Minerals.Refresh();
         }
         #endregion
-
-
-
         private void addIntoMainLabToolStripMenuItem_Click(object sender, EventArgs e)
         {
-            if (m_SubMidWindow.m_MainForm.m_STDRuleslist.tabControl1.SelectedIndex == 0)
+            foreach (TreeNode treeNode1 in m_SubMidWindow.m_MainForm.m_STDRuleslist.treeView_G.Nodes)
             {
-                MessageBox.Show("Please do not operate the reference library in the grouping interface!");
-                return;
-            }
-            m_SubMidWindow.m_MainForm.m_STDRuleslist.Grid_Minerals.Focus(true);
-            int i = m_SubMidWindow.m_MainForm.m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row;
-            int j = m_SubMidWindow.m_MainForm.m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Column;
-            /// 保证鼠标点击的GRID行和列是有效的
-            if (i > 0 && j >= 0)
-            {
-                //规则名称不为空
-                if (m_SubMidWindow.m_MainForm.m_STDRuleslist.Grid_Minerals[i, j].Value.ToString().Replace(" ", "").Trim() != "")
+                if (((STDGroups)treeNode1.Tag).name == "Default")
                 {
-                    int id = ((STDdata)m_SubMidWindow.m_MainForm.m_STDRuleslist.Grid_Minerals[i, 0].Tag).STDId; ;
-                    m_SubMidWindow.m_MainForm.SaveDataOfSelRule(id);
+                    if (m_SubMidWindow.m_MainForm.m_STDRuleslist.Predata != null)
+                    {
+                        m_SubMidWindow.m_MainForm.SaveDataOfSelRule(m_SubMidWindow.m_MainForm.m_STDRuleslist.Predata.STDId);
+                    }
+                    STDdata ddata = AddIntoMainLab();
+                    int STDId = 40000;
+                    foreach (STDGroups grp in m_SubMidWindow.m_MainForm.m_STDRuleslist.GroupViewDic.Values)
+                    {
+                        foreach (STDdata ddata1 in grp.ContainSTD)
+                        {
+                            if (STDId < ddata1.STDId)
+                            {
+                                STDId = ddata1.STDId;
+                            }
+                        }
+                    }
+                    ddata.STDId = STDId + 1;
+                    TreeNode treeNode = new TreeNode();
+                    treeNode.Text = ddata.StrName;
+                    treeNode.Tag = ddata;
+
+                    ddata.ListNum = ((((STDGroups)treeNode1.Tag).ContainSTD).Count - 1).ToString();
+                    ddata.GroupId = ((STDGroups)treeNode1.Tag).id;
+                    ((STDGroups)treeNode1.Tag).ContainSTD.Add(ddata);
+                    m_SubMidWindow.m_MainForm.m_STDRuleslist.InitGroupView();
 
-                    AddIntoMainLab();
+                    foreach (TreeNode node in m_SubMidWindow.m_MainForm.m_STDRuleslist.treeView_G.Nodes)
+                    {
+                        foreach (TreeNode node1 in node.Nodes)
+                        {
+                            if (((STDdata)node1.Tag).STDId == ddata.STDId)
+                            {
+                                m_SubMidWindow.m_MainForm.ChangeSTDEditorAndGrid_Attributes(ddata);
+                                m_SubMidWindow.m_MainForm.m_STDRuleslist.Predata = (STDdata)treeNode.Tag;
+                                m_SubMidWindow.m_MainForm.m_STDRuleslist.treeView_G.SelectedNode = node1;
+                                m_SubMidWindow.m_MainForm.m_STDRuleslist.treeView_G.Focus();
+                                break;
+                            }
+                        }
+                    }
                 }
             }
-            else if(i==-1&&j==-1)
-            {
-                AddIntoMainLab();
-            }
         }
-        void AddIntoMainLab()
+        STDdata AddIntoMainLab()
         {
             PropGrid.Focus(true);
             int selrow = PropGrid.Selection.ActivePosition.Row;
             int STDnum = ((STDdata)PropGrid[selrow, 1].Tag).STDId;
-
-            int STDId = 1;
-            foreach (KeyValuePair<int, STDdata> kv in m_SubMidWindow.m_MainForm._sTDEditor.STDDictionary)
+            //int STDId = 40000;
+            //foreach (KeyValuePair<int, STDdata> kv in m_SubMidWindow.m_MainForm._sTDEditor.STDDictionary)
+            //{
+            //    if (STDId < kv.Key)
+            //    {
+            //        STDId = kv.Key;
+            //    }
+            //}
+            STDdata sT = new STDdata
             {
-                if (STDId < kv.Key)
-                {
-                    STDId = kv.Key;
-                }
-            }
-            STDdata sT = new STDdata();
-            sT.STDId = STDId + 1;
-            sT.BSE = ReferenceDictionary[STDnum].BSE;
-            sT.StrName = ReferenceDictionary[STDnum].StrName;
-            sT.Color = ReferenceDictionary[STDnum].Color;
-            sT.Density = ReferenceDictionary[STDnum].Density;
-            sT.Expression = ReferenceDictionary[STDnum].Expression;
-            sT.Formula = ReferenceDictionary[STDnum].Formula;
-            sT.Hardness = ReferenceDictionary[STDnum].Hardness;
-            sT.UsingImgPropertyList = ReferenceDictionary[STDnum].UsingImgPropertyList;
-            sT.UsingOtherPropertyList = ReferenceDictionary[STDnum].UsingOtherPropertyList;
-            sT.KeyElementList = ReferenceDictionary[STDnum].KeyElementList;
-            sT.SubElementList = ReferenceDictionary[STDnum].SubElementList;
-            sT.Electrical_conductivity = ReferenceDictionary[STDnum].Electrical_conductivity;
-            sT.Element = ReferenceDictionary[STDnum].Element;
-            if (m_SubMidWindow.m_MainForm._sTDEditor.GroupIdDictionaryFromId.ContainsKey(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._sTDEditor.STDDictionary.Add(STDId + 1, sT);
-
-            m_SubMidWindow.m_MainForm.m_STDRuleslist.AddNewRow(STDId + 1, sT.StrName, STDRuleslist.colorHx16toRGB(sT.Color));
-            m_SubMidWindow.m_MainForm.m_STDRuleslist.Refresh();
-            m_SubMidWindow.m_MainForm.m_STDRuleslist.Predata = (STDdata)m_SubMidWindow.m_MainForm.m_STDRuleslist.Grid_Minerals[m_SubMidWindow.m_MainForm.m_STDRuleslist.Grid_Minerals.RowsCount - 1, 0].Tag;
+                BSE = ReferenceDictionary[STDnum].BSE,
+                StrName = ReferenceDictionary[STDnum].StrName,
+                Color = ReferenceDictionary[STDnum].Color,
+                Density = ReferenceDictionary[STDnum].Density,
+                Expression = ReferenceDictionary[STDnum].Expression,
+                Formula = ReferenceDictionary[STDnum].Formula,
+                Hardness = ReferenceDictionary[STDnum].Hardness,
+                UsingImgPropertyList = ReferenceDictionary[STDnum].UsingImgPropertyList,
+                UsingOtherPropertyList = ReferenceDictionary[STDnum].UsingOtherPropertyList,
+                KeyElementList = ReferenceDictionary[STDnum].KeyElementList,
+                SubElementList = ReferenceDictionary[STDnum].SubElementList,
+                Electrical_conductivity = ReferenceDictionary[STDnum].Electrical_conductivity,
+                Element = ReferenceDictionary[STDnum].Element
+            };
+            return sT;
         }
     }
 }

+ 29 - 116
OTSPartA_STDEditor/UI/STDRuleslist.Designer.cs

@@ -29,51 +29,20 @@
         private void InitializeComponent()
         {
             this.components = new System.ComponentModel.Container();
-            this.MenuStrip_STDRulelist = new System.Windows.Forms.ContextMenuStrip(this.components);
-            this.ToolStripMenuItem_New = new System.Windows.Forms.ToolStripMenuItem();
-            this.ToolStripMenuItem_Del = new System.Windows.Forms.ToolStripMenuItem();
             this.tabControl1 = new System.Windows.Forms.TabControl();
             this.tabPage_GroupView = new System.Windows.Forms.TabPage();
             this.treeView_G = new System.Windows.Forms.TreeView();
             this.contextMenuStrip_GroupView = new System.Windows.Forms.ContextMenuStrip(this.components);
             this.ToolStripMenuItem_NewGroup = new System.Windows.Forms.ToolStripMenuItem();
-            this.ToolStripMenuItem_DelGroup = new System.Windows.Forms.ToolStripMenuItem();
             this.ToolStripMenuItem_EDGcolor = new System.Windows.Forms.ToolStripMenuItem();
-            this.ToolStripMenuItem_RenameGroup = new System.Windows.Forms.ToolStripMenuItem();
-            this.tabPage_RuleView = new System.Windows.Forms.TabPage();
-            this.Grid_Minerals = new SourceGrid.Grid();
-            this.button_DownOrder = new System.Windows.Forms.Button();
-            this.button_UpOrder = new System.Windows.Forms.Button();
-            this.MenuStrip_STDRulelist.SuspendLayout();
+            this.ToolStripMenuItem_NewRule = new System.Windows.Forms.ToolStripMenuItem();
+            this.ToolStripMenuItem_Rename = new System.Windows.Forms.ToolStripMenuItem();
+            this.ToolStripMenuItem_Del = new System.Windows.Forms.ToolStripMenuItem();
             this.tabControl1.SuspendLayout();
             this.tabPage_GroupView.SuspendLayout();
             this.contextMenuStrip_GroupView.SuspendLayout();
-            this.tabPage_RuleView.SuspendLayout();
             this.SuspendLayout();
             // 
-            // MenuStrip_STDRulelist
-            // 
-            this.MenuStrip_STDRulelist.ImageScalingSize = new System.Drawing.Size(24, 24);
-            this.MenuStrip_STDRulelist.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
-            this.ToolStripMenuItem_New,
-            this.ToolStripMenuItem_Del});
-            this.MenuStrip_STDRulelist.Name = "MenuStrip_STDRulelist";
-            this.MenuStrip_STDRulelist.Size = new System.Drawing.Size(101, 48);
-            // 
-            // ToolStripMenuItem_New
-            // 
-            this.ToolStripMenuItem_New.Name = "ToolStripMenuItem_New";
-            this.ToolStripMenuItem_New.Size = new System.Drawing.Size(100, 22);
-            this.ToolStripMenuItem_New.Text = "新建";
-            this.ToolStripMenuItem_New.Click += new System.EventHandler(this.ToolStripMenuItem_New_Click);
-            // 
-            // ToolStripMenuItem_Del
-            // 
-            this.ToolStripMenuItem_Del.Name = "ToolStripMenuItem_Del";
-            this.ToolStripMenuItem_Del.Size = new System.Drawing.Size(100, 22);
-            this.ToolStripMenuItem_Del.Text = "删除";
-            this.ToolStripMenuItem_Del.Click += new System.EventHandler(this.ToolStripMenuItem_Del_Click);
-            // 
             // tabControl1
             // 
             this.tabControl1.Alignment = System.Windows.Forms.TabAlignment.Bottom;
@@ -81,13 +50,11 @@
             | System.Windows.Forms.AnchorStyles.Left) 
             | System.Windows.Forms.AnchorStyles.Right)));
             this.tabControl1.Controls.Add(this.tabPage_GroupView);
-            this.tabControl1.Controls.Add(this.tabPage_RuleView);
             this.tabControl1.Location = new System.Drawing.Point(1, 1);
             this.tabControl1.Name = "tabControl1";
             this.tabControl1.SelectedIndex = 1;
             this.tabControl1.Size = new System.Drawing.Size(313, 782);
             this.tabControl1.TabIndex = 30;
-            this.tabControl1.SelectedIndexChanged += new System.EventHandler(this.tabControl1_SelectedIndexChanged);
             // 
             // tabPage_GroupView
             // 
@@ -110,21 +77,25 @@
             this.treeView_G.Name = "treeView_G";
             this.treeView_G.Size = new System.Drawing.Size(299, 750);
             this.treeView_G.TabIndex = 0;
+            this.treeView_G.BeforeLabelEdit += new System.Windows.Forms.NodeLabelEditEventHandler(this.treeView_G_BeforeLabelEdit);
             this.treeView_G.AfterLabelEdit += new System.Windows.Forms.NodeLabelEditEventHandler(this.treeView_G_AfterLabelEdit);
             this.treeView_G.ItemDrag += new System.Windows.Forms.ItemDragEventHandler(this.treeView_G_ItemDrag);
             this.treeView_G.NodeMouseClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.treeView_G_NodeMouseClick);
             this.treeView_G.DragDrop += new System.Windows.Forms.DragEventHandler(this.treeView_G_DragDrop);
             this.treeView_G.DragOver += new System.Windows.Forms.DragEventHandler(this.treeView_G_DragOver);
+            this.treeView_G.KeyUp += new System.Windows.Forms.KeyEventHandler(this.treeView_G_KeyUp);
+            this.treeView_G.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.Grid_Minerals_PreviewKeyDown);
             // 
             // contextMenuStrip_GroupView
             // 
             this.contextMenuStrip_GroupView.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
             this.ToolStripMenuItem_NewGroup,
-            this.ToolStripMenuItem_DelGroup,
             this.ToolStripMenuItem_EDGcolor,
-            this.ToolStripMenuItem_RenameGroup});
+            this.ToolStripMenuItem_NewRule,
+            this.ToolStripMenuItem_Rename,
+            this.ToolStripMenuItem_Del});
             this.contextMenuStrip_GroupView.Name = "contextMenuStrip_GroupView";
-            this.contextMenuStrip_GroupView.Size = new System.Drawing.Size(137, 92);
+            this.contextMenuStrip_GroupView.Size = new System.Drawing.Size(137, 114);
             // 
             // ToolStripMenuItem_NewGroup
             // 
@@ -133,13 +104,6 @@
             this.ToolStripMenuItem_NewGroup.Text = "新建组";
             this.ToolStripMenuItem_NewGroup.Click += new System.EventHandler(this.ToolStripMenuItem_NewGroup_Click);
             // 
-            // ToolStripMenuItem_DelGroup
-            // 
-            this.ToolStripMenuItem_DelGroup.Name = "ToolStripMenuItem_DelGroup";
-            this.ToolStripMenuItem_DelGroup.Size = new System.Drawing.Size(136, 22);
-            this.ToolStripMenuItem_DelGroup.Text = "删除组";
-            this.ToolStripMenuItem_DelGroup.Click += new System.EventHandler(this.ToolStripMenuItem_DelGroup_Click);
-            // 
             // ToolStripMenuItem_EDGcolor
             // 
             this.ToolStripMenuItem_EDGcolor.Name = "ToolStripMenuItem_EDGcolor";
@@ -147,68 +111,26 @@
             this.ToolStripMenuItem_EDGcolor.Text = "修改组颜色";
             this.ToolStripMenuItem_EDGcolor.Click += new System.EventHandler(this.ToolStripMenuItem_EdGroupColor_Click);
             // 
-            // ToolStripMenuItem_RenameGroup
+            // ToolStripMenuItem_NewRule
             // 
-            this.ToolStripMenuItem_RenameGroup.Name = "ToolStripMenuItem_RenameGroup";
-            this.ToolStripMenuItem_RenameGroup.Size = new System.Drawing.Size(136, 22);
-            this.ToolStripMenuItem_RenameGroup.Text = "修改组名称";
-            this.ToolStripMenuItem_RenameGroup.Click += new System.EventHandler(this.ToolStripMenuItem_RenameGroup_Click);
+            this.ToolStripMenuItem_NewRule.Name = "ToolStripMenuItem_NewRule";
+            this.ToolStripMenuItem_NewRule.Size = new System.Drawing.Size(136, 22);
+            this.ToolStripMenuItem_NewRule.Text = "新建规则";
+            this.ToolStripMenuItem_NewRule.Click += new System.EventHandler(this.ToolStripMenuItem_NewRule_Click);
             // 
-            // tabPage_RuleView
+            // ToolStripMenuItem_Rename
             // 
-            this.tabPage_RuleView.Controls.Add(this.Grid_Minerals);
-            this.tabPage_RuleView.Controls.Add(this.button_DownOrder);
-            this.tabPage_RuleView.Controls.Add(this.button_UpOrder);
-            this.tabPage_RuleView.Location = new System.Drawing.Point(4, 4);
-            this.tabPage_RuleView.Name = "tabPage_RuleView";
-            this.tabPage_RuleView.Padding = new System.Windows.Forms.Padding(3);
-            this.tabPage_RuleView.Size = new System.Drawing.Size(305, 756);
-            this.tabPage_RuleView.TabIndex = 1;
-            this.tabPage_RuleView.Text = "规则视图";
-            this.tabPage_RuleView.UseVisualStyleBackColor = true;
+            this.ToolStripMenuItem_Rename.Name = "ToolStripMenuItem_Rename";
+            this.ToolStripMenuItem_Rename.Size = new System.Drawing.Size(136, 22);
+            this.ToolStripMenuItem_Rename.Text = "修改名称";
+            this.ToolStripMenuItem_Rename.Click += new System.EventHandler(this.ToolStripMenuItem_Rename_Click);
             // 
-            // Grid_Minerals
+            // ToolStripMenuItem_Del
             // 
-            this.Grid_Minerals.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
-            | System.Windows.Forms.AnchorStyles.Left) 
-            | System.Windows.Forms.AnchorStyles.Right)));
-            this.Grid_Minerals.BackColor = System.Drawing.SystemColors.Control;
-            this.Grid_Minerals.ContextMenuStrip = this.MenuStrip_STDRulelist;
-            this.Grid_Minerals.EnableSort = true;
-            this.Grid_Minerals.Location = new System.Drawing.Point(27, 3);
-            this.Grid_Minerals.Margin = new System.Windows.Forms.Padding(3, 3, 10, 3);
-            this.Grid_Minerals.Name = "Grid_Minerals";
-            this.Grid_Minerals.OptimizeMode = SourceGrid.CellOptimizeMode.ForRows;
-            this.Grid_Minerals.SelectionMode = SourceGrid.GridSelectionMode.Cell;
-            this.Grid_Minerals.Size = new System.Drawing.Size(273, 751);
-            this.Grid_Minerals.TabIndex = 30;
-            this.Grid_Minerals.TabStop = true;
-            this.Grid_Minerals.ToolTipText = "";
-            this.Grid_Minerals.Click += new System.EventHandler(this.MineralsGrid_Click);
-            // 
-            // button_DownOrder
-            // 
-            this.button_DownOrder.Font = new System.Drawing.Font("华文彩云", 21.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.button_DownOrder.Location = new System.Drawing.Point(3, 118);
-            this.button_DownOrder.Name = "button_DownOrder";
-            this.button_DownOrder.Size = new System.Drawing.Size(18, 92);
-            this.button_DownOrder.TabIndex = 32;
-            this.button_DownOrder.Text = "↓";
-            this.button_DownOrder.UseVisualStyleBackColor = true;
-            this.button_DownOrder.Visible = false;
-            this.button_DownOrder.Click += new System.EventHandler(this.button_DownOrder_Click);
-            // 
-            // button_UpOrder
-            // 
-            this.button_UpOrder.Font = new System.Drawing.Font("华文彩云", 21.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.button_UpOrder.Location = new System.Drawing.Point(3, 17);
-            this.button_UpOrder.Name = "button_UpOrder";
-            this.button_UpOrder.Size = new System.Drawing.Size(18, 92);
-            this.button_UpOrder.TabIndex = 31;
-            this.button_UpOrder.Text = "↑";
-            this.button_UpOrder.UseVisualStyleBackColor = true;
-            this.button_UpOrder.Visible = false;
-            this.button_UpOrder.Click += new System.EventHandler(this.button_UpOrder_Click);
+            this.ToolStripMenuItem_Del.Name = "ToolStripMenuItem_Del";
+            this.ToolStripMenuItem_Del.Size = new System.Drawing.Size(136, 22);
+            this.ToolStripMenuItem_Del.Text = "删除";
+            this.ToolStripMenuItem_Del.Click += new System.EventHandler(this.ToolStripMenuItem_Del_Click);
             // 
             // STDRuleslist
             // 
@@ -225,31 +147,22 @@
             this.ShowIcon = false;
             this.Text = "STDRuleslist";
             this.Load += new System.EventHandler(this.STDRuleslist_Load);
-            this.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.Grid_Minerals_PreviewKeyDown);
-            this.MenuStrip_STDRulelist.ResumeLayout(false);
             this.tabControl1.ResumeLayout(false);
             this.tabPage_GroupView.ResumeLayout(false);
             this.contextMenuStrip_GroupView.ResumeLayout(false);
-            this.tabPage_RuleView.ResumeLayout(false);
             this.ResumeLayout(false);
 
         }
 
         #endregion
-        private System.Windows.Forms.ContextMenuStrip MenuStrip_STDRulelist;
-        private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem_New;
-        private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem_Del;
         private System.Windows.Forms.TabPage tabPage_GroupView;
-        private System.Windows.Forms.TabPage tabPage_RuleView;
-        public System.Windows.Forms.Button button_DownOrder;
-        public System.Windows.Forms.Button button_UpOrder;
-        private System.Windows.Forms.TreeView treeView_G;
-        public SourceGrid.Grid Grid_Minerals;
         private System.Windows.Forms.ContextMenuStrip contextMenuStrip_GroupView;
         private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem_NewGroup;
-        private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem_DelGroup;
+        private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem_Del;
         private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem_EDGcolor;
         public System.Windows.Forms.TabControl tabControl1;
-        private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem_RenameGroup;
+        private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem_Rename;
+        private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem_NewRule;
+        public System.Windows.Forms.TreeView treeView_G;
     }
 }

+ 329 - 456
OTSPartA_STDEditor/UI/STDRuleslist.cs

@@ -1,14 +1,13 @@
 using OTS.WinFormsUI.Docking;
-using SourceGrid;
 using System;
 using System.Collections.Generic;
 using System.Drawing;
 using System.Drawing.Imaging;
 using System.Linq;
 using System.Runtime.InteropServices;
-
 using System.Windows.Forms;
 
+
 namespace OTSPartA_STDEditor
 {
     public partial class STDRuleslist : DockContent
@@ -16,24 +15,23 @@ namespace OTSPartA_STDEditor
         public STDdata Predata = null;//之前选中的位置
         public Form_Main m_MainForm = null;
         ValueChangedEvent m_ValueChangedEvent = null;//单元格内容改变事件
-        Dictionary<int,STDGroups> GroupViewDic=null;
+        public Dictionary<int,STDGroups> GroupViewDic=null;
+
+        System.Collections.Hashtable table_STDRuleslist;
+        bool RenFlag = false;
         public STDRuleslist(Form_Main mainForm)
         {
             InitializeComponent();
             m_MainForm = mainForm;
             m_ValueChangedEvent = new ValueChangedEvent(this);
         }
-        System.Collections.Hashtable table_STDRuleslist;
+
         private void STDRuleslist_Load(object sender, EventArgs e)
         {
             m_MainForm.lan = new Language(this);
             table_STDRuleslist = m_MainForm.lan.GetNameTable("Attributes");
-            InitRuleView();
-            button_UpOrder.Enabled = false;
-            button_DownOrder.Enabled = false;
+            InitGroupEditorView();
         }
-
-
         /// <summary>
         /// [颜色:16进制转成RGB]
         /// </summary>
@@ -58,135 +56,6 @@ namespace OTSPartA_STDEditor
             }
         }
 
-        private void MineralsGrid_Click(object sender, EventArgs e)
-        {
-            SourceGrid.Grid ls_gd = (SourceGrid.Grid)sender;
-            ls_gd.Focus();
-            int i = ls_gd.Selection.ActivePosition.Row;
-            int j = ls_gd.Selection.ActivePosition.Column;
-            if (i >= 0 && j >= 0)
-            {
-                if (Predata != null)
-                {
-                    m_MainForm.SaveDataOfSelRule(Predata.STDId);
-                }
-                m_MainForm.ChangeSTDEditorAndGrid_Attributes(((STDdata)Grid_Minerals[i, 0].Tag).STDId);
-                m_MainForm.m_SubMidWindow.m_ComparativeLibrary.MakeCheckboxUnchecked();
-                Predata = (STDdata)Grid_Minerals[i, 0].Tag;
-            }
-            SetOrderButtonsStatus();
-        }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-        private void ToolStripMenuItem_New_Click(object sender, EventArgs e)
-        {
-            int i = Grid_Minerals.Selection.ActivePosition.Row;
-            int j = Grid_Minerals.Selection.ActivePosition.Column;
-            if (i >= 0 && j >= 0)
-            {
-                int id = ((STDdata)Grid_Minerals[i, 0].Tag).STDId;
-                m_MainForm.SaveDataOfSelRule(id);
-                Predata = (STDdata)Grid_Minerals[i, 0].Tag;
-                int STDId = m_MainForm._sTDEditor.AddSTDDictionaryItem();
-                AddNewRow(STDId, "NewRuleName", Attributes.colorHx16toRGB(m_MainForm._sTDEditor.STDDictionary[STDId].Color));
-                m_MainForm.m_SubMidWindow.m_ComparativeLibrary.MakeCheckboxUnchecked();
-            }
-            else
-            {
-                int STDId = m_MainForm._sTDEditor.AddSTDDictionaryItem();
-                AddNewRow(STDId, "NewRuleName", Attributes.colorHx16toRGB(m_MainForm._sTDEditor.STDDictionary[STDId].Color));
-                m_MainForm.m_SubMidWindow.m_ComparativeLibrary.MakeCheckboxUnchecked();
-            }
-        }
-        public void AddNewRow(int STDId, string RuleName, Color color)
-        {
-            Grid_Minerals.Rows.Insert(Grid_Minerals.Rows.Count);
-            Grid_Minerals[Grid_Minerals.Rows.Count - 1, 0] = new SourceGrid.Cells.Cell(RuleName, typeof(string));
-            Grid_Minerals[Grid_Minerals.Rows.Count - 1, 0].Tag = m_MainForm._sTDEditor.STDDictionary[STDId];
-            Grid_Minerals.Rows[Grid_Minerals.Rows.Count - 1].Height = 25;
-            Grid_Minerals[Grid_Minerals.Rows.Count - 1, 1] = new SourceGrid.Cells.Cell();
-            m_MainForm._sTDEditor.STDDictionary[STDId].StrName = RuleName;
-            m_MainForm.ChangeSTDEditorAndGrid_Attributes(STDId);
-            SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
-            view.BackColor = color;
-            Grid_Minerals[Grid_Minerals.Rows.Count - 1, 1].View = view;
-            Position pos = new Position(Grid_Minerals.Rows.Count - 1, 0);
-            Grid_Minerals.Selection.Focus(pos, true);
-            Predata = (STDdata)Grid_Minerals[Grid_Minerals.Rows.Count - 1, 0].Tag;
-            SetOrderButtonsStatus();
-        }
-        void Grid_MineralsDelRow()
-        {
-            int x = Grid_Minerals.Selection.ActivePosition.Row;
-            if (x > 0)
-            {
-                m_MainForm.RemoveSTDDictionaryItem(((STDdata)Grid_Minerals[x, 0].Tag).STDId);
-                Grid_Minerals.Rows.Remove(x);
-                if (Grid_Minerals.RowsCount > 1)
-                {
-                    if (x != Grid_Minerals.RowsCount)
-                    {
-                        Position pos = new Position(x, 0);
-                        Grid_Minerals.Selection.Focus(pos, true);
-                        Grid_Minerals[x, 0].Grid.Select();
-                        m_MainForm.ChangeSTDEditorAndGrid_Attributes(((STDdata)Grid_Minerals[x, 0].Tag).STDId);
-                        Predata = (STDdata)Grid_Minerals[x, 0].Tag;
-                    }
-                    else
-                    {
-                        Position pos = new Position(x - 1, 0);
-                        Grid_Minerals.Selection.Focus(pos, true);
-                        Grid_Minerals[x - 1, 0].Grid.Select();
-
-                        m_MainForm.ChangeSTDEditorAndGrid_Attributes(((STDdata)Grid_Minerals[x-1, 0].Tag).STDId);
-                        Predata = (STDdata)Grid_Minerals[x-1, 0].Tag;
-                    }
-                }
-                else
-                {
-                    m_MainForm.SetNull();
-                    Predata = null;
-                }
-            }
-            else
-            {
-                MessageBox.Show("There is no rule to delete!", "Tip");
-            }
-        }
-        private void ToolStripMenuItem_Del_Click(object sender, EventArgs e)
-        {
-            Grid_MineralsDelRow();
-        }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
 
 
 
@@ -207,7 +76,6 @@ namespace OTSPartA_STDEditor
                 else
                 {
                     m_parentWnd.ChangeStrName(sender.Position.Row, "NewRuleName");
-                    m_parentWnd.Grid_Minerals[sender.Position.Row,0].Value = "NewRuleName";
                 }
             }
         }
@@ -215,229 +83,59 @@ namespace OTSPartA_STDEditor
         {
             m_MainForm.ChangeStrName(RowNum, NewStrName);
         }
-        private void Grid_Minerals_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
-        {
-            SourceGrid.Grid ls_gd = (SourceGrid.Grid)sender;
-            ls_gd.Focus();
-            int i = ls_gd.Selection.ActivePosition.Row;
-            int j = ls_gd.Selection.ActivePosition.Column;
-            if(i==-1)
-            {
-                return;
-            }
-            if (e.KeyCode == Keys.Up)
-            {
-                if (i >= 2 && j >= 0)
-                {
-                    //规则名称不为空
-                    if (Grid_Minerals[i, 0].Value.ToString().Replace(" ", "").Trim() != "")
-                    {
-                        int id = ((STDdata)Grid_Minerals[i, 0].Tag).STDId;
 
-                        m_MainForm.SaveDataOfSelRule(id);
-                        m_MainForm.ChangeSTDEditorAndGrid_Attributes(((STDdata)Grid_Minerals[i - 1, 0].Tag).STDId);
-                        m_MainForm.m_SubMidWindow.m_ComparativeLibrary.MakeCheckboxUnchecked();
-                        Predata = (STDdata)Grid_Minerals[i - 1, 0].Tag;
-                        if (i == 2)
-                        {
-                            button_UpOrder.Enabled = false;
-                        }
-                        if (i == ls_gd.RowsCount - 1)
-                        {
-                            button_DownOrder.Enabled = true;
-                        }
 
-                    }
-                    else
-                    {
-                        Position pos = new Position(i + 1, 0);
-                        Grid_Minerals.Selection.Focus(pos, true);
-                        m_MainForm.m_SubMidWindow.m_ComparativeLibrary.MakeCheckboxUnchecked();
-                    }
-                }
-            }
-            if (e.KeyCode == Keys.Down)
-            {
-                if (i < ls_gd.RowsCount - 1 && j >= 0)
-                {
-                    if (Grid_Minerals[i, 0].Value.ToString().Replace(" ", "").Trim() != "")
-                    {
-                        int id = ((STDdata)Grid_Minerals[i, 0].Tag).STDId;
-                           
-                                m_MainForm.SaveDataOfSelRule(id);
-                                m_MainForm.ChangeSTDEditorAndGrid_Attributes(((STDdata)Grid_Minerals[i + 1, 0].Tag).STDId);
-                                Predata = (STDdata)Grid_Minerals[i+1, 0].Tag;
-                                m_MainForm.m_SubMidWindow.m_ComparativeLibrary.MakeCheckboxUnchecked();
-
-                            if (i == 1)
-                            {
-                                button_UpOrder.Enabled = true;
-                            }
-                            if (i == ls_gd.RowsCount - 2)
-                            {
-                                button_DownOrder.Enabled = false;
-                            }
-                        
-                    }
-                    else
-                    {
-                        Position pos = new Position(i - 1, 0);
-                        Grid_Minerals.Selection.Focus(pos, true);
-                        m_MainForm.m_SubMidWindow.m_ComparativeLibrary.MakeCheckboxUnchecked();
-                    }
-                }
-            }
+
+
+        private void Grid_Minerals_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
+        {
+            
             if (e.KeyCode == Keys.Delete)
             {
-                Grid_MineralsDelRow();
+                ToolStripMenuItem_Del_Click(null, null);
             }
         }
         public int ChangeSTDRulesLISTBackColor()
         {
-            if (tabControl1.SelectedIndex == 1)
+            if (treeView_G.SelectedNode.Level == 0)
             {
-                if (Grid_Minerals.RowsCount > 1)
-                {
-                    Position pos = new Position(1, 0);
-                    Grid_Minerals[1, 0].Grid.Select();
-
-                    Grid_Minerals[Grid_Minerals.Selection.ActivePosition.Row, 1].View.BackColor = m_MainForm.m_Attributes.Grid_Attributes[3, 1].View.BackColor;
-                    m_MainForm._sTDEditor.STDDictionary[((STDdata)Grid_Minerals[Grid_Minerals.Selection.ActivePosition.Row, 0].Tag).STDId].Color = Attributes.colorRGBtoHx16(m_MainForm.m_Attributes.Grid_Attributes[3, 1].View.BackColor.R, m_MainForm.m_Attributes.Grid_Attributes[3, 1].View.BackColor.G, m_MainForm.m_Attributes.Grid_Attributes[3, 1].View.BackColor.B);
-                    Grid_Minerals.Refresh();
-                    return ((STDdata)Grid_Minerals[Grid_Minerals.Selection.ActivePosition.Row, 0].Tag).STDId;
-                }
-                else
-                {
-                    return -1;
-                }
+                return -1;
             }
-            else
+            STDdata ddata = (STDdata)treeView_G.SelectedNode.Tag;
+            int id = ddata.STDId;
+            foreach(STDdata ddata1 in ((STDGroups)treeView_G.SelectedNode.Parent.Tag).ContainSTD)
             {
-                if(treeView_G.SelectedNode.Level==0)
+                if(ddata1.STDId== ddata.STDId)
                 {
-                    return -1;
-                }
-                STDdata ddata = (STDdata)treeView_G.SelectedNode.Tag;
-                int id= ddata.STDId;
-                m_MainForm._sTDEditor.STDDictionary[id].Color = Attributes.colorRGBtoHx16(m_MainForm.m_Attributes.Grid_Attributes[3, 1].View.BackColor.R, m_MainForm.m_Attributes.Grid_Attributes[3, 1].View.BackColor.G, m_MainForm.m_Attributes.Grid_Attributes[3, 1].View.BackColor.B);
-                InitGroupView();
-                foreach(TreeNode treeNode in treeView_G.Nodes)
-                {
-                    if(((STDGroups)treeNode.Tag).id== ddata.GroupId)
-                    {
-                        foreach (TreeNode node in treeNode.Nodes)
-                        {
-                            if (((STDdata)node.Tag).STDId == id)
-                            {
-                                treeView_G.SelectedNode = node;
-                                Predata = (STDdata)node.Tag;
-                            }
-                        }
-                    }
+                    ddata1.Color = Attributes.colorRGBtoHx16(m_MainForm.m_Attributes.Grid_Attributes[3, 1].View.BackColor.R, m_MainForm.m_Attributes.Grid_Attributes[3, 1].View.BackColor.G, m_MainForm.m_Attributes.Grid_Attributes[3, 1].View.BackColor.B);
+                    break;
                 }
-                return id;
             }
-        }
-        private void button_UpOrder_Click(object sender, EventArgs e)
-        {
-            
-        }
-        private void button_DownOrder_Click(object sender, EventArgs e)
-        {
-            
-        }
-
-        public void InsertNewRow(int STDId, string RuleName, Color color)
-        {
-            Grid_Minerals.Focus(true);
-            Grid_Minerals.Rows.InsertRange(Grid_Minerals.Selection.ActivePosition.Row, 1);
-            int i = Grid_Minerals.Selection.ActivePosition.Row;
-            Grid_Minerals[Grid_Minerals.Selection.ActivePosition.Row, 0] = new SourceGrid.Cells.Cell(RuleName, typeof(string));
-            Grid_Minerals[Grid_Minerals.Selection.ActivePosition.Row, 0].Tag = m_MainForm._sTDEditor.STDDictionary[STDId];
-            Grid_Minerals.Rows[Grid_Minerals.Selection.ActivePosition.Row].Height = 25;
-            Grid_Minerals[Grid_Minerals.Selection.ActivePosition.Row, 1] = new SourceGrid.Cells.Cell();
-            m_MainForm.ChangeSTDEditorAndGrid_Attributes(STDId);
-
-            Grid_Minerals.Focus(true);
-            SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
-            view.BackColor = color;
-            Grid_Minerals[Grid_Minerals.Selection.ActivePosition.Row, 1].View = view;
-            Position pos = new Position(Grid_Minerals.Selection.ActivePosition.Row, 0);
-            Grid_Minerals.Selection.Focus(pos, true);
-            Predata = (STDdata)Grid_Minerals[Grid_Minerals.Selection.ActivePosition.Row - 1, 0].Tag ;
-            SetOrderButtonsStatus();
-        }
-        void SetOrderButtonsStatus()
-        {
-            Grid_Minerals.Focus();
-            int i = Grid_Minerals.Selection.ActivePosition.Row;
-            int j = Grid_Minerals.Selection.ActivePosition.Column;
-            if (i != -1)
+            InitGroupView();
+            foreach (TreeNode treeNode in treeView_G.Nodes)
             {
-                if (i == 1)
-                {
-                    button_UpOrder.Enabled = false;
-                }
-                else
-                {
-                    button_UpOrder.Enabled = true;
-                }
-                if (i == Grid_Minerals.RowsCount - 1)
-                {
-                    button_DownOrder.Enabled = false;
-                }
-                else
+                if (((STDGroups)treeNode.Tag).id == ddata.GroupId)
                 {
-                    button_DownOrder.Enabled = true;
-                }
-            }
-            else
-            {
-                button_UpOrder.Enabled = false;button_DownOrder.Enabled = false;
-            }
-        }
-
+                    foreach (TreeNode node in treeNode.Nodes)
+                    {
+                        if (((STDdata)node.Tag).STDId == id)
+                        {
+                            treeView_G.SelectedNode = node;
+                            Predata = (STDdata)node.Tag;
+                            break;
 
-        private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
-        {
-            if (Predata != null)
-            {
-                m_MainForm.SaveDataOfSelRule(Predata.STDId);
-            }
-            if (tabControl1.SelectedIndex == 0)
-            {
-                Predata = null;
-                InitGroupEditorView();
-            }
-            else if (tabControl1.SelectedIndex == 1)
-            {
-                ConvertToRuleViewDic();
-                InitRuleView();
-                if (m_MainForm._sTDEditor.STDDictionary.Count == 0)
-                {
-                    m_MainForm.SetNull();
-                    Predata = null;
-                }
-                else
-                {
 
-                    Position pos = new Position(1, 0);
-                    Grid_Minerals[1, 0].Grid.Select();
-                    Grid_Minerals.Selection.Focus(pos, true);
-                    Grid_Minerals.Refresh();
-                    m_MainForm.ChangeSTDEditorAndGrid_Attributes(((STDdata)Grid_Minerals[1, 0].Tag).STDId);
-                    
-                    Predata = (STDdata)Grid_Minerals[1, 0].Tag;
+                        }
+                    }
                 }
-                //}
             }
+            return id;
         }
-        void InitGroupEditorView()
+        public void InitGroupEditorView()
         {
             GroupViewDic = ConvertToGroupViewDic();
             InitGroupView();
         }
-
         Dictionary<int, STDGroups> ConvertToGroupViewDic()
         {
             Dictionary<int, STDGroups> keyValuePairs = new Dictionary<int, STDGroups>();
@@ -457,19 +155,18 @@ namespace OTSPartA_STDEditor
             m_MainForm._sTDEditor.GroupIdDictionaryFromId.Clear();
             m_MainForm._sTDEditor.GroupIdDictionaryFromName.Clear();
             m_MainForm._sTDEditor.STDDictionary.Clear();
-            for(int i=0;i< treeView_G.Nodes.Count;i++)
-            {
-                STDGroups tDGroups = (STDGroups)treeView_G.Nodes[i].Tag;
-                GroupViewDic[tDGroups.id].iorder = i;
-            }
-            foreach (STDGroups group in GroupViewDic.Values)
+            foreach (TreeNode treeNode in treeView_G.Nodes)
             {
-                foreach (STDdata Ddata in group.ContainSTD)
+                STDGroups tDGroups = (STDGroups)treeNode.Tag;
+                GroupViewDic[tDGroups.id].iorder = treeNode.Index;
+                foreach (TreeNode treeNode1 in treeNode.Nodes)
                 {
+                    STDdata Ddata = (STDdata)treeNode1.Tag;
+                    Ddata.ListNum = treeNode1.Index.ToString();
                     m_MainForm._sTDEditor.STDDictionary.Add(Ddata.STDId, Ddata);
                 }
-                m_MainForm._sTDEditor.GroupIdDictionaryFromName.Add(group.name.ToString(), int.Parse(group.id.ToString()));
-                m_MainForm._sTDEditor.GroupIdDictionaryFromId.Add(int.Parse(group.id.ToString()), group.name.ToString());
+                m_MainForm._sTDEditor.GroupIdDictionaryFromName.Add(tDGroups.name.ToString(), int.Parse(tDGroups.id.ToString()));
+                m_MainForm._sTDEditor.GroupIdDictionaryFromId.Add(int.Parse(tDGroups.id.ToString()), tDGroups.name.ToString());
             }
             if (treeView_G.SelectedNode == null){return;}
             if (treeView_G.SelectedNode.Level == 1)
@@ -482,6 +179,12 @@ namespace OTSPartA_STDEditor
 
 
 
+
+
+
+
+
+
         private void ToolStripMenuItem_NewGroup_Click(object sender, EventArgs e)
         {
             STDGroups group = new STDGroups();
@@ -497,55 +200,100 @@ namespace OTSPartA_STDEditor
             group.id = id;
             group.name = "Group" + id.ToString();
             group.color = Attributes.colorRGBtoHx16(Color.WhiteSmoke.R, Color.WhiteSmoke.G, Color.WhiteSmoke.B);
+            group.iorder = GroupViewDic.Count-1;
             GroupViewDic.Add(group.id, group);
             m_MainForm.m_Attributes.AddSTDGroupsToAttribute();
-            this.Refresh();
-            TreeNode treeNode = new TreeNode();
-            treeNode.Tag = group;
-            treeNode.Text = group.name;
             m_MainForm._sTDEditor.GroupIdDictionaryFromId.Add(id, group.name);
             m_MainForm._sTDEditor.GroupIdDictionaryFromName.Add(group.name, group.id);
-            treeView_G.Nodes.Add(treeNode);
-            treeView_G.SelectedNode = treeNode;
+            InitGroupView();
+            foreach (TreeNode treeNode in treeView_G.Nodes)
+            {
+                if (((STDGroups)treeNode.Tag).id == id)
+                {
+                    treeView_G.SelectedNode = treeNode;
+                    break;
+                }
+            }
             m_MainForm.SetNull();
             Predata = null;
+            this.Refresh();
         }
-
-
-
-        private void ToolStripMenuItem_DelGroup_Click(object sender, EventArgs e)
+        private void ToolStripMenuItem_Del_Click(object sender, EventArgs e)
         {
-            if(treeView_G.SelectedNode==null)
+            if (treeView_G.SelectedNode == null)
             {
-                MessageBox.Show("Please select a group!", "Tip");
+                MessageBox.Show("Please select a node!", "Tip");
                 return;
             }
             if (treeView_G.SelectedNode.Level == 0)
             {
                 int id = ((STDGroups)treeView_G.SelectedNode.Tag).id;
-                if(((STDGroups)treeView_G.SelectedNode.Tag).id==0)
+                if (((STDGroups)treeView_G.SelectedNode.Tag).id == 0)
                 {
                     MessageBox.Show("Can not delete the group which named default!", "Tip");
                     return;
                 }
-                DialogResult result = MessageBox.Show("删除组会一并删除组内规则,是否继续?", "Tip", MessageBoxButtons.YesNo);
-                if (result == DialogResult.Yes)
+                m_MainForm._sTDEditor.GroupIdDictionaryFromId.Remove(id);
+
+                m_MainForm._sTDEditor.GroupIdDictionaryFromName.Remove(GroupViewDic[id].name);
+                foreach (TreeNode treeNode1 in treeView_G.Nodes)
+                {
+                    if (((STDGroups)treeNode1.Tag).name == "Default")
+                    {
+                        if (Predata != null)
+                        {
+                            m_MainForm.SaveDataOfSelRule(Predata.STDId);
+                        }
+                        foreach (STDdata ddata in GroupViewDic[((STDGroups)treeView_G.SelectedNode.Tag).id].ContainSTD)
+                        {
+                            ddata.GroupId = ((STDGroups)treeNode1.Tag).id;
+                            ddata.ListNum = "1000";
+                        }
+                        GroupViewDic[((STDGroups)treeNode1.Tag).id].ContainSTD.AddRange(GroupViewDic[((STDGroups)treeView_G.SelectedNode.Tag).id].ContainSTD);
+
+                        GroupViewDic.Remove(id);
+                        InitGroupView();
+                        break;
+                    }
+                }
+                foreach (TreeNode treeNode1 in treeView_G.Nodes)
                 {
-                    m_MainForm._sTDEditor.GroupIdDictionaryFromId.Remove(id);
-                    m_MainForm._sTDEditor.GroupIdDictionaryFromName.Remove(GroupViewDic[id].name);
-                    GroupViewDic.Remove(id);
-                    treeView_G.Nodes.Remove(treeView_G.SelectedNode);
-                    this.Refresh();
+                    if (((STDGroups)treeNode1.Tag).name == "Default")
+                    {
+                        treeView_G.SelectedNode = treeNode1;
+                        m_MainForm.SetNull();
+                        Predata = null;
+                        break;
+                    }
                 }
             }
             else
             {
-                MessageBox.Show("Please select a group!", "Tip");
-
-                return;
+                foreach (int grpid in GroupViewDic.Keys)
+                {
+                    foreach (STDdata ddata in GroupViewDic[grpid].ContainSTD)
+                    {
+                        if (ddata.STDId == ((STDdata)treeView_G.SelectedNode.Tag).STDId)
+                        {
+                            GroupViewDic[grpid].ContainSTD.Remove(ddata);
+                            break;
+                        }
+                    }
+                }
+                treeView_G.SelectedNode.Remove();
+                if (treeView_G.SelectedNode != null&& treeView_G.SelectedNode.Level !=0)
+                {
+                    m_MainForm.ChangeSTDEditorAndGrid_Attributes((STDdata)treeView_G.SelectedNode.Tag);
+                    Predata = (STDdata)treeView_G.SelectedNode.Tag;
+                }
+                else
+                {
+                    m_MainForm.SetNull();
+                    Predata = null;
+                }
+                this.Refresh();
             }
         }
-
         private void ToolStripMenuItem_EdGroupColor_Click(object sender, EventArgs e)
         {
             if(treeView_G.SelectedNode==null)
@@ -555,6 +303,12 @@ namespace OTSPartA_STDEditor
             }
             if (treeView_G.SelectedNode.Level == 0)
             {
+                if (treeView_G.SelectedNode.Text == "Default")
+                {
+                    MessageBox.Show("The default group cannot be changed!", "Tip");
+                    treeView_G.SelectedNode.EndEdit(true);
+                    return;
+                }
                 ColorDialog cd = new ColorDialog();
                 cd.FullOpen = true;//自定义颜色界面打开
                 DialogResult result = cd.ShowDialog();
@@ -569,7 +323,7 @@ namespace OTSPartA_STDEditor
                 MessageBox.Show("Please select a group!", "Tip");
             }
         }
-        void InitGroupView()
+        public void InitGroupView()
         {
             treeView_G.ImageList=new ImageList();
             treeView_G.Nodes.Clear();
@@ -579,12 +333,11 @@ namespace OTSPartA_STDEditor
             {
                 if (group.name == "Default")
                 {
-                    group.iorder = 9999999;
+                    group.iorder = 10000;
                 }
                 groups.Add(group);
             }
 
-            
             groups=groups.OrderBy(s => s.iorder).ToList();
             
             for (int i=0;i< groups.Count;i++)
@@ -601,8 +354,10 @@ namespace OTSPartA_STDEditor
                 treeNode.ImageKey = groups[i].id.ToString();
                 treeNode.SelectedImageKey = groups[i].id.ToString();
                 treeView_G.Nodes.Add(treeNode);
-                foreach (STDdata ddata in groups[i].ContainSTD)
+                groups[i].ContainSTD= groups[i].ContainSTD.OrderBy(s => int.Parse(s.ListNum)).ToList();
+                for(int j=0;j<groups[i].ContainSTD.Count;j++)
                 {
+                    STDdata ddata = groups[i].ContainSTD[j];
                     TreeNode childtreeNode = new TreeNode();
                     childtreeNode.Tag = ddata;
                     childtreeNode.Text = ddata.StrName;
@@ -621,62 +376,6 @@ namespace OTSPartA_STDEditor
             treeView_G.ShowLines = false;
             this.Refresh();
         }
-        void InitRuleView()
-        {
-            Grid_Minerals.Rows.Clear();
-            Grid_Minerals.Columns.Clear();
-
-            Grid_Minerals.Redim(m_MainForm._sTDEditor.STDDictionary.Count + 1, 2);
-            SourceGrid.Cells.ColumnHeader head1 = null;
-            if (m_MainForm.lan.GetNameTable("Form_Main")["language"].ToString() == "EN")
-            {
-                head1 = new SourceGrid.Cells.ColumnHeader("Rule Name");
-            }
-            else
-            {
-                head1 = new SourceGrid.Cells.ColumnHeader("规则名称");
-            }
-            Grid_Minerals[0, 0] = head1;
-
-            SourceGrid.Cells.ColumnHeader head2 = null;
-            if (m_MainForm.lan.GetNameTable("Form_Main")["language"].ToString() == "EN")
-            {
-                head2 = new SourceGrid.Cells.ColumnHeader("Color");
-            }
-            else
-            {
-                head2 = new SourceGrid.Cells.ColumnHeader("颜色");
-            }
-            Grid_Minerals[0, 1] = head2;
-            SourceGrid.Cells.Views.ColumnHeader boldHeader = new SourceGrid.Cells.Views.ColumnHeader();
-            boldHeader.Font = new Font("Microsoft YaHei UI", 11, FontStyle.Bold);
-            boldHeader.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter;
-            Grid_Minerals[0, 0].View = boldHeader;
-            Grid_Minerals[0, 1].View = boldHeader;
-            Grid_Minerals.Rows.SetHeight(0, 25);
-            head1.AutomaticSortEnabled = false;
-            head2.AutomaticSortEnabled = false;
-            Grid_Minerals.Selection.EnableMultiSelection = false;
-            Grid_Minerals.AutoStretchColumnsToFitWidth = true;
-            Grid_Minerals.Columns[0].Width = this.Width / 2 - 15;
-            Grid_Minerals.Columns[1].Width = this.Width / 2 - 39;
-            int i = 1;
-            foreach (KeyValuePair<int, STDdata> kv in m_MainForm._sTDEditor.STDDictionary)
-            {
-                Grid_Minerals[i, 0] = new SourceGrid.Cells.Cell(kv.Value.StrName, typeof(string));
-                Grid_Minerals.Rows[i].Height = 25;
-                Grid_Minerals[i, 0].Tag = kv.Value;
-                Grid_Minerals[i, 1] = new SourceGrid.Cells.Cell();
-                SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
-                view.BackColor = colorHx16toRGB(kv.Value.Color);
-                Grid_Minerals[i, 1].View = view;
-                i++;
-            }
-            Grid_Minerals.Controller.AddController(m_ValueChangedEvent);
-            Grid_Minerals.FixedRows = 1;
-            Grid_Minerals.Selection.FocusStyle = FocusStyle.None;
-        }
-
         private void treeView_G_ItemDrag(object sender, ItemDragEventArgs e)
         {
             if (e.Button == MouseButtons.Left)
@@ -695,6 +394,10 @@ namespace OTSPartA_STDEditor
             if (m_targetNode != null)
             {
                 TreeNode _node = (TreeNode)e.Data.GetData(typeof(TreeNode));
+                if (Predata != null)
+                {
+                    m_MainForm.SaveDataOfSelRule(Predata.STDId);
+                }
                 if (_node.Level == 1)
                 {
                     if (!m_targetNode.Equals(_node))
@@ -706,6 +409,9 @@ namespace OTSPartA_STDEditor
                                 _node.Remove();
                                 m_targetNode.Parent.Nodes.Insert(m_targetNode.Index+1, _node);
                                 m_targetNode.Parent.ExpandAll();
+                                treeView_G.SelectedNode = _node;
+                                m_MainForm.ChangeSTDEditorAndGrid_Attributes((STDdata)_node.Tag);
+                                Predata = (STDdata)_node.Tag;
                             }
                             else
                             {
@@ -716,7 +422,7 @@ namespace OTSPartA_STDEditor
                                 GroupViewDic[((STDGroups)m_targetNode.Parent.Tag).id].ContainSTD.Add((STDdata)_node.Tag);
                                 treeView_G.SelectedNode = _node; // 选中节点
                                 m_targetNode.Parent.Expand(); // 展开父节点
-                                m_MainForm.ChangeSTDEditorAndGrid_Attributes(int.Parse(((STDdata)_node.Tag).STDId.ToString()));
+                                m_MainForm.ChangeSTDEditorAndGrid_Attributes((STDdata)_node.Tag);
                                 Predata = (STDdata)_node.Tag;
                             }
                         }
@@ -729,13 +435,15 @@ namespace OTSPartA_STDEditor
                             GroupViewDic[((STDGroups)m_targetNode.Tag).id].ContainSTD.Add((STDdata)_node.Tag);
                             treeView_G.SelectedNode = _node; // 选中节点
                             m_targetNode.Expand(); // 展开父节点
-                            m_MainForm.ChangeSTDEditorAndGrid_Attributes(int.Parse(((STDdata)_node.Tag).STDId.ToString()));
+                            m_MainForm.ChangeSTDEditorAndGrid_Attributes((STDdata)_node.Tag);
                             Predata = (STDdata)_node.Tag;
                         }
                     }
                 }
                 else
                 {
+                    m_MainForm.SetNull();
+                    Predata = null;
                     if (!m_targetNode.Equals(_node)&& m_targetNode.Text != "Default")
                     {
                         if (m_targetNode.Level == _node.Level)
@@ -743,16 +451,12 @@ namespace OTSPartA_STDEditor
                             _node.Remove();
                             treeView_G.Nodes.Insert(m_targetNode.Index+1, _node);
                             treeView_G.SelectedNode = _node;
-                            m_MainForm.SetNull();
-                            Predata = null;
                         }
                         else
                         {
                             _node.Remove();
                             treeView_G.Nodes.Insert(m_targetNode.Parent.Index+1, _node);
                             treeView_G.SelectedNode = _node;
-                            m_MainForm.SetNull();
-                            Predata = null;
                         }
                     }
                 }
@@ -763,7 +467,6 @@ namespace OTSPartA_STDEditor
 
         [DllImport("user32.dll")]
         private static extern int SendMessage(IntPtr hWnd, int wMsg, int wParam,int lParam);
-
         private void treeView_G_DragOver(object sender, DragEventArgs e)
         {
             const Single scrollRegion = 20;
@@ -779,6 +482,9 @@ namespace OTSPartA_STDEditor
             TreeNode _node2 = treeView_G.GetNodeAt(treeView_G.PointToClient(new Point(e.X, e.Y)));
             m_targetNode = null;
 
+
+
+
             if (_node2 != null)
             {
                 m_targetNode = _node2;
@@ -791,8 +497,7 @@ namespace OTSPartA_STDEditor
         }
         private void treeView_G_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
         {
-
-            if(Predata!=null)
+            if (Predata!=null)
             {
                 m_MainForm.SaveDataOfSelRule(Predata.STDId);
             }
@@ -804,8 +509,9 @@ namespace OTSPartA_STDEditor
             }
             else
             {
-                m_MainForm.ChangeSTDEditorAndGrid_Attributes(int.Parse(((STDdata)e.Node.Tag).STDId.ToString()));
+                m_MainForm.ChangeSTDEditorAndGrid_Attributes((STDdata)e.Node.Tag);
                 Predata = (STDdata)e.Node.Tag;
+                treeView_G.SelectedNode = e.Node;
             }
         }
         public void AdjustTreenodeByGroup(int Groupid)
@@ -844,24 +550,25 @@ namespace OTSPartA_STDEditor
                         GroupViewDic[Groupid].ContainSTD.Add(ddata);
                         treeView_G.SelectedNode = node1;
                         nodenew.Expand();
-                        m_MainForm.ChangeSTDEditorAndGrid_Attributes(int.Parse(((STDdata)node1.Tag).STDId.ToString()));
+                        m_MainForm.ChangeSTDEditorAndGrid_Attributes((STDdata)node1.Tag);
                         Predata = ddata;
                         break;
                     }
                 }
             }
         }
-        private void ToolStripMenuItem_RenameGroup_Click(object sender, EventArgs e)
+        private void ToolStripMenuItem_Rename_Click(object sender, EventArgs e)
         {
             if (treeView_G.SelectedNode != null)
             {
-                
+                RenFlag = true;
+                treeView_G.SelectedNode.Text = "";
                 if (treeView_G.SelectedNode.Level == 0)
                 {
 
                     if (treeView_G.SelectedNode.Text == "Default")
                     {
-                        MessageBox.Show("默认组不能更改名称!", "Tip");
+                        MessageBox.Show("The default group cannot be changed!", "Tip");
                         treeView_G.SelectedNode.EndEdit(true);
                         return;
                     }
@@ -872,8 +579,7 @@ namespace OTSPartA_STDEditor
                 }
                 else
                 {
-                    MessageBox.Show("Please select a group!", "Tip");
-                    treeView_G.SelectedNode.EndEdit(true);
+                    treeView_G.SelectedNode.BeginEdit();
                 }
             }
         }
@@ -881,25 +587,192 @@ namespace OTSPartA_STDEditor
         {
             if (treeView_G.SelectedNode.Level == 0)
             {
-                if(e.Label==null|| e.Label =="")
+                if(e.Label == null|| e.Label == "")
                 {
                     MessageBox.Show("GroupName Cannot Be Null!", "Tip");
                     e.CancelEdit=true;
+                    treeView_G.SelectedNode.Text = ((STDGroups)treeView_G.SelectedNode.Tag).name;
                     return;
                 }
-                STDGroups Group = (STDGroups)treeView_G.SelectedNode.Tag;
-                m_MainForm._sTDEditor.GroupIdDictionaryFromId.Remove(Group.id);
-                m_MainForm._sTDEditor.GroupIdDictionaryFromName.Remove(GroupViewDic[Group.id].name);
-                GroupViewDic[Group.id].name = e.Label;
-                m_MainForm._sTDEditor.GroupIdDictionaryFromId.Add(Group.id, Group.name);
-                m_MainForm._sTDEditor.GroupIdDictionaryFromName.Add(GroupViewDic[Group.id].name, Group.id);
-                m_MainForm.m_Attributes.AddSTDGroupsToAttribute();
+                if (e.Label != null && e.Label != "")
+                {
+                    if (m_MainForm._sTDEditor.GroupIdDictionaryFromName.ContainsKey(e.Label))
+                    {
+                        MessageBox.Show("Group names cannot be duplicated!", "Tip");
+                        e.CancelEdit = true;
+                        return;
+                    }
+                    else
+                    {
+                        STDGroups Group = (STDGroups)treeView_G.SelectedNode.Tag;
+                        m_MainForm._sTDEditor.GroupIdDictionaryFromId.Remove(Group.id);
+                        m_MainForm._sTDEditor.GroupIdDictionaryFromName.Remove(GroupViewDic[Group.id].name);
+                        GroupViewDic[Group.id].name = e.Label;
+                        m_MainForm._sTDEditor.GroupIdDictionaryFromId.Add(Group.id, Group.name);
+                        m_MainForm._sTDEditor.GroupIdDictionaryFromName.Add(GroupViewDic[Group.id].name, Group.id);
+                        m_MainForm.m_Attributes.AddSTDGroupsToAttribute();
+                    }
+                }
             }
             else
             {
-                MessageBox.Show("Please select a group!", "Tip");
-                return;
+                if (e.Label == null || e.Label == "") 
+                {
+                    MessageBox.Show("RuleName Cannot Be Null!", "Tip");
+                    e.CancelEdit = true;
+                    treeView_G.SelectedNode.Text = ((STDdata)treeView_G.SelectedNode.Tag).StrName;
+                    return;
+                }
+                if (e.Label != null && e.Label != "")
+                {
+                    STDdata sT = (STDdata)treeView_G.SelectedNode.Tag;
+                    foreach (int grpid in GroupViewDic.Keys)
+                    {
+                        foreach (STDdata ddata in GroupViewDic[grpid].ContainSTD)
+                        {
+                            if (ddata.STDId == ((STDdata)treeView_G.SelectedNode.Tag).STDId)
+                            {
+                                ddata.StrName = e.Label;
+                                m_MainForm.ChangeSTDEditorAndGrid_Attributes(ddata);
+                                break;
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        private void ToolStripMenuItem_NewRule_Click(object sender, EventArgs e)
+        {
+            TreeNode _node2 = treeView_G.SelectedNode;
+            if (_node2 != null)
+            {
+                if (Predata != null)
+                {
+                    m_MainForm.SaveDataOfSelRule(Predata.STDId);
+                }
+                STDdata ddata= m_MainForm._sTDEditor.AddSTDDictionaryItem();
+                int STDId = 40000;
+                foreach (STDGroups grp in GroupViewDic.Values)
+                {
+                    foreach (STDdata ddata1 in grp.ContainSTD)
+                    {
+                        if (STDId < ddata1.STDId)
+                        {
+                            STDId = ddata1.STDId;
+                        }
+                    }
+                }
+                ddata.STDId = STDId + 1;
+                TreeNode treeNode = new TreeNode();
+                treeNode.Text = ddata.StrName;
+                treeNode.Tag = ddata;
+                if (_node2.Level == 0)
+                {
+                    ddata.ListNum = ((((STDGroups)treeView_G.SelectedNode.Tag).ContainSTD).Count - 1).ToString();
+                    ddata.GroupId = ((STDGroups)_node2.Tag).id;
+                    ((STDGroups)treeView_G.SelectedNode.Tag).ContainSTD.Add(ddata);
+                    _node2.Nodes.Add(treeNode);
+                }
+                else
+                {
+                    ddata.ListNum = ((((STDGroups)treeView_G.SelectedNode.Parent.Tag).ContainSTD).Count - 1).ToString();
+                    ddata.GroupId = ((STDGroups)_node2.Parent.Tag).id;
+                    ((STDGroups)treeView_G.SelectedNode.Parent.Tag).ContainSTD.Add(ddata);
+                    _node2.Parent.Nodes.Add(treeNode);
+                }
+                m_MainForm.ChangeSTDEditorAndGrid_Attributes(ddata);
+                Predata = (STDdata)treeNode.Tag;
+                InitGroupView();
+                foreach(TreeNode node in treeView_G.Nodes)
+                {
+                    foreach (TreeNode node1 in node.Nodes)
+                    {
+                        if (((STDdata)node1.Tag).STDId == ddata.STDId)
+                        {
+                            treeView_G.SelectedNode = node1;
+                            this.Refresh();
+                            break;
+                        }
+                    }
+                }
+            }
+            else
+            {
+                foreach (TreeNode treeNode1 in treeView_G.Nodes)
+                {
+                    if (((STDGroups)treeNode1.Tag).name == "Default")
+                    {
+                        if(Predata != null)
+                        { 
+                        m_MainForm.SaveDataOfSelRule(Predata.STDId);
+                        }
+                        STDdata ddata = m_MainForm._sTDEditor.AddSTDDictionaryItem();
+                        int STDId = 40000;
+                        foreach (STDGroups grp in GroupViewDic.Values)
+                        {
+                            foreach (STDdata ddata1 in grp.ContainSTD)
+                            {
+                                if (STDId < ddata1.STDId)
+                                {
+                                    STDId = ddata1.STDId;
+                                }
+                            }
+                        }
+                        ddata.STDId = STDId + 1;
+                        TreeNode treeNode = new TreeNode();
+                        treeNode.Text= ddata.StrName;
+                        treeNode.Tag = ddata;
+
+                        ddata.ListNum = ((((STDGroups)treeNode1.Tag).ContainSTD).Count - 1).ToString();
+                        ddata.GroupId = ((STDGroups)treeNode1.Tag).id;
+                        ((STDGroups)treeNode1.Tag).ContainSTD.Add(ddata);
+                        InitGroupView();
+
+                        foreach (TreeNode node in treeView_G.Nodes)
+                        {
+                            foreach (TreeNode node1 in node.Nodes)
+                            {
+                                if (((STDdata)node1.Tag).STDId == ddata.STDId)
+                                {
+                                    treeView_G.SelectedNode = node1;
+                                    m_MainForm.ChangeSTDEditorAndGrid_Attributes(ddata);
+                                    Predata = (STDdata)treeNode.Tag;
+                                    treeView_G.Focus();
+                                    break;
+                                }
+                            }
+                        }
+                        break;
+                    }
+                }
+            }
+        }
+        private void treeView_G_KeyUp(object sender, KeyEventArgs e)
+        {
+            if (e.KeyCode == Keys.Up|| e.KeyCode == Keys.Down)
+            {
+                if (Predata != null)
+                {
+                    int id = Predata.STDId;
+                    m_MainForm.SaveDataOfSelRule(id);
+                }
+                if (treeView_G.SelectedNode.Level != 0 && treeView_G.SelectedNode != null)
+                {
+                    m_MainForm.ChangeSTDEditorAndGrid_Attributes((STDdata)treeView_G.SelectedNode.Tag);
+                    Predata = (STDdata)treeView_G.SelectedNode.Tag;
+                }
+                else
+                {
+                    m_MainForm.SetNull();
+                    Predata = null;
+                }
+                m_MainForm.m_SubMidWindow.m_ComparativeLibrary.MakeCheckboxUnchecked();
             }
         }
+        private void treeView_G_BeforeLabelEdit(object sender, NodeLabelEditEventArgs e)
+        {
+            if (!RenFlag) e.CancelEdit = true;
+            RenFlag = false;
+        }
     }
 }

+ 0 - 3
OTSPartA_STDEditor/UI/STDRuleslist.resx

@@ -117,9 +117,6 @@
   <resheader name="writer">
     <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
   </resheader>
-  <metadata name="MenuStrip_STDRulelist.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
-    <value>17, 17</value>
-  </metadata>
   <metadata name="contextMenuStrip_GroupView.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
     <value>201, 17</value>
   </metadata>

+ 7 - 5
OTSPartA_STDEditor/UI/SubMidWindow.cs

@@ -8,6 +8,7 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using System.Windows.Forms;
+using static System.Windows.Forms.VisualStyles.VisualStyleElement;
 
 namespace OTSPartA_STDEditor
 {
@@ -49,15 +50,16 @@ namespace OTSPartA_STDEditor
             //m_SubMidWindow.m_ComparativeLibrary.DockAreas = OTS.WinFormsUI.Docking.DockAreas.DockTop;
         }
 
-        public void ChangeText_textbox_STDEditor(int STDId)
+        public void ChangeText_textbox_STDEditor(STDdata ddata)
         {
-            m_STDEditor.textbox_STDEditor.Text = m_MainForm._sTDEditor.STDDictionary[STDId].Expression;
-            m_STDEditor.STDId = STDId;
+            STDdata ddata2 = ddata;
+            m_STDEditor.textbox_STDEditor.Text = ddata2.Expression;
+            m_STDEditor.STDId = ddata.STDId;
 
             m_STDEditor.dataGridView_KeyElements.Rows.Clear();
             m_STDEditor.dataGridView_KeyElements.Columns.Clear();
 
-            string[] KeyElement = m_MainForm._sTDEditor.STDDictionary[STDId].KeyElementList.Trim().Split(',');
+            string[] KeyElement = ddata2.KeyElementList.Trim().Split(',');
             for (int i = 0; i < KeyElement.Length; i++)
             {
                 if (KeyElement[0] != "")
@@ -77,7 +79,7 @@ namespace OTSPartA_STDEditor
             m_STDEditor.dataGridView_SubElements.Rows.Clear();
             m_STDEditor.dataGridView_SubElements.Columns.Clear();
 
-            string[] SubElement = m_MainForm._sTDEditor.STDDictionary[STDId].SubElementList.Trim().Split(',');
+            string[] SubElement = ddata2.SubElementList.Trim().Split(',');
             for (int i = 0; i < SubElement.Length; i++)
             {
                 if (SubElement[i] != "")