123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Linq.Expressions;
- using System.Text.RegularExpressions;
- using Bowin.Common.Linq;
- using Bowin.Common.Linq.Entity;
- using Bowin.Common.Exceptions;
- using Bowin.Common.Utility;
- using EMIS.Entities;
- using EMIS.ViewModel;
- using EMIS.ViewModel.CacheManage;
- using EMIS.ViewModel.Cultureplan;
- using EMIS.DataLogic.Repositories;
- using EMIS.DataLogic.Common.Cultureplan;
- using EMIS.CommonLogic.EducationManagement;
- namespace EMIS.CommonLogic.Cultureplan
- {
- public class CoursematerialServices : BaseServices, ICoursematerialServices
- {
- public CoursematerialDAL CoursematerialDAL { get; set; }
- /// <summary>
- /// 查询课程信息CoursematerialView
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="courseLevelID"></param>
- /// <param name="courseScienceID"></param>
- /// <param name="classGroupingID"></param>
- /// <param name="isEnable"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <returns></returns>
- public IGridResultSet<CoursematerialView> GetCoursematerialViewGrid(ConfiguretView configuretView, int? courseLevelID, int? courseScienceID,
- Guid? classGroupingID, int? isEnable, int pageIndex, int pageSize)
- {
- //课程信息
- Expression<Func<EM_Coursematerial, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (courseLevelID.HasValue)
- {
- exp = exp.And(x => x.CourseLevelID == courseLevelID);
- }
- if (courseScienceID.HasValue)
- {
- exp = exp.And(x => x.CourseScienceID == courseScienceID);
- }
- if (classGroupingID.HasValue)
- {
- exp = exp.And(x => x.ClassGroupingID == classGroupingID);
- }
- if (isEnable.HasValue)
- {
- if (isEnable == 1)
- {
- exp = exp.And(x => x.IsEnable == true);
- }
- if (isEnable == 0)
- {
- exp = exp.And(x => x.IsEnable != true);
- }
- }
- var query = CoursematerialDAL.GetCoursematerialViewQueryable(exp);
- //查询条件
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- {
- query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
- }
- return query.OrderBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode)
- .ToGridResultSet<CoursematerialView>(pageIndex, pageSize);
- }
- /// <summary>
- /// 查询课程信息List
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="courseLevelID"></param>
- /// <param name="courseScienceID"></param>
- /// <param name="classGroupingID"></param>
- /// <param name="isEnable"></param>
- /// <returns></returns>
- public IList<CoursematerialView> GetCoursematerialViewList(ConfiguretView configuretView, int? courseLevelID, int? courseScienceID,
- Guid? classGroupingID, int? isEnable)
- {
- //课程信息
- Expression<Func<EM_Coursematerial, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (courseLevelID.HasValue)
- {
- exp = exp.And(x => x.CourseLevelID == courseLevelID);
- }
- if (courseScienceID.HasValue)
- {
- exp = exp.And(x => x.CourseScienceID == courseScienceID);
- }
- if (classGroupingID.HasValue)
- {
- exp = exp.And(x => x.ClassGroupingID == classGroupingID);
- }
- if (isEnable.HasValue)
- {
- if (isEnable == 1)
- {
- exp = exp.And(x => x.IsEnable == true);
- }
- if (isEnable == 0)
- {
- exp = exp.And(x => x.IsEnable != true);
- }
- }
- var query = CoursematerialDAL.GetCoursematerialViewQueryable(exp);
- //查询条件
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- {
- query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
- }
- return query.OrderBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode).ToList();
- }
- /// <summary>
- /// 查询课程信息CoursematerialView(启用状态为是或已使用的信息)
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="coursematerialID"></param>
- /// <param name="isEnable"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <returns></returns>
- public IGridResultSet<CoursematerialView> GetEnableAndUseCoursematerialViewGrid(ConfiguretView configuretView, Guid? coursematerialID, int? isEnable, int pageIndex, int pageSize)
- {
- //课程信息
- Expression<Func<EM_Coursematerial, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (isEnable.HasValue)
- {
- if (isEnable == 1)
- {
- if (coursematerialID.HasValue)
- {
- exp = exp.And(x => x.IsEnable == true || x.CoursematerialID == coursematerialID);
- }
- else
- {
- exp = exp.And(x => x.IsEnable == true);
- }
- }
- if (isEnable == 0)
- {
- if (coursematerialID.HasValue)
- {
- exp = exp.And(x => x.IsEnable != true || x.CoursematerialID == coursematerialID);
- }
- else
- {
- exp = exp.And(x => x.IsEnable != true);
- }
- }
- }
- var query = CoursematerialDAL.GetCoursematerialViewQueryable(exp);
- //查询条件
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- {
- query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
- }
- return query.OrderBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode)
- .ToGridResultSet<CoursematerialView>(pageIndex, pageSize);
- }
- /// <summary>
- /// 查询课程信息List(启用状态为是或已使用的信息)
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="coursematerialID"></param>
- /// <param name="isEnable"></param>
- /// <returns></returns>
- public IList<CoursematerialView> GetEnableAndUseCoursematerialViewList(ConfiguretView configuretView, Guid? coursematerialID, int? isEnable)
- {
- //课程信息
- Expression<Func<EM_Coursematerial, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (coursematerialID.HasValue)
- {
- exp = exp.Or(x => x.CoursematerialID == coursematerialID);
- }
- if (isEnable.HasValue)
- {
- if (isEnable == 1)
- {
- exp = exp.Or(x => x.IsEnable == true);
- }
- if (isEnable == 0)
- {
- exp = exp.Or(x => x.IsEnable != true);
- }
- }
- var query = CoursematerialDAL.GetCoursematerialViewQueryable(exp);
- //查询条件
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- {
- query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
- }
- return query.OrderBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode).ToList();
- }
- /// <summary>
- /// 查询对应的课程信息CoursematerialView
- /// </summary>
- /// <param name="coursematerialID"></param>
- /// <returns></returns>
- public CoursematerialView GetCoursematerialView(Guid? coursematerialID)
- {
- try
- {
- var coursematerialView = CoursematerialDAL.GetCoursematerialViewQueryable(x => x.CoursematerialID == coursematerialID).SingleOrDefault();
- return coursematerialView;
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
- /// <summary>
- /// 编辑(新增、修改)
- /// 注:个性化配置(业务主键默认为课程代码或课程名称唯一)
- /// </summary>
- /// <param name="coursematerialView"></param>
- public virtual void CoursematerialEdit(CoursematerialView coursematerialView)
- {
- try
- {
- //查询数据库进行验证
- var courseCodeVerify = CoursematerialDAL.CoursematerialRepository
- .GetList(x => x.CoursematerialID != coursematerialView.CoursematerialID
- && x.CourseCode == coursematerialView.CourseCode).SingleOrDefault();
- var courseNameVerify = CoursematerialDAL.CoursematerialRepository
- .GetList(x => x.CoursematerialID != coursematerialView.CoursematerialID
- && x.CourseName == coursematerialView.CourseName).FirstOrDefault();
- if (courseCodeVerify == null && courseNameVerify == null)
- {
- //数据有误验证
- if (coursematerialView.CoursematerialID != Guid.Empty)
- {
- var course = CoursematerialDAL.CoursematerialRepository
- .GetList(x => x.CoursematerialID == coursematerialView.CoursematerialID).SingleOrDefault();
- if (course == null)
- {
- throw new Exception("数据有误,请核查。");
- }
- else
- {
- //表示修改
- course.CourseCode = coursematerialView.CourseCode;
- course.CourseName = coursematerialView.CourseName;
- course.Abbreviation = coursematerialView.Abbreviation;
- course.EnglishName = coursematerialView.EnglishName;
- course.StandardName = coursematerialView.StandardName;
- course.CourseEdition = coursematerialView.CourseEdition;
- course.CourseLevelID = coursematerialView.CourseLevelID;
- course.CourseScienceID = coursematerialView.CourseScienceID;
- course.ClassGroupingID = coursematerialView.ClassGroupingID;
- course.CourseSynopsis = coursematerialView.CourseSynopsis;
- course.CourseReserve = coursematerialView.CourseReserve;
- course.IsEnable = coursematerialView.IsEnable;
- course.Remark = coursematerialView.Remark;
- SetModifyStatus(course);
- }
- }
- else
- {
- //表示新增
- var newCourse = new EM_Coursematerial();
- newCourse.CoursematerialID = Guid.NewGuid();
- newCourse.CourseCode = coursematerialView.CourseCode;
- newCourse.CourseName = coursematerialView.CourseName;
- newCourse.Abbreviation = coursematerialView.Abbreviation;
- newCourse.EnglishName = coursematerialView.EnglishName;
- newCourse.StandardName = coursematerialView.StandardName;
- newCourse.CourseEdition = coursematerialView.CourseEdition;
- newCourse.CourseLevelID = coursematerialView.CourseLevelID;
- newCourse.CourseScienceID = coursematerialView.CourseScienceID;
- newCourse.ClassGroupingID = coursematerialView.ClassGroupingID;
- newCourse.CourseSynopsis = coursematerialView.CourseSynopsis;
- newCourse.CourseReserve = coursematerialView.CourseReserve;
- newCourse.IsEnable = coursematerialView.IsEnable;
- newCourse.Remark = coursematerialView.Remark;
- SetNewStatus(newCourse);
- UnitOfWork.Add(newCourse);
- }
- //事务提交
- UnitOfWork.Commit();
- }
- else
- {
- if (courseCodeVerify != null && courseNameVerify != null)
- {
- throw new Exception("已存在相同的课程代码、课程名称,请核查。");
- }
- else if (courseCodeVerify != null)
- {
- throw new Exception("已存在相同的课程代码,请核查。");
- }
- else
- {
- throw new Exception("已存在相同的课程名称,请核查。");
- }
- }
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="coursematerialIDs"></param>
- /// <returns></returns>
- public bool CoursematerialDelete(List<Guid?> coursematerialIDs)
- {
- try
- {
- if (coursematerialIDs.Count() > 0)
- {
- UnitOfWork.Delete<EM_Coursematerial>(x => coursematerialIDs.Contains(x.CoursematerialID));
- }
- return true;
- }
- catch (Exception)
- {
- throw;
- }
- }
- /// <summary>
- /// 课程信息导入(个性化配置)
- /// 注:业务主键默认为课程代码或课程名称唯一
- /// </summary>
- /// <param name="cellheader"></param>
- /// <param name="inCount"></param>
- /// <param name="upCount"></param>
- /// <param name="errdataList"></param>
- /// <param name="errCount"></param>
- /// <param name="sourcePhysicalPath"></param>
- public virtual void CoursematerialImport(Dictionary<string, string> cellheader, out int? inCount, out int? upCount, out List<CoursematerialView> errdataList, out int? errCount, string sourcePhysicalPath)
- {
- try
- {
- StringBuilder errorMsg = new StringBuilder(); // 错误信息
- List<CoursematerialView> errList = new List<CoursematerialView>();
- // 1.1解析文件,存放到一个List集合里
- cellheader.Remove("ErrorMessage");//移除“未导入原因”列(ErrorMessage)
- List<CoursematerialView> enlist = NpoiExcelHelper.ExcelToEntityList<CoursematerialView>(cellheader, sourcePhysicalPath, out errorMsg, out errList);
- cellheader.Add("ErrorMessage", "未导入原因");
- //对List集合进行有效性校验
- if (enlist.Count() <= 0)
- {
- throw new Exception("Excel文件数据为空,请检查。");
- }
- Regex reg = null; //正则表达式
- //DateTime result; //用于返回判断日期字段格式
- //bool isListPass = true; //List判断标识
- inCount = 0; //导入个数
- upCount = 0; //更新个数
- errCount = 0; //失败个数
- string errorMsgStr = ""; //错误信息
- List<EM_Coursematerial> newCoursematerialInList = new List<EM_Coursematerial>();
- List<EM_Coursematerial> newCoursematerialUpList = new List<EM_Coursematerial>();
- //将循环中相关数据库查询统一查询出来进行匹配(尽量避免在循环中进行数据库查询)
- //课程信息
- var courseList = CoursematerialDAL.CoursematerialRepository.GetList(x => true).ToList();
- //课程代码
- var courseCodeList = enlist.Where(x => !string.IsNullOrWhiteSpace(x.CourseCode)).Select(x => x.CourseCode.Trim()).ToList();
- //课程名称
- var courseNameList = enlist.Where(x => !string.IsNullOrWhiteSpace(x.CourseName)).Select(x => x.CourseName.Trim()).ToList();
- //对比后的newCourseList
- var newCourseList = courseList.Where(x => courseCodeList.Contains(x.CourseCode) || courseNameList.Contains(x.CourseName)).ToList();
- //课程级别
- var courseLevelList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_CourseLevel).ToList();
- //课程科类
- var courseScienceList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_CourseScience).ToList();
- //上课类型信息
- var classGroupingList = CoursematerialDAL.ClassGroupingRepository.GetList(x => true).ToList();
- //上课类型
- var classNameList = enlist.Where(x => !string.IsNullOrWhiteSpace(x.ClassName)).Select(x => x.ClassName.Trim()).ToList();
- //对比后的newClassGroupingList
- var newClassGroupingList = classGroupingList.Where(x => classNameList.Contains(x.ClassName)).ToList();
- //是否启用
- var generalPurposeList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_GeneralPurpose).ToList();
- //循环检测数据列,对各数据列进行验证(必填、字典项验证、数据格式等)
- for (int i = 0; i < enlist.Count; i++)
- {
- CoursematerialView en = enlist[i]; //Excel表数据视图
- EM_Coursematerial newCoursematerial = new EM_Coursematerial();
- //课程代码
- if (string.IsNullOrWhiteSpace(en.CourseCode))
- {
- errCount++;
- errorMsgStr = "课程代码不能为空";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- reg = new Regex(@"^[0-9a-zA-Z\s?]+$"); //正则表达式(请输入数字或英文字母)
- if (!reg.IsMatch(en.CourseCode.Trim()))
- {
- errCount++;
- errorMsgStr = "课程代码格式不正确,请检查(数字或英文字母)";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //课程代码
- newCoursematerial.CourseCode = en.CourseCode.Trim();
- }
- }
- //课程名称
- if (string.IsNullOrWhiteSpace(en.CourseName))
- {
- errCount++;
- errorMsgStr = "课程名称不能为空";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //课程名称
- newCoursematerial.CourseName = en.CourseName.Trim();
- }
- //课程简称
- if (string.IsNullOrWhiteSpace(en.Abbreviation))
- {
- //默认
- newCoursematerial.Abbreviation = en.CourseName.Trim();
- }
- else
- {
- newCoursematerial.Abbreviation = en.Abbreviation.Trim();
- }
- //英文名称
- if (string.IsNullOrWhiteSpace(en.EnglishName))
- {
- //暂不考虑
- }
- else
- {
- newCoursematerial.EnglishName = en.EnglishName.Trim();
- }
- //课程规范名
- if (string.IsNullOrWhiteSpace(en.StandardName))
- {
- //默认
- newCoursematerial.StandardName = en.CourseName.Trim();
- }
- else
- {
- newCoursematerial.StandardName = en.StandardName.Trim();
- }
- //课程版本
- if (string.IsNullOrWhiteSpace(en.CourseEdition))
- {
- //暂不考虑
- }
- else
- {
- newCoursematerial.CourseEdition = en.CourseEdition.Trim();
- }
- //课程级别
- if (string.IsNullOrWhiteSpace(en.CourseLevelStr))
- {
- //暂不考虑
- }
- else
- {
- var courseLevel = courseLevelList.Where(x => x.Name == en.CourseLevelStr.Trim()).SingleOrDefault();
- if (courseLevel == null)
- {
- errCount++;
- errorMsgStr = "课程级别不存在,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //课程级别
- newCoursematerial.CourseLevelID = courseLevel.Value;
- }
- }
- //课程科类
- if (string.IsNullOrWhiteSpace(en.CourseScienceStr))
- {
- //暂不考虑
- }
- else
- {
- var courseScience = courseScienceList.Where(x => x.Name == en.CourseScienceStr.Trim()).SingleOrDefault();
- if (courseScience == null)
- {
- errCount++;
- errorMsgStr = "课程科类不存在,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //课程科类
- newCoursematerial.CourseScienceID = courseScience.Value;
- }
- }
- //上课类型
- if (string.IsNullOrWhiteSpace(en.ClassName))
- {
- //暂不考虑
- }
- else
- {
- var classGrouping = newClassGroupingList.Where(x => x.ClassName == en.ClassName.Trim()).SingleOrDefault();
- if (classGrouping == null)
- {
- errCount++;
- errorMsgStr = "上课类型不存在,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //上课类型ID
- newCoursematerial.ClassGroupingID = classGrouping.ClassGroupingID;
- }
- }
- //课程简介
- if (string.IsNullOrWhiteSpace(en.CourseSynopsis))
- {
- //暂不考虑
- }
- else
- {
- newCoursematerial.CourseSynopsis = en.CourseSynopsis.Trim();
- }
- //预修课程集
- if (string.IsNullOrWhiteSpace(en.CourseReserve))
- {
- //暂不考虑
- }
- else
- {
- newCoursematerial.CourseReserve = en.CourseReserve.Trim();
- }
- //是否启用
- if (string.IsNullOrWhiteSpace(en.IsEnableStr))
- {
- errCount++;
- errorMsgStr = "是否启用不能为空";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- var generalPurpose = generalPurposeList.Where(x => x.Name == en.IsEnableStr.Trim()).SingleOrDefault();
- if (generalPurpose == null)
- {
- errCount++;
- errorMsgStr = "是否启用不存在,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //是否启用
- newCoursematerial.IsEnable = generalPurpose.Value == (int)CF_GeneralPurpose.IsYes ? true : false;
- }
- }
- //备注
- if (string.IsNullOrWhiteSpace(en.Remark))
- {
- //不考虑
- }
- else
- {
- newCoursematerial.Remark = en.Remark.Trim();
- }
- ////Excel表重复性验证(注:当数据表中没有此记录,但是Excel中有重复数据时的去掉)
- //for (int j = i + 1; j < enlist.Count; j++)
- //{
- // CoursematerialView enA = enlist[j];
- // //根据Excel表中的业务主键进行去重(课程代码或课程名称唯一)
- // if (en.No == enA.No && en.Name == enA.Name)
- // {
- // //用于标识Excel表中的重复记录(由于是批量进行插入数据表)
- // }
- //}
- //数据表重复性验证(课程代码或课程名称唯一)
- var courseCodeVerify = newCourseList.Where(x => x.CourseCode == newCoursematerial.CourseCode).SingleOrDefault();
- var courseNameVerifyList = newCourseList.Where(x => x.CourseName == newCoursematerial.CourseName).ToList();
- var courseVerify = newCourseList.Where(x => x.CourseCode == newCoursematerial.CourseCode
- && x.CourseName == newCoursematerial.CourseName).SingleOrDefault();
- if (courseCodeVerify == null && courseNameVerifyList.Count() <= 0)
- {
- //新增
- if (!newCoursematerialInList.Any(x => x.CourseCode == newCoursematerial.CourseCode
- || x.CourseName == newCoursematerial.CourseName))
- {
- newCoursematerial.CoursematerialID = Guid.NewGuid();
- SetNewStatus(newCoursematerial);
- newCoursematerialInList.Add(newCoursematerial);
- inCount++;
- }
- else
- {
- //Excel表重复性验证
- //(注:当数据表中没有此记录,但是Excel中有重复数据,可在此处进行抛出到失败数据文件中,目前暂不考虑)
- inCount++;
- }
- }
- else
- {
- //更新(Excel有重复时,以最后一条记录的更新为准)
- if (courseCodeVerify != null && courseNameVerifyList.Count() > 0)
- {
- if (courseVerify == null)
- {
- errCount++;
- errorMsgStr = "课程代码、课程名称已存在且无法匹配(不为同一课程信息),请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //courseVerify.CourseCode = newCoursematerial.CourseCode;
- //courseVerify.CourseName = newCoursematerial.CourseName;
- courseVerify.Abbreviation = newCoursematerial.Abbreviation;
- courseVerify.EnglishName = newCoursematerial.EnglishName;
- courseVerify.StandardName = newCoursematerial.StandardName;
- courseVerify.CourseEdition = newCoursematerial.CourseEdition;
- courseVerify.CourseLevelID = newCoursematerial.CourseLevelID;
- courseVerify.CourseScienceID = newCoursematerial.CourseScienceID;
- courseVerify.ClassGroupingID = newCoursematerial.ClassGroupingID;
- courseVerify.CourseSynopsis = newCoursematerial.CourseSynopsis;
- courseVerify.CourseReserve = newCoursematerial.CourseReserve;
- courseVerify.IsEnable = newCoursematerial.IsEnable;
- courseVerify.Remark = newCoursematerial.Remark;
- SetModifyStatus(courseVerify);
- newCoursematerialUpList.Add(courseVerify);
- upCount++;
- }
- }
- else if (courseCodeVerify != null)
- {
- //courseCodeVerify.CourseCode = newCoursematerial.CourseCode;
- courseCodeVerify.CourseName = newCoursematerial.CourseName;
- courseCodeVerify.Abbreviation = newCoursematerial.Abbreviation;
- courseCodeVerify.EnglishName = newCoursematerial.EnglishName;
- courseCodeVerify.StandardName = newCoursematerial.StandardName;
- courseCodeVerify.CourseEdition = newCoursematerial.CourseEdition;
- courseCodeVerify.CourseLevelID = newCoursematerial.CourseLevelID;
- courseCodeVerify.CourseScienceID = newCoursematerial.CourseScienceID;
- courseCodeVerify.ClassGroupingID = newCoursematerial.ClassGroupingID;
- courseCodeVerify.CourseSynopsis = newCoursematerial.CourseSynopsis;
- courseCodeVerify.CourseReserve = newCoursematerial.CourseReserve;
- courseCodeVerify.IsEnable = newCoursematerial.IsEnable;
- courseCodeVerify.Remark = newCoursematerial.Remark;
- SetModifyStatus(courseCodeVerify);
- newCoursematerialUpList.Add(courseCodeVerify);
- upCount++;
- }
- else
- {
- if (courseNameVerifyList.Count() > 1)
- {
- errCount++;
- errorMsgStr = "课程名称已存在且无法匹配(课程名称多个重复),请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- var courseNameVerify = courseNameVerifyList.Where(x => x.CourseName == newCoursematerial.CourseName).SingleOrDefault();
- if (courseNameVerify == null)
- {
- errCount++;
- errorMsgStr = "数据有误(课程名称对应的课程信息不存在),请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- courseNameVerify.CourseCode = newCoursematerial.CourseCode;
- //courseNameVerify.CourseName = newCoursematerial.CourseName;
- courseNameVerify.Abbreviation = newCoursematerial.Abbreviation;
- courseNameVerify.EnglishName = newCoursematerial.EnglishName;
- courseNameVerify.StandardName = newCoursematerial.StandardName;
- courseNameVerify.CourseEdition = newCoursematerial.CourseEdition;
- courseNameVerify.CourseLevelID = newCoursematerial.CourseLevelID;
- courseNameVerify.CourseScienceID = newCoursematerial.CourseScienceID;
- courseNameVerify.ClassGroupingID = newCoursematerial.ClassGroupingID;
- courseNameVerify.CourseSynopsis = newCoursematerial.CourseSynopsis;
- courseNameVerify.CourseReserve = newCoursematerial.CourseReserve;
- courseNameVerify.IsEnable = newCoursematerial.IsEnable;
- courseNameVerify.Remark = newCoursematerial.Remark;
- SetModifyStatus(courseNameVerify);
- newCoursematerialUpList.Add(courseNameVerify);
- upCount++;
- }
- }
- }
- }
- }
- //批量插入
- UnitOfWork.BulkInsert(newCoursematerialInList);
- //批量统一提交更新
- if (newCoursematerialUpList != null && newCoursematerialUpList.Count() > 0)
- {
- UnitOfWork.BatchUpdate(newCoursematerialUpList);
- }
- errdataList = errList.Distinct().ToList(); //错误列表List
- }
- catch (Exception)
- {
- throw;
- }
- }
- }
- }
|