private void Win_config_save_button_Click(object sender, RoutedEventArgs e) { win3_dataGrid.SelectAll(); Int32 selectedCellCount = win3_dataGrid.SelectedItems.Count; System.Text.StringBuilder sb = new System.Text.StringBuilder(); Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); var appSettings = ConfigurationManager.AppSettings; for (int i = 0; i < selectedCellCount; i++) { string row = "bab"; row = win3_dataGrid.SelectedItems[i].ToString(); if (string.Equals("{NewItemPlaceholder}", row)) { } else { myConfig myCfg = (myConfig)win3_dataGrid.SelectedItems[i]; sb.Append(myCfg.key.ToString()); sb.Append(" => "); sb.Append(myCfg.value.ToString()); sb.Append(Environment.NewLine); if (String.Equals(myCfg.value.ToString(), appSettings[myCfg.key])) { } else { config.AppSettings.Settings.Remove(myCfg.key); config.AppSettings.Settings.Add(myCfg.key, myCfg.value); config.Save(); } } } ConfigurationManager.RefreshSection("appSettings"); MessageBox.Show("Successfuly saved. :)"); }
private void Win_config_save_button_Click(object sender, RoutedEventArgs e) { win3_dataGrid.SelectAll(); Int32 selectedCellCount = win3_dataGrid.SelectedItems.Count; System.Text.StringBuilder sb = new System.Text.StringBuilder(); Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); var appSettings = ConfigurationManager.AppSettings; for (int i = 0; i < selectedCellCount; i++) { string row = "bab"; row = win3_dataGrid.SelectedItems[i].ToString(); if (string.Equals("{NewItemPlaceholder}", row)) { continue; } myConfig myCfg = (myConfig)win3_dataGrid.SelectedItems[i]; if (string.Equals("{NewItemPlaceholder}", row)) { } else if (myCfg.key.ToString() == "PLAYER") { Properties.Settings.Default.PLAYER = myCfg.value.ToString(); } else if (myCfg.key.ToString() == "REPLAY_PATH") { Properties.Settings.Default.REPLAY_PATH = myCfg.value.ToString(); } else { //myConfig myCfg = (myConfig)win3_dataGrid.SelectedItems[i]; sb.Append(myCfg.key.ToString()); sb.Append(" => "); sb.Append(myCfg.value.ToString()); sb.Append(Environment.NewLine); if (String.Equals(myCfg.value.ToString(), appSettings[myCfg.key])) { } else { config.AppSettings.Settings.Remove(myCfg.key); config.AppSettings.Settings.Add(myCfg.key, myCfg.value); config.Save(); } } } ConfigurationManager.RefreshSection("appSettings"); config.Save(); Properties.Settings.Default.Save(); MW.player_name = Properties.Settings.Default.PLAYER; MW.SetPlayerList(Properties.Settings.Default.PLAYER); MW.myReplay_Path = Properties.Settings.Default.REPLAY_PATH; MW.SetReplayList(Properties.Settings.Default.REPLAY_PATH); MessageBox.Show("Successfuly saved. :)", "sc2dsstats"); }