예제 #1
0
        private void btnAdminUsersEdit_Click(object sender, EventArgs e)
        {
            if (lvAdminUsers.SelectedItems.Count > 0)
            {
                FillFunctionsCMB();
                int employeeId = int.Parse(lvAdminUsers.SelectedItems[0].SubItems[0].Text);

                User user = userService.GetUserById(employeeId);

                admin_tbEditUsername.Text           = user.Name;
                admin_tbEditCode.Text               = user.EmployeeCode;
                admin_cmbEditFunction.SelectedIndex = user.FunctionId - 1;
                admin_tbEditQuestion.Text           = user.SecretQuestion;
                admin_tbEditAnswer.Text             = user.SecretAnswer;

                pnlAdminUsersEdit.Show();
            }
            else
            {
                CallErrorPanel($"Selecteer de gebruiker die u wilt bewerken.");
            }
        }
예제 #2
0
        //Updates the user by reducing the number of the old user tickets and increasing the number of new user tickets.
        //Also Ticket is updated here in order to change the user id.
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            User oldUser = ticket.ReportedByUser;

            string [] selectedUser = cmbUsers.SelectedItem.ToString().Split('.');
            int       id           = int.Parse(selectedUser[0]);
            User      newUser      = userService.GetUserById(id);

            if (oldUser.id != newUser.id)
            {
                try
                {
                    if (oldUser.nrTickets > 0)
                    {
                        oldUser.nrTickets--;
                        newUser.nrTickets++;
                        userService.UpdateUserTickets(oldUser);
                        userService.UpdateUserTickets(newUser);
                    }

                    ticket.ReportedByUser = newUser;
                    ticketService.UpdateTicketUser(ticket);
                    MessageBox.Show("User of the ticket is updated", "Transfer completed", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch
                {
                    MessageBox.Show("Something went wrong", "Error", MessageBoxButtons.OK);
                }
                finally
                {
                    this.Close();
                }
            }
            else
            {
                MessageBox.Show("Please do not pick the same user ", "Transfer failed", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }