AddClassroomLayout.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. var examinationPlanID;
  2. var examinationRoomLayoutID;
  3. var availableSeatCount;
  4. var totalSeat;
  5. var rowCount;
  6. var columnCount;
  7. $(function () {
  8. examinationPlanID = $.SystemGeneral.getUrlParam("ExaminationPlanID");
  9. examinationRoomLayoutID = $.SystemGeneral.getUrlParam("ExaminationRoomLayoutID");
  10. });
  11. function ExaminationPlan_ClassroomLayoutSave() {
  12. // if (!calculateSeatCount()) {
  13. // return;
  14. // }
  15. // var curStudentCount = $("#dgStudent").cmsXDataTable("getRows").length;
  16. // if (availableSeatCount < curStudentCount) {
  17. // $.messager.alert("系统提示", "教室只能容纳" + availableSeatCount + "人,目前选中了" + curStudentCount + "个学生,请先删除多出的学生后再保存。");
  18. // return;
  19. // } else {
  20. // $(document.forms[0]).submit();
  21. // }
  22. $(document.forms[0]).submit();
  23. var d = [];
  24. var windowID = $.SystemGeneral.getUrlParam("WindowID");
  25. var maxSelect = $.SystemGeneral.getUrlParam("MaxSelect");
  26. if (!maxSelect || isNaN(maxSelect)) maxSelect = 0;
  27. if (d.length == 0) {
  28. $.messager.alert("系统提示", "请选择教师。");
  29. return;
  30. }
  31. if (maxSelect > 0 && d.length > maxSelect) {
  32. $.messager.alert("系统提示", "只能选择" + maxSelect + "项记录。");
  33. return;
  34. }
  35. top.$("#" + windowID).data("resultData", d);
  36. top.$("#" + windowID).dialog("close");
  37. }
  38. function ExaminationPlan_TeacherAdd() {
  39. var classroomID = $("#ClassroomID").combogridX("getValue");
  40. if (classroomID == "" || classroomID == nonSelect) {
  41. $.messager.alert("系统提示", "请先选择考场再选择监考老师。");
  42. return;
  43. }
  44. $.popupTopWindow('新增监考老师', CMS_SystemConfig.VirtualDirectoryPath + '/ExaminationTeacher/ExaminationAddTeacherSelect?classroomID=' + classroomID, 800, 600, ExaminationPlan_TeacherAdd_Confirm);
  45. }
  46. function ExaminationPlan_TeacherAdd_Confirm(teacherList) {
  47. if (!teacherList) return;
  48. var examinationTeacherList = $("#dgRoomTeacher").cmsXDataTable("getRows");
  49. $.each(teacherList, function () {
  50. var curUserID = this.UserID;
  51. if ($.grep(examinationTeacherList, function (x) { return x.UserID == curUserID }).length == 0) {
  52. examinationTeacherList.push(this);
  53. }
  54. });
  55. $("#dgRoomTeacher").cmsXDataTable("loadData", { rows: examinationTeacherList, total: examinationTeacherList.length });
  56. }
  57. //获取选中的数据
  58. function validChooseTeacher() {
  59. var d = [];
  60. $.each($("#dgRoomTeacher").cmsXDataTable("getSelections"), function (index) {
  61. d.push(this.UserID);
  62. });
  63. return d;
  64. }
  65. function validChooseStudent() {
  66. var d = [];
  67. $.each($("#dgStudent").cmsXDataTable("getSelections"), function (index) {
  68. d.push(this.UserID);
  69. });
  70. return d;
  71. }
  72. function ExaminationPlan_TeacherDelete() {
  73. var d = validChooseTeacher();
  74. var teacherViewList = $("#dgRoomTeacher").cmsXDataTable("getRows");
  75. var i, j;
  76. var len = teacherViewList.length;
  77. for (i = len - 1; i >= 0; i--) {
  78. for (j = 0; j < d.length; j++) {
  79. if (teacherViewList[i].UserID == d[j]) {
  80. teacherViewList.splice(i, 1);
  81. break;
  82. }
  83. }
  84. }
  85. $("#dgRoomTeacher").cmsXDataTable("loadData", { rows: teacherViewList, total: teacherViewList.length });
  86. }
  87. function ClassroomSelected(data) {
  88. totalSeat = data.Totalseating;
  89. rowCount = data.RowCout;
  90. columnCount = data.ColumnCount;
  91. availableSeatCount = data.RemainSeatCount;
  92. }
  93. function Classroom_LoadSuccess(data) {
  94. var classroomID = $("#ClassroomID").combogridX("options").value;
  95. var curClassroom = $.grep(data.rows, function (x) { return x.ClassroomID == classroomID; });
  96. if (curClassroom.length > 0) {
  97. ClassroomSelected(curClassroom[0]);
  98. }
  99. }
  100. function calculateSeatCount() {
  101. if (!$(document.forms[0]).valid()) return false;
  102. if (!rowCount || !columnCount) {
  103. $.messager.alert("系统提示", "选中的教室还没有设置正确的行列数,请通知负责教室管理的老师进行设置。");
  104. return false;
  105. }
  106. var rowSpacing = parseFloat($("input[name='RowSpacing']").val());
  107. var columnSpacing = parseFloat($("input[name='ColumnSpacing']").val());
  108. //availableSeatCount = Math.ceil(columnCount / (columnSpacing + 1)) * Math.ceil(rowCount / (rowSpacing + 1));
  109. // availableSeatCount = 0;
  110. // if (rowSpacing > 0) {
  111. // availableSeatCount = Math.ceil(columnCount / (columnSpacing + 1));
  112. // for (var i = 0; i < Math.floor(rowCount / (rowSpacing + 1)); i++) {
  113. // for (var j = 0; j < (rowSpacing + 1); j++) {
  114. // if (i * 2 * rowSpacing + j + 1 > rowCount) break;
  115. // if (j < rowSpacing)
  116. // availableSeatCount += Math.ceil((columnCount - j - 1) / (columnSpacing + 1))
  117. // else
  118. // availableSeatCount += Math.ceil((columnCount - (rowSpacing * 2 - j - 1)) / (columnSpacing + 1))
  119. // }
  120. // }
  121. // } else {
  122. // availableSeatCount = Math.ceil(columnCount / (columnSpacing + 1)) * rowCount;
  123. // }
  124. return true;
  125. }
  126. function ExaminationPlan_StudentAdd() {
  127. if (!calculateSeatCount()) {
  128. return;
  129. }
  130. var curStudentCount = $("#dgStudent").cmsXDataTable("getRows").length;
  131. var studentOrderType = $("#StudentOrderType").combobox('getValue');
  132. $.popupTopWindow('添加学生', CMS_SystemConfig.VirtualDirectoryPath + '/ExaminationPlan/AddStudentSelect', 800, 600, ExaminationPlan_StudentAdd_Confirm, { limit: availableSeatCount - curStudentCount, studentOrderType: studentOrderType });
  133. //, examinationPlanID: examinationPlanID
  134. }
  135. function ExaminationPlan_StudentAdd_Confirm(studentList) {
  136. if (!studentList) return;
  137. var studentOrderType = $("#StudentOrderType").combobox('getValue');
  138. var studentViewList = $("#dgStudent").cmsXDataTable("getRows");
  139. var newStudentViewList = $.map(
  140. $.grep(studentList, function (x) { return $.grep(studentViewList, function (y) { return y.UserID == x.UserID; }).length == 0; }),
  141. function (x) {
  142. return {
  143. ExaminationRoomStudentID: Guid.NewGuid().ToString(),
  144. ExaminationRoomLayoutID: examinationRoomLayoutID,
  145. UserID: x.UserID,
  146. LoginID: x.LoginID,
  147. Name: x.UserName,
  148. Row: null,
  149. Column: null,
  150. Remark: '',
  151. RecordStatus: null,
  152. CreateTime: null,
  153. CreateUserID: null,
  154. ModifyUserID: null,
  155. ModifyTime: null
  156. };
  157. }
  158. ).concat(
  159. studentViewList
  160. ).sort(function (a, b) {
  161. if (studentOrderType == "2") {
  162. return a.LoginID - b.LoginID;
  163. } else {
  164. return 1;
  165. }
  166. });
  167. $("#dgStudent").cmsXDataTable("loadData", { rows: newStudentViewList, total: newStudentViewList.length });
  168. }
  169. function ExaminationPlan_StudentDelete() {
  170. var d = validChooseStudent();
  171. var studentViewList = $("#dgStudent").cmsXDataTable("getRows");
  172. var i, j;
  173. var len = studentViewList.length;
  174. for (i = len - 1; i >= 0; i--) {
  175. for (j = 0; j < d.length; j++) {
  176. if (studentViewList[i].UserID == d[j]) {
  177. studentViewList.splice(i, 1);
  178. break;
  179. }
  180. }
  181. }
  182. $("#dgStudent").cmsXDataTable("loadData", { rows: studentViewList, total: studentViewList.length });
  183. }