Beispiel #1
0
        private void btnSaveNew_Click_1(object sender, EventArgs e) // populate the save new button and text box to be passed to enable data creation
        {
            PersonalContact personalContact = new PersonalContact();

            personalContact.ContactFname    = tbFname.Text;
            personalContact.ContactLname    = tbLname.Text;
            personalContact.ContactEmail    = tbEmail.Text;
            personalContact.ContactAddr1    = tbAddr1.Text;
            personalContact.ContactAddr2    = tbAddr2.Text;
            personalContact.ContactCity     = tbCity.Text;
            personalContact.ContactPostcode = tbPostcode.Text;
            personalContact.PersonalTel     = tbTel.Text;
            dbConn.InsertPersonal(personalContact);                  // INSERT PERSONAL TAKES PERSONAL CONTACT AS A PERIMETER
            tbFname.Enabled               = false;                   // changed true to false
            tbLname.Enabled               = false;                   // changed true to false
            tbEmail.Enabled               = false;                   // changed true to false
            tbAddr1.Enabled               = false;                   // changed true to false
            tbAddr2.Enabled               = false;                   // changed true to false;
            tbCity.Enabled                = false;                   // changed true to false
            tbPostcode.Enabled            = false;                   // changed true to false
            tbTel.Enabled                 = false;                   // changed true to false
            btnUpdate.Enabled             = true;                    // changed false to true
            btnDelete.Enabled             = true;                    // changed FALSE to TRUE
            btnSaveNew.Enabled            = false;                   // changed true to false
            dGVPersonalRecords.DataSource = dbConn.GetAllPersonal(); // Passed objects and enable them in the database
        }
Beispiel #2
0
        public async void UpdatePersonal(PersonalContact personalContact)  // added async method for multi threading

        // duplicate of insert personal but changed codes to update version.
        {
            using (var conn = new MySqlConnection(connString))
            {
                await conn.OpenAsync(); // openness connection to asyn

                using (var cmd = new MySqlCommand())
                {
                    cmd.Connection  = conn;
                    cmd.CommandText = "CALL updatePersonal(@p1,@p2,@p3,@p4,@p5,@p6,@p7,@p8,@p9);"; // call stored procedure
                    cmd.Parameters.AddWithValue("p1", personalContact.ContactID);
                    cmd.Parameters.AddWithValue("p2", personalContact.ContactFname);
                    cmd.Parameters.AddWithValue("p3", personalContact.ContactLname);
                    cmd.Parameters.AddWithValue("p4", personalContact.ContactEmail);
                    cmd.Parameters.AddWithValue("p5", personalContact.ContactAddr1);
                    cmd.Parameters.AddWithValue("p6", personalContact.ContactAddr2);
                    cmd.Parameters.AddWithValue("p7", personalContact.ContactCity);
                    cmd.Parameters.AddWithValue("p8", personalContact.ContactPostcode);
                    cmd.Parameters.AddWithValue("p9", personalContact.PersonalTel);
                    await cmd.ExecuteNonQueryAsync(); // statement accomplished
                }
            }
        }
Beispiel #3
0
        private void BtnSave_Click(object sender, EventArgs e)
        {
            int             index           = Int32.Parse(dGVPersonalRecords.SelectedCells[0].Value.ToString()); // get index of current selected for contact ID
            PersonalContact personalContact = new PersonalContact();

            personalContact.ContactID       = index;
            personalContact.ContactFname    = tbFname.Text;
            personalContact.ContactLname    = tbLname.Text;
            personalContact.ContactEmail    = tbEmail.Text;
            personalContact.ContactAddr1    = tbAddr2.Text;
            personalContact.ContactAddr2    = tbAddr2.Text;
            personalContact.ContactCity     = tbCity.Text;
            personalContact.ContactPostcode = tbPostcode.Text;
            personalContact.PersonalTel     = tbTel.Text;
            dbConn.UpdatePersonal(personalContact);
            dGVPersonalRecords.DataSource = dbConn.GetAllPersonal(); // refreshing the data when insert any record
            tbFname.Enabled    = false;
            tbLname.Enabled    = false;
            tbEmail.Enabled    = false;
            tbAddr1.Enabled    = false;
            tbAddr2.Enabled    = false;
            tbCity.Enabled     = false;
            tbPostcode.Enabled = false;
            tbTel.Enabled      = false;
            btnUpdate.Enabled  = true;
            btnDelete.Enabled  = true;
            btnAddNew.Enabled  = true;
            btnSave.Enabled    = false;
        }
Beispiel #4
0
        public async void InsertPersonal(PersonalContact personalContact) // Inolve asynchronise method
        {
            using (var conn = new MySqlConnection(connString))            // INSERT PERSONAL TAKES PERSONAL CONTACT AS A PERIMETER And enable connection
            {
                await conn.OpenAsync();                                   // openness connection to asyn

                using (var cmd = new MySqlCommand())
                {
                    cmd.Connection  = conn;
                    cmd.CommandText = "CALL insertPersonal(@p1,@p2,@p3,@p4,@p5,@p6,@p7,@p8);"; // call stored procedure in heidi
                    cmd.Parameters.AddWithValue("p1", personalContact.ContactFname);
                    cmd.Parameters.AddWithValue("p2", personalContact.ContactLname);
                    cmd.Parameters.AddWithValue("p3", personalContact.ContactEmail);
                    cmd.Parameters.AddWithValue("p4", personalContact.ContactAddr1);
                    cmd.Parameters.AddWithValue("p5", personalContact.ContactAddr2);
                    cmd.Parameters.AddWithValue("p6", personalContact.ContactCity);
                    cmd.Parameters.AddWithValue("p7", personalContact.ContactPostcode);
                    cmd.Parameters.AddWithValue("p8", personalContact.PersonalTel);
                    await cmd.ExecuteNonQueryAsync(); // await command shows parameters are passed and query will be awaited to complete
                }
            }
        }