Pārlūkot izejas kodu

Merge branch 'cxs' into dev

CXS 3 gadi atpakaļ
vecāks
revīzija
8555dfdacc

+ 33 - 5
OTSPartA_STDEditor/Form_ConstantsEditor2.cs

@@ -1291,8 +1291,11 @@ namespace OTSPartA_STDEditor
                     {
                         GroupIdDictionaryFromId.Clear();
                         GroupIdDictionaryFromName.Clear();
-                        GroupIdDictionaryFromId.Add(0, "");
-                        GroupIdDictionaryFromName.Add("", 0);
+                        if (dt.Select("id='0'").Length==0)
+                        {
+                            GroupIdDictionaryFromId.Add(0, "Default");
+                            GroupIdDictionaryFromName.Add("Default", 0);
+                        }
 
                         List<string> ss = new List<string>();
                         foreach (DataRow item in dt.Rows)
@@ -1304,7 +1307,7 @@ namespace OTSPartA_STDEditor
                         SourceGrid.Cells.Editors.ComboBox GroupIdCBBox = new SourceGrid.Cells.Editors.ComboBox(typeof(string));
                         GroupIdCBBox.StandardValues = ss;
                         GroupIdCBBox.EditableMode = SourceGrid.EditableMode.SingleClick| SourceGrid.EditableMode.Focus;
-                        m_Attributes.Grid_Attributes[10, 1] = new SourceGrid.Cells.Cell("", GroupIdCBBox);
+                        m_Attributes.Grid_Attributes[10, 1] = new SourceGrid.Cells.Cell("Default", GroupIdCBBox);
                     }
                 }
                 //string ConstantsStr = dt.Rows[0][0].ToString();
@@ -1316,13 +1319,26 @@ namespace OTSPartA_STDEditor
             }
         }
 
+        void SetNonexistentGroupsToDefault()
+        {
+            foreach (KeyValuePair<int, STDdata> kv in STDDictionary)
+            {
+                if(!GroupIdDictionaryFromId.Keys.Contains(int.Parse(kv.Value.GroupId)))
+                {
+                    kv.Value.GroupId = "0";
+                }
+            }
+            m_Attributes.Grid_Attributes.Refresh();
+        }
         private void ribbon_GroupNameMaintenance_Click(object sender, EventArgs e)
         {
-            Form_GroupId form_GroupId = new Form_GroupId(STDDBAddress);
+            STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row,0].Tag.ToString())].GroupId = GroupIdDictionaryFromName[m_Attributes.Grid_Attributes[10, 1].Value.ToString()].ToString();
+            Form_GroupId form_GroupId = new Form_GroupId(STDDBAddress,this);
             DialogResult dialogResult = form_GroupId.ShowDialog();
             if (dialogResult == DialogResult.Yes)
             {
                 AddSTDGroupsToAttribute();
+                //SetNonexistentGroupsToDefault();
             }
         }
 
@@ -1623,7 +1639,7 @@ namespace OTSPartA_STDEditor
                     this.Text = this.Text.Split(' ')[0] + "   " + STDDBAddress;
                     IsModified = false;
                 }
-                catch/*(Exception ex)*/
+                catch (Exception ex)
                 {
                     MessageBox.Show(table["message6"].ToString(), table["message32"].ToString());
                 }
@@ -1846,6 +1862,18 @@ namespace OTSPartA_STDEditor
                             MessageBox.Show(table["message2"].ToString(), table["message32"].ToString());
                         }
                     }
+                    else
+                    {
+                        foreach (KeyValuePair<int, STDdata> kv in STDDictionary)
+                        {
+                            if (!GroupIdDictionaryFromId.Keys.Contains(int.Parse(kv.Value.GroupId)))
+                            {
+                                MessageBox.Show("There is non-existent grouping informations in the classification, please adjust!");
+                                e.Cancel = true;
+                                return;
+                            }
+                        }
+                    }
                 }
             }
                                 

+ 84 - 32
OTSPartA_STDEditor/Form_GroupId.cs

