/// <summary> Generates a barcode(with checksum) for a given string </summary>
        /// <param name="ItemID"> ItemID for the material </param>
        /// <param name="Action"> Indicates the Imaging action represented by this barcode</param>
        /// <param name="FilenameToSave"> Name of the output file to save </param>
        /// <returns>The url of the generated barcode GIF image</returns>
        public string Get_BarcodeImageUrl_from_string(int ItemID, string Action, string FilenameToSave)
        {
            string convertedItemID = int_to_base26(ItemID);
            string inputString     = (convertedItemID + Action).ToUpper();

            if (inputString == null)
            {
                throw new ArgumentNullException("InputString");
            }

            //Calculate the checksum
            int actionNum;

            Int32.TryParse(Action, out actionNum);
            int    checksumInt = (ItemID + actionNum) % 26;
            string checksum    = int_to_base26(checksumInt).ToUpper();

            string barcodeString = inputString + checksum;

            string image_save_location = image_location + "\\" + FilenameToSave + ".gif";

            //Generate the image
            Code39BarcodeDraw barcode39 = BarcodeDrawFactory.Code39WithoutChecksum;

            System.Drawing.Image barcode_image = barcode39.Draw(barcodeString, 60);

            //Save the image
            barcode_image.Save(@image_save_location, ImageFormat.Gif);

            string url = CurrentRequest.Base_URL + "temp/" + "tsBarcodes/" + ItemID;

            return(url + "/" + FilenameToSave + ".gif");
        }
Example #2
0
        public String Get39BarCode(String barcode)
        {
            String            token     = CreateUniqueToken();
            String            Route     = string.Format("{0}\\{1}.{2}", Directorio, token, Tipo.jpg);
            int               maxheight = 40;
            Code39BarcodeDraw barcode39 = BarcodeDrawFactory.Code39WithoutChecksum;
            Image             img       = barcode39.Draw(barcode, maxheight);

            img.Save(Route, System.Drawing.Imaging.ImageFormat.Jpeg);
            return(Route);
        }
Example #3
0
        private void setBarcode(Document doc, PdfWriter writer, string barcode)
        {
            Code39BarcodeDraw barcode39 = BarcodeDrawFactory.Code39WithoutChecksum;

            System.Drawing.Image img = barcode39.Draw(barcode, 50);
            Image im = Image.GetInstance(img, System.Drawing.Imaging.ImageFormat.Png);
            float y  = writer.GetVerticalPosition(false);

            im.SetAbsolutePosition(175, y + 28);
            doc.Add(im);

            PdfContentByte cb     = writer.DirectContent;
            ColumnText     ct     = new ColumnText(cb);
            Phrase         myText = new Phrase(barcode);

            ct.SetSimpleColumn(myText, 300, y + 28, 580, 317, 15, Element.ALIGN_LEFT);
            ct.Go();
        }
Example #4
0
        /*private void xmlButton_Click(object sender, EventArgs e)
         * {
         *  if (xmlOpenFileDialog.ShowDialog() == DialogResult.OK)
         *  {
         *      try
         *      {
         *          string xml = File.ReadAllText(xmlOpenFileDialog.FileName);
         *          InvoiceModel invoice = _invoice.XmlDecode(xml);
         *          try
         *          {
         *              _invoice.Add(invoice);
         *              MessageBox.Show("Zapisano z XML'a do bazy");
         *          }
         *          catch (Exception ex)
         *          {
         *              MessageBox.Show(ex.Message.ToString());
         *          }
         *
         *      }
         *      catch (Exception err)
         *      {
         *          MessageBox.Show(err.Message);
         *      }
         *  }
         * }*/

        private void buttonKreskowe_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            Dict   si           = comboBoxKreskowe.SelectedItem as Dict;
            string text         = textBoxBarcode.Text;
            Image  barcodeImage = null;

            switch (si.Key)
            {
            case "qr":
                CodeQrBarcodeDraw bd = BarcodeDrawFactory.CodeQr;
                barcodeImage = bd.Draw(text, 2, 2);
                break;

            case "code_11":
                if (Barcode.isValidCode11(text))
                {
                    Code11BarcodeDraw bd_code11 = BarcodeDrawFactory.Code11WithoutChecksum;
                    barcodeImage = bd_code11.Draw(text, 60, 1);
                }
                else
                {
                    MessageBox.Show("Wprowadzona wartość nie może zostać wygenerowana.\nCode 11 zawiera cyfry od 0 do 9 oraz łącznik (-).");
                }
                break;

            case "code_39":
                if (Barcode.isValidCode39(text))
                {
                    Code39BarcodeDraw bd_code39 = BarcodeDrawFactory.Code39WithoutChecksum;
                    barcodeImage = bd_code39.Draw(text, 60, 1);
                }
                else
                {
                    MessageBox.Show("Wprowadzona wartość nie może zostać wygenerowana.\n" +
                                    "Code 39 zawiera wszystkie litery, cyfry od 0 do 9, następujące znaki specjalne \"-.$/+%\" i spacje.");
                }
                break;

            case "code_128":
                if (Barcode.isValidCode128(text))
                {
                    Code128BarcodeDraw bd_code128 = BarcodeDrawFactory.Code128WithChecksum;
                    barcodeImage = bd_code128.Draw(text, 60, 1);
                }
                else
                {
                    MessageBox.Show("Wprowadzona wartość nie może zostać wygenerowana.\n" +
                                    "");
                }
                break;

            case "ean8":
                if (Barcode.isValidEan8(text))
                {
                    CodeEan8BarcodeDraw bd_ean8 = BarcodeDrawFactory.CodeEan8WithChecksum;
                    barcodeImage = bd_ean8.Draw(text, 60, 1);
                }
                else
                {
                    MessageBox.Show("Wprowadzona wartość nie może zostać wygenerowana.\n" +
                                    "Kod ten zawiera 8 cyfr, ale ostatni znak jest sumą kontrolną, więc należy wprowadzić 7 znaków.");
                }
                break;

            case "ean13":
                if (Barcode.isValidEan13(text))
                {
                    CodeEan13BarcodeDraw bd_ean13 = BarcodeDrawFactory.CodeEan13WithChecksum;
                    barcodeImage = bd_ean13.Draw(text, 60, 1);
                }
                else
                {
                    MessageBox.Show("Wprowadzona wartość nie może zostać wygenerowana.\n" +
                                    "Kod ten zawiera 13 cyfr, ale ostatni znak jest sumą kontrolną, więc należy wprowadzić 12 znaków.");
                }
                break;
            }
            if (barcodeImage != null)
            {
                Print print = new Print();
                print.printBarcode(barcodeImage, text);
                pictureBoxKreskowe.Image = barcodeImage;
            }

            Cursor = Cursors.Default;
        }