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.ViewModel;
using EMIS.ViewModel.CacheManage;
using EMIS.ViewModel.StudentManage.StudentProfile;
using EMIS.ViewModel.UniversityManage.SpecialtyClassManage;
using EMIS.DataLogic.UniversityManage.SpecialtyClassManage;
using EMIS.CommonLogic.StudentManage.StudentStatistics;

namespace EMIS.CommonLogic.UniversityManage.SpecialtyClassManage
{
    public class GrademajorServices : BaseServices, IGrademajorServices
    {
        public GrademajorDAL GrademajorDAL { get; set; }
        public Lazy<IInSchoolSettingServices> InSchoolSettingServices { get; set; }

        /// <summary>
        /// 查询对应的年级专业信息GrademajorView
        /// </summary>
        /// <param name="configuretView"></param>
        /// <param name="campusID"></param>
        /// <param name="collegeID"></param>
        /// <param name="gradeID"></param>
        /// <param name="standardID"></param>
        /// <param name="educationID"></param>
        /// <param name="learningformID"></param>
        /// <param name="learnSystem"></param>
        /// <param name="inSchoolStatus"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public IGridResultSet<GrademajorView> GetGrademajorViewGrid(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? gradeID, int? standardID, 
                int? educationID, int? learningformID, string learnSystem, int? inSchoolStatus, int pageIndex, int pageSize)
        {
            Expression<Func<CF_Grademajor, bool>> expGrademajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
            if (gradeID.HasValue)
            {
                expGrademajor = expGrademajor.And(x => x.GradeID == gradeID);
            }
            //学生信息
            Expression<Func<CF_Student, bool>> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
            if (inSchoolStatus != null && inSchoolStatus > -1)
            {
                var inschoolStatusList = InSchoolSettingServices.Value.GetInschoolStatusList(true);
                if (inSchoolStatus == 1)
                {
                    //表示在校
                    expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
                }
                if (inSchoolStatus == 0)
                {
                    //不在校
                    expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
                }
            }
            var query = GrademajorDAL.GetGrademajorViwQueryable(expGrademajor, expStudent);
            if (campusID.HasValue)
            {
                //校区
                query = query.Where(x => x.CampusID == campusID);
            }
            if (collegeID.HasValue)
            {
                //院系所
                query = query.Where(x => x.CollegeID == collegeID);
            }
            if (standardID.HasValue)
            {
                //专业ID(Value)
                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 (inSchoolStatus != null && inSchoolStatus > -1)
            //{
            //    //排除人数为0的信息
            //    query = query.Where(x => x.StudentCount > 0);
            //}

            //查询条件
            if (!string.IsNullOrEmpty(configuretView.ConditionValue))
            {
                query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
            }

            return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode).ThenBy(x => x.StandardID)
                    .ThenBy(x => x.Code.Length).ThenBy(x => x.Code).ToGridResultSet<GrademajorView>(pageIndex, pageSize);
        }

        /// <summary>
        /// 查询对应的年级专业信息List
        /// </summary>
        /// <param name="configuretView"></param>
        /// <param name="campusID"></param>
        /// <param name="collegeID"></param>
        /// <param name="gradeID"></param>
        /// <param name="standardID"></param>
        /// <param name="educationID"></param>
        /// <param name="learningformID"></param>
        /// <param name="learnSystem"></param>
        /// <param name="inSchoolStatus"></param>
        /// <returns></returns>
        public IList<GrademajorView> GetGrademajorViewList(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? gradeID, int? standardID, 
                int? educationID, int? learningformID, string learnSystem, int? inSchoolStatus)
        {
            Expression<Func<CF_Grademajor, bool>> expGrademajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
            if (gradeID.HasValue)
            {
                expGrademajor = expGrademajor.And(x => x.GradeID == gradeID);
            }
            //学生信息
            Expression<Func<CF_Student, bool>> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
            if (inSchoolStatus != null && inSchoolStatus > -1)
            {
                var inschoolStatusList = InSchoolSettingServices.Value.GetInschoolStatusList(true);
                if (inSchoolStatus == 1)
                {
                    //表示在校
                    expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
                }
                if (inSchoolStatus == 0)
                {
                    //不在校
                    expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
                }
            }
            var query = GrademajorDAL.GetGrademajorViwQueryable(expGrademajor, expStudent);
            if (campusID.HasValue)
            {
                //校区
                query = query.Where(x => x.CampusID == campusID);
            }
            if (collegeID.HasValue)
            {
                //院系所
                query = query.Where(x => x.CollegeID == collegeID);
            }
            if (standardID.HasValue)
            {
                //专业ID(Value)
                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 (inSchoolStatus != null && inSchoolStatus > -1)
            //{
            //    //排除人数为0的信息
            //    query = query.Where(x => x.StudentCount > 0);
            //}

            //查询条件
            if (!string.IsNullOrEmpty(configuretView.ConditionValue))
            {
                query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
            }

            return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode).ThenBy(x => x.StandardID)
                    .ThenBy(x => x.Code.Length).ThenBy(x => x.Code).ToList();
        }

