Пример #1
0
        /// <summary>
        /// 001977684 056 100353
        /// </summary>
        /// <param name="barcode"></param>
        /// <returns></returns>
        public virtual bool ParseBarcode(string barcode, ref BarcodeData data)
        {
            if (string.IsNullOrWhiteSpace(barcode))
            {
                throw new ArgumentException("empty barcode", "barcode");
            }

            if (barcode.Length != this.Length)
            {
                return(false);
            }

            //Remove check digits if any
            var voucherId =
                this.VoucherID.Item2 <= 0 ?
                int.Parse(barcode.Substring(this.VoucherID.Item1)) :
                int.Parse(barcode.Substring(this.VoucherID.Item1, this.VoucherID.Item2));

            var countryId =
                this.CountryID.Item2 <= 0 ?
                int.Parse(barcode.Substring(this.CountryID.Item1)) :
                int.Parse(barcode.Substring(this.CountryID.Item1, this.CountryID.Item2));

            var retailerId = this.RetailerID != null ?
                             this.RetailerID.Item2 <= 0 ?
                             int.Parse(barcode.Substring(this.RetailerID.Item1)) :
                             int.Parse(barcode.Substring(this.RetailerID.Item1, this.RetailerID.Item2)) :
                             0;

            data = new BarcodeData(countryId, retailerId, voucherId, barcode);
            return(true);
        }
Пример #2
0
        public override bool ParseBarcode(string barcode, ref BarcodeData data)
        {
            if (barcode.IndexOf("82620") != 9)
            {
                return(false);
            }

            return(base.ParseBarcode(barcode, ref data));
        }
Пример #3
0
        public void Test()
        {
            if (string.IsNullOrEmpty(Sample))
            {
                throw new Exception("Barcode sample not valid");
            }

            BarcodeData data = null;

            if (!ParseBarcode(Sample.Replace(" ", ""), ref data))
            {
                throw new Exception("Barcode template not valid");
            }

            data.Test();
        }
Пример #4
0
        public BarcodeData Match(string barcode)
        {
            ConcurrentBag <BarcodeConfig> b;

            if (HttpContext.Current != null)
            {
                b = (ConcurrentBag <BarcodeConfig>)HttpContext.Current.Application[Strings.LIST_OF_BARCODECONFIGS];
            }
            else
            {
                b = ms_configBags;
            }

            BarcodeData data = null;

            foreach (var item in b)
            {
                if (item.ParseBarcode(barcode, ref data))
                {
                    return(data);
                }
            }
            return(data);
        }