static void Main(string[] args) { StudentsGroup g1 = new StudentsGroup(1, "数控1班", 22); List<CourseClass> courses = GetCourseClasses(); StudentsGroup g2 = new StudentsGroup(2, "数控2班", 23); List<CourseClass> courses2 = GetCourseClasses(); Hashtable table = new Hashtable(); table.Add(g1, courses); table.Add(g2, courses2); Hashtable courseTable = new Hashtable(); DataSet classTableSet = new DataSet(); courseTable = ScheduleService.MakeSchedule(table); IDictionaryEnumerator it = courseTable.GetEnumerator(); for (int j = 0; j < courseTable.Count; j++) { it.MoveNext(); // 实际课程表 DataTable ClassTable = new DataTable(); ClassTable.Columns.Add("时段"); ClassTable.Columns.Add("周一"); ClassTable.Columns.Add("周二"); ClassTable.Columns.Add("周三"); ClassTable.Columns.Add("周四"); ClassTable.Columns.Add("周五"); for (int d = 0; d < 4; d++) { DataRow dr1 = ClassTable.NewRow(); dr1[0] = "第" + (d + 1) + "节"; dr1[1] = ""; dr1[2] = ""; dr1[3] = ""; dr1[4] = ""; ClassTable.Rows.Add(dr1); } Console.WriteLine(((StudentsGroup)it.Key).GetName() + " 的课表如下:"); ClassTable.TableName = ((StudentsGroup)it.Key).GetName(); for (int i = 0; i < ((Schedule)it.Value).GetSlots().Count; i++) { List<List<CourseClass>> slot = ((Schedule)it.Value).GetSlots(); int day = i / 4; int time = i % 4; DataRow dr = ClassTable.Rows[time]; if (slot[i].Count >= 1) { Console.WriteLine("周 " + (day + 1) + "第 " + (time + 1) + " 节课是 " + slot[i].First().GetCourse().GetName() + " 老师是 " + slot[i].First().GetProfessor().GetName()); dr[day + 1] = slot[i].First().GetCourse().GetName(); } else { dr[day + 1] = ""; } } classTableSet.Tables.Add(ClassTable); // Console.Read(); } //ScheduleService.ExportSchedule(courseTable); }
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; } }