예제 #1
0
        public SequencingStation GetSequencingStationSettingsById(int id)
        {
            PartSequencingDataContext dbSeq = new PartSequencingDataContext();
            HP_MESDataContext dbMes = new HP_MESDataContext();

            var result = (from s in SequencingSettingsCacheManager.SequencingStationSettings where s.Id == id select s).Single();

            var baseStation = SequencingSettingsCacheManager.BaseSequencingStationOffsets.Where(x => x.LineId == result.LineId).Single();

            
           var setting = new SequencingStation
            {
                Description = result.Description,
                Id = result.Id,
                SequencingLocation = dbSeq.SequencingLocations.Where(x => x.Id == result.SequencingLocationId).Single(),
                Line = dbSeq.Lines.Where(x => x.Id == result.LineId).Single(),
                Station = GetStation((int)result.StationId),
                StationOrder = (int)result.StationOrder,
                BoxPerSchedule = (int)result.BoxPerSchedule,
                BoxQty = (int)result.BoxQty,
                MessageFormat = result.MessageFormat,
                Obsolete = (bool)result.Obsolete,
                PartsPerBox = (int)result.PartsPerBox,
                SeatOptions = (int)result.SeatOptions,
                SeatOptions2Check = (int)result.SeatOptions2Check,
                Status = false,
                Offset = (int)result.Offset,
                BaseStation = SequencingSettingsCacheManager.SequencingStationSettings.Where(x => x.Id == baseStation.SequencingStationSettingsId).Single()
            };

            return setting;
        }
예제 #2
0
        public Employee GetEmployeeInfo(int employeeId)
        {
            HP_MESDataContext db = new HP_MESDataContext();

            return (from e in db.Employees
                    where e.EmployeeId == employeeId.ToString()
                    select e).Single();
        }
예제 #3
0
        public IEnumerable<TempBuffer> GetSequencingBuffer(SequencingStation station)
        {
            PartSequencingDataContext dbSeq = new PartSequencingDataContext();
            HP_MESDataContext dbMes = new HP_MESDataContext();
            SequencingDatabase db = new SequencingDatabase();

            List<TempBuffer> lineBuffer = null;

            string groupLine = station.SequencingLocation.LineGroup.Trim();
            int lineId = station.Line.Id;
            int locationId = station.SequencingLocation.Id;
            if (station.SequencingLocation.ParentId == null)
            {
                lineBuffer = (from s in dbSeq.SEQ_SP_GetSequencingBufferBySeqId(station.Id)
                              select new TempBuffer
                              {
                                  Group = groupLine,
                                  //ItemNumber = "1800VR",
                                  ItemNumber = s.ItemNumber.Trim(),
                                  ItemType = s.ItemType.Trim(),
                                  JobId = (int)s.JobId,
                                  OrderId = (int)s.OrderId,
                                  OrderStatus = (int)s.OrderStatus,
                                  Region = s.Region.Trim(),
                                  LineId = (int)s.LineId,
                                  OrderNumber = s.OrderNumber,
                                  BuildDTM = s.BuildDTM == null ? "" : s.BuildDTM.Value.ToString("mm/dd/yyyy hh:mm:ss tt")
                              }).ToList();
            }
            else
            {

                lineBuffer = (from s in dbSeq.IWS_GetSequencingStationQueueByLocationId(locationId)
                              select new TempBuffer
                              {
                                  ScheduleNum = (int)s.ScheduleNum,
                                  BoxNum = (int)s.BoxNum,
                                  OrderNumber = s.OrderNumber == null ? "" : s.OrderNumber.Trim(),
                                  Group = groupLine,
                                  //ItemNumber = "1420CF",
                                  ItemNumber = s.ItemNumber.Trim(),
                                  ItemType = s.ItemType.Trim(),
                                  JobId = (int)s.JobId,
                                  OrderId = (int)s.OrderId,
                                  OrderStatus = (int)s.OrderStatus,
                                  Region = s.Region.Trim(),
                                  LineId = lineId
                              }).ToList();

            }

            return lineBuffer;
        }
예제 #4
0
        public List<ItemNumberDescription> GetItemNumberDescriptions()
        {
            HP_MESDataContext db = new HP_MESDataContext();
            var descriptions = (from i in db.ItemMasterTables.Where(i => i.Item_Type.Trim() == "SKU-F" || i.Item_Type.Trim() == "SKU-R")
                                select new ItemNumberDescription {
                                    Description = i.Description.Trim(),
                                    ItemNumber = i.Item_Nbr.Trim(),
                                    ItemType = i.Item_Type.Trim()
                                }).ToList();

            return descriptions;
        }
예제 #5
0
        public bool IsScheduleReadyBySequencingStationId(int id)
        {
            PartSequencingDataContext dbSeq = new PartSequencingDataContext();
            SequencingFactory maker = new SequencingFactory();
            HP_MESDataContext dbMes = new HP_MESDataContext();

            var seqStations = dbSeq.SequencingStationSettings.Where(i => i.SequencingLocationId == id).ToList();
            if (seqStations.Count() > 0)
            {
                var seqStation = seqStations.FirstOrDefault();
                if (seqStation != null)
                {
                    var station = maker.UpdateNextBoxBySequencingId(seqStation.Id);
                    if (!station.Status)
                    {
                        if (station.ItemsWaiting != 0)
                            return false;
                    }
                    
                    var scheduleStatus = dbSeq.SequencingStationLookups.Where(s => s.SequenceStationSettingsId == station.Id).FirstOrDefault();
                    var tokens = MessageTokensCacheManager.MessageTokens.Where(s => s.LineId == station.Line.Id || s.LineId == 4).ToList();

                    var lineBuffer = maker.GetSequencingBuffer(station);

                    SequencingTrackingItem lastItem = null;
                    var tracking = maker.GetSequencingHistory(station);

                    if (tracking.Any())
                        lastItem = tracking.OrderByDescending(i => i.OrderId).First();

                    var lastJobId = Int32.MinValue;

                    if (lastItem != null)
                        lastJobId = lastItem.OrderId;

                    if (lineBuffer != null)
                    {
                        var itemsinbox = station.PartsPerBox;
                        var boxperschedule = station.BoxPerSchedule;
                        var itemsinschedule = itemsinbox * boxperschedule;

                        var jobs = lineBuffer.Where(i => i.OrderId >= station.NextBox.OrderId).Take(itemsinschedule).ToList();
                        if (itemsinschedule == jobs.Count())
                            return true;
                    }
                }
            }

            return false;
        }
