1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using EMIS.DataLogic.Common.Specialtyclass;
- using Bowin.Common.Linq.Entity;
- using EMIS.ViewModel.Specialtyclass;
- using EMIS.Entities;
- using EMIS.DataLogic.Common.CalendarManage;
- using EMIS.ViewModel.Students;
- using EMIS.ViewModel;
- using System.Linq.Expressions;
- using Bowin.Common.Linq;
- using EMIS.CommonLogic.Students;
- using EMIS.ViewModel.UniversityInformationManage.Specialtyclass;
- using Bowin.Common.Utility;
- using System.Text.RegularExpressions;
- using EMIS.ViewModel.Cache;
- namespace EMIS.CommonLogic.Specialtyclass
- {
- public class GrademajorServices : BaseServices, IGrademajorServices
- {
- public GrademajorDAL GrademajorDAL { get; set; }
- /// <summary>
- /// 查询年级专业对应的标准专业信息
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="campusID"></param>
- /// <param name="collegeID"></param>
- /// <param name="schoolyearID"></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<StandardView> GetGradeStandardViewGrid(ConfiguretView configuretView, int? schoolAreaID, Guid? collegeID,
- int? schoolyearID, 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 (schoolyearID.HasValue)
- {
- //年级
- expGrademajor = expGrademajor.And(x => x.SchoolyearID == schoolyearID);
- }
- //学生信息
- Expression<Func<CF_Student, bool>> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- var query = GrademajorDAL.GetGrademajorViwQueryable(expGrademajor, expStudent);
- if (schoolAreaID.HasValue)
- {
- //校区
- query = query.Where(x => x.SchoolAreaID == schoolAreaID);
- }
- 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)
- .GroupBy(x => new
- {
- x.StandardID
- }).Select(x => new StandardView { StandardID = x.Key.StandardID }).OrderBy(x => x.StandardID)
- .ToGridResultSet(pageIndex, pageSize);
-
- }
- /// <summary>
- /// 通过年级专业查询对应的标准专业
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="schoolAreaID"></param>
- /// <param name="collegeID"></param>
- /// <param name="schoolyearID"></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<ExamProjectControlView> GetSchoolyearStandardViewGrid(ConfiguretView configuretView, int? schoolAreaID, Guid? collegeID,
- int? schoolyearID, 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 (schoolyearID.HasValue)
- {
- //年级
- expGrademajor = expGrademajor.And(x => x.SchoolyearID == schoolyearID);
- }
- //学生信息
- Expression<Func<CF_Student, bool>> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- var query = GrademajorDAL.GetGrademajorViwQueryable(expGrademajor, expStudent);
- if (schoolAreaID.HasValue)
- {
- //校区
- query = query.Where(x => x.SchoolAreaID == schoolAreaID);
- }
- 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)
- .GroupBy(x => new
- {
- x.CollegeCode,
- x.CollegeID,
- x.SchoolyearID,
- x.StandardID,
- x.CollegeName
- }).Select(x => new ExamProjectControlView
- {
- CollegeCode = x.Key.CollegeCode,
- CollegeID = x.Key.CollegeID,
- SchoolyearID = x.Key.SchoolyearID,
- StandardID = x.Key.StandardID,
- CollegeName = x.Key.CollegeName
- }).OrderBy(x => x.CollegeCode.Length).ThenBy(x => x.CollegeCode)
- .ThenBy(x => x.StandardID)
- .ToGridResultSet<ExamProjectControlView>(pageIndex, pageSize);
- }
- /// <summary>
- /// 查询对应的年级专业信息GrademajorView
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="campusID"></param>
- /// <param name="collegeID"></param>
- /// <param name="schoolyearID"></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, int? schoolAreaID, Guid? collegeID,
- int? schoolyearID, 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 (schoolyearID.HasValue)
- {
- //年级
- expGrademajor = expGrademajor.And(x => x.SchoolyearID == schoolyearID);
- }
- //学生信息
- Expression<Func<CF_Student, bool>> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- var query = GrademajorDAL.GetGrademajorViwQueryable(expGrademajor, expStudent);
- if (schoolAreaID.HasValue)
- {
- //校区
- query = query.Where(x => x.SchoolAreaID == schoolAreaID);
- }
- 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="schoolyearID"></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, int? schoolAreaID,
- Guid? collegeID, int? schoolyearID, int? standardID, int? educationID, int? learningformID,
- string learnSystem, int? inSchoolStatus)
- {
- //年级专业信息
- Expression<Func<CF_Grademajor, bool>> expGrademajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (schoolyearID.HasValue)
- {
- //年级
- expGrademajor = expGrademajor.And(x => x.SchoolyearID == schoolyearID);
- }
- //学生信息
- Expression<Func<CF_Student, bool>> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- var query = GrademajorDAL.GetGrademajorViwQueryable(expGrademajor, expStudent);
- if (schoolAreaID.HasValue)
- {
- //校区
- query = query.Where(x => x.SchoolAreaID == schoolAreaID);
- }
- 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="schoolyearID"></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> GetGrademajorViewGridWithoutRange(ConfiguretView configuretView, int? schoolAreaID,
- Guid? collegeID, int? schoolyearID, 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 (schoolyearID.HasValue)
- {
- //年级
- expGrademajor = expGrademajor.And(x => x.SchoolyearID == schoolyearID);
- }
- var query = GrademajorDAL.GetGrademajorViwQueryable(expGrademajor);
- if (schoolAreaID.HasValue)
- {
- //校区
- query = query.Where(x => x.SchoolAreaID == schoolAreaID);
- }
- 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>
- /// 查询对应的年级专业信息List(带数据范围)
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="collegeID"></param>
- /// <param name="schoolyearID"></param>
- /// <returns></returns>
- public IList<GrademajorView> GetGrademajorViewList(ConfiguretView configuretView, Guid? collegeID, int? schoolyearID)
- {
- //年级专业信息
- Expression<Func<CF_Grademajor, bool>> expGrademajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (schoolyearID.HasValue)
- {
- //年级
- expGrademajor = expGrademajor.And(x => x.SchoolyearID == schoolyearID);
- }
- 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 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>
- /// 查询年级专业中的专业信息StandardView(无数据范围)
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="collegeID"></param>
- /// <param name="schoolyearID"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <returns></returns>
- public IGridResultSet<StandardView> GetStandardViewGrid(ConfiguretView configuretView, int? schoolAreaID, Guid? collegeID,
- int? schoolyearID, int pageIndex, int pageSize)
- {
- //年级专业信息
- Expression<Func<CF_Grademajor, bool>> expGrademajor = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (schoolAreaID.HasValue)
- {
- //院系所
- expGrademajor = expGrademajor.And(x => x.SchoolAreaID == schoolAreaID);
- }
- if (collegeID.HasValue)
- {
- //院系所
- expGrademajor = expGrademajor.And(x => x.CF_Facultymajor.CollegeID == collegeID);
- }
- if (schoolyearID.HasValue)
- {
- //年级
- expGrademajor = expGrademajor.And(x => x.SchoolyearID == schoolyearID);
- }
- var query = GrademajorDAL.GetStandardForComboGridQueryable(expGrademajor);
- //查询条件
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- {
- query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
- }
- return query.OrderBy(x => x.StandardID)
- .ToGridResultSet<StandardView>(pageIndex, pageSize);
- }
- /// <summary>
- /// 查询年级专业中的专业信息List(无数据范围)
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="collegeID"></param>
- /// <param name="schoolyearID"></param>
- /// <returns></returns>
- public IList<StandardView> GetStandardViewList(ConfiguretView configuretView, Guid? collegeID, int? schoolyearID)
- {
- //年级专业信息
- 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 (schoolyearID.HasValue)
- {
- //年级
- expGrademajor = expGrademajor.And(x => x.SchoolyearID == schoolyearID);
- }
- var query = GrademajorDAL.GetStandardForComboGridQueryable(expGrademajor);
- //查询条件
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- {
- query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
- }
- return query.OrderBy(x => x.StandardID)
- .ToList();
- }
- /// <summary>
- /// 查询年级专业中的专业信息List(无数据范围)
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="collegeID"></param>
- /// <param name="schoolyearID"></param>
- /// <returns></returns>
- public IList<GrademajorView> GetStandardQueryableExcludeNotHaveStudentList(ConfiguretView configuretView, Guid? collegeID, int? schoolyearID)
- {
- //年级专业信息
- 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 (schoolyearID.HasValue)
- {
- //年级
- expGrademajor = expGrademajor.And(x => x.SchoolyearID == schoolyearID);
- }
- //学生信息
- Expression<Func<CF_Student, bool>> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- var query = GrademajorDAL.GetStandardQueryableExcludeNotHaveStudent(expGrademajor, expStudent);
- //查询条件
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- {
- query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
- }
- return query.OrderBy(x => x.StandardID)
- .ToList();
- }
- /// <summary>
- /// 查询年级专业中的年级信息SchoolyearView(无数据范围)
- /// </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<SchoolyearView> GetSchoolyearViewGrid(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)
- {
- //专业ID(Value)
- expGrademajor = expGrademajor.And(x => x.CF_Facultymajor.StandardID == standardID);
- }
- var query = GrademajorDAL.GetSchoolyearForComboGridQueryable(expGrademajor);
- //查询条件
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- {
- query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
- }
- return query.OrderBy(x => x.SchoolyearID)
- .ToGridResultSet<SchoolyearView>(pageIndex, pageSize);
- }
- /// <summary>
- /// 查询年级专业中的年级信息List(无数据范围)
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="collegeID"></param>
- /// <param name="standardID"></param>
- /// <returns></returns>
- public IList<SchoolyearView> GetSchoolyearViewGrid(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)
- {
- //专业ID(Value)
- expGrademajor = expGrademajor.And(x => x.CF_Facultymajor.StandardID == standardID);
- }
- var query = GrademajorDAL.GetSchoolyearForComboGridQueryable(expGrademajor);
- //查询条件
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- {
- query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
- }
- return query.OrderBy(x => x.SchoolyearID)
- .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);
- return query.SingleOrDefault();
- }
- 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);
- return query.SingleOrDefault();
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
- /// <summary>
- /// 编辑(新增、修改,业务主键:年级专业编号或年级专业名称唯一)
- /// </summary>
- /// <param name="grademajorView"></param>
- public void GrademajorEdit(GrademajorView grademajorView)
- {
- try
- {
- //查询数据库进行验证
- var grademajorVerification = GrademajorDAL.GrademajorRepository
- .GetList(x => x.GrademajorID != grademajorView.GrademajorID
- && (x.Code == grademajorView.Code
- || x.Name == grademajorView.Name))
- .FirstOrDefault();
- if (grademajorVerification == null)
- {
- //计算相应的毕业学年学期Value 岭南不需要预计毕业学年学期
- //var facultymajor = GrademajorDAL.FacultymajorRepository
- // .GetSingle(x => x.FacultymajorID == grademajorView.FacultymajorID);
- //var graduateSchoolyearValue = (grademajorView.SchoolyearID.Value * 2) - 1
- // + (grademajorView.SchoolcodeID.Value - 1);
- //graduateSchoolyearValue += Convert.ToInt32(Math.Ceiling(facultymajor.LearnSystem.Value * 2 - 1));
- //var graduatingSemester = GrademajorDAL.SchoolyearRepository
- // .GetSingle(x => x.Value == graduateSchoolyearValue);
- //if (graduatingSemester == 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.SchoolyearID = grademajorView.SchoolyearID;
- grademajor.SchoolcodeID = grademajorView.SchoolcodeID;
- //grademajor.GraduatingSemesterID = graduatingSemester.SchoolyearID;
- grademajor.Professional = grademajorView.Professional;
- grademajor.SchoolAreaID = grademajorView.SchoolAreaID;
- 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.SchoolyearID = grademajorView.SchoolyearID;
- grademajor.SchoolcodeID = grademajorView.SchoolcodeID;
- //grademajor.GraduatingSemesterID = graduatingSemester.SchoolyearID;
- grademajor.Professional = grademajorView.Professional;
- grademajor.SchoolAreaID = grademajorView.SchoolAreaID;
- 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.SchoolyearID == grademajorView.SchoolyearID);
- 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.SchoolyearID == grademajorView.BatchSchoolyearID);
- 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.BatchSchoolyearID.Value * 2) - 1 + (g.SchoolcodeID.Value - 1);
- graduateSchoolyearValue += Convert.ToInt32(Math.Ceiling(facultymajor.LearnSystem.Value * 2 - 1));
- var graduatingSemester = SchoolYearList.Where(x => x.Value == graduateSchoolyearValue).FirstOrDefault();
- CF_Grademajor grademajor = new CF_Grademajor();
- if (graduatingSemester == null)
- {
- throw new Exception("预计毕业学年学期超出了系统学年学期数据的范围,请添加足够的学年学期记录以支撑该操作。");
- }
- string Schoolyear = g.SchoolyearID.ToString();
- string BatchSchoolyear = grademajorView.BatchSchoolyearID.Value.ToString();
- //替换复制的年级专业代码
- string Code = g.Code.Trim().Replace(Schoolyear, BatchSchoolyear);
- //替换复制的年级专业名称
- string Name = g.Name.Trim().Replace(Schoolyear, BatchSchoolyear);
- //替换复制的年级专业简称
- string Abbreviation = g.Abbreviation;
- if (g.Abbreviation != null)
- {
- Abbreviation = g.Abbreviation.Trim().Replace(Schoolyear, BatchSchoolyear);
- }
- grademajor.GrademajorID = Guid.NewGuid();
- grademajor.Code = Code;
- grademajor.Name = Name;
- grademajor.Abbreviation = Abbreviation;
- grademajor.SchoolyearID = grademajorView.BatchSchoolyearID;
- grademajor.Professional = g.Professional;
- grademajor.SchoolcodeID = g.SchoolcodeID;
- grademajor.FacultymajorID = g.FacultymajorID;
- grademajor.GraduatingSemesterID = graduatingSemester.SchoolyearID;
- grademajor.SchoolAreaID = g.SchoolAreaID;
- grademajor.Remark = g.Remark;
- SetNewStatus(grademajor);
- if (!grademajorView.IsOverwrite)
- {
- var batch = BatchGrademajorList.Where(x => x.Code == Code && x.SchoolyearID == grademajorView.BatchSchoolyearID && 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
- {
- if (grademajorIDList.Count > 0)
- {
- 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);
- 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);
- 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<BaseStudentView> GetBaseStudentViewGrid(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);
- var query = GrademajorDAL.GetBaseStudentViewQueryable(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.ClassmajorCode.Length).ThenBy(x => x.ClassmajorCode)
- .ToGridResultSet<BaseStudentView>(pageIndex, pageSize);
- }
- /// <summary>
- /// 查询年级专业对应的学生信息List
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="grademajorID"></param>
- /// <param name="inSchoolStatus"></param>
- /// <returns></returns>
- public IList<BaseStudentView> GetBaseStudentViewList(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);
- var query = GrademajorDAL.GetBaseStudentViewQueryable(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.ClassmajorCode.Length).ThenBy(x => x.ClassmajorCode)
- .ToList();
- }
- /// <summary>
- /// 批量修改(重写)
- /// 暂时不考虑对应的班级信息下的学生拟毕业日期的更新,后续再处理
- /// 目前通过修改对应的班级信息来更新
- /// </summary>
- /// <param name="grademajorIDs"></param>
- /// <param name="schoolyearID"></param>
- /// <param name="schoolcodeID"></param>
- /// <returns></returns>
- public string BatchModify(string grademajorIDs, int? schoolyearID, int? schoolcodeID)
- {
- 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 (schoolyearID != null)
- {
- sCount++;
- grademajor.SchoolyearID = schoolyearID;
- var graduateSchoolyearValue = (schoolyearID * 2) - 1 + ((int)grademajor.SchoolcodeID - 1);
- graduateSchoolyearValue += Convert.ToInt32(Math.Ceiling((double)grademajorView.LearnSystem * 2 - 1));
- var graduatingSemester = GrademajorDAL.SchoolyearRepository.GetSingle(x => x.Value == graduateSchoolyearValue);
- if (graduatingSemester == null)
- {
- lCount++;
- hs.Add("预计毕业学年学期超出了系统学年学期数据的范围,请添加足够的学年学期记录以支撑该操作。");
- continue;
- }
- else
- {
- grademajor.GraduatingSemesterID = graduatingSemester.SchoolyearID;
- }
- }
- if (schoolcodeID != null)
- {
- sCount++;
- grademajor.SchoolcodeID = schoolcodeID;
- var graduateSchoolyearValue = (grademajor.SchoolyearID * 2) - 1 + ((int)schoolcodeID - 1);
- graduateSchoolyearValue += Convert.ToInt32(Math.Ceiling((double)grademajorView.LearnSystem * 2 - 1));
- var graduatingSemester = GrademajorDAL.SchoolyearRepository.GetSingle(x => x.Value == graduateSchoolyearValue);
- if (graduatingSemester == null)
- {
- lCount++;
- hs.Add("预计毕业学年学期超出了系统学年学期数据的范围,请添加足够的学年学期记录以支撑该操作。");
- continue;
- }
- else
- {
- grademajor.GraduatingSemesterID = graduatingSemester.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>();
- // 1.1解析文件,存放到一个List集合里
- cellheader.Remove("ErrorMessage");//移除“未导入原因”列(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 schoolyearList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Schoolyear).ToList();
- //校区
- var schoolAreaList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_SchoolArea).ToList();
- //学期
- var schoolcodeList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Schoolcode).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.SchoolyearStr))
- {
- errCount++;
- errorMsgStr = "年级不能为空";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- var schoolyear = schoolyearList.Where(x => x.Name == en.SchoolyearStr.Trim()).SingleOrDefault();
- if (schoolyear == null)
- {
- errCount++;
- errorMsgStr = "年级不存在,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //年级
- newGrademajor.SchoolyearID = schoolyear.Value;
- }
- }
- //入学学期
- if (string.IsNullOrEmpty(en.SchoolcodeStr))
- {
- errCount++;
- errorMsgStr = "入学学期不能为空";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- var schoolcode = schoolcodeList.Where(x => x.Name == en.SchoolcodeStr.Trim()).SingleOrDefault();
- if (schoolcode == null)
- {
- errCount++;
- errorMsgStr = "入学学期不存在,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //入学学期
- newGrademajor.SchoolcodeID = schoolcode.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.SchoolyearID.Value * 2) - 1
- + (newGrademajor.SchoolcodeID.Value - 1);
- graduateSchoolyearValue += Convert.ToInt32(Math.Ceiling(en.LearnSystem.Value * 2 - 1));
- var graduatingSemester = GrademajorDAL.SchoolyearRepository
- .GetSingle(x => x.Value == graduateSchoolyearValue);
- if (graduatingSemester == null)
- {
- errCount++;
- errorMsgStr = "预计毕业学年学期超出了系统学年学期数据的范围,请添加足够的学年学期记录以支撑该操作,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- newGrademajor.GraduatingSemesterID = graduatingSemester.SchoolyearID;
- }
- }
- //校区
- if (string.IsNullOrEmpty(en.SchoolAreaStr))
- {
- errCount++;
- errorMsgStr = "校区不能为空";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- var schoolyear = schoolAreaList.Where(x => x.Name == en.SchoolAreaStr.Trim()).SingleOrDefault();
- if (schoolyear == null)
- {
- errCount++;
- errorMsgStr = "校区不存在,请检查";
- en.ErrorMessage = errorMsgStr;
- errList.Add(en);
- errorMsg.AppendLine(errorMsgStr);
- continue;
- }
- else
- {
- //年级
- newGrademajor.SchoolAreaID = schoolyear.Value;
- }
- }
- ////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 grademajorVerification = newGrademajorList
- .Where(x => x.Code == newGrademajor.Code || x.Name == newGrademajor.Name)
- .FirstOrDefault();
- if (grademajorVerification == 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有重复时,以最后一条记录的更新为准)
- grademajorVerification.Abbreviation = newGrademajor.Abbreviation;
- grademajorVerification.FacultymajorID = newGrademajor.FacultymajorID;
- grademajorVerification.SchoolyearID = newGrademajor.SchoolyearID;
- grademajorVerification.SchoolcodeID = newGrademajor.SchoolcodeID;
- grademajorVerification.GraduatingSemesterID = newGrademajor.GraduatingSemesterID;
- grademajorVerification.Professional = newGrademajor.Professional;
- grademajorVerification.SchoolAreaID = newGrademajor.SchoolAreaID;
- grademajorVerification.Remark = newGrademajor.Remark;
- SetModifyStatus(grademajorVerification);
- newGrademajorUpList.Add(grademajorVerification);
- upCount++;
- }
- }
- UnitOfWork.BulkInsert(newGrademajorInList); //批量插入
- //批量统一提交更新
- if (newGrademajorUpList != null && newGrademajorUpList.Count() > 0)
- {
- UnitOfWork.BatchUpdate(newGrademajorUpList);
- }
- errdataList = errList.Distinct().ToList(); //错误列表List
- }
- catch (Exception ex)
- {
- //目前会出现,由于错误信息字符太长,无法抛出弹出框的问题
- throw new Exception(ex.Message);
- }
- }
- }
- }
|