123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683 |
- 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<int, STDdata> STDDictionary = new Dictionary<int, STDdata>();
- /// <summary>
- /// 原始数据字典用于在关闭时比较是否弹出保存提示
- /// </summary>
- private Dictionary<int, STDdata> STDDictionaryInitial = new Dictionary<int, STDdata>();
- public Dictionary<int, STDGroups> GroupDictionary = new Dictionary<int, STDGroups>();
- public string[] ConstantsStr = null;
- public Dictionary<int, string> GroupIdDictionaryFromId = new Dictionary<int, string>();
- public Dictionary<string, int> GroupIdDictionaryFromName = new Dictionary<string, int>();
- 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<int, STDdata>;
- }
- 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<int, STDdata> STDDictionary)
- {
- Dictionary<int, STDdata> STDDictionaryInitial = new Dictionary<int, STDdata>();
- foreach (var key in STDDictionary.Keys)
- {
- STDdata tDdata = new STDdata();
- tDdata = tDdata.Clone(STDDictionary[key]) as STDdata;
- STDDictionaryInitial.Add(key, tDdata);
- }
- return STDDictionaryInitial;
- }
- /// <summary>
- /// 保存ClassifySTD库和MineralElements库
- /// </summary>
- /// <param name="DBAddress"></param>
- /// <returns></returns>
- 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<int, STDdata> kv in STDDictionary)
- {
- string UsingElementList = "";
- string UsingImgPropertyList = "";
- string UsingOtherPropertyList = "";
- List<string> UsingElementL = new List<string>();
- List<string> UsingImgPropertyL = new List<string>();
- List<string> UsingOtherPropertyL = new List<string>();
- 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<string> str_Removeandor = new List<string>();
- 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<string> list_all = new List<string>();
- 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<int, STDdata> kv in STDDictionary)
- {
- string UsingElementList = "";
- string UsingImgPropertyList = "";
- string UsingOtherPropertyList = "";
- List<string> UsingElementL = new List<string>();
- List<string> UsingImgPropertyL = new List<string>();
- List<string> UsingOtherPropertyL = new List<string>();
- 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<string> str_Removeandor = new List<string>();
- 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<string> list_all = new List<string>();
- 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<int, STDdata>;
- }
- public void SetNonexistentGroupsToDefault()
- {
- foreach (KeyValuePair<int, STDdata> kv in STDDictionary)
- {
- if (!GroupIdDictionaryFromId.Keys.Contains(kv.Value.GroupId))
- {
- kv.Value.GroupId = -1;
- }
- }
- }
- }
- }
|