예제 #6
0
 public List<ItemMaster> GetItemMasters()
 {
     HP_MESDataContext db = new HP_MESDataContext();
     var items = (from s in db.IWS_SP_GetAllSkuInfo()
                  select new ItemMaster
                  {
                      Active = (bool)s.Active,
                      ItemDescription = s.Description,
                      ItemComponent = s.PartNumber,
                      ItemNumber = s.Sku,
                      ItemType = s.ItemType,
                      LineId = s.LineId,
                      OptionNumber = s.OptionNumber,
                      OptionValue = s.OptionValue,
                      PartIndex = s.PartIndex,
                      ShortDescription = s.OptionShortDescription,
                      Description = s.OptionDescription,
                      Buildcode = (int)s.Buildcode
                  }).ToList();
     return items;
 }
예제 #7
0
        public TrimSchedule GetTrimSchedule(int id)
        {
            PartSequencingDataContext dbSeq = new PartSequencingDataContext();
            SequencingFactory factory = new SequencingFactory();
            HP_MESDataContext dbMes = new HP_MESDataContext();
            ItemDetailsFactory itemDetailsModel = new ItemDetailsFactory();
            TrimSchedule trimSchedule = null;
            List<Seat> offsetSeats = null;
            List<Seat> currentjobs = null;
            var seqMessageProcessor = new SeqMessageProcessor();

            var seqStations = dbSeq.SequencingStationSettings.Where(i => i.SequencingLocationId == id).ToList();
            if (seqStations.Count() > 0)
            {
                var seqStation = seqStations.FirstOrDefault();
                if (seqStation != null)
                {
                    var station = factory.UpdateNextBoxBySequencingId(seqStation.Id);
                    var scheduleStatus = dbSeq.SequencingStationLookups.Where(s => s.SequenceStationSettingsId == station.Id).FirstOrDefault();
                    var tokens = MessageTokensCacheManager.MessageTokens.Where(s => s.LineId == station.Line.Id || s.LineId == 4).ToList();

                    var lineBuffer = factory.GetSequencingBuffer(station);

                    if (lineBuffer != null)
                    {
                        var itemsinbox = station.PartsPerBox;
                        var boxperschedule = station.BoxPerSchedule;
                        var itemsinschedule = itemsinbox * boxperschedule;
                        var boxqty = station.BoxQty;

                        trimSchedule = new TrimSchedule();

                        var tracking = factory.GetSequencingHistory(station);
                        if (tracking.Any()) 
                        {
                            var lastTrackItem = tracking.LastOrDefault();
                            if (lastTrackItem != null)
                            {
                                if (lastTrackItem.Type == 2)
                                {
                                    var lastRealJob = tracking.Where(o => o.OrderId < lastTrackItem.OrderId).OrderByDescending(f => f.OrderId).Where(x => x.ScheduleNum > 0).FirstOrDefault();

                                    if (lastRealJob != null)
                                    {
                                        var unassignedBuffer = tracking.Where(o => o.OrderId <= lastTrackItem.OrderId && o.OrderId >lastRealJob.OrderId).OrderBy(f => f.OrderId).ToList();
                                        if (unassignedBuffer.Count() > 0)
                                        {
                                            var offsetjobs = (from j in unassignedBuffer
                                                              select new Seat
                                                              {
                                                                  OrderStatus = (int)j.OrderStatus,
                                                                  Complete = false,
                                                                  TrimStyle = GetOptionValue(j.ItemNumber.Trim(), 100),
                                                                  Colour = GetOptionValue(j.ItemNumber.Trim(), 101),
                                                                  OrderNumber = j.OrderNumber == null ? "" : j.OrderNumber.Trim(),
                                                                  ItemNumber = j.ItemNumber.Trim(),
                                                                  ItemType = j.ItemType.Trim(),
                                                                  DescLine1 = j.ItemNumber.Trim(),
                                                                  DescLine2 = seqMessageProcessor.GetSequencingMessage(station, j.ItemNumber.Trim(), tokens),
                                                                  JobId = (int)j.JobId,
                                                                  OrderId = j.OrderId,
                                                                  Item = itemDetailsModel.GetItemInfoByLineId(j.ItemNumber.Trim(), station.Line.Id)
                                                              }).ToList();

                                            offsetSeats = offsetjobs;
                                        }
                                    }

                                }
                            }


                        }


                        if (station.SequencingLocation.ParentId == null)
                        {
                            currentjobs = (from j in lineBuffer.Where(i => i.OrderId >= station.NextBox.OrderId).Take(itemsinschedule).ToList()
                                           select new Seat
                                           {
                                               OrderStatus = (int)j.OrderStatus,
                                               Complete = false,
                                               TrimStyle = GetOptionValue(j.ItemNumber.Trim(), 100),
                                               Colour = GetOptionValue(j.ItemNumber.Trim(), 101),
                                               OrderNumber = j.OrderNumber == null ? "" : j.OrderNumber.Trim(),
                                               ItemNumber = j.ItemNumber.Trim(),
                                               ItemType = j.ItemType.Trim(),
                                               DescLine1 = j.ItemNumber.Trim(),
                                               DescLine2 = seqMessageProcessor.GetSequencingMessage(station, j.ItemNumber.Trim(), tokens),
                                               JobId = (int)j.JobId,
                                               OrderId = j.OrderId,
                                               Item = itemDetailsModel.GetItemInfoByLineId(j.ItemNumber.Trim(), station.Line.Id),
                                           }).OrderBy(s => s.OrderId).ToList();
                        }
                        else //from queue
                        {
                            currentjobs = (from j in lineBuffer.Where(i => i.OrderId >= station.NextBox.OrderId).Take(itemsinschedule).ToList()
                                            select new Seat
                                            {
                                                ScheduleNum = j.ScheduleNum,
                                                BoxNum = j.BoxNum,
                                                OrderStatus = (int)j.OrderStatus,
                                                Complete = false,
                                                TrimStyle = GetOptionValue(j.ItemNumber.Trim(), 100),
                                                Colour = GetOptionValue(j.ItemNumber.Trim(), 101),
                                                OrderNumber = j.OrderNumber == null ? "" : j.OrderNumber.Trim(),
                                                ItemNumber = j.ItemNumber.Trim(),
                                                ItemType = j.ItemType.Trim(),
                                                DescLine1 = j.ItemNumber.Trim(),
                                                DescLine2 = seqMessageProcessor.GetSequencingMessage(station, j.ItemNumber.Trim(), tokens),
                                                JobId = (int)j.JobId,
                                                OrderId = j.OrderId,
                                                Item = itemDetailsModel.GetItemInfoByLineId(j.ItemNumber.Trim(), station.Line.Id),
                                            }).OrderBy(s => s.OrderId).ToList();
                        }


                        if (currentjobs.Count() != itemsinschedule)
                            return null;

                        for(int i=0; i<currentjobs.Count(); i++)
                            currentjobs[i].Index = i;

                        trimSchedule.CurrentSchedule = new TrimScheduleInfo
                        {
                            Complete = false,
                            SeatSchedule = currentjobs,
                            SummaryList = GetSummaryHeaderItems(currentjobs, station.Line.Id),
                            ScheduleStatus = GetTrimScheduleStatus(station, scheduleStatus, currentjobs),
                            OffsetSeats = offsetSeats
                        };

                        return trimSchedule;

                    }
                }
            }
            return null;
        }
