123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300 |
- 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;
- namespace OTSPartA_STDEditor
- {
- public partial class ConstantsEditor : Form
- {
- public ConstantsEditor()
- {
- InitializeComponent();
- }
- void Initialization()
- {
- 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;
- }
- private void ConstantsEditor_Load(object sender, EventArgs e)
- {
- Initialization();
- XmlDocument doc = new XmlDocument();
- string Address = "C:\\Users\\someo\\Desktop\\OTSPartA_STDEditor\\OTSPartA_STDEditor\\bin\\Debug\\OTSParticleSTD.xml";
- doc.Load(Address);
- XmlNode root = doc.SelectSingleNode("XMLData");
- XmlNode root2 = root.SelectSingleNode("Member");
- string ConstantsStr = root2.Attributes["value"].Value;
- ConstantsStr = ConstantsStr.Replace(" ", "");
- string[] ConstantsStr2 = ConstantsStr.Split(',');
- 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];
- }
- }
- //Form1 form1 = (Form1)this.Owner;
- //this.StartPosition= FormStartPosition.Manual;
- //this.Location = new Point(form1.Location.X/2, form1.Location.Y/2);
- }
- private void checkBox_0_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox_0.Checked)
- {
- textBox_0.ReadOnly = false;
- }
- else
- {
- textBox_0.ReadOnly = true;
- }
- }
- private void checkBox_1_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox_1.Checked)
- {
- textBox_1.ReadOnly = false;
- }
- else
- {
- textBox_1.ReadOnly = true;
- }
- }
- private void checkBox_2_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox_2.Checked)
- {
- textBox_2.ReadOnly = false;
- }
- else
- {
- textBox_2.ReadOnly = true;
- }
- }
- private void checkBox_3_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox_3.Checked)
- {
- textBox_3.ReadOnly = false;
- }
- else
- {
- textBox_3.ReadOnly = true;
- }
- }
- private void checkBox_4_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox_4.Checked)
- {
- textBox_4.ReadOnly = false;
- }
- else
- {
- textBox_4.ReadOnly = true;
- }
- }
- private void checkBox_5_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox_5.Checked)
- {
- textBox_5.ReadOnly = false;
- }
- else
- {
- textBox_5.ReadOnly = true;
- }
- }
- private void checkBox_6_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox_6.Checked)
- {
- textBox_6.ReadOnly = false;
- }
- else
- {
- textBox_6.ReadOnly = true;
- }
- }
- private void checkBox_7_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox_7.Checked)
- {
- textBox_7.ReadOnly = false;
- }
- else
- {
- textBox_7.ReadOnly = true;
- }
- }
- private void checkBox_8_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox_8.Checked)
- {
- textBox_8.ReadOnly = false;
- }
- else
- {
- textBox_8.ReadOnly = true;
- }
- }
- private void checkBox_9_CheckedChanged(object sender, EventArgs e)
- {
- if (checkBox_9.Checked)
- {
- textBox_9.ReadOnly = false;
- }
- else
- {
- textBox_9.ReadOnly = true;
- }
- }
- private void button_OK_Click(object sender, EventArgs e)
- {
- string value = "";
- double DoubleTry = 0;
- foreach (Control control in this.groupBox1.Controls)
- {
- if (control is CheckBox)
- {
- CheckBox checkBox = (CheckBox)control;
- if (checkBox.Checked)
- {
- TextBox tBox = (TextBox)this.groupBox1.Controls.Find("textBox_" + checkBox.Name.Remove(0, checkBox.Name.Length - 1), true)[0];
- if (double.TryParse(tBox.Text, out DoubleTry))
- {
- value += checkBox.Text + "=" + tBox.Text + ",";
- }
- else
- {
- MessageBox.Show("符号" + checkBox.Name + "所对应值输入错误!", "提示");
- return;
- }
- }
- }
- }
- if (value != "")
- {
- value = value.Substring(0, value.Length - 1);
- }
- string Address = "C:\\Users\\someo\\Desktop\\OTSPartA_STDEditor\\OTSPartA_STDEditor\\bin\\Debug\\OTSParticleSTD.xml";
- XmlDocument doc = new XmlDocument();
- doc.Load(Address);
- XmlNode root = (XmlElement)doc.SelectSingleNode("XMLData");
- XmlElement root2 = (XmlElement)root.SelectSingleNode("Member");
- root2.SetAttribute("value", value);
- doc.Save(Address);
- Form_ConstantsEditor form1 = (Form_ConstantsEditor)this.Owner;
- form1.UpdateConstants = value;
- this.Close();
- }
- private void button_Cancel_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- }
- }
|