@@ -13,13 +13,14 @@ namespace OTSPartA_STDEditor
 {
     public partial class Form_GroupId : Form
     {
+        public Form_ConstantsEditor2 m_MainForm = null;
         //国际化
         Language lan;
         System.Collections.Hashtable table_GroupId;
 
         string MineralGroupDBAddress = Application.StartupPath + "\\Config\\SysData\\" + "OTSCleanlinesSTD.db";
         Dictionary<int,STDGroups> MineralGroupDictionary = new Dictionary<int, STDGroups>();
-
+        //Dictionary<int, STDGroups> MineralGroupDictionaryInitial = new Dictionary<int, STDGroups>();
         /// <summary>
         ///数据库修改状态
         /// </summary>
@@ -29,7 +30,17 @@ namespace OTSPartA_STDEditor
             Modify = 1,
             Delete = 2
         }
-
+        object Clone(Dictionary<int, STDGroups> Dictionary)
+        {
+            Dictionary<int, STDGroups> DictionaryInitial = new Dictionary<int, STDGroups>();
+            foreach (var key in Dictionary.Keys)
+            {
+                STDGroups DGroups = new STDGroups();
+                DGroups = DGroups.Clone(Dictionary[key]) as STDGroups;
+                DictionaryInitial.Add(key,DGroups);
+            }
+            return DictionaryInitial;
+        }
         bool LoadDataFromDb(string DBaddress)
         {
             try
@@ -43,17 +54,27 @@ namespace OTSPartA_STDEditor
 
                 if (dt != null)
                 {
+                    STDGroups new_data = new STDGroups();
+                    new_data.name = "Default";
+                    new_data.color = "#C9C9C9";
+                    new_data.iorder = 999;
+                    MineralGroupDictionary.Add(0, new_data);
+                    
                     if (dt.Rows.Count > 0)
                     {
                         foreach (DataRow item in dt.Rows)
                         {
-                            STDGroups new_STDdata = new STDGroups();
-                            new_STDdata.name = item["name"].ToString();
-                            new_STDdata.color = item["color"].ToString();
-                            new_STDdata.iorder = int.Parse(item["iorder"].ToString());
-                            MineralGroupDictionary.Add(int.Parse(item["id"].ToString()), new_STDdata);
+                            if (item["name"].ToString() != "Default")
+                            {
+                                STDGroups new_STDdata = new STDGroups();
+                                new_STDdata.name = item["name"].ToString();
+                                new_STDdata.color = item["color"].ToString();
+                                new_STDdata.iorder = int.Parse(item["iorder"].ToString());
+                                MineralGroupDictionary.Add(int.Parse(item["id"].ToString()), new_STDdata);
+                            }
                         }
                     }
+                    
                 }
 
                 m_dbConnection.Close();
@@ -170,9 +191,9 @@ namespace OTSPartA_STDEditor
 
         void SaveDataIntoDB(string DBAddress)
         {
-            for (int i = 1; i < Grid_FroupId.RowsCount; i++)
+            for (int i = 2; i < Grid_FroupId.RowsCount; i++)
             {
-                MineralGroupDictionary[(int)Grid_FroupId[i, 0].Tag].iorder = i;
+                MineralGroupDictionary[(int)Grid_FroupId[i, 0].Tag].iorder = i-1;
             }
             System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + DBAddress + "'");
             m_dbConnection.Open();
@@ -209,10 +230,11 @@ namespace OTSPartA_STDEditor
             m_dbConnection.Close();
         }
 
-        public Form_GroupId(string DBAddress)
+        public Form_GroupId(string DBAddress, Form_ConstantsEditor2 mainForm)
         {
             InitializeComponent();
             MineralGroupDBAddress = DBAddress;
+            m_MainForm = mainForm;
         }
 
         private void Form_GroupId_Load(object sender, EventArgs e)
@@ -220,7 +242,7 @@ namespace OTSPartA_STDEditor
             lan = new Language(this);
             table_GroupId = lan.GetNameTable("Form_GroupId");
 
-            bool result = LoadDataFromDb(MineralGroupDBAddress);
+            bool result = LoadDataFromDb(MineralGroupDBAddress); 
             if(result)
             {
                 Grid_FroupId.Redim(MineralGroupDictionary.Count + 1, 2);
@@ -251,28 +273,41 @@ namespace OTSPartA_STDEditor
                 Grid_FroupId[0, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
                 Grid_FroupId[0, 1].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
 
+                Grid_FroupId[1, 0] = new SourceGrid.Cells.Cell("Default", typeof(string));
+                Grid_FroupId[1, 1] = new SourceGrid.Cells.Cell("", typeof(string));
+                Grid_FroupId.Rows[1].Height = 25;
+                Grid_FroupId[1, 0].Tag = 0;
 
-                int i = 1;
+                SourceGrid.Cells.Views.Cell vw = new SourceGrid.Cells.Views.Cell();
+                vw.BackColor = Attributes.colorHx16toRGB("#C9C9C9");
+                Grid_FroupId[1, 1].View = vw;
+                Grid_FroupId[1, 0].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
+                Grid_FroupId[1, 1].AddController(SourceGrid.Cells.Controllers.Unselectable.Default);
+
+                int i = 2;
                 foreach (KeyValuePair<int, STDGroups> kv in MineralGroupDictionary)
                 {
-                    Grid_FroupId[i, 0] = new SourceGrid.Cells.Cell(kv.Value.name, typeof(string));
-                    Grid_FroupId[i, 1] = new SourceGrid.Cells.Cell("", typeof(string));
-                    Grid_FroupId.Rows[i].Height = 25;
-                    Grid_FroupId[i, 0].Tag = kv.Key;
+                    if (kv.Key != 0)
+                    {
+                        Grid_FroupId[i, 0] = new SourceGrid.Cells.Cell(kv.Value.name, typeof(string));
+                        Grid_FroupId[i, 1] = new SourceGrid.Cells.Cell("", typeof(string));
+                        Grid_FroupId.Rows[i].Height = 25;
+                        Grid_FroupId[i, 0].Tag = kv.Key;
 
-                    SourceGrid.Cells.Views.Cell vew = new SourceGrid.Cells.Views.Cell();
-                    vew.BackColor = Attributes.colorHx16toRGB(kv.Value.color);
-                    Grid_FroupId[i, 1].View = vew;
+                        SourceGrid.Cells.Views.Cell vew = new SourceGrid.Cells.Views.Cell();
+                        vew.BackColor = Attributes.colorHx16toRGB(kv.Value.color);
+                        Grid_FroupId[i, 1].View = vew;
 
-                    SourceGrid.Cells.Controllers.CustomEvents clickEvent = new SourceGrid.Cells.Controllers.CustomEvents();
-                    clickEvent.ValueChanged += new EventHandler(clickEvent_ValueChanged);
-                    Grid_FroupId[i, 0].AddController(clickEvent);
+                        SourceGrid.Cells.Controllers.CustomEvents clickEvent = new SourceGrid.Cells.Controllers.CustomEvents();
+                        clickEvent.ValueChanged += new EventHandler(clickEvent_ValueChanged);
+                        Grid_FroupId[i, 0].AddController(clickEvent);
 
-                    SourceGrid.Cells.Controllers.CustomEvents clickEvent2 = new SourceGrid.Cells.Controllers.CustomEvents();
-                    clickEvent2.Click+= new EventHandler(clickEvent_Click);
-                    Grid_FroupId[i, 1].AddController(clickEvent2);
+                        SourceGrid.Cells.Controllers.CustomEvents clickEvent2 = new SourceGrid.Cells.Controllers.CustomEvents();
+                        clickEvent2.Click += new EventHandler(clickEvent_Click);
+                        Grid_FroupId[i, 1].AddController(clickEvent2);
 
-                    i++;
+                        i++;
+                    }
                 }
             }
             else
@@ -371,6 +406,20 @@ namespace OTSPartA_STDEditor
             int y = Grid_FroupId.Selection.ActivePosition.Column;
             if (x > 0 && (y == 0|| y == 1))
             {
+                bool bexist = false;
+                foreach (KeyValuePair<int, STDdata> kv in m_MainForm.STDDictionary)
+                {
+                    if(kv.Value.GroupId.ToString()== Grid_FroupId[x, 0].Tag.ToString())
+                    {
+                        bexist = true;
+                        break;
+                    }
+                }
+                if(bexist)
+                {
+                    MessageBox.Show("There is a grouping in the user standard library that you want to delete!");
+                    return;
+                }
                 RemoveMineralGroupDictionaryItem((int)Grid_FroupId[x, 0].Tag);
                 Grid_FroupId.Rows.Remove(x);
                 Grid_FroupId.Refresh();
@@ -477,22 +526,25 @@ namespace OTSPartA_STDEditor
             /// 保证鼠标点击的GRID行和列是有效的
             if (i >= 0 && j >= 0)
             {
-                if (i == 1)
+                if (i == ls_gd.RowsCount - 1)
                 {
-                    button_up.Enabled = false;
+                    button_down.Enabled = false;
                 }
                 else
                 {
-                    button_up.Enabled = true;
+                    button_down.Enabled = true;
                 }
-                if (i == ls_gd.RowsCount - 1)
+                if (i == 1)
                 {
-                    button_down.Enabled = false;
+                    button_up.Enabled = false;
+                    //MessageBox.Show("Group by default, not editable!");
+                    //return;
                 }
                 else
                 {
-                    button_down.Enabled = true;
+                    button_up.Enabled = true;
                 }
+                
             }
         }
     }

+ 9 - 0
OTSPartA_STDEditor/STDGroups.cs

@@ -39,5 +39,14 @@ namespace OTSPartA_STDEditor
             set { i_InfoState = value; }
             get { return i_InfoState; }
         }
+        public object Clone(STDGroups a_oSource)
+        {
+            STDGroups MySTDGroups = new STDGroups();
+            MySTDGroups.name = a_oSource.name;
+            MySTDGroups.color = a_oSource.color;
+            MySTDGroups.iorder = a_oSource.iorder;
+            MySTDGroups.InfoState = a_oSource.InfoState;
+            return MySTDGroups;
+        }
     }
 }