예제 #8
0
        public TrimScheduleInfo GetNextTrimSchedule(int locationId)
        {
            PartSequencingDataContext dbSeq = new PartSequencingDataContext();
            SequencingFactory factory = new SequencingFactory();
            HP_MESDataContext dbMes = new HP_MESDataContext();
            ItemDetailsFactory itemDetailsModel = new ItemDetailsFactory();
            TrimScheduleInfo nextTrimScheduleInfo = null;

            var seqMessageProcessor = new SeqMessageProcessor();

            var seqStations = dbSeq.SequencingStationSettings.Where(i => i.SequencingLocationId == locationId).ToList();
            if (seqStations.Count() > 0)
            {
                var seqStation = seqStations.FirstOrDefault();
                if (seqStation != null)
                {
                    var station = factory.UpdateNextBoxBySequencingId(seqStation.Id);
                    var scheduleStatus = dbSeq.SequencingStationLookups.Where(s => s.SequenceStationSettingsId == station.Id).FirstOrDefault();
                    var tokens = MessageTokensCacheManager.MessageTokens.Where(s => s.LineId == station.Line.Id || s.LineId == 4).ToList();

                    var lineBuffer = factory.GetSequencingBuffer(station);

                    if (lineBuffer != null)
                    {
                        var itemsinbox = station.PartsPerBox;
                        var boxperschedule = station.BoxPerSchedule;
                        var itemsinschedule = itemsinbox * boxperschedule;
                        var boxqty = station.BoxQty;

                        var currentjobs = (from j in lineBuffer.Where(i => i.OrderId >= station.NextBox.OrderId).Take(itemsinschedule).ToList()
                                           select new Seat
                                           {
                                               OrderStatus = (int)j.OrderStatus,
                                               Complete = false,
                                               TrimStyle = GetOptionValue(j.ItemNumber.Trim(), 100),
                                               Colour = GetOptionValue(j.ItemNumber.Trim(), 101),
                                               OrderNumber = j.OrderNumber == null ? "" : j.OrderNumber.Trim(),
                                               ItemNumber = j.ItemNumber.Trim(),
                                               ItemType = j.ItemType.Trim(),
                                               DescLine1 = j.ItemNumber.Trim(),
                                               DescLine2 = seqMessageProcessor.GetSequencingMessage(station, j.ItemNumber.Trim(), tokens),
                                               JobId = (int)j.JobId,
                                               OrderId = j.OrderId,
                                               Item = itemDetailsModel.GetItemInfoByLineId(j.ItemNumber.Trim(), station.Line.Id),
                                           }).OrderBy(s => s.OrderId).ToList();

                        if (currentjobs.Count() != itemsinschedule)
                            return null;

                        var lastcurrentjob = currentjobs.Last();

                        var nextjobs = (from j in lineBuffer.Where(i => i.OrderId > lastcurrentjob.OrderId).Take(itemsinschedule).ToList()
                                        select new Seat
                                        {
                                            OrderStatus = (int)j.OrderStatus,
                                            Complete = false,
                                            TrimStyle = GetOptionValue(j.ItemNumber.Trim(), 100),
                                            Colour = GetOptionValue(j.ItemNumber.Trim(), 101),
                                            OrderNumber = j.OrderNumber == null ? "" : j.OrderNumber.Trim(),
                                            ItemNumber = j.ItemNumber.Trim(),
                                            ItemType = j.ItemType.Trim(),
                                            DescLine1 = j.ItemNumber.Trim(),
                                            DescLine2 = seqMessageProcessor.GetSequencingMessage(station, j.ItemNumber.Trim(), tokens),
                                            JobId = (int)j.JobId,
                                            OrderId = j.OrderId,
                                            Item = itemDetailsModel.GetItemInfoByLineId(j.ItemNumber.Trim(), station.Line.Id)
                                        }).OrderBy(s => s.OrderId).ToList();

                        if (nextjobs.Count() == itemsinschedule)
                        {
                            nextTrimScheduleInfo = new TrimScheduleInfo
                            {
                                Complete = false,
                                SeatSchedule = nextjobs,
                                SummaryList = GetSummaryHeaderItems(nextjobs, station.Line.Id),
                                ScheduleStatus = new TrimScheduleStatus
                                {
                                    CurrentBoxNumber = (scheduleStatus.NextBoxNum + 1) > boxqty ? 1 : scheduleStatus.NextBoxNum + 1,
                                    CurrentScheduleNumber = scheduleStatus.NextScheduleNum + 1
                                }
                            };
                        }
                        else
                        {
                            return null;
                        }

                        for (int i = 0; i < nextjobs.Count(); i++)
                            nextjobs[i].Index = i;

                        return nextTrimScheduleInfo;

                    }
                }
            }
            return null;
        }
