/** * Method to connect to the given Database */ private void connectDB(string DataBase, string PassWord) { ConnectionFactory connecter = ConnectionFactory.new_instance(DataBase, PassWord); Data myData = new Data(DataBase, PassWord); using (OleDbConnection conn = myData.connect_data()) { try { conn.Open(); QueryPrompt selectQuery = new QueryPrompt(); int choice = getChoice(selectQuery); switch (choice) { case 0: { Trainee specific = myData.find_an_employee(conn, selectQuery.fName, selectQuery.lName); resultList.Text += (specific.firstName + " " + specific.midInit + ". " + specific.lastName); break; } case 1: { List <Trainee> trainees = myData.find_employees(conn); foreach (Trainee e in trainees) { resultList.Text += (e.firstName + " " + e.midInit + ". " + e.lastName + System.Environment.NewLine); } break; } case 2: { List <String> tableNames = myData.get_tables(conn); foreach (String s in tableNames) { resultList.Text += (s + System.Environment.NewLine); } break; } } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conn.Close(); } } }
private int getChoice(QueryPrompt prompt) { int choose; System.Windows.Forms.DialogResult res = prompt.ShowDialog(); choose = prompt.choice; if (prompt.DialogResult.Equals(DialogResult.Cancel)) { return(-1); } else { return(choose); } }