Просмотр исходного кода

Merge branch 'OTSRelease3_2' of http://36.129.169.60:30080/gogsadmin/OTS into OTSRelease3_2

gsp 3 месяцев назад
Родитель
Сommit
5f0be3b9a0

+ 15 - 7
OTSPartA_STDEditor/BaseClass/STDGroups.cs

@@ -6,19 +6,21 @@ using System.Threading.Tasks;
 
 namespace OTSPartA_STDEditor
 {
-    class STDGroups
+    public class STDGroups
     {
-        //int s_id = 0;
+        int s_id = 0;
         string s_name = "";
         string s_color = "#FFFFFF";
         int i_iorder = 0;
         int i_InfoState = 1;
+        List<STDdata> _ContainSTD=new List<STDdata>();
 
-        //public int id
-        //{
-        //    set { s_id = value; }
-        //    get { return s_id; }
-        //}
+
+        public int id
+        {
+            set { s_id = value; }
+            get { return s_id; }
+        }
         public string name
         {
             set { s_name = value; }
@@ -39,9 +41,15 @@ namespace OTSPartA_STDEditor
             set { i_InfoState = value; }
             get { return i_InfoState; }
         }
+        public List<STDdata> ContainSTD
+        {
+            set { _ContainSTD = value;}
+            get { return _ContainSTD;}
+        }
         public object Clone(STDGroups a_oSource)
         {
             STDGroups MySTDGroups = new STDGroups();
+            MySTDGroups.id=a_oSource.id;
             MySTDGroups.name = a_oSource.name;
             MySTDGroups.color = a_oSource.color;
             MySTDGroups.iorder = a_oSource.iorder;

+ 18 - 9
OTSPartA_STDEditor/BaseClass/STDdata.cs

@@ -8,7 +8,7 @@ namespace OTSPartA_STDEditor
 {
     public class STDdata
     {
-        //string s_STDId = "";
+        string s_STDId = "";
         string s_StrName = "";
         string s_Color = "#FFFFFF";
         string s_KeyElementList = "";
@@ -27,11 +27,11 @@ namespace OTSPartA_STDEditor
         bool b_IfElementAnalysis = true;
 
 
-        //public string STDId
-        //{
-        //    set { s_STDId = value; }
-        //    get { return s_STDId; }
-        //}
+        public int STDId
+        {
+            set { s_STDId = value.ToString(); }
+            get { return int.Parse(s_STDId); }
+        }
 
         public string Hardness
         {
@@ -111,10 +111,18 @@ namespace OTSPartA_STDEditor
             get { return s_Expression; }
         }
 
-        public string GroupId
+
+
+
+
+
+
+
+
+        public int GroupId
         {
-            set { s_GroupId = value; }
-            get { return s_GroupId; }
+            set { s_GroupId = value.ToString(); }
+            get { return int.Parse(s_GroupId); }
         }
 
         public string ListNum
@@ -152,6 +160,7 @@ namespace OTSPartA_STDEditor
         public object Clone(STDdata a_oSource)
         {
             STDdata MySTDdata = new STDdata();
+            MySTDdata.STDId = a_oSource.STDId;
             MySTDdata.Hardness = a_oSource.Hardness ;
             MySTDdata.Density = a_oSource.Density ;
             MySTDdata.Electrical_conductivity = a_oSource.Electrical_conductivity ;

+ 1 - 0
OTSPartA_STDEditor/OTSPartA_STDEditor.csproj

@@ -237,6 +237,7 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="BaseClass\Periodic.cs" />
+    <Compile Include="BaseClass\STDInfo.cs" />
     <Compile Include="UI\Attributes.cs">
       <SubType>Form</SubType>
     </Compile>

+ 37 - 11
OTSPartA_STDEditor/UI/Attributes.cs

@@ -196,6 +196,7 @@ namespace OTSPartA_STDEditor
             Grid_Attributes[9, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
             Grid_Attributes[10, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
 
+            AddSTDGroupsToAttribute();
             Grid_Attributes.Selection.FocusStyle = SourceGrid.FocusStyle.None;
             //SourceGrid.Position po = new SourceGrid.Position(1, 0);
             //Grid_Attributes[1, 0].Grid.Select();
@@ -204,22 +205,23 @@ namespace OTSPartA_STDEditor
 
         public void SetDatatoGrid_Attributes(int STDId)
         {
+            STDdata sTDdata = m_MainForm._sTDEditor.STDDictionary[STDId];
             Grid_Attributes[1, 1].Value = STDId;
-            Grid_Attributes[2, 1].Value = m_MainForm.STDDictionary[STDId].StrName;
+            Grid_Attributes[2, 1].Value = sTDdata.StrName;
             SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
-            view.BackColor = colorHx16toRGB(m_MainForm.STDDictionary[STDId].Color);
+            view.BackColor = colorHx16toRGB(sTDdata.Color);
             Grid_Attributes[3, 1].View = view;
-            Grid_Attributes[4, 1].Value = Convert.ToBoolean(m_MainForm.STDDictionary[STDId].IfElementAnalysis);
-            Grid_Attributes[5, 1].Value = m_MainForm.STDDictionary[STDId].Hardness;
-            Grid_Attributes[6, 1].Value = m_MainForm.STDDictionary[STDId].Density;
-            Grid_Attributes[7, 1].Value = m_MainForm.STDDictionary[STDId].Electrical_conductivity;
+            Grid_Attributes[4, 1].Value = Convert.ToBoolean(sTDdata.IfElementAnalysis);
+            Grid_Attributes[5, 1].Value = sTDdata.Hardness;
+            Grid_Attributes[6, 1].Value = sTDdata.Density;
+            Grid_Attributes[7, 1].Value = sTDdata.Electrical_conductivity;
 
-            Grid_Attributes[8, 1].Value = int.Parse(m_MainForm.STDDictionary[STDId].BSE);
-            Grid_Attributes[9, 1].Value = m_MainForm.STDDictionary[STDId].Formula;
-            Grid_Attributes[10, 1].Value = m_MainForm.STDDictionary[STDId].Element;
+            Grid_Attributes[8, 1].Value = int.Parse(sTDdata.BSE);
+            Grid_Attributes[9, 1].Value = sTDdata.Formula;
+            Grid_Attributes[10, 1].Value = sTDdata.Element;
 
             //m_MainForm.AddSTDGroupsToAttribute();
-            Grid_Attributes[11, 1].Value = m_MainForm.GroupIdDictionaryFromId[int.Parse(m_MainForm.STDDictionary[STDId].GroupId)];
+            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();
@@ -245,7 +247,7 @@ namespace OTSPartA_STDEditor
             Grid_Attributes[10, 1].Value = sTDdata.Element;
 
             //m_MainForm.AddSTDGroupsToAttribute();
-            Grid_Attributes[11, 1].Value = m_MainForm.GroupIdDictionaryFromId[int.Parse(sTDdata.GroupId)];
+            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();
@@ -253,5 +255,29 @@ namespace OTSPartA_STDEditor
 
             Grid_Attributes.Refresh();
         }
+
+        public void AddSTDGroupsToAttribute()
+        {
+            List<string> ss = new List<string>();
+            foreach (var item in m_MainForm._sTDEditor.GroupDictionary)
+            {
+                ss.Add(item.Value.name.ToString());
+            }
+            SourceGrid.Cells.Editors.ComboBox GroupIdCBBox = new SourceGrid.Cells.Editors.ComboBox(typeof(string));
+            GroupIdCBBox.StandardValues = ss;
+            GroupIdCBBox.EditableMode = SourceGrid.EditableMode.SingleClick | SourceGrid.EditableMode.Focus;
+            Grid_Attributes[11, 1] = new SourceGrid.Cells.Cell("Default", GroupIdCBBox);
+            GroupIdCBBox.Control.DropDownStyle = ComboBoxStyle.DropDownList;        //设置下拉框为不可以编辑的状态
+            ComboBox winFormsCombo = GroupIdCBBox.Control;
+            winFormsCombo.SelectedValueChanged += (sender, e) =>
+            {
+                if(winFormsCombo.Text=="")
+                {
+                    return;
+                }
+                int Groupid = m_MainForm._sTDEditor.GroupIdDictionaryFromName[winFormsCombo.Text];
+                m_MainForm.m_STDRuleslist.AdjustTreenodeByGroup(Groupid);
+            };
+        }
     }
 }

+ 1 - 3
OTSPartA_STDEditor/UI/Form_GroupId.cs

@@ -74,9 +74,7 @@ namespace OTSPartA_STDEditor
                             }
                         }
                     }
-                    
                 }
-
                 m_dbConnection.Close();
                 return true;
             }
@@ -408,7 +406,7 @@ namespace OTSPartA_STDEditor
             if (x > 0 && (y == 0|| y == 1))
             {
                 bool bexist = false;
-                foreach (KeyValuePair<int, STDdata> kv in m_MainForm.STDDictionary)
+                foreach (KeyValuePair<int, STDdata> kv in m_MainForm._sTDEditor.STDDictionary)
                 {
                     if(kv.Value.GroupId.ToString()== Grid_FroupId[x, 0].Tag.ToString())
                     {

Разница между файлами не показана из-за своего большого размера
+ 114 - 663
OTSPartA_STDEditor/UI/Form_Main.cs


+ 60 - 51
OTSPartA_STDEditor/UI/ReferenceLibrary.cs

@@ -122,7 +122,7 @@ 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();
@@ -134,7 +134,7 @@ namespace OTSPartA_STDEditor
                             new_STDdata.Color = item["Color"].ToString();
                             new_STDdata.KeyElementList = item["KeyElementList"].ToString();
                             new_STDdata.SubElementList = item["SubElementList"].ToString();
-                            new_STDdata.GroupId = item["GroupId"].ToString();
+                            new_STDdata.GroupId = (int)item["GroupId"];
 
                             STDDictionary.Add(int.Parse(item["STDId"].ToString()), new_STDdata);
                         }
@@ -190,10 +190,10 @@ namespace OTSPartA_STDEditor
                 }
 
                 PropGrid.Rows[i].Height = 25;
-                PropGrid.Rows[i].Tag = kv.Key;
+                PropGrid.Rows[i].Tag = kv.Value;
 
                 PropGrid[i, 1] = new SourceGrid.Cells.Cell(kv.Value.StrName, typeof(string));
-                PropGrid[i, 1].Tag = kv.Key;
+                PropGrid[i, 1].Tag = kv.Value;
 
                 PropGrid[i, 2] = new SourceGrid.Cells.Cell("", typeof(string));
 
@@ -208,7 +208,7 @@ namespace OTSPartA_STDEditor
                 PropGrid[i, 8] = new SourceGrid.Cells.Cell(kv.Value.BSE, typeof(string));
                 PropGrid[i, 9] = new SourceGrid.Cells.Cell(kv.Value.Formula, typeof(string));
                 PropGrid[i, 10] = new SourceGrid.Cells.Cell(kv.Value.Element, typeof(string));
-                PropGrid[i, 11] = new SourceGrid.Cells.Cell(ReferenceGroup[int.Parse(kv.Value.GroupId)], typeof(string));
+                PropGrid[i, 11] = new SourceGrid.Cells.Cell(ReferenceGroup[kv.Value.GroupId], typeof(string));
                 i++;
             }
 
@@ -336,7 +336,7 @@ namespace OTSPartA_STDEditor
 
                     // 判断左侧区域是否已经选中了某个stdmineral
                     bool bEnable = false;
-                    bEnable = (-1 == m_SubMidWindow.m_MainForm.m_STDRuleslist.PreRow) ? false : true;
+                    bEnable = (null == m_SubMidWindow.m_MainForm.m_STDRuleslist.Predata) ? false : true;
                     this.insertToolStripMenuItem.Enabled = bEnable;
                 }
             }
