예제 #1
0
        public virtual ActionResult CartonEditor(CartonEditorViewModel model)
        {
            ModelState.Clear();     // No errors matter
            if (string.IsNullOrEmpty(model.ScanText))
            {
                // User forgot to enter carton id?
                ModelState.AddModelError("", "Please scan carton");
                return(View(Views.CartonEditor, model));
            }
            var cartonId = model.ScanText;

            model.OnViewExecuting(_service, this.ControllerContext);

            if (model.StatusMessages.Count > 0)
            {
                // This can only mean that the carton is invalid
                ModelState.AddModelError("", string.Format("Invalid Carton {0}", cartonId));
            }
            //Read value of area from cookie.
            if (Request.Cookies[COOKIE_AREA] != null)
            {
                model.IrregularAreaId = Request.Cookies[COOKIE_AREA][COOKIE_IRREGULAR_AREA];
                model.SamplesAreaId   = Request.Cookies[COOKIE_AREA][COOKIE_SAMPLE_AREA];
            }

            if (Request.Cookies[COOKIE_PRINTER] != null)
            {
                model.PrinterId = Request.Cookies[COOKIE_PRINTER][COOKIE_SUB_PRINTERID];
            }

            return(View(Views.CartonEditor, model));
        }
예제 #2
0
        public virtual ActionResult Edit(string id)
        {
            //throw new NotImplementedException();
            var model = new CartonEditorViewModel
            {
                ScanText = id
            };

            return(CartonEditor(model));
        }
예제 #3
0
        public virtual ActionResult RemovePieces(CartonEditorViewModel model)
        {
            if (model.PiecesFlag == PiecesRemoveFlag.Irregular && model.IrregularPieces == null || model.IrregularPieces <= 0 || model.IrregularPieces > 999)
            {
                ModelState.AddModelError("", "Pieces to transfer must be between 1 and 999");
                return(AdaptiveResult(null, null, model));
            }
            if (model.PiecesFlag == PiecesRemoveFlag.Samples && model.SamplePieces == null || model.SamplePieces <= 0 || model.SamplePieces > 999)
            {
                ModelState.AddModelError("", "Pieces to transfer must be between 1 and 999");
                return(AdaptiveResult(null, null, model));
            }
            if (model.PiecesFlag == PiecesRemoveFlag.Irregular && model.IrregularAreaId == null)
            {
                ModelState.AddModelError("", "Please provide area to transfer irregular pieces");
                return(AdaptiveResult(null, null, model));
            }
            if (model.PiecesFlag == PiecesRemoveFlag.Samples && model.SamplesAreaId == null)
            {
                ModelState.AddModelError("", "Please provide area to transfer sample pieces");
                return(AdaptiveResult(null, null, model));
            }
            if ((model.PiecesFlag == PiecesRemoveFlag.Irregular || model.PiecesFlag == PiecesRemoveFlag.Samples) && (model.IrregularPieces > model.UpdatingRules.Pieces || model.SamplePieces > model.UpdatingRules.Pieces))
            {
                ModelState.AddModelError("", "Pieces to transfer must not exceed pieces in carton");
                return(AdaptiveResult(null, null, model));
            }


            // Create cookie to add area for removing irregular and sample pieces.
            var cookieArea = new HttpCookie(COOKIE_AREA);

            if (!string.IsNullOrEmpty(model.IrregularAreaId) || !string.IsNullOrEmpty(model.SamplesAreaId))
            {
                cookieArea.Values.Add(COOKIE_IRREGULAR_AREA, model.IrregularAreaId);
                cookieArea.Values.Add(COOKIE_SAMPLE_AREA, model.SamplesAreaId);
                cookieArea.Expires = DateTime.Now.AddDays(15);
                this.HttpContext.Response.Cookies.Add(cookieArea);
            }

            //Create cookie to add selected printer
            var cookiePrinter = new HttpCookie(COOKIE_PRINTER);

            if (!string.IsNullOrEmpty(model.PrinterId))
            {
                cookiePrinter.Values.Add(COOKIE_SUB_PRINTERID, model.PrinterId);
                cookiePrinter.Expires = DateTime.Now.AddDays(15);
                this.HttpContext.Response.Cookies.Add(cookiePrinter);

                //Print carton ticket
                _service.PrintCartonTicket(model.ScanText, model.PrinterId);
                model.StatusMessages.Add(string.Format("Carton printed on '{0}' printer successfully.", model.PrinterId));
            }
            if (model.PiecesFlag == PiecesRemoveFlag.Irregular)
            {
                _service.RemoveIrregularSamples(model.ScanText, model.BundleId, model.IrregularAreaId, model.IrregularPieces, null);
                model.StatusMessages.Add(string.Format("{0} Pieces transferred to {1} area ", model.IrregularPieces, model.IrregularAreaId));
            }
            if (model.PiecesFlag == PiecesRemoveFlag.Samples)
            {
                var reasonCode = _service.GetSampleReasonCode();
                _service.RemoveIrregularSamples(model.ScanText, model.BundleId, model.SamplesAreaId, model.SamplePieces, reasonCode);
                model.StatusMessages.Add(string.Format("{0} Pieces transferred to {1} area ", model.SamplePieces, model.SamplesAreaId));
            }
            return(AdaptiveResult(null, null, model));
        }