Пример #1
0
        public void Encode_ContentTooLong_ShouldThrowException()
        {
            Action action = () => Code128.Encode("123456789012345678901234567890123456789012345678901234567890123456789012345678901");

            action.Should().Throw <ArgumentException>()
            .And.Message.StartsWith("Content length should be between 1 and 80 but got 81");
        }
Пример #2
0
        public void TestDefault()
        {
            var barcode = new Code128
            {
                EncodeThis = "AbC1234567890!"
            };

            var payload = barcode.Build();

            Assert.NotNull(payload);
            Assert.IsNotEmpty(payload);

            var expected = new byte[]
            {
                0x1D, 0x68, 0x64,   // BarcodeDotHeight
                0x1D, 0x77, 0x02,   // BarcodeWidthMultiplier
                0x1D, 0x48, 0x00,   // HRI Position
                0x1D, 0x66, 0x00,   // BarcodeFont
                0x1D, 0x6B, 0x08,   // Code128 Form 1
                0x7B, 0x41,         // Mode A
                (byte)'A', (byte)'b', (byte)'C',
                (byte)'1', (byte)'2', (byte)'3', (byte)'4', (byte)'5', (byte)'6',
                (byte)'7', (byte)'8', (byte)'9', (byte)'0', (byte)'!', (byte)'\0',
            };

            Assert.AreEqual(expected, payload);
        }
Пример #3
0
        public void Encode_EmptyString_ShouldThrowException()
        {
            Action action = () => Code128.Encode(string.Empty);

            action.Should().Throw <ArgumentException>()
            .And.Message.StartsWith("Content length should be between 1 and 80 but got 0");
        }
Пример #4
0
        public void Render_Barcode1D()
        {
            // Arrange
            IBarcodeIntCS barcode  = Code128.Encode("Wikipedia");
            var           renderer = new SvgRenderer();

            // Act
            string svg;

            using (var stream = new MemoryStream())
                using (var reader = new StreamReader(stream))
                {
                    renderer.Render(barcode, stream);
                    stream.Position = 0;
                    svg             = reader.ReadToEnd();
                }

            // Assert
            svg.Length.Should().BeGreaterOrEqualTo(0);

            string expected;

            using (Stream stream = typeof(SvgRendererTests).Assembly.GetManifestResourceStream("Barcoder.Renderer.Svg.Tests.ExpectedSvgOutput.txt"))
                using (var reader = new StreamReader(stream))
                    expected = reader.ReadToEnd().Replace("\r", "").Replace("\n", "");

            var actual = svg.Replace("\r", "").Replace("\n", "");

            actual.Should().Be(expected);
        }
Пример #5
0
        /// <summary>
        /// 打印弹出页面
        /// </summary>
        /// <returns></returns>
        public ActionResult NewPrintOrder(string orderid)
        {
            OrderInfo order = ServiceHelper.Create <IOrderService>().GetOrder(long.Parse(orderid));

            foreach (var r in order.OrderItemInfo)
            {
                r.Id    = r.Id;
                r.CASNo = ServiceHelper.Create <ChemCloud.IServices.IProductService>().GetProduct(r.ProductId) != null?ServiceHelper.Create <ChemCloud.IServices.IProductService>().GetProduct(r.ProductId).CASNo : "";

                r.ThumbnailsUrl = ServiceHelper.Create <ChemCloud.IServices.IProductService>().GetProduct(r.ProductId) != null?ServiceHelper.Create <ChemCloud.IServices.IProductService>().GetProduct(r.ProductId).ImagePath : "";

                r.MolecularFormula = ServiceHelper.Create <ChemCloud.IServices.IProductService>().GetProduct(r.ProductId) != null?ServiceHelper.Create <ChemCloud.IServices.IProductService>().GetProduct(r.ProductId).MolecularFormula : "";
            }
            if (order != null && !string.IsNullOrEmpty(order.ShipOrderNumber))
            {
                Code128 _Code = new Code128();
                System.Drawing.Bitmap imgTemp = _Code.GetCodeImage(order.ShipOrderNumber, Code128.Encode.Code128A);
                string ImagePath = System.AppDomain.CurrentDomain.BaseDirectory + "Storage/Code128/";

                if (!Directory.Exists(ImagePath))
                {
                    Directory.CreateDirectory(ImagePath);
                }
                string path = order.ShipOrderNumber + DateTime.Now.ToString("yyyyMMddHHmmss") + ".gif";
                ImagePath = ImagePath + path;

                imgTemp.Save(ImagePath, System.Drawing.Imaging.ImageFormat.Gif);
                ViewBag.CodePath = ChemCloud.Core.Common.GetRootUrl("") + "/Storage/Code128/" + path;
            }
            else
            {
                ViewBag.CodePath = "";
            }
            return(View(order));
        }
Пример #6
0
        public void TestForm2()
        {
            var barcode = new Code128
            {
                EncodeThis  = "AbC1234567890!",
                Form        = 2,
                HriPosition = HRIPositions.Above,
                Mode        = Code128.Modes.B
            };

            var payload = barcode.Build();

            Assert.NotNull(payload);
            Assert.IsNotEmpty(payload);

            var expected = new byte[]
            {
                0x1D, 0x68, 0x64,   // BarcodeDotHeight
                0x1D, 0x77, 0x02,   // BarcodeWidthMultiplier
                0x1D, 0x48, 0x01,   // HRI Position
                0x1D, 0x66, 0x00,   // BarcodeFont
                0x1D, 0x6B, 0x49,   // ITF Form 2
                (byte)barcode.EncodeThis.Length,
                0x7B, 0x42,         // Mode B
                (byte)'A', (byte)'b', (byte)'C',
                (byte)'1', (byte)'2', (byte)'3', (byte)'4', (byte)'5', (byte)'6',
                (byte)'7', (byte)'8', (byte)'9', (byte)'0', (byte)'!', (byte)'\0',
            };

            Assert.AreEqual(expected, payload);
        }
Пример #7
0
        public static void Create(string text, string fileName)
        {
            var code = new Code128();

            code.ValueFont = new Font("宋体", 12f);
            var codeImage = code.GetCodeImage(text, Code128.Encode.Code128B);

            codeImage.Save(fileName, ImageFormat.Jpeg);
        }
        /// <summary>
        ///     Tests the code128 C_B.
        /// </summary>
        /// <externalUnit/>
        /// <revision revisor="dev13" date="11/19/2009" version="1.1.3.7">
        ///     Added documentation header
        /// </revision>
        private static void TestCode128C_b()
        {
            string text    = "982739487";
            Bitmap barcode = Code128.Encode(text, 2, 0.125F, 96);

            barcode.RotateFlip(RotateFlipType.Rotate90FlipY);

            barcode.Save(text + ".bmp", ImageFormat.Bmp);
        }
        /// <summary>
        ///     Tests the code128 C.
        /// </summary>
        /// <externalUnit/>
        /// <revision revisor="dev13" date="11/19/2009" version="1.1.3.7">
        ///     Added documentation header
        /// </revision>
        private static void TestCode128C()
        {
            string text    = "98723493871103000000";
            Bitmap barcode = Code128.Encode(text, 1, 0.125F, 96, 12, 0);

            PixelChar.DrawChar(barcode, 'M', 0, 2);

            Bitmap   pixelchar = new Bitmap(70, 40);
            Graphics g         = Graphics.FromImage(pixelchar);

            g.Clear(Color.White);
            g.Dispose();
            pixelchar.SetResolution(96, 96);
            for (int i = 0; i < 7; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    if (j * 7 + i < 26)
                    {
                        char ch = (char)(j * 7 + i + 65);
                        PixelChar.DrawChar(pixelchar, ch, 10 * i, 10 * j);
                    }
                }
            }

            MemoryInputStream misStream = new MemoryInputStream(barcode, 100);

            barcode.Dispose();
            barcode.Dispose();
            DSxInput pdfInput = new DSxInput(misStream);

            DSxSystem.setLicenseKey(
                "[Insert your license key here]");
            DSxTask task = new DSxTask();

            PDFxDocument pdfDoc  = PDF.createDocument(task);
            PDFxContext  context = pdfDoc.getContext();
            PDFxPage     pdfPage = pdfDoc.createCustomPage(5, 2);

            PDFxImage bar = PDFxImage.createImageFromJPEG(pdfInput);
            double    dpi = 96D,
                      k   = 72D / dpi;

            pdfPage.drawImage(
                18, 18, k * bar.getWidth(), k * bar.getHeight(), bar);

            bar =
                PDFxImage.createImageFromJPEG(
                    new DSxInput(new MemoryInputStream(pixelchar, 100)));
            pixelchar.Dispose();
            pdfPage.drawImage(
                18, 72, k * bar.getWidth(), k * bar.getHeight(), bar);

            DSxPDFDocument dsDocument = new DSxPDFDocument(pdfDoc);

            dsDocument.save(new DSxOutput(@"bin\Debug\DSxInput2.pdf"));
        }
