using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Text.RegularExpressions;
using System.Data;
using System.IO;
using System.Transactions;
using Bowin.Common.Utility;
using Bowin.Common.Linq;
using Bowin.Common.Linq.Entity;
using EMIS.Entities;
using EMIS.Utility;
using EMIS.ViewModel;
using EMIS.ViewModel.CacheManage;
using EMIS.ViewModel.EnrollManage.NewStudentManage;
using EMIS.DataLogic.EnrollManage.NewStudentManage;
namespace EMIS.CommonLogic.EnrollManage.NewStudentManage
{
public class NewStudentServices : BaseServices, INewStudentServices
{
public NewStudentDAL NewStudentDAL { get; set; }
///
/// 查询对应的新生名单信息View
///
///
///
///
///
///
///
///
///
///
///
public IGridResultSet GetNewStudentViewGrid(ConfiguretView configuretView, int? gradeID, int? standardID, int? educationID, int? learningformID, string learnSystem, int? isPhoto, int pageIndex, int pageSize)
{
Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
exp = exp.And(x => x.AssignStatus == (int)CF_AssignStatus.NotAssigned);
if (gradeID.HasValue)
{
exp = exp.And(x => x.GradeID == gradeID);
}
if (isPhoto.HasValue)
{
if (isPhoto.Value == (int)CF_GeneralExist.Have)
{
exp = exp.And(x => x.RecruitPictureUrl != null && x.RecruitPictureUrl != "");
}
if (isPhoto.Value == (int)CF_GeneralExist.No)
{
exp = exp.And(x => x.RecruitPictureUrl == null || x.RecruitPictureUrl == "");
}
}
var query = NewStudentDAL.GetNewStudentViewQueryable(exp);
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 query.OrderByDescending(x => x.GradeID).ThenBy(x => x.StandardName).ThenBy(x => x.EducationID).ThenBy(x => x.LearningformID)
.ThenBy(x => x.LearnSystem).ToGridResultSet(pageIndex, pageSize);
}
///
/// 查询对应的新生名单信息List
///
///
///
///
///
///
///
///
///
public IList GetNewStudentViewList(ConfiguretView configuretView, int? gradeID, int? standardID, int? educationID, int? learningformID, string learnSystem, int? isPhoto)
{
Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
exp = exp.And(x => x.AssignStatus == (int)CF_AssignStatus.NotAssigned);
if (gradeID.HasValue)
{
exp = exp.And(x => x.GradeID == gradeID);
}
if (isPhoto.HasValue)
{
if (isPhoto.Value == (int)CF_GeneralExist.Have)
{
exp = exp.And(x => x.RecruitPictureUrl != null && x.RecruitPictureUrl != "");
}
if (isPhoto.Value == (int)CF_GeneralExist.No)
{
exp = exp.And(x => x.RecruitPictureUrl == null || x.RecruitPictureUrl == "");
}
}
var query = NewStudentDAL.GetNewStudentViewQueryable(exp);
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 query.OrderByDescending(x => x.GradeID).ThenBy(x => x.StandardName).ThenBy(x => x.EducationID).ThenBy(x => x.LearningformID)
.ThenBy(x => x.LearnSystem).ToList();
}
///
/// 查询对应的新生名单信息NewStudentView
///
///
///
public NewStudentView GetNewStudentView(Guid? newStudentID)
{
try
{
Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
exp = exp.And(x => x.AssignStatus == (int)CF_AssignStatus.NotAssigned);
exp = exp.And(x => x.NewStudentID == newStudentID);
var query = NewStudentDAL.GetNewStudentViewQueryable(exp).SingleOrDefault();
return query;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///
/// 编辑(新增、修改,业务主键:考生号唯一)
///
///
///
public void NewStudentEdit(NewStudentView newStudentView, string photoUrl)
{
try
{
var examineeNumVerify = NewStudentDAL.NewStudentRepository.GetList(x => x.NewStudentID != newStudentView.NewStudentID
&& x.ExamineeNum == newStudentView.ExamineeNum.Trim()).SingleOrDefault();
if (examineeNumVerify == null)
{
//if (!string.IsNullOrEmpty(newStudentView.AdmissionTicketNo))
//{
// var admissionTicketNoVerify = NewStudentDAL.NewStudentRepository.GetList(x => x.NewStudentID != newStudentView.NewStudentID
// && x.AdmissionTicketNo == newStudentView.AdmissionTicketNo.Trim()).SingleOrDefault();
// if (admissionTicketNoVerify != null)
// {
// if (admissionTicketNoVerify.AssignStatus == (int)CF_AssignStatus.PreAssigned)
// {
// throw new Exception("新生分配信息中已存在此准考证号(准考证号重复),请核查。");
// }
// else if (admissionTicketNoVerify.AssignStatus == (int)CF_AssignStatus.Assigned)
// {
// throw new Exception("录取名单信息中已存在此准考证号(准考证号重复),请核查。");
// }
// else
// {
// throw new Exception("已存在相同的准考证号(准考证号重复),请核查。");
// }
// }
//}
if (newStudentView.NewStudentID != Guid.Empty)
{
var newStudent = NewStudentDAL.NewStudentRepository.GetList(x => x.NewStudentID == newStudentView.NewStudentID
&& x.AssignStatus == (int)CF_AssignStatus.NotAssigned).SingleOrDefault();
if (newStudent == null)
{
throw new Exception("数据有误,请核查。");
}
else
{
//表示修改
newStudent.ExamineeNum = newStudentView.ExamineeNum.Trim();
if (!string.IsNullOrEmpty(newStudentView.AdmissionTicketNo))
{
newStudent.AdmissionTicketNo = newStudentView.AdmissionTicketNo.Trim();
}
else
{
newStudent.AdmissionTicketNo = newStudentView.AdmissionTicketNo;
}
newStudent.Name = newStudentView.Name;
newStudent.SexID = newStudentView.SexID;
newStudent.NationID = newStudentView.NationID;
newStudent.PoliticsID = newStudentView.PoliticsID;
newStudent.BirthDate = newStudentView.BirthDate;
newStudent.CertificatesType = newStudentView.CertificatesType;
newStudent.IDNumber = newStudentView.IDNumber;
newStudent.GradeID = newStudentView.GradeID;
newStudent.SemesterID = newStudentView.SemesterID;
newStudent.SpecialtyID = newStudentView.SpecialtyID;
newStudent.EntranceDate = newStudentView.EntranceDate;
newStudent.Score = newStudentView.Score;
newStudent.Telephone = newStudentView.Telephone;
newStudent.ZIPCode = newStudentView.ZIPCode;
newStudent.EntranceWayID = newStudentView.EntranceWayID;
newStudent.FeaturesID = newStudentView.FeaturesID;
newStudent.TerritorialID = newStudentView.TerritorialID;
newStudent.Address = newStudentView.Address;
newStudent.Dormitory = newStudentView.Dormitory;
if (!string.IsNullOrEmpty(photoUrl))
{
newStudent.RecruitPictureUrl = photoUrl;
}
newStudent.Remark = newStudentView.Remark;
SetModifyStatus(newStudent);
}
}
else
{
//表示新增
var newStudent = new CF_NewStudent();
newStudent.NewStudentID = Guid.NewGuid();
newStudent.ExamineeNum = newStudentView.ExamineeNum.Trim();
if (!string.IsNullOrEmpty(newStudentView.AdmissionTicketNo))
{
newStudent.AdmissionTicketNo = newStudentView.AdmissionTicketNo.Trim();
}
else
{
newStudent.AdmissionTicketNo = newStudentView.AdmissionTicketNo;
}
newStudent.Name = newStudentView.Name;
newStudent.SexID = newStudentView.SexID;
newStudent.NationID = newStudentView.NationID;
newStudent.PoliticsID = newStudentView.PoliticsID;
newStudent.BirthDate = newStudentView.BirthDate;
newStudent.CertificatesType = newStudentView.CertificatesType;
newStudent.IDNumber = newStudentView.IDNumber;
newStudent.GradeID = newStudentView.GradeID;
newStudent.SemesterID = newStudentView.SemesterID;
newStudent.SpecialtyID = newStudentView.SpecialtyID;
newStudent.EntranceDate = newStudentView.EntranceDate;
newStudent.Score = newStudentView.Score;
newStudent.Telephone = newStudentView.Telephone;
newStudent.ZIPCode = newStudentView.ZIPCode;
newStudent.EntranceWayID = newStudentView.EntranceWayID;
newStudent.FeaturesID = newStudentView.FeaturesID;
newStudent.TerritorialID = newStudentView.TerritorialID;
newStudent.Address = newStudentView.Address;
newStudent.Dormitory = newStudentView.Dormitory;
if (!string.IsNullOrEmpty(photoUrl))
{
newStudent.RecruitPictureUrl = photoUrl;
}
newStudent.IsDoubt = false;
newStudent.AssignStatus = (int)CF_AssignStatus.NotAssigned;
newStudent.Remark = newStudentView.Remark;
SetNewStatus(newStudent, (int)CF_NewStudentEnterStatus.NotSubmitted);
UnitOfWork.Add(newStudent);
}
}
else
{
if (examineeNumVerify.AssignStatus == (int)CF_AssignStatus.PreAssigned)
{
throw new Exception("新生分配信息中已存在此考生号(考生号重复),请核查。");
}
else if (examineeNumVerify.AssignStatus == (int)CF_AssignStatus.Assigned)
{
throw new Exception("录取名单信息中已存在此考生号(考生号重复),请核查。");
}
else
{
throw new Exception("已存在相同的考生号(考生号重复),请核查。");
}
}
UnitOfWork.Commit();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///
/// 删除
///
///
///
public bool NewStudentDelete(List newStudentIDList)
{
try
{
UnitOfWork.Delete(x => newStudentIDList.Contains(x.NewStudentID) && x.AssignStatus == (int)CF_AssignStatus.NotAssigned);
return true;
}
catch (Exception)
{
throw;
}
}
///
/// 删除照片(单个删除)
///
///
public void DeletePhoto(Guid? newStudentID)
{
try
{
var newStudent = NewStudentDAL.NewStudentRepository.GetList(x => x.NewStudentID == newStudentID && x.AssignStatus == (int)CF_AssignStatus.NotAssigned).SingleOrDefault();
if (newStudent != null)
{
if (!string.IsNullOrEmpty(newStudent.RecruitPictureUrl))
{
FileUploadHelper.DeleteFile(newStudent.RecruitPictureUrl);
newStudent.RecruitPictureUrl = null;
this.UnitOfWork.Commit();
}
else
{
throw new Exception("对应的照片不存在。");
}
}
else
{
throw new Exception("对应的信息未保存,数据有误。");
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///
/// 删除照片(批量删除)
///
///
///
public bool PicDelete(List newStudentIDs)
{
try
{
List photoUrlList = new List();
List newStudentUpList = new List();
var newStudentList = NewStudentDAL.NewStudentRepository.GetList(x => newStudentIDs.Contains(x.NewStudentID) && x.AssignStatus == (int)CF_AssignStatus.NotAssigned).ToList();
foreach (var newStudent in newStudentList)
{
if (newStudent != null)
{
if (!string.IsNullOrEmpty(newStudent.RecruitPictureUrl))
{
photoUrlList.Add(newStudent.RecruitPictureUrl);
newStudent.RecruitPictureUrl = null;
newStudentUpList.Add(newStudent);
}
}
}
using (TransactionScope ts = new TransactionScope())
{
foreach (var photoUrl in photoUrlList)
{
FileUploadHelper.DeleteFile(photoUrl);
}
if (newStudentUpList != null && newStudentUpList.Count() > 0)
{
UnitOfWork.BatchUpdate(newStudentUpList);
}
//this.UnitOfWork.Commit();
ts.Complete();
}
return true;
}
catch (Exception)
{
throw;
}
}
///
/// 导入照片
///
///
///
///
///
///
public void NewStudentPicImport(IList photoPaths, string importPicType, out int? inCount, out int? errCount, out DataTable errDataTable)
{
try
{
var mapList = photoPaths.Select(s => new
{
PhotoInfo = Path.GetFileName(s).Trim(),
PhotoName = Path.GetFileNameWithoutExtension(s).Trim(),
PhotoPath = s,
}).ToArray();
var photoNameList = mapList.Select(s => s.PhotoName).Distinct().ToList();
inCount = 0;
errCount = 0;
errDataTable = new DataTable();
List newStudentUpList = new List();
if (importPicType.Equals("ExamineeNum"))
{
var newPhotoNameList = new List();
foreach (var photoName in photoNameList)
{
var photoNameStart = photoName.Substring(0, 1);
if (photoNameStart.Equals("F") || photoNameStart.Equals("Z"))
{
newPhotoNameList.Add(photoName.Substring(1));
}
}
errDataTable.Columns.Add("PhotoInfo", typeof(string));
errDataTable.Columns.Add("ExamineeNum", typeof(string));
errDataTable.Columns.Add("ErrorMessage", typeof(string));
var newStudentList = NewStudentDAL.NewStudentRepository.GetList(x => x.AssignStatus == (int)CF_AssignStatus.NotAssigned && (photoNameList.Contains(x.ExamineeNum) || newPhotoNameList.Contains(x.ExamineeNum))).ToList();
foreach (var map in mapList)
{
var photoNameStart = map.PhotoName.Substring(0, 1);
if (photoNameStart.Equals("F") || photoNameStart.Equals("Z"))
{
var newStudent = newStudentList.Where(x => x.ExamineeNum == map.PhotoName || x.ExamineeNum == map.PhotoName.Substring(1)).SingleOrDefault();
if (newStudent == null)
{
DataRow errDataRow = errDataTable.NewRow();
errDataRow["PhotoInfo"] = map.PhotoInfo;
errDataRow["ExamineeNum"] = map.PhotoName;
errDataRow["ErrorMessage"] = "不存在对应的考生号(" + map.PhotoName + ")";
errDataTable.Rows.Add(errDataRow);
errCount++;
}
else
{
newStudent.RecruitPictureUrl = map.PhotoPath;
this.SetModifyStatus(newStudent);
newStudentUpList.Add(newStudent);
inCount++;
}
}
else
{
var newStudent = newStudentList.Where(x => x.ExamineeNum == map.PhotoName).SingleOrDefault();
if (newStudent == null)
{
DataRow errDataRow = errDataTable.NewRow();
errDataRow["PhotoInfo"] = map.PhotoInfo;
errDataRow["ExamineeNum"] = map.PhotoName;
errDataRow["ErrorMessage"] = "不存在对应的考生号(" + map.PhotoName + ")";
errDataTable.Rows.Add(errDataRow);
errCount++;
}
else
{
newStudent.RecruitPictureUrl = map.PhotoPath;
this.SetModifyStatus(newStudent);
newStudentUpList.Add(newStudent);
inCount++;
}
}
}
}
else if (importPicType.Equals("IDNumber"))
{
errDataTable.Columns.Add("PhotoInfo", typeof(string));
errDataTable.Columns.Add("IDNumber", typeof(string));
errDataTable.Columns.Add("ErrorMessage", typeof(string));
var newStudentList = NewStudentDAL.NewStudentRepository.GetList(x => x.AssignStatus == (int)CF_AssignStatus.NotAssigned && photoNameList.Contains(x.IDNumber)).ToList();
foreach (var map in mapList)
{
var newStudentVerifyList = newStudentList.Where(x => x.IDNumber == map.PhotoName).ToList();
if (newStudentVerifyList != null && newStudentVerifyList.Count() > 1)
{
DataRow errDataRow = errDataTable.NewRow();
errDataRow["PhotoInfo"] = map.PhotoInfo;
errDataRow["IDNumber"] = map.PhotoName;
errDataRow["ErrorMessage"] = "存在多个对应的证件号码(" + map.PhotoName + ")";
errDataTable.Rows.Add(errDataRow);
errCount++;
}
else
{
if (newStudentVerifyList != null && newStudentVerifyList.Count() == 1)
{
var newStudent = newStudentVerifyList.Where(x => x.IDNumber == map.PhotoName).SingleOrDefault();
if (newStudent == null)
{
DataRow errDataRow = errDataTable.NewRow();
errDataRow["PhotoInfo"] = map.PhotoInfo;
errDataRow["IDNumber"] = map.PhotoName;
errDataRow["ErrorMessage"] = "不存在对应的证件号码(" + map.PhotoName + ")";
errDataTable.Rows.Add(errDataRow);
errCount++;
}
else
{
newStudent.RecruitPictureUrl = map.PhotoPath;
this.SetModifyStatus(newStudent);
newStudentUpList.Add(newStudent);
inCount++;
}
}
else
{
DataRow errDataRow = errDataTable.NewRow();
errDataRow["PhotoInfo"] = map.PhotoInfo;
errDataRow["IDNumber"] = map.PhotoName;
errDataRow["ErrorMessage"] = "不存在对应的证件号码(" + map.PhotoName + ")";
errDataTable.Rows.Add(errDataRow);
errCount++;
}
}
}
}
if (newStudentUpList != null && newStudentUpList.Count() > 0)
{
UnitOfWork.BatchUpdate(newStudentUpList);
}
}
catch (Exception)
{
throw;
}
}
///
/// Excel导入
///
///
///
///
///
///
///
public void NewStudentImport(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");//移除“未导入原因”列(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 newStudentInList = new List();
List newStudentUpList = new List();
//将循环中相关数据库查询统一查询出来进行匹配(尽量避免在循环中进行数据库查询)
//性别
var sexList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Sex).ToList();
//民族
var nationList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Nation).ToList();
//政治面貌
var politicsList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Politics).ToList();
//年级
var gradeList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Grade).ToList();
//学期
var semesterList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Semester).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 certificatesTypeList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_CertificatesType).ToList();
//专业信息
var specialtyList = NewStudentDAL.SpecialtyRepository.GetList(x => true).ToList();
//考生号
var examineeNumList = enlist.Where(x => !string.IsNullOrEmpty(x.ExamineeNum)).Select(x => x.ExamineeNum.Trim()).ToList();
//新生名单
var newStudentAllList = NewStudentDAL.NewStudentRepository.GetList(x => true).ToList();
//对比后的newStudentList
var newStudentList = newStudentAllList.Where(x => examineeNumList.Contains(x.ExamineeNum)).ToList();
//循环检测数据列,对各数据列进行验证(必填、字典项验证、数据格式等)
for (int i = 0; i < enlist.Count; i++)
{
NewStudentView en = enlist[i]; //Excel表数据视图
CF_NewStudent newStudent = new CF_NewStudent();
//考生号
if (string.IsNullOrEmpty(en.ExamineeNum))
{
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.ExamineeNum))
{
errCount++;
errorMsgStr = "考生号格式不正确,请检查";
en.ErrorMessage = errorMsgStr;
errList.Add(en);
errorMsg.AppendLine(errorMsgStr);
continue;
}
else
{
//考生号
newStudent.ExamineeNum = en.ExamineeNum.Trim();
}
}
//准考证号
if (!string.IsNullOrEmpty(en.AdmissionTicketNo))
{
reg = new Regex(@"^[0-9a-zA-Z\s?]+$"); //准考证号正则表达式
if (!reg.IsMatch(en.AdmissionTicketNo))
{
errCount++;
errorMsgStr = "准考证号格式不正确,请检查";
en.ErrorMessage = errorMsgStr;
errList.Add(en);
errorMsg.AppendLine(errorMsgStr);
continue;
}
else
{
//准考证号
newStudent.AdmissionTicketNo = en.AdmissionTicketNo.Trim();
}
}
else
{
//为空
}
//姓名
if (string.IsNullOrEmpty(en.Name))
{
errCount++;
errorMsgStr = "姓名不能为空";
en.ErrorMessage = errorMsgStr;
errList.Add(en);
errorMsg.AppendLine(errorMsgStr);
continue;
}
else
{
//姓名
newStudent.Name = en.Name.Trim();
}
//性别
if (string.IsNullOrEmpty(en.SexStr))
{
errCount++;
errorMsgStr = "性别不能为空";
en.ErrorMessage = errorMsgStr;
errList.Add(en);
errorMsg.AppendLine(errorMsgStr);
continue;
}
else
{
var sex = sexList.Where(x => x.Name == en.SexStr.Trim()).SingleOrDefault();
if (sex == null)
{
errCount++;
errorMsgStr = "性别不存在,请检查";
en.ErrorMessage = errorMsgStr;
errList.Add(en);
errorMsg.AppendLine(errorMsgStr);
continue;
}
else
{
//性别
newStudent.SexID = sex.Value;
}
}
//民族
if (string.IsNullOrEmpty(en.NationStr))
{
errCount++;
errorMsgStr = "民族不能为空";
en.ErrorMessage = errorMsgStr;
errList.Add(en);
errorMsg.AppendLine(errorMsgStr);
continue;
}
else
{
var nation = nationList.Where(x => x.Name == en.NationStr.Trim()).SingleOrDefault();
if (nation == null)
{
errCount++;
errorMsgStr = "民族不存在,请检查";
en.ErrorMessage = errorMsgStr;
errList.Add(en);
errorMsg.AppendLine(errorMsgStr);
continue;
}
else
{
//民族
newStudent.NationID = nation.Value;
}
}
//政治面貌
if (string.IsNullOrEmpty(en.PoliticsStr))
{
errCount++;
errorMsgStr = "政治面貌不能为空";
en.ErrorMessage = errorMsgStr;
errList.Add(en);
errorMsg.AppendLine(errorMsgStr);
continue;
}
else
{
var politics = politicsList.Where(x => x.Name == en.PoliticsStr.Trim()).SingleOrDefault();
if (politics == null)
{
errCount++;
errorMsgStr = "政治面貌不存在,请检查";
en.ErrorMessage = errorMsgStr;
errList.Add(en);
errorMsg.AppendLine(errorMsgStr);
continue;
}
else
{
//政治面貌
newStudent.PoliticsID = politics.Value;
}
}
//出生日期
if (!string.IsNullOrEmpty(en.BirthDateStr))
{
//reg = new Regex(@"(\d{4})-(\d{1,2})-(\d{1,2})"); //日期正则表达式,2017-12-28
if (!DateTime.TryParse(en.BirthDateStr, out result))
{
errCount++;
errorMsgStr = "出生日期格式不正确,请检查";
en.ErrorMessage = errorMsgStr;
errList.Add(en);
errorMsg.AppendLine(errorMsgStr);
continue;
}
else
{
//出生日期
newStudent.BirthDate = Convert.ToDateTime(en.BirthDateStr);
}
}
else
{
//为空
}
//证件类型
if (string.IsNullOrEmpty(en.CertificatesTypeStr))
{
errCount++;
errorMsgStr = "证件类型不能为空";
en.ErrorMessage = errorMsgStr;
errList.Add(en);
errorMsg.AppendLine(errorMsgStr);
continue;
}
else
{
var certificatesType = certificatesTypeList.Where(x => x.Name == en.CertificatesTypeStr.Trim()).SingleOrDefault();
if (certificatesType == null)
{
errCount++;
errorMsgStr = "证件类型不存在,请检查";
en.ErrorMessage = errorMsgStr;
errList.Add(en);
errorMsg.AppendLine(errorMsgStr);
continue;
}
else
{
//证件类型
newStudent.CertificatesType = certificatesType.Value;
}
}
//身份证号
if (string.IsNullOrEmpty(en.IDNumber))
{
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.IDNumber))
//{
// errCount++;
// errorMsgStr = "身份证号格式不正确,请检查";
// en.ErrorMessage = errorMsgStr;
// errList.Add(en);
// errorMsg.AppendLine(errorMsgStr);
// continue;
//}
//else
//{
// //身份证号
// newStudent.IDNumber = en.IDNumber.Trim();
//}
newStudent.IDNumber = en.IDNumber.Trim();
}
//年级
if (string.IsNullOrEmpty(en.GradeStr))
{
errCount++;
errorMsgStr = "年级不能为空";
en.ErrorMessage = errorMsgStr;
errList.Add(en);
errorMsg.AppendLine(errorMsgStr);
continue;
}
else
{
var grade = gradeList.Where(x => x.Name == en.GradeStr.Trim()).SingleOrDefault();
if (grade == null)
{
errCount++;
errorMsgStr = "年级不存在,请检查";
en.ErrorMessage = errorMsgStr;
errList.Add(en);
errorMsg.AppendLine(errorMsgStr);
continue;
}
else
{
newStudent.GradeID = grade.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
{
//学期
newStudent.SemesterID = semester.Value;
}
}
//专业代码
if (string.IsNullOrEmpty(en.StandardCode))
{
errCount++;
errorMsgStr = "专业代码不能为空";
en.ErrorMessage = errorMsgStr;
errList.Add(en);
errorMsg.AppendLine(errorMsgStr);
continue;
}
else
{
var standardCode = standardList.Where(x => x.Code == en.StandardCode.Trim()).FirstOrDefault();
if (standardCode == null)
{
errCount++;
errorMsgStr = "专业代码不存在,请检查";
en.ErrorMessage = errorMsgStr;
errList.Add(en);
errorMsg.AppendLine(errorMsgStr);
continue;
}
else
{
//专业代码
}
}
//专业名称
if (string.IsNullOrEmpty(en.StandardName))
{
errCount++;
errorMsgStr = "专业名称不能为空";
en.ErrorMessage = errorMsgStr;
errList.Add(en);
errorMsg.AppendLine(errorMsgStr);
continue;
}
else
{
var standardName = standardList.Where(x => x.Name == en.StandardName.Trim()).FirstOrDefault();
if (standardName == null)
{
errCount++;
errorMsgStr = "专业名称不存在,请检查";
en.ErrorMessage = errorMsgStr;
errList.Add(en);
errorMsg.AppendLine(errorMsgStr);
continue;
}
else
{
//专业名称
}
}
//专业代码与专业名称查询专业ID(Value)
if (string.IsNullOrEmpty(en.StandardCode) || string.IsNullOrEmpty(en.StandardName))
{
errCount++;
errorMsgStr = "专业代码或专业名称不能为空";
en.ErrorMessage = errorMsgStr;
errList.Add(en);
errorMsg.AppendLine(errorMsgStr);
continue;
}
else
{
var standardID = standardList.Where(x => x.Code == en.StandardCode.Trim() && x.Name == en.StandardName.Trim()).SingleOrDefault();
if (standardID == null)
{
errCount++;
errorMsgStr = "专业代码与专业名称对应的元素值不存在,请检查";
en.ErrorMessage = errorMsgStr;
errList.Add(en);
errorMsg.AppendLine(errorMsgStr);
continue;
}
else
{
//专业ID(Value)
en.StandardID = standardID.Value.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.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.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))
{
errCount++;
errorMsgStr = "学制格式不正确,请检查";
en.ErrorMessage = errorMsgStr;
errList.Add(en);
errorMsg.AppendLine(errorMsgStr);
continue;
}
else
{
//学制
en.LearnSystem = Convert.ToDecimal(en.LearnSystemStr);
}
}
//入学日期
if (!string.IsNullOrEmpty(en.EntranceDateStr))
{
//reg = new Regex(@"(\d{4})-(\d{1,2})-(\d{1,2})"); //日期正则表达式,2017-12-28
if (!DateTime.TryParse(en.EntranceDateStr, out result))
{
errCount++;
errorMsgStr = "入学日期格式不正确,请检查";
en.ErrorMessage = errorMsgStr;
errList.Add(en);
errorMsg.AppendLine(errorMsgStr);
continue;
}
else
{
//入学日期
newStudent.EntranceDate = Convert.ToDateTime(en.EntranceDateStr);
}
}
else
{
//为空
}
//总分
if (!string.IsNullOrEmpty(en.ScoreStr))
{
reg = new Regex(@"^[0-9]+([.]{1}[0-9]+){0,1}$"); //数字正则表达式
if (!reg.IsMatch(en.ScoreStr))
{
errCount++;
errorMsgStr = "总分格式不正确,请检查";
en.ErrorMessage = errorMsgStr;
errList.Add(en);
errorMsg.AppendLine(errorMsgStr);
continue;
}
else
{
//总分
newStudent.Score = Convert.ToDecimal(en.ScoreStr);
}
}
else
{
//为空
}
//联系电话
if (string.IsNullOrEmpty(en.Telephone))
{
//暂不考虑
}
else
{
reg = new Regex(@"^[-0-9]+$"); //联系电话正则表达式
if (!reg.IsMatch(en.Telephone))
{
errCount++;
errorMsgStr = "联系电话格式不正确,请检查";
en.ErrorMessage = errorMsgStr;
errList.Add(en);
errorMsg.AppendLine(errorMsgStr);
continue;
}
else
{
//联系电话
newStudent.Telephone = en.Telephone;
}
}
//通讯地址
if (string.IsNullOrEmpty(en.Address))
{
//暂不考虑
}
else
{
newStudent.Address = en.Address;
}
//宿舍地址
if (string.IsNullOrEmpty(en.Dormitory))
{
//暂不考虑
}
else
{
newStudent.Dormitory = en.Dormitory;
}
//备注
if (string.IsNullOrEmpty(en.Remark))
{
//暂不考虑
}
else
{
newStudent.Remark = en.Remark;
}
//专业信息查询
var specialty = specialtyList.Where(x => x.StandardID == en.StandardID && x.LearnSystem == en.LearnSystem && x.EducationID == en.EducationID
&& x.LearningformID == en.LearningformID).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)
{
newStudent.SpecialtyID = specialty.SpecialtyID;
}
else
{
newStudent.SpecialtyID = specialty.SpecialtyID;
errCount++;
errorMsgStr = "专业信息为禁用状态,请检查";
en.ErrorMessage = errorMsgStr;
errList.Add(en);
errorMsg.AppendLine(errorMsgStr);
continue;
}
}
////Excel表重复性验证(注:当数据表中没有此记录,但是Excel中有重复数据时的去掉)
//for (int j = i + 1; j < enlist.Count; j++)
//{
// NewStudentView enA = enlist[j];
// //根据Excel表中的业务主键进行去重(考生号唯一)
// if (en.ExamineeNum == enA.ExamineeNum)
// {
// //用于标识Excel表中的重复记录(由于是批量进行插入数据表)
// }
//}
//由于新生管理模块中存在新生分配的业务,在进行新生信息新增时,
//需要对新生分配、录取名单中的信息进行提示性验证(业务主键:考生号唯一)
//处理方法:进行Excel导入时,对新生分配、录取名单中的信息提示性验证(当错误信息抛出)
//注:(未分配-1,预分配-2,已分配-3)
//数据表重复性验证(考生号唯一)
var examineeNumVerify = newStudentList.Where(x => x.ExamineeNum == newStudent.ExamineeNum).SingleOrDefault();
if (examineeNumVerify == null)
{
//if (!string.IsNullOrEmpty(newStudent.AdmissionTicketNo))
//{
// if (!newStudentUpList.Any(x => x.AdmissionTicketNo == newStudent.AdmissionTicketNo))
// {
// if (!newStudentInList.Any(x => x.AdmissionTicketNo == newStudent.AdmissionTicketNo))
// {
// var admissionTicketNoVerify = newStudentList.Where(x => x.AdmissionTicketNo == newStudent.AdmissionTicketNo).SingleOrDefault();
// if (admissionTicketNoVerify != null)
// {
// if (admissionTicketNoVerify.AssignStatus == (int)CF_AssignStatus.PreAssigned)
// {
// errCount++;
// errorMsgStr = "新生分配信息中已存在此准考证号(准考证号重复),请核查";
// en.ErrorMessage = errorMsgStr;
// errList.Add(en);
// errorMsg.AppendLine(errorMsgStr);
// continue;
// }
// else if (admissionTicketNoVerify.AssignStatus == (int)CF_AssignStatus.Assigned)
// {
// errCount++;
// errorMsgStr = "录取名单信息中已存在此准考证号(准考证号重复),请核查";
// en.ErrorMessage = errorMsgStr;
// errList.Add(en);
// errorMsg.AppendLine(errorMsgStr);
// continue;
// }
// else
// {
// errCount++;
// errorMsgStr = "已存在相同的准考证号(准考证号重复),请核查";
// en.ErrorMessage = errorMsgStr;
// errList.Add(en);
// errorMsg.AppendLine(errorMsgStr);
// continue;
// }
// }
// }
// else
// {
// errCount++;
// errorMsgStr = "准考证号重复(Excel中),请检查";
// en.ErrorMessage = errorMsgStr;
// errList.Add(en);
// errorMsg.AppendLine(errorMsgStr);
// continue;
// }
// }
// else
// {
// errCount++;
// errorMsgStr = "准考证号重复(Excel中),请检查";
// en.ErrorMessage = errorMsgStr;
// errList.Add(en);
// errorMsg.AppendLine(errorMsgStr);
// continue;
// }
//}
//新增
if (!newStudentInList.Any(x => x.ExamineeNum == newStudent.ExamineeNum))
{
newStudent.NewStudentID = Guid.NewGuid();
newStudent.IsDoubt = false;
newStudent.AssignStatus = (int)CF_AssignStatus.NotAssigned;
SetNewStatus(newStudent, (int)CF_NewStudentEnterStatus.NotSubmitted);
newStudentInList.Add(newStudent);
inCount++;
}
else
{
//Excel表重复性验证
//(注:当数据表中没有此记录,但是Excel中有重复数据,可在此处进行抛出到失败数据文件中)
errCount++;
errorMsgStr = "考生号重复(Excel中),请检查";
en.ErrorMessage = errorMsgStr;
errList.Add(en);
errorMsg.AppendLine(errorMsgStr);
continue;
}
}
else
{
//由于新生管理模块中存在新生分配的业务,只更新分配状态为:未分配-1
//分配状态为:预分配-2,已分配-3
if (examineeNumVerify.AssignStatus == (int)CF_AssignStatus.PreAssigned)
{
errCount++;
errorMsgStr = "导入失败,新生分配信息中已存在此考生号(考生号重复)";
en.ErrorMessage = errorMsgStr;
errList.Add(en);
errorMsg.AppendLine(errorMsgStr);
continue;
}
else if (examineeNumVerify.AssignStatus == (int)CF_AssignStatus.Assigned)
{
errCount++;
errorMsgStr = "导入失败,录取名单信息中已存在此考生号(考生号重复)";
en.ErrorMessage = errorMsgStr;
errList.Add(en);
errorMsg.AppendLine(errorMsgStr);
continue;
}
else
{
//更新(Excel有重复时,以最后一条记录的更新为准)
//if (!string.IsNullOrEmpty(newStudent.AdmissionTicketNo))
//{
// if (!newStudentInList.Any(x => x.AdmissionTicketNo == newStudent.AdmissionTicketNo))
// {
// if (!newStudentUpList.Any(x => x.AdmissionTicketNo == newStudent.AdmissionTicketNo))
// {
// var admissionTicketNoVerify = newStudentList.Where(x => x.AdmissionTicketNo == newStudent.AdmissionTicketNo).SingleOrDefault();
// if (admissionTicketNoVerify != null)
// {
// if (admissionTicketNoVerify.AssignStatus == (int)CF_AssignStatus.PreAssigned)
// {
// errCount++;
// errorMsgStr = "新生分配信息中已存在此准考证号(准考证号重复),请核查";
// en.ErrorMessage = errorMsgStr;
// errList.Add(en);
// errorMsg.AppendLine(errorMsgStr);
// continue;
// }
// else if (admissionTicketNoVerify.AssignStatus == (int)CF_AssignStatus.Assigned)
// {
// errCount++;
// errorMsgStr = "录取名单信息中已存在此准考证号(准考证号重复),请核查";
// en.ErrorMessage = errorMsgStr;
// errList.Add(en);
// errorMsg.AppendLine(errorMsgStr);
// continue;
// }
// else
// {
// errCount++;
// errorMsgStr = "已存在相同的准考证号(准考证号重复),请核查";
// en.ErrorMessage = errorMsgStr;
// errList.Add(en);
// errorMsg.AppendLine(errorMsgStr);
// continue;
// }
// }
// }
// else
// {
// errCount++;
// errorMsgStr = "准考证号重复(Excel中),请检查";
// en.ErrorMessage = errorMsgStr;
// errList.Add(en);
// errorMsg.AppendLine(errorMsgStr);
// continue;
// }
// }
// else
// {
// errCount++;
// errorMsgStr = "准考证号重复(Excel中),请检查";
// en.ErrorMessage = errorMsgStr;
// errList.Add(en);
// errorMsg.AppendLine(errorMsgStr);
// continue;
// }
//}
examineeNumVerify.ExamineeNum = newStudent.ExamineeNum;
examineeNumVerify.AdmissionTicketNo = newStudent.AdmissionTicketNo;
examineeNumVerify.Name = newStudent.Name;
examineeNumVerify.SexID = newStudent.SexID;
examineeNumVerify.NationID = newStudent.NationID;
examineeNumVerify.PoliticsID = newStudent.PoliticsID;
examineeNumVerify.BirthDate = newStudent.BirthDate;
examineeNumVerify.CertificatesType = newStudent.CertificatesType;
examineeNumVerify.IDNumber = newStudent.IDNumber;
examineeNumVerify.GradeID = newStudent.GradeID;
examineeNumVerify.SemesterID = newStudent.SemesterID;
examineeNumVerify.SpecialtyID = newStudent.SpecialtyID;
examineeNumVerify.EntranceDate = newStudent.EntranceDate;
examineeNumVerify.Score = newStudent.Score;
examineeNumVerify.Telephone = newStudent.Telephone;
examineeNumVerify.Address = newStudent.Address;
examineeNumVerify.Dormitory = newStudent.Dormitory;
examineeNumVerify.Remark = newStudent.Remark;
SetModifyStatus(examineeNumVerify);
newStudentUpList.Add(examineeNumVerify);
upCount++;
}
}
}
using (TransactionScope ts = new TransactionScope())
{
UnitOfWork.BulkInsert(newStudentInList);
if (newStudentUpList != null && newStudentUpList.Count() > 0)
{
UnitOfWork.BatchUpdate(newStudentUpList);
}
ts.Complete();
}
errdataList = errList.Distinct().ToList();
}
catch (Exception)
{
throw;
}
}
}
}