private void btnSaveNew_Click(object sender, EventArgs e) { /* * This block of code represents the * */ BusinessContacts businessContacts = new BusinessContacts(); businessContacts.bName = bName_Textbox.Text; businessContacts.bEmail = bEmail_Textbox.Text; businessContacts.bNumber = bNumber_Textbox.Text; DbConn.insertBContacts(businessContacts); /* calls the method insertbContacts from dbconn, passing the parameter businessContacts so that the textbox text can be stored * into the database */ btnAddNew.Enabled = true; btnDeleteSelected.Enabled = true; btnSaveSelected.Enabled = true; btnSaveSelected.Enabled = true; btnSaveNew.Enabled = false; bName_Textbox.Enabled = false; bEmail_Textbox.Enabled = false; bNumber_Textbox.Enabled = false; bName_Textbox.Text = String.Empty; bEmail_Textbox.Text = String.Empty; bNumber_Textbox.Text = String.Empty; bContactsDataGrid.DataSource = DbConn.getBContacts(); // refresh the datagridtable by recalling the getbContacts method from dbconn. }
public async void insertBContacts(BusinessContacts businessContacts) { using (var conn = new MySqlConnection(sConn)) { await conn.OpenAsync(); using (var callCommand = new MySqlCommand()) { callCommand.Connection = conn; callCommand.CommandText = "CALL insertIntoBusiness(@p1,@p2,@p3);"; callCommand.Parameters.AddWithValue("p1", businessContacts.bName); callCommand.Parameters.AddWithValue("P2", businessContacts.bEmail); callCommand.Parameters.AddWithValue("p3", businessContacts.bNumber); await callCommand.ExecuteNonQueryAsync(); } } }
private void btnSaveSelected_Click(object sender, EventArgs e) { int index = Int32.Parse(bContactsDataGrid.SelectedCells[0].Value.ToString()); BusinessContacts businessContacts = new BusinessContacts(); businessContacts.BusinessID = index; // id set to index so that relative row can be updated given the id matches the information in the table businessContacts.bName = bName_Textbox.Text; businessContacts.bEmail = bEmail_Textbox.Text; businessContacts.bNumber = bNumber_Textbox.Text; DbConn.updateBContacts(businessContacts); bContactsDataGrid.DataSource = DbConn.getBContacts(); btnAddNew.Enabled = true; btnDeleteSelected.Enabled = true; btnSaveSelected.Enabled = false; btnUpdateSelected.Enabled = true; btnSaveNew.Enabled = false; bName_Textbox.Enabled = false; bEmail_Textbox.Enabled = false; bNumber_Textbox.Enabled = false; bName_Textbox.Text = String.Empty; bEmail_Textbox.Text = String.Empty; bNumber_Textbox.Text = String.Empty; }