public void Edit_Admin_ListedUser()
        {
            #region
            try
            {
                string sqlQuery1 = $"INSERT INTO dbo.DatabaseHistory" +
                                   $" VALUES ('Listed User Record with EmployeeID = {Admin_ListedUsers_ListedUsersDetails_EmployeeID_TextBox.Text} was UPDATED at {DateTime.Now.ToString("MM/dd/yyyy hh:mm tt")}', @Username)";

                string sqlQuery2 = "UPDATE dbo.ListedUsers" +
                                   " SET Email = @Email," +
                                   " PhoneNo = @PhoneNo," +
                                   " Department = @Department" +
                                   " WHERE EmployeeID = @EmployeeID";

                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();

                    SqlCommand cmd1 = new SqlCommand(sqlQuery1, conn);
                    cmd1.Parameters.AddWithValue("@EmployeeID", Admin_ListedUsers_ListedUsersDetails_EmployeeID_TextBox.Text);
                    cmd1.Parameters.AddWithValue("@Username", Admin_ListedUsers_LoginDetails_LoggedInAs_TextBox.Text);

                    SqlCommand cmd2 = new SqlCommand(sqlQuery2, conn);
                    cmd2.Parameters.AddWithValue("@EmployeeID", Admin_ListedUsers_ListedUsersDetails_EmployeeID_TextBox.Text);
                    cmd2.Parameters.AddWithValue("@Email", Admin_ListedUsers_ListedUsersDetails_Email_TextBox.Text);
                    cmd2.Parameters.AddWithValue("@PhoneNo", Admin_ListedUsers_ListedUsersDetails_PhoneNo_TextBox.Text);
                    cmd2.Parameters.AddWithValue("@Department", Admin_ListedUsers_ListedUsersDetails_Department_Dropdown.Text);


                    DialogResult dialog = MessageBox.Show($"Are you sure you want to make the following changes to this Employee record with EmployeeID = {Admin_ListedUsers_ListedUsersDetails_EmployeeID_TextBox.Text}?:" +
                                                          $"\n\nEmail:\t\t{Admin_ListedUsers_ListedUsersDetails_Email_TextBox.Text}" +
                                                          $"\nPhoneNo:\t{Admin_ListedUsers_ListedUsersDetails_PhoneNo_TextBox.Text}" +
                                                          $"\nDepartment\t{Admin_ListedUsers_ListedUsersDetails_Department_Dropdown.Text}",
                                                          "Update Record", MessageBoxButtons.YesNo);

                    if (dialog == DialogResult.Yes)
                    {
                        int a = cmd1.ExecuteNonQuery();

                        if (a > 0)
                        {
                            MessageBox.Show("Record Updated Successfully", "Successful Update", MessageBoxButtons.OK);
                            cmd2.ExecuteNonQuery();
                        }
                        else
                        {
                            MessageBox.Show("Record Update Failed", "Failed Update", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        Admin_ListedUsers a_lu = new Admin_ListedUsers(Admin_ListedUsers_LoginDetails_LoggedInAs_TextBox.Text, Admin_ListedUsers_LoginDetails_UserLevel_TextBox.Text);
                        this.Hide();
                        a_lu.ShowDialog();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            #endregion
        }
Example #2
0
 private void Load_Admin_ListedUsers()
 {
     #region
     Admin_ListedUsers lup = new Admin_ListedUsers(NewUser_LoginDetails_LoggedInAs_TextBox.Text, NewUser_LoginDetails_UserLevel_TextBox.Text);
     this.Hide();
     lup.ShowDialog();
     #endregion
 }
 public void Load_Admin_ListedUsers()
 {
     #region
     Admin_ListedUsers a_lup = new Admin_ListedUsers(Admin_LoginDetails_LoggedInAs_TextBox.Text, Admin_LoginDetails_UserLevel_TextBox.Text);
     this.Hide();
     a_lup.ShowDialog();
     #endregion
 }
        public void Delete_Admin_ListedUser()
        {
            #region
            try
            {
                string sqlQuery1 = $"INSERT INTO dbo.DatabaseHistory" +
                                   $" VALUES('ListedUser Record with EmployeeID = {Admin_ListedUsers_ListedUsersDetails_EmployeeID_TextBox.Text} was DELETED at {DateTime.Now.ToString("MM/dd/yyyy hh:mm tt")}', @Username)";

                string sqlQuery2 = $"DELETE FROM dbo.LoginDetails WHERE Username = @Username;";

                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();

                    SqlCommand cmd1 = new SqlCommand(sqlQuery1, conn);
                    cmd1.Parameters.AddWithValue("@EmployeeID", Admin_ListedUsers_ListedUsersDetails_EmployeeID_TextBox.Text);
                    cmd1.Parameters.AddWithValue("@Username", Admin_ListedUsers_LoginDetails_LoggedInAs_TextBox.Text);

                    SqlCommand cmd2 = new SqlCommand(sqlQuery2, conn);
                    cmd2.Parameters.AddWithValue("@Username", Admin_ListedUsers_ListedUsersDetails_Username_TextBox.Text);


                    DialogResult dialog = MessageBox.Show("Are you sure you want to delete this Listed User?:" +
                                                          $"\n\nStudentID:\t{Admin_ListedUsers_ListedUsersDetails_EmployeeID_TextBox.Text}" +
                                                          $"\nUsername:\t{Admin_ListedUsers_ListedUsersDetails_Username_TextBox.Text}" +
                                                          $"\nFirst Name:\t{Admin_ListedUsers_ListedUsersDetails_Surname_TextBox.Text}" +
                                                          $"\nSurname:\t{Admin_ListedUsers_ListedUsersDetails_FirstName_TextBox.Text}" +
                                                          $"\nEmail:\t\t{Admin_ListedUsers_ListedUsersDetails_Email_TextBox.Text}" +
                                                          $"\nPhoneNo:\t{Admin_ListedUsers_ListedUsersDetails_PhoneNo_TextBox.Text}",
                                                          "Delete Record", MessageBoxButtons.YesNo
                                                          );
                    if (dialog == DialogResult.Yes)
                    {
                        int a = cmd1.ExecuteNonQuery();

                        if (a > 0)
                        {
                            MessageBox.Show("Record Deleted Successfully", "Successful Delete", MessageBoxButtons.OK);

                            cmd2.ExecuteNonQuery();
                        }
                        else
                        {
                            MessageBox.Show("Record Deletion Failed. Please try again", "Failed Delete", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        Admin_ListedUsers lup = new Admin_ListedUsers(Admin_ListedUsers_LoginDetails_LoggedInAs_TextBox.Text, Admin_ListedUsers_LoginDetails_UserLevel_TextBox.Text);
                        this.Hide();
                        lup.ShowDialog();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            #endregion
        }