@@ -348,6 +348,11 @@ namespace OTSPartA_STDEditor
 
         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;
@@ -357,43 +362,42 @@ namespace OTSPartA_STDEditor
                 //规则名称不为空
                 if (m_SubMidWindow.m_MainForm.m_STDRuleslist.Grid_Minerals[i, 0].Value.ToString().Replace(" ", "").Trim() != "")
                 {
-                    
-                            m_SubMidWindow.m_MainForm.SaveDataOfSelRule(i, j);
-
-                            PropGrid.Focus(true);
-                            int selrow = PropGrid.Selection.ActivePosition.Row;
-                            int STDnum = (int)PropGrid[selrow, 1].Tag;
-                            int STDId = 1;
-                            foreach (KeyValuePair<int, STDdata> kv in m_SubMidWindow.m_MainForm.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;
-                            m_SubMidWindow.m_MainForm.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.PreRow = i;
-                       
-
+                    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;
                 }
 
             }
@@ -420,6 +424,11 @@ namespace OTSPartA_STDEditor
 
         private void addIntoMainLabToolStripMenuItem_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;
@@ -429,8 +438,8 @@ namespace OTSPartA_STDEditor
                 //规则名称不为空
                 if (m_SubMidWindow.m_MainForm.m_STDRuleslist.Grid_Minerals[i, j].Value.ToString().Replace(" ", "").Trim() != "")
                 {
-
-                    m_SubMidWindow.m_MainForm.SaveDataOfSelRule(i, j);
+                    int id = ((STDdata)m_SubMidWindow.m_MainForm.m_STDRuleslist.Grid_Minerals[i, 0].Tag).STDId; ;
+                    m_SubMidWindow.m_MainForm.SaveDataOfSelRule(id);
 
                     AddIntoMainLab();
                 }
@@ -440,15 +449,14 @@ namespace OTSPartA_STDEditor
                 AddIntoMainLab();
             }
         }
