コード例 #1
0
ファイル: PersContactCRUD.cs プロジェクト: andy109l/509ITCRUD
        /// <summary>
        /// on click toggles all the required buttons and text boxes used to save selected personal contact
        /// saves the updated contacts in the database
        /// reloads the data in the dgvPers
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSaveSel_Click(object sender, EventArgs e)
        {
            int         indx            = Int32.Parse(dgvPers.SelectedCells[0].Value.ToString());
            PersContact personalContact = new PersContact();

            personalContact.id             = indx;
            personalContact.first_name     = tbFirstNamePers.Text;
            personalContact.last_name      = tbLastNamePers.Text;
            personalContact.email          = tbEmailPers.Text;
            personalContact.phone_number   = tbPhonePers.Text;
            personalContact.address_line_1 = tbAddressLine1Pers.Text;
            personalContact.address_line_2 = tbAddressLine2Pers.Text;
            personalContact.postcode       = tbPostcodePers.Text;
            personalContact.country        = tbCountryPers.Text;

            dbConn.UpdatePersonal(personalContact);
            dgvPers.DataSource = dbConn.getAllPersonal();

            tbFirstNamePers.Enabled    = false;
            tbLastNamePers.Enabled     = false;
            tbEmailPers.Enabled        = false;
            tbPhonePers.Enabled        = false;
            tbAddressLine1Pers.Enabled = false;
            tbAddressLine2Pers.Enabled = false;
            tbPostcodePers.Enabled     = false;
            tbCountryPers.Enabled      = false;
            btnUpdateSel.Enabled       = true;
            btnDeleteSel.Enabled       = true;
            btnAddNew.Enabled          = true;
            btnSaveSel.Enabled         = false;
        }
コード例 #2
0
ファイル: PersContactCRUD.cs プロジェクト: andy109l/509ITCRUD
        /// <summary>
        /// on click toggles all the required buttons and text boxes used to save new personal contact, resets the text boxes
        /// saves contacts in the database
        /// reloads the data in the dgvPers
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSaveNew_Click(object sender, EventArgs e)
        {
            PersContact personalContact = new PersContact();

            personalContact.first_name     = tbFirstNamePers.Text;
            personalContact.last_name      = tbLastNamePers.Text;
            personalContact.email          = tbEmailPers.Text;
            personalContact.phone_number   = tbPhonePers.Text;
            personalContact.address_line_1 = tbAddressLine1Pers.Text;
            personalContact.address_line_2 = tbAddressLine2Pers.Text;
            personalContact.postcode       = tbPostcodePers.Text;
            personalContact.country        = tbCountryPers.Text;
            dbConn.InsertPersoanl(personalContact);
            tbFirstNamePers.Enabled    = false;
            tbLastNamePers.Enabled     = false;
            tbEmailPers.Enabled        = false;
            tbPhonePers.Enabled        = false;
            tbAddressLine1Pers.Enabled = false;
            tbAddressLine2Pers.Enabled = false;
            tbPostcodePers.Enabled     = false;
            tbCountryPers.Enabled      = false;
            btnUpdateSel.Enabled       = true;
            btnDeleteSel.Enabled       = true;
            btnAddNew.Enabled          = true;
            btnSaveNew.Enabled         = false;

            dgvPers.DataSource = dbConn.getAllPersonal();
        }
コード例 #3
0
ファイル: DbConn.cs プロジェクト: andy109l/509ITCRUD
        /// <summary>
        /// Insets the personal contact data from the object into database using the add_personal stored procedure
        /// </summary>
        /// <param name="personalContact"></param>
        public async void InsertPersoanl(PersContact personalContact)
        {
            using (var conn = new MySqlConnection(connString))
            {
                await conn.OpenAsync();

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