Exemplo n.º 1
0
 private void lv_search_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (lv_search.SelectedIndices.Count > 0)
     {
         int          selIndex = lv_search.SelectedIndices[0];
         ListViewItem item     = lv_search.Items[selIndex];
         try
         {
             using (HBSModel _entity = new HBSModel())
             {
                 _selectedUser = _entity.Users.Find(Convert.ToInt32(item.SubItems[0].Text));
                 updateUserBox(
                     _selectedUser.Username.ToString(),
                     _selectedUser.Role.RoleName,
                     _selectedUser.Department.DepartmentName,
                     _selectedUser.StartDate,
                     _selectedUser.PhoneNumber);
             }
         }
         catch (Exception err)
         {
             DesktopAppUtils.popDefaultErrorMessageBox("Could not connect to DB \n" + err.Message);
         }
     }
 }
Exemplo n.º 2
0
        protected void loginRequest(object sender, EventArgs e)
        {
            try
            {
                LogoutMessageAlert.Visible = false;

                string username = usernameTextBox.Text.Trim();
                string password = passwordTextBox.Text.Trim();
                using (HBSModel _entity = new HBSModel())
                {
                    var _user = _entity.Users.FirstOrDefault(x => x.Username == username);
                    if (_user != null)
                    {
                        if (GeneralUtils.VerifyPasswordHash(password, _user.Pwd, _user.PwdSalt))
                        {
                            if (_user.Role.RoleName != GeneralUtils.ADMIN_ROLE)
                            {
                                Session["username"] = _user.Username;
                                Session["userId"]   = _user.id;
                                Response.Redirect("EmployeeHome");
                                return;
                            }
                        }
                    }
                    errorMessageLabel.Visible = true;
                    errorMessageLabel.Text    = "Incorrect login details";
                }
            }
            catch (Exception ex)
            {
                Response.Write("Server encountered an issue during login " + ex.Message);
            }
        }
Exemplo n.º 3
0
        private void btn_Search_Click(object sender, EventArgs e)
        {
            try
            {
                if (String.IsNullOrEmpty(tb_search.Text))
                {
                    throw new Exception("Empty search - please type a search value");
                }
                using (HBSModel _entity = new HBSModel())
                {
                    lv_search.Items.Clear();
                    var _users = _entity.Users.Where(user => user.Username.Contains(tb_search.Text) &&
                                                     user.Username != GeneralUtils.ADMIN_ROLE);

                    foreach (User user in _users.ToList())
                    {
                        string[] arr = new string[5];
                        arr[0] = user.id.ToString();
                        arr[1] = user.Username.ToString();
                        arr[2] = user.Role.RoleName;
                        arr[3] = user.Department.DepartmentName;
                        ListViewItem item = new ListViewItem(arr);
                        lv_search.Items.Add(item);
                    }
                }
            }
            catch (Exception err)
            {
                DesktopAppUtils.popDefaultErrorMessageBox("Something went wrong \n" + err.Message);
            }
        }
Exemplo n.º 4
0
 public ConstraintChecking(User user, HolidayRequest holidayRequest)
 {
     entity = new HBSModel();
     this.holidayRequest = holidayRequest;
     this.user           = user;
     usersFromDepartment = entity.Users.Where(x => x.DepartmentID == user.DepartmentID && x.id != user.id).ToList();
 }
