using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EMIS.DataLogic.Repositories;
using EMIS.ViewModel.TeachingMaterial;
using System.Linq.Expressions;
using EMIS.Entities;
using EMIS.ViewModel;
namespace EMIS.DataLogic.Common.TeachingMaterial
{
public class TeachersOrderDAL
{
public TeachersOrderRepository TeachersOrderRepository { get; set; }
public TeachersPreOrderRepository TeachersPreOrderRepository { get; set; }
public TeachingMaterialPoolRepository TeachingMaterialPoolRepository { get; set; }
public TeachersConfirmOrderRepository TeachersConfirmOrderRepository { 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 IQueryable GetTeachingOrderGridView(Expression> exporder)
{
var view = (from to in TeachersOrderRepository.Entities.Where(exporder)
join tm in TeachingMaterialPoolRepository.Entities on to.TeachingMaterialPoolID equals tm.TeachingMaterialPoolID
join u in UserRepository.Entities on to.OrderUserID equals u.UserID
join p in PublishRepository.Entities on tm.PublishID equals (Guid)p.PublishID
join sl in SchoolyearRepository.Entities on to.SchoolyearID equals sl.SchoolyearID
join cr in CollegeRepository.Entities on to.CollegeID equals cr.CollegeID
select new TeachersOrderView
{
SchoolyearID = sl.SchoolyearID,
SchoolyearName = sl.Code,
TeachingMaterialCode = tm.TeachingMaterialCode,
Author = tm.Author,
CollegeID = cr.CollegeID,
CollegeName = cr.Name,
TeachingMaterialName = tm.TeachingMaterialName,
TeachingMaterialTypeID = tm.TeachingMaterialTypeID,
PublishTime = tm.PublishTime,
TeachersOrderID = to.TeachersOrderID,
TeachingMaterialPoolID = tm.TeachingMaterialPoolID,
PublishName = p.UnitName,
OrderLoginID = u.LoginID,
OrderUserName = u.Name,
OrderDate = to.OrderDate,
OrderQty = to.OrderQty,
OrderDesc = to.OrderDesc,
ApproveStatus = (int)to.ApprovalStatus,
CoursematerialEntityList = tm.EM_Coursematerial,
PublishID = p.PublishID,
CreateTime = to.CreateTime,
CreateUserID = to.CreateUserID,
ISBN = tm.ISBN,
Price = tm.Price
});
return view;
}
///
/// 获取教材及征订信息列表
///
///
///
public IQueryable GetTeachingOrderByTeachingMaterialPoolGridView(Guid? teachersOrderID, Expression> teachingMaterialPoolExp)
{
var view = (from to in TeachersOrderRepository.Entities.Where(x => x.TeachersOrderID == teachersOrderID)
join tm in TeachingMaterialPoolRepository.GetList(teachingMaterialPoolExp) on to.TeachingMaterialPoolID equals tm.TeachingMaterialPoolID
join u in UserRepository.Entities on to.OrderUserID equals u.UserID
join p in PublishRepository.Entities on tm.PublishID equals (Guid)p.PublishID
join sl in SchoolyearRepository.Entities on to.SchoolyearID equals sl.SchoolyearID
join cr in CollegeRepository.Entities on to.CollegeID equals cr.CollegeID
//join ct in DictionaryItemRepository.Entities on c.CourseScienceID equals ct.Value
//join cl in DictionaryItemRepository.Entities on c.CourseLevelID equals cl.Value
//join s in DictionaryItemRepository.Entities on to.ApprovalStatus equals s.Value
select new TeachingMaterialPoolView
{
TeachingMaterialPoolID = tm.TeachingMaterialPoolID,
TeachingMaterialCode = tm.TeachingMaterialCode,
TeachingMaterialName = tm.TeachingMaterialName,
TeachingMaterialShorName = tm.TeachingMaterialShorName,
CoursematerialEntityList = tm.EM_Coursematerial,
ISBN = tm.ISBN,
PublishTime = tm.PublishTime,
PublishName = p.UnitName,
Author = tm.Author,
Price = tm.Price,
OrderQty = to.OrderQty,
});
return view;
}
///
/// 获取教师征订视图
///
///
public TeachersOrderView GetSingleTeachersOrderView(Guid teachersOrderID)
{
var teachersOrder = TeachersOrderRepository.GetSingle(x => x.TeachersOrderID == teachersOrderID,
(x => x.CF_College), (x => x.CF_Schoolyear), (x => x.CF_TeachingMaterialPool),(x=>x.CF_TeachingMaterialPool.EM_Coursematerial));
var teachersOrderView = new TeachersOrderView()
{
TeachingMaterialCode = teachersOrder.CF_TeachingMaterialPool.TeachingMaterialCode,
CoursematerialEntityList = teachersOrder.CF_TeachingMaterialPool.EM_Coursematerial,
TeachingMaterialName = teachersOrder.CF_TeachingMaterialPool.TeachingMaterialName,
PublishTime = teachersOrder.CF_TeachingMaterialPool.PublishTime,
PublishID = teachersOrder.CF_TeachingMaterialPool.PublishID,
Author = teachersOrder.CF_TeachingMaterialPool.Author,
ISBN = teachersOrder.CF_TeachingMaterialPool.ISBN,
Price = teachersOrder.CF_TeachingMaterialPool.Price,
OrderQty = teachersOrder.OrderQty,
OrderDesc = teachersOrder.OrderDesc,
SchoolyearID = teachersOrder.SchoolyearID,
CollegeID = teachersOrder.CollegeID,
CollegeName = teachersOrder.CF_College.Name,
SchoolyearName=teachersOrder.CF_Schoolyear.Code,
ApproveStatus=(int)teachersOrder.ApprovalStatus
};
return teachersOrderView;
}
///
/// 获取单个基本信息
///
///
public TeachersOrderView GetSingleTeachersOrderOneView(Guid teachersOrderID)
{
var teachersOrder = TeachersOrderRepository.GetSingle(x => x.TeachersOrderID == teachersOrderID,
(x => x.CF_College), (x => x.CF_Schoolyear), (x => x.CF_TeachingMaterialPool));
var teachersOrderView = new TeachersOrderView()
{
TeachingMaterialCode = teachersOrder.CF_TeachingMaterialPool.TeachingMaterialCode,
CoursematerialEntityList = teachersOrder.CF_TeachingMaterialPool.EM_Coursematerial,
TeachingMaterialName = teachersOrder.CF_TeachingMaterialPool.TeachingMaterialName,
PublishTime = teachersOrder.CF_TeachingMaterialPool.PublishTime,
PublishID = teachersOrder.CF_TeachingMaterialPool.PublishID,
Author = teachersOrder.CF_TeachingMaterialPool.Author,
ISBN = teachersOrder.CF_TeachingMaterialPool.ISBN,
Price = teachersOrder.CF_TeachingMaterialPool.Price,
OrderQty = teachersOrder.OrderQty
};
return teachersOrderView;
}
///
/// 获取单个教师征订记录
///
///
///
public ET_TeachersOrder GetSingleTeachersOrder(Guid teachersOrderID)
{
return TeachersOrderRepository.GetSingle(x => x.TeachersOrderID == teachersOrderID);
}
///
/// 获取单个教师征订View
///
///
///
public TeachersOrderView GetSingleTeachersOrderById(Guid teachersOrderID)
{
var teachersOrder = TeachersOrderRepository.GetSingle(x => x.TeachersOrderID == teachersOrderID);
var teachersOrderView = new TeachersOrderView()
{
OrderQty = teachersOrder.OrderQty,
TeachersOrderID = teachersOrder.TeachersOrderID,
CollegeID = teachersOrder.CollegeID,
CreateTime = teachersOrder.CreateTime,
CreateUserID = teachersOrder.CreateUserID,
OrderDate = teachersOrder.OrderDate,
OrderDesc = teachersOrder.OrderDesc,
OrderUserID = teachersOrder.OrderUserID,
TeachingMaterialPoolID = teachersOrder.TeachingMaterialPoolID,
SchoolyearID = teachersOrder.SchoolyearID
};
return teachersOrderView;
}
#region 复制征订数据到征订清单表(废弃)
/////
///// 复制征订数据到征订清单表
/////
/////
//public void CopyTeachersOrderInTeachersConfirmOrder(Guid teachersOrderID)
//{
// try
// {
// if (teachersOrderID != null && teachersOrderID != Guid.Empty)
// {
// ET_TeachersOrder teachersOrder = TeachersOrderRepository.GetSingle(x => x.TeachersOrderID == teachersOrderID && x.ApprovalStatus == (int)CF_TeachersOrderStatus.Completed);
// if (teachersOrder != null)
// {
// ET_TeachersConfirmOrder teachersConfirmOrder = new ET_TeachersConfirmOrder
// {
// PreAddedValue = 5,//设置预加值、
// TeachersOrderID = teachersOrder.TeachersOrderID,
// CollegeID = teachersOrder.CollegeID,
// CreateTime = DateTime.Now,
// CreateUserID = teachersOrder.CreateUserID,
// Desc = teachersOrder.Desc,
// ModifyTime = DateTime.Now,
// ModifyUserID = teachersOrder.ModifyUserID,
// OrderDate = teachersOrder.OrderDate,
// OrderDesc = teachersOrder.OrderDesc,
// OrderQty = teachersOrder.OrderQty,
// OrderUserID = teachersOrder.OrderUserID,
// SchoolyearID = teachersOrder.SchoolyearID,
// TeachingMaterialPoolID = teachersOrder.TeachingMaterialPoolID
// };
// TeachersConfirmOrderRepository.UnitOfWork.Add(teachersConfirmOrder);
// TeachersConfirmOrderRepository.UnitOfWork.Commit();
// }
// }
// }
// catch (Exception ex)
// {
// throw ex;
// }
//}
#endregion
///
/// 获取教材总库信息列表、排除在教师征订表已存在的教材
///
///
///
public IQueryable GetTeachersOrderByTeachingMaterial(Expression> exp)
{
//教材所有信息以教材总库表为准 其他都左联 --- 兵良提出
var view = (from l in TeachingMaterialPoolRepository.Entities.Where(exp)
//关联字典导致数据重复
//join d in DictionaryItemRepository.Entities on l.TeachingMaterialTypeID equals d.Value
// into td
//from ctd in td.DefaultIfEmpty()
join u in UserRepository.Entities on l.CreateUserID equals u.UserID
into user
from uu in user.DefaultIfEmpty()
join p in PublishRepository.Entities on l.PublishID equals p.PublishID
into pp
from ppp in pp.DefaultIfEmpty()
// join g in TeachersOrderRepository.Entities on l.TeachingMaterialPoolID equals g.TeachingMaterialPoolID
// into teachingMaterialPool
// from gteachingMaterialPool in teachingMaterialPool.DefaultIfEmpty()
// where gteachingMaterialPool.TeachingMaterialPoolID ==null //在征订表不存在记录
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 = ctd.Name,
PublishID = l.PublishID,
PublishName = ppp.UnitName,
PublishTime = l.PublishTime,
CreateTime = l.CreateTime,
CreateUserName = uu.Name,
Desc = l.Desc,
IsLate = l.IsLate.Value,
ModifyTime = l.ModifyTime,
IsLateName = l.IsLate == true ? "是" : "否",
OrderQty = 1
});
return view;
}
public IQueryable GetPreOrderByTeachersOrderIDList(List teacherOrderIDList)
{
var query = (from tpo in TeachersPreOrderRepository.Entities
join to in TeachersOrderRepository.GetList(x => teacherOrderIDList.Contains(x.TeachersOrderID))
on new { tpo.SchoolyearID, tpo.TeachingMaterialPoolID }
equals new { to.SchoolyearID, to.TeachingMaterialPoolID }
select tpo);
return query;
}
}
}