private void MainForm_Load(object sender, EventArgs e) { Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); ConfigSectionData data = config.Sections["add"] as ConfigSectionData; if (data != null) { num = data.Randomnum; } SortedList <String, String> FileList = new SortedList <String, String>(); //读取配置文件 String snum = ConfigurationManager.AppSettings["randomnum"]; if (snum != null && snum != "") { num = int.Parse(snum); } //DirectoryInfo d = new DirectoryInfo(Application.StartupPath); FileList = GetCurrentDirAllxls(Application.StartupPath, FileList); foreach (KeyValuePair <string, string> item in FileList) { ComboBoxItem cbi = new ComboBoxItem(); cbi.Text = item.Key; cbi.Value = item.Value; fileselect.Items.Add(cbi); } if (fileselect.Items.Count > 0) { fileselect.SelectedIndex = 0; } config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); ConfigurationSectionGroup group1 = config.SectionGroups["A" + Math.Abs(fileselect.SelectedText.GetHashCode()).ToString()]; if (group1 != null) { data = config.SectionGroups["A" + Math.Abs(fileselect.SelectedText.GetHashCode()).ToString()].Sections["add"] as ConfigSectionData; if (data.Absence.Length > 0) { absence = (ArrayList)RetrieveObject(System.Convert.FromBase64String(data.Absence)); } if (classname != null) { classname = data.Classname; } } if (fileselect.Items.Count == 0) { button1.Enabled = false; } }
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); ConfigSectionData data = new ConfigSectionData(); data.Randomnum = num; ConfigurationSection add = config.Sections["add"] as ConfigurationSection; if (add == null) { config.Sections.Add("add", data); } else { config.Sections.Remove("add"); config.Sections.Add("add", data); } data = new ConfigSectionData(); if (absence != null) { data.Absence = System.Convert.ToBase64String(GetBinaryFormatData(absence)); } if (classname != null) { data.Classname = classname; } ConfigurationSectionGroup group1 = config.SectionGroups["A" + Math.Abs(fileselect.SelectedText.GetHashCode()).ToString()]; if (group1 == null) { config.SectionGroups.Add("A" + Math.Abs(fileselect.SelectedText.GetHashCode()).ToString(), new ConfigurationSectionGroup()); } group1 = config.SectionGroups["A" + Math.Abs(fileselect.SelectedText.GetHashCode()).ToString()]; add = group1.Sections["add"] as ConfigurationSection; if (add == null) { config.SectionGroups["A" + Math.Abs(fileselect.SelectedText.GetHashCode()).ToString()].Sections.Add("add", data); } else { //System.Collections.Specialized.NameObjectCollectionBase.KeysCollection a = group1.Sections.Keys; group1.Sections.Remove("add"); group1.Sections.Add("add", data); } config.Save(ConfigurationSaveMode.Full); }
private void fileselect_SelectionChangeCommitted(object sender, EventArgs e) { Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); ConfigurationSectionGroup group1 = config.SectionGroups["A" + Math.Abs(fileselect.SelectedText.GetHashCode()).ToString()]; if (group1 != null) { ConfigSectionData data = config.SectionGroups["A" + Math.Abs(fileselect.SelectedText.GetHashCode()).ToString()].Sections["add"] as ConfigSectionData; if (data.Absence.Length > 0) { absence = (ArrayList)RetrieveObject(System.Convert.FromBase64String(data.Absence)); } if (classname != null) { classname = data.Classname; } } }