Exemplo n.º 5
0
        public void initialiseEmployeesLists()
        {
            onHolidayEmployeesListView.Items.Clear();
            workingEmployeesListView.Items.Clear();
            var selectedDate = datePickCalendar.SelectionRange.Start;

            using (HBSModel entity = new HBSModel())
            {
                var users = entity.Users.Where(x => x.Username != GeneralUtils.ADMIN_ROLE).ToList();
                foreach (var user in users)
                {
                    if (user.HolidayRequests != null &&
                        user.HolidayRequests.Any(x => x.StatusRequest.Status == GeneralUtils.APPROVED &&
                                                 x.StartDate <= selectedDate && x.EndDate >= selectedDate))
                    {
                        string[] arr = new string[5];
                        arr[0] = user.id.ToString();
                        arr[1] = user.Username;
                        arr[2] = user.Department.DepartmentName;
                        ListViewItem item = new ListViewItem(arr);
                        onHolidayEmployeesListView.Items.Add(item);
                    }
                    else
                    {
                        string[] arr = new string[5];
                        arr[0] = user.id.ToString();
                        arr[1] = user.Username;
                        arr[2] = user.Department.DepartmentName;
                        ListViewItem item = new ListViewItem(arr);
                        workingEmployeesListView.Items.Add(item);
                    }
                }
            }
        }
Exemplo n.º 6
0
 public void initializeUserList()
 {
     lv_search.Items.Clear();
     try
     {
         using (HBSModel _entity = new HBSModel())
         {
             var _users = _entity.Users.Where(x => x.Username != GeneralUtils.ADMIN_ROLE);
             foreach (User usr in _users.ToList())
             {
                 string[] arr = new string[5];
                 arr[0] = usr.id.ToString();
                 arr[1] = usr.Username.ToString();
                 arr[2] = usr.Role.RoleName;
                 arr[3] = usr.Department.DepartmentName;
                 ListViewItem item = new ListViewItem(arr);
                 lv_search.Items.Add(item);
             }
         }
     }
     catch
     {
         DesktopAppUtils.popDefaultErrorMessageBox("Could not retrieve Item from DB");
     }
 }
        protected void submitHolidayRequest(object sender, EventArgs e)
        {
            DateTime startDate   = startDateCalendar.SelectedDate;
            DateTime endDate     = endDateCalendar.SelectedDate;
            int      workingDays = GeneralUtils.CalculateWorkingDays(startDate, endDate);

            startDate = GeneralUtils.simplifyStartDate(startDate);
            endDate   = GeneralUtils.simplifyEndDate(endDate);
            if (workingDays == 0)
            {
                displayHolidaySummary("You selected weekend days, no need for holiday allowance", GeneralUtils.DANGER_COLOR);
                return;
            }
            else if (workingDays > GeneralUtils.MAX_POSSIBLE_HOLIDAY)
            {
                displayHolidaySummary("Too many days selected, it exceeds the maximum allowance", GeneralUtils.DANGER_COLOR);
                return;
            }
            if (startDate.Year > DateTime.Now.Year || endDate.Year > DateTime.Now.Year)
            {
                displayHolidaySummary("Sorry, not accepting holiday requests for next year yet", GeneralUtils.DANGER_COLOR);
                return;
            }
            try
            {
                using (HBSModel _entity = new HBSModel())
                {
                    int userId = (int)Session["userId"];

                    HolidayRequest holidayRequest = new HolidayRequest()
                    {
                        StartDate    = startDate,
                        EndDate      = endDate,
                        UserID       = userId,
                        NumberOfDays = workingDays
                    };
                    var usr = _entity.Users.Find(userId);

                    if (usr.HolidayRequests.Where(x => x.StatusRequest.Status == GeneralUtils.APPROVED ||
                                                  x.StatusRequest.Status == GeneralUtils.PENDING)
                        .Any(x => GeneralUtils.isOverlappingHoliday(x, holidayRequest)))
                    {
                        displayHolidaySummary("There is an overlap with your current pending or approved requests", GeneralUtils.DANGER_COLOR);
                        return;
                    }
                    holidayRequest.RequestStatusID = _entity.StatusRequests
                                                     .FirstOrDefault(status => status.Status == GeneralUtils.PENDING).ID;
                    holidayRequest.ConstraintsBroken = new ConstraintChecking(usr, holidayRequest).getBrokenConstraints();
                    holidayRequest.DaysPeakTime      = PrioritiseRequests
                                                       .daysFallPeakTimesCount(holidayRequest.StartDate, holidayRequest.EndDate);
                    _entity.HolidayRequests.Add(holidayRequest);
                    _entity.SaveChanges();
                    Response.Redirect("/EmployeeHome?HolidayRequest=Success");
                }
            }
            catch
            {
                Response.Write("Server encountered an issue while submitting your request");
            }
        }
