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 ConstantsEditorcs : Form { public ConstantsEditorcs() { 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; this.Width = groupBox1.Width + 45; this.Height = groupBox1.Height + button_Cancel.Height + 69; } private void ConstantsEditorcs_Load(object sender, EventArgs e) { Initialization(); XmlDocument doc = new XmlDocument(); doc.Load("C:\\Users\\someo\\Desktop\\OTSPartA_STDEditor\\OTSPartA_STDEditor\\bin\\Debug\\OTSParticleSTD.xml"); XmlNode root = doc.SelectSingleNode("XMLData"); XmlNode root2 = root.SelectSingleNode("Member"); string ConstantsStr = root2.Attributes["value"].Value; ConstantsStr = ConstantsStr.Replace(" ", ""); string[] ConstantsStr2 = ConstantsStr.Split(','); List Constantslist = new List(); 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]; } } } 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.Controls) { if(control is CheckBox) { CheckBox checkBox = (CheckBox)control; if(checkBox.Checked) { TextBox tBox=(TextBox)this.Controls.Find("textBox_" + checkBox.Name.Remove(0, checkBox.Name.Length - 2), false)[0]; if (double.TryParse(tBox.Text, out DoubleTry)) { value += checkBox.Name + "=" + tBox.Text + ","; } else { MessageBox.Show("符号"+checkBox.Name+"所对应值输入错误!", "提示"); } } } } if(value!="") { value = value.Remove(value.Length - 2, value.Length - 1); } string adr = "C:\\Users\\someo\\Desktop\\OTSPartA_STDEditor\\OTSPartA_STDEditor\\bin\\Debug\\OTSParticleSTD.xml"; XmlDocument doc = new XmlDocument(); doc.Load(adr); XmlNode root = (XmlElement)doc.SelectSingleNode("XMLData"); XmlElement root2 = (XmlElement)doc.SelectSingleNode("Member"); root2.SetAttribute("value", value); doc.Save(adr); } private void button_Cancel_Click(object sender, EventArgs e) { this.Close(); } } }