public static void RefferingGPSelectedAddEdit(ComboBox refGPDropDownList, TextBox id, TextBox firstName, TextBox lastName, TextBox directNumber, TextBox email, TextBox notes, ComboBox practiceDropDownList) { DataTable pracdt; //Will be used to search through the practice names string practiceName = null; //Will Hold the name of the practice int pracSelectedIndex = 0; //Will Hold the selected index of the Dropdown2 string query = "SELECT * FROM [REFFERING GP] WHERE REFGP_ID_Number =" + refGPDropDownList.SelectedValue + ";"; //SQL Query //Connect to database and run query using (Global.connection = new SQLiteConnection(Global.connectionString)) using (SQLiteCommand cmd = new SQLiteCommand(query, Global.connection)) { try { Global.connection.Open(); SQLiteDataReader reader = cmd.ExecuteReader(); //Populating the fields with the found Reffering GP details while (reader.Read()) { id.Text = reader.GetInt32(0).ToString(); firstName.Text = reader.GetString(1); lastName.Text = reader.GetString(2); directNumber.Text = reader.GetString(3); email.Text = reader.GetString(4); practiceName = reader.GetString(5); //Sets a local variable to hold the Practice Name notes.Text = reader.GetString(6); } Global.editingExistingRefferingGP = true; //Creates an edit session Global.connection.Close(); } catch (SQLiteException ex) { MessageBox.Show(ex.ToString()); } } pracdt = Practice_Database.populatePracticeDropDown(practiceDropDownList); int counter = 0; //Counter will be used to find pracSelectedIndex //Loop through datatable to find the row with the selected Practice Name foreach (DataRow row in pracdt.Rows) { if (row[0].ToString() == practiceName) { pracSelectedIndex = counter; break; } counter++; } practiceDropDownList.SelectedIndex = pracSelectedIndex; //Selects the correct Reffering GP from Reffering_GP_Dropdown }
//********************Database Event Methods******************** //Shows list of all existing practices private void Dropdown_1_DropDown(object sender, EventArgs e) { Practice_Database.populatePracticeDropDown(Dropdown_1); }
//Shows list of practices to delete private void Delete_Existing_Dropdown_DropDown(object sender, EventArgs e) { Practice_Database.populatePracticeDropDown(Delete_Existing_Dropdown); }