Exemplo n.º 8
0
 public void initializeUserList()
 {
     lv_users.Items.Clear();
     try
     {
         using (HBSModel _entity = new HBSModel())
         {
             var _users = _entity.Users.Where(x => x.Username != GeneralUtils.ADMIN_ROLE);
             foreach (User usr in _users.ToList())
             {
                 if (usr.Role.RoleName == GeneralUtils.ADMIN_ROLE)
                 {
                     continue;
                 }
                 string[] arr = new string[7];
                 arr[0] = usr.id.ToString();
                 arr[1] = usr.Username;
                 arr[2] = usr.StartDate.ToString().Substring(0, 10);
                 arr[3] = usr.RemainingDays.ToString() == "" ? "N/A" : usr.RemainingDays.ToString();
                 arr[4] = usr.Role.RoleName;
                 arr[5] = usr.Department.DepartmentName;
                 arr[6] = String.IsNullOrEmpty(usr.PhoneNumber) ? "N/A" : usr.PhoneNumber;
                 ListViewItem item = new ListViewItem(arr);
                 lv_users.Items.Add(item);
             }
         }
     }
     catch (Exception err)
     {
         DesktopAppUtils.popDefaultErrorMessageBox("Could not retrieve Item from DB \n" + err.Message);
     }
 }
 public static void AddRoles()
 {
     using (HBSModel _entity = new HBSModel())
     {
         if (_entity.Roles.Count() < 2)
         {
             _entity.Roles.Add(new Role()
             {
                 RoleName = "Head"
             });
             _entity.Roles.Add(new Role()
             {
                 RoleName = "Deputy Head"
             });
             _entity.Roles.Add(new Role()
             {
                 RoleName = "Manager"
             });
             _entity.Roles.Add(new Role()
             {
                 RoleName = "Apprentice"
             });
             _entity.Roles.Add(new Role()
             {
                 RoleName = "Senior"
             });
             _entity.Roles.Add(new Role()
             {
                 RoleName = "Junior"
             });
             _entity.SaveChanges();
         }
     }
 }
 public static void AddDepartments()
 {
     using (HBSModel entity = new HBSModel())
     {
         if (entity.Departments.Count() < 2)
         {
             entity.Departments.Add(new Department()
             {
                 DepartmentName = "Engineering"
             });
             entity.Departments.Add(new Department()
             {
                 DepartmentName = "Plumbing"
             });
             entity.Departments.Add(new Department()
             {
                 DepartmentName = "Roofing"
             });
             entity.Departments.Add(new Department()
             {
                 DepartmentName = "Carpentry"
             });
             entity.Departments.Add(new Department()
             {
                 DepartmentName = "Bricklaying"
             });
             entity.Departments.Add(new Department()
             {
                 DepartmentName = "Office"
             });
             entity.SaveChanges();
         }
     }
 }
        public static void RegisterAdmin()
        {
            using (HBSModel _entity = new HBSModel())
            {
                if (_entity.Users.Any(x => x.Username == GeneralUtils.ADMIN_ROLE))
                {
                    return;
                }
                Role role = new Role()
                {
                    RoleName = GeneralUtils.ADMIN_ROLE
                };

                Department department = new Department()
                {
                    DepartmentName = "Management"
                };
                User admin = new User();
                admin.Username = GeneralUtils.ADMIN_ROLE;
                byte[] passwordHash, passwordSalt;
                GeneralUtils.CreatePasswordHash("Test123!", out passwordHash, out passwordSalt);
                admin.Pwd          = passwordHash;
                admin.PwdSalt      = passwordSalt;
                admin.RoleID       = role.ID;
                admin.DepartmentID = department.ID;
                _entity.Users.Add(admin);

                role.Users.Add(admin);
                department.Users.Add(admin);
                _entity.Roles.Add(role);
                _entity.Departments.Add(department);

                _entity.SaveChanges();
            }
        }
