public void dayAssigner(int i, ref day tempDay) { if (i == 0)//monday { tempDay.name = "Monday"; tempDay.splashShifts = 2; tempDay.maintenceShiftsDay = 2; tempDay.maintenceShiftsNight = 2; tempDay.managerShift = 1; } else if (i == 1) { tempDay.name = "Tuesday"; tempDay.splashShifts = 2; tempDay.maintenceShiftsDay = 2; tempDay.maintenceShiftsNight = 2; tempDay.managerShift = 1; } else if (i == 2) { tempDay.name = "Wednesday"; tempDay.splashShifts = 2; tempDay.maintenceShiftsDay = 2; tempDay.maintenceShiftsNight = 2; tempDay.managerShift = 1; } else if (i == 3) { tempDay.name = "Thursday"; tempDay.splashShifts = 2; tempDay.maintenceShiftsDay = 2; tempDay.maintenceShiftsNight = 2; tempDay.managerShift = 1; } else if (i == 4) { tempDay.name = "Friday"; tempDay.splashShifts = 2; tempDay.maintenceShiftsDay = 2; tempDay.maintenceShiftsNight = 2; tempDay.managerShift = 1; } else if (i == 5) { tempDay.name = "Saturday"; tempDay.splashShifts = 2; tempDay.maintenceShiftsDay = 2; tempDay.maintenceShiftsNight = 2; tempDay.managerShift = 1; } else if (i == 6) { tempDay.name = "Sunday"; tempDay.splashShifts = 2; tempDay.maintenceShiftsDay = 2; tempDay.maintenceShiftsNight = 2; tempDay.managerShift = 1; } }
public void CreateSchedule()//creates and saves the current schedule. randomizes it each time { days.Clear(); importEmployees(); Random randomGen = new Random(); for (int i = 0; i < 7; i++)//iterates through each day { //sometimes runs into problem where cant put anyone else in a day at end of week because people have too many hours at beginning day currentDay = new day(); dayAssigner(i, ref currentDay); currentDay.e_index = new List <int>(); currentDay.shift_index = new List <int>(); List <Employee> currentEmployee = new List <Employee>(); for (int e = 0; e < employees.Count; e++) { if (employees[e].hours < 33) { currentEmployee.Add(employees[e]); } } for (int j = 0; j < currentDay.managerShift; j++) { int ran = randomGen.Next(currentEmployee.Count); Employee temp = currentEmployee[ran]; if (temp.manager || temp.superviser) { temp.firstName = currentEmployee[ran].firstName; temp.lastName = currentEmployee[ran].lastName; temp.superviser = currentEmployee[ran].superviser; temp.manager = currentEmployee[ran].manager; temp.hours = currentEmployee[ran].hours + 8; temp.index = currentEmployee[ran].index; currentDay.e_index.Add(temp.index); currentDay.shift_index.Add(4); currentEmployee.RemoveAt(ran); employees[temp.index] = temp; } else { j--; } } for (int j = 0; j < currentDay.maintenceShiftsDay; j++) { int ran = randomGen.Next(currentEmployee.Count); Employee temp = currentEmployee[ran]; temp.firstName = currentEmployee[ran].firstName; temp.lastName = currentEmployee[ran].lastName; temp.superviser = currentEmployee[ran].superviser; temp.manager = currentEmployee[ran].manager; temp.hours = currentEmployee[ran].hours + 8; temp.index = currentEmployee[ran].index; currentDay.e_index.Add(temp.index); currentDay.shift_index.Add(2); currentEmployee.RemoveAt(ran); employees[temp.index] = temp; } for (int j = 0; j < currentDay.maintenceShiftsNight; j++) { int ran = randomGen.Next(currentEmployee.Count); Employee temp = currentEmployee[ran]; temp.firstName = currentEmployee[ran].firstName; temp.lastName = currentEmployee[ran].lastName; temp.superviser = currentEmployee[ran].superviser; temp.manager = currentEmployee[ran].manager; temp.hours = currentEmployee[ran].hours + 8; temp.index = currentEmployee[ran].index; currentDay.e_index.Add(temp.index); currentDay.shift_index.Add(3); currentEmployee.RemoveAt(ran); employees[temp.index] = temp; } for (int j = 0; j < currentDay.splashShifts; j++) { int ran = randomGen.Next(currentEmployee.Count); Employee temp = new Employee(); temp.firstName = currentEmployee[ran].firstName; temp.lastName = currentEmployee[ran].lastName; temp.superviser = currentEmployee[ran].superviser; temp.manager = currentEmployee[ran].manager; temp.hours = currentEmployee[ran].hours + 8; temp.index = currentEmployee[ran].index; currentDay.e_index.Add(temp.index); currentDay.shift_index.Add(1); currentEmployee.RemoveAt(ran); employees[temp.index] = temp; } days.Add(currentDay); } writeToFile(); }