-
         void AddIntoMainLab()
         {
             PropGrid.Focus(true);
             int selrow = PropGrid.Selection.ActivePosition.Row;
-            int STDnum = (int)PropGrid[selrow, 1].Tag;
+            int STDnum = ((STDdata)PropGrid[selrow, 1].Tag).STDId;
 
             int STDId = 1;
-            foreach (KeyValuePair<int, STDdata> kv in m_SubMidWindow.m_MainForm.STDDictionary)
+            foreach (KeyValuePair<int, STDdata> kv in m_SubMidWindow.m_MainForm._sTDEditor.STDDictionary)
             {
                 if (STDId < kv.Key)
                 {
@@ -456,6 +464,7 @@ namespace OTSPartA_STDEditor
                 }
             }
             STDdata sT = new STDdata();
+            sT.STDId = STDId + 1;
             sT.BSE = ReferenceDictionary[STDnum].BSE;
             sT.StrName = ReferenceDictionary[STDnum].StrName;
             sT.Color = ReferenceDictionary[STDnum].Color;
@@ -469,18 +478,18 @@ namespace OTSPartA_STDEditor
             sT.SubElementList = ReferenceDictionary[STDnum].SubElementList;
             sT.Electrical_conductivity = ReferenceDictionary[STDnum].Electrical_conductivity;
             sT.Element = ReferenceDictionary[STDnum].Element;
-            if (m_SubMidWindow.m_MainForm.GroupIdDictionaryFromId.ContainsKey(int.Parse(ReferenceDictionary[STDnum].GroupId)))
+            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.STDDictionary.Add(STDId + 1, sT);
+            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.PreRow = m_SubMidWindow.m_MainForm.m_STDRuleslist.Grid_Minerals.RowsCount - 1;
+            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;
         }
     }
 }

+ 7 - 47
OTSPartA_STDEditor/UI/STDEditor.cs

@@ -6,6 +6,7 @@ using System.Linq;
 using System.Windows.Forms;
 using System.Collections;
 using System.Text.RegularExpressions;
+using OTSPartA_STDEditor.BaseClass;
 
 namespace OTSPartA_STDEditor
 {
@@ -15,8 +16,6 @@ namespace OTSPartA_STDEditor
         public SubMidWindow m_SubMidWindow = null;
         public int STDId = -1;
         Hashtable table_STDEditor;
-        //数据库操作对象
-        public SqlLiteClass m_sc = null;
         #endregion
 
         public enum Result
@@ -29,7 +28,6 @@ namespace OTSPartA_STDEditor
         public STDEditor(SubMidWindow SubMidWindow)
         {
             InitializeComponent();
-            m_sc = new SqlLiteClass();
             m_SubMidWindow = SubMidWindow;
 
             X = this.Width;
@@ -39,7 +37,6 @@ namespace OTSPartA_STDEditor
         public STDEditor(SubMidWindow SubMidWindow, string STDDBaddress)
         {
             InitializeComponent();
-            m_sc = new SqlLiteClass(STDDBaddress);
             m_SubMidWindow = SubMidWindow;
 
             X = this.Width;
@@ -51,54 +48,17 @@ namespace OTSPartA_STDEditor
         {
             m_SubMidWindow.m_MainForm.lan = new Language(this);
             table_STDEditor = m_SubMidWindow.m_MainForm.lan.GetNameTable("STDEditor");
-            //初始化comboBox
-            this.comboBox_Elem1.Items.Add("first_elem");
-            this.comboBox_Elem1.Items.Add("second_elem");
-            this.comboBox_Elem1.Items.Add("third_elem");
-            this.comboBox_Elem1.Items.Add("fourth_elem");
-            this.comboBox_Elem1.Items.Add("fifth_elem");
-            this.comboBox_Elem1.Items.Add("sixth_elem");
-            this.comboBox_Elem1.Items.Add("seventh_elem");
-            this.comboBox_Elem1.Items.Add("eighth_elem");
-            this.comboBox_Elem1.Items.Add("ninth_elem");
-            this.comboBox_Elem1.Items.Add("tenth_elem");
+            comboBox_Elem1.Items.AddRange(STDInfo.Elem1);
             comboBox_Elem1.SelectedIndex = comboBox_Elem1.Items.IndexOf("first_elem");
-
-            this.comboBox_Elem.Items.Add("Element#1");
-            this.comboBox_Elem.Items.Add("Element#2");
-            this.comboBox_Elem.Items.Add("Element#3");
-            this.comboBox_Elem.Items.Add("Element#4");
-            this.comboBox_Elem.Items.Add("Element#5");
-            this.comboBox_Elem.Items.Add("Element#6");
-            this.comboBox_Elem.Items.Add("Element#7");
-            this.comboBox_Elem.Items.Add("Element#8");
-            this.comboBox_Elem.Items.Add("Element#9");
-            this.comboBox_Elem.Items.Add("Element#10");
+            this.comboBox_Elem.Items.AddRange(STDInfo.Elem2);
             comboBox_Elem.SelectedIndex = comboBox_Elem.Items.IndexOf("Element#1");
-
-            this.comboBox_ImgProperty.Items.Add("Dmax");              //颗粒最大直径;
-            this.comboBox_ImgProperty.Items.Add("Dmin");              //颗粒最小直径;
-            this.comboBox_ImgProperty.Items.Add("Aspect");            //长宽比;
-            this.comboBox_ImgProperty.Items.Add("Dperp");             //与Dmax垂直直径;
-            this.comboBox_ImgProperty.Items.Add("Dmean");             //平均内接圆直径;
-            this.comboBox_ImgProperty.Items.Add("Area");              //面积;
-            this.comboBox_ImgProperty.Items.Add("Dferet");            //费雷特直径;
-            this.comboBox_ImgProperty.Items.Add("Width");             //宽度(直上直下那种);
-            this.comboBox_ImgProperty.Items.Add("Height");            //高度(直上直下那种)
-            this.comboBox_ImgProperty.Items.Add("Perimeter");         //周长
-            this.comboBox_ImgProperty.Items.Add("Dinscr");            //最大内接圆直径
-            this.comboBox_ImgProperty.Items.Add("Orientation");       //朝向
-            this.comboBox_ImgProperty.Items.Add("Delong");            //展开长度
-            this.comboBox_ImgProperty.Items.Add("Aspectelong");       //展开后长宽比
-            this.comboBox_ImgProperty.Items.Add("Dequalcircle");      //等效圆直径
-            this.comboBox_ImgProperty.Items.Add("Vedio");             //BSE灰度平均值
-
+            this.comboBox_ImgProperty.Items.AddRange(STDInfo.ImgProperty);
             comboBox_ImgProperty.SelectedIndex = comboBox_ImgProperty.Items.IndexOf("Dmax");
 
-            string[] PeriodicTable = { "H", "He", "Li", "Be", "B", "C", "N", "O", "F", "Ne", "Na", "Mg", "Al", "Si", "P", "S", "Cl", "Ar", "K", "Ca", "Sc", "Ti", "V", "Cr", "Mn", "Fe", "Co", "Ni", "Cu", "Zn", "Ga", "Ge", "As", "Se", "Br", "Kr", "Rb", "Sr", "Y", "Zr", "Nb", "Mo", "Tc", "Ru", "Rh", "Pd", "Ag", "Cd", "In", "Sn", "Sb", "Te", "I", "Xe", "Cs", "Ba", "La", "Ce", "Pr", "Nd", "Pm", "Sm", "Eu", "Gd", "Tb", "Dy", "Ho", "Er", "Tm", "Yb", "Lu", "Hf", "Ta", "W", "Re", "Os", "Ir", "Pt", "Au", "Hg", "Tl", "Pb", "Bi", "Po", "At", "Rn", "Fr", "Ra", "Ac", "Th", "Pa", "U", "Np", "Pu", "Am", "Cm", "Bk", "Cf", "Es", "Fm", "Md", "No", "Lr", "Rf", "Db", "Sg", "Bh", "Hs", "Mt", "Ds", "Rg", "Unb" };
-            comboBox_PeriodicTable.Items.AddRange(PeriodicTable);
+            
+            comboBox_PeriodicTable.Items.AddRange(STDInfo.PeriodicTable);
             AutoCompleteStringCollection sc = new AutoCompleteStringCollection();
-            sc.AddRange(PeriodicTable);
+            sc.AddRange(STDInfo.PeriodicTable);
             this.comboBox_PeriodicTable.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
             this.comboBox_PeriodicTable.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.CustomSource;
             this.comboBox_PeriodicTable.AutoCompleteCustomSource = sc;

+ 70 - 11
OTSPartA_STDEditor/UI/STDRuleslist.Designer.cs

@@ -34,7 +34,12 @@
             this.ToolStripMenuItem_Del = new System.Windows.Forms.ToolStripMenuItem();
             this.tabControl1 = new System.Windows.Forms.TabControl();
             this.tabPage_GroupView = new System.Windows.Forms.TabPage();
-            this.treeView1 = new System.Windows.Forms.TreeView();
+            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();
@@ -42,6 +47,7 @@
             this.MenuStrip_STDRulelist.SuspendLayout();
             this.tabControl1.SuspendLayout();
             this.tabPage_GroupView.SuspendLayout();
+            this.contextMenuStrip_GroupView.SuspendLayout();
             this.tabPage_RuleView.SuspendLayout();
             this.SuspendLayout();
             // 
@@ -53,7 +59,6 @@
             this.ToolStripMenuItem_Del});
             this.MenuStrip_STDRulelist.Name = "MenuStrip_STDRulelist";
             this.MenuStrip_STDRulelist.Size = new System.Drawing.Size(101, 48);
-            this.MenuStrip_STDRulelist.Resize += new System.EventHandler(this.MenuStrip_STDRulelist_Resize);
             // 
             // ToolStripMenuItem_New
             // 
@@ -86,7 +91,7 @@
             // 
             // tabPage_GroupView
             // 
-            this.tabPage_GroupView.Controls.Add(this.treeView1);
+            this.tabPage_GroupView.Controls.Add(this.treeView_G);
             this.tabPage_GroupView.Location = new System.Drawing.Point(4, 4);
             this.tabPage_GroupView.Name = "tabPage_GroupView";
             this.tabPage_GroupView.Padding = new System.Windows.Forms.Padding(3);
@@ -95,13 +100,59 @@
             this.tabPage_GroupView.Text = "分组视图";
             this.tabPage_GroupView.UseVisualStyleBackColor = true;
             // 
-            // treeView1
+            // treeView_G
             // 
-            this.treeView1.Dock = System.Windows.Forms.DockStyle.Fill;
-            this.treeView1.Location = new System.Drawing.Point(3, 3);
-            this.treeView1.Name = "treeView1";
-            this.treeView1.Size = new System.Drawing.Size(299, 750);
-            this.treeView1.TabIndex = 0;
+            this.treeView_G.AllowDrop = true;
+            this.treeView_G.ContextMenuStrip = this.contextMenuStrip_GroupView;
+            this.treeView_G.Dock = System.Windows.Forms.DockStyle.Fill;
+            this.treeView_G.LabelEdit = true;
+            this.treeView_G.Location = new System.Drawing.Point(3, 3);
+            this.treeView_G.Name = "treeView_G";
+            this.treeView_G.Size = new System.Drawing.Size(299, 750);
+            this.treeView_G.TabIndex = 0;
+            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);
+            // 
+            // 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.contextMenuStrip_GroupView.Name = "contextMenuStrip_GroupView";
+            this.contextMenuStrip_GroupView.Size = new System.Drawing.Size(137, 92);
+            // 
+            // ToolStripMenuItem_NewGroup
+            // 
+            this.ToolStripMenuItem_NewGroup.Name = "ToolStripMenuItem_NewGroup";
+            this.ToolStripMenuItem_NewGroup.Size = new System.Drawing.Size(136, 22);
+            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";
+            this.ToolStripMenuItem_EDGcolor.Size = new System.Drawing.Size(136, 22);
+            this.ToolStripMenuItem_EDGcolor.Text = "修改组颜色";
+            this.ToolStripMenuItem_EDGcolor.Click += new System.EventHandler(this.ToolStripMenuItem_EdGroupColor_Click);
+            // 
+            // ToolStripMenuItem_RenameGroup
+            // 
+            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);
             // 
             // tabPage_RuleView
             // 
