123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892 |
- using OTS.WinFormsUI.Docking;
- using OTSPartA_STDEditor.BaseClass;
- using SourceGrid;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Windows.Forms;
- using System.Xml;
- using System.Xml.Linq;
- namespace OTSPartA_STDEditor
- {
- public partial class Form_Main : Form
- {
- public STDRuleslist m_STDRuleslist = null;
- public Attributes m_Attributes = null;
- public SubMidWindow m_SubMidWindow = null;
- public string STDDBAddress = "";
- public STDInfo _sTDEditor=null;
- /// <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 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_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_ConstantsEditor2_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 = _sTDEditor.AddSTDDictionaryItem();
- m_STDRuleslist.AddNewRow(STDId, "NewClassify", Attributes.colorHx16toRGB(_sTDEditor.STDDictionary[STDId].Color));
- }
- }
- }
- }
- public void ChangeSTDEditorAndGrid_Attributes(int STDId)
- {
- m_SubMidWindow.ChangeText_textbox_STDEditor(STDId);
- m_Attributes.SetDatatoGrid_Attributes(STDId);
- }
- private void rbBackup_Click(object sender, EventArgs e)
- {
- if (m_STDRuleslist.tabControl1.SelectedIndex == 0)
- {
- m_STDRuleslist.ConvertToRuleViewDic();
- }
- else
- {
- if (m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row > 0)
- {
- STDdata sTDdata = (STDdata)m_STDRuleslist.Grid_Minerals[m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0].Tag;
- SaveDataOfSelRule(sTDdata.STDId);
- }
- }
- 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("Cannot save as same name!", "Tip");
- return;
- }
- FormForWaiting forWaiting = new FormForWaiting();
- forWaiting.Show();
- this.Refresh();
- System.IO.File.Copy(STDDBAddress, saveFile.FileName, true);
- bool result = _sTDEditor.SaveAsDictionaryToClassify(saveFile.FileName);
- if (result)
- {
- _sTDEditor.UpdateSTDDictionaryInitial();
- 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);
- }
- }
- private void rbSave_Click(object sender, EventArgs e)
- {
- if (m_STDRuleslist.tabControl1.SelectedIndex == 0)
- {
- m_STDRuleslist.ConvertToRuleViewDic();
- }
- else
- {
- if (m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row > 0)
- {
- STDdata sTDdata = (STDdata)m_STDRuleslist.Grid_Minerals[m_STDRuleslist.Grid_Minerals.Selection.ActivePosition.Row, 0].Tag;
- SaveDataOfSelRule(sTDdata.STDId);
- }
- }
- if (Ruleformatcheck())
- {
- FormForWaiting forWaiting = new FormForWaiting();
- forWaiting.Show();
- this.Refresh();
- bool result = _sTDEditor.SaveDictionaryToClassify();
- if (result)
- {
- _sTDEditor.UpdateSTDDictionaryInitial();
- forWaiting.Close();
- IsModified = false;
- MessageBox.Show("Save successful!", "Tip");
- }
- else
- {
- forWaiting.Close();
- MessageBox.Show("Save failed!", "Tip");
- }
- }
- else
- {
- return;
- }
- }
- bool Ruleformatcheck()
- {
- foreach (var ite in _sTDEditor.STDDictionary)
- {
- if (CheckExpression(ite.Value.Expression))
- {
- }
- else
- {
- int Id = 0;
- for (int i = 1; i < m_STDRuleslist.Grid_Minerals.RowsCount; i++)
- {
- if(((STDdata)m_STDRuleslist.Grid_Minerals[i, 0].Tag).STDId == ite.Key)
- {
- Id = i;break;
- }
- }
- Position pos = new Position(Id, 0);
- m_STDRuleslist.Grid_Minerals[Id, 0].Grid.Select();
- m_STDRuleslist.Grid_Minerals.Selection.Focus(pos, true);
- m_STDRuleslist.Grid_Minerals.Refresh();
- ChangeSTDEditorAndGrid_Attributes(ite.Key);
- m_STDRuleslist.Predata = ite.Value;
- 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));
- }
- //表达式规则检查
- public bool CheckExpression(string Expression)
- {
- string str_RemoveBlank = Expression.Replace(" ", "");
- if (!string.IsNullOrEmpty(str_RemoveBlank))
- {
- str_RemoveBlank = str_RemoveBlank.Replace("\r\n", "");
- //分割符号检验
- string[] Symbol = { "and", "or", "+", "-", "*", "/", "=", ">", "<" };
- for (int i = 0; i < Symbol.Length; i++)
- {
- for (int j = 0; j < Symbol.Length; j++)
- {
- if ((Symbol[i] + Symbol[j]) != ">=" && (Symbol[i] + Symbol[j]) != "<=")
- {
- if (str_RemoveBlank.Contains(Symbol[i] + Symbol[j]))
- {
- MessageBox.Show("Invalid string exists:" + Symbol[i] + Symbol[j], "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return false;
- }
- }
- }
- if (str_RemoveBlank.Contains(Symbol[i] + ")") || str_RemoveBlank.Contains("(" + Symbol[i]))
- {
- MessageBox.Show("Invalid string exists:" + Symbol[i] + ")", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return false;
- }
- if (str_RemoveBlank.Contains("(" + Symbol[i]))
- {
- MessageBox.Show("Invalid string exists:" + "(" + Symbol[i], "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return false;
- }
- //尾字符检测
- int n= Symbol[i].Length;
- if (str_RemoveBlank.Length >= n)
- {
- if (str_RemoveBlank.Substring(str_RemoveBlank.Length-n, n) == Symbol[i])
- {
- MessageBox.Show("Last character is error!", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return false;
- }
- if (str_RemoveBlank.Substring(0, n) == Symbol[i])
- {
- MessageBox.Show("First character is error!", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return false;
- }
- }
- }
- //左右括号匹配检验
- int BracketsNum = 0;
- for (int i = 0; i < str_RemoveBlank.Length; i++)
- {
- if (str_RemoveBlank[i] == '(') BracketsNum++;
- if (str_RemoveBlank[i] == ')') BracketsNum--;
- }
- if (BracketsNum != 0)
- {
- MessageBox.Show("Number of left and right parentheses does not match!", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return false;
- }
- ////首字符检测
- //if ((str_RemoveBlank[0] == '+') || (str_RemoveBlank[0] == '-') || (str_RemoveBlank[0] == '*') || (str_RemoveBlank[0] == '/') || (str_RemoveBlank[0] == '>') || (str_RemoveBlank[0] == '<') || (str_RemoveBlank[0] == '=') || (str_RemoveBlank[0] == ')') || (str_RemoveBlank[str_RemoveBlank.Length - 1] == '('))
- //{
- // MessageBox.Show("First character is error!", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
- // return false;
- //}
- //if (str_RemoveBlank.Length >= 3)
- //{
- // if ((str_RemoveBlank.Substring(0, 3) == "and") || (str_RemoveBlank.Substring(0, 3) == "end"))
- // {
- // MessageBox.Show("First character is error!", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
- // return false;
- // }
- //}
- //forth_elem干扰or分隔符,故先行去掉
- //str_RemoveBlank = str_RemoveBlank.Replace("fourth_elem", "");
- 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[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));
- }
- //常量
- List<string> Constantslist = new List<string>();
- for (int j = 0; j < m_SubMidWindow.m_STDEditor.comboBox_Constants.Items.Count; j++)
- {
- Constantslist.Add(m_SubMidWindow.m_STDEditor.comboBox_Constants.Items[j].ToString().Split('=')[0]);
- }
- for (int i = 0; i < list_all.Count; i++)
- {
- //周期元素?
- if (this.m_SubMidWindow.m_STDEditor.comboBox_PeriodicTable.Items.Contains(list_all[i]))
- {
- continue;
- }
- //first_elem?
- if (this.m_SubMidWindow.m_STDEditor.comboBox_Elem1.Items.Contains(list_all[i]))
- {
- continue;
- }
- //Element1?
- if (this.m_SubMidWindow.m_STDEditor.comboBox_Elem.Items.Contains(list_all[i]))
- {
- continue;
- }
- //其它元素?
- if (this.m_SubMidWindow.m_STDEditor.comboBox_ImgProperty.Items.Contains(list_all[i]))
- {
- continue;
- }
- //常量?
- if (Constantslist.Contains(list_all[i]))
- {
- continue;
- }
- //数字?
- double DNum = 0;
- if (double.TryParse(list_all[i], out DNum))
- {
- continue;
- }
- //>=? <=?等其它情况
- if (list_all[i] == "")
- {
- continue;
- }
- //true false?
- if ((list_all[i] == "true") || (list_all[i] == "false"))
- {
- continue;
- }
- MessageBox.Show("Please check whether the input rules are correct, error characters:" + list_all[i], "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return false;
- }
- //检测是否有<>= true,false
- if (!Expression.Contains("<") && !Expression.Contains(">") && !Expression.Contains("=") && Expression.ToLower() != "true" && Expression.ToLower() != "false")
- {
- MessageBox.Show("Expressions have no effect!", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return false;
- }
- }
- else
- {
- MessageBox.Show("The expresstion is mull!", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return false;
- }
- return true;
- }
- /// <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 stdid)
- {
- _sTDEditor.STDDictionary[stdid].StrName = Convert.ToString(m_Attributes.Grid_Attributes[2, 1].Value);
- _sTDEditor.STDDictionary[stdid].Color = colorRGBtoHx16(m_Attributes.Grid_Attributes[3, 1].View.BackColor.R, m_Attributes.Grid_Attributes[3, 1].View.BackColor.G, m_Attributes.Grid_Attributes[3, 1].View.BackColor.B);
- _sTDEditor.STDDictionary[stdid].IfElementAnalysis = Convert.ToBoolean(m_Attributes.Grid_Attributes[4, 1].Value);
- _sTDEditor.STDDictionary[stdid].Hardness = Convert.ToString(m_Attributes.Grid_Attributes[5, 1].Value);
- _sTDEditor.STDDictionary[stdid].Density = Convert.ToString(m_Attributes.Grid_Attributes[6, 1].Value);
- _sTDEditor.STDDictionary[stdid].Electrical_conductivity = Convert.ToString(m_Attributes.Grid_Attributes[7, 1].Value);
- _sTDEditor.STDDictionary[stdid].BSE = Convert.ToString(m_Attributes.Grid_Attributes[8, 1].Value);
- if (m_Attributes.Grid_Attributes[9, 1].Value != null)
- {
- _sTDEditor.STDDictionary[stdid].Formula = Convert.ToString(m_Attributes.Grid_Attributes[9, 1].Value);
- }
- else
- {
- _sTDEditor.STDDictionary[stdid].Formula = "";
- }
- if (m_Attributes.Grid_Attributes[10, 1].Value != null)
- {
- _sTDEditor.STDDictionary[stdid].Element = Convert.ToString(m_Attributes.Grid_Attributes[10, 1].Value);
- }
- else
- {
- _sTDEditor.STDDictionary[stdid].Element = "";
- }
- if (m_Attributes.Grid_Attributes[11, 1].Value != null)
- {
- _sTDEditor.STDDictionary[stdid].GroupId = _sTDEditor.GroupIdDictionaryFromName[Convert.ToString(m_Attributes.Grid_Attributes[11, 1].Value)];
- }
- else
- {
- _sTDEditor.STDDictionary[stdid].GroupId = -1;
- }
- _sTDEditor.STDDictionary[stdid].Expression = m_SubMidWindow.m_STDEditor.textbox_STDEditor.Text.ToString();
- string sKeyElements = "";
- for (int i = 0; i < m_SubMidWindow.m_STDEditor.dataGridView_KeyElements.Columns.Count; i++)
- {
- sKeyElements += m_SubMidWindow.m_STDEditor.dataGridView_KeyElements.Rows[0].Cells[i].Value.ToString() + ",";
- }
- if (sKeyElements.Length > 0)
- {
- sKeyElements = sKeyElements.Substring(0, sKeyElements.Length - 1);
- }
- string sSubElements = "";
- for (int i = 0; i < m_SubMidWindow.m_STDEditor.dataGridView_SubElements.Columns.Count; i++)
- {
- sSubElements += m_SubMidWindow.m_STDEditor.dataGridView_SubElements.Rows[0].Cells[i].Value.ToString() + ",";
- }
- if (sSubElements.Length > 0)
- {
- sSubElements = sSubElements.Substring(0, sSubElements.Length - 1);
- }
- _sTDEditor.STDDictionary[stdid].KeyElementList = sKeyElements;
- _sTDEditor.STDDictionary[stdid].SubElementList = sSubElements;
- _sTDEditor.STDDictionary[stdid].ListNum = "0";
- }
- public void RemoveSTDDictionaryItem(int STDId)
- {
- _sTDEditor.STDDictionary.Remove(STDId);
- }
- public void ChangeStrName(int RowNum, string NewStrName)
- {
- _sTDEditor.STDDictionary[((STDdata)m_STDRuleslist.Grid_Minerals[RowNum, 0].Tag).STDId].StrName = NewStrName;
- m_Attributes.Grid_Attributes[2, 1].Value = NewStrName;
- }
- public void ChangeSTDRulesLISTBackColor()
- {
- int stdid = m_STDRuleslist.ChangeSTDRulesLISTBackColor();
- }
- 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 = "";
- SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
- view.BackColor = Color.White;
- m_Attributes.Grid_Attributes[3, 1].View = view;
- 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 = "";
- }
- }
- }
- m_Attributes.Grid_Attributes.Refresh();
- m_SubMidWindow.m_STDEditor.dataGridView_KeyElements.Rows.Clear();
- m_SubMidWindow.m_STDEditor.dataGridView_KeyElements.Columns.Clear();
- m_SubMidWindow.m_STDEditor.dataGridView_SubElements.Rows.Clear();
- m_SubMidWindow.m_STDEditor.dataGridView_SubElements.Columns.Clear();
- }
- private void ribbon_ESDMaxRules_Click(object sender, EventArgs e)
- {
- Form_MaxEDSRules form_MaxEDSRules = new Form_MaxEDSRules(STDDBAddress);
- form_MaxEDSRules.Show();
- }
- private void ribbon_ZeroRules_Click(object sender, EventArgs e)
- {
- Form_ZeroElementRules form_ZeroElementRules = new Form_ZeroElementRules(STDDBAddress);
- form_ZeroElementRules.Show();
- }
- private void ribbon_UserConstants_Click(object sender, EventArgs e)
- {
- Form_UserConstants form_UserConstants = new Form_UserConstants(STDDBAddress);
- DialogResult dialogResult = form_UserConstants.ShowDialog();
- if (dialogResult == DialogResult.Yes)
- {
- try
- {
- _sTDEditor.LoadConstants();
- string[] ConstantsStr2 = _sTDEditor.ConstantsStr;
- m_SubMidWindow.m_STDEditor.comboBox_Constants.Items.Clear();
- m_SubMidWindow.m_STDEditor.comboBox_Constants.Items.AddRange(ConstantsStr2);
- }
- catch (Exception ee)
- {
- MessageBox.Show(ee.ToString());
- }
- }
- }
- private void ribbon_GroupNameMaintenance_Click(object sender, EventArgs e)
- {
- int selGroupId = _sTDEditor.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)
- {
- m_Attributes.AddSTDGroupsToAttribute();
- m_Attributes.Grid_Attributes[11, 1].Value = _sTDEditor.GroupIdDictionaryFromId[selGroupId];
- }
- }
- private void ribbon_Exit_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- private void rbClose_Click(object sender, EventArgs e)
- {
- if (!_sTDEditor.Isoldversion)
- {
- if (!EqualsBetweenDictionary() || 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() != ""))
- {
- if (m_STDRuleslist.Predata != null)
- {
- int id = m_STDRuleslist.Predata.STDId;
- SaveDataOfSelRule(id);
- }
- }
- else
- {
- return;
- }
- }
- //else
- //{
- // STDDictionaryInitial.Clear();
- //}
- FormForWaiting forWaiting = new FormForWaiting();
- forWaiting.Show();
- bool result = _sTDEditor.SaveDictionaryToClassify();
- 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
- {
- STDDBAddress = openFileDialog.FileName;
- InitForms(STDDBAddress);
- this.Text = this.Text.Split(' ')[0] + " " + STDDBAddress;
- IsModified = false;
- CheckAccuracyofZeroRules();
- }
- catch(Exception ex)
- {
- MessageBox.Show(ex.ToString(), "Tip");
- }
- }
- }
- void ButtonStatusOpen()
- {
- rbOpen.Enabled = false;
- rbClose.Enabled = true;
- //rbRecover.Enabled = true;
- rbBackup.Enabled = true;
- rbSave.Enabled = true;
- rbNew.Enabled = false;
- ribbon_ZeroRules.Enabled = true;
- ribbon_ESDMaxRules.Enabled = true;
- ribbon_UserConstants.Enabled = true;
- ribbon_GroupNameMaintenance.Enabled = false;
- }
- void ButtonStatusClose()
- {
- rbOpen.Enabled = true;
- rbClose.Enabled = false;
- //rbRecover.Enabled = false;
- rbBackup.Enabled = false;
- rbSave.Enabled = false;
- rbNew.Enabled = true;
- ribbon_ZeroRules.Enabled = false;
- ribbon_ESDMaxRules.Enabled = false;
- ribbon_UserConstants.Enabled = false;
- ribbon_GroupNameMaintenance.Enabled = false;
- }
- void InitForms(string DBAddress)
- {
- ButtonStatusOpen();
- _sTDEditor = new STDInfo(DBAddress);
- if (_sTDEditor.STDDictionary == null|| _sTDEditor.GroupDictionary==null)
- {
- 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;
- m_SubMidWindow.m_STDEditor.comboBox_Constants.Items.Clear();
- if(_sTDEditor.ConstantsStr != null)
- {
- m_SubMidWindow.m_STDEditor.comboBox_Constants.Items.AddRange(_sTDEditor.ConstantsStr);
- }
- 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(((STDdata)m_STDRuleslist.Grid_Minerals[1, 0].Tag).STDId);
- Position pos = new Position(1, 0);
- m_STDRuleslist.Grid_Minerals[1, 0].Grid.Select();
- m_STDRuleslist.Grid_Minerals.Selection.Focus(pos, true);
- }
- }
-
- private void Form_ConstantsEditor2_FormClosing(object sender, FormClosingEventArgs e)
- {
- if(_sTDEditor==null)
- {
- return;
- }
- if (_sTDEditor.Isoldversion)
- {
- return;
- }
- if (m_STDRuleslist.Text != "")
- {
- if (!EqualsBetweenDictionary() || 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() != "")
- {
- int id = m_STDRuleslist.Predata.STDId;
- SaveDataOfSelRule(id);
- }
- else
- {
- e.Cancel = true;
- return;
- }
- }
- //else
- //{
- // STDDictionaryInitial.Clear();
- //}
- FormForWaiting forWaiting = new FormForWaiting();
- forWaiting.Show();
- bool result = _sTDEditor.SaveDictionaryToClassify();
- if (result)
- {
- forWaiting.Close();
- }
- else
- {
- forWaiting.Close();
- MessageBox.Show("Save failed!", "Tip");
- }
- }
- }
- }
- }
- bool EqualsBetweenDictionary()
- {
- return _sTDEditor.EqualsBetweenDictionary();
- }
- 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 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)";
- OtsDatabaseCommand.ExecuteNonQuery();
- OtsDatabaseCommand.CommandText = "CREATE TABLE Constants (value TEXT)";
- OtsDatabaseCommand.ExecuteNonQuery();
- OtsDatabaseCommand.CommandText = "CREATE TABLE MaxEDSRules (MaxEDSTime INT,UsingElementList TEXT, UsingImgPropertyList TEXT,UsingOtherPropertyList TEXT,Expression TEXT)";
- OtsDatabaseCommand.ExecuteNonQuery();
- OtsDatabaseCommand.CommandText = "CREATE TABLE STDGroups (id INTEGER,name TEXT, color TEXT,iorder INTEGER)";
- OtsDatabaseCommand.ExecuteNonQuery();
- OtsDatabaseCommand.CommandText = "CREATE TABLE STDMinerals (id INTEGER,SPEC BLOB)";
- OtsDatabaseCommand.ExecuteNonQuery();
- OtsDatabaseCommand.CommandText = "CREATE TABLE ZeroElementRules (ZeroElement TEXT,UsingElementList TEXT, UsingImgPropertyList TEXT,UsingOtherPropertyList TEXT,Expression TEXT)";
- 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("检测到该数据库零元素规则格式错误,已进行修正!");
- }
- }
- }
- }
- }
|