12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436 |
- 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_ZeroElementRules : 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_ZeroElementRules(string DBAddress)
- {
- InitializeComponent();
- STDDBAddress = DBAddress;
- X = this.Width;
- Y = this.Height;
- setTag(this);
- }
- private void Form_ZeroElementRules_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;
- LoadZeroElementRulesToTreeControl(STDDBAddress, XmlTree_ZeroElementRules.Nodes);
- LoadConstants(STDDBAddress);
- this.textbox_STDEditor.Text = "";
- lan = new Language(this);
- table = lan.GetNameTable("Form_ZeroElementRules");
- 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 = "元素周期表";
- }
-
- Size size = Screen.PrimaryScreen.WorkingArea.Size;
- Left = (size.Width - Width) / 2;
- Top = (size.Height - Height) / 2;
- WindowState = FormWindowState.Normal;
-
- //panel_OTSPeriodicTable.Visible = true;
- //this.Width = this.Width - panel_OTSPeriodicTable.Width - 5;
- this.XmlTree_ZeroElementRules.HideSelection = false;//失去焦点后不隐藏选中节点
- XmlTree_ZeroElementRules.Focus();
- if (XmlTree_ZeroElementRules.Nodes.Count > 0)
- {
- XmlTree_ZeroElementRules.SelectedNode = XmlTree_ZeroElementRules.Nodes[0];
- XmlTree_ZeroElementRules_AfterSelect(XmlTree_ZeroElementRules, new TreeViewEventArgs(XmlTree_ZeroElementRules.SelectedNode));
- }
-
- }
-
- void LoadZeroElementRulesToTreeControl(string DBAddress, TreeNodeCollection XmlTree_ZeroElementRules)
- {
- 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 ZeroElementRules", m_dbConnection);
- DataSet ds = new DataSet();
- m_dataAdapter.Fill(ds);
- DataTable dt = ds.Tables[0];
- if (dt != null)
- {
- if (dt.Rows.Count > 0)
- {
- foreach (DataRow item in dt.Rows)
- {
- TreeNode new_child = new TreeNode();//定义一个TreeNode节点对象
- new_child.Text = item["ZeroElement"].ToString() + "=0";
- new_child.Tag = item["Expression"];
- XmlTree_ZeroElementRules.Add(new_child);
- }
- }
- }
- }
- 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 = "";
- if (dt.Rows.Count > 0)
- {
- 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)
- {
- //textbox_STDEditor 中的光标
- 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)
- {
- //textbox_STDEditor 中的光标
- 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)
- {
- //textbox_STDEditor 中的光标
- 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)
- {
- //textbox_STDEditor 中的光标
- 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)
- {
- //textbox_STDEditor 中的光标
- 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)
- {
- //textbox_STDEditor 中的光标
- 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)
- {
- //textbox_STDEditor 中的光标
- 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)
- {
- //textbox_STDEditor 中的光标
- 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)
- {
- //textbox_STDEditor 中的光标
- 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;
- }
- }
- }
- else
- {
- MessageBox.Show("No nodes are selected!", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.ToString(), "Tip");
- }
- }
- //新建
- private void AddTreeNode_Click(object sender, EventArgs e)
- {
- try
- {
- if (XmlTree_ZeroElementRules.SelectedNode != null)
- {
- if (XmlTree_ZeroElementRules.SelectedNode.Text.Contains("="))
- {
- if (!comboBox_PeriodicTable.Items.Contains(XmlTree_ZeroElementRules.SelectedNode.Text.Split('=')[0]))
- {
- MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + "Item,It`s format of name is error, The correct format is : element name =0", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- }
- else
- {
- MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + "Item,It`s format of name is error, The correct format is : element name =0", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- //判断textbox_STDEditor
- if (!Checktextbox_STDEditor())
- {
- return;
- }
- XmlTree_ZeroElementRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
- }
- TreeNode new_child = new TreeNode();//定义一个TreeNode节点对象
- TreeView XmlTree = (TreeView)XmlTreeMenuStrip.SourceControl;
- if (XmlTreeMenuStrip.SourceControl.Name == "XmlTree_ZeroElementRules")
- {
- new_child.Text = "NewElement=0";
- 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(), "Tip");
- }
- }
-
- void SaveXmlTreeDataToZeroElementRules(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 ZeroElementRules";
- try
- {
- cmm.ExecuteNonQuery();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.ToString());
- }
- System.Data.SQLite.SQLiteDataAdapter m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select * from ZeroElementRules", m_dbConnection);
- System.Data.SQLite.SQLiteCommandBuilder qLiteCommandBuilder = new System.Data.SQLite.SQLiteCommandBuilder(m_dataAdapter);
- DataSet ds = new DataSet();
- m_dataAdapter.Fill(ds, "ZeroElementRules");
- DataTable dt = ds.Tables["ZeroElementRules"];
- dt.Clear();
- for (int num = 0; num < XmlTree_ZeroElementRules.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_ZeroElementRules.Nodes[num].Tag.ToString().Contains("forth_elem"))
- {
- str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
- UsingOtherPropertyList = "forth_elem,";
- }
- str_RemoveBlank = XmlTree_ZeroElementRules.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["ZeroElement"] = XmlTree_ZeroElementRules.Nodes[num].Text.Split('=')[0];
- newRow["UsingElementList"] = UsingElementList;
- newRow["UsingImgPropertyList"] = UsingImgPropertyList;
- newRow["UsingOtherPropertyList"] = UsingOtherPropertyList;
- newRow["Expression"] = XmlTree_ZeroElementRules.Nodes[num].Tag;
- dt.Rows.Add(newRow);
- }
- m_dataAdapter.Update(ds, "ZeroElementRules");
- m_dbConnection.Close();
- MessageBox.Show("Save successful!", "Tip");
- }
- //元素周期表开关
- private void PeriodicTableSwitch_Click(object sender, EventArgs e)
- {
- //if (PeriodicTableSwitch.BackColor == SystemColors.Control)
- //{
- // ////this.Resize -= new System.EventHandler(this.Form_ZeroElementRules_Resize);
- // //panel_OTSPeriodicTable.Visible = false;
- // //this.Width = this.Width - panel_OTSPeriodicTable.Width;
- // ////this.Resize += new System.EventHandler(this.Form_ZeroElementRules_Resize);
- // //PeriodicTableSwitch.BackColor = SystemColors.ControlDark;
- // ////if (Language == "English")
- // ////{
- // //// PeriodicTableSwitch.Text = "Close PeriodicTable";
- // ////}
- // ////else if(Language == "Chinese")
- // ////{
- // //// PeriodicTableSwitch.Text = "关闭元素周期表";
- // ////}
- // 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();
- // }
- // }
- //}
- //else if (PeriodicTableSwitch.BackColor == SystemColors.ControlDark)
- //{
- // //this.Resize -= new System.EventHandler(this.Form_ZeroElementRules_Resize);
- // //this.Width = this.Width + panel_OTSPeriodicTable.Width + 5;
- // panel_OTSPeriodicTable.Visible = true;
- // //this.Resize += new System.EventHandler(this.Form_ZeroElementRules_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_ZeroElementRules.SelectedNode != null)
- {
- if (XmlTree_ZeroElementRules.SelectedNode.Text.Contains("="))
- {
- if (!comboBox_PeriodicTable.Items.Contains(XmlTree_ZeroElementRules.SelectedNode.Text.Split('=')[0]))
- {
- MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + "Item,It`s format of name is error, The correct format is : element name =0", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- }
- else
- {
- MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + "Item,It`s format of name is error, The correct format is : element name =0", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- //判断textbox_STDEditor
- if (!Checktextbox_STDEditor())
- {
- return;
- }
- XmlTree_ZeroElementRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
- }
- //SaveXmlTreeDataToXml(Address);
- SaveXmlTreeDataToZeroElementRules(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_STDEditor.Focus();
- MessageBox.Show("The content of Standard library cannot be empty!", "Tip", 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("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;
- }
- }
- 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("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("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("Please check whether the input rules are correct, error characters:" + list_all[i], "Tip", 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("Expressions have no effect!", "Tip", 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);
- XmlTree_ZeroElementRules.Nodes.Clear();
- //LoadXmlToTreeControl(doc,XmlTree_ZeroElementRules.Nodes);
- 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;
- }
- }
- LoadZeroElementRulesToTreeControl(STDDBAddress_backup, XmlTree_ZeroElementRules.Nodes);
- XmlTree_ZeroElementRules.Focus();
- if (XmlTree_ZeroElementRules.Nodes.Count > 0)
- {
- XmlTree_ZeroElementRules.SelectedNode = XmlTree_ZeroElementRules.Nodes[0];
- XmlTree_ZeroElementRules_AfterSelect(XmlTree_ZeroElementRules, new TreeViewEventArgs(XmlTree_ZeroElementRules.SelectedNode));
- }
- else
- {
- textbox_STDEditor.Text = "";
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show("Recovery failed!" + "\n" + ex.Message.ToString(), "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- private void XmlTree_ZeroElementRules_MouseDoubleClick(object sender, MouseEventArgs e)
- {
- if (e.Button == MouseButtons.Left)
- {
- Point ClickPoint = new Point(e.X, e.Y);
- TreeNode CurrentNode = XmlTree_ZeroElementRules.GetNodeAt(ClickPoint);
- if (CurrentNode != null)//判断你点的是不是一个节点
- {
- XmlTree_ZeroElementRules.SelectedNode = CurrentNode;//选中这个节点
- //this.textbox_STDEditor.Text = XmlTree_ZeroElementRules.SelectedNode.Tag.ToString();
- XmlTree_ZeroElementRules.LabelEdit = true;
- XmlTree_ZeroElementRules.SelectedNode.BeginEdit();
- }
- }
- }
- private bool CheckConstants(string ConstantName)
- {
- for (int num = 0; num < XmlTree_ZeroElementRules.Nodes.Count; num++)
- {
- if (XmlTree_ZeroElementRules.Nodes[num].Tag.ToString().Contains(ConstantName))
- {
- XmlTree_ZeroElementRules.SelectedNode = XmlTree_ZeroElementRules.Nodes[num];
- SetGrayExceptSelectedNode(XmlTree_ZeroElementRules, XmlTree_ZeroElementRules.SelectedNode);
- DialogResult result = MessageBox.Show("Closing failed," + XmlTree_ZeroElementRules.Nodes[num].Text + "Item ,it`s rule input contains this constant!", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- }
- return true;
- }
- private void XmlTree_ZeroElementRules_BeforeSelect(object sender, TreeViewCancelEventArgs e)
- {
- if (XmlTree_ZeroElementRules.SelectedNode != null)
- {
- if (XmlTree_ZeroElementRules.SelectedNode.Text.Contains("="))
- {
- if (!comboBox_PeriodicTable.Items.Contains(XmlTree_ZeroElementRules.SelectedNode.Text.Split('=')[0]))
- {
- MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + "Item,It`s format of name is error, The correct format is : element name =0", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
- SetGrayExceptSelectedNode(XmlTree_ZeroElementRules, XmlTree_ZeroElementRules.SelectedNode);
- e.Cancel = true;
- return;
- }
- }
- else
- {
- MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + "Item,It`s format of name is error, The correct format is : element name =0", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
- SetGrayExceptSelectedNode(XmlTree_ZeroElementRules, XmlTree_ZeroElementRules.SelectedNode);
- e.Cancel = true;
- return;
- }
- if (!Checktextbox_STDEditor())
- {
- SetGrayExceptSelectedNode(XmlTree_ZeroElementRules, XmlTree_ZeroElementRules.SelectedNode);
- e.Cancel = true;
- return;
- }
- XmlTree_ZeroElementRules.SelectedNode.Tag = this.textbox_STDEditor.Text;
- }
- }
- private void XmlTree_ZeroElementRules_AfterSelect(object sender, TreeViewEventArgs e)
- {
- SetBlackAllNodes(XmlTree_ZeroElementRules);
- this.textbox_STDEditor.Text = XmlTree_ZeroElementRules.SelectedNode.Tag.ToString();
- }
- private void textbox_STDEditor_Leave(object sender, EventArgs e)
- {
- XmlTree_ZeroElementRules.Focus();
- }
- #region 为配合textbox_STDEditor_Leave时事件,点击其它groupbox组件时使焦点转移
- private void Form_ConstantsEditor_Click(object sender, EventArgs e)
- {
- groupBox_CalculatingSymbols.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();
- }
- #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_ZeroElementRules_Resize(object sender, EventArgs e)
- {
- }
- 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(con.Name== "Form_ZeroElementRules")
- {
- continue;
- }
- 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
- //string Address_backup = Application.StartupPath + "\\Config\\SysData\\OTSParticleSTD_backup.xml";
- //string Address = Application.StartupPath + "\\Config\\SysData\\OTSParticleSTD.xml";
- //private void Form_ZeroElementRules_Load(object sender, EventArgs e)
- //{
- // XmlDocument doc = new XmlDocument();
- // doc.Load(Address);
- // LoadXmlToTreeControl(doc, XmlTree_ZeroElementRules.Nodes);
- //}
- //保存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("ZeroElementRules")
- // select ele1).FirstOrDefault();
- // if (item != null)
- // {
- // item.Remove();
- // }
- // XElement ZeroElement = new XElement("Collection");
- // ZeroElement.SetAttributeValue("RegName", "ZeroElementRules");
- // elements.ElementAt(0).Add(ZeroElement);
- // for (int num = 0; num < XmlTree_ZeroElementRules.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_ZeroElementRules.Nodes[num].Tag.ToString().Contains("forth_elem"))
- // {
- // str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");
- // UsingOtherPropertyL.Add("forth_elem");
- // }
- // str_RemoveBlank = XmlTree_ZeroElementRules.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("ZeroElement", XmlTree_ZeroElementRules.Nodes[num].Text.Split('=')[0]);
- // EleName.SetAttributeValue("UsingElementList", UsingElementList);
- // EleName.SetAttributeValue("UsingImgPropertyList", UsingImgPropertyList);
- // EleName.SetAttributeValue("UsingOtherPropertyList", UsingOtherPropertyList);
- // EleName.SetAttributeValue("Expression", XmlTree_ZeroElementRules.Nodes[num].Tag);
- // ZeroElement.Add(EleName);
- // }
- // xdoc.Save(Address);
- //}
- //XmlTree_ZeroElementRules
- //void LoadXmlToTreeControl(XmlDocument xml, TreeNodeCollection XmlTree_ZeroElementRules)
- //{
- // 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() == "ZeroElementRules")
- // {
- // XmlNodeList childlist = root2[j].ChildNodes;
- // for (int i = 0; i < childlist.Count; i++)
- // {
- // TreeNode new_child = new TreeNode();//定义一个TreeNode节点对象
- // new_child.Text = childlist[i].Attributes["ZeroElement"].Value + "=0";
- // new_child.Tag = childlist[i].Attributes["Expression"].Value;
- // XmlTree_ZeroElementRules.Add(new_child);
- // }
- // }
- // }
- // 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);
- //}
- //private void button_Backup_Click(object sender, EventArgs e)
- //{
- // if (XmlTree_ZeroElementRules.SelectedNode != null)
- // {
- // if (XmlTree_ZeroElementRules.SelectedNode.Text.Contains("="))
- // {
- // if (!comboBox_PeriodicTable.Items.Contains(XmlTree_ZeroElementRules.SelectedNode.Text.Split('=')[0]))
- // {
- // MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- // return;
- // }
- // }
- // else
- // {
- // MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
- // return;
- // }
- // //判断textbox_STDEditor
- // if (!Checktextbox_STDEditor())
- // {
- // return;
- // }
- // XmlTree_ZeroElementRules.SelectedNode.Tag = this.textbox_STDEditor.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_ZeroElementRules_FormClosing(object sender, FormClosingEventArgs e)
- {
- if (form_PeriodicTable != null)
- {
- form_PeriodicTable.Close();
- }
- }
- }
- }
|