123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Linq.Expressions;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Transactions;
- using Bowin.Common.Utility;
- using Bowin.Common.Linq;
- using Bowin.Common.Linq.Entity;
- using EMIS.Utility;
- using EMIS.Entities;
- using EMIS.ViewModel;
- using EMIS.ViewModel.CacheManage;
- using EMIS.ViewModel.EnrollManage.SpecialtyManage;
- using EMIS.DataLogic.EnrollManage.SpecialtyManage;
- namespace EMIS.CommonLogic.EnrollManage.SpecialtyManage
- {
- public class CustomStandardSettingServices : BaseServices, ICustomStandardSettingServices
- {
- public CustomStandardSettingDAL customStandardSettingDAL { get; set; }
- /// <summary>
- /// 查询对应的省招专业信息View
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="campusID"></param>
- /// <param name="collegeID"></param>
- /// <param name="yearID"></param>
- /// <param name="standardID"></param>
- /// <param name="educationID"></param>
- /// <param name="learningformID"></param>
- /// <param name="learnSystem"></param>
- /// <param name="semesterID"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <returns></returns>
- public IGridResultSet<CustomStandardSettingView> GetCustomStandardSettingViewGrid(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? yearID,
- int? standardID, int? educationID, int? learningformID, string learnSystem, int? semesterID, int pageIndex, int pageSize)
- {
- Expression<Func<CF_CustomStandardSetting, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (collegeID.HasValue)
- {
- exp = exp.And(x => x.CollegeID == collegeID);
- }
- if (yearID.HasValue)
- {
- exp = exp.And(x => x.YearID == yearID);
- }
- if (semesterID.HasValue)
- {
- exp = exp.And(x => x.SemesterID == semesterID);
- }
- var query = customStandardSettingDAL.GetCustomStandardSettingViewQueryable(exp);
- if (campusID.HasValue)
- {
- query = query.Where(x => x.CampusID == campusID);
- }
- if (standardID.HasValue)
- {
- query = query.Where(x => x.StandardID == standardID);
- }
- if (educationID.HasValue)
- {
- query = query.Where(x => x.EducationID == educationID);
- }
- if (learningformID.HasValue)
- {
- query = query.Where(x => x.LearningformID == learningformID);
- }
- if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1")
- {
- var LearnSystems = Convert.ToDecimal(learnSystem);
- query = query.Where(x => x.LearnSystem == LearnSystems);
- }
- //查询条件
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- {
- query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
- }
- return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode).ThenByDescending(x => x.YearID)
- .ThenBy(x => x.StandardName).ThenBy(x => x.EducationID).ThenBy(x => x.LearningformID).ThenBy(x => x.LearnSystem).ToGridResultSet<CustomStandardSettingView>(pageIndex, pageSize);
- }
- /// <summary>
- /// 查询对应的省招专业信息List
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="campusID"></param>
- /// <param name="collegeID"></param>
- /// <param name="yearID"></param>
- /// <param name="standardID"></param>
- /// <param name="educationID"></param>
- /// <param name="learningformID"></param>
- /// <param name="learnSystem"></param>
- /// <param name="semesterID"></param>
- /// <returns></returns>
- public IList<CustomStandardSettingView> GetCustomStandardSettingViewList(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? yearID,
- int? standardID, int? educationID, int? learningformID, string learnSystem, int? semesterID)
- {
- Expression<Func<CF_CustomStandardSetting, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (collegeID.HasValue)
- {
- exp = exp.And(x => x.CollegeID == collegeID);
- }
- if (yearID.HasValue)
- {
- exp = exp.And(x => x.YearID == yearID);
- }
- if (semesterID.HasValue)
- {
- exp = exp.And(x => x.SemesterID == semesterID);
- }
- var query = customStandardSettingDAL.GetCustomStandardSettingViewQueryable(exp);
- if (campusID.HasValue)
- {
- query = query.Where(x => x.CampusID == campusID);
- }
- if (standardID.HasValue)
- {
- query = query.Where(x => x.StandardID == standardID);
- }
- if (educationID.HasValue)
- {
- query = query.Where(x => x.EducationID == educationID);
- }
- if (learningformID.HasValue)
- {
- query = query.Where(x => x.LearningformID == learningformID);
- }
- if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1")
- {
- var LearnSystems = Convert.ToDecimal(learnSystem);
- query = query.Where(x => x.LearnSystem == LearnSystems);
- }
- //查询条件
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- {
- query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
- }
- return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode).ThenByDescending(x => x.YearID)
- .ThenBy(x => x.StandardName).ThenBy(x => x.EducationID).ThenBy(x => x.LearningformID).ThenBy(x => x.LearnSystem).ToList();
- }
- /// <summary>
- /// 查询对应的省招专业信息CustomStandardSettingView
- /// </summary>
- /// <param name="customStandardSettingID"></param>
- /// <returns></returns>
- public CustomStandardSettingView GetCustomStandardSettingView(Guid? customStandardSettingID)
- {
- try
- {
- var query = customStandardSettingDAL.GetCustomStandardSettingViewQueryable(x => x.CustomStandardSettingID == customStandardSettingID).SingleOrDefault();
- return query;
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
- /// <summary>
- /// 编辑(新增、修改,业务主键:省招代码或学年、学期、院系所、专业信息ID唯一)
- /// </summary>
- /// <param name="customStandardSettingView"></param>
- public void CustomStandardSettingEdit(CustomStandardSettingView customStandardSettingView)
- {
- try
- {
- var customStandardSettingVerification = customStandardSettingDAL.customStandardSettingRepository.GetList(x => x.CustomStandardSettingID != customStandardSettingView.CustomStandardSettingID
- && ((x.YearID == customStandardSettingView.YearID && x.SemesterID == customStandardSettingView.SemesterID
- && x.CollegeID == customStandardSettingView.CollegeID && x.SpecialtyID == customStandardSettingView.SpecialtyID)
- || (x.Code == customStandardSettingView.Code))).FirstOrDefault();
- if (customStandardSettingVerification == null)
- {
- //数据有误验证
- if (customStandardSettingView.CustomStandardSettingID != Guid.Empty)
- {
- var customStandardSetting = customStandardSettingDAL.customStandardSettingRepository
- .GetList(x => x.CustomStandardSettingID == customStandardSettingView.CustomStandardSettingID).SingleOrDefault();
- if (customStandardSetting == null)
- {
- throw new Exception("数据有误,请核查。");
- }
- else
- {
- //表示修改
- customStandardSetting.Code = customStandardSettingView.Code;
- customStandardSetting.SpecialtyID = customStandardSettingView.SpecialtyID;
- customStandardSetting.CollegeID = customStandardSettingView.CollegeID;
- customStandardSetting.YearID = customStandardSettingView.YearID;
- customStandardSetting.SemesterID = customStandardSettingView.SemesterID;
- customStandardSetting.Remark = customStandardSettingView.Remark;
- SetModifyStatus(customStandardSetting);
- }
- }
- else
- {
- //表示新增
- CF_CustomStandardSetting customStandardSetting = new CF_CustomStandardSetting();
- customStandardSetting.CustomStandardSettingID = Guid.NewGuid();
- customStandardSetting.Code = customStandardSettingView.Code;
- customStandardSetting.SpecialtyID = customStandardSettingView.SpecialtyID;
- customStandardSetting.CollegeID = customStandardSettingView.CollegeID;
- customStandardSetting.YearID = customStandardSettingView.YearID;
- customStandardSetting.SemesterID = customStandardSettingView.SemesterID;
- customStandardSetting.Remark = customStandardSettingView.Remark;
- SetNewStatus(customStandardSetting);
- UnitOfWork.Add(customStandardSetting);
- }
- }
- else
- {
- throw new Exception("存在相同的省招专业信息(省招代码唯一或学年、学期、" + RSL.Get("CollegeName") + "专业信息唯一)。");
- }
- //事务提交
- UnitOfWork.Commit();
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="customStandardSettingIDList"></param>
- /// <returns></returns>
- public bool CustomStandardSettingDelete(List<Guid?> customStandardSettingIDList)
- {
- try
- {
- UnitOfWork.Delete<CF_CustomStandardSetting>(x => customStandardSettingIDList.Contains(x.CustomStandardSettingID));
- return true;
- }
- catch (Exception)
- {
- throw;
- }
- }
- /// <summary>
- /// Excel导入
- /// </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 void CustomStandardSettingImport(Dictionary<string, string> cellheader, out int? inCount, out int? upCount, out List<CustomStandardSettingView> errdataList, out int? errCount, string sourcePhysicalPath)
- {
- try
- {
- StringBuilder errorMsg = new StringBuilder(); // 错误信息
- List<CustomStandardSettingView> errList = new List<CustomStandardSettingView>();
- // 1.1解析文件,存放到一个List集合里
- cellheader.Remove("ErrorMessage");//移除“未导入原因”列(ErrorMessage)
- List<CustomStandardSettingView> enlist = NpoiExcelHelper.ExcelToEntityList<CustomStandardSettingView>(cellheader, sourcePhysicalPath, out errorMsg, out errList);
- cellheader.Add("ErrorMessage", "未导入原因");
- //对List集合进行有效性校验
- if (enlist.Count() <= 0)
- {
- throw new Exception("Excel文件数据为空,请检查。");
- }
- Regex reg = null; //正则表达式
- inCount = 0; //导入个数
- upCount = 0; //更新个数
- errCount = 0; //失败个数
- string errorMsgStr = ""; //错误信息
- //省招专业insert实体List
- List<CF_CustomStandardSetting> customStandardSettingInList = new List<CF_CustomStandardSetting>();
- //省招专业update实体List
- List<CF_CustomStandardSetting> customStandardSettingUpList = new List<CF_CustomStandardSetting>();
- //将循环中相关数据库查询统一查询出来进行匹配(尽量避免在循环中进行数据库查询)
- //省招代码
- var codeList = enlist.Where(x => !string.IsNullOrEmpty(x.Code)).Select(x => x.Code).ToList();
- //省招专业(由于需要和Excel中数据进行比对,数据太多就会报异常,所以需要先查询出来)
- var customStandardSettingAllList = customStandardSettingDAL.customStandardSettingRepository.GetList(x => true).ToList();
- //省招代码对比后的List(省招代码唯一)
- var newCodeList = customStandardSettingAllList.Where(x => codeList.Contains(x.Code)).ToList();
- //学年
- var yearList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Year).ToList();
- //学期
- var semesterList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Semester).ToList();
- //院系所代码
- var collegeCodeList = enlist.Where(x => !string.IsNullOrEmpty(x.CollegeCode)).Select(x => x.CollegeCode).ToList();
- //对应的院系所信息
- var collegeList = customStandardSettingDAL.collegeRepository.GetList(x => collegeCodeList.Contains(x.No), x => x.CF_CollegeProfile).ToList();
- //专业代码、专业名称、专业ID(Value)
- var standardList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Standard).ToList();
- //培养层次(所修学历)
- var educationList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Education).ToList();
- //学习形式
- var learningFormList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Learningform).ToList();
- //专业信息
- var specialtyList = customStandardSettingDAL.specialtyRepository.GetList(x => true).ToList();
- //循环检测数据列,对各数据列进行验证(必填、字典项验证、数据格式等)
- for (int i = 0; i < enlist.Count; i++)
- {
- CustomStandardSettingView en = enlist[i]; //Excel表数据视图
- CF_CustomStandardSetting newCustomStandardSetting = new CF_CustomStandardSetting(); //省招专业实体
- //省招代码(唯一)
- if (string.IsNullOrEmpty(en.Code))
- {
- 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.Code.Trim()))
- {
- errCount++;
- errorMsgStr = "省招代码格式不正确,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //省招代码
- newCustomStandardSetting.Code = en.Code.Trim();
- }
- }
- //学年
- if (string.IsNullOrEmpty(en.YearStr))
- {
- errCount++;
- errorMsgStr = "学年不能为空";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- var year = yearList.Where(x => x.Name == en.YearStr.Trim()).SingleOrDefault();
- if (year == null)
- {
- errCount++;
- errorMsgStr = "学年不存在,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //学年
- newCustomStandardSetting.YearID = year.Value;
- }
- }
- //学期
- if (string.IsNullOrEmpty(en.SemesterStr))
- {
- errCount++;
- errorMsgStr = "学期不能为空";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- var semester = semesterList.Where(x => x.Name == en.SemesterStr.Trim()).SingleOrDefault();
- if (semester == null)
- {
- errCount++;
- errorMsgStr = "学期不存在,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //学期
- newCustomStandardSetting.SemesterID = semester.Value;
- }
- }
- //院系所代码
- if (string.IsNullOrEmpty(en.CollegeCode))
- {
- errCount++;
- errorMsgStr = RSL.Get("CollegeCode") + "不能为空";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- var college = collegeList.Where(x => x.No == en.CollegeCode.Trim()).SingleOrDefault();
- if (college == null)
- {
- errCount++;
- errorMsgStr = RSL.Get("CollegeCode") + "不存在,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- if (college.CF_CollegeProfile == null)
- {
- errCount++;
- errorMsgStr = RSL.Get("CollegeCode") + "所属的单位类别有误,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else if (college.CF_CollegeProfile.UnitCategoryID != (int)CF_UnitCategory.College)
- {
- errCount++;
- errorMsgStr = RSL.Get("CollegeCode") + "所属的单位类别有误,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- //院系所ID
- newCustomStandardSetting.CollegeID = college.CollegeID;
- }
- }
- //专业代码
- if (string.IsNullOrEmpty(en.StandardCodeStr))
- {
- errCount++;
- errorMsgStr = "专业代码不能为空";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- var standardCode = standardList.Where(x => x.Code == en.StandardCodeStr.Trim()).FirstOrDefault();
- if (standardCode == null)
- {
- errCount++;
- errorMsgStr = "专业代码不存在,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //专业代码
- }
- }
- //专业名称
- if (string.IsNullOrEmpty(en.StandardNameStr))
- {
- errCount++;
- errorMsgStr = "专业名称不能为空";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- var standardName = standardList.Where(x => x.Name == en.StandardNameStr.Trim()).FirstOrDefault();
- if (standardName == null)
- {
- errCount++;
- errorMsgStr = "专业名称不存在,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //专业名称
- }
- }
- //专业代码与专业名称查询专业ID(Value)
- if (string.IsNullOrEmpty(en.StandardCodeStr.Trim()) || string.IsNullOrEmpty(en.StandardNameStr.Trim()))
- {
- errCount++;
- errorMsgStr = "专业代码或专业名称不能为空";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- var standardID = standardList.Where(x => x.Code == en.StandardCodeStr.Trim() && x.Name == en.StandardNameStr.Trim()).SingleOrDefault();
- if (standardID == null)
- {
- errCount++;
- errorMsgStr = "专业代码与专业名称对应的元素值不存在,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //专业ID(Value)
- en.StandardID = standardID.Value;
- }
- }
- //培养层次(所修学历)
- if (string.IsNullOrEmpty(en.EducationStr))
- {
- errCount++;
- errorMsgStr = RSL.Get("EducationID") + "不能为空";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- var education = educationList.Where(x => x.Name == en.EducationStr.Trim()).SingleOrDefault();
- if (education == null)
- {
- errCount++;
- errorMsgStr = RSL.Get("EducationID") + "不存在,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //培养层次
- en.EducationID = education.Value;
- }
- }
- //学习形式
- if (string.IsNullOrEmpty(en.LearningformStr))
- {
- errCount++;
- errorMsgStr = "学习形式不能为空";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- var learningForm = learningFormList.Where(x => x.Name == en.LearningformStr.Trim()).SingleOrDefault();
- if (learningForm == null)
- {
- errCount++;
- errorMsgStr = "学习形式不存在,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //学习形式
- en.LearningformID = learningForm.Value;
- }
- }
- //学制
- if (string.IsNullOrEmpty(en.LearnSystemStr))
- {
- errCount++;
- errorMsgStr = "学制不能为空";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- reg = new Regex(@"^[0-9]+([.]{1}[0-9]+){0,1}$"); //学制字段正则表达式()
- if (!reg.IsMatch(en.LearnSystemStr.Trim()))
- {
- errCount++;
- errorMsgStr = "学制格式不正确,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //学制
- en.LearnSystem = Convert.ToDecimal(en.LearnSystemStr);
- }
- }
- //专业信息查询
- var specialty = specialtyList.Where(x => x.StandardID == en.StandardID && x.EducationID == en.EducationID && x.LearningformID == en.LearningformID && x.LearnSystem == en.LearnSystem).SingleOrDefault();
- //专业信息ID
- if (specialty == null)
- {
- errCount++;
- errorMsgStr = "专业信息不存在,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //查询专业信息(启用、禁用状态)
- if (specialty.RecordStatus > (int)SYS_STATUS.UNUSABLE)
- {
- newCustomStandardSetting.SpecialtyID = specialty.SpecialtyID;
- }
- else
- {
- newCustomStandardSetting.SpecialtyID = specialty.SpecialtyID;
- errCount++;
- errorMsgStr = "专业信息为禁用状态,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- }
- //备注
- if (string.IsNullOrEmpty(en.Remark))
- {
- //不考虑
- }
- else
- {
- newCustomStandardSetting.Remark = en.Remark;
- }
- ////Excel表重复性验证(注:当数据表中没有此记录,但是Excel中有重复数据时的去掉)
- //for (int j = i + 1; j < enlist.Count; j++)
- //{
- // CustomStandardSettingView enA = enlist[j];
- // //根据Excel表中的业务主键进行去重(省招代码唯一或学年、学期、院系所ID、专业信息唯一)
- // if (en.Code == enA.Code ||
- // (
- // en.YearStr == enA.YearStr
- // && en.SemesterID == enA.SemesterID
- // && en.CollegeCode == enA.CollegeCode
- // && en.SpecialtyID == enA.SpecialtyID
- // )
- // )
- // {
- // //用于标识Excel表中的重复记录(由于是批量进行插入数据表)
- // }
- //}
- //数据表重复性验证(省招代码唯一)
- var codeVerification = newCodeList.Where(x => x.Code == newCustomStandardSetting.Code).FirstOrDefault();
- if (codeVerification == null)
- {
- //Excel表重复验证
- if (!customStandardSettingInList.Any(x => x.Code == newCustomStandardSetting.Code))
- {
- //数据表重复性验证(学年、学期、院系所ID、专业信息唯一)
- var cusVerification = customStandardSettingAllList.Where(x => x.SpecialtyID == newCustomStandardSetting.SpecialtyID
- && x.CollegeID == newCustomStandardSetting.CollegeID && x.YearID == newCustomStandardSetting.YearID
- && x.SemesterID == newCustomStandardSetting.SemesterID).FirstOrDefault();
- //新增
- if (cusVerification == null)
- {
- //Excel表重复验证
- if (!customStandardSettingInList.Any(x => x.YearID == newCustomStandardSetting.YearID
- && x.SemesterID == newCustomStandardSetting.SemesterID
- && x.CollegeID == newCustomStandardSetting.CollegeID
- && x.SpecialtyID == newCustomStandardSetting.SpecialtyID))
- {
- newCustomStandardSetting.CustomStandardSettingID = Guid.NewGuid();
- SetNewStatus(newCustomStandardSetting);
- customStandardSettingInList.Add(newCustomStandardSetting);
- inCount++;
- }
- else
- {
- //Excel表重复性验证
- //(注:当数据表中没有此记录,但是Excel中有重复数据,可在此处进行抛出到失败数据文件中,目前暂不考虑)
- inCount++;
- }
- }
- else
- {
- //更新(Excel有重复时,以最后一条记录的更新为准)
- //cusVerification.Remark = newCustomStandardSetting.Remark;
- //SetModifyStatus(cusVerification);
- //customStandardSettingUpList.Add(cusVerification);
- //upCount++;
- //(此处暂时以抛出失败数据文件中的方式进行处理)
- errCount++;
- errorMsgStr = "导入失败,已存在相同学年、学期、" + RSL.Get("CollegeCode") + "、专业信息的数据(数据重复)";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- }
- else
- {
- //Excel表重复性验证
- //(注:当数据表中没有此记录,但是Excel中有重复数据,可在此处进行抛出到失败数据文件中,目前暂不考虑)
- inCount++;
- }
- }
- else
- {
- //更新(Excel有重复时,以最后一条记录的更新为准)
- //codeVerification.Remark = newCustomStandardSetting.Remark;
- //SetModifyStatus(codeVerification);
- //customStandardSettingUpList.Add(codeVerification);
- //upCount++;
- //(此处暂时以抛出失败数据文件中的方式进行处理)
- errCount++;
- errorMsgStr = "导入失败,已存在相同的省招代码(数据重复)";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- }
- using (TransactionScope ts = new TransactionScope())
- {
- if (customStandardSettingInList != null && customStandardSettingInList.Count() > 0)
- {
- UnitOfWork.BulkInsert(customStandardSettingInList);
- }
- if (customStandardSettingUpList != null && customStandardSettingUpList.Count() > 0)
- {
- UnitOfWork.BatchUpdate(customStandardSettingUpList);
- }
- ts.Complete();
- }
- errdataList = errList.Distinct().ToList(); //错误列表List
- }
- catch (Exception)
- {
- throw;
- }
- }
- }
- }
|