Esempio n. 1
0
        public void TestPutGenerateMultiple()
        {
            BarcodeApi target = new BarcodeApi(APIKEY, APPSID, BASEPATH);


            string          name   = "barcodePng.png";
            string          format = "";
            string          folder = "";
            BarcodeBuilders body   = new BarcodeBuilders();

            BarcodeBuilder barcodeBuilder1 = new BarcodeBuilder();

            barcodeBuilder1.TypeOfBarcode = "qr";
            barcodeBuilder1.Text          = "The Latest barcode";

            BarcodeBuilder barcodeBuilder2 = new BarcodeBuilder();

            barcodeBuilder2.TypeOfBarcode = "qr";
            barcodeBuilder2.Text          = "The Latest barcode";

            body.BarcodeBuilderList = new System.Collections.Generic.List <BarcodeBuilder> {
                barcodeBuilder1, barcodeBuilder2
            };

            SaaSposeResponse actual;

            actual = target.PutGenerateMultiple(name, format, folder, body);
            Assert.AreEqual("200", actual.Code);
            Assert.IsInstanceOfType(new SaaSposeResponse(), actual.GetType());
        }
Esempio n. 2
0
        public void TestPostGenerateMultiple()
        {
            BarcodeApi target = new BarcodeApi(APIKEY, APPSID, BASEPATH);

            string          format = "png";
            BarcodeBuilders body   = new BarcodeBuilders();

            BarcodeBuilder barcodeBuilder1 = new BarcodeBuilder();

            barcodeBuilder1.TypeOfBarcode = "qr";
            barcodeBuilder1.Text          = "The Latest barcode";

            BarcodeBuilder barcodeBuilder2 = new BarcodeBuilder();

            barcodeBuilder2.TypeOfBarcode = "qr";
            barcodeBuilder2.Text          = "The Latest barcode";

            body.BarcodeBuilderList = new System.Collections.Generic.List <BarcodeBuilder> {
                barcodeBuilder1, barcodeBuilder2
            };


            ResponseMessage actual;

            actual = target.PostGenerateMultiple(format, body);
            Assert.AreEqual(200, actual.Code);
            Assert.IsInstanceOfType(new ResponseMessage(), actual.GetType());
        }
Esempio n. 3
0
        public void ProcessRequest(HttpContext context)
        {
            Enums.Barcodes barcodeType = (Enums.Barcodes) int.Parse(context.Request.QueryString["barcodeType"]);
            string         message     = context.Request.QueryString["message"];
            IBarcode       barcoder    = BarcodeBuilder.CreateBarcode(barcodeType);

            Bitmap bitmap;

            if (barcodeType == Enums.Barcodes.MSI)
            {
                Enums.Modulo       modulo    = (Enums.Modulo) int.Parse(context.Request.QueryString["modulo"]);
                Enums.MSIWeighting weighting = (Enums.MSIWeighting) int.Parse(context.Request.QueryString["msiWeighting"]);
                bitmap = ((BarcodeMSI)barcoder).EncodeToBitmap(message, modulo, weighting);
            }
            else
            {
                bitmap = barcoder.EncodeToBitmap(message);
            }

            MemoryStream mem = new MemoryStream();

            bitmap.Save(mem, ImageFormat.Png);

            byte[] buffer = mem.ToArray();

            context.Response.ContentType = "image/png";
            context.Response.BinaryWrite(buffer);
            context.Response.Flush();
        }
        /// <summary>
        /// 初始化一个<see cref="PrintCommand"/>类型的实例
        /// </summary>
        /// <param name="printPaper">打印纸</param>
        /// <param name="encoding">字符编码</param>
        public PrintCommand(IPrintPaper printPaper, Encoding encoding)
        {
            Writer         = new WriterCommand(encoding);
            BarcodeBuilder = new BarcodeBuilder(encoding);

            FontStyle       = new FontStyleCommand();
            PagerCut        = new PagerCutCommand();
            Drawer          = new DrawerCommand();
            QrCode          = new QRCodeCommand();
            Barcode         = new BarcodeCommand(BarcodeBuilder);
            Style           = new StyleCommand(printPaper, encoding);
            InitializePrint = new InitializePrintCommand();
            PrintStyle      = new PrintStyleCommand();
            Image           = new ImageCommand(printPaper);
            PrintLine       = new PrintLineCommand(printPaper);
        }
Esempio n. 5
0
        private void cmdEncode_Click(object sender, EventArgs e)
        {
            cmdSave.Enabled = false;

            try
            {
                Enums.Barcodes barcodeType = (Enums.Barcodes)cboFormat.SelectedValue;

                IBarcode barcoder = null;
                switch (barcodeType)
                {
                case Enums.Barcodes.EAN13:
                    barcoder = BarcodeBuilder.CreateBarcode(Enums.Barcodes.EAN13);
                    break;

                case Enums.Barcodes.EAN8:
                    barcoder = BarcodeBuilder.CreateBarcode(Enums.Barcodes.EAN8);
                    break;

                case Enums.Barcodes.UPC2:
                    barcoder = BarcodeBuilder.CreateBarcode(Enums.Barcodes.UPC2);
                    break;

                case Enums.Barcodes.UPC5:
                    barcoder = BarcodeBuilder.CreateBarcode(Enums.Barcodes.UPC5);
                    break;

                case Enums.Barcodes.UPCA:
                    barcoder = BarcodeBuilder.CreateBarcode(Enums.Barcodes.UPCA);
                    break;

                case Enums.Barcodes.UPCE:
                    barcoder = BarcodeBuilder.CreateBarcode(Enums.Barcodes.UPCE);
                    break;

                case Enums.Barcodes.Interleaved2Of5:
                    barcoder = BarcodeBuilder.CreateBarcode(Enums.Barcodes.Interleaved2Of5);
                    break;

                case Enums.Barcodes.Standard2Of5:
                    barcoder = BarcodeBuilder.CreateBarcode(Enums.Barcodes.Standard2Of5);
                    break;

                case Enums.Barcodes.Postnet:
                    barcoder = BarcodeBuilder.CreateBarcode(Enums.Barcodes.Postnet);
                    break;

                case Enums.Barcodes.MSI:
                    barcoder = BarcodeBuilder.CreateBarcode(Enums.Barcodes.MSI);
                    break;
                }

                if (barcoder == null)
                {
                    MessageBox.Show("Invalid barcode type specified", "Error", MessageBoxButtons.OK);
                    return;
                }

                if (barcodeType == Enums.Barcodes.MSI)
                {
                    picOutput.Image = ((BarcodeMSI)barcoder).EncodeToBitmap(txtMessage.Text.Trim(), (Enums.Modulo)cboModulo.SelectedValue, (Enums.MSIWeighting)cboWeightType.SelectedValue);
                }
                else
                {
                    picOutput.Image = barcoder.EncodeToBitmap(txtMessage.Text.Trim());
                }
                cmdSave.Enabled = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK);
            }
        }