Exemplo n.º 1
0
        public ProductionShiftDto GetCurrentProductionShift(int lineID)
        {
            ProductionShiftDto    dto        = null;
            ProdDateChangeService dateSvc    = new ProdDateChangeService();
            ProdDateChangeDto     dateChange = dateSvc.GetCurrentProductionDate(lineID);
            var currentTime = DateTime.Now.TimeOfDay;
            var shiftType   = _repository.Repository <ProductionShiftType>().GetById(dateChange.ShiftTypeID);

            switch (shiftType.Code)
            {
            case "0":
            case "1":
            case "2":
            {
                dto = GetProductionShiftForTypes012(currentTime, lineID);
            } break;

            case "3":
            {
                dto = GetProductionShiftForType3(dateChange, currentTime, lineID);
            } break;

            case "4":
            {
                dto = GetProductionShiftForType4(dateChange, currentTime, lineID);
            } break;

            case "5":
            {
                dto = GetProductionShiftForType5(dateChange, currentTime, lineID);
            } break;
            }
            return(dto);
        }
Exemplo n.º 2
0
        private ProductionShiftDto GetProductionShiftForType3(ProdDateChangeDto dateChange, TimeSpan currentTime, int lineID)
        {
            var             maxEnd     = _repository.Repository <ProductionShiftUse>().GetAllBy(psu => psu.LineID == lineID && psu.UseShift == true).Select(psu => psu.ProductionShift.EndTime).Max();
            var             timeChange = dateChange.DateChange.TimeOfDay;
            ProductionShift shift1     = null;
            ProductionShift shift2     = null;
            Expression <Func <ProductionShiftUse, bool> > expression = null;

            if (currentTime < timeChange || currentTime > maxEnd)
            {
                expression = psu => psu.ProductionShift.StartTime > psu.ProductionShift.EndTime && psu.LineID == lineID && psu.UseShift == true;
            }
            else
            {
                expression = psu => psu.ProductionShift.StartTime < psu.ProductionShift.EndTime && psu.LineID == lineID && psu.UseShift == true;
            }
            shift1 = _repository.Repository <ProductionShiftUse>().GetAllBy(expression).Select(psu => psu.ProductionShift).FirstOrDefault();
            shift2 = _repository.Repository <ProductionShiftUse>().GetAllBy(expression).Select(psu => psu.ProductionShift).LastOrDefault();
            var daysDiff           = (dateChange.RotationStart - dateChange.CurrentProductionDate).Days % 14;
            ProductionShiftDto dto = null;

            switch (daysDiff)
            {
            case 0:
            case 1:
            case 4:
            case 5:
            case 6:
            case 9:
            case 10:
            {
                dto = Mapper.Map <ProductionShift, ProductionShiftDto>(shift1);
            } break;

            default:
            {
                dto = Mapper.Map <ProductionShift, ProductionShiftDto>(shift2);
            } break;
            }

            return(dto);
        }
Exemplo n.º 3
0
        public ActionResult Edit(ProdDateChangeModel model)
        {
            if (ModelState.IsValid)
            {
                ProdDateChangeDto dto = Mapper.Map <ProdDateChangeModel, ProdDateChangeDto>(model);

                //TODO: move to service
                using (var service = new ProdDateChangeService())
                {
                    dto.ID = service.GetAll().Find(p => p.LineID == model.LineID).ID;
                    if (model.Id > 0)
                    {
                        service.Update(dto);
                    }
                }
                SetResponseMesssage(ActionTypeMessage.SuccessfulSave);
            }
            else
            {
                ModelState.AddModelError(string.Empty, "Please enter required fields.");
                SetResponseMesssage(ActionTypeMessage.FailedSave);

                return(View(model));
            }

            return(RedirectToAction("Edit"));


            //string status = "ok";
            //string msg = string.Empty;

            //try
            //{
            //    if (ModelState.IsValid)
            //    {
            //        ProdDateChangeDto dto = Mapper.Map<ProdDateChangeModel, ProdDateChangeDto>(model);

            //        //TODO: move to service
            //        using (var service = new ProdDateChangeService())
            //        {
            //            dto.ID = service.GetAll().Find(p => p.LineID == model.LineID).ID;
            //            if (model.ID > 0)
            //            {
            //                service.Update(dto);
            //            }
            //        }
            //        SetResponseMesssage(ActionTypeMessage.SuccessfulSave);
            //    }
            //    else
            //    {
            //        ModelState.AddModelError(string.Empty, "Please enter required fields.");
            //        SetResponseMesssage(ActionTypeMessage.FailedSave);
            //    }
            //}
            //catch (Exception exc)
            //{
            //    status = "error";
            //    msg = exc.Message;
            //}

            //model.ResponseStatus = status;
            //model.ResponseMessage = msg;

            //return View(model);
        }