예제 #1
0
        //Show description of benefit currently in benefits box
        private void showBenefitDescription()
        {
            BeneDescBox.Clear();
            String query = "select [Description] from [Entitlements] where EntitlementID = @EntitlementID";

            using (connection = new SqlConnection(connectionString))
                using (SqlCommand command = new SqlCommand(query, connection))
                    using (SqlDataAdapter adapter = new SqlDataAdapter(command))
                    {
                        command.Parameters.AddWithValue("@EntitlementID", AddBeneBox.Text);

                        connection.Open();
                        SqlDataReader cr = command.ExecuteReader();
                        if (cr.Read())
                        {
                            BeneDescBox.Text = (cr["Description"].ToString());
                        }
                    }
        }
        //Deletes any use of a chosen entitlement from the employee benefits and job benefits and sets all fields of the entitlement, except the ID number, to NULL
        private void DeleteBeneBtn_Click(object sender, EventArgs e)
        {
            if (BeneBox.Items.Count > 0)
            {
                String query = " " +
                               "Delete from [Employee Benefits] where EntitlementID = @ID; " +
                               "Delete from [Job Benefits] where EntitlementID = @ID;" +
                               "update Entitlements set Description = NULL where EntitlementID = @ID;";

                using (connection = new SqlConnection(connectionString))
                    using (SqlCommand command = new SqlCommand(query, connection))
                        using (SqlDataAdapter adapter = new SqlDataAdapter(command))
                        {
                            command.Parameters.AddWithValue("@ID", BeneBox.Text);

                            try
                            {
                                connection.Open();
                                command.ExecuteNonQuery();
                                MessageBox.Show("Entitlement Deleted");
                                showBenefits();
                                if (BeneBox.Items.Count == 0)
                                {
                                    BeneDescBox.Clear();
                                }
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message);
                            }
                        }
            }
            else
            {
                MessageBox.Show("No Benefit to delete");
            }
        }