        /// <summary>
        /// 查询对应的年级专业信息GrademajorView(无数据范围)
        /// </summary>
        /// <param name="configuretView"></param>
        /// <param name="campusID"></param>
        /// <param name="collegeID"></param>
        /// <param name="gradeID"></param>
        /// <param name="standardID"></param>
        /// <param name="educationID"></param>
        /// <param name="learningformID"></param>
        /// <param name="learnSystem"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public IGridResultSet<GrademajorView> GetGrademajorViewWithoutRangeGrid(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? gradeID, 
                int? standardID, int? educationID, int? learningformID, string learnSystem, int pageIndex, int pageSize)
        {
            Expression<Func<CF_Grademajor, bool>> expGrademajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
            if (gradeID.HasValue)
            {
                expGrademajor = expGrademajor.And(x => x.GradeID == gradeID);
            }
            var query = GrademajorDAL.GetGrademajorViwQueryable(expGrademajor);
            if (campusID.HasValue)
            {
                //校区
                query = query.Where(x => x.CampusID == campusID);
            }
            if (collegeID.HasValue)
            {
                //院系所
                query = query.Where(x => x.CollegeID == collegeID);
            }
            if (standardID.HasValue)
            {
                //专业ID(Value)
                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.OrderBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode).ThenBy(x => x.StandardID).ThenBy(x => x.Code.Length).ThenBy(x => x.Code).ToGridResultSet<GrademajorView>(pageIndex, pageSize);
        }

        /// <summary>
        /// 查询年级专业中的专业名称信息FacultymajorView(去重)
        /// </summary>
        /// <param name="configuretView"></param>
        /// <param name="collegeID"></param>
        /// <param name="gradeID"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public IGridResultSet<FacultymajorView> GetStandardViewGrid(ConfiguretView configuretView, Guid? collegeID, int? gradeID, int pageIndex, int pageSize)
        {
            Expression<Func<CF_Grademajor, bool>> expGrademajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
            if (collegeID.HasValue)
            {
                expGrademajor = expGrademajor.And(x => x.CF_Facultymajor.CollegeID == collegeID);
            }
            if (gradeID.HasValue)
            {
                expGrademajor = expGrademajor.And(x => x.GradeID == gradeID);
            }
            var query = GrademajorDAL.GetStandardViewQueryable(expGrademajor);

            //查询条件
            if (!string.IsNullOrEmpty(configuretView.ConditionValue))
            {
                query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
            }

            return query.OrderBy(x => x.StandardName).ToGridResultSet<FacultymajorView>(pageIndex, pageSize);

        }

        /// <summary>
        /// 查询年级专业中的专业名称信息List(去重)
        /// </summary>
        /// <param name="configuretView"></param>
        /// <param name="collegeID"></param>
        /// <param name="gradeID"></param>
        /// <returns></returns>
        public IList<FacultymajorView> GetStandardViewList(ConfiguretView configuretView, Guid? collegeID, int? gradeID)
        {
            Expression<Func<CF_Grademajor, bool>> expGrademajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
            if (collegeID.HasValue)
            {
                expGrademajor = expGrademajor.And(x => x.CF_Facultymajor.CollegeID == collegeID);
            }
            if (gradeID.HasValue)
            {
                expGrademajor = expGrademajor.And(x => x.GradeID == gradeID);
            }
            var query = GrademajorDAL.GetStandardViewQueryable(expGrademajor);

            //查询条件
            if (!string.IsNullOrEmpty(configuretView.ConditionValue))
            {
                query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
            }

            return query.OrderBy(x => x.StandardName).ToList();
        }

        /// <summary>
        /// 查询年级专业中的年级信息GrademajorView(去重)
        /// </summary>
        /// <param name="configuretView"></param>
        /// <param name="collegeID"></param>
        /// <param name="standardID"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public IGridResultSet<GrademajorView> GetGradeViewGrid(ConfiguretView configuretView, Guid? collegeID, int? standardID, int pageIndex, int pageSize)
        {
            Expression<Func<CF_Grademajor, bool>> expGrademajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
            if (collegeID.HasValue)
            {
                expGrademajor = expGrademajor.And(x => x.CF_Facultymajor.CollegeID == collegeID);
            }
            if (standardID.HasValue)
            {
                expGrademajor = expGrademajor.And(x => x.CF_Facultymajor.StandardID == standardID);
            }
            var query = GrademajorDAL.GetGradeViewQueryable(expGrademajor);

            //查询条件
            if (!string.IsNullOrEmpty(configuretView.ConditionValue))
            {
                query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
            }

            return query.OrderByDescending(x => x.GradeID).ToGridResultSet<GrademajorView>(pageIndex, pageSize);
        }

        /// <summary>
        /// 查询年级专业中的年级信息List(去重)
        /// </summary>
        /// <param name="configuretView"></param>
        /// <param name="collegeID"></param>
        /// <param name="standardID"></param>
        /// <returns></returns>
        public IList<GrademajorView> GetGradeViewList(ConfiguretView configuretView, Guid? collegeID, int? standardID)
        {
            Expression<Func<CF_Grademajor, bool>> expGrademajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
            if (collegeID.HasValue)
            {
                expGrademajor = expGrademajor.And(x => x.CF_Facultymajor.CollegeID == collegeID);
            }
            if (standardID.HasValue)
            {
                expGrademajor = expGrademajor.And(x => x.CF_Facultymajor.StandardID == standardID);
            }
            var query = GrademajorDAL.GetGradeViewQueryable(expGrademajor);

            //查询条件
            if (!string.IsNullOrEmpty(configuretView.ConditionValue))
            {
                query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
            }

            return query.OrderByDescending(x => x.GradeID).ToList();
        }

        /// <summary>
        /// 查询对应的年级专业信息CF_Grademajor
        /// </summary>
        /// <param name="grademajorID"></param>
        /// <returns></returns>
        public CF_Grademajor GetGrademajorInfo(Guid? grademajorID)
        {
            try
            {
                var query = GrademajorDAL.GrademajorRepository.GetList(x => x.GrademajorID == grademajorID).SingleOrDefault();

                return query;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

        /// <summary>
        /// 查询对应的年级专业信息GrademajorView
        /// </summary>
        /// <param name="grademajorID"></param>
        /// <returns></returns>
        public GrademajorView GetGrademajorView(Guid? grademajorID)
        {
            try
            {
                var query = GrademajorDAL.GetGrademajorViwQueryable(x => x.GrademajorID == grademajorID).SingleOrDefault();

                return query;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

        /// <summary>
        /// 查询对应的年级专业信息List
        /// </summary>
        /// <param name="collegeID"></param>
        /// <param name="gradeID"></param>
        /// <returns></returns>
        public IList<GrademajorView> GetGrademajorViewList(Guid? collegeID, int? gradeID)
        {
            Expression<Func<CF_Grademajor, bool>> expGrademajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
            if (gradeID.HasValue)
            {
                expGrademajor = expGrademajor.And(x => x.GradeID == gradeID);
            }
            var query = GrademajorDAL.GetGrademajorViwQueryable(expGrademajor);
            if (collegeID.HasValue)
            {
                query = query.Where(x => x.CollegeID == collegeID);
            }

            return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode).ThenBy(x => x.StandardID).ThenBy(x => x.Code.Length).ThenBy(x => x.Code).ToList();
        }

        /// <summary>
        /// 编辑(新增、修改,业务主键:年级专业编号或年级专业名称唯一)
        /// </summary>
        /// <param name="grademajorView"></param>
        public void GrademajorEdit(GrademajorView grademajorView)
        {
            try
            {
                //查询数据库进行验证
                var grademajorVerify = GrademajorDAL.GrademajorRepository.GetList(x => x.GrademajorID != grademajorView.GrademajorID && (x.Code == grademajorView.Code || x.Name == grademajorView.Name)).FirstOrDefault();
                if (grademajorVerify == null)
                {
                    //计算相应的毕业学年学期Value
                    var facultymajor = GrademajorDAL.FacultymajorRepository.GetSingle(x => x.FacultymajorID == grademajorView.FacultymajorID);
                    var graduateSchoolyearValue = (grademajorView.GradeID.Value * 2) - 1 + (grademajorView.SemesterID.Value - 1);
                    graduateSchoolyearValue += Convert.ToInt32(Math.Ceiling(facultymajor.LearnSystem.Value * 2 - 1));
                    var graduateSchoolyear = GrademajorDAL.SchoolyearRepository.GetSingle(x => x.Value == graduateSchoolyearValue);
                    if (graduateSchoolyear == null)
                    {
                        throw new Exception("预计毕业学年学期超出了系统学年学期数据的范围,请添加足够的学年学期记录以支撑该操作。");
                    }
                    //数据有误验证
                    if (grademajorView.GrademajorID != Guid.Empty)
                    {
                        var grademajor = GrademajorDAL.GrademajorRepository.GetList(x => x.GrademajorID == grademajorView.GrademajorID).SingleOrDefault();
                        if (grademajor == null)
                        {
                            throw new Exception("数据有误,请核查。");
                        }
                        else
                        {
                            //表示修改(暂时不考虑对应的班级信息下的学生拟毕业日期的更新,后续再处理)
                            //目前通过修改对应的班级信息来更新
                            grademajor.FacultymajorID = grademajorView.FacultymajorID;
                            grademajor.Code = grademajorView.Code.Trim();
                            grademajor.Name = grademajorView.Name;
                            grademajor.Abbreviation = grademajorView.Abbreviation;
                            grademajor.GradeID = grademajorView.GradeID;
                            grademajor.SemesterID = grademajorView.SemesterID;
                            grademajor.GraduateSchoolyearID = graduateSchoolyear.SchoolyearID;
                            grademajor.Professional = grademajorView.Professional;
                            grademajor.Remark = grademajorView.Remark;
                            SetModifyStatus(grademajor);
                        }
                    }
                    else
                    {
                        //表示新增
                        CF_Grademajor grademajor = new CF_Grademajor();
                        grademajor.GrademajorID = Guid.NewGuid();
                        grademajor.FacultymajorID = grademajorView.FacultymajorID;
                        grademajor.Code = grademajorView.Code.Trim();
                        grademajor.Name = grademajorView.Name;
                        grademajor.Abbreviation = grademajorView.Abbreviation;
                        grademajor.GradeID = grademajorView.GradeID;
                        grademajor.SemesterID = grademajorView.SemesterID;
                        grademajor.GraduateSchoolyearID = graduateSchoolyear.SchoolyearID;
                        grademajor.Professional = grademajorView.Professional;
                        grademajor.Remark = grademajorView.Remark;
                        SetNewStatus(grademajor);
                        UnitOfWork.Add(grademajor);
                    }
                }
                else
                {
                    throw new Exception("已存在相同的年级专业编号或年级专业名称,请核查。");
                }
                //事务提交
                UnitOfWork.Commit();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

        /// <summary>
        /// 批量新增
        /// </summary>
        /// <param name="grademajorView"></param>
        /// <returns></returns>
        public int GrademajorBatchAdd(GrademajorView grademajorView)
        {
            try
            {
                List<CF_Grademajor> grade = new List<CF_Grademajor>();
                //获取源数据
                var Grademajor = GrademajorDAL.GetGrademajorViwQueryable(x => x.GradeID == grademajorView.GradeID);
                if (grademajorView.CollegeID != null)
                {
                    Grademajor = Grademajor.Where(x => x.CollegeID == grademajorView.CollegeID);
                }
                if (grademajorView.StandardID != null && grademajorView.StandardID != -1)
                {
                    Grademajor = Grademajor.Where(x => x.StandardID == grademajorView.StandardID);
                }
                //获取年级专业
                var GrademajorList = Grademajor.ToList();
                //获取学年学期
                var SchoolYearList = GrademajorDAL.SchoolyearRepository.GetList(x => x.RecordStatus == (int)SYS_STATUS.USABLE).ToList();
                //获取院系专业
                var FacultymajorIDList = GrademajorList.Select(x => x.FacultymajorID).ToList();
                var Facultymajorlist = GrademajorDAL.FacultymajorRepository.GetList(x => FacultymajorIDList.Contains(x.FacultymajorID)).ToList();
                //获取目标年级已存在数据
                var BatchGrademajor = GrademajorDAL.GetGrademajorViwQueryable(x => x.GradeID == grademajorView.BatchGradeID);
                if (grademajorView.CollegeID != null)
                {
                    BatchGrademajor = BatchGrademajor.Where(x => x.CollegeID == grademajorView.CollegeID);
                }
                if (grademajorView.StandardID != null && grademajorView.StandardID != -1)
                {
                    BatchGrademajor = BatchGrademajor.Where(x => x.StandardID == grademajorView.StandardID);
                }
                var BatchGrademajorList = BatchGrademajor.ToList();
                //插入数据
                foreach (var g in GrademajorList)
                {
                    CF_Facultymajor facultymajor = new CF_Facultymajor();
                    facultymajor = Facultymajorlist.Where(x => x.FacultymajorID == g.FacultymajorID).FirstOrDefault();
                    var graduateSchoolyearValue = (grademajorView.BatchGradeID.Value * 2) - 1 + (g.SemesterID.Value - 1);
                    graduateSchoolyearValue += Convert.ToInt32(Math.Ceiling(facultymajor.LearnSystem.Value * 2 - 1));
                    var graduateSchoolyear = SchoolYearList.Where(x => x.Value == graduateSchoolyearValue).FirstOrDefault();
                    CF_Grademajor grademajor = new CF_Grademajor();
                    if (graduateSchoolyear == null)
                    {
                        throw new Exception("预计毕业学年学期超出了系统学年学期数据的范围,请添加足够的学年学期记录以支撑该操作。");
                    }
                    string gradeID = g.GradeID.ToString();
                    string batchGradeID = grademajorView.BatchGradeID.Value.ToString();
                    //替换复制的年级专业代码
                    string Code = g.Code.Trim().Replace(gradeID, batchGradeID);
                    //替换复制的年级专业名称
                    string Name = g.Name.Trim().Replace(gradeID, batchGradeID);
                    //替换复制的年级专业简称
                    string Abbreviation = g.Abbreviation;
                    if (g.Abbreviation != null)
                    {
                        Abbreviation = g.Abbreviation.Trim().Replace(gradeID, batchGradeID);
                    }
                    grademajor.GrademajorID = Guid.NewGuid();
                    grademajor.Code = Code;
                    grademajor.Name = Name;
                    grademajor.Abbreviation = Abbreviation;
                    grademajor.GradeID = grademajorView.BatchGradeID;
                    grademajor.Professional = g.Professional;
                    grademajor.SemesterID = g.SemesterID;
                    grademajor.FacultymajorID = g.FacultymajorID;
                    grademajor.GraduateSchoolyearID = graduateSchoolyear.SchoolyearID;
                    grademajor.Remark = g.Remark;
                    SetNewStatus(grademajor);
                    if (!grademajorView.IsOverwrite)
                    {
                        var batch = BatchGrademajorList.Where(x => x.Code == Code && x.GradeID == grademajorView.BatchGradeID && x.FacultymajorID == g.FacultymajorID).FirstOrDefault();
                        if (batch == null)
                        {
                            grade.Add(grademajor);
                        }
                    }
                    else
                    {
                        var BatchGrademajorIDList = BatchGrademajorList.Select(x => x.GrademajorID).ToList();
                        List<Guid> ids = new List<Guid>();
                        if (BatchGrademajorIDList.Count > 0)
                        {
                            foreach (var id in BatchGrademajorIDList)
                            {
                                ids.Add(id);
                            }

                            UnitOfWork.Remove<CF_Grademajor>(x => ids.Contains(x.GrademajorID));
                        }
                        grade.Add(grademajor);
                    }
                }
                UnitOfWork.BulkInsert(grade);
                UnitOfWork.Commit();
                return grade.Count();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="grademajorIDList"></param>
        /// <returns></returns>
        public bool GrademajorDelete(List<Guid?> grademajorIDList)
        {
            try
            {
                UnitOfWork.Delete<CF_Grademajor>(x => grademajorIDList.Contains(x.GrademajorID));
                return true;
            }
            catch (Exception)
            {
                throw;
            }
        }

        /// <summary>
        /// 查询年级专业对应的班级信息ClassmajorView(带对应的在校状态学生人数)
        /// </summary>
        /// <param name="configuretView"></param>
        /// <param name="grademajorID"></param>
        /// <param name="inSchoolStatus"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public IGridResultSet<ClassmajorView> GetClassmajorViewGrid(ConfiguretView configuretView, Guid? grademajorID, int? inSchoolStatus, int pageIndex, int pageSize)
        {
            Expression<Func<CF_Grademajor, bool>> expGrademajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
            expGrademajor = expGrademajor.And(x => x.GrademajorID == grademajorID);
            //学生信息
            Expression<Func<CF_Student, bool>> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
            if (inSchoolStatus != null && inSchoolStatus > -1)
            {
                var inschoolStatusList = InSchoolSettingServices.Value.GetInschoolStatusList(true);
                if (inSchoolStatus == 1)
                {
                    //表示在校
                    expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
                }
                if (inSchoolStatus == 0)
                {
                    //不在校
                    expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
                }
            }
            var query = GrademajorDAL.GetClassmajorViewQueryable(expGrademajor, expStudent);

            //if (inSchoolStatus != null && inSchoolStatus > -1)
            //{
            //    //排除人数为0的信息
            //    query = query.Where(x => x.StudentCount > 0);
            //}

            //查询条件
            if (!string.IsNullOrEmpty(configuretView.ConditionValue))
            {
                query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
            }

            return query.OrderBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode).ThenBy(x => x.StandardID).ThenBy(x => x.No.Length)
                    .ThenBy(x => x.No).ThenBy(x => x.ClassNum).ToGridResultSet<ClassmajorView>(pageIndex, pageSize);
        }

        /// <summary>
        /// 查询年级专业对应的班级信息List(带对应的在校状态学生人数)
        /// </summary>
        /// <param name="configuretView"></param>
        /// <param name="grademajorID"></param>
        /// <param name="inSchoolStatus"></param>
        /// <returns></returns>
        public IList<ClassmajorView> GetClassmajorViewList(ConfiguretView configuretView, Guid? grademajorID, int? inSchoolStatus)
        {
            Expression<Func<CF_Grademajor, bool>> expGrademajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
            expGrademajor = expGrademajor.And(x => x.GrademajorID == grademajorID);
            //学生信息
            Expression<Func<CF_Student, bool>> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
            if (inSchoolStatus != null && inSchoolStatus > -1)
            {
                var inschoolStatusList = InSchoolSettingServices.Value.GetInschoolStatusList(true);
                if (inSchoolStatus == 1)
                {
                    //表示在校
                    expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
                }
                if (inSchoolStatus == 0)
                {
                    //不在校
                    expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
                }
            }
            var query = GrademajorDAL.GetClassmajorViewQueryable(expGrademajor, expStudent);

            //if (inSchoolStatus != null && inSchoolStatus > -1)
            //{
            //    //排除人数为0的信息
            //    query = query.Where(x => x.StudentCount > 0);
            //}

            //查询条件
            if (!string.IsNullOrEmpty(configuretView.ConditionValue))
            {
                query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
            }

            return query.OrderBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode).ThenBy(x => x.StandardID).ThenBy(x => x.No.Length)
                    .ThenBy(x => x.No).ThenBy(x => x.ClassNum).ToList();
        }

        /// <summary>
        /// 查询年级专业对应的学生信息BaseStudentView
        /// </summary>
        /// <param name="configuretView"></param>
        /// <param name="grademajorID"></param>
        /// <param name="inSchoolStatus"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public IGridResultSet<StudentBaseView> GetStudentBaseViewGrid(ConfiguretView configuretView, Guid? grademajorID, int? inSchoolStatus, int pageIndex, int pageSize)
        {
            Expression<Func<CF_Grademajor, bool>> expGrademajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
            expGrademajor = expGrademajor.And(x => x.GrademajorID == grademajorID);
            //学生信息
            Expression<Func<CF_Student, bool>> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
            if (inSchoolStatus != null && inSchoolStatus > -1)
            {
                var inschoolStatusList = InSchoolSettingServices.Value.GetInschoolStatusList(true);
                if (inSchoolStatus == 1)
                {
                    //表示在校
                    expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
                }
                if (inSchoolStatus == 0)
                {
                    //不在校
                    expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
                }
            }
            var query = GrademajorDAL.GetStudentBaseViewQueryable(expGrademajor, expStudent);

            //查询条件
            if (!string.IsNullOrEmpty(configuretView.ConditionValue))
            {
                query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
            }
            return query.OrderBy(x => x.LoginID).ThenBy(x => x.ClassmajorNo.Length).ThenBy(x => x.ClassmajorNo).ToGridResultSet<StudentBaseView>(pageIndex, pageSize);
        }

        /// <summary>
        /// 查询年级专业对应的学生信息List
        /// </summary>
        /// <param name="configuretView"></param>
        /// <param name="grademajorID"></param>
        /// <param name="inSchoolStatus"></param>
        /// <returns></returns>
        public IList<StudentBaseView> GetStudentBaseViewList(ConfiguretView configuretView, Guid? grademajorID, int? inSchoolStatus)
        {
            Expression<Func<CF_Grademajor, bool>> expGrademajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
            expGrademajor = expGrademajor.And(x => x.GrademajorID == grademajorID);
            //学生信息
            Expression<Func<CF_Student, bool>> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
            if (inSchoolStatus != null && inSchoolStatus > -1)
            {
                var inschoolStatusList = InSchoolSettingServices.Value.GetInschoolStatusList(true);
                if (inSchoolStatus == 1)
                {
                    //表示在校
                    expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID));
                }
                if (inSchoolStatus == 0)
                {
                    //不在校
                    expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID));
                }
            }
            var query = GrademajorDAL.GetStudentBaseViewQueryable(expGrademajor, expStudent);

            //查询条件
            if (!string.IsNullOrEmpty(configuretView.ConditionValue))
            {
                query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
            }
            return query.OrderBy(x => x.LoginID).ThenBy(x => x.ClassmajorNo.Length).ThenBy(x => x.ClassmajorNo).ToList();
        }

        /// <summary>
        /// 批量修改(重写)
        /// 暂时不考虑对应的班级信息下的学生拟毕业日期的更新,后续再处理
        /// 目前通过修改对应的班级信息来更新
        /// </summary>
        /// <param name="grademajorIDs"></param>
        /// <param name="gradeID"></param>
        /// <param name="semesterID"></param>
        /// <returns></returns>
        public string BatchModify(string grademajorIDs, int? gradeID, int? semesterID)
        {
            List<Guid> list = new List<Guid>();
            HashSet<string> hs = new HashSet<string>();
            for (int i = 0; i < grademajorIDs.Split(',').Length; i++)
            {
                string id = grademajorIDs.Split(',')[i];
                if (!string.IsNullOrEmpty(id))
                {
                    Guid grademajorID = new Guid(id);
                    list.Add(grademajorID);
                }
            }
            int sCount = 0;
            int lCount = 0;
            foreach (Guid li in list)
            {
                GrademajorView grademajorView = GrademajorDAL.GetGrademajorViwQueryable(x => x.GrademajorID == li).FirstOrDefault();
                CF_Grademajor grademajor = new CF_Grademajor();
                grademajor = GrademajorDAL.GrademajorRepository.GetSingle(x => x.GrademajorID == li);
                if (gradeID != null)
                {
                    sCount++;
                    grademajor.GradeID = gradeID;
                    var graduateSchoolyearValue = (gradeID * 2) - 1 + ((int)grademajor.SemesterID - 1);
                    graduateSchoolyearValue += Convert.ToInt32(Math.Ceiling((double)grademajorView.LearnSystem * 2 - 1));
                    var graduateSchoolyear = GrademajorDAL.SchoolyearRepository.GetSingle(x => x.Value == graduateSchoolyearValue);
                    if (graduateSchoolyear == null)
                    {
                        lCount++;
                        hs.Add("预计毕业学年学期超出了系统学年学期数据的范围,请添加足够的学年学期记录以支撑该操作。");
                        continue;
                    }
                    else
                    {
                        grademajor.GraduateSchoolyearID = graduateSchoolyear.SchoolyearID;
                    }
                }
                if (semesterID != null)
                {
                    sCount++;
                    grademajor.SemesterID = semesterID;
                    var graduateSchoolyearValue = (grademajor.GradeID * 2) - 1 + ((int)semesterID - 1);
                    graduateSchoolyearValue += Convert.ToInt32(Math.Ceiling((double)grademajorView.LearnSystem * 2 - 1));
                    var graduateSchoolyear = GrademajorDAL.SchoolyearRepository.GetSingle(x => x.Value == graduateSchoolyearValue);
                    if (graduateSchoolyear == null)
                    {
                        lCount++;
                        hs.Add("预计毕业学年学期超出了系统学年学期数据的范围,请添加足够的学年学期记录以支撑该操作。");
                        continue;
                    }
                    else
                    {
                        grademajor.GraduateSchoolyearID = graduateSchoolyear.SchoolyearID;
                    }
                }
                SetModifyStatus(grademajor);
                UnitOfWork.Commit();

            }
            StringBuilder sb = new StringBuilder();
            int s = hs.Count();
            foreach (string li in hs)
            {
                sb.Append(li);
            }
            if (lCount > 0)
            {
                return "批量修改成功" + (grademajorIDs.Split(',').Length - lCount) + "条,批量修改失败" + lCount + "条,失败原因:" + sb;
            }
            else
            {
                return "批量修改成功" + (grademajorIDs.Split(',').Length - lCount) + "条";
            }
        }

        /// <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 GrademajorImport(Dictionary<string, string> cellheader, out int? inCount, out int? upCount, out List<GrademajorView> errdataList, out int? errCount, string sourcePhysicalPath)
        {
            try
            {
                StringBuilder errorMsg = new StringBuilder();
                List<GrademajorView> errList = new List<GrademajorView>();
                cellheader.Remove("ErrorMessage");
                List<GrademajorView> enlist = NpoiExcelHelper.ExcelToEntityList<GrademajorView>(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<CF_Grademajor> newGrademajorInList = new List<CF_Grademajor>();
                List<CF_Grademajor> newGrademajorUpList = new List<CF_Grademajor>();
                //将循环中相关数据库查询统一查询出来进行匹配(尽量避免在循环中进行数据库查询)
                //年级专业信息
                var grademajorList = GrademajorDAL.GrademajorRepository.GetList(x => true).ToList();
                //年级专业编号
                var grademajorCodeList = enlist.Where(x => !string.IsNullOrEmpty(x.Code)).Select(x => x.Code).ToList();
                //年级专业名称
                var grademajorNameList = enlist.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name).ToList();
                //对比后的newGrademajorList
                var newGrademajorList = grademajorList.Where(x => grademajorCodeList.Contains(x.Code) || grademajorNameList.Contains(x.Name)).ToList();
                //院系专业信息
                var facultymajorList = GrademajorDAL.FacultymajorRepository.GetList(x => true).ToList();
                //院系专业编号
                var facultymajorCodeList = enlist.Where(x => !string.IsNullOrEmpty(x.FacultymajorCode)).Select(x => x.FacultymajorCode).ToList();
                //对比后的newFacultymajorList
                var newFacultymajorList = facultymajorList.Where(x => facultymajorCodeList.Contains(x.Code)).ToList();
                //年级
                var gradeList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Grade).ToList();
                //学期
                var semesterList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Semester).ToList();

                //循环检测数据列,对各数据列进行验证(必填、字典项验证、数据格式等)
                for (int i = 0; i < enlist.Count; i++)
                {
                    GrademajorView en = enlist[i]; //Excel表数据视图
                    CF_Grademajor newGrademajor = new CF_Grademajor();
                    //年级专业编号
                    if (string.IsNullOrEmpty(en.Code))
                    {
                        errCount++;
                        errorMsgStr = "年级专业编号不能为空";
                        en.ErrorMessage = errorMsgStr;
                        errList.Add(en);
                        errorMsg.AppendLine(errorMsgStr);
                        continue;
                    }
                    else
                    {
                        reg = new Regex(@"^[0-9a-zA-Z\s?]+$"); //正则表达式(请输入数字或英文字母)
                        if (!reg.IsMatch(en.Code))
                        {
                            errCount++;
                            errorMsgStr = "年级专业编号格式不正确,请检查(数字或英文字母)";
                            en.ErrorMessage = errorMsgStr;
                            errList.Add(en);
                            errorMsg.AppendLine(errorMsgStr);
                            continue;
                        }
                        else
                        {
                            //年级专业编号
                            newGrademajor.Code = en.Code.Trim();
                        }
                    }
                    //年级专业名称
                    if (string.IsNullOrEmpty(en.Name))
                    {
                        errCount++;
                        errorMsgStr = "年级专业名称不能为空";
                        en.ErrorMessage = errorMsgStr;
                        errList.Add(en);
                        errorMsg.AppendLine(errorMsgStr);
                        continue;
                    }
                    else
                    {
                        //年级专业名称
                        newGrademajor.Name = en.Name.Trim();
                    }
                    //简称
                    if (string.IsNullOrEmpty(en.Abbreviation))
                    {
                        //不考虑
                    }
                    else
                    {
                        newGrademajor.Abbreviation = en.Abbreviation;
                    }
                    //院系专业编号
                    if (string.IsNullOrEmpty(en.FacultymajorCode))
                    {
                        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.FacultymajorCode))
                        {
                            errCount++;
                            errorMsgStr = "院系专业编号格式不正确,请检查(数字或英文字母)";
                            en.ErrorMessage = errorMsgStr;
                            errList.Add(en);
                            errorMsg.AppendLine(errorMsgStr);
                            continue;
                        }
                        else
                        {
                            //暂时不考虑院系专业编号有相同的情况
                            var facultymajor = newFacultymajorList.Where(x => x.Code == en.FacultymajorCode.Trim()).SingleOrDefault();
                            if (facultymajor == null)
                            {
                                errCount++;
                                errorMsgStr = "院系专业编号不存在,请检查";
                                en.ErrorMessage = errorMsgStr;
                                errList.Add(en);
                                errorMsg.AppendLine(errorMsgStr);
                                continue;
                            }
                            else
                            {
                                //院系专业信息ID
                                newGrademajor.FacultymajorID = facultymajor.FacultymajorID;
                                //学制(用于计算毕业学期)
                                en.LearnSystem = facultymajor.LearnSystem;
                            }
                        }
                    }
                    //年级
                    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
                        {
                            //年级
                            newGrademajor.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
                        {
                            //入学学期
                            newGrademajor.SemesterID = semester.Value;
                        }
                    }
                    //专业方向
                    if (string.IsNullOrEmpty(en.Professional))
                    {
                        //不考虑
                    }
                    else
                    {
                        newGrademajor.Professional = en.Professional;
                    }
                    //备注
                    if (string.IsNullOrEmpty(en.Remark))
                    {
                        //不考虑
                    }
                    else
                    {
                        newGrademajor.Remark = en.Remark;
                    }
                    //学制
                    if (en.LearnSystem == null)
                    {
                        errCount++;
                        errorMsgStr = "院系专业编号中对应的学制有误(不能为空),请检查";
                        en.ErrorMessage = errorMsgStr;
                        errList.Add(en);
                        errorMsg.AppendLine(errorMsgStr);
                        continue;
                    }
                    else
                    {
                        //计算相应的毕业学年学期Value
                        var graduateSchoolyearValue = (newGrademajor.GradeID.Value * 2) - 1 + (newGrademajor.SemesterID.Value - 1);
                        graduateSchoolyearValue += Convert.ToInt32(Math.Ceiling(en.LearnSystem.Value * 2 - 1));
                        var graduateSchoolyear = GrademajorDAL.SchoolyearRepository.GetSingle(x => x.Value == graduateSchoolyearValue);
                        if (graduateSchoolyear == null)
                        {
                            errCount++;
                            errorMsgStr = "预计毕业学年学期超出了系统学年学期数据的范围,请添加足够的学年学期记录以支撑该操作,请检查";
                            en.ErrorMessage = errorMsgStr;
                            errList.Add(en);
                            errorMsg.AppendLine(errorMsgStr);
                            continue;
                        }
                        else
                        {
                            newGrademajor.GraduateSchoolyearID = graduateSchoolyear.SchoolyearID;
                        }
                    }

                    ////Excel表重复性验证(注:当数据表中没有此记录,但是Excel中有重复数据时的去掉)
                    //for (int j = i + 1; j < enlist.Count; j++)
                    //{
                    //    NewGrademajorView enA = enlist[j];
                    //    //根据Excel表中的业务主键进行去重(年级专业编号或年级专业名称唯一)
                    //    if (en.No == enA.No && en.Name == enA.Name)
                    //    {
                    //        //用于标识Excel表中的重复记录(由于是批量进行插入数据表)

                    //    }
                    //}

                    //数据表重复性验证(年级专业编号或年级专业名称唯一)
                    var grademajorVerify = newGrademajorList.Where(x => x.Code == newGrademajor.Code || x.Name == newGrademajor.Name).FirstOrDefault();
                    if (grademajorVerify == null)
                    {
                        //新增
                        if (!newGrademajorInList.Any(x => x.Code == newGrademajor.Code || x.Name == newGrademajor.Name))
                        {
                            //CF_Grademajor表
                            newGrademajor.GrademajorID = Guid.NewGuid();
                            SetNewStatus(newGrademajor);
                            newGrademajorInList.Add(newGrademajor);
                            inCount++;
                        }
                        else
                        {
                            //Excel表重复性验证
                            //(注:当数据表中没有此记录,但是Excel中有重复数据,可在此处进行抛出到失败数据文件中,目前暂不考虑)

                            inCount++;
                        }
                    }
                    else
                    {
                        //更新(Excel有重复时,以最后一条记录的更新为准)
                        grademajorVerify.Abbreviation = newGrademajor.Abbreviation;
                        grademajorVerify.FacultymajorID = newGrademajor.FacultymajorID;
                        grademajorVerify.GradeID = newGrademajor.GradeID;
                        grademajorVerify.SemesterID = newGrademajor.SemesterID;
                        grademajorVerify.GraduateSchoolyearID = newGrademajor.GraduateSchoolyearID;
                        grademajorVerify.Professional = newGrademajor.Professional;
                        grademajorVerify.Remark = newGrademajor.Remark;
                        SetModifyStatus(grademajorVerify);
                        newGrademajorUpList.Add(grademajorVerify);
                        upCount++;
                    }
                }
                using (TransactionScope ts = new TransactionScope())
                {
                    UnitOfWork.BulkInsert(newGrademajorInList);
                    //批量统一提交更新
                    if (newGrademajorUpList != null && newGrademajorUpList.Count() > 0)
                    {
                        UnitOfWork.BatchUpdate(newGrademajorUpList);
                    }
                    ts.Complete();
                }
                errdataList = errList.Distinct().ToList(); //错误列表List
            }
            catch (Exception)
            {
                throw;
            }
        }

    }
}