@@ -144,6 +195,7 @@
             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
@@ -155,6 +207,7 @@
             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);
             // 
             // STDRuleslist
@@ -176,6 +229,7 @@
             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);
 
@@ -185,12 +239,17 @@
         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.TabControl tabControl1;
         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 treeView1;
+        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_EDGcolor;
+        public System.Windows.Forms.TabControl tabControl1;
+        private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem_RenameGroup;
     }
 }

+ 571 - 283
OTSPartA_STDEditor/UI/STDRuleslist.cs

@@ -2,22 +2,20 @@
 using SourceGrid;
 using System;
 using System.Collections.Generic;
-using System.ComponentModel;
-using System.Data;
 using System.Drawing;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using System.Drawing.Imaging;
+using System.Runtime.InteropServices;
+
 using System.Windows.Forms;
 
 namespace OTSPartA_STDEditor
 {
     public partial class STDRuleslist : DockContent
     {
-        public int PreRow = 1;//之前选中的位置
+        public STDdata Predata = null;//之前选中的位置
         public Form_Main m_MainForm = null;
         ValueChangedEvent m_ValueChangedEvent = null;//单元格内容改变事件
-
+        Dictionary<int,STDGroups> GroupViewDic=null;
         public STDRuleslist(Form_Main mainForm)
         {
             InitializeComponent();
@@ -25,75 +23,16 @@ namespace OTSPartA_STDEditor
             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");
-            Grid_Minerals.Redim(m_MainForm.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;
-            tabControl1.TabPages.RemoveAt(0);
-            Grid_Minerals.Selection.EnableMultiSelection = false;
-            Grid_Minerals.AutoStretchColumnsToFitWidth = true;
-            Grid_Minerals.Columns[0].Width = this.Width/2-10;
-            Grid_Minerals.Columns[1].Width = this.Width/2-30;
-
-
-            int i = 1;
-            foreach (KeyValuePair<int, STDdata> kv in m_MainForm.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.Key;
-
-
-                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;
-
-
+            InitRuleView();
             button_UpOrder.Enabled = false;
             button_DownOrder.Enabled = false;
         }
+
+
         /// <summary>
         /// [颜色:16进制转成RGB]
         /// </summary>
@@ -124,105 +63,75 @@ namespace OTSPartA_STDEditor
             ls_gd.Focus();
             int i = ls_gd.Selection.ActivePosition.Row;
             int j = ls_gd.Selection.ActivePosition.Column;
-            //string jj =m_MainForm.m_Attributes.Grid_Attributes[10, 1].Value.ToString();
-            /// 保证鼠标点击的GRID行和列是有效的
             if (i >= 0 && j >= 0)
             {
-                ////规则名称不为空
-                //if (Grid_Minerals[i, 0].Value.ToString().Replace(" ", "").Trim() != "")
-                //{
-                //    if (m_MainForm.CheckAttributes() && m_MainForm.Checktextbox_STDEditor())
-                //    {
-
-                m_MainForm.SaveDataOfSelRule(PreRow, 0);
-                m_MainForm.ChangeSTDEditorAndGrid_Attributes(int.Parse(Grid_Minerals[i, 0].Tag.ToString()));
+                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();
-                PreRow = i;
-
-                //    }
-                //    else
-                //    {
-                //        Position pos = new Position(PreRow, 0);
-                //        Grid_Minerals.Selection.Focus(pos, true);
-                //        m_MainForm.m_SubMidWindow.m_ComparativeLibrary.MakeCheckboxUnchecked();
-                //    }
-                //}
-                //else
-                //{
-                //    Position pos = new Position(PreRow, 0);
-                //    Grid_Minerals.Selection.Focus(pos, true);
-                //    m_MainForm.m_SubMidWindow.m_ComparativeLibrary.MakeCheckboxUnchecked();
-                //}
+                Predata = (STDdata)Grid_Minerals[i, 0].Tag;
             }
             SetOrderButtonsStatus();
         }
-        /// <summary>
-        /// 新建
-        /// </summary>
-        /// <param name="sender"></param>
-        /// <param name="e"></param>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
         private void ToolStripMenuItem_New_Click(object sender, EventArgs e)
         {
             int i = Grid_Minerals.Selection.ActivePosition.Row;
             int j = Grid_Minerals.Selection.ActivePosition.Column;
-
-            /// 保证鼠标点击的GRID行和列是有效的
             if (i >= 0 && j >= 0)
             {
-                ////规则名称不为空
-                //if (Grid_Minerals[i, j].Value.ToString().Replace(" ", "").Trim() != "")
-                //{
-                //    if (m_MainForm.CheckAttributes())
-                //    {
-                //        if (m_MainForm.Checktextbox_STDEditor())
-                //        {
-                            m_MainForm.SaveDataOfSelRule(i, j);
-
-                            int STDId = m_MainForm.AddSTDDictionaryItem();
-                            AddNewRow(STDId, "NewRuleName", Attributes.colorHx16toRGB(m_MainForm.STDDictionary[STDId].Color));
-                            m_MainForm.m_SubMidWindow.m_ComparativeLibrary.MakeCheckboxUnchecked();
-                //        }
-                //    }
-                //}
+                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.AddSTDDictionaryItem();
-                AddNewRow(STDId, "NewRuleName", Attributes.colorHx16toRGB(m_MainForm.STDDictionary[STDId].Color));
+                int STDId = m_MainForm._sTDEditor.AddSTDDictionaryItem();
+                AddNewRow(STDId, "NewRuleName", Attributes.colorHx16toRGB(m_MainForm._sTDEditor.STDDictionary[STDId].Color));
                 m_MainForm.m_SubMidWindow.m_ComparativeLibrary.MakeCheckboxUnchecked();
             }
-            //SetOrderButtonsStatus();
         }
-
         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 = STDId;
+            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();
-            //Grid_Minerals[Grid_Minerals.Rows.Count - 1, 1].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
-            m_MainForm.STDDictionary[STDId].StrName = RuleName;
+            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);
-
-            PreRow = Grid_Minerals.Rows.Count - 1;
+            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((int)Grid_Minerals[x, 0].Tag);
+                m_MainForm.RemoveSTDDictionaryItem(((STDdata)Grid_Minerals[x, 0].Tag).STDId);
                 Grid_Minerals.Rows.Remove(x);
                 if (Grid_Minerals.RowsCount > 1)
                 {
@@ -231,9 +140,8 @@ namespace OTSPartA_STDEditor
                         Position pos = new Position(x, 0);
                         Grid_Minerals.Selection.Focus(pos, true);
                         Grid_Minerals[x, 0].Grid.Select();
-
-                        m_MainForm.ChangeSTDEditorAndGrid_Attributes(int.Parse(Grid_Minerals[x, 0].Tag.ToString()));
-                        PreRow = x;
+                        m_MainForm.ChangeSTDEditorAndGrid_Attributes(((STDdata)Grid_Minerals[x, 0].Tag).STDId);
+                        Predata = (STDdata)Grid_Minerals[x, 0].Tag;
                     }
                     else
                     {
@@ -241,26 +149,45 @@ namespace OTSPartA_STDEditor
                         Grid_Minerals.Selection.Focus(pos, true);
                         Grid_Minerals[x - 1, 0].Grid.Select();
 
-                        m_MainForm.ChangeSTDEditorAndGrid_Attributes(int.Parse(Grid_Minerals[x - 1, 0].Tag.ToString()));
-                        PreRow = x - 1;
+                        m_MainForm.ChangeSTDEditorAndGrid_Attributes(((STDdata)Grid_Minerals[x-1, 0].Tag).STDId);
+                        Predata = (STDdata)Grid_Minerals[x-1, 0].Tag;
                     }
                 }
                 else
                 {
                     m_MainForm.SetNull();
-                    PreRow = -1;
+                    Predata = null;
                 }
             }
             else
             {
                 MessageBox.Show("There is no rule to delete!", "Tip");
             }
