using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Windows.Forms; namespace OTSPartA_STDEditor.BaseClass { public class STDInfo { public Dictionary STDDictionary = new Dictionary(); /// /// 原始数据字典用于在关闭时比较是否弹出保存提示 /// private Dictionary STDDictionaryInitial = new Dictionary(); public Dictionary GroupDictionary = new Dictionary(); public string[] ConstantsStr = null; public Dictionary GroupIdDictionaryFromId = new Dictionary(); public Dictionary GroupIdDictionaryFromName = new Dictionary(); public bool Isoldversion { set; get; } public bool rbSaveStatus { set; get; } public static readonly string[] ColorGroup = { "#FFB6C1", "#FFC0CB", "#DC143C", "#FFF0F5", "#DB7093", "#FF69B4", "#FF1493", "#C71585", "#DA70D6", "#D8BFD8", "#DDA0DD", "#EE82EE", "#FF00FF", "#8B008B", "#800080", "#BA55D3", "#9400D3", "#9932CC", "#4B0082", "#8A2BE2", "#9370DB", "#7B68EE", "#6A5ACD", "#483D8B", "#E6E6FA", "#F8F8FF", "#0000FF", "#0000CD", "#191970", "#00008B", "#000080", "#4169E1", "#6495ED", "#B0C4DE", "#778899", "#708090", "#1E90FF", "#F0F8FF", "#00FFFF" }; public static 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" }; public static string[] Elem1 = { "first_elem", "second_elem", "third_elem", "fourth_elem", "fifth_elem", "sixth_elem", "seventh_elem", "eighth_elem", "ninth_elem", "tenth_elem" }; public static string[] Elem2 = { "Element#1", "Element#2", "Element#3", "Element#4", "Element#5", "Element#6", "Element#7", "Element#8", "Element#9", "Element#10"}; public static string[] ImgProperty = { "Dmax", "Dmin", "Aspect", "Dperp", "Dmean", "Area", "Dferet", "Width", "Height", "Perimeter", "Dinscr", "Orientation", "Delong", "Aspectelong", "Dequalcircle", "Vedio" }; string _DBAddress; public STDInfo(string DBAddress) { _DBAddress=DBAddress; bool aa = LoadClassifyToDictionary(); if (!aa) { STDDictionary=null; STDDictionaryInitial = Clone(STDDictionary) as Dictionary; } aa = LoadGroupDataFromDb(); if (!aa) { GroupDictionary = null; } LoadConstants(); } bool LoadClassifyToDictionary() { try { STDDictionaryInitial.Clear(); STDDictionary.Clear(); System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + _DBAddress + "'"); m_dbConnection.Open(); System.Data.SQLite.SQLiteDataAdapter m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select * from ClassifySTD order by ListNum", m_dbConnection); DataSet ds = new DataSet(); m_dataAdapter.Fill(ds); DataTable dt = ds.Tables[0]; if (dt != null) { if ((dt.Columns.Contains("IfElementAnalysis"))) { rbSaveStatus = true; Isoldversion = false; } else { rbSaveStatus = false; Isoldversion = true; } if (dt.Rows.Count > 0) { foreach (DataRow item in dt.Rows) { STDdata new_STDdata = new STDdata(); new_STDdata.STDId = int.Parse(item["STDId"].ToString()); new_STDdata.Hardness = item["Hardness"].ToString(); new_STDdata.Density = item["Density"].ToString(); new_STDdata.Electrical_conductivity = item["Electrical_conductivity"].ToString(); new_STDdata.BSE = item["BSE"].ToString(); new_STDdata.Formula = item["Formula"].ToString(); new_STDdata.Element = item["Element"].ToString(); new_STDdata.StrName = item["StrName"].ToString(); new_STDdata.Expression = item["Expression"].ToString(); new_STDdata.Color = item["Color"].ToString(); new_STDdata.KeyElementList = item["KeyElementList"].ToString(); new_STDdata.SubElementList = item["SubElementList"].ToString(); new_STDdata.GroupId = int.Parse(item["GroupId"].ToString()); new_STDdata.ListNum = item["ListNum"].ToString(); if (dt.Columns.Contains("IfElementAnalysis")) { if (Convert.ToBoolean(item["IfElementAnalysis"])) { new_STDdata.IfElementAnalysis = true; } else { new_STDdata.IfElementAnalysis = false; } } STDDictionary.Add(int.Parse(item["STDId"].ToString()), new_STDdata); STDDictionaryInitial.Add(int.Parse(item["STDId"].ToString()), new_STDdata); } } } return true; } catch /*(Exception ee)*/ { MessageBox.Show("The selected standard library is formatted incorrectly, please open the correct standard library!", "Tip"); return false; } } bool LoadGroupDataFromDb() { try { System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + _DBAddress + "'"); m_dbConnection.Open(); System.Data.SQLite.SQLiteDataAdapter m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select * from STDGroups order by iorder", m_dbConnection); DataSet ds = new DataSet(); m_dataAdapter.Fill(ds); DataTable dt = ds.Tables[0]; if (dt != null) { GroupDictionary.Clear(); GroupIdDictionaryFromId.Clear(); GroupIdDictionaryFromName.Clear(); STDGroups new_data = new STDGroups(); new_data.name = "Default"; new_data.color = "#C9C9C9"; new_data.iorder = 10000; GroupDictionary.Add(0, new_data); if (dt.Select("id='0'").Length == 0) { GroupIdDictionaryFromId.Add(0, "Default"); GroupIdDictionaryFromName.Add("Default", 0); } if (dt.Rows.Count > 0) { foreach (DataRow item in dt.Rows) { if (item["name"].ToString() != "Default") { STDGroups new_STDdata = new STDGroups(); new_STDdata.id = int.Parse(item["id"].ToString()); new_STDdata.name = item["name"].ToString(); new_STDdata.color = item["color"].ToString(); new_STDdata.iorder = int.Parse(item["iorder"].ToString()); GroupDictionary.Add(int.Parse(item["id"].ToString()), new_STDdata); } GroupIdDictionaryFromName.Add(item["name"].ToString(), int.Parse(item["id"].ToString())); GroupIdDictionaryFromId.Add(int.Parse(item["id"].ToString()), item["name"].ToString()); } } } m_dbConnection.Close(); m_dbConnection.Close(); return true; } catch (Exception ee) { MessageBox.Show(ee.ToString()); return false; } } public void LoadConstants() { try { System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + _DBAddress + "'"); m_dbConnection.Open(); System.Data.SQLite.SQLiteDataAdapter m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select * from Constants", m_dbConnection); DataSet ds = new DataSet(); m_dataAdapter.Fill(ds); DataTable dt = ds.Tables[0]; if (dt.Rows.Count > 0) { string ConstantsStr2 = dt.Rows[0][0].ToString(); ConstantsStr2 = ConstantsStr2.Replace(" ", ""); ConstantsStr = ConstantsStr2.Split(','); } else { ConstantsStr = null; } m_dbConnection.Close(); } catch (Exception ee) { MessageBox.Show(ee.ToString()); } } public bool EqualsBetweenDictionary() { if (STDDictionaryInitial.Count != STDDictionary.Count) { return false; } foreach (var key in STDDictionaryInitial.Keys) { if (STDDictionary.Keys.Contains(key)) { if (!STDDictionaryInitial[key].Equals(STDDictionary[key])) { return false; } } else { return false; } } return true; } public bool ClearDb(string DBAddress, string DBTableName) { try { System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + DBAddress + "'"); m_dbConnection.Open(); System.Data.SQLite.SQLiteCommand cmm = m_dbConnection.CreateCommand(); cmm.CommandText = "delete from " + DBTableName; cmm.ExecuteNonQuery(); m_dbConnection.Close(); return true; } catch (Exception ex) { MessageBox.Show(ex.ToString()); return false; } } public STDdata AddSTDDictionaryItem() { STDdata new_STDdata = new STDdata();//定义一个TreeNode节点对象 new_STDdata.Hardness = "1"; new_STDdata.Density = "1"; new_STDdata.Electrical_conductivity = "1"; new_STDdata.BSE = "1"; new_STDdata.Formula = "1"; new_STDdata.Element = "1"; new_STDdata.StrName = "NewRuleName"; new_STDdata.Expression = "false"; new_STDdata.KeyElementList = ""; new_STDdata.SubElementList = ""; Random random = new Random(); new_STDdata.Color = ColorGroup[random.Next(ColorGroup.Length)]; return new_STDdata; } object Clone(Dictionary STDDictionary) { Dictionary STDDictionaryInitial = new Dictionary(); foreach (var key in STDDictionary.Keys) { STDdata tDdata = new STDdata(); tDdata = tDdata.Clone(STDDictionary[key]) as STDdata; STDDictionaryInitial.Add(key, tDdata); } return STDDictionaryInitial; } /// /// 保存ClassifySTD库和MineralElements库 /// /// /// public bool SaveDictionaryToClassify() { //保存列表顺序 //for (int i = 1; i < m_STDRuleslist.Grid_Minerals.RowsCount; i++) //{ // STDDictionary[(int)m_STDRuleslist.Grid_Minerals[i, 0].Tag].ListNum = i.ToString(); //} try { System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + _DBAddress + "'"); m_dbConnection.Open(); System.Data.SQLite.SQLiteCommand cmm = m_dbConnection.CreateCommand(); cmm.CommandText = "delete from ClassifySTD"; //cmm.CommandText = "delete from ClassifySTD_Backup"; try { cmm.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); return false; } System.Data.SQLite.SQLiteDataAdapter m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select * from ClassifySTD", m_dbConnection); //System.Data.SQLite.SQLiteDataAdapter m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select * from ClassifySTD_Backup", m_dbConnection); System.Data.SQLite.SQLiteCommandBuilder qLiteCommandBuilder = new System.Data.SQLite.SQLiteCommandBuilder(m_dataAdapter); DataSet ds = new DataSet(); m_dataAdapter.Fill(ds, "ClassifySTD"); DataTable dt = ds.Tables["ClassifySTD"]; //m_dataAdapter.Fill(ds, "ClassifySTD_Backup"); //DataTable dt = ds.Tables["ClassifySTD_Backup"]; dt.Clear(); foreach (KeyValuePair kv in STDDictionary) { string UsingElementList = ""; string UsingImgPropertyList = ""; string UsingOtherPropertyList = ""; List UsingElementL = new List(); List UsingImgPropertyL = new List(); List UsingOtherPropertyL = new List(); string str_RemoveBlank = kv.Value.Expression; ////forth_elem干扰or分隔符,故先行去掉 //if (str_RemoveBlank.Contains("fourth_elem")) //{ // str_RemoveBlank = str_RemoveBlank.Replace("fourth_elem", ""); // UsingOtherPropertyList = "fourth_elem"; //} str_RemoveBlank = str_RemoveBlank.Replace(" ", ""); string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None); List str_Removeandor = new List(); for (int i = 0; i < str_Removeand.Length; i++) { str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None)); } List list_all = new List(); for (int i = 0; i < str_Removeandor.Count; i++) { list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' })); } for (int i = 0; i < list_all.Count; i++) { //周期元素? if (PeriodicTable.Contains(list_all[i])) { if (!UsingElementL.Contains(list_all[i])) { UsingElementL.Add(list_all[i]); } } //first_elem? if (Elem1.Contains(list_all[i])) { if (!UsingOtherPropertyL.Contains(list_all[i])) { UsingOtherPropertyL.Add(list_all[i]); } } //Element1? if (Elem2.Contains(list_all[i])) { if (!UsingOtherPropertyL.Contains(list_all[i])) { UsingOtherPropertyL.Add(list_all[i]); } } //其它元素? if (ImgProperty.Contains(list_all[i])) { if (!UsingImgPropertyL.Contains(list_all[i])) { UsingImgPropertyL.Add(list_all[i]); } } } if (UsingElementL.Count > 0) { for (int i = 0; i < UsingElementL.Count - 1; i++) { UsingElementList += UsingElementL[i] + ","; } UsingElementList += UsingElementL[UsingElementL.Count - 1]; } if (UsingImgPropertyL.Count > 0) { for (int i = 0; i < UsingImgPropertyL.Count - 1; i++) { UsingImgPropertyList += UsingImgPropertyL[i] + ","; } UsingImgPropertyList += UsingImgPropertyL[UsingImgPropertyL.Count - 1]; } if (UsingOtherPropertyL.Count > 0) { for (int i = 0; i < UsingOtherPropertyL.Count - 1; i++) { UsingOtherPropertyList += UsingOtherPropertyL[i] + ","; } UsingOtherPropertyList += UsingOtherPropertyL[UsingOtherPropertyL.Count - 1]; } DataRow newRow = dt.NewRow(); newRow["STDId"] = kv.Key; newRow["StrName"] = kv.Value.StrName; newRow["Color"] = kv.Value.Color; newRow["KeyElementList"] = kv.Value.KeyElementList; newRow["SubElementList"] = kv.Value.SubElementList; newRow["UsingImgPropertyList"] = UsingImgPropertyList; newRow["UsingOtherPropertyList"] = UsingOtherPropertyList; newRow["Expression"] = kv.Value.Expression; newRow["Hardness"] = kv.Value.Hardness; newRow["Density"] = kv.Value.Density; newRow["Electrical_conductivity"] = kv.Value.Electrical_conductivity; newRow["BSE"] = int.Parse(kv.Value.BSE); newRow["Formula"] = kv.Value.Formula; newRow["Element"] = kv.Value.Element; newRow["IfElementAnalysis"] = kv.Value.IfElementAnalysis; newRow["GroupId"] = kv.Value.GroupId; newRow["ListNum"] = kv.Value.ListNum; dt.Rows.Add(newRow); } m_dataAdapter.Update(ds, "ClassifySTD"); System.Data.SQLite.SQLiteCommand tr = m_dbConnection.CreateCommand(); cmm.CommandText = "delete from STDGroups"; try { cmm.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); return false; } System.Data.SQLite.SQLiteDataAdapter m_dataAdapter_grp = new System.Data.SQLite.SQLiteDataAdapter("select * from STDGroups", m_dbConnection); System.Data.SQLite.SQLiteCommandBuilder qLiteCommandBuilder_grp = new System.Data.SQLite.SQLiteCommandBuilder(m_dataAdapter_grp); DataSet ds_grp = new DataSet(); m_dataAdapter_grp.Fill(ds_grp, "STDGroups"); DataTable dt_grp = ds_grp.Tables["STDGroups"]; dt_grp.Clear(); foreach (STDGroups kv in GroupDictionary.Values) { DataRow newRow = dt_grp.NewRow(); newRow["id"] = kv.id; newRow["name"] = kv.name; newRow["color"] = kv.color; newRow["iorder"] = kv.iorder; if (kv.name == "Default") { newRow["iorder"] = 10000; newRow["color"] = "#C9C9C9"; } dt_grp.Rows.Add(newRow); } m_dataAdapter_grp.Update(ds_grp, "STDGroups"); m_dbConnection.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); return false; } return true; } public bool SaveAsDictionaryToClassify(string DBAddress) { ////保存列表顺序 //for (int i = 1; i < m_STDRuleslist.Grid_Minerals.RowsCount; i++) //{ // STDDictionary[(int)m_STDRuleslist.Grid_Minerals[i, 0].Tag].ListNum = i.ToString(); //} try { System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + DBAddress + "'"); m_dbConnection.Open(); System.Data.SQLite.SQLiteCommand cmm = m_dbConnection.CreateCommand(); cmm.CommandText = "drop table ClassifySTD"; cmm.ExecuteNonQuery(); cmm.CommandText = "CREATE TABLE ClassifySTD (STDId INTEGER,StrName TEXT, Color TEXT,KeyElementList TEXT,SubElementList TEXT,UsingImgPropertyList TEXT,UsingOtherPropertyList TEXT,Expression TEXT,Hardness TEXT,Density TEXT,Electrical_conductivity TEXT,BSE INTEGER,Formula TEXT,Element TEXT,IfElementAnalysis BOOLEAN,ListNum INT,GroupId INT)"; cmm.ExecuteNonQuery(); System.Data.Common.DbTransaction trans = m_dbConnection.BeginTransaction(); trans.Commit(); System.Data.SQLite.SQLiteDataAdapter m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select * from ClassifySTD", m_dbConnection); System.Data.SQLite.SQLiteCommandBuilder qLiteCommandBuilder = new System.Data.SQLite.SQLiteCommandBuilder(m_dataAdapter); DataSet ds = new DataSet(); m_dataAdapter.Fill(ds, "ClassifySTD"); DataTable dt = ds.Tables["ClassifySTD"]; foreach (KeyValuePair kv in STDDictionary) { string UsingElementList = ""; string UsingImgPropertyList = ""; string UsingOtherPropertyList = ""; List UsingElementL = new List(); List UsingImgPropertyL = new List(); List UsingOtherPropertyL = new List(); string str_RemoveBlank = kv.Value.Expression; ////forth_elem干扰or分隔符,故先行去掉 //if (str_RemoveBlank.Contains("fourth_elem")) //{ // str_RemoveBlank = str_RemoveBlank.Replace("fourth_elem", ""); // UsingOtherPropertyList = "fourth_elem,"; //} str_RemoveBlank = str_RemoveBlank.Replace(" ", ""); string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None); List str_Removeandor = new List(); for (int i = 0; i < str_Removeand.Length; i++) { str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None)); } List list_all = new List(); for (int i = 0; i < str_Removeandor.Count; i++) { list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' })); } for (int i = 0; i < list_all.Count; i++) { //周期元素? if (PeriodicTable.Contains(list_all[i])) { if (!UsingElementL.Contains(list_all[i])) { UsingElementL.Add(list_all[i]); } } //first_elem? if (Elem1.Contains(list_all[i])) { if (!UsingOtherPropertyL.Contains(list_all[i])) { UsingOtherPropertyL.Add(list_all[i]); } } //Element1? if (Elem2.Contains(list_all[i])) { if (!UsingOtherPropertyL.Contains(list_all[i])) { UsingOtherPropertyL.Add(list_all[i]); } } //其它元素? if (ImgProperty.Contains(list_all[i])) { if (!UsingImgPropertyL.Contains(list_all[i])) { UsingImgPropertyL.Add(list_all[i]); } } } if (UsingElementL.Count > 0) { for (int i = 0; i < UsingElementL.Count - 1; i++) { UsingElementList += UsingElementL[i] + ","; } UsingElementList += UsingElementL[UsingElementL.Count - 1]; } if (UsingImgPropertyL.Count > 0) { for (int i = 0; i < UsingImgPropertyL.Count - 1; i++) { UsingImgPropertyList += UsingImgPropertyL[i] + ","; } UsingImgPropertyList += UsingImgPropertyL[UsingImgPropertyL.Count - 1]; } if (UsingOtherPropertyL.Count > 0) { for (int i = 0; i < UsingOtherPropertyL.Count - 1; i++) { UsingOtherPropertyList += UsingOtherPropertyL[i] + ","; } UsingOtherPropertyList += UsingOtherPropertyL[UsingOtherPropertyL.Count - 1]; } DataRow newRow = dt.NewRow(); newRow["STDId"] = kv.Key; newRow["StrName"] = kv.Value.StrName; newRow["Color"] = kv.Value.Color; newRow["KeyElementList"] = kv.Value.KeyElementList; newRow["SubElementList"] = kv.Value.SubElementList; newRow["UsingImgPropertyList"] = UsingImgPropertyList; newRow["UsingOtherPropertyList"] = UsingOtherPropertyList; newRow["Expression"] = kv.Value.Expression; newRow["Hardness"] = kv.Value.Hardness; newRow["Density"] = kv.Value.Density; newRow["Electrical_conductivity"] = kv.Value.Electrical_conductivity; newRow["BSE"] = int.Parse(kv.Value.BSE); newRow["Formula"] = kv.Value.Formula; newRow["Element"] = kv.Value.Element; newRow["IfElementAnalysis"] = kv.Value.IfElementAnalysis; newRow["GroupId"] = kv.Value.GroupId; newRow["ListNum"] = kv.Value.ListNum; dt.Rows.Add(newRow); } m_dataAdapter.Update(ds, "ClassifySTD"); System.Data.SQLite.SQLiteCommand tr = m_dbConnection.CreateCommand(); cmm.CommandText = "delete from STDGroups"; try { cmm.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); return false; } System.Data.SQLite.SQLiteDataAdapter m_dataAdapter_grp = new System.Data.SQLite.SQLiteDataAdapter("select * from STDGroups", m_dbConnection); System.Data.SQLite.SQLiteCommandBuilder qLiteCommandBuilder_grp = new System.Data.SQLite.SQLiteCommandBuilder(m_dataAdapter_grp); DataSet ds_grp = new DataSet(); m_dataAdapter_grp.Fill(ds_grp, "STDGroups"); DataTable dt_grp = ds_grp.Tables["STDGroups"]; dt_grp.Clear(); foreach (STDGroups kv in GroupDictionary.Values) { DataRow newRow = dt_grp.NewRow(); newRow["id"] = kv.id; newRow["name"] = kv.name; newRow["color"] = kv.color; newRow["iorder"] = 0; if (kv.name == "Default") { newRow["iorder"] = 10000; } dt_grp.Rows.Add(newRow); } m_dataAdapter_grp.Update(ds_grp, "STDGroups"); m_dbConnection.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); return false; } return true; } public void UpdateSTDDictionaryInitial() { STDDictionaryInitial.Clear(); STDDictionaryInitial = Clone(STDDictionary) as Dictionary; } public void SetNonexistentGroupsToDefault() { foreach (KeyValuePair kv in STDDictionary) { if (!GroupIdDictionaryFromId.Keys.Contains(kv.Value.GroupId)) { kv.Value.GroupId = -1; } } } } }