| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405 | using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using System.Xml;using System.Xml.Linq;namespace OTSPartA_STDEditor{    public partial class Form_MaxEDSRules : Form    {        //国际化        Language lan;        System.Collections.Hashtable table;                string STDDBAddress = Application.StartupPath + "\\Config\\SysData\\" + "OTSCleanlinesSTD.db";        //string STDDBAddress_backup = Application.StartupPath + "\\Config\\SysData\\LibBackup\\" + "OTSCleanlinesSTD_backup.db";        string STDDBAddress_backupDirectory = Application.StartupPath + "\\Config\\SysData\\LibBackup\\";        //元素周期表        Form_PeriodicTable form_PeriodicTable=null;        public Form_MaxEDSRules(string DBAddress)        {            InitializeComponent();            STDDBAddress = DBAddress;            //X = this.Width;            //Y = this.Height;            //setTag(this);        }        private void Form_MaxEDSRules_Load(object sender, EventArgs e)        {                        //初始化comboBox            this.comboBox_Elem1.Items.Add("first_elem");            this.comboBox_Elem1.Items.Add("second_elem");            this.comboBox_Elem1.Items.Add("third_elem");            this.comboBox_Elem1.Items.Add("forth_elem");            this.comboBox_Elem1.Items.Add("fifth_elem");            this.comboBox_Elem1.Items.Add("sixth_elem");            this.comboBox_Elem1.Items.Add("seventh_elem");            this.comboBox_Elem1.Items.Add("eighth_elem");            this.comboBox_Elem1.Items.Add("ninth_elem");            this.comboBox_Elem1.Items.Add("tenth_elem");            comboBox_Elem1.SelectedIndex = comboBox_Elem1.Items.IndexOf("first_elem");            this.comboBox_Elem.Items.Add("Element#1");            this.comboBox_Elem.Items.Add("Element#2");            this.comboBox_Elem.Items.Add("Element#3");            this.comboBox_Elem.Items.Add("Element#4");            this.comboBox_Elem.Items.Add("Element#5");            this.comboBox_Elem.Items.Add("Element#6");            this.comboBox_Elem.Items.Add("Element#7");            this.comboBox_Elem.Items.Add("Element#8");            this.comboBox_Elem.Items.Add("Element#9");            this.comboBox_Elem.Items.Add("Element#10");            comboBox_Elem.SelectedIndex = comboBox_Elem.Items.IndexOf("Element#1");            this.comboBox_ImgProperty.Items.Add("Dmax");            this.comboBox_ImgProperty.Items.Add("Dmin");            this.comboBox_ImgProperty.Items.Add("Aspect");            this.comboBox_ImgProperty.Items.Add("Dperp");            this.comboBox_ImgProperty.Items.Add("Dmean");            this.comboBox_ImgProperty.Items.Add("Area");            this.comboBox_ImgProperty.Items.Add("Dferet");            this.comboBox_ImgProperty.Items.Add("With");            this.comboBox_ImgProperty.Items.Add("Height");            this.comboBox_ImgProperty.Items.Add("Perimeter");            this.comboBox_ImgProperty.Items.Add("Dinscr");            this.comboBox_ImgProperty.Items.Add("Orientation");            this.comboBox_ImgProperty.Items.Add("Delong");            this.comboBox_ImgProperty.Items.Add("Aspectelong");            this.comboBox_ImgProperty.Items.Add("Dequalcircle");            this.comboBox_ImgProperty.Items.Add("Vedio");            comboBox_ImgProperty.SelectedIndex = comboBox_ImgProperty.Items.IndexOf("Dmax");            string[] PeriodicTable = { "H", "He", "Li", "Be", "B", "C", "N", "O", "F", "Ne", "Na", "Mg", "Al", "Si", "P", "S", "Cl", "Ar", "K", "Ca", "Sc", "Ti", "V", "Cr", "Mn", "Fe", "Co", "Ni", "Cu", "Zn", "Ga", "Ge", "As", "Se", "Br", "Kr", "Rb", "Sr", "Y", "Zr", "Nb", "Mo", "Tc", "Ru", "Rh", "Pd", "Ag", "Cd", "In", "Sn", "Sb", "Te", "I", "Xe", "Cs", "Ba", "La", "Ce", "Pr", "Nd", "Pm", "Sm", "Eu", "Gd", "Tb", "Dy", "Ho", "Er", "Tm", "Yb", "Lu", "Hf", "Ta", "W", "Re", "Os", "Ir", "Pt", "Au", "Hq", "TI", "Pb", "Bi", "Po", "At", "Rn", "Fr", "Ra", "Ac", "Th", "Pa", "U", "Np", "Pu", "Am", "Cm", "Bk", "Cf", "Es", "Fm", "Mc", "No", "Lr", "Rf", "Db", "Sg", "Bh", "Hs", "Mt", "Ds", "Rg", "Unb" };            comboBox_PeriodicTable.Items.AddRange(PeriodicTable);            AutoCompleteStringCollection sc = new AutoCompleteStringCollection();            sc.AddRange(PeriodicTable);            this.comboBox_PeriodicTable.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest;            this.comboBox_PeriodicTable.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.CustomSource;            this.comboBox_PeriodicTable.AutoCompleteCustomSource = sc;            LoadMaxEDSRulesToTreeControl(STDDBAddress, XmlTree_MaxEDSRules.Nodes);            LoadConstants(STDDBAddress);            this.textbox_STDEditor.Text = "";            lan = new Language(this);            table = lan.GetNameTable("Form_MaxEDSRules");            if (table["language"].ToString() == "EN")            {                //panel_OTSPeriodicTable.BackgroundImage = global::OTSPartA_STDEditor.Properties.Resources.PeriodicTable_EN;                PeriodicTableSwitch.BackgroundImage = global::OTSPartA_STDEditor.Properties.Resources.STDEditoName;                PeriodicTableSwitch.Text = "";            }            else            {                //panel_OTSPeriodicTable.BackgroundImage = global::OTSPartA_STDEditor.Properties.Resources.PeriodicTable_ZH;                PeriodicTableSwitch.Text = "元素周期表";            }            //panel_OTSPeriodicTable.Visible = true;            //this.Width = this.Width - panel_OTSPeriodicTable.Width - 5;            Size size = Screen.PrimaryScreen.WorkingArea.Size;            Left = (size.Width - Width) / 2;            Top = (size.Height - Height) / 2;            WindowState = FormWindowState.Normal;            //groupBox_XmlTree_MaxEDSRules.Focus();            this.XmlTree_MaxEDSRules.HideSelection = false;//失去焦点后不隐藏选中节点            XmlTree_MaxEDSRules.Focus();            if (XmlTree_MaxEDSRules.Nodes.Count > 0)            {                XmlTree_MaxEDSRules.SelectedNode = XmlTree_MaxEDSRules.Nodes[0];                XmlTree_MaxEDSRules_AfterSelect(XmlTree_MaxEDSRules, new TreeViewEventArgs(XmlTree_MaxEDSRules.SelectedNode));            }        }               //XmlTree_MaxEDSRules        void LoadXmlToTreeControl(XmlDocument xml,TreeNodeCollection XmlTree_MaxEDSRules)        {            XmlNode root = xml.SelectSingleNode("XMLData");            XmlNodeList root2 = root.SelectNodes("Collection");            for (int j = 0; j < root2.Count; j++)            {                if (root2[j].Attributes["RegName"].Value.ToString() == "MaxEDSRules")                {                    XmlNodeList childlist = root2[j].ChildNodes;                    if (childlist.Count != 0)                    {                        for (int i = 0; i < childlist.Count; i++)                        {                            TreeNode new_child = new TreeNode();//定义一个TreeNode节点对象                                                                //new_child.Name = childlist[i].Attributes["MaxEDSTime"].Value;                            new_child.Tag = childlist[i].Attributes["Expression"].Value;                            new_child.Text = "Rule" + i.ToString();                            XmlTree_MaxEDSRules.Add(new_child);                        }                        if (childlist[0].Attributes["MaxEDSTime"] != null)                        {                            textBox_MaxEDSTime.Text = childlist[0].Attributes["MaxEDSTime"].Value;                        }                    }                }            }            XmlNode root3 = root.SelectSingleNode("Member");            string ConstantsStr = root3.Attributes["value"].Value;            ConstantsStr = ConstantsStr.Replace(" ", "");            string[] ConstantsStr2 = ConstantsStr.Split(',');            this.comboBox_Constants.Items.Clear();            this.comboBox_Constants.Items.AddRange(ConstantsStr2);        }        void LoadMaxEDSRulesToTreeControl(string DBAddress, TreeNodeCollection XmlTree_MaxEDSRules)        {            try            {                System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + DBAddress + "'");                m_dbConnection.Open();                System.Data.SQLite.SQLiteDataAdapter m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select * from MaxEDSRules", m_dbConnection);                DataSet ds = new DataSet();                m_dataAdapter.Fill(ds);                DataTable dt = ds.Tables[0];                if (dt != null)                {                    if (dt.Rows.Count > 0)                    {                        int i = 1;                        foreach (DataRow item in dt.Rows)                        {                            TreeNode new_child = new TreeNode();//定义一个TreeNode节点对象                            new_child.Tag = item["Expression"].ToString();                            new_child.Text = "Rule" + i.ToString();                            XmlTree_MaxEDSRules.Add(new_child);                            i++;                        }                        if (dt.Rows[0]["MaxEDSTime"] != null)                        {                            textBox_MaxEDSTime.Text = dt.Rows[0]["MaxEDSTime"].ToString();                        }                    }                }            }            catch (Exception ee)            {                MessageBox.Show(ee.ToString());            }        }        void LoadConstants(string STDDBAddress)        {            try            {                System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + STDDBAddress + "'");                m_dbConnection.Open();                System.Data.SQLite.SQLiteDataAdapter m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select * from Constants", m_dbConnection);                DataSet ds = new DataSet();                m_dataAdapter.Fill(ds);                DataTable dt = ds.Tables[0];                string ConstantsStr = "";                if (dt.Rows.Count > 0)                {                    ConstantsStr = dt.Rows[0][0].ToString();                }                ConstantsStr = ConstantsStr.Replace(" ", "");                string[] ConstantsStr2 = ConstantsStr.Split(',');                comboBox_Constants.Items.Clear();                comboBox_Constants.Items.AddRange(ConstantsStr2);                m_dbConnection.Close();            }            catch (Exception ee)            {                MessageBox.Show(ee.ToString());            }        }        private void comboBox_Elem1_SelectedIndexChanged(object sender, EventArgs e)        {            string newStr = comboBox_Elem1.SelectedItem.ToString();            int index = textbox_STDEditor.SelectionStart;            textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);            textbox_STDEditor.Focus();            textbox_STDEditor.Select(index + newStr.Length, 0);            textbox_STDEditor.ScrollToCaret();        }        private void comboBox_Elem2_SelectedIndexChanged(object sender, EventArgs e)        {            string newStr = comboBox_Elem.SelectedItem.ToString();            int index = textbox_STDEditor.SelectionStart;            textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);            textbox_STDEditor.Focus();            textbox_STDEditor.Select(index + newStr.Length, 0);            textbox_STDEditor.ScrollToCaret();        }        private void comboBox_ImgProperty_SelectedIndexChanged(object sender, EventArgs e)        {            string newStr = comboBox_ImgProperty.SelectedItem.ToString();            int index = textbox_STDEditor.SelectionStart;            textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);            textbox_STDEditor.Focus();            textbox_STDEditor.Select(index + newStr.Length, 0);            textbox_STDEditor.ScrollToCaret();        }        private void button_Plus_Click(object sender, EventArgs e)        {            int index = textbox_STDEditor.SelectionStart;            textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "+");            textbox_STDEditor.Focus();            textbox_STDEditor.Select(index+1,0);            textbox_STDEditor.ScrollToCaret();        }        private void button_Subtract_Click(object sender, EventArgs e)        {            int index = textbox_STDEditor.SelectionStart;            textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "-");            textbox_STDEditor.Focus();            textbox_STDEditor.Select(index + 1, 0);            textbox_STDEditor.ScrollToCaret();        }        private void button_Multiply_Click(object sender, EventArgs e)        {            int index = textbox_STDEditor.SelectionStart;            textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "*");            textbox_STDEditor.Focus();            textbox_STDEditor.Select(index + 1, 0);            textbox_STDEditor.ScrollToCaret();        }        private void button_Divide_Click(object sender, EventArgs e)        {            int index = textbox_STDEditor.SelectionStart;            textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "/");            textbox_STDEditor.Focus();            textbox_STDEditor.Select(index + 1, 0);            textbox_STDEditor.ScrollToCaret(); ;        }        private void button_More_Click(object sender, EventArgs e)        {            int index = textbox_STDEditor.SelectionStart;            textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, ">");            textbox_STDEditor.Focus();            textbox_STDEditor.Select(index + 1, 0);            textbox_STDEditor.ScrollToCaret();        }        private void button_Less_Click(object sender, EventArgs e)        {            int index = textbox_STDEditor.SelectionStart;            textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "<");            textbox_STDEditor.Focus();            textbox_STDEditor.Select(index + 1, 0);            textbox_STDEditor.ScrollToCaret();        }        private void button_LeftParenthesis_Click(object sender, EventArgs e)        {            int index = textbox_STDEditor.SelectionStart;            textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "(");            textbox_STDEditor.Focus();            textbox_STDEditor.Select(index + 1, 0);            textbox_STDEditor.ScrollToCaret();        }        private void button_RightParenthesis_Click(object sender, EventArgs e)        {            int index = textbox_STDEditor.SelectionStart;            textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, ")");            textbox_STDEditor.Focus();            textbox_STDEditor.Select(index + 1, 0);            textbox_STDEditor.ScrollToCaret();        }        private void button_Equal_Click(object sender, EventArgs e)        {            int index = textbox_STDEditor.SelectionStart;            textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "=");            textbox_STDEditor.Focus();            textbox_STDEditor.Select(index + 1, 0);            textbox_STDEditor.ScrollToCaret();        }        //除选中点以外其它节点前景色置灰        private void SetGrayExceptSelectedNode(TreeView Tree, TreeNode SelectedNode)        {            foreach (TreeNode node in Tree.Nodes)            {                if (node != SelectedNode)                {                    node.ForeColor = Color.Gray;                }            }        }        //恢复所有节点颜色为可用        private void SetBlackAllNodes(TreeView Tree)        {            foreach (TreeNode node in Tree.Nodes)            {                node.ForeColor = Color.Black;            }        }        //删除        private void DeleteTreeNode_Click(object sender, EventArgs e)        {            try            {                TreeView XmlTree = (TreeView)XmlTreeMenuStrip.SourceControl;                if (XmlTree.SelectedNode != null)                {                    if (XmlTree != null)                    {                         if (XmlTree.SelectedNode.NextNode != null)                        {                            TreeNode Temp = XmlTree.SelectedNode.NextNode;                            XmlTree.SelectedNode.Remove();                            XmlTree.SelectedNode = Temp;                        }                        else if (XmlTree.SelectedNode.PrevNode != null)                        {                            TreeNode Temp = XmlTree.SelectedNode.PrevNode;                            XmlTree.SelectedNode.Remove();                            XmlTree.SelectedNode = Temp;                        }                        else                         {                            XmlTree.SelectedNode.Remove();                            XmlTree.SelectedNode = null;                            if (XmlTree.Name == "XmlTree_MaxEDSRules")                            {                                textbox_STDEditor.Text = "";                                textBox_MaxEDSTime.Text = "";                            }                        }                    }                }                else                {                    MessageBox.Show("No nodes are selected!", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);                }            }            catch (Exception ex)            {                MessageBox.Show(ex.ToString(), "Tip");            }        }        //新建        private void AddTreeNode_Click(object sender, EventArgs e)        {            try            {                if (XmlTree_MaxEDSRules.SelectedNode != null)                {                    //判断MaxEDSTime                    double dMaxEDSTime = 0;                    if (!double.TryParse(textBox_MaxEDSTime.Text, out dMaxEDSTime) || double.Parse(textBox_MaxEDSTime.Text) <= 0)                    {                        MessageBox.Show("The MaxEDSTime of current selected node input error, please enter the correct format!", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);                        return;                    }                    //判断textbox_STDEditor                    if (!Checktextbox_STDEditor())                    {                        return;                    }                    XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text;                }                TreeNode new_child = new TreeNode();//定义一个TreeNode节点对象                TreeView XmlTree = (TreeView)XmlTreeMenuStrip.SourceControl;                                if (XmlTreeMenuStrip.SourceControl.Name == "XmlTree_MaxEDSRules")                {                    int Number = XmlTree.Nodes.Count;                    for (int num = 0; num < XmlTree.Nodes.Count; num++)                    {                        string aa = XmlTree.Nodes[num].Text.ToString().Substring(XmlTree.Nodes[num].Text.Length - 1, 1);                        int tp = int.Parse(XmlTree.Nodes[num].Text.ToString().Substring(XmlTree.Nodes[num].Text.Length - 1, 1));                        if (Number < tp) Number = tp;                    }                    new_child.Text = "Rule" + Number.ToString();                    new_child.Tag = "NewRules";                    textbox_STDEditor.Text = "NewRules";                }                                XmlTree.Nodes.Add(new_child);                XmlTree.SelectedNode = null;                XmlTree.SelectedNode = new_child;            }            catch (Exception ex)            {                MessageBox.Show(ex.ToString(), "Tip");            }        }        void SaveXmlTreeDataToMaxEDSRules(string DBAddress)        {            System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + DBAddress + "'");            m_dbConnection.Open();            System.Data.SQLite.SQLiteCommand cmm = m_dbConnection.CreateCommand();            cmm.CommandText = "delete from MaxEDSRules";            try            {                cmm.ExecuteNonQuery();            }            catch (Exception ex)            {                MessageBox.Show(ex.ToString());            }            System.Data.SQLite.SQLiteDataAdapter m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select * from MaxEDSRules", m_dbConnection);            System.Data.SQLite.SQLiteCommandBuilder qLiteCommandBuilder = new System.Data.SQLite.SQLiteCommandBuilder(m_dataAdapter);            DataSet ds = new DataSet();            m_dataAdapter.Fill(ds, "MaxEDSRules");            DataTable dt = ds.Tables["MaxEDSRules"];            dt.Clear();            for (int num = 0; num < XmlTree_MaxEDSRules.Nodes.Count; num++)            {                string UsingElementList = "";                string UsingImgPropertyList = "";                string UsingOtherPropertyList = "";                List<string> UsingElementL = new List<string>();                List<string> UsingImgPropertyL = new List<string>();                List<string> UsingOtherPropertyL = new List<string>();                string str_RemoveBlank = "";                //forth_elem干扰or分隔符,故先行去掉                if (XmlTree_MaxEDSRules.Nodes[num].Tag.ToString().Contains("forth_elem"))                {                    str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");                    UsingOtherPropertyList = "forth_elem,";                }                str_RemoveBlank = XmlTree_MaxEDSRules.Nodes[num].Tag.ToString().Replace(" ", "");                string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);                List<string> str_Removeandor = new List<string>();                for (int i = 0; i < str_Removeand.Length; i++)                {                    str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));                }                List<string> list_all = new List<string>();                for (int i = 0; i < str_Removeandor.Count; i++)                {                    list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));                }                for (int i = 0; i < list_all.Count; i++)                {                    //周期元素?                    if (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))                    {                        if (!UsingElementL.Contains(list_all[i]))                        {                            UsingElementL.Add(list_all[i]);                        }                    }                    //first_elem?                    if (this.comboBox_Elem1.Items.Contains(list_all[i]))                    {                        if (!UsingOtherPropertyL.Contains(list_all[i]))                        {                            UsingOtherPropertyL.Add(list_all[i]);                        }                    }                    //Element1?                    if (this.comboBox_Elem.Items.Contains(list_all[i]))                    {                        if (!UsingOtherPropertyL.Contains(list_all[i]))                        {                            UsingOtherPropertyL.Add(list_all[i]);                        }                    }                    //其它元素?                    if (this.comboBox_ImgProperty.Items.Contains(list_all[i]))                    {                        if (!UsingImgPropertyL.Contains(list_all[i]))                        {                            UsingImgPropertyL.Add(list_all[i]);                        }                    }                }                if (UsingElementL.Count > 0)                {                    for (int i = 0; i < UsingElementL.Count - 1; i++)                    {                        UsingElementList += UsingElementL[i] + ",";                    }                    UsingElementList += UsingElementL[UsingElementL.Count - 1];                }                if (UsingImgPropertyL.Count > 0)                {                    for (int i = 0; i < UsingImgPropertyL.Count - 1; i++)                    {                        UsingImgPropertyList += UsingImgPropertyL[i] + ",";                    }                    UsingImgPropertyList += UsingImgPropertyL[UsingImgPropertyL.Count - 1];                }                if (UsingOtherPropertyL.Count > 0)                {                    for (int i = 0; i < UsingOtherPropertyL.Count - 1; i++)                    {                        UsingOtherPropertyList += UsingOtherPropertyL[i] + ",";                    }                    UsingOtherPropertyList += UsingOtherPropertyL[UsingOtherPropertyL.Count - 1];                }                DataRow newRow = dt.NewRow();                newRow["MaxEDSTime"] = int.Parse(textBox_MaxEDSTime.Text);                newRow["UsingElementList"] = UsingElementList;                newRow["UsingImgPropertyList"] = UsingImgPropertyList;                newRow["UsingOtherPropertyList"] = UsingOtherPropertyList;                newRow["Expression"] = XmlTree_MaxEDSRules.Nodes[num].Tag;                dt.Rows.Add(newRow);            }            m_dataAdapter.Update(ds, "MaxEDSRules");            m_dbConnection.Close();            MessageBox.Show("Save successful!", "Tip");        }        //元素周期表开关        private void PeriodicTableSwitch_Click(object sender, EventArgs e)        {            //if (PeriodicTableSwitch.BackColor == SystemColors.Control)            //{            //    //this.Resize -= new System.EventHandler(this.Form_MaxEDSRules_Resize);            //    panel_OTSPeriodicTable.Visible = false;            //    this.Width = this.Width - panel_OTSPeriodicTable.Width;            //    //this.Resize += new System.EventHandler(this.Form_MaxEDSRules_Resize);            //    PeriodicTableSwitch.BackColor = SystemColors.ControlDark;            //    //if (Language == "English")            //    //{            //    //    PeriodicTableSwitch.Text = "Close PeriodicTable";            //    //}            //    //else if(Language == "Chinese")            //    //{            //    //    PeriodicTableSwitch.Text = "关闭元素周期表";            //    //}            //}            //else if (PeriodicTableSwitch.BackColor == SystemColors.ControlDark)            //{            //    //this.Resize -= new System.EventHandler(this.Form_MaxEDSRules_Resize);            //    //this.Width = this.Width + panel_OTSPeriodicTable.Width + 5;            //    panel_OTSPeriodicTable.Visible = true;            //    //this.Resize += new System.EventHandler(this.Form_MaxEDSRules_Resize);            //    PeriodicTableSwitch.BackColor = SystemColors.Control;            //    //if (Language == "English")            //    //{            //    //    PeriodicTableSwitch.Text = "Open PeriodicTable";            //    //}            //    //else if (Language == "Chinese")            //    //{            //    //    PeriodicTableSwitch.Text = "打开元素周期表";            //    //}            //    //textbox_STDEditor.Focus();            //    groupBox_CalculatingSymbols.Focus();            //}            if (form_PeriodicTable == null)            {                form_PeriodicTable = new Form_PeriodicTable();                form_PeriodicTable.Show();                form_PeriodicTable.Location = new Point(this.Location.X + this.Width - 14, this.Location.Y);            }            else            {                if (form_PeriodicTable.IsDisposed)                {                    form_PeriodicTable = new Form_PeriodicTable();                    form_PeriodicTable.Show();                    form_PeriodicTable.Location = new Point(this.Location.X + this.Width - 14, this.Location.Y);                }                else                {                    form_PeriodicTable.Activate();                }            }        }        private void button_Ok_Click(object sender, EventArgs e)        {            if (XmlTree_MaxEDSRules.SelectedNode != null)            {                //判断MaxEDSTime                double dMaxEDSTime = 0;                if (!double.TryParse(textBox_MaxEDSTime.Text, out dMaxEDSTime) || double.Parse(textBox_MaxEDSTime.Text) <= 0)                {                    textBox_MaxEDSTime.Focus();                    textBox_MaxEDSTime.SelectAll();                    MessageBox.Show("The Item of MaxEDSTime input error, please enter the correct format!", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);                    return;                }                //判断textbox_STDEditor                if (!Checktextbox_STDEditor())                {                    return;                }                XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text;                //XmlTree_MaxEDSRules.SelectedNode.Name = textBox_MaxEDSTime.Text;            }            SaveXmlTreeDataToMaxEDSRules(STDDBAddress);            this.Close();         }        private void button_Cancel_Click(object sender, EventArgs e)        {            this.Close();        }        //元素下拉选择输入        private void comboBox_PeriodicTable_SelectedIndexChanged(object sender, EventArgs e)        {            if (comboBox_PeriodicTable.Text != null && comboBox_PeriodicTable.SelectedItem != null)            {                string newStr = comboBox_PeriodicTable.SelectedItem.ToString();                comboBox_PeriodicTable.Text = null;                int index = textbox_STDEditor.SelectionStart;                textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);                textbox_STDEditor.Focus();                textbox_STDEditor.Select(index + newStr.Length, 0);                textbox_STDEditor.ScrollToCaret();            }        }        //元素自身text按回车键输入        private void comboBox_PeriodicTable_KeyDown(object sender, KeyEventArgs e)        {            if (e.KeyValue == 13)            {                if (comboBox_PeriodicTable.Text != null && comboBox_PeriodicTable.Text != "")                {                    this.textbox_STDEditor.Text += comboBox_PeriodicTable.Text.ToString();                    comboBox_PeriodicTable.Text = null;                }            }        }        //表达式规则检查        private bool Checktextbox_STDEditor()        {            if (textbox_STDEditor.Text == "" || textbox_STDEditor.Text == null)            {                textBox_MaxEDSTime.Focus();                MessageBox.Show("The content of Standard library cannot be empty!", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);                return false;            }            string str_RemoveBlank = textbox_STDEditor.Text.ToString().Replace(" ", "");            str_RemoveBlank = str_RemoveBlank.Replace("\r\n", "");            //分割符号检验            string[] Symbol = { "and", "or", "+", "-", "*", "/", "=", ">", "<" };            for (int i = 0; i < Symbol.Length; i++)            {                for (int j = 0; j < Symbol.Length; j++)                {                    if ((Symbol[i] + Symbol[j]) != ">=" && (Symbol[i] + Symbol[j]) != "<=")                    {                        if (str_RemoveBlank.Contains(Symbol[i] + Symbol[j]))                        {                            MessageBox.Show("Invalid string exists:" + Symbol[i] + Symbol[j], "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);                            return false;                        }                    }                }                if (str_RemoveBlank.Contains(Symbol[i] + ")") || str_RemoveBlank.Contains("(" + Symbol[i]))                {                    MessageBox.Show("Invalid string exists:" + Symbol[i] + ")", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);                    return false;                }                if (str_RemoveBlank.Contains("(" + Symbol[i]))                {                    MessageBox.Show("Invalid string exists:" + "(" + Symbol[i], "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);                    return false;                }            }            if ((str_RemoveBlank != null) && (str_RemoveBlank != ""))            {                //左右括号匹配检验                int BracketsNum = 0;                for (int i = 0; i < str_RemoveBlank.Length; i++)                {                    if (str_RemoveBlank[i] == '(') BracketsNum++;                    if (str_RemoveBlank[i] == ')') BracketsNum--;                }                if (BracketsNum != 0)                {                    MessageBox.Show("Number of left and right parentheses does not match!", "Tip", MessageBoxButtons.OK,MessageBoxIcon.Information);                    return false;                }                //首字符检测                if ((str_RemoveBlank[0] == '+') || (str_RemoveBlank[0] == '-') || (str_RemoveBlank[0] == '*') || (str_RemoveBlank[0] == '/') || (str_RemoveBlank[0] == '>') || (str_RemoveBlank[0] == '<') || (str_RemoveBlank[0] == '=') || (str_RemoveBlank[0] == ')') || (str_RemoveBlank[str_RemoveBlank.Length - 1] == '('))                {                    MessageBox.Show("First character is error!", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);                    return false;                }                if (str_RemoveBlank.Length >= 3)                {                    if ((str_RemoveBlank.Substring(0, 3) == "and") || (str_RemoveBlank.Substring(0, 3) == "end"))                    {                        MessageBox.Show("First character is error!", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);                        return false;                    }                }            }            //forth_elem干扰or分隔符,故先行去掉            str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");            string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);            List<string> str_Removeandor = new List<string>();            for (int i = 0; i < str_Removeand.Length; i++)            {                str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));            }            List<string> list_all = new List<string>();            for (int i = 0; i < str_Removeandor.Count; i++)            {                list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));            }            //常量            List<string> Constantslist = new List<string>();            for (int j = 0; j < comboBox_Constants.Items.Count; j++)            {                Constantslist.Add(comboBox_Constants.Items[j].ToString().Split('=')[0]);            }            for (int i = 0; i < list_all.Count; i++)            {                //周期元素?                if (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))                {                    continue;                }                //first_elem?                if (this.comboBox_Elem1.Items.Contains(list_all[i]))                {                    continue;                }                //Element1?                if (this.comboBox_Elem.Items.Contains(list_all[i]))                {                    continue;                }                //其它元素?                if (this.comboBox_ImgProperty.Items.Contains(list_all[i]))                {                    continue;                }                //常量?                if (Constantslist.Contains(list_all[i]))                {                    continue;                }                //数字?                double DNum = 0;                if (double.TryParse(list_all[i], out DNum))                {                    continue;                }                //>=? <=?等其它情况                if (list_all[i] == "")                {                    continue;                }                //true false?                if ((list_all[i] == "true") || (list_all[i] == "false"))                {                    continue;                }                MessageBox.Show("Please check whether the input rules are correct, error characters:" + list_all[i], "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);                return false;            }            //检测是否有<>= true,false            if (!textbox_STDEditor.Text.ToString().Contains("<") && !textbox_STDEditor.Text.ToString().Contains(">") && !textbox_STDEditor.Text.ToString().Contains("=")&& textbox_STDEditor.Text.ToString()!="true"&& textbox_STDEditor.Text.ToString() != "false")            {                MessageBox.Show("Expressions have no effect!", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);                return false;            }            return true;        }                private void button_And_Click(object sender, EventArgs e)        {            //textbox_STDEditor 中的光标            int index = textbox_STDEditor.SelectionStart;            textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "and");            textbox_STDEditor.Focus();            textbox_STDEditor.Select(index + 3, 0);            textbox_STDEditor.ScrollToCaret();        }        private void button_Or_Click(object sender, EventArgs e)        {            //textbox_STDEditor 中的光标            int index = textbox_STDEditor.SelectionStart;            textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "or");            textbox_STDEditor.Focus();            textbox_STDEditor.Select(index + 2, 0);            textbox_STDEditor.ScrollToCaret();        }        private void comboBox_Constants_SelectedIndexChanged(object sender, EventArgs e)        {                if (comboBox_Constants.SelectedItem != null)                {                     string newStr = comboBox_Constants.SelectedItem.ToString().Split('=')[0];                    int index = textbox_STDEditor.SelectionStart;                    textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, newStr);                    textbox_STDEditor.Focus();                    textbox_STDEditor.Select(index + newStr.Length, 0);                    textbox_STDEditor.ScrollToCaret();                }        }        private void button_Recover_Click(object sender, EventArgs e)        {            XmlDocument doc = new XmlDocument();            try            {                //System.IO.File.Copy(Address_backup, Address, true);                //doc.Load(Address_backup);                //LoadXmlToTreeControl(doc, XmlTree_MaxEDSRules.Nodes);                XmlTree_MaxEDSRules.Nodes.Clear();                string STDDBAddress_backup = "";                string[] files = System.IO.Directory.GetFiles(STDDBAddress_backupDirectory);//得到文件                foreach (var file in files)                {                    if (".db".IndexOf(file.Substring(file.LastIndexOf(".") + 1)) > -1)                    {                        STDDBAddress_backup = file;                    }                }                LoadMaxEDSRulesToTreeControl(STDDBAddress_backup, XmlTree_MaxEDSRules.Nodes);                XmlTree_MaxEDSRules.Focus();                if (XmlTree_MaxEDSRules.Nodes.Count > 0)                {                    XmlTree_MaxEDSRules.SelectedNode = XmlTree_MaxEDSRules.Nodes[0];                    XmlTree_MaxEDSRules_AfterSelect(XmlTree_MaxEDSRules, new TreeViewEventArgs(XmlTree_MaxEDSRules.SelectedNode));                }                else                {                    textbox_STDEditor.Text = "";                    textBox_MaxEDSTime.Text = "";                }            }            catch(Exception ex)            {                MessageBox.Show("Recovery failed!" + "\n"+ex.Message.ToString(), "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);            }        }        private bool CheckConstants(string ConstantName)        {                        for (int num = 0; num < XmlTree_MaxEDSRules.Nodes.Count; num++)            {                if (XmlTree_MaxEDSRules.Nodes[num].Tag.ToString().Contains(ConstantName))                {                    XmlTree_MaxEDSRules.SelectedNode = XmlTree_MaxEDSRules.Nodes[num];                    SetGrayExceptSelectedNode(XmlTree_MaxEDSRules, XmlTree_MaxEDSRules.SelectedNode);                    DialogResult result = MessageBox.Show("Closing failed," + XmlTree_MaxEDSRules.Nodes[num].Text + table["message28"].ToString(), "Tip", MessageBoxButtons.OK, MessageBoxIcon.Warning);                    return false;                }            }                        return true;        }        private void XmlTree_MaxEDSRules_AfterSelect(object sender, TreeViewEventArgs e)        {            SetBlackAllNodes(XmlTree_MaxEDSRules);            this.textbox_STDEditor.Text = XmlTree_MaxEDSRules.SelectedNode.Tag.ToString();        }        private void XmlTree_MaxEDSRules_BeforeSelect(object sender, TreeViewCancelEventArgs e)        {            if (XmlTree_MaxEDSRules.SelectedNode != null)            {                if (!Checktextbox_STDEditor())                {                    SetGrayExceptSelectedNode(XmlTree_MaxEDSRules, XmlTree_MaxEDSRules.SelectedNode);                    e.Cancel = true;                    return;                }                XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text;            }        }        private void textbox_STDEditor_Leave(object sender, EventArgs e)        {            XmlTree_MaxEDSRules.Focus();        }        		 #region  为配合textbox_STDEditor_Leave时事件,点击其它groupbox组件时使焦点转移        private void Form_ConstantsEditor_Click(object sender, EventArgs e)        {            groupBox_XmlTree_MaxEDSRules.Focus();        }        private void groupBox_Data_Click(object sender, EventArgs e)        {            groupBox_Data.Focus();        }        private void groupBox_ChemicalElement_Click(object sender, EventArgs e)        {            groupBox_ChemicalElement.Focus();        }        private void groupBox_OtherCommonlyUsedSymbols_Click(object sender, EventArgs e)        {            groupBox_OtherCommonlyUsedSymbols.Focus();        }        private void groupBox_CalculatingSymbols_Click(object sender, EventArgs e)        {            groupBox_CalculatingSymbols.Focus();        }        private void groupBox_XmlTree_MaxEDSRules_Click(object sender, EventArgs e)        {            groupBox_XmlTree_MaxEDSRules.Focus();        }        #endregion        private void button_1_Click(object sender, EventArgs e)        {            //textbox_STDEditor 中的光标            int index = textbox_STDEditor.SelectionStart;            textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "1");            textbox_STDEditor.Focus();            textbox_STDEditor.Select(index + 1, 0);            textbox_STDEditor.ScrollToCaret();        }        private void button_2_Click(object sender, EventArgs e)        {            //textbox_STDEditor 中的光标            int index = textbox_STDEditor.SelectionStart;            textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "2");            textbox_STDEditor.Focus();            textbox_STDEditor.Select(index + 1, 0);            textbox_STDEditor.ScrollToCaret();        }        private void button_3_Click(object sender, EventArgs e)        {            //textbox_STDEditor 中的光标            int index = textbox_STDEditor.SelectionStart;            textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "3");            textbox_STDEditor.Focus();            textbox_STDEditor.Select(index + 1, 0);            textbox_STDEditor.ScrollToCaret();        }        private void button_4_Click(object sender, EventArgs e)        {            //textbox_STDEditor 中的光标            int index = textbox_STDEditor.SelectionStart;            textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "4");            textbox_STDEditor.Focus();            textbox_STDEditor.Select(index + 1, 0);            textbox_STDEditor.ScrollToCaret();        }        private void button_5_Click(object sender, EventArgs e)        {            //textbox_STDEditor 中的光标            int index = textbox_STDEditor.SelectionStart;            textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "5");            textbox_STDEditor.Focus();            textbox_STDEditor.Select(index + 1, 0);            textbox_STDEditor.ScrollToCaret();        }        private void button_6_Click(object sender, EventArgs e)        {            //textbox_STDEditor 中的光标            int index = textbox_STDEditor.SelectionStart;            textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "6");            textbox_STDEditor.Focus();            textbox_STDEditor.Select(index + 1, 0);            textbox_STDEditor.ScrollToCaret();        }        private void button_7_Click(object sender, EventArgs e)        {            //textbox_STDEditor 中的光标            int index = textbox_STDEditor.SelectionStart;            textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "7");            textbox_STDEditor.Focus();            textbox_STDEditor.Select(index + 1, 0);            textbox_STDEditor.ScrollToCaret();        }        private void button_8_Click(object sender, EventArgs e)        {            //textbox_STDEditor 中的光标            int index = textbox_STDEditor.SelectionStart;            textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "8");            textbox_STDEditor.Focus();            textbox_STDEditor.Select(index + 1, 0);            textbox_STDEditor.ScrollToCaret();        }        private void button_9_Click(object sender, EventArgs e)        {            //textbox_STDEditor 中的光标            int index = textbox_STDEditor.SelectionStart;            textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "9");            textbox_STDEditor.Focus();            textbox_STDEditor.Select(index + 1, 0);            textbox_STDEditor.ScrollToCaret();        }        private void button_0_Click(object sender, EventArgs e)        {            int index = textbox_STDEditor.SelectionStart;            textbox_STDEditor.Text = textbox_STDEditor.Text.Insert(index, "0");            textbox_STDEditor.Focus();            textbox_STDEditor.Select(index + 1, 0);            textbox_STDEditor.ScrollToCaret();        }        //private float X = 1;        //private float Y = 1;        //float AmplificationFactor = 1;        private void Form_MaxEDSRules_Resize(object sender, EventArgs e)        {            //float newx = this.Width / X;            //float newy = this.Height / Y;            //AmplificationFactor = newy;            //setControls(newx, newy, this);            //this.Resize -= new System.EventHandler(this.Form_MaxEDSRules_Resize);            //if (panel_OTSPeriodicTable.Visible == false)            //{            //    int w = this.Width - panel_OTSPeriodicTable.Width;            //    this.Width = w;            //}            //this.Resize += new System.EventHandler(this.Form_MaxEDSRules_Resize);            ////if (WindowState == FormWindowState.Maximized)            ////{            ////    panel_OTSPeriodicTable.Visible = true;            ////    PeriodicTableSwitch.Enabled = false;            ////}        }        private void setTag(Control cons)        {            foreach (Control con in cons.Controls)            {                con.Tag = con.Width + ":" + con.Height + ":" + con.Left + ":" + con.Top + ":" + con.Font.Size;                if (con.Controls.Count > 0)                    setTag(con);            }        }        private void setControls(float newx, float newy, Control cons)        {            foreach (Control con in cons.Controls)            {                if (false)                {                }                else                {                    string[] mytag = con.Tag.ToString().Split(':');                    float a = Convert.ToSingle(mytag[0]) * newx;                    con.Width = (int)a;                    a = Convert.ToSingle(mytag[1]) * newy;                    con.Height = (int)(a);                    a = Convert.ToSingle(mytag[2]) * newx;                    con.Left = (int)(a);                    a = Convert.ToSingle(mytag[3]) * newy;                    con.Top = (int)(a);                    Single currentSize;                    if (con.GetType().ToString() == "System.Windows.Forms.Label")                    {                        currentSize = Convert.ToSingle(mytag[4]) * ((newx + newy) / 2);                        //currentSize = 6f;                    }                    else                    {                        if (Math.Max(newx, newy) < 1)                        {                            currentSize = Convert.ToSingle(mytag[4]) * 1;                        }                        else                        {                            currentSize = Convert.ToSingle(mytag[4]) * Math.Max(newx, newy);                        }                    }                    con.Font = new Font(con.Font.Name, currentSize, con.Font.Style, con.Font.Unit);                    if (con.Controls.Count > 0)                    {                        setControls(newx, newy, con);                    }                }            }        }        #region        //XmlDocument doc = new XmlDocument();        //doc.Load(Address);        //LoadXmlToTreeControl(doc,XmlTree_MaxEDSRules.Nodes);        //public string Language = "English";        //string Address_backup = Application.StartupPath + "\\Config\\SysData\\OTSParticleSTD_backup.xml";        //string Address = Application.StartupPath + "\\Config\\SysData\\OTSParticleSTD.xml";        //保存xmltree内容到xml文件        //void SaveXmlTreeDataToXml(string Address)        //{        //    XDocument xdoc = XDocument.Load(Address);        //    IEnumerable<XElement> elements = from ele in xdoc.Descendants("XMLData") select ele;        //    var item = (from ele1 in elements.Elements("Collection")        //                where ele1.Attribute("RegName").Value.Equals("MaxEDSRules")        //                select ele1).FirstOrDefault();        //    if (item != null)        //    {        //        item.Remove();        //    }        //    XElement MaxEDS = new XElement("Collection");        //    MaxEDS.SetAttributeValue("RegName", "MaxEDSRules");        //    elements.ElementAt(0).Add(MaxEDS);        //    for (int num = 0; num < XmlTree_MaxEDSRules.Nodes.Count; num++)        //    {        //        string UsingElementList = "";        //        string UsingImgPropertyList = "";        //        string UsingOtherPropertyList = "";        //        List<string> UsingElementL = new List<string>();        //        List<string> UsingImgPropertyL = new List<string>();        //        List<string> UsingOtherPropertyL = new List<string>();        //        string str_RemoveBlank = "";        //        //forth_elem干扰or分隔符,故先行去掉        //        if (XmlTree_MaxEDSRules.Nodes[num].Tag.ToString().Contains("forth_elem"))        //        {        //            str_RemoveBlank = str_RemoveBlank.Replace("forth_elem", "");        //            UsingOtherPropertyList = "forth_elem,";        //        }        //        str_RemoveBlank = XmlTree_MaxEDSRules.Nodes[num].Tag.ToString().Replace(" ", "");        //        string[] str_Removeand = System.Text.RegularExpressions.Regex.Split(str_RemoveBlank, "and", System.Text.RegularExpressions.RegexOptions.None);        //        List<string> str_Removeandor = new List<string>();        //        for (int i = 0; i < str_Removeand.Length; i++)        //        {        //            str_Removeandor.AddRange(System.Text.RegularExpressions.Regex.Split(str_Removeand[i], "or", System.Text.RegularExpressions.RegexOptions.None));        //        }        //        List<string> list_all = new List<string>();        //        for (int i = 0; i < str_Removeandor.Count; i++)        //        {        //            list_all.AddRange(str_Removeandor[i].Split(new char[] { '+', '-', '*', '/', '=', '>', '<', '(', ')' }));        //        }        //        for (int i = 0; i < list_all.Count; i++)        //        {        //            //周期元素?        //            if (this.comboBox_PeriodicTable.Items.Contains(list_all[i]))        //            {        //                if (!UsingElementL.Contains(list_all[i]))        //                {        //                    UsingElementL.Add(list_all[i]);        //                }        //            }        //            //first_elem?        //            if (this.comboBox_Elem1.Items.Contains(list_all[i]))        //            {        //                if (!UsingOtherPropertyL.Contains(list_all[i]))        //                {        //                    UsingOtherPropertyL.Add(list_all[i]);        //                }        //            }        //            //Element1?        //            if (this.comboBox_Elem.Items.Contains(list_all[i]))        //            {        //                if (!UsingOtherPropertyL.Contains(list_all[i]))        //                {        //                    UsingOtherPropertyL.Add(list_all[i]);        //                }        //            }        //            //其它元素?        //            if (this.comboBox_ImgProperty.Items.Contains(list_all[i]))        //            {        //                if (!UsingImgPropertyL.Contains(list_all[i]))        //                {        //                    UsingImgPropertyL.Add(list_all[i]);        //                }        //            }        //        }        //        if (UsingElementL.Count > 0)        //        {        //            for (int i = 0; i < UsingElementL.Count - 1; i++)        //            {        //                UsingElementList += UsingElementL[i] + ",";        //            }        //            UsingElementList += UsingElementL[UsingElementL.Count - 1];        //        }        //        if (UsingImgPropertyL.Count > 0)        //        {        //            for (int i = 0; i < UsingImgPropertyL.Count - 1; i++)        //            {        //                UsingImgPropertyList += UsingImgPropertyL[i] + ",";        //            }        //            UsingImgPropertyList += UsingImgPropertyL[UsingImgPropertyL.Count - 1];        //        }        //        if (UsingOtherPropertyL.Count > 0)        //        {        //            for (int i = 0; i < UsingOtherPropertyL.Count - 1; i++)        //            {        //                UsingOtherPropertyList += UsingOtherPropertyL[i] + ",";        //            }        //            UsingOtherPropertyList += UsingOtherPropertyL[UsingOtherPropertyL.Count - 1];        //        }        //        XElement EleName = new XElement("Member");        //        //EleName.SetAttributeValue("MaxEDSTime", XmlTree_MaxEDSRules.Nodes[num].Name);        //        EleName.SetAttributeValue("MaxEDSTime", textBox_MaxEDSTime.Text);        //        EleName.SetAttributeValue("UsingElementList", UsingElementList);        //        EleName.SetAttributeValue("UsingImgPropertyList", UsingImgPropertyList);        //        EleName.SetAttributeValue("UsingOtherPropertyList", UsingOtherPropertyList);        //        EleName.SetAttributeValue("Expression", XmlTree_MaxEDSRules.Nodes[num].Tag);        //        MaxEDS.Add(EleName);        //    }        //    xdoc.Save(Address);        //}        //private void button_Backup_Click(object sender, EventArgs e)        //{        //    if (XmlTree_MaxEDSRules.SelectedNode != null)        //    {        //        //判断MaxEDSTime        //        double dMaxEDSTime = 0;        //        if (!double.TryParse(textBox_MaxEDSTime.Text, out dMaxEDSTime) || double.Parse(textBox_MaxEDSTime.Text) <= 0)        //        {        //            textBox_MaxEDSTime.Focus();        //            textBox_MaxEDSTime.SelectAll();        //            MessageBox.Show(table["message16"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);        //            return;        //        }        //        //判断textbox_STDEditor        //        if (!Checktextbox_STDEditor())        //        {        //            return;        //        }        //        XmlTree_MaxEDSRules.SelectedNode.Tag = this.textbox_STDEditor.Text;        //        //XmlTree_MaxEDSRules.SelectedNode.Name = textBox_MaxEDSTime.Text;        //    }        //    try        //    {        //        SaveFileDialog saveFile = new SaveFileDialog();        //        saveFile.Title = table["message23"].ToString();        //        saveFile.Filter = table["message24"].ToString();        //        saveFile.OverwritePrompt = true;  //是否覆盖当前文件        //        saveFile.RestoreDirectory = true;  //还原上次目录        //        if (saveFile.ShowDialog() == DialogResult.OK)        //        {        //            System.IO.File.Copy(Address, saveFile.FileName, true);        //            SaveXmlTreeDataToXml(saveFile.FileName);        //            MessageBox.Show(table["message25"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);        //        }        //        else        //        {        //            return;        //        }        //    }        //    catch (Exception ex)        //    {        //        MessageBox.Show(ex.Message);        //    }        //}        #endregion        private void Form_MaxEDSRules_FormClosing(object sender, FormClosingEventArgs e)        {            if (form_PeriodicTable != null)            {                form_PeriodicTable.Close();            }        }    }}
 |