-            SetOrderButtonsStatus();
         }
         private void ToolStripMenuItem_Del_Click(object sender, EventArgs e)
         {
             Grid_MineralsDelRow();
         }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
 
         public class ValueChangedEvent : SourceGrid.Cells.Controllers.ControllerBase
         {
@@ -283,12 +210,10 @@ namespace OTSPartA_STDEditor
                 }
             }
         }
-
         public void ChangeStrName(int RowNum, string NewStrName)
         {
             m_MainForm.ChangeStrName(RowNum, NewStrName);
         }
-
         private void Grid_Minerals_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
         {
             SourceGrid.Grid ls_gd = (SourceGrid.Grid)sender;
@@ -301,27 +226,26 @@ namespace OTSPartA_STDEditor
             }
             if (e.KeyCode == Keys.Up)
             {
-                /// 保证鼠标点击的GRID行和列是有效的
                 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;
+                        }
 
-                            m_MainForm.SaveDataOfSelRule(i, 0);
-                            m_MainForm.ChangeSTDEditorAndGrid_Attributes(int.Parse(Grid_Minerals[i - 1, 0].Tag.ToString()));
-                            m_MainForm.m_SubMidWindow.m_ComparativeLibrary.MakeCheckboxUnchecked();
-                            PreRow = i;
-                            if (i == 2)
-                            {
-                                button_UpOrder.Enabled = false;
-                            }
-                            if (i == ls_gd.RowsCount - 1)
-                            {
-                                button_DownOrder.Enabled = true;
-                            }
-                        
                     }
                     else
                     {
@@ -333,17 +257,15 @@ namespace OTSPartA_STDEditor
             }
             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(i, 0);
