123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544 |
- 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<string> comboBox_Constants = new List<string>();
- comboBox_Constants.AddRange(ConstantsStr2);
- List<string> Constantslist = new List<string>();
- 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<string> Constantslist = new List<string>();
- 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("Symbol" + checkBox.Name + "Input error for corresponding value!", "Tip", 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("The library of constants updated successfully!", "Tip", 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("Failed to close. Applied to other rules!", "Tip");
- 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<string> comboBox_Constants = new List<string>();
- // comboBox_Constants.AddRange(ConstantsStr2);
- // List<string> Constantslist = new List<string>();
- // 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
- }
- }
|