Form_UserConstants.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Xml;
  11. using System.Xml.Linq;
  12. namespace OTSPartA_STDEditor
  13. {
  14. public partial class Form_UserConstants : Form
  15. {
  16. //国际化
  17. Language lan;
  18. System.Collections.Hashtable table;
  19. string STDDBAddress = Application.StartupPath + "\\Config\\SysData\\" + "OTSCleanlinesSTD.db";
  20. public Form_UserConstants(string DBAddress)
  21. {
  22. InitializeComponent();
  23. STDDBAddress = DBAddress;
  24. }
  25. private void Form_UserConstants_Load(object sender, EventArgs e)
  26. {
  27. checkBox_0.Checked = false;
  28. checkBox_1.Checked = false;
  29. checkBox_2.Checked = false;
  30. checkBox_3.Checked = false;
  31. checkBox_4.Checked = false;
  32. checkBox_5.Checked = false;
  33. checkBox_6.Checked = false;
  34. checkBox_7.Checked = false;
  35. checkBox_8.Checked = false;
  36. checkBox_9.Checked = false;
  37. textBox_0.ReadOnly = true;
  38. textBox_1.ReadOnly = true;
  39. textBox_2.ReadOnly = true;
  40. textBox_3.ReadOnly = true;
  41. textBox_4.ReadOnly = true;
  42. textBox_5.ReadOnly = true;
  43. textBox_6.ReadOnly = true;
  44. textBox_7.ReadOnly = true;
  45. textBox_8.ReadOnly = true;
  46. textBox_9.ReadOnly = true;
  47. lan = new Language(this);
  48. table = lan.GetNameTable("Form_UserConstants");
  49. LoadXmlConstantsTreeControl(STDDBAddress);
  50. this.DialogResult = DialogResult.None;
  51. }
  52. void LoadXmlConstantsTreeControl(string STDDBAddress)
  53. {
  54. try
  55. {
  56. System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + STDDBAddress + "'");
  57. m_dbConnection.Open();
  58. System.Data.SQLite.SQLiteDataAdapter m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select * from Constants", m_dbConnection);
  59. DataSet ds = new DataSet();
  60. m_dataAdapter.Fill(ds);
  61. DataTable dt = ds.Tables[0];
  62. string ConstantsStr = "";
  63. if (dt.Rows.Count >0)
  64. {
  65. ConstantsStr = dt.Rows[0][0].ToString();
  66. }
  67. m_dbConnection.Close();
  68. ConstantsStr = ConstantsStr.Replace(" ", "");
  69. string[] ConstantsStr2 = ConstantsStr.Split(',');
  70. List<string> comboBox_Constants = new List<string>();
  71. comboBox_Constants.AddRange(ConstantsStr2);
  72. List<string> Constantslist = new List<string>();
  73. for (int i = 0; i < ConstantsStr2.Length; i++)
  74. {
  75. Constantslist.AddRange(ConstantsStr2[i].Split('='));
  76. }
  77. for (int i = 0; i < Constantslist.Count; i += 2)
  78. {
  79. if (Constantslist[i].Contains("MAC#0"))
  80. {
  81. this.checkBox_0.Checked = true;
  82. this.textBox_0.ReadOnly = false;
  83. this.textBox_0.Text = Constantslist[i + 1];
  84. }
  85. else if (Constantslist[i].Contains("MAC#1"))
  86. {
  87. this.checkBox_1.Checked = true;
  88. this.textBox_1.ReadOnly = false;
  89. this.textBox_1.Text = Constantslist[i + 1];
  90. }
  91. else if (Constantslist[i].Contains("MAC#2"))
  92. {
  93. this.checkBox_2.Checked = true;
  94. this.textBox_2.ReadOnly = false;
  95. this.textBox_2.Text = Constantslist[i + 1];
  96. }
  97. else if (Constantslist[i].Contains("MAC#3"))
  98. {
  99. this.checkBox_3.Checked = true;
  100. this.textBox_3.ReadOnly = false;
  101. this.textBox_3.Text = Constantslist[i + 1];
  102. }
  103. else if (Constantslist[i].Contains("MAC#4"))
  104. {
  105. this.checkBox_4.Checked = true;
  106. this.textBox_4.ReadOnly = false;
  107. this.textBox_4.Text = Constantslist[i + 1];
  108. }
  109. else if (Constantslist[i].Contains("MAC#5"))
  110. {
  111. this.checkBox_5.Checked = true;
  112. this.textBox_5.ReadOnly = false;
  113. this.textBox_5.Text = Constantslist[i + 1];
  114. }
  115. else if (Constantslist[i].Contains("MAC#6"))
  116. {
  117. this.checkBox_6.Checked = true;
  118. this.textBox_6.ReadOnly = false;
  119. this.textBox_6.Text = Constantslist[i + 1];
  120. }
  121. else if (Constantslist[i].Contains("MAC#7"))
  122. {
  123. this.checkBox_7.Checked = true;
  124. this.textBox_7.ReadOnly = false;
  125. this.textBox_7.Text = Constantslist[i + 1];
  126. }
  127. else if (Constantslist[i].Contains("MAC#8"))
  128. {
  129. this.checkBox_8.Checked = true;
  130. this.textBox_8.ReadOnly = false;
  131. this.textBox_8.Text = Constantslist[i + 1];
  132. }
  133. else if (Constantslist[i].Contains("MAC#9"))
  134. {
  135. this.checkBox_9.Checked = true;
  136. this.textBox_9.ReadOnly = false;
  137. this.textBox_9.Text = Constantslist[i + 1];
  138. }
  139. }
  140. }
  141. catch (Exception ee)
  142. {
  143. MessageBox.Show(ee.ToString());
  144. }
  145. }
  146. private void button_UpdateConstants_Click(object sender, EventArgs e)
  147. {
  148. List<string> Constantslist = new List<string>();
  149. for (int i = 0; i < 10; i++)
  150. {
  151. CheckBox checkBox = (CheckBox)this.groupBox1.Controls.Find("checkBox_" + i.ToString(), false)[0];
  152. if (checkBox.Checked)
  153. {
  154. TextBox tBox = (TextBox)this.groupBox1.Controls.Find("textBox_" + i.ToString(), false)[0];
  155. double DoubleTry = 0;
  156. if (double.TryParse(tBox.Text, out DoubleTry))
  157. {
  158. Constantslist.Add(checkBox.Text + "=" + tBox.Text);
  159. }
  160. else
  161. {
  162. MessageBox.Show("Symbol" + checkBox.Name + "Input error for corresponding value!", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  163. return;
  164. }
  165. }
  166. }
  167. string value = "";
  168. foreach (var str in Constantslist)
  169. {
  170. value += str + ",";
  171. }
  172. if (value != "")
  173. {
  174. value = value.Substring(0, value.Length - 1);
  175. }
  176. System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + STDDBAddress + "'");
  177. System.Data.SQLite.SQLiteCommand cmm = m_dbConnection.CreateCommand();
  178. cmm.CommandText = "delete from Constants";
  179. try
  180. {
  181. m_dbConnection.Open();
  182. cmm.ExecuteNonQuery();
  183. string insertstr = "Insert into Constants(value)";
  184. string aa = "values("+"'" + value + "'"+")";
  185. cmm.CommandText = insertstr + aa;
  186. cmm.ExecuteNonQuery();
  187. m_dbConnection.Close();
  188. }
  189. catch (Exception ex)
  190. {
  191. MessageBox.Show(ex.ToString());
  192. }
  193. MessageBox.Show("The library of constants updated successfully!", "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
  194. this.DialogResult = DialogResult.Yes;
  195. }
  196. private bool CheckConstantIsUseingInDB(string ConstantSysbol,string dbName)
  197. {
  198. try
  199. {
  200. System.Data.SQLite.SQLiteConnection m_dbConnection = new System.Data.SQLite.SQLiteConnection("data source='" + STDDBAddress + "'");
  201. m_dbConnection.Open();
  202. System.Data.SQLite.SQLiteDataAdapter m_dataAdapter = new System.Data.SQLite.SQLiteDataAdapter("select Expression from "+ dbName, m_dbConnection); //,MaxEDSRules,ZeroElementRules
  203. DataSet ds = new DataSet();
  204. m_dataAdapter.Fill(ds);
  205. DataTable dt = ds.Tables[0];
  206. if (dt != null)
  207. {
  208. if (dt.Rows.Count > 0)
  209. {
  210. foreach (DataRow item in dt.Rows)
  211. {
  212. if (item["Expression"].ToString().Contains(ConstantSysbol))
  213. {
  214. return false;
  215. }
  216. }
  217. }
  218. }
  219. return true;
  220. }
  221. catch (Exception ee)
  222. {
  223. MessageBox.Show(ee.ToString());
  224. return false;
  225. }
  226. }
  227. private bool CheckConstantIsUseing(string ConstantSysbol)
  228. {
  229. if (CheckConstantIsUseingInDB(ConstantSysbol, "ClassifySTD") && CheckConstantIsUseingInDB(ConstantSysbol, "MaxEDSRules") && CheckConstantIsUseingInDB(ConstantSysbol, "ZeroElementRules"))
  230. {
  231. return true;
  232. }
  233. else
  234. {
  235. MessageBox.Show("Failed to close. Applied to other rules!", "Tip");
  236. return false;
  237. }
  238. }
  239. private void checkBox_0_CheckedChanged(object sender, EventArgs e)
  240. {
  241. if (checkBox_0.Checked)
  242. {
  243. textBox_0.ReadOnly = false;
  244. }
  245. else
  246. {
  247. if (!CheckConstantIsUseing(checkBox_0.Text))
  248. {
  249. checkBox_0.Checked = true;
  250. }
  251. else
  252. {
  253. textBox_0.ReadOnly = true;
  254. }
  255. }
  256. }
  257. private void checkBox_1_CheckedChanged(object sender, EventArgs e)
  258. {
  259. if (checkBox_1.Checked)
  260. {
  261. textBox_1.ReadOnly = false;
  262. }
  263. else
  264. {
  265. if (!CheckConstantIsUseing(checkBox_1.Text))
  266. {
  267. checkBox_1.Checked = true;
  268. }
  269. else
  270. {
  271. textBox_1.ReadOnly = true;
  272. }
  273. }
  274. }
  275. private void checkBox_2_CheckedChanged(object sender, EventArgs e)
  276. {
  277. if (checkBox_2.Checked)
  278. {
  279. textBox_2.ReadOnly = false;
  280. }
  281. else
  282. {
  283. if (!CheckConstantIsUseing(checkBox_2.Text))
  284. {
  285. checkBox_2.Checked = true;
  286. }
  287. else
  288. {
  289. textBox_2.ReadOnly = true;
  290. }
  291. }
  292. }
  293. private void checkBox_3_CheckedChanged(object sender, EventArgs e)
  294. {
  295. if (checkBox_3.Checked)
  296. {
  297. textBox_3.ReadOnly = false;
  298. }
  299. else
  300. {
  301. if (!CheckConstantIsUseing(checkBox_3.Text))
  302. {
  303. checkBox_3.Checked = true;
  304. }
  305. else
  306. {
  307. textBox_3.ReadOnly = true;
  308. }
  309. }
  310. }
  311. private void checkBox_4_CheckedChanged(object sender, EventArgs e)
  312. {
  313. if (checkBox_4.Checked)
  314. {
  315. textBox_4.ReadOnly = false;
  316. }
  317. else
  318. {
  319. if (!CheckConstantIsUseing(checkBox_4.Text))
  320. {
  321. checkBox_4.Checked = true;
  322. }
  323. else
  324. {
  325. textBox_4.ReadOnly = true;
  326. }
  327. }
  328. }
  329. private void checkBox_5_CheckedChanged(object sender, EventArgs e)
  330. {
  331. if (checkBox_5.Checked)
  332. {
  333. textBox_5.ReadOnly = false;
  334. }
  335. else
  336. {
  337. if (!CheckConstantIsUseing(checkBox_5.Text))
  338. {
  339. checkBox_5.Checked = true;
  340. }
  341. else
  342. {
  343. textBox_5.ReadOnly = true;
  344. }
  345. }
  346. }
  347. private void checkBox_6_CheckedChanged(object sender, EventArgs e)
  348. {
  349. if (checkBox_6.Checked)
  350. {
  351. textBox_6.ReadOnly = false;
  352. }
  353. else
  354. {
  355. if (!CheckConstantIsUseing(checkBox_6.Text))
  356. {
  357. checkBox_6.Checked = true;
  358. }
  359. else
  360. {
  361. textBox_6.ReadOnly = true;
  362. }
  363. }
  364. }
  365. private void checkBox_7_CheckedChanged(object sender, EventArgs e)
  366. {
  367. if (checkBox_7.Checked)
  368. {
  369. textBox_7.ReadOnly = false;
  370. }
  371. else
  372. {
  373. if (!CheckConstantIsUseing(checkBox_7.Text))
  374. {
  375. checkBox_7.Checked = true;
  376. }
  377. else
  378. {
  379. textBox_7.ReadOnly = true;
  380. }
  381. }
  382. }
  383. private void checkBox_8_CheckedChanged(object sender, EventArgs e)
  384. {
  385. if (checkBox_8.Checked)
  386. {
  387. textBox_8.ReadOnly = false;
  388. }
  389. else
  390. {
  391. if (!CheckConstantIsUseing(checkBox_8.Text))
  392. {
  393. checkBox_8.Checked = true;
  394. }
  395. else
  396. {
  397. textBox_8.ReadOnly = true;
  398. }
  399. }
  400. }
  401. private void checkBox_9_CheckedChanged(object sender, EventArgs e)
  402. {
  403. if (checkBox_9.Checked)
  404. {
  405. textBox_9.ReadOnly = false;
  406. }
  407. else
  408. {
  409. if (!CheckConstantIsUseing(checkBox_9.Text))
  410. {
  411. checkBox_9.Checked = true;
  412. }
  413. else
  414. {
  415. textBox_9.ReadOnly = true;
  416. }
  417. }
  418. }
  419. #region
  420. //string Address_backup = Application.StartupPath + "\\Config\\SysData\\OTSParticleSTD_backup.xml";
  421. //string Address = Application.StartupPath + "\\Config\\SysData\\OTSParticleSTD.xml";
  422. //XmlDocument doc = new XmlDocument();
  423. //doc.Load(Address);
  424. //LoadXmlToTreeControl(doc);
  425. //void LoadXmlToTreeControl(XmlDocument xml)
  426. //{
  427. // XmlNode root = xml.SelectSingleNode("XMLData");
  428. // XmlNodeList root2 = root.SelectNodes("Collection");
  429. // XmlNode root3 = root.SelectSingleNode("Member");
  430. // string ConstantsStr = root3.Attributes["value"].Value;
  431. // ConstantsStr = ConstantsStr.Replace(" ", "");
  432. // string[] ConstantsStr2 = ConstantsStr.Split(',');
  433. // List<string> comboBox_Constants = new List<string>();
  434. // comboBox_Constants.AddRange(ConstantsStr2);
  435. // List<string> Constantslist = new List<string>();
  436. // for (int i = 0; i < ConstantsStr2.Length; i++)
  437. // {
  438. // Constantslist.AddRange(ConstantsStr2[i].Split('='));
  439. // }
  440. // for (int i = 0; i < Constantslist.Count; i += 2)
  441. // {
  442. // if (Constantslist[i].Contains("MAC#0"))
  443. // {
  444. // this.checkBox_0.Checked = true;
  445. // this.textBox_0.ReadOnly = false;
  446. // this.textBox_0.Text = Constantslist[i + 1];
  447. // }
  448. // else if (Constantslist[i].Contains("MAC#1"))
  449. // {
  450. // this.checkBox_1.Checked = true;
  451. // this.textBox_1.ReadOnly = false;
  452. // this.textBox_1.Text = Constantslist[i + 1];
  453. // }
  454. // else if (Constantslist[i].Contains("MAC#2"))
  455. // {
  456. // this.checkBox_2.Checked = true;
  457. // this.textBox_2.ReadOnly = false;
  458. // this.textBox_2.Text = Constantslist[i + 1];
  459. // }
  460. // else if (Constantslist[i].Contains("MAC#3"))
  461. // {
  462. // this.checkBox_3.Checked = true;
  463. // this.textBox_3.ReadOnly = false;
  464. // this.textBox_3.Text = Constantslist[i + 1];
  465. // }
  466. // else if (Constantslist[i].Contains("MAC#4"))
  467. // {
  468. // this.checkBox_4.Checked = true;
  469. // this.textBox_4.ReadOnly = false;
  470. // this.textBox_4.Text = Constantslist[i + 1];
  471. // }
  472. // else if (Constantslist[i].Contains("MAC#5"))
  473. // {
  474. // this.checkBox_5.Checked = true;
  475. // this.textBox_5.ReadOnly = false;
  476. // this.textBox_5.Text = Constantslist[i + 1];
  477. // }
  478. // else if (Constantslist[i].Contains("MAC#6"))
  479. // {
  480. // this.checkBox_6.Checked = true;
  481. // this.textBox_6.ReadOnly = false;
  482. // this.textBox_6.Text = Constantslist[i + 1];
  483. // }
  484. // else if (Constantslist[i].Contains("MAC#7"))
  485. // {
  486. // this.checkBox_7.Checked = true;
  487. // this.textBox_7.ReadOnly = false;
  488. // this.textBox_7.Text = Constantslist[i + 1];
  489. // }
  490. // else if (Constantslist[i].Contains("MAC#8"))
  491. // {
  492. // this.checkBox_8.Checked = true;
  493. // this.textBox_8.ReadOnly = false;
  494. // this.textBox_8.Text = Constantslist[i + 1];
  495. // }
  496. // else if (Constantslist[i].Contains("MAC#9"))
  497. // {
  498. // this.checkBox_9.Checked = true;
  499. // this.textBox_9.ReadOnly = false;
  500. // this.textBox_9.Text = Constantslist[i + 1];
  501. // }
  502. // }
  503. //}
  504. #endregion
  505. }
  506. }