public RepairBarcodeValidateResponse ValidateBarcodeFault([FromBody]ReworkBarcodeValidateRequest request, string barcode)
        {
            ItemDetailsModel model = new ItemDetailsModel();
            RequirementsDataContext db = new RequirementsDataContext();
            RepairBarcodeValidateResponse response = new RepairBarcodeValidateResponse();

            if (request.SkuInfo.Count() > 0) {
                var sku = request.SkuInfo[0].Sku;
                var lineId = request.SkuInfo[0].LineId;
                var cstype = request.BarcodeFault.CSType;
                var bcregex = db.BarcodeRegexes.Where(r=>r.CSType == request.BarcodeFault.CSType && r.LineId == lineId).FirstOrDefault();
                if (bcregex != null) {

                    var regex = new Regex(@bcregex.Regex.Trim());
                    var bcmatch = regex.Match(barcode);
                    if (bcmatch.Success)    //validate barcode
                    {
                        //still need to validate barcode
                        var itemInfo = model.GetItemInfo(sku);
                        var partItem = itemInfo.ItemInfos.Where(p => p.PartIndex == bcregex.PartIndex).FirstOrDefault();

                        switch (cstype)
                        {
                            case 1:
                            case 2:
                                var pretensionerPart = bcmatch.Groups["PART"].Value;
                                var pretensionerTrack = bcmatch.Groups["TRACKING"].Value;

                                if (partItem != null)
                                {
                                    string expectedPretPart = model.GetOptionValue(partItem, (int)bcregex.OptionNumber);

                                    if (expectedPretPart == pretensionerPart)
                                    {
                                        //part okay to update and save
                                        response.Success = true;
                                    }
                                    else
                                    {
                                        response.ErrorMessage = "Ops, Wrong Part Expecting: " + expectedPretPart;
                                        response.ExpectedValue = expectedPretPart;
                                        response.Success = false;
                                    }
                                }

                                break;
                            case 7:
                            case 8:
                                var headrestPart = bcmatch.Groups["PARTNO"].Value;
                                string expectedHeadRestPart = model.GetOptionValue(partItem, (int)bcregex.OptionNumber);
                                if (expectedHeadRestPart.IndexOf(headrestPart) != -1)
                                {
                                    //part okay to update and save
                                    response.Success = true;
                                }
                                else
                                {
                                    response.ErrorMessage = "Ops, Wrong Part Expecting: " + expectedHeadRestPart;
                                    response.ExpectedValue = expectedHeadRestPart;
                                    response.Success = false;
                                }

                                break;
                            case 11:
                            case 12:
                                var backDocusew = bcmatch.Groups["BC"].Value;
                                response.Success = true;
                                break;
                            case 23:
                            case 24:
                                var airbagTrack = bcmatch.Groups["AIRBAGTRCK"].Value;
                                response.Success = true;
                                break;
                            default:
                                break;
                        }

                        return response;
                    }
                    else
                    {
                        return new RepairBarcodeValidateResponse
                        {
                            ErrorMessage = "Error: Incorrect Barcode Pattern Match",
                            Success = false,
                        };
                    }
                }
            }

            return new RepairBarcodeValidateResponse
            {
                ErrorMessage = "Error: Cannot Locate Part Info",
                Success = false,
            };
        }
        public BarcodeSwap GetSwapBarcodeSerial(int palletId, string original, string replace)
        {
            MesDataContext dbMes = new MesDataContext();
            RequirementsDataContext db = new RequirementsDataContext();

            int lineId = 0;
            if (palletId > 5000)
                lineId = 1;

            var palletHdr = (from p in dbMes.PalletInfos
                             where p.PalletNbr == palletId && (p.Pallet_Type == "S1" || p.Pallet_Type == "S2")
                             select p).FirstOrDefault();

            if (palletHdr != null)
            {

                var jobInfo = (from j in dbMes.MasterJobTables
                               where j.Job_ID == palletHdr.Job_ID
                               select j).FirstOrDefault();

                if (jobInfo != null)
                {
                    var bcregex = db.BarcodeRegexes.ToList();
                    foreach (var reg in bcregex)
                    {
                        var regex = new Regex(reg.Regex.Trim());
                        var bcmatch = regex.Match(original);
                        if (bcmatch.Success)    //validate barcode
                        {
                            //pretensioner
                            if (reg.CSType == 1 || reg.CSType == 2)
                            {
                                var pretensionerTrack = bcmatch.Groups["TRACKING"].Value;
                                original = pretensionerTrack;
                                break;
                            }
                        }
                    }

                    var result = (from b in dbMes.IWS_SP_GetJobSerialByJobId(jobInfo.Job_ID).Where(s=>s.Serial_Nbr.Trim() == original.Trim())
                                join t in dbMes.EDS_cfg_Component_Serialization_Types on b.CS_Type equals t.CS_Type
                                select new BarcodeSwap {
                                    Description = t.Description_Short.Trim(),
                                    JobId = jobInfo.Job_ID,
                                    OriginalBarcode = original,
                                    ReplaceBarcode = replace
                                }).FirstOrDefault();

                    if (result != null)
                        return result;
                }
            }



            throw new HttpResponseException(
                            HttpErrorResponse.GetHttpErrorResponse(
                            HttpStatusCode.NotFound, "Error", string.Format("Error Has Occured")));
        }
Example #3
0
 private List<BarcodeRequirementInfo> GetBarcodeValidationRequirements(List<SkuInfo> skuInfos)
 {
     RequirementsDataContext db = new RequirementsDataContext();
     var bcreqs = (from b in db.BarcodeRequirementInfos.Where(b => b.Obsolete == false).ToList()
                   join part in skuInfos on b.LineId equals part.LineId
                   where ((part.BuildCode & b.SeatOptions) == (part.BuildCode & b.SeatOptions2Check)) &&
                   ((part.BuildCode & b.SeatOptions) == (b.SeatOptions & b.SeatOptions2Check))
                   select b).ToList();
     return bcreqs;
 }