/// <summary> /// Add a new connection to the DatabaseSettings.xml and connect to the Database /// </summary> /// <author>Bernhard Bruns</author> private void SaveAndConnectClick(object sender, RoutedEventArgs e) { DBConnectionHelpers.LoadConnectionParameters(); ConnectionParameters connectionParameters = new ConnectionParameters(DBTypeComboBox.Text, DBConnectionnameTextBox.Text, DBHostnameTextBox.Text, DBDatabaseTextBox.Text, DBUsernameTextBox.Text, DBPasswordTextBox.Password, DBPortTextBox.Text); if (connectionParameters.IsComplete()) { if (DBConnectionHelpers.CheckIfDatabaseNameExists(connectionParameters.Name)) { DBConnectionHelpers.AddDatabaseConnectionToConnectionList(connectionParameters); if (ConnectToDb(connectionParameters)) { DBConnectionHelpers.SaveConnectionParameters(); DBConnectionHelpers.SaveLastUsedDatabase(connectionParameters); AddConnectionGrid.Visibility = Visibility.Collapsed; } else { ModernDialog.ShowMessage("Can't connect to database!", "New Connection", MessageBoxButton.OK); } } else { ModernDialog.ShowMessage("Connection Name \"" + connectionParameters.Name + "\" already exists! \r\nPlease choose a new Name for your connection.", "New Connection", MessageBoxButton.OK); } } else { ModernDialog.ShowMessage("Please fill out all fields to add the new connection!", "New Connection", MessageBoxButton.OK); } }
public void SaveConnectionParametersTest() { DBConnectionHelpers.ConnectionParametersList = new List <ConnectionParameters>(); DBConnectionHelpers.AddDatabaseConnectionToConnectionList(ConParams); DBConnectionHelpers.SaveConnectionParameters(); Assert.IsTrue(File.Exists(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\" + "DatabaseSettings.mpm")); }
/// <summary> /// Reloads the connection listbox /// </summary> private void ReloadListbox() { ConnectionsListBox.ItemsSource = null; ConnectionsListBox.ItemsSource = DBConnectionHelpers.ConnectionParametersList; DBConnectionHelpers.SaveConnectionParameters(); }