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_UserConstants : Form { //国际化 Language lan; System.Collections.Hashtable table; string STDDBAddress = Application.StartupPath + "\\Config\\SysData\\" + "OTSCleanlinesSTD.db"; public Form_UserConstants(string DBAddress) { InitializeComponent(); STDDBAddress = DBAddress; } private void Form_UserConstants_Load(object sender, EventArgs e) { 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; lan = new Language(this); table = lan.GetNameTable("Form_UserConstants"); LoadXmlConstantsTreeControl(STDDBAddress); this.DialogResult = DialogResult.None; } void LoadXmlConstantsTreeControl(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(); } m_dbConnection.Close(); ConstantsStr = ConstantsStr.Replace(" ", ""); string[] ConstantsStr2 = ConstantsStr.Split(','); List comboBox_Constants = new List(); comboBox_Constants.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]; } } } catch (Exception ee) { MessageBox.Show(ee.ToString()); } } private void button_UpdateConstants_Click(object sender, EventArgs e) { List Constantslist = new List(); for (int i = 0; i < 10; i++) { CheckBox checkBox = (CheckBox)this.groupBox1.Controls.Find("checkBox_" + i.ToString(), false)[0]; if (checkBox.Checked) { TextBox tBox = (TextBox)this.groupBox1.Controls.Find("textBox_" + i.ToString(), false)[0]; double DoubleTry = 0; if (double.TryParse(tBox.Text, out DoubleTry)) { Constantslist.Add(checkBox.Text + "=" + tBox.Text); } else { MessageBox.Show(table["message29"].ToString() + checkBox.Name + table["message30"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } } string value = ""; foreach (var str in Constantslist) { value += str + ","; } if (value != "") { value = value.Substring(0, value.Length - 1); } System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + STDDBAddress + "'"); System.Data.SQLite.SQLiteCommand cmm = m_dbConnection.CreateCommand(); cmm.CommandText = "delete from Constants"; try { m_dbConnection.Open(); cmm.ExecuteNonQuery(); string insertstr = "Insert into Constants(value)"; string aa = "values("+"'" + value + "'"+")"; cmm.CommandText = insertstr + aa; cmm.ExecuteNonQuery(); m_dbConnection.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } MessageBox.Show(table["message31"].ToString(), table["message32"].ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information); this.DialogResult = DialogResult.Yes; } private bool CheckConstantIsUseingInDB(string ConstantSysbol,string dbName) { 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 Expression from "+ dbName, m_dbConnection); //,MaxEDSRules,ZeroElementRules DataSet ds = new DataSet(); m_dataAdapter.Fill(ds); DataTable dt = ds.Tables[0]; if (dt != null) { if (dt.Rows.Count > 0) { foreach (DataRow item in dt.Rows) { if (item["Expression"].ToString().Contains(ConstantSysbol)) { return false; } } } } return true; } catch (Exception ee) { MessageBox.Show(ee.ToString()); return false; } } private bool CheckConstantIsUseing(string ConstantSysbol) { if (CheckConstantIsUseingInDB(ConstantSysbol, "ClassifySTD") && CheckConstantIsUseingInDB(ConstantSysbol, "MaxEDSRules") && CheckConstantIsUseingInDB(ConstantSysbol, "ZeroElementRules")) { return true; } else { MessageBox.Show(table["message1"].ToString(), table["message32"].ToString()); return false; } } private void checkBox_0_CheckedChanged(object sender, EventArgs e) { if (checkBox_0.Checked) { textBox_0.ReadOnly = false; } else { if (!CheckConstantIsUseing(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 (!CheckConstantIsUseing(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 (!CheckConstantIsUseing(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 (!CheckConstantIsUseing(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 (!CheckConstantIsUseing(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 (!CheckConstantIsUseing(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 (!CheckConstantIsUseing(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 (!CheckConstantIsUseing(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 (!CheckConstantIsUseing(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 (!CheckConstantIsUseing(checkBox_9.Text)) { checkBox_9.Checked = true; } else { textBox_9.ReadOnly = true; } } } #region //string Address_backup = Application.StartupPath + "\\Config\\SysData\\OTSParticleSTD_backup.xml"; //string Address = Application.StartupPath + "\\Config\\SysData\\OTSParticleSTD.xml"; //XmlDocument doc = new XmlDocument(); //doc.Load(Address); //LoadXmlToTreeControl(doc); //void LoadXmlToTreeControl(XmlDocument xml) //{ // XmlNode root = xml.SelectSingleNode("XMLData"); // XmlNodeList root2 = root.SelectNodes("Collection"); // XmlNode root3 = root.SelectSingleNode("Member"); // string ConstantsStr = root3.Attributes["value"].Value; // ConstantsStr = ConstantsStr.Replace(" ", ""); // string[] ConstantsStr2 = ConstantsStr.Split(','); // List comboBox_Constants = new List(); // comboBox_Constants.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]; // } // } //} #endregion } }