public Form1() { // // Windows 窗体设计器支持所必需的 // InitializeComponent(); setStartAndEnd(1); MyConfigSection config = readConfig(); if (config != null) { this.textBox1.Text = config.PartNumber; if (config.PasueNumber == null || config.PasueNumber.Length <= 0) { this.textBox2.Text = config.StartNumber; } else { this.textBox2.Text = config.PasueNumber; } this.textBox3.Text = config.EndNumber; this.comboBox1.Text = config.Country; } }
MyConfigSection readConfig() { Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); MyConfigSection data = config.Sections["last"] as MyConfigSection; return(data); }
private void saveConfig() { Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); MyConfigSection data = new MyConfigSection(); data.OperTime = DateTime.Now; data.PartNumber = this.textBox1.Text.Trim(); data.StartNumber = this.textBox2.Text.Trim(); data.EndNumber = this.textBox3.Text.Trim(); data.Country = this.comboBox1.Text.Trim(); data.PasueNumber = pasueNum; //config.SectionGroups.Remove("last"); config.Sections.Remove("last"); config.Sections.Add("last", data); config.Save(ConfigurationSaveMode.Minimal); }