private void DelProfile_Click(object sender, RoutedEventArgs e) { MessageBoxResult messageBoxResult = MessageBox.Show("Are you sure you want to delete the profile " + ((ArtivaProfile)Profiles.SelectedItem).ProfileName + "?", "Delete Confirmation", MessageBoxButton.YesNo); if (messageBoxResult == MessageBoxResult.Yes) { ArtivaProfile oldProfile = (ArtivaProfile)Profiles.SelectedItem; try { using (RegistryKey key = Registry.CurrentUser.OpenSubKey(registryPath, true)) { if (key != null) { key.DeleteValue(oldProfile.ProfileName); } } MessageBox.Show("Profile Deleted"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void Window_Loaded(object sender, RoutedEventArgs e) { profileNameBox.GotFocus += Name_OnFocus; profileNameBox.LostFocus += Name_LostFocus; tabControl.SelectionChanged += Selection_Change; ObservableCollection <ArtivaProfile> ArtivaProfiles = new ObservableCollection <ArtivaProfile>(); oldProfile = new ArtivaProfile { ProfileName = "", Description = "", HostName = "", HostPort = "", User = "", Password = "", Namespace = "", DeskNumber = "" }; registryPath = @"Software\VB and VBA Program Settings\Ontario Systems API Manager\Profiles"; workstationPath = @"C:\Program Files (x86)\Ontario\Workstation\guiApp.exe"; studioPath = @"C:\Program Files (x86)\Ontario\Stuido\studio.exe"; saved = false; try { using (RegistryKey key = Registry.CurrentUser.OpenSubKey(registryPath)) { if (key != null) { foreach (string subkey in key.GetValueNames()) { var val = (string)(key.GetValue(subkey)); var item = new ArtivaProfile { ProfileName = subkey, Description = val.Split('\x7')[0], HostName = val.Split('\x7')[1], HostPort = val.Split('\x7')[2], User = val.Split('\x7')[3], Password = val.Split('\x7')[4], Namespace = val.Split('\x7')[5], DeskNumber = val.Split('\x7')[6] }; ArtivaProfiles.Add(item); } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } Profiles.ItemsSource = ArtivaProfiles; }
private void Name_OnFocus(object sender, EventArgs e) { //Ensure a profile is selected if ((ArtivaProfile)Profiles.SelectedItem != null) { //Save the old profile name so it can be deleted and replaced with a new profile if (oldProfile.ProfileName == ((ArtivaProfile)Profiles.SelectedItem).ProfileName) { ArtivaProfile oldProfile = (ArtivaProfile)Profiles.SelectedItem; } } }
private void SaveProfile_Click(object sender, RoutedEventArgs e) { string oldProfileName = oldProfile.ProfileName; ArtivaProfile newProfile = new ArtivaProfile { ProfileName = profileNameBox.Text, Description = descriptionBox.Text, HostName = hostNameBox.Text, HostPort = hostPortBox.Text, User = userBox.Text, Password = passwordBox.Text, Namespace = namespaceBox.Text, DeskNumber = deskNumberBox.Text }; try { using (RegistryKey key = Registry.CurrentUser.OpenSubKey(registryPath, true)) { if (key != null) { //Replace old profile key.DeleteValue(oldProfile.ProfileName); key.SetValue(newProfile.ProfileName, newProfile.ToDelimitedString(), RegistryValueKind.String); } else { //New profile key.SetValue(newProfile.ProfileName, newProfile.ToDelimitedString(), RegistryValueKind.String); } } saved = true; MessageBox.Show("Profile Saved"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }