Esempio n. 1
0
        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 IEnumerable<PlasticSeqSchedule> GetPlasticScheduleHistoryDetailByLocationId(int locationId, int scheduleNum)
        {
            PlasticScheduleFactory factory = new PlasticScheduleFactory();
            PlasticSeqDatabase db = new PlasticSeqDatabase();

            List<PlasticSeqSchedule> listPlasticHistory = new List<PlasticSeqSchedule>();

            var seqStations = db.GetSequencingStationsBySequencingLocationId(locationId);

            foreach (var station in seqStations)
            {
                var schedule = factory.GetPlasticSeqScheduleHistoryDetail(station, scheduleNum);
                listPlasticHistory.Add(schedule);
            }

            return listPlasticHistory;
        }
 public IEnumerable<SequencingStation> SequencingStationSettingsBySequencingLocationId(int id)
 {
     PlasticSeqDatabase dbPlastic = new PlasticSeqDatabase();
     return dbPlastic.GetSequencingStationSettingssBySequencingLocationId(id);
 }
 public HttpResponseMessage SequencingStationSettingsById([FromBody]SequencingStation settings)
 {
     PlasticSeqDatabase dbPlastic = new PlasticSeqDatabase();
     dbPlastic.UpdateSequencingStationSettingsById(settings);
     return new HttpResponseMessage(HttpStatusCode.OK);
 }
 public SequencingStation SequencingStationSettingsById(int id) 
 {
     PlasticSeqDatabase dbPlastic = new PlasticSeqDatabase();
     return dbPlastic.GetSequencingStationSettingsById(id);
 }
Esempio n. 6
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;

        }
        public async Task<int> CompletePlasticSeqByLocationId(int id, int employeeId)
        {
            #region Complete Plastic Seq By Location Id
            try
            {
                PartSequencingDataContext dbSeq = new PartSequencingDataContext();
                EmployeeDatabase dbEmp = new EmployeeDatabase();
                PlasticSeqDatabase db = new PlasticSeqDatabase();

                int scheduleNum = 0;

                var seqStations = db.GetSequencingStationsBySequencingLocationId(id);

                if (seqStations.Count() > 0)
                {
                    var first = seqStations.FirstOrDefault();
                    if (first != null)
                        scheduleNum = first.NextBox.ScheduleNum;
                }

                Log.Logging.Info("Global Complete|Schedule #{0}|Location Id: {1}", scheduleNum, id);

                await Task.Run(() => Parallel.ForEach(seqStations, station =>
                {
                    Log.Logging.Info("Attempt Complete Schedule|Station: {0} Seq Id: {1}", station.SequencingLocation.Description, station.Id);
                    CompletePlasticSeqByStation(station);
                    Log.Logging.Info("Complete Schedule Done|Seq Id: {1}", id);
                }));

                var employee = dbEmp.GetEmployeeInfo(employeeId);

                var scheduleHist = new SequencingStationScheduleHistory
                {
                    EmployeeId = employeeId,
                    EmployeeName = employee == null ? "Unknown Employee" : employee.Name.Trim(),
                    ScheduleNum = scheduleNum,
                    SequencingLocationId = id,
                    DateCompleted = DateTime.Now,
                };

                dbSeq.SequencingStationScheduleHistories.InsertOnSubmit(scheduleHist);
                dbSeq.SubmitChanges();
                Log.Logging.Info("Insert|SequencingStationScheduleHistory|Schedule #{0}, {1}, {2}, {3}", scheduleNum, scheduleHist.SequencingLocationId, scheduleHist.EmployeeName, scheduleHist.DateCompleted);
                return 1;
            }
            catch (Exception ex)
            {
                Log.Logging.Fatal("FATAL|CompleteSequencingByAisleId(SeqId={0}, EmployeeId={1})", id, employeeId);
                Log.Logging.Fatal("FATAL|Error: {0}", ex.Message);
            }
            return 0;
            #endregion
        }