ConstantsEditor.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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. namespace OTSPartA_STDEditor
  12. {
  13. public partial class ConstantsEditor : Form
  14. {
  15. public ConstantsEditor()
  16. {
  17. InitializeComponent();
  18. }
  19. void Initialization()
  20. {
  21. checkBox_0.Checked = false;
  22. checkBox_1.Checked = false;
  23. checkBox_2.Checked = false;
  24. checkBox_3.Checked = false;
  25. checkBox_4.Checked = false;
  26. checkBox_5.Checked = false;
  27. checkBox_6.Checked = false;
  28. checkBox_7.Checked = false;
  29. checkBox_8.Checked = false;
  30. checkBox_9.Checked = false;
  31. textBox_0.ReadOnly = true;
  32. textBox_1.ReadOnly = true;
  33. textBox_2.ReadOnly = true;
  34. textBox_3.ReadOnly = true;
  35. textBox_4.ReadOnly = true;
  36. textBox_5.ReadOnly = true;
  37. textBox_6.ReadOnly = true;
  38. textBox_7.ReadOnly = true;
  39. textBox_8.ReadOnly = true;
  40. textBox_9.ReadOnly = true;
  41. }
  42. private void ConstantsEditor_Load(object sender, EventArgs e)
  43. {
  44. Initialization();
  45. XmlDocument doc = new XmlDocument();
  46. string Address = "C:\\Users\\someo\\Desktop\\OTSPartA_STDEditor\\OTSPartA_STDEditor\\bin\\Debug\\OTSParticleSTD.xml";
  47. doc.Load(Address);
  48. XmlNode root = doc.SelectSingleNode("XMLData");
  49. XmlNode root2 = root.SelectSingleNode("Member");
  50. string ConstantsStr = root2.Attributes["value"].Value;
  51. ConstantsStr = ConstantsStr.Replace(" ", "");
  52. string[] ConstantsStr2 = ConstantsStr.Split(',');
  53. List<string> Constantslist = new List<string>();
  54. for (int i = 0; i < ConstantsStr2.Length; i++)
  55. {
  56. Constantslist.AddRange(ConstantsStr2[i].Split('='));
  57. }
  58. for (int i = 0; i < Constantslist.Count; i += 2)
  59. {
  60. if (Constantslist[i].Contains("MAC#0"))
  61. {
  62. this.checkBox_0.Checked = true;
  63. this.textBox_0.ReadOnly = false;
  64. this.textBox_0.Text = Constantslist[i + 1];
  65. }
  66. else if (Constantslist[i].Contains("MAC#1"))
  67. {
  68. this.checkBox_1.Checked = true;
  69. this.textBox_1.ReadOnly = false;
  70. this.textBox_1.Text = Constantslist[i + 1];
  71. }
  72. else if (Constantslist[i].Contains("MAC#2"))
  73. {
  74. this.checkBox_2.Checked = true;
  75. this.textBox_2.ReadOnly = false;
  76. this.textBox_2.Text = Constantslist[i + 1];
  77. }
  78. else if (Constantslist[i].Contains("MAC#3"))
  79. {
  80. this.checkBox_3.Checked = true;
  81. this.textBox_3.ReadOnly = false;
  82. this.textBox_3.Text = Constantslist[i + 1];
  83. }
  84. else if (Constantslist[i].Contains("MAC#4"))
  85. {
  86. this.checkBox_4.Checked = true;
  87. this.textBox_4.ReadOnly = false;
  88. this.textBox_4.Text = Constantslist[i + 1];
  89. }
  90. else if (Constantslist[i].Contains("MAC#5"))
  91. {
  92. this.checkBox_5.Checked = true;
  93. this.textBox_5.ReadOnly = false;
  94. this.textBox_5.Text = Constantslist[i + 1];
  95. }
  96. else if (Constantslist[i].Contains("MAC#6"))
  97. {
  98. this.checkBox_6.Checked = true;
  99. this.textBox_6.ReadOnly = false;
  100. this.textBox_6.Text = Constantslist[i + 1];
  101. }
  102. else if (Constantslist[i].Contains("MAC#7"))
  103. {
  104. this.checkBox_7.Checked = true;
  105. this.textBox_7.ReadOnly = false;
  106. this.textBox_7.Text = Constantslist[i + 1];
  107. }
  108. else if (Constantslist[i].Contains("MAC#8"))
  109. {
  110. this.checkBox_8.Checked = true;
  111. this.textBox_8.ReadOnly = false;
  112. this.textBox_8.Text = Constantslist[i + 1];
  113. }
  114. else if (Constantslist[i].Contains("MAC#9"))
  115. {
  116. this.checkBox_9.Checked = true;
  117. this.textBox_9.ReadOnly = false;
  118. this.textBox_9.Text = Constantslist[i + 1];
  119. }
  120. }
  121. //Form1 form1 = (Form1)this.Owner;
  122. //this.StartPosition= FormStartPosition.Manual;
  123. //this.Location = new Point(form1.Location.X/2, form1.Location.Y/2);
  124. }
  125. private void checkBox_0_CheckedChanged(object sender, EventArgs e)
  126. {
  127. if (checkBox_0.Checked)
  128. {
  129. textBox_0.ReadOnly = false;
  130. }
  131. else
  132. {
  133. textBox_0.ReadOnly = true;
  134. }
  135. }
  136. private void checkBox_1_CheckedChanged(object sender, EventArgs e)
  137. {
  138. if (checkBox_1.Checked)
  139. {
  140. textBox_1.ReadOnly = false;
  141. }
  142. else
  143. {
  144. textBox_1.ReadOnly = true;
  145. }
  146. }
  147. private void checkBox_2_CheckedChanged(object sender, EventArgs e)
  148. {
  149. if (checkBox_2.Checked)
  150. {
  151. textBox_2.ReadOnly = false;
  152. }
  153. else
  154. {
  155. textBox_2.ReadOnly = true;
  156. }
  157. }
  158. private void checkBox_3_CheckedChanged(object sender, EventArgs e)
  159. {
  160. if (checkBox_3.Checked)
  161. {
  162. textBox_3.ReadOnly = false;
  163. }
  164. else
  165. {
  166. textBox_3.ReadOnly = true;
  167. }
  168. }
  169. private void checkBox_4_CheckedChanged(object sender, EventArgs e)
  170. {
  171. if (checkBox_4.Checked)
  172. {
  173. textBox_4.ReadOnly = false;
  174. }
  175. else
  176. {
  177. textBox_4.ReadOnly = true;
  178. }
  179. }
  180. private void checkBox_5_CheckedChanged(object sender, EventArgs e)
  181. {
  182. if (checkBox_5.Checked)
  183. {
  184. textBox_5.ReadOnly = false;
  185. }
  186. else
  187. {
  188. textBox_5.ReadOnly = true;
  189. }
  190. }
  191. private void checkBox_6_CheckedChanged(object sender, EventArgs e)
  192. {
  193. if (checkBox_6.Checked)
  194. {
  195. textBox_6.ReadOnly = false;
  196. }
  197. else
  198. {
  199. textBox_6.ReadOnly = true;
  200. }
  201. }
  202. private void checkBox_7_CheckedChanged(object sender, EventArgs e)
  203. {
  204. if (checkBox_7.Checked)
  205. {
  206. textBox_7.ReadOnly = false;
  207. }
  208. else
  209. {
  210. textBox_7.ReadOnly = true;
  211. }
  212. }
  213. private void checkBox_8_CheckedChanged(object sender, EventArgs e)
  214. {
  215. if (checkBox_8.Checked)
  216. {
  217. textBox_8.ReadOnly = false;
  218. }
  219. else
  220. {
  221. textBox_8.ReadOnly = true;
  222. }
  223. }
  224. private void checkBox_9_CheckedChanged(object sender, EventArgs e)
  225. {
  226. if (checkBox_9.Checked)
  227. {
  228. textBox_9.ReadOnly = false;
  229. }
  230. else
  231. {
  232. textBox_9.ReadOnly = true;
  233. }
  234. }
  235. private void button_OK_Click(object sender, EventArgs e)
  236. {
  237. string value = "";
  238. double DoubleTry = 0;
  239. foreach (Control control in this.groupBox1.Controls)
  240. {
  241. if (control is CheckBox)
  242. {
  243. CheckBox checkBox = (CheckBox)control;
  244. if (checkBox.Checked)
  245. {
  246. TextBox tBox = (TextBox)this.groupBox1.Controls.Find("textBox_" + checkBox.Name.Remove(0, checkBox.Name.Length - 1), true)[0];
  247. if (double.TryParse(tBox.Text, out DoubleTry))
  248. {
  249. value += checkBox.Text + "=" + tBox.Text + ",";
  250. }
  251. else
  252. {
  253. MessageBox.Show("符号" + checkBox.Name + "所对应值输入错误!", "提示");
  254. return;
  255. }
  256. }
  257. }
  258. }
  259. if (value != "")
  260. {
  261. value = value.Substring(0, value.Length - 1);
  262. }
  263. string Address = "C:\\Users\\someo\\Desktop\\OTSPartA_STDEditor\\OTSPartA_STDEditor\\bin\\Debug\\OTSParticleSTD.xml";
  264. XmlDocument doc = new XmlDocument();
  265. doc.Load(Address);
  266. XmlNode root = (XmlElement)doc.SelectSingleNode("XMLData");
  267. XmlElement root2 = (XmlElement)root.SelectSingleNode("Member");
  268. root2.SetAttribute("value", value);
  269. doc.Save(Address);
  270. Form_ConstantsEditor form1 = (Form_ConstantsEditor)this.Owner;
  271. form1.UpdateConstants = value;
  272. this.Close();
  273. }
  274. private void button_Cancel_Click(object sender, EventArgs e)
  275. {
  276. this.Close();
  277. }
  278. }
  279. }