123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371 |
- 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
- {
- /// <summary>
- /// 入库
- /// </summary>
- 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 入库编辑
- /// <summary>
- /// 编辑入库信息
- /// </summary>
- /// <param name="publisherView"></param>
- /// <param name="createUserID"></param>
- 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<StockInView> GetStockInGridView(Expression<Func<ET_StockIn, bool>> 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 获取入库对应的需要的教材信息
- /// <summary>
- /// 获取入库对应的需要的教材信息
- /// </summary>
- /// <param name="exp"></param>
- /// <returns></returns>
- public IQueryable<TeachingMaterialPoolView> GetTeachersOrderByTeachingMaterial(Expression<Func<CF_TeachingMaterialPool, bool>> exp,
- Expression<Func<ET_TeachersOrder, bool>> teacherOrderExp,
- Expression<Func<ET_StudentsOrder, bool>> 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 获取入库编辑信息
- /// <summary>
- /// 获取入库信息
- /// </summary>
- /// <returns></returns>
- 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<TeachingMaterialPoolView> 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 获取入库对应的需要的教材信息(新增)
- /// <summary>
- /// 获取入库对应的需要的教材信息(新增)
- /// </summary>
- /// <param name="exp"></param>
- /// <returns></returns>
- public IQueryable<TeachingMaterialPoolView> GetTeachingMaterial(Expression<Func<CF_TeachingMaterialPool, bool>> 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<StockInDetailView> GetDetailByIDList(List<Guid> 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;
- }
- }
- }
|