예제 #9
0
        public IEnumerable<SideBySide> GetSequencingTracking2StationsByLineId(int lineId, int seqId1, int seqId2)
        {
            HP_MESDataContext dbMes = new HP_MESDataContext();
            SequencingFactory factory = new SequencingFactory();

            var results = (from s in dbMes.IWS_SP_GetWIPSequencingTracking2StationsByLineId(lineId, seqId1, seqId2)
                           select new SideBySide
                           {
                               Complete1 = s.ScheduleNum1 == -1 ? false : true,
                               Complete2 = s.ScheduleNum2 == -1 ? false : true,
                               BoxNum1 = s.BoxNum1,
                               BoxNum2 = s.BoxNum2,
                               Group = s.Group,
                               ItemNumber = s.ItemNumber,
                               ItemType = s.ItemType,
                               JobId = (int)s.JobId,
                               LineId = (int)s.LineId,
                               OrderId = (int)s.OrderId,
                               OrderStatus = (int)s.OrderStatus,
                               OrderNumber = s.OrderNumber,
                               Position1 = s.Position1,
                               Position2 = s.Position2,
                               Region = s.Region,
                               ScheduleNum1 = s.ScheduleNum1,
                               ScheduleNum2 = s.ScheduleNum2,
                               Type1 = s.Type1,
                               Type2 = s.Type2,
                           }).ToList();

            var station1 = factory.UpdateNextBoxBySequencingId(seqId1);
            var station2 = factory.UpdateNextBoxBySequencingId(seqId2);

            UpdateNextSeqScheduleSideBySide(station1, results, 1);
            UpdateNextSeqScheduleSideBySide(station2, results, 2);


            var scheduleNum1 = -1;
            var scheduleNum2 = -1;
            var boxNum1 = -1;
            var boxNum2 = -1;

            var itemsinschedule1 = station1.PartsPerBox * station1.BoxPerSchedule;
            var itemsinschedule2 = station2.PartsPerBox * station2.BoxPerSchedule;

            //Schedule calc
            for (var i = 0; i < results.Count(); i++)
            {

                if (results[i].ScheduleNum1 != scheduleNum1)
                {

                    results[i].StartDrawSchedule1 = true;

                    var countSchedule = 0;
                    for (var j = i; j < results.Count(); j++)
                    {
                        if (results[j].ScheduleNum1 == results[i].ScheduleNum1)
                        {
                            countSchedule++;
                        }
                        else
                        {
                            break;
                        }
                    }

                    if (results[i].Complete1)
                        results[i].ScheduleCount1 = countSchedule;
                    else
                    {
                        if (countSchedule > itemsinschedule1)
                            results[i].ScheduleCount1 = itemsinschedule1;
                        else
                            results[i].ScheduleCount1 = countSchedule;
                    }

                    scheduleNum1 = results[i].ScheduleNum1;
                }
                else
                {
                    results[i].StartDrawSchedule1 = false;
                }

                if (results[i].ScheduleNum2 != scheduleNum2)
                {

                    results[i].StartDrawSchedule2 = true;

                    var countSchedule = 0;
                    for (var j = i; j < results.Count(); j++)
                    {
                        if (results[j].ScheduleNum2 == results[i].ScheduleNum2)
                        {
                            countSchedule++;
                        }
                        else
                        {
                            break;
                        }
                    }

                    if (results[i].Complete2)
                        results[i].ScheduleCount2 = countSchedule;
                    else
                    {
                        if (countSchedule > itemsinschedule2)
                            results[i].ScheduleCount2 = itemsinschedule2;
                        else
                            results[i].ScheduleCount2 = countSchedule;
                    }

                    scheduleNum2 = results[i].ScheduleNum2;
                }
                else
                {
                    results[i].StartDrawSchedule2 = false;
                }


            }

            //Box Calc
            scheduleNum1 = -1;
            scheduleNum2 = -1;
            for (var i = 0; i < results.Count(); i++)
            {
                if (results[i].BoxNum1 != boxNum1 || results[i].ScheduleNum1 != scheduleNum1)
                {
                    results[i].StartDrawBox1 = true;

                    var countBox = 0;

                    for (var j = i; j < results.Count(); j++)
                    {
                        if (results[j].BoxNum1 == results[i].BoxNum1 && results[j].ScheduleNum1 == results[i].ScheduleNum1)
                        {
                            countBox++;
                        }

                    }
                    results[i].BoxCount1 = countBox;

                    boxNum1 = results[i].BoxNum1;
                    scheduleNum1 = results[i].ScheduleNum1;

                }
                else
                {
                    results[i].StartDrawBox1 = false;
                }

                if (results[i].BoxNum2 != boxNum2 || results[i].ScheduleNum2 != scheduleNum2)
                {
                    results[i].StartDrawBox2 = true;

                    var countBox = 0;

                    for (var j = i; j < results.Count(); j++)
                    {
                        if (results[j].BoxNum2 == results[i].BoxNum2 && results[j].ScheduleNum2 == results[i].ScheduleNum2)
                        {
                            countBox++;
                        }

                    }
                    results[i].BoxCount2 = countBox;

                    boxNum2 = results[i].BoxNum2;
                    scheduleNum2 = results[i].ScheduleNum2;

                }
                else
                {
                    results[i].StartDrawBox2 = false;
                }
            }



            return results;
        }
예제 #10
0
        public void AutoCorrectSeqScheduleBySequencingStationId(int id)
        {
            PartSequencingDataContext dbSeq = new PartSequencingDataContext();
            HP_MESDataContext dbMes = new HP_MESDataContext();

            var station = UpdateNextBoxBySequencingId(id);
            var scheduleStatus = dbSeq.SequencingStationLookups.Where(s => s.SequenceStationSettingsId == station.Id).FirstOrDefault();

            var baseStation = UpdateNextBoxBySequencingId((int)station.BaseStation.Id);
            var baseStatus = dbSeq.SequencingStationLookups.Where(s => s.SequenceStationSettingsId == baseStation.Id).FirstOrDefault();

            var lineBuffer = GetSequencingBuffer(station);

            //calculate offset
            var correctOffset = station.Offset;
            int offsetDifference = 0;

            if (lineBuffer.Any())
            {
                var baseFirst = lineBuffer.Where(itm => itm.OrderId >= baseStatus.NextOrderId).FirstOrDefault();
                var stationFirst = lineBuffer.Where(itm => itm.OrderId >= scheduleStatus.NextOrderId).FirstOrDefault();


                if (baseFirst.OrderId >= stationFirst.OrderId) //behind base station
                {
                    offsetDifference = lineBuffer.Where(itm => itm.OrderId >= scheduleStatus.NextOrderId && itm.OrderId < baseStatus.NextOrderId).Count();

                    int amountAbleToMove = lineBuffer.Where(itm => itm.OrderId >= scheduleStatus.NextOrderId).Count();
                    int adjustOffset = correctOffset + offsetDifference;

                    if (adjustOffset <= amountAbleToMove)
                    {
                        if (adjustOffset > 0) //should move down 
                            UpdateOffsetStationById(station.Id, 0, adjustOffset);
                    }
                    else //not enough to move
                    {
                        throw new HttpResponseException(
                            HttpErrorResponse.GetHttpErrorResponse(
                            HttpStatusCode.NotFound, "Buffer not large enough", string.Format("Buffer = {0}, Adjust = {1}", amountAbleToMove, adjustOffset)));
                    }
                }
                else //ahead of base station
                {
                    offsetDifference = lineBuffer.Where(itm => itm.OrderId >= baseStatus.NextOrderId && itm.OrderId < scheduleStatus.NextOrderId).Count();
                    int adjustOffset = offsetDifference - correctOffset;
                    if (adjustOffset == 0)
                    {
                        //do nothing
                    }
                    else if (adjustOffset > 0)
                        UpdateOffsetStationById(station.Id, 1, adjustOffset);
                    else
                        UpdateOffsetStationById(station.Id, 0, Math.Abs(adjustOffset));

                }
            }


        }
