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 BuildingsInfoServices : BaseServices, IBuildingsInfoServices
{
public BuildingsInfoDAL BuildingsInfoDAL { get; set; }
///
/// 查询对应的建筑信息View
///
///
///
///
///
///
///
///
///
public IGridResultSet GetBuildingsInfoViewGrid(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? buildingsTypeID, int? isSpecial, int pageIndex, int pageSize)
{
Expression> expBuildingsInfo = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
if (campusID.HasValue)
{
//校区
expBuildingsInfo = expBuildingsInfo.And(x => x.CampusID == campusID);
}
if (collegeID.HasValue)
{
//所属院系所
expBuildingsInfo = expBuildingsInfo.And(x => x.CollegeID == collegeID);
}
if (buildingsTypeID.HasValue)
{
//建筑类型
expBuildingsInfo = expBuildingsInfo.And(x => x.BuildingsTypeID == buildingsTypeID);
}
if (isSpecial.HasValue)
{
//是否启用
if (isSpecial.Value == (int)CF_GeneralPurpose.IsYes)
{
expBuildingsInfo = expBuildingsInfo.And(x => x.IsSpecial == true);
}
if (isSpecial.Value == (int)CF_GeneralPurpose.IsNo)
{
expBuildingsInfo = expBuildingsInfo.And(x => x.IsSpecial != true);
}
}
var query = BuildingsInfoDAL.GetBuildingsInfoViewQueryable(expBuildingsInfo);
//查询条件
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.Code.Length)
.ThenBy(x => x.Code).ThenBy(x => x.BuildingsTypeID).ThenBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode).ToGridResultSet(pageIndex, pageSize);
}
///
/// 查询对应的建筑信息List
///
///
///
///
///
///
///
public IList GetBuildingsInfoViewList(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? buildingsTypeID, int? isSpecial)
{
Expression> expBuildingsInfo = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
if (campusID.HasValue)
{
//校区
expBuildingsInfo = expBuildingsInfo.And(x => x.CampusID == campusID);
}
if (collegeID.HasValue)
{
//所属院系所
expBuildingsInfo = expBuildingsInfo.And(x => x.CollegeID == collegeID);
}
if (buildingsTypeID.HasValue)
{
//建筑类型
expBuildingsInfo = expBuildingsInfo.And(x => x.BuildingsTypeID == buildingsTypeID);
}
if (isSpecial.HasValue)
{
//是否启用
if (isSpecial.Value == (int)CF_GeneralPurpose.IsYes)
{
expBuildingsInfo = expBuildingsInfo.And(x => x.IsSpecial == true);
}
if (isSpecial.Value == (int)CF_GeneralPurpose.IsNo)
{
expBuildingsInfo = expBuildingsInfo.And(x => x.IsSpecial != true);
}
}
var query = BuildingsInfoDAL.GetBuildingsInfoViewQueryable(expBuildingsInfo);
//查询条件
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.Code.Length)
.ThenBy(x => x.Code).ThenBy(x => x.BuildingsTypeID).ThenBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode).ToList();
}
///
/// 查询对应的建筑信息CF_BuildingsInfo
///
///
///
public CF_BuildingsInfo GetBuildingsInfo(Guid? buildingsInfoID)
{
try
{
var query = BuildingsInfoDAL.BuildingsInfoRepository.GetList(x => x.BuildingsInfoID == buildingsInfoID).SingleOrDefault();
return query;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///
/// 查询对应的建筑信息BuildingsInfoView
///
///
///
public BuildingsInfoView GetBuildingsInfoView(Guid? buildingsInfoID)
{
try
{
var query = BuildingsInfoDAL.GetBuildingsInfoViewQueryable(x => x.BuildingsInfoID == buildingsInfoID).SingleOrDefault();
return query;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///
/// 编辑(新增、修改,业务主键:建筑编号唯一)
///
///
public void BuildingsInfoEdit(BuildingsInfoView buildingsInfoView)
{
try
{
//查询数据库进行验证
var buildingsInfoVerify = BuildingsInfoDAL.BuildingsInfoRepository.GetList(x => x.BuildingsInfoID != buildingsInfoView.BuildingsInfoID && x.Code == buildingsInfoView.Code).FirstOrDefault();
if (buildingsInfoVerify == null)
{
//数据有误验证
if (buildingsInfoView.BuildingsInfoID != Guid.Empty)
{
var buildingsInfo = BuildingsInfoDAL.BuildingsInfoRepository.GetList(x => x.BuildingsInfoID == buildingsInfoView.BuildingsInfoID).SingleOrDefault();
if (buildingsInfo == null)
{
throw new Exception("数据有误,请核查");
}
else
{
//表示修改
buildingsInfo.Code = buildingsInfoView.Code.Trim();
buildingsInfo.Name = buildingsInfoView.Name;
buildingsInfo.CampusID = buildingsInfoView.CampusID;
buildingsInfo.CollegeID = buildingsInfoView.CollegeID;
buildingsInfo.BuildingsTypeID = buildingsInfoView.BuildingsTypeID;
buildingsInfo.BuildingsStatusID = buildingsInfoView.BuildingsStatusID;
buildingsInfo.BuildingsLevel = buildingsInfoView.BuildingsLevel;
buildingsInfo.BuildingsArea = buildingsInfoView.BuildingsArea;
buildingsInfo.UseArea = buildingsInfoView.UseArea;
buildingsInfo.Position = buildingsInfoView.Position;
buildingsInfo.IsSpecial = buildingsInfoView.IsSpecial;
buildingsInfo.Remark = buildingsInfoView.Remark;
SetModifyStatus(buildingsInfo);
}
}
else
{
//表示新增
CF_BuildingsInfo buildingsInfo = new CF_BuildingsInfo();
buildingsInfo.BuildingsInfoID = Guid.NewGuid();
buildingsInfo.Code = buildingsInfoView.Code.Trim();
buildingsInfo.Name = buildingsInfoView.Name;
buildingsInfo.CampusID = buildingsInfoView.CampusID;
buildingsInfo.CollegeID = buildingsInfoView.CollegeID;
buildingsInfo.BuildingsTypeID = buildingsInfoView.BuildingsTypeID;
buildingsInfo.BuildingsStatusID = buildingsInfoView.BuildingsStatusID;
buildingsInfo.BuildingsLevel = buildingsInfoView.BuildingsLevel;
buildingsInfo.BuildingsArea = buildingsInfoView.BuildingsArea;
buildingsInfo.UseArea = buildingsInfoView.UseArea;
buildingsInfo.Position = buildingsInfoView.Position;
buildingsInfo.IsSpecial = buildingsInfoView.IsSpecial;
buildingsInfo.Remark = buildingsInfoView.Remark;
SetNewStatus(buildingsInfo);
UnitOfWork.Add(buildingsInfo);
}
}
else
{
throw new Exception("已存在相同的建筑编号,请核查");
}
//事务提交
UnitOfWork.Commit();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///
/// 删除
///
///
///
public bool BuildingsInfoDelete(List buildingsInfoIDList)
{
try
{
UnitOfWork.Delete(x => buildingsInfoIDList.Contains(x.BuildingsInfoID));
UnitOfWork.Commit();
return true;
}
catch (Exception)
{
throw;
}
}
///
/// 查询建筑信息中对应的教室信息View(关联排课中教室预留信息、统计排课分配的院系个数)
///
///
///
///
///
///
///
///
///
///
///
///
public IGridResultSet GetClassroomViewGrid(ConfiguretView configuretView, Guid? buildingsInfoID, string classroomName, int? classroomTypeID, Guid? collegeID, int? isConcurrentUse, int? isReserve, int? isAvailable, int pageIndex, int pageSize)
{
Expression> expBuildingsInfo = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
expBuildingsInfo = expBuildingsInfo.And(x => x.BuildingsInfoID == buildingsInfoID);
var query = BuildingsInfoDAL.GetClassroomViewQueryable(expBuildingsInfo);
if (!string.IsNullOrEmpty(classroomName) && classroomName != "-1")
{
//教室名称
query = query.Where(x => x.Name == classroomName);
}
if (classroomTypeID.HasValue)
{
//教室类型(模糊查询)
query = query.Where(x => x.CF_ClassroomType.Select(w => w.ClassroomType).Contains(classroomTypeID));
}
if (collegeID.HasValue)
{
//所属院系所
query = query.Where(x => x.CollegeID == collegeID);
}
if (isConcurrentUse.HasValue)
{
//可否多班教学
if (isConcurrentUse.Value == (int)CF_GeneralPurpose.IsYes)
{
query = query.Where(x => x.IsConcurrentUse == true);
}
if (isConcurrentUse.Value == (int)CF_GeneralPurpose.IsNo)
{
query = query.Where(x => x.IsConcurrentUse != true);
}
}
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 (isAvailable.HasValue)
{
//是否可用
if (isAvailable.Value == (int)CF_GeneralPurpose.IsYes)
{
query = query.Where(x => x.IsAvailable == true);
}
if (isAvailable.Value == (int)CF_GeneralPurpose.IsNo)
{
query = query.Where(x => x.IsAvailable != true);
}
}
//查询条件
if (!string.IsNullOrEmpty(configuretView.ConditionValue))
{
query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
}
return query.OrderBy(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? buildingsInfoID, string classroomName,
int? classroomTypeID, Guid? collegeID, int? isConcurrentUse, int? isReserve, int? isAvailable)
{
Expression> expBuildingsInfo = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
expBuildingsInfo = expBuildingsInfo.And(x => x.BuildingsInfoID == buildingsInfoID);
var query = BuildingsInfoDAL.GetClassroomViewQueryable(expBuildingsInfo);
if (!string.IsNullOrEmpty(classroomName) && classroomName != "-1")
{
//教室名称
query = query.Where(x => x.Name == classroomName);
}
if (classroomTypeID.HasValue)
{
//教室类型(模糊查询)
query = query.Where(x => x.CF_ClassroomType.Select(w => w.ClassroomType).Contains(classroomTypeID));
}
if (collegeID.HasValue)
{
//所属院系所
query = query.Where(x => x.CollegeID == collegeID);
}
if (isConcurrentUse.HasValue)
{
//可否多班教学
if (isConcurrentUse.Value == (int)CF_GeneralPurpose.IsYes)
{
query = query.Where(x => x.IsConcurrentUse == true);
}
if (isConcurrentUse.Value == (int)CF_GeneralPurpose.IsNo)
{
query = query.Where(x => x.IsConcurrentUse != true);
}
}
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 (isAvailable.HasValue)
{
//是否可用
if (isAvailable.Value == (int)CF_GeneralPurpose.IsYes)
{
query = query.Where(x => x.IsAvailable == true);
}
if (isAvailable.Value == (int)CF_GeneralPurpose.IsNo)
{
query = query.Where(x => x.IsAvailable != true);
}
}
//查询条件
if (!string.IsNullOrEmpty(configuretView.ConditionValue))
{
query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
}
return query.OrderBy(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();
}
///
/// 建筑信息Excel导入
///
///
///
///
///
///
///
public void BuildingsInfoImport(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();
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; //用于返回判断日期字段格式
inCount = 0; //导入个数
upCount = 0; //更新个数
errCount = 0; //失败个数
string errorMsgStr = ""; //错误信息
List newBuildingsInfoInList = new List();
List newBuildingsInfoUpList = new List();
//将循环中相关数据库查询统一查询出来进行匹配(尽量避免在循环中进行数据库查询)
//校区信息
var campusList = BuildingsInfoDAL.CampusRepository.GetList(x => true).ToList();
//校区代码
var campusNoList = enlist.Where(x => !string.IsNullOrEmpty(x.CampusCode)).Select(x => x.CampusCode).ToList();
//对比后的newCampusList
var newCampusList = campusList.Where(x => campusNoList.Contains(x.No)).ToList();
//院系所信息
var collegeList = BuildingsInfoDAL.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 buildingsTypeList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_BuildingsType).ToList();
//建筑状况
var buildingsStatusList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_BuildingsStatus).ToList();
//是否启用
var generalPurposeList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_GeneralPurpose).ToList();
//建筑信息
var buildingsInfoList = BuildingsInfoDAL.BuildingsInfoRepository.GetList(x => true).ToList();
//建筑编号
var buildingsInfoCodeList = enlist.Where(x => !string.IsNullOrEmpty(x.Code)).Select(x => x.Code).ToList();
//对比后的newBuildingsInfoList(暂时只对比建筑编号)
var newBuildingsInfoList = buildingsInfoList.Where(x => buildingsInfoCodeList.Contains(x.Code)).ToList();
//循环检测数据列,对各数据列进行验证(必填、字典项验证、数据格式等)
for (int i = 0; i < enlist.Count; i++)
{
BuildingsInfoView en = enlist[i]; //Excel表数据视图
CF_BuildingsInfo newBuildingsInfo = new CF_BuildingsInfo();
//建筑编号
if (string.IsNullOrWhiteSpace(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
{
//建筑编号
newBuildingsInfo.Code = en.Code.Trim();
}
}
//建筑名称
if (string.IsNullOrWhiteSpace(en.Name))
{
errCount++;
errorMsgStr = "建筑名称不能为空";
en.ErrorMessage = errorMsgStr;
errList.Add(en);
errorMsg.AppendLine(errorMsgStr);
continue;
}
else
{
//建筑名称
newBuildingsInfo.Name = en.Name.Trim();
}
//校区代码
if (string.IsNullOrWhiteSpace(en.CampusCode))
{
errCount++;
errorMsgStr = RSL.Get("CampusCode") + "不能为空";
en.ErrorMessage = errorMsgStr;
errList.Add(en);
errorMsg.AppendLine(errorMsgStr);
continue;
}
else
{
reg = new Regex(@"^[0-9a-zA-Z\s?]+$"); //正则表达式(请输入数字或英文字母)
if (!reg.IsMatch(en.CampusCode.Trim()))
{
errCount++;
errorMsgStr = RSL.Get("CampusCode") + "格式不正确,请检查(数字或英文字母)";
en.ErrorMessage = errorMsgStr;
errList.Add(en);
errorMsg.AppendLine(errorMsgStr);
continue;
}
else
{
var campus = newCampusList.Where(x => x.No == en.CampusCode.Trim()).SingleOrDefault();
if (campus == null)
{
errCount++;
errorMsgStr = RSL.Get("CampusCode") + "不存在,请检查";
en.ErrorMessage = errorMsgStr;
errList.Add(en);
errorMsg.AppendLine(errorMsgStr);
continue;
}
else
{
//校区信息ID
newBuildingsInfo.CampusID = campus.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 == newBuildingsInfo.CampusID)
//{
// //院系所信息ID
// newBuildingsInfo.CollegeID = college.CollegeID;
//}
//else
//{
// errCount++;
// errorMsgStr = RSL.Get("CampusCode") + "与" + RSL.Get("CollegeCode") + "对应关系不存在,请检查";
// en.ErrorMessage = errorMsgStr;
// errList.Add(en);
// errorMsg.AppendLine(errorMsgStr);
// continue;
//}
//院系所信息ID
newBuildingsInfo.CollegeID = college.CollegeID;
}
}
}
//建筑类型
if (string.IsNullOrWhiteSpace(en.BuildingsTypeStr))
{
errCount++;
errorMsgStr = "建筑类型不能为空";
en.ErrorMessage = errorMsgStr;
errList.Add(en);
errorMsg.AppendLine(errorMsgStr);
continue;
}
else
{
var buildingsType = buildingsTypeList.Where(x => x.Name == en.BuildingsTypeStr.Trim()).SingleOrDefault();
if (buildingsType == null)
{
errCount++;
errorMsgStr = "建筑类型不存在,请检查";
en.ErrorMessage = errorMsgStr;
errList.Add(en);
errorMsg.AppendLine(errorMsgStr);
continue;
}
else
{
//建筑类型
newBuildingsInfo.BuildingsTypeID = buildingsType.Value;
}
}
//建筑状况
if (string.IsNullOrWhiteSpace(en.BuildingsStatusStr))
{
errCount++;
errorMsgStr = "建筑状况不能为空";
en.ErrorMessage = errorMsgStr;
errList.Add(en);
errorMsg.AppendLine(errorMsgStr);
continue;
}
else
{
var buildingsStatus = buildingsStatusList.Where(x => x.Name == en.BuildingsStatusStr.Trim()).SingleOrDefault();
if (buildingsStatus == null)
{
errCount++;
errorMsgStr = "建筑状况不存在,请检查";
en.ErrorMessage = errorMsgStr;
errList.Add(en);
errorMsg.AppendLine(errorMsgStr);
continue;
}
else
{
//建筑状况
newBuildingsInfo.BuildingsStatusID = buildingsStatus.Value;
}
}
//建筑层数
if (string.IsNullOrWhiteSpace(en.BuildingsLevelStr))
{
//不考虑
}
else
{
reg = new Regex(@"^[0-9]+([.]{1}[0-9]+){0,1}$"); //正则表达式()
if (!reg.IsMatch(en.BuildingsLevelStr.Trim()))
{
errCount++;
errorMsgStr = "建筑层数格式不正确,请检查";
en.ErrorMessage = errorMsgStr;
errList.Add(en);
errorMsg.AppendLine(errorMsgStr);
continue;
}
else
{
//建筑层数
newBuildingsInfo.BuildingsLevel = Convert.ToDecimal(en.BuildingsLevelStr.Trim());
}
}
//建筑面积
if (string.IsNullOrWhiteSpace(en.BuildingsAreaStr))
{
//不考虑
}
else
{
reg = new Regex(@"^[0-9]+([.]{1}[0-9]+){0,1}$"); //正则表达式()
if (!reg.IsMatch(en.BuildingsAreaStr.Trim()))
{
errCount++;
errorMsgStr = "建筑面积格式不正确,请检查";
en.ErrorMessage = errorMsgStr;
errList.Add(en);
errorMsg.AppendLine(errorMsgStr);
continue;
}
else
{
//建筑面积
newBuildingsInfo.BuildingsArea = Convert.ToDecimal(en.BuildingsAreaStr.Trim());
}
}
//使用面积
if (string.IsNullOrWhiteSpace(en.UseAreaStr))
{
//不考虑
}
else
{
reg = new Regex(@"^[0-9]+([.]{1}[0-9]+){0,1}$"); //正则表达式()
if (!reg.IsMatch(en.UseAreaStr.Trim()))
{
errCount++;
errorMsgStr = "使用面积格式不正确,请检查";
en.ErrorMessage = errorMsgStr;
errList.Add(en);
errorMsg.AppendLine(errorMsgStr);
continue;
}
else
{
//使用面积
newBuildingsInfo.UseArea = Convert.ToDecimal(en.UseAreaStr.Trim());
}
}
//地址
if (string.IsNullOrWhiteSpace(en.Position))
{
//不考虑
}
else
{
newBuildingsInfo.Position = en.Position;
}
//是否可用
if (string.IsNullOrWhiteSpace(en.IsSpecialStr))
{
errCount++;
errorMsgStr = "是否可用不能为空";
en.ErrorMessage = errorMsgStr;
errList.Add(en);
errorMsg.AppendLine(errorMsgStr);
continue;
}
else
{
var generalPurpose = generalPurposeList.Where(x => x.Name == en.IsSpecialStr.Trim()).SingleOrDefault();
if (generalPurpose == null)
{
errCount++;
errorMsgStr = "是否可用不存在,请检查";
en.ErrorMessage = errorMsgStr;
errList.Add(en);
errorMsg.AppendLine(errorMsgStr);
continue;
}
else
{
//是否可用
newBuildingsInfo.IsSpecial = generalPurpose.Value == (int)CF_GeneralPurpose.IsYes ? true : false;
}
}
//备注
if (string.IsNullOrWhiteSpace(en.Remark))
{
//不考虑
}
else
{
newBuildingsInfo.Remark = en.Remark;
}
////Excel表重复性验证(注:当数据表中没有此记录,但是Excel中有重复数据时的去掉)
//for (int j = i + 1; j < enlist.Count; j++)
//{
// NewBuildingsInfoView enA = enlist[j];
// //根据Excel表中的业务主键进行去重(建筑编号唯一)
// if (en.No == enA.No && en.Name == enA.Name)
// {
// //用于标识Excel表中的重复记录(由于是批量进行插入数据表)
// }
//}
//数据表重复性验证(建筑编号唯一)
var buildingsInfoVerify = newBuildingsInfoList.Where(x => x.Code == newBuildingsInfo.Code).SingleOrDefault();
if (buildingsInfoVerify == null)
{
//新增
if (!newBuildingsInfoInList.Any(x => x.Code == newBuildingsInfo.Code))
{
newBuildingsInfo.BuildingsInfoID = Guid.NewGuid();
SetNewStatus(newBuildingsInfo);
newBuildingsInfoInList.Add(newBuildingsInfo);
inCount++;
}
else
{
//Excel表重复性验证
//(注:当数据表中没有此记录,但是Excel中有重复数据,可在此处进行抛出到失败数据文件中,目前暂不考虑)
inCount++;
}
}
else
{
//更新(Excel有重复时,以最后一条记录的更新为准)
buildingsInfoVerify.Name = newBuildingsInfo.Name;
buildingsInfoVerify.CampusID = newBuildingsInfo.CampusID;
buildingsInfoVerify.CollegeID = newBuildingsInfo.CollegeID;
buildingsInfoVerify.BuildingsTypeID = newBuildingsInfo.BuildingsTypeID;
buildingsInfoVerify.BuildingsStatusID = newBuildingsInfo.BuildingsStatusID;
buildingsInfoVerify.BuildingsLevel = newBuildingsInfo.BuildingsLevel;
buildingsInfoVerify.BuildingsArea = newBuildingsInfo.BuildingsArea;
buildingsInfoVerify.UseArea = newBuildingsInfo.UseArea;
buildingsInfoVerify.Position = newBuildingsInfo.Position;
buildingsInfoVerify.IsSpecial = newBuildingsInfo.IsSpecial;
buildingsInfoVerify.Remark = newBuildingsInfo.Remark;
SetModifyStatus(buildingsInfoVerify);
newBuildingsInfoUpList.Add(buildingsInfoVerify);
upCount++;
}
}
using (TransactionScope ts = new TransactionScope())
{
UnitOfWork.BulkInsert(newBuildingsInfoInList);
//批量统一提交更新
if (newBuildingsInfoUpList != null && newBuildingsInfoUpList.Count() > 0)
{
UnitOfWork.BatchUpdate(newBuildingsInfoUpList);
}
ts.Complete();
}
errdataList = errList.Distinct().ToList(); //错误列表List
}
catch (Exception)
{
//目前会出现,由于错误信息字符太长,无法抛出弹出框的问题
throw;
}
}
}
}