123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Data.Entity;
- using System.Text;
- using EMIS.DataLogic.Common.TeachingMaterial;
- using EMIS.ViewModel.TeachingMaterial;
- using Bowin.Common.Linq.Entity;
- using EMIS.ViewModel;
- using EMIS.DataLogic.Repositories;
- using EMIS.Entities;
- using EMIS.Utility.FormValidate;
- using System.Data;
- using Bowin.Common.Utility;
- using EMIS.ViewModel.CacheManage;
- using Bowin.Common.Linq;
- using System.Linq.Expressions;
- using EMIS.ViewModel.Cultureplan;
- using System.Text.RegularExpressions;
- namespace EMIS.CommonLogic.TeachingMaterial
- {
- public class TeachingMaterialPoolServices : BaseServices, ITeachingMaterialPoolServices
- {
- #region --0.0 定义--
- public TeachingMaterialPoolDAL TeachingMaterialPoolDAL { get; set; }
- public TeachingMaterialPoolRepository TeachingMaterialPoolRepository { get; set; }
- public UserRepository UserRepository { get; set; }
- public CoursematerialRepository CoursematerialRepository { get; set; }
- public DictionaryItemRepository DictionaryItemRepository { get; set; }
- public PublishRepository PublishRepository { get; set; }
- #endregion
- #region 1.0 获取教材总库信息列表
- /// <summary>
- /// 获取教材总库信息列表
- /// </summary>
- /// <param name="exp"></param>
- /// <returns></returns>
- public IGridResultSet<TeachingMaterialPoolView> GetTeachingMaterialPoolViewGrid(ConfiguretView configuretView, Guid? publishID, Guid? coursematerialID, bool? isLate, int? teachingMaterialType, int pageIndex, int pageSize)
- {
- Expression<Func<CF_TeachingMaterialPool, bool>> exp = (x => true);
- if (publishID != null && publishID != Guid.Empty)
- {
- exp = exp.And(x => x.PublishID == publishID);
- }
- if (coursematerialID != null && coursematerialID != Guid.Empty)
- {
- exp = exp.And(x => x.EM_Coursematerial.Any(w => w.CoursematerialID == coursematerialID));
- }
- if (isLate != null)
- {
- exp = exp.And(x => x.IsLate == isLate);
- }
- if (teachingMaterialType != null && teachingMaterialType > 0)
- {
- exp = exp.And(x => x.TeachingMaterialTypeID == teachingMaterialType);
- }
- var query = TeachingMaterialPoolDAL.GetTeachingMaterialPoolGridView(exp);
-
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.TeachingMaterialCode.Length).ThenBy(x => x.TeachingMaterialCode).ToGridResultSet<TeachingMaterialPoolView>(pageIndex, pageSize);//.OrderBy(x => x.TeachingMaterialTypeID).OrderByDescending(x => x.TeachingMaterialName)
- //.OrderBy(x => x.TeachingMaterialCode)
- return query.OrderBy(x => x.TeachingMaterialCode.Length).ThenBy(x => x.TeachingMaterialCode).ToGridResultSet<TeachingMaterialPoolView>(pageIndex, pageSize);
- }
- #endregion
- #region 2.0 编辑保存教材信息
- /// <summary>
- /// 编辑教材总库
- /// </summary>
- /// <param name="publisherView"></param>
- public void EditTeachingMaterialPool(TeachingMaterialPoolView teachingMaterialPoolView, Guid createUserID, IList<CoursematerialView> coursematerialList)
- {
- try
- {
- var coursematerialIDList = coursematerialList.Select(x => x.CoursematerialID).ToList();
- var coursematerialEntityList = CoursematerialRepository.GetList(x => coursematerialIDList.Contains(x.CoursematerialID)).ToList();
- if (teachingMaterialPoolView.PublishTime == null || teachingMaterialPoolView.PublishTime == "")
- {
- throw new Exception("版本时间不能为空");
- }
- if (teachingMaterialPoolView.TeachingMaterialCode.Length > 10)
- {
- throw new Exception("教材编号不能超过十位数,请重新输入");
- }
- if (this.TeachingMaterialPoolRepository.GetList(x => x.TeachingMaterialCode == teachingMaterialPoolView.TeachingMaterialCode
- && x.TeachingMaterialPoolID != teachingMaterialPoolView.TeachingMaterialPoolID).Count() > 0)
- {
- throw new Exception("教材编号已经存在,请重新输入!");
- }
- if (this.TeachingMaterialPoolRepository.GetList(x => x.ISBN == teachingMaterialPoolView.ISBN
- && x.TeachingMaterialPoolID != teachingMaterialPoolView.TeachingMaterialPoolID).Count() > 0)
- {
- throw new Exception("ISBN已经存在,请重新输入!");
- }
- Regex datestr = new Regex("^[0-9]{4}年[0-9]{1,2}月[0-9]{1,3}版[0-9]{1,3}次$");
- if (!datestr.IsMatch(teachingMaterialPoolView.PublishTime))//时间格式验证
- {
- throw new Exception("版本时间格式不正确,应为 xxxx年xx月xx版xx次,请重新输入!");
- }
- if (teachingMaterialPoolView.TeachingMaterialPoolID != null && teachingMaterialPoolView.TeachingMaterialPoolID != Guid.Empty)
- {
- CF_TeachingMaterialPool teachingMaterialPool = TeachingMaterialPoolRepository
- .GetSingle(x => x.TeachingMaterialPoolID == teachingMaterialPoolView.TeachingMaterialPoolID, (x => x.EM_Coursematerial));
- teachingMaterialPool.TeachingMaterialCode = teachingMaterialPoolView.TeachingMaterialCode;
- teachingMaterialPool.TeachingMaterialName = teachingMaterialPoolView.TeachingMaterialName;
- teachingMaterialPool.EM_Coursematerial = new HashSet<EM_Coursematerial>();
- teachingMaterialPool.EM_Coursematerial = new HashSet<EM_Coursematerial>(coursematerialEntityList);
- teachingMaterialPool.ISBN = teachingMaterialPoolView.ISBN;
- teachingMaterialPool.TeachingMaterialShorName = teachingMaterialPoolView.TeachingMaterialShorName;
- teachingMaterialPool.TeachingMaterialTypeID = teachingMaterialPoolView.TeachingMaterialTypeID == null ? -1 : teachingMaterialPoolView.TeachingMaterialTypeID;
- teachingMaterialPool.WnningLevel = teachingMaterialPoolView.WnningLevel == null ? -1 : teachingMaterialPoolView.WnningLevel;
- teachingMaterialPool.PublishTime = teachingMaterialPoolView.PublishTime;
- teachingMaterialPool.PublishID = teachingMaterialPoolView.PublishID;
- teachingMaterialPool.Author = teachingMaterialPoolView.Author;
- teachingMaterialPool.Price = teachingMaterialPoolView.Price;
- teachingMaterialPool.IsLate = teachingMaterialPoolView.IsLate;
- teachingMaterialPool.ModifyUserID = createUserID;
- teachingMaterialPool.ModifyTime = DateTime.Now;
- teachingMaterialPool.Desc = teachingMaterialPoolView.Desc;
- teachingMaterialPool.MinInventory = teachingMaterialPoolView.MinInventory;
- TeachingMaterialPoolRepository.UnitOfWork.Update(teachingMaterialPool);
- TeachingMaterialPoolRepository.UnitOfWork.Commit();
- }
- else
- {
- CF_TeachingMaterialPool teachingMaterialPool = new CF_TeachingMaterialPool()
- {
- TeachingMaterialPoolID = Guid.NewGuid(),
- WnningLevel = teachingMaterialPoolView.WnningLevel == null ? -1 : teachingMaterialPoolView.WnningLevel,
- PublishID = teachingMaterialPoolView.PublishID,
- Author = teachingMaterialPoolView.Author,
- ISBN = teachingMaterialPoolView.ISBN,
- IsLate = teachingMaterialPoolView.IsLate,
- PublishTime = teachingMaterialPoolView.PublishTime,
- TeachingMaterialCode = teachingMaterialPoolView.TeachingMaterialCode,
- TeachingMaterialName = teachingMaterialPoolView.TeachingMaterialName,
- TeachingMaterialShorName = teachingMaterialPoolView.TeachingMaterialShorName == null ? teachingMaterialPoolView.TeachingMaterialName : teachingMaterialPoolView.TeachingMaterialShorName,
- TeachingMaterialTypeID = teachingMaterialPoolView.TeachingMaterialTypeID == null ? -1 : teachingMaterialPoolView.TeachingMaterialTypeID,
- Price = teachingMaterialPoolView.Price,
- EM_Coursematerial = new HashSet<EM_Coursematerial>(coursematerialEntityList),
- Desc = teachingMaterialPoolView.Desc,
- CreateTime = DateTime.Now,
- CreateUserID = createUserID,
- MinInventory = 1,//最小库存量默认1
- ModifyUserID = createUserID,
- ModifyTime = DateTime.Now
- };
- TeachingMaterialPoolRepository.UnitOfWork.Add(teachingMaterialPool);
- TeachingMaterialPoolRepository.UnitOfWork.Commit();
- }
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- #endregion
- #region 3.0 删除教材总库信息
- /// <summary>
- /// 删除教材总库信息
- /// </summary>
- /// <param name="publishID"></param>
- public void DeleteTeachingMaterialPool(List<Guid> TeachingMaterialPoolIDs)
- {
- try
- {
- TeachingMaterialPoolRepository.UnitOfWork.Delete<CF_TeachingMaterialPool>(x => TeachingMaterialPoolIDs.Contains(x.TeachingMaterialPoolID));
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- #endregion
- #region 4.0 获取教材总库单位
- /// <summary>
- /// 获取教材总库单位
- /// </summary>
- /// <returns></returns>
- public TeachingMaterialPoolView GetSingleTeachingMaterialPool(Guid TeachingMaterialPoolID)
- {
- return TeachingMaterialPoolDAL.GetSingleTeachingMaterialPool(TeachingMaterialPoolID);
- }
- #endregion
- #region 5.0 获取教材总库息列表导出
- /// <summary>
- /// 获取教材总库息列表导出
- /// </summary>
- /// <param name="exp"></param>
- /// <returns></returns>
- public IList<TeachingMaterialPoolView> GetTeachingMaterialPoolViewExcel(ConfiguretView configuretView, Guid? publishID, Guid? coursematerialID, bool? isLate, int? teachingMaterialType)
- {
- Expression<Func<CF_TeachingMaterialPool, bool>> exp = (x => true);
- if (publishID != null && publishID != Guid.Empty)
- {
- exp = exp.And(x => x.PublishID == publishID);
- }
- if (coursematerialID != null && coursematerialID != Guid.Empty)
- {
- exp = exp.And(x => x.EM_Coursematerial.Any(w => w.CoursematerialID == coursematerialID));
- }
- if (isLate != null)
- {
- exp = exp.And(x => x.IsLate == isLate);
- }
- if (teachingMaterialType != null && teachingMaterialType > 0)
- {
- exp = exp.And(x => x.TeachingMaterialTypeID == teachingMaterialType);
- }
- var query = TeachingMaterialPoolDAL.GetTeachingMaterialPoolGridView(exp);
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.TeachingMaterialTypeID).OrderByDescending(x => x.TeachingMaterialName).ToList();
- return query.OrderBy(x => x.TeachingMaterialCode).ToList();
- }
- #endregion
- #region 获取教材对应的课程资料
- public List<CoursematerialView> GetTeachingMaterialCoursematerialList(Guid? teachingMaterialPoolID)
- {
- if (teachingMaterialPoolID.HasValue)
- {
- var coursematerialViewList = TeachingMaterialPoolDAL.GetTeachingMaterialPoolCoursematerialView(x => x.TeachingMaterialPoolID == teachingMaterialPoolID);
- return coursematerialViewList.ToList();
- }
- else
- {
- return new List<CoursematerialView>();
- }
- }
- #endregion
- #region 6.0 获取教材总库信息列表(用于学生征订)
- /// <summary>
- /// 获取教材总库信息列表(用于学生征订)
- /// </summary>
- /// <param name="exp"></param>
- /// <returns></returns>
- public IGridResultSet<TeachingMaterialPoolView> GetTeachingMaterialPoolForOrder(ConfiguretView configuretView, Guid? publishID, string isbn, Guid? coursematerialID, string teachingMaterialName, string ischeck, int pageIndex, int pageSize)
- {
- Expression<Func<CF_TeachingMaterialPool, bool>> exp = x => true;
- exp = exp.And(x => x.IsLate != true);
- if (ischeck == "true" && coursematerialID != null && coursematerialID != Guid.Empty)
- {
- exp = exp.And(x => x.EM_Coursematerial.Any(y => y.CoursematerialID == coursematerialID));
- }
- var query = TeachingMaterialPoolDAL.GetTeachingMaterialPoolForOrder(exp, coursematerialID);
- if (publishID != null && publishID != Guid.Empty)
- {
- query = query.Where(x => x.PublishID == publishID);
- }
- if (isbn != null && isbn != "")// && !isbn.IsEmpty()
- {
- query = query.Where(x => x.ISBN.Contains(isbn));
- }
- if (teachingMaterialName != null && teachingMaterialName != "")
- {
- query = query.Where(x => x.TeachingMaterialName.Contains(teachingMaterialName));
- }
- //暂时不根据征订的课程筛选教材
- //if (coursematerialID != null && coursematerialID != Guid.Empty)
- //{
- // query = query.where(x => x.coursematerialid == coursematerialid);
- //}
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue)
- .OrderBy(x => x.TeachingMaterialName).ToGridResultSet<TeachingMaterialPoolView>(pageIndex, pageSize);
- return query.OrderBy(x => x.OrderID)
- .ThenBy(x => x.TeachingMaterialName).ToGridResultSet<TeachingMaterialPoolView>(pageIndex, pageSize);
- }
- #endregion
- #region 7.0 编辑保存教材库存信息
- /// <summary>
- /// 编辑教材库存
- /// </summary>
- /// <param name="publisherView"></param>
- public void EditTeachingMateriaInventory(TeachingMaterialPoolView teachingMaterialPoolView, Guid createUserID)
- {
- try
- {
- if (teachingMaterialPoolView.TeachingMaterialPoolID != null && teachingMaterialPoolView.TeachingMaterialPoolID != Guid.Empty)
- {
- CF_TeachingMaterialPool teachingMaterialPool = TeachingMaterialPoolRepository.GetSingle(x => x.TeachingMaterialPoolID == teachingMaterialPoolView.TeachingMaterialPoolID);
- teachingMaterialPool.MinInventory = teachingMaterialPoolView.MinInventory;
- TeachingMaterialPoolRepository.UnitOfWork.Update(teachingMaterialPool);
- TeachingMaterialPoolRepository.UnitOfWork.Commit();
- }
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- #endregion
- public bool IsExistCode(string code)
- {
- bool IsExist = false;
- var Endt = TeachingMaterialPoolRepository.GetSingle(x => x.TeachingMaterialCode == code);
- if (Endt != null)
- {
- IsExist = true;
- }
- return IsExist;
- }
- public bool IsExistISBN(string ISBN)
- {
- bool IsExist = false;
- var Endt = TeachingMaterialPoolRepository.GetSingle(x => x.ISBN == ISBN);
- if (Endt != null)
- {
- IsExist = true;
- }
- return IsExist;
- }
- public IGridResultSet<StudentTeachingMaterialView> GetStudentTeachingMaterialViewGrid(ConfiguretView configuretView, int pageIndex, int pageSize)
- {
- var user = CustomPrincipal.Current;
- var query = TeachingMaterialPoolDAL.GetStudentTeachingMaterialView(x => x.UserID == user.UserID);
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
- return query.OrderBy(x => x.SchoolYearValue).ThenBy(x => x.CourseName).ToGridResultSet<StudentTeachingMaterialView>(pageIndex, pageSize);
- }
- public IList<StudentTeachingMaterialView> GetStudentTeachingMaterialViewList(ConfiguretView configuretView)
- {
- var user = CustomPrincipal.Current;
- var query = TeachingMaterialPoolDAL.GetStudentTeachingMaterialView(x => x.UserID == user.UserID);
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
- return query.OrderBy(x => x.SchoolYearValue).ThenBy(x => x.CourseName).ToList();
- }
- public void TeachingMaterialPoolImport(Dictionary<string, string> cellheader, out int OkCount, out List<TeachingMaterialPoolImportView> errdataList, out int successCount, string sourcePhysicalPath)
- {
- StringBuilder errorMsg = new StringBuilder(); // 错误信息
- List<TeachingMaterialPoolImportView> errList = new List<TeachingMaterialPoolImportView>();
- #region 1.1解析文件,存放到一个List集合里
- cellheader.Remove("ErrorMessage");//去除异常列、导入操作不需要
- // 1.1解析文件,存放到一个List集合里
- List<TeachingMaterialPoolImportView> enlist =
- NpoiExcelHelper.ExcelToEntityList<TeachingMaterialPoolImportView>(cellheader, sourcePhysicalPath, out errorMsg, out errList);
- cellheader.Add("ErrorMessage", "错误信息");//还原字典项
- #endregion
- #region 1.2 将Excel数据写入数据库中
- #region 1.2.1 对List集合进行有效性校验
- if (enlist.Count() <= 0)
- {
- throw new Exception("请填写Excel模板信息数据。");
- }
- #region 1.2.1.1检测必填项是否必填
- for (int i = 0; i < enlist.Count; i++)
- {
- TeachingMaterialPoolImportView en = enlist[i];
- string errorMsgStr = "第" + (i + 1) + "行数据检测异常:";
- bool isHaveNoInputValue = false; // 是否含有未输入项
- if (string.IsNullOrEmpty(en.TeachingMaterialName))
- {
- errorMsgStr += "教材名称不能为空;";
- en.ErrorMessage = errorMsgStr;
- isHaveNoInputValue = true;
- }
- if (string.IsNullOrEmpty(en.CoursematerialName))
- {
- errorMsgStr += "课程名称不能为空;";
- en.ErrorMessage = errorMsgStr;
- isHaveNoInputValue = true;
- }
- if (string.IsNullOrEmpty(en.TeachingMaterialCode))
- {
- errorMsgStr += "教材编号不能为空;";
- en.ErrorMessage = errorMsgStr;
- isHaveNoInputValue = true;
- }
- if (string.IsNullOrEmpty(en.ISBN))
- {
- errorMsgStr += "ISBN不能为空;";
- en.ErrorMessage = errorMsgStr;
- isHaveNoInputValue = true;
- }
- Regex datestr = new Regex("^[0-9]{4}年[0-9]{1,2}月[0-9]{1,3}版[0-9]{1,3}次$");
- if (string.IsNullOrEmpty(en.PublishTime))
- {
- errorMsgStr += "版本时间不能为空;";
- en.ErrorMessage = errorMsgStr;
- isHaveNoInputValue = true;
- }
- else if (!datestr.IsMatch(en.PublishTime))//时间格式验证
- {
- errorMsgStr += "版本时间格式不正确,应为 xxxx年xx月xx版xx次,请重新输入!";
- en.ErrorMessage = errorMsgStr;
- isHaveNoInputValue = true;
- }
- if (string.IsNullOrEmpty(en.PublishName))
- {
- errorMsgStr += "出版单位不能为空;";
- en.ErrorMessage = errorMsgStr;
- isHaveNoInputValue = true;
- }
- else
- {
- if (!PublishRepository.Entities.Any(x => x.UnitName == en.PublishName))
- {
- errorMsgStr += "该出版单位不存在,请添加后再导入;";
- en.ErrorMessage = errorMsgStr;
- isHaveNoInputValue = true;
- }
- }
- if (string.IsNullOrEmpty(en.Author))
- {
- errorMsgStr += "作者不能为空;";
- en.ErrorMessage = errorMsgStr;
- isHaveNoInputValue = true;
- }
- if (en.Price == null)
- {
- errorMsgStr += "单价列不能为空;";
- en.ErrorMessage = errorMsgStr;
- isHaveNoInputValue = true;
- }
- #region 1.2.1.2 检测(启用状态课程名称唯一性、)
- //if (CoursematerialRepository.Entities.Where(x => x.IsEnable == true && x.CourseName == en.CoursematerialName).Count() > 1)
- //{
- // errorMsgStr += "该课程名称列对应的课程编码存在多条;";
- // en.ErrorMessage = errorMsgStr;
- // isHaveNoInputValue = true;
- //}
- var coursematerialNames = en.CoursematerialName.Split(',').Where(x => !string.IsNullOrEmpty(x)).ToList();
- if (CoursematerialRepository.Entities.Where(x => x.IsEnable == true && coursematerialNames.Contains(x.CourseName)).Count() != coursematerialNames.Count)
- {
- errorMsgStr += "部分对应的课程不存在或未启用,请添加后再导入;";
- en.ErrorMessage = errorMsgStr;
- isHaveNoInputValue = true;
- }
- if (TeachingMaterialPoolRepository.Entities.Any(x => x.TeachingMaterialCode == en.TeachingMaterialCode))
- {
- errorMsgStr += "教材编号已存在;";
- en.ErrorMessage = errorMsgStr;
- isHaveNoInputValue = true;
- }
- if (TeachingMaterialPoolRepository.Entities.Any(x => x.ISBN == en.ISBN))
- {
- errorMsgStr += "ISBN已存在;";
- en.ErrorMessage = errorMsgStr;
- isHaveNoInputValue = true;
- }
- if (!string.IsNullOrEmpty(en.WnningLevelName))
- {
- if (!IdNameExt.GetDictionaryItem(DictionaryItem.CF_WnningLevel.ToString())
- .Any(x => x.Name == en.WnningLevelName))
- {
- errorMsgStr += "获奖等级不存在;";
- en.ErrorMessage = errorMsgStr;
- isHaveNoInputValue = true;
- }
- }
- if (!string.IsNullOrEmpty(en.TeachingMaterialTypeName))
- {
- if (!IdNameExt.GetDictionaryItem(DictionaryItem.CF_TeachingMaterialType.ToString())
- .Any(x => x.Name == en.TeachingMaterialTypeName))
- {
- errorMsgStr += "该教材类型不存在,请添加后再导入;";
- en.ErrorMessage = errorMsgStr;
- isHaveNoInputValue = true;
- }
- }
- #endregion
- if (isHaveNoInputValue) // 若必填项有值未填
- {
- en.IsExcelVaildateOK = false;
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- }
- }
- #endregion
- // TODO:其他检测
- #region 1.2.1.3 循环写入验证成功的数据
- List<CF_TeachingMaterialPool> tpList = new List<CF_TeachingMaterialPool>();
- var coursematerialNameList = enlist.SelectMany(x => x.CoursematerialName.Split(',').Where(w => !string.IsNullOrEmpty(w)).ToList()).Distinct().ToList();
- var coursematerialEntityList = CoursematerialRepository.GetList(x => x.IsEnable == true
- && coursematerialNameList.Contains(x.CourseName)).ToList();
- var publishNameList = enlist.Select(x => x.PublishName).Distinct().ToList();
- var publishEntityList = PublishRepository.GetList(x => publishNameList.Contains(x.UnitName)).ToList();
- for (int i = 0; i < enlist.Count; i++)
- {
- TeachingMaterialPoolImportView enA = enlist[i];
- if (enA.IsExcelVaildateOK == false) // 上面验证不通过,不进行此步验证
- {
- continue;
- }
- var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
- CF_Publish publishEntity = publishEntityList.Where(x => x.UnitName == enA.PublishName).FirstOrDefault();
- var curCoursematerialNameList = enA.CoursematerialName.Split('.').Where(w => !string.IsNullOrEmpty(w)).ToList();
- //EM_Coursematerial coursematerialEntity = CoursematerialRepository.Entities.Where(x => x.IsEnable == true && x.CourseName == enA.CoursematerialName).FirstOrDefault();
- CF_TeachingMaterialPool teachingMaterialPool = new CF_TeachingMaterialPool()
- {
- TeachingMaterialPoolID = Guid.NewGuid(),
- WnningLevel = enA.WnningLevelName == null ? -1 : IdNameExt.GetDictionaryItem(DictionaryItem.CF_WnningLevel.ToString())
- .Where(x => x.Name == enA.WnningLevelName).FirstOrDefault().Value,
- PublishID = publishEntity.PublishID,
- Author = enA.Author.Trim(),
- ISBN = enA.ISBN.Trim(),
- IsLate = false,
- PublishTime = enA.PublishTime,
- TeachingMaterialCode = enA.TeachingMaterialCode,
- TeachingMaterialName = enA.TeachingMaterialName,
- TeachingMaterialShorName = enA.TeachingMaterialName,
- TeachingMaterialTypeID = enA.TeachingMaterialTypeName == null ? -1 : IdNameExt.GetDictionaryItem(DictionaryItem.CF_TeachingMaterialType.ToString())
- .Where(x => x.Name == enA.TeachingMaterialTypeName)
- .FirstOrDefault().Value,
- Price = enA.Price == null ? 0 : enA.Price,
- EM_Coursematerial = new HashSet<EM_Coursematerial>(coursematerialEntityList.Where(x => curCoursematerialNameList.Contains(x.CourseName)).ToList()),
- Desc = enA.Desc,
- CreateTime = DateTime.Now,
- CreateUserID = curUser.UserID,
- MinInventory = 1,//最小库存量默认1
- ModifyUserID = curUser.UserID,
- ModifyTime = DateTime.Now
- };
- tpList.Add(teachingMaterialPool);
- }
- #endregion
- UnitOfWork.BulkInsert(tpList);//统一写入
- #endregion
- #endregion
- #region 1.3 返回各项数据值
- successCount = enlist.Distinct().Count() - errList.Distinct().Count();//共条数减去失败条数
- errdataList = errList.Distinct().ToList();
- OkCount = errList.Distinct().Count();
- #endregion
- }
- public string GetLastTeachingMaterialCode()
- {
- List<string> codeList = TeachingMaterialPoolRepository.Entities.Select(x => x.TeachingMaterialCode).ToList();
- string pattern = "^[0-9]*$";
- int newcodeInt = 1;
- List<string> newcodeList = new List<string>();
- foreach (string code in codeList)
- {
- if (Regex.IsMatch(code, pattern))
- {
- newcodeList.Add(code);
- }
- }
- newcodeList.OrderByDescending(x => x.ToString().Length).ThenByDescending(x => x.ToString());
- string newcode = newcodeList.OrderByDescending(x => x.ToString().Length).ThenByDescending(x => x.ToString()).FirstOrDefault();
- if (newcode != "" && newcode != String.Empty && newcode != null)
- {
- newcodeInt = int.Parse(newcode) + 1;
- }
- return (newcodeInt).ToString();
- }
- }
- }
|