private void btnSaveNew_Click(object sender, EventArgs e) //save new button fuctionality and settings related to it { BusinessContact businessContact = new BusinessContact(); //creates a new business contact record businessContact.contactFname = tbFname.Text; //converts the text to information stored businessContact.contactLname = tbLname.Text; businessContact.contactTel = tbTel.Text; businessContact.contactEmail = tbEmail.Text; businessContact.contactAddr1 = tbAddr1.Text; businessContact.contactAddr2 = tbAddr2.Text; businessContact.contactCity = tbCity.Text; businessContact.contactPostcode = tbPost.Text; businessContact.contactBusinessTel = tbBTel.Text; dbConn.InsertBusiness(businessContact); //calls the inserbusiness comamnd from dbconn.cs tbFname.Enabled = false; //disables the text boxes after clicking tbLname.Enabled = false; tbTel.Enabled = false; tbEmail.Enabled = false; tbAddr1.Enabled = false; tbAddr2.Enabled = false; tbCity.Enabled = false; tbPost.Enabled = false; tbBTel.Enabled = false; btnDelete.Enabled = true; btnUpdate.Enabled = true; btnSaveNew.Enabled = false; dGVBusinessRecords.DataSource = dbConn.GetAllBusiness(); }
private void btnSave_Click(object sender, EventArgs e) //on clicking save { int index = Int32.Parse(dGVBusinessRecords.SelectedCells[0].Value.ToString()); //creates an id BusinessContact businessContact = new BusinessContact(); businessContact.ContactID = index; //the value taken from index businessContact.contactFname = tbFname.Text; //text field values businessContact.contactLname = tbLname.Text; businessContact.contactTel = tbTel.Text; businessContact.contactEmail = tbEmail.Text; businessContact.contactAddr1 = tbAddr1.Text; businessContact.contactAddr2 = tbAddr2.Text; businessContact.contactCity = tbCity.Text; businessContact.contactPostcode = tbPost.Text; businessContact.contactBusinessTel = tbBTel.Text; dbConn.UpdateBusiness(businessContact); //command that is run upon collecting the needed information dGVBusinessRecords.DataSource = dbConn.GetAllBusiness(); //refreshes the table with records tbFname.Enabled = false; //going back to the defaulot settings tbLname.Enabled = false; tbTel.Enabled = false; tbEmail.Enabled = false; tbAddr1.Enabled = false; tbAddr2.Enabled = false; tbCity.Enabled = false; tbPost.Enabled = false; tbBTel.Enabled = false; btnDelete.Enabled = true; btnUpdate.Enabled = true; btnSave.Enabled = false; }
public async void InsertBusiness(BusinessContact businessContact)//insert business command { using (var conn = new MySqlConnection(connString)) { await conn.OpenAsync(); using (var cmd = new MySqlCommand()) { cmd.Connection = conn; cmd.CommandText = "CALL INSERTBusiness(@p1,@p2,@p3,@p4,@p5,@p6,@p7,@p8,@p9);"; cmd.Parameters.AddWithValue("p1", businessContact.contactFname); cmd.Parameters.AddWithValue("p2", businessContact.contactLname); cmd.Parameters.AddWithValue("p3", businessContact.contactTel); cmd.Parameters.AddWithValue("p4", businessContact.contactEmail); cmd.Parameters.AddWithValue("p5", businessContact.contactAddr1); cmd.Parameters.AddWithValue("p6", businessContact.contactAddr2); cmd.Parameters.AddWithValue("p7", businessContact.contactCity); cmd.Parameters.AddWithValue("p8", businessContact.contactPostcode); cmd.Parameters.AddWithValue("p9", businessContact.contactBusinessTel); await cmd.ExecuteNonQueryAsync(); } } }