diff --git a/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/EducationalAdministration/Controllers/StuScoreController.cs b/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/EducationalAdministration/Controllers/StuScoreController.cs index 7a2712595..9cb5eec38 100644 --- a/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/EducationalAdministration/Controllers/StuScoreController.cs +++ b/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/EducationalAdministration/Controllers/StuScoreController.cs @@ -1,4 +1,5 @@ using Hangfire; +using Learun.Application.Base.SystemModule; using Learun.Application.Organization; using Learun.Application.TwoDevelopment.EducationalAdministration; using Learun.Util; @@ -27,6 +28,8 @@ namespace Learun.Application.Web.Areas.EducationalAdministration.Controllers private CdMajorIBLL cdMajorIBLL = new CdMajorBLL(); private UserIBLL userIBLL = new UserBLL(); private EADateArrangeIBLL eADateArrangeIBLL = new EADateArrangeBLL(); + private AnnexesFileIBLL annexesFileIBLL = new AnnexesFileBLL(); + #region 视图功能 @@ -249,6 +252,18 @@ namespace Learun.Application.Web.Areas.EducationalAdministration.Controllers ViewBag.WebApi = ConfigurationManager.AppSettings["WebApi"]; return View(); } + + + /// + /// 成绩录入导入 + /// + /// + [HttpGet] + public ActionResult InputScoreIndexInTeacherImport() + { + return View(); + } + #endregion #region 获取数据 @@ -581,7 +596,7 @@ namespace Learun.Application.Web.Areas.EducationalAdministration.Controllers { var loginInfo = LoginUserInfo.Get(); var semesterAndYear = Common.GetSemesterAndYear(); - var data = stuScoreIBLL.GetLessonNoDataOfAll(loginInfo.account, loginInfo.Description,semesterAndYear.AcademicYearShort,semesterAndYear.Semester); + var data = stuScoreIBLL.GetLessonNoDataOfAll(loginInfo.account, loginInfo.Description, semesterAndYear.AcademicYearShort, semesterAndYear.Semester); foreach (var item in data) { item.text = string.Format("{0}({1})", item.text, item.value); @@ -795,9 +810,9 @@ namespace Learun.Application.Web.Areas.EducationalAdministration.Controllers var data = stuScoreIBLL.GetScoreListByStuInfo(queryJson); if (data.Any()) { - data = data.OrderByDescending(x => x.AcademicYearNo).ThenByDescending(x => x.Semester).ThenBy(x=>x.LessonSortNo).ThenBy(x => x.LessonNo); + data = data.OrderByDescending(x => x.AcademicYearNo).ThenByDescending(x => x.Semester).ThenBy(x => x.LessonSortNo).ThenBy(x => x.LessonNo); } - + return Success(data); } @@ -1131,6 +1146,89 @@ namespace Learun.Application.Web.Areas.EducationalAdministration.Controllers return Success("操作成功"); } + #endregion + + #region 成绩录入--导入 + /// + /// 成绩导入---下载导入模板 + /// + /// + /// 表头 + /// 列表数据 + [HttpPost, ValidateInput(false)] + public void ExportExcel(string fileName, string columnJson, string dataJson) + { + //设置导出格式 + ExcelConfig excelconfig = new ExcelConfig(); + //excelconfig.Title = Server.UrlDecode(fileName); + excelconfig.TitleFont = "微软雅黑"; + excelconfig.TitlePoint = 15; + excelconfig.FileName = Server.UrlDecode(fileName) + ".xls"; + excelconfig.IsAllSizeColumn = true; + excelconfig.ColumnEntity = new List(); + //表头 + List columnList = columnJson.ToList(); + //行数据 + DataTable rowData = dataJson.ToTable(); + ////写入Excel表头 + //Dictionary exportFieldMap = new Dictionary(); + //if (!string.IsNullOrEmpty(exportField)) + //{ + // string[] exportFields = exportField.Split(','); + // foreach (var field in exportFields) + // { + // if (!exportFieldMap.ContainsKey(field)) + // { + // exportFieldMap.Add(field, "1"); + // } + // } + //} + + foreach (jfGridModel columnModel in columnList) + { + //if (exportFieldMap.ContainsKey(columnModel.name) || string.IsNullOrEmpty(exportField)) + //{ + excelconfig.ColumnEntity.Add(new ColumnModel() + { + Column = columnModel.name, + ExcelColumn = columnModel.label, + Alignment = columnModel.align, + }); + + // } + } + ExcelHelper.ExcelDownload(rowData, excelconfig); + } + + /// + /// 成绩导入 + /// + /// + [HttpPost] + [ValidateAntiForgeryToken] + public ActionResult ExecuteImportExcel(string fileGuid, int chunks, string queryJson) + { + string path = annexesFileIBLL.SaveAnnexes(fileGuid, fileGuid, chunks, LoginUserInfo.Get()); + if (!string.IsNullOrEmpty(path)) + { + DataTable dt = ExcelHelper.ExcelImport(path); + var res = stuScoreIBLL.ExecuteImportExcel(dt, fileGuid, queryJson); + var data = new + { + Success = res.snum, + Fail = res.failDt.Rows.Count + }; + return Success(data); + } + else + { + return Fail("导入数据失败!"); + } + } + + + #endregion + } } diff --git a/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/EducationalAdministration/Views/StuScore/InputScoreIndexInTeacher.cshtml b/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/EducationalAdministration/Views/StuScore/InputScoreIndexInTeacher.cshtml index c078d06d9..df0746ec9 100644 --- a/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/EducationalAdministration/Views/StuScore/InputScoreIndexInTeacher.cshtml +++ b/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/EducationalAdministration/Views/StuScore/InputScoreIndexInTeacher.cshtml @@ -89,6 +89,7 @@  提交教务处  去审核成绩  设置成绩比例 +  导入 diff --git a/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/EducationalAdministration/Views/StuScore/InputScoreIndexInTeacher.js b/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/EducationalAdministration/Views/StuScore/InputScoreIndexInTeacher.js index 923897170..d22181361 100644 --- a/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/EducationalAdministration/Views/StuScore/InputScoreIndexInTeacher.js +++ b/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/EducationalAdministration/Views/StuScore/InputScoreIndexInTeacher.js @@ -18,6 +18,9 @@ var headData; //常规列头 var headDataEdit; //可编辑列头 var headDataNoEdit; //不可编辑列头 var headDataFinally; //最终列头 +var rowJson; +var columnJson; +var queryJson; var bootstrap = function ($, learun) { "use strict"; var page = { @@ -469,6 +472,69 @@ var bootstrap = function ($, learun) { learun.postFormSilence(top.$.rootUrl + '/EducationalAdministration/StuScore/AddMinutes', { queryJson: JSON.stringify(query), minutes: newMinutes }, function (res) { }); } }); + //导入 + $("#lr_importScore").on("click", function () { + var query = judgeSelect(); + if (query) { + //判断成绩比例是否合理 + var OrdinaryScoreScale = $('#OrdinaryScoreScale').html(); + var TermInScoreScale = $('#TermInScoreScale').html(); + var TermEndScoreScale = $('#TermEndScoreScale').html(); + var OtherScoreScale = $('#OtherScoreScale').html(); + var totalScale = Number(OrdinaryScoreScale) + Number(TermInScoreScale) + Number(TermEndScoreScale) + Number(OtherScoreScale); + if (totalScale !== 100) { + learun.alert.warning("成绩比例设置不合理!"); + return false; + } else { + //判断是否已审核;判断是否被其他教师占用 + $.lrSetForm(top.$.rootUrl + '/EducationalAdministration/StuScore/GetEntityByJson?queryJson=' + JSON.stringify(query), function (data) { + if (data != null) { + if (data.CheckMark == 1) { + learun.alert.warning("学生成绩已审核!"); + return false; + } + if (data.IsEditable == 0) { + if (data.EditUserId == learun.clientdata.get(['userinfo']).account) { + modifyDate = data.ModifyDate; + } else { + learun.alert.warning("当前班级成绩由账号为" + data.EditUserId + "的教师在使用!"); + return false; + } + } + var param = {}; + param.F_SchoolId = $('#F_SchoolId').lrselectGet(); + param.AcademicYearNo = $('#AcademicYearNo').lrselectGet(); + param.Semester = $('#Semester').lrselectGet(); + param.LessonNo = $('#LessonNo').lrselectGet(); + param.ClassNo = $('#ClassNo').lrselectGet(); + + rowJson = $('#gridtable').jfGridGet('showData'); + columnJson = $('#gridtable').jfGridGet('settingInfo').headData; + queryJson = param; + + learun.layerForm({ + id: 'indexImport', + title: "导入学生成绩", + url: top.$.rootUrl + '/EducationalAdministration/StuScore/InputScoreIndexInTeacherImport', + width: 600, + height: 400, + maxmin: true, + btn: null, + end: function () { + refreshGirdData2(); + } + }); + + } else { + learun.alert.warning("学生成绩不存在!"); + return false; + } + }); + } + } + + + }); }, bindSelect: function () { //校区 diff --git a/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/EducationalAdministration/Views/StuScore/InputScoreIndexInTeacherImport.cshtml b/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/EducationalAdministration/Views/StuScore/InputScoreIndexInTeacherImport.cshtml new file mode 100644 index 000000000..67a7ef54f --- /dev/null +++ b/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/EducationalAdministration/Views/StuScore/InputScoreIndexInTeacherImport.cshtml @@ -0,0 +1,27 @@ +@{ + ViewBag.Title = "Form"; + Layout = "~/Views/Shared/_Form.cshtml"; +} + + +@Html.AppendCssFile("/Areas/LR_SystemModule/Views/ExcelImport/ImportForm.css") + +@*必修成绩录入导入*@ +
+
+
上传文件
+
下载模板
+
+
+
+
+ +
+
+