Exemplo n.º 12
0
 public ConstraintChecking(int userId, DateTime holidayStartDate, DateTime holidayEndDate)
 {
     entity = new HBSModel();
     this.holidayRequest = entity.HolidayRequests
                           .FirstOrDefault(x => x.EndDate == holidayEndDate && x.StartDate == holidayStartDate && x.UserID == userId);
     this.user           = entity.Users.Find(userId);
     usersFromDepartment = entity.Users.Where(x => x.DepartmentID == user.DepartmentID && x.id != user.id).ToList();
 }
Exemplo n.º 13
0
 private void employeesComboBox_SelectedIndexChanged(object sender, EventArgs e)
 {
     using (HBSModel entity = new HBSModel())
     {
         ComboItem itm             = (ComboItem)employeesComboBox.SelectedItem;
         var       holidayBookings = entity.HolidayRequests.Where(x => x.UserID == itm.ID &&
                                                                  x.StatusRequest.Status == GeneralUtils.APPROVED).ToList();
         populateBookingsList(holidayBookings);
     }
 }
Exemplo n.º 14
0
        public void initializeRequestsList()
        {
            outstandingHolidaysListView.Items.Clear();
            try
            {
                messageLabel.Visible = false;
                using (HBSModel _entity = new HBSModel())
                {
                    var prioritiseReqs = (from el in _entity.HolidayRequests
                                          where el.StatusRequest.Status == GeneralUtils.PENDING
                                          select new PriorityRequest()
                    {
                        Constraints = new BreakingConstraints()
                        {
                            AtLeastPercentage = el.ConstraintsBroken.AtLeastPercentage,
                            ExceedsHolidayEntitlement = el.ConstraintsBroken.ExceedsHolidayEntitlement,
                            HeadOrDeputy = el.ConstraintsBroken.HeadOrDeputy,
                            ManagerOrSenior = el.ConstraintsBroken.ManagerOrSenior
                        },
                        WorkingDays = el.NumberOfDays,
                        DaysPeakTime = el.DaysPeakTime,
                        EndDate = el.EndDate,
                        ID = el.ID,
                        RemainingDays = el.User.RemainingDays,
                        StartDate = el.StartDate,
                        InitialHolidayEntitlement = el.User.InitialHolidayEntitlement,
                        TotalPeakDaysHoliday = el.User.TotalPeakDaysHoliday
                    }).ToList();
                    var ordered = new PrioritiseRequests(prioritiseReqs).getPrioritisedRequests();
                    foreach (var request in ordered)
                    {
                        string[] arr = new string[4];
                        arr[0] = request.ID.ToString();
                        arr[1] = request.StartDate.ToShortDateString();
                        arr[2] = request.EndDate.ToShortDateString();
                        arr[3] = request.WorkingDays.ToString();
                        ListViewItem item = new ListViewItem(arr);
                        if (PriorityRequest.isAnyConstraintBroken(request.Constraints))
                        {
                            item.BackColor = Color.SandyBrown;
                        }
                        else
                        {
                            item.BackColor = Color.Lime;
                        }

                        outstandingHolidaysListView.Items.Add(item);
                    }
                }
            }
            catch (Exception err)
            {
                DesktopAppUtils.popDefaultErrorMessageBox("Could not retrieve Item from DB \n" + err.Message);
            }
        }
Exemplo n.º 15
0
 public void populateEmployeesDropdown(int departmentId)
 {
     using (HBSModel entity = new HBSModel())
     {
         var employees = entity.Users.Where(x => x.DepartmentID == departmentId).ToList();
         employeesComboBox.Items.Clear();
         foreach (var employee in employees)
         {
             employeesComboBox.Items.Add(new ComboItem(employee.Username, employee.id));
         }
     }
 }
