var currentItem = null;
var currentCell = null;
var currentSchedulingWeekList = null;
var usedClassroomList = new Array();
var teacherScheduleContinuousCount = 0;
var classScheduleContinuousCount = 0;
var classCourseScheduleContinuousCount = 0;
var mnu = "";
var colorGroup = ["timeSpanCell1", "timeSpanCell2", "timeSpanCell3"];
var isZoomOuted = false;
var zoomRate = 5;
var schedulingClassSelectedWeekList = [];
$(function () {
mnu = $.SystemGeneral.getUrlParam("MNU");
$(".middleBar").mousedown(middleStartDrag);
$(document).mousemove(middleDragging);
});
function EducationScheduling_ZoomOut() {
if (!isZoomOuted) {
$(".schedulingHeaderCell").width($(".schedulingHeaderCell").width() * zoomRate);
$(".schedulingHeader").width($(".schedulingHeader").width() * zoomRate);
$(".schedulingRow").width($(".schedulingRow").width() * zoomRate);
$(".schedulingCell").width($(".schedulingCell").width() * zoomRate);
$(".schedulingCellHeader").height($(".schedulingCellHeader").height() * zoomRate);
$(".schedulingRow").height($(".schedulingRow").height() * zoomRate);
$(".schedulingCell").height($(".schedulingCell").height() * zoomRate);
$(".schedulingItem").each(function (i, x) {
$(x).width($(x).width() * zoomRate);
$(x).height($(x).height() * zoomRate);
});
isZoomOuted = true;
}
}
function EducationScheduling_ZoomIn() {
if (isZoomOuted) {
$(".schedulingHeaderCell").width($(".schedulingHeaderCell").width() / zoomRate);
$(".schedulingHeader").width($(".schedulingHeader").width() / zoomRate);
$(".schedulingRow").width($(".schedulingRow").width() / zoomRate);
$(".schedulingCell").width($(".schedulingCell").width() / zoomRate);
$(".schedulingCellHeader").height($(".schedulingCellHeader").height() / zoomRate);
$(".schedulingRow").height($(".schedulingRow").height() / zoomRate);
$(".schedulingCell").height($(".schedulingCell").height() / zoomRate);
$(".schedulingItem").each(function (i, x) {
$(x).width($(x).width() / zoomRate);
$(x).height($(x).height() / zoomRate);
});
isZoomOuted = false;
}
}
var mouseXStart;
var vmiddleBar;
var isDragging = false;
function middleStartDrag(event) {
mouseXStart = $(".middleBar").offset().left;
vmiddleBar = $(".middleBar").clone();
vmiddleBar.removeClass("middleBar");
vmiddleBar.css("border-style", "dashed");
vmiddleBar.mouseup(middleEndDrag);
vmiddleBar.appendTo(".popupWindowContent");
isDragging = true;
}
function middleDragging(event) {
if (isDragging) {
event = event || window.event;
event.cancelBubble = true;
var x = event.clientX || event.originalEvent.layerX;
var offset = $(".middleBar").offset();
if ((mouseXStart - x) <= offset.left
&& (x - mouseXStart) <= $("#scheduleContainer").width()) {
offset.left = offset.left - (mouseXStart - x);
vmiddleBar.offset(offset);
}
return false;
}
}
function middleEndDrag(event) {
if (vmiddleBar) {
event = event || window.event;
var x = event.clientX || event.originalEvent.layerX;
var middleBarOffset = $(".middleBar").offset();
var containerWidth = $("#scheduleContainer").width();
var containerOffset = $("#scheduleContainer").offset();
if ((mouseXStart - x) <= middleBarOffset.left && (x - mouseXStart) <= containerWidth) {
middleBarOffset.left = middleBarOffset.left - (mouseXStart - x);
} else if ((mouseXStart - x) > middleBarOffset.left) {
middleBarOffset.left = 1;
} else if ((x - mouseXStart) > containerWidth) {
middleBarOffset.left = containerWidth - 3;
}
$("#leftContainer").width(middleBarOffset.left);
$(".middleBar").offset(middleBarOffset);
$("#scheduleContainer").width(containerWidth + (mouseXStart - x) - 2);
if ($("#scheduleContainer").width() - 100 > 0) {
$(".schedulingHeaderContainer").width($("#scheduleContainer").width() - 100);
$(".schedulingCellContainer").width($(".schedulingHeaderContainer").width());
} else {
$(".schedulingHeaderContainer").width(1);
$(".schedulingCellContainer").width(1);
}
containerOffset.left = middleBarOffset.left + 2;
$("#scheduleContainer").offset(containerOffset);
vmiddleBar.css("display", "none");
$(".popupWindowContent").remove(vmiddleBar);
vmiddleBar = null;
isDragging = false;
}
}
function popupTeacherReport(userID) {
var schoolYearID = $("#SchoolYearDropdown").combobox("getValue");
var fullUrl = CMS_SystemConfig.ReportPagePath + "?ReportFolder=%2fEducationScheduling%2fTeacherSchedulingView&CollegeID_RAP=&UserID_RAP=" + userID + "&SchoolyearID_RAP=" + schoolYearID;
$.popupTopWindowOutsite('教师课表', fullUrl, 1024, 600);
}
function popupClassroomReport(ClassroomID) {
var schoolYearID = $("#SchoolYearDropdown").combobox("getValue");
var fullUrl = CMS_SystemConfig.ReportPagePath + "?ReportFolder=%2fEducationScheduling%2fClassroomSchedulingView&BuildingsInfoID_RAP=&ClassroomID_RAP=" + ClassroomID + "&SchoolyearID_RAP=" + schoolYearID;
$.popupTopWindowOutsite('教室课表', fullUrl, 1024, 600);
}
function showClassroomScheduleView(classroomID) {
var schoolYearID = $("#SchoolYearDropdown").combobox("getValue");
$.popupTopWindowOutsite('教室课表', CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/ClassroomScheduleView?SchoolyearID=' + schoolYearID + '&ClassroomID=' + classroomID, 800, 400);
}
function EducationScheduling_Submit() {
var collegeID = $("#CollegeDropdown").combobox("getValue");
$.popupTopWindow('提交课表', CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/Submit', 300, 200, reload, {
collegeID: collegeID
});
}
function gridLoaded() {
//加载中间内容
loadScheduleContainer();
}
function loadScheduleContainer() {
$.post(CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/GetContinuousLimitView', null, function (data) {
teacherScheduleContinuousCount = data.TeacherScheduleContinuousCount;
classScheduleContinuousCount = data.ClassScheduleContinuousCount;
classCourseScheduleContinuousCount = data.ClassCourseScheduleContinuousCount;
loadScheduleData();
});
}
function getCoursesTimeList(schedulingData) {
$.post(CMS_SystemConfig.VirtualDirectoryPath + '/CoursesTime/ListAll', null, function (courseTimeData) {
drawScheduleContainer(courseTimeData, schedulingData);
});
}
function checkWeekTimeOverflowAndSetWeekList(weekList) {
var workhours = parseInt(currentCell.attr("workhours"));
weekList = $.grep(weekList, function (x) { return x.Times >= workhours });
if (weekList.length == 0) {
$.messager.alert("系统提示", "该时段需要排" + workhours.toString() + "个学时,该任务班的剩余学时不足,不能排课。");
return false;
}
currentSchedulingWeekList = weekList;
var isDup = false;
//只有同一个排课班才需要判断周次冲突
$.each(currentCell.find('.schedulingItem'), function (i, x) {
if (currentItem.EducationSchedulingClassID == $(x).attr("EducationSchedulingClassID")) {
var weeklyNumList = eval($(x).attr("WeeklyNums"));
$.each(currentSchedulingWeekList, function (n, w) {
if (weeklyNumList.contains(w.Week)) {
$.messager.alert("系统提示", "上课周次冲突。");
isDup = true;
return false;
}
});
}
});
if (isDup) {
return false;
}
return true;
}
function getScheduledItemRemainWeekNums(scheduleItem, allScheduled) {
var weekList = $.map(scheduleItem.CourseProcessViewList, function (x) {
return {
Week: x.Week,
Times: x.Times,
CourseProcessTeacherViewList: x.CourseProcessTeacherViewList,
StaffNames: x.StaffNames,
ClassroomTypeID: x.ClassroomTypeID,
ClassroomTypeName: x.ClassroomTypeName,
ClassroomID: x.ClassroomID,
ClassroomName: x.ClassroomName
};
});
$.each(allScheduled, function (i, x) {
var weeklyNumList = eval($(x).attr("WeeklyNums"));
var workhours = parseInt($(x).parent().attr("workhours"));
var teacherTeachingViewList = eval(unescape($(x).attr("TeacherTeachingViewList")));
weekList = $.map(weekList, function (m) {
var newTimes = m.Times;
if (weeklyNumList.contains(m.Week)
&& $.map(m.CourseProcessTeacherViewList, function (w) { return w.UserID + '|' + w.TeachingMethod.toString(); }).join(',') == $.map(teacherTeachingViewList, function (w) { return w.UserID + '|' + w.TeachingMethod.toString(); }).join(',')) {
newTimes = newTimes - workhours;
}
return {
Week: m.Week,
Times: newTimes,
CourseProcessTeacherViewList: m.CourseProcessTeacherViewList,
StaffNames: m.StaffNames,
ClassroomTypeID: m.ClassroomTypeID,
ClassroomTypeName: m.ClassroomTypeName,
ClassroomID: m.ClassroomID,
ClassroomName: m.ClassroomName
};
});
});
weekList = $.grep(weekList, function (x) { return x.Times > 0; });
return weekList;
}
//输入一个列表上的排课班,和已排有这个排课班的格子匹配,获取这个排课班剩余可以排的周次
function getScheduleItemWeekNums(scheduleItem, allScheduled, splitWeeks) {
var weekList = $.map(scheduleItem.CourseProcessViewList, function (x) {
return {
Week: x.Week,
Times: x.Times,
CourseProcessTeacherViewList: x.CourseProcessTeacherViewList,
StaffNames: x.StaffNames,
ClassroomTypeID: x.ClassroomTypeID,
ClassroomTypeName: x.ClassroomTypeName,
ClassroomID: x.ClassroomID,
ClassroomName: x.ClassroomName
};
});
if (!splitWeeks && schedulingClassSelectedWeekList[scheduleItem.EducationSchedulingClassID] != null) {
weekList = $.grep(weekList, function (x) { return schedulingClassSelectedWeekList[scheduleItem.EducationSchedulingClassID].contains(x.Week); });
}
$.each(allScheduled, function (i, x) {
var weeklyNumList = eval($(x).attr("WeeklyNums"));
var workhours = parseInt($(x).parent().attr("workhours"));
var teacherTeachingViewList = eval(unescape($(x).attr("TeacherTeachingViewList")));
// var classroomTypeID = $(x).attr("ClassroomTypeID");
// var classroomID = $(x).attr("ClassroomID");
weekList = $.map(weekList, function (m) {
var newTimes = m.Times;
if (weeklyNumList.contains(m.Week)
&& $.map(m.CourseProcessTeacherViewList, function (w) { return w.UserID + '|' + w.TeachingMethod.toString(); }).join(',') == $.map(teacherTeachingViewList, function (w) { return w.UserID + '|' + w.TeachingMethod.toString(); }).join(',')
// && m.ClassroomTypeID == classroomTypeID
// && m.ClassroomID == classroomID
) {
newTimes = newTimes - workhours;
}
return {
Week: m.Week,
Times: newTimes,
CourseProcessTeacherViewList: m.CourseProcessTeacherViewList,
StaffNames: m.StaffNames,
ClassroomTypeID: m.ClassroomTypeID,
ClassroomTypeName: m.ClassroomTypeName,
ClassroomID: m.ClassroomID,
ClassroomName: m.ClassroomName
};
});
});
weekList = $.grep(weekList, function (x) { return x.Times > 0; })
.sort(function (a, b) { return a.Times - b.Times; });
var weekListMap = {};
var weekListGroup = [];
for (var i = 0; i < weekList.length; i++) {
var existModifyGroup = $.grep(weekListGroup, function (x) {
return x.CourseProcessTeacherViewList.length == weekList[i].CourseProcessTeacherViewList.length
&& $.map(x.CourseProcessTeacherViewList, function (w) { return w.UserID + '|' + w.TeachingMethod.toString(); }).join(',') == $.map(weekList[i].CourseProcessTeacherViewList, function (w) { return w.UserID + '|' + w.TeachingMethod.toString(); }).join(',')
&& x.ClassroomTypeID == weekList[i].ClassroomTypeID
&& x.ClassroomID == weekList[i].ClassroomID
&& x.Times <= weekList[i].Times
});
if (existModifyGroup.length > 0) {
$.each(weekListGroup, function (n, x) {
if ($.map(x.CourseProcessTeacherViewList, function (w) { return w.UserID + '|' + w.TeachingMethod.toString(); }).join(',') == $.map(weekList[i].CourseProcessTeacherViewList, function (w) { return w.UserID + '|' + w.TeachingMethod.toString(); }).join(',')
&& x.ClassroomTypeID == weekList[i].ClassroomTypeID
&& x.ClassroomID == weekList[i].ClassroomID
&& x.Times <= weekList[i].Times) {
x.WeekNums.push(weekList[i].Week);
}
});
}
var existGroup = $.grep(weekListGroup, function (x) {
return x.CourseProcessTeacherViewList.length == weekList[i].CourseProcessTeacherViewList.length
&& $.map(x.CourseProcessTeacherViewList, function (w) { return w.UserID + '|' + w.TeachingMethod.toString(); }).join(',') == $.map(weekList[i].CourseProcessTeacherViewList, function (w) { return w.UserID + '|' + w.TeachingMethod.toString(); }).join(',')
&& x.ClassroomTypeID == weekList[i].ClassroomTypeID
&& x.ClassroomID == weekList[i].ClassroomID
&& x.Times == weekList[i].Times
});
if (existGroup.length == 0) {
weekListGroup.push({
CourseProcessTeacherViewList: weekList[i].CourseProcessTeacherViewList,
ClassroomTypeID: weekList[i].ClassroomTypeID,
ClassroomTypeName: weekList[i].ClassroomTypeName,
ClassroomID: weekList[i].ClassroomID,
ClassroomName: weekList[i].ClassroomName,
Times: weekList[i].Times,
TeacherNameColumn: $.map(weekList[i].CourseProcessTeacherViewList, function (x) { return x.Name + '(' + x.TeachingMethodName + ')'; }).join(','),
WeekNums: [weekList[i].Week]
});
}
}
$.each(weekListGroup, function (i, x) { x.WeekNumString = getWeekNumString(x.WeekNums); });
if (weekListGroup.length == 0) {
$.messager.alert("系统提示", "任务班的周学时已经排满。");
return;
}
if (weekListGroup) {
if (splitWeeks) {
if (weekListGroup.length > 1) {
$.popupTopWindow('选择排课组', CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/SelectGroup', 650, 320, preSelectWeek, {
weekList: weekList,
weekListGroup: weekListGroup
});
} else {
preSelectWeek({
weekList: weekList,
weekListGroup: weekListGroup[0]
});
}
} else {
if (weekListGroup.length > 1) {
$.popupTopWindow('选择排课组', CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/SelectGroup', 650, 320, selectGroupConfirm, {
weekList: weekList,
weekListGroup: weekListGroup
});
} else {
selectGroupConfirm({
weekList: weekList,
weekListGroup: weekListGroup[0]
});
}
}
}
}
function selectGroupConfirm(weekListGroupData) {
if (!weekListGroupData) return;
var weekday = currentCell.attr("weekday");
var courseTimeID = currentCell.attr("coursesTimeID");
weekList = $.grep(weekListGroupData.weekList, function (x) {
return x.CourseProcessTeacherViewList.length == weekListGroupData.weekListGroup.CourseProcessTeacherViewList.length
&& $.map(x.CourseProcessTeacherViewList, function (w) { return w.UserID + '|' + w.TeachingMethod.toString(); }).join(',') == $.map(weekListGroupData.weekListGroup.CourseProcessTeacherViewList, function (w) { return w.UserID + '|' + w.TeachingMethod.toString(); }).join(',')
&& x.ClassroomTypeID == weekListGroupData.weekListGroup.ClassroomTypeID
&& x.ClassroomID == weekListGroupData.weekListGroup.ClassroomID
&& x.Times >= weekListGroupData.weekListGroup.Times
});
if (!checkWeekTimeOverflowAndSetWeekList(weekList)) {
resetSelection();
return;
}
checkTeacherIsOnWork(weekday, courseTimeID);
}
function isTeacherOverflow(teacherWorkTimeList, weekday) {
var teacherDayClasses = new Array();
var isOverflow = false;
$.each(teacherWorkTimeList, function (i, x) {
var teacherDayClass = $.grep(teacherDayClasses, function (y) { return y.UserID == x.UserID && y.WeekNum == x.WeekNum; });
if (teacherDayClass.length == 0) {
teacherDayClasses.push({
UserID: x.UserID,
Name: x.Name,
WeekNum: x.WeekNum,
WorkTime: x.WorkTime
});
} else {
$.each(teacherDayClasses, function (o, y) {
if (y.UserID == x.UserID && y.WeekNum == x.WeekNum) {
y.WorkTime += x.WorkTime;
}
});
}
});
//再循环一次,加入待排课程的上课时间
var cellworkhours = parseInt(currentCell.attr("workhours"));
$.each(currentSchedulingWeekList, function (i, x) {
$.each(x.CourseProcessTeacherViewList, function (n, w) {
var teacherDayClass = $.grep(teacherDayClasses, function (y) { return y.UserID == w.UserID && y.WeekNum == x.Week; });
if (teacherDayClass.length == 0) {
teacherDayClasses.push({
UserID: w.UserID,
Name: w.Name,
WeekNum: x.Week,
WorkTime: cellworkhours
});
} else {
$.each(teacherDayClasses, function (o, y) {
if (y.UserID == w.UserID && y.WeekNum == x.Week) {
y.WorkTime += cellworkhours;
}
if (y.WorkTime > teacherScheduleContinuousCount) {
isOverflow = true;
}
});
}
});
});
return isOverflow;
}
function schedulingCellClicked() {
if ($(event.srcElement).hasClass("scheduleItemTeacherLink")) {
return;
}
if (currentItem != null) {
currentCell = $(this);
var weekday = currentCell.attr("weekday");
var courseTimeID = currentCell.attr("coursesTimeID");
var allScheduled = $('.schedulingItem[EducationSchedulingClassID=' + currentItem.EducationSchedulingClassID + ']');
//先看当前时间点是否可以排课
$.post(CMS_SystemConfig.VirtualDirectoryPath + '/Arrangements/IsOnWork', {
weekday: weekday,
courseTimeID: courseTimeID
}, function (data) {
if (!data) {
$.messager.alert("系统提示", "该时间点不是工作时间,不能排课,请与校历管理员联系咨询。");
} else {
//选教室之前,需要判断是否可以排在这一格
$.post(CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/IsCourseOnWork', {
coursematerialID: currentItem.CoursematerialID,
weekday: weekday,
courseTimeID: courseTimeID
}, function (data) {
if (!data.IsSuccess) {
$.messager.confirm("系统提示", data.Message + "是否继续将课程排在该节次?", function (r) {
if (r) {
getScheduleItemWeekNums(currentItem, allScheduled, false);
} else {
resetSelection();
}
});
} else {
getScheduleItemWeekNums(currentItem, allScheduled, false);
}
});
}
})
} else {
if ($(this).children('.schedulingItem').length == 0) {
var selectedItems = $('.schedulingItemSelected');
selectedItems.removeClass('schedulingItemSelected');
}
}
}
function checkTeacherIsOnWork(weekday, courseTimeID) {
$.post(CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/IsTeacherOnWork', {
educationScheduleClassID: currentItem.EducationSchedulingClassID,
schedulingWeekListStr: JSON.stringify(currentSchedulingWeekList),
weekday: weekday,
courseTimeID: courseTimeID
}, function (data) {
isContinue = true;
if (!data.IsSuccess) {
$.messager.confirm("系统提示", data.Message + "是否继续将课程排在该节次?", function (r) {
if (r) {
checkIsBusy(weekday, courseTimeID);
} else {
resetSelection();
}
});
} else {
checkIsBusy(weekday, courseTimeID);
}
});
}
function checkIsBusy(weekday, courseTimeID) {
var schoolYearID = $("#SchoolYearDropdown").combobox("getValue");
$.post(CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/IsEducationSchedulingClassCanAddManualSchedule', {
educationScheduleClassID: currentItem.EducationSchedulingClassID,
schedulingWeekListStr: JSON.stringify(currentSchedulingWeekList),
schoolYearID: schoolYearID,
weekday: weekday,
courseTimeID: courseTimeID
}, function (data) {
if (data.IsSuccess) {
checkTeacherWorktimeLimit(schoolYearID, weekday);
}
else {
var reportLink = "";
if (data.Message.indexOf('教师') >= 0) {
reportLink += "点击下列链接查看相关教师的课表:
";
$.each(data.Data, function (i, x) {
reportLink += '';
reportLink += x.Value + "课表";
reportLink += " ";
});
}
$.messager.alert("系统提示", data.Message + reportLink);
resetSelection();
return;
}
});
}
function checkTeacherWorktimeLimit(schoolYearID, weekday) {
//再判断教师连续工作时间、班级连续工作时间是否超限
$.post(CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/GetTeacherContinuousWorkTime', {
educationScheduleClassID: currentItem.EducationSchedulingClassID,
schedulingWeekListStr: JSON.stringify(currentSchedulingWeekList),
schoolYearID: schoolYearID,
weekday: weekday
}, function (teacherWorkTimeList) {
if (isTeacherOverflow(teacherWorkTimeList, weekday)) {
var reportLink = "";
var teacherList = [];
$.each(teacherWorkTimeList, function (i, x) {
if (!teacherList.contains(x.UserID)) {
teacherList.push(x.UserID);
reportLink += '';
reportLink += x.Name + "课表";
reportLink += " ";
}
});
$.messager.confirm("系统提示", "教师连续工作时间超限,是否继续将课程排在该节次?点击下列链接查看相关教师的课表:
" + reportLink, function (r) {
if (r) {
checkCourseContinuousLimit(weekday);
} else {
resetSelection();
}
});
}
else {
checkCourseContinuousLimit(weekday);
}
});
}
function checkCourseContinuousLimit(weekday) {
var weekCourseTimes = new Array();
var currentCellWorkhours = parseInt(currentCell.attr("workhours"));
var courses = $('.schedulingCell[weekday=' + weekday + '] .schedulingItem');
$.each(courses, function (i, x) {
var weekNums = eval($(x).attr("WeeklyNums"));
var workhours = parseInt($(x).parent().attr("workhours"));
$.each(weekNums, function (n, w) {
var isContain = false;
$.each(weekCourseTimes, function (m, v) {
if (v.WeekNum == w) {
isContain = true;
v.Times += workhours;
}
});
if (isContain == false) {
weekCourseTimes.push({ WeekNum: w, Times: workhours });
}
});
});
$.each(currentSchedulingWeekList, function (n, w) {
var isContain = false;
$.each(weekCourseTimes, function (m, v) {
if (v.WeekNum == w.Week) {
isContain = true;
v.Times += currentCellWorkhours;
}
});
if (isContain == false) {
weekCourseTimes.push({ WeekNum: w.Week, Times: currentCellWorkhours });
}
});
if ($.grep(weekCourseTimes, function (x) { return x.Times > classScheduleContinuousCount; }).length > 0) {
$.messager.confirm("系统提示", "班级连续上课时间超限。是否继续将课程排在该节次?", function (r) {
if (r) {
checkCourseScheduleContinuousLimit(weekday);
} else {
resetSelection();
}
});
} else {
checkCourseScheduleContinuousLimit(weekday);
}
}
function checkCourseScheduleContinuousLimit(weekday) {
var weekCourseTimes = new Array();
var currentCellWorkhours = parseInt(currentCell.attr("workhours"));
var courses = $('.schedulingCell[weekday=' + weekday + '] .schedulingItem[CoursematerialID=' + currentItem.CoursematerialID + ']');
$.each(courses, function (i, x) {
var weekNums = eval($(x).attr("WeeklyNums"));
var workhours = parseInt($(x).parent().attr("workhours"));
var coursematerialID = $(x).attr("CoursematerialID");
$.each(weekNums, function (n, w) {
var isContain = false;
$.each(weekCourseTimes, function (m, v) {
if (v.WeekNum == w && v.CoursematerialID == coursematerialID) {
isContain = true;
v.Times += workhours;
}
});
if (isContain == false) {
weekCourseTimes.push({ WeekNum: w, CoursematerialID: coursematerialID, Times: workhours });
}
});
});
$.each(currentSchedulingWeekList, function (n, w) {
var isContain = false;
$.each(weekCourseTimes, function (m, v) {
if (v.WeekNum == w.Week && v.CoursematerialID == currentItem.CoursematerialID) {
isContain = true;
v.Times += currentCellWorkhours;
}
});
if (isContain == false) {
weekCourseTimes.push({ WeekNum: w.Week, CoursematerialID: currentItem.CoursematerialID, Times: currentCellWorkhours });
}
});
if ($.grep(weekCourseTimes, function (x) { return x.Times > classCourseScheduleContinuousCount; }).length > 0) {
$.messager.confirm("系统提示", "班级连续上同一课程时间超限。是否继续将课程排在该节次?", function (r) {
if (r) {
loadClassroom();
} else {
resetSelection();
}
});
} else {
loadClassroom();
}
}
function loadClassroom() {
var fixClassroomID = currentSchedulingWeekList[0].ClassroomID;
var fixClassroomName = currentSchedulingWeekList[0].ClassroomName;
if (fixClassroomID) {
var schoolYearID = $("#SchoolYearDropdown").combobox("getValue");
var collegeID = $("#CollegeDropdown").combobox("getValue");
var schedulingWeekListStr = $.map(currentSchedulingWeekList, function (x) { return x.Week; }).join(',');
var weekday = currentCell.attr("weekday");
var courseTimeID = currentCell.attr("coursesTimeID");
$.post(CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/IsClassroomIsAvailable', {
collegeID: collegeID,
schoolYearID: schoolYearID,
schedulingWeekListStr: schedulingWeekListStr,
weekday: weekday,
courseTimeID: courseTimeID,
classroomID: fixClassroomID
}, function (data) {
if (data.IsSuccess) {
addSchdulingCellItemWithClassroom({ ClassroomID: fixClassroomID, Name: fixClassroomName });
} else {
var reportLink = "";
if (data.Data) {
reportLink += '点击下列链接查看教室课表:
';
reportLink += '';
reportLink += fixClassroomName + "课表";
reportLink += " ";
}
$.messager.alert("系统提示", data.Message + reportLink);
}
}
);
}
else {
popupClassroomSelector();
}
}
function drawScheduleContainer(courseTimeData, schedulingData) {
var container = $('#scheduleContainer');
drawSchedulingCells(container, courseTimeData);
drawSchedulingData(container, schedulingData);
$(".schedulingCell").click(schedulingCellClicked);
}
function popupClassroomSelector() {
var schoolYearID = $("#SchoolYearDropdown").combobox("getValue");
var collegeID = $("#CollegeDropdown").combobox("getValue");
var weekday = currentCell.attr("weekday");
var courseTimeID = currentCell.attr("coursesTimeID");
var availableClassroomList = $.grep(usedClassroomList, function (x) { return x.weekday == weekday && x.courseTimeID == courseTimeID });
var classroomTypeID = currentSchedulingWeekList[0].ClassroomTypeID;
$.popupTopWindow('选择教室', CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/Setting', 650, 320, addSchdulingCellItemWithClassroom, {
schoolYearID: schoolYearID,
collegeID: collegeID,
weekday: weekday,
courseTimeID: courseTimeID,
classroomTypeID: classroomTypeID,
studentNum: currentItem.StudentNum,
schedulingWeekList: $.map(currentSchedulingWeekList, function (x) { return x.Week; }),
usedClassroomIDList: $.map(availableClassroomList, function (x) { return x.classroomID; })
});
}
function addSchdulingCellItemWithClassroom(classroom) {
if (classroom) {
var schoolYearID = $("#SchoolYearDropdown").combobox("getValue");
var weekday = currentCell.attr("weekday");
var courseTimeID = currentCell.attr("coursesTimeID");
$.post(CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/AddScheduling', {
schoolYearID: schoolYearID,
educationSchedulingClassID: currentItem.EducationSchedulingClassID,
weekListStr: $.map(currentSchedulingWeekList, function (x) { return x.Week }).join(','),
teacherStr: JSON.stringify(currentSchedulingWeekList[0].CourseProcessTeacherViewList),
weekday: weekday,
courseTimeID: courseTimeID,
classroomID: classroom.ClassroomID
}, function (data) {
if (!data.IsSuccess) {
$.messager.alert("系统提示", "排课失败:" + data.Message);
}
else {
schedulingClassSelectedWeekList[currentItem.EducationSchedulingClassID] = null;
currentItem = null;
currentCell = null;
currentSchedulingWeekList = null;
usedClassroomList = new Array();
teacherScheduleContinuousCount = 0;
classScheduleContinuousCount = 0;
classCourseScheduleContinuousCount = 0;
reload();
// var schedulingItem = {
// EducationSchedulingClassID: currentItem.EducationSchedulingClassID,
// TeachingModeName: currentItem.TeachingModeName,
// CoursematerialID: currentItem.CoursematerialID,
// CoursematerialName: currentItem.CoursematerialName,
// ClassroomTypeID: currentItem.ClassroomTypeID,
// ClassroomID: classroom.ClassroomID,
// ClassroomName: classroom.Name,
// WeekNumList: currentSchedulingWeekList,
// WeeklyNumString: currentItem.WeeklyNumString,
// TaskGroupName: currentItem.TaskGroupName,
// TeacherNames: currentItem.TeacherNames,
// CourseProcessViewList: currentItem.CourseProcessViewList,
// StudentCount: currentItem.StudentNum
// };
// usedClassroomList.push({ weekday: weekday, courseTimeID: courseTimeID, classroomID: classroom.ClassroomID });
// var listSchedulingClassList = $("#dgEducationSchedulingClassList").cmsXDataTable("getRows");
// $.each(listSchedulingClassList, function () {
// if (this.EducationSchedulingClassID == currentItem.EducationSchedulingClassID) {
// this.RemainCourseTime -= currentSchedulingWeekList.length;
// }
// });
// $("#dgEducationSchedulingClassList").cmsXDataTable("loadData", { rows: listSchedulingClassList, total: listSchedulingClassList.length });
// var html = drawSchedulingCellItem(currentCell, schedulingItem);
// resetSelection();
}
});
}
}
function resetSelection() {
currentCell = null;
currentItem = null;
currentSchedulingWeekList = null;
$("#dgEducationSchedulingClassList").find('tr.row>td').removeClass('selectedSchedulingClass');
}
function drawSchedulingCells(container, courseTimeData) {
var html = new Array();
html.push('