SchedulingCommon.js 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256
  1. var currentItem = null;
  2. var currentCell = null;
  3. var currentSchedulingWeekList = null;
  4. var usedClassroomList = new Array();
  5. var teacherScheduleContinuousCount = 0;
  6. var classScheduleContinuousCount = 0;
  7. var classCourseScheduleContinuousCount = 0;
  8. var mnu = "";
  9. var colorGroup = ["timeSpanCell1", "timeSpanCell2", "timeSpanCell3"];
  10. var isZoomOuted = false;
  11. var zoomRate = 5;
  12. var schedulingClassSelectedWeekList = [];
  13. $(function () {
  14. mnu = $.SystemGeneral.getUrlParam("MNU");
  15. $(".middleBar").mousedown(middleStartDrag);
  16. $(document).mousemove(middleDragging);
  17. });
  18. function EducationScheduling_ZoomOut() {
  19. if (!isZoomOuted) {
  20. $(".schedulingHeaderCell").width($(".schedulingHeaderCell").width() * zoomRate);
  21. $(".schedulingHeader").width($(".schedulingHeader").width() * zoomRate);
  22. $(".schedulingRow").width($(".schedulingRow").width() * zoomRate);
  23. $(".schedulingCell").width($(".schedulingCell").width() * zoomRate);
  24. $(".schedulingCellHeader").height($(".schedulingCellHeader").height() * zoomRate);
  25. $(".schedulingRow").height($(".schedulingRow").height() * zoomRate);
  26. $(".schedulingCell").height($(".schedulingCell").height() * zoomRate);
  27. $(".schedulingItem").each(function (i, x) {
  28. $(x).width($(x).width() * zoomRate);
  29. $(x).height($(x).height() * zoomRate);
  30. });
  31. isZoomOuted = true;
  32. }
  33. }
  34. function EducationScheduling_ZoomIn() {
  35. if (isZoomOuted) {
  36. $(".schedulingHeaderCell").width($(".schedulingHeaderCell").width() / zoomRate);
  37. $(".schedulingHeader").width($(".schedulingHeader").width() / zoomRate);
  38. $(".schedulingRow").width($(".schedulingRow").width() / zoomRate);
  39. $(".schedulingCell").width($(".schedulingCell").width() / zoomRate);
  40. $(".schedulingCellHeader").height($(".schedulingCellHeader").height() / zoomRate);
  41. $(".schedulingRow").height($(".schedulingRow").height() / zoomRate);
  42. $(".schedulingCell").height($(".schedulingCell").height() / zoomRate);
  43. $(".schedulingItem").each(function (i, x) {
  44. $(x).width($(x).width() / zoomRate);
  45. $(x).height($(x).height() / zoomRate);
  46. });
  47. isZoomOuted = false;
  48. }
  49. }
  50. var mouseXStart;
  51. var vmiddleBar;
  52. var isDragging = false;
  53. function middleStartDrag(event) {
  54. mouseXStart = $(".middleBar").offset().left;
  55. vmiddleBar = $(".middleBar").clone();
  56. vmiddleBar.removeClass("middleBar");
  57. vmiddleBar.css("border-style", "dashed");
  58. vmiddleBar.mouseup(middleEndDrag);
  59. vmiddleBar.appendTo(".popupWindowContent");
  60. isDragging = true;
  61. }
  62. function middleDragging(event) {
  63. if (isDragging) {
  64. event = event || window.event;
  65. event.cancelBubble = true;
  66. var x = event.clientX || event.originalEvent.layerX;
  67. var offset = $(".middleBar").offset();
  68. if ((mouseXStart - x) <= offset.left
  69. && (x - mouseXStart) <= $("#scheduleContainer").width()) {
  70. offset.left = offset.left - (mouseXStart - x);
  71. vmiddleBar.offset(offset);
  72. }
  73. return false;
  74. }
  75. }
  76. function middleEndDrag(event) {
  77. if (vmiddleBar) {
  78. event = event || window.event;
  79. var x = event.clientX || event.originalEvent.layerX;
  80. var middleBarOffset = $(".middleBar").offset();
  81. var containerWidth = $("#scheduleContainer").width();
  82. var containerOffset = $("#scheduleContainer").offset();
  83. if ((mouseXStart - x) <= middleBarOffset.left && (x - mouseXStart) <= containerWidth) {
  84. middleBarOffset.left = middleBarOffset.left - (mouseXStart - x);
  85. } else if ((mouseXStart - x) > middleBarOffset.left) {
  86. middleBarOffset.left = 1;
  87. } else if ((x - mouseXStart) > containerWidth) {
  88. middleBarOffset.left = containerWidth - 3;
  89. }
  90. $("#leftContainer").width(middleBarOffset.left);
  91. $(".middleBar").offset(middleBarOffset);
  92. $("#scheduleContainer").width(containerWidth + (mouseXStart - x) - 2);
  93. if ($("#scheduleContainer").width() - 100 > 0) {
  94. $(".schedulingHeaderContainer").width($("#scheduleContainer").width() - 100);
  95. $(".schedulingCellContainer").width($(".schedulingHeaderContainer").width());
  96. } else {
  97. $(".schedulingHeaderContainer").width(1);
  98. $(".schedulingCellContainer").width(1);
  99. }
  100. containerOffset.left = middleBarOffset.left + 2;
  101. $("#scheduleContainer").offset(containerOffset);
  102. vmiddleBar.css("display", "none");
  103. $(".popupWindowContent").remove(vmiddleBar);
  104. vmiddleBar = null;
  105. isDragging = false;
  106. }
  107. }
  108. function popupTeacherReport(userID) {
  109. var schoolYearID = $("#SchoolYearDropdown").combobox("getValue");
  110. var fullUrl = CMS_SystemConfig.ReportPagePath + "?ReportFolder=%2fEducationScheduling%2fTeacherSchedulingView&CollegeID_RAP=&UserID_RAP=" + userID + "&SchoolyearID_RAP=" + schoolYearID;
  111. $.popupTopWindowOutsite('教师课表', fullUrl, 1024, 600);
  112. }
  113. function popupClassroomReport(ClassroomID) {
  114. var schoolYearID = $("#SchoolYearDropdown").combobox("getValue");
  115. var fullUrl = CMS_SystemConfig.ReportPagePath + "?ReportFolder=%2fEducationScheduling%2fClassroomSchedulingView&BuildingsInfoID_RAP=&ClassroomID_RAP=" + ClassroomID + "&SchoolyearID_RAP=" + schoolYearID;
  116. $.popupTopWindowOutsite('教室课表', fullUrl, 1024, 600);
  117. }
  118. function showClassroomScheduleView(classroomID) {
  119. var schoolYearID = $("#SchoolYearDropdown").combobox("getValue");
  120. $.popupTopWindowOutsite('教室课表', CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/ClassroomScheduleView?SchoolyearID=' + schoolYearID + '&ClassroomID=' + classroomID, 800, 400);
  121. }
  122. function EducationScheduling_Submit() {
  123. var collegeID = $("#CollegeDropdown").combobox("getValue");
  124. $.popupTopWindow('提交课表', CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/Submit', 300, 200, reload, {
  125. collegeID: collegeID
  126. });
  127. }
  128. function gridLoaded() {
  129. //加载中间内容
  130. loadScheduleContainer();
  131. }
  132. function loadScheduleContainer() {
  133. $.post(CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/GetContinuousLimitView', null, function (data) {
  134. teacherScheduleContinuousCount = data.TeacherScheduleContinuousCount;
  135. classScheduleContinuousCount = data.ClassScheduleContinuousCount;
  136. classCourseScheduleContinuousCount = data.ClassCourseScheduleContinuousCount;
  137. loadScheduleData();
  138. });
  139. }
  140. function getCoursesTimeList(schedulingData) {
  141. $.post(CMS_SystemConfig.VirtualDirectoryPath + '/CoursesTime/ListAll', null, function (courseTimeData) {
  142. drawScheduleContainer(courseTimeData, schedulingData);
  143. });
  144. }
  145. function checkWeekTimeOverflowAndSetWeekList(weekList) {
  146. var workhours = parseInt(currentCell.attr("workhours"));
  147. weekList = $.grep(weekList, function (x) { return x.Times >= workhours });
  148. if (weekList.length == 0) {
  149. $.messager.alert("系统提示", "该时段需要排" + workhours.toString() + "个学时,该任务班的剩余学时不足,不能排课。");
  150. return false;
  151. }
  152. currentSchedulingWeekList = weekList;
  153. var isDup = false;
  154. //只有同一个排课班才需要判断周次冲突
  155. $.each(currentCell.find('.schedulingItem'), function (i, x) {
  156. if (currentItem.EducationSchedulingClassID == $(x).attr("EducationSchedulingClassID")) {
  157. var weeklyNumList = eval($(x).attr("WeeklyNums"));
  158. $.each(currentSchedulingWeekList, function (n, w) {
  159. if (weeklyNumList.contains(w.Week)) {
  160. $.messager.alert("系统提示", "上课周次冲突。");
  161. isDup = true;
  162. return false;
  163. }
  164. });
  165. }
  166. });
  167. if (isDup) {
  168. return false;
  169. }
  170. return true;
  171. }
  172. function getScheduledItemRemainWeekNums(scheduleItem, allScheduled) {
  173. var weekList = $.map(scheduleItem.CourseProcessViewList, function (x) {
  174. return {
  175. Week: x.Week,
  176. Times: x.Times,
  177. CourseProcessTeacherViewList: x.CourseProcessTeacherViewList,
  178. StaffNames: x.StaffNames,
  179. ClassroomTypeID: x.ClassroomTypeID,
  180. ClassroomTypeName: x.ClassroomTypeName,
  181. ClassroomID: x.ClassroomID,
  182. ClassroomName: x.ClassroomName
  183. };
  184. });
  185. $.each(allScheduled, function (i, x) {
  186. var weeklyNumList = eval($(x).attr("WeeklyNums"));
  187. var workhours = parseInt($(x).parent().attr("workhours"));
  188. var teacherTeachingViewList = eval(unescape($(x).attr("TeacherTeachingViewList")));
  189. weekList = $.map(weekList, function (m) {
  190. var newTimes = m.Times;
  191. if (weeklyNumList.contains(m.Week)
  192. && $.map(m.CourseProcessTeacherViewList, function (w) { return w.UserID + '|' + w.TeachingMethod.toString(); }).join(',') == $.map(teacherTeachingViewList, function (w) { return w.UserID + '|' + w.TeachingMethod.toString(); }).join(',')) {
  193. newTimes = newTimes - workhours;
  194. }
  195. return {
  196. Week: m.Week,
  197. Times: newTimes,
  198. CourseProcessTeacherViewList: m.CourseProcessTeacherViewList,
  199. StaffNames: m.StaffNames,
  200. ClassroomTypeID: m.ClassroomTypeID,
  201. ClassroomTypeName: m.ClassroomTypeName,
  202. ClassroomID: m.ClassroomID,
  203. ClassroomName: m.ClassroomName
  204. };
  205. });
  206. });
  207. weekList = $.grep(weekList, function (x) { return x.Times > 0; });
  208. return weekList;
  209. }
  210. //输入一个列表上的排课班,和已排有这个排课班的格子匹配,获取这个排课班剩余可以排的周次
  211. function getScheduleItemWeekNums(scheduleItem, allScheduled, splitWeeks) {
  212. var weekList = $.map(scheduleItem.CourseProcessViewList, function (x) {
  213. return {
  214. Week: x.Week,
  215. Times: x.Times,
  216. CourseProcessTeacherViewList: x.CourseProcessTeacherViewList,
  217. StaffNames: x.StaffNames,
  218. ClassroomTypeID: x.ClassroomTypeID,
  219. ClassroomTypeName: x.ClassroomTypeName,
  220. ClassroomID: x.ClassroomID,
  221. ClassroomName: x.ClassroomName
  222. };
  223. });
  224. if (!splitWeeks && schedulingClassSelectedWeekList[scheduleItem.EducationSchedulingClassID] != null) {
  225. weekList = $.grep(weekList, function (x) { return schedulingClassSelectedWeekList[scheduleItem.EducationSchedulingClassID].contains(x.Week); });
  226. }
  227. $.each(allScheduled, function (i, x) {
  228. var weeklyNumList = eval($(x).attr("WeeklyNums"));
  229. var workhours = parseInt($(x).parent().attr("workhours"));
  230. var teacherTeachingViewList = eval(unescape($(x).attr("TeacherTeachingViewList")));
  231. // var classroomTypeID = $(x).attr("ClassroomTypeID");
  232. // var classroomID = $(x).attr("ClassroomID");
  233. weekList = $.map(weekList, function (m) {
  234. var newTimes = m.Times;
  235. if (weeklyNumList.contains(m.Week)
  236. && $.map(m.CourseProcessTeacherViewList, function (w) { return w.UserID + '|' + w.TeachingMethod.toString(); }).join(',') == $.map(teacherTeachingViewList, function (w) { return w.UserID + '|' + w.TeachingMethod.toString(); }).join(',')
  237. // && m.ClassroomTypeID == classroomTypeID
  238. // && m.ClassroomID == classroomID
  239. ) {
  240. newTimes = newTimes - workhours;
  241. }
  242. return {
  243. Week: m.Week,
  244. Times: newTimes,
  245. CourseProcessTeacherViewList: m.CourseProcessTeacherViewList,
  246. StaffNames: m.StaffNames,
  247. ClassroomTypeID: m.ClassroomTypeID,
  248. ClassroomTypeName: m.ClassroomTypeName,
  249. ClassroomID: m.ClassroomID,
  250. ClassroomName: m.ClassroomName
  251. };
  252. });
  253. });
  254. weekList = $.grep(weekList, function (x) { return x.Times > 0; })
  255. .sort(function (a, b) { return a.Times - b.Times; });
  256. var weekListMap = {};
  257. var weekListGroup = [];
  258. for (var i = 0; i < weekList.length; i++) {
  259. var existModifyGroup = $.grep(weekListGroup, function (x) {
  260. return x.CourseProcessTeacherViewList.length == weekList[i].CourseProcessTeacherViewList.length
  261. && $.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(',')
  262. && x.ClassroomTypeID == weekList[i].ClassroomTypeID
  263. && x.ClassroomID == weekList[i].ClassroomID
  264. && x.Times <= weekList[i].Times
  265. });
  266. if (existModifyGroup.length > 0) {
  267. $.each(weekListGroup, function (n, x) {
  268. 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(',')
  269. && x.ClassroomTypeID == weekList[i].ClassroomTypeID
  270. && x.ClassroomID == weekList[i].ClassroomID
  271. && x.Times <= weekList[i].Times) {
  272. x.WeekNums.push(weekList[i].Week);
  273. }
  274. });
  275. }
  276. var existGroup = $.grep(weekListGroup, function (x) {
  277. return x.CourseProcessTeacherViewList.length == weekList[i].CourseProcessTeacherViewList.length
  278. && $.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(',')
  279. && x.ClassroomTypeID == weekList[i].ClassroomTypeID
  280. && x.ClassroomID == weekList[i].ClassroomID
  281. && x.Times == weekList[i].Times
  282. });
  283. if (existGroup.length == 0) {
  284. weekListGroup.push({
  285. CourseProcessTeacherViewList: weekList[i].CourseProcessTeacherViewList,
  286. ClassroomTypeID: weekList[i].ClassroomTypeID,
  287. ClassroomTypeName: weekList[i].ClassroomTypeName,
  288. ClassroomID: weekList[i].ClassroomID,
  289. ClassroomName: weekList[i].ClassroomName,
  290. Times: weekList[i].Times,
  291. TeacherNameColumn: $.map(weekList[i].CourseProcessTeacherViewList, function (x) { return x.Name + '(' + x.TeachingMethodName + ')'; }).join(','),
  292. WeekNums: [weekList[i].Week]
  293. });
  294. }
  295. }
  296. $.each(weekListGroup, function (i, x) { x.WeekNumString = getWeekNumString(x.WeekNums); });
  297. if (weekListGroup.length == 0) {
  298. $.messager.alert("系统提示", "任务班的周学时已经排满。");
  299. return;
  300. }
  301. if (weekListGroup) {
  302. if (splitWeeks) {
  303. if (weekListGroup.length > 1) {
  304. $.popupTopWindow('选择排课组', CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/SelectGroup', 650, 320, preSelectWeek, {
  305. weekList: weekList,
  306. weekListGroup: weekListGroup
  307. });
  308. } else {
  309. preSelectWeek({
  310. weekList: weekList,
  311. weekListGroup: weekListGroup[0]
  312. });
  313. }
  314. } else {
  315. if (weekListGroup.length > 1) {
  316. $.popupTopWindow('选择排课组', CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/SelectGroup', 650, 320, selectGroupConfirm, {
  317. weekList: weekList,
  318. weekListGroup: weekListGroup
  319. });
  320. } else {
  321. selectGroupConfirm({
  322. weekList: weekList,
  323. weekListGroup: weekListGroup[0]
  324. });
  325. }
  326. }
  327. }
  328. }
  329. function selectGroupConfirm(weekListGroupData) {
  330. if (!weekListGroupData) return;
  331. var weekday = currentCell.attr("weekday");
  332. var courseTimeID = currentCell.attr("coursesTimeID");
  333. weekList = $.grep(weekListGroupData.weekList, function (x) {
  334. return x.CourseProcessTeacherViewList.length == weekListGroupData.weekListGroup.CourseProcessTeacherViewList.length
  335. && $.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(',')
  336. && x.ClassroomTypeID == weekListGroupData.weekListGroup.ClassroomTypeID
  337. && x.ClassroomID == weekListGroupData.weekListGroup.ClassroomID
  338. && x.Times >= weekListGroupData.weekListGroup.Times
  339. });
  340. if (!checkWeekTimeOverflowAndSetWeekList(weekList)) {
  341. resetSelection();
  342. return;
  343. }
  344. checkTeacherIsOnWork(weekday, courseTimeID);
  345. }
  346. function isTeacherOverflow(teacherWorkTimeList, weekday) {
  347. var teacherDayClasses = new Array();
  348. var isOverflow = false;
  349. $.each(teacherWorkTimeList, function (i, x) {
  350. var teacherDayClass = $.grep(teacherDayClasses, function (y) { return y.UserID == x.UserID && y.WeekNum == x.WeekNum; });
  351. if (teacherDayClass.length == 0) {
  352. teacherDayClasses.push({
  353. UserID: x.UserID,
  354. Name: x.Name,
  355. WeekNum: x.WeekNum,
  356. WorkTime: x.WorkTime
  357. });
  358. } else {
  359. $.each(teacherDayClasses, function (o, y) {
  360. if (y.UserID == x.UserID && y.WeekNum == x.WeekNum) {
  361. y.WorkTime += x.WorkTime;
  362. }
  363. });
  364. }
  365. });
  366. //再循环一次,加入待排课程的上课时间
  367. var cellworkhours = parseInt(currentCell.attr("workhours"));
  368. $.each(currentSchedulingWeekList, function (i, x) {
  369. $.each(x.CourseProcessTeacherViewList, function (n, w) {
  370. var teacherDayClass = $.grep(teacherDayClasses, function (y) { return y.UserID == w.UserID && y.WeekNum == x.Week; });
  371. if (teacherDayClass.length == 0) {
  372. teacherDayClasses.push({
  373. UserID: w.UserID,
  374. Name: w.Name,
  375. WeekNum: x.Week,
  376. WorkTime: cellworkhours
  377. });
  378. } else {
  379. $.each(teacherDayClasses, function (o, y) {
  380. if (y.UserID == w.UserID && y.WeekNum == x.Week) {
  381. y.WorkTime += cellworkhours;
  382. }
  383. if (y.WorkTime > teacherScheduleContinuousCount) {
  384. isOverflow = true;
  385. }
  386. });
  387. }
  388. });
  389. });
  390. return isOverflow;
  391. }
  392. function schedulingCellClicked() {
  393. if ($(event.srcElement).hasClass("scheduleItemTeacherLink")) {
  394. return;
  395. }
  396. if (currentItem != null) {
  397. currentCell = $(this);
  398. var weekday = currentCell.attr("weekday");
  399. var courseTimeID = currentCell.attr("coursesTimeID");
  400. var allScheduled = $('.schedulingItem[EducationSchedulingClassID=' + currentItem.EducationSchedulingClassID + ']');
  401. //先看当前时间点是否可以排课
  402. $.post(CMS_SystemConfig.VirtualDirectoryPath + '/Arrangements/IsOnWork', {
  403. weekday: weekday,
  404. courseTimeID: courseTimeID
  405. }, function (data) {
  406. if (!data) {
  407. $.messager.alert("系统提示", "该时间点不是工作时间,不能排课,请与校历管理员联系咨询。");
  408. } else {
  409. //选教室之前,需要判断是否可以排在这一格
  410. $.post(CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/IsCourseOnWork', {
  411. coursematerialID: currentItem.CoursematerialID,
  412. weekday: weekday,
  413. courseTimeID: courseTimeID
  414. }, function (data) {
  415. if (!data.IsSuccess) {
  416. $.messager.confirm("系统提示", data.Message + "是否继续将课程排在该节次?", function (r) {
  417. if (r) {
  418. getScheduleItemWeekNums(currentItem, allScheduled, false);
  419. } else {
  420. resetSelection();
  421. }
  422. });
  423. } else {
  424. getScheduleItemWeekNums(currentItem, allScheduled, false);
  425. }
  426. });
  427. }
  428. })
  429. } else {
  430. if ($(this).children('.schedulingItem').length == 0) {
  431. var selectedItems = $('.schedulingItemSelected');
  432. selectedItems.removeClass('schedulingItemSelected');
  433. }
  434. }
  435. }
  436. function checkTeacherIsOnWork(weekday, courseTimeID) {
  437. $.post(CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/IsTeacherOnWork', {
  438. educationScheduleClassID: currentItem.EducationSchedulingClassID,
  439. schedulingWeekListStr: JSON.stringify(currentSchedulingWeekList),
  440. weekday: weekday,
  441. courseTimeID: courseTimeID
  442. }, function (data) {
  443. isContinue = true;
  444. if (!data.IsSuccess) {
  445. $.messager.confirm("系统提示", data.Message + "是否继续将课程排在该节次?", function (r) {
  446. if (r) {
  447. checkIsBusy(weekday, courseTimeID);
  448. } else {
  449. resetSelection();
  450. }
  451. });
  452. } else {
  453. checkIsBusy(weekday, courseTimeID);
  454. }
  455. });
  456. }
  457. function checkIsBusy(weekday, courseTimeID) {
  458. var schoolYearID = $("#SchoolYearDropdown").combobox("getValue");
  459. $.post(CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/IsEducationSchedulingClassCanAddManualSchedule', {
  460. educationScheduleClassID: currentItem.EducationSchedulingClassID,
  461. schedulingWeekListStr: JSON.stringify(currentSchedulingWeekList),
  462. schoolYearID: schoolYearID,
  463. weekday: weekday,
  464. courseTimeID: courseTimeID
  465. }, function (data) {
  466. if (data.IsSuccess) {
  467. checkTeacherWorktimeLimit(schoolYearID, weekday);
  468. }
  469. else {
  470. var reportLink = "";
  471. if (data.Message.indexOf('教师') >= 0) {
  472. reportLink += "点击下列链接查看相关教师的课表:<br>";
  473. $.each(data.Data, function (i, x) {
  474. reportLink += '<a href="#this" onclick="javascript:popupTeacherReport(\'' + x.Key + '\');" style="color: #0000ff;">';
  475. reportLink += x.Value + "课表";
  476. reportLink += "</a>&nbsp;";
  477. });
  478. }
  479. $.messager.alert("系统提示", data.Message + reportLink);
  480. resetSelection();
  481. return;
  482. }
  483. });
  484. }
  485. function checkTeacherWorktimeLimit(schoolYearID, weekday) {
  486. //再判断教师连续工作时间、班级连续工作时间是否超限
  487. $.post(CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/GetTeacherContinuousWorkTime', {
  488. educationScheduleClassID: currentItem.EducationSchedulingClassID,
  489. schedulingWeekListStr: JSON.stringify(currentSchedulingWeekList),
  490. schoolYearID: schoolYearID,
  491. weekday: weekday
  492. }, function (teacherWorkTimeList) {
  493. if (isTeacherOverflow(teacherWorkTimeList, weekday)) {
  494. var reportLink = "";
  495. var teacherList = [];
  496. $.each(teacherWorkTimeList, function (i, x) {
  497. if (!teacherList.contains(x.UserID)) {
  498. teacherList.push(x.UserID);
  499. reportLink += '<a href="#this" onclick="javascript:popupTeacherReport(\'' + x.UserID + '\');" style="color: #0000ff;">';
  500. reportLink += x.Name + "课表";
  501. reportLink += "</a>&nbsp;";
  502. }
  503. });
  504. $.messager.confirm("系统提示", "教师连续工作时间超限,是否继续将课程排在该节次?点击下列链接查看相关教师的课表:<br>" + reportLink, function (r) {
  505. if (r) {
  506. checkCourseContinuousLimit(weekday);
  507. } else {
  508. resetSelection();
  509. }
  510. });
  511. }
  512. else {
  513. checkCourseContinuousLimit(weekday);
  514. }
  515. });
  516. }
  517. function checkCourseContinuousLimit(weekday) {
  518. var weekCourseTimes = new Array();
  519. var currentCellWorkhours = parseInt(currentCell.attr("workhours"));
  520. var courses = $('.schedulingCell[weekday=' + weekday + '] .schedulingItem');
  521. $.each(courses, function (i, x) {
  522. var weekNums = eval($(x).attr("WeeklyNums"));
  523. var workhours = parseInt($(x).parent().attr("workhours"));
  524. $.each(weekNums, function (n, w) {
  525. var isContain = false;
  526. $.each(weekCourseTimes, function (m, v) {
  527. if (v.WeekNum == w) {
  528. isContain = true;
  529. v.Times += workhours;
  530. }
  531. });
  532. if (isContain == false) {
  533. weekCourseTimes.push({ WeekNum: w, Times: workhours });
  534. }
  535. });
  536. });
  537. $.each(currentSchedulingWeekList, function (n, w) {
  538. var isContain = false;
  539. $.each(weekCourseTimes, function (m, v) {
  540. if (v.WeekNum == w.Week) {
  541. isContain = true;
  542. v.Times += currentCellWorkhours;
  543. }
  544. });
  545. if (isContain == false) {
  546. weekCourseTimes.push({ WeekNum: w.Week, Times: currentCellWorkhours });
  547. }
  548. });
  549. if ($.grep(weekCourseTimes, function (x) { return x.Times > classScheduleContinuousCount; }).length > 0) {
  550. $.messager.confirm("系统提示", "班级连续上课时间超限。是否继续将课程排在该节次?", function (r) {
  551. if (r) {
  552. checkCourseScheduleContinuousLimit(weekday);
  553. } else {
  554. resetSelection();
  555. }
  556. });
  557. } else {
  558. checkCourseScheduleContinuousLimit(weekday);
  559. }
  560. }
  561. function checkCourseScheduleContinuousLimit(weekday) {
  562. var weekCourseTimes = new Array();
  563. var currentCellWorkhours = parseInt(currentCell.attr("workhours"));
  564. var courses = $('.schedulingCell[weekday=' + weekday + '] .schedulingItem[CoursematerialID=' + currentItem.CoursematerialID + ']');
  565. $.each(courses, function (i, x) {
  566. var weekNums = eval($(x).attr("WeeklyNums"));
  567. var workhours = parseInt($(x).parent().attr("workhours"));
  568. var coursematerialID = $(x).attr("CoursematerialID");
  569. $.each(weekNums, function (n, w) {
  570. var isContain = false;
  571. $.each(weekCourseTimes, function (m, v) {
  572. if (v.WeekNum == w && v.CoursematerialID == coursematerialID) {
  573. isContain = true;
  574. v.Times += workhours;
  575. }
  576. });
  577. if (isContain == false) {
  578. weekCourseTimes.push({ WeekNum: w, CoursematerialID: coursematerialID, Times: workhours });
  579. }
  580. });
  581. });
  582. $.each(currentSchedulingWeekList, function (n, w) {
  583. var isContain = false;
  584. $.each(weekCourseTimes, function (m, v) {
  585. if (v.WeekNum == w.Week && v.CoursematerialID == currentItem.CoursematerialID) {
  586. isContain = true;
  587. v.Times += currentCellWorkhours;
  588. }
  589. });
  590. if (isContain == false) {
  591. weekCourseTimes.push({ WeekNum: w.Week, CoursematerialID: currentItem.CoursematerialID, Times: currentCellWorkhours });
  592. }
  593. });
  594. if ($.grep(weekCourseTimes, function (x) { return x.Times > classCourseScheduleContinuousCount; }).length > 0) {
  595. $.messager.confirm("系统提示", "班级连续上同一课程时间超限。是否继续将课程排在该节次?", function (r) {
  596. if (r) {
  597. loadClassroom();
  598. } else {
  599. resetSelection();
  600. }
  601. });
  602. } else {
  603. loadClassroom();
  604. }
  605. }
  606. function loadClassroom() {
  607. var fixClassroomID = currentSchedulingWeekList[0].ClassroomID;
  608. var fixClassroomName = currentSchedulingWeekList[0].ClassroomName;
  609. if (fixClassroomID) {
  610. var schoolYearID = $("#SchoolYearDropdown").combobox("getValue");
  611. var collegeID = $("#CollegeDropdown").combobox("getValue");
  612. var schedulingWeekListStr = $.map(currentSchedulingWeekList, function (x) { return x.Week; }).join(',');
  613. var weekday = currentCell.attr("weekday");
  614. var courseTimeID = currentCell.attr("coursesTimeID");
  615. $.post(CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/IsClassroomIsAvailable', {
  616. collegeID: collegeID,
  617. schoolYearID: schoolYearID,
  618. schedulingWeekListStr: schedulingWeekListStr,
  619. weekday: weekday,
  620. courseTimeID: courseTimeID,
  621. classroomID: fixClassroomID
  622. }, function (data) {
  623. if (data.IsSuccess) {
  624. addSchdulingCellItemWithClassroom({ ClassroomID: fixClassroomID, Name: fixClassroomName });
  625. } else {
  626. var reportLink = "";
  627. if (data.Data) {
  628. reportLink += '点击下列链接查看教室课表:<br>';
  629. reportLink += '<a href="#this" onclick="javascript:popupClassroomReport(\'' + fixClassroomID + '\');" style="color: #0000ff;">';
  630. reportLink += fixClassroomName + "课表";
  631. reportLink += "</a>&nbsp;";
  632. }
  633. $.messager.alert("系统提示", data.Message + reportLink);
  634. }
  635. }
  636. );
  637. }
  638. else {
  639. popupClassroomSelector();
  640. }
  641. }
  642. function drawScheduleContainer(courseTimeData, schedulingData) {
  643. var container = $('#scheduleContainer');
  644. drawSchedulingCells(container, courseTimeData);
  645. drawSchedulingData(container, schedulingData);
  646. $(".schedulingCell").click(schedulingCellClicked);
  647. }
  648. function popupClassroomSelector() {
  649. var schoolYearID = $("#SchoolYearDropdown").combobox("getValue");
  650. var collegeID = $("#CollegeDropdown").combobox("getValue");
  651. var weekday = currentCell.attr("weekday");
  652. var courseTimeID = currentCell.attr("coursesTimeID");
  653. var availableClassroomList = $.grep(usedClassroomList, function (x) { return x.weekday == weekday && x.courseTimeID == courseTimeID });
  654. var classroomTypeID = currentSchedulingWeekList[0].ClassroomTypeID;
  655. $.popupTopWindow('选择教室', CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/Setting', 650, 320, addSchdulingCellItemWithClassroom, {
  656. schoolYearID: schoolYearID,
  657. collegeID: collegeID,
  658. weekday: weekday,
  659. courseTimeID: courseTimeID,
  660. classroomTypeID: classroomTypeID,
  661. studentNum: currentItem.StudentNum,
  662. schedulingWeekList: $.map(currentSchedulingWeekList, function (x) { return x.Week; }),
  663. usedClassroomIDList: $.map(availableClassroomList, function (x) { return x.classroomID; })
  664. });
  665. }
  666. function addSchdulingCellItemWithClassroom(classroom) {
  667. if (classroom) {
  668. var schoolYearID = $("#SchoolYearDropdown").combobox("getValue");
  669. var weekday = currentCell.attr("weekday");
  670. var courseTimeID = currentCell.attr("coursesTimeID");
  671. $.post(CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/AddScheduling', {
  672. schoolYearID: schoolYearID,
  673. educationSchedulingClassID: currentItem.EducationSchedulingClassID,
  674. weekListStr: $.map(currentSchedulingWeekList, function (x) { return x.Week }).join(','),
  675. teacherStr: JSON.stringify(currentSchedulingWeekList[0].CourseProcessTeacherViewList),
  676. weekday: weekday,
  677. courseTimeID: courseTimeID,
  678. classroomID: classroom.ClassroomID
  679. }, function (data) {
  680. if (!data.IsSuccess) {
  681. $.messager.alert("系统提示", "排课失败:" + data.Message);
  682. }
  683. else {
  684. schedulingClassSelectedWeekList[currentItem.EducationSchedulingClassID] = null;
  685. currentItem = null;
  686. currentCell = null;
  687. currentSchedulingWeekList = null;
  688. usedClassroomList = new Array();
  689. teacherScheduleContinuousCount = 0;
  690. classScheduleContinuousCount = 0;
  691. classCourseScheduleContinuousCount = 0;
  692. reload();
  693. // var schedulingItem = {
  694. // EducationSchedulingClassID: currentItem.EducationSchedulingClassID,
  695. // TeachingModeName: currentItem.TeachingModeName,
  696. // CoursematerialID: currentItem.CoursematerialID,
  697. // CoursematerialName: currentItem.CoursematerialName,
  698. // ClassroomTypeID: currentItem.ClassroomTypeID,
  699. // ClassroomID: classroom.ClassroomID,
  700. // ClassroomName: classroom.Name,
  701. // WeekNumList: currentSchedulingWeekList,
  702. // WeeklyNumString: currentItem.WeeklyNumString,
  703. // TaskGroupName: currentItem.TaskGroupName,
  704. // TeacherNames: currentItem.TeacherNames,
  705. // CourseProcessViewList: currentItem.CourseProcessViewList,
  706. // StudentCount: currentItem.StudentNum
  707. // };
  708. // usedClassroomList.push({ weekday: weekday, courseTimeID: courseTimeID, classroomID: classroom.ClassroomID });
  709. // var listSchedulingClassList = $("#dgEducationSchedulingClassList").cmsXDataTable("getRows");
  710. // $.each(listSchedulingClassList, function () {
  711. // if (this.EducationSchedulingClassID == currentItem.EducationSchedulingClassID) {
  712. // this.RemainCourseTime -= currentSchedulingWeekList.length;
  713. // }
  714. // });
  715. // $("#dgEducationSchedulingClassList").cmsXDataTable("loadData", { rows: listSchedulingClassList, total: listSchedulingClassList.length });
  716. // var html = drawSchedulingCellItem(currentCell, schedulingItem);
  717. // resetSelection();
  718. }
  719. });
  720. }
  721. }
  722. function resetSelection() {
  723. currentCell = null;
  724. currentItem = null;
  725. currentSchedulingWeekList = null;
  726. $("#dgEducationSchedulingClassList").find('tr.row>td').removeClass('selectedSchedulingClass');
  727. }
  728. function drawSchedulingCells(container, courseTimeData) {
  729. var html = new Array();
  730. html.push('<div class="schedulingHeaderCellHeader"></div>');
  731. html.push('<div class="schedulingHeaderContainer">');
  732. html.push('<div class="schedulingHeader">');
  733. html.push('<div class="schedulingHeaderCell">星期一</div>');
  734. html.push('<div class="schedulingHeaderCell">星期二</div>');
  735. html.push('<div class="schedulingHeaderCell">星期三</div>');
  736. html.push('<div class="schedulingHeaderCell">星期四</div>');
  737. html.push('<div class="schedulingHeaderCell">星期五</div>');
  738. html.push('<div class="schedulingHeaderCell">星期六</div>');
  739. html.push('<div class="schedulingHeaderCell">星期日</div>');
  740. html.push('</div>');
  741. html.push('</div>');
  742. var timesSegment = $.map(courseTimeData, function (x) { return x.TimesSegment; }).unique().sort();
  743. var schedulingCellHeaderContainerHtml = new Array();
  744. var schedulingCellContainerHtml = new Array();
  745. schedulingCellHeaderContainerHtml.push('<div class="schedulingCellHeaderContainer">');
  746. schedulingCellContainerHtml.push('<div class="schedulingCellContainer">');
  747. $.each(courseTimeData, function () {
  748. var colorStyleString = '';
  749. var i;
  750. for (i = 0; i < timesSegment.length; i++) {
  751. if (timesSegment[i] == this.TimesSegment) {
  752. colorStyleString = " " + colorGroup[i % colorGroup.length];
  753. }
  754. }
  755. schedulingCellHeaderContainerHtml.push('<div class="schedulingCellHeader' + colorStyleString + '" coursesTimeID="' + this.CoursesTimeID + '">');
  756. schedulingCellHeaderContainerHtml.push(this.StartDate + "-" + this.EndDate);
  757. schedulingCellHeaderContainerHtml.push('</div>');
  758. schedulingCellContainerHtml.push('<div class="schedulingRow">');
  759. schedulingCellContainerHtml.push('<div class="schedulingCell' + colorStyleString + '" coursesTimeID="' + this.CoursesTimeID + '" workhours="' + this.Workhours + '" weekday="1">');
  760. schedulingCellContainerHtml.push('</div>');
  761. schedulingCellContainerHtml.push('<div class="schedulingCell' + colorStyleString + '" coursesTimeID="' + this.CoursesTimeID + '" workhours="' + this.Workhours + '" weekday="2">');
  762. schedulingCellContainerHtml.push('</div>');
  763. schedulingCellContainerHtml.push('<div class="schedulingCell' + colorStyleString + '" coursesTimeID="' + this.CoursesTimeID + '" workhours="' + this.Workhours + '" weekday="3">');
  764. schedulingCellContainerHtml.push('</div>');
  765. schedulingCellContainerHtml.push('<div class="schedulingCell' + colorStyleString + '" coursesTimeID="' + this.CoursesTimeID + '" workhours="' + this.Workhours + '" weekday="4">');
  766. schedulingCellContainerHtml.push('</div>');
  767. schedulingCellContainerHtml.push('<div class="schedulingCell' + colorStyleString + '" coursesTimeID="' + this.CoursesTimeID + '" workhours="' + this.Workhours + '" weekday="5">');
  768. schedulingCellContainerHtml.push('</div>');
  769. schedulingCellContainerHtml.push('<div class="schedulingCell' + colorStyleString + '" coursesTimeID="' + this.CoursesTimeID + '" workhours="' + this.Workhours + '" weekday="6">');
  770. schedulingCellContainerHtml.push('</div>');
  771. schedulingCellContainerHtml.push('<div class="schedulingCell' + colorStyleString + '" coursesTimeID="' + this.CoursesTimeID + '" workhours="' + this.Workhours + '" weekday="0">');
  772. schedulingCellContainerHtml.push('</div>');
  773. schedulingCellContainerHtml.push('</div>');
  774. });
  775. schedulingCellHeaderContainerHtml.push('</div>');
  776. schedulingCellContainerHtml.push('</div>')
  777. html.push("<div>");
  778. html.push(schedulingCellHeaderContainerHtml.join(''));
  779. html.push(schedulingCellContainerHtml.join(''));
  780. html.push("</div>");
  781. container.html(html.join(''));
  782. var containerWith = $(document).width() - $("#scheduleContainer").position().left - $(".schedulingCellHeader").width() - 18;
  783. var containerHeight = $(document).height() - $("#scheduleContainer").position().top - $(".schedulingCellHeader").height();
  784. var mainContainer = $(".schedulingCellContainer").parent();
  785. //mainContainer.css("line-height", containerHeight + "px");
  786. mainContainer.height(containerHeight);
  787. $(".schedulingCellHeaderContainer").width($(".schedulingCellHeader").width() + 2);
  788. $(".schedulingCellHeaderContainer").height(containerHeight);
  789. $(".schedulingHeaderContainer").width(containerWith);
  790. $(".schedulingHeaderContainer").css("margin-left", "100px");
  791. $(".schedulingRow").width($(".schedulingHeader").width() - 16);
  792. $(".schedulingCellContainer").width(containerWith);
  793. $(".schedulingCellContainer").height(containerHeight);
  794. $(".schedulingCellContainer").css("margin-left", ($(".schedulingCellHeader").width() + 2) + "px");
  795. $(".schedulingCellContainer").scroll(function () {
  796. $(".schedulingHeaderContainer").scrollLeft($(".schedulingCellContainer").scrollLeft());
  797. $(".schedulingCellHeaderContainer").scrollTop($(".schedulingCellContainer").scrollTop());
  798. });
  799. }
  800. function drawSchedulingData(container, schedulingData) {
  801. $.each(schedulingData, function () {
  802. var queryString = '.schedulingCell';
  803. queryString += '[coursesTimeID="' + this.CoursesTimeID + '"]';
  804. queryString += '[weekday="' + this.Weekday + '"]';
  805. var currentCell = container.find(queryString);
  806. drawSchedulingCellItem(currentCell, this);
  807. });
  808. }
  809. function drawSchedulingCellItem(cell, schedulingItem) {
  810. var html = new Array();
  811. var itemCount = cell.children('.schedulingItem').length;
  812. var eachWidth = cell.width() / (itemCount + 1);
  813. var tooltip = "";
  814. var text = "";
  815. var availableSchedulingClass = $("#dgEducationSchedulingClassList").cmsXDataTable("getRows");
  816. var isAvailable = true;
  817. if ($.grep(availableSchedulingClass, function (x) { return x.EducationSchedulingClassID == schedulingItem.EducationSchedulingClassID; }).length == 0) {
  818. isAvailable = false;
  819. }
  820. if (!schedulingItem.IsCanEdit) {
  821. isAvailable = false;
  822. }
  823. cell.children('.schedulingItem').width(eachWidth);
  824. html.push(cell.html());
  825. html.push('<div class="schedulingItem');
  826. if (!isAvailable) {
  827. html.push(' disabledItem');
  828. }
  829. html.push('" style="width: ' + eachWidth + 'px;" ClassroomID="' + schedulingItem.ClassroomID
  830. + '" ClassroomTypeID="' + schedulingItem.ClassroomTypeID
  831. + '" EducationSchedulingID="' + schedulingItem.EducationSchedulingID
  832. + '" CoursematerialID="' + schedulingItem.CoursematerialID
  833. + '" EducationSchedulingClassID="' + schedulingItem.EducationSchedulingClassID
  834. + '" WeeklyNums = "' + JSON.stringify(schedulingItem.WeekNumList)
  835. + '" StudentCount = "' + schedulingItem.StudentCount
  836. + '" TeachingModeID="' + schedulingItem.TeachingModeID
  837. + '" TeacherTeachingViewList="' + escape(JSON.stringify(schedulingItem.TeacherTeachingViewList))
  838. + '">');
  839. if (!schedulingItem.TeachingModeName || schedulingItem.TeachingModeName == "") {
  840. tooltip += schedulingItem.CoursematerialName;
  841. } else {
  842. tooltip += '【' + schedulingItem.TeachingModeName + '】' + schedulingItem.CoursematerialName;
  843. }
  844. tooltip += '(' + schedulingItem.TaskGroupName + ')';
  845. tooltip += '<br>';
  846. text = tooltip;
  847. if (schedulingItem.ClassroomName) {
  848. text += '<a href="#this" style="color: #0000ff" class="scheduleItemClassroomLink" onclick=showClassroomScheduleView("' + schedulingItem.ClassroomID + '");>'
  849. text += schedulingItem.ClassroomName;
  850. text += '</a>'
  851. tooltip += schedulingItem.ClassroomName;
  852. }
  853. text += ',';
  854. tooltip += ',';
  855. text += schedulingItem.WeeklyNumString;
  856. tooltip += schedulingItem.WeeklyNumString;
  857. text += '<br>';
  858. tooltip += '<br>';
  859. if (schedulingItem.TeacherNames) {
  860. tooltip += schedulingItem.TeacherNames;
  861. text += schedulingItem.TeracherNamesWithLink;
  862. }
  863. html.push('<div title="' + tooltip.replace(/<br>/g, " ") + '" class="schedulingItemTitle">');
  864. html.push(text);
  865. html.push('</div>');
  866. html.push('</div>');
  867. cell.html(html.join(''));
  868. setSchedulingItemUsed(schedulingItem);
  869. cell.children('.schedulingItem:not(.disabledItem)').click(function () {
  870. selectScheduleItem($(this));
  871. });
  872. cell.children('.schedulingItem').on('contextmenu', function (e) {
  873. e.preventDefault();
  874. var isDisable = false;
  875. if ($(this).hasClass('disabledItem')) {
  876. isDisable = true;
  877. }
  878. if (!isDisable) {
  879. selectScheduleItem($(this));
  880. } else {
  881. var selectedItems = $('.schedulingItemSelected');
  882. selectedItems.removeClass('schedulingItemSelected');
  883. }
  884. $("#popupMenu").css('display', 'block');
  885. if (!isDisable) {
  886. $("#popupMenu div:not(.commonMenu)").css('display', 'block');
  887. } else {
  888. $("#popupMenu div:not(.commonMenu)").css('display', 'none');
  889. }
  890. $("#popupMenu").offset({
  891. left: e.pageX,
  892. top: e.pageY
  893. });
  894. });
  895. }
  896. function selectScheduleItem(scheduleItem) {
  897. if ($(event.srcElement).hasClass("scheduleItemTeacherLink")) {
  898. return;
  899. }
  900. if ($(event.srcElement).hasClass("scheduleItemClassroomLink")) {
  901. return;
  902. }
  903. if (currentItem != null) return;
  904. var selectedItems = $('.schedulingItemSelected');
  905. selectedItems.removeClass('schedulingItemSelected');
  906. scheduleItem.addClass('schedulingItemSelected');
  907. }
  908. function setSchedulingItemUsed(schedulingItem) {
  909. var data = $("#dgEducationSchedulingClassList").cmsXDataTable("options").data.rows;
  910. var i;
  911. var allScheduled = $('.schedulingItem[EducationSchedulingClassID=' + schedulingItem.EducationSchedulingClassID + ']');
  912. var remainWeekNum = $.map(getScheduledItemRemainWeekNums(schedulingItem, allScheduled), function (x) { return x.Week });
  913. for (i = 0; i < data.length; i++) {
  914. if (data[i].EducationSchedulingClassID == schedulingItem.EducationSchedulingClassID) {
  915. if (remainWeekNum.length == 0) {
  916. $("#dgEducationSchedulingClassList").find('tr.row[xRowIndex=' + i + ']>td').addClass('finishedSchedulingClass');
  917. } else {
  918. $("#dgEducationSchedulingClassList").find('tr.row[xRowIndex=' + i + ']>td').addClass('usedSchedulingClass');
  919. }
  920. return;
  921. }
  922. }
  923. }
  924. function clearSchedulingItemUsed(schedulingItem) {
  925. var usedCells = $('.schedulingItem[EducationSchedulingClassID=' + schedulingItem.EducationSchedulingClassID + ']');
  926. var data = $("#dgEducationSchedulingClassList").cmsXDataTable("options").data.rows;
  927. var i;
  928. for (i = 0; i < data.length; i++) {
  929. if (data[i].EducationSchedulingClassID == schedulingItem.EducationSchedulingClassID) {
  930. $("#dgEducationSchedulingClassList").find('tr.row[xRowIndex=' + i + ']>td').removeClass('finishedSchedulingClass');
  931. if (usedCells.length == 0) {
  932. $("#dgEducationSchedulingClassList").find('tr.row[xRowIndex=' + i + ']>td').removeClass('usedSchedulingClass');
  933. }
  934. return;
  935. }
  936. }
  937. }
  938. function selectItem(rowIndex, rowData) {
  939. if (rowData.IsCanEdit) {
  940. if (currentItem != null && currentItem.EducationSchedulingClassID == rowData.EducationSchedulingClassID) {
  941. resetSelection();
  942. } else {
  943. $(this).find('tr.row>td').removeClass('selectedSchedulingClass');
  944. $(this).find('tr.row[xRowIndex=' + rowIndex + ']>td').addClass('selectedSchedulingClass');
  945. currentItem = rowData;
  946. }
  947. }
  948. }
  949. function EducationScheduling_Close() {
  950. top.$('#' + windowID).window('close');
  951. }
  952. function EducationScheduling_WeekModify() {
  953. var selectedItems = $('.schedulingItemSelected');
  954. if (selectedItems.length > 1) {
  955. $.messager.alert("系统提示", "不能同时操作多条记录。");
  956. return;
  957. }
  958. var educationSchedulingID = selectedItems.attr("EducationSchedulingID");
  959. var weekNums = eval(selectedItems.attr("WeeklyNums"));
  960. $.popupTopWindow('编辑上课周次', CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/WeekModify', 200, 500, popupClose, {
  961. EducationSchedulingID: educationSchedulingID,
  962. WeeklyNums: weekNums
  963. });
  964. }
  965. function popupClose() {
  966. if (top.$.data(this, "isSuccess")) {
  967. top.$.data(this, "isSuccess", false)
  968. reload();
  969. }
  970. }
  971. function EducationScheduling_ModifyTeacher() {
  972. var selectedItems = $('.schedulingItemSelected');
  973. if (selectedItems.length == 0) {
  974. $.messager.alert("系统提示", "请选择需要修改的排课记录。");
  975. return;
  976. }
  977. if (selectedItems.length > 1) {
  978. $.messager.alert("系统提示", "不能同时操作多条记录。");
  979. return;
  980. }
  981. var schoolYearID = $("#SchoolYearDropdown").combobox("getValue");
  982. var educationSchedulingID = selectedItems.attr('EducationSchedulingID');
  983. var redirectTo = CMS_SystemConfig.VirtualDirectoryPath + "/EducationSchedule/SetTeacher?EducationSchedulingID=" + educationSchedulingID
  984. + "&SchoolYearID=" + schoolYearID;
  985. $.popupTopWindow('设置教师', redirectTo, 800, 300, popupClose, null);
  986. }
  987. function EducationScheduling_ModifyClassroom() {
  988. var selectedItems = $('.schedulingItemSelected');
  989. if (selectedItems.length == 0) {
  990. $.messager.alert("系统提示", "请选择需要修改的排课记录。");
  991. return;
  992. }
  993. if (selectedItems.length > 1) {
  994. $.messager.alert("系统提示", "不能同时操作多条记录。");
  995. return;
  996. }
  997. var cell = selectedItems.parent(".schedulingCell");
  998. var schoolYearID = $("#SchoolYearDropdown").combobox("getValue");
  999. var collegeID = $("#CollegeDropdown").combobox("getValue");
  1000. var weekday = cell.attr("weekday");
  1001. var courseTimeID = cell.attr("coursesTimeID");
  1002. var classroomTypeID = selectedItems.attr("ClassroomTypeID");
  1003. var studentCount = selectedItems.attr("StudentCount");
  1004. var availableClassroomList = $.grep(usedClassroomList, function (x) { return x.weekday == weekday && x.courseTimeID == courseTimeID });
  1005. var weekNums = eval(selectedItems.attr("WeeklyNums"));
  1006. var courseTimeID = cell.attr("coursesTimeID");
  1007. $.popupTopWindow('选择教室', CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/Setting', 650, 320, modifyClassroom, {
  1008. schoolYearID: schoolYearID,
  1009. collegeID: collegeID,
  1010. weekday: weekday,
  1011. courseTimeID: courseTimeID,
  1012. classroomTypeID: classroomTypeID,
  1013. studentNum: studentCount,
  1014. schedulingWeekList: weekNums,
  1015. usedClassroomIDList: $.map(availableClassroomList, function (x) { return x.classroomID; })
  1016. });
  1017. }
  1018. function modifyClassroom(classroom) {
  1019. if (classroom) {
  1020. var selectedItems = $('.schedulingItemSelected');
  1021. var classroomID = classroom.ClassroomID;
  1022. var educationSchedulingID = selectedItems.attr('EducationSchedulingID');
  1023. $.post(CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/ChangeClassroom', { educationSchedulingID: educationSchedulingID, classroomID: classroomID }, function (data) {
  1024. if (!data.IsSuccess) {
  1025. $.messager.alert("系统提示", "修改教室失败:" + data.Message);
  1026. }
  1027. else {
  1028. reload();
  1029. }
  1030. });
  1031. }
  1032. }
  1033. function EducationScheduling_DeleteItem() {
  1034. var selectedItems = $('.schedulingItemSelected');
  1035. $.each(selectedItems, function (i, w) {
  1036. var cell = $(w).parent();
  1037. var itemCount = cell.children('.schedulingItem').length;
  1038. var eachWidth = cell.width() / (itemCount - 1);
  1039. var weekday = cell.attr("weekday");
  1040. var courseTimeID = selectedItems.parent().attr("coursesTimeID");
  1041. var workhours = parseInt(selectedItems.parent().attr("workhours"));
  1042. var schoolYearID = $("#SchoolYearDropdown").combobox("getValue");
  1043. var weekNums = eval($(w).attr("WeeklyNums"));
  1044. $.post(CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/DelScheduling', {
  1045. educationSchedulingID: $(w).attr('EducationSchedulingID')
  1046. }, function (data) {
  1047. if (!data.IsSuccess) {
  1048. $.messager.alert("系统提示", "删除失败:" + data.Message);
  1049. }
  1050. else {
  1051. usedClassroomList = $.grep(usedClassroomList, function (x) {
  1052. return !(x.weekday == weekday && x.courseTimeID == courseTimeID && x.classroomID == $(w).attr("ClassroomID"));
  1053. });
  1054. cell.children('.schedulingItem').width(eachWidth);
  1055. var classdata = $("#dgEducationSchedulingClassList").cmsXDataTable("options").data.rows;
  1056. var schedulingItem = $.grep(classdata, function (v) { return v.EducationSchedulingClassID == $(w).attr('EducationSchedulingClassID'); });
  1057. $(w).remove();
  1058. if (schedulingItem.length > 0) {
  1059. var listSchedulingClassList = $("#dgEducationSchedulingClassList").cmsXDataTable("getRows");
  1060. $.each(listSchedulingClassList, function () {
  1061. if (this.EducationSchedulingClassID == schedulingItem[0].EducationSchedulingClassID) {
  1062. this.RemainCourseTime += weekNums.length * workhours;
  1063. }
  1064. });
  1065. $("#dgEducationSchedulingClassList").cmsXDataTable("loadData", { rows: listSchedulingClassList, total: listSchedulingClassList.length });
  1066. clearSchedulingItemUsed(schedulingItem[0]);
  1067. }
  1068. }
  1069. });
  1070. });
  1071. }
  1072. function isScheduleEnable(rowIndex, rowData) {
  1073. if (!rowData.IsCanEdit) {
  1074. var rowObj = $("#dgEducationSchedulingClassList").find('tr.row[xRowIndex=' + rowIndex + ']');
  1075. return "color: #cccccc;";
  1076. } else {
  1077. return "";
  1078. }
  1079. }
  1080. function EducationSchedulingClass_SelectWeeks(rowIndex, rowData) {
  1081. if (rowData.IsCanEdit) {
  1082. $("#dgEducationSchedulingClassList").find('tr.row>td').removeClass('selectedSchedulingClass');
  1083. $("#dgEducationSchedulingClassList").find('tr.row[xRowIndex=' + rowIndex + ']>td').addClass('selectedSchedulingClass');
  1084. currentItem = rowData;
  1085. }
  1086. var allScheduled = $('.schedulingItem[EducationSchedulingClassID=' + currentItem.EducationSchedulingClassID + ']');
  1087. getScheduleItemWeekNums(rowData, allScheduled, true);
  1088. }
  1089. function preSelectWeek(weekListGroupData) {
  1090. if (!weekListGroupData) return;
  1091. var selectedWeekList = $.grep(weekListGroupData.weekList, function (x) {
  1092. return x.CourseProcessTeacherViewList.length == weekListGroupData.weekListGroup.CourseProcessTeacherViewList.length
  1093. && $.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(',')
  1094. && x.ClassroomTypeID == weekListGroupData.weekListGroup.ClassroomTypeID
  1095. && x.ClassroomID == weekListGroupData.weekListGroup.ClassroomID
  1096. && x.Times >= weekListGroupData.weekListGroup.Times
  1097. })
  1098. var selectedWeekNumList = $.map(selectedWeekList, function (x) { return x.Week; });
  1099. $.popupTopWindow('选择周次', CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/PreSelectWeeks', 200, 500, preSelectWeekConfirm, selectedWeekNumList);
  1100. }
  1101. function preSelectWeekConfirm(selectedWeekList) {
  1102. schedulingClassSelectedWeekList[currentItem.EducationSchedulingClassID] = selectedWeekList;
  1103. }
  1104. (function ($) {
  1105. $('.easyui-menu').menu('hide');
  1106. $(document).keydown(function (e) {
  1107. if (e.keyCode == 46) {
  1108. EducationScheduling_DeleteItem();
  1109. }
  1110. });
  1111. $(document).on('contextmenu', function (e) {
  1112. $("#popupMenu").css('display', 'block');
  1113. if ($(e.srcElement).parent().hasClass("row") && !$(e.srcElement).hasClass("finishedSchedulingClass")) {
  1114. var rowIndex = parseInt($(e.srcElement).parent().attr("xRowIndex"));
  1115. var rowData = $("#dgEducationSchedulingClassList").cmsXDataTable("getRows")[rowIndex];
  1116. if (rowData.IsCanEdit) {
  1117. $("#popupMenu div").css('display', 'none');
  1118. $("#popupMenu div.schedulingClassMenu").css('display', 'block');
  1119. $("#popupMenu div.commonMenu").css('display', 'block');
  1120. $("#popupMenu div.editWeek").unbind();
  1121. $("#popupMenu div.editWeek").click(function () {
  1122. EducationSchedulingClass_SelectWeeks(rowIndex, rowData);
  1123. $('#popupMenu').css('display', 'none');
  1124. });
  1125. } else {
  1126. $("#popupMenu div:not(.commonMenu)").css('display', 'none');
  1127. }
  1128. $("#popupMenu").offset({
  1129. left: e.pageX,
  1130. top: e.pageY
  1131. });
  1132. } else if (!$(e.srcElement).parents().hasClass('schedulingItem') && !$(e.srcElement).parents().hasClass("row") && !$(e.srcElement).hasClass('scheduleMenu')) {
  1133. $("#popupMenu div:not(.commonMenu)").css('display', 'none');
  1134. $("#popupMenu").offset({
  1135. left: e.pageX,
  1136. top: e.pageY
  1137. });
  1138. } else {
  1139. $("#popupMenu div.schedulingClassMenu").css('display', 'none');
  1140. $("#popupMenu").offset({
  1141. left: e.pageX,
  1142. top: e.pageY
  1143. });
  1144. }
  1145. e.preventDefault();
  1146. });
  1147. $(document).click(function () {
  1148. $("#popupMenu").css('display', 'none');
  1149. });
  1150. })(jQuery);