Exemplo n.º 16
0
 public void populateEmployeesDropdown()
 {
     using (HBSModel entity = new HBSModel())
     {
         var employees = entity.Users.Where(x => x.Username != GeneralUtils.ADMIN_ROLE).ToList();
         employeesComboBox.Items.Clear();
         foreach (var employee in employees)
         {
             employeesComboBox.Items.Add(new ComboItem(employee.Username, employee.id));
         }
     }
 }
        private void searchBookingsButton_Click(object sender, EventArgs e)
        {
            if (employeeDropDown.SelectedIndex == -1)
            {
                DesktopAppUtils.popDefaultErrorMessageBox("No employee selected");
                return;
            }
            ComboItem employee = (ComboItem)employeeDropDown.SelectedItem;

            if (employee.ID == -1)
            {
                DesktopAppUtils.popDefaultErrorMessageBox("No employee selected");
                return;
            }
            if (departmentDropDown.SelectedIndex == -1)
            {
                DesktopAppUtils.popDefaultErrorMessageBox("No department selected");
                return;
            }
            if (monthDropDown.SelectedIndex == -1)
            {
                DesktopAppUtils.popDefaultErrorMessageBox("No month selected");
                return;
            }
            ComboItem month = (ComboItem)monthDropDown.SelectedItem;
            object    year  = yearDropDown.SelectedItem;

            this.Cursor = Cursors.WaitCursor;
            if (currentlySelectedEmployeeId == employee.ID)
            {
                calendarDataVisualization1.ChangeSelection(month.ID, int.Parse(year.ToString()));
            }
            else
            {
                currentlySelectedEmployeeId = employee.ID;
                using (HBSModel model = new HBSModel())
                {
                    var holidayRequests = model.HolidayRequests.Where(x => x.UserID == employee.ID &&
                                                                      x.StatusRequest.Status == GeneralUtils.APPROVED).ToList();
                    List <DateRange> dateRanges = new List <DateRange>();
                    foreach (HolidayRequest holidayRequest in holidayRequests)
                    {
                        dateRanges.Add(new DateRange(holidayRequest.StartDate, holidayRequest.EndDate));
                    }
                    calendarDataVisualization1.ClearDateRanges();
                    calendarDataVisualization1.AddDateRangesList(dateRanges);
                    calendarDataVisualization1.ChangeSelection(month.ID, int.Parse(year.ToString()));
                }
            }
            selectedMonthLabel.Text = "Selected Month: " + month.Text + " " + year.ToString();
            this.Cursor             = Cursors.Default;
        }
Exemplo n.º 18
0
 public void initializeHolidayBookingsList()
 {
     using (HBSModel entity = new HBSModel())
     {
         var holidayBookings = entity.HolidayRequests
                               .Where(x => x.StatusRequest.Status == GeneralUtils.APPROVED).ToList();
         populateBookingsList(holidayBookings);
         var departments = entity.Departments.Where(x => x.DepartmentName != GeneralUtils.MANAGEMENT_DEPARTMENT);
         departmentComboBox.Items.Clear();
         foreach (var department in departments)
         {
             departmentComboBox.Items.Add(new ComboItem(department.DepartmentName, department.ID));
         }
     }
 }
