private Staff SearchSelectedStaff()
        {
            String auxName   = null;
            Staff  searching = null;

            if (lbEmployees.SelectedItem != null)
            {
                auxName = lbEmployees.SelectedItem.ToString();
            }
            else if (lbManagers.SelectedItem != null)
            {
                auxName = lbManagers.SelectedItem.ToString();
            }

            if (!String.IsNullOrEmpty(auxName))
            {
                String[] name      = auxName.Split(' '); //Splits the string by the comma.
                String   firstName = name[0].Trim();
                String   lastName  = name[1].Trim();
                searching = department.GetStaffMember(firstName, lastName);

                if (searching == null)
                {
                    MessageBox.Show("Employee not found.");
                }
            }

            return(searching);
        }
예제 #2
0
        /**
         * Method to get staff
         */
        public List <Staff> getStaffFromDB(Department dep)
        {
            MySqlConnection conn = new MySqlConnection(connString);

            conn.Open();
            String sql = "SELECT * FROM person JOIN role ON person.RoleID = role.Id WHERE DepartmentID = @DepartmentID";

            MySqlCommand cmd = new MySqlCommand(sql, conn);

            cmd.Parameters.AddWithValue("@DepartmentID", dep.DepartmentID);
            MySqlDataReader reader = cmd.ExecuteReader();

            //List<Staff> result = new List<Staff>();
            while (reader.Read())
            {
                int      ID             = (int)reader.GetValue(0);
                String   firstName      = reader.GetString(1);
                String   lastName       = reader.GetString(2);
                DateTime birthDate      = (DateTime)reader.GetValue(3);
                String   address        = reader.GetString(4);
                String   email          = reader.GetString(5);
                double   salary         = reader.GetDouble(7);
                int      hoursavailable = (int)reader.GetValue(9);
                int      dbContract     = (int)reader.GetValue(14); //13
                String   role           = reader.GetString(16);     //16

                Contract contract;
                if (dbContract == 1)
                {
                    contract = Contract.FullTime;
                }
                else
                {
                    contract = Contract.PartTime;
                }

                if (role == "Manager" || role == "Stock Manager")
                {
                    Manager man = new Manager(ID, firstName, lastName, birthDate, address, salary, hoursavailable, email, contract);
                    if (dep.GetStaffMember(man.FirstName, man.LastName) == null)
                    {
                        dep.AddStaffMember(man);
                    }
                }
                else if (role == "Employee")
                {
                    Employee emp = new Employee(ID, firstName, lastName, birthDate, address, salary, hoursavailable, email, contract);
                    if (dep.GetStaffMember(emp.FirstName, emp.LastName) == null)
                    {
                        dep.AddStaffMember(emp);
                    }
                }
            }
            reader.Close();
            conn.Close();

            return(dep.GetStaff());
        }
예제 #3
0
 /**
  * Method to assign employee to a schedule and save to DB
  */
 private void btnDone_Click(object sender, EventArgs e)
 {
     try
     {
         updateTimer.Enabled = true;
         lBoxAssignEmployee.Items.Clear();
         Staff    staff           = department.GetStaffMember(txtBoxEmployeeName.Text);
         String   startTime       = comBoxStartTime.SelectedItem.ToString();
         String   endTime         = comBoxEndTime.SelectedItem.ToString();
         String   workDate        = dtpWorkDates.Value.ToString();
         DateTime updateStartTime = DateTime.Parse(startTime);
         DateTime updateEndTime   = DateTime.Parse(endTime);
         DateTime updateWorkDate  = DateTime.Parse(workDate);
         String   body            = "Your shift has been updated. This is your new shift start time: " + startTime + " end time: " + endTime + " work date: " + workDate;
         databaseHelper.UpdateEmployeeSchedule(schedule, startTime, endTime, workDate);
         emailHelper.SendScheduleEmail(body, staff.Email);
         schedule.UpdateSchedule(schedule.dbID, schedule.FirstName, schedule.LastName, schedule.Role, updateStartTime, updateEndTime, updateWorkDate, this.department.Name);
         this.Hide();
         MessageBox.Show("Schedule successfully added!");
     }
     catch (Exception)
     {
         MessageBox.Show("Sorry request failed.");
     }
 }