예제 #11
0
        public SequencingStation UpdateNextBoxBySequencingId(int id)
        {
            PartSequencingDataContext dbSeq = new PartSequencingDataContext();
            HP_MESDataContext dbMes = new HP_MESDataContext();
            PlasticSeqDatabase dbPlasticSeq = new PlasticSeqDatabase();

            SequencingTrackingItem lastItem = null;
            SequencingTrackingItem firstItem = null;

            var station = (from s in SequencingSettingsCacheManager.SequencingStationSettings
                           where s.Obsolete == false && s.Id == id
                           select new SequencingStation
                           {
                               Description = s.Description,
                               ScheduleAvailable = false,
                               ItemsWaiting = 0,
                               ItemsWaitingPercentage = 0,
                               Id = s.Id,
                               SequencingLocation = dbSeq.SequencingLocations.Where(x => x.Id == s.SequencingLocationId).Single(),
                               Line = dbSeq.Lines.Where(x => x.Id == s.LineId).Single(),
                               Station = dbPlasticSeq.GetStation((int)s.StationId),
                               StationOrder = (int)s.StationOrder,
                               BoxPerSchedule = (int)s.BoxPerSchedule,
                               BoxQty = (int)s.BoxQty,
                               MessageFormat = s.MessageFormat,
                               Obsolete = (bool)s.Obsolete,
                               PartsPerBox = (int)s.PartsPerBox,
                               SeatOptions = (int)s.SeatOptions,
                               SeatOptions2Check = (int)s.SeatOptions2Check,
                               BaseStation = SequencingSettingsCacheManager.SequencingStationSettings.Where(i => i.Id == SequencingSettingsCacheManager.BaseSequencingStationOffsets.Where(x => x.LineId == s.LineId).Single().SequencingStationSettingsId).Single(),
                               Offset = (int)s.Offset,
                           }).Single();

            var tracking = GetSequencingHistory(station);
            var lineBuffer = GetSequencingBuffer(station);

            var minBuffer = lineBuffer.OrderBy(j => j.OrderId).FirstOrDefault();

            var scheduleStatus = dbSeq.SequencingStationLookups.Where(s => s.SequenceStationSettingsId == station.Id).FirstOrDefault();

            if (tracking.Any())
            {
                lastItem = tracking.OrderByDescending(j => j.OrderId).First();
                firstItem = tracking.OrderBy(j => j.OrderId).First();
            }

            station.NextBox = new SequenceBox();

            if (scheduleStatus == null)
            {
                int nextOrderId = Int16.MinValue;

                var onlineBuffer = GetAdminSequencingBuffer(station);
                onlineBuffer.OrderBy(j => j.OrderId).FirstOrDefault();

                if (onlineBuffer != null)
                    nextOrderId = onlineBuffer.First().OrderId;


                if (lastItem != null)
                {
                    if (lastItem.OrderId > nextOrderId)
                    {
                        nextOrderId = lastItem.OrderId + 1;
                    }
                }

                scheduleStatus = new SequencingStationLookup
                {
                    SequenceStationSettingsId = station.Id,
                    NextBoxNum = 1,
                    NextScheduleNum = 1,
                    NextOrderId = nextOrderId
                };

                station.NextBox.BoxNum = scheduleStatus.NextBoxNum;
                station.NextBox.OrderId = scheduleStatus.NextOrderId;
                station.NextBox.ScheduleNum = scheduleStatus.NextScheduleNum;
                SetScheduleAvailable(station, lineBuffer.Count());

                dbSeq.SequencingStationLookups.InsertOnSubmit(scheduleStatus);
                dbSeq.SubmitChanges();
            }
            else
            {
                if (lastItem != null)
                {
                    if (lastItem.Type == 2)
                    {
                        var lastRealJob = tracking.Where(o => o.OrderId < lastItem.OrderId).OrderByDescending(f => f.OrderId).Where(x => x.ScheduleNum > 0).FirstOrDefault();
                        if (lastRealJob != null)
                        {
                            if ((lastRealJob.BoxNum + station.BoxPerSchedule) > station.BoxQty)
                                station.NextBox.BoxNum = 1;
                            else
                                station.NextBox.BoxNum = lastRealJob.BoxNum + 1;


                            station.NextBox.ScheduleNum = lastRealJob.ScheduleNum + 1;
                            //station.NextBox.BoxNum = lastRealJob.BoxNum + 1;
                            station.NextBox.OrderId = lastItem.OrderId + 1;
                        }
                        else
                        {
                            station.NextBox.ScheduleNum = scheduleStatus.NextScheduleNum;
                            station.NextBox.BoxNum = scheduleStatus.NextBoxNum;
                            station.NextBox.OrderId = lastItem.OrderId + 1;
                        }
                    }
                    else
                    {
                        if ((lastItem.BoxNum + station.BoxPerSchedule) > station.BoxQty)
                            station.NextBox.BoxNum = 1;
                        else
                            station.NextBox.BoxNum = (lastItem.BoxNum + 1);

                        station.NextBox.ScheduleNum = lastItem.ScheduleNum + 1;
                        station.NextBox.OrderId = lastItem.OrderId + 1;
                    }


                }
                else
                {
                    if (minBuffer != null)
                    {
                        station.NextBox.OrderId = minBuffer.OrderId;
                        station.NextBox.BoxNum = 1;
                        station.NextBox.ScheduleNum = 1;
                    }
                    else
                    {
                        station.NextBox.OrderId = scheduleStatus.NextOrderId;
                        station.NextBox.BoxNum = scheduleStatus.NextBoxNum;
                        station.NextBox.ScheduleNum = scheduleStatus.NextScheduleNum;
                    }

                }

                scheduleStatus.NextBoxNum = station.NextBox.BoxNum;
                scheduleStatus.NextScheduleNum = station.NextBox.ScheduleNum;
                scheduleStatus.NextOrderId = station.NextBox.OrderId;

                dbSeq.SubmitChanges();

                //var validBuffer = (from l in lineBuffer
                //                   where l.OrderId >= station.NextBox.OrderId
                //                   select l).ToList();

                SetScheduleAvailable(station, lineBuffer.Where(l=>l.OrderId >= station.NextBox.OrderId).Count());

            }


            return station;

        }