Exemplo n.º 19
0
        private void btn_details_Click(object sender, EventArgs e)
        {
            usernameErrorLabel.Visible = false;
            phoneErrorLabel.Visible    = false;
            bool noErrors = true;

            try
            {
                if (String.IsNullOrEmpty(_selectedUser.Username))
                {
                    throw new Exception("No User selected");
                }
                if (String.IsNullOrEmpty(tb_username.Text) || (tb_username.Text.Length < 6))
                {
                    usernameErrorLabel.Visible = true;
                    noErrors = false;
                }
                if (!String.IsNullOrEmpty(tb_phoneNumber.Text))
                {
                    if (!tb_phoneNumber.ValidInput())
                    {
                        phoneErrorLabel.Text    = "The phone number entered is not in a valid format";
                        phoneErrorLabel.Visible = true;
                        noErrors = false;
                    }
                }
                if (noErrors)
                {
                    using (HBSModel _entity = new HBSModel())
                    {
                        var _user = _entity.Users.FirstOrDefault(user => user.Username == _selectedUser.Username);
                        _user.Username     = tb_username.Text;
                        _user.RoleID       = _entity.Roles.SingleOrDefault(role => role.RoleName == cb_roles.SelectedItem.ToString()).ID;
                        _user.DepartmentID = _entity.Departments.SingleOrDefault(role => role.DepartmentName == cb_departments.SelectedItem.ToString()).ID;
                        _user.StartDate    = dp_edit.Value.Date;
                        _user.PhoneNumber  = tb_phoneNumber.Text;
                        _selectedUser      = _user;
                        _entity.SaveChanges();
                    }
                    initializeUserList();
                    initalizeUserInputs();
                }
            }
            catch (Exception err)
            {
                DesktopAppUtils.popDefaultErrorMessageBox("Error:\n" + err.Message);
            }
        }
Exemplo n.º 20
0
        private void declineHolidayRequest()
        {
            int          selIndex = outstandingHolidaysListView.SelectedIndices[0];
            ListViewItem item     = outstandingHolidaysListView.Items[selIndex];

            using (HBSModel entity = new HBSModel())
            {
                var request = entity.HolidayRequests.Find(Convert.ToInt32(item.SubItems[0].Text));
                request.RequestStatusID = entity.StatusRequests.FirstOrDefault(x => x.Status == GeneralUtils.DECLINED).ID;
                entity.SaveChanges();
            }
            messageLabel.Visible   = true;
            messageLabel.Text      = "Request " + item.SubItems[0].Text + " Declined";
            messageLabel.BackColor = Color.DarkRed;
            outstandingHolidaysListView.Items.RemoveAt(selIndex);
        }
        public int EmployeeLogin(string username, string password)
        {
            using (HBSModel _entity = new HBSModel())
            {
                var _user = _entity.Users.FirstOrDefault(x => x.Username == username);
                if (_user == null)
                {
                    return(-1);
                }
                if (!GeneralUtils.VerifyPasswordHash(password, _user.Pwd, _user.PwdSalt) || _user.Role.RoleName == GeneralUtils.ADMIN_ROLE)
                {
                    return(-2);
                }

                return(1);
            }
        }
Exemplo n.º 22
0
        private void approveHolidayRequest()
        {
            int          selIndex = outstandingHolidaysListView.SelectedIndices[0];
            ListViewItem item     = outstandingHolidaysListView.Items[selIndex];

            using (HBSModel entity = new HBSModel())
            {
                var request = entity.HolidayRequests.Find(Convert.ToInt32(item.SubItems[0].Text));
                request.User.RemainingDays = request.User.RemainingDays - request.NumberOfDays;
                request.RequestStatusID    = entity.StatusRequests.FirstOrDefault(x => x.Status == GeneralUtils.APPROVED).ID;
                entity.SaveChanges();
            }
            messageLabel.Visible   = true;
            messageLabel.Text      = "Request " + item.SubItems[0].Text + " Approved";
            messageLabel.BackColor = Color.Green;
            outstandingHolidaysListView.Items.RemoveAt(selIndex);
        }
