123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173 |
- 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.Linq;
- using Bowin.Common.Linq.Entity;
- using Bowin.Common.Utility;
- using EMIS.Entities;
- using EMIS.Utility;
- using EMIS.ViewModel;
- using EMIS.ViewModel.CacheManage;
- using EMIS.ViewModel.UniversityManage.ClassroomManage;
- using EMIS.DataLogic.UniversityManage.ClassroomManage;
- namespace EMIS.CommonLogic.UniversityManage.ClassroomManage
- {
- public class ClassroomServices : BaseServices, IClassroomServices
- {
- public ClassroomDAL ClassroomDAL { get; set; }
- /// <summary>
- /// 查询对应的教室信息View
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="campusID"></param>
- /// <param name="buildingsInfoID"></param>
- /// <param name="classroomName"></param>
- /// <param name="classroomTypeID"></param>
- /// <param name="collegeID"></param>
- /// <param name="isConcurrentUse"></param>
- /// <param name="isReserve"></param>
- /// <param name="isAvailable"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <returns></returns>
- public IGridResultSet<ClassroomView> GetClassroomViewGrid(ConfiguretView configuretView, Guid? campusID, Guid? buildingsInfoID, string classroomName, int? classroomTypeID,
- Guid? collegeID, int? isConcurrentUse, int? isReserve, int? isAvailable, int pageIndex, int pageSize)
- {
- Expression<Func<CF_Classroom, bool>> expClassroom = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (buildingsInfoID.HasValue)
- {
- //建筑信息
- expClassroom = expClassroom.And(x => x.BuildingsInfoID == buildingsInfoID);
- }
- if (!string.IsNullOrEmpty(classroomName) && classroomName != "-1")
- {
- //教室名称
- expClassroom = expClassroom.And(x => x.Name == classroomName);
- }
- if (classroomTypeID.HasValue)
- {
- //教室类型(模糊查询)
- expClassroom = expClassroom.And(x => x.CF_ClassroomType.Select(w => w.ClassroomType).Contains(classroomTypeID));
- }
- if (collegeID.HasValue)
- {
- //院系所
- expClassroom = expClassroom.And(x => x.CollegeID == collegeID);
- }
- if (isConcurrentUse.HasValue)
- {
- //可否多班教学
- if (isConcurrentUse.Value == (int)CF_GeneralPurpose.IsYes)
- {
- expClassroom = expClassroom.And(x => x.IsConcurrentUse == true);
- }
- if (isConcurrentUse.Value == (int)CF_GeneralPurpose.IsNo)
- {
- expClassroom = expClassroom.And(x => x.IsConcurrentUse != true);
- }
- }
- if (isAvailable.HasValue)
- {
- //是否可用
- if (isAvailable.Value == (int)CF_GeneralPurpose.IsYes)
- {
- expClassroom = expClassroom.And(x => x.IsAvailable == true);
- }
- if (isAvailable.Value == (int)CF_GeneralPurpose.IsNo)
- {
- expClassroom = expClassroom.And(x => x.IsAvailable != true);
- }
- }
- var query = ClassroomDAL.GetClassroomViewQueryable(expClassroom);
- if (campusID.HasValue)
- {
- //校区
- query = query.Where(x => x.CampusID == campusID);
- }
- if (isReserve.HasValue)
- {
- //是否预留(排课用)
- if (isReserve.Value == (int)CF_GeneralPurpose.IsYes)
- {
- query = query.Where(x => x.IsReserve == true);
- }
- if (isReserve.Value == (int)CF_GeneralPurpose.IsNo)
- {
- query = query.Where(x => x.IsReserve != true);
- }
- }
- //查询条件
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- {
- query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
- }
- return this.GetQueryByDataRangeByCampus(query).OrderBy(x => x.CampusCode.Length).ThenBy(x => x.CampusCode)
- .ThenBy(x => x.BuildingsInfoCode.Length).ThenBy(x => x.BuildingsInfoCode).ThenBy(x => x.Code.Length)
- .ThenBy(x => x.Code).ThenBy(x => x.RoomUseID).ThenBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode).ToGridResultSet<ClassroomView>(pageIndex, pageSize);
- }
- /// <summary>
- /// 查询对应的教室信息List
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="campusID"></param>
- /// <param name="buildingsInfoID"></param>
- /// <param name="classroomName"></param>
- /// <param name="classroomTypeID"></param>
- /// <param name="collegeID"></param>
- /// <param name="isConcurrentUse"></param>
- /// <param name="isReserve"></param>
- /// <param name="isAvailable"></param>
- /// <returns></returns>
- public IList<ClassroomView> GetClassroomViewList(ConfiguretView configuretView, Guid? campusID, Guid? buildingsInfoID, string classroomName, int? classroomTypeID,
- Guid? collegeID, int? isConcurrentUse, int? isReserve, int? isAvailable)
- {
- Expression<Func<CF_Classroom, bool>> expClassroom = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (buildingsInfoID.HasValue)
- {
- //建筑信息
- expClassroom = expClassroom.And(x => x.BuildingsInfoID == buildingsInfoID);
- }
- if (!string.IsNullOrEmpty(classroomName) && classroomName != "-1")
- {
- //教室名称
- expClassroom = expClassroom.And(x => x.Name == classroomName);
- }
- if (classroomTypeID.HasValue)
- {
- //教室类型(模糊查询)
- expClassroom = expClassroom.And(x => x.CF_ClassroomType.Select(w => w.ClassroomType).Contains(classroomTypeID));
- }
- if (collegeID.HasValue)
- {
- //院系所
- expClassroom = expClassroom.And(x => x.CollegeID == collegeID);
- }
- if (isConcurrentUse.HasValue)
- {
- //可否多班教学
- if (isConcurrentUse.Value == (int)CF_GeneralPurpose.IsYes)
- {
- expClassroom = expClassroom.And(x => x.IsConcurrentUse == true);
- }
- if (isConcurrentUse.Value == (int)CF_GeneralPurpose.IsNo)
- {
- expClassroom = expClassroom.And(x => x.IsConcurrentUse != true);
- }
- }
- if (isAvailable.HasValue)
- {
- //是否可用
- if (isAvailable.Value == (int)CF_GeneralPurpose.IsYes)
- {
- expClassroom = expClassroom.And(x => x.IsAvailable == true);
- }
- if (isAvailable.Value == (int)CF_GeneralPurpose.IsNo)
- {
- expClassroom = expClassroom.And(x => x.IsAvailable != true);
- }
- }
- var query = ClassroomDAL.GetClassroomViewQueryable(expClassroom);
- if (campusID.HasValue)
- {
- //校区
- query = query.Where(x => x.CampusID == campusID);
- }
- if (isReserve.HasValue)
- {
- //是否预留(排课用)
- if (isReserve.Value == (int)CF_GeneralPurpose.IsYes)
- {
- query = query.Where(x => x.IsReserve == true);
- }
- if (isReserve.Value == (int)CF_GeneralPurpose.IsNo)
- {
- query = query.Where(x => x.IsReserve != true);
- }
- }
- //查询条件
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- {
- query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
- }
- return this.GetQueryByDataRangeByCampus(query).OrderBy(x => x.CampusCode.Length).ThenBy(x => x.CampusCode)
- .ThenBy(x => x.BuildingsInfoCode.Length).ThenBy(x => x.BuildingsInfoCode).ThenBy(x => x.Code.Length)
- .ThenBy(x => x.Code).ThenBy(x => x.RoomUseID).ThenBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode).ToList();
- }
- /// <summary>
- /// 查询对应的教室信息CF_Classroom
- /// </summary>
- /// <param name="classroomID"></param>
- /// <returns></returns>
- public CF_Classroom GetClassroomInfo(Guid? classroomID)
- {
- try
- {
- var query = ClassroomDAL.ClassroomRepository.GetList(x => x.ClassroomID == classroomID).SingleOrDefault();
- return query;
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
- /// <summary>
- /// 查询对应的教室信息ClassroomView
- /// </summary>
- /// <param name="classroomID"></param>
- /// <returns></returns>
- public ClassroomView GetClassroomView(Guid? classroomID)
- {
- try
- {
- var query = ClassroomDAL.GetClassroomViewQueryable(x => x.ClassroomID == classroomID).SingleOrDefault();
- return query;
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
- /// <summary>
- /// 编辑(新增、修改,业务主键:教室编号唯一)
- /// </summary>
- /// <param name="classroomView"></param>
- public void ClassroomEdit(ClassroomView classroomView)
- {
- try
- {
- //查询数据库进行验证
- var classroomVerify = ClassroomDAL.ClassroomRepository.GetList(x => x.ClassroomID != classroomView.ClassroomID && x.Code == classroomView.Code).FirstOrDefault();
- if (classroomVerify == null)
- {
- //数据有误验证
- if (classroomView.ClassroomID != null && classroomView.ClassroomID != Guid.Empty)
- {
- var classroom = ClassroomDAL.ClassroomRepository.GetList(x => x.ClassroomID == classroomView.ClassroomID, x => x.CF_ClassroomType).SingleOrDefault();
- if (classroom == null)
- {
- throw new Exception("数据有误,请核查");
- }
- else
- {
- //表示修改
- classroom.Code = classroomView.Code.Trim();
- classroom.Name = classroomView.Name.Trim();
- classroom.BuildingsInfoID = classroomView.BuildingsInfoID;
- classroom.CollegeID = classroomView.CollegeID;
- classroom.LayoutTypeID = classroomView.LayoutTypeID;
- classroom.RoomUseID = classroomView.RoomUseID;
- classroom.FloorLevel = classroomView.FloorLevel;
- classroom.Acreage = classroomView.Acreage;
- classroom.RowCout = classroomView.RowCout;
- classroom.ColumnCount = classroomView.ColumnCount;
- classroom.Totalseating = classroomView.Totalseating;
- classroom.Effectiveseating = classroomView.Effectiveseating;
- classroom.Examinationseating = classroomView.Examinationseating;
- classroom.IsWrittenExam = classroomView.IsWrittenExam;
- classroom.IsMachinetest = classroomView.IsMachinetest;
- classroom.IsConcurrentUse = classroomView.IsConcurrentUse;
- classroom.IsAvailable = classroomView.IsAvailable;
- classroom.Remark = classroomView.Remark;
- SetModifyStatus(classroom);
- //教室类型
- if (classroomView.ClassroomTypeIDList != null && classroomView.ClassroomTypeIDList.Count() > 0)
- {
- UnitOfWork.Delete<EMIS.Entities.CF_ClassroomType>(x => x.ClassroomID == classroom.ClassroomID);
- foreach (var classroomTypeID in classroomView.ClassroomTypeIDList)
- {
- EMIS.Entities.CF_ClassroomType classroomModeType = new EMIS.Entities.CF_ClassroomType();
- classroomModeType.ClassroomTypeID = Guid.NewGuid();
- classroomModeType.ClassroomID = classroom.ClassroomID;
- classroomModeType.ClassroomType = classroomTypeID;
- SetNewStatus(classroomModeType);
- UnitOfWork.Add(classroomModeType);
- }
- }
- }
- }
- else
- {
- //表示新增
- CF_Classroom classroom = new CF_Classroom();
- classroom.ClassroomID = Guid.NewGuid();
- classroom.Code = classroomView.Code.Trim();
- classroom.Name = classroomView.Name.Trim();
- classroom.BuildingsInfoID = classroomView.BuildingsInfoID;
- classroom.CollegeID = classroomView.CollegeID;
- classroom.LayoutTypeID = classroomView.LayoutTypeID;
- classroom.RoomUseID = classroomView.RoomUseID;
- classroom.FloorLevel = classroomView.FloorLevel;
- classroom.Acreage = classroomView.Acreage;
- classroom.RowCout = classroomView.RowCout;
- classroom.ColumnCount = classroomView.ColumnCount;
- classroom.Totalseating = classroomView.Totalseating;
- classroom.Effectiveseating = classroomView.Effectiveseating;
- classroom.Examinationseating = classroomView.Examinationseating;
- classroom.IsWrittenExam = classroomView.IsWrittenExam;
- classroom.IsMachinetest = classroomView.IsMachinetest;
- classroom.IsConcurrentUse = classroomView.IsConcurrentUse;
- classroom.IsAvailable = classroomView.IsAvailable;
- classroom.Remark = classroomView.Remark;
- SetNewStatus(classroom);
- UnitOfWork.Add(classroom);
- //教室类型
- if (classroomView.ClassroomTypeIDList != null && classroomView.ClassroomTypeIDList.Count() > 0)
- {
- //UnitOfWork.Delete<EMIS.Entities.CF_ClassroomType>(x => x.ClassroomID == classroom.ClassroomID);
- foreach (var classroomTypeID in classroomView.ClassroomTypeIDList)
- {
- EMIS.Entities.CF_ClassroomType classroomModeType = new EMIS.Entities.CF_ClassroomType();
- classroomModeType.ClassroomTypeID = Guid.NewGuid();
- classroomModeType.ClassroomID = classroom.ClassroomID;
- classroomModeType.ClassroomType = classroomTypeID;
- SetNewStatus(classroomModeType);
- UnitOfWork.Add(classroomModeType);
- }
- }
- }
- }
- else
- {
- throw new Exception("已存在相同的教室编号,请核查");
- }
- //事务提交
- UnitOfWork.Commit();
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
- /// <summary>
- /// 增加对应的教室类型(根据教室信息ID、教室类型List)
- /// </summary>
- /// <param name="classroomID"></param>
- /// <param name="list"></param>
- /// <returns></returns>
- public bool ClassroomModeTypeAdd(Guid? classroomID, List<int> list)
- {
- try
- {
- if (list != null && list.Count() > 0)
- {
- UnitOfWork.Delete<EMIS.Entities.CF_ClassroomType>(x => x.ClassroomID == classroomID);
- foreach (var value in list)
- {
- EMIS.Entities.CF_ClassroomType classroomModeType = new EMIS.Entities.CF_ClassroomType();
- classroomModeType.ClassroomTypeID = Guid.NewGuid();
- classroomModeType.ClassroomID = classroomID;
- classroomModeType.ClassroomType = value;
- SetNewStatus(classroomModeType);
- UnitOfWork.Add(classroomModeType);
- }
- UnitOfWork.Commit();
- return true;
- }
- return false;
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="classroomIDList"></param>
- /// <returns></returns>
- public bool ClassroomDelete(List<Guid?> classroomIDList)
- {
- try
- {
- using (TransactionScope ts = new TransactionScope())
- {
- UnitOfWork.Delete<EMIS.Entities.CF_ClassroomType>(x => classroomIDList.Contains(x.ClassroomID));
- UnitOfWork.Delete<CF_Classroom>(x => classroomIDList.Contains(x.ClassroomID));
- ts.Complete();
- return true;
- }
- }
- catch (Exception)
- {
- throw;
- }
- }
- /// <summary>
- /// 根据教室信息ID查询对应的教室类型List
- /// </summary>
- /// <param name="classroomID"></param>
- /// <returns></returns>
- public List<int> GetClassroomTypeList(Guid? classroomID)
- {
- var query = ClassroomDAL.GetClassroomModeTypeQueryble(classroomID);
- return query.OrderBy(x => x).ToList();
- }
- /// <summary>
- /// 查询教室信息对应的排课分配院系所信息ClassroomView(无数据范围)
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="classroomID"></param>
- /// <param name="campusID"></param>
- /// <param name="collegeID"></param>
- /// <param name="unitCategoryID"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <returns></returns>
- public IGridResultSet<ClassroomView> GetClassroomCollegeViewGrid(ConfiguretView configuretView, Guid? classroomID, Guid? campusID, Guid? collegeID, int? unitCategoryID, int pageIndex, int pageSize)
- {
- Expression<Func<CF_Classroom, bool>> expClassroom = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- expClassroom = expClassroom.And(x => x.ClassroomID == classroomID);
- var query = ClassroomDAL.GetClassroomCollegeViewQueryable(expClassroom);
- if (campusID.HasValue)
- {
- query = query.Where(x => x.CollegeCampusID == campusID);
- }
- if (collegeID.HasValue)
- {
- query = query.Where(x => x.CollegeID == collegeID);
- }
- if (unitCategoryID.HasValue)
- {
- query = query.Where(x => x.UnitCategoryID == unitCategoryID);
- }
- //查询条件
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- {
- query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
- }
- return query.OrderBy(x => x.Code.Length).ThenBy(x => x.Code).ThenBy(x => x.RoomUseID).ThenBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode)
- .OrderBy(x => x.CollegeCampusCode.Length).ThenBy(x => x.CollegeCampusCode).ToGridResultSet<ClassroomView>(pageIndex, pageSize);
- }
- /// <summary>
- /// 查询教室信息对应的排课分配院系所信息List(无数据范围)
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="classroomID"></param>
- /// <param name="campusID"></param>
- /// <param name="collegeID"></param>
- /// <param name="unitCategoryID"></param>
- /// <returns></returns>
- public IList<ClassroomView> GetClassroomCollegeViewList(ConfiguretView configuretView, Guid? classroomID, Guid? campusID, Guid? collegeID, int? unitCategoryID)
- {
- Expression<Func<CF_Classroom, bool>> expClassroom = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- expClassroom = expClassroom.And(x => x.ClassroomID == classroomID);
- var query = ClassroomDAL.GetClassroomCollegeViewQueryable(expClassroom);
- if (campusID.HasValue)
- {
- query = query.Where(x => x.CollegeCampusID == campusID);
- }
- if (collegeID.HasValue)
- {
- query = query.Where(x => x.CollegeID == collegeID);
- }
- if (unitCategoryID.HasValue)
- {
- query = query.Where(x => x.UnitCategoryID == unitCategoryID);
- }
- //查询条件
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- {
- query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
- }
- return query.OrderBy(x => x.Code.Length).ThenBy(x => x.Code).ThenBy(x => x.RoomUseID).ThenBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode)
- .OrderBy(x => x.CollegeCampusCode.Length).ThenBy(x => x.CollegeCampusCode).ToList();
- }
- /// <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 ClassroomImport(Dictionary<string, string> cellheader, out int? inCount, out int? upCount, out List<ClassroomView> errdataList, out int? errCount, string sourcePhysicalPath)
- {
- try
- {
- StringBuilder errorMsg = new StringBuilder();
- List<ClassroomView> errList = new List<ClassroomView>();
- // 1.1解析文件,存放到一个List集合里
- cellheader.Remove("ErrorMessage");
- List<ClassroomView> enlist = NpoiExcelHelper.ExcelToEntityList<ClassroomView>(cellheader, sourcePhysicalPath, out errorMsg, out errList);
- cellheader.Add("ErrorMessage", "未导入原因");
- //对List集合进行有效性校验
- if (enlist.Count() <= 0)
- {
- throw new Exception("Excel文件数据为空,请检查。");
- }
- Regex reg = null; //正则表达式
- //DateTime result; //用于返回判断日期字段格式
- bool isClassroomTypePass = true; //教室类型判断标识
- inCount = 0; //导入个数
- upCount = 0; //更新个数
- errCount = 0; //失败个数
- string errorMsgStr = ""; //错误信息
- List<CF_Classroom> newClassroomInList = new List<CF_Classroom>();
- List<CF_Classroom> newClassroomUpList = new List<CF_Classroom>();
- List<EMIS.Entities.CF_ClassroomType> newClassroomTypeInList = new List<Entities.CF_ClassroomType>();
- List<Guid?> classroomCTDelList = new List<Guid?>();
- //将循环中相关数据库查询统一查询出来进行匹配(尽量避免在循环中进行数据库查询)
- //建筑信息
- var buildingsInfoList = ClassroomDAL.BuildingsInfoRepository.GetList(x => true).ToList();
- //建筑编号
- var buildingsInfoCodeList = enlist.Where(x => !string.IsNullOrEmpty(x.BuildingsInfoCode)).Select(x => x.BuildingsInfoCode).ToList();
- //对比后的newBuildingsInfoList
- var newBuildingsInfoList = buildingsInfoList.Where(x => buildingsInfoCodeList.Contains(x.Code)).ToList();
- //院系所信息
- var collegeList = ClassroomDAL.CollegeRepository.GetList(x => true, x => x.CF_Campus).ToList();
- //院系所代码
- var collegeNoList = enlist.Where(x => !string.IsNullOrEmpty(x.CollegeCode)).Select(x => x.CollegeCode).ToList();
- //对比后的newCollegeList
- var newCollegeList = collegeList.Where(x => collegeNoList.Contains(x.No)).ToList();
- //房间用途
- var roomUseList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_RoomUse).ToList();
- //教室类型
- var classroomTypeDicList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_ClassroomType).ToList();
- //是否启用
- var generalPurposeList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_GeneralPurpose).ToList();
- //教室信息
- var classroomList = ClassroomDAL.ClassroomRepository.GetList(x => true).ToList();
- //教室编号
- var classroomCodeList = enlist.Where(x => !string.IsNullOrEmpty(x.Code)).Select(x => x.Code).ToList();
- //对比后的newClassroomList(暂时只对比教室编号)
- var newClassroomList = classroomList.Where(x => classroomCodeList.Contains(x.Code)).ToList();
- //循环检测数据列,对各数据列进行验证(必填、字典项验证、数据格式等)
- for (int i = 0; i < enlist.Count; i++)
- {
- ClassroomView en = enlist[i]; //Excel表数据视图
- CF_Classroom newClassroom = new CF_Classroom();
- List<int> newClassroomTypeIDList = new List<int>();
- //教室编号
- if (string.IsNullOrWhiteSpace(en.Code))
- {
- errCount++;
- errorMsgStr = "教室编号不能为空";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //教室编号
- newClassroom.Code = en.Code.Trim();
- }
- //教室名称
- if (string.IsNullOrWhiteSpace(en.Name))
- {
- errCount++;
- errorMsgStr = "教室名称不能为空";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //教室名称
- newClassroom.Name = en.Name.Trim();
- }
- //建筑编号
- if (string.IsNullOrWhiteSpace(en.BuildingsInfoCode))
- {
- 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.BuildingsInfoCode.Trim()))
- {
- errCount++;
- errorMsgStr = "建筑编号格式不正确,请检查(数字或英文字母)";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- var buildingsInfo = newBuildingsInfoList.Where(x => x.Code == en.BuildingsInfoCode.Trim()).SingleOrDefault();
- if (buildingsInfo == null)
- {
- errCount++;
- errorMsgStr = "建筑编号不存在,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //建筑信息ID
- newClassroom.BuildingsInfoID = buildingsInfo.BuildingsInfoID;
- //建筑信息对应的校区
- en.CampusID = buildingsInfo.CampusID;
- }
- }
- }
- //院系所代码
- if (string.IsNullOrWhiteSpace(en.CollegeCode))
- {
- //不考虑
- }
- else
- {
- reg = new Regex(@"^[0-9a-zA-Z\s?]+$"); //正则表达式(请输入数字或英文字母)
- if (!reg.IsMatch(en.CollegeCode.Trim()))
- {
- errCount++;
- errorMsgStr = RSL.Get("CollegeCode") + "格式不正确,请检查(数字或英文字母)";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- var college = newCollegeList.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.CampusID == en.CampusID)
- //{
- // //院系所信息ID
- // newClassroom.CollegeID = college.CollegeID;
- //}
- //else
- //{
- // errCount++;
- // errorMsgStr = "建筑信息中对应的" + RSL.Get("CampusCode")
- // + "与" + RSL.Get("CollegeCode") + "对应关系不存在,请检查";
- // en.ErrorMessage = errorMsgStr;
- // errList.Add(en);
- // errorMsg.AppendLine(errorMsgStr);
- // continue;
- //}
- //院系所信息ID
- newClassroom.CollegeID = college.CollegeID;
- }
- }
- }
- //教室类型
- if (string.IsNullOrWhiteSpace(en.ClassroomTypeIDListStr))
- {
- errCount++;
- errorMsgStr = "教室类型不能为空(存在多个教室类型时,可用顿号隔开)";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //教室类型可为多个(可用顿号隔开)
- List<string> list = en.ClassroomTypeIDListStr.Split('、').Where(x => !string.IsNullOrEmpty(x)).Select(x => x.Trim()).Distinct().ToList();
- foreach (var item in list)
- {
- var classroomTypeDic = classroomTypeDicList.Where(x => x.Name == item.Trim()).SingleOrDefault();
- if (classroomTypeDic == null)
- {
- errCount++;
- errorMsgStr = "教室类型(" + item.Trim() + ")不存在,请检查(存在多个教室类型时,可用顿号隔开)";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- isClassroomTypePass = false;
- break;
- }
- }
- if (isClassroomTypePass)
- {
- newClassroomTypeIDList = classroomTypeDicList.Where(x => list.Contains(x.Name)).Select(x => x.Value.Value).ToList();
- }
- else
- {
- isClassroomTypePass = true;
- continue;
- }
- }
- //布局类型(暂不考虑)
- //房间用途
- if (string.IsNullOrWhiteSpace(en.RoomUseStr))
- {
- //不考虑
- }
- else
- {
- var roomUse = roomUseList.Where(x => x.Name == en.RoomUseStr.Trim()).SingleOrDefault();
- if (roomUse == null)
- {
- errCount++;
- errorMsgStr = "房间用途不存在,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //房间用途
- newClassroom.RoomUseID = roomUse.Value;
- }
- }
- //所在楼层
- if (string.IsNullOrWhiteSpace(en.FloorLevelStr))
- {
- //不考虑
- }
- else
- {
- reg = new Regex(@"^-?\d+$"); //正则表达式(整数)
- if (!reg.IsMatch(en.FloorLevelStr.Trim()))
- {
- errCount++;
- errorMsgStr = "所在楼层格式不正确,请检查(请输入整数)";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //所在楼层
- newClassroom.FloorLevel = Convert.ToInt32(en.FloorLevelStr.Trim());
- }
- }
- //面积
- if (string.IsNullOrWhiteSpace(en.AcreageStr))
- {
- //不考虑
- }
- else
- {
- reg = new Regex(@"^[0-9]+([.]{1}[0-9]+){0,1}$"); //正则表达式()
- if (!reg.IsMatch(en.AcreageStr.Trim()))
- {
- errCount++;
- errorMsgStr = "面积格式不正确,请检查(请输入数字)";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //面积
- newClassroom.Acreage = Convert.ToDecimal(en.AcreageStr.Trim());
- }
- }
- //行数
- if (string.IsNullOrWhiteSpace(en.RowCoutStr))
- {
- //不考虑
- }
- else
- {
- reg = new Regex(@"^\d+$"); //正则表达式(非负整数)
- if (!reg.IsMatch(en.RowCoutStr.Trim()))
- {
- errCount++;
- errorMsgStr = "行数格式不正确,请检查(请输入非负整数)";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //行数
- newClassroom.RowCout = Convert.ToInt32(en.RowCoutStr.Trim());
- }
- }
- //列数
- if (string.IsNullOrWhiteSpace(en.ColumnCountStr))
- {
- //不考虑
- }
- else
- {
- reg = new Regex(@"^\d+$"); //正则表达式(非负整数)
- if (!reg.IsMatch(en.ColumnCountStr.Trim()))
- {
- errCount++;
- errorMsgStr = "列数格式不正确,请检查(请输入负零整数)";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //列数
- newClassroom.ColumnCount = Convert.ToInt32(en.ColumnCountStr.Trim());
- }
- }
- //总座位数
- if (string.IsNullOrWhiteSpace(en.TotalseatingStr))
- {
- //不考虑
- }
- else
- {
- reg = new Regex(@"^\d+$"); //正则表达式(非负整数)
- if (!reg.IsMatch(en.TotalseatingStr.Trim()))
- {
- errCount++;
- errorMsgStr = "总座位数格式不正确,请检查(请输入非负整数)";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //总座位数
- newClassroom.Totalseating = Convert.ToInt32(en.TotalseatingStr.Trim());
- }
- }
- //有效座位数
- if (string.IsNullOrWhiteSpace(en.EffectiveseatingStr))
- {
- //不考虑
- }
- else
- {
- reg = new Regex(@"^\d+$"); //正则表达式(非负整数)
- if (!reg.IsMatch(en.EffectiveseatingStr.Trim()))
- {
- errCount++;
- errorMsgStr = "有效座位数格式不正确,请检查(请输入非负整数)";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //有效座位数
- newClassroom.Effectiveseating = Convert.ToInt32(en.EffectiveseatingStr.Trim());
- //座位判断
- if (newClassroom.Totalseating != null)
- {
- if (newClassroom.Effectiveseating.Value > newClassroom.Totalseating.Value)
- {
- errCount++;
- errorMsgStr = "有效座位数不能大于总座位数,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- }
- }
- }
- //考试座位数
- if (string.IsNullOrWhiteSpace(en.ExaminationseatingStr))
- {
- //不考虑
- }
- else
- {
- reg = new Regex(@"^\d+$"); //正则表达式(非负整数)
- if (!reg.IsMatch(en.ExaminationseatingStr.Trim()))
- {
- errCount++;
- errorMsgStr = "考试座位数格式不正确,请检查(请输入非负整数)";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //考试座位数
- newClassroom.Examinationseating = Convert.ToInt32(en.ExaminationseatingStr.Trim());
- //座位判断
- if (newClassroom.Totalseating != null)
- {
- if (newClassroom.Examinationseating.Value > newClassroom.Totalseating.Value)
- {
- errCount++;
- errorMsgStr = "考试座位数不能大于总座位数,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- }
- }
- }
- //可否笔试
- if (string.IsNullOrWhiteSpace(en.IsWrittenExamStr))
- {
- //可否笔试(默认为否)
- newClassroom.IsWrittenExam = false;
- }
- else
- {
- var generalPurpose = generalPurposeList.Where(x => x.Name == en.IsWrittenExamStr.Trim()).SingleOrDefault();
- if (generalPurpose == null)
- {
- errCount++;
- errorMsgStr = "可否笔试不存在,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //可否笔试
- newClassroom.IsWrittenExam = generalPurpose.Value == (int)CF_GeneralPurpose.IsYes ? true : false;
- }
- }
- //可否机试
- if (string.IsNullOrWhiteSpace(en.IsMachinetestStr))
- {
- //可否机试(默认为否)
- newClassroom.IsMachinetest = false;
- }
- else
- {
- var generalPurpose = generalPurposeList.Where(x => x.Name == en.IsMachinetestStr.Trim()).SingleOrDefault();
- if (generalPurpose == null)
- {
- errCount++;
- errorMsgStr = "可否机试不存在,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //可否机试
- newClassroom.IsMachinetest = generalPurpose.Value == (int)CF_GeneralPurpose.IsYes ? true : false;
- }
- }
- //可否多班教学
- if (string.IsNullOrWhiteSpace(en.IsConcurrentUseStr))
- {
- //可否多班教学(默认为否)
- newClassroom.IsConcurrentUse = false;
- }
- else
- {
- var generalPurpose = generalPurposeList.Where(x => x.Name == en.IsConcurrentUseStr.Trim()).SingleOrDefault();
- if (generalPurpose == null)
- {
- errCount++;
- errorMsgStr = "可否多班教学不存在,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //可否多班教学
- newClassroom.IsConcurrentUse = generalPurpose.Value == (int)CF_GeneralPurpose.IsYes ? true : false;
- }
- }
- //是否可用
- if (string.IsNullOrWhiteSpace(en.IsAvailableStr))
- {
- errCount++;
- errorMsgStr = "是否可用不能为空";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- var generalPurpose = generalPurposeList.Where(x => x.Name == en.IsAvailableStr.Trim()).SingleOrDefault();
- if (generalPurpose == null)
- {
- errCount++;
- errorMsgStr = "是否可用不存在,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //是否可用
- newClassroom.IsAvailable = generalPurpose.Value == (int)CF_GeneralPurpose.IsYes ? true : false;
- }
- }
- //备注
- if (string.IsNullOrWhiteSpace(en.Remark))
- {
- //不考虑
- }
- else
- {
- newClassroom.Remark = en.Remark;
- }
- ////Excel表重复性验证(注:当数据表中没有此记录,但是Excel中有重复数据时的去掉)
- //for (int j = i + 1; j < enlist.Count; j++)
- //{
- // NewClassroomView enA = enlist[j];
- // //根据Excel表中的业务主键进行去重(教室编号唯一)
- // if (en.No == enA.No && en.Name == enA.Name)
- // {
- // //用于标识Excel表中的重复记录(由于是批量进行插入数据表)
- // }
- //}
- //数据表重复性验证(教室编号唯一)
- var classroomVerify = newClassroomList.Where(x => x.Code == newClassroom.Code).SingleOrDefault();
- if (classroomVerify == null)
- {
- //新增
- if (!newClassroomInList.Any(x => x.Code == newClassroom.Code))
- {
- newClassroom.ClassroomID = Guid.NewGuid();
- SetNewStatus(newClassroom);
- newClassroomInList.Add(newClassroom);
- //教室类型
- if (newClassroomTypeIDList != null && newClassroomTypeIDList.Count() > 0)
- {
- foreach (var value in newClassroomTypeIDList)
- {
- EMIS.Entities.CF_ClassroomType classroomModeType = new EMIS.Entities.CF_ClassroomType();
- classroomModeType.ClassroomTypeID = Guid.NewGuid();
- classroomModeType.ClassroomID = newClassroom.ClassroomID;
- classroomModeType.ClassroomType = value;
- SetNewStatus(classroomModeType);
- newClassroomTypeInList.Add(classroomModeType);
- }
- }
- inCount++;
- }
- else
- {
- //Excel表重复性验证
- //(注:当数据表中没有此记录,但是Excel中有重复数据,可在此处进行抛出到失败数据文件中,目前暂不考虑)
- inCount++;
- }
- }
- else
- {
- //更新(Excel有重复时,以最后一条记录的更新为准)
- classroomVerify.Name = newClassroom.Name;
- classroomVerify.BuildingsInfoID = newClassroom.BuildingsInfoID;
- classroomVerify.CollegeID = newClassroom.CollegeID;
- classroomVerify.LayoutTypeID = newClassroom.LayoutTypeID;
- classroomVerify.RoomUseID = newClassroom.RoomUseID;
- classroomVerify.FloorLevel = newClassroom.FloorLevel;
- classroomVerify.Acreage = newClassroom.Acreage;
- classroomVerify.RowCout = newClassroom.RowCout;
- classroomVerify.ColumnCount = newClassroom.ColumnCount;
- classroomVerify.Totalseating = newClassroom.Totalseating;
- classroomVerify.Effectiveseating = newClassroom.Effectiveseating;
- classroomVerify.Examinationseating = newClassroom.Examinationseating;
- classroomVerify.IsWrittenExam = newClassroom.IsWrittenExam;
- classroomVerify.IsMachinetest = newClassroom.IsMachinetest;
- classroomVerify.IsConcurrentUse = newClassroom.IsConcurrentUse;
- classroomVerify.IsAvailable = newClassroom.IsAvailable;
- classroomVerify.Remark = newClassroom.Remark;
- SetModifyStatus(classroomVerify);
- newClassroomUpList.Add(classroomVerify);
- //教室类型
- if (newClassroomTypeIDList != null && newClassroomTypeIDList.Count() > 0)
- {
- if (newClassroomTypeInList.Any(x => x.ClassroomID == classroomVerify.ClassroomID))
- {
- newClassroomTypeInList.RemoveAll(x => x.ClassroomID == classroomVerify.ClassroomID);
- }
- classroomCTDelList.Add(classroomVerify.ClassroomID);
- foreach (var value in newClassroomTypeIDList)
- {
- EMIS.Entities.CF_ClassroomType classroomModeType = new EMIS.Entities.CF_ClassroomType();
- classroomModeType.ClassroomTypeID = Guid.NewGuid();
- classroomModeType.ClassroomID = classroomVerify.ClassroomID;
- classroomModeType.ClassroomType = value;
- SetNewStatus(classroomModeType);
- newClassroomTypeInList.Add(classroomModeType);
- }
- }
- else
- {
- classroomCTDelList.Add(classroomVerify.ClassroomID);
- }
- upCount++;
- }
- }
- using (TransactionScope ts = new TransactionScope())
- {
- //删除
- UnitOfWork.Delete<EMIS.Entities.CF_ClassroomType>(x => classroomCTDelList.Contains(x.ClassroomID));
- //批量插入
- UnitOfWork.BulkInsert(newClassroomInList);
- UnitOfWork.BulkInsert<EMIS.Entities.CF_ClassroomType>(newClassroomTypeInList);
- //批量统一提交更新
- if (newClassroomUpList != null && newClassroomUpList.Count() > 0)
- {
- UnitOfWork.BatchUpdate(newClassroomUpList);
- }
- ts.Complete();
- }
- errdataList = errList.Distinct().ToList(); //错误列表List
- }
- catch (Exception)
- {
- //目前会出现,由于错误信息字符太长,无法抛出弹出框的问题
- throw;
- }
- }
- }
- }
|