예제 #12
0
        public JobBuffer ScheduleAdminView(int id)
        {
            PartSequencingDataContext dbSeq = new PartSequencingDataContext();
            HP_MESDataContext dbMes = new HP_MESDataContext();
            ItemDetailsFactory itemDetailsModel = new ItemDetailsFactory();
            var seqMessageProcessor = new SeqMessageProcessor();

            var station = UpdateNextBoxBySequencingId(id);

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

            var lineBuffer = GetAdminSequencingBuffer(station);

            var boxBuffer = new JobBuffer
            {
                CurrentBoxNum = station.NextBox.BoxNum,
                CurrentScheduleNum = station.NextBox.ScheduleNum,
                SequencingStation = station,
                Buffer = new List<SequenceItem>()
            };

            var tracking = GetSequencingHistory(station);

            boxBuffer.Buffer = (lineBuffer.GroupJoin(tracking, jb => jb.OrderId, st => st.OrderId, (jb, g) => new { _jb = jb, g }).
            SelectMany(t => t.g.DefaultIfEmpty(), (t, st) => new SequenceItem
            {
                BoxNum = st == null ? 0 : st.BoxNum,
                OrderId = t._jb.OrderId,
                Complete = true,
                OrderNumber = t._jb.OrderNumber == null ? "" : t._jb.OrderNumber,
                ScheduleNum = st == null ? 0 : st.ScheduleNum,
                ItemNumber = t._jb.ItemNumber,
                JobId = (int)t._jb.JobId,
                Region = t._jb.Region.Trim(),
                Type = st == null ? 0 : (int)st.Type,
                Message = seqMessageProcessor.GetSequencingMessage(station, t._jb.ItemNumber, tokens),
                Item = itemDetailsModel.GetItemInfo(t._jb.ItemNumber)
            })).ToList();

            boxBuffer.Buffer = boxBuffer.Buffer.OrderBy(s => s.OrderId).ToList();

            var itemsinbox = station.PartsPerBox;
            var boxperschedule = station.BoxPerSchedule;
            var itemsintheschedule = itemsinbox * boxperschedule;
            if (station.NextBox != null)
            {

                var currentbox = station.NextBox.BoxNum;

                var jobs = boxBuffer.Buffer.Where(i => i.OrderId >= station.NextBox.OrderId).Take(itemsintheschedule).OrderBy(s => s.OrderId).ToList();

                foreach (var item in jobs)
                {
                    item.Complete = false;
                    item.BoxNum = currentbox;
                    item.ScheduleNum = station.NextBox.ScheduleNum;

                    if (item.Message.ToUpper().IndexOf("*SKIPPED*") < 0)
                    {
                        item.Skipped = false;
                        --itemsinbox;
                    }
                    else
                        item.Skipped = true;


                    if (itemsinbox > 0 && itemsintheschedule > 0) continue;
                    if (itemsintheschedule <= 1)
                    {
                        break;
                    }

                    itemsinbox = station.PartsPerBox;
                    --boxperschedule;
                    currentbox = currentbox >= station.BoxQty ? 1 : ++currentbox;

                }

            }

            var scheduleNum = -1;
            var boxNum = -1;
            var initialJobId = Int32.MinValue;

            for(var i=0;i<boxBuffer.Buffer.Count(); i++) {
                if (i == 0) {
                    initialJobId = boxBuffer.Buffer[i].JobId;
                }

                if (boxBuffer.Buffer[i].ScheduleNum != scheduleNum)
                {
                    
                    boxBuffer.Buffer[i].StartDrawSchedule = true;
                    boxBuffer.Buffer[i].InitialJobId = initialJobId;

                    var countSchedule = 0;
                    for(var j=i; j<boxBuffer.Buffer.Count();j++) {
                        if (boxBuffer.Buffer[j].ScheduleNum == boxBuffer.Buffer[i].ScheduleNum) {
                            countSchedule++;
                        } else {
                            break;
                        }
                    }

                    if (boxBuffer.Buffer[i].Complete)
                        boxBuffer.Buffer[i].ScheduleCount = countSchedule;
                    else
                    {
                        if (countSchedule > itemsintheschedule)
                            boxBuffer.Buffer[i].ScheduleCount = itemsintheschedule;
                        else
                            boxBuffer.Buffer[i].ScheduleCount = countSchedule;
                    }
                    initialJobId = boxBuffer.Buffer[i].JobId;
                    scheduleNum = boxBuffer.Buffer[i].ScheduleNum;
                }
                else
                {
                    boxBuffer.Buffer[i].StartDrawSchedule = false;

                }
            }

            scheduleNum = -1;
            for (var i = 0; i < boxBuffer.Buffer.Count(); i++)
            {
                if (boxBuffer.Buffer[i].BoxNum != boxNum || boxBuffer.Buffer[i].ScheduleNum != scheduleNum)
                {
                    boxBuffer.Buffer[i].StartDrawBox = true;

                    var countBox = 0;
                    for (var j = i; j < boxBuffer.Buffer.Count(); j++)
                    {
                        if (boxBuffer.Buffer[j].BoxNum == boxBuffer.Buffer[i].BoxNum && boxBuffer.Buffer[j].ScheduleNum == boxBuffer.Buffer[i].ScheduleNum)
                        {
                            countBox++;
                        }
                        else
                            break;
                    }
                    boxBuffer.Buffer[i].BoxCount = countBox;
                    boxNum = boxBuffer.Buffer[i].BoxNum;
                    scheduleNum = boxBuffer.Buffer[i].ScheduleNum;
                }
                else
                {
                    boxBuffer.Buffer[i].StartDrawBox = false;
                }
            }
            
            return boxBuffer;

        }
