using System; using System.Collections.Generic; using System.Linq; using System.Text; using EMIS.CommonLogic.SystemServices; using EMIS.Entities; using System.Configuration; using EMIS.ViewModel; using Bowin.Common.Linq.Entity; using EMIS.ViewModel.SystemView; using EMIS.DataLogic.Common.TeachingMaterial; using EMIS.ViewModel.TeachingMaterial; using EMIS.CommonLogic; using EMIS.DataLogic.Repositories; using Bowin.Common.Linq; using System.Linq.Expressions; namespace EMIS.CommonLogic.TeachingMaterial { public class TeachersConfirmOrderServices : BaseServices, ITeachersConfirmOrderServices { #region 0.0 --定义-- public TeachersOrderRepository TeachersOrderRepository { get; set; } public TeachersConfirmOrderRepository TeachersConfirmOrderRepository { get; set; } public TeachingMaterialPoolRepository TeachingMaterialPoolRepository { get; set; } public TeachersPreOrderRepository TeachersPreOrderRepository { get; set; } public UserRepository UserRepository { get; set; } public CoursematerialRepository CoursematerialRepository { get; set; } public PublishRepository PublishRepository { get; set; } public SchoolyearRepository SchoolyearRepository { get; set; } public CollegeRepository CollegeRepository { get; set; } public DictionaryItemRepository DictionaryItemRepository { get; set; } public TeachersConfirmOrderDAL TeachersConfirmOrderDAL { get; set; } public Lazy TeachersOrderServices { get; set; } #endregion #region 1.0 查询教师征订清单信息 /// /// 查询教师征订清单记录绑定页面 /// /// /// /// /// /// /// /// /// /// /// public IGridResultSet GetTeachersOrderViewGrid(ViewModel.ConfiguretView configuretView, Guid? schoolyearID, Guid? teachingMaterialPoolID, Guid? coursematerialID, Guid? publishID, int? ApprovalStatus, int pageIndex, int pageSize) { ApprovalStatus = TeachersOrderServices.Value.GetCorrectEndStatus();//提取已通过 Expression> exp = (x => x.ApprovalStatus == ApprovalStatus); if (schoolyearID.HasValue) exp = exp.And(x => x.SchoolyearID == schoolyearID); if (teachingMaterialPoolID.HasValue) exp = exp.And(x => x.TeachingMaterialPoolID == teachingMaterialPoolID); if (coursematerialID.HasValue) exp = exp.And(x => x.CF_TeachingMaterialPool.EM_Coursematerial.Any(w => w.CoursematerialID == coursematerialID)); if (publishID.HasValue) exp = exp.And(x => x.CF_TeachingMaterialPool.PublishID == publishID); var query = TeachersConfirmOrderDAL.GetTeachersConfirmOrderGridView(exp); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.TeachingMaterialCode.Length).ThenBy(x => x.TeachingMaterialCode).ThenBy(x => x.SchoolyearName).ToGridResultSet(pageIndex, pageSize); return query.OrderBy(x => x.TeachingMaterialCode.Length).ThenBy(x => x.TeachingMaterialCode).ThenBy(x => x.SchoolyearName).ToGridResultSet(pageIndex, pageSize); } #endregion #region 2.0 查询教师征订清单明细信息 /// /// 查询教师征订清单征订明细页面 /// /// /// /// /// /// /// /// /// /// /// public IGridResultSet GetTeachersOrderDetailViewGrid(Guid? schoolyearID, Guid? collegeID, Guid? teachingMaterialPoolID, int pageIndex, int pageSize) { var endStatus = TeachersOrderServices.Value.GetCorrectEndStatus(); var query = TeachersConfirmOrderDAL.GetTeachingOrderDetail(x => x.ApprovalStatus == endStatus); if (schoolyearID.HasValue) query = query.Where(x => x.SchoolyearID == schoolyearID); //if (collegeID.HasValue) // query = query.Where(x => x.CollegeID == collegeID); if (teachingMaterialPoolID.HasValue) query = query.Where(x => x.TeachingMaterialPoolID == teachingMaterialPoolID); return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.PublishTime).ToGridResultSet(pageIndex, pageSize); } #endregion #region 3.0 查询教师征订清单Excel导出 /// /// 获取征订清单列表导出 /// /// /// public IList GetTeachersConfirmOrderViewExcel(ConfiguretView configuretView, Guid? schoolyearID, Guid? teachingMaterialPoolID, Guid? coursematerialID, Guid? publishID) { int? ApprovalStatus = TeachersOrderServices.Value.GetCorrectEndStatus();//提取已通过 Expression> exp = (x => x.ApprovalStatus == ApprovalStatus); if (schoolyearID.HasValue) exp = exp.And(x => x.SchoolyearID == schoolyearID); if (teachingMaterialPoolID.HasValue) exp = exp.And(x => x.TeachingMaterialPoolID == teachingMaterialPoolID); if (coursematerialID.HasValue) exp = exp.And(x => x.CF_TeachingMaterialPool.EM_Coursematerial.Any(w => w.CoursematerialID == coursematerialID)); if (publishID.HasValue) exp = exp.And(x => x.CF_TeachingMaterialPool.PublishID == publishID); var query = TeachersConfirmOrderDAL.GetTeachersConfirmOrderGridView(exp); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.TeachingMaterialCode.Length).ThenBy(x => x.TeachingMaterialCode).ThenBy(x => x.SchoolyearName).ToList(); return query.OrderBy(x => x.TeachingMaterialCode.Length).ThenBy(x => x.TeachingMaterialCode).ThenBy(x => x.SchoolyearName).ToList(); } #endregion #region 4.0 批量更新预加值 /// /// 批量更新预加值 /// /// /// public void BatchUpdatePreAddedValue(List teachersOrderList, int preAddedValue, Guid userId) { try { if (teachersOrderList.Count > 0) { //int? ApprovalStatus = (int)CF_TeachersOrderStatus.Completed;//提取已通过 foreach (var teachersOrder in teachersOrderList) { var teachersPreOrderEnt = TeachersPreOrderRepository.Entities.Where(x => x.TeachingMaterialPoolID == teachersOrder.TeachingMaterialPoolID && x.SchoolyearID == teachersOrder.SchoolyearID).FirstOrDefault();//&& x.ApprovalStatus == ApprovalStatus 所有教材征订附加表的信息ApprovalStatus的值为空 if (teachersPreOrderEnt == null)//如果该记录存在、就更新数据 { ET_TeachersPreOrder teachersPreOrder = new ET_TeachersPreOrder(); teachersPreOrder.TeachersPreOrderID = Guid.NewGuid(); teachersPreOrder.TeachingMaterialPoolID = teachersOrder.TeachingMaterialPoolID; teachersPreOrder.SchoolyearID = (Guid)teachersOrder.SchoolyearID; teachersPreOrder.CreateTime = DateTime.Now; teachersPreOrder.CreateUserID = userId; teachersPreOrder.ModifyTime = DateTime.Now; teachersPreOrder.ModifyUserID = userId; teachersPreOrder.Desc = "预加值"; teachersPreOrder.PreQty = preAddedValue;//设置预加值; TeachersPreOrderRepository.UnitOfWork.Add(teachersPreOrder); } else { ET_TeachersPreOrder teachersPreOrder = teachersPreOrderEnt; teachersPreOrder.ModifyTime = DateTime.Now; teachersPreOrder.ModifyUserID = userId; teachersPreOrder.Desc = "预加值"; teachersPreOrder.PreQty = preAddedValue;//设置预加值; TeachersPreOrderRepository.UnitOfWork.Update(teachersPreOrder); } } UnitOfWork.Commit(); } } catch (Exception ex) { throw ex; } } #endregion #region 5.0 导出Excel明细信息 /// /// 导出清单明细数据 /// /// /// /// public IList GetTeachersConfirmOrderViewDetailExcel(Guid? schoolyearID, Guid? teachingMaterialPoolID) { int? ApprovalStatus = TeachersOrderServices.Value.GetCorrectEndStatus();//提取已通过 var query = TeachersConfirmOrderDAL.GetTeachingOrderDetail(x => x.ApprovalStatus == ApprovalStatus); if (schoolyearID.HasValue) query = query.Where(x => x.SchoolyearID == schoolyearID); if (teachingMaterialPoolID.HasValue) query = query.Where(x => x.TeachingMaterialPoolID == teachingMaterialPoolID); return query.OrderBy(x => x.PublishTime).ToList(); } #endregion } }