-                                m_MainForm.ChangeSTDEditorAndGrid_Attributes(int.Parse(Grid_Minerals[i + 1, 0].Tag.ToString()));
-                                PreRow = i;
+                                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)
@@ -369,137 +291,68 @@ namespace OTSPartA_STDEditor
                 Grid_MineralsDelRow();
             }
         }
-
         public int ChangeSTDRulesLISTBackColor()
         {
-            if (Grid_Minerals.RowsCount > 1)
+            if (tabControl1.SelectedIndex == 1)
             {
-                Position pos = new Position(1, 0);
-                Grid_Minerals[1, 0].Grid.Select();
+                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.STDDictionary[(int)Grid_Minerals[Grid_Minerals.Selection.ActivePosition.Row, 0].Tag].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 (int)Grid_Minerals[Grid_Minerals.Selection.ActivePosition.Row, 0].Tag;
+                    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;
+                }
             }
             else
             {
-                return -1;
+                if(treeView_G.SelectedNode.Level==0)
+                {
+                    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;
+                            }
+                        }
+                    }
+                }
+                return id;
             }
         }
-
-        private void MenuStrip_STDRulelist_Resize(object sender, EventArgs e)
-        {
-        }
-
         private void button_UpOrder_Click(object sender, EventArgs e)
         {
-            Grid_Minerals.Focus(true);
-            int selrow = Grid_Minerals.Selection.ActivePosition.Row;
-
-            int id = (int)Grid_Minerals[selrow, 0].Tag;
-            int id2 = (int)Grid_Minerals[selrow - 1, 0].Tag;
-            string sname = Grid_Minerals[selrow, 0].Value.ToString();
-
-            Grid_Minerals[selrow, 0].Value = Grid_Minerals[selrow - 1, 0].Value;
-            Grid_Minerals[selrow, 0].Tag = id2;
-            SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
-            view.BackColor = colorHx16toRGB(m_MainForm.STDDictionary[id2].Color);
-            Grid_Minerals[selrow, 1].View = view;
-
-            Grid_Minerals[selrow - 1, 0].Value = sname;
-            Grid_Minerals[selrow - 1, 0].Tag = id;
-            SourceGrid.Cells.Views.Cell view2 = new SourceGrid.Cells.Views.Cell();
-            view2.BackColor = colorHx16toRGB(m_MainForm.STDDictionary[id].Color);
-            Grid_Minerals[selrow - 1, 1].View = view2;
-
-            m_MainForm.STDDictionary[id].StrName = Grid_Minerals[selrow - 1, 0].Value.ToString();
-            m_MainForm.STDDictionary[id2].StrName = Grid_Minerals[selrow, 0].Value.ToString();
-
-            Position pos = new Position(selrow - 1, 1);
-            Grid_Minerals[selrow - 1, 0].Grid.Select();
-            Grid_Minerals.Selection.Focus(pos, true);
-            PreRow = selrow - 1;
-
-            button_DownOrder.Enabled = true;
-            if (selrow - 1 == 1)
-            {
-                button_UpOrder.Enabled = false;
-            }
-            m_MainForm.IsModified = true;
-            Grid_Minerals.Refresh();
-            //m_MainForm.ChangeSTDEditorAndGrid_Attributes(int.Parse(Grid_Minerals[selrow-1, 0].Tag.ToString()));
+            
         }
-
         private void button_DownOrder_Click(object sender, EventArgs e)
         {
-            Grid_Minerals.Focus(true);
-            int selrow = Grid_Minerals.Selection.ActivePosition.Row;
-
-            int id = (int)Grid_Minerals[selrow, 0].Tag;
-            int id2 = (int)Grid_Minerals[selrow + 1, 0].Tag;
-            string sname = Grid_Minerals[selrow, 0].Value.ToString();
-
-            Grid_Minerals[selrow, 0].Value = Grid_Minerals[selrow + 1, 0].Value;
-            Grid_Minerals[selrow, 0].Tag = id2;
-            SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
-            view.BackColor = colorHx16toRGB(m_MainForm.STDDictionary[id2].Color);
-            Grid_Minerals[selrow, 1].View = view;
-
-            Grid_Minerals[selrow + 1, 0].Value = sname;
-            Grid_Minerals[selrow + 1, 0].Tag = id;
-            SourceGrid.Cells.Views.Cell view2 = new SourceGrid.Cells.Views.Cell();
-            view2.BackColor = colorHx16toRGB(m_MainForm.STDDictionary[id].Color);
-            Grid_Minerals[selrow + 1, 1].View = view2;
-
-            m_MainForm.STDDictionary[id].StrName = Grid_Minerals[selrow + 1, 0].Value.ToString();
-            m_MainForm.STDDictionary[id2].StrName = Grid_Minerals[selrow, 0].Value.ToString();
-
-            Position pos = new Position(selrow + 1, 0);
-            Grid_Minerals[selrow + 1, 0].Grid.Select();
-            Grid_Minerals.Selection.Focus(pos, true);
-
-            PreRow = selrow + 1;
-
-            button_UpOrder.Enabled = true;
-            if (selrow + 1 == Grid_Minerals.RowsCount - 1)
-            {
-                button_DownOrder.Enabled = false;
-            }
-            #region 添加修改stdid顺序 ,由于需求改变只完成一部分(差相应修改能谱部分)
-            //DialogResult result=MessageBox.Show("检测到顺序已修改,是否调整STDId?", "提示",MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
-            //if (result == DialogResult.Yes)
-            //{
-            //    ChangeSTDidFromNum changeSTDidFromNum = new ChangeSTDidFromNum();
-            //    DialogResult res=changeSTDidFromNum.ShowDialog();
-            //    {
-            //        if (res == DialogResult.OK)
-            //        {
-            //            int StartId = int.Parse(changeSTDidFromNum.textBox_NewFirstSTDId.Text);
-            //            Dictionary<int, STDdata> STDDictionaryCopy = new Dictionary<int, STDdata>();
-            //            for (int i = 0; i < Grid_Minerals.RowsCount-1; i++)
-            //            {
-            //                STDdata dataCopy = m_MainForm.STDDictionary[(int)Grid_Minerals[i+1, 0].Tag];
-            //                STDDictionaryCopy.Add(StartId + i, dataCopy);
-            //            }
-            //            m_MainForm.STDDictionary.Clear();
-            //            m_MainForm.STDDictionary = STDDictionaryCopy;
-            //        }
-            //    }
-            //}
-            #endregion
-            m_MainForm.IsModified = true;
-            Grid_Minerals.Refresh();
+            
         }
 
         public void InsertNewRow(int STDId, string RuleName, Color color)
         {
             Grid_Minerals.Focus(true);
             Grid_Minerals.Rows.InsertRange(Grid_Minerals.Selection.ActivePosition.Row, 1);
-            //Grid_Minerals.Rows.Insert(Grid_Minerals.Rows.Count);
             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 = STDId;
+            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);
@@ -508,19 +361,11 @@ namespace OTSPartA_STDEditor
             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);
-
-            PreRow = Grid_Minerals.Selection.ActivePosition.Row - 1;
+            Predata = (STDdata)Grid_Minerals[Grid_Minerals.Selection.ActivePosition.Row - 1, 0].Tag ;
             SetOrderButtonsStatus();
         }