예제 #13
0
        public void UpdateOffsetStationById(int id, int direction, int offset)
        {
            PartSequencingDataContext dbSeq = new PartSequencingDataContext();
            HP_MESDataContext dbMes = new HP_MESDataContext();

            var station = UpdateNextBoxBySequencingId(id);
            var scheduleStatus = dbSeq.SequencingStationLookups.Where(s => s.SequenceStationSettingsId == station.Id).FirstOrDefault();

            SequencingTrackingItem lastItem = null;
            var tracking = GetSequencingHistory(station);
            var lineBuffer = GetSequencingBuffer(station);

            if (tracking.Any())
            {
                lastItem = tracking.OrderByDescending(i => i.OrderId).First();

                if (direction == 0) //down
                {
                    var buffer = lineBuffer.Where(item => item.OrderId > lastItem.OrderId).ToList();
                    buffer = buffer.OrderBy(item => item.OrderId).Take(offset).ToList();

                    if (buffer.Count() == offset)   //enough schedule to move it
                    {
                        var lastBuffer = buffer.Last();
                        SequencingTrackingHistoryDetail histDetail = new SequencingTrackingHistoryDetail
                        {
                            BoxNum = -1, //scheduleStatus.NextBoxNum - 1 == 0 ? 4 : scheduleStatus.NextBoxNum - 1,
                            DTM = DateTime.Now,
                            ScheduleNum = -1, //scheduleStatus.NextScheduleNum - 1,
                            SequencingStationSettingsId = station.Id,
                            Type = 2
                        };
                        dbSeq.SequencingTrackingHistoryDetails.InsertOnSubmit(histDetail);

                        int position = 1;
                        foreach (var seat in buffer)
                        {
                            SequencingTrackingHistory hist = new SequencingTrackingHistory
                            {
                                OrderNumber = seat.OrderNumber,
                                ItemNumber = seat.ItemNumber,
                                ItemType = seat.ItemType,
                                Position = position,
                                JobId = seat.JobId,
                                OrderId = seat.OrderId,
                                OrderStatus = (int)seat.OrderStatus,
                                SequencingTrackingHistoryDetail = histDetail,
                            };

                            dbSeq.SequencingTrackingHistories.InsertOnSubmit(hist);
                            position++;
                        }

                        scheduleStatus.NextOrderId = lastBuffer.OrderId + 1;
                        dbSeq.SubmitChanges();
                    }
                }
                else if (direction == 1) //up
                {

                    var buffer = tracking.OrderByDescending(i => i.OrderId).Take(offset).ToList();
                    if (buffer.Count() == offset)   //enough schedule to move it up
                    {
                        var lastBuffer = buffer.Last();

                        foreach (var seat in buffer)
                        {
                            var deleteSeat = dbSeq.SequencingTrackingHistories.Where(s=>s.Id == seat.SequencingTrackingHistoryId).FirstOrDefault();
                            if (deleteSeat != null)
                                dbSeq.SequencingTrackingHistories.DeleteOnSubmit(deleteSeat);
                        }

                        if (lastBuffer.Type == 2)
                        {
                            scheduleStatus.NextOrderId = lastBuffer.OrderId;
                        }

                        dbSeq.SubmitChanges();

                        var histDetailId = buffer.First().SequencingTrackingHistoryDetailsId;
                        var root = dbSeq.SequencingTrackingHistoryDetails.Where(s => s.Id == histDetailId).FirstOrDefault();
                        if (root != null)
                        {
                            if (root.SequencingTrackingHistories.Count() == 0)
                            {
                                dbSeq.SequencingTrackingHistoryDetails.DeleteOnSubmit(root);
                                dbSeq.SubmitChanges();
                            }
                        }

                    }
                }


            }
            else
            {
                if (lineBuffer.Any())
                {
                    if (direction == 0) //down
                    {
                        var buffer = lineBuffer.Take(offset).ToList();
                        if (buffer.Count() == offset)
                        {
                            var lastBuffer = buffer.Last();
                            SequencingTrackingHistoryDetail histDetail = new SequencingTrackingHistoryDetail
                            {
                                BoxNum = -1, //scheduleStatus.NextBoxNum - 1 == 0 ? 4 : scheduleStatus.NextBoxNum - 1,
                                DTM = DateTime.Now,
                                ScheduleNum = -1, //scheduleStatus.NextScheduleNum - 1,
                                SequencingStationSettingsId = station.Id,
                                Type = 2
                            };
                            dbSeq.SequencingTrackingHistoryDetails.InsertOnSubmit(histDetail);

                            int position = 1;
                            foreach (var seat in buffer)
                            {
                                SequencingTrackingHistory hist = new SequencingTrackingHistory
                                {
                                    OrderNumber = seat.OrderNumber,
                                    ItemNumber = seat.ItemNumber,
                                    ItemType = seat.ItemType,
                                    Position = position,
                                    JobId = seat.JobId,
                                    OrderId = seat.OrderId,
                                    OrderStatus = (int)seat.OrderStatus,
                                    SequencingTrackingHistoryDetail = histDetail,
                                };

                                dbSeq.SequencingTrackingHistories.InsertOnSubmit(hist);
                                position++;
                            }

                            scheduleStatus.NextOrderId = lastBuffer.OrderId + 1;
                            dbSeq.SubmitChanges();
                        }
                    }
                    else if (direction == 1)
                    {
                        //cannot go move up when there is no tracking
                    }
                }
            }

            //send broadcast to clients to update/refresh screen
            //var context = GlobalHost.ConnectionManager.GetHubContext<FrontTrimSeqHub>();
            //context.Clients.All.frontTrimReceiveBroadcast(999, station.SequencingLocation.Id, "Refresh Command");
            //context.Clients.All.frontTrimReceiveBroadcast(998, 1, "Maintenance");

        }
예제 #14
0
        public PlasticSeqSchedule GetPlasticSeqScheduleBySequencingStationId(int id)
        {
            #region Get Plastic Seq Schedule By Sequencing Station Id
            PartSequencingDataContext dbSeq = new PartSequencingDataContext();
            HP_MESDataContext dbMes = new HP_MESDataContext();
            SequencingFactory seqFactory = new SequencingFactory();
            var seqMessageProcessor = new SeqMessageProcessor();


            PlasticSeqSchedule schedule = null;

            var station = seqFactory.UpdateNextBoxBySequencingId(id);
            var scheduleStatus = dbSeq.SequencingStationLookups.Where(s => s.SequenceStationSettingsId == station.Id).FirstOrDefault();

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

            var lineBuffer = seqFactory.GetSequencingBuffer(station);

            schedule = new PlasticSeqSchedule
            {
                SequencingStation = station,
            };

            SequencingTrackingItem lastTrackItem = null;
            var tracking = seqFactory.GetSequencingHistory(station);

            if (tracking.Any())
            {
                lastTrackItem = tracking.OrderByDescending(i => i.OrderId).FirstOrDefault();
                if (lastTrackItem != null)
                {
                    if (lastTrackItem.Type == 2)
                    {
                        var lastRealJob = tracking.Where(o => o.OrderId < lastTrackItem.OrderId).OrderByDescending(f => f.OrderId).Where(x => x.ScheduleNum > 0).FirstOrDefault();

                        if (lastRealJob != null)
                        {
                            var unassignedBuffer = tracking.Where(o => o.OrderId <= lastTrackItem.OrderId && o.OrderId > lastRealJob.OrderId).OrderBy(f => f.OrderId).ToList();
                            if (unassignedBuffer.Count() > 0)
                            {
                                var unassignbox = new ScheduleBox(1, 1);
                                var items = unassignedBuffer.Select(item => seqMessageProcessor.GetSequencingMessage(station, item.ItemNumber, tokens).Trim());
                                int unassignPosition = 1;
                                foreach (var message in items)
                                {
                                    if (message.ToUpper().IndexOf("*SKIPPED*") < 0)
                                    {
                                        //string[] msg = message.Split(',');
                                        unassignbox.Items.Add(new ScheduleItem(unassignPosition, message));
                                        unassignPosition++;
                                    }

                                }
                                schedule.OffsetBoxes = unassignbox;
                            }
                        }


                    }
                }
            }


            if (lineBuffer != null)
            {
                //check for not assigned parts for schedule
                var itemsinbox = station.PartsPerBox;
                var boxperschedule = station.BoxPerSchedule;
                var itemsinschedule = itemsinbox * boxperschedule;

                var jobs = lineBuffer.Where(i => i.OrderId >= station.NextBox.OrderId).Take(itemsinschedule).ToList();
                var boxPosition = 1;
                var boxperpage = boxperschedule;

                do
                {
                    var currentbox = station.NextBox.BoxNum;
                    var box = new ScheduleBox(boxPosition, currentbox);

                    var items = jobs.Select(item => seqMessageProcessor.GetSequencingMessage(station, item.ItemNumber.Trim(), tokens).Trim());
                    if (!items.Any())
                        break;


                    foreach (var message in items)
                    {
                        if (message.ToUpper().IndexOf("*SKIPPED*") < 0)
                        {
                            box.Items.Add(new ScheduleItem((station.PartsPerBox - itemsinbox + 1), message));
                            --itemsinbox;
                        }

                        --itemsinschedule;
                        if (itemsinbox > 0 && itemsinschedule > 0) continue;
                        itemsinbox = station.PartsPerBox;
                        currentbox = currentbox >= station.BoxQty ? 1 : (++currentbox);
                        schedule.Boxes.Add(box);
                        --boxperschedule;
                        if (boxperschedule > 0 && itemsinschedule > 0)
                        {
                            --boxperpage;
                            boxPosition++;
                            box = new ScheduleBox(boxPosition, currentbox);
                        }
                        else
                        {
                            boxperpage = 0;
                            boxPosition = 1;
                            break;
                        }
                    }
                } while (boxperpage > 1);

            }

            return schedule;
            #endregion
        }
