public List <Request> GetAll() { allRequests = new List <Request>(); String query = "SELECT requests.id, requests.senderId, requests.receiverId, requests.shiftId, requests.status, shifts.date, shifts.shiftType, shifts.id FROM requests, shifts WHERE requests.shiftId = shifts.id AND requests.status = 2 ORDER BY shifts.date;"; MySqlCommand command = new MySqlCommand(query, connection); try { connection.Open(); MySqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { Employee sender = employeeStorage.Get(Convert.ToInt32(reader[1])); Employee receiver = employeeStorage.Get(Convert.ToInt32(reader[2])); allRequests.Add(new Request(Convert.ToInt32(reader[0]), sender.FirstName, sender.SurName, receiver.FirstName, receiver.SurName, Convert.ToDateTime(reader[5]), Convert.ToInt32(reader[6]), Convert.ToInt32(reader[7]), Convert.ToInt32(reader[2]), Convert.ToInt32(reader[1]))); } } catch (Exception ex) { ErrorMessages.Generic(ex); } finally { connection.Close(); } return(allRequests); }
/// <summary> /// Removes the selected employee from the shift and re-adds it to the list of employees you can add to the shift. /// </summary> private void RemoveEmployeeFromShift() { int index = dataGridViewScheduling.CurrentRow.Index; // Checks if there's actually an employee selected to be removed if (dataGridViewScheduling.SelectedRows.Count == 1) { List <Department> allDepartments = GetDepartmentListFromComboBox(); // Ensures the right employee object is used //Employee selectedEmployee = (listBoxCurrentEmployees.SelectedItem as dynamic).Employee; DataGridViewRow row = dataGridViewScheduling.SelectedRows[0]; int employeeID = Convert.ToInt32(row.Cells["ID"].Value); Employee selectedEmployee = employeeStorage.Get(employeeID); // Removes 4 hours from the selected employees hours selectedEmployee.WorkingHours -= Globals.shiftDuration; if (comboBoxSelectDepartments.SelectedIndex != -1) { // Selects the correct index from the combobox Department dep = (comboBoxSelectDepartments.SelectedItem as dynamic).Department; int selectedIndex = dep.Id - 1; RemoveSelectedEmployee(selectedEmployee, selectedIndex); } else { MessageBox.Show("Please select a department first1"); } } }
private void Login() { loginStorage = new LoginMySQL(); employeeStorage = new EmployeeMySQL(); functionStorage = new FunctionMySQL(); //Asks the loginStorage to check if the entered details match those we have stored. userId = loginStorage.Check(textBoxLoginUsername.Text, textBoxLoginPassword.Text); if (userId > 0) { this.loggedInUser = employeeStorage.Get(userId); this.loggedInUser.Permissions = functionStorage.GetPermissions(loggedInUser.Function); this.DialogResult = DialogResult.OK; } else if (userId < 0) { MessageBox.Show("Invalid Credentials"); } else { MessageBox.Show("Your account has been disabled"); } }
public Employee Get(string employeeId) { return(_storage.Get(employeeId)); }
private void chbxForceShift_CheckedChanged(object sender, EventArgs e) { if (chbxForceShift.Checked) { cmbxDepartment.Items.Clear(); lblDepartment.Visible = true; cmbxDepartment.Visible = true; Employee employee = employeeStorage.Get(this.userid); List <int> selectedDepartments = new List <int>(); if (employee.WorkingDepartments != String.Empty) { selectedDepartments = employee.WorkingDepartments.Split(',').Select(int.Parse).ToList(); } List <Department> departments = new List <Department>(); departments = departmentStorage.GetAll(); foreach (Department d in departments) { if (selectedDepartments.Contains(d.Id)) { ComboboxItem ci = new ComboboxItem(); ci.Text = d.Id.ToString() + " - " + d.Name; ci.Value = d.Id; cmbxDepartment.Items.Add(ci); } } string date = dtpDate.Value.Date.ToString("yyyy-MM-dd"); List <Shift> shifts = shiftStorage.GetShiftsByEmployee(this.userid, date); List <int> shifttypes = new List <int>(); foreach (Shift s in shifts) { switch (s.ShiftTime) { case ShiftTime.Morning: shifttypes.Add(0); break; case ShiftTime.Afternoon: shifttypes.Add(1); break; case ShiftTime.Evening: shifttypes.Add(2); break; } } cmbShift.SelectedIndex = -1; cmbShift.Items.Clear(); for (int i = 0; i <= 2; i++) { if (!shifttypes.Contains(i)) { ComboboxItem ci = new ComboboxItem(); switch (i) { case 0: ci.Text = "Morning"; break; case 1: ci.Text = "Afternoon"; break; case 2: ci.Text = "Evening"; break; } ci.Value = i; cmbShift.Items.Add(ci); } } } else { refresh_shift(); lblDepartment.Visible = false; cmbxDepartment.Visible = false; } }
public Employee Get(long id) { return(employeeStorage.Get(id)); }