public IEnumerable<SequencingStation> GetSequencingStationsByType(string type) { PartSequencingDataContext dbSeq = new PartSequencingDataContext(); PlasticSeqDatabase dbPlasticSeq = new PlasticSeqDatabase(); if (type.ToUpper().Equals("FRONT")) { return (from s in SequencingSettingsCacheManager.SequencingStationSettings.Where(s => s.LineId == 1 && s.Obsolete == false) where s.Obsolete == false 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, }).ToList(); } else if (type.ToUpper().Equals("REAR")) { return (from s in SequencingSettingsCacheManager.SequencingStationSettings.Where(s => (s.LineId == 2 || s.LineId == 3) && s.Obsolete == false) where s.Obsolete == false 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, }).ToList(); } return null; }
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; }