-
-        private void Grid_Minerals_VScrollPositionChanged(object sender, ScrollPositionChangedEventArgs e)
-        {
-            //Grid_Minerals.Refresh();
-        }
-
         void SetOrderButtonsStatus()
         {
             Grid_Minerals.Focus();
@@ -547,26 +392,469 @@ namespace OTSPartA_STDEditor
             }
             else
             {
-                button_UpOrder.Enabled = false;
-                button_DownOrder.Enabled = false;
+                button_UpOrder.Enabled = false;button_DownOrder.Enabled = false;
             }
         }
 
+
         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();
+                //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;
+                //    if (m_MainForm._sTDEditor.STDDictionary.ContainsKey(id))
+                //    {
+                //        m_MainForm.ChangeSTDEditorAndGrid_Attributes(id);
+                //        Predata = (STDdata)Grid_Minerals[i, 0].Tag;
+                //    }
+                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;
+                }
+                //}
             }
         }
-
         void InitGroupEditorView()
         {
+            GroupViewDic = ConvertToGroupViewDic();
+            InitGroupView();
+        }
 
+        Dictionary<int, STDGroups> ConvertToGroupViewDic()
+        {
+            Dictionary<int, STDGroups> keyValuePairs = new Dictionary<int, STDGroups>();
+            keyValuePairs = m_MainForm._sTDEditor.GroupDictionary;
+            foreach (STDGroups group in keyValuePairs.Values)
+            {
+                group.ContainSTD.Clear();
+            }
+            foreach (STDdata Ddata in  m_MainForm._sTDEditor.STDDictionary.Values)
+            {
+                keyValuePairs[Ddata.GroupId].ContainSTD.Add(Ddata);
+            }
+            return keyValuePairs;
+        }
+        public void ConvertToRuleViewDic()
+        {
+            m_MainForm._sTDEditor.GroupIdDictionaryFromId.Clear();
+            m_MainForm._sTDEditor.GroupIdDictionaryFromName.Clear();
+            m_MainForm._sTDEditor.STDDictionary.Clear();
+            foreach (STDGroups group in GroupViewDic.Values)
+            {
+                foreach (STDdata Ddata in group.ContainSTD)
+                {
+                    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());
+            }
+            if (treeView_G.SelectedNode == null){return;}
+            if (treeView_G.SelectedNode.Level == 1)
+            {
+                m_MainForm.SaveDataOfSelRule(((STDdata)treeView_G.SelectedNode.Tag).STDId);
+            }
+        }
+
+
+
+
+
+        private void ToolStripMenuItem_NewGroup_Click(object sender, EventArgs e)
+        {
+            STDGroups group = new STDGroups();
+            int id = 0;
+            foreach(STDGroups grp in GroupViewDic.Values)
+            {
+                if(grp.id>id)
+                {
+                    id= grp.id;
+                }
+            }
+            id++;
+            group.id = id;
+            group.name = "Group" + id.ToString();
+            group.color = Attributes.colorRGBtoHx16(Color.WhiteSmoke.R, Color.WhiteSmoke.G, Color.WhiteSmoke.B);
+            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;
+            m_MainForm.SetNull();
+            Predata = null;
+        }
+
+
+
+        private void ToolStripMenuItem_DelGroup_Click(object sender, EventArgs e)
+        {
+            if(treeView_G.SelectedNode==null)
+            {
+                MessageBox.Show("Please select a group!", "Tip");
+                return;
+            }
+            if (treeView_G.SelectedNode.Level == 0)
+            {
+                int id = ((STDGroups)treeView_G.SelectedNode.Tag).id;
+                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);
+                    GroupViewDic.Remove(id);
+                    treeView_G.Nodes.Remove(treeView_G.SelectedNode);
+                    this.Refresh();
+                }
+            }
+            else
+            {
+                MessageBox.Show("Please select a group!", "Tip");
+
+                return;
+            }
+        }
+
+        private void ToolStripMenuItem_EdGroupColor_Click(object sender, EventArgs e)
+        {
+            if(treeView_G.SelectedNode==null)
+            {
+                MessageBox.Show("Please select a group!", "Tip");
+                return;
+            }
+            if (treeView_G.SelectedNode.Level == 0)
+            {
+                ColorDialog cd = new ColorDialog();
+                cd.FullOpen = true;//自定义颜色界面打开
+                DialogResult result = cd.ShowDialog();
+                if (result == DialogResult.OK)
+                {
+                    GroupViewDic[((STDGroups)treeView_G.SelectedNode.Tag).id].color = Attributes.colorRGBtoHx16(cd.Color.R, cd.Color.G, cd.Color.B);
+                    InitGroupView();
+                }
+            }
+            else
+            {
+                MessageBox.Show("Please select a group!", "Tip");
+            }
+        }
+
+        void InitGroupView()
+        {
+            treeView_G.ImageList=new ImageList();
+            treeView_G.Nodes.Clear();
+            treeView_G.ImageList.ColorDepth = ColorDepth.Depth32Bit;
+            foreach (STDGroups group in GroupViewDic.Values)
+            {
+                TreeNode treeNode = new TreeNode();
+                treeNode.Tag = group;
+                treeNode.Text = group.name;
+                Color color = Attributes.colorHx16toRGB(group.color);
+                Bitmap bitmap = new Bitmap(100, 100, PixelFormat.Format32bppArgb);
+                Graphics graphics = Graphics.FromImage(bitmap);
+                SolidBrush b1 = new SolidBrush(color);
+                graphics.FillEllipse(b1, new Rectangle(0, 0, 100, 100));
+                treeView_G.ImageList.Images.Add(group.id.ToString(),bitmap);
+                treeNode.ImageKey = group.id.ToString();
+                treeNode.SelectedImageKey = group.id.ToString();
+                treeView_G.Nodes.Add(treeNode);
+                foreach (STDdata ddata in group.ContainSTD)
+                {
+                    TreeNode childtreeNode = new TreeNode();
+                    childtreeNode.Tag = ddata;
+                    childtreeNode.Text = ddata.StrName;
+                    Color color2 = Attributes.colorHx16toRGB(ddata.Color);
+                    SolidBrush b2 = new SolidBrush(color2);
+                    graphics.FillEllipse(b2, new Rectangle(0, 0, 100, 100));
+                    treeView_G.ImageList.Images.Add("0x"+ ddata.STDId, bitmap);
+                    childtreeNode.ImageKey = "0x" + ddata.STDId;
+                    childtreeNode.SelectedImageKey = "0x" + ddata.STDId;
+                    treeNode.Nodes.Add(childtreeNode);
+                }
+            }
+
+            treeView_G.Font = new Font("微软雅黑", 12);
+            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)
+            {
+                m_targetNode = null;
+                TreeNode _node = (TreeNode)e.Item;
+                if (_node.Level > 0)
+                {
+                    DoDragDrop(e.Item, DragDropEffects.Move | DragDropEffects.Copy);
+                }
+            }
+        }
+        TreeNode m_targetNode;      //用于记录当前拖拽到的目标节点;
+        private void treeView_G_DragDrop(object sender, DragEventArgs e)
+        {
+            if (m_targetNode != null)
+            {
+                TreeNode _node = (TreeNode)e.Data.GetData(typeof(TreeNode));
+                if (!m_targetNode.Equals(_node))
+                {
+                    if (m_targetNode.Level == _node.Level)
+                    {
+                        if (_node.Parent.Equals(m_targetNode.Parent))
+                        {
+                            _node.Remove();
+                            m_targetNode.Parent.Nodes.Insert(m_targetNode.Index, _node);
+                            m_targetNode.Parent.ExpandAll();
+                        }
+                        else
+                        {
+                            GroupViewDic[((STDGroups)_node.Parent.Tag).id].ContainSTD.Remove((STDdata)_node.Tag);
+                            _node.Remove();
+                            ((STDdata)_node.Tag).GroupId = ((STDGroups)m_targetNode.Parent.Tag).id;
+                            m_targetNode.Parent.Nodes.Add(_node);
+                            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()));
+                            Predata = (STDdata)_node.Tag;
+                        }
+                    }
+                    else
+                    {
+                        GroupViewDic[((STDGroups)_node.Parent.Tag).id].ContainSTD.Remove((STDdata)_node.Tag);
+                        _node.Remove();
+                        ((STDdata)_node.Tag).GroupId = ((STDGroups)m_targetNode.Tag).id;
+                        m_targetNode.Nodes.Add(_node);
+                        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()));
+                        Predata = (STDdata)_node.Tag;
+                    }
+                }
+                m_targetNode = null;
+                _node = null;
+            }
+        }
+
+        [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;
+            Point pt = treeView_G.PointToClient(Cursor.Position);
+            if ((pt.Y + scrollRegion) > treeView_G.Height)
+            {
+                SendMessage(treeView_G.Handle, (int)277, (int)1, 0);
+            }
+            else if (pt.Y < (treeView_G.Top + scrollRegion))
+            {
+                SendMessage(treeView_G.Handle, (int)277, (int)0, 0);
+            }
+            TreeNode _node2 = treeView_G.GetNodeAt(treeView_G.PointToClient(new Point(e.X, e.Y)));
+            m_targetNode = null;
+
+            if (_node2 != null)
+            {
+                m_targetNode = _node2;
+                e.Effect = DragDropEffects.Move;
+            }
+            else
+            {
+                e.Effect = DragDropEffects.None;
+            }
+        }
+        private void treeView_G_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
+        {
+
+            if(Predata!=null)
+            {
+                m_MainForm.SaveDataOfSelRule(Predata.STDId);
+            }
+            if(e.Node.Level==0)
+            {
+                m_MainForm.SetNull();
+                Predata = null;
+                treeView_G.SelectedNode = e.Node;
+            }
+            else
+            {
+                m_MainForm.ChangeSTDEditorAndGrid_Attributes(int.Parse(((STDdata)e.Node.Tag).STDId.ToString()));
+                Predata = (STDdata)e.Node.Tag;
+            }
+        }
+        public void AdjustTreenodeByGroup(int Groupid)
+        {
+            if (m_MainForm.m_STDRuleslist.tabControl1.SelectedIndex == 1)
+            {
+                return;
+            }
+            if (treeView_G.SelectedNode.Level == null)
+            {
+                return;
+            }
+            if (treeView_G.SelectedNode.Level == 0)
+            {
+                return;
+            }
+            STDdata ddata = (STDdata)treeView_G.SelectedNode.Tag;
+            TreeNode nodenew = null;
+            foreach (TreeNode node in treeView_G.Nodes)
+            {
+                if (((STDGroups)node.Tag).id == Groupid)
+                {
+                    nodenew = node;break;
+                }
+            }
+            foreach (TreeNode node in treeView_G.Nodes)
+            {
+                foreach (TreeNode node1 in node.Nodes)
+                {
+                    if (((STDdata)node1.Tag).STDId == ddata.STDId)
+                    {
+                        GroupViewDic[((STDGroups)node.Tag).id].ContainSTD.Remove(ddata);
+                        node1.Remove();
+                        ((STDdata)node1.Tag).GroupId = ddata.GroupId;
+                        nodenew.Nodes.Add(node1);
+                        GroupViewDic[Groupid].ContainSTD.Add(ddata);
+                        treeView_G.SelectedNode = node1;
+                        nodenew.Expand();
+                        m_MainForm.ChangeSTDEditorAndGrid_Attributes(int.Parse(((STDdata)node1.Tag).STDId.ToString()));
+                        Predata = ddata;
+                        break;
+                    }
+                }
+            }
+        }
+        private void ToolStripMenuItem_RenameGroup_Click(object sender, EventArgs e)
+        {
+            if (treeView_G.SelectedNode != null)
+            {
+                if (treeView_G.SelectedNode.Level == 0)
+                {
+                    treeView_G.SelectedNode.BeginEdit();
+                }
+                else
+                {
+                    MessageBox.Show("Please select a group!", "Tip");
+                    treeView_G.SelectedNode.EndEdit(true);
+                }
+            }
+        }
+        private void treeView_G_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
+        {
+            if (treeView_G.SelectedNode.Level == 0)
+            {
+                if(e.Label==null|| e.Label =="")
+                {
+                    MessageBox.Show("GroupName Cannot Be Null!", "Tip");
+                    e.CancelEdit=true;
+                    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();
+            }
+            else
+            {
+                MessageBox.Show("Please select a group!", "Tip");
+                return;
+            }
         }
     }
 }

