예제 #1
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());
        }
        /**
         * JOSE WHY IS THIS NOT WORKING???
         * Method to add staff member
         */
        private void btnAddStaff_Click(object sender, EventArgs e)
        {
            try
            {
                ReadInfoFromForm();
                int tempID = -1;


                Staff newStaffMember = null;

                if (role == Position.Employee)
                {
                    newStaffMember = new Employee(tempID, FirstName, LastName, birthDate, address, salary, hoursAvailable, email, contract);
                }
                else if (role == Position.HRManager)
                {
                    newStaffMember = new Manager(tempID, FirstName, LastName, birthDate, address, salary, hoursAvailable, email, contract);
                }
                else if (role == Position.StockManager)
                {
                    newStaffMember = new Manager(tempID, FirstName, LastName, birthDate, address, salary, hoursAvailable, email, contract, passcode);
                }

                dataBase.addStaffToDB(newStaffMember, DepartmentID);

                MessageBox.Show("Staff member added successfully");

                //newStaffMember.dbID = dataBase.getStaffID();

                if (this.department.DepartmentID == DepartmentID)
                {
                    department.AddStaffMember(newStaffMember);
                }

                this.Close();
            }
            catch (Exception)
            {
                MessageBox.Show("Information not filled correctly");
            }
        }