Exemplo n.º 23
0
        private void btn_login_Click(object sender, EventArgs e)
        {
            if (btn_login.Cursor == Cursors.No)
            {
                return;
            }
            try
            {
                string username = tb_username.Text.Trim();
                string password = tb_password.Text.Trim();
                if (!inputValuesChanged(username, password))
                {
                    throw new Exception("Username and password must not be empty");
                }
                using (HBSModel _entity = new HBSModel())
                {
                    var _user = _entity.Users.FirstOrDefault(x => x.Username == username);
                    if (_user == null)
                    {
                        throw new Exception("User not found");
                    }
                    if (!GeneralUtils.VerifyPasswordHash(password, _user.Pwd, _user.PwdSalt))
                    {
                        throw new Exception("Invalid login attempt");
                    }

                    // Only users matching the role Head and beloging to the Office department can login as admins
                    if (_user.Role.RoleName != GeneralUtils.ADMIN_ROLE)
                    {
                        throw new Exception("Only admins can login with this app");
                    }
                }
            }
            catch (Exception ex)
            {
                DesktopAppUtils.popDefaultErrorMessageBox(ex.Message);
                return;
            }

            this.Hide();
            Dashboard dashboard = new Dashboard();

            dashboard.ShowDialog();
            this.Close();
        }
Exemplo n.º 24
0
 private void suggestionsButton_Click(object sender, EventArgs e)
 {
     if (selectedItem != null)
     {
         if (suggestionsPanel.Contains(groupBox3))
         {
             groupBox3.SendToBack();
             UC_Suggestions.Instance.Show();
             UC_Suggestions.Instance.BringToFront();
             UC_Suggestions.Instance.clearSuggestions();
             using (HBSModel entity = new HBSModel())
             {
                 var request = entity.HolidayRequests.Find(Convert.ToInt32(selectedItem.SubItems[0].Text));
                 UC_Suggestions.Instance.findSuggestions(request);
             }
         }
     }
 }
Exemplo n.º 25
0
 public void ConfirmSuggestion(DateTime startDate, DateTime endDate)
 {
     messageLabel.Text      = "Request ID " + selectedItem.SubItems[0].Text + " was sent back for approval";
     messageLabel.BackColor = Color.DarkOrange;
     messageLabel.Visible   = true;
     using (HBSModel entity = new HBSModel())
     {
         var request = entity.HolidayRequests.Find(Convert.ToInt32(selectedItem.SubItems[0].Text));
         request.RequestStatusID = entity.StatusRequests.FirstOrDefault(x => x.Status == GeneralUtils.CHANGED).ID;
         request.StartDate       = startDate;
         request.EndDate         = endDate;
         entity.SaveChanges();
     }
     selectedItem = null;
     outstandingHolidaysListView.Items.RemoveAt(currentlySelectedIndex);
     UC_Suggestions.Instance.Hide();
     initializeConstraintsLabels();
 }
        public void fillEmployeesDropDown(int departmentId)
        {
            employeeDropDown.Items.Clear();
            employeeDropDown.SelectedIndex = -1;

            using (HBSModel model = new HBSModel())
            {
                var employees = model.Users.Where(x => x.DepartmentID == departmentId)
                                .OrderBy(x => x.Username).ToList();
                foreach (var employee in employees)
                {
                    employeeDropDown.Items.Add(new ComboItem(employee.Username, employee.id));
                }
                if (employees.Count() == 0)
                {
                    employeeDropDown.Items.Add(new ComboItem("No employee found", -1));
                }
            }
        }
