Example #1
0
        /// <summary>
        /// on click toggles all the required buttons and text boxes used to save new business contact, resets the text boxes
        /// saves contacts in the database
        /// reloads the data in the dgvBusi
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSaveNewBusi_Click(object sender, EventArgs e)
        {
            BusiContact businessContact = new BusiContact();

            businessContact.first_name            = tbFirstNameBusi.Text;
            businessContact.last_name             = tbLastNameBusi.Text;
            businessContact.email                 = tbEmailBusi.Text;
            businessContact.business_phone_number = tbPhoneBusi.Text;
            businessContact.address_line_1        = tbAddressLine1Busi.Text;
            businessContact.address_line_2        = tbAddressLine2Busi.Text;
            businessContact.postcode              = tbPostcodeBusi.Text;
            businessContact.country               = tbCountryBusi.Text;
            businessContact.company               = tbCompanyBusi.Text;

            dbConn.InsertBusiness(businessContact);

            tbFirstNameBusi.Enabled    = false;
            tbLastNameBusi.Enabled     = false;
            tbEmailBusi.Enabled        = false;
            tbPhoneBusi.Enabled        = false;
            tbAddressLine1Busi.Enabled = false;
            tbAddressLine2Busi.Enabled = false;
            tbPostcodeBusi.Enabled     = false;
            tbCountryBusi.Enabled      = false;
            tbCompanyBusi.Enabled      = false;
            btnUpdateSelBusi.Enabled   = true;
            btnDeleteSelBusi.Enabled   = true;
            btnAddNewBusi.Enabled      = true;
            btnSaveNewBusi.Enabled     = false;

            dgvBusi.DataSource = dbConn.getAllBusiness();
        }
Example #2
0
        /// <summary>
        /// on click toggles all the required buttons and text boxes used to save selected business contact
        /// saves the updated contacts in the database
        /// reloads the data in the dgvBusi
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSaveSelBusi_Click(object sender, EventArgs e)
        {
            int         indx            = Int32.Parse(dgvBusi.SelectedCells[0].Value.ToString());
            BusiContact businessContact = new BusiContact();

            businessContact.id                    = indx;
            businessContact.first_name            = tbFirstNameBusi.Text;
            businessContact.last_name             = tbLastNameBusi.Text;
            businessContact.email                 = tbEmailBusi.Text;
            businessContact.business_phone_number = tbPhoneBusi.Text;
            businessContact.address_line_1        = tbAddressLine1Busi.Text;
            businessContact.address_line_2        = tbAddressLine2Busi.Text;
            businessContact.postcode              = tbPostcodeBusi.Text;
            businessContact.country               = tbCountryBusi.Text;
            businessContact.company               = tbCompanyBusi.Text;

            dbConn.UpdateBusiness(businessContact);
            dgvBusi.DataSource = dbConn.getAllBusiness();

            tbFirstNameBusi.Enabled    = false;
            tbLastNameBusi.Enabled     = false;
            tbEmailBusi.Enabled        = false;
            tbPhoneBusi.Enabled        = false;
            tbAddressLine1Busi.Enabled = false;
            tbAddressLine2Busi.Enabled = false;
            tbPostcodeBusi.Enabled     = false;
            tbCountryBusi.Enabled      = false;
            tbCompanyBusi.Enabled      = false;
            btnUpdateSelBusi.Enabled   = true;
            btnDeleteSelBusi.Enabled   = true;
            btnAddNewBusi.Enabled      = true;
            btnSaveSelBusi.Enabled     = false;
        }
Example #3
0
        /// <summary>
        /// Insets the business contact data from the object into database using the add_business stored procedure
        /// </summary>
        /// <param name="businessContact"></param>
        public async void InsertBusiness(BusiContact businessContact)
        {
            using (var conn = new MySqlConnection(connString))
            {
                await conn.OpenAsync();

                using (var cmd = new MySqlCommand())
                {
                    cmd.Connection  = conn;
                    cmd.CommandText = "CALL add_business(@p1,@p2,@p3,@p4,@p5,@p6,@p7,@p8,@p9);";
                    cmd.Parameters.AddWithValue("p1", businessContact.first_name);
                    cmd.Parameters.AddWithValue("p2", businessContact.last_name);
                    cmd.Parameters.AddWithValue("p3", businessContact.email);
                    cmd.Parameters.AddWithValue("p4", businessContact.address_line_1);
                    cmd.Parameters.AddWithValue("p5", businessContact.address_line_2);
                    cmd.Parameters.AddWithValue("p6", businessContact.postcode);
                    cmd.Parameters.AddWithValue("p7", businessContact.country);
                    cmd.Parameters.AddWithValue("p8", businessContact.company);
                    cmd.Parameters.AddWithValue("p9", businessContact.business_phone_number);
                    await cmd.ExecuteNonQueryAsync();
                }
            }
        }