Пример #1
0
        /// <summary>
        /// Печать штрихового кода
        /// </summary>
        /// <param name="barcodeValue">Данные ШК</param>
        /// <param name="barcodeType">Тип ШК</param>
        public PrintBarcodeOperation(string barcodeValue, BarcodeType barcodeType) : base("PrintBarCode")
        {
            if (barcodeValue.IsNullOrEmptyOrWhiteSpace())
            {
                throw new ArgumentException(
                          string.Format(
                              ErrorStrings.ResourceManager.GetString("StringFormatError"),
                              this.GetType().GetProperty(nameof(Value)).GetDisplayName()),
                          nameof(barcodeValue));
            }

            var isBarcodeValueValid = false;

            switch (barcodeType)
            {
            case BarcodeType.EAN8:
                if (Regex.IsMatch(barcodeValue, RegexHelper.BarcodeEAN8Pattern))
                {
                    isBarcodeValueValid = true;
                }

                break;

            case BarcodeType.EAN13:
                if (Regex.IsMatch(barcodeValue, RegexHelper.BarcodeEAN13Pattern))
                {
                    isBarcodeValueValid = true;
                }

                break;

            case BarcodeType.CODE39:
                if (Regex.IsMatch(barcodeValue, RegexHelper.BarcodeCODE39Pattern))
                {
                    isBarcodeValueValid = true;
                }

                break;

            case BarcodeType.QR:
                if (barcodeValue.Length < 256)
                {
                    isBarcodeValueValid = true;
                }

                break;
            }

            if (!isBarcodeValueValid)
            {
                throw new ArgumentException(
                          string.Format(ErrorStrings.ResourceManager.GetString("BarcodeValueFormatError"),
                                        barcodeType.GetDisplayName()), nameof(barcodeValue));
            }

            BcType = barcodeType;
            Value  = barcodeValue;
        }
Пример #2
0
        /// <summary>
        /// Элемент штрихкода
        /// </summary>
        /// <param name="barcodeValue">Данные ШК</param>
        /// <param name="barcodeType">Тип ШК</param>
        public BarcodeDocumentParams(string barcodeValue, BarcodeType barcodeType) : base(PrintDocumentType.Barcode)
        {
            if (barcodeValue.IsNullOrEmptyOrWhiteSpace())
            {
                throw new ArgumentException(
                          string.Format(ErrorStrings.ResourceManager.GetString("RequiredError"),
                                        this.GetType().GetProperty(nameof(Barcode)).GetDisplayName()),
                          nameof(barcodeValue));
            }

            var isBarcodeValueValid = false;

            switch (barcodeType)
            {
            case BarcodeType.EAN8:
                if (Regex.IsMatch(barcodeValue, RegexHelper.BarcodeEAN8Pattern))
                {
                    isBarcodeValueValid = true;
                }

                break;

            case BarcodeType.EAN13:
                if (Regex.IsMatch(barcodeValue, RegexHelper.BarcodeEAN13Pattern))
                {
                    isBarcodeValueValid = true;
                }

                break;

            case BarcodeType.CODE39:
                if (Regex.IsMatch(barcodeValue, RegexHelper.BarcodeCODE39Pattern))
                {
                    isBarcodeValueValid = true;
                }

                break;

            case BarcodeType.QR:
                if (barcodeValue.Length < 7089)
                {
                    isBarcodeValueValid = true;
                }

                break;

            case BarcodeType.UPCA:
                if (Regex.IsMatch(barcodeValue, RegexHelper.BarcodeUPCAPattern))
                {
                    isBarcodeValueValid = true;
                }

                break;

            case BarcodeType.UPCE:
                if (Regex.IsMatch(barcodeValue, RegexHelper.BarcodeUPCEPattern))
                {
                    isBarcodeValueValid = true;
                }

                break;

            case BarcodeType.CODE93:
                if (Regex.IsMatch(barcodeValue, RegexHelper.BarcodeCODE93Pattern))
                {
                    isBarcodeValueValid = true;
                }

                break;

            case BarcodeType.CODE128:
                if (Regex.IsMatch(barcodeValue, RegexHelper.BarcodeCODE128Pattern))
                {
                    isBarcodeValueValid = true;
                }

                break;

            case BarcodeType.CODABAR:
                if (Regex.IsMatch(barcodeValue, RegexHelper.BarcodeCODABARPattern))
                {
                    isBarcodeValueValid = true;
                }

                break;

            case BarcodeType.ITF:
                if (Regex.IsMatch(barcodeValue, RegexHelper.BarcodeITFPattern))
                {
                    isBarcodeValueValid = true;
                }

                break;

            case BarcodeType.ITF14:
                if (Regex.IsMatch(barcodeValue, RegexHelper.BarcodeITF14Pattern))
                {
                    isBarcodeValueValid = true;
                }

                break;

            case BarcodeType.GS1_128:
                if (Regex.IsMatch(barcodeValue, RegexHelper.BarcodeGS1_128Pattern))
                {
                    isBarcodeValueValid = true;
                }

                break;

            case BarcodeType.PDF417:
                if (Regex.IsMatch(barcodeValue, RegexHelper.BarcodePDF417Pattern))
                {
                    isBarcodeValueValid = true;
                }

                break;

            case BarcodeType.CODE39_EXTENDED:
                if (Regex.IsMatch(barcodeValue, RegexHelper.BarcodeCODE39_EXTENDEDPattern))
                {
                    isBarcodeValueValid = true;
                }

                break;
            }

            if (!isBarcodeValueValid)
            {
                throw new ArgumentException(
                          string.Format(ErrorStrings.ResourceManager.GetString("BarcodeValueFormatError"),
                                        barcodeType.GetDisplayName()), nameof(barcodeValue));
            }

            Barcode     = barcodeValue;
            BarcodeType = barcodeType;
        }