Exemplo n.º 27
0
        private void btn_password_Click(object sender, EventArgs e)
        {
            confirmPasswordErrorLabel.Visible = false;
            passwordErrorLabel.Visible        = false;
            bool noErrors = true;

            try
            {
                if (String.IsNullOrEmpty(_selectedUser.Username))
                {
                    throw new Exception("No User selected");
                }
                if (tb_password.Text != tb_repeat_password.Text)
                {
                    confirmPasswordErrorLabel.Visible = true;
                    noErrors = false;
                }
                if (!GeneralUtils.checkPasswordComplexity(tb_password.Text))
                {
                    passwordErrorLabel.Visible = true;
                    noErrors = false;
                }
                if (noErrors)
                {
                    using (HBSModel _entity = new HBSModel())
                    {
                        var    _user = _entity.Users.FirstOrDefault(user => user.Username == _selectedUser.Username);
                        byte[] passwordHash, passwordSalt;
                        GeneralUtils.CreatePasswordHash(tb_password.Text, out passwordHash, out passwordSalt);
                        _user.Pwd     = passwordHash;
                        _user.PwdSalt = passwordSalt;
                        _entity.SaveChanges();
                        MessageBox.Show("Password Updated", "Update", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        initalizeUserInputs();
                    }
                }
            }
            catch (Exception ex)
            {
                DesktopAppUtils.popDefaultErrorMessageBox("Error:\n" + ex.Message);
            }
        }
        public void InitializeDropdowns()
        {
            yearDropDown.Items.AddRange(new object[] { DateTime.Now.Year, DateTime.Now.Year + 1 });
            for (int i = 1; i < 13; i++)
            {
                monthDropDown.Items.Add(new ComboItem(GeneralUtils.getMonthName(i), i));
            }
            yearDropDown.SelectedIndex = 0;
            using (HBSModel model = new HBSModel())
            {
                departments = model.Departments.OrderBy(x => x.DepartmentName).ToList();
                fillEmployeesDropDown(departments.ElementAt(0).ID);
            }

            departmentDropDown.Items.Clear();
            foreach (var department in departments)
            {
                departmentDropDown.Items.Add(new ComboItem(department.DepartmentName, department.ID));
            }
        }
 public int HolidayRequest(DateTime startDate, DateTime endDate, int workingDays, string username, string password)
 {
     if (startDate > endDate || startDate < DateTime.Now.AddDays(2) || workingDays == 0)
     {
         return(-4);
     }
     try
     {
         using (HBSModel _entity = new HBSModel())
         {
             var _user = _entity.Users.FirstOrDefault(x => x.Username == username);
             if (_user == null)
             {
                 return(-1);
             }
             if (!GeneralUtils.VerifyPasswordHash(password, _user.Pwd, _user.PwdSalt) || _user.Role.RoleName == GeneralUtils.ADMIN_ROLE)
             {
                 return(-2);
             }
             HolidayRequest holidayRequest = new HolidayRequest()
             {
                 StartDate    = startDate,
                 EndDate      = endDate,
                 UserID       = _user.id,
                 NumberOfDays = workingDays
             };
             holidayRequest.RequestStatusID = _entity.StatusRequests
                                              .FirstOrDefault(status => status.Status == GeneralUtils.PENDING).ID;
             holidayRequest.ConstraintsBroken = new ConstraintChecking(_user, holidayRequest).getBrokenConstraints();
             holidayRequest.DaysPeakTime      = PrioritiseRequests
                                                .daysFallPeakTimesCount(holidayRequest.StartDate, holidayRequest.EndDate);
             _entity.HolidayRequests.Add(holidayRequest);
             _entity.SaveChanges();
         }
     }
     catch
     {
         return(-3);
     }
     return(1);
 }
Exemplo n.º 30
0
 private void btn_delete_Click(object sender, EventArgs e)
 {
     try {
         int          selIndex = lv_users.SelectedIndices[0];
         ListViewItem item     = lv_users.Items[selIndex];
         if (MessageBox.Show("Are you sure you want to delete this record?", "Confirm deletion", MessageBoxButtons.YesNo) == DialogResult.Yes)
         {
             using (HBSModel _entity = new HBSModel())
             {
                 User userDelete = _entity.Users.Find(Convert.ToInt32(item.SubItems[0].Text));
                 _entity.Users.Remove(userDelete);
                 _entity.SaveChanges();
             }
             initializeUserList();
         }
     }
     catch (Exception ex)
     {
         DesktopAppUtils.popDefaultErrorMessageBox("Could not complete delete operation. Ensure to select a user.\n" + ex.Message);
     }
 }