public List <SlsBuyerOrderItemBadhon> GetBuyerOrderList(string _BuyerID)
        {
            using (_context)
            {
                var Data = (from o in _context.SLS_BuyerOrder.AsEnumerable()
                            where o.BuyerID.ToString() == _BuyerID
                            join i in _context.SLS_BuyerOrderItem on o.BuyerOrderID equals i.BuyerOrderID into Items
                            from i in Items.DefaultIfEmpty()

                            join ItemName in _context.Sys_ItemType on(i == null? null: i.ItemTypeID) equals ItemName.ItemTypeID into ItemNames
                            from ItemName in ItemNames.DefaultIfEmpty()

                            join ls in _context.Sys_LeatherStatus on(i == null ? null : i.LeatherStatusID) equals ls.LeatherStatusID into LeatherStatus
                            from ls in LeatherStatus.DefaultIfEmpty()

                            join a in _context.Sys_Article on(i == null ? 0 : i.ArticleID) equals a.ArticleID into Articles
                            from a in Articles.DefaultIfEmpty()

                            join au in _context.Sys_Unit on(i == null ? 0 : i.AvgSizeUnit) equals au.UnitID into AVGUnits
                            from au in AVGUnits.DefaultIfEmpty()

                            join tu in _context.Sys_Unit on(i == null ? 0 : i.ThicknessUnit) equals tu.UnitID into ThickUnits
                            from tu in ThickUnits.DefaultIfEmpty()
                            select new SlsBuyerOrderItemBadhon
                {
                    BuyerOrderID = o.BuyerOrderID,
                    BuyerOrderNo = o.BuyerOrderNo,
                    BuyerOrderDate = Convert.ToDateTime(o.BuyerOrderDate).ToString("dd'/'MM'/'yyyy"),
                    BuyerOrderItemID = (i == null ? 0 : i.BuyerOrderItemID),

                    ItemTypeID = (i == null ? 0 : i.ItemTypeID),
                    ItemTypeName = (ItemName == null? "": ItemName.ItemTypeName),

                    LeatherStatusID = (i == null ? 0 : i.LeatherStatusID),
                    LeatherStatusName = (ls == null ? "" : ls.LeatherStatusName),

                    ArticleID = (i == null ? 0 : i.ArticleID),
                    ArticleNo = (i == null ? null : i.ArticleNo),
                    ArticleChallanNo = (i == null ? null : i.ArticleChallanNo),
                    ArticleName = (a == null ? null : a.ArticleName),
                    AvgSize = (i == null ? null : i.AvgSize),
                    AvgSizeUnit = (i == null ? 0 : i.AvgSizeUnit),
                    AvgSizeUnitName = (au == null ? "" : au.UnitName),
                    SideDescription = (i == null ? null : i.SideDescription),
                    SelectionRange = (i == null ? null : i.SelectionRange),
                    Thickness = (i == null ? null : i.Thickness),
                    ThicknessUnit = (i == null ? 0 : i.ThicknessUnit),
                    ThicknessUnitName = (tu == null ? "" : tu.UnitName),
                    ThicknessAt = (i == null ? "" : (i.ThicknessAt == "AFSV" ? "After Shaving" : "After Finishing")),
                }).ToList();

                return(Data);
            }
        }
        public List <PrdYearMonthCrustScheduleItem> GetRequisitionItemList(string _RequistionDateID)
        {
            using (var context = new BLC_DEVEntities())
            {
                var ScheduleItem = (from i in context.PRD_YearMonthFinishReqItem.AsEnumerable()
                                    where i.RequisitionDateID.ToString() == _RequistionDateID
                                    //join d in YearMonthScheduleDate on i.ScheduleDateID equals d.ScheduleDateID into Items
                                    //from d in Items.DefaultIfEmpty()

                                    join b in context.Sys_Buyer on i.BuyerID equals b.BuyerID into Buyers
                                    from b in Buyers.DefaultIfEmpty()

                                    join o in context.SLS_BuyerOrder on i.BuyerOrderID equals o.BuyerOrderID into Orders
                                    from o in Orders.DefaultIfEmpty()

                                    join u in context.Sys_Unit on i.AvgSizeUnit equals u.UnitID into AVGUnits
                                    from u in AVGUnits.DefaultIfEmpty()

                                    join tu in context.Sys_Unit on i.ThicknessUnit equals tu.UnitID into ThickUnits
                                    from tu in ThickUnits.DefaultIfEmpty()

                                    join a in context.Sys_Article on i.ArticleID equals a.ArticleID into Articles
                                    from a in Articles.DefaultIfEmpty()

                                    join it in context.Sys_ItemType on i.ItemTypeID equals it.ItemTypeID into ItemTypes
                                    from it in ItemTypes.DefaultIfEmpty()

                                    join ls in context.Sys_LeatherStatus on i.LeatherStatusID equals ls.LeatherStatusID into LeatherStatus
                                    from ls in LeatherStatus.DefaultIfEmpty()

                                    select new PrdYearMonthCrustScheduleItem
                {
                    //ScheduleItemID = i.ScheduleItemID,
                    RequisitionItemID = i.RequisitionItemID,
                    ScheduleProductionNo = i.ScheduleProductionNo == "Press F9" ? null : i.ScheduleProductionNo,
                    BuyerID = i.BuyerID,
                    BuyerName = (b == null ? null : b.BuyerName),
                    BuyerOrderID = i.BuyerOrderID,
                    BuyerOrderNo = (o == null ? null : o.BuyerOrderNo),

                    ItemTypeID = i.ItemTypeID,
                    ItemTypeName = (it == null ? "" : it.ItemTypeName),

                    LeatherStatusID = i.LeatherStatusID,
                    LeatherStatusName = (ls == null ? "" : ls.LeatherStatusName),
                    ArticleID = i.ArticleID,
                    ArticleNo = i.ArticleNo,
                    ArticleName = (a == null ? null : a.ArticleName),

                    ArticleChallanID = i.ArticleChallanID,
                    ArticleChallanNo = i.ArticleChallanNo,

                    AvgSize = i.AvgSize,
                    AvgSizeUnit = i.AvgSizeUnit,
                    AvgSizeUnitName = (u == null ? "" : u.UnitName),
                    SideDescription = i.SideDescription,
                    SelectionRange = i.SelectionRange,
                    Thickness = i.Thickness,
                    ThicknessUnit = i.ThicknessUnit,
                    ThicknessUnitName = (tu == null ? "" : tu.UnitName),
                    ThicknessAt = i.ThicknessAt == "AFSV" ? "After Shaving" : "After Finishing",
                    Remarks = i.Remark
                }).ToList();

                return(ScheduleItem);
            }
        }
        public List <PrdYearMonthCrustScheduleItem> GetScheduleList(string _ScheduleYear, string _ScheduleMonth, string _ProductionFloor)
        {
            using (_context)
            {
                var YearMonthID = (from y in _context.PRD_YearMonth.AsEnumerable()
                                   where y.ScheduleYear == _ScheduleYear & y.ScheduleMonth == _ScheduleMonth & (y.ProductionFloor).ToString() == _ProductionFloor &
                                   y.ScheduleFor == "CRP"
                                   select y.YearMonID).FirstOrDefault();

                var YearMonthSchedule = (from s in _context.PRD_YearMonthSchedule.AsEnumerable()
                                         where s.YearMonID == YearMonthID
                                         select new
                {
                    ScheduleID = s.ScheduleID
                }).ToList();

                var YearMonthScheduleDate = (from s in YearMonthSchedule.AsEnumerable()
                                             join d in _context.PRD_YearMonthScheduleDate on s.ScheduleID equals d.ScheduleID into ScheduleDates
                                             from d in ScheduleDates.DefaultIfEmpty()
                                             select new
                {
                    ScheduleDateID = (d == null ? 0 : d.ScheduleDateID)
                }).ToList();

                var ScheduleItem = (from i in _context.PRD_YearMonthFinishScheduleItem.AsEnumerable()
                                    join d in YearMonthScheduleDate on i.ScheduleDateID equals d.ScheduleDateID into Items
                                    from d in Items.DefaultIfEmpty()

                                    join b in _context.Sys_Buyer on i.BuyerID equals b.BuyerID into Buyers
                                    from b in Buyers.DefaultIfEmpty()

                                    join o in _context.SLS_BuyerOrder on i.BuyerOrderID equals o.BuyerOrderID into Orders
                                    from o in Orders.DefaultIfEmpty()

                                    join u in _context.Sys_Unit on i.AvgSizeUnit equals u.UnitID into AVGUnits
                                    from u in AVGUnits.DefaultIfEmpty()

                                    join tu in _context.Sys_Unit on i.ThicknessUnit equals tu.UnitID into ThickUnits
                                    from tu in ThickUnits.DefaultIfEmpty()

                                    join a in _context.Sys_Article on i.ArticleID equals a.ArticleID into Articles
                                    from a in Articles.DefaultIfEmpty()

                                    join it in _context.Sys_ItemType on i.ItemTypeID equals it.ItemTypeID into ItemTypes
                                    from it in ItemTypes.DefaultIfEmpty()

                                    join ls in _context.Sys_LeatherStatus on i.LeatherStatusID equals ls.LeatherStatusID into LeatherStatus
                                    from ls in LeatherStatus.DefaultIfEmpty()

                                    select new PrdYearMonthCrustScheduleItem
                {
                    ScheduleItemID = i.ScheduleItemID,
                    ScheduleProductionNo = i.ScheduleProductionNo,
                    BuyerID = i.BuyerID,
                    BuyerName = (b == null ? null : b.BuyerName),
                    BuyerOrderID = i.BuyerOrderID,
                    BuyerOrderNo = (o == null ? null : o.BuyerOrderNo),

                    ItemTypeID = i.ItemTypeID,
                    ItemTypeName = (it == null ? null : it.ItemTypeName),

                    LeatherStatusID = i.LeatherStatusID,
                    LeatherStatusName = (ls == null ? null : ls.LeatherStatusName),
                    ArticleID = i.ArticleID,
                    ArticleNo = i.ArticleNo,
                    ArticleName = (a == null ? null : a.ArticleName),
                    ArticleChallanID = i.ArticleChallanID,
                    ArticleChallanNo = i.ArticleChallanNo,
                    AvgSize = i.AvgSize,
                    AvgSizeUnit = i.AvgSizeUnit,
                    AvgSizeUnitName = (u == null ? null : u.UnitName),
                    SideDescription = i.SideDescription,
                    SelectionRange = i.SelectionRange,
                    Thickness = i.Thickness,
                    ThicknessUnit = i.ThicknessUnit,
                    ThicknessUnitName = (tu == null ? null : tu.UnitName),
                    ThicknessAt = i.ThicknessAt == "AFSV" ? "After Shaving" : "After Finishing",
                    Remarks = i.Remarks
                }).ToList();

                return(ScheduleItem);
            }
        }