private void EmployeesForm_Load(object sender, EventArgs e) { try { DatabaseFunctions.GetAllUsers(); DatabaseFunctions.GetAllDepartments(); employeesLv.Items.Clear(); foreach (var item in Users.users) { ListViewItem lvi = new ListViewItem(item.ID.ToString()); lvi.SubItems.Add(item.FirstName); lvi.SubItems.Add(item.LastName); lvi.SubItems.Add(item.Email); lvi.SubItems.Add(item.PhoneNumber); lvi.SubItems.Add(item.Position.ToString()); lvi.SubItems.Add(item.Salary.ToString("C2", CultureInfo.CurrentCulture)); lvi.SubItems.Add(item.UserDepartment.Name); employeesLv.Items.Add(lvi); } departmentCb.Items.Clear(); departmentCb.Items.Add("Department"); departmentCb.Items.Add("All Departments"); departmentCb.SelectedIndex = 0; foreach (var item in Departments.departments) { departmentCb.Items.Add(item.Name); } roleCb.SelectedIndex = 0; } catch (NoConnectionException) { MessageBox.Show("Connection unsuccessful, please restart", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (NotExistingException) { MessageBox.Show("Department is non-existent, please restart", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } AnimateWindow(this.Handle, 500, AnimateWindowFlags.AW_SLIDE); }
public MainForm() { InitializeComponent(); usernameTb.Click += new EventHandler(click_username); usernameTb.Leave += new EventHandler(leave_username); passwordTb.Click += new EventHandler(click_password); passwordTb.Leave += new EventHandler(leave_password); try { if (!DatabaseFunctions.GetAllUsers() && !DatabaseFunctions.GetAllProducts()) { MessageBox.Show("Loading Data Failure, please restart", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (!DatabaseFunctions.GetAllDepartments()) { MessageBox.Show("Loading Data Failure, please restart", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (!File.Exists("idSeeder")) { string id = (Users.LastGenUsernameId() + 1).ToString(); File.WriteAllLines("idSeeder", new string[] { id }); } } catch (NoConnectionException) { MessageBox.Show("Loading Data Failure, please restart", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (IOException) { MessageBox.Show("Loading Data Failure, please restart", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static void RemoveUser(User user) { DatabaseFunctions.RemoveUser(user); DatabaseFunctions.GetAllUsers(); }
public static void UpdateUser(User user) { DatabaseFunctions.UpdateUser(user); DatabaseFunctions.GetAllUsers(); }
public static void AddUser(User user, bool manager = false) { DatabaseFunctions.AddUser(user, manager); DatabaseFunctions.GetAllUsers(); }
private void confirmBtn_Click(object sender, EventArgs e) { try { if (!string.IsNullOrWhiteSpace(firstNameTb.Text) && !string.IsNullOrWhiteSpace(lastNameTb.Text) && !string.IsNullOrWhiteSpace(emailTb.Text) && !string.IsNullOrWhiteSpace(salaryTb.Text)) { if (shiftCb.SelectedIndex > 0 && departmentCb.SelectedIndex > 0 && roleCb.SelectedIndex > 0) { const string emailPattern = "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$"; Regex regex = new Regex(emailPattern); if (regex.IsMatch(emailTb.Text)) { string fn = firstNameTb.Text; string ln = lastNameTb.Text; string email = emailTb.Text; string salaryStr = Regex.Replace(salaryTb.Text, "€", ""); double salary = double.Parse(salaryStr.Trim()); Department department = Departments.DepartmentByName(departmentCb.SelectedItem.ToString()); PersonPosition position = (PersonPosition)Enum.Parse(typeof(PersonPosition), roleCb.Text, true); if ((position == PersonPosition.Manager && Users.admin) || (position != PersonPosition.Manager)) { ShiftType type = (ShiftType)Enum.Parse(typeof(ShiftType), shiftCb.Text, true); bool[] _days = new bool[7]; _days[0] = mondayCbx.Checked; _days[1] = tuesdayCbx.Checked; _days[2] = wednesdayCbx.Checked; _days[3] = thursdayCbx.Checked; _days[4] = fridayCbx.Checked; _days[5] = saturdayCbx.Checked; _days[6] = sundayCbx.Checked; if (_edit) { _userToBeEdited.FirstName = fn; _userToBeEdited.LastName = ln; _userToBeEdited.Email = email; _userToBeEdited.Position = position; _userToBeEdited.Salary = salary; _userToBeEdited.ShiftTypeU = type; _userToBeEdited.WorkingDays = _days; _userToBeEdited.UserDepartment = department; Users.UpdateUser(_userToBeEdited); } else { if (position == PersonPosition.Manager) { Users.AddUser(new User(fn, ln, email, position, salary, type, _days, department), true); } else { Users.AddUser(new User(fn, ln, email, position, salary, type, _days, department)); } } DatabaseFunctions.GetAllUsers(); this.Close(); } else { MessageBox.Show("Managers can be added just by admin profile!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Please, select a valid Email!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Choose valid shift!"); } } else { MessageBox.Show("Fill in the empty fields!"); } } catch (FormatException) { MessageBox.Show("Salary must be numeric!"); } catch (NoConnectionException) { MessageBox.Show("Connection unsuccessful, please restart", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (NotExistingException) { MessageBox.Show("User is non-existent, please restart", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (UsernameErrorException) { MessageBox.Show("Error occured, when tried to generate username, please restart", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (IOException) { MessageBox.Show("Error loading resources, please restart", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnEmployeeStatistics_Click(object sender, EventArgs e) { lbStatistics.Items.Clear(); if (cbEmployeeDepartment.SelectedIndex > -1) { string departmentName = cbEmployeeDepartment.SelectedItem.ToString(); double avgSalary = 0; int[] shifts = new int[3]; int favouriteShift = 0; Users.GetUsers(6, departmentName); int employees = Users.requestedUsers.Count; foreach (User user in Users.requestedUsers) { avgSalary += user.Salary; if (user.ShiftTypeU == ShiftType.Day) { shifts[0]++; } else if (user.ShiftTypeU == ShiftType.Night) { shifts[1]++; } else if (user.ShiftTypeU == ShiftType.HalfDay) { shifts[2]++; } } favouriteShift = shifts.Max(); int index = Array.IndexOf(shifts, favouriteShift); lbStatistics.Items.Add($"The average salary for the department {departmentName} is: {(avgSalary / employees).ToString("C2", CultureInfo.CurrentCulture)}"); lbStatistics.Items.Add($"The favourite shift of employees is: {(ShiftType)index}"); } else { double avgSalary = 0; int[] shifts = new int[3]; int favouriteShift = 0; DatabaseFunctions.GetAllUsers(); int employees = Users.requestedUsers.Count; foreach (User user in Users.requestedUsers) { avgSalary += user.Salary; if (user.ShiftTypeU == ShiftType.Day) { shifts[0]++; } else if (user.ShiftTypeU == ShiftType.Night) { shifts[1]++; } else if (user.ShiftTypeU == ShiftType.HalfDay) { shifts[2]++; } } favouriteShift = shifts.Max(); int index = Array.IndexOf(shifts, favouriteShift); lbStatistics.Items.Add($"The average salary for all the employees is: {(avgSalary / employees).ToString("C2", CultureInfo.CurrentCulture)}"); lbStatistics.Items.Add($"The most requested shift of all the employees is: {(ShiftType)index}"); } }