/// <summary>
        /// Get info of carton
        /// </summary>
        /// <param name="service"></param>
        /// <param name="context"></param>
        public override void OnViewExecuting(CartonManagerService service, ControllerContext context)
        {
            base.OnViewExecuting(service, context);
            var carton = service.GetCarton(this.ScanText);

            if (carton == null)
            {
                this.StatusMessages.Add(string.Format("Carton {0} has been deleted", this.ScanText));
                this.ScanText = string.Empty;
            }
            else if (string.IsNullOrEmpty(carton.BundleId))
            {
                if (this.EmptyCarton)
                {
                    service.DeleteEmptyCarton(this.ScanText);
                }
                this.StatusMessages.Add(string.Format("Carton {0} is empty and cannot be modified", this.ScanText));
                this.ScanText = string.Empty;
            }
            else
            {
                IrregularAreaList                  = service.GetTransferAreas(PiecesRemoveFlag.Irregular).Select(p => Map(p));
                SamplesAreaList                    = service.GetTransferAreas(PiecesRemoveFlag.Samples).Select(p => Map(p));
                this.UpdatingRules.Pieces          = carton.Pieces;
                this.UpdatingRules.PriceSeasonCode = carton.PriceSeasonCode;
                this.UpdatingRules.QualityCode     = carton.QualityCode;
                this.UpdatingRules.VwhId           = carton.VwhId;
                this.QualificationRules.Rework     = carton.RemarkWorkNeeded ? ReworkStatus.NeedsRework : ReworkStatus.DoesNotNeedRework;
                this.UpdatingRules.SkuBarCode      = carton.SkuInCarton.UpcCode;
                this.UpdatingRules.SkuId           = carton.SkuInCarton.SkuId;
                this.QualificationRules.IsReserved = carton.IsReserved;
                this.SkuDescription                = carton.SkuInCarton.ToString();
                this.BundleId  = carton.BundleId;
                this.ShortName = carton.CartonArea.ShortName;
                this.UpdatingRules.LocationID = carton.LocationId;
                this.DestinationPalletId      = carton.PalletId;
            }
            var helper = new UrlHelper(context.RequestContext);

            if (helper.RouteCollection[DcmsLibrary.Mvc.PublicRoutes.DcmsConnect_SearchCarton1] != null)
            {
                this.UrlInquiryCarton = helper.RouteUrl(DcmsLibrary.Mvc.PublicRoutes.DcmsConnect_SearchCarton1, new
                {
                    id = carton.CartonId
                });
            }
        }
Beispiel #2
0
        public virtual ActionResult UpdateCartonOrPallet(ViewModelBase model)
        {
            if (!ModelState.IsValid)
            {
                //TC1:We get here when no update property specified
                return(AdaptiveResult(202, null, model));
            }

            if (string.IsNullOrEmpty(model.ScanText))
            {
                // TC2: Scan nothing and press Go.
                ModelState.AddModelError("", "Please scan carton/pallet.");
                return(AdaptiveResult(202, null, model));
            }

            try
            {
                if (_service.IsPallet(model.ScanText))
                {
                    // TC3:Pallet has been scanned
                    var cartons = _service.GetCartonsOnPallet(model.ScanText).ToArray();
                    if (cartons.Count() == 0)
                    {
                        model.StatusMessages.Add(string.Format("Pallet {0} does not exist.", model.ScanText));
                        return(AdaptiveResult(202, null, model));
                    }
                    if (model.ConfirmScanText != model.ScanText)
                    {
                        //TC4: Give a non matching confirmation scan
                        model.StatusMessages.Add(
                            string.Format("Please rescan Pallet {0} to confirm updating of {1} cartons.", model.ScanText,
                                          cartons.Count()));
                        return(AdaptiveResult(201, new RouteValueDictionary
                        {
                            { "ConfirmScan", model.ScanText }
                        }, model));
                    }

                    foreach (var carton in cartons)
                    {
                        EnsureCartonQualifies(carton, model.QualificationRules, true);
                        // If any carton does not qualify, we do not check other cartons
                        if (!ModelState.IsValid)
                        {
                            // TC5:Scan a pallet containg a non qualifying carton
                            return(AdaptiveResult(202, null, model));
                        }
                    }


                    var nUpdated = 0; // Number of cartons updated
                    using (var trans = _service.BeginTransaction())
                    {
                        foreach (var carton in cartons)
                        {
                            var bUpdated = _service.UpdateMoveCarton(carton, Map(model.UpdatingRules), model.UpdateFlags,
                                                                     model.UpdatingRules.ReasonCode);
                            if (bUpdated)
                            {
                                ++nUpdated;
                            }
                        }
                        trans.Commit();
                    }
                    if (nUpdated == cartons.Count())
                    {
                        // All cartons were updated
                        model.StatusMessages.Add(string.Format("{0} cartons updated.", nUpdated));
                    }
                    else
                    {
                        model.StatusMessages.Add(string.Format("{0} of {1} cartons needed updating", nUpdated,
                                                               cartons.Count()));
                    }
                    this.Response.AppendHeader("CartonCount", nUpdated.ToString());
                }
                else
                {
                    // TC6:Carton has been scanned
                    var currentCarton = _service.GetCarton(model.ScanText);
                    if (currentCarton == null)
                    {
                        // TC7:Scan invalid carton
                        ModelState.AddModelError("", string.Format("No such carton : {0}", model.ScanText));
                        return(AdaptiveResult(202, null, model));
                    }

                    EnsureCartonQualifies(currentCarton, model.QualificationRules, false);
                    if (!ModelState.IsValid)
                    {
                        // TC8:Scan a non qualifying carton
                        return(AdaptiveResult(202, null, model));
                    }
                    //Using transaction, because possibly UpdateCarton() or moveCarton() method can fail. In this case either process should not be completed.
                    using (var trans = _service.BeginTransaction())
                    {
                        var bUpdated = _service.UpdateMoveCarton(currentCarton, Map(model.UpdatingRules),
                                                                 model.UpdateFlags,
                                                                 model.UpdatingRules.ReasonCode);
                        if (bUpdated)
                        {
                            model.StatusMessages.Add(string.Format("Carton# {0} with SKU {1} updated.",
                                                                   currentCarton.CartonId,
                                                                   currentCarton.SkuInCarton.ToString()));
                            this.Response.AppendHeader("CartonCount", "1");
                        }
                        else
                        {
                            this.Response.AppendHeader("CartonCount", "0");
                        }
                        trans.Commit();
                    }
                }

                //Add seleted printer in cookie
                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);
                }
                // Giving printing message in success case when user select printer.
                if (!string.IsNullOrEmpty(model.PrinterId))
                {
                    _service.PrintCartonTicket(model.ScanText, model.PrinterId);
                    model.StatusMessages.Add(string.Format("Carton printed on '{0}' printer successfully.",
                                                           model.PrinterId));
                }
                model.OnCartonUpdated(_service);
                return(AdaptiveResult(202, null, model));
            }
            catch (Exception ex)
            {
                // Simulate the behavior of the obsolete HandleAjaxError attribute
                this.Response.StatusCode = 203;
                return(Content(ex.Message));
            }
        }