Form_UserConstants.cs 19 KB

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