private void btnSaveNew_Click(object sender, EventArgs e)
        {
            BusinessContact businessContact = new BusinessContact();//creates a new instance of Business Contacts

            //insert records present in text boxes into BusinessContact table in the database
            businessContact.ContactFname    = tbFname.Text;
            businessContact.ContactLname    = tbLname.Text;
            businessContact.ContactEmail    = tbEmail.Text;
            businessContact.BusinessTel     = tbBusTel.Text;
            businessContact.ContactAddr1    = tbAddress1.Text;
            businessContact.ContactAddr2    = tbAddress2.Text;
            businessContact.ContactCity     = tbCity.Text;
            businessContact.ContactPostcode = tbPostcode.Text;
            dbConn.InsertBusiness(businessContact);//inserts business Contacts to the record

            //accessiblity of text boxes when save new is clicked
            tbFname.Enabled    = false;
            tbLname.Enabled    = false;
            tbEmail.Enabled    = false;
            tbBusTel.Enabled   = false;
            tbAddress1.Enabled = false;
            tbAddress2.Enabled = false;
            tbCity.Enabled     = false;
            tbPostcode.Enabled = false;

            //accessiblity of buttons when SaveNew is clicked
            btnUpdate.Enabled  = true;  //enable update button
            btnDelete.Enabled  = true;  //enable delete button
            btnSaveNew.Enabled = false; //disable save new button
        }
        //UPDATE BUSINESS RECORDS
        private void btnSave_Click(object sender, EventArgs e)
        {
            int             index           = Int32.Parse(dGVBusinessRecords.SelectedCells[0].Value.ToString());
            BusinessContact businessContact = new BusinessContact();//creates new busines contact instance

            //populate businesscontact through records in the text box
            businessContact.ContactID       = index;
            businessContact.ContactFname    = tbFname.Text;
            businessContact.ContactLname    = tbLname.Text;
            businessContact.ContactEmail    = tbEmail.Text;
            businessContact.BusinessTel     = tbBusTel.Text;
            businessContact.ContactAddr1    = tbAddress1.Text;
            businessContact.ContactAddr2    = tbAddress2.Text;
            businessContact.ContactCity     = tbCity.Text;
            businessContact.ContactPostcode = tbPostcode.Text;
            dbConn.UpdateBusinessContact(businessContact);           //updates business contact in the database with new populated instace
            dGVBusinessRecords.DataSource = dbConn.GetAllBusiness(); //gets BusinessRecords from database into the datagridview

            //Accessiblity of textboxes when save button is clicked
            tbFname.Enabled    = false;
            tbLname.Enabled    = false;
            tbEmail.Enabled    = false;
            tbBusTel.Enabled   = false;
            tbAddress1.Enabled = false;
            tbAddress2.Enabled = false;
            tbCity.Enabled     = false;
            tbPostcode.Enabled = false;

            //Accessiblity of buttons when Save button is clicked
            btnUpdate.Enabled = true;
            btnDelete.Enabled = true;
            btnAddNew.Enabled = true;
            btnSave.Enabled   = false;
        }
Пример #3
0
        public async void InsertBusiness(BusinessContact businessContact) //INSERT BUSINESS CONTACT
        {
            using (var conn = new MySqlConnection(connString))            //accessing private class with connString
            {
                await conn.OpenAsync();

                using (var cmd = new MySqlCommand())
                {
                    cmd.Connection  = conn;
                    cmd.CommandText = "CALL insertBusiness(@p1,@p2,@p3,@p4,@p5,@p6,@p7,@p8);";
                    cmd.Parameters.AddWithValue("p1", businessContact.ContactFname);//inserting the value for ContactFname from business contacts in parameter 1
                    cmd.Parameters.AddWithValue("p2", businessContact.ContactLname);
                    cmd.Parameters.AddWithValue("p3", businessContact.ContactEmail);
                    cmd.Parameters.AddWithValue("p4", businessContact.BusinessTel);
                    cmd.Parameters.AddWithValue("p5", businessContact.ContactAddr1);
                    cmd.Parameters.AddWithValue("p6", businessContact.ContactAddr2);
                    cmd.Parameters.AddWithValue("p7", businessContact.ContactCity);
                    cmd.Parameters.AddWithValue("p8", businessContact.ContactPostcode);
                    await cmd.ExecuteNonQueryAsync();
                }
            }
        }
Пример #4
0
        public async void UpdateBusinessContact(BusinessContact businessContact) //UPDATE BUSINESS CONTACT
        {
            using (var conn = new MySqlConnection(connString))                   //accessing private class with connString
            {
                await conn.OpenAsync();

                using (var cmd = new MySqlCommand())
                {
                    cmd.Connection  = conn;
                    cmd.CommandText = "CALL updateBusiness(@p1,@p2,@p3,@p4,@p5,@p6,@p7,@p8,@p9);";//update parameter through contact ID
                    cmd.Parameters.AddWithValue("p1", businessContact.ContactID);
                    cmd.Parameters.AddWithValue("p2", businessContact.ContactFname);
                    cmd.Parameters.AddWithValue("p3", businessContact.ContactLname);
                    cmd.Parameters.AddWithValue("p4", businessContact.ContactEmail);
                    cmd.Parameters.AddWithValue("p5", businessContact.BusinessTel);
                    cmd.Parameters.AddWithValue("p6", businessContact.ContactAddr1);
                    cmd.Parameters.AddWithValue("p7", businessContact.ContactAddr2);
                    cmd.Parameters.AddWithValue("p8", businessContact.ContactCity);
                    cmd.Parameters.AddWithValue("p9", businessContact.ContactPostcode);
                    await cmd.ExecuteNonQueryAsync();
                }
            }
        }