public TrimScheduleInfo GetTrimScheduleHistoryDetail(int locationId, int scheduleNum)
        {
            PartSequencingDataContext dbSeq = new PartSequencingDataContext();
            ItemDetailsFactory itemDetailsModel = new ItemDetailsFactory();
            SequencingFactory factory = new SequencingFactory();
            var seqMessageProcessor = new SeqMessageProcessor();

            var seqStation = dbSeq.SequencingStationSettings.Where(i => i.SequencingLocationId == locationId).FirstOrDefault();
            var tokens = MessageTokensCacheManager.MessageTokens.Where(s => s.LineId == seqStation.LineId || s.LineId == 4).ToList();
            var station = factory.UpdateNextBoxBySequencingId(seqStation.Id);

            TrimScheduleInfo trimHistorySchedule = null;

            if (station != null)
            {
                SequencingTrackingItem lastItem = null;
                var tracking = factory.GetSequencingHistory(station);

                if (tracking.Any())
                {
                    lastItem = tracking.OrderByDescending(i => i.OrderId).First();
                    if (lastItem != null)
                    {
                        var historyjobs = (from t in dbSeq.IWS_GetSequencingDetailHistoryBySeqSettingsIdAndScheduleNum(station.Id, scheduleNum)
                                          select new Seat
                                          {
                                            ScheduleNum = t.ScheduleNum,
                                            BoxNum = t.BoxNum,
                                            Complete = false,
                                            TrimStyle = GetOptionValue(t.ItemNumber.Trim(), 100),
                                            Colour = GetOptionValue(t.ItemNumber.Trim(), 101),
                                            ItemNumber = t.ItemNumber.Trim(),
                                            ItemType = t.ItemType.Trim(),
                                            DescLine1 = t.ItemNumber.Trim(),
                                            DescLine2 = seqMessageProcessor.GetSequencingMessage(station, t.ItemNumber.Trim(), tokens),
                                            OrderId = t.OrderId,
                                            Item = itemDetailsModel.GetItemInfoByLineId(t.ItemNumber.Trim(), station.Line.Id)
                                          }).ToList();

                        var firstItem = historyjobs.FirstOrDefault();

                        trimHistorySchedule = new TrimScheduleInfo
                        {
                            Complete = true,
                            ScheduleStatus = new TrimScheduleStatus
                            {
                                CurrentBoxNumber = firstItem == null ? 0 : firstItem.BoxNum,
                                CurrentScheduleNumber = firstItem == null ? 0 : firstItem.ScheduleNum
                            },
                            SeatSchedule = historyjobs,
                            SummaryList = GetSummaryHeaderItems(historyjobs, station.Line.Id),
                        };
                        return trimHistorySchedule;
                    }

                }

            }
            return trimHistorySchedule;
        }
        public PlasticSeqSchedule GetPlasticScheduleHistoryDetail(SequencingStation station, int scheduleNum)
        {
            PartSequencingDataContext dbSeq = new PartSequencingDataContext();
            SequencingScheduleFactory factory = new SequencingScheduleFactory();
            PlasticSeqSchedule plasticHistorySchedule = new PlasticSeqSchedule();

            var tokens = MessageTokensCacheManager.MessageTokens.Where(t => t.LineId == station.Line.Id || t.LineId == 4).ToList();

            var boxHistory = (from h in dbSeq.IWS_GetSequencingDetailHistoryBySeqSettingsIdAndScheduleNum(station.Id, scheduleNum)
                           group h by new
                           {
                               h.ScheduleNum,
                               h.BoxNum
                           } into grp
                           select new ScheduleBox
                           {
                               BoxNum = grp.Key.BoxNum,
                               Items = (from s in grp.ToList()
                                        select new ScheduleItem
                                        {
                                            Message = factory.GetSequencingMessage(station, s.ItemNumber.Trim(), tokens),
                                            Position = (int)s.Position
                                        }).ToList(),
                           }).ToList();

            plasticHistorySchedule = new PlasticSeqSchedule
            {
                SequencingStation = station,
                Boxes = boxHistory,
                Status = true,
            };

            return plasticHistorySchedule;
        }