Пример #10
0
        private void InitializeType()
        {
            IBarcode barcode;

            switch (_type)
            {
            case Type.Code128:
                barcode = new Code128(_data);
                break;

            case Type.Code128A:
                barcode = new Code128(_data, Code128.Code128Type.A);
                break;

            case Type.Code128B:
                barcode = new Code128(_data, Code128.Code128Type.B);
                break;

            case Type.Code128C:
                barcode = new Code128(_data, Code128.Code128Type.C);
                break;

            case Type.Code11:
                barcode = new Code11(_data);
                break;

            case Type.Code39:
                barcode = new Code39(_data);
                break;

            case Type.Code39E:
                barcode = new Code39(_data, true);
                break;

            case Type.Code93:
                barcode = new Code93(_data);
                break;

            case Type.EAN8:
                barcode = new EAN8(_data);
                break;

            case Type.EAN13:
                barcode = new EAN13(_data);
                break;

            case Type.Codabar:
                barcode = new Codabar(_data);
                break;

            default:
                barcode = new Code128(_data);
                break;
            }

            _encodedData = barcode.GetEncoding();
        }
Пример #11
0
        public Barcode(string data, TYPE iType)
        {
            this.RawData      = data;
            this.Encoded_Type = iType;
            switch (iType)
            {
            case TYPE.EAN13:
                ibarcode = new EAN13(data);
                country  = ((EAN_UPCBase)ibarcode).Country;
                break;

            case TYPE.EAN8:
                ibarcode = new EAN8(data);
                country  = ((EAN_UPCBase)ibarcode).Country;
                break;

            case TYPE.UPCA:
                ibarcode = new UPCA(data);
                break;

            case TYPE.UPCE:
                ibarcode = new UPCE(data);
                break;

            case TYPE.Interleaved2of5:
                ibarcode = new Interleaved2of5(data);
                break;

            case TYPE.ITF14:
                ibarcode = new ITF14(data);
                break;

            case TYPE.CODE128A:
                ibarcode = new Code128(data, CharSet.A);
                break;

            case TYPE.CODE128B:
                ibarcode = new Code128(data, CharSet.B);
                break;

            case TYPE.CODE128C:
                ibarcode = new Code128(data, CharSet.C);
                break;

            case TYPE.CODE128:
                ibarcode = new Code128(data, CharSet.Auto);
                break;

            case TYPE.GS1_128:
                ibarcode = new GS1_128(data);
                break;
            }
            RawData     = ibarcode.RawData;
            EncodeValue = ibarcode.GetEncode();
            SetFontSize(RawData);
        }
Пример #12
0
        static void Main(string[] args)
        {
            Code128 code128 = new Code128("test taaa", Code128.CODESET.B);

            Console.WriteLine(code128.GetCode128String);

            Code128 code128w = new Code128("test taaa", Code128.CODESET.B, Code128.RETURNCOLUMN.Widths);

            Console.WriteLine(code128w.GetCode128String);
        }
Пример #13
0
        public void TestEmpty()
        {
            var barcode = new Code128
            {
                EncodeThis = ""
            };

            var payload = barcode.Build();

            Assert.NotNull(payload);
            Assert.IsEmpty(payload);
        }
Пример #14
0
        /// <summary>
        /// 保存条形码图片
        /// </summary>
        /// <param name="Num">条形码值</param>
        /// <param name="imgSaveUrl">图片路径</param>
        /// <param name="imgName">图片名称,不输入默认为条形码值(不带图片后缀)</param>
        public static void code128_SaveImg(string Num, string imgSaveUrl, string imgName)
        {
            if (imgName == "")
            {
                imgName = Num;
            }
            Code128 _Code = new Code128();

            _Code.ValueFont = new Font("宋体", 10);
            Bitmap Img = _Code.GetCodeImage(Num, Code128.Encode.Code128A);

            Img.Save(imgSaveUrl + imgName + ".jpg", ImageFormat.Jpeg);
        }
Пример #15
0
        /// <summary>
        /// 生成条形码
        /// </summary>
        /// <param name="barNumber">条形码,位数必须为2的倍数</param>
        public Image CreateBarCode(string barNumber)
        {
            if (barNumber.Length % 2 == 1)
            {
                barNumber = "0" + barNumber;
            }
            Code128 code = new Code128();

            //code.ValueFont = new Font("Arial", 9); //显示条码文字字体
            code.Height = 38;
            Bitmap image = code.GetCodeImage(barNumber, BarCode.Code128.Encode.Code128C);

            return(image);
            //image.Save("d:\\barcode.jpg");
        }
Пример #16
0
        private void button1_Click(object sender, EventArgs e)
        {
            Code128 _Code = new Code128();

            _Code.ValueFont = new Font("宋体", 9);
            _Code.Height    = 50;
            System.Drawing.Bitmap imgTemp = _Code.GetCodeImage("12345678945645", Code128.Encode.EAN128, "ceshi ", "ceshi ");
            string path = System.AppDomain.CurrentDomain.BaseDirectory + "\\" + "BarCode.gif";

            imgTemp.Save(path, System.Drawing.Imaging.ImageFormat.Gif);
            _Code.Code128Path.Add(path);
            _Code.Code128Path.Add(path);
            _Code.Code128Path.Add(path);
            _Code.BarCodeShow();
        }
Пример #17
0
        public void Encode_ShouldUseATable()
        {
            bool result;

            bool T(byte currentEncoding, params char[] nextChars)
            => Code128.ShouldUseATable(nextChars, currentEncoding);

            result = T(0, '\r', 'A');
            result.Should().BeTrue();

            result = T(0, Code128Constants.FNC1, '\r');
            result.Should().BeTrue();

            result = T(0, Code128Constants.FNC1, '1', '2', '3');
            result.Should().BeFalse();
        }
