//deletes everything in the employee benefits and employee tables
        private void ClearEmpBtn_Click(object sender, EventArgs e)
        {
            DialogResult Dr = MessageBox.Show("You pressed the button to completely clear all your employees from the database. Are you sure you want to do this?", "Clear Job Benefits", MessageBoxButtons.YesNo);

            if (Dr == DialogResult.Yes)
            {
                String query = " " +
                               "Delete from [Employee Benefits]; " +
                               "Delete from Employee;";

                using (connection = new SqlConnection(connectionString))
                    using (SqlCommand command = new SqlCommand(query, connection))
                        using (SqlDataAdapter adapter = new SqlDataAdapter(command))
                        {
                            try
                            {
                                connection.Open();
                                command.ExecuteNonQuery();
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message);
                            }
                        }
                this.Hide();
                EnterEmp En = new EnterEmp();
                En.Show();
            }
        }
Esempio n. 2
0
//------------------------------------------------------------------------------------------------------------------------------------The Button Click Events needed to navigate the various forms---------------------
//----------------------------------------------------------------------------------------------------------

        //closes the current page and then opens the Enter Employee page when the button is pressed
        private void EnterEmpBtn_Click(object sender, EventArgs e)
        {
            this.Hide();
            EnterEmp Ee = new EnterEmp();

            Ee.Show();
        }
        //deletes everything in the database
        private void ClearDatabaseBtn_Click(object sender, EventArgs e)
        {
            DialogResult Dr = MessageBox.Show("You pressed the button to completely clear your database of all data. Are you sure you want to do this?", "Clear Database", MessageBoxButtons.YesNo);

            if (Dr == DialogResult.Yes)
            {
                DialogResult dr = MessageBox.Show("Are you completely sure that you wish to clear your database? You cannot retrieve your database and it will be deleted forever", "Clear Database", MessageBoxButtons.YesNo);

                if (dr == DialogResult.Yes)
                {
                    String query = "Delete from [Employee Benefits]; " +
                                   "Delete from [Job Benefits]; " +
                                   "Delete from Entitlements; " +
                                   "Delete from Employee; " +
                                   "Delete from Jobs;";

                    using (connection = new SqlConnection(connectionString))
                        using (SqlCommand command = new SqlCommand(query, connection))
                            using (SqlDataAdapter adapter = new SqlDataAdapter(command))
                            {
                                try
                                {
                                    connection.Open();
                                    command.ExecuteNonQuery();
                                }
                                catch (Exception ex)
                                {
                                    MessageBox.Show(ex.Message);
                                }
                            }
                    this.Hide();
                    EnterEmp En = new EnterEmp();
                    En.Show();
                }
            }
        }