ConstantsEditorcs.cs 9.3 KB

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