Пример #18
0
        internal override void Render()
        {
            RenderFilling();

            BarcodeFormatInfo formatInfo = (BarcodeFormatInfo)this.renderInfo.FormatInfo;
            Area  contentArea            = this.renderInfo.LayoutInfo.ContentArea;
            XRect destRect = new XRect(contentArea.X, contentArea.Y, formatInfo.Width, formatInfo.Height);

            BarCode gfxBarcode = null;

            switch (this.barcode.Type)
            {
            case BarcodeType.Barcode128:
                gfxBarcode = new Code128();
                break;

            case BarcodeType.Barcode25i:
                gfxBarcode = new Code2of5Interleaved();
                break;

            case BarcodeType.Barcode39:
                gfxBarcode = new Code3of9Standard();
                break;

            case BarcodeType.BarcodeEan13:
                gfxBarcode = new Ean13();
                break;

            default:
                break;
            }

            // if gfxBarcode is null, the barcode type is not supported
            if (gfxBarcode != null)
            {
                if (barcode.Text)
                {
                    gfxBarcode.TextLocation = TextLocation.BelowEmbedded;
                }
                gfxBarcode.Text      = this.barcode.Code;
                gfxBarcode.Direction = CodeDirection.LeftToRight;
                gfxBarcode.Size      = new XSize(ShapeWidth, ShapeHeight);
                this.gfx.DrawBarCode(gfxBarcode, XBrushes.Black, destRect.Location);
            }

            RenderLine();
        }
Пример #19
0
                    "1100011101011")] // STOP
        public void Encode(string txt, string testResult)
        {
            IBarcodeIntCS code = Code128.Encode(txt);

            code.Bounds.X.Should().Be(testResult.Length);
            code.Bounds.Y.Should().Be(1);
            code.Metadata.CodeKind.Should().Be(BarcodeType.Code128);
            code.Metadata.Dimensions.Should().Be(1);

            string encoded = string.Empty;
            int    i       = 0;

            foreach (var r in testResult)
            {
                encoded += code.At(i++, 0) ? "1" : "0";
            }
            encoded.Should().Be(testResult);
        }
Пример #20
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Code128 _Code = new Code128();
            _Code.Height = 60;

            _Code.ValueFont = new Font("宋体", 1);
            string num = Request["num"].ToString();
            System.Drawing.Image _CodeImage = _Code.GetCodeImage(num, Code128.Encode.Code128A);
            System.IO.MemoryStream _Stream = new System.IO.MemoryStream();
            _CodeImage.Save(_Stream, System.Drawing.Imaging.ImageFormat.Jpeg);

            Response.ContentType = "image/jpeg";
            Response.Clear();
            Response.BufferOutput = true;
            Response.BinaryWrite(_Stream.GetBuffer());
            Response.Flush();
        }
    }
Пример #21
0
        public void Encode_ShouldUseCTable()
        {
            bool result;

            bool T(byte currentEncoding, params char[] nextChars)
            => Code128.ShouldUseCTable(nextChars, currentEncoding);

            result = T(Code128Constants.StartCSymbol, Code128Constants.FNC1, '1', '2');
            result.Should().BeTrue();

            result = T(Code128Constants.StartCSymbol, Code128Constants.FNC1, '1');
            result.Should().BeFalse();

            result = T(Code128Constants.StartCSymbol, '0', Code128Constants.FNC1, '1');
            result.Should().BeFalse();

            result = T(Code128Constants.StartBSymbol, '0', '1', Code128Constants.FNC1, '2', '3');
            result.Should().BeTrue();

            result = T(Code128Constants.StartBSymbol, '0', '1', Code128Constants.FNC1);
            result.Should().BeFalse();
        }
Пример #22
0
        /// <summary>
        /// Выполняет поиск стандартных элементов в документе по значению <paramref name="name"/>.
        /// Генерирует изображение в формате png, представляющее штрих код соответствующий страндарту Code128,
        /// на основе значения <c><paramref name="value"/>.ToString()</c>.
        /// Извлекает из наденых элементов дочерний элемент, представляющий контейнер изображения
        /// и заполняет сгенерированным изображением.
        /// </summary>
        /// <param name="name">Имя целевого(ых) стандартных элементов.</param>
        /// <param name="value">
        /// Ссылка на объект, строковое представление которого необходимо необходимо закодировать.
        /// </param>
        /// <exception cref="InvalidSdtElementException">
        /// Возникает если дерево дочерних элементов <see cref="SdtElement"/> содержит недопустимые элементы
        /// или отсутствует обязательный дочерний элемент.
        /// </exception>
        protected void FillBarcode(string name, object value)
        {
            name.ThrowIfNullOrWhiteSpace(nameof(name));
            value.ThrowIfNull(nameof(value));

            try
            {
                var imageStream    = new MemoryStream();
                var relationshipId = new StringValue(string.Empty);

                using (var barcodeImage = new Code128().Barcode(value.ToString(), false, BarWeight.Double, 40, true))
                {
                    barcodeImage.Save(imageStream, ImageFormat.Png);
                    imageStream.Position = 0;
                }

                foreach (var element in _elemetns.Where(element => element.SdtProperties.GetFirstChild <SdtAlias>()?.Val == name))
                {
                    relationshipId = element.Descendants <Blip>().Single().Embed;

                    FeedDataIfExistImagePart(_mainDocumentPart, relationshipId, imageStream);

                    foreach (var footerPart in _mainDocumentPart.FooterParts)
                    {
                        FeedDataIfExistImagePart(footerPart, relationshipId, imageStream);
                    }

                    foreach (var headerPart in _mainDocumentPart.HeaderParts)
                    {
                        FeedDataIfExistImagePart(headerPart, relationshipId, imageStream);
                    }
                }
            }
            catch (InvalidOperationException)
            {
                throw new InvalidSdtElementException(name);
            }
        }
Пример #23
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.Params["wireids"] != null)
        {
            string v_wireids = Request.Params["wireids"].ToString();

            Code128 MyCode = new Code128();

            //條碼高度
            MyCode.Height = 100;

            //可見號碼
            MyCode.ValueFont = new Font("細明體", 18, FontStyle.Regular);

            //產生條碼
            System.Drawing.Image img = MyCode.GetCodeImage(v_wireids, Code128.Encode.Code128A);

            //在網頁上輸出
            Response.Clear();
            Response.ContentType = "image/jpeg";
            img.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
        }
    }
Пример #24
0
        private void InitializeType()
        {
            IBarcode barcode;

            switch (_type)
            {
            case Type.Code128:
                barcode = new Code128(_data);
                break;

            case Type.Code11:
                barcode = new Code11(_data);
                break;

            case Type.Code39:
                barcode = new Code39(_data);
                break;

            case Type.Code93:
                barcode = new Code93(_data);
                break;

            case Type.EAN8:
                barcode = new EAN8(_data);
                break;

            case Type.EAN13:
                barcode = new EAN13(_data);
                break;

            default:
                barcode = new Code128(_data);
                break;
            }

            _encodedData = barcode.GetEncoding();
        }
