12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772 |
- using System;
- using System.Collections.Generic;
- using System.Data.Entity;
- using System.Linq;
- using System.Text;
- using EMIS.ViewModel;
- using System.Linq.Expressions;
- using EMIS.Entities;
- using Bowin.Common.Linq.Entity;
- using Bowin.Common.Linq;
- using EMIS.DataLogic.ScoreManage;
- using EMIS.ViewModel.ScoreManage;
- using System.Dynamic;
- using EMIS.Utility;
- using System.Reflection;
- using System.Data;
- using EMIS.ViewModel.CacheManage;
- using EMIS.CommonLogic.SystemServices;
- using EMIS.DataLogic.Repositories;
- using EMIS.ViewModel.WorkflowManage;
- using System.Transactions;
- using Bowin.Common.Utility;
- using System.Text.RegularExpressions;
- using System.Web;
- using System.IO;
- using System.Web.Mvc;
- using EMIS.ViewModel.SystemView;
- using EMIS.Utility.FormValidate;
- using EMIS.DataLogic.ChargeManage.ArrearsSituation;
- namespace EMIS.CommonLogic.ScoreManage
- {
- public class ScoreServices : BaseWorkflowServices<ER_FinalExamination>, IScoreServices
- {
- public ScoreDAL scoreDAL { get; set; }
- public StudentScoreDAL StudentScoreDAL { get; set; }
- public MisconductDAL MisconductDAL { get; set; }
- public Lazy<IMisconductServices> MisconductServices { get; set; }
- public Lazy<IExaminationSuspensionServices> ExaminationSuspensionServices { get; set; }
- public Lazy<IExaminationExemptionServices> ExaminationExemptionServices { get; set; }
- public IUserServices UserServices { get; set; }
- public Lazy<IStudentScoreServices> StudentScoreServices { get; set; }
- public SubmitedScoreRepository SubmitedScoreRepository { get; set; }
- public SubmitedScoreDetailRepository SubmitedScoreDetailRepository { get; set; }
- public FinalExaminationStudentRepository FinalExaminationStudentRepository { get; set; }
- public ExamsStateSettingDAL ExamsStateSettingDAL { get; set; }
- public ExamsCategorySettingDAL ExamsCategorySettingDAL { get; set; }
- public FinalExaminationDAL FinalExaminationDAL { get; set; }
- public ImportScoreDAL ImportScoreDAL { get; set; }
- public Lazy<IScoreParamterCollegeSettingServices> ScoreParamterCollegeSettingServices { get; set; }
- public Lazy<IParameterServices> ParameterServices { get; set; }
- public CustomScoreFormulaRepository CustomScoreFormulaRepository { get; set; }
- public ScoreFormulaRepository ScoreFormulaRepository { get; set; }
- public IScoreConvertByApplyServices scoreConvertByApplyServices { get; set; }
- public IScoreConvertByReplaceServices scoreConvertByReplaceServices { get; set; }
- public ArrearsListDAL arrearsListDAL { get; set; }
- protected Func<IQueryable<FinalExaminationView>, IQueryable<FinalExaminationView>> DataRangeFunction { get; set; }
- protected Func<Guid?, Expression<Func<ER_FinalExamination, bool>>> CollegeExpression { get; set; }
- public ScoreServices()
- {
- DataRangeFunction = (x => this.GetQueryByDataRangeByDepartment(x));
- CollegeExpression = (w => (x => x.CF_Department.CF_College.CollegeID == w));
- }
- private List<int?> GetInputStatusList(IList<WorkflowStatusView> statusList, int? startStatus)
- {
- var inputStatusList = statusList.Where(x => (!(x.Description ?? "").Contains("[AP]"))
- && x.ID != startStatus && !(x.Description ?? "").Contains("[PASS]"))
- .Select(x => x.ID).ToList();
- return inputStatusList;
- }
- /// <summary>
- /// 获取期末设定
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="collegeID"></param>
- /// <param name="departmentID"></param>
- /// <param name="schoolyearID"></param>
- /// <param name="coursematerialID"></param>
- /// <param name="courseTypeID"></param>
- /// <param name="examsCategoryID"></param>
- /// <param name="examinationType"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <returns></returns>
- public Bowin.Common.Linq.Entity.IGridResultSet<ViewModel.ScoreManage.FinalExaminationView> GetFinalExaminationViewGrid(ViewModel.ConfiguretView configuretView, Guid? collegeID, Guid? departmentID, Guid? schoolyearID, Guid? coursematerialID, int? courseTypeID, int? examsCategoryID, int? approvalStatus, int? gradeYearID, string isCheck, int pageIndex, int pageSize)
- {
- var statusList = this.GetStatusViewList();
- var startStatus = this.GetStartStatus();
- var status = this.GetInputStatusList(statusList, startStatus);
- var endStatus = statusList.Where(x => x.Description.Contains("[PASS]")).Select(x => x.ID).FirstOrDefault();
- Expression<Func<ER_FinalExamination, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (collegeID.HasValue)
- exp = exp.And(this.CollegeExpression(collegeID));
- if (departmentID.HasValue)
- exp = exp.And(x => x.DepartmentID == departmentID);
- if (schoolyearID.HasValue)
- exp = exp.And(x => x.SchoolyearID == schoolyearID);
- if (coursematerialID.HasValue)
- exp = exp.And(x => x.CoursematerialID == coursematerialID);
- if (courseTypeID.HasValue)
- exp = exp.And(x => x.CourseTypeID == courseTypeID);
- if (examsCategoryID.HasValue)
- exp = exp.And(x => x.ExamsCategoryID == examsCategoryID);
- if (approvalStatus.HasValue)
- exp = exp.And(x => x.ApprovalStatus == approvalStatus);
- if (gradeYearID.HasValue)
- exp = exp.And(x => x.GradeYearID == gradeYearID);
- if (isCheck == "true")
- exp = exp.And(x => x.CreatorUserID == EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID);
- var query = scoreDAL.GetScoreViewQueryable(exp);
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
- if (isCheck != "true")
- {
- query = this.DataRangeFunction(query);
- }
- var result = query.OrderByDescending(x => x.SchoolyearCode).ThenByDescending(x => x.CourseName).ThenByDescending(x => x.CreateTime).ThenByDescending(x => x.ApprovalStatus).ToGridResultSet<FinalExaminationView>(pageIndex, pageSize);
- result.rows.ForEach(x => { x.ApprovalStatusName = statusList.FirstOrDefault(w => w.ID == x.ApprovalStatus).Name; x.ApprovalEndStatus = endStatus; });
- result.rows.ForEach(x => x.IsEntry = status.Contains(x.ApprovalStatus) ? true : false); //控制是否可录入成绩
- return result;
- }
- /// <summary>
- /// 获取期末设定
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="collegeID"></param>
- /// <param name="departmentID"></param>
- /// <param name="schoolyearID"></param>
- /// <param name="coursematerialID"></param>
- /// <param name="courseTypeID"></param>
- /// <param name="examsCategoryID"></param>
- /// <param name="examinationType"></param>
- /// <returns></returns>
- public List<ViewModel.ScoreManage.FinalExaminationView> GetFinalExaminationViewList(ViewModel.ConfiguretView configuretView, Guid? collegeID, Guid? departmentID, Guid? schoolyearID, Guid? coursematerialID, int? courseTypeID, int? examsCategoryID, int? approvalStatus, int? gradeYearID, string isCheck, List<Guid?> idList = null)
- {
- var statusList = this.GetStatusViewList();
- Expression<Func<ER_FinalExamination, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (collegeID.HasValue)
- exp = exp.And(this.CollegeExpression(collegeID));
- if (departmentID.HasValue)
- exp = exp.And(x => x.DepartmentID == departmentID);
- if (schoolyearID.HasValue)
- exp = exp.And(x => x.SchoolyearID == schoolyearID);
- if (coursematerialID.HasValue)
- exp = exp.And(x => x.CoursematerialID == coursematerialID);
- if (courseTypeID.HasValue)
- exp = exp.And(x => x.CourseTypeID == courseTypeID);
- if (examsCategoryID.HasValue)
- exp = exp.And(x => x.ExamsCategoryID == examsCategoryID);
- if (approvalStatus.HasValue)
- exp = exp.And(x => x.ApprovalStatus == approvalStatus);
- if (gradeYearID.HasValue)
- exp = exp.And(x => x.GradeYearID == gradeYearID);
- if (isCheck == "true")
- exp = exp.And(x => x.CreatorUserID == EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID);
- if (idList != null && idList.Count() > 0)
- exp = exp.And(x => idList.Contains(x.FinalExaminationID));
- var query = scoreDAL.GetScoreViewQueryable(exp);
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
- if (isCheck != "true")
- {
- query = this.DataRangeFunction(query);
- }
- var result = query.OrderByDescending(x => x.SchoolyearCode).ThenByDescending(x => x.CourseName).ThenByDescending(x => x.CreateTime).ThenByDescending(x => x.ApprovalStatus).ToList();
- result.ForEach(x => x.ApprovalStatusName = statusList.FirstOrDefault(w => w.ID == x.ApprovalStatus).Name);
- return result;
- }
- /// <summary>
- /// 重置
- /// </summary>
- /// <param name="finalExaminationID"></param>
- public void ScoreResettingDelete(Guid? finalExaminationID)
- {
- try
- {
- if (finalExaminationID.HasValue)
- {
- UnitOfWork.Delete<ER_ScoreDetail>(x => x.ER_Score.FinalExaminationID == finalExaminationID && x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- UnitOfWork.Delete<ER_Score>(x => x.FinalExaminationID == finalExaminationID && x.RecordStatus == (int)SYS_STATUS.USABLE);
- }
- }
- catch (Exception)
- {
- throw;
- }
- }
- /// <summary>
- /// 重置
- /// </summary>
- /// <param name="finalExaminationID"></param>
- public void ScoreDelete(List<Guid> finalExaminationIDs)
- {
- try
- {
- var nowTime = DateTime.Now;
- var curUser = CustomPrincipal.Current;
- UnitOfWork.Update<ER_FinalExamination>(x => new ER_FinalExamination { ScoreFormulaID = null, CreditFormulaID = null, GradePointFormulaID = null, ModifyTime = nowTime, ModifyUserID = curUser.UserID },
- (x => finalExaminationIDs.Contains(x.FinalExaminationID)));
- UnitOfWork.Delete<ER_ScoreDetail>(x => finalExaminationIDs.Contains((Guid)x.ER_Score.FinalExaminationID) && x.RecordStatus == (int)SYS_STATUS.USABLE);
- UnitOfWork.Delete<ER_Score>(x =>finalExaminationIDs.Contains((Guid)x.FinalExaminationID)&& x.RecordStatus == (int)SYS_STATUS.USABLE);
- }
- catch (Exception)
- {
- throw;
- }
- }
- /// <summary>
- /// 学生成绩录入
- /// </summary>
- /// <param name="finalExaminationID"></param>
- /// <returns></returns>
- public IGridResultSet<StudentScoreInputView> GetStudentScoreInputViewGrid(Guid? finalExaminationID)
- {
- #region 获取各种初始化数据
- var applyConvertEndStatus = scoreConvertByReplaceServices.GetCorrectEndStatus();
- var replaceConvertEndStatus = scoreConvertByReplaceServices.GetCorrectEndStatus();
- //获取各流程的结束状态,需要注意的是,不一定所有的高校都有部署全部的流程,所以 如果读不出数据来就留空
- var suspensionEndStatusID = ExaminationSuspensionServices.Value.GetEndStatusID();
- var misconductEndStatusID = MisconductServices.Value.GetEndStatusID();
- var exemptionEndStatusID = ExaminationExemptionServices.Value.GetEndStatusID();
- //获取考试性质设置项,用于判断是否需要读取上次考试成绩
- var examsCategorySettingList = ExamsCategorySettingDAL.GetExamsCategorySettingView().ToList();
- //缓交申请(审核通过)
- var chargeDelayEndStatusID = WorkflowServices.Value.GetCorrectEndStatus("EC_ChargeDelay") ?? null;
- var statusList = this.GetStatusViewList();
- var startStatus = this.GetStartStatus();
- var inputStatusList = this.GetInputStatusList(statusList, startStatus);
- var canInputStatus = statusList.Where(x => x.Description.Contains("[ENTRY]")).Select(x => x.ID).FirstOrDefault();
- //获取缴费控制项
- var isChargeControl = ParameterServices.Value.GetParameterValue<bool>(CF_ParameterType.IsScoreEditControlForCharge);
- var importScoreList = new List<ImportScoreView>();
- var lastPassScoreList = new List<StudentScoreInputDetailView>();
- var scoreTypeList = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ScoreType).ToList();
- #endregion
- var finalExamination = FinalExaminationDAL.finalExaminationRepository.GetSingle(x => x.FinalExaminationID == finalExaminationID);
- var ResultTypeList = scoreDAL.ResultTypeDetailRepository.GetList(x => x.ResultTypeID == finalExamination.ResultTypeID).ToList();
- var collegeScoreParameterSetting = this.ScoreParamterCollegeSettingServices.Value.GetScoreParameterCollegeSettingView(finalExamination.CollegeID, finalExamination.GradeYearID);
- var query = scoreDAL.GetStudentScoreInputViewQuqeryable(finalExaminationID, suspensionEndStatusID, misconductEndStatusID, exemptionEndStatusID, chargeDelayEndStatusID, isChargeControl ?? false, applyConvertEndStatus, replaceConvertEndStatus);
- var resultList = query.OrderBy(x => x.LoginID).ToGridResultSet();
- var detailList = scoreDAL.GetStudentScoreInputDetailViewQuqeryable(finalExaminationID).ToList();
- //当期末设定处于可录入和重新录入两个状态下就刷新平时成绩(如果有的话)
- bool isGetImportScore = inputStatusList.Contains(finalExamination.ApprovalStatus)
- && finalExamination.ExamsCategoryID == (int)CF_ExamsCategory.FinalExam
- && collegeScoreParameterSetting != null && collegeScoreParameterSetting.ScoreTypeID != null;
- bool isLoadScore = (examsCategorySettingList.Any(x => x.ExamsCategoryID == finalExamination.ExamsCategoryID && x.IsReadHistory)
- && finalExamination.ApprovalStatus == canInputStatus);
-
- if (isGetImportScore)
- {
- importScoreList = this.ImportScoreDAL.GetImportScoreViewQueryableByFinalExaminationID(finalExamination.FinalExaminationID).ToList();
- }
- if (isLoadScore)
- {
- lastPassScoreList = this.scoreDAL.GetLastPassedStudentScoreForResit(finalExamination.FinalExaminationID).ToList();
- }
- for (int i = 0; i < resultList.rows.Count; i ++ )
- {
- resultList.rows[i].No = i + 1;
- resultList.rows[i].ScoreDetail = (from scoreType in scoreTypeList
- join detail in detailList.Where(x => x.UserID == resultList.rows[i].UserID)
- on scoreType.Value equals detail.ScoreTypeID into ddetail
- from detail in ddetail.DefaultIfEmpty()
- select new StudentScoreInputDetailView
- {
- ScoreTypeID = scoreType.Value,
- UserID = resultList.rows[i].UserID,
- Score = (detail == null ?
- (
- (collegeScoreParameterSetting != null
- && finalExamination.ExamsCategoryID == (int)CF_ExamsCategory.FinalExam
- && collegeScoreParameterSetting.ScoreTypeID == (int)CF_ScoreType.Peacetime
- && scoreType.Value == (int)CF_ScoreType.Peacetime) ?
- (int?)0 :
- null
- ) : detail.Score),
- IsCanEdit = (detail == null ?
- (collegeScoreParameterSetting == null || collegeScoreParameterSetting.ScoreTypeID != scoreType.Value || finalExamination.ExamsCategoryID != (int)CF_ExamsCategory.FinalExam)
- : detail.IsCanEdit),
- RecordStatus = (detail == null ? (int)SYS_STATUS.USABLE : detail.RecordStatus)
- })
- .ToDictionary(x => x.ScoreTypeID.ToString());
- //读取导入的平时成绩
- if (isGetImportScore && resultList.rows[i].RecordStatus > (int)SYS_STATUS.UNUSABLE)
- {
- var importScore = importScoreList.FirstOrDefault(x => x.UserID == resultList.rows[i].UserID);
- if (importScore != null)
- {
- if (!resultList.rows[i].ScoreDetail.ContainsKey(collegeScoreParameterSetting.ScoreTypeID.ToString()))
- {
- resultList.rows[i].ScoreDetail.Add(collegeScoreParameterSetting.ScoreTypeID.ToString(), new StudentScoreInputDetailView
- {
- ScoreTypeID = collegeScoreParameterSetting.ScoreTypeID,
- UserID = importScore.UserID,
- RecordStatus = (int)SYS_STATUS.USABLE
- });
- }
- resultList.rows[i].ScoreDetail[collegeScoreParameterSetting.ScoreTypeID.ToString()].Score = importScore.Score;
- resultList.rows[i].ScoreDetail[collegeScoreParameterSetting.ScoreTypeID.ToString()].IsCanEdit = false;
- }
- else {
- //如果有个性设定,但是没有导入成绩
- resultList.rows[i].ScoreDetail[collegeScoreParameterSetting.ScoreTypeID.ToString()].Score = null;
- resultList.rows[i].ScoreDetail[collegeScoreParameterSetting.ScoreTypeID.ToString()].IsCanEdit = false;
- }
- }
- //读取上一次期末考试合格的分数
- if (isLoadScore && resultList.rows[i].RecordStatus > (int)SYS_STATUS.UNUSABLE)
- {
- var lastPassScore = lastPassScoreList.Where(x => x.UserID == resultList.rows[i].UserID).ToList();
- lastPassScore.ForEach(x =>
- {
- if (!resultList.rows[i].ScoreDetail.ContainsKey(x.ScoreTypeID.ToString()))
- {
- resultList.rows[i].ScoreDetail.Add(x.ScoreTypeID.ToString(), new StudentScoreInputDetailView
- {
- ScoreTypeID = x.ScoreTypeID,
- UserID = x.UserID,
- RecordStatus = (int)SYS_STATUS.USABLE,
- IsCanEdit = true
- });
- }
- resultList.rows[i].ScoreDetail[x.ScoreTypeID.ToString()].Score = x.Score;
- });
- }
- //如果整行都不能编辑,那这里面的明细也不能编辑
- if (!resultList.rows[i].IsCanEdit)
- {
- resultList.rows[i].ScoreDetail.ForEach(x => x.Value.IsCanEdit = false);
- }
- }
- return resultList;
- }
- /// <summary>
- /// 获取成绩录入
- /// </summary>
- /// <param name="finalExaminationIDs"></param>
- /// <returns></returns>
- public List<ER_Score> GetScoreList(Guid? finalExaminationID)
- {
- try
- {
- List<ER_Score> scoreList = scoreDAL.ScoreRepository.GetList(x => x.FinalExaminationID == finalExaminationID, (x => x.ER_ScoreDetail), (x => x.CF_Student.Sys_User), (x => x.CF_Student.CF_DifferentDynamic)).ToList();
-
- scoreList.ForEach(x => { x.TotalScore = Math.Round(x.TotalScore ?? 0, 0, MidpointRounding.AwayFromZero); });
- return scoreList;
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
- public void ScoreSave(FinalExaminationView finalExaminationView, IList<StudentScoreInputView> scoreViewList)
- {
- var startStatus = this.GetStartStatus();
- var statusList = this.GetStatusViewList();
- var inputStatusList = this.GetInputStatusList(statusList, startStatus);
- ER_FinalExamination finalExamination = scoreDAL.finalExaminationRepository.GetSingle(x => x.FinalExaminationID == finalExaminationView.FinalExaminationID);
- if (!inputStatusList.Contains(finalExamination.ApprovalStatus))
- {
- return;
- }
- finalExamination.ScoreFormulaID = finalExaminationView.ScoreFormulaID;
- finalExamination.CreditFormulaID = finalExaminationView.CreditFormulaID;
- finalExamination.GradePointFormulaID = finalExaminationView.GradePointFormulaID;
- finalExamination.Comment = finalExaminationView.Comment;
-
- var insertDetailList = scoreViewList.Where(x =>
- //重录时需要过滤掉无需重录的学生
- (x.RecordStatus ?? (int)SYS_STATUS.USABLE) > (int)SYS_STATUS.UNUSABLE
- //过滤总成绩为null的行,一般只有空行会是null
- && x.TotalScore != null)
- .ToList();
-
- var reEnterDetailList = scoreViewList.Where(x =>
- //重录时需要过滤掉无需重录的学生
- (x.RecordStatus ?? (int)SYS_STATUS.USABLE) > (int)SYS_STATUS.UNUSABLE)
- .ToList();
- //重录时只删除重录的数据再插入
- var userIDList = reEnterDetailList.Select(x => x.UserID).ToList();
- if (userIDList.Count > 0)
- {
- UnitOfWork.Delete<ER_ScoreDetail>(x => x.ER_Score.FinalExaminationID == finalExamination.FinalExaminationID && userIDList.Contains(x.ER_Score.UserID) && x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- UnitOfWork.Delete<ER_Score>(x => x.FinalExaminationID == finalExamination.FinalExaminationID && userIDList.Contains(x.UserID) && x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- }
- foreach (var scoreView in reEnterDetailList)
- {
- ER_Score score = new ER_Score();
- score.ScoreID = Guid.NewGuid();
- score.UserID = scoreView.UserID;
- score.FinalExaminationID = scoreView.FinalExaminationID;
- score.ExamsStateID = scoreView.ExamsStateID;
- score.TotalScore = scoreView.TotalScore;
- score.Credit = scoreView.Credit;
- score.GradePoint = scoreView.GradePoint;
- score.Remark = scoreView.Remarks;
- SetNewStatus(score);
- score.RecordStatus = Convert.ToInt32(scoreView.RecordStatus);
- UnitOfWork.Add(score);
- foreach (var scoreDetailView in scoreView.ScoreDetail)
- {
- ER_ScoreDetail scoreDetail = new ER_ScoreDetail();
- scoreDetail.ScoreDetailID = Guid.NewGuid();
- scoreDetail.ScoreID = score.ScoreID;
- scoreDetail.ScoreTypeID = Convert.ToInt32(scoreDetailView.Key);
- scoreDetail.Score = scoreDetailView.Value.Score;
- SetNewStatus(scoreDetail);
- UnitOfWork.Add(scoreDetail);
- }
- }
- UnitOfWork.Commit();
- }
- private List<int?> GetRequiredScoreTypeList(FinalExaminationView finalExaminationView, IList<StudentScoreInputView> scoreViewList)
- {
- var customScoreFormulaList = this.CustomScoreFormulaRepository.Entities.ToList();
- if (customScoreFormulaList.Count > 0)
- {
- var scoreTypesList = scoreViewList.SelectMany(x => x.ScoreDetail)
- .Where(x => x.Value.Score != null)
- .Select(x => x.Value.ScoreTypeID).Distinct().ToList();
- //创建空结构
- var groups = customScoreFormulaList.Where(x => false).Select(x => new { Total = 0, Detail = new List<ER_CustomScoreFormula> {x} }).ToList();
- scoreTypesList.ForEach(scoreType => {
- customScoreFormulaList.ForEach(scoreFormula => {
- var mateResultList = groups.Where(x => x.Detail.Any(w => w.ScoreType == scoreFormula.ScoreType)).ToList();
- mateResultList.ForEach(mateResult => {
- var item = new { Total = mateResult.Total + (scoreFormula.Percentage ?? 0), Detail = mateResult.Detail.Where(x => x.ScoreType != scoreFormula.ScoreType).ToList() };
- item.Detail.Add(scoreFormula);
- groups.Add(item);
- });
- if (mateResultList.Count == 0)
- {
- groups.ForEach(x => x = new { Total = x.Total + (scoreFormula.Percentage ?? 0), Detail = x.Detail.Concat(new List<ER_CustomScoreFormula> { scoreFormula }).ToList() });
- groups.Add(new { Total = (scoreFormula.Percentage ?? 0), Detail = new List<ER_CustomScoreFormula> { scoreFormula } });
- }
- });
- });
- return groups.Where(x => x.Total == 100).SelectMany(x => x.Detail).Select(x => x.ScoreType).Distinct().ToList();
- }
- else
- {
- var scoreFormula = ScoreFormulaRepository.GetSingle(x => x.ScoreFormulaID == finalExaminationView.ScoreFormulaID, (x => x.ER_ScoreFormulaDetail));
- return scoreFormula.ER_ScoreFormulaDetail.Where(x => x.Percentage > 0).Select(x => x.ScoreType).Distinct().ToList();
- }
- }
- public void Submit(FinalExaminationView finalExaminationView, IList<StudentScoreInputView> scoreViewList)
- {
- var normalStateID = ExamsStateSettingDAL.GetNormalID();
- var examinationSuspensionID = ExamsStateSettingDAL.GetExaminationSuspensionID();
- var examinationExemptionID = ExamsStateSettingDAL.GetExaminationExemptionID();
- var misconductIDList = ExamsStateSettingDAL.GetMisconductIDList();
- //缓交申请(审核通过)
- var chargeDelayEndStatusID = WorkflowServices.Value.GetCorrectEndStatus("EC_ChargeDelay") ?? null;
- //获取缴费控制项
- var isChargeControl = ParameterServices.Value.GetParameterValue<bool>(CF_ParameterType.IsScoreEditControlForCharge);
-
- var userIDList = scoreViewList.Select(x => x.UserID).ToList();
- Expression<Func<EC_StudentCharge, bool>> expStudentCharge = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- expStudentCharge = expStudentCharge.And(x => userIDList.Contains(x.UserID));
- var arrearList = arrearsListDAL.GetArrearListViewAble(expStudentCharge, x => x.RecordStatus == chargeDelayEndStatusID);
- this.ScoreSave(finalExaminationView, scoreViewList);
- var requireScoreTypeList = this.GetRequiredScoreTypeList(finalExaminationView, scoreViewList);
- //有欠费控制并且欠费的不让提交
- if (arrearList != null && isChargeControl.HasValue)
- {
- if (arrearList.Count() > 0 && isChargeControl.Value)
- {
- throw new Exception("存在欠费的学生无法提交,请检查。");
- }
- }
- if (scoreViewList.Any(x =>
- x.ExamsStateID != examinationSuspensionID && x.ExamsStateID != examinationExemptionID && !misconductIDList.Contains(x.ExamsStateID)
- && x.ScoreDetail.Any(w => requireScoreTypeList.Contains(w.Value.ScoreTypeID) && w.Value.Score == null)))//&& x.IsConvert == false
- {
- throw new Exception("学生成绩录入未完整,请检查。");
- }
-
- var actionList = this.GetActionView(finalExaminationView.FinalExaminationID.Value, EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID).ToList();
- var actionID = actionList.Where(x => x.ActionName == "提交").Select(w => w.ActionID).FirstOrDefault();
- if (actionID != null)
- {
- Approve(new List<Guid> { finalExaminationView.FinalExaminationID.Value }, EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID, actionID, null);
- }
- }
- /// <summary>
- /// 提交以及保存
- /// </summary>
- /// <param name="finalExaminationID"></param>
- /// <param name="listExpandoObject"></param>
- public void ScoreAdd(FinalExaminationView finalExaminationView, List<ExpandoObject> listExpandoObject, int? approvalStatus)
- {
- try
- {
- var normalStateID = ExamsStateSettingDAL.GetNormalID();
- var suspensionID = ExamsStateSettingDAL.GetExaminationSuspensionID();
- var exemptionID = ExamsStateSettingDAL.GetExaminationExemptionID();
- var misconductStateList = ExamsStateSettingDAL.GetMisconductIDList();
- var scoreDynamicTypes = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ScoreType);
- ER_FinalExamination finalExamination = scoreDAL.finalExaminationRepository.GetSingle(x => x.FinalExaminationID == finalExaminationView.FinalExaminationID);
- List<ExaminationSuspensionView> suspensionList = ExaminationSuspensionServices.Value.GetExaminationSuspensionViewListByFinalExamination(finalExaminationView.FinalExaminationID);
- List<ExaminationExemptionView> exemptionList = ExaminationExemptionServices.Value.GetExaminationExemptionViewListByFinalExamination(finalExaminationView.FinalExaminationID);
- List<MisconductView> misconductList = MisconductServices.Value.GetMisconductViewListByFinalExamination(finalExaminationView.FinalExaminationID);
- if (finalExamination == null)
- throw new Exception("未找到相对应的设定!");
- //if (approvalStatus.HasValue)
- // finalExamination.ApprovalStatus = approvalStatus;
- finalExamination.ScoreFormulaID = finalExaminationView.ScoreFormulaID;
- finalExamination.CreditFormulaID = finalExaminationView.CreditFormulaID;
- finalExamination.GradePointFormulaID = finalExaminationView.GradePointFormulaID;
- finalExamination.Comment = finalExaminationView.Comment;
- if (listExpandoObject != null)
- {
- UnitOfWork.Delete<ER_ScoreDetail>(x => x.ER_Score.FinalExaminationID == finalExamination.FinalExaminationID);
- UnitOfWork.Delete<ER_Score>(x => x.FinalExaminationID == finalExamination.FinalExaminationID);
- foreach (dynamic item in listExpandoObject)
- {
- Guid ScoreID = item.ScoreID == "" || item.ScoreID == null ? Guid.Empty : new Guid(item.ScoreID);
- ER_Score score = new ER_Score();
- decimal totalScoreNum = Convert.ToDecimal(item.TotalScore);
- score.ScoreID = Guid.NewGuid();
- score.UserID = new Guid(item.UserID);
- score.FinalExaminationID = new Guid(item.FinalExaminationID);
- score.ExamsStateID = Convert.ToInt32(item.ExamsStateID);
- var suspension = suspensionList.FirstOrDefault(x => x.UserID == new Guid(item.UserID));
- var exemption = exemptionList.FirstOrDefault(x => x.UserID == new Guid(item.UserID));
- var misconduct = misconductList.FirstOrDefault(x => x.UserID == new Guid(item.UserID));
- if (misconduct != null)
- {
- score.ExamsStateID = misconduct.ExamsStateID;
- score.TotalScore = 0;
- score.Credit = 0;
- score.GradePoint = 0;
- }
- else if (exemption != null)
- {
- score.ExamsStateID = exemptionID;
- score.TotalScore = 0;
- score.Credit = 0;
- score.GradePoint = 0;
- }
- else if (suspension != null)
- {
- score.ExamsStateID = suspensionID;
- score.TotalScore = 0;
- score.Credit = 0;
- score.GradePoint = 0;
- }
- else
- {
- score.ExamsStateID = normalStateID;
- if (Convert.ToInt32(item.ExamsStateID) != normalStateID)
- {
- score.ExamsStateID = Convert.ToInt32(item.ExamsStateID);
- }
- score.TotalScore = totalScoreNum > 0 ? Math.Round(totalScoreNum, 0, MidpointRounding.AwayFromZero) : totalScoreNum;
- score.Credit = Convert.ToDecimal(item.Credit);
- score.GradePoint = Convert.ToDecimal(item.GradePoint);
- }
- score.Remark = item.Remarks;
- SetNewStatus(score);
- score.RecordStatus = Convert.ToInt32(item.RecordStatus);
- UnitOfWork.Add(score);
- foreach (var scoreDynamicType in scoreDynamicTypes)
- {
- var dic = (IDictionary<string, object>)item;
- var formulascore = dic["Formula_" + scoreDynamicType.Value];
- ER_ScoreDetail scoreDetail = new ER_ScoreDetail();
- scoreDetail.ScoreDetailID = Guid.NewGuid();
- scoreDetail.ScoreID = score.ScoreID;
- scoreDetail.ScoreTypeID = scoreDynamicType.Value;
- //if (scoreDetail.ScoreTypeID != (int)CF_ScoreType.Peacetime
- // && (score.ExamsStateID == suspensionID || score.ExamsStateID == exemptionID
- // || misconductStateList.Contains(score.ExamsStateID)))
- //{
- // scoreDetail.Score = null;
- //}
- //else
- //{
- if (formulascore == "")
- {
- formulascore = null;
- }
- if (formulascore != null)
- {
- scoreDetail.Score = Convert.ToDecimal(formulascore);
- }
- else
- {
- scoreDetail.Score = null;
- }
- //}
- SetNewStatus(scoreDetail);
- UnitOfWork.Add(scoreDetail);
- }
- }
- }
- UnitOfWork.Commit();
- //因为成绩保存和提交调用同样的方法,参数传1表示成绩提交,调用工作流
- if (approvalStatus == 1)
- {
- var actionList = WorkflowServices.Value.GetActionView("ER_FinalExamination", finalExamination.FinalExaminationID, EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID).ToList();
- var actionID = actionList.Where(x => x.ActionName == "提交").Select(w => w.ActionID).FirstOrDefault();
- Approve(new List<Guid> { finalExamination.FinalExaminationID }, EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID, actionID, null);
- //UnitOfWork.Commit();
- }
- }
- catch (Exception ex)
- {
- throw;
- }
- }
- /// <summary>
- /// 查询未审核期末设定
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="collegeID"></param>
- /// <param name="departmentID"></param>
- /// <param name="schoolyearID"></param>
- /// <param name="coursematerialID"></param>
- /// <param name="courseTypeID"></param>
- /// <param name="courseQualityID"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <returns></returns>
- public IGridResultSet<FinalExaminationView> GetFinalExaminationScoreAuditViewGrid(ConfiguretView configuretView, Guid? collegeID, Guid? departmentID, Guid? schoolyearID, Guid? coursematerialID, int? courseTypeID, int? examsCategoryID, int? gradeYearID, int? approvalStatus, int pageIndex, int pageSize)
- {
- //List<int> list = new List<int>();
- //list.Add((int)EMIS.ViewModel.CF_ScoreState.Submitted);
- var statusList = this.GetStatusViewList(); //获取工作流列表
- var status = statusList.Where(x => (x.Description ?? "").Contains("[AP]")).Select(x => x.ID); //审核中的节点的Description标识为[AP]
- Expression<Func<ER_FinalExamination, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (collegeID.HasValue)
- exp = exp.And(this.CollegeExpression(collegeID));
- if (departmentID.HasValue)
- exp = exp.And(x => x.DepartmentID == departmentID);
- if (schoolyearID.HasValue)
- exp = exp.And(x => x.SchoolyearID == schoolyearID);
- if (coursematerialID.HasValue)
- exp = exp.And(x => x.CoursematerialID == coursematerialID);
- if (courseTypeID.HasValue)
- exp = exp.And(x => x.CourseTypeID == courseTypeID);
- if (examsCategoryID.HasValue)
- exp = exp.And(x => x.ExamsCategoryID == examsCategoryID);
- if (gradeYearID.HasValue)
- exp = exp.And(x => x.GradeYearID == gradeYearID);
- if (approvalStatus.HasValue)
- exp = exp.And(x => x.ApprovalStatus == approvalStatus);
- //if (status.Count() > 0) //
- // exp = exp.And(x => status.Contains((int)x.ApprovalStatus));
- //exp = exp.And(x => list.Contains((int)x.ApprovalStatus));
- var query = scoreDAL.GetScoreViewQueryable(exp);
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
- var result = this.DataRangeFunction(query).OrderByDescending(x => x.SchoolyearCode).ThenByDescending(x => x.CourseName).ThenByDescending(x => x.CreateTime).ThenByDescending(x => x.ApprovalStatus).ToGridResultSet<FinalExaminationView>(pageIndex, pageSize);
- result.rows.ForEach(x => x.ApprovalStatusName = statusList.FirstOrDefault(w => w.ID == x.ApprovalStatus).Name);
- return result;
- }
- /// <summary>
- /// //获取录入状态
- /// </summary>
- /// <returns></returns>
- public int? ApprovalStatus()
- {
- var statusList = this.GetStatusViewList(); //获取工作流列表
- var status = statusList.Where(x => (x.Description ?? "").Contains("[AP]")).Select(x => x.ID).FirstOrDefault();
- return status;
- }
- ///<summary>
- ///检查是否能被审核
- ///</summary>
- public void CheckApprovalStatus(List<int?> ApprovalStatus)
- {
- try
- {
- var statusList = this.GetStatusViewList(); //获取工作流列表
- var status = statusList.Where(x => (x.Description ?? "").Contains("[AP]")).Select(w => w.ID).ToList();
- List<int?> okNo = new List<int?>();
- foreach (var s in status)
- {
- for (int i = 0; i < ApprovalStatus.Count(); i++)
- {
- if (ApprovalStatus[i] == s)
- {
- okNo.Add(ApprovalStatus[i]);
- }
- }
- }
- if (okNo.Count() != ApprovalStatus.Count())
- {
- throw new Exception("只能操作待审核和重录待审的数据!");
- }
- }
- catch (Exception)
- {
- throw;
- }
- }
- /// <summary>
- /// 查询期末设定
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="collegeID"></param>
- /// <param name="departmentID"></param>
- /// <param name="schoolyearID"></param>
- /// <param name="coursematerialID"></param>
- /// <param name="courseTypeID"></param>
- /// <param name="courseQualityID"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <returns></returns>
- public List<FinalExaminationView> GetFinalExaminationScoreAuditViewList(ConfiguretView configuretView, Guid? collegeID, Guid? departmentID, Guid? schoolyearID, Guid? coursematerialID, int? courseTypeID, int? examsCategoryID, int? gradeYearID, int? status)
- {
- //List<int> list = new List<int>();
- //list.Add((int)EMIS.ViewModel.CF_ScoreState.Submitted);
- var statusList = this.GetStatusViewList(); //获取工作流列表
- //var status = statusList.Where(x => (x.Description ?? "").Contains("[AP]")).Select(x => x.ID); //审核中的节点的Description标识为[AP]
- Expression<Func<ER_FinalExamination, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (collegeID.HasValue)
- exp = exp.And(this.CollegeExpression(collegeID));
- if (departmentID.HasValue)
- exp = exp.And(x => x.DepartmentID == departmentID);
- if (schoolyearID.HasValue)
- exp = exp.And(x => x.SchoolyearID == schoolyearID);
- if (coursematerialID.HasValue)
- exp = exp.And(x => x.CoursematerialID == coursematerialID);
- if (courseTypeID.HasValue)
- exp = exp.And(x => x.CourseTypeID == courseTypeID);
- if (examsCategoryID.HasValue)
- exp = exp.And(x => x.ExamsCategoryID == examsCategoryID);
- if (gradeYearID.HasValue)
- exp = exp.And(x => x.GradeYearID == gradeYearID);
- //exp = exp.And(x => list.Contains((int)x.ApprovalStatus));
- if (status.HasValue)
- exp = exp.And(x => x.ApprovalStatus == status);
- var query = scoreDAL.GetScoreViewQueryable(exp);
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
- var result = this.DataRangeFunction(query).OrderByDescending(x => x.SchoolyearCode).ThenByDescending(x => x.CourseName).ThenByDescending(x => x.CreateTime).ThenByDescending(x => x.ApprovalStatus).ToList();
- result.ForEach(x => x.ApprovalStatusName = statusList.FirstOrDefault(w => w.ID == x.ApprovalStatus).Name);
- return result;
- }
- /// <summary>
- /// 申请撤销成绩
- /// </summary>
- /// <param name="listUserID"></param>
- /// <param name="FinalExaminationID"></param>
- public void Rebut(List<Guid?> listUserID, Guid? FinalExaminationID)
- {
- try
- {
- //ModifyProcessState(FinalExaminationID.Value, "A", null);
- var statusList = this.GetStatusViewList();
- var endStatus = statusList.Where(x => (x.Description ?? "").Contains("[PASS]")).Select(x => x.ID).FirstOrDefault();
- var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
- var curUserID = curUser.UserID;
- var action = GetActionView(FinalExaminationID.Value, curUserID);
- var finalExamination = scoreDAL.finalExaminationRepository.GetSingle(x => x.FinalExaminationID == FinalExaminationID, (x => x.CF_Schoolyear), x => x.ER_FinalExaminationStudent);
- if (finalExamination.ApprovalStatus != endStatus)
- throw new Exception("只能选择已审核通过的成绩进行撤销");
- var queryScore = scoreDAL.ScoreRepository.GetList(x => x.FinalExaminationID == FinalExaminationID, (x => x.ER_ScoreDetail), (x => x.CF_Student.CF_Recruitstudents.CF_Schoolyear)).ToList();
- var listScore = queryScore.Where(x => x.FinalExaminationID == finalExamination.FinalExaminationID
- && !listUserID.Contains(x.UserID.Value)).ToList();
- var studentList = scoreDAL.userRepository.GetList(x => listUserID.Contains(x.UserID));
- string studentNames = "";
- var count = 0;
- foreach (Sys_User user in studentList)
- {
- studentNames = studentNames + user.Name + "、";
- count++;
- if (count > 10)
- {
- break;
- }
- }
- studentNames = studentNames.Substring(0, studentNames.Length - 1);
- string comment = "";
- if (studentList.Count() > 10)
- {
- comment = "意见:" + studentNames + "... 共" + studentList.Count() + "位学生成绩申请重录";
- }
- else
- {
- comment = "意见:" + studentNames + "共" + studentList.Count() + "位学生成绩申请重录";
- }
- foreach (var score in listScore)
- {
- //申请撤销成绩时,将ER_Score表没有勾选的数据的RecordStatus标识为false,成绩再次录入时,这些成绩不可编辑修改,只能修改申请撤销时选中的数据
- score.RecordStatus = (int)SYS_STATUS.UNUSABLE;
- score.CreateUserID = curUserID;
- score.ModifyUserID = curUserID;
- score.ModifyTime = score.CreateTime = DateTime.Now;
- }
- UnitOfWork.BatchUpdate<ER_Score>(listScore);
- //删除所勾选的提交成绩表
- var SubmitedScoreIDs = scoreDAL.GetDeleteSubmittedScore(finalExamination.FinalExaminationID, listUserID).Select(x => x.SubmitedScoreID).ToList();
- if (SubmitedScoreIDs.Count > 0)
- {
- //先刷新最终成绩在删除已提交成绩,否则会找不到最终成绩
- StudentScoreServices.Value.RefreshFinallyScoreBeforeDelete(x => SubmitedScoreIDs.Contains(x.SubmitedScoreID));
- UnitOfWork.Delete<ER_SubmitedScoreDetail>(x => SubmitedScoreIDs.Contains(x.SubmitedScoreID));
- UnitOfWork.Delete<ER_SubmitedScore>(x => SubmitedScoreIDs.Contains(x.SubmitedScoreID));
- }
- Approve(new List<Guid> { FinalExaminationID.Value }, EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID, Guid.Empty, comment);
- //UnitOfWork.Commit();
- }
- catch (Exception)
- {
- throw;
- }
- }
- /// <summary>
- /// 根据当前环节ID获取下一步审批动作
- /// </summary>
- /// <param name="formID">表单ID</param>
- /// <param name="userID">当前用户ID</param>
- /// <returns></returns>
- public List<ActionView> GetAuditingActionView(Guid formID, Guid userID)
- {
- try
- {
- List<ActionView> listAction = GetActionView(formID, userID);
- return listAction;
- }
- catch (Exception)
- {
- throw;
- }
- }
- public void SubmitedScoreDelete(Guid finalExaminationID, Guid userID)
- {
- var finalExamination = scoreDAL.finalExaminationRepository.GetList(x => x.FinalExaminationID == finalExaminationID, x => x.ER_Score).FirstOrDefault();
- if (finalExamination != null)
- {
- var userList = finalExamination.ER_Score.Select(x => x.UserID);
- UnitOfWork.Delete<ER_SubmitedScoreDetail>(x => x.ER_SubmitedScore.SchoolyearID == finalExamination.SchoolyearID
- && x.ER_SubmitedScore.CoursematerialID == finalExamination.CoursematerialID
- && x.ER_SubmitedScore.ExamsCategoryID == finalExamination.ExamsCategoryID
- && userList.Contains(x.ER_SubmitedScore.UserID));
- UnitOfWork.Delete<ER_SubmitedScore>(x => x.SchoolyearID == finalExamination.SchoolyearID
- && x.CoursematerialID == finalExamination.CoursematerialID
- && x.ExamsCategoryID == finalExamination.ExamsCategoryID
- && userList.Contains(x.UserID));
- }
- }
- /// <summary>
- /// 审核通过后执行方法
- /// </summary>
- /// <param name="finalExaminationID"></param>
- /// <param name="userID"></param>
- public void FinalExaminationApproved(List<Guid> finalExaminationIDList, Guid userID)
- {
- try
- {
- List<ER_SubmitedScore> listSubmitedScore = new List<ER_SubmitedScore>();
- List<ER_SubmitedScoreDetail> listSubmitedScoreDetail = new List<ER_SubmitedScoreDetail>();
- var finalExaminationList = scoreDAL.finalExaminationRepository.GetList(x => finalExaminationIDList.Contains(x.FinalExaminationID), (x => x.CF_Schoolyear), x => x.ER_FinalExaminationStudent).ToList();
- var queryScore = scoreDAL.ScoreRepository.GetList(x => finalExaminationIDList.Contains(x.FinalExaminationID ?? Guid.Empty)
- && x.RecordStatus > (int)EMIS.ViewModel.SYS_STATUS.UNUSABLE, (x => x.ER_ScoreDetail), (x => x.CF_Student.CF_Recruitstudents.CF_Schoolyear)).ToList();
- var userList = queryScore.Select(x => x.UserID).ToList();
- var queryFinalExaminationStudentList = scoreDAL.finalExaminationRepository.GetList(x => finalExaminationIDList.Contains(x.FinalExaminationID), (x => x.ER_FinalExaminationStudent.Select(w => w.CF_Student.CF_Classmajor.CF_Grademajor)))
- .ToList().SelectMany(x => x.ER_FinalExaminationStudent).ToList().Where(x => userList.Contains(x.UserID));
- var listUserID = queryFinalExaminationStudentList.Select(x => x.UserID).Distinct().ToList();
- var listScore = queryScore.Where(x => finalExaminationIDList.Contains(x.FinalExaminationID ?? Guid.Empty)).ToList();
- var listFinalExaminationStudentList = queryFinalExaminationStudentList.Where(x => finalExaminationIDList.Contains(x.FinalExaminationID ?? Guid.Empty)).ToList();
- using (TransactionScope ts = new TransactionScope())
- {
- //删除提交成绩表
- var SubmitedScoreIDs = scoreDAL.GetDeleteSubmittedScore(finalExaminationIDList, listUserID).Select(x => x.SubmitedScoreID).ToList();
- if (SubmitedScoreIDs.Count > 0)
- {
- UnitOfWork.Delete<ER_SubmitedScoreDetail>(x => SubmitedScoreIDs.Contains(x.SubmitedScoreID));
- UnitOfWork.Delete<ER_SubmitedScore>(x => SubmitedScoreIDs.Contains(x.SubmitedScoreID));
- }
- //UnitOfWork.Remove<ER_SubmitedScore>(x => x.SchoolyearID == finalExamination.SchoolyearID
- // && x.CoursematerialID == finalExamination.CoursematerialID
- // && x.ExamsCategoryID == finalExamination.ExamsCategoryID);
- //UnitOfWork.Commit();
- ts.Complete();
- }
- foreach (var score in listScore)
- {
- if (score.RecordStatus == (int)EMIS.ViewModel.SYS_STATUS.UNUSABLE)
- continue; //当ER_Score表RecordStatus禁用状态时,表明本次更新不更新该成绩,所以不新增或修改成绩
- var finalExaminationStudent = listFinalExaminationStudentList.Where(x => x.UserID == score.UserID && x.FinalExaminationID == score.FinalExaminationID).FirstOrDefault();
- if (finalExaminationStudent == null)
- {
- continue;
- }
- var finalExamination = finalExaminationList.FirstOrDefault(x => x.FinalExaminationID == score.FinalExaminationID);
- if (finalExamination == null)
- {
- continue;
- }
- ER_SubmitedScore submitedScore = new ER_SubmitedScore();
- submitedScore.SubmitedScoreID = Guid.NewGuid();
- submitedScore.SchoolyearID = finalExamination.SchoolyearID;
- submitedScore.SchoolyearNumID = finalExaminationStudent.SchoolyearNumID;
- submitedScore.FinalExaminationID = finalExamination.FinalExaminationID;
- submitedScore.DepartmentID = finalExamination.DepartmentID;
- submitedScore.ClassName = finalExamination.ClassName;
- submitedScore.CoursematerialID = finalExamination.CoursematerialID;
- submitedScore.CourseTypeID = finalExamination.CourseTypeID;
- submitedScore.ExamsCategoryID = finalExamination.ExamsCategoryID;
- submitedScore.ExaminationModeID = finalExamination.ExaminationModeID;
- submitedScore.Credit = finalExamination.Credit;
- submitedScore.ExamsDatetime = finalExamination.ExamsDatetime;
- submitedScore.ResultTypeID = finalExamination.ResultTypeID;
- submitedScore.CreatorUserID = finalExamination.CreatorUserID;
- submitedScore.EntryDeadlineTime = finalExamination.EntryDeadlineTime;
- submitedScore.IsEntry = finalExamination.IsEntry;
- submitedScore.ExaminationType = finalExamination.ExaminationType;
- submitedScore.StarttermID = finalExaminationStudent.StarttermID;
- submitedScore.UserID = score.UserID;
- submitedScore.ExamsStateID = score.ExamsStateID;
- submitedScore.TotalScore = score.TotalScore;
- submitedScore.ScoreCredit = score.Credit;
- submitedScore.GradePoint = score.GradePoint;
- submitedScore.Remark = score.Remark;
- //在期末设定、已提交成绩、最终成绩增加总学时字段,已提交成绩总学时来源于期末设定
- submitedScore.TotalHours = finalExamination.TotalHours;
- SetNewStatus(submitedScore);
- listSubmitedScore.Add(submitedScore);
- //详细表
- foreach (var scoreDetail in score.ER_ScoreDetail)
- {
- //已提交成绩录入分数表
- ER_SubmitedScoreDetail submitedScoreDetail = new ER_SubmitedScoreDetail();
- submitedScoreDetail.SubmitedScoreDetailID = Guid.NewGuid();
- submitedScoreDetail.SubmitedScoreID = submitedScore.SubmitedScoreID;
- submitedScoreDetail.ScoreTypeID = scoreDetail.ScoreTypeID;
- submitedScoreDetail.Score = scoreDetail.Score;
- SetNewStatus(submitedScoreDetail);
- listSubmitedScoreDetail.Add(submitedScoreDetail);
- }
- }
- //query.ForEach(x => x.ApprovalStatus = approvalStatus);
- //query.ForEach(x => x.Remark = opinioncomment);
- UnitOfWork.BulkInsert(listSubmitedScore);
- UnitOfWork.BulkInsert(listSubmitedScoreDetail);
- StudentScoreServices.Value.RefreshFinallyScoreBySubmitedScoreID(listSubmitedScore.Select(x => x.SubmitedScoreID).ToList());
- //当成绩更新完时,ER_Score表RecordStatus恢复可用状态,因为RecordStatus只用于标识本次不更新该成绩
- UnitOfWork.Update<ER_Score>(x => new ER_Score { RecordStatus = (int)EMIS.ViewModel.SYS_STATUS.USABLE }, x => finalExaminationIDList.Contains(x.FinalExaminationID ?? Guid.Empty));
- //UnitOfWork.Commit();
- }
- catch (Exception)
- {
- throw;
- }
- }
- /// <summary>
- /// 审核不同意撤销成绩后执行方法
- /// </summary>
- /// <param name="finalExaminationIDList"></param>
- /// <param name="userID"></param>
- //public void FinalExaminationRebutDisAgree(Guid finalExaminationID, Guid userID)
- //{
- // try
- // {
- // var queryScore = scoreDAL.scoreRepository.GetList(x => x.FinalExaminationID == finalExaminationID, (x => x.ER_ScoreDetail), (x => x.CF_Student.CF_Recruitstudents.CF_Schoolyear)).ToList();
- // //当不同意撤销成绩时,ER_Score表RecordStatus恢复可用状态,因为RecordStatus用于标识撤销成绩时不更新的成绩
- // queryScore.ForEach(x => x.RecordStatus = (int)EMIS.ViewModel.SYS_STATUS.USABLE);
- // UnitOfWork.Commit();
- // }
- // catch (Exception)
- // {
- // throw;
- // }
- //}
- // 申请撤销成绩时驳回后执行方法
- public void FinalExaminationRebutDisAgree(List<Guid> finalExaminationIDList, Guid userID)
- {
- try
- {
- this.FinalExaminationApproved(finalExaminationIDList, userID);
- }
- catch (Exception)
- {
- throw;
- }
- }
- ///// <summary>
- ///// 审核
- ///// </summary>
- ///// <param name="listFinalExaminationID"></param>
- ///// <param name="approvalStatus"></param>
- //public void GetFinalExaminationApprovalStatus(List<Guid> listFinalExaminationID, int? approvalStatus, string opinioncomment)
- //{
- // try
- // {
- // List<ER_SubmitedScore> listSubmitedScore = new List<ER_SubmitedScore>();
- // List<ER_SubmitedScoreDetail> listSubmitedScoreDetail = new List<ER_SubmitedScoreDetail>();
- // var query = scoreDAL.finalExaminationRepository.GetList(x => listFinalExaminationID.Contains(x.FinalExaminationID), (x => x.CF_Schoolyear)).ToList();
- // var schoolyearIDs = query.Select(x => x.SchoolyearID).ToList(); //获取学年学期
- // var coursematerialIDs = query.Select(x => x.CoursematerialID).ToList(); //获取课程
- // var queryScore = scoreDAL.scoreRepository.GetList(x => listFinalExaminationID.Contains((Guid)x.FinalExaminationID), (x => x.ER_ScoreDetail), (x => x.CF_Student.CF_Recruitstudents.CF_Schoolyear)).ToList();
- // var queryFinalExaminationStudentList = scoreDAL.finalExaminationRepository.GetList(x => listFinalExaminationID.Contains((Guid)x.FinalExaminationID), (x => x.ER_FinalExaminationStudent.Select(w => w.CF_Student.CF_Classmajor.CF_Grademajor)))
- // .ToList().SelectMany(x => x.ER_FinalExaminationStudent).ToList();
- // var userIDs = queryScore.Select(x => x.UserID).ToList();
- // foreach (var finalExamination in query)
- // {
- // var listScore = queryScore.Where(x => x.FinalExaminationID == finalExamination.FinalExaminationID).ToList();
- // var listFinalExaminationStudentList = queryFinalExaminationStudentList.Where(x => x.FinalExaminationID == finalExamination.FinalExaminationID).ToList();
- // if (approvalStatus == (int)EMIS.ViewModel.CF_ScoreState.Approved)
- // {
- // foreach (var score in listScore)
- // {
- // var finalExaminationStudent = listFinalExaminationStudentList.Where(x => x.UserID == score.UserID).FirstOrDefault();
- // if (finalExaminationStudent == null)
- // {
- // continue;
- // }
- // //已提交成绩
- // ER_SubmitedScore submitedScore = new ER_SubmitedScore();
- // submitedScore.SubmitedScoreID = Guid.NewGuid();
- // submitedScore.SchoolyearID = finalExamination.SchoolyearID;
- // submitedScore.SchoolyearNumID = finalExaminationStudent.SchoolyearNumID;
- // submitedScore.DepartmentID = finalExamination.DepartmentID;
- // submitedScore.ClassName = finalExamination.ClassName;
- // submitedScore.CoursematerialID = finalExamination.CoursematerialID;
- // submitedScore.CourseTypeID = finalExamination.CourseTypeID;
- // submitedScore.ExamsCategoryID = finalExamination.ExamsCategoryID;
- // submitedScore.ExaminationModeID = finalExamination.ExaminationModeID;
- // submitedScore.Credit = finalExamination.Credit;
- // submitedScore.ExamsDatetime = finalExamination.ExamsDatetime;
- // submitedScore.ResultTypeID = finalExamination.ResultTypeID;
- // submitedScore.CreatorUserID = finalExamination.CreatorUserID;
- // submitedScore.EntryDeadlineTime = finalExamination.EntryDeadlineTime;
- // submitedScore.IsEntry = finalExamination.IsEntry;
- // submitedScore.ExaminationType = finalExamination.ExaminationType;
- // submitedScore.StarttermID = finalExaminationStudent.StarttermID;
- // submitedScore.UserID = score.UserID;
- // submitedScore.ExamsStateID = score.ExamsStateID;
- // submitedScore.TotalScore = score.TotalScore;
- // submitedScore.ScoreCredit = score.Credit;
- // submitedScore.GradePoint = score.GradePoint;
- // submitedScore.Remark = score.Remark;
- // SetNewStatus(submitedScore);
- // listSubmitedScore.Add(submitedScore); //已提交成绩
- // //详细表
- // foreach (var scoreDetail in score.ER_ScoreDetail)
- // {
- // //已提交成绩录入分数表
- // ER_SubmitedScoreDetail submitedScoreDetail = new ER_SubmitedScoreDetail();
- // submitedScoreDetail.SubmitedScoreDetailID = Guid.NewGuid();
- // submitedScoreDetail.SubmitedScoreID = submitedScore.SubmitedScoreID;
- // submitedScoreDetail.ScoreTypeID = scoreDetail.ScoreTypeID;
- // submitedScoreDetail.Score = scoreDetail.Score;
- // SetNewStatus(submitedScoreDetail);
- // listSubmitedScoreDetail.Add(submitedScoreDetail);
- // }
- // }
- // }
- // }
- // query.ForEach(x => x.ApprovalStatus = approvalStatus);
- // query.ForEach(x => x.Remark = opinioncomment);
- // UnitOfWork.BulkInsert(listSubmitedScore);
- // UnitOfWork.BulkInsert(listSubmitedScoreDetail);
- // foreach (var finalExamination in query)
- // {
- // var userList = queryScore.Where(x => x.FinalExaminationID == finalExamination.FinalExaminationID).Select(x => x.UserID).ToList();
- // StudentScoreServices.Value.RefreshFinallyScore(finalExamination.CoursematerialID ?? Guid.Empty, userList, null);
- // }
- // UnitOfWork.Commit();
- // }
- // catch (Exception)
- // {
- // throw;
- // }
- //}
- public void RefreshExaminationSuspensionState(IList<Guid> examinationSuspensionIDList)
- {
- var suspensionID = ExamsStateSettingDAL.GetExaminationSuspensionID();
- var statusList = this.GetStatusViewList(); //获取工作流列表
- //审核中的数据(节点的Description为[AP])和end的节点不能修改
- var approvedFinalExaminationState = statusList.Where(x => (x.Description ?? "").Contains("[AP]") && (x.Description ?? "").Contains("[PASS]")).Select(x => x.ID).ToList();
- //List<int?> approvedFinalExaminationState = new List<int?> { (int)CF_ScoreState.Approved, (int)CF_ScoreState.Submitted };
- var submitedFinalExaminationList = this.scoreDAL.GetFinalExaminationByExaminationSuspension(
- (x => examinationSuspensionIDList.Contains(x.ExaminationSuspensionID)),
- (x => approvedFinalExaminationState.Contains(x.ApprovalStatus))
- ).ToList();
- if (submitedFinalExaminationList.Count > 0)
- {
- throw new Exception("该课程的期末考试成绩已经提交,无法更新缓考状态。");
- }
- var scoreList = this.scoreDAL.GetScoreByExaminationSuspension((x => examinationSuspensionIDList.Contains(x.ExaminationSuspensionID)))
- .Include(x => x.ER_ScoreDetail).ToList();
-
- foreach (var score in scoreList)
- {
- score.ExamsStateID = suspensionID;
- score.TotalScore = null;
- score.Credit = null;
- score.GradePoint = null;
- foreach (var detail in score.ER_ScoreDetail)
- {
- detail.Score = null;
- }
- }
- this.UnitOfWork.Commit();
- }
- public void RefreshCancelExaminationSuspensionState(IList<Guid> examinationSuspensionIDList)
- {
- var normalStateID = ExamsStateSettingDAL.GetNormalID();
- List<int?> approvedFinalExaminationState = new List<int?> { (int)CF_ScoreState.Approved, (int)CF_ScoreState.Submitted };
- var submitedFinalExaminationList = this.scoreDAL.GetFinalExaminationByExaminationSuspension(
- (x => examinationSuspensionIDList.Contains(x.ExaminationSuspensionID)),
- (x => approvedFinalExaminationState.Contains(x.ApprovalStatus))
- ).ToList();
- if (submitedFinalExaminationList.Count > 0)
- {
- throw new Exception("该课程的期末考试成绩已经提交,无法更新缓考状态。");
- }
- var scoreList = this.scoreDAL.GetScoreByExaminationSuspension((x => examinationSuspensionIDList.Contains(x.ExaminationSuspensionID)))
- .Include(x => x.ER_ScoreDetail).ToList();
-
- foreach (var score in scoreList)
- {
- score.ExamsStateID = normalStateID;
- score.TotalScore = null;
- score.Credit = null;
- score.GradePoint = null;
- foreach (var detail in score.ER_ScoreDetail)
- {
- detail.Score = null;
- }
- }
- this.UnitOfWork.Commit();
- }
- public void RefreshExaminationExemptionState(IList<Guid> examinationExemptionIDList)
- {
- var exemptionID = ExamsStateSettingDAL.GetExaminationExemptionID();
- var scoreList = this.scoreDAL.GetScoreByExaminationExemption(x => examinationExemptionIDList.Contains(x.ExaminationExemptionID))
- .Include(x => x.ER_ScoreDetail)
- .Include(x => x.ER_FinalExamination)
- .Include(x => x.ER_FinalExamination.ER_FinalExaminationStudent).ToList();
- var submitedScoreList = this.StudentScoreDAL.GetSubmitedScoreByExaminationExemption(x => examinationExemptionIDList.Contains(x.ExaminationExemptionID))
- .Include(x => x.ER_SubmitedScoreDetail).ToList();
- foreach (var score in scoreList)
- {
- score.ExamsStateID = exemptionID;
- score.TotalScore = null;
- score.Credit = null;
- score.GradePoint = null;
- foreach (var detail in score.ER_ScoreDetail)
- {
- detail.Score = null;
- }
- var finalExaminationStudent = score.ER_FinalExamination.ER_FinalExaminationStudent.FirstOrDefault(x => x.UserID == score.UserID);
- if (finalExaminationStudent != null)
- {
- var submittedScore = submitedScoreList.FirstOrDefault(x => x.CoursematerialID == score.ER_FinalExamination.CoursematerialID
- && x.UserID == score.UserID && x.StarttermID == finalExaminationStudent.StarttermID);
- if (submittedScore != null)
- {
- submittedScore.ExamsStateID = exemptionID;
- submittedScore.TotalScore = null;
- submittedScore.Credit = null;
- submittedScore.GradePoint = null;
- foreach (var submitedScoreDetail in submittedScore.ER_SubmitedScoreDetail)
- {
- submitedScoreDetail.Score = null;
- }
- }
- }
- }
- this.UnitOfWork.Commit();
- var submitedScoreIDList = submitedScoreList.Select(x => x.SubmitedScoreID).ToList();
- this.StudentScoreServices.Value.RefreshFinallyScoreBySubmitedScoreID(submitedScoreIDList);
- this.UnitOfWork.Commit();
- }
- public void RefreshCancelExaminationExemptionState(IList<Guid> examinationExemptionIDList)
- {
- var normalStateID = ExamsStateSettingDAL.GetNormalID();
- var scoreList = this.scoreDAL.GetScoreByExaminationExemption(x => examinationExemptionIDList.Contains(x.ExaminationExemptionID))
- .Include(x => x.ER_ScoreDetail)
- .Include(x => x.ER_FinalExamination)
- .Include(x => x.ER_FinalExamination.ER_FinalExaminationStudent).ToList();
- var submitedScoreList = this.StudentScoreDAL.GetSubmitedScoreByExaminationExemption(x => examinationExemptionIDList.Contains(x.ExaminationExemptionID))
- .Include(x => x.ER_SubmitedScoreDetail).ToList();
-
- foreach (var score in scoreList)
- {
- score.ExamsStateID = normalStateID;
- score.TotalScore = null;
- score.Credit = null;
- score.GradePoint = null;
- foreach (var detail in score.ER_ScoreDetail)
- {
- detail.Score = null;
- }
- var finalExaminationStudent = score.ER_FinalExamination.ER_FinalExaminationStudent.FirstOrDefault(x => x.UserID == score.UserID);
- if (finalExaminationStudent != null)
- {
- var submittedScore = submitedScoreList.FirstOrDefault(x => x.CoursematerialID == score.ER_FinalExamination.CoursematerialID
- && x.UserID == score.UserID && x.StarttermID == finalExaminationStudent.StarttermID);
- if (submittedScore != null)
- {
- submittedScore.ExamsStateID = normalStateID;
- submittedScore.TotalScore = null;
- submittedScore.Credit = null;
- submittedScore.GradePoint = null;
- foreach (var submitedScoreDetail in submittedScore.ER_SubmitedScoreDetail)
- {
- submitedScoreDetail.Score = null;
- }
- }
- }
- }
- this.UnitOfWork.Commit();
- var submitedScoreIDList = submitedScoreList.Select(x => x.SubmitedScoreID).ToList();
- this.StudentScoreServices.Value.RefreshFinallyScoreBySubmitedScoreID(submitedScoreIDList);
- this.UnitOfWork.Commit();
- }
- #region 免修刷成绩注释
- //public void RefreshExaminationExemptionState(IList<Guid> examinationExemptionIDList)
- //{
- // var exemptionID = ExamsStateSettingDAL.GetExaminationExemptionID();
- // var exemptionScore = ExamsStateSettingDAL.GetExemptionScore();
- // var scoreList = this.scoreDAL.GetScoreByExaminationExemption(x => examinationExemptionIDList.Contains(x.ExaminationExemptionID))
- // .Include(x => x.ER_ScoreDetail)
- // .Include(x => x.ER_FinalExamination)
- // .Include(x => x.ER_FinalExamination.ER_FinalExaminationStudent).ToList();
- // var submitedScoreList = this.StudentScoreDAL.GetSubmitedScoreByExaminationExemption(x => examinationExemptionIDList.Contains(x.ExaminationExemptionID))
- // .Include(x => x.ER_SubmitedScoreDetail).ToList();
- // if (scoreList.Count > 0)
- // {
- // foreach (var score in scoreList)
- // {
- // score.ExamsStateID = exemptionID;
- // score.TotalScore = null;
- // score.Credit = null;
- // score.GradePoint = null;
- // foreach (var detail in score.ER_ScoreDetail)
- // {
- // detail.Score = null;
- // }
- // var finalExaminationStudent = score.ER_FinalExamination.ER_FinalExaminationStudent.FirstOrDefault(x => x.UserID == score.UserID);
- // if (finalExaminationStudent != null)
- // {
- // var submittedScore = submitedScoreList.FirstOrDefault(x => x.CoursematerialID == score.ER_FinalExamination.CoursematerialID
- // && x.UserID == score.UserID && x.StarttermID == finalExaminationStudent.StarttermID);
- // if (submittedScore != null)
- // {
- // submittedScore.ExamsStateID = exemptionID;
- // submittedScore.TotalScore = null;
- // submittedScore.Credit = null;
- // submittedScore.GradePoint = null;
- // foreach (var submitedScoreDetail in submittedScore.ER_SubmitedScoreDetail)
- // {
- // submitedScoreDetail.Score = null;
- // }
- // }
- // }
- // }
- // this.UnitOfWork.Commit();
- // var submitedScoreIDList = submitedScoreList.Select(x => x.SubmitedScoreID).ToList();
- // this.StudentScoreServices.Value.RefreshFinallyScoreBySubmitedScoreID(submitedScoreIDList);
- // this.UnitOfWork.Commit();
- // }
- // else
- // {
- // List<ER_SubmitedScore> listSubmitedScore = new List<ER_SubmitedScore>();
- // List<ER_SubmitedScoreDetail> listSubmitedScoreDetail = new List<ER_SubmitedScoreDetail>();
- // //查询该课程来源是否为期末设定
- // var examinationExemptionFromFinalExamination = scoreDAL.GetExaminationExemptionFromFinalExamination(x => examinationExemptionIDList.Contains(x.ExaminationExemptionID)).FirstOrDefault();
- // var examinationExemptionFromEducationMission = scoreDAL.GetExaminationExemptionFromFinalExamination(x => examinationExemptionIDList.Contains(x.ExaminationExemptionID)).FirstOrDefault();
- // if (examinationExemptionFromFinalExamination != null)
- // {
- // List<Guid> SubmitedScoreIDList = new List<Guid>();
- // var GradePoint = this.StudentScoreServices.Value.GetGradePoint(examinationExemptionFromFinalExamination.CollegeID, examinationExemptionFromFinalExamination.GradeYearID, examinationExemptionFromFinalExamination.ExamsCategoryID, examinationExemptionFromFinalExamination.CourseTypeID, exemptionScore);
- // ER_SubmitedScore submitedScore = new ER_SubmitedScore();
- // submitedScore.SubmitedScoreID = Guid.NewGuid();
- // submitedScore.SchoolyearID = examinationExemptionFromFinalExamination.SchoolyearID;
- // submitedScore.SchoolyearNumID = examinationExemptionFromFinalExamination.SchooolYearNumID;
- // submitedScore.FinalExaminationID = examinationExemptionFromFinalExamination.FinalExaminationID;
- // submitedScore.DepartmentID = examinationExemptionFromFinalExamination.DepartmentID;
- // submitedScore.ClassName = examinationExemptionFromFinalExamination.ClassName;
- // submitedScore.CoursematerialID = examinationExemptionFromFinalExamination.CoursematerialID;
- // submitedScore.CourseTypeID = examinationExemptionFromFinalExamination.CourseTypeID;
- // submitedScore.ExamsCategoryID = examinationExemptionFromFinalExamination.ExamsCategoryID;
- // submitedScore.ExaminationModeID = examinationExemptionFromFinalExamination.ExaminationModeID;
- // submitedScore.Credit = examinationExemptionFromFinalExamination.Credit;
- // submitedScore.ExamsDatetime = examinationExemptionFromFinalExamination.ExamsDatetime;
- // submitedScore.ResultTypeID = examinationExemptionFromFinalExamination.ResultTypeID;
- // submitedScore.CreatorUserID = examinationExemptionFromFinalExamination.CreatorUserID;
- // submitedScore.EntryDeadlineTime = examinationExemptionFromFinalExamination.EntryDeadlineTime;
- // submitedScore.IsEntry = examinationExemptionFromFinalExamination.IsEntry;
- // submitedScore.ExaminationType = examinationExemptionFromFinalExamination.ExaminationType;
- // submitedScore.StarttermID = examinationExemptionFromFinalExamination.StarttermID;
- // submitedScore.UserID = examinationExemptionFromFinalExamination.UserID;
- // submitedScore.ExamsStateID = exemptionID;
- // submitedScore.TotalScore = exemptionScore;
- // submitedScore.ScoreCredit = examinationExemptionFromFinalExamination.Credit;
- // submitedScore.GradePoint = GradePoint;
- // submitedScore.Remark = null;
- // //在期末设定、已提交成绩、最终成绩增加总学时字段,已提交成绩总学时来源于期末设定
- // submitedScore.TotalHours = examinationExemptionFromFinalExamination.TotalHours;
- // SetNewStatus(submitedScore);
- // listSubmitedScore.Add(submitedScore);
- // var scoreDynamicTypes = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ScoreType);
- // //详细表
- // foreach (var scoreDetail in scoreDynamicTypes)
- // {
- // //已提交成绩录入分数表
- // ER_SubmitedScoreDetail submitedScoreDetail = new ER_SubmitedScoreDetail();
- // submitedScoreDetail.SubmitedScoreDetailID = Guid.NewGuid();
- // submitedScoreDetail.SubmitedScoreID = submitedScore.SubmitedScoreID;
- // submitedScoreDetail.ScoreTypeID = scoreDetail.Value;
- // submitedScoreDetail.Score = null;
- // SetNewStatus(submitedScoreDetail);
- // listSubmitedScoreDetail.Add(submitedScoreDetail);
- // }
- // SubmitedScoreIDList.Add(submitedScore.SubmitedScoreID);
- // UnitOfWork.BulkInsert(listSubmitedScore);
- // UnitOfWork.BulkInsert(listSubmitedScoreDetail);
- // this.UnitOfWork.Commit();
- // this.StudentScoreServices.Value.RefreshFinallyScoreBySubmitedScoreID(SubmitedScoreIDList);
- // }
- // //查询该课程来源是否为教学任务
- // //查询该课程来源是否为执行计划
- // }
- //}
- #endregion
- public void RefreshMisconductState(IList<Guid> misconductIDList)
- {
- var scoreList = this.scoreDAL.GetScoreByMisconduct(x => misconductIDList.Contains(x.MisconductID))
- .Include(x => x.ER_ScoreDetail)
- .Include(x => x.ER_FinalExamination)
- .Include(x => x.ER_FinalExamination.ER_FinalExaminationStudent).ToList();
- var misconductViewList = this.MisconductDAL.GetMisconductViewQueryable(x => misconductIDList.Contains(x.MisconductID)).ToList();
- var submitedScoreList = this.StudentScoreDAL.GetSubmitedScoreByMisconduct(x => misconductIDList.Contains(x.MisconductID))
- .Include(x => x.ER_SubmitedScoreDetail).ToList();
-
- foreach (var score in scoreList)
- {
- var finalExamination = score.ER_FinalExamination;
- var misconductView = misconductViewList.FirstOrDefault(x => x.SchoolyearID == finalExamination.SchoolyearID
- && x.CoursematerialID == finalExamination.CoursematerialID && x.ExamsCategoryID == finalExamination.ExamsCategoryID
- && x.UserID == score.UserID);
- score.ExamsStateID = misconductView.ExamsStateID;
- score.TotalScore = null;
- score.Credit = null;
- score.GradePoint = null;
- foreach (var detail in score.ER_ScoreDetail)
- {
- detail.Score = null;
- }
- var finalExaminationStudent = score.ER_FinalExamination.ER_FinalExaminationStudent.FirstOrDefault(x => x.UserID == score.UserID);
- if (finalExaminationStudent != null)
- {
- var submittedScore = submitedScoreList.FirstOrDefault(x => x.CoursematerialID == misconductView.CoursematerialID
- && x.UserID == misconductView.UserID && x.StarttermID == finalExaminationStudent.StarttermID);
- if (submittedScore != null)
- {
- submittedScore.ExamsStateID = misconductView.ExamsStateID;
- submittedScore.TotalScore = null;
- submittedScore.Credit = null;
- submittedScore.GradePoint = null;
- foreach (var submitedScoreDetail in submittedScore.ER_SubmitedScoreDetail)
- {
- submitedScoreDetail.Score = null;
- }
- }
- }
- }
- this.UnitOfWork.Commit();
- var submitedScoreIDList = submitedScoreList.Select(x => x.SubmitedScoreID).ToList();
- this.StudentScoreServices.Value.RefreshFinallyScoreBySubmitedScoreID(submitedScoreIDList);
- this.UnitOfWork.Commit();
- }
- public void RefreshCancelMisconductState(IList<Guid> misconductIDList)
- {
- var normalStateID = ExamsStateSettingDAL.GetNormalID();
- var scoreList = this.scoreDAL.GetScoreByMisconduct(x => misconductIDList.Contains(x.MisconductID))
- .Include(x => x.ER_ScoreDetail)
- .Include(x => x.ER_FinalExamination)
- .Include(x => x.ER_FinalExamination.ER_FinalExaminationStudent).ToList();
- var misconductViewList = this.MisconductDAL.GetMisconductViewQueryable(x => misconductIDList.Contains(x.MisconductID)).ToList();
- var submitedScoreList = this.StudentScoreDAL.GetSubmitedScoreByMisconduct(x => misconductIDList.Contains(x.MisconductID))
- .Include(x => x.ER_SubmitedScoreDetail).ToList();
- foreach (var score in scoreList)
- {
- score.ExamsStateID = normalStateID;
- score.TotalScore = null;
- score.Credit = null;
- score.GradePoint = null;
- foreach (var detail in score.ER_ScoreDetail)
- {
- detail.Score = null;
- }
- var finalExaminationStudent = score.ER_FinalExamination.ER_FinalExaminationStudent.FirstOrDefault(x => x.UserID == score.UserID);
- if (finalExaminationStudent != null)
- {
- var submittedScore = submitedScoreList.FirstOrDefault(x => x.CoursematerialID == score.ER_FinalExamination.CoursematerialID
- && x.UserID == score.UserID && x.StarttermID == finalExaminationStudent.StarttermID);
- if (submittedScore != null)
- {
- submittedScore.ExamsStateID = normalStateID;
- submittedScore.TotalScore = null;
- submittedScore.Credit = null;
- submittedScore.GradePoint = null;
- foreach (var submitedScoreDetail in submittedScore.ER_SubmitedScoreDetail)
- {
- submitedScoreDetail.Score = null;
- }
- }
- }
- }
- this.UnitOfWork.Commit();
- var submitedScoreIDList = submitedScoreList.Select(x => x.SubmitedScoreID).ToList();
- this.StudentScoreServices.Value.RefreshFinallyScoreBySubmitedScoreID(submitedScoreIDList);
- this.UnitOfWork.Commit();
- }
- private List<string> GetImportColumns()
- {
- List<string> cellheader = new List<string>
- {
- "学号", "姓名", "考试性质"
- };
- var scoreTypeList = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ScoreType);
- scoreTypeList.ForEach(x => {
- cellheader.Add(x.Name);
- });
- return cellheader;
- }
- private void CheckColumns(List<string> cellheader, DataTable data)
- {
- List<string> missColumn = new List<string>();
- cellheader.ForEach(x =>
- {
- if (data.Columns.IndexOf(x) < 0)
- {
- missColumn.Add(x);
- }
- });
- if (missColumn.Count > 0)
- {
- throw new Exception("导入模板中缺少" + string.Join("、", missColumn) + "列的信息。");
- }
- }
- private object[] GetErrorMessageData(int rowIndex, DataRow row, string message)
- {
- var result = row.ItemArray;
- result = (new object[] { (object)(rowIndex + 1) })
- .Concat(result)
- .Concat(new object[] { (object)("第" + (rowIndex + 1).ToString() + "行数据错误:" + message) }).ToArray();
- return result;
- }
- private IEnumerable<string> GetErrorCellHeader(IList<string> cellheader)
- {
- return new List<string> { "行号" }
- .Concat(cellheader)
- .Concat(new List<string> { "错误提示" });
- }
- private DataTable CheckValues(IList<string> cellheader, DataTable data,
- IList<Sys_User> userList, IList<Guid?> examStudentList, IList<StudentScoreImportView> correctList)
- {
- var errorColumnList = GetErrorCellHeader(cellheader);
- var scoreTypeList = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ScoreType);
- var errorTable = new DataTable();
- errorColumnList.ForEach(x => errorTable.Columns.Add(x));
- List<object[]> errorStack = new List<object[]>();
- var dupRows = data.AsEnumerable()
- .GroupBy(key => key.Field<string>("学号"))
- .Where(w => w.Count() > 1)
- .SelectMany(s => s)
- .ToArray();
- for (int i = data.Rows.Count - 1; i >= 0; i--)
- {
- DataRow row = data.Rows[i];
- var allNull = true;
- var rowErrorMessage = "";
- foreach (var columnName in cellheader)
- {
- if (!string.IsNullOrEmpty(row[columnName] as string))
- {
- allNull = false;
- }
- }
- if (allNull)
- {
- continue;
- }
- var importRow = new StudentScoreImportView();
- var loginID = row["学号"] as string;
- var userName = row["姓名"] as string;
- if (string.IsNullOrEmpty(loginID))
- {
- rowErrorMessage += "学号不能为空;";
- }
- else
- {
- if (dupRows.Any(x => x.Field<string>("学号") == loginID))
- {
- rowErrorMessage += "学号重复;";
- }
- var user = userList.FirstOrDefault(x => x.LoginID == loginID);
- if (user == null)
- {
- rowErrorMessage += "系统中找不到对应的学生;";
- }
- else if (!examStudentList.Contains(user.UserID))
- {
- rowErrorMessage += "该学号不存在当前录入班级,请检查;";
- }
- else
- {
- importRow.LoginID = loginID;
- importRow.UserName = userName;
- importRow.UserID = user.UserID;
- }
- }
- importRow.ScoreDetail = new Dictionary<int?, decimal?>();
- scoreTypeList.ForEach(x =>
- {
- var score = row[x.Name];
- if (score == null || score.ToString().Trim() == "")
- {
- importRow.ScoreDetail.Add(x.Value, null);
- }
- else if (!Regex.IsMatch(score.ToString(), @"^\d+(\.\d{1,2})?$"))
- {
- rowErrorMessage += x.Name + "必须为保留最多两位小数的数字;";
- }
- else
- {
- importRow.ScoreDetail.Add(x.Value, Convert.ToDecimal(score));
- }
- });
- if (!string.IsNullOrEmpty(rowErrorMessage))
- {
- errorStack.Add(this.GetErrorMessageData(i, row, rowErrorMessage));
- }
- else
- {
- correctList.Add(importRow);
- }
- }
- errorStack.OrderBy(x => x[0]).ForEach(x => errorTable.Rows.Add(x));
- return errorTable;
- }
- private string WriteErrorFile(NpoiExcelHelper excel, IEnumerable<string> errorCellheader, DataTable errorTable)
- {
- var errorExcelBuff = excel.ExportMemoryStream(errorTable, "", errorCellheader.ToArray());
- var logicalPath = Const.LOCAL_SETTING_UPLOAD_FILEPATH + "/" + Guid.NewGuid().ToString() + ".xls";
- var physicalPath = HttpContext.Current.Server.MapPath(logicalPath);
- var fs = File.Create(physicalPath);
- fs.Write(errorExcelBuff, 0, errorExcelBuff.Length);
- fs.Flush();
- fs.Close();
- return UrlHelper.GenerateContentUrl(logicalPath, HttpContext.Current.Request.RequestContext.HttpContext);
- }
- public ExcelImportResult ScoreImport(string filePath, Guid? finalExaminationID)
- {
- var result = new ExcelImportResult();
- var excel = new NpoiExcelHelper();
- List<string> cellheader = GetImportColumns();
- var dt = excel.ImpotColumns(filePath);
- System.IO.File.Delete(filePath);//删除本地缓存文件
- this.CheckColumns(cellheader, dt);
- #region 准备校验数据
- var loginIDList = dt.AsEnumerable().Select(x => x.Field<string>("学号")).Distinct();
- var userList = this.ImportScoreDAL.UserRepository.GetList(x => loginIDList.Contains(x.LoginID)).ToList();
- var examStudentList = this.FinalExaminationStudentRepository.GetList(x => x.FinalExaminationID == finalExaminationID)
- .Select(x => x.UserID).ToList();
- #endregion
- var correctList = new List<StudentScoreImportView>();
- var errorTable = this.CheckValues(cellheader, dt, userList, examStudentList, correctList);
- result.SuccessCount = correctList.Count;
- result.ErrorCount = errorTable.Rows.Count;
- if (errorTable.Rows.Count > 0)
- {
- result.IsAllSuccess = false;
- var errorCellHeader = this.GetErrorCellHeader(cellheader).ToArray();
- result.ErrorFilePath = this.WriteErrorFile(excel, this.GetErrorCellHeader(cellheader), errorTable);
- result.Message = string.Format("导入失败,详情请点击错误数据下载查看。");
- }
- else
- {
- result.IsAllSuccess = true;
- result.Data = correctList;
- }
- return result;
- }
- public int? GetNormalExamsID()
- {
- return this.ExamsStateSettingDAL.GetNormalID();
- }
- public int? GetExaminationSuspensionID()
- {
- return this.ExamsStateSettingDAL.GetExaminationSuspensionID();
- }
- public int? GetExaminationExemptionID()
- {
- return this.ExamsStateSettingDAL.GetExaminationExemptionID();
- }
- public List<int?> GetMisconductIDList()
- {
- return this.ExamsStateSettingDAL.GetMisconductIDList();
- }
- public List<ER_ResultTypeDetail> GetScoreType(Guid? finalExaminationIDs)
- {
- var finalExamination=scoreDAL.finalExaminationRepository.Entities.Where(x => x.FinalExaminationID == finalExaminationIDs).FirstOrDefault();
- return scoreDAL.ResultTypeDetailRepository.GetList(x=>x.ResultTypeID==finalExamination.ResultTypeID).ToList();
- }
- public List<ER_ExamsStateSetting> GetExamsStateSettingList()
- {
- return this.ExamsStateSettingDAL.ExamsStateSettingRepository.Entities.ToList();
- }
- public List<ER_ScoreFormula> GetScoreFormulaList()
- {
- var query = ScoreFormulaRepository.Entities.ToList();
- return query;
-
- }
- }
- }
|