+ 3 - 0
OTSPartA_STDEditor/UI/STDRuleslist.resx

@@ -120,4 +120,7 @@
   <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>
 </root>

+ 3 - 3
OTSPartA_STDEditor/UI/SubMidWindow.cs

@@ -51,13 +51,13 @@ namespace OTSPartA_STDEditor
 
         public void ChangeText_textbox_STDEditor(int STDId)
         {
-            m_STDEditor.textbox_STDEditor.Text = m_MainForm.STDDictionary[STDId].Expression;
+            m_STDEditor.textbox_STDEditor.Text = m_MainForm._sTDEditor.STDDictionary[STDId].Expression;
             m_STDEditor.STDId = STDId;
 
             m_STDEditor.dataGridView_KeyElements.Rows.Clear();
             m_STDEditor.dataGridView_KeyElements.Columns.Clear();
 
-            string[] KeyElement = m_MainForm.STDDictionary[STDId].KeyElementList.Trim().Split(',');
+            string[] KeyElement = m_MainForm._sTDEditor.STDDictionary[STDId].KeyElementList.Trim().Split(',');
             for (int i = 0; i < KeyElement.Length; i++)
             {
                 if (KeyElement[0] != "")
@@ -77,7 +77,7 @@ namespace OTSPartA_STDEditor
             m_STDEditor.dataGridView_SubElements.Rows.Clear();
             m_STDEditor.dataGridView_SubElements.Columns.Clear();
 
-            string[] SubElement = m_MainForm.STDDictionary[STDId].SubElementList.Trim().Split(',');
+            string[] SubElement = m_MainForm._sTDEditor.STDDictionary[STDId].SubElementList.Trim().Split(',');
             for (int i = 0; i < SubElement.Length; i++)
             {
                 if (SubElement[i] != "")

Некоторые файлы не были показаны из-за большого количества измененных файлов