/// <summary> /// 初始化 /// </summary> /// <param name="professor"></param> /// <param name="course"></param> /// <param name="groups"></param> /// <param name="requiresLab"></param> /// <param name="duration"></param> public CourseClass(Professor professor, Course course, List<StudentsGroup> groups, bool requiresLab, int duration) { // 教这门课的老师是谁 this.professor = professor; this.course = course; // 座位数初始化为0 this.numberOfSeats = 0; this.requiresLab = requiresLab; this.duration = duration; this.isPE = false; // 知道这门课是谁在教了,也要让教的人知道他要教哪些课,_professor->AddCourseClass( this )函数的作用就是 // 在初始化了一门课之后,让某个老师知道他要教这门课 this.professor.AddCourseClass(this); // bind student groups to class // 初始化了一门课之后,也要指定说谁应该上这门课, 下面这段代码就是通过StudentsGroup类的AddClass函数指定了groups里的班都要上这门课 foreach (StudentsGroup it in groups) { it.AddClass(this); this.groups.Add(it); this.numberOfSeats += it.GetNumberOfStudents(); // 从这里可以知道groups参数是指同时上这门课的班级 } }
public static List<CourseClass> GetCourseClasses() { Professor p1 = new Professor(1, "Victor"); Professor p2 = new Professor(2, "Red"); Professor p3 = new Professor(3, "Philip"); Professor p4 = new Professor(4, "Marry"); Professor p5 = new Professor(5, "Don"); Professor p6 = new Professor(6, "Mark"); Professor p7 = new Professor(7, "Peter"); Professor p8 = new Professor(8, "John"); Professor p9 = new Professor(9, "Ben"); Professor p10 = new Professor(10, "Mike"); Professor p11 = new Professor(11, "Steve"); Professor p12 = new Professor(12, "Ann"); Professor p13 = new Professor(13, "Alex"); Course c1 = new Course(1, "Introduction to Programming"); Course c2 = new Course(2, "Introduction to Computer Architecture"); Course c3 = new Course(3, "Business Applications"); Course c4 = new Course(4, "English"); Course c5 = new Course(5, "Discrete Mathematic I"); Course c6 = new Course(6, "Linear Algebra"); Course c7 = new Course(7, "Introduction to Information Technology I"); Course c8 = new Course(8, "System Administration and Maintenance I"); // StudentsGroup StudentsGroup g1 = new StudentsGroup(1, "101", 19); StudentsGroup g2 = new StudentsGroup(2, "102", 19); StudentsGroup g3 = new StudentsGroup(3, "103", 19); StudentsGroup g4 = new StudentsGroup(4, "104", 19); List<StudentsGroup> ls1 = new List<StudentsGroup>(); // CourseClass CourseClass cc1 = new CourseClass(p1, c1, new List<StudentsGroup>() { g1}, false, 1); CourseClass cc2 = new CourseClass(p1, c1, new List<StudentsGroup>() { g1 }, false, 1); CourseClass cc3 = new CourseClass(p9, c1, new List<StudentsGroup>() { g1 }, true, 1); CourseClass cc4 = new CourseClass(p9, c1, new List<StudentsGroup>() { g1 }, true, 1); CourseClass cc5 = new CourseClass(p9, c1, new List<StudentsGroup>() { g1 }, true, 1); CourseClass cc6 = new CourseClass(p9, c1, new List<StudentsGroup>() { g1 }, true, 1); CourseClass cc7 = new CourseClass(p2, c2, new List<StudentsGroup>() { g1 }, false, 1); CourseClass cc8 = new CourseClass(p2, c2, new List<StudentsGroup>() { g1 }, false, 1); CourseClass cc9 = new CourseClass(p3, c2, new List<StudentsGroup>() { g1 }, false, 1); CourseClass cc10 = new CourseClass(p3, c2, new List<StudentsGroup>() { g1 }, true, 1); CourseClass cc11 = new CourseClass(p3, c2, new List<StudentsGroup>() { g1 }, true, 1); CourseClass cc12 = new CourseClass(p3, c2, new List<StudentsGroup>() { g1 }, true, 1); CourseClass cc13 = new CourseClass(p4, c4, new List<StudentsGroup>() { g1 }, false, 1); //CourseClass cc13 = new CourseClass(p4, c4, new List<StudentsGroup>() { g3, g4 }, false, 2); CourseClass cc14 = new CourseClass(p4, c4, new List<StudentsGroup>() { g1 }, false, 1); //CourseClass cc14 = new CourseClass(p4, c4, new List<StudentsGroup>() { g1, g2 }, false, 2); CourseClass cc15 = new CourseClass(p5, c6, new List<StudentsGroup>() { g1}, false, 1); //CourseClass cc15 = new CourseClass(p5, c6, new List<StudentsGroup>() { g1, g2, g3 }, false, 2); CourseClass cc16 = new CourseClass(p7, c5, new List<StudentsGroup>() { g1}, false, 1); CourseClass cc17 = new CourseClass(p7, c5, new List<StudentsGroup>() { g1 }, false, 1); CourseClass cc18 = new CourseClass(p10, c5, new List<StudentsGroup>() { g1}, false, 1); CourseClass cc19 = new CourseClass(p8, c3, new List<StudentsGroup>() { g1 }, false, 1); CourseClass cc20 = new CourseClass(p8, c3, new List<StudentsGroup>() { g3 }, false, 1); CourseClass cc21 = new CourseClass(p12, c3, new List<StudentsGroup>() { g1 }, false, 1); CourseClass cc22 = new CourseClass(p12, c3, new List<StudentsGroup>() { g4 }, false, 1); CourseClass cc23 = new CourseClass(p11, c7, new List<StudentsGroup>() { g4 }, false, 1); CourseClass cc24 = new CourseClass(p13, c8, new List<StudentsGroup>() { g4 }, false, 1); CourseClass cc25 = new CourseClass(p4, c4, new List<StudentsGroup>() { g3, g4 }, false, 1); CourseClass cc26 = new CourseClass(p4, c4, new List<StudentsGroup>() { g1, g2 }, false, 1); CourseClass cc27 = new CourseClass(p5, c6, new List<StudentsGroup>() { g1, g2, g3 }, false, 1); List<CourseClass> courseClasses = new List<CourseClass>(); courseClasses.Add(cc1); courseClasses.Add(cc2); courseClasses.Add(cc3); courseClasses.Add(cc4); courseClasses.Add(cc5); courseClasses.Add(cc6); courseClasses.Add(cc7); courseClasses.Add(cc8); courseClasses.Add(cc9); courseClasses.Add(cc10); courseClasses.Add(cc11); courseClasses.Add(cc12); courseClasses.Add(cc13); courseClasses.Add(cc14); courseClasses.Add(cc15); //courseClasses.Add(cc16); //courseClasses.Add(cc17); //courseClasses.Add(cc18); //courseClasses.Add(cc19); //courseClasses.Add(cc20); //courseClasses.Add(cc21); //courseClasses.Add(cc22); //courseClasses.Add(cc23); //courseClasses.Add(cc24); //courseClasses.Add(cc25); //courseClasses.Add(cc26); //courseClasses.Add(cc27); return courseClasses; }
protected void btnMakeSchedule_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(tbYear.Text)) { Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript'>alert('学年不能为空!')</script>"); return; } int term = default(int); if (string.IsNullOrEmpty(ddlTerm.SelectedValue) || !int.TryParse(ddlTerm.SelectedValue, out term) || term < 1 || term > 2) { Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript'>alert('学期不能为空!')</script>"); return; } bool IsSucess = false; try { List<CY.GFive.Core.Business.CoursePlan> Plans = CY.GFive.Core.Business.CoursePlan.FillPlans(tbYear.Text, ddlTerm.SelectedValue) as List<CY.GFive.Core.Business.CoursePlan>; if (Plans != null) { // 教师信息转化 List<CY.GFive.Core.Business.StaffInfo> professorList = CY.GFive.Core.Business.CoursePlan.FillTeachers(Plans) as List<CY.GFive.Core.Business.StaffInfo>; List<GAAlgorithm.Model.Professor> GAProfessorList = new List<Professor>(); for (int i = 0; i < professorList.Count; i++) { GAAlgorithm.Model.Professor tempProfessor = new GAAlgorithm.Model.Professor(professorList[i].Id, professorList[i].Name); GAProfessorList.Add(tempProfessor); } // 排课前初始化教师信息 SimpleCourseSchedule.Service.ScheduleService.InitialProfessors(GAProfessorList); // 初始化教室信息 List<Room> roomList = new List<Room>(); List<CY.GFive.Core.Business.ClassRoom> classRoomList = new List<CY.GFive.Core.Business.ClassRoom>(); classRoomList = CY.GFive.Core.Business.ClassRoom.GetAvailableRooms() as List<CY.GFive.Core.Business.ClassRoom>; for (int r = 0; r < classRoomList.Count; r++) { GAAlgorithm.Model.Room room = new Room(classRoomList[r].Code, false, classRoomList[r].AvailNum); room.SetId(classRoomList[r].Id); room.SetRoomCode(classRoomList[r].Code); roomList.Add(room); } // 课程信息转化 Dictionary<CY.GFive.Core.Business.ClassInfo, List<CY.GFive.Core.Business.PlanCourse>> courseDic = CY.GFive.Core.Business.CoursePlan.FillClassCourse(Plans) as Dictionary<CY.GFive.Core.Business.ClassInfo, List<CY.GFive.Core.Business.PlanCourse>>; Hashtable courseHash = new Hashtable(); foreach (KeyValuePair<CY.GFive.Core.Business.ClassInfo, List<CY.GFive.Core.Business.PlanCourse>> it in courseDic) { GAAlgorithm.Model.StudentsGroup tempGroup = new StudentsGroup(((CY.GFive.Core.Business.ClassInfo)it.Key).Id, ((CY.GFive.Core.Business.ClassInfo)it.Key).ClassName.ToString(), ((CY.GFive.Core.Business.ClassInfo)it.Key).OrStdNum); tempGroup.SetRoomId(-1); List<CourseClass> tempCourseClassList = new List<CourseClass>(); for (int j = 0; j < ((List<CY.GFive.Core.Business.PlanCourse>)it.Value).Count; j++) { CY.GFive.Core.Business.PlanCourse tempPlanCourse = ((List<CY.GFive.Core.Business.PlanCourse>)it.Value)[j]; GAAlgorithm.Model.Professor tempProfessor = new Professor(tempPlanCourse.Teacher.Id, tempPlanCourse.Teacher.Name); GAAlgorithm.Model.Course tempCourse = new Course(tempPlanCourse.Course.Id, tempPlanCourse.Course.Name); GAAlgorithm.Model.CourseClass tempCourseClass = new CourseClass(tempProfessor, tempCourse, new List<StudentsGroup> { tempGroup }, false, 1); tempCourseClassList.Add(tempCourseClass); // 根据学分增加课时 if ((tempPlanCourse.CourseScore % 2) > 0) { tempPlanCourse.CourseScore++; } for (int i = 1; i < tempPlanCourse.CourseScore/2; i++) { GAAlgorithm.Model.CourseClass copyCourse = new CourseClass(tempProfessor, tempCourse, new List<StudentsGroup> { tempGroup }, false, 1); tempCourseClassList.Add(copyCourse); } } courseHash.Add(tempGroup, tempCourseClassList); } // 分班, 分班要在"课程信息转化"步骤之后 List<StudentsGroup> groupList = new List<StudentsGroup>(); // 等待分班的学生们 int limitedNbr = 2; foreach (DictionaryEntry it in courseHash) { groupList.Add(it.Key as StudentsGroup); } groupList = ScheduleService.AssignClassRoom(groupList, roomList, limitedNbr); for (int h = 0; h < groupList.Count; h++) { IDictionaryEnumerator it = courseHash.GetEnumerator(); for (int d = 0; d < courseHash.Count; d++) { it.MoveNext(); if ((it.Key as StudentsGroup).GetId() == groupList[h].GetId()) { (it.Key as StudentsGroup).SetRoomId(groupList[h].GetRoomId()); (it.Key as StudentsGroup).SetRoomCode(groupList[h].GetRoomCode()); } } } //排课前信息检验 int iDay = int.Parse(ddDays.SelectedValue); int iNbr = int.Parse(ddNbr.SelectedValue); string msg = ""; if (!ScheduleService.ValidateProfessorInfo(out msg)) { Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript'>alert('" + msg + "');</script>"); return; } else { if (!ScheduleService.ValidateCourseInfo(courseHash, iNbr, iDay, out msg)) { Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript'>alert('" + msg + "');</script>"); return; } } // 排课并返回逻辑课表 Hashtable scheduledTable = ScheduleService.MakeSchedule(courseHash, iDay, iNbr); // 清除排课的教师信息 ScheduleService.DelProfessors(); // 生成将课表数据保存到数据库中 if (ScheduleService.StoreSchedule(scheduledTable, tbYear.Text, term.ToString())) { IsSucess = true; } /* string ExcelPathForStudent = GetExcelPathForStudent(); string ExcelPathForTeacher = GetExcelPathForTeacher(); string ActualExcelPathForStudent = string.Empty; string ActualExcelPathForTeacher = string.Empty; ScheduleService.ExportSchedule(scheduledTable, ref ExcelPathForStudent, ref ExcelPathForTeacher, out ActualExcelPathForStudent, out ActualExcelPathForTeacher); // 将课表导入Excel 并存储课表的保存地址 //if (!File.Exists(ExcelPathForStudent) && !File.Exists(ExcelPathForTeacher)) //{ // // 在没有生成课表的情况下才存课表,如果已存有课表的话,是不需要生成课表的,也是不允许生成新的课表的。 // ScheduleService.ExportSchedule(scheduledTable, ref ExcelPathForStudent, ref ExcelPathForTeacher, out ActualExcelPathForStudent, out ActualExcelPathForTeacher); // if (StordScheduleRcd(ExcelNameForStudent, ExcelRelativeFilePath, tbYear.Text.Trim(), ddlTerm.SelectedValue.Trim()) && StordScheduleRcd(ExcelNameForTeacher, ExcelRelativeFilePath, tbYear.Text.Trim(), ddlTerm.SelectedValue.Trim())) // { // //IsSucess = true; // } //} * */ } } catch (Exception ex) { Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript'>alert('" + ex.Message.ToString() + "');</script>"); } if (IsSucess) { Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript'>alert('生成课表成功');</script>"); return; } else { Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript'>alert('该学期的课表已存在!');</script>"); return; } }
public static Professor GetProfessor(int id) { Professor p2 = new Professor(); if (ScheduleService.professors != null) { foreach (Professor p in ScheduleService.professors) { if (p.GetId() == id) p2 = p; } return p2; } else { return null; } }