예제 #15
0
        public void CompletePlasticSeqByStation(SequencingStation station)
        {
            #region Complete Plastic Seq By Station
            PartSequencingDataContext dbSeq = new PartSequencingDataContext();
            HP_MESDataContext dbMes = new HP_MESDataContext();
            SequencingFactory seqFactory = new SequencingFactory();
            var seqMessageProcessor = new SeqMessageProcessor();

            var completeDTM = DateTime.Now;

            var lineBuffer = seqFactory.GetSequencingBuffer(station);

            if (station.ScheduleAvailable)
            {
                Log.Logging.Info("station.ScheduleAvailable = true|Seq Id: {0}", station.Id);

                var itemsinbox = station.PartsPerBox;
                var boxperschedule = station.BoxPerSchedule;
                var itemsinschedule = itemsinbox * boxperschedule;

                var currentBox = station.NextBox.BoxNum;

                var jobs = lineBuffer.Where(i => i.OrderId >= station.NextBox.OrderId).Take(itemsinschedule).ToList();
                Log.Logging.Info("Job Count: {0}|Station: {1} Seq Id: {2}", jobs.Count(), station.SequencingLocation.Description, station.Id);
                var tokens = MessageTokensCacheManager.MessageTokens.Where(t => t.LineId == station.Line.Id).ToList();

                SequencingTrackingHistoryDetail histDetail = new SequencingTrackingHistoryDetail
                {
                    BoxNum = currentBox,
                    DTM = completeDTM,
                    ScheduleNum = station.NextBox.ScheduleNum,
                    SequencingStationSettingsId = station.Id,
                    Type = 1
                };

                dbSeq.SequencingTrackingHistoryDetails.InsertOnSubmit(histDetail);
                dbSeq.SubmitChanges();

                Log.Logging.Info("History Header|BoxNum={0}, DTM={1}, ScheduleNum={2}, SeqId={3}, Type={4}", histDetail.BoxNum, histDetail.DTM, histDetail.ScheduleNum, histDetail.SequencingStationSettingsId, histDetail.Type);

                int position = 1;
                foreach (var job in jobs)
                {
                    var message = seqMessageProcessor.GetSequencingMessage(station, job.ItemNumber, tokens).Trim();

                    SequencingTrackingHistory hist = new SequencingTrackingHistory
                    {
                        OrderNumber = job.OrderNumber,
                        ItemNumber = job.ItemNumber,
                        ItemType = job.ItemType,
                        JobId = job.JobId,
                        Position = position,
                        OrderId = job.OrderId,
                        SequencingTrackingHistoryDetail = histDetail,
                    };
                    position++;

                    dbSeq.SequencingTrackingHistories.InsertOnSubmit(hist);

                    Log.Logging.Info("History Detail Item|Job Hist = {0}|Station: {1} Seq Id: {2}", hist, station.SequencingLocation.Description, station.Id);
                    Log.Logging.Info("History Detail Item|OrderNumber={0}, ItemNumber={1}, ItemType={2}, JobId={3}, Position={4}, OrderId={5}", hist.OrderNumber, hist.ItemNumber, hist.ItemType, hist.JobId, hist.Position, hist.OrderId);

                    dbSeq.SubmitChanges();

                    if (message.ToUpper().IndexOf("*SKIPPED*") < 0)
                        --itemsinbox;

                    --itemsinschedule;

                    if (itemsinbox > 0 && itemsinschedule > 0) continue;
                    if (itemsinschedule <= 0)
                        break;

                    itemsinbox = station.PartsPerBox;
                    --boxperschedule;

                    if (currentBox + 1 > station.BoxQty)
                        currentBox = 1;
                    else
                    {
                        currentBox++;
                        position = 1;
                    }

                    histDetail = new SequencingTrackingHistoryDetail
                    {
                        Type = 1,
                        BoxNum = currentBox,
                        DTM = completeDTM,
                        ScheduleNum = station.NextBox.ScheduleNum,
                        SequencingStationSettingsId = station.Id,
                    };

                    Log.Logging.Info("History Detail|BoxNum={0}, DTM={1}, ScheduleNum={2}, SeqId={3}, Type={4}", histDetail.BoxNum, histDetail.DTM, histDetail.ScheduleNum, histDetail.SequencingStationSettingsId, histDetail.Type);

                }


                var lookup = dbSeq.SequencingStationLookups.Where(s => s.SequenceStationSettingsId == station.Id).FirstOrDefault();
                if (lookup != null)
                {
                    if (jobs.Count() > 0)
                    {
                        Log.Logging.Info("Count Jobs={0} SeqId={1}", jobs.Count(), station.Id);
                        var lastJob = jobs.Last();
                        if (lastJob != null)
                        {
                            Log.Logging.Info("Last Jobs: OrderId={0} SeqId={1}", lastJob.OrderId, station.Id);
                            lookup.NextOrderId = lastJob.OrderId + 1;
                            dbSeq.SubmitChanges();
                            Log.Logging.Info("Success Update Lookup: NextOrderId={0} NextScheduleNum={1} NextNextBoxNum={2}", lookup.NextOrderId, lookup.NextScheduleNum, lookup.NextBoxNum);
                        }
                    }
                }

            }
            else
            {
                Log.Logging.Info("station.ScheduleAvailable = false|Seq Id: {0}", station.Id);
            }
            #endregion
        }