using System; using System.Collections.Generic; using System.Linq; using System.Text; using EMIS.DataLogic.Repositories; using EMIS.ViewModel.TeachingMaterial; using EMIS.Entities; using System.Linq.Expressions; using EMIS.ViewModel; using System.Data; using EMIS.ViewModel.Cultureplan; using EMIS.DataLogic.Common.Cultureplan; namespace EMIS.DataLogic.Common.TeachingMaterial { public class TeachingMaterialPoolDAL { public TeachingMaterialPoolRepository TeachingMaterialPoolRepository { get; set; } public UserRepository UserRepository { get; set; } public CoursematerialRepository CoursematerialRepository { get; set; } public DictionaryItemRepository DictionaryItemRepository { get; set; } public PublishRepository PublishRepository { get; set; } public OptionalCoursePlanRepository OptionalCoursePlanRepository { get; set; } public StudentRepository StudentRepository { get; set; } public SpecialtyPlanRepository SpecialtyPlanRepository { get; set; } public GrademajorRepository GrademajorRepository { get; set; } public SpecialtyCourseRepository SpecialtyCourseRepository { get; set; } public Lazy CoursematerialDAL { get; set; } /// /// 获取教材总库信息列表 /// /// /// public IQueryable GetTeachingMaterialPoolGridView(Expression> exp) { var view = (from l in TeachingMaterialPoolRepository.Entities.Where(exp) //join d in DictionaryItemRepository.Entities //on new { l.TeachingMaterialTypeID, DictionaryCode = DictionaryItem.CF_TeachingMaterialType.ToString() } equals new { TeachingMaterialTypeID = d.Value, d.DictionaryCode } //into tdic //from tbdic in tdic.DefaultIfEmpty() join u in UserRepository.Entities on l.CreateUserID equals u.UserID join p in PublishRepository.Entities on l.PublishID equals p.PublishID into up from gup in up.DefaultIfEmpty() select new TeachingMaterialPoolView { Author = l.Author, ISBN = l.ISBN, CoursematerialEntityList = l.EM_Coursematerial, Price = l.Price, TeachingMaterialCode = l.TeachingMaterialCode, TeachingMaterialName = l.TeachingMaterialName, TeachingMaterialShorName = l.TeachingMaterialShorName, TeachingMaterialPoolID = l.TeachingMaterialPoolID, TeachingMaterialTypeID = l.TeachingMaterialTypeID, //TeachingMaterialTypeName = tbdic.Name, PublishID = l.PublishID, PublishName = gup.UnitName, PublishTime = l.PublishTime, CreateTime = l.CreateTime, CreateUserName = u.Name, Desc = l.Desc, IsLate = l.IsLate.Value, ModifyTime = l.ModifyTime, IsLateName = l.IsLate == true ? "是" : "否", OrderQty = 1 }); return view; } /// /// 获取教材总库 /// /// public TeachingMaterialPoolView GetSingleTeachingMaterialPool(Guid teachingMaterialPoolID) { var teachingMaterialPool = TeachingMaterialPoolRepository.GetSingle(x => x.TeachingMaterialPoolID == teachingMaterialPoolID, (x => x.EM_Coursematerial), (x => x.CF_Publish)); var teachingMaterialPoolView = new TeachingMaterialPoolView() { Author = teachingMaterialPool.Author, IsLate = teachingMaterialPool.IsLate.GetValueOrDefault(), ISBN = teachingMaterialPool.ISBN, Price = teachingMaterialPool.Price, PublishID = teachingMaterialPool.PublishID, TeachingMaterialPoolID = teachingMaterialPool.TeachingMaterialPoolID, PublishTime = teachingMaterialPool.PublishTime, TeachingMaterialCode = teachingMaterialPool.TeachingMaterialCode, Desc = teachingMaterialPool.Desc, CoursematerialEntityList = teachingMaterialPool.EM_Coursematerial, WnningLevel = teachingMaterialPool.WnningLevel == null ? -1 : teachingMaterialPool.WnningLevel, TeachingMaterialTypeID = teachingMaterialPool.TeachingMaterialTypeID, TeachingMaterialShorName = teachingMaterialPool.TeachingMaterialShorName, TeachingMaterialName = teachingMaterialPool.TeachingMaterialName, MinInventory = teachingMaterialPool.MinInventory }; return teachingMaterialPoolView; } /// /// 获取教材总库信息列表(用于学生征订) /// /// /// public IQueryable GetTeachingMaterialPoolForOrder(Expression> exp, Guid? coursematerialID) { var view = (from l in TeachingMaterialPoolRepository.Entities.Where(exp) join p in PublishRepository.Entities on l.PublishID equals p.PublishID into lp from slp in lp.DefaultIfEmpty() select new TeachingMaterialPoolForOrderView { Author = l.Author, ISBN = l.ISBN, CoursematerialEntityList = l.EM_Coursematerial, Price = l.Price, TeachingMaterialCode = l.TeachingMaterialCode, TeachingMaterialName = l.TeachingMaterialName, TeachingMaterialPoolID = l.TeachingMaterialPoolID, PublishID = l.PublishID, PublishName = slp.UnitName, PublishTime = l.PublishTime, OrderID = l.EM_Coursematerial.Any(x => x.CoursematerialID == coursematerialID) ? 0 : 1 }); return view; } public IQueryable GetStudentTeachingMaterialView(Expression> studentExp) { var user = StudentRepository.GetSingle(studentExp, (x => x.CF_Classmajor.CF_Grademajor)); var q = (from sc in (from gm in GrademajorRepository.GetList(x => x.GrademajorID == user.CF_Classmajor.CF_Grademajor.GrademajorID) join sp in SpecialtyPlanRepository.GetList(x => x.IsNeedMaterial == true) on gm.GrademajorID equals sp.GrademajorID select new { Schoolyear = sp.CF_Schoolyear, SpecialtyPlan = sp }) //.Union( //from gm in GrademajorRepository.GetList(x => x.GrademajorID == user.CF_Classmajor.CF_Grademajor.GrademajorID) //join op in OptionalCoursePlanRepository.GetList(x => x.IsNeedMaterial == true) on gm.GrademajorID equals op.GrademajorID //join sc in SpecialtyCourseRepository.Entities on op.SpecialtyCourseID equals sc.SpecialtyCourseID //select new { Schoolyear = op.CF_Schoolyear, SpecialtyCourse = sc }) from tmp in sc.SpecialtyPlan.EM_Coursematerial.CF_TeachingMaterialPool select new StudentTeachingMaterialView { SchoolYearID = sc.Schoolyear.SchoolyearID, SchoolYearCode = sc.Schoolyear.Code, SchoolYearValue = sc.Schoolyear.Value, CoursematerialID = sc.SpecialtyPlan.EM_Coursematerial.CoursematerialID, CourseName = sc.SpecialtyPlan.EM_Coursematerial.CourseName, TeachingMaterialPoolID = tmp.TeachingMaterialPoolID, TeachingMaterialName = tmp.TeachingMaterialName, PublishTime = tmp.PublishTime, ISBN = tmp.ISBN, PublishID = tmp.PublishID, PublishName = tmp.CF_Publish.UnitName, Price = tmp.Price } ); return q; } /// /// 判断是否已经录入 /// /// /// private void AddErrorAndExceptExistingDataRow(DataTable dataSource, DataTable errorSource) { //foreach (DataRow dr in dataSource.Rows) //{ // string loginID = dr["学号"].ToString(); // var user = listUser.Where(x => x.LoginID == loginID).FirstOrDefault(); // if (user == null) // { // AddError(errorSource, dr, "该学号不存在当前录入班级,请检查!"); // } //} } public IQueryable GetTeachingMaterialPoolCoursematerialView(Expression> exp) { var query = (from tmp in TeachingMaterialPoolRepository.GetList(exp) from cm in tmp.EM_Coursematerial join cmv in CoursematerialDAL.Value.GetCoursematerialViewQueryable(x => true) on cm.CoursematerialID equals cmv.CoursematerialID select cmv); return query; } } }