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; using EMIS.DataLogic.Common.ProcurementPlan; namespace EMIS.DataLogic.Common.TeachingMaterial { /// /// 入库 /// public class StockInDAL { #region --0.0 定义-- public TeachersOrderRepository TeachersOrderRepository { get; set; } public StockInRepository StockInRepository { get; set; } public StockInDetailRepository StockInDetailRepository { get; set; } public SchoolyearRepository SchoolyearRepository { get; set; } public UserRepository UserRepository { get; set; } public TeachingMaterialPoolRepository TeachingMaterialPoolRepository { get; set; } public CoursematerialRepository CoursematerialRepository { get; set; } public PublishRepository PublishRepository { get; set; } public CollegeRepository CollegeRepository { get; set; } public DictionaryItemRepository DictionaryItemRepository { get; set; } public TeachingMateriaInventoryRepository TeachingMateriaInventoryRepository { get; set; } public SupplierDiscountSetRepository SupplierDiscountSetRepository { get; set; } public PurchasingStatisticsDAL PurchasingStatisticsDAL { get; set; } #endregion #region 2.0 入库编辑 /// /// 编辑入库信息 /// /// /// public void Update(StockInView stockInView) { try { ET_StockIn stockIn = StockInRepository.GetSingle(x => x.StockInID == stockInView.StockInID); stockIn.StockInDocumentNo = stockInView.StockInDocumentNo; stockIn.SchoolyearID = stockInView.SchoolyearID; stockIn.SupplierID = (Guid)stockInView.SupplierID; //stockIn.StockInDJTime = (DateTime)stockInView.StockInDJTime; //stockIn.Discount = (double)stockInView.Discount; stockIn.Desc = stockInView.Desc; StockInRepository.UnitOfWork.Update(stockIn); StockInRepository.UnitOfWork.Commit(); } catch (Exception ex) { throw ex; } } #endregion #region 4.0 信息列表 public IQueryable GetStockInGridView(Expression> exporder) { var viewList = (from a in StockInRepository.GetList(exporder) join c in UserRepository.Entities on a.HandlerUserID equals c.UserID into cdata from cta in cdata.DefaultIfEmpty() join d in PublishRepository.Entities on a.SupplierID equals d.PublishID into ddata from dta in ddata.DefaultIfEmpty() from e in a.ET_StockInDetail group new { a, cta, e, dta } by new { a.StockInID, a.CF_Schoolyear.SchoolyearID, a.SupplierID, a.CreateUserID, a.StockInTime, a.Desc, a.CF_Schoolyear.Code, cta.Name, dta.UnitName, a.StockInDocumentNo, a.RecordStatus } into h select new StockInView { StockInID = h.Key.StockInID, SchoolyearName = h.Key.Code, StockInDocumentNo = h.Key.StockInDocumentNo, SupplierName = h.Key.UnitName, HandlerUserName = h.Key.Name, StockInDJTime = h.Key.StockInTime, StockInSumMoney = h.Sum(x => x.a.StockInSumMoney) == null ? Math.Round((decimal)(h.Sum(x => (x.e.DiscountPrice) * x.e.Quantity) == null ? 0 : h.Sum(x => (x.e.DiscountPrice) * x.e.Quantity)), 2) : h.Sum(x => x.a.StockInSumMoney), SupplierID = h.Key.SupplierID, SchoolyearID = (Guid)h.Key.SchoolyearID, RecordStatus = h.Key.RecordStatus, RecordStatusName = h.Key.RecordStatus == 1 ? "是" : "否", isLate = h.Key.RecordStatus == 1 ? true : false, Desc = h.Key.Desc, Discount = 1, DiscountPrice = 1, TotalDollar = 1, TotalPrice = 1 }); return viewList; } #endregion #region 5.0 验证入库单据号是否存在 public bool IsExistStockInDocumentNo(string stockInDocumentNo) { bool IsExist = false; var Endt = StockInRepository.GetSingle(x => x.StockInDocumentNo == stockInDocumentNo); if (Endt != null) { IsExist = true; } return IsExist; } #endregion #region 6.0 获取入库对应的需要的教材信息 /// /// 获取入库对应的需要的教材信息 /// /// /// public IQueryable GetTeachersOrderByTeachingMaterial(Expression> exp, Expression> teacherOrderExp, Expression> studentOrderExp) { var view = (from l in TeachingMaterialPoolRepository.Entities.Where(exp) //教材新增不考虑是否有征订信息 join ps in PurchasingStatisticsDAL.GetPurchasingStatisticsGridView(teacherOrderExp, studentOrderExp) on l.TeachingMaterialPoolID equals ps.TeachingMaterialPoolID //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 join p in PublishRepository.Entities on l.PublishID equals p.PublishID group new { TeachingMaterial = l, //TeachingMaterialType = ctd } by new { Author = l.Author, ISBN = l.ISBN, 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 = p.UnitName, PublishTime = l.PublishTime, CreateTime = l.CreateTime, CreateUserName = u.Name, Desc = l.Desc, DiscountPrice = l.Price, IsLate = l.IsLate.Value, ModifyTime = l.ModifyTime, IsLateName = l.IsLate == true ? "是" : "否", ZongJia = l.Price, MaYang = l.Price } into g join tmp in TeachingMaterialPoolRepository.Entities on g.Key.TeachingMaterialPoolID equals tmp.TeachingMaterialPoolID select new TeachingMaterialPoolView { Author = g.Key.Author, ISBN = g.Key.ISBN, CoursematerialEntityList = tmp.EM_Coursematerial, Price = g.Key.Price, TeachingMaterialCode = g.Key.TeachingMaterialCode, TeachingMaterialName = g.Key.TeachingMaterialName, TeachingMaterialShorName = g.Key.TeachingMaterialShorName, TeachingMaterialPoolID = g.Key.TeachingMaterialPoolID, TeachingMaterialTypeID = g.Key.TeachingMaterialTypeID, //TeachingMaterialTypeName = g.Key.TeachingMaterialTypeName, PublishID = g.Key.PublishID, PublishName = g.Key.PublishName, PublishTime = g.Key.PublishTime, CreateTime = g.Key.CreateTime, CreateUserName = g.Key.CreateUserName, Desc = g.Key.Desc, DiscountPrice = g.Key.Price, IsLate = g.Key.IsLate, ModifyTime = g.Key.ModifyTime, IsLateName = g.Key.IsLateName, OrderQty = 1, Discount = 1, ZongJia = g.Key.Price, MaYang = g.Key.Price }); return view; } #endregion #region 7.0 获取入库编辑信息 /// /// 获取入库信息 /// /// public StockInView GetSingleStockIn(Guid stockInID) { //var stockInDetail = StockInDetailRepository.GetList(x => x.StockInID == stockInID).ToList(); //var query = from c in stockInDetail // group c by new // { // c.StockInID // } // into s // select new // { // Qty = s.Sum(x => x.Quantity) // }; //int qty = query.Select(x => x.Qty).FirstOrDefault().Value; var view = (from a in StockInRepository.Entities.Where(x => x.StockInID == stockInID) join b in SchoolyearRepository.Entities on a.SchoolyearID equals b.SchoolyearID join c in UserRepository.Entities on a.HandlerUserID equals c.UserID into handlerUser from HandlerUserTab in handlerUser.DefaultIfEmpty() join d in PublishRepository.Entities on a.SupplierID equals d.PublishID into publish from pu in publish.DefaultIfEmpty() select new StockInView { StockInID = a.StockInID, SchoolyearName = b.Code, SchoolyearID = a.SchoolyearID, StockInDocumentNo = a.StockInDocumentNo, OrdersNo = a.OrdersNo, StockInType = a.StockInType, SupplierName = pu.UnitName, SupplierID = a.SupplierID, StockInNumber = a.StockInNumber, RecordStatus = a.RecordStatus, StockInDJTime = a.StockInTime, Desc = a.Desc }).FirstOrDefault(); return view; } #endregion #region 8.0 获取总价格 public decimal? GetSumMoney(decimal? Price, double? Discount, int? Quantity) { decimal Total = decimal.Multiply((decimal)Price, (decimal)Discount); decimal Money = decimal.Multiply(Total, (decimal)Quantity); return Money; } #endregion #region 9.0 根据ID、加载入库信息 public IList GetTeachingMaterialView(Guid stockInID) { var view = (from a in StockInRepository.Entities.Where(x => x.StockInID == stockInID) join sr in StockInDetailRepository.Entities on a.StockInID equals sr.StockInID join l in TeachingMaterialPoolRepository.Entities on sr.TeachingMaterialPoolID equals l.TeachingMaterialPoolID //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 join p in PublishRepository.Entities on l.PublishID equals p.PublishID 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 = p.UnitName, PublishTime = l.PublishTime, CreateTime = l.CreateTime, CreateUserName = u.Name, DiscountPrice = sr.DiscountPrice == null ? 0 : sr.DiscountPrice, Desc = l.Desc, IsLate = l.IsLate.Value, ModifyTime = l.ModifyTime, IsLateName = l.IsLate == true ? "是" : "否", OrderQty = sr.Quantity == null ? 1 : sr.Quantity, Discount = sr.Discount == null ? 1 : sr.Discount, ZongJia = Math.Round((decimal)(sr.Quantity * sr.DiscountPrice), 2) == null ? 0 : Math.Round((decimal)(sr.Quantity * sr.DiscountPrice), 2), MaYang = Math.Round((decimal)(sr.Quantity * l.Price), 2) == null ? 0 : Math.Round((decimal)(sr.Quantity * l.Price), 2) }).ToList(); return view; } #endregion #region 10.0 获取入库对应的需要的教材信息(新增) /// /// 获取入库对应的需要的教材信息(新增) /// /// /// public IQueryable GetTeachingMaterial(Expression> exp, decimal? discount) { var view = from a in TeachingMaterialPoolRepository.GetList(exp) join p in PublishRepository.Entities on a.PublishID equals p.PublishID into pp from ppp in pp.DefaultIfEmpty() join u in UserRepository.Entities on a.CreateUserID equals u.UserID select new TeachingMaterialPoolView { Author = a.Author, ISBN = a.ISBN, CoursematerialEntityList = a.EM_Coursematerial, Price = a.Price, TeachingMaterialCode = a.TeachingMaterialCode, TeachingMaterialName = a.TeachingMaterialName, TeachingMaterialShorName = a.TeachingMaterialShorName, TeachingMaterialPoolID = a.TeachingMaterialPoolID, TeachingMaterialTypeID = a.TeachingMaterialTypeID, //TeachingMaterialTypeName = a.TeachingMaterialTypeName, PublishID = a.PublishID, PublishName = ppp.UnitName, PublishTime = a.PublishTime, CreateTime = a.CreateTime, CreateUserName = u.Name, Desc = a.Desc, DiscountPrice = a.Price, IsLate = a.IsLate.Value, ModifyTime = a.ModifyTime, IsLateName = a.IsLate == true ? "是" : "否", OrderQty = 1, Discount = discount, ZongJia = a.Price, MaYang = a.Price }; return view; } #endregion public IQueryable GetDetailByIDList(List idList) { var query = from stock in StockInRepository.GetList(x => idList.Contains(x.StockInID)) join detail in StockInDetailRepository.Entities on stock.StockInID equals detail.StockInID select new StockInDetailView { StockInDetailID = detail.StockInDetailID, StockInID = detail.StockInID, TeachingMaterialPoolID = detail.TeachingMaterialPoolID, Discount = detail.Discount, DiscountPrice = detail.DiscountPrice, LibraryID = detail.LibraryID, Quantity = detail.Quantity }; return query; } } }