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; }
///
/// 查询对应的教室信息View
///
///
///
///
///
///
///
///
///
///
///
///
///
public IGridResultSet GetClassroomViewGrid(ConfiguretView configuretView, Guid? campusID, Guid? buildingsInfoID, string classroomName, int? classroomTypeID,
Guid? collegeID, int? isConcurrentUse, int? isReserve, int? isAvailable, int pageIndex, int pageSize)
{
Expression> 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(pageIndex, pageSize);
}
///
/// 查询对应的教室信息List
///
///
///
///
///
///
///
///
///
///
///
public IList GetClassroomViewList(ConfiguretView configuretView, Guid? campusID, Guid? buildingsInfoID, string classroomName, int? classroomTypeID,
Guid? collegeID, int? isConcurrentUse, int? isReserve, int? isAvailable)
{
Expression> 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();
}
///
/// 查询对应的教室信息CF_Classroom
///
///
///
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);
}
}
///
/// 查询对应的教室信息ClassroomView
///
///
///
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);
}
}
///
/// 编辑(新增、修改,业务主键:教室编号唯一)
///
///
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(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(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);
}
}
///
/// 增加对应的教室类型(根据教室信息ID、教室类型List)
///
///
///
///
public bool ClassroomModeTypeAdd(Guid? classroomID, List list)
{
try
{
if (list != null && list.Count() > 0)
{
UnitOfWork.Delete(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);
}
}
///
/// 删除
///
///
///
public bool ClassroomDelete(List classroomIDList)
{
try
{
using (TransactionScope ts = new TransactionScope())
{
UnitOfWork.Delete(x => classroomIDList.Contains(x.ClassroomID));
UnitOfWork.Delete(x => classroomIDList.Contains(x.ClassroomID));
ts.Complete();
return true;
}
}
catch (Exception)
{
throw;
}
}
///
/// 根据教室信息ID查询对应的教室类型List
///
///
///
public List GetClassroomTypeList(Guid? classroomID)
{
var query = ClassroomDAL.GetClassroomModeTypeQueryble(classroomID);
return query.OrderBy(x => x).ToList();
}
///
/// 查询教室信息对应的排课分配院系所信息ClassroomView(无数据范围)
///
///
///
///
///
///
///
///
///
public IGridResultSet GetClassroomCollegeViewGrid(ConfiguretView configuretView, Guid? classroomID, Guid? campusID, Guid? collegeID, int? unitCategoryID, int pageIndex, int pageSize)
{
Expression> 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(pageIndex, pageSize);
}
///
/// 查询教室信息对应的排课分配院系所信息List(无数据范围)
///
///
///
///
///
///
///
public IList GetClassroomCollegeViewList(ConfiguretView configuretView, Guid? classroomID, Guid? campusID, Guid? collegeID, int? unitCategoryID)
{
Expression> 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();
}
///
/// Excel教室信息导入
///
///
///
///
///
///
///
public void ClassroomImport(Dictionary cellheader, out int? inCount, out int? upCount, out List errdataList, out int? errCount, string sourcePhysicalPath)
{
try
{
StringBuilder errorMsg = new StringBuilder();
List errList = new List();
// 1.1解析文件,存放到一个List集合里
cellheader.Remove("ErrorMessage");
List enlist = NpoiExcelHelper.ExcelToEntityList(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 newClassroomInList = new List();
List newClassroomUpList = new List();
List newClassroomTypeInList = new List();
List classroomCTDelList = new List();
//将循环中相关数据库查询统一查询出来进行匹配(尽量避免在循环中进行数据库查询)
//建筑信息
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 newClassroomTypeIDList = new List();
//教室编号
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 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(x => classroomCTDelList.Contains(x.ClassroomID));
//批量插入
UnitOfWork.BulkInsert(newClassroomInList);
UnitOfWork.BulkInsert(newClassroomTypeInList);
//批量统一提交更新
if (newClassroomUpList != null && newClassroomUpList.Count() > 0)
{
UnitOfWork.BatchUpdate(newClassroomUpList);
}
ts.Complete();
}
errdataList = errList.Distinct().ToList(); //错误列表List
}
catch (Exception)
{
//目前会出现,由于错误信息字符太长,无法抛出弹出框的问题
throw;
}
}
}
}