private void btnDeleteProgramSource_OnClick(object sender, RoutedEventArgs e) { ProgramSource seletedProgramSource = programSourceView.SelectedItem as ProgramSource; if (seletedProgramSource != null && MessageBox.Show("Are your sure to delete " + seletedProgramSource.ToString(), "Delete ProgramSource", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { UserSettingStorage.Instance.ProgramSources.Remove(seletedProgramSource); programSourceView.Items.Refresh(); } else { MessageBox.Show("Please select a program source"); } }
private void btnAdd_OnClick(object sender, RoutedEventArgs e) { string location = tbLocation.Text; if (this.tbLocation.IsEnabled == true && string.IsNullOrEmpty(location)) { MessageBox.Show("Please input Type field"); return; } string type = cbType.SelectedItem as string; if (string.IsNullOrEmpty(type)) { MessageBox.Show("Please input Type field"); return; } int bonusPoint = 0; int.TryParse(this.tbBonusPoints.Text, out bonusPoint); if (!update) { ProgramSource p = new ProgramSource() { Location = this.tbLocation.IsEnabled ? location : null, Enabled = cbEnable.IsChecked ?? false, Type = type, BonusPoints = bonusPoint }; if (UserSettingStorage.Instance.ProgramSources.Exists(o => o.ToString() == p.ToString() && o != p)) { MessageBox.Show("Program source already exists!"); return; } UserSettingStorage.Instance.ProgramSources.Add(p); MessageBox.Show(string.Format("Add {0} program source successfully!", p.ToString())); } else { if (UserSettingStorage.Instance.ProgramSources.Exists(o => o.ToString() == updateProgramSource.ToString() && o != updateProgramSource)) { MessageBox.Show("Program source already exists!"); return; } updateProgramSource.Location = this.tbLocation.IsEnabled ? location : null; updateProgramSource.Type = type; updateProgramSource.Enabled = cbEnable.IsChecked ?? false; updateProgramSource.BonusPoints = bonusPoint; MessageBox.Show(string.Format("Update {0} program source successfully!", updateProgramSource.ToString())); } UserSettingStorage.Instance.Save(); settingWindow.ReloadProgramSourceView(); Close(); }