Пример #25
0
        /// <summary>
        /// 物流面单打印
        /// </summary>
        /// <param name="orderid"></param>
        /// <returns></returns>
        public ActionResult NewPrintExpress(string orderid)
        {
            OrderInfo order = ServiceHelper.Create <IOrderService>().GetOrder(long.Parse(orderid));

            foreach (var r in order.OrderItemInfo)
            {
                r.Id    = r.Id;
                r.CASNo = ServiceHelper.Create <ChemCloud.IServices.IProductService>().GetProduct(r.ProductId) != null?ServiceHelper.Create <ChemCloud.IServices.IProductService>().GetProduct(r.ProductId).CASNo : "";

                r.ThumbnailsUrl = ServiceHelper.Create <ChemCloud.IServices.IProductService>().GetProduct(r.ProductId) != null?ServiceHelper.Create <ChemCloud.IServices.IProductService>().GetProduct(r.ProductId).ImagePath : "";

                r.MolecularFormula = ServiceHelper.Create <ChemCloud.IServices.IProductService>().GetProduct(r.ProductId) != null?ServiceHelper.Create <ChemCloud.IServices.IProductService>().GetProduct(r.ProductId).MolecularFormula : "";
            }

            if (order != null && !string.IsNullOrEmpty(order.ShipOrderNumber))
            {
                //条形码
                Code128 _Code = new Code128();
                System.Drawing.Bitmap imgTemp = _Code.GetCodeImage(order.ShipOrderNumber, Code128.Encode.Code128A);
                string ImagePath = System.AppDomain.CurrentDomain.BaseDirectory + "Storage/Code128/";

                if (!Directory.Exists(ImagePath))
                {
                    Directory.CreateDirectory(ImagePath);
                }
                string path = order.ShipOrderNumber + DateTime.Now.ToString("yyyyMMddHHmmss") + ".gif";
                ImagePath = ImagePath + path;

                imgTemp.Save(ImagePath, System.Drawing.Imaging.ImageFormat.Gif);
                ViewBag.CodePath = ChemCloud.Core.Common.GetRootUrl("") + "/Storage/Code128/" + path;

                if (ServiceHelper.Create <IChemCloud_OrderWithCoaService>().GetChemCloud_OrderWithCoaByOrderid(long.Parse(orderid)) == null)
                {
                    ViewBag.QRcode = null;
                }
                else
                {
                    //二维码
                    string CoaNo = ServiceHelper.Create <IChemCloud_OrderWithCoaService>().GetChemCloud_OrderWithCoaByOrderid(long.Parse(orderid)).CoaNo;
                    if (!string.IsNullOrEmpty(CoaNo))
                    {
                        CoaNo = ChemCloud.Core.Common.GetRootUrl("") + "/search/Search_COA?key=" + CoaNo;
                        QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
                        qrCodeEncoder.QRCodeEncodeMode   = QRCodeEncoder.ENCODE_MODE.BYTE;
                        qrCodeEncoder.QRCodeScale        = 2;
                        qrCodeEncoder.QRCodeVersion      = 6;
                        qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;
                        System.Drawing.Image image = qrCodeEncoder.Encode(CoaNo);//二维码内容
                        string filename            = DateTime.Now.ToString("yyyymmddhhmmssfff").ToString() + ".jpg";
                        string filepath            = Server.MapPath(@"~\Temp\") + filename;
                        System.IO.FileStream fs    = new System.IO.FileStream(filepath, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write);
                        image.Save(fs, System.Drawing.Imaging.ImageFormat.Jpeg);
                        fs.Close();
                        image.Dispose();

                        ViewBag.QRcode = ChemCloud.Core.Common.GetRootUrl("") + "/Temp/" + filename;

                        //if (System.IO.File.Exists(filepath))
                        //{
                        //    //上传到服务器后 删除本地文件
                        //    System.IO.File.Delete(filepath);
                        //}
                    }
                    else
                    {
                        ViewBag.QRcode = null;
                    }
                }
            }
            else
            {
                ViewBag.CodePath = "";
            }

            return(View(order));
        }
Пример #26
0
        private static void TesteCodigoBarras()
        {
            using (var printer = new GenericPrinter(PortaCom))
            {
                //Code128
                Code128 code = new Code128()
                {
                    EncodeThis             = "12321321312",
                    BarcodeWidthMultiplier = 2,
                    BarcodeDotHeight       = 50, //Autura do codigo
                    HriPosition            = Printer.Barcodes.Enums.HRIPositions.Below,
                    Mode        = Code128.Modes.A,
                    BarcodeFont = ThermalFontsEnum.A
                };

                printer.PrintASCIIString("Code 128 - Altura 50");
                printer.FormFeed(1);
                printer.PrintBarCode(code);
                printer.FormFeed(1);
                printer.Reinitialize();


                //Code39
                Code39 code39 = new Code39()
                {
                    EncodeThis             = "12321321312",
                    BarcodeWidthMultiplier = 2,
                    BarcodeDotHeight       = 30, //Autura do codigo
                    BarcodeFont            = ThermalFontsEnum.A
                };

                printer.PrintASCIIString("Code 39 - Altura 30");
                printer.FormFeed(1);
                printer.PrintBarCode(code);
                printer.FormFeed(1);
                printer.Reinitialize();

                //ITF
                ITF itf = new ITF()
                {
                    EncodeThis             = "12321321312",
                    BarcodeDotHeight       = 100, //Autura do codigo
                    BarcodeWidthMultiplier = 2,
                    BarcodeFont            = ThermalFontsEnum.A
                };

                printer.PrintASCIIString("ITF - Altura 100");
                printer.FormFeed(1);
                printer.PrintBarCode(code);
                printer.FormFeed(3);
                printer.Reinitialize();

                //NFCe
                printer.PrintASCIIString("Exemplo QRCode NFCe\n");
                var qrCodeNFCe = new QrCode(4, "http://www.sefaz.mt.gov.br/nfce/consultanfce?chNFe=51131003460900000290650010000000031000000031&nVersao=100&tpAmb=2&cDest=02801244147&dhEmi=323031332D31302D32345431363A32313A30332D30333A3030&vNF=1,00&vICMS=0,00&digVal=78764D34764E2B48586A735657516F653474415A547855547764383D&cIdToken=000001&cHashQRCode=7AF4285DA2D18133BEF9F9370AD4A185B2527AFB");

                printer.PrintBarCode(qrCodeNFCe);
                printer.FormFeed(1);
                printer.Reinitialize();

                //Sat
                printer.PrintASCIIString("Exemplo QRCode SAT\n");
                var qrCodeSat = new QrCode(4, "http://www.sefaz.mt.gov.br/nfce/consultanfce?chNFe=51131003460900000290650010000000031000000031&nVersao=100&tpAmb=2&cDest=02801244147&dhEmi=323031332D31302D32345431363A32313A30332D30333A3030&vNF=1,00&vICMS=0,00&digVal=78764D34764E2B48586A735657516F653474415A547855547764383D&cIdToken=000001&cHashQRCode=7AF4285DA2D18133BEF9F9370AD4A185B2527AFB");

                printer.PrintBarCode(qrCodeNFCe);
                printer.FormFeed(1);

                printer.Cut(CutModeEnum.Parcial);
                printer.Reinitialize();
            }
        }
Пример #27
0
        private void BigCardPrint(System.Drawing.Printing.PrintPageEventArgs e)
        {
            int oX = -3, oY = -13;  //偏移量

            int i = 53;
            int j = 2;

            int[] xPos = { 0, 50, 150, 200, 300 };
            int[] yPos = { 0, 182, 212, 242, 272, 302, 332, 362, 412, 420 };

            Font CFont = new Font("隶书", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            Font EFont = new Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            Font EFont1 = new Font("Arial", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            Font sEFont = new Font("Arial", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            Font sCFont = new Font("隶书", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            //Font ssCFont = new Font("隶书", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));

            Font cCFont = new Font("隶书", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            Font eEFont = new Font("Arial", 11F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

            StringFormat drawFormat1 = new StringFormat();
            drawFormat1.Alignment = StringAlignment.Center;
            drawFormat1.LineAlignment = StringAlignment.Center;
            //------------------------------------------------------------------------------------------1行
            Rectangle rec;

            rec = new Rectangle(oX + xPos[1] - 10 - j, oY + yPos[1] + 17 - i, xPos[4] - xPos[1], yPos[2] - yPos[1]);
            rec.Height = 30;

            if (m_BarCodeStruct.BandNo.Length == 1)
                e.Graphics.DrawString(m_BarCodeStruct.BatchNo + " 0" + m_BarCodeStruct.BandNo, EFont, Brushes.Black, rec, drawFormat1);  //批次号
            else
                e.Graphics.DrawString(m_BarCodeStruct.BatchNo + " " + m_BarCodeStruct.BandNo, EFont, Brushes.Black, rec, drawFormat1);  //批次号

            //------------------------------------------------------------------------------------------2行
            if (m_BarCodeStruct.PrintStandard == "1")
            {
                rec.X = xPos[1] + oX + 4 - j;
                rec.Y = yPos[3] + oY - 12 - i;
                rec.Width = xPos[2] - xPos[1];
                rec.Height = 30;
                e.Graphics.DrawString(m_BarCodeStruct.Standard, sEFont, Brushes.Black, rec, drawFormat1); //标准
            }

            if (m_BarCodeStruct.PrintSteelType == "1")
            {
                rec.X = xPos[3] + oX - 12 - j; //35
                rec.Y = yPos[3] + oY - 12 - i;
                rec.Width = xPos[4] - xPos[3];
                rec.Height = 34;
                e.Graphics.DrawString(m_BarCodeStruct.SteelType, EFont1, Brushes.Black, rec, drawFormat1); //牌号
            }

            //--------------------------------------------------------------------------------------------3行
            rec.X = xPos[1] + oX - j;
            rec.Y = yPos[4] + oY - 10 - i;
            rec.Width = xPos[2] - xPos[1];
            rec.Height = 30;
            e.Graphics.DrawString("Φ" + m_BarCodeStruct.Spec + "mm", EFont, Brushes.Black, rec, drawFormat1); //规格

            rec.X = xPos[3] + oX - 12 - j; //35
            rec.Y = yPos[4] + oY - 10 - i;
            rec.Width = xPos[4] - xPos[3];
            rec.Height = 30;
            e.Graphics.DrawString(Convert.ToString(Convert.ToSingle(m_BarCodeStruct.Weight)) + " kg", EFont, Brushes.Black, rec, drawFormat1); //重量

            //---------------------------------------------------------------------------------------------5行
            rec.X = xPos[1] + oX + xPos[1] - 15;
            rec.Y = yPos[5] + oY - 10 - i;
            rec.Width = xPos[2] - xPos[1] + 30;
            rec.Height = 30;
            e.Graphics.DrawString(m_BarCodeStruct.Date.ToString("yyyy") + "    " + m_BarCodeStruct.Date.ToString("MM") + "    " + m_BarCodeStruct.Date.ToString("dd") + "   ", eEFont, Brushes.Black, rec, drawFormat1); //生产日期

            //---------------------------------------------------------------------------------------------5行
            rec.X = xPos[1] + oX + xPos[1] - 15;
            rec.Y = yPos[5] + oY - 10 - i;
            rec.Width = xPos[2] - xPos[1] + 50;
            rec.Height = 30;
            e.Graphics.DrawString("      年   月    日", cCFont, Brushes.Black, rec, drawFormat1); //生产日期

            rec.X = xPos[3] + oX - 10; //35
            rec.Y = yPos[5] + oY - 10 - i;
            rec.Width = xPos[4] - xPos[3];
            rec.Height = 30;
            e.Graphics.DrawString(m_BarCodeStruct.Term, CFont, Brushes.Black, rec, drawFormat1); //班别

            //---------------------------------------------------------------------------------------------7行
            if (m_BarCodeStruct.PrintAddress == "1")
            {
                rec.X = xPos[0] + oX;
                rec.Y = yPos[8] + oY - 28 - i;
                rec.Width = xPos[4] - xPos[0];
                rec.Height = 20;
                e.Graphics.DrawString("云南 ● 红钢", sCFont, Brushes.Black, rec, drawFormat1); //地点
            }

            Code128 c128 = new Code128();
            c128.printBigCode(m_BarCodeStruct.BarCode, 280, 50, e);
        }
Пример #28
0
        private void SmallCardPrint(System.Drawing.Printing.PrintPageEventArgs e)
        {
            int oX = -3, oY = -13;  //偏移量

            int[] xPos = { 0, 50, 150, 200, 300 };
            int[] yPos = { 0, 40, 212, 242, 70, 90, 332, 362, 412, 420 };

            Font CFont = new Font("隶书", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            Font EFont = new Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            Font sEFont = new Font("Arial", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            Font sCFont = new Font("隶书", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            //Font ssCFont = new Font("隶书", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));

            Font cCFont = new Font("隶书", 11F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            Font eEFont = new Font("Arial", 11F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

            StringFormat drawFormat1 = new StringFormat();
            drawFormat1.Alignment = StringAlignment.Center;
            drawFormat1.LineAlignment = StringAlignment.Center;
            //------------------------------------------------------------------------------------------1行
            Rectangle rec;
            int i = 40;

            rec = new Rectangle(45, 255 - i, 250, 30);
            rec.Height = 30;

            if (m_BarCodeStruct.BandNo.Length == 1)
                e.Graphics.DrawString(m_BarCodeStruct.BatchNo + " 0" + m_BarCodeStruct.BandNo, EFont, Brushes.Black, rec, drawFormat1);  //批次号
            else
                e.Graphics.DrawString(m_BarCodeStruct.BatchNo + " " + m_BarCodeStruct.BandNo, EFont, Brushes.Black, rec, drawFormat1);  //批次号

            //------------------------------------------------------------------------------------------2行
            //if (m_BarCodeStruct.PrintStandard == "1")
            //{
            //    rec.X = xPos[1] + oX + 4;
            //    rec.Y = yPos[3] + oY - 12;
            //    rec.Width = xPos[2] - xPos[1];
            //    rec.Height = 30;
            //    e.Graphics.DrawString("GB1499.1-2008", sEFont, Brushes.Black, rec, drawFormat1); //标准
            //}

            //if (m_BarCodeStruct.PrintSteelType == "1")
            //{
            //    rec.X = xPos[3] + oX - 12; //35
            //    rec.Y = yPos[3] + oY - 12;
            //    rec.Width = xPos[4] - xPos[3];
            //    rec.Height = 34;
            //    e.Graphics.DrawString(m_BarCodeStruct.SteelType, EFont, Brushes.Black, rec, drawFormat1); //牌号
            //}

            //--------------------------------------------------------------------------------------------3行
            rec.X = 60;
            rec.Y = 276 - i;
            rec.Width = 100;
            rec.Height = 30;
            e.Graphics.DrawString("Φ" + m_BarCodeStruct.Spec + "mm", EFont, Brushes.Black, rec, drawFormat1); //规格

            rec.X = 185; //35
            rec.Y = 276 - i;
            rec.Width = 100;
            rec.Height = 30;
            e.Graphics.DrawString(Convert.ToString(Convert.ToSingle(m_BarCodeStruct.Weight)) + " kg", EFont, Brushes.Black, rec, drawFormat1); //重量

            //---------------------------------------------------------------------------------------------5行
            rec.X = 105;
            rec.Y = 303 - i;
            rec.Width = 130;
            rec.Height = 30;
            e.Graphics.DrawString(m_BarCodeStruct.Date.ToString("yyyy") + "     " + m_BarCodeStruct.Date.ToString("MM") + "   " + m_BarCodeStruct.Date.ToString("dd") + "   ", eEFont, Brushes.Black, rec, drawFormat1); //生产日期

            //---------------------------------------------------------------------------------------------5行
            rec.X = 105;
            rec.Y = 303 - i;
            rec.Width = 150;
            rec.Height = 30;
            e.Graphics.DrawString("      年  月   日", cCFont, Brushes.Black, rec, drawFormat1); //生产日期

            rec.X = 230; //35
            rec.Y = 303 - i;
            rec.Width = 50;
            rec.Height = 30;
            e.Graphics.DrawString(m_BarCodeStruct.Term, CFont, Brushes.Black, rec, drawFormat1); //班别

            //---------------------------------------------------------------------------------------------7行
            //if (m_BarCodeStruct.PrintAddress == "1")
            //{
            //    rec.X = xPos[0] + oX;
            //    rec.Y = yPos[8] + oY - 28;
            //    rec.Width = xPos[4] - xPos[0];
            //    rec.Height = 20;
            //    e.Graphics.DrawString("云南 ● 红钢", sCFont, Brushes.Black, rec, drawFormat1); //地点
            //}

            Code128 c128 = new Code128();
            c128.printSmallCode(m_BarCodeStruct.BarCode, 275, 45, e);
        }
Пример #29
0
        static void Main(string[] args)
        {
            // Create a new PDF document
            var document = new PdfDocument();

            // Create an empty page
            var page = document.AddPage();

            page.Size = PageSize.A4;

            // Get an XGraphics object for drawing
            var gfx = XGraphics.FromPdfPage(page);

            gfx.DrawLine(XPens.Black, 1, 1, page.Width - 1, 1);
            gfx.DrawLine(XPens.Black, 1, 1, 1, page.Height - 1);
            gfx.DrawLine(XPens.Black, page.Width - 1, 1, page.Width - 1, page.Height - 1);
            gfx.DrawLine(XPens.Black, 1, page.Height - 1, page.Width - 1, page.Height - 1);

            gfx.DrawH1Text("Vehicle Manifest", page.Width / 2, 25, XStringFormats.Center);

            gfx.DrawLine(XPens.Black, 1, 50, page.Width - 1, 50);

            gfx.DrawH2Text("Shipper Load Reference", _xAxis, 80);

            //code128 barcode
            var code128Barcode = new Code128("(9001)2325/8841/1234")
            {
                Size = new XSize(180, 90)
            };

            gfx.DrawBarCode(code128Barcode, XBrushes.Black, _barcodeFont, new XPoint(_xAxis, 90));

            gfx.DrawH2Text(DateTime.Now.ToString("dd/MM/yyyy HH:mm"), (page.Width / 2) + (page.Width / 4), 80);

            gfx.DrawText("Despatch Location ID", _xAxis, 200);
            gfx.DrawText("(414)5060/0123/4999/8", _xAxis, 220);

            gfx.DrawText("Load Reference No.", _xAxis + 170, 200);
            gfx.DrawText("(9001)2325/8841/1234", _xAxis + 170, 220);

            gfx.DrawH2Text("Despatch Location", _xAxis, 270);
            gfx.DrawText("Supplier: 6539", _xAxis, 285);
            gfx.DrawText("Blue Earth Foods", _xAxis, 300);
            gfx.DrawText("B98 0RE", _xAxis, 315);

            gfx.DrawH2Text("Deliver To / Haulier", (page.Width / 2), 270);
            gfx.DrawText("Gist Portbury", (page.Width / 2), 285);
            gfx.DrawText("BS20 7XR", (page.Width / 2), 300);

            gfx.DrawText("Total Pallets", _xAxis, 360);
            gfx.DrawText("Total Dollies", _xAxis, 375);
            gfx.DrawText("Total Other", _xAxis, 390);
            gfx.DrawText("Vehicle Registration / Box No", _xAxis, 405);
            gfx.DrawText("Security Seal Number", _xAxis, 420);

            gfx.DrawText("0", _xAxis + 210, 360);
            gfx.DrawText("87", _xAxis + 210, 375);
            gfx.DrawText("0", _xAxis + 210, 390);
            gfx.DrawText("CU1547", _xAxis + 210, 405);
            gfx.DrawText("123456789012", _xAxis + 210, 420);


            var ponos = new List <string>()
            {
                "2055703012", "2055703012", "2055703012", "2055703012", "2055703012", "2055703012",
            };

            var rowHeight = 35;

            // Initial table construct
            // Table head (TH)
            gfx.DrawLine(XPens.Black, 1, 450, page.Width - 1, 450);
            gfx.DrawLine(XPens.Black, 1, 470, page.Width - 1, 470);
            gfx.DrawLine(XPens.Black, 130, 450, 130, 470);
            gfx.DrawLine(XPens.Black, 230, 450, 230, 470);
            gfx.DrawLine(XPens.Black, 310, 450, 310, 470);
            gfx.DrawLine(XPens.Black, 370, 450, 370, 470);
            gfx.DrawLine(XPens.Black, 480, 450, 480, 470);

            gfx.DrawTH1Text("RDC Destination", _xAxis, 465);
            gfx.DrawTH1Text("Delivery Method", _xAxis + 125, 465);
            gfx.DrawTH1Text("Equipment", _xAxis + 230, 465);
            gfx.DrawTH1Text("Quantity", _xAxis + 305, 465);
            gfx.DrawTH1Text("Depot Date/Cycle", _xAxis + 365, 465);
            gfx.DrawTH1Text("Purchase Orders", _xAxis + 475, 465);

            // Table data
            // Table body (TB)
            gfx.DrawTB1Text("M&S Bristol", _xAxis, 485);
            gfx.DrawTB1Text("Chilled", _xAxis + 125, 485);
            gfx.DrawTB1Text("Supplier", _xAxis + 230, 485);
            gfx.DrawTB1Text("Dolly", _xAxis + 235, 500);
            gfx.DrawTB1Text("17", _xAxis + 305, 485);
            gfx.DrawTB1Text(DateTime.Now.ToString("dd/MM/yyyy tt"), _xAxis + 365, 485);

            var currentPos   = 470;
            var currentCount = 0;

            ponos.ForEach(x =>
            {
                currentPos += 15;
                gfx.DrawTB1Text(x, _xAxis + 475, currentPos);
            });

            if (ponos.Count > 2)
            {
                rowHeight += (15 * (ponos.Count - 2));
            }

            gfx.DrawLine(XPens.Black, 130, 470, 130, 470 + rowHeight);
            gfx.DrawLine(XPens.Black, 230, 470, 230, 470 + rowHeight);
            gfx.DrawLine(XPens.Black, 310, 470, 310, 470 + rowHeight);
            gfx.DrawLine(XPens.Black, 370, 470, 370, 470 + rowHeight);
            gfx.DrawLine(XPens.Black, 480, 470, 480, 470 + rowHeight);
            gfx.DrawLine(XPens.Black, 1, 470 + rowHeight, page.Width - 1, 470 + rowHeight);


            gfx.DrawLine(XPens.Black, 1, 680, page.Width - 1, 680);
            gfx.DrawLine(XPens.Black, 100, 700, page.Width - 1, 700);
            gfx.DrawLine(XPens.Black, 100, 680, 100, 770);
            gfx.DrawLine(XPens.Black, page.Width / 2 + 50, 680, page.Width / 2 + 50, 770);
            gfx.DrawLine(XPens.Black, 1, 770, page.Width - 1, 770);


            gfx.DrawTB1Text("Quantities", _xAxis, 695);
            gfx.DrawTB1Text("Received As", _xAxis, 710);
            gfx.DrawTB1Text("Indicated", _xAxis, 725);
            gfx.DrawTH1Text("Driver Signature:", _xAxis + 90, 695);
            gfx.DrawTH1Text("Date:", _xAxis + 90, 710);
            gfx.DrawTH1Text("Receiving Site Signature:", _xAxis + 340, 695);
            gfx.DrawTH1Text("Date:", _xAxis + 340, 710);
            gfx.DrawSmallText("* Provide for any delivery differences, damage, quantity variances etc.", _xAxis, 780);

            // Save the document...
            string filename = $"HelloWorld{Guid.NewGuid()}.pdf";

            document.Save(filename);
            // ...and start a viewer.
            Process.Start(filename);
        }
Пример #30
0
        private string Code_128()
        {
            int         achecksum = 0;
            string      startcode = "";
            string      aresult   = "";
            int         i         = 0;
            string      cadc;
            int         idx;
            BarcodeType btyp;
            string      text = CurrentText;

            while (i < text.Length)
            {
                btyp = BarType;
                if (btyp == BarcodeType.Code128)
                {
                    btyp = Code128.FindNewType(text, i);
                }
                switch (btyp)
                {
                case BarcodeType.Code128A:
                    achecksum = 103;
                    startcode = Code128.StartA;
                    break;

                case BarcodeType.Code128B:
                    achecksum = 104;
                    startcode = Code128.StartB;
                    break;

                case BarcodeType.Code128C:
                    achecksum = 105;
                    startcode = Code128.StartC;
                    break;
                }
                // Start code
                if (i == 0)
                {
                    aresult = aresult + DoConvert(startcode);
                }
                // Look for EAN control
                if (text[i] == (char)0xBF)
                {
                    aresult   = aresult + DoConvert("411131");
                    achecksum = achecksum + 102 * (i + 1);
                    i++;
                    if (i >= text.Length)
                    {
                        break;
                    }
                }
                switch (btyp)
                {
                case BarcodeType.Code128A:
                case BarcodeType.Code128B:
                    while (i < text.Length)
                    {
                        idx = Code128.FindCodeAB(btyp, text[i]);
                        if (idx < 0)
                        {
                            idx = Code128.FindCodeAB(btyp, ' ');
                        }
                        aresult   = aresult + DoConvert(Code128.table[idx].data);
                        achecksum = achecksum + idx * (i + 1);
                        i++;
                        // Look for EAN control
                        if (i < text.Length)
                        {
                            if (text[i] == (char)0xBF)
                            {
                                aresult   = aresult + DoConvert("411131");
                                achecksum = achecksum + 102 * (i + 1);
                                i++;
                                break;
                            }
                        }
                    }
                    break;

                case BarcodeType.Code128C:
                    cadc = "";
                    while (i < text.Length)
                    {
                        cadc = cadc + text[i];
                        if (cadc.Length > 1)
                        {
                            idx = Code128.FindCodeC(cadc);
                            if (idx < 0)
                            {
                                idx = Code128.FindCodeC("00");
                            }
                            achecksum = achecksum + idx * ((i + 1) / 2);
                            aresult   = aresult + DoConvert(Code128.table[idx].data);
                            cadc      = "";
                        }
                        i++;
                        // Look for EAN control
                        if (i < text.Length)
                        {
                            if (text[i] == (char)0xBF)
                            {
                                aresult   = aresult + DoConvert("411131");
                                achecksum = achecksum + 102 * (i + 1);
                                i++;
                                break;
                            }
                        }
                    }
                    break;
                }
            }
            achecksum = achecksum % 103;
            aresult   = aresult + DoConvert(Code128.table[achecksum].data);
            aresult   = aresult + DoConvert(Code128.Stop);
            return(aresult);
        }
Пример #31
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (comboBox1.Text == "Code128")
            {
                Code128 bc = new Code128();
                int     i;
                bc.BarcodeSubtype = (Code128Subtype)Enum.Parse(typeof(Code128Subtype), comboBox2.Text);
                int.TryParse(textBox3.Text, out i); bc.Height      = i;
                int.TryParse(textBox2.Text, out i); bc.ModuleWidth = i;
                bc.TextAbove   = checkBox2.Checked;
                bc.DisplayText = checkBox1.Checked;
                int.TryParse(textBox4.Text, out i); bc.RotationAngle = i;
                try
                {
                    if (checkBox3.Checked)
                    {
                        try
                        {
                            string line;

                            System.IO.StreamReader file = new System.IO.StreamReader(textBox5.Text);
                            while ((line = file.ReadLine()) != null)
                            {
                                bc.SaveBarcodeToFile(line, String.Format("{0}\\{1}.{2}", Path.GetDirectoryName(textBox5.Text), line, "gif"));
                            }

                            file.Close();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                        }
                    }
                    else
                    {
                        pictureBox1.Image = bc.GetBarcodeImage(textBox1.Text);
                        bc.SaveBarcodeToFile(textBox1.Text, @"C:\Temp\BC.gif");
                    }
                }
                catch (Exception) { }
            }
            ;
            if (comboBox1.Text == "Code39")
            {
                Code39 bc = new Code39();
                int    i;
                int.TryParse(textBox3.Text, out i); bc.Height      = i;
                int.TryParse(textBox2.Text, out i); bc.ModuleWidth = i;
                bc.TextAbove   = checkBox2.Checked;
                bc.DisplayText = checkBox1.Checked;
                int.TryParse(textBox4.Text, out i); bc.RotationAngle = i;
                pictureBox1.Image = bc.GetBarcodeImage(textBox1.Text);
                bc.SaveBarcodeToFile(textBox1.Text, @"C:\Temp\BC.gif");
            }

            if (comboBox1.Text == "PDF417")
            {
                PDF417 bc = new PDF417();
                int    i;
                int.TryParse(textBox2.Text, out i); bc.ModuleWidth   = i;
                int.TryParse(textBox4.Text, out i); bc.RotationAngle = i;
                pictureBox1.Image = bc.GetBarcodeImage(textBox1.Text);
                bc.SaveBarcodeToFile(textBox1.Text, @"C:\Temp\BC.gif");
            }

            if (comboBox1.Text == "QRCode")
            {
                QRCode bc = new QRCode();
                int    i;
                int.TryParse(textBox2.Text, out i); bc.ModuleWidth = i;
                //int.TryParse(textBox4.Text, out i); bc.RotationAngle = i;
                int.TryParse(textBox4.Text, out i); bc.ErrorCorrectionLevel = i;
                pictureBox1.Image = bc.GetBarcodeImage(textBox1.Text);
                bc.SaveBarcodeToFile(textBox1.Text, @"C:\Temp\BC.gif");
            }

            if (comboBox1.Text == "DataMatrix")
            {
                DataMatrix bc = new DataMatrix();
                int        i;
                int.TryParse(textBox2.Text, out i); bc.ModuleWidth = i;
                //int.TryParse(textBox4.Text, out i); bc.RotationAngle = i;
                //int.TryParse(textBox4.Text, out i); bc.ErrorCorrectionLevel = i;
                pictureBox1.Image = bc.GetBarcodeImage(textBox1.Text);
                bc.SaveBarcodeToFile(textBox1.Text, @"C:\Temp\BC.gif");
            }

            //BarcodeGenerator BCG = new BarcodeGenerator();
            //BCG.BarcodeType = BarcodeType.Code39;
            //pictureBox1.Image = BCG.GetBarcodeImage(textBox1.Text);
            //textBox2.Text = BCG.TextWidth.ToString();

            //MessageBox.Show(NumberFormatInfo.CurrentInfo.PerMilleSymbol);
            //MessageBox.Show(NumberFormatInfo.CurrentInfo.NegativeInfinitySymbol);
            //MessageBox.Show((-1).ToString("x"));
        }
Пример #32
0
        public void TestEan()
        {
            Assert.IsFalse(InternationalArticleNumber.Validate("abcdefg"));
            Assert.IsFalse(InternationalArticleNumber.Validate("4003994155480"));

            // EAN-13
            var ean = InternationalArticleNumber.Create("400399415548");
            var bin = ean.ToBarcodeString();

            ean = InternationalArticleNumber.Create(bin);
            var s = "4003994155486";

            Assert.AreEqual(s, ean.ToString());
            Assert.AreEqual(13, ean.ToList().Count);
            Assert.IsTrue(InternationalArticleNumber.Validate(s));

            // EAN-8
            ean = InternationalArticleNumber.Create("7351353");
            bin = ean.ToBarcodeString();
            ean = InternationalArticleNumber.Create(bin);
            s   = "73513537";
            Assert.AreEqual(s, ean.ToString());
            Assert.AreEqual(8, ean.ToList().Count);
            Assert.IsTrue(InternationalArticleNumber.Validate(s));

            // EAN-5
            s   = "52495";
            ean = InternationalArticleNumber.Create(s);
            bin = ean.ToBarcodeString();
            ean = InternationalArticleNumber.Create(bin);
            Assert.AreEqual(s, ean.ToString());
            Assert.AreEqual(5, ean.ToList().Count);
            Assert.IsTrue(InternationalArticleNumber.Validate(s));

            // EAN-2
            s   = "53";
            ean = InternationalArticleNumber.Create(s);
            bin = ean.ToBarcodeString();
            ean = InternationalArticleNumber.Create(bin);
            Assert.AreEqual(s, ean.ToString());
            Assert.AreEqual(2, ean.ToList().Count);
            Assert.IsTrue(InternationalArticleNumber.Validate(s));

            // Code 128
            var code128 = Code128.CreateB(new byte[] { 43, 73, 78, 71, 67, 69, 65, 78 });

            Assert.AreEqual("Kingcean", code128.ToString());
            code128 = Code128.CreateA("Kingcean");
            Assert.AreEqual("Kingcean", code128.ToString());

            // Code 128 high character
            code128 = Code128.CreateB(new byte[] { 52, 100, 52, 52, 100, 100, 52, 52, 100, 52, 52, 100, 100, 52, 100, 100, 101, 52 });
            Assert.AreEqual("TÔTÔÔTÔTÔ", code128.ToString());

            // GS1-128
            code128 = Code128.CreateC(new byte[] { 102, 42, 18, 40, 20, 50, 101, 16 });
            Assert.AreEqual("[FNC1]42184020500", code128.ToString());
            var ai = code128.GetAiData();

            Assert.AreEqual("42184020500", ai.First());
            code128 = Code128.CreateGs1(421, "84020500");
            Assert.AreEqual("[Start C] [FNC1] 42 18 40 20 50 [Code A] 16 [Check symbol 92] [Stop]", code128.ToString(Code128.Formats.Values));
            Assert.AreEqual((byte)92, code128.Skip(code128.Count - 2).ToList()[0]);
            ai = code128.GetAiData();
            Assert.AreEqual("42184020500", ai.First());

            // Code 128 combination
            code128 += Code128.Gs1Generator.BankAccount("100016") + Code128.CreateA(" Something... ") + Code128.Join(new List <Code128>
            {
                Code128.CreateA("And "),
                Code128.CreateC(123),
                Code128.Gs1Generator.Sn("01234567890123456789")
            });
            Assert.AreEqual("[FNC1]42184020500[FNC1]8007100016 Something... And 123[FNC1]2101234567890123456789", code128.ToString());

//#if NET6_0_OR_GREATER
//            if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows))
//            {
//                Assert.IsTrue(RegistryUtility.TryGetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "ProductName", out string v));
//                Assert.AreEqual("Windows 10 Pro", v);
//                Assert.IsTrue(RegistryUtility.TryGetValue(Microsoft.Win32.Registry.LocalMachine, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "ProductName", out v));
//                Assert.AreEqual("Windows 10 Pro", v);
//            }
//#endif
        }
Пример #33
0
        }//Encode()

        /// <summary>
        /// Encodes the raw data into binary form representing bars and spaces.
        /// </summary>
        internal Image Encode()
        {
            DateTime dtStartTime = DateTime.Now;

            //make sure there is something to encode
            if (Raw_Data.Trim() == "")
            {
                throw new System.Exception("EENCODE-1: Input data not allowed to be blank.");
            }

            if (this.EncodedType == EncodingType.UNSPECIFIED)
            {
                throw new System.Exception("EENCODE-2: Symbology type not allowed to be unspecified.");
            }

            this.Encoded_Value = "";
            this._Country_Assigning_Manufacturer_Code = "N/A";

            IBarcode ibarcode;

            switch (this.Encoded_Type)
            {
            case EncodingType.UCC12:
            case EncodingType.UPCA:     //Encode_UPCA();
                ibarcode = new UPCA(Raw_Data);
                break;

            case EncodingType.UCC13:
            case EncodingType.EAN13:     //Encode_EAN13();
                ibarcode = new EAN13(Raw_Data);
                break;

            case EncodingType.Interleaved2of5:     //Encode_Interleaved2of5();
                ibarcode = new Interleaved2of5(Raw_Data);
                break;

            case EncodingType.Industrial2of5:
            case EncodingType.Standard2of5:     //Encode_Standard2of5();
                ibarcode = new Standard2of5(Raw_Data);
                break;

            case EncodingType.LOGMARS:
            case EncodingType.CODE39:     //Encode_Code39();
                ibarcode = new Code39(Raw_Data);
                break;

            case EncodingType.CODE39Extended:
                ibarcode = new Code39(Raw_Data, true);
                break;

            case EncodingType.Codabar:     //Encode_Codabar();
                ibarcode = new Codabar(Raw_Data);
                break;

            case EncodingType.PostNet:     //Encode_PostNet();
                ibarcode = new Postnet(Raw_Data);
                break;

            case EncodingType.ISBN:
            case EncodingType.BOOKLAND:     //Encode_ISBN_Bookland();
                ibarcode = new ISBN(Raw_Data);
                break;

            case EncodingType.JAN13:     //Encode_JAN13();
                ibarcode = new JAN13(Raw_Data);
                break;

            case EncodingType.UPC_SUPPLEMENTAL_2DIGIT:     //Encode_UPCSupplemental_2();
                ibarcode = new UPCSupplement2(Raw_Data);
                break;

            case EncodingType.MSI_Mod10:
            case EncodingType.MSI_2Mod10:
            case EncodingType.MSI_Mod11:
            case EncodingType.MSI_Mod11_Mod10:
            case EncodingType.Modified_Plessey:     //Encode_MSI();
                ibarcode = new MSI(Raw_Data, Encoded_Type);
                break;

            case EncodingType.UPC_SUPPLEMENTAL_5DIGIT:     //Encode_UPCSupplemental_5();
                ibarcode = new UPCSupplement5(Raw_Data);
                break;

            case EncodingType.UPCE:     //Encode_UPCE();
                ibarcode = new UPCE(Raw_Data);
                break;

            case EncodingType.EAN8:     //Encode_EAN8();
                ibarcode = new EAN8(Raw_Data);
                break;

            case EncodingType.USD8:
            case EncodingType.CODE11:     //Encode_Code11();
                ibarcode = new Code11(Raw_Data);
                break;

            case EncodingType.CODE128:     //Encode_Code128();
                ibarcode = new Code128(Raw_Data);
                break;

            case EncodingType.CODE128A:
                ibarcode = new Code128(Raw_Data, Code128.TYPES.A);
                break;

            case EncodingType.CODE128B:
                ibarcode = new Code128(Raw_Data, Code128.TYPES.B);
                break;

            case EncodingType.CODE128C:
                ibarcode = new Code128(Raw_Data, Code128.TYPES.C);
                break;

            case EncodingType.ITF14:
                ibarcode = new ITF14(Raw_Data);
                break;

            case EncodingType.CODE93:
                ibarcode = new Code93(Raw_Data);
                break;

            default: throw new System.Exception("EENCODE-2: Unsupported encoding type specified.");
            }//switch

            this.Encoded_Value  = ibarcode.Encoded_Value;
            this.Raw_Data       = ibarcode.RawData;
            this.Formatted_Data = ibarcode.FormattedData;
            this._EncodingTime  = ((TimeSpan)(DateTime.Now - dtStartTime)).TotalMilliseconds;

            _Encoded_Image = (Image)Generate_Image();

            _XML = GetXML();

            return(EncodedImage);
        }//Encode