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_ConstantsEditor : Form { //readonly 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"}; //readonly string[] OtherSymbol = { "first_elem" , "second_elem" , "third_elem" , "forth_elem", "fifth_elem", "sixth_elem", "seventh_elem","eighth_elem","ninth_elem", "tenth_elem", "Element1", "Element2" }; public Form_ConstantsEditor() { InitializeComponent(); //changeSize(); } //国际化 Language lan; System.Collections.Hashtable table; //public string Language = "English"; string Address_backup = Application.StartupPath + "\\Config\\SysData\\OTSParticleSTD_backup.xml"; string Address = Application.StartupPath + "\\Config\\SysData\\OTSParticleSTD.xml"; private void Form_ConstantsEditor_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"); //this.comboBox_Constants.Items.Add("MAC#0"); //this.comboBox_Constants.Items.Add("MAC#1"); //this.comboBox_Constants.Items.Add("MAC#2"); //this.comboBox_Constants.Items.Add("MAC#3"); //this.comboBox_Constants.Items.Add("MAC#4"); //this.comboBox_Constants.Items.Add("MAC#5"); //this.comboBox_Constants.Items.Add("MAC#6"); //this.comboBox_Constants.Items.Add("MAC#7"); //this.comboBox_Constants.Items.Add("MAC#8"); //this.comboBox_Constants.Items.Add("MAC#9"); //comboBox_Constants.SelectedIndex = comboBox_Constants.Items.IndexOf("MAC#1"); 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; checkBox_0.Checked = false; checkBox_1.Checked = false; checkBox_2.Checked = false; checkBox_3.Checked = false; checkBox_4.Checked = false; checkBox_5.Checked = false; checkBox_6.Checked = false; checkBox_7.Checked = false; checkBox_8.Checked = false; checkBox_9.Checked = false; textBox_0.ReadOnly = true; textBox_1.ReadOnly = true; textBox_2.ReadOnly = true; textBox_3.ReadOnly = true; textBox_4.ReadOnly = true; textBox_5.ReadOnly = true; textBox_6.ReadOnly = true; textBox_7.ReadOnly = true; textBox_8.ReadOnly = true; textBox_9.ReadOnly = true; textBox_Density.ReadOnly = false; textBox_Electrical_conductivity.ReadOnly = false; textBox_Hardness.ReadOnly = false; btn_dbs.Enabled = true; dataGridView_KeyElements.RowHeadersVisible = false; dataGridView_KeyElements.ColumnHeadersVisible = false; dataGridView_KeyElements.AllowUserToAddRows = false; dataGridView_KeyElements.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; dataGridView_SubElements.RowHeadersVisible = false; dataGridView_SubElements.ColumnHeadersVisible = false; dataGridView_SubElements.AllowUserToAddRows = false; dataGridView_SubElements.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; XmlDocument doc = new XmlDocument(); //string Address = Application.StartupPath.Substring(0, Application.StartupPath.Length-35) + "\\Opton\\OTSPartA\\OTS\\Bin\\Win32\\Debug\\Config\\SysData\\OTSParticleSTD.xml"; //string Address = ".\\Config\\SysData\\OTSParticleSTD.xml"; doc.Load(Address); LoadXmlToTreeControl(doc, XmlTree_STDlist.Nodes, XmlTree_MaxEDSRules.Nodes, XmlTree_ZeroElementRules.Nodes); button_UpOrder.Enabled = false; button_DownOrder.Enabled = false; textBox_MaxEDSTime.ReadOnly = true; this.textbox_STDEditor.Text = ""; //this.XmlTree.TabStop = false; panel_OTSPeriodicTable.Visible = false; //修改窗体宽度 //this.Width = this.Width - panel_OTSPeriodicTable.Width - 5; //if (XmlTree.GetNodeCount(true) != 0) //{ // this.XmlTree.SelectedNode = XmlTree.Nodes[0]; //} lan = new Language(this); table = lan.GetNameTable(this.Name); 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 = false; 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_STDlist.HideSelection = false;//失去焦点后不隐藏选中节点 XmlTree_STDlist.Focus(); if (XmlTree_STDlist.Nodes.Count > 0) { XmlTree_STDlist.SelectedNode = XmlTree_STDlist.Nodes[0]; XmlTree_STDlist_AfterSelect(XmlTree_STDlist, new TreeViewEventArgs(XmlTree_STDlist.SelectedNode)); } } /// /// [颜色:16进制转成RGB] /// /// 设置16进制颜色 [返回RGB] /// public static System.Drawing.Color colorHx16toRGB(string strHxColor) { try { if (strHxColor.Length == 0) {//如果为空 return System.Drawing.Color.FromArgb(255, 255, 204);//设为白色 } else {//转换颜色 return System.Drawing.Color.FromArgb(System.Int32.Parse(strHxColor.Substring(1, 2), System.Globalization.NumberStyles.AllowHexSpecifier), System.Int32.Parse(strHxColor.Substring(3, 2), System.Globalization.NumberStyles.AllowHexSpecifier), System.Int32.Parse(strHxColor.Substring(5, 2), System.Globalization.NumberStyles.AllowHexSpecifier)); } } catch {//设为白色 return System.Drawing.Color.FromArgb(255, 255, 204); } } /// /// [颜色:RGB转成16进制] /// /// 红 int /// 绿 int /// 蓝 int /// public static string colorRGBtoHx16(int R, int G, int B) { return System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.FromArgb(R, G, B)); } //XmlTree_STDlist、XmlTree_MaxEDSRules、XmlTree_ZeroElementRules和 ConstantsPage页 void LoadXmlToTreeControl(XmlDocument xml, TreeNodeCollection XmlTree_STDlist, TreeNodeCollection XmlTree_MaxEDSRules, 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()== "STDList") { XmlNodeList childlist = root2[j].ChildNodes; for (int i = 0; i < childlist.Count; i++) { TreeNode new_child = new TreeNode();//定义一个TreeNode节点对象 new_child.Name = childlist[i].Attributes["Hardness"].Value + "_" + childlist[i].Attributes["Density"].Value + "_" + childlist[i].Attributes["Electrical_conductivity"].Value+"$"+ childlist[i].Attributes["KeyElementList"].Value + "$" + childlist[i].Attributes["SubElementList"].Value; new_child.Text = childlist[i].Attributes["StrName"].Value; new_child.Tag = childlist[i].Attributes["Expression"].Value; new_child.ToolTipText = childlist[i].Attributes["STDId"].Value; new_child.BackColor = colorHx16toRGB(childlist[i].Attributes["Color"].Value); XmlTree_STDlist.Add(new_child); } } 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); } } 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); List Constantslist = new List(); for (int i = 0; i < ConstantsStr2.Length; i++) { Constantslist.AddRange(ConstantsStr2[i].Split('=')); } for (int i = 0; i < Constantslist.Count; i += 2) { if (Constantslist[i].Contains("MAC#0")) { this.checkBox_0.Checked = true; this.textBox_0.ReadOnly = false; this.textBox_0.Text = Constantslist[i + 1]; } else if (Constantslist[i].Contains("MAC#1")) { this.checkBox_1.Checked = true; this.textBox_1.ReadOnly = false; this.textBox_1.Text = Constantslist[i + 1]; } else if (Constantslist[i].Contains("MAC#2")) { this.checkBox_2.Checked = true; this.textBox_2.ReadOnly = false; this.textBox_2.Text = Constantslist[i + 1]; } else if (Constantslist[i].Contains("MAC#3")) { this.checkBox_3.Checked = true; this.textBox_3.ReadOnly = false; this.textBox_3.Text = Constantslist[i + 1]; } else if (Constantslist[i].Contains("MAC#4")) { this.checkBox_4.Checked = true; this.textBox_4.ReadOnly = false; this.textBox_4.Text = Constantslist[i + 1]; } else if (Constantslist[i].Contains("MAC#5")) { this.checkBox_5.Checked = true; this.textBox_5.ReadOnly = false; this.textBox_5.Text = Constantslist[i + 1]; } else if (Constantslist[i].Contains("MAC#6")) { this.checkBox_6.Checked = true; this.textBox_6.ReadOnly = false; this.textBox_6.Text = Constantslist[i + 1]; } else if (Constantslist[i].Contains("MAC#7")) { this.checkBox_7.Checked = true; this.textBox_7.ReadOnly = false; this.textBox_7.Text = Constantslist[i + 1]; } else if (Constantslist[i].Contains("MAC#8")) { this.checkBox_8.Checked = true; this.textBox_8.ReadOnly = false; this.textBox_8.Text = Constantslist[i + 1]; } else if (Constantslist[i].Contains("MAC#9")) { this.checkBox_9.Checked = true; this.textBox_9.ReadOnly = false; this.textBox_9.Text = Constantslist[i + 1]; } } } 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 XmlTree_STDlist_MouseClick(object sender, MouseEventArgs e) { //if (e.Button == MouseButtons.Left) //{ // Point ClickPoint = new Point(e.X, e.Y); // TreeNode CurrentNode = XmlTree_STDlist.GetNodeAt(ClickPoint); // if (CurrentNode != null)//判断你点的是不是一个节点 // { // if (XmlTree_STDlist.SelectedNode != null&& XmlTree_STDlist.SelectedNode != CurrentNode) // { // //判断Hardness、Density、Electrical_conductivity // double dHardness = 0, dDensity = 0, dElectrical_conductivity = 0; // if (!double.TryParse(textBox_Hardness.Text, out dHardness)) // { // MessageBox.Show("硬度输入错误,请输入数字!"); // SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode); // return; // } // if (!double.TryParse(textBox_Density.Text, out dDensity)) // { // MessageBox.Show("密度输入错误,请输入数字!"); // SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode); // return; // } // if (!double.TryParse(textBox_Electrical_conductivity.Text, out dElectrical_conductivity)) // { // MessageBox.Show("导电性输入错误,请输入数字!"); // SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode); // return; // } // //判断textbox_STDEditor // if (!Checktextbox_STDEditor()) // { // SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode); // return; // } // XmlTree_STDlist_SaveBeforeMouseClick(e); // } // SetBlackAllNodes(XmlTree_STDlist); // XmlTree_STDlist.SelectedNode = CurrentNode; // XmlTree_STDlist.LabelEdit = true; // this.textbox_STDEditor.Text = XmlTree_STDlist.SelectedNode.Tag.ToString(); // btn_dbs.BackColor = XmlTree_STDlist.SelectedNode.BackColor; // string[] strOther = XmlTree_STDlist.SelectedNode.Name.Split('_'); // textBox_Hardness.Text = strOther[0]; // textBox_Density.Text = strOther[1]; // textBox_Electrical_conductivity.Text = strOther[2]; // if (UpOrder.Enabled == false) // { // UpOrder.Enabled = true; // } // if (DownOrder.Enabled == false) // { // DownOrder.Enabled = true; // } // if (XmlTree_STDlist.SelectedNode.PrevNode == null) // { // UpOrder.Enabled = false; // } // else if (XmlTree_STDlist.SelectedNode.NextNode == null) // { // DownOrder.Enabled = false; // } // } //} //if (e.Button == MouseButtons.Right) //{ // Point ClickPoint = new Point(e.X, e.Y); // TreeNode CurrentNode = XmlTree.GetNodeAt(ClickPoint); // if (CurrentNode != null)//判断你点的是不是一个节点 // { // XmlTree.SelectedNode = CurrentNode;//选中这个节点 // XmlTree.LabelEdit = true; // this.textbox_STDEditor.Text = XmlTree.SelectedNode.Tag.ToString(); // } //} } //XmlTree_STDlist点击节点前保存数据-Hardness、Density、Electrical_conductivity、textbox_STDEditor void XmlTree_STDlist_SaveBeforeMouseClick(MouseEventArgs e) { if ((this.textbox_STDEditor.Text != null) && (XmlTree_STDlist.SelectedNode != null)) { XmlTree_STDlist.SelectedNode.Tag = this.textbox_STDEditor.Text; XmlTree_STDlist.SelectedNode.Name = textBox_Hardness.Text + "_" + textBox_Density.Text + "_" + textBox_Electrical_conductivity.Text; string sKeyElements = ""; for (int i = 0; i < dataGridView_KeyElements.Columns.Count; i++) { sKeyElements += dataGridView_KeyElements.Rows[0].Cells[i].Value.ToString() + ","; } if (sKeyElements.Length > 0) { sKeyElements = sKeyElements.Substring(0, sKeyElements.Length - 1); } string sSubElements = ""; for (int i = 0; i < dataGridView_SubElements.Columns.Count; i++) { sSubElements += dataGridView_SubElements.Rows[0].Cells[i].Value.ToString() + ","; } if (sSubElements.Length > 0) { sSubElements = sSubElements.Substring(0, sSubElements.Length - 1); } XmlTree_STDlist.SelectedNode.Name += "$" + sKeyElements + "$" + sSubElements; } } //删除 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_STDlist") { textbox_STDEditor.Text = ""; textBox_Density.Text = ""; textBox_Electrical_conductivity.Text = ""; textBox_Hardness.Text = ""; btn_dbs.BackColor = Color.White; } if (XmlTree.Name == "XmlTree_MaxEDSRules") { textbox_STDEditor.Text = ""; textBox_MaxEDSTime.Text = ""; } if (XmlTree.Name == "XmlTree_ZeroElementRules") { textbox_STDEditor.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 (tabControl_Rules.SelectedIndex == 0) { //保存节点当前数据 if (XmlTree_STDlist.SelectedNode != null) { //判断Hardness、Density、Electrical_conductivity double dHardness = 0, dDensity = 0, dElectrical_conductivity = 0; if (!double.TryParse(textBox_Hardness.Text, out dHardness) || (double.Parse(textBox_Hardness.Text) <= 0)) { textBox_Hardness.Focus(); textBox_Hardness.SelectAll(); MessageBox.Show(table["message2"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (!double.TryParse(textBox_Density.Text, out dDensity)||double.Parse(textBox_Density.Text)<=0) { textBox_Density.Focus(); textBox_Density.SelectAll(); MessageBox.Show(table["message3"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (!double.TryParse(textBox_Electrical_conductivity.Text, out dElectrical_conductivity)||double.Parse(textBox_Electrical_conductivity.Text)<=0) { textBox_Electrical_conductivity.Focus(); textBox_Electrical_conductivity.SelectAll(); MessageBox.Show(table["message4"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } //判断textbox_STDEditor if (!Checktextbox_STDEditor()) { return; } XmlTree_STDlist.SelectedNode.Tag = this.textbox_STDEditor.Text; XmlTree_STDlist.SelectedNode.Name = textBox_Hardness.Text + "_" + textBox_Density.Text + "_" + textBox_Electrical_conductivity.Text; string sKeyElements = ""; for (int i = 0; i < dataGridView_KeyElements.Columns.Count; i++) { sKeyElements += dataGridView_KeyElements.Rows[0].Cells[i].Value.ToString() + ","; } if (sKeyElements.Length > 0) { sKeyElements = sKeyElements.Substring(0, sKeyElements.Length - 1); } string sSubElements = ""; for (int i = 0; i < dataGridView_SubElements.Columns.Count; i++) { sSubElements += dataGridView_SubElements.Rows[0].Cells[i].Value.ToString() + ","; } if (sSubElements.Length > 0) { sSubElements = sSubElements.Substring(0, sSubElements.Length - 1); } XmlTree_STDlist.SelectedNode.Name += "$" + sKeyElements + "$" + sSubElements; } } else if (tabControl_Rules.SelectedIndex == 1) { 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; //XmlTree_MaxEDSRules.SelectedNode.Name = textBox_MaxEDSTime.Text; } } else if (tabControl_Rules.SelectedIndex == 2) { 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; } } dataGridView_KeyElements.Rows.Clear(); dataGridView_KeyElements.Columns.Clear(); dataGridView_SubElements.Rows.Clear(); dataGridView_SubElements.Columns.Clear(); TreeNode new_child = new TreeNode();//定义一个TreeNode节点对象 TreeView XmlTree = (TreeView)XmlTreeMenuStrip.SourceControl; if (XmlTreeMenuStrip.SourceControl.Name == "XmlTree_STDlist") { new_child.Name = "1_1_1$$"; new_child.Text = "new strName"; new_child.Tag = "NewRules"; textbox_STDEditor.Text = "NewRules"; textBox_Density.Text = "1"; textBox_Electrical_conductivity.Text = "1"; textBox_Hardness.Text = "1"; new_child.BackColor = Color.White; int STDId = 1; for (int i = 0; i < XmlTree_STDlist.Nodes.Count; i++) { if (STDId < int.Parse(XmlTree_STDlist.Nodes[i].ToolTipText)) { STDId = int.Parse(XmlTree_STDlist.Nodes[i].ToolTipText); } } new_child.ToolTipText = (STDId+1).ToString(); } 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"; } 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(), table["message32"].ToString()); } } //双击节点 private void XmlTree_STDlist_MouseDoubleClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { Point ClickPoint = new Point(e.X, e.Y); TreeNode CurrentNode = XmlTree_STDlist.GetNodeAt(ClickPoint); if (CurrentNode != null)//判断你点的是不是一个节点 { XmlTree_STDlist.SelectedNode = CurrentNode;//选中这个节点 XmlTree_STDlist.LabelEdit = true; XmlTree_STDlist.SelectedNode.BeginEdit(); } } } //保存xmltree内容到xml文件 void SaveXmlTreeDataToXml(string Address) { XDocument xdoc = XDocument.Load(Address); IEnumerable elements = from ele in xdoc.Descendants("XMLData") select ele; foreach (var ele in elements) { if (ele != null) { ele.RemoveAll(); } } string value = ""; foreach (var str in comboBox_Constants.Items) { value += str + ","; } if (value != "") { value = value.Substring(0, value.Length - 1); } XElement Constant = new XElement("Member"); Constant.SetAttributeValue("RegName", "Constants"); Constant.SetAttributeValue("value", value); elements.ElementAt(0).Add(Constant); 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 UsingElementL = new List(); List UsingImgPropertyL = new List(); List UsingOtherPropertyL = new List(); 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 str_Removeandor = new List(); 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 list_all = new List(); 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); } 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 UsingElementL = new List(); List UsingImgPropertyL = new List(); List UsingOtherPropertyL = new List(); 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 str_Removeandor = new List(); 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 list_all = new List(); 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); } XElement STD = new XElement("Collection"); STD.SetAttributeValue("RegName", "STDList"); elements.ElementAt(0).Add(STD); for (int num = 0; num < XmlTree_STDlist.Nodes.Count; num++) { string UsingElementList = ""; string UsingImgPropertyList = ""; string UsingOtherPropertyList = ""; List UsingElementL = new List(); List UsingImgPropertyL = new List(); List UsingOtherPropertyL = new List(); string str_RemoveBlank = ""; //forth_elem干扰or分隔符,故先行去掉 if (XmlTree_STDlist.Nodes[num].Tag.ToString().Contains("forth_elem")) { str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", ""); UsingOtherPropertyList = "forth_elem,"; } str_RemoveBlank = XmlTree_STDlist.Nodes[num].Tag.ToString().Replace(" ", ""); string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None); List str_Removeandor = new List(); 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 list_all = new List(); 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]; } string[] str = XmlTree_STDlist.Nodes[num].Name.Split('$'); string[] strOther = str[0].Split('_'); XElement EleName = new XElement("Member"); EleName.SetAttributeValue("STDId", XmlTree_STDlist.Nodes[num].ToolTipText); EleName.SetAttributeValue("StrName", XmlTree_STDlist.Nodes[num].Text); EleName.SetAttributeValue("Color", colorRGBtoHx16(XmlTree_STDlist.Nodes[num].BackColor.R, XmlTree_STDlist.Nodes[num].BackColor.G, XmlTree_STDlist.Nodes[num].BackColor.B)); //EleName.SetAttributeValue("UsingElementList", UsingElementList); EleName.SetAttributeValue("KeyElementList", str[1]); EleName.SetAttributeValue("SubElementList", str[2]); EleName.SetAttributeValue("UsingImgPropertyList", UsingImgPropertyList); EleName.SetAttributeValue("UsingOtherPropertyList", UsingOtherPropertyList); EleName.SetAttributeValue("Expression", XmlTree_STDlist.Nodes[num].Tag); EleName.SetAttributeValue("Hardness", strOther[0]); EleName.SetAttributeValue("Density", strOther[1]); EleName.SetAttributeValue("Electrical_conductivity", strOther[2]); STD.Add(EleName); } xdoc.Save(Address); } //元素周期表开关 private void PeriodicTableSwitch_Click(object sender, EventArgs e) { if (PeriodicTableSwitch.BackColor == SystemColors.Control) { panel_OTSPeriodicTable.Visible = true; this.Width = this.Width + panel_OTSPeriodicTable.Width + 5; PeriodicTableSwitch.BackColor = SystemColors.ControlDark; //if (Language == "English") //{ // PeriodicTableSwitch.Text = "Close PeriodicTable"; //} //else if(Language == "Chinese") //{ // PeriodicTableSwitch.Text = "关闭元素周期表"; //} } else if (PeriodicTableSwitch.BackColor == SystemColors.ControlDark) { panel_OTSPeriodicTable.Visible = false; this.Width = this.Width - panel_OTSPeriodicTable.Width - 5; PeriodicTableSwitch.BackColor = SystemColors.Control; //if (Language == "English") //{ // PeriodicTableSwitch.Text = "Open PeriodicTable"; //} //else if (Language == "Chinese") //{ // PeriodicTableSwitch.Text = "打开元素周期表"; //} //textbox_STDEditor.Focus(); groupBox_XmlTree_MaxEDSRules.Focus(); } } private void button_Ok_Click(object sender, EventArgs e) { if (tabControl_Rules.SelectedIndex == 0) { //保存节点当前数据 if (XmlTree_STDlist.SelectedNode != null) { //判断Hardness、Density、Electrical_conductivity double dHardness = 0, dDensity = 0, dElectrical_conductivity = 0; if (!double.TryParse(textBox_Hardness.Text, out dHardness) || (double.Parse(textBox_Hardness.Text) <= 0)) { textBox_Hardness.Focus(); textBox_Hardness.SelectAll(); MessageBox.Show(table["message10"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (!double.TryParse(textBox_Density.Text, out dDensity) || double.Parse(textBox_Density.Text) <= 0) { textBox_Density.Focus(); textBox_Density.SelectAll(); MessageBox.Show(table["message11"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (!double.TryParse(textBox_Electrical_conductivity.Text, out dElectrical_conductivity) || double.Parse(textBox_Electrical_conductivity.Text) <= 0) { textBox_Electrical_conductivity.Focus(); textBox_Electrical_conductivity.SelectAll(); MessageBox.Show(table["message12"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } //判断textbox_STDEditor if (!Checktextbox_STDEditor()) { return; } XmlTree_STDlist.SelectedNode.Tag = this.textbox_STDEditor.Text; XmlTree_STDlist.SelectedNode.Name = textBox_Hardness.Text + "_" + textBox_Density.Text + "_" + textBox_Electrical_conductivity.Text; string sKeyElements = ""; for (int i = 0; i < dataGridView_KeyElements.Columns.Count; i++) { sKeyElements += dataGridView_KeyElements.Rows[0].Cells[i].Value.ToString() + ","; } if (sKeyElements.Length > 0) { sKeyElements = sKeyElements.Substring(0, sKeyElements.Length - 1); } string sSubElements = ""; for (int i = 0; i < dataGridView_SubElements.Columns.Count; i++) { sSubElements += dataGridView_SubElements.Rows[0].Cells[i].Value.ToString() + ","; } if (sSubElements.Length > 0) { sSubElements = sSubElements.Substring(0, sSubElements.Length - 1); } XmlTree_STDlist.SelectedNode.Name += "$" + sKeyElements + "$" + sSubElements; } } else if (tabControl_Rules.SelectedIndex == 1) { 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; } } else if (tabControl_Rules.SelectedIndex == 2) { 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; } } string value = ""; foreach (var str in comboBox_Constants.Items) { value += str + ","; } if (value != "") { value = value.Substring(0, value.Length - 1); } //string Address = Application.StartupPath + "\\Config\\SysData\\OTSParticleSTD.xml"; //string Address = ".\\Config\\SysData\\OTSParticleSTD.xml"; SaveXmlTreeDataToXml(Address); 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) { //comboBox_PeriodicTable.Text = null; //this.textbox_STDEditor.Text += comboBox_PeriodicTable.SelectedItem.ToString(); //textbox_STDEditor.Focus(); //textbox_STDEditor.SelectionStart = textbox_STDEditor.Text.Length; //textbox_STDEditor.ScrollToCaret(); 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 str_Removeandor = new List(); 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 list_all = new List(); for (int i = 0; i < str_Removeandor.Count; i++) { list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' })); } //常量 List Constantslist = new List(); 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 btn_dbs_Click(object sender, EventArgs e) { ColorDialog cd = new ColorDialog(); cd.FullOpen = true;//自定义颜色界面打开 DialogResult result = cd.ShowDialog(); if (result == DialogResult.OK) { btn_dbs.BackColor = cd.Color; if (XmlTree_STDlist.SelectedNode != null) { XmlTree_STDlist.SelectedNode.BackColor = cd.Color; } } if (XmlTree_STDlist.SelectedNode != null) { //如果不是白色了,就把文字去掉吧,显得好看 if (btn_dbs.BackColor != Color.White) { btn_dbs.Text = ""; } } } 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 (Flag_comboBox_Constants) //{ if (comboBox_Constants.SelectedItem != null) { //this.textbox_STDEditor.Text += comboBox_Constants.SelectedItem.ToString().Split('=')[0]; ////comboBox_Constants.Text = null; //textbox_STDEditor.Focus(); //textbox_STDEditor.SelectionStart = textbox_STDEditor.Text.Length; //textbox_STDEditor.ScrollToCaret(); 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(); } //} //Flag_comboBox_Constants = true; } bool Flag_SelStatus = true; //XML切换成功失败状态 private void button_UpOrder_Click(object sender, EventArgs e) { if (XmlTree_STDlist.SelectedNode.PrevNode != null) { //object tag = XmlTree_STDlist.SelectedNode.PrevNode.Tag; //string name = XmlTree_STDlist.SelectedNode.PrevNode.Name; //string text = XmlTree_STDlist.SelectedNode.PrevNode.Text; //Color backcolor=XmlTree_STDlist.SelectedNode.PrevNode.BackColor; //string STDId = XmlTree_STDlist.SelectedNode.PrevNode.ToolTipText; //XmlTree_STDlist.SelectedNode.PrevNode.Tag = XmlTree_STDlist.SelectedNode.Tag; //XmlTree_STDlist.SelectedNode.PrevNode.BackColor = XmlTree_STDlist.SelectedNode.BackColor; //XmlTree_STDlist.SelectedNode.PrevNode.Name = XmlTree_STDlist.SelectedNode.Name; //XmlTree_STDlist.SelectedNode.PrevNode.Text = XmlTree_STDlist.SelectedNode.Text; //XmlTree_STDlist.SelectedNode.PrevNode.ToolTipText = XmlTree_STDlist.SelectedNode.ToolTipText; //XmlTree_STDlist.SelectedNode.Tag = tag; //XmlTree_STDlist.SelectedNode.BackColor = backcolor; //XmlTree_STDlist.SelectedNode.Name = name; //XmlTree_STDlist.SelectedNode.Text = text; //XmlTree_STDlist.SelectedNode.ToolTipText = STDId; //this.textbox_STDEditor.Text = XmlTree_STDlist.SelectedNode.Tag.ToString(); //btn_dbs.BackColor = XmlTree_STDlist.SelectedNode.BackColor; //string[] strOther = XmlTree_STDlist.SelectedNode.Name.Split('$'); //string[] strOther2 = strOther[0].Split('_'); //textBox_Hardness.Text = strOther2[0]; //textBox_Density.Text = strOther2[1]; //textBox_Electrical_conductivity.Text = strOther2[2]; //dataGridView_KeyElements.Rows.Clear(); //dataGridView_KeyElements.Columns.Clear(); //string[] KeyElement = strOther[1].Split(','); //for (int i = 0; i < KeyElement.Length; i++) //{ // if (KeyElement[0] != "") // { // DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn(); // dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString(); // dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn); // if (dataGridView_KeyElements.Rows.Count == 0) // { // DataGridViewRow row = new DataGridViewRow(); // dataGridView_KeyElements.Rows.Add(row); // } // dataGridView_KeyElements.Rows[0].Cells[i].Value = KeyElement[i]; // } //} //dataGridView_SubElements.Rows.Clear(); //dataGridView_SubElements.Columns.Clear(); //string[] SubElement = strOther[2].Split(','); //for (int i = 0; i < SubElement.Length; i++) //{ // if (SubElement[i] != "") // { // DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn(); // dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString(); // dataGridView_SubElements.Columns.Add(dataGridViewButtonColumn); // if (dataGridView_SubElements.Rows.Count == 0) // { // DataGridViewRow row = new DataGridViewRow(); // dataGridView_SubElements.Rows.Add(row); // } // dataGridView_SubElements.Rows[0].Cells[i].Value = SubElement[i]; // } //} //this.XmlTree_STDlist.Focus(); //XmlTree_STDlist.SelectedNode = XmlTree_STDlist.SelectedNode.PrevNode; //if (XmlTree_STDlist.SelectedNode.PrevNode == null) //{ // UpOrder.Enabled = false; //} } XmlTree_STDlist.SelectedNode = XmlTree_STDlist.SelectedNode.PrevNode; if (Flag_SelStatus) { object tag = XmlTree_STDlist.SelectedNode.NextNode.Tag; string name = XmlTree_STDlist.SelectedNode.NextNode.Name; string text = XmlTree_STDlist.SelectedNode.NextNode.Text; Color backcolor = XmlTree_STDlist.SelectedNode.NextNode.BackColor; string STDId = XmlTree_STDlist.SelectedNode.NextNode.ToolTipText; XmlTree_STDlist.SelectedNode.NextNode.Tag = XmlTree_STDlist.SelectedNode.Tag; XmlTree_STDlist.SelectedNode.NextNode.BackColor = XmlTree_STDlist.SelectedNode.BackColor; XmlTree_STDlist.SelectedNode.NextNode.Name = XmlTree_STDlist.SelectedNode.Name; XmlTree_STDlist.SelectedNode.NextNode.Text = XmlTree_STDlist.SelectedNode.Text; XmlTree_STDlist.SelectedNode.NextNode.ToolTipText = XmlTree_STDlist.SelectedNode.ToolTipText; XmlTree_STDlist.SelectedNode.Tag = tag; XmlTree_STDlist.SelectedNode.BackColor = backcolor; XmlTree_STDlist.SelectedNode.Name = name; XmlTree_STDlist.SelectedNode.Text = text; XmlTree_STDlist.SelectedNode.ToolTipText = STDId; this.textbox_STDEditor.Text = XmlTree_STDlist.SelectedNode.Tag.ToString(); btn_dbs.BackColor = XmlTree_STDlist.SelectedNode.BackColor; string[] strOther = XmlTree_STDlist.SelectedNode.Name.Split('$'); string[] strOther2 = strOther[0].Split('_'); textBox_Hardness.Text = strOther2[0]; textBox_Density.Text = strOther2[1]; textBox_Electrical_conductivity.Text = strOther2[2]; dataGridView_KeyElements.Rows.Clear(); dataGridView_KeyElements.Columns.Clear(); string[] KeyElement = strOther[1].Split(','); for (int i = 0; i < KeyElement.Length; i++) { if (KeyElement[0] != "") { DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn(); dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString(); dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn); if (dataGridView_KeyElements.Rows.Count == 0) { DataGridViewRow row = new DataGridViewRow(); dataGridView_KeyElements.Rows.Add(row); } dataGridView_KeyElements.Rows[0].Cells[i].Value = KeyElement[i]; } } dataGridView_SubElements.Rows.Clear(); dataGridView_SubElements.Columns.Clear(); string[] SubElement = strOther[2].Split(','); for (int i = 0; i < SubElement.Length; i++) { if (SubElement[i] != "") { DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn(); dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString(); dataGridView_SubElements.Columns.Add(dataGridViewButtonColumn); if (dataGridView_SubElements.Rows.Count == 0) { DataGridViewRow row = new DataGridViewRow(); dataGridView_SubElements.Rows.Add(row); } dataGridView_SubElements.Rows[0].Cells[i].Value = SubElement[i]; } } this.XmlTree_STDlist.Focus(); if (XmlTree_STDlist.SelectedNode.PrevNode == null) { button_UpOrder.Enabled = false; } dataGridView_KeyElements.ClearSelection(); dataGridView_SubElements.ClearSelection(); } this.XmlTree_STDlist.Focus(); Flag_SelStatus = true; } private void button_DownOrder_Click(object sender, EventArgs e) { if (XmlTree_STDlist.SelectedNode.NextNode != null) { //object tag = XmlTree_STDlist.SelectedNode.NextNode.Tag; //string name = XmlTree_STDlist.SelectedNode.NextNode.Name; //string text = XmlTree_STDlist.SelectedNode.NextNode.Text; //Color backcolor = XmlTree_STDlist.SelectedNode.NextNode.BackColor; //string STDId = XmlTree_STDlist.SelectedNode.NextNode.ToolTipText; //XmlTree_STDlist.SelectedNode.NextNode.Tag = XmlTree_STDlist.SelectedNode.Tag; //XmlTree_STDlist.SelectedNode.NextNode.BackColor = XmlTree_STDlist.SelectedNode.BackColor; //XmlTree_STDlist.SelectedNode.NextNode.Name = XmlTree_STDlist.SelectedNode.Name; //XmlTree_STDlist.SelectedNode.NextNode.Text = XmlTree_STDlist.SelectedNode.Text; //XmlTree_STDlist.SelectedNode.NextNode.ToolTipText = XmlTree_STDlist.SelectedNode.ToolTipText; //XmlTree_STDlist.SelectedNode.Tag = tag; //XmlTree_STDlist.SelectedNode.BackColor = backcolor; //XmlTree_STDlist.SelectedNode.Name = name; //XmlTree_STDlist.SelectedNode.Text = text; //XmlTree_STDlist.SelectedNode.ToolTipText = STDId; //this.textbox_STDEditor.Text = XmlTree_STDlist.SelectedNode.Tag.ToString(); //btn_dbs.BackColor = XmlTree_STDlist.SelectedNode.BackColor; //string[] strOther = XmlTree_STDlist.SelectedNode.Name.Split('$'); //string[] strOther2 = strOther[0].Split('_'); //textBox_Hardness.Text = strOther2[0]; //textBox_Density.Text = strOther2[1]; //textBox_Electrical_conductivity.Text = strOther2[2]; //dataGridView_KeyElements.Rows.Clear(); //dataGridView_KeyElements.Columns.Clear(); //string[] KeyElement = strOther[1].Split(','); //for (int i = 0; i < KeyElement.Length; i++) //{ // if (KeyElement[0] != "") // { // DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn(); // dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString(); // dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn); // if (dataGridView_KeyElements.Rows.Count == 0) // { // DataGridViewRow row = new DataGridViewRow(); // dataGridView_KeyElements.Rows.Add(row); // } // dataGridView_KeyElements.Rows[0].Cells[i].Value = KeyElement[i]; // } //} //dataGridView_SubElements.Rows.Clear(); //dataGridView_SubElements.Columns.Clear(); //string[] SubElement = strOther[2].Split(','); //for (int i = 0; i < SubElement.Length; i++) //{ // if (SubElement[i] != "") // { // DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn(); // dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString(); // dataGridView_SubElements.Columns.Add(dataGridViewButtonColumn); // if (dataGridView_SubElements.Rows.Count == 0) // { // DataGridViewRow row = new DataGridViewRow(); // dataGridView_SubElements.Rows.Add(row); // } // dataGridView_SubElements.Rows[0].Cells[i].Value = SubElement[i]; // } //} //this.XmlTree_STDlist.Focus(); //XmlTree_STDlist.SelectedNode = XmlTree_STDlist.SelectedNode.NextNode; //if (XmlTree_STDlist.SelectedNode.NextNode == null) //{ // DownOrder.Enabled = false; //} } XmlTree_STDlist.SelectedNode = XmlTree_STDlist.SelectedNode.NextNode; if (Flag_SelStatus) { object tag = XmlTree_STDlist.SelectedNode.PrevNode.Tag; string name = XmlTree_STDlist.SelectedNode.PrevNode.Name; string text = XmlTree_STDlist.SelectedNode.PrevNode.Text; Color backcolor = XmlTree_STDlist.SelectedNode.PrevNode.BackColor; string STDId = XmlTree_STDlist.SelectedNode.PrevNode.ToolTipText; XmlTree_STDlist.SelectedNode.PrevNode.Tag = XmlTree_STDlist.SelectedNode.Tag; XmlTree_STDlist.SelectedNode.PrevNode.BackColor = XmlTree_STDlist.SelectedNode.BackColor; XmlTree_STDlist.SelectedNode.PrevNode.Name = XmlTree_STDlist.SelectedNode.Name; XmlTree_STDlist.SelectedNode.PrevNode.Text = XmlTree_STDlist.SelectedNode.Text; XmlTree_STDlist.SelectedNode.PrevNode.ToolTipText = XmlTree_STDlist.SelectedNode.ToolTipText; XmlTree_STDlist.SelectedNode.Tag = tag; XmlTree_STDlist.SelectedNode.BackColor = backcolor; XmlTree_STDlist.SelectedNode.Name = name; XmlTree_STDlist.SelectedNode.Text = text; XmlTree_STDlist.SelectedNode.ToolTipText = STDId; this.textbox_STDEditor.Text = XmlTree_STDlist.SelectedNode.Tag.ToString(); btn_dbs.BackColor = XmlTree_STDlist.SelectedNode.BackColor; string[] strOther = XmlTree_STDlist.SelectedNode.Name.Split('$'); string[] strOther2 = strOther[0].Split('_'); textBox_Hardness.Text = strOther2[0]; textBox_Density.Text = strOther2[1]; textBox_Electrical_conductivity.Text = strOther2[2]; dataGridView_KeyElements.Rows.Clear(); dataGridView_KeyElements.Columns.Clear(); string[] KeyElement = strOther[1].Split(','); for (int i = 0; i < KeyElement.Length; i++) { if (KeyElement[0] != "") { DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn(); dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString(); dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn); if (dataGridView_KeyElements.Rows.Count == 0) { DataGridViewRow row = new DataGridViewRow(); dataGridView_KeyElements.Rows.Add(row); } dataGridView_KeyElements.Rows[0].Cells[i].Value = KeyElement[i]; } } dataGridView_SubElements.Rows.Clear(); dataGridView_SubElements.Columns.Clear(); string[] SubElement = strOther[2].Split(','); for (int i = 0; i < SubElement.Length; i++) { if (SubElement[i] != "") { DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn(); dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString(); dataGridView_SubElements.Columns.Add(dataGridViewButtonColumn); if (dataGridView_SubElements.Rows.Count == 0) { DataGridViewRow row = new DataGridViewRow(); dataGridView_SubElements.Rows.Add(row); } dataGridView_SubElements.Rows[0].Cells[i].Value = SubElement[i]; } } this.XmlTree_STDlist.Focus(); if (XmlTree_STDlist.SelectedNode.PrevNode == null) { button_DownOrder.Enabled = false; } dataGridView_KeyElements.ClearSelection(); dataGridView_SubElements.ClearSelection(); } this.XmlTree_STDlist.Focus(); Flag_SelStatus = true; } private void button_Backup_Click(object sender, EventArgs e) { if (tabControl_Rules.SelectedIndex == 0) { //保存节点当前数据 if (XmlTree_STDlist.SelectedNode != null) { //判断Hardness、Density、Electrical_conductivity double dHardness = 0, dDensity = 0, dElectrical_conductivity = 0; if (!double.TryParse(textBox_Hardness.Text, out dHardness) || (double.Parse(textBox_Hardness.Text) <= 0)) { textBox_Hardness.Focus(); textBox_Hardness.SelectAll(); MessageBox.Show(table["message10"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (!double.TryParse(textBox_Density.Text, out dDensity) || double.Parse(textBox_Density.Text) <= 0) { textBox_Density.Focus(); textBox_Density.SelectAll(); MessageBox.Show(table["message11"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (!double.TryParse(textBox_Electrical_conductivity.Text, out dElectrical_conductivity) || double.Parse(textBox_Electrical_conductivity.Text) <= 0) { textBox_Electrical_conductivity.Focus(); textBox_Electrical_conductivity.SelectAll(); MessageBox.Show(table["message12"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } //判断textbox_STDEditor if (!Checktextbox_STDEditor()) { return; } XmlTree_STDlist.SelectedNode.Tag = this.textbox_STDEditor.Text; XmlTree_STDlist.SelectedNode.Name = textBox_Hardness.Text + "_" + textBox_Density.Text + "_" + textBox_Electrical_conductivity.Text; string sKeyElements = ""; for (int i = 0; i < dataGridView_KeyElements.Columns.Count; i++) { sKeyElements += dataGridView_KeyElements.Rows[0].Cells[i].Value.ToString() + ","; } if (sKeyElements.Length > 0) { sKeyElements = sKeyElements.Substring(0, sKeyElements.Length - 1); } string sSubElements = ""; for (int i = 0; i < dataGridView_SubElements.Columns.Count; i++) { sSubElements += dataGridView_SubElements.Rows[0].Cells[i].Value.ToString() + ","; } if (sSubElements.Length > 0) { sSubElements = sSubElements.Substring(0, sSubElements.Length - 1); } XmlTree_STDlist.SelectedNode.Name += "$" + sKeyElements + "$" + sSubElements; } } else if (tabControl_Rules.SelectedIndex == 1) { 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; } } else if (tabControl_Rules.SelectedIndex == 2) { 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) { //string Address = Application.StartupPath.Substring(0, Application.StartupPath.Length - 35) + "\\Opton\\OTSPartA\\OTS\\Bin\\Win32\\Debug\\Config\\SysData\\OTSParticleSTD.xml"; //string Address = ".\\Config\\SysData\\OTSParticleSTD.xml"; 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); } //string Address_backup = Application.StartupPath.Substring(0, Application.StartupPath.Length-35) + "\\Bin\\Win32\\Debug\\Config\\SysData\\OTSParticleSTD_backup.xml"; //string Address_backup = ".\\Config\\SysData\\OTSParticleSTD_backup.xml"; //SaveXmlTreeDataToXml(Address_backup); //MessageBox.Show("备份成功!", "提示"); } private void button_Recover_Click(object sender, EventArgs e) { XmlDocument doc = new XmlDocument(); //string Address_backup = ".\\Config\\SysData\\OTSParticleSTD_backup.xml"; //string Address = ".\\Config\\SysData\\OTSParticleSTD.xml"; //string Address_backup = Application.StartupPath + "\\Config\\SysData\\\\OTSParticleSTD_backup.xml"; //string Address = Application.StartupPath + "\\Config\\SysData\\OTSParticleSTD.xml"; try { System.IO.File.Copy(Address_backup, Address, true); doc.Load(Address_backup); XmlTree_STDlist.Nodes.Clear(); XmlTree_MaxEDSRules.Nodes.Clear(); XmlTree_ZeroElementRules.Nodes.Clear(); checkBox_0.Checked = false; checkBox_1.Checked = false; checkBox_2.Checked = false; checkBox_3.Checked = false; checkBox_4.Checked = false; checkBox_5.Checked = false; checkBox_6.Checked = false; checkBox_7.Checked = false; checkBox_8.Checked = false; checkBox_9.Checked = false; textBox_0.ReadOnly = true; textBox_1.ReadOnly = true; textBox_2.ReadOnly = true; textBox_3.ReadOnly = true; textBox_4.ReadOnly = true; textBox_5.ReadOnly = true; textBox_6.ReadOnly = true; textBox_7.ReadOnly = true; textBox_8.ReadOnly = true; textBox_9.ReadOnly = true; LoadXmlToTreeControl(doc, XmlTree_STDlist.Nodes, XmlTree_MaxEDSRules.Nodes, XmlTree_ZeroElementRules.Nodes); XmlTree_STDlist.SelectedNode = null; XmlTree_MaxEDSRules.SelectedNode = null; XmlTree_ZeroElementRules.SelectedNode = null; textbox_STDEditor.Text = ""; textBox_Density.Text = ""; textBox_Electrical_conductivity.Text = ""; textBox_Hardness.Text = ""; //textBox_MaxEDSTime.Text = ""; btn_dbs.BackColor = Color.White; dataGridView_KeyElements.Rows.Clear(); dataGridView_KeyElements.Columns.Clear(); dataGridView_SubElements.Rows.Clear(); dataGridView_SubElements.Columns.Clear(); } catch(Exception ex) { MessageBox.Show(table["message26"].ToString() + "\n"+ex.Message.ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information); } } private void tabControl_Rules_DrawItem(object sender, DrawItemEventArgs e) { //SolidBrush _Brush = new SolidBrush(Color.Black);//单色画刷 //RectangleF _TabTextArea = (RectangleF)tabControl_Rules.GetTabRect(e.Index);//绘制区域 //StringFormat _sf = new StringFormat();//封装文本布局格式信息 //_sf.LineAlignment = StringAlignment.Center; //_sf.Alignment = StringAlignment.Center; //e.Graphics.DrawString(tabControl_Rules.Controls[e.Index].Text, SystemInformation.MenuFont, _Brush, _TabTextArea, _sf); //RectangleF tabArea = tabControl_Rules.GetTabRect(e.Index); //RectangleF tabTextArea = tabArea; //Graphics g = e.Graphics; //StringFormat sf = new StringFormat(); //sf.LineAlignment = StringAlignment.Center; //sf.Alignment = StringAlignment.Center; //Font font = this.tabControl_Rules.Font; //SolidBrush brush = new SolidBrush(Color.Black); //g.DrawString(((TabControl)(sender)).TabPages[e.Index].Text, font, brush, tabTextArea, sf); } private void XmlTree_ZeroElementRules_MouseClick(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)//判断你点的是不是一个节点 // { // if (XmlTree_ZeroElementRules.SelectedNode != null&& XmlTree_ZeroElementRules.SelectedNode != CurrentNode) // { // if (XmlTree_ZeroElementRules.SelectedNode.Text.Contains("=")) // { // if (!comboBox_PeriodicTable.Items.Contains(XmlTree_ZeroElementRules.SelectedNode.Text.Split('=')[0])) // { // MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + "项,名称格式填写错误,正确格式为:元素名=0"); // SetGrayExceptSelectedNode(XmlTree_ZeroElementRules, XmlTree_ZeroElementRules.SelectedNode); // return; // } // } // else // { // MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + "项,名称格式填写错误,正确格式为:元素名=0"); // SetGrayExceptSelectedNode(XmlTree_ZeroElementRules, XmlTree_ZeroElementRules.SelectedNode); // return; // } // if (!Checktextbox_STDEditor()) // { // SetGrayExceptSelectedNode(XmlTree_ZeroElementRules, XmlTree_ZeroElementRules.SelectedNode); // return; // } // XmlTree_ZeroElementRules.SelectedNode.Tag = this.textbox_STDEditor.Text; // } // SetBlackAllNodes(XmlTree_ZeroElementRules); // XmlTree_ZeroElementRules.SelectedNode = CurrentNode; // this.textbox_STDEditor.Text = XmlTree_ZeroElementRules.SelectedNode.Tag.ToString(); // } //} } 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 void XmlTree_MaxEDSRules_MouseClick(object sender, MouseEventArgs e) { //if (e.Button == MouseButtons.Left) //{ // Point ClickPoint = new Point(e.X, e.Y); // TreeNode CurrentNode = XmlTree_MaxEDSRules.GetNodeAt(ClickPoint); // if (CurrentNode != null)//判断你点的是不是一个节点 // { // if (XmlTree_MaxEDSRules.SelectedNode != null&& XmlTree_MaxEDSRules.SelectedNode!= CurrentNode) // { // if (!Checktextbox_STDEditor()) // { // SetGrayExceptSelectedNode(XmlTree_MaxEDSRules, XmlTree_MaxEDSRules.SelectedNode); // return; // } // //double dMaxEDSTime = 0; // //if (!double.TryParse(textBox_MaxEDSTime.Text, out dMaxEDSTime)||double.Parse(textBox_MaxEDSTime.Text)<=0) // //{ // // MessageBox.Show("MaxEDSTime请填写数字!", "提示"); // //} // XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text; // //XmlTree_MaxEDSRules.SelectedNode.Name = this.textBox_MaxEDSTime.Text; // } // SetBlackAllNodes(XmlTree_MaxEDSRules); // XmlTree_MaxEDSRules.SelectedNode = CurrentNode; // this.textbox_STDEditor.Text = XmlTree_MaxEDSRules.SelectedNode.Tag.ToString(); // //textBox_MaxEDSTime.Text = XmlTree_MaxEDSRules.SelectedNode.Name; // } //} } private void checkBox_0_CheckedChanged(object sender, EventArgs e) { if (checkBox_0.Checked) { textBox_0.ReadOnly = false; } else { if (!CheckConstants(checkBox_0.Text)) { checkBox_0.Checked = true; } else { textBox_0.ReadOnly = true; } } } private void checkBox_1_CheckedChanged(object sender, EventArgs e) { if (checkBox_1.Checked) { textBox_1.ReadOnly = false; } else { if (!CheckConstants(checkBox_1.Text)) { checkBox_1.Checked = true; } else { textBox_1.ReadOnly = true; } } } private void checkBox_2_CheckedChanged(object sender, EventArgs e) { if (checkBox_2.Checked) { textBox_2.ReadOnly = false; } else { if (!CheckConstants(checkBox_2.Text)) { checkBox_2.Checked = true; } else { textBox_2.ReadOnly = true; } } } private void checkBox_3_CheckedChanged(object sender, EventArgs e) { if (checkBox_3.Checked) { textBox_3.ReadOnly = false; } else { if (!CheckConstants(checkBox_3.Text)) { checkBox_3.Checked = true; } else { textBox_3.ReadOnly = true; } } } private void checkBox_4_CheckedChanged(object sender, EventArgs e) { if (checkBox_4.Checked) { textBox_4.ReadOnly = false; } else { if (!CheckConstants(checkBox_4.Text)) { checkBox_4.Checked = true; } else { textBox_4.ReadOnly = true; } } } private void checkBox_5_CheckedChanged(object sender, EventArgs e) { if (checkBox_5.Checked) { textBox_5.ReadOnly = false; } else { if (!CheckConstants(checkBox_5.Text)) { checkBox_5.Checked = true; } else { textBox_5.ReadOnly = true; } } } private void checkBox_6_CheckedChanged(object sender, EventArgs e) { if (checkBox_6.Checked) { textBox_6.ReadOnly = false; } else { if (!CheckConstants(checkBox_6.Text)) { checkBox_6.Checked = true; } else { textBox_6.ReadOnly = true; } } } private void checkBox_7_CheckedChanged(object sender, EventArgs e) { if (checkBox_7.Checked) { textBox_7.ReadOnly = false; } else { if (!CheckConstants(checkBox_7.Text)) { checkBox_7.Checked = true; } else { textBox_7.ReadOnly = true; } } } private void checkBox_8_CheckedChanged(object sender, EventArgs e) { if (checkBox_8.Checked) { textBox_8.ReadOnly = false; } else { if (!CheckConstants(checkBox_8.Text)) { checkBox_8.Checked = true; } else { textBox_8.ReadOnly = true; } } } private void checkBox_9_CheckedChanged(object sender, EventArgs e) { if (checkBox_9.Checked) { textBox_9.ReadOnly = false; } else { if (!CheckConstants(checkBox_9.Text)) { checkBox_9.Checked = true; } else { textBox_9.ReadOnly = true; } } } private bool CheckConstants(string ConstantName) { for (int num = 0; num < XmlTree_STDlist.Nodes.Count; num++) { if (XmlTree_STDlist.Nodes[num].Tag.ToString().Contains(ConstantName)) { tabControl_Rules.SelectedIndex = 0; XmlTree_STDlist.SelectedNode = XmlTree_STDlist.Nodes[num]; SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode); DialogResult result = MessageBox.Show(table["message27"].ToString() + XmlTree_STDlist.Nodes[num].Text + table["message28"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } } for (int num = 0; num < XmlTree_MaxEDSRules.Nodes.Count; num++) { if (XmlTree_MaxEDSRules.Nodes[num].Tag.ToString().Contains(ConstantName)) { tabControl_Rules.SelectedIndex = 1; 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; } } for (int num = 0; num < XmlTree_ZeroElementRules.Nodes.Count; num++) { if (XmlTree_ZeroElementRules.Nodes[num].Tag.ToString().Contains(ConstantName)) { tabControl_Rules.SelectedIndex = 2; XmlTree_ZeroElementRules.SelectedNode = XmlTree_ZeroElementRules.Nodes[num]; SetGrayExceptSelectedNode(XmlTree_ZeroElementRules, XmlTree_ZeroElementRules.SelectedNode); DialogResult result = MessageBox.Show(table["message27"].ToString() + XmlTree_ZeroElementRules.Nodes[num].Text + table["message28"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } } return true; } private void button_UpdateConstants_Click(object sender, EventArgs e) { this.comboBox_Constants.Items.Clear(); for (int i=0;i<10;i++) { CheckBox checkBox= (CheckBox)this.tabControl_Rules.TabPages[3].Controls.Find("checkBox_" + i.ToString(), false)[0]; if (checkBox.Checked) { TextBox tBox = (TextBox)this.tabControl_Rules.TabPages[3].Controls.Find("textBox_" + i.ToString(), false)[0]; double DoubleTry = 0; if (double.TryParse(tBox.Text, out DoubleTry)) { this.comboBox_Constants.Items.Add(checkBox.Text + "=" + tBox.Text); } else { MessageBox.Show(table["message29"].ToString() + checkBox.Name + table["message30"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } } List Constantslist = new List(); Constantslist.Add("MAC#0"); Constantslist.Add("MAC#1"); Constantslist.Add("MAC#2"); Constantslist.Add("MAC#3"); Constantslist.Add("MAC#4"); Constantslist.Add("MAC#5"); Constantslist.Add("MAC#6"); Constantslist.Add("MAC#7"); Constantslist.Add("MAC#8"); Constantslist.Add("MAC#9"); foreach (var item in comboBox_Constants.Items) { Constantslist.Remove(item.ToString().Split('=')[0]); } MessageBox.Show(table["message31"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information); } //tabpage切换开关 bool Flag_TabControlChange = true; private void tabControl_Rules_Deselecting(object sender, TabControlCancelEventArgs e) { if (tabControl_Rules.SelectedIndex == 0) { //保存节点当前数据 if (XmlTree_STDlist.SelectedNode != null) { //判断Hardness、Density、Electrical_conductivity double dHardness = 0, dDensity = 0, dElectrical_conductivity = 0; if (!double.TryParse(textBox_Hardness.Text, out dHardness) || (double.Parse(textBox_Hardness.Text) <= 0)) { textBox_Hardness.Focus(); textBox_Hardness.SelectAll(); MessageBox.Show(table["message10"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information); Flag_TabControlChange = false; return; } if (!double.TryParse(textBox_Density.Text, out dDensity) || double.Parse(textBox_Density.Text) <= 0) { textBox_Density.Focus(); textBox_Density.SelectAll(); MessageBox.Show(table["message11"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information); Flag_TabControlChange = false; return; } if (!double.TryParse(textBox_Electrical_conductivity.Text, out dElectrical_conductivity) || double.Parse(textBox_Electrical_conductivity.Text) <= 0) { textBox_Electrical_conductivity.Focus(); textBox_Electrical_conductivity.SelectAll(); MessageBox.Show(table["message12"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information); Flag_TabControlChange = false; return; } //判断textbox_STDEditor if (!Checktextbox_STDEditor()) { Flag_TabControlChange = false; return; } Flag_TabControlChange = true; XmlTree_STDlist.SelectedNode.Tag = this.textbox_STDEditor.Text; XmlTree_STDlist.SelectedNode.Name = textBox_Hardness.Text + "_" + textBox_Density.Text + "_" + textBox_Electrical_conductivity.Text; string sKeyElements = ""; for (int i = 0; i < dataGridView_KeyElements.Columns.Count; i++) { sKeyElements += dataGridView_KeyElements.Rows[0].Cells[i].Value.ToString() + ","; } if (sKeyElements.Length > 0) { sKeyElements = sKeyElements.Substring(0, sKeyElements.Length - 1); } string sSubElements = ""; for (int i = 0; i < dataGridView_SubElements.Columns.Count; i++) { sSubElements += dataGridView_SubElements.Rows[0].Cells[i].Value.ToString() + ","; } if (sSubElements.Length > 0) { sSubElements = sSubElements.Substring(0, sSubElements.Length - 1); } XmlTree_STDlist.SelectedNode.Name += "$" + sKeyElements + "$" + sSubElements; XmlTree_STDlist.SelectedNode.BackColor= btn_dbs.BackColor; } } else if (tabControl_Rules.SelectedIndex == 1) { 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); Flag_TabControlChange = false; return; } //判断textbox_STDEditor if (!Checktextbox_STDEditor()) { Flag_TabControlChange = false; return; } Flag_TabControlChange = true; XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text; //XmlTree_MaxEDSRules.SelectedNode.Name = textBox_MaxEDSTime.Text; } } else if (tabControl_Rules.SelectedIndex == 2) { 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); Flag_TabControlChange = false; return; } } else { MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information); Flag_TabControlChange = false; return; } //判断textbox_STDEditor if (!Checktextbox_STDEditor()) { Flag_TabControlChange = false; return; } Flag_TabControlChange = true; XmlTree_ZeroElementRules.SelectedNode.Tag = this.textbox_STDEditor.Text; } } //XmlTree_STDlist.SelectedNode = null; //XmlTree_MaxEDSRules.SelectedNode = null; //XmlTree_ZeroElementRules.SelectedNode = null; //textbox_STDEditor.Text = ""; //textBox_Density.Text = ""; //textBox_Electrical_conductivity.Text = ""; //textBox_Hardness.Text = ""; //textBox_MaxEDSTime.Text = ""; //btn_dbs.BackColor = Color.White; } private void tabControl_Rules_SelectedIndexChanged(object sender, EventArgs e) { if (tabControl_Rules.SelectedIndex == 0) { //XmlTree_STDlist.SelectedNode = null; XmlTree_STDlist.Focus(); XmlTree_STDlist_AfterSelect(XmlTree_STDlist, new TreeViewEventArgs(XmlTree_STDlist.SelectedNode)); textBox_Density.ReadOnly = false; textBox_Electrical_conductivity.ReadOnly = false; textBox_Hardness.ReadOnly = false; btn_dbs.Enabled = true; textBox_MaxEDSTime.ReadOnly = true; button_UpOrder.Enabled = false; button_DownOrder.Enabled = false; } else if (tabControl_Rules.SelectedIndex == 1) { //XmlTree_MaxEDSRules.SelectedNode = null; XmlTree_MaxEDSRules.Focus(); XmlTree_MaxEDSRules_AfterSelect(XmlTree_MaxEDSRules, new TreeViewEventArgs(XmlTree_MaxEDSRules.SelectedNode)); dataGridView_KeyElements.Rows.Clear(); dataGridView_KeyElements.Columns.Clear(); dataGridView_SubElements.Rows.Clear(); dataGridView_SubElements.Columns.Clear(); btn_dbs.BackColor = SystemColors.Control; textBox_Density.Text = ""; textBox_Electrical_conductivity.Text = ""; textBox_Hardness.Text = ""; textBox_Density.ReadOnly = true; textBox_Electrical_conductivity.ReadOnly = true; textBox_Hardness.ReadOnly = true; btn_dbs.Enabled = false; textBox_MaxEDSTime.ReadOnly = false; } else if (tabControl_Rules.SelectedIndex == 2) { //XmlTree_ZeroElementRules.SelectedNode = null; XmlTree_ZeroElementRules.Focus(); XmlTree_ZeroElementRules_AfterSelect(XmlTree_MaxEDSRules, new TreeViewEventArgs(XmlTree_ZeroElementRules.SelectedNode)); dataGridView_KeyElements.Rows.Clear(); dataGridView_KeyElements.Columns.Clear(); dataGridView_SubElements.Rows.Clear(); dataGridView_SubElements.Columns.Clear(); btn_dbs.BackColor = SystemColors.Control; textBox_Density.Text = ""; textBox_Electrical_conductivity.Text = ""; textBox_Hardness.Text = ""; textBox_Density.ReadOnly = true; textBox_Electrical_conductivity.ReadOnly = true; textBox_Hardness.ReadOnly = true; btn_dbs.Enabled = false; textBox_MaxEDSTime.ReadOnly = true; } else { textbox_STDEditor.Text = ""; dataGridView_KeyElements.Rows.Clear(); dataGridView_KeyElements.Columns.Clear(); dataGridView_SubElements.Rows.Clear(); dataGridView_SubElements.Columns.Clear(); btn_dbs.BackColor = SystemColors.Control; textBox_Density.Text = ""; textBox_Electrical_conductivity.Text = ""; textBox_Hardness.Text = ""; textBox_Density.ReadOnly = true; textBox_Electrical_conductivity.ReadOnly = true; textBox_Hardness.ReadOnly = true; btn_dbs.Enabled = false; textBox_MaxEDSTime.ReadOnly = true; } } private void XmlTree_ZeroElementRules_BeforeSelect(object sender, TreeViewCancelEventArgs e) { //if (e.Node != null) //{ // if (e.Node.ForeColor == Color.Gray) // { // e.Cancel = true; //不让选中禁用节点 // return; // } //} 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); SetGrayExceptSelectedNode(XmlTree_ZeroElementRules, XmlTree_ZeroElementRules.SelectedNode); e.Cancel = true; return; } } else { MessageBox.Show(XmlTree_ZeroElementRules.SelectedNode.Text + table["message9"].ToString(), table["message32"].ToString(), 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 tabControl_Rules_Selecting(object sender, TabControlCancelEventArgs e) { if (!Flag_TabControlChange) { e.Cancel = true; } else { } } private void XmlTree_ZeroElementRules_AfterSelect(object sender, TreeViewEventArgs e) { SetBlackAllNodes(XmlTree_ZeroElementRules); this.textbox_STDEditor.Text = XmlTree_ZeroElementRules.SelectedNode.Tag.ToString(); } private void XmlTree_STDlist_AfterSelect(object sender, TreeViewEventArgs e) { SetBlackAllNodes(XmlTree_STDlist); this.textbox_STDEditor.Text = XmlTree_STDlist.SelectedNode.Tag.ToString(); btn_dbs.BackColor = XmlTree_STDlist.SelectedNode.BackColor; string[] strOther = XmlTree_STDlist.SelectedNode.Name.Split('$'); string[] strOther2 = strOther[0].Split('_'); textBox_Hardness.Text = strOther2[0]; textBox_Density.Text = strOther2[1]; textBox_Electrical_conductivity.Text = strOther2[2]; dataGridView_KeyElements.Rows.Clear(); dataGridView_KeyElements.Columns.Clear(); string[] KeyElement = strOther[1].Split(','); for (int i=0;i< KeyElement.Length;i++) { if(KeyElement[0]!="") { DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn(); dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString(); dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn); if (dataGridView_KeyElements.Rows.Count == 0) { DataGridViewRow row = new DataGridViewRow(); dataGridView_KeyElements.Rows.Add(row); } dataGridView_KeyElements.Rows[0].Cells[i].Value = KeyElement[i]; } } dataGridView_SubElements.Rows.Clear(); dataGridView_SubElements.Columns.Clear(); string[] SubElement = strOther[2].Split(','); for (int i = 0; i < SubElement.Length; i++) { if(SubElement[i]!="") { DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn(); dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString(); dataGridView_SubElements.Columns.Add(dataGridViewButtonColumn); if (dataGridView_SubElements.Rows.Count == 0) { DataGridViewRow row = new DataGridViewRow(); dataGridView_SubElements.Rows.Add(row); } dataGridView_SubElements.Rows[0].Cells[i].Value = SubElement[i]; } } if (button_UpOrder.Enabled == false) { button_UpOrder.Enabled = true; } if (button_DownOrder.Enabled == false) { button_DownOrder.Enabled = true; } if (XmlTree_STDlist.SelectedNode.PrevNode == null) { button_UpOrder.Enabled = false; } else if (XmlTree_STDlist.SelectedNode.NextNode == null) { button_DownOrder.Enabled = false; } dataGridView_KeyElements.ClearSelection(); dataGridView_SubElements.ClearSelection(); } private void XmlTree_STDlist_BeforeSelect(object sender, TreeViewCancelEventArgs e) { if (XmlTree_STDlist.SelectedNode != null) { //判断Hardness、Density、Electrical_conductivity double dHardness = 0, dDensity = 0, dElectrical_conductivity = 0; if (!double.TryParse(textBox_Hardness.Text, out dHardness) || (double.Parse(textBox_Hardness.Text) <= 0)) { MessageBox.Show(table["message10"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information); SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode); Flag_SelStatus = false; e.Cancel = true; return; } if (!double.TryParse(textBox_Density.Text, out dDensity) || double.Parse(textBox_Density.Text) <= 0) { MessageBox.Show(table["message11"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information); SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode); Flag_SelStatus = false; e.Cancel = true; return; } if (!double.TryParse(textBox_Electrical_conductivity.Text, out dElectrical_conductivity) || double.Parse(textBox_Electrical_conductivity.Text) <= 0) { MessageBox.Show(table["message12"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information); SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode); Flag_SelStatus = false; e.Cancel = true; return; } //判断textbox_STDEditor if (!Checktextbox_STDEditor()) { SetGrayExceptSelectedNode(XmlTree_STDlist, XmlTree_STDlist.SelectedNode); Flag_SelStatus = false; e.Cancel = true; return; } XmlTree_STDlist.SelectedNode.Tag = this.textbox_STDEditor.Text; if (dataGridView_KeyElements.Rows.Count == 0&& dataGridView_SubElements.Rows.Count==0) { string str_RemoveBlank = textbox_STDEditor.Text.ToString().Replace(" ", ""); str_RemoveBlank = str_RemoveBlank.Replace("\r\n", ""); str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", ""); string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None); List str_Removeandor = new List(); 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 list_all = new List(); for (int i = 0; i < str_Removeandor.Count; i++) { list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' })); } List UsingElementL = new List(); 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]); } } } for (int i = 0; i < UsingElementL.Count; i++) { DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn(); dataGridViewButtonColumn.Name = dataGridView_KeyElements.Columns.Count.ToString(); dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn); if (dataGridView_KeyElements.Rows.Count == 0) { DataGridViewRow row = new DataGridViewRow(); dataGridView_KeyElements.Rows.Add(row); } dataGridView_KeyElements.Rows[0].Cells[i].Value = UsingElementL[i]; } } XmlTree_STDlist.SelectedNode.Name = textBox_Hardness.Text + "_" + textBox_Density.Text + "_" + textBox_Electrical_conductivity.Text; string sKeyElements = ""; for (int i = 0; i < dataGridView_KeyElements.Columns.Count; i++) { sKeyElements += dataGridView_KeyElements.Rows[0].Cells[i].Value.ToString()+","; } if (sKeyElements.Length > 0) { sKeyElements = sKeyElements.Substring(0,sKeyElements.Length-1); } string sSubElements = ""; for (int i = 0; i < dataGridView_SubElements.Columns.Count; i++) { sSubElements += dataGridView_SubElements.Rows[0].Cells[i].Value.ToString()+","; } if(sSubElements.Length>0) { sSubElements = sSubElements.Substring(0, sSubElements.Length-1); } XmlTree_STDlist.SelectedNode.Name += "$" + sKeyElements + "$" + sSubElements; XmlTree_STDlist.SelectedNode.BackColor= btn_dbs.BackColor; } } private void XmlTree_MaxEDSRules_AfterSelect(object sender, TreeViewEventArgs e) { SetBlackAllNodes(XmlTree_MaxEDSRules); this.textbox_STDEditor.Text = XmlTree_MaxEDSRules.SelectedNode.Tag.ToString(); //textBox_MaxEDSTime.Text = XmlTree_MaxEDSRules.SelectedNode.Name; } 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; } //double dMaxEDSTime = 0; //if (!double.TryParse(textBox_MaxEDSTime.Text, out dMaxEDSTime)||double.Parse(textBox_MaxEDSTime.Text)<=0) //{ // MessageBox.Show("MaxEDSTime请填写数字!", "提示"); // e.Cancel = true; //} XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text; //XmlTree_MaxEDSRules.SelectedNode.Name = this.textBox_MaxEDSTime.Text; } } string ElementKeyOrSub = ""; private void dataGridView_KeyElements_CellClick(object sender, DataGridViewCellEventArgs e) { ElementKeyOrSub = dataGridView_KeyElements.CurrentCell.Value.ToString(); dataGridView_KeyElements.Columns.RemoveAt(e.ColumnIndex); DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn(); dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString(); dataGridView_SubElements.Columns.Add(dataGridViewButtonColumn); if (dataGridView_SubElements.Rows.Count == 0) { DataGridViewRow row = new DataGridViewRow(); dataGridView_SubElements.Rows.Add(row); } dataGridView_SubElements.Rows[0].Cells[dataGridView_SubElements.Columns.Count-1].Value = ElementKeyOrSub; dataGridView_SubElements.ClearSelection(); dataGridView_KeyElements.ClearSelection(); XmlTree_STDlist.Focus(); } private void dataGridView_SubElements_CellClick(object sender, DataGridViewCellEventArgs e) { ElementKeyOrSub = dataGridView_SubElements.CurrentCell.Value.ToString(); dataGridView_SubElements.Columns.RemoveAt(e.ColumnIndex); DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn(); dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString(); dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn); if (dataGridView_KeyElements.Rows.Count == 0) { DataGridViewRow row = new DataGridViewRow(); dataGridView_KeyElements.Rows.Add(row); } dataGridView_KeyElements.Rows[0].Cells[dataGridView_KeyElements.Columns.Count - 1].Value = ElementKeyOrSub; dataGridView_KeyElements.ClearSelection(); dataGridView_SubElements.ClearSelection(); XmlTree_STDlist.Focus(); } private void textbox_STDEditor_TextChanged(object sender, EventArgs e) { //string str_RemoveBlank = textbox_STDEditor.Text.ToString().Replace(" ", ""); //str_RemoveBlank = str_RemoveBlank.Replace("\r\n", ""); //str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", ""); //string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None); //List str_Removeandor = new List(); //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 list_all = new List(); //for (int i = 0; i < str_Removeandor.Count; i++) //{ // list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' })); //} //List UsingElementL = new List(); //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]); // } // } //} //for (int i = 0; i < UsingElementL.Count; i++) //{ // DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn(); // dataGridViewButtonColumn.Name = dataGridView_KeyElements.Columns.Count.ToString(); // dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn); // if (dataGridView_KeyElements.Rows.Count == 0) // { // DataGridViewRow row = new DataGridViewRow(); // dataGridView_KeyElements.Rows.Add(row); // } // dataGridView_KeyElements.Rows[0].Cells[i].Value = UsingElementL[i]; //} } private void textbox_STDEditor_KeyPress(object sender, KeyPressEventArgs e) { //if (e.KeyChar == '\r') //{ // dataGridView_KeyElements.Rows.Clear(); // dataGridView_KeyElements.Columns.Clear(); // dataGridView_SubElements.Rows.Clear(); // dataGridView_SubElements.Columns.Clear(); // string str_RemoveBlank = textbox_STDEditor.Text.ToString().Replace(" ", ""); // str_RemoveBlank = str_RemoveBlank.Replace("\r\n", ""); // str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", ""); // string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None); // List str_Removeandor = new List(); // 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 list_all = new List(); // for (int i = 0; i < str_Removeandor.Count; i++) // { // list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' })); // } // List UsingElementL = new List(); // 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]); // } // } // } // for (int i = 0; i < UsingElementL.Count; i++) // { // DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn(); // dataGridViewButtonColumn.Name = dataGridView_KeyElements.Columns.Count.ToString(); // dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn); // if(dataGridView_KeyElements.Rows.Count==0) // { // DataGridViewRow row = new DataGridViewRow(); // dataGridView_KeyElements.Rows.Add(row); // } // dataGridView_KeyElements.Rows[0].Cells[i].Value = UsingElementL[i]; // } //} } private void textbox_STDEditor_Leave(object sender, EventArgs e) { if (tabControl_Rules.SelectedIndex == 0) { dataGridView_KeyElements.Rows.Clear(); dataGridView_KeyElements.Columns.Clear(); string str_RemoveBlank = textbox_STDEditor.Text.ToString().Replace(" ", ""); str_RemoveBlank = str_RemoveBlank.Replace("\r\n", ""); str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", ""); string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None); List str_Removeandor = new List(); 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 list_all = new List(); for (int i = 0; i < str_Removeandor.Count; i++) { list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' })); } List UsingElementL = new List(); 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]); } } } List SubElements = new List(); for (int i = 0; i < dataGridView_SubElements.ColumnCount; i++) { if (UsingElementL.Contains(dataGridView_SubElements.Rows[0].Cells[i].Value)) { SubElements.Add(dataGridView_SubElements.Rows[0].Cells[i].Value.ToString()); } } dataGridView_SubElements.Rows.Clear(); dataGridView_SubElements.Columns.Clear(); for (int i = 0; i < SubElements.Count; i++) { DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn(); dataGridViewButtonColumn.Name = dataGridView_SubElements.Columns.Count.ToString(); dataGridView_SubElements.Columns.Add(dataGridViewButtonColumn); if (dataGridView_SubElements.Rows.Count == 0) { DataGridViewRow row = new DataGridViewRow(); dataGridView_SubElements.Rows.Add(row); } dataGridView_SubElements.Rows[0].Cells[dataGridView_SubElements.ColumnCount - 1].Value = SubElements[i]; } if (SubElements.Count > 0) { for (int i = 0; i < UsingElementL.Count; i++) { if (!SubElements.Contains(UsingElementL[i])) { DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn(); dataGridViewButtonColumn.Name = dataGridView_KeyElements.Columns.Count.ToString(); dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn); if (dataGridView_KeyElements.Rows.Count == 0) { DataGridViewRow row = new DataGridViewRow(); dataGridView_KeyElements.Rows.Add(row); } dataGridView_KeyElements.Rows[0].Cells[dataGridView_KeyElements.ColumnCount - 1].Value = UsingElementL[i]; } } } else { for (int i = 0; i < UsingElementL.Count; i++) { DataGridViewButtonColumn dataGridViewButtonColumn = new DataGridViewButtonColumn(); dataGridViewButtonColumn.Name = dataGridView_KeyElements.Columns.Count.ToString(); dataGridView_KeyElements.Columns.Add(dataGridViewButtonColumn); if (dataGridView_KeyElements.Rows.Count == 0) { DataGridViewRow row = new DataGridViewRow(); dataGridView_KeyElements.Rows.Add(row); } dataGridView_KeyElements.Rows[0].Cells[i].Value = UsingElementL[i]; } } dataGridView_KeyElements.ClearSelection(); dataGridView_SubElements.ClearSelection(); XmlTree_STDlist.Focus(); } else if(tabControl_Rules.SelectedIndex == 1) { XmlTree_MaxEDSRules.Focus(); } else if (tabControl_Rules.SelectedIndex == 2) { XmlTree_ZeroElementRules.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_Color_Click(object sender, EventArgs e) { groupBox_Color.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_XmlTree_STDlist1_Click(object sender, EventArgs e) { groupBox_XmlTree_STDlist1.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(); } ////改变大小 //void changeSize() //{ // //SetStyle(ControlStyles.UserPaint, true); // //SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景. // //SetStyle(ControlStyles.OptimizedDoubleBuffer, true); // 双缓冲DoubleBuffer // x = this.Width; // y = this.Height; // setTag(this); // //if (this.WindowState == FormWindowState.Maximized) // //{ // // this.WindowState = FormWindowState.Normal; // //} // //else // //{ // // this.FormBorderStyle = FormBorderStyle.None; // // this.WindowState = FormWindowState.Maximized; // //} //} //#region 控件大小随窗体大小等比例缩放 //private float x;//定义当前窗体的宽度 //private float y;//定义当前窗体的高度 //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); // } // } //} ////设置双缓冲区、解决闪屏问题 //public static void SetDouble(Control cc) //{ // cc.GetType().GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance | // System.Reflection.BindingFlags.NonPublic).SetValue(cc, true, null); //} //private void setControls(float newx, float newy, Control cons) //{ // //遍历窗体中的控件,重新设置控件的值 // foreach (Control con in cons.Controls) // { // ////获取控件的Tag属性值,并分割后存储字符串数组 // SetDouble(this); // SetDouble(con); // if (con.Tag != null) // { // string[] mytag = con.Tag.ToString().Split(new char[] { ';' }); // //根据窗体缩放的比例确定控件的值 // con.Width = Convert.ToInt32(System.Convert.ToSingle(mytag[0]) * newx);//宽度 // con.Height = Convert.ToInt32(System.Convert.ToSingle(mytag[1]) * newy);//高度 // con.Left = Convert.ToInt32(System.Convert.ToSingle(mytag[2]) * newx);//左边距 // con.Top = Convert.ToInt32(System.Convert.ToSingle(mytag[3]) * newy);//顶边距 // Single currentSize = System.Convert.ToSingle(mytag[4]) * newy;//字体大小 // con.Font = new Font(con.Font.Name, currentSize, con.Font.Style, con.Font.Unit); // if (con.Controls.Count > 0) // { // setControls(newx, newy, con); // } // } // } //} //private void setControls2(float newx, float newy, Control cons) //{ // //遍历窗体中的控件,重新设置控件的值 // foreach (Control con in cons.Controls) // { // //根据窗体缩放的比例确定控件的值 // con.Width = Convert.ToInt32(con.Width * newx); // con.Height = Convert.ToInt32(con.Height * newy); // con.Left = Convert.ToInt32(con.Left * newx); // con.Top = Convert.ToInt32(con.Top * newx); // //Single currentSize = System.Convert.ToSingle(con.Font.Size) * newy;//字体大小 // //con.Font = new Font(con.Font.Name, currentSize, con.Font.Style, con.Font.Unit); // if (con.Controls.Count > 0) // { // setControls2(newx, newy, con); // } // } //} ////在窗体的的时间中添加Resize事件 //private void Login_Resize(object sender, EventArgs e) //{ // if (this.WindowState == FormWindowState.Maximized) // { // float newx = (this.Width) / x; // float newy = (this.Height) / y; // setControls2(newx, newy, this); // PeriodicTableSwitch_Click(PeriodicTableSwitch, new EventArgs()); // } // else // { // //setControls2(x, y, this); // } //} //#endregion } }