var mnu; var time; var isSave = false; var isSubmit = false; var isWindowCanClose = false; $.parser.onComplete = function () { var tableContainer = $("#dgScoreDetailList").find(".xDataTable").parent(); var maxHeight = parseInt(tableContainer.css("maxHeight").replace("px", "")); tableContainer.css("maxHeight", maxHeight - $("#Comment").parent().outerHeight() - 20 + "px"); }; $(function () { mnu = $.SystemGeneral.getUrlParam("MNU"); var Isdisplay = $.SystemGeneral.getUrlParam("Isdisplay"); if (Isdisplay == "" || Isdisplay == null) { top.ScoreEditSetInterval = top.setInterval(setTimeout_Save, 1800000); } if (ApprovalStatus == 2 || ApprovalStatus == 4 || ApprovalStatus == 6) { isWindowCanClose = true; } $(document).keydown(function (e) { var keyEv = e || window.event; if (![37, 38, 39, 40].contains(keyEv.keyCode)) return; var source = keyEv.srcElement || keyEv.target; if (!$(source).hasClass('validatebox-text')) return; if (!$(source).parent().attr('columnIndex')) return; if (!$(source).parent().parent().attr('xRowIndex')) return; var allRange = source.createTextRange(); var columnIndex = parseInt($(source).parent().attr('columnIndex')); var rowIndex = parseInt($(source).parent().parent().attr('xRowIndex')); switch (keyEv.keyCode) { //Left Arrow case 37: if (document.selection.createRange().compareEndPoints('StartToStart', allRange) > 0) { return; } columnIndex--; break; //Up Arrow case 38: rowIndex--; break; //Right Arrow case 39: if (document.selection.createRange().compareEndPoints('EndToEnd', allRange) < 0) { return; } columnIndex++; break; //Dw Arrow case 40: rowIndex++; break; } var row = $("#dgScoreDetailList").find("[xRowIndex='" + rowIndex + "']"); if (row.length > 0) { var column = row.find("[columnIndex='" + columnIndex + "']"); if (column.length > 0) { var textbox = column.find('.validatebox-text'); if (textbox.length > 0) { textbox.focus(); } } } }); }); //获取选中的数据 function validChoose() { var d = []; $.each($("#dgScoreDetailList").cmsXDataTable("getSelections"), function (index) { d.push(this); }); return d; } function reload() { $("#dgScoreDetailList").cmsXDataTable("load", $.getDataGridParams("dgScoreDetailList")); } function getCustomScoreFormular(scoreTypes) { var result = new Array(); var customScoreFormula = eval("(" + $("[name='CustomScoreFormula']").val() + ")"); var scoreTypesCount = scoreTypes.length; //将各种组合先塞到result数组中 $.each(scoreTypes, function (n, scoreType) { $.each($.grep(customScoreFormula, function (x) { return x.ScoreType == scoreType }), function (i, scoreFormula) { //找已有数组中有自己同伴的,复制出来把同伴换成自己,增加新数组 var mateResultList = $.grep(result, function (x) { return $.grep(x.Detail, function (w) { return w.ScoreType == scoreFormula.ScoreType; }).length > 0 }); $.each(mateResultList, function (m, mateResult) { var item = { total: 0, order: 1, Detail: $.grep(mateResult.Detail, function (x) { return x.ScoreType != scoreFormula.ScoreType; }) }; item.Detail.push(scoreFormula); item.order = scoreTypesCount - item.Detail.length; $.each(item.Detail, function (v, x) { item.total += x.Percentage; }); result.push(item); }); //如果已有数组中没有同伴(一个新的ID出现,肯定是没有同伴的),则 //遍历已有数组,把自己加进去 //增加以自己为起点的数组 if (mateResultList.length == 0) { $.each(result, function (i, x) { x.total += scoreFormula.Percentage; x.Detail.push(scoreFormula); x.order = scoreTypesCount - x.Detail.length; }); var item = { total: scoreFormula.Percentage, order: scoreTypesCount - 1, Detail: [scoreFormula] }; result.push(item); } }); }); //找出总和是100的组合并返回 var correctResult = $.grep(result, function (x) { return x.total == 100 }).sort(function (a, b) { return a.order - b.order; }); if (correctResult.length > 0) { return correctResult[0].Detail; } else { return new Array(); } } function getResultType() { var ResultTypeDetail = new Array(); var ResultType = eval("(" + $("[name='ResultType']").val() + ")"); if (ResultType.length > 0) { ResultTypeDetail = $.map(ResultType, function (x) { return { Name: x.Name, MinScore: x.MinScore, MaxScore: x.MaxScore, MinScoreOperator: x.MinScoreOperator, MaxScoreOperator: x.MaxScoreOperator, Score: x.Score }; }); } else { ResultTypeDetail = null; } return ResultTypeDetail; } function getScoreFormulaDetail(scoreDetailList) { var scoreFormulaDetail = new Array(); var scoreFormulaDropdownList = $("#ScoreFormulaID").combobox("getValue"); var scoreFormula = eval("(" + scoreFormulaDropdownList + ")"); //如果有自定义公式(广体那种),就拿自定义公式,否则就按选择的来 var customScoreFormula = eval("(" + $("[name='CustomScoreFormula']").val() + ")"); if (customScoreFormula.length > 0) { //获取有填写的分数类型 var allScoreTypeList = $.map(customScoreFormula, function (x) { return x.ScoreType; }).unique(); var notEmptyScoreTypes = new Array(); $.each(scoreDetailList, function (i, scoreDetail) { $.each(allScoreTypeList, function (n, scoreType) { if (!(scoreDetail.ScoreDetail[scoreType].Score === "" || scoreDetail.ScoreDetail[scoreType].Score == null)) { if (!notEmptyScoreTypes.contains(scoreType)) { notEmptyScoreTypes.push(scoreType); } } }); }); //获取对应的总分公式 scoreFormulaDetail = $.map(getCustomScoreFormular(notEmptyScoreTypes), function (x) { return { ScoreType: x.ScoreType, Percentage: x.Percentage, IsRequirePass: x.IsRequirePass, PassScore: x.PassScore }; }); } else { scoreFormulaDetail = $.map(scoreFormula.ScoreFormulaDetail, function (x) { return { ScoreType: x.ScoreType, Percentage: x.Percentage, IsRequirePass: x.IsRequirePass, PassScore: x.PassScore }; }); } return scoreFormulaDetail; } function getSpecialStateScore(examsStateID, originalScore) { var examStateSettingList = eval("(" + $("#ExamsStateSetting").val() + ")"); var examStateSetting = $.grep(examStateSettingList, function (x) { return x.ExamsStateID == examsStateID }).shift(); if (examStateSetting) { if (examStateSetting.Score) { return examStateSetting.Score; } else { return originalScore; } } return originalScore; } function Score_Calculate() { var creditFormulaDropdownList = $("#CreditFormulaID").combobox("getValue"); var gradePointFormulaDropdownList = $("#GradePointFormulaID").combobox("getValue"); var scoreDetailList = $("#dgScoreDetailList").cmsXDataTable("getRows"); var creditFormula = eval("(" + creditFormulaDropdownList + ")"); var gradePointFormula = eval("(" + gradePointFormulaDropdownList + ")"); //根据目前填写情况获取总分公式 var scoreFormulaDetail = getScoreFormulaDetail(scoreDetailList); var ResultType = new Array(); var defeat = 0; ResultType = getResultType(); // if (scoreFormulaDetail.length <= 0) { // return false; // } $.each(scoreDetailList, function (index, value) { //如果当前行不可编辑(重录时的非重录学生),跳过 if (!value.RecordStatus) { return true; } //如果当前行不可编辑(成绩认定的学生),跳过 if (!value.IsCanEdit) { return true; } if (value.RecordStatus <= unusableStatusID) { return true; } var examsStateID = null; if (value.ExamsStateID != null) { examsStateID = parseInt(value.ExamsStateID); } //如果考试状态不为正常考试,总分清零,跳过 if (examsStateID == suspensionStateID || misconductStateIDList.contains(examsStateID)) { value.TotalScore = getSpecialStateScore(examsStateID, 0); value.Credit = 0; value.GradePoint = 0; return true; } //如果当前行是空行,则跳过 if (examsStateID != exemptionStateID) { var isEmpty = true; for (var scoreType in value.ScoreDetail) { //判断空行时,单独管理的成绩不算填了值,因为不是用户填的 if (scoreType == fixedScoreTypeID) { continue; } if (!(value.ScoreDetail[scoreType].Score === "" || value.ScoreDetail[scoreType].Score == null)) { isEmpty = false; } } if (isEmpty) { value.TotalScore = null; value.Credit = null; value.GradePoint = null; return true; } } //算总分 var totalScore = 0; var needPassFailed = false; if (examsStateID == exemptionStateID) { value.TotalScore = getSpecialStateScore(examsStateID, 0); } else { if (scoreFormulaDetail.length > 0) { $.each(scoreFormulaDetail, function (i, x) { if (value.ScoreDetail[x.ScoreType]) { if (!(value.ScoreDetail[x.ScoreType].Score === "" || value.ScoreDetail[x.ScoreType].Score == null)) { totalScore += value.ScoreDetail[x.ScoreType].Score * x.Percentage / 100; if (x.IsRequirePass && x.PassScore != null) { if (value.ScoreDetail[x.ScoreType].Score < x.PassScore) { needPassFailed = true; } } } else if (x.IsRequirePass) { needPassFailed = true; } if (isSubmit && (value.ScoreDetail[x.ScoreType].Score === "" || value.ScoreDetail[x.ScoreType].Score == null)) { defeat++; return; } } else if (x.IsRequirePass) { needPassFailed = true; } }); } else if (isSubmit) { defeat++; return; } if (needPassFailed) { totalScore = 0; value.TotalScore = 0; } else { //toFixed方法有问题,对小于1的数字计算不正确,所以运算前先加1确保没问题 value.TotalScore = totalScore.toFixed(scoreDigitCount); } } //分制转化 if (ResultType != null) { $.each(ResultType, function (i, x) { if (x.MinScore <= totalScore && totalScore <= x.MaxScore && x.MinScoreOperator == "<=" && x.MaxScoreOperator == "<=") { value.TotalScore = x.Score; } if (x.MinScore < totalScore && totalScore <= x.MaxScore && x.MinScoreOperator == "<" && x.MaxScoreOperator == "<=") { value.TotalScore = x.Score; } if (x.MinScore < totalScore && totalScore < x.MaxScore && x.MinScoreOperator == "<" && x.MaxScoreOperator == "<") { value.TotalScore = x.Score; } if (x.MinScore <= totalScore && totalScore < x.MaxScore && x.MinScoreOperator == "<=" && x.MaxScoreOperator == "<") { value.TotalScore = x.Score; } }); } //算学分 //免修是不需要计算,直接获得学分的 if (examsStateID == exemptionStateID) { value.Credit = credit; } else { if (value.TotalScore >= creditFormula.Scores) { value.Credit = credit; } else { value.Credit = 0; } } //算绩点 if (value.TotalScore >= gradePointFormula.GradePointlimit) { var gradePoint = 1; gradePoint += (value.TotalScore - gradePointFormula.GradePointlimit) * gradePointFormula.GradePointFloor; value.GradePoint = gradePoint.toFixed(1); } else { value.GradePoint = 0; } }); if (defeat > 0 && isSubmit) { return false; } // if (defeat > 0 && !isSave && !isSubmit) { // $.messager.alert("系统提示", "录入信息不完整"); // return; // } $("#dgScoreDetailList").cmsXDataTable("loadData", { rows: scoreDetailList, total: scoreDetailList.length }); } //提交 function Score_Submit() { var msg = ""; var scoreDetailList = $("#dgScoreDetailList").cmsXDataTable("getRows"); var scoreFormulaDetail = getScoreFormulaDetail(scoreDetailList); var requireScoreTypes = $.map(scoreFormulaDetail, function (x) { return x.ScoreType; }); isSubmit = true; isSave = false; //Score_Calculate(); var isOk = Score_Calculate(); if (!isOk && isOk != null) { $.messager.alert("系统提示", "录入信息不完整。"); return; } else { $.each(scoreDetailList, function (index, value) { if (value.ExamsStateID == null) { msg = "请选择考试状态!" return false; } }); if (scoreDetailList.length == 0) { $.messager.alert("系统提示", "录入学生数不能为0"); return } if (msg != "") { $.messager.alert("系统提示", msg); return; } $(document.forms[0]).attr("action", CMS_SystemConfig.VirtualDirectoryPath + '/Score/Submit'); $(document.forms[0]).submit(); isWindowCanClose = true; } } //保存 function Score_Save() { isSubmit = false; isSave = true; commonSave(); } function commonSave() { Score_Calculate(); //计算 $(document.forms[0]).attr("action", CMS_SystemConfig.VirtualDirectoryPath + '/Score/ScoreSave'); $(document.forms[0]).submit(); isWindowCanClose = true; } //定时保存 function setTimeout_Save() { isSubmit = false; isSave = false; commonSave(); } //重置 function Score_Resetting() { var scoreDetailList = $("#dgScoreDetailList").cmsXDataTable("getRows"); $.each(scoreDetailList, function (index, value) { //如果当前行不可编辑(重录时的非重录学生),跳过 if (!value.RecordStatus) { return true; } //如果当前行不可编辑(成绩认定的学生),跳过 if (!value.IsCanEdit) { return true; } if (value.RecordStatus <= unusableStatusID) { return true; } $.each(value.ScoreDetail, function (i, score) { score.Score = null; }); value.TotalScore = null; value.Credit = null; value.GradePoint = null; }); $("#dgScoreDetailList").cmsXDataTable("loadData", { rows: scoreDetailList, total: scoreDetailList.length }); } //成绩导入 function Score_Import() { var finalExaminationID = $("#FinalExaminationID").val(); var redirectTo = CMS_SystemConfig.VirtualDirectoryPath + '/Score/Import?finalExaminationID=' + finalExaminationID + '&MNU=' + mnu; $.popupTopWindow('学生成绩导入', redirectTo, 400, 300, ScoreImportComplete); } function ScoreImportComplete(data) { if (data != null) { var scoreViewList = $("#dgScoreDetailList").cmsXDataTable("getRows"); $.each(scoreViewList, function (i, x) { if (x.IsCanEdit == true) { var importedScore = $.grep(data, function (w) { return w.UserID == x.UserID }).pop(); if (importedScore) { $.each(x.ScoreDetail, function (n, v) { if (v.IsCanEdit == true) { var score = importedScore.ScoreDetail[v.ScoreTypeID]; v.Score = score; } }); } } }); $("#dgScoreDetailList").cmsXDataTable("loadData", { rows: scoreViewList, total: scoreViewList.length }); Score_Calculate(); } } function FormSuecess(data) { if (isSubmit) { EMISFunction.FormSuccess(data); } else if (isSave) { $.messager.alert("系统提示", data.Message); } } function FormSubmit(formID) { if (isSubmit || isSave) { EMISFunction.FormSubmit(formID); } else { $('a').attr('disabled', 'disabled'); $.each($('a'), function () { if ($.data(this, "linkbutton")) { $(this).linkbutton('disable'); } }); $('#autoSave').show(); } } function FormComplete() { if (isSubmit || isSave) { EMISFunction.FormComplete(); } else { $.each($('a'), function () { if ($.data(this, "linkbutton")) { $(this).linkbutton('enable'); } }); $('a').removeAttr('disabled', 'disabled'); $('#autoSave').hide(); } } function formSuccessReloadNoClose(data) { if (data.IsSuccess == true) { if (data.Message == "提交成功。" || data.Message == "保存成功。") { $.messager.alert("系统提示", data.Message, null, function () { location.reload(); }); } } else { $.messager.alert("系统提示", data.Message); } } // if (data.IsSuccess == true) { // $.messager.alert("系统提示", data.Message); // location.reload(); // //isWindowCanClose = true; // } // else { // $.messager.alert("系统提示", data.Message); // } function LoginIDColor(index, row, value) { if (row.IsDifferentDynamic == true) { return " " + value + ""; } else { return value } } function UserNameColor(index, row, value) { if (row.IsDifferentDynamic == true) { return " " + value + ""; } else { return value } } function ExamsCategoryNameColor(index, row, value) { if (row.IsDifferentDynamic == true) { return " " + value + ""; } else { return value } } function TotalScoreColor(index, row, value) { var ResultType = new Array(); ResultType = getResultType(); if (row.IsDifferentDynamic == true) { if (ResultType != null) { var valueName = ""; $.each(ResultType, function (i, x) { if (value !== "" && value != null) { if (x.MinScore <= value && value <= x.MaxScore && x.MinScoreOperator == "<=" && x.MaxScoreOperator == "<=") { valueName = " " + x.Name + ""; } if (x.MinScore < value && value <= x.MaxScore && x.MinScoreOperator == "<" && x.MaxScoreOperator == "<=") { valueName = " " + x.Name + ""; } if (x.MinScore < value && value < x.MaxScore && x.MinScoreOperator == "<" && x.MaxScoreOperator == "<") { valueName = " " + x.Name + ""; } if (x.MinScore <= value && value < x.MaxScore && x.MinScoreOperator == "<=" && x.MaxScoreOperator == "<") { valueName = " " + x.Name + ""; } } }); return valueName; } else { return " " + value + ""; } } else { if (ResultType != null) { var valueName = ""; $.each(ResultType, function (i, x) { if (value !== "" && value != null) { if (x.MinScore <= value && value <= x.MaxScore && x.MinScoreOperator == "<=" && x.MaxScoreOperator == "<=") { valueName = x.Name; } if (x.MinScore < value && value <= x.MaxScore && x.MinScoreOperator == "<" && x.MaxScoreOperator == "<=") { valueName = x.Name; } if (x.MinScore < value && value < x.MaxScore && x.MinScoreOperator == "<" && x.MaxScoreOperator == "<") { valueName = x.Name; } if (x.MinScore <= value && value < x.MaxScore && x.MinScoreOperator == "<=" && x.MaxScoreOperator == "<") { valueName = x.Name; } } }); return valueName; } else { return value; } } } function Score_Report() { var FinalExaminationID = $("#FinalExaminationID").val(); var redirectTo = CMS_SystemConfig.VirtualDirectoryPath + "/Score/Report?FinalExaminationID=" + FinalExaminationID + "&MNU=" + mnu; $.popupTopWindow('学生课程成绩报表', redirectTo, 800, 600, null, null); } function CreditColor(index, row, value) { if (row.IsDifferentDynamic == true) { return " " + value + ""; } else { return value } } function GradePointColor(index, row, value) { if (row.IsDifferentDynamic == true) { return " " + value + ""; } else { return value } } function Score_SetScoreBySOCScore() { var FinalExaminationID = $("#FinalExaminationID").val(); var scoreDetailList = $("#dgScoreDetailList").cmsXDataTable("getRows"); $.messager.confirm("系统提示", "同步SOC成绩后将覆盖当前已录的考试成绩,是否需要同步?", function (r) { if (r) { $.postWithLoading(CMS_SystemConfig.VirtualDirectoryPath + '/Score/SetScoreBySOCScore', { finalExaminationID: FinalExaminationID }, function (res) { $.messager.alert("系统提示", res.Message); if (res.IsSuccess) { if (res.Data.length > 0) { for (var i = 0; i < res.Data.length; i++) { $.each(scoreDetailList, function (index, value) { if (res.Data[i].UserID == value.UserID) { $.each(value.ScoreDetail, function (ind, score) { if (ind == 3) { score.Score = res.Data[i].TotalScore; } }); //value.Score = res.Data[i].TotalScore; } }); } $("#dgScoreDetailList").cmsXDataTable("loadData", { rows: scoreDetailList, total: scoreDetailList.length }); } } }); } }); }