试试将电脑里的文件拖拽到此上传

+
+
+
+
+ +@Html.AppendJsFile("/Areas/EducationalAdministration/Views/StuScore/InputScoreIndexInTeacherImport.js") diff --git a/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/EducationalAdministration/Views/StuScore/InputScoreIndexInTeacherImport.js b/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/EducationalAdministration/Views/StuScore/InputScoreIndexInTeacherImport.js new file mode 100644 index 000000000..8af2c9085 --- /dev/null +++ b/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/EducationalAdministration/Views/StuScore/InputScoreIndexInTeacherImport.js @@ -0,0 +1,185 @@ +/* + * 描 述:附件上传管理 + */ +var gridId = request('gridtable'); +var bootstrap = function ($, learun) { + "use strict"; + + var fileInfo = {}; + + // 触发合并文件碎片 + var mergeFileChunks = function (file) { + var param = {}; + param['__RequestVerificationToken'] = $.lrToken; + param['fileGuid'] = fileInfo[file.id].fileGuid; + param['fileName'] = fileInfo[file.id].name; + param['chunks'] = fileInfo[file.id].chunks; + var queryJson = JSON.stringify(learun.frameTab.currentIframe().queryJson); + + param['queryJson'] = queryJson; + learun.httpAsyncPost(top.$.rootUrl + "/EducationalAdministration/StuScore/ExecuteImportExcel", param, function (res) { + var $fileItem = $('#lr_form_file_queue_list').find('#lr_filequeue_' + file.id); + $fileItem.find('.lr-uploader-progress').remove(); + + if (res.code == learun.httpCode.success) { + if (res.data.Success != '0') { + learun.alert.success('导入成功' + res.data.Success + '条'); + } + // 文件保存成功后 + $fileItem.append('
' + res.data.Success + '/' + res.data.Fail + '
'); + // 如果有失败 + if (res.data.Fail != '0') { + learun.download({ url: top.$.rootUrl + '/LR_SystemModule/ExcelImport/DownImportErrorFile', param: { fileId: fileInfo[file.id].fileGuid, fileName: fileInfo[file.id].name, __RequestVerificationToken: $.lrToken }, method: 'POST' }); + } + + } + else { + learun.alert.error(res.info); + $fileItem.append('
'); + } + }); + } + // 触发清楚文件碎片 + var reomveFileChunks = function (file) { + var param = {}; + param['__RequestVerificationToken'] = $.lrToken; + param['fileGuid'] = fileInfo[file.id].fileGuid; + param['chunks'] = fileInfo[file.id].chunks; + learun.httpAsyncPost(top.$.rootUrl + "/LR_SystemModule/Annexes/MergeAnnexesFile", param, function (res) { }); + var $fileItem = $('#lr_form_file_queue_list').find('#lr_filequeue_' + file.id); + $fileItem.find('.lr-uploader-progress').remove(); + $fileItem.append('
'); + } + // 删除文件 + var DeleteFile = function (fileId) { + var param = {}; + param['__RequestVerificationToken'] = $.lrToken; + param['fileId'] = fileInfo[fileId].fileGuid; + learun.httpAsyncPost(top.$.rootUrl + "/LR_SystemModule/Annexes/DeleteAnnexesFile", param, function (res) { }); + var file = page.uploader.getFile(fileId); + if (!!file) { + page.uploader.removeFile(file); + } + delete fileInfo[fileId]; + var $fileItem = $('#lr_form_file_queue_list').find('#lr_filequeue_' + fileId); + $fileItem.remove(); + if ($('#lr_form_file_queue_list>div').length == 0) { + $('#lr_form_file_queue .lr-form-file-queue-bg').show(); + } + } + + var page = { + uploader: null, + init: function () { + if (!WebUploader.Uploader.support()) { + alert('Web Uploader 不支持您的浏览器!如果你使用的是IE浏览器,请尝试升级 flash 播放器'); + throw new Error('WebUploader does not support the browser you are using.'); + } + /*导入模板下载*/ + $('#lr_down_file_btn').on('click', function () { + var columnJson = learun.frameTab.currentIframe().columnJson; + columnJson = JSON.stringify(columnJson.filter(item => item.name !== 'CheckMark')); + var rowJson = JSON.stringify(learun.frameTab.currentIframe().rowJson); + + learun.download({ + method: "POST", + url: '/EducationalAdministration/StuScore/ExportExcel', + param: { + fileName: '成绩录入数据', + columnJson: columnJson, + dataJson: rowJson, + //exportField: String(exportField) + } + }); + }); + + page.uploader = WebUploader.create({ + auto: true, + swf: top.$.rootUrl + '/Content/webuploader/Uploader.swf', + // 文件接收服务端。 + server: top.$.rootUrl + "/LR_SystemModule/Annexes/UploadAnnexesFileChunk", + // 选择文件的按钮。可选。 + // 内部根据当前运行是创建,可能是input元素,也可能是flash. + pick: '#lr_add_file_btn', + dnd: '#lr_form_file_queue', + paste: 'document.body', + disableGlobalDnd: true, + accept: { + extensions: "xls,xlsx" + }, + multiple: false, + // 不压缩image, 默认如果是jpeg,文件上传前会压缩一把再上传! + resize: false, + // 文件分片上传 + chunked: true, + chunkRetry: 3, + prepareNextFile: true, + chunkSize: '1048576', + // 上传参数 + formData: { + __RequestVerificationToken: $.lrToken + } + }); + page.uploader.on('fileQueued', page.fileQueued); + page.uploader.on('uploadStart', page.uploadStart); + page.uploader.on('uploadBeforeSend', page.uploadBeforeSend); + page.uploader.on('uploadProgress', page.uploadProgress); + page.uploader.on('uploadSuccess', page.uploadSuccess); + page.uploader.on('uploadError', page.uploadError); + page.uploader.on('uploadComplete', page.uploadComplete); + page.uploader.on('error', page.error); + + + //$('#lr_form_file_queue').mCustomScrollbar({ // 优化滚动条 + // theme: "minimal-dark" + //}); + + }, + fileQueued: function (file) {// 文件加载到队列 + fileInfo[file.id] = { name: file.name }; + $('#lr_form_file_queue .lr-form-file-queue-bg').hide(); + // 添加一条文件记录 + var $item = $('
'); + $item.append('
'); + $item.append('' + file.name + '(' + learun.countFileSize(file.size) + ')'); + + $('#lr_form_file_queue_list').append($item); + }, + uploadStart: function (file) { + var $fileItem = $('#lr_form_file_queue_list').find('#lr_filequeue_' + file.id); + $fileItem.append('
'); + }, + uploadBeforeSend: function (object, data, headers) { + data.chunk = data.chunk || 0; + data.chunks = data.chunks || 1; + fileInfo[data.id].fileGuid = fileInfo[data.id].fileGuid || WebUploader.Base.guid(); + data.fileGuid = fileInfo[data.id].fileGuid; + fileInfo[data.id].chunks = data.chunks; + }, + uploadProgress: function (file, percentage) { + var $fileItem = $('#lr_form_file_queue_list').find('#lr_filequeue_' + file.id); + $fileItem.find('.lr-uploader-progress-bar').css('width', (percentage * 100 + '%')); + }, + uploadSuccess: function (file, res) { + if (res.code == 200) {// 上传成功 + mergeFileChunks(file); + } + else {// 上传失败 + reomveFileChunks(file); + } + }, + uploadError: function (file, code) { + reomveFileChunks(file); + }, + uploadComplete: function (file) { + }, + error: function (type) { + switch (type) { + case 'Q_TYPE_DENIED': + learun.alert.error('当前文件类型不允许上传'); + break; + }; + } + }; + page.init(); +} diff --git a/Learun.Framework.Ultimate V7/Learun.Application.Web/Learun.Application.Web.csproj b/Learun.Framework.Ultimate V7/Learun.Application.Web/Learun.Application.Web.csproj index c27776283..89eae60e0 100644 --- a/Learun.Framework.Ultimate V7/Learun.Application.Web/Learun.Application.Web.csproj +++ b/Learun.Framework.Ultimate V7/Learun.Application.Web/Learun.Application.Web.csproj @@ -1138,6 +1138,7 @@ + @@ -7995,6 +7996,7 @@ + diff --git a/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/EducationalAdministration/StuScore/StuScoreBLL.cs b/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/EducationalAdministration/StuScore/StuScoreBLL.cs index fe16b50c0..b08392adf 100644 --- a/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/EducationalAdministration/StuScore/StuScoreBLL.cs +++ b/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/EducationalAdministration/StuScore/StuScoreBLL.cs @@ -41,6 +41,26 @@ namespace Learun.Application.TwoDevelopment.EducationalAdministration } } } + + public DataTable GetListForExport(string queryJson) + { + try + { + return stuScoreService.GetListForExport(queryJson); + } + catch (Exception ex) + { + if (ex is ExceptionEx) + { + throw; + } + else + { + throw ExceptionEx.ThrowBusinessException(ex); + } + } + } + public IEnumerable GetMonitorList(string queryJson) { try @@ -1070,6 +1090,26 @@ namespace Learun.Application.TwoDevelopment.EducationalAdministration } } } + public (DataTable failDt, int snum, int fnum) ExecuteImportExcel(DataTable dt, string fileGuid, string queryJson) + { + try + { + return stuScoreService.ExecuteImportExcel(dt, fileGuid, queryJson); + + } + catch (Exception ex) + { + if (ex is ExceptionEx) + { + throw; + } + else + { + throw ExceptionEx.ThrowBusinessException(ex); + } + + } + } #endregion diff --git a/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/EducationalAdministration/StuScore/StuScoreIBLL.cs b/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/EducationalAdministration/StuScore/StuScoreIBLL.cs index 840f76b7a..3a1c76ebd 100644 --- a/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/EducationalAdministration/StuScore/StuScoreIBLL.cs +++ b/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/EducationalAdministration/StuScore/StuScoreIBLL.cs @@ -21,6 +21,7 @@ namespace Learun.Application.TwoDevelopment.EducationalAdministration /// /// IEnumerable GetList(string queryJson); + DataTable GetListForExport(string queryJson); IEnumerable GetMonitorList(string queryJson); /// @@ -250,6 +251,8 @@ namespace Learun.Application.TwoDevelopment.EducationalAdministration /// 已审核:1;未审核:0; void DoCheckScore(string queryJson, int checkMark); + (DataTable failDt, int snum, int fnum) ExecuteImportExcel(DataTable dt, string fileGuid, string queryJson); + #endregion IEnumerable GetLessonNoDataFromStuNo(string academicYearNo, string semester, string stuNo); diff --git a/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/EducationalAdministration/StuScore/StuScoreService.cs b/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/EducationalAdministration/StuScore/StuScoreService.cs index 009c6d85c..f7695a95c 100644 --- a/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/EducationalAdministration/StuScore/StuScoreService.cs +++ b/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/EducationalAdministration/StuScore/StuScoreService.cs @@ -9,6 +9,8 @@ using System.Net.Http; using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; +using Learun.Cache.Base; +using Learun.Cache.Factory; namespace Learun.Application.TwoDevelopment.EducationalAdministration { @@ -79,7 +81,10 @@ namespace Learun.Application.TwoDevelopment.EducationalAdministration "; } #endregion - + #region 缓存定义 + private ICache cache = CacheFactory.CaChe(); + private string cacheKey = "Learun_adms_excelError_"; + #endregion #region 获取数据 public IEnumerable GetMonitorList(string queryJson) @@ -188,6 +193,72 @@ namespace Learun.Application.TwoDevelopment.EducationalAdministration } } + public DataTable GetListForExport(string queryJson) + { + try + { + var strSql = new StringBuilder(); + strSql.Append("SELECT t.*,sb.StudyModality,sb.MoveType FROM StuScore t "); + strSql.Append(" left join StuInfoBasic sb on t.StuNo=sb.StuNo "); + strSql.Append(" where 1=1 "); + + //学籍异动的学生不显示 + //strSql.Append(" and t.StuNo not in (select StuNo from StuInfoBasic where ChangeStatus=1) "); + //20220616改 休学的要录入成绩,退学和转校的不用 + strSql.Append(" and t.StuNo not in (select StuNo from StuInfoBasicChange where StuChangeType in('04','06')) "); + var queryParam = queryJson.ToJObject(); + var dp = new DynamicParameters(new { }); + if (!queryParam["F_SchoolId"].IsEmpty()) + { + strSql.Append(" and t.F_SchoolId=@F_SchoolId "); + dp.Add("F_SchoolId", queryParam["F_SchoolId"].ToString(), DbType.String); + } + if (!queryParam["AcademicYearNo"].IsEmpty()) + { + strSql.Append(" and t.AcademicYearNo=@AcademicYearNo "); + dp.Add("AcademicYearNo", queryParam["AcademicYearNo"].ToString(), DbType.String); + } + if (!queryParam["Semester"].IsEmpty()) + { + strSql.Append(" and t.Semester=@Semester "); + dp.Add("Semester", queryParam["Semester"].ToString(), DbType.String); + } + if (!queryParam["LessonNo"].IsEmpty()) + { + strSql.Append(" and t.LessonNo=@LessonNo "); + dp.Add("LessonNo", queryParam["LessonNo"].ToString(), DbType.String); + } + if (!queryParam["ClassNo"].IsEmpty()) + { + strSql.Append(" and t.ClassNo=@ClassNo "); + dp.Add("ClassNo", queryParam["ClassNo"].ToString(), DbType.String); + } + if (!queryParam["ClassRoomNo"].IsEmpty()) + { + strSql.Append(" and t.ClassRoomNo=@ClassRoomNo "); + dp.Add("ClassRoomNo", queryParam["ClassRoomNo"].ToString(), DbType.String); + } + if (!queryParam["LessonSection"].IsEmpty()) + { + strSql.Append(" and t.LessonSection=@LessonSection "); + dp.Add("LessonSection", queryParam["LessonSection"].ToString(), DbType.String); + } + + return new DataTable(); //this.BaseRepository("CollegeMIS").FindList(strSql.ToString(), dp); + } + catch (Exception ex) + { + if (ex is ExceptionEx) + { + throw; + } + else + { + throw ExceptionEx.ThrowServiceException(ex); + } + } + } + /// /// 获取列表分页数据 /// 分页参数 @@ -1115,7 +1186,7 @@ where StuNo not in(Select StuNo from stuscore s where s.Academicyearno = sl.Acad /// 课程下拉框信息【学生成绩录入可去审核】 /// /// - public IEnumerable GetLessonNoDataOfAll(string userAccount, string userType,string AcademicYearNo="",string Semester="") + public IEnumerable GetLessonNoDataOfAll(string userAccount, string userType, string AcademicYearNo = "", string Semester = "") { try { @@ -1131,7 +1202,7 @@ where StuNo not in(Select StuNo from stuscore s where s.Academicyearno = sl.Acad } if (!string.IsNullOrEmpty(AcademicYearNo)) { - strSql.Append(" and s.AcademicYearNo='" + AcademicYearNo + "' and s.Semester='"+Semester+"' "); + strSql.Append(" and s.AcademicYearNo='" + AcademicYearNo + "' and s.Semester='" + Semester + "' "); } var data = this.BaseRepository("CollegeMIS").FindList(strSql.ToString()); data = data.Where(x => !string.IsNullOrEmpty(x.value)).OrderBy(x => x.value); @@ -1655,7 +1726,7 @@ where StuNo not in(Select StuNo from stuscore s where s.Academicyearno = sl.Acad var classInfoEntity = this.BaseRepository("CollegeMIS").FindEntity(x => x.ClassNo == classno); if (classInfoEntity != null) { - this.BaseRepository("CollegeMIS").ExecuteBySql("update StuScore set IsEditable='0',EditUserId='" + loginUserInfo.account + "',BeginModifyDate='" + now + "' where F_SchoolId='" + F_SchoolId + "' and AcademicYearNo='" + AcademicYearNo + "' and Semester='" + Semester + "' and OpenLessonDeptNo='" + classInfoEntity.DeptNo + "' and OpenLessonMajorNo='" + classInfoEntity.MajorNo + "' and LessonNo='" + LessonNo + "' and LessonSortNo='1' and ClassNo='" + classno+ "' "); + this.BaseRepository("CollegeMIS").ExecuteBySql("update StuScore set IsEditable='0',EditUserId='" + loginUserInfo.account + "',BeginModifyDate='" + now + "' where F_SchoolId='" + F_SchoolId + "' and AcademicYearNo='" + AcademicYearNo + "' and Semester='" + Semester + "' and OpenLessonDeptNo='" + classInfoEntity.DeptNo + "' and OpenLessonMajorNo='" + classInfoEntity.MajorNo + "' and LessonNo='" + LessonNo + "' and LessonSortNo='1' and ClassNo='" + classno + "' "); } } else @@ -1765,7 +1836,7 @@ where StuNo not in(Select StuNo from stuscore s where s.Academicyearno = sl.Acad } } - + } catch (Exception ex) { @@ -1870,17 +1941,17 @@ where StuNo not in(Select StuNo from stuscore s where s.Academicyearno = sl.Acad //教师电子成绩单 if (checkMark == 0)//撤销 { - db.ExecuteBySql("update EmpReportCard set ElectronicStatus=0,ElectronicTime=null where F_SchoolId='" + F_SchoolId + "' and AcademicYearNo='" + AcademicYearNo + "' and Semester='" + Semester + "' and LessonNo='" + LessonNo + "' and ClassRoomNo='" + classroomno + "' and LessonSortNo='2' and LessonSection='"+ lessonsection + "'"); + db.ExecuteBySql("update EmpReportCard set ElectronicStatus=0,ElectronicTime=null where F_SchoolId='" + F_SchoolId + "' and AcademicYearNo='" + AcademicYearNo + "' and Semester='" + Semester + "' and LessonNo='" + LessonNo + "' and ClassRoomNo='" + classroomno + "' and LessonSortNo='2' and LessonSection='" + lessonsection + "'"); } else { - db.ExecuteBySql("update EmpReportCard set ElectronicStatus=1,ElectronicTime='" + DateTime.Now + "' where F_SchoolId='" + F_SchoolId + "' and AcademicYearNo='" + AcademicYearNo + "' and Semester='" + Semester + "' and LessonNo='" + LessonNo + "' and classroomno='" + classroomno + "' and LessonSortNo='2' and LessonSection='"+ lessonsection + "'"); + db.ExecuteBySql("update EmpReportCard set ElectronicStatus=1,ElectronicTime='" + DateTime.Now + "' where F_SchoolId='" + F_SchoolId + "' and AcademicYearNo='" + AcademicYearNo + "' and Semester='" + Semester + "' and LessonNo='" + LessonNo + "' and classroomno='" + classroomno + "' and LessonSortNo='2' and LessonSection='" + lessonsection + "'"); } } db.Commit(); } - + } catch (Exception ex) { @@ -2100,6 +2171,107 @@ where StuNo not in(Select StuNo from stuscore s where s.Academicyearno = sl.Acad } } + /// + /// 导入学生成绩 + /// + /// + /// + public (DataTable failDt, int snum, int fnum) ExecuteImportExcel(DataTable dt, string fileGuid, string queryJson) + { + int snum = 0; + int fnum = 0; + var db = this.BaseRepository("CollegeMIS"); + var msg = ""; + try + { + db.BeginTrans(); + var queryParam = queryJson.ToJObject(); + var F_SchoolId = queryParam["F_SchoolId"].ToString(); + var AcademicYearNo = queryParam["AcademicYearNo"].ToString(); + var Semester = queryParam["Semester"].ToString(); + var LessonNo = queryParam["LessonNo"].ToString(); + var ClassNo = queryParam["ClassNo"].ToString(); + var classInfoEntity = db.FindEntity(x => x.ClassNo == ClassNo); + + //获取成绩比例数据 + var stuSelectLessonListEntity = db.FindEntity(x => x.F_SchoolId == F_SchoolId && x.AcademicYearNo == AcademicYearNo && x.Semester == Semester && x.OpenLessonDeptNo == classInfoEntity.DeptNo && x.OpenLessonMajorNo == classInfoEntity.MajorNo && x.LessonNo == LessonNo && x.LessonSortNo == "1" && x.ClassNo == ClassNo); + //当前班级学生成绩 + var list = GetList(queryJson).ToList(); + + // 创建一个datatable容器用于保存导入失败的数据 + DataTable failDt = new DataTable(); + foreach (DataColumn dc in dt.Columns) + { + failDt.Columns.Add(dc.ColumnName, dc.DataType); + } + failDt.Columns.Add("导入错误", typeof(string)); + dt.Columns.Add("导入错误", typeof(string)); + + foreach (DataRow dr in dt.Rows) + { + try + { + var stuno = dr["学号"].ToString().Trim(); + if (!string.IsNullOrEmpty(stuno)) + { + var item = list.Find(x => x.StuNo == stuno); + if (item == null) + { + fnum++; + dr["导入错误"] = classInfoEntity.ClassName + "找不到学号为" + stuno + "的学生"; + failDt.Rows.Add(dr.ItemArray); + continue; + } + var OrdinaryScore = Convert.ToDecimal(string.IsNullOrEmpty(dr["平时成绩"].ToString().Trim()) ? "0" : dr["平时成绩"].ToString().Trim()); + var TermInScore = Convert.ToDecimal(string.IsNullOrEmpty(dr["期中成绩"].ToString().Trim()) ? "0" : dr["期中成绩"].ToString().Trim()); + var TermEndScore = Convert.ToDecimal(string.IsNullOrEmpty(dr["期末成绩"].ToString().Trim()) ? "0" : dr["期末成绩"].ToString().Trim()); + var OtherScore = Convert.ToDecimal(string.IsNullOrEmpty(dr["其他成绩"].ToString().Trim()) ? "0" : dr["其他成绩"].ToString().Trim()); + var Score = Math.Round(Convert.ToDouble(OrdinaryScore * (stuSelectLessonListEntity.OrdinaryScoreScale / 100) + + TermInScore * (stuSelectLessonListEntity.TermInScoreScale / 100) + + TermEndScore * (stuSelectLessonListEntity.TermEndScoreScale / 100) + + OtherScore * (stuSelectLessonListEntity.OtherScoreScale / 100)), MidpointRounding.AwayFromZero); + var remark = dr["备注"].ToString().Trim(); + db.ExecuteBySql($"update StuScore set OrdinaryScore={OrdinaryScore},TermInScore={TermInScore},TermEndScore={TermEndScore},OtherScore={OtherScore},Score={Score},Remark='{remark}' where ScoreId='{item.ScoreId}' "); + + } + else + { + break; + } + } + catch (Exception e) + { + dr["导入错误"] = "出现异常:" + e.Message; + failDt.Rows.Add(dr.ItemArray); + continue; + } + } + db.Commit(); + + // 写入缓存如果有未导入的数据 + if (failDt.Rows.Count > 0) + { + string errordt = failDt.ToJson(); + + cache.Write(cacheKey + fileGuid, errordt, CacheId.excel); + } + + snum = list.Count - failDt.Rows.Count; + return (failDt, snum, failDt.Rows.Count); + } + catch (Exception ex) + { + db.Rollback(); + if (ex is ExceptionEx) + { + throw; + } + else + { + throw ExceptionEx.ThrowServiceException(ex); + } + } + } }