1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045 |
- using OTS.WinFormsUI.Docking;
- using SourceGrid;
- using SpectrumSTDEditor.BaseClass;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Windows.Forms;
- namespace SpectrumSTDEditor
- {
- public partial class Form_Main : Form
- {
- public STDRuleslist m_STDRuleslist = null;
- public Attributes m_Attributes = null;
- public SubMidWindow m_SubMidWindow = null;
- //public STDEditor m_STDEditor = null;
- /// <summary>
- /// 实际存储的字典
- /// </summary>
- public Dictionary<int, STDdata> STDDictionary = new Dictionary<int, STDdata>();
- /// <summary>
- /// 原始数据字典用于在关闭时比较是否弹出保存提示
- /// </summary>
- private Dictionary<int, STDdata> STDDictionaryInitial = new Dictionary<int, STDdata>();
- public Dictionary<int, string> GroupIdDictionaryFromId = new Dictionary<int, string>();
- public Dictionary<string, int> GroupIdDictionaryFromName = new Dictionary<string, int>();
- public string STDDBAddress = "";
- /// <summary>
- /// 0:正在打开的标准库路径;1:所增加标准的颗粒所在结果库位置;2:所增加标准的颗粒FieldId;3:所增加标准的颗粒ParticleId;4:所增加标准的颗粒XRayId
- /// </summary>
- List<string> ImportArgs = new List<string>();
- //国际化
- public Language lan;
- Hashtable table;
- //是否做出过更改
- public bool IsModified { set; get; }
- public bool Isoldversion { 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 Form_Main()
- {
- InitializeComponent();
- m_STDRuleslist = new STDRuleslist(this);
- m_Attributes = new Attributes(this);
- //m_STDEditor = new STDEditor(this, m_MainForm.STDDBAddress);
- m_SubMidWindow = new SubMidWindow(this);
- }
- public Form_Main(string[] ImportStandardLibraryArgs)
- {
- InitializeComponent();
- m_STDRuleslist = new STDRuleslist(this);
- m_Attributes = new Attributes(this);
- m_SubMidWindow = new SubMidWindow(this);
- foreach (var it in ImportStandardLibraryArgs)
- {
- ImportArgs.Add(it);
- }
- }
- private void Form_Main_Load(object sender, EventArgs e)
- {
- lan = new Language(this);
- table = lan.GetNameTable("Form_Main");
- if (STDDBAddress != "")
- {
- InitForms(STDDBAddress);
- this.Text = this.Text.Split(' ')[0] + " " + STDDBAddress;
- IsModified = false;
- //if (ImportArgs.Count > 1)
- //{
- // ImportStandardLibraryTypeSelection m_importStandardLibraryTypeSelection = new ImportStandardLibraryTypeSelection();
- // var result = m_importStandardLibraryTypeSelection.ShowDialog();
- // if (m_importStandardLibraryTypeSelection.SelectEvent == "expression")
- // {
- // int STDId = AddSTDDictionaryItem();
- // m_STDRuleslist.AddNewRow(STDId, "NewClassify", Attributes.string10ToColor(STDDictionary[STDId].Color));
- // }
- //}
-
- }
- }
-
- bool LoadClassifyToDictionary(string DBAddress, ref Dictionary<int, STDdata> STDDictionary)
- {
- try
- {
- //STDDictionaryInitial.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 STDMinerals order by orderid", m_dbConnection);
- DataSet ds = new DataSet();
- m_dataAdapter.Fill(ds);
- DataTable dt = ds.Tables[0];
- if (dt != null)
- {
- rbSave.Enabled = true;
- Isoldversion = false;
- if (dt.Rows.Count > 0)
- {
- foreach (DataRow item in dt.Rows)
- {
- STDdata new_STDdata = new STDdata();
- new_STDdata.Hardness = item["rigiditymod"].ToString();
- new_STDdata.Density = item["density"].ToString();
- //new_STDdata.Electrical_conductivity = item["Electrical_conductivity"].ToString();
- new_STDdata.BSE = item["BSEValue"].ToString();
- new_STDdata.Formula = item["formula"].ToString();
- new_STDdata.Element = item["element"].ToString();
- new_STDdata.StrName = item["name"].ToString();
- new_STDdata.ChineseName = item["chinesename"].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 = item["GroupId"].ToString();
- new_STDdata.OrderId = item["orderid"].ToString();
- new_STDdata.XrayData = (byte[])item["SPEC"];
- //new_STDdata.GroupId = item["GroupId"].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["id"].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;
- }
- }
- public void ChangeSTDEditorAndGrid_Attributes(int STDId)
- {
- m_SubMidWindow.SelSTDXray(STDId, STDDictionary[STDId]);
- m_Attributes.SetDatatoGrid_Attributes(STDId);
- }
- private void rbBackup_Click(object sender, EventArgs e)
- {
- if (m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row >= 0)
- {
- SaveDataOfSelRule(m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Column);
- }
- try
- {
- SaveFileDialog saveFile = new SaveFileDialog();
- saveFile.Title = "Please select the path which to save the file";
- saveFile.Filter = "Database File(*.db)|*.db";
- saveFile.InitialDirectory = Application.StartupPath + "\\Config\\SysData\\";
- saveFile.OverwritePrompt = false; //是否覆盖当前文件
- if (saveFile.ShowDialog() == DialogResult.OK)
- {
- if (STDDBAddress == saveFile.FileName)
- {
- MessageBox.Show("不能另存为同名文件!", "Tip");
- return;
- }
- FormForWaiting forWaiting = new FormForWaiting();
- forWaiting.Show();
- System.IO.File.Copy(STDDBAddress, saveFile.FileName, true);
- bool result = SaveAsDictionaryToClassify(saveFile.FileName);
- if (result)
- {
-
- m_SubMidWindow.m_STDEditor.SaveSTDXray();
- STDDictionaryInitial.Clear();
- STDDictionaryInitial = Clone(STDDictionary) as Dictionary<int, STDdata>;
- STDDBAddress = saveFile.FileName;
- this.Text = this.Text.Split(' ')[0] + " " + saveFile.FileName;
- IsModified = false;
- forWaiting.Close();
- MessageBox.Show("Save successful!", "Tip");
- }
- else
- {
- forWaiting.Close();
- MessageBox.Show("Save failed!", "Tip");
- }
- }
- else
- {
- return;
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- 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;
- }
- }
- 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;
- }
- private void rbSave_Click(object sender, EventArgs e)
- {
- if (m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row > 0)
- {
- SaveDataOfSelRule(m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0);
- }
- //if (RuleformatcheckAndSave())
- //{
- FormForWaiting forWaiting = new FormForWaiting();
- forWaiting.Show();
- bool result = SaveDictionaryToClassify(STDDBAddress);
- if (result)
- {
- m_SubMidWindow.m_STDEditor.SaveSTDXray();
- STDDictionaryInitial.Clear();
- STDDictionaryInitial = Clone(STDDictionary) as Dictionary<int, STDdata>;
- forWaiting.Close();
- IsModified = false;
- MessageBox.Show("Save successful!", "Tip");
- }
- else
- {
- forWaiting.Close();
- MessageBox.Show("Save failed!", "Tip");
- }
- //}
- //else
- //{
- // return;
- //}
- }
- bool RuleformatcheckAndSave()
- {
- foreach (var ite in STDDictionary)
- {
- Position pos = new Position(Convert.ToInt32(ite.Value.OrderId), 0);
- m_STDRuleslist.Grid_Minerals[Convert.ToInt32(ite.Value.OrderId), 0].Grid.Select();
- m_STDRuleslist.Grid_Minerals.Selection.Focus(pos, true);
- m_STDRuleslist.Grid_Minerals.Refresh();
- ChangeSTDEditorAndGrid_Attributes(ite.Key);
- m_STDRuleslist.PreRow = Convert.ToInt32(ite.Value.OrderId);
- return false;
- }
- return true;
- }
- ///// <summary>
- ///// [颜色:RGB转成16进制]
- ///// </summary>
- ///// <param name="R">红 int</param>
- ///// <param name="G">绿 int</param>
- ///// <param name="B">蓝 int</param>
- ///// <returns></returns>
- //public static string colorRGBtoHx16(int R, int G, int B)
- //{
- // return System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.FromArgb(R, G, B));
- //}
-
- /// <summary>
- /// 属性检测
- /// </summary>
- /// <param name="ddata"></param>
- /// <returns></returns>
- public bool CheckAttributes(STDdata ddata)
- {
- if (string.IsNullOrEmpty(ddata.StrName))
- {
- MessageBox.Show("Rule name can not be null !", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- //if (string.IsNullOrEmpty(ddata.g)
- //{
- // if (!GroupIdDictionaryFromName.ContainsKey(m_Attributes.Grid_Attributes[11, 1].Value.ToString()))
- // {
- // Position pos = new Position(11, 1);
- // m_Attributes.Grid_Attributes.Selection.Focus(pos, true);
- // MessageBox.Show("This group name is not included, please fill in again!", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
- // return false;
- // }
- //}
- #region 化学式和元素暂无限制
- //if (m_Attributes.Grid_Attributes[7, 1].Value.ToString())
- //{
- // Position pos = new Position(7, 1);
- // m_Attributes.Grid_Attributes.Selection.Focus(pos, true);
- // MessageBox.Show(table["message10"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- // return false;
- //}
- //if (m_Attributes.Grid_Attributes[8, 1].Value.ToString())
- //{
- // Position pos = new Position(8, 1);
- // m_Attributes.Grid_Attributes.Selection.Focus(pos, true);
- // MessageBox.Show(table["message10"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- // return false;
- //}
- #endregion
- return true;
- }
- public void SaveDataOfSelRule(int PreRow, int PreColumn)
- {
- STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, 0].Tag.ToString())].StrName = Convert.ToString(m_Attributes.Grid_Attributes[2, 1].Value);
- STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, 0].Tag.ToString())].ChineseName = Convert.ToString(m_Attributes.Grid_Attributes[3, 1].Value);
- STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, 0].Tag.ToString())].Color = shareFunction.ColorTostring10(m_Attributes.Grid_Attributes[4, 1].View.BackColor);
- //STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, 0].Tag.ToString())].IfElementAnalysis = Convert.ToBoolean(m_Attributes.Grid_Attributes[4, 1].Value);
- STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, 0].Tag.ToString())].Hardness = Convert.ToString(m_Attributes.Grid_Attributes[5, 1].Value);
- STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, 0].Tag.ToString())].Density = Convert.ToString(m_Attributes.Grid_Attributes[6, 1].Value);
- //STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, 0].Tag.ToString())].Electrical_conductivity = Convert.ToString(m_Attributes.Grid_Attributes[7, 1].Value);
- STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, 0].Tag.ToString())].BSE = Convert.ToString(m_Attributes.Grid_Attributes[7, 1].Value);
- if (m_Attributes.Grid_Attributes[8, 1].Value != null)
- {
- STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, 0].Tag.ToString())].Formula = Convert.ToString(m_Attributes.Grid_Attributes[8, 1].Value);
- }
- else
- {
- STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, 0].Tag.ToString())].Formula = "";
- }
- if (m_Attributes.Grid_Attributes[9, 1].Value != null)
- {
- STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, 0].Tag.ToString())].Element = Convert.ToString(m_Attributes.Grid_Attributes[9, 1].Value);
- }
- else
- {
- STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, 0].Tag.ToString())].Element = "";
- }
- //if (m_Attributes.Grid_Attributes[11, 1].Value != null)
- //{
- // STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, 0].Tag.ToString())].GroupId = GroupIdDictionaryFromName[Convert.ToString(m_Attributes.Grid_Attributes[11, 1].Value)].ToString();
- //}
- //else
- //{
- // STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, 0].Tag.ToString())].GroupId = "0";
- //}
- //STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, 0].Tag.ToString())].Expression = "";
- //string sKeyElements = "";
- //string sSubElements = "";
- //STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, 0].Tag.ToString())].KeyElementList = sKeyElements;
- //STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, 0].Tag.ToString())].SubElementList = sSubElements;
- STDDictionary[int.Parse(m_STDRuleslist.Grid_Minerals[PreRow, 0].Tag.ToString())].OrderId = PreRow.ToString();
- }
- /// <summary>
- /// 保存ClassifySTD库和MineralElements库
- /// </summary>
- /// <param name="DBAddress"></param>
- /// <returns></returns>
- bool SaveDictionaryToClassify(string DBAddress)
- {
- //保存列表顺序
- for (int i = 1; i < m_STDRuleslist.Grid_Minerals.RowsCount; i++)
- {
- STDDictionary[(int)m_STDRuleslist.Grid_Minerals[i, 0].Tag].OrderId = 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 STDMinerals";
- 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 STDMinerals", m_dbConnection);
-
- System.Data.SQLite.SQLiteCommandBuilder qLiteCommandBuilder = new System.Data.SQLite.SQLiteCommandBuilder(m_dataAdapter);
- DataSet ds = new DataSet();
- m_dataAdapter.Fill(ds, "STDMinerals");
- DataTable dt = ds.Tables["STDMinerals"];
- dt.Clear();
- foreach (KeyValuePair<int, STDdata> kv in STDDictionary)
- {
- DataRow newRow = dt.NewRow();
- newRow["id"] = kv.Key;
- newRow["name"] = kv.Value.StrName;
- newRow["chinesename"] = kv.Value.ChineseName;
- newRow["color"] = kv.Value.Color;
- newRow["rigiditymod"] = kv.Value.Hardness;
- newRow["density"] = kv.Value.Density;
- newRow["BSEValue"] = int.Parse(kv.Value.BSE);
- newRow["formula"] = kv.Value.Formula;
- newRow["element"] = kv.Value.Element;
- newRow["orderid"] = kv.Value.OrderId;
- newRow["SPEC"] = kv.Value.XrayData;
- dt.Rows.Add(newRow);
- }
- m_dataAdapter.Update(ds, "STDMinerals");
- m_dbConnection.Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.ToString());
- return false;
- }
- return true;
- }
- bool SaveAsDictionaryToClassify(string DBAddress)
- {
- 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 STDMinerals";
- cmm.ExecuteNonQuery();
- cmm.CommandText = "CREATE TABLE STDMinerals (id INTEGER,name TEXT,chinesename TEXT,formula TEXT,density FLOAT,BSEValue INTEGER,rigiditymod FLOAT,color INTEGER,SPEC BLOB,element TEXT,orderid INTEGER)";
- 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 STDMinerals", m_dbConnection);
- System.Data.SQLite.SQLiteCommandBuilder qLiteCommandBuilder = new System.Data.SQLite.SQLiteCommandBuilder(m_dataAdapter);
- DataSet ds = new DataSet();
- m_dataAdapter.Fill(ds, "STDMinerals");
- DataTable dt = ds.Tables["STDMinerals"];
- foreach (KeyValuePair<int, STDdata> kv in STDDictionary)
- {
- DataRow newRow = dt.NewRow();
- newRow["id"] = kv.Key;
- newRow["name"] = kv.Value.StrName;
- newRow["chinesename"] = kv.Value.ChineseName;
- newRow["color"] = kv.Value.Color;
- newRow["rigiditymod"] = kv.Value.Hardness;
- newRow["density"] = kv.Value.Density;
- newRow["BSEValue"] = int.Parse(kv.Value.BSE);
- newRow["formula"] = kv.Value.Formula;
- newRow["element"] = kv.Value.Element;
- newRow["orderid"] = kv.Value.OrderId;
- newRow["SPEC"] = kv.Value.XrayData;
- dt.Rows.Add(newRow);
- }
- m_dataAdapter.Update(ds, "STDMinerals");
- m_dbConnection.Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.ToString());
- return false;
- }
- return true;
- }
- public int AddSTDDictionaryItem()
- {
- STDdata new_STDdata = new STDdata();
- new_STDdata.Hardness = "1";
- new_STDdata.Density = "1";
- new_STDdata.BSE = "1";
- new_STDdata.Formula = "1";
- new_STDdata.Element = "1";
- new_STDdata.StrName = "NewRuleName";
- new_STDdata.ChineseName = "新建标准";
- Random random = new Random();
- new_STDdata.Color = shareFunction.ObtainRandomColor();
- int STDId = 40000;
- foreach (KeyValuePair<int, STDdata> kv in STDDictionary)
- {
- if (STDId < kv.Key)
- {
- STDId = kv.Key;
- }
- }
- STDDictionary.Add(STDId + 1, new_STDdata);
- return STDId + 1;
- }
- public void RemoveSTDDictionaryItem(int STDId)
- {
- STDDictionary.Remove(STDId);
- }
- public void ChangeStrName(int RowNum, string NewStrName)
- {
- STDDictionary[(int)m_STDRuleslist.Grid_Minerals[RowNum, 0].Tag].StrName = NewStrName;
- m_Attributes.Grid_Attributes[2, 1].Value = NewStrName;
- }
- public void ChangeSTDRulesLISTBackColor()
- {
- int stdid = m_STDRuleslist.ChangeSTDRulesLISTBackColor();
- m_SubMidWindow.SelSTDXray(stdid, STDDictionary[stdid]);
- }
- public void ChangeSTDRuleName(String RuleName)
- {
- m_STDRuleslist.Grid_Minerals[m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0].Value = RuleName;
- }
- public void SetNull()
- {
- //m_SubMidWindow.m_STDEditor.textbox_STDEditor.Text = "";
- for (int i = 1; i < m_Attributes.Grid_Attributes.RowsCount - 1; i++)
- {
- if (m_Attributes.Grid_Attributes[i, 1].Value != null)
- {
- if (m_Attributes.Grid_Attributes[i, 1].View is SourceGrid.Cells.Views.CheckBox)
- {
- m_Attributes.Grid_Attributes[i, 1].Value = true;
- }
- else
- {
- m_Attributes.Grid_Attributes[i, 1].Value = "";
- }
- }
- }
- SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
- view.BackColor = Color.White;
- m_Attributes.Grid_Attributes[2, 1].View = view;
- }
- //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)
- //{
- // //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();
- // int selGroupId = GroupIdDictionaryFromName[m_Attributes.Grid_Attributes[11, 1].Value.ToString()];
- // Form_GroupId form_GroupId = new Form_GroupId(STDDBAddress, this);
- // DialogResult dialogResult = form_GroupId.ShowDialog();
- // if (dialogResult == DialogResult.Yes)
- // {
- // AddSTDGroupsToAttribute();
- // //SetNonexistentGroupsToDefault();
- // m_Attributes.Grid_Attributes[11, 1].Value = GroupIdDictionaryFromId[selGroupId];
- // }
- //}
- private void ribbon_Exit_Click(object sender, EventArgs e)
- {
- this.Close();
- }
-
- private void rbClose_Click(object sender, EventArgs e)
- {
- if (!Isoldversion)
- {
- if (!EqualsBetweenDictionary(STDDictionaryInitial, STDDictionary) || IsModified)
- {
- DialogResult dr = MessageBox.Show("Whether to save the current modification?", "Tip", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
- if (dr == DialogResult.Yes)
- {
- if (m_STDRuleslist.Grid_Minerals.RowsCount > 1)
- {
- if ((m_STDRuleslist.Grid_Minerals[m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0].Value.ToString().Replace(" ", "").Trim() != ""))
- {
- SaveDataOfSelRule(m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0);
- }
- else
- {
- return;
- }
- }
- else
- {
- STDDictionaryInitial.Clear();
- }
- FormForWaiting forWaiting = new FormForWaiting();
- forWaiting.Show();
- bool result = SaveDictionaryToClassify(STDDBAddress);
- if (result)
- {
- forWaiting.Close();
- }
- else
- {
- forWaiting.Close();
- MessageBox.Show("Save failed!", "Tip");
- }
- }
- }
- }
- m_Attributes.Close();
- m_STDRuleslist.Close();
- m_SubMidWindow.m_STDEditor.Close();
- m_SubMidWindow.m_ComparativeLibrary.Close();
- m_SubMidWindow.Close();
- ButtonStatusClose();
- if (this.Text.Split(' ').Count() != 0)
- {
- this.Text = this.Text.Split(' ')[0];
- }
- }
- private void rbOpen_Click(object sender, EventArgs e)
- {
- OpenFileDialog openFileDialog = new OpenFileDialog();
- openFileDialog.Filter = "(*.db)|*.db";
- openFileDialog.RestoreDirectory = true;
- openFileDialog.InitialDirectory = Application.StartupPath + "\\Config\\SysData\\";
- openFileDialog.FilterIndex = 1;
- if (openFileDialog.ShowDialog() == DialogResult.OK)
- {
- try
- {
- this.Cursor = Cursors.WaitCursor;
- STDDBAddress = openFileDialog.FileName;
- InitForms(STDDBAddress);
- this.Text = this.Text.Split(' ')[0] + " " + STDDBAddress;
- IsModified = false;
- this.Cursor = Cursors.Default;
- //CheckAccuracyofZeroRules();
- }
- catch(Exception ex)
- {
- MessageBox.Show(ex.ToString(), "Tip");
- this.Cursor = Cursors.Default;
- }
- }
- }
- void ButtonStatusOpen()
- {
- rbOpen.Enabled = false;
- rbClose.Enabled = true;
- //rbRecover.Enabled = true;
- rbBackup.Enabled = true;
- rbSave.Enabled = true;
- rbNew.Enabled = false;
- }
- void ButtonStatusClose()
- {
- rbOpen.Enabled = true;
- rbClose.Enabled = false;
- //rbRecover.Enabled = false;
- rbBackup.Enabled = false;
- rbSave.Enabled = false;
- rbNew.Enabled = true;
- }
- void InitForms(string DBAddress)
- {
- STDDictionary.Clear();
- ButtonStatusOpen();
- bool ret = LoadClassifyToDictionary(DBAddress, ref STDDictionary);
- STDDictionaryInitial = Clone(STDDictionary) as Dictionary<int, STDdata>;
- if (!ret)
- {
- return;
- }
- m_STDRuleslist = new STDRuleslist(this);
- m_Attributes = new Attributes(this);
- m_SubMidWindow = new SubMidWindow(this);
- m_STDRuleslist.Show(dockPanel1, DockState.DockLeft);
- m_Attributes.Show(dockPanel1, DockState.DockRight);
- m_SubMidWindow.Show(dockPanel1, DockState.Document);
- dockPanel1.DockLeftPortion = 360;
- dockPanel1.DockRightPortion = 381;
- if (m_SubMidWindow.m_STDEditor.m_sc != null)
- {
- m_SubMidWindow.m_STDEditor.m_sc.CloseDB();
- }
- m_SubMidWindow.m_STDEditor.m_sc = new SqlLiteClass(DBAddress);
- //AddSTDGroupsToAttribute();
- //m_SubMidWindow.m_STDEditor.textbox_STDEditor.Text = "";
- if (m_STDRuleslist.Grid_Minerals.RowsCount > 1)
- {
- m_STDRuleslist.button_UpOrder.Enabled = false;
- if (m_STDRuleslist.Grid_Minerals.RowsCount == 2) //就一条时向下按钮置灰
- {
- m_STDRuleslist.button_DownOrder.Enabled = false;
- }
- ChangeSTDEditorAndGrid_Attributes(int.Parse(m_STDRuleslist.Grid_Minerals[1, 0].Tag.ToString()));
- Position pos = new Position(1, 0);
- m_STDRuleslist.Grid_Minerals[1, 0].Grid.Select();
- m_STDRuleslist.Grid_Minerals.Selection.Focus(pos, true);
- }
- }
- bool EqualsBetweenDictionary(Dictionary<int, STDdata> STDDictionaryInitial, Dictionary<int, STDdata> STDDictionary)
- {
- 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;
- }
- private void Form_ConstantsEditor2_FormClosing(object sender, FormClosingEventArgs e)
- {
- if (Isoldversion)
- {
- return;
- }
- if (m_STDRuleslist.Text != "")
- {
- if (!EqualsBetweenDictionary(STDDictionaryInitial, STDDictionary) || IsModified)
- {
- DialogResult dr = MessageBox.Show("Whether to save the current modification", "Tip", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
- if (dr == DialogResult.Yes)
- {
- if (m_STDRuleslist.Grid_Minerals.RowsCount > 1)
- {
- if (m_STDRuleslist.Grid_Minerals[m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0].Value.ToString().Replace(" ", "").Trim() != "")
- {
- SaveDataOfSelRule(m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0);
- }
- else
- {
- e.Cancel = true;
- return;
- }
- }
- else
- {
- STDDictionaryInitial.Clear();
- }
- FormForWaiting forWaiting = new FormForWaiting();
- forWaiting.Show();
- bool result = SaveDictionaryToClassify(STDDBAddress);
- if (result)
- {
- forWaiting.Close();
- }
- else
- {
- forWaiting.Close();
- MessageBox.Show("Save failed!", "Tip");
- }
- }
- 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;
- // }
- //}
- }
- }
- }
- }
- private void rbNew_Click(object sender, EventArgs e)
- {
- SaveFileDialog saveFile = new SaveFileDialog();
- saveFile.Title = table["message23"].ToString();
- saveFile.Filter = table["message36"].ToString();
- saveFile.OverwritePrompt = true; //是否覆盖当前文件
- saveFile.RestoreDirectory = true; //还原上次目录
- if (saveFile.ShowDialog() == DialogResult.OK)
- {
- try
- {
- System.Data.SQLite.SQLiteConnection.CreateFile(saveFile.FileName);
- System.Data.SQLite.SQLiteConnection m_OtsDatabaseConnection = new System.Data.SQLite.SQLiteConnection("data source='" + saveFile.FileName + "'");
- m_OtsDatabaseConnection.Open();
- System.Data.SQLite.SQLiteCommand OtsDatabaseCommand = m_OtsDatabaseConnection.CreateCommand();
- OtsDatabaseCommand.CommandText = "CREATE TABLE STDMinerals (id INTEGER,name TEXT,chinesename TEXT,formula TEXT,density FLOAT,BSEValue INTEGER,rigiditymod FLOAT,color INTEGER,SPEC BLOB,element TEXT,orderid INTEGER)";
- OtsDatabaseCommand.ExecuteNonQuery();
- System.Data.Common.DbTransaction trans = m_OtsDatabaseConnection.BeginTransaction();
- trans.Commit();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.ToString());
- return;
- }
- STDDBAddress = saveFile.FileName;
- InitForms(STDDBAddress);
- this.Text = this.Text.Split(' ')[0] + " " + STDDBAddress;
- IsModified = false;
- }
- else
- {
- return;
- }
- }
- //void CheckAccuracyofZeroRules()
- //{
- // System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + STDDBAddress + "'");
- // m_dbConnection.Open();
- // System.Data.SQLite.SQLiteDataAdapter m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select * from ZeroElementRules", m_dbConnection);
- // DataSet ds = new DataSet();
- // m_dataAdapter.Fill(ds);
- // DataTable dt = ds.Tables[0];
- // DataTable dt2 = dt.Copy();
- // if (dt != null)
- // {
- // if (dt.Columns[dt.Columns.Count - 1].ColumnName != "Expression")
- // {
- // System.Data.SQLite.SQLiteCommand cmm = m_dbConnection.CreateCommand();
-
- // cmm.CommandText = "CREATE TABLE sqlitestudio_temp_table AS SELECT * FROM ZeroElementRules";
- // cmm.ExecuteNonQuery();
- // cmm.CommandText = "DROP TABLE ZeroElementRules";
- // cmm.ExecuteNonQuery();
- // cmm.CommandText = "CREATE TABLE ZeroElementRules (ZeroElement TEXT,UsingElementList TEXT,UsingImgPropertyList TEXT,UsingOtherPropertyList TEXT,Expression TEXT)";
- // cmm.ExecuteNonQuery();
- // cmm.CommandText = @"INSERT INTO ZeroElementRules (
- // ZeroElement,
- // UsingElementList,
- // UsingImgPropertyList,
- // UsingOtherPropertyList,
- // Expression
- // )
- // SELECT ZeroElement,
- // UsingElementList,
- // UsingImgPropertyList,
- // UsingOtherPropertyList,
- // Expression
- // FROM sqlitestudio_temp_table; ";
- // cmm.ExecuteNonQuery();
- // cmm.CommandText = "DROP TABLE sqlitestudio_temp_table";
- // cmm.ExecuteNonQuery();
- // m_dbConnection.Close();
- // MessageBox.Show("检测到该数据库零元素规则格式错误,已进行修正!");
- // }
- // }
- //}
- private void ribbonOrbMenuItem_Convert_Click(object sender, EventArgs e)
- {
- DataTable OreDatabasedt = new DataTable();
- OpenFileDialog openFileDialog = new OpenFileDialog();
- openFileDialog.Title = "Please select the database you want to convert";
- openFileDialog.Filter = "(*.db)|*.db";
- openFileDialog.RestoreDirectory = true;
- openFileDialog.FilterIndex = 1;
- if (openFileDialog.ShowDialog() == DialogResult.OK)
- {
- try
- {
- string OreDatabaseAddress = openFileDialog.FileName;
- System.Data.SQLite.SQLiteConnection m_OreDatabaseConnection = new System.Data.SQLite.SQLiteConnection("data source='" + OreDatabaseAddress + "'");
- m_OreDatabaseConnection.Open();
- System.Data.SQLite.SQLiteDataAdapter m_OreDatabasedataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select * from STDMinerals", m_OreDatabaseConnection);
- DataSet OreDatabaseds = new DataSet();
- m_OreDatabasedataAdapter.Fill(OreDatabaseds);
- OreDatabasedt = OreDatabaseds.Tables[0];
- int listnum = 1;
- SaveFileDialog saveFile = new SaveFileDialog();
- saveFile.Title = table["message23"].ToString();
- saveFile.Filter = table["message36"].ToString();
- saveFile.OverwritePrompt = true;
- saveFile.RestoreDirectory = true;
- if (saveFile.ShowDialog() == DialogResult.OK)
- {
- System.Data.SQLite.SQLiteConnection.CreateFile(saveFile.FileName);
- System.Data.SQLite.SQLiteConnection m_OtsDatabaseConnection = new System.Data.SQLite.SQLiteConnection("data source='" + saveFile.FileName + "'");
- m_OtsDatabaseConnection.Open();
- System.Data.SQLite.SQLiteCommand OtsDatabaseCommand = m_OtsDatabaseConnection.CreateCommand();
- OtsDatabaseCommand.CommandText = "CREATE TABLE STDMinerals (id INTEGER,name TEXT,chinesename TEXT,formula TEXT,density FLOAT,BSEValue INTEGER,rigiditymod FLOAT,color INTEGER,SPEC BLOB,element TEXT,orderid INTEGER)";
- OtsDatabaseCommand.ExecuteNonQuery();
- System.Data.Common.DbTransaction trans = m_OtsDatabaseConnection.BeginTransaction();
- foreach (DataRow item in OreDatabasedt.Rows)
- {
- OtsDatabaseCommand.CommandText = "insert into STDMinerals (id,name,chinesename,formula,density,BSEValue,rigiditymod,color,SPEC,element,orderid) values (@id, @name, @chinesename, @formula, @density, @BSEValue, @rigiditymod, @color,@SPEC,@element, @orderid)";
- OtsDatabaseCommand.Parameters.Add("id", DbType.Int32).Value = item["id"];
- OtsDatabaseCommand.Parameters.Add("name", DbType.String).Value = item["name"];
- OtsDatabaseCommand.Parameters.Add("chinesename", DbType.String).Value = " ";
- OtsDatabaseCommand.Parameters.Add("formula", DbType.String).Value = item["formula"].ToString();
- OtsDatabaseCommand.Parameters.Add("density", DbType.String).Value = item["density"];
- OtsDatabaseCommand.Parameters.Add("BSEValue", DbType.String).Value = item["BSEValue"];
- OtsDatabaseCommand.Parameters.Add("rigiditymod", DbType.String).Value = item["rigiditymod"];
- OtsDatabaseCommand.Parameters.Add("color", DbType.String).Value = item["color"];
- OtsDatabaseCommand.Parameters.Add("SPEC", DbType.Binary).Value = item["SPEC"];
- OtsDatabaseCommand.Parameters.Add("element", DbType.String).Value = " ";
- OtsDatabaseCommand.Parameters.Add("orderid", DbType.String).Value = listnum.ToString();
- OtsDatabaseCommand.ExecuteNonQuery();
- }
- trans.Commit();
- MessageBox.Show("successful");
- }
- else
- {
- return;
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.ToString());
- }
- }
- else
- {
- return;
- }
- }
- private void Form_Main_Paint(object sender, PaintEventArgs e)
- {
- comboBoxfilter.Location = new Point(ribbonPanel5.GetContentBounds().X+1, ribbonPanel5.GetContentBounds().Y + 1);
- btnfilter.Location = new Point(ribbonPanel5.GetContentBounds().X + 36, ribbonPanel5.GetContentBounds().Y + 25);
- }
- private void comboBoxfilter_Enter(object sender, EventArgs e)
- {
- comboBoxfilter.Items.Clear();
- List<string> PeriodicTable =new List<string>();
- foreach (var item in STDDictionary)
- {
- PeriodicTable.Add(item.Value.ChineseName);
- PeriodicTable.Add(item.Value.StrName);
- }
- AutoCompleteStringCollection sc = new AutoCompleteStringCollection();
- sc.AddRange(PeriodicTable.ToArray());
- this.comboBoxfilter.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
- this.comboBoxfilter.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.CustomSource;
- this.comboBoxfilter.AutoCompleteCustomSource = sc;
- }
- private void comboBoxfilter_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (comboBoxfilter.Text.Length > 0)
- {
- // 将 SelectionStart 设置为文本的长度,即光标位置移到文本末尾
- comboBoxfilter.SelectionStart = comboBoxfilter.Text.Length;
- // 如果你想让光标仅仅定位而没有任何文本被选中,保持 SelectionLength 为 0
- comboBoxfilter.SelectionLength = 0;
- }
- }
- private void btnfilter_Click(object sender, EventArgs e)
- {
- for (int i = 1; i < m_STDRuleslist.Grid_Minerals.RowsCount; i++)
- {
- int id = (int)m_STDRuleslist.Grid_Minerals[i, 0].Tag;
- if (STDDictionary[id].StrName == comboBoxfilter.Text || STDDictionary[id].ChineseName == comboBoxfilter.Text)
- {
- Position pos = new Position(i, 0);
- m_STDRuleslist.Grid_Minerals.Selection.Focus(pos, true);
- SaveDataOfSelRule(m_STDRuleslist.PreRow, 0);
- ChangeSTDEditorAndGrid_Attributes(id);
- m_SubMidWindow.m_ComparativeLibrary.MakeCheckboxUnchecked();
- m_STDRuleslist.PreRow = i;
- }
- m_STDRuleslist.SetOrderButtonsStatus();
- }
- }
- }
- }
|