123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Xml;
- using System.Xml.Linq;
- namespace OTSPartA_STDEditor
- {
- public partial class Form_MaxEDSRules : Form
- {
- //国际化
- Language lan;
- System.Collections.Hashtable table;
-
- string STDDBAddress = Application.StartupPath + "\\Config\\SysData\\" + "OTSCleanlinesSTD.db";
- //string STDDBAddress_backup = Application.StartupPath + "\\Config\\SysData\\LibBackup\\" + "OTSCleanlinesSTD_backup.db";
- string STDDBAddress_backupDirectory = Application.StartupPath + "\\Config\\SysData\\LibBackup\\";
- //元素周期表
- Form_PeriodicTable form_PeriodicTable=null;
- public Form_MaxEDSRules(string DBAddress)
- {
- InitializeComponent();
- STDDBAddress = DBAddress;
- //X = this.Width;
- //Y = this.Height;
- //setTag(this);
- }
- private void Form_MaxEDSRules_Load(object sender, EventArgs e)
- {
-
- //初始化comboBox
- this.comboBox_Elem1.Items.Add("first_elem");
- this.comboBox_Elem1.Items.Add("second_elem");
- this.comboBox_Elem1.Items.Add("third_elem");
- this.comboBox_Elem1.Items.Add("forth_elem");
- this.comboBox_Elem1.Items.Add("fifth_elem");
- this.comboBox_Elem1.Items.Add("sixth_elem");
- this.comboBox_Elem1.Items.Add("seventh_elem");
- this.comboBox_Elem1.Items.Add("eighth_elem");
- this.comboBox_Elem1.Items.Add("ninth_elem");
- this.comboBox_Elem1.Items.Add("tenth_elem");
- comboBox_Elem1.SelectedIndex = comboBox_Elem1.Items.IndexOf("first_elem");
- this.comboBox_Elem.Items.Add("Element#1");
- this.comboBox_Elem.Items.Add("Element#2");
- this.comboBox_Elem.Items.Add("Element#3");
- this.comboBox_Elem.Items.Add("Element#4");
- this.comboBox_Elem.Items.Add("Element#5");
- this.comboBox_Elem.Items.Add("Element#6");
- this.comboBox_Elem.Items.Add("Element#7");
- this.comboBox_Elem.Items.Add("Element#8");
- this.comboBox_Elem.Items.Add("Element#9");
- this.comboBox_Elem.Items.Add("Element#10");
- comboBox_Elem.SelectedIndex = comboBox_Elem.Items.IndexOf("Element#1");
- this.comboBox_ImgProperty.Items.Add("Dmax");
- this.comboBox_ImgProperty.Items.Add("Dmin");
- this.comboBox_ImgProperty.Items.Add("Aspect");
- this.comboBox_ImgProperty.Items.Add("Dperp");
- this.comboBox_ImgProperty.Items.Add("Dmean");
- this.comboBox_ImgProperty.Items.Add("Area");
- this.comboBox_ImgProperty.Items.Add("Dferet");
- this.comboBox_ImgProperty.Items.Add("With");
- this.comboBox_ImgProperty.Items.Add("Height");
- this.comboBox_ImgProperty.Items.Add("Perimeter");
- this.comboBox_ImgProperty.Items.Add("Dinscr");
- this.comboBox_ImgProperty.Items.Add("Orientation");
- this.comboBox_ImgProperty.Items.Add("Delong");
- this.comboBox_ImgProperty.Items.Add("Aspectelong");
- this.comboBox_ImgProperty.Items.Add("Dequalcircle");
- this.comboBox_ImgProperty.Items.Add("Vedio");
- comboBox_ImgProperty.SelectedIndex = comboBox_ImgProperty.Items.IndexOf("Dmax");
- 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", "Hq", "TI", "Pb", "Bi", "Po", "At", "Rn", "Fr", "Ra", "Ac", "Th", "Pa", "U", "Np", "Pu", "Am", "Cm", "Bk", "Cf", "Es", "Fm", "Mc", "No", "Lr", "Rf", "Db", "Sg", "Bh", "Hs", "Mt", "Ds", "Rg", "Unb" };
- comboBox_PeriodicTable.Items.AddRange(PeriodicTable);
- AutoCompleteStringCollection sc = new AutoCompleteStringCollection();
- sc.AddRange(PeriodicTable);
- this.comboBox_PeriodicTable.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest;
- this.comboBox_PeriodicTable.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.CustomSource;
- this.comboBox_PeriodicTable.AutoCompleteCustomSource = sc;
- LoadMaxEDSRulesToTreeControl(STDDBAddress, XmlTree_MaxEDSRules.Nodes);
- LoadConstants(STDDBAddress);
- this.textbox_STDEditor.Text = "";
- lan = new Language(this);
- table = lan.GetNameTable("Form_MaxEDSRules");
- if (table["language"].ToString() == "EN")
- {
- //panel_OTSPeriodicTable.BackgroundImage = global::OTSPartA_STDEditor.Properties.Resources.PeriodicTable_EN;
- PeriodicTableSwitch.BackgroundImage = global::OTSPartA_STDEditor.Properties.Resources.STDEditoName;
- PeriodicTableSwitch.Text = "";
- }
- else
- {
- //panel_OTSPeriodicTable.BackgroundImage = global::OTSPartA_STDEditor.Properties.Resources.PeriodicTable_ZH;
- PeriodicTableSwitch.Text = "元素周期表";
- }
- //panel_OTSPeriodicTable.Visible = true;
- //this.Width = this.Width - panel_OTSPeriodicTable.Width - 5;
- Size size = Screen.PrimaryScreen.WorkingArea.Size;
- Left = (size.Width - Width) / 2;
- Top = (size.Height - Height) / 2;
- WindowState = FormWindowState.Normal;
- //groupBox_XmlTree_MaxEDSRules.Focus();
- this.XmlTree_MaxEDSRules.HideSelection = false;//失去焦点后不隐藏选中节点
- XmlTree_MaxEDSRules.Focus();
- if (XmlTree_MaxEDSRules.Nodes.Count > 0)
- {
- XmlTree_MaxEDSRules.SelectedNode = XmlTree_MaxEDSRules.Nodes[0];
- XmlTree_MaxEDSRules_AfterSelect(XmlTree_MaxEDSRules, new TreeViewEventArgs(XmlTree_MaxEDSRules.SelectedNode));
- }
- }
-
- //XmlTree_MaxEDSRules
- void LoadXmlToTreeControl(XmlDocument xml,TreeNodeCollection XmlTree_MaxEDSRules)
- {
- XmlNode root = xml.SelectSingleNode("XMLData");
- XmlNodeList root2 = root.SelectNodes("Collection");
- for (int j = 0; j < root2.Count; j++)
- {
- if (root2[j].Attributes["RegName"].Value.ToString() == "MaxEDSRules")
- {
- XmlNodeList childlist = root2[j].ChildNodes;
- if (childlist.Count != 0)
- {
- for (int i = 0; i < childlist.Count; i++)
- {
- TreeNode new_child = new TreeNode();//定义一个TreeNode节点对象
- //new_child.Name = childlist[i].Attributes["MaxEDSTime"].Value;
- new_child.Tag = childlist[i].Attributes["Expression"].Value;
- new_child.Text = "Rule" + i.ToString();
- XmlTree_MaxEDSRules.Add(new_child);
- }
- if (childlist[0].Attributes["MaxEDSTime"] != null)
- {
- textBox_MaxEDSTime.Text = childlist[0].Attributes["MaxEDSTime"].Value;
- }
- }
- }
- }
- XmlNode root3 = root.SelectSingleNode("Member");
- string ConstantsStr = root3.Attributes["value"].Value;
- ConstantsStr = ConstantsStr.Replace(" ", "");
- string[] ConstantsStr2 = ConstantsStr.Split(',');
- this.comboBox_Constants.Items.Clear();
- this.comboBox_Constants.Items.AddRange(ConstantsStr2);
- }
- void LoadMaxEDSRulesToTreeControl(string DBAddress, TreeNodeCollection XmlTree_MaxEDSRules)
- {
- 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 MaxEDSRules", m_dbConnection);
- DataSet ds = new DataSet();
- m_dataAdapter.Fill(ds);
- DataTable dt = ds.Tables[0];
- if (dt != null)
- {
- if (dt.Rows.Count > 0)
- {
- int i = 1;
- foreach (DataRow item in dt.Rows)
- {
- TreeNode new_child = new TreeNode();//定义一个TreeNode节点对象
- new_child.Tag = item["Expression"].ToString();
- new_child.Text = "Rule" + i.ToString();
- XmlTree_MaxEDSRules.Add(new_child);
- i++;
- }
- if (dt.Rows[0]["MaxEDSTime"] != null)
- {
- textBox_MaxEDSTime.Text = dt.Rows[0]["MaxEDSTime"].ToString();
- }
- }
- }
- }
- catch (Exception ee)
- {
- MessageBox.Show(ee.ToString());
- }
- }
- void LoadConstants(string STDDBAddress)
- {
- try
- {
- 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 Constants", m_dbConnection);
- DataSet ds = new DataSet();
- m_dataAdapter.Fill(ds);
- DataTable dt = ds.Tables[0];
- string ConstantsStr = dt.Rows[0][0].ToString();
- ConstantsStr = ConstantsStr.Replace(" ", "");
- string[] ConstantsStr2 = ConstantsStr.Split(',');
- comboBox_Constants.Items.Clear();
- comboBox_Constants.Items.AddRange(ConstantsStr2);
- m_dbConnection.Close();
- }
- catch (Exception ee)
- {
- MessageBox.Show(ee.ToString());
- }
- }
- private void comboBox_Elem1_SelectedIndexChanged(object sender, EventArgs e)
- {
- string newStr = comboBox_Elem1.SelectedItem.ToString();
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + newStr.Length, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void comboBox_Elem2_SelectedIndexChanged(object sender, EventArgs e)
- {
- string newStr = comboBox_Elem.SelectedItem.ToString();
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + newStr.Length, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void comboBox_ImgProperty_SelectedIndexChanged(object sender, EventArgs e)
- {
- string newStr = comboBox_ImgProperty.SelectedItem.ToString();
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + newStr.Length, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_Plus_Click(object sender, EventArgs e)
- {
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "+");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index+1,0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_Subtract_Click(object sender, EventArgs e)
- {
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "-");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_Multiply_Click(object sender, EventArgs e)
- {
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "*");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_Divide_Click(object sender, EventArgs e)
- {
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "/");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret(); ;
- }
- private void button_More_Click(object sender, EventArgs e)
- {
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, ">");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_Less_Click(object sender, EventArgs e)
- {
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "<");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_LeftParenthesis_Click(object sender, EventArgs e)
- {
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "(");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_RightParenthesis_Click(object sender, EventArgs e)
- {
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, ")");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_Equal_Click(object sender, EventArgs e)
- {
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "=");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- //除选中点以外其它节点前景色置灰
- private void SetGrayExceptSelectedNode(TreeView Tree, TreeNode SelectedNode)
- {
- foreach (TreeNode node in Tree.Nodes)
- {
- if (node != SelectedNode)
- {
- node.ForeColor = Color.Gray;
- }
- }
- }
- //恢复所有节点颜色为可用
- private void SetBlackAllNodes(TreeView Tree)
- {
- foreach (TreeNode node in Tree.Nodes)
- {
- node.ForeColor = Color.Black;
- }
- }
- //删除
- private void DeleteTreeNode_Click(object sender, EventArgs e)
- {
- try
- {
- TreeView XmlTree = (TreeView)XmlTreeMenuStrip.SourceControl;
- if (XmlTree.SelectedNode != null)
- {
- if (XmlTree != null)
- {
- if (XmlTree.SelectedNode.NextNode != null)
- {
- TreeNode Temp = XmlTree.SelectedNode.NextNode;
- XmlTree.SelectedNode.Remove();
- XmlTree.SelectedNode = Temp;
- }
- else if (XmlTree.SelectedNode.PrevNode != null)
- {
- TreeNode Temp = XmlTree.SelectedNode.PrevNode;
- XmlTree.SelectedNode.Remove();
- XmlTree.SelectedNode = Temp;
- }
- else
- {
- XmlTree.SelectedNode.Remove();
- XmlTree.SelectedNode = null;
- if (XmlTree.Name == "XmlTree_MaxEDSRules")
- {
- textbox_STDEditor.Text = "";
- textBox_MaxEDSTime.Text = "";
- }
- }
- }
- }
- else
- {
- MessageBox.Show(table["message1"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.ToString(), table["message32"].ToString());
- }
- }
- //新建
- private void AddTreeNode_Click(object sender, EventArgs e)
- {
- try
- {
- if (XmlTree_MaxEDSRules.SelectedNode != null)
- {
- //判断MaxEDSTime
- double dMaxEDSTime = 0;
- if (!double.TryParse(textBox_MaxEDSTime.Text, out dMaxEDSTime) || double.Parse(textBox_MaxEDSTime.Text) <= 0)
- {
- MessageBox.Show(table["message8"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- //判断textbox_STDEditor
- if (!Checktextbox_STDEditor())
- {
- return;
- }
- XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
- }
- TreeNode new_child = new TreeNode();//定义一个TreeNode节点对象
- TreeView XmlTree = (TreeView)XmlTreeMenuStrip.SourceControl;
-
- if (XmlTreeMenuStrip.SourceControl.Name == "XmlTree_MaxEDSRules")
- {
- int Number = XmlTree.Nodes.Count;
- for (int num = 0; num < XmlTree.Nodes.Count; num++)
- {
- string aa = XmlTree.Nodes[num].Text.ToString().Substring(XmlTree.Nodes[num].Text.Length - 1, 1);
- int tp = int.Parse(XmlTree.Nodes[num].Text.ToString().Substring(XmlTree.Nodes[num].Text.Length - 1, 1));
- if (Number < tp) Number = tp;
- }
- new_child.Text = "Rule" + Number.ToString();
- new_child.Tag = "NewRules";
- textbox_STDEditor.Text = "NewRules";
- }
-
- XmlTree.Nodes.Add(new_child);
- XmlTree.SelectedNode = null;
- XmlTree.SelectedNode = new_child;
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.ToString(), table["message32"].ToString());
- }
- }
- void SaveXmlTreeDataToMaxEDSRules(string DBAddress)
- {
- 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 MaxEDSRules";
- try
- {
- cmm.ExecuteNonQuery();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.ToString());
- }
- System.Data.SQLite.SQLiteDataAdapter m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select * from MaxEDSRules", m_dbConnection);
- System.Data.SQLite.SQLiteCommandBuilder qLiteCommandBuilder = new System.Data.SQLite.SQLiteCommandBuilder(m_dataAdapter);
- DataSet ds = new DataSet();
- m_dataAdapter.Fill(ds, "MaxEDSRules");
- DataTable dt = ds.Tables["MaxEDSRules"];
- dt.Clear();
- for (int num = 0; num < XmlTree_MaxEDSRules.Nodes.Count; num++)
- {
- 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 = "";
- //forth_elem干扰or分隔符,故先行去掉
- if (XmlTree_MaxEDSRules.Nodes[num].Tag.ToString().Contains("forth_elem"))
- {
- str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
- UsingOtherPropertyList = "forth_elem,";
- }
- str_RemoveBlank = XmlTree_MaxEDSRules.Nodes[num].Tag.ToString().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 (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))
- {
- if (!UsingElementL.Contains(list_all[i]))
- {
- UsingElementL.Add(list_all[i]);
- }
- }
- //first_elem?
- if (this.comboBox_Elem1.Items.Contains(list_all[i]))
- {
- if (!UsingOtherPropertyL.Contains(list_all[i]))
- {
- UsingOtherPropertyL.Add(list_all[i]);
- }
- }
- //Element1?
- if (this.comboBox_Elem.Items.Contains(list_all[i]))
- {
- if (!UsingOtherPropertyL.Contains(list_all[i]))
- {
- UsingOtherPropertyL.Add(list_all[i]);
- }
- }
- //其它元素?
- if (this.comboBox_ImgProperty.Items.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["MaxEDSTime"] = int.Parse(textBox_MaxEDSTime.Text);
- newRow["UsingElementList"] = UsingElementList;
- newRow["UsingImgPropertyList"] = UsingImgPropertyList;
- newRow["UsingOtherPropertyList"] = UsingOtherPropertyList;
- newRow["Expression"] = XmlTree_MaxEDSRules.Nodes[num].Tag;
- dt.Rows.Add(newRow);
- }
- m_dataAdapter.Update(ds, "MaxEDSRules");
- m_dbConnection.Close();
- MessageBox.Show(table["message2"].ToString(), table["message32"].ToString());
- }
- //元素周期表开关
- private void PeriodicTableSwitch_Click(object sender, EventArgs e)
- {
- //if (PeriodicTableSwitch.BackColor == SystemColors.Control)
- //{
- // //this.Resize -= new System.EventHandler(this.Form_MaxEDSRules_Resize);
- // panel_OTSPeriodicTable.Visible = false;
- // this.Width = this.Width - panel_OTSPeriodicTable.Width;
- // //this.Resize += new System.EventHandler(this.Form_MaxEDSRules_Resize);
- // PeriodicTableSwitch.BackColor = SystemColors.ControlDark;
- // //if (Language == "English")
- // //{
- // // PeriodicTableSwitch.Text = "Close PeriodicTable";
- // //}
- // //else if(Language == "Chinese")
- // //{
- // // PeriodicTableSwitch.Text = "关闭元素周期表";
- // //}
- //}
- //else if (PeriodicTableSwitch.BackColor == SystemColors.ControlDark)
- //{
- // //this.Resize -= new System.EventHandler(this.Form_MaxEDSRules_Resize);
- // //this.Width = this.Width + panel_OTSPeriodicTable.Width + 5;
- // panel_OTSPeriodicTable.Visible = true;
- // //this.Resize += new System.EventHandler(this.Form_MaxEDSRules_Resize);
- // PeriodicTableSwitch.BackColor = SystemColors.Control;
- // //if (Language == "English")
- // //{
- // // PeriodicTableSwitch.Text = "Open PeriodicTable";
- // //}
- // //else if (Language == "Chinese")
- // //{
- // // PeriodicTableSwitch.Text = "打开元素周期表";
- // //}
- // //textbox_STDEditor.Focus();
- // groupBox_CalculatingSymbols.Focus();
- //}
- if (form_PeriodicTable == null)
- {
- form_PeriodicTable = new Form_PeriodicTable();
- form_PeriodicTable.Show();
- form_PeriodicTable.Location = new Point(this.Location.X + this.Width - 14, this.Location.Y);
- }
- else
- {
- if (form_PeriodicTable.IsDisposed)
- {
- form_PeriodicTable = new Form_PeriodicTable();
- form_PeriodicTable.Show();
- form_PeriodicTable.Location = new Point(this.Location.X + this.Width - 14, this.Location.Y);
- }
- else
- {
- form_PeriodicTable.Activate();
- }
- }
- }
- private void button_Ok_Click(object sender, EventArgs e)
- {
- if (XmlTree_MaxEDSRules.SelectedNode != null)
- {
- //判断MaxEDSTime
- double dMaxEDSTime = 0;
- if (!double.TryParse(textBox_MaxEDSTime.Text, out dMaxEDSTime) || double.Parse(textBox_MaxEDSTime.Text) <= 0)
- {
- textBox_MaxEDSTime.Focus();
- textBox_MaxEDSTime.SelectAll();
- MessageBox.Show(table["message16"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- //判断textbox_STDEditor
- if (!Checktextbox_STDEditor())
- {
- return;
- }
- XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
- //XmlTree_MaxEDSRules.SelectedNode.Name = textBox_MaxEDSTime.Text;
- }
- SaveXmlTreeDataToMaxEDSRules(STDDBAddress);
- this.Close();
- }
- private void button_Cancel_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- //元素下拉选择输入
- private void comboBox_PeriodicTable_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (comboBox_PeriodicTable.Text != null && comboBox_PeriodicTable.SelectedItem != null)
- {
- string newStr = comboBox_PeriodicTable.SelectedItem.ToString();
- comboBox_PeriodicTable.Text = null;
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + newStr.Length, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- }
- //元素自身text按回车键输入
- private void comboBox_PeriodicTable_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyValue == 13)
- {
- if (comboBox_PeriodicTable.Text != null && comboBox_PeriodicTable.Text != "")
- {
- this.textbox_STDEditor.Text += comboBox_PeriodicTable.Text.ToString();
- comboBox_PeriodicTable.Text = null;
- }
- }
- }
- //表达式规则检查
- private bool Checktextbox_STDEditor()
- {
- if (textbox_STDEditor.Text == "" || textbox_STDEditor.Text == null)
- {
- textBox_MaxEDSTime.Focus();
- MessageBox.Show(table["message17"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return false;
- }
- string str_RemoveBlank = textbox_STDEditor.Text.ToString().Replace(" ", "");
- 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(table["message18"].ToString() + Symbol[i] + Symbol[j], table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return false;
- }
- }
- }
- if (str_RemoveBlank.Contains(Symbol[i] + ")") || str_RemoveBlank.Contains("(" + Symbol[i]))
- {
- MessageBox.Show(table["message18"].ToString() + Symbol[i] + ")", table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return false;
- }
- if (str_RemoveBlank.Contains("(" + Symbol[i]))
- {
- MessageBox.Show(table["message18"].ToString() + "(" + Symbol[i], table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return false;
- }
- }
- if ((str_RemoveBlank != null) && (str_RemoveBlank != ""))
- {
- //左右括号匹配检验
- 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(table["message19"].ToString(),table["message32"].ToString(),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(table["message20"].ToString(), table["message32"].ToString(), 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(table["message20"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return false;
- }
- }
- }
- //forth_elem干扰or分隔符,故先行去掉
- str_RemoveBlank = str_RemoveBlank.Replace("forth_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 < comboBox_Constants.Items.Count; j++)
- {
- Constantslist.Add(comboBox_Constants.Items[j].ToString().Split('=')[0]);
- }
- for (int i = 0; i < list_all.Count; i++)
- {
- //周期元素?
- if (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))
- {
- continue;
- }
- //first_elem?
- if (this.comboBox_Elem1.Items.Contains(list_all[i]))
- {
- continue;
- }
- //Element1?
- if (this.comboBox_Elem.Items.Contains(list_all[i]))
- {
- continue;
- }
- //其它元素?
- if (this.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(table["message21"].ToString() + list_all[i], table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return false;
- }
- //检测是否有<>= true,false
- if (!textbox_STDEditor.Text.ToString().Contains("<") && !textbox_STDEditor.Text.ToString().Contains(">") && !textbox_STDEditor.Text.ToString().Contains("=")&& textbox_STDEditor.Text.ToString()!="true"&& textbox_STDEditor.Text.ToString() != "false")
- {
- MessageBox.Show(table["message22"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- return false;
- }
- return true;
- }
-
- private void button_And_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "and");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 3, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_Or_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "or");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 2, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void comboBox_Constants_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (comboBox_Constants.SelectedItem != null)
- {
-
- string newStr = comboBox_Constants.SelectedItem.ToString().Split('=')[0];
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + newStr.Length, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- }
- private void button_Recover_Click(object sender, EventArgs e)
- {
- XmlDocument doc = new XmlDocument();
- try
- {
- //System.IO.File.Copy(Address_backup, Address, true);
- //doc.Load(Address_backup);
- //LoadXmlToTreeControl(doc, XmlTree_MaxEDSRules.Nodes);
- XmlTree_MaxEDSRules.Nodes.Clear();
- string STDDBAddress_backup = "";
- string[] files = System.IO.Directory.GetFiles(STDDBAddress_backupDirectory);//得到文件
- foreach (var file in files)
- {
- if (".db".IndexOf(file.Substring(file.LastIndexOf(".") + 1)) > -1)
- {
- STDDBAddress_backup = file;
- }
- }
- LoadMaxEDSRulesToTreeControl(STDDBAddress_backup, XmlTree_MaxEDSRules.Nodes);
- XmlTree_MaxEDSRules.Focus();
- if (XmlTree_MaxEDSRules.Nodes.Count > 0)
- {
- XmlTree_MaxEDSRules.SelectedNode = XmlTree_MaxEDSRules.Nodes[0];
- XmlTree_MaxEDSRules_AfterSelect(XmlTree_MaxEDSRules, new TreeViewEventArgs(XmlTree_MaxEDSRules.SelectedNode));
- }
- else
- {
- textbox_STDEditor.Text = "";
- textBox_MaxEDSTime.Text = "";
- }
- }
- catch(Exception ex)
- {
- MessageBox.Show(table["message26"].ToString() + "\n"+ex.Message.ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- private bool CheckConstants(string ConstantName)
- {
-
- for (int num = 0; num < XmlTree_MaxEDSRules.Nodes.Count; num++)
- {
- if (XmlTree_MaxEDSRules.Nodes[num].Tag.ToString().Contains(ConstantName))
- {
- XmlTree_MaxEDSRules.SelectedNode = XmlTree_MaxEDSRules.Nodes[num];
- SetGrayExceptSelectedNode(XmlTree_MaxEDSRules, XmlTree_MaxEDSRules.SelectedNode);
- DialogResult result = MessageBox.Show(table["message27"].ToString() + XmlTree_MaxEDSRules.Nodes[num].Text + table["message28"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- }
-
- return true;
- }
- private void XmlTree_MaxEDSRules_AfterSelect(object sender, TreeViewEventArgs e)
- {
- SetBlackAllNodes(XmlTree_MaxEDSRules);
- this.textbox_STDEditor.Text = XmlTree_MaxEDSRules.SelectedNode.Tag.ToString();
- }
- private void XmlTree_MaxEDSRules_BeforeSelect(object sender, TreeViewCancelEventArgs e)
- {
- if (XmlTree_MaxEDSRules.SelectedNode != null)
- {
- if (!Checktextbox_STDEditor())
- {
- SetGrayExceptSelectedNode(XmlTree_MaxEDSRules, XmlTree_MaxEDSRules.SelectedNode);
- e.Cancel = true;
- return;
- }
- XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
- }
- }
- private void textbox_STDEditor_Leave(object sender, EventArgs e)
- {
- XmlTree_MaxEDSRules.Focus();
- }
-
- #region 为配合textbox_STDEditor_Leave时事件,点击其它groupbox组件时使焦点转移
- private void Form_ConstantsEditor_Click(object sender, EventArgs e)
- {
- groupBox_XmlTree_MaxEDSRules.Focus();
- }
- private void groupBox_Data_Click(object sender, EventArgs e)
- {
- groupBox_Data.Focus();
- }
- private void groupBox_ChemicalElement_Click(object sender, EventArgs e)
- {
- groupBox_ChemicalElement.Focus();
- }
- private void groupBox_OtherCommonlyUsedSymbols_Click(object sender, EventArgs e)
- {
- groupBox_OtherCommonlyUsedSymbols.Focus();
- }
- private void groupBox_CalculatingSymbols_Click(object sender, EventArgs e)
- {
- groupBox_CalculatingSymbols.Focus();
- }
- private void groupBox_XmlTree_MaxEDSRules_Click(object sender, EventArgs e)
- {
- groupBox_XmlTree_MaxEDSRules.Focus();
- }
- #endregion
- private void button_1_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "1");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_2_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "2");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_3_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "3");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_4_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "4");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_5_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "5");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_6_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "6");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_7_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "7");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_8_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "8");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_9_Click(object sender, EventArgs e)
- {
- //textbox_STDEditor 中的光标
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "9");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private void button_0_Click(object sender, EventArgs e)
- {
- int index = textbox_STDEditor.SelectionStart;
- textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "0");
- textbox_STDEditor.Focus();
- textbox_STDEditor.Select(index + 1, 0);
- textbox_STDEditor.ScrollToCaret();
- }
- private float X = 1;
- private float Y = 1;
- float AmplificationFactor = 1;
- private void Form_MaxEDSRules_Resize(object sender, EventArgs e)
- {
- //float newx = this.Width / X;
- //float newy = this.Height / Y;
- //AmplificationFactor = newy;
- //setControls(newx, newy, this);
- //this.Resize -= new System.EventHandler(this.Form_MaxEDSRules_Resize);
- //if (panel_OTSPeriodicTable.Visible == false)
- //{
- // int w = this.Width - panel_OTSPeriodicTable.Width;
- // this.Width = w;
- //}
- //this.Resize += new System.EventHandler(this.Form_MaxEDSRules_Resize);
- ////if (WindowState == FormWindowState.Maximized)
- ////{
- //// panel_OTSPeriodicTable.Visible = true;
- //// PeriodicTableSwitch.Enabled = false;
- ////}
- }
- private void setTag(Control cons)
- {
- foreach (Control con in cons.Controls)
- {
- con.Tag = con.Width + ":" + con.Height + ":" + con.Left + ":" + con.Top + ":" + con.Font.Size;
- if (con.Controls.Count > 0)
- setTag(con);
- }
- }
- private void setControls(float newx, float newy, Control cons)
- {
- foreach (Control con in cons.Controls)
- {
- if (false)
- {
- }
- else
- {
- string[] mytag = con.Tag.ToString().Split(':');
- float a = Convert.ToSingle(mytag[0]) * newx;
- con.Width = (int)a;
- a = Convert.ToSingle(mytag[1]) * newy;
- con.Height = (int)(a);
- a = Convert.ToSingle(mytag[2]) * newx;
- con.Left = (int)(a);
- a = Convert.ToSingle(mytag[3]) * newy;
- con.Top = (int)(a);
- Single currentSize;
- if (con.GetType().ToString() == "System.Windows.Forms.Label")
- {
- currentSize = Convert.ToSingle(mytag[4]) * ((newx + newy) / 2);
- //currentSize = 6f;
- }
- else
- {
- if (Math.Max(newx, newy) < 1)
- {
- currentSize = Convert.ToSingle(mytag[4]) * 1;
- }
- else
- {
- currentSize = Convert.ToSingle(mytag[4]) * Math.Max(newx, newy);
- }
- }
- con.Font = new Font(con.Font.Name, currentSize, con.Font.Style, con.Font.Unit);
- if (con.Controls.Count > 0)
- {
- setControls(newx, newy, con);
- }
- }
- }
- }
- #region
- //XmlDocument doc = new XmlDocument();
- //doc.Load(Address);
- //LoadXmlToTreeControl(doc,XmlTree_MaxEDSRules.Nodes);
- //public string Language = "English";
- //string Address_backup = Application.StartupPath + "\\Config\\SysData\\OTSParticleSTD_backup.xml";
- //string Address = Application.StartupPath + "\\Config\\SysData\\OTSParticleSTD.xml";
- //保存xmltree内容到xml文件
- //void SaveXmlTreeDataToXml(string Address)
- //{
- // XDocument xdoc = XDocument.Load(Address);
- // IEnumerable<XElement> elements = from ele in xdoc.Descendants("XMLData") select ele;
- // var item = (from ele1 in elements.Elements("Collection")
- // where ele1.Attribute("RegName").Value.Equals("MaxEDSRules")
- // select ele1).FirstOrDefault();
- // if (item != null)
- // {
- // item.Remove();
- // }
- // XElement MaxEDS = new XElement("Collection");
- // MaxEDS.SetAttributeValue("RegName", "MaxEDSRules");
- // elements.ElementAt(0).Add(MaxEDS);
- // for (int num = 0; num < XmlTree_MaxEDSRules.Nodes.Count; num++)
- // {
- // 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 = "";
- // //forth_elem干扰or分隔符,故先行去掉
- // if (XmlTree_MaxEDSRules.Nodes[num].Tag.ToString().Contains("forth_elem"))
- // {
- // str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
- // UsingOtherPropertyList = "forth_elem,";
- // }
- // str_RemoveBlank = XmlTree_MaxEDSRules.Nodes[num].Tag.ToString().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 (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))
- // {
- // if (!UsingElementL.Contains(list_all[i]))
- // {
- // UsingElementL.Add(list_all[i]);
- // }
- // }
- // //first_elem?
- // if (this.comboBox_Elem1.Items.Contains(list_all[i]))
- // {
- // if (!UsingOtherPropertyL.Contains(list_all[i]))
- // {
- // UsingOtherPropertyL.Add(list_all[i]);
- // }
- // }
- // //Element1?
- // if (this.comboBox_Elem.Items.Contains(list_all[i]))
- // {
- // if (!UsingOtherPropertyL.Contains(list_all[i]))
- // {
- // UsingOtherPropertyL.Add(list_all[i]);
- // }
- // }
- // //其它元素?
- // if (this.comboBox_ImgProperty.Items.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];
- // }
- // XElement EleName = new XElement("Member");
- // //EleName.SetAttributeValue("MaxEDSTime", XmlTree_MaxEDSRules.Nodes[num].Name);
- // EleName.SetAttributeValue("MaxEDSTime", textBox_MaxEDSTime.Text);
- // EleName.SetAttributeValue("UsingElementList", UsingElementList);
- // EleName.SetAttributeValue("UsingImgPropertyList", UsingImgPropertyList);
- // EleName.SetAttributeValue("UsingOtherPropertyList", UsingOtherPropertyList);
- // EleName.SetAttributeValue("Expression", XmlTree_MaxEDSRules.Nodes[num].Tag);
- // MaxEDS.Add(EleName);
- // }
- // xdoc.Save(Address);
- //}
- //private void button_Backup_Click(object sender, EventArgs e)
- //{
- // if (XmlTree_MaxEDSRules.SelectedNode != null)
- // {
- // //判断MaxEDSTime
- // double dMaxEDSTime = 0;
- // if (!double.TryParse(textBox_MaxEDSTime.Text, out dMaxEDSTime) || double.Parse(textBox_MaxEDSTime.Text) <= 0)
- // {
- // textBox_MaxEDSTime.Focus();
- // textBox_MaxEDSTime.SelectAll();
- // MessageBox.Show(table["message16"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- // return;
- // }
- // //判断textbox_STDEditor
- // if (!Checktextbox_STDEditor())
- // {
- // return;
- // }
- // XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
- // //XmlTree_MaxEDSRules.SelectedNode.Name = textBox_MaxEDSTime.Text;
- // }
- // try
- // {
- // SaveFileDialog saveFile = new SaveFileDialog();
- // saveFile.Title = table["message23"].ToString();
- // saveFile.Filter = table["message24"].ToString();
- // saveFile.OverwritePrompt = true; //是否覆盖当前文件
- // saveFile.RestoreDirectory = true; //还原上次目录
- // if (saveFile.ShowDialog() == DialogResult.OK)
- // {
- // System.IO.File.Copy(Address, saveFile.FileName, true);
- // SaveXmlTreeDataToXml(saveFile.FileName);
- // MessageBox.Show(table["message25"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- // }
- // else
- // {
- // return;
- // }
- // }
- // catch (Exception ex)
- // {
- // MessageBox.Show(ex.Message);
- // }
- //}
- #endregion
- private void Form_MaxEDSRules_FormClosing(object sender, FormClosingEventArgs e)
- {
- if (form_PeriodicTable != null)
- {
- form_PeriodicTable.Close();
- }
- }
- }
- }
|