示例#1
0
 public Task <Image> GetBarcodeAsync(string data)
 {
     return(Task.Factory.StartNew <Image>(() =>
     {
         return _barcode.Draw(data, 3, 3);
     }));
 }
示例#2
0
        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            Graphics g = e.Graphics;

            CodeQrBarcodeDraw QRcode = BarcodeDrawFactory.CodeQr; // to generate QR code

            System.Drawing.Image QRcodeImage = QRcode.Draw(coilID.Text, 100);
            // RectangleF(The coordinates of the upper-left corner of the rectangle, width, height)
            RectangleF QRcodeRect = new RectangleF(50.0F, 40.0F, 150.0F, 150.0F);

            g.DrawImage(QRcodeImage, QRcodeRect);

            BarcodeDraw bdraw = BarcodeDrawFactory.GetSymbology(BarcodeSymbology.Code128);

            System.Drawing.Image barcodeImage = bdraw.Draw(coilID.Text, 100);
            RectangleF           barcodeRect  = new RectangleF(250.0F, 40.0F, 400.0F, 100.0F);

            g.DrawImage(barcodeImage, barcodeRect);

            // Create string to draw.
            String drawString = coilID.Text;

            // Create font and brush.
            System.Drawing.Font drawFont  = new System.Drawing.Font("Times New Roman", 16);
            SolidBrush          drawBrush = new SolidBrush(Color.Black);

            // Create point for upper-left corner of drawing.
            float x = 250.0F;
            float y = 150.0F;

            g.DrawString(drawString, drawFont, drawBrush, x, y);
        }
示例#3
0
        private void button3_Click_1(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count != 1)
            {
                MessageBox.Show("On ne peut modifier qu'un seul élément à la fois", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            else
            {
                FormEtudiant f = new FormEtudiant();
                f.FormBorderStyle = FormBorderStyle.FixedSingle;
                f.Show();
                f.button1.Text     = "Edit";
                f.lblBarre.Visible = true;

                for (i = 0; i < listView1.Items.Count; i++)
                {
                    if (listView1.Items[i].Selected)
                    {
                        f.txtNom.Text               = Class1.Tab1[i][0];
                        f.txtPrenom.Text            = Class1.Tab1[i][1];
                        f.txtIdentifiant.Text       = Class1.Tab1[i][2];
                        f.dateTimePicker1.Text      = Class1.Tab1[i][3];
                        f.txtEmail.Text             = Class1.Tab1[i][4];
                        f.txtContact.Text           = Class1.Tab1[i][5];
                        f.pictureBox4.ImageLocation = Class1.Tab1[i][6];
                        CodeQrBarcodeDraw barcode = BarcodeDrawFactory.CodeQr;
                        f.pictureBox1.Image = barcode.Draw(Class1.Tab1[i][2], 50);
                        f.lblPhoto.Visible  = false;

                        Class1.temp = i;
                    }
                }
            }
        }
示例#4
0
        public FormParent()
        {
            InitializeComponent();

            using (StreamReader sr = new StreamReader(@"C:\Users\dhout\Desktop\CC01\WindowsFormsApp1\DATA\Data_Etudiant.json"))
            {
                CodeQrBarcodeDraw barcode = BarcodeDrawFactory.CodeQr;
                using (JsonReader jr = new JsonTextReader(sr))
                {
                    JsonSerializer js = new JsonSerializer();
                    Class1.Tab1 = js.Deserialize <List <string[]> >(jr);

                    for (i = 0; i < Class1.Tab1.Count; i++)
                    {
                        Class1.l.listView1.Items.Add(new ListViewItem(Class1.Tab1[i]));
                        Class1.bte.Add((byte[])new ImageConverter().ConvertTo(barcode.Draw(Class1.Tab1[i][2], 30), typeof(byte[])));
                    }
                }
            }

            using (StreamReader sr = new StreamReader(@"C:\Users\dhout\Desktop\CC01\WindowsFormsApp1\DATA\Data_Ecole.json"))
            {
                using (JsonReader jr = new JsonTextReader(sr))
                {
                    JsonSerializer js = new JsonSerializer();
                    Class1.Tab2 = js.Deserialize <List <string[]> >(jr);

                    for (i = 0; i < Class1.Tab2.Count; i++)
                    {
                        Class1.l2.listView1.Items.Add(new ListViewItem(Class1.Tab2[i]));
                        Class1.ch.comboBox1.Items.Add(Class1.Tab2[i][0]);
                    }
                }
            }
        }
示例#5
0
        private void renderBarcode(string textData, PrintCapabilities printCaps)
        {
            //create barcode image
            CodeQrBarcodeDraw barcode = BarcodeDrawFactory.CodeQr;
            //draw barcode image
            DrawImage image = barcode.Draw(textData, 2);

            image = resizeImage(image, new Size(printCaps.PageImageableArea.ExtentWidth, printCaps.PageImageableArea.ExtentHeight));

            //create memory stream for barcode conversion
            MemoryStream ms = new MemoryStream();

            //save barcode image to memory stream as PNG
            image.Save(ms, ImageFormat.Png);
            //set memory stream position back to the beginning
            ms.Position = 0;
            //create bitmap image
            bitmap = new BitmapImage();
            //prep bitmap for memory stream
            bitmap.BeginInit();
            //set memory stream
            bitmap.StreamSource = ms;
            //end stream prep
            bitmap.EndInit();

            ms = new MemoryStream();
            saveAsPng(getImage(getDrawingVisual(bitmap)), ms);
            bitmap = bitmapImageFromStream(ms);

            //use bitmap as image source
            imgBarcode.Source = bitmap;
        }
示例#6
0
        public ActionResult Create([Bind(Include = "Id,Item_Name,Category,Serial_Number,QR_Code,Date_Added,Status,Image,Current_User")] Inventory inventory)
        {
            Random            rnd    = new Random();
            CodeQrBarcodeDraw qrcode = BarcodeDrawFactory.CodeQr;

            if (inventory.Serial_Number != string.Empty)

            ///GET QR CODE
            {
                var FilePath = inventory.Serial_Number + ".gif";
                var QRCode   = qrcode.Draw(inventory.Serial_Number, 50, 20);
                //QRCode.Save(FilePath, System.Drawing.Imaging.ImageFormat.Jpeg);
                inventory.QR_Code = inventory.Serial_Number + ".jpeg";
            }



            if (ModelState.IsValid)
            {
                db.Inventory.Add(inventory);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(inventory));
        }
示例#7
0
        private void renderBarcode(string textData)
        {
            //create barcode image
            CodeQrBarcodeDraw barcode = BarcodeDrawFactory.CodeQr;
            //draw barcode image
            DrawImage image = barcode.Draw(textData, 20);
            //create memory stream for barcode conversion
            MemoryStream ms = new MemoryStream();

            //save barcode image to memory stream as PNG
            image.Save(ms, ImageFormat.Png);
            //---debug render to file
            //FileStream fStream = new FileStream("barcode.png", FileMode.Create);
            //image.Save(fStream, ImageFormat.Png);
            //set memory stream position back to the beginning
            ms.Position = 0;
            //create bitmap image
            bitmap = new BitmapImage();
            //prep bitmap for memory stream
            bitmap.BeginInit();
            //set memory stream
            bitmap.StreamSource = ms;
            //end stream prep
            bitmap.EndInit();

            //use bitmap as image source
            imgBarcode.Source = bitmap;
        }
示例#8
0
        private void button3_Click_1(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count != 1)
            {
                MessageBox.Show("Sélectionner une école s'il-vous-plait", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            else
            {
                FormEcole f1 = new FormEcole();
                f1.FormBorderStyle = FormBorderStyle.FixedSingle;
                f1.Show();
                f1.button1.Text     = "Edit";
                f1.lblBarre.Visible = true;

                for (i = 0; i < listView1.Items.Count; i++)
                {
                    if (listView1.Items[i].Selected)
                    {
                        f1.txtNom.Text               = Class1.Tab2[i][0];
                        f1.dateTimePicker1.Text      = Class1.Tab2[i][1];
                        f1.txtEmail.Text             = Class1.Tab2[i][2];
                        f1.txtContact.Text           = Class1.Tab2[i][3];
                        f1.pictureBox4.ImageLocation = Class1.Tab2[i][4];
                        CodeQrBarcodeDraw qrcode = BarcodeDrawFactory.CodeQr;
                        f1.pictureBox1.Image = qrcode.Draw(Class1.Tab2[i][0], 50);
                        f1.lblPhoto.Visible  = false;

                        Class1.temp = i;
                    }
                }
            }
        }
示例#9
0
        //_______________QR CODE_________________________________________//
        private void metroBtbQrCode_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(this.metroTxtQrCode.Text.Trim()))
            {
                this.pictureBoxQR.Visible      = false;
                this.metroTxtQrCode.ShowButton = false;
                MetroMessageBox.Show(this, "Text value can not be null.Please fill the field.",
                                     "Value is Empty", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
            }

            else
            {
                this.metroCbxQR.Visible = true;
                pictureBoxQR.SizeMode   = PictureBoxSizeMode.CenterImage;
                qrWidth  = this.pictureBoxQR.Width;
                qrHeight = this.pictureBoxQR.Height;

                this.pictureBoxQR.Visible      = true;
                this.metroTxtQrCode.ShowButton = true;
                metroBtnSaveQRCode.Visible     = true;
                CodeQrBarcodeDraw qrDraw = BarcodeDrawFactory.CodeQr;
                qrDraw.GetDefaultMetrics(this.pictureBoxQR.Height + 25);
                pictureBoxQR.Image = qrDraw.Draw(this.metroTxtQrCode.Text.Trim(), this.pictureBoxQR.Height);
            }
        }
示例#10
0
        private void Btn_QRGenerate_Click(object sender, EventArgs e)
        {
            CodeQrBarcodeDraw barcode = BarcodeDrawFactory.CodeQr;
            string            QRInfor = txt_warehouseName.Text + ";" + txt_location.Text + ";" + txt_rack.Text + ";" + DateTime.Now.ToString("dd/MM/yyyy");

            pic_QRCode.Image = barcode.Draw(QRInfor, 50);
            testDrawQRCODE(pic_QRCode);
        }
示例#11
0
        private void genBarCode()
        {
            Code128BarcodeDraw barcode = BarcodeDrawFactory.Code128WithChecksum;

            picBarcode.Image = barcode.Draw(txtBarCode.Text, 60);

            string qr = "http://www.ppakorn.info/siam_summaryDoc/page/coding2/coding2-index.html?qrCode=" +
                        txtBarCode.Text.Trim();
            CodeQrBarcodeDraw qrcode = BarcodeDrawFactory.CodeQr;

            picQR.Image        = qrcode.Draw(qr, 50);
            lblBarCodeImg.Text = txtBarCode.Text;
        }
示例#12
0
        private void dataGridView1_MouseClick(object sender, MouseEventArgs e)
        {
            string id2 = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
            int    id  = Convert.ToInt32(id2);

            textBox1.Text  = id.ToString();
            textBox2.Text  = dataGridView1.SelectedRows[0].Cells[1].Value.ToString().ToUpper();
            comboBox1.Text = dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
            textBox4.Text  = dataGridView1.SelectedRows[0].Cells[3].Value.ToString();
            textBox5.Text  = dataGridView1.SelectedRows[0].Cells[4].Value.ToString().Trim('d', 'b');
            textBox6.Text  = dataGridView1.SelectedRows[0].Cells[5].Value.ToString().Trim('F', 't');
            //pictureBox7.Image = LoadPhoto((byte[]))

            CodeQrBarcodeDraw qrcode = BarcodeDrawFactory.CodeQr;

            barcode.Image = qrcode.Draw(textBox2.Text, 30);
        }
示例#13
0
        private void dataGridView1_MouseClick(object sender, MouseEventArgs e)
        {
            string id2 = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
            int    id  = Convert.ToInt32(id2);

            textBox1.Text  = id.ToString();
            textBox2.Text  = dataGridView1.SelectedRows[0].Cells[1].Value.ToString().ToUpper();
            comboBox1.Text = dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
            textBox4.Text  = dataGridView1.SelectedRows[0].Cells[3].Value.ToString();
            textBox5.Text  = dataGridView1.SelectedRows[0].Cells[4].Value.ToString().Trim('d', 'b');
            if (Convert.ToInt32(textBox5.Text) == 0)
            {
                dataGridView1.SelectedRows[0].DefaultCellStyle.SelectionBackColor = Color.Red;
                MessageBox.Show("Nincs ebből a termékből!");
            }
            textBox6.Text = dataGridView1.SelectedRows[0].Cells[5].Value.ToString().Trim('F', 't');
            // byte image1 = LoadPhoto(Convert.ToByte(dataGridView1.SelectedRows[0].Cells[6].Value);

            CodeQrBarcodeDraw qrcode = BarcodeDrawFactory.CodeQr;

            barcode.Image = qrcode.Draw(textBox2.Text, 30);
        }
        public ActionResult Imagez(String token)
        {
            CodeQrBarcodeDraw qrCode = BarcodeDrawFactory.CodeQr;
            Image             img    = qrCode.Draw(token, 100, 6);
            string            path   = Server.MapPath("~/App_Data/logo2.png");

            Image image_m = Image.FromFile(path);


            Bitmap baseImage;
            Bitmap overlayImage;

            baseImage    = (Bitmap)img;
            overlayImage = (Bitmap)image_m;

            var finalImage = new Bitmap(baseImage.Width, baseImage.Height, PixelFormat.Format32bppArgb);
            var graphics   = Graphics.FromImage(finalImage);

            graphics.CompositingMode = CompositingMode.SourceOver;
            float overlayPosX = baseImage.Width / 2 - 40f;
            float overlayPosY = baseImage.Height / 2 - 40f;

            graphics.DrawImage(baseImage, 0, 0);



            graphics.DrawImage(imageOuterEdge(overlayImage, 2), overlayPosX, overlayPosY, 80f, 80f);
            //overlayImage.MakeTransparent();
            graphics.DrawImage(overlayImage, baseImage.Width / 2 - 30f, baseImage.Height / 2 - 30f, 60f, 60f);
            // finalImage.MakeTransparent();


            //ViewData["bitmap"] = finalImage;
            var bitmap      = finalImage;
            var bitmapBytes = ImageToByte2(bitmap);

            return(File(bitmapBytes, "image/jpeg")); //Return as file result
        }
示例#15
0
        private void qrcode_Click(object sender, EventArgs e)
        {
            CodeQrBarcodeDraw Qrcode = BarcodeDrawFactory.CodeQr;

            pictureBox1.Image = Qrcode.Draw(Mybarcode.Text, 50);
        }
示例#16
0
        private void ButtonCreate_Click(object sender, EventArgs e)
        {
            CodeQrBarcodeDraw qr = new CodeQrBarcodeDraw();

            pictureBox1.Image = qr.Draw(textBox1.Text, 100);
        }
示例#17
0
        // create QRCode from string
        static public Image GenerateQRCodeFromAdress(string row)
        {
            CodeQrBarcodeDraw qrCode = BarcodeDrawFactory.CodeQr;

            return(qrCode.Draw(row, 200));
        }
示例#18
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;
        }
示例#19
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            if (button1.Text == "Save")
            {
                if (pictureBox4.Image != null)
                {
                    i = 0;
                    while (Class1.Tab1.Count != i)
                    {
                        if (Class1.Tab1[i][2] == txtIdentifiant.Text)
                        {
                            break;
                        }
                        i++;
                    }

                    if (i == Class1.Tab1.Count)
                    {
                        //string[] infos = new string[] { txtNom.Text, txtPrenom.Text, txtIdentifiant.Text, dateTimePicker1.Text, txtEmail.Text, txtContact.Text, ofd.FileName };
                        string[] copie  = new string[] { txtNom.Text, txtPrenom.Text, txtIdentifiant.Text, dateTimePicker1.Text, txtEmail.Text, txtContact.Text };
                        string[] copies = new string[] { txtNom.Text, txtPrenom.Text, txtIdentifiant.Text, dateTimePicker1.Text, txtEmail.Text, txtContact.Text, ofd.FileName };

                        Class1.l.listView1.Items.Add(new ListViewItem(copie));
                        Class1.Tab1.Add(copies);

                        CodeQrBarcodeDraw barcode = BarcodeDrawFactory.CodeQr;
                        Class1.bte.Add((byte[])new ImageConverter().ConvertTo(barcode.Draw(Class1.Tab1[Class1.Tab1.Count - 1][2], 30), typeof(byte[])));

                        txtNom.Clear();
                        txtPrenom.Clear();
                        txtIdentifiant.Clear();
                        txtEmail.Clear();
                        txtContact.Clear();
                        pictureBox4.ImageLocation = null;
                        lblPhoto.Visible          = true;

                        MessageBox.Show("Enregistrement réussi");

                        using (StreamWriter sw = new StreamWriter(@"C:\Users\dhout\Desktop\CC01\WindowsFormsApp1\DATA\Data_Etudiant.json"))
                        {
                            using (JsonWriter jw = new JsonTextWriter(sw))
                            {
                                jw.Formatting = Formatting.Indented;

                                JsonSerializer js = new JsonSerializer();

                                js.Serialize(jw, JsonConvert.DeserializeObject(JsonConvert.SerializeObject(Class1.Tab1)));
                            }
                        }
                    }

                    else
                    {
                        MessageBox.Show
                        (
                            "Cet identifiant existe déjà !!!",
                            "Error",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error
                        );

                        txtIdentifiant.Focus();
                    }
                }

                else
                {
                    MessageBox.Show("Vous n'avez pas de photo");
                }
            }

            else
            {
                if
                (
                    MessageBox.Show
                    (
                        "Souhaitez-vous enregistrer ces modifications?",
                        "Confirmation",
                        MessageBoxButtons.YesNo,
                        MessageBoxIcon.Question
                    ) == DialogResult.Yes
                )
                {
                    if (pictureBox4.Image != null)
                    {
                        i = 0;
                        while (Class1.Tab1.Count != i)
                        {
                            if (Class1.Tab1[i][2] == txtIdentifiant.Text)
                            {
                                break;
                            }
                            i++;
                        }

                        if (i == Class1.Tab1.Count)
                        {
                            Class1.Tab1[Class1.temp][0] = txtNom.Text;
                            Class1.Tab1[Class1.temp][1] = txtPrenom.Text;
                            Class1.Tab1[Class1.temp][2] = txtIdentifiant.Text;
                            Class1.Tab1[Class1.temp][3] = dateTimePicker1.Text;
                            Class1.Tab1[Class1.temp][4] = txtEmail.Text;
                            Class1.Tab1[Class1.temp][5] = txtContact.Text;
                            Class1.Tab1[Class1.temp][6] = pictureBox4.ImageLocation;

                            CodeQrBarcodeDraw barcode = BarcodeDrawFactory.CodeQr;
                            Class1.bte[Class1.temp] = (byte[])new ImageConverter().ConvertTo(barcode.Draw(Class1.Tab1[Class1.temp][2], 30), typeof(byte[]));

                            Class1.l.listView1.Items.Clear();

                            for (i = 0; i < Class1.Tab1.Count; i++)
                            {
                                Class1.l.listView1.Items.Add(new ListViewItem(Class1.Tab1[i]));
                            }

                            using (StreamWriter sw = new StreamWriter(@"C:\Users\dhout\Desktop\CC01\WindowsFormsApp1\DATA\Data_Etudiant.json"))
                            {
                                using (JsonWriter jw = new JsonTextWriter(sw))
                                {
                                    jw.Formatting = Formatting.Indented;

                                    JsonSerializer js = new JsonSerializer();

                                    js.Serialize(jw, JsonConvert.DeserializeObject(JsonConvert.SerializeObject(Class1.Tab1)));
                                }
                            }

                            this.Close();
                        }

                        else
                        {
                            MessageBox.Show
                            (
                                "Cet identifiant existe déjà !!!",
                                "Error",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error
                            );

                            txtIdentifiant.Focus();
                        }
                    }

                    else
                    {
                        MessageBox.Show("Vous n'avez pas de photo");
                    }
                }
            }
        }
示例#20
0
        private void createPDFButton_Click(object sender, EventArgs e)
        {
            try
            {
                string path = Application.StartupPath;
                // In PDF we use user unit as the measurement, 1 cm = 28.34 user units. So to create a 30 cm by 4 cm page we need below sizes.
                var pgSize = new iTextSharp.text.Rectangle(878, 141);

                Document  pdfdoc = new Document(pgSize);                                                                                          // Setting the page size for the PDF
                PdfWriter writer = PdfWriter.GetInstance(pdfdoc, new FileStream(path + "/" + createPDFColorList.Text + ".pdf", FileMode.Create)); //Using the PDF Writer class to generate the PDF
                pdfdoc.Open();                                                                                                                    // Opening the PDF to write the data from the textbox

                CodeQrBarcodeDraw     QRcode      = BarcodeDrawFactory.CodeQr;                                                                    // to generate QR code
                System.Drawing.Image  QRcodeImage = QRcode.Draw(createPDFNameText.Text + " / " + createPDFColorList.Text + " " + sizeText.Text + " MM", 100);
                iTextSharp.text.Image pic         = iTextSharp.text.Image.GetInstance(QRcodeImage, System.Drawing.Imaging.ImageFormat.Jpeg);
                pic.ScaleAbsolute(90, 90);
                pic.SetAbsolutePosition(20F, 25F);

                pdfdoc.Add(pic);
                PdfContentByte cb = writer.DirectContent;
                // we tell the ContentByte we're ready to draw text
                cb.BeginText();

                // set up Font and Size for Content to be shown in PDF
                BaseFont mybf = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                cb.SetFontAndSize(mybf, 70);

                // we draw some text on a certain position
                cb.SetTextMatrix(310, 70);
                cb.ShowText(createPDFColorList.Text);


                cb.SetFontAndSize(mybf, 50);
                cb.SetTextMatrix(250, 30);
                cb.ShowText(createPDFNameText.Text);

                cb.SetFontAndSize(mybf, 90);
                cb.SetTextMatrix(710, 40);
                cb.ShowText(sizeText.Text);
                // we tell the contentByte, we've finished drawing text
                cb.EndText();
                //var test = pdfdoc.Add(new Paragraph("my timestamp"));

                iTextSharp.text.Rectangle pageBorderRect = new iTextSharp.text.Rectangle(pgSize);

                pageBorderRect.Left       += (pdfdoc.LeftMargin - 22);
                pageBorderRect.Right      -= (pdfdoc.RightMargin - 22);
                pageBorderRect.Top        -= (pdfdoc.TopMargin - 22);
                pageBorderRect.Bottom     += (pdfdoc.BottomMargin - 22);
                pageBorderRect.BorderWidth = 6;

                cb.SetColorStroke(BaseColor.GRAY);
                cb.Rectangle(pageBorderRect.Left, pageBorderRect.Bottom, pageBorderRect.Width, pageBorderRect.Height);
                cb.Stroke();
                pdfdoc.Close();

                //MessageBox.Show("PDF Generation Successfull");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#21
0
        private void CreatePDFButtonForRackLocation_Click(object sender, EventArgs e)
        {
            try
            {
                for (int numberOfTray = 1; numberOfTray <= 20; numberOfTray++)
                {
                    for (int numberOfRow = 1; numberOfRow <= 4; numberOfRow++)
                    {
                        for (int numberOfColumn = 1; numberOfColumn <= 3; numberOfColumn++)
                        {
                            string path = Application.StartupPath;
                            // In PDF we use user unit as the measurement, 1 cm = 28.34 user units. So to create a 30 cm by 4 cm page we need below sizes.
                            var       pgSize = new iTextSharp.text.Rectangle(156, 567);
                            Document  pdfdoc = new Document(pgSize);                                                                                                                                            // Setting the page size for the PDF
                            PdfWriter writer = PdfWriter.GetInstance(pdfdoc, new FileStream(path + "/RackLocation/SM_" + numberOfTray + "_R" + numberOfRow + "_C" + numberOfColumn + ".pdf", FileMode.Create)); //Using the PDF Writer class to generate the PDF
                            pdfdoc.Open();                                                                                                                                                                      // Opening the PDF to write the data from the textbox

                            CodeQrBarcodeDraw     QRcode      = BarcodeDrawFactory.CodeQr;                                                                                                                      // to generate QR code
                            System.Drawing.Image  QRcodeImage = QRcode.Draw("SM_" + numberOfTray + "_R" + numberOfRow + "_C" + numberOfColumn, 100);
                            iTextSharp.text.Image pic         = iTextSharp.text.Image.GetInstance(QRcodeImage, System.Drawing.Imaging.ImageFormat.Jpeg);
                            pic.ScaleAbsolute(120, 120);        // QR code size
                            pic.SetAbsolutePosition(20F, 420F); // QR code position

                            pdfdoc.Add(pic);
                            PdfContentByte cb = writer.DirectContent;
                            // we tell the ContentByte we're ready to draw text
                            cb.BeginText();

                            // set up Font and Size for Content to be shown in PDF
                            BaseFont mybf = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                            cb.SetFontAndSize(mybf, 80);

                            // we draw some text on a certain position
                            cb.SetTextMatrix(20, 340);
                            cb.ShowText("SM");

                            if (numberOfTray < 10)
                            {
                                cb.SetTextMatrix(30, 260);
                                cb.ShowText("0" + numberOfTray.ToString());
                            }
                            else
                            {
                                cb.SetTextMatrix(30, 260);
                                cb.ShowText(numberOfTray.ToString());
                            }

                            cb.SetTextMatrix(30, 180);
                            cb.ShowText("R" + numberOfRow);

                            cb.SetTextMatrix(30, 100);
                            cb.ShowText("C" + numberOfColumn);

                            // we tell the contentByte, we've finished drawing text
                            cb.EndText();

                            iTextSharp.text.Rectangle pageBorderRect = new iTextSharp.text.Rectangle(pgSize);

                            pageBorderRect.Left       += (pdfdoc.LeftMargin - 22);
                            pageBorderRect.Right      -= (pdfdoc.RightMargin - 22);
                            pageBorderRect.Top        -= (pdfdoc.TopMargin - 22);
                            pageBorderRect.Bottom     += (pdfdoc.BottomMargin - 22);
                            pageBorderRect.BorderWidth = 6;

                            cb.SetColorStroke(BaseColor.GRAY);
                            cb.Rectangle(pageBorderRect.Left, pageBorderRect.Bottom, pageBorderRect.Width, pageBorderRect.Height);
                            cb.Stroke();
                            pdfdoc.Close();
                        }
                    }
                }

                //MessageBox.Show("PDF Generation Successfull");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#22
0
        public ActionResult Sliting(CoilSlits slits)
        {
            ViewBag.Title       = "Coil Slit";
            Session["CurrForm"] = "CoilSlit";

            slits.errMsg = "";

            if (slits.inputHidden != null)
            {
                //char[] delimiters = { ' ', '+' };
                //string[] inputArray = slits.input.Split(delimiters); // split the input string by using the delimiter '+'
                if (slits.inputHidden.Length < 9)
                {
                    slits.errMsg = "Wrong Coil ID.";
                    return(View(slits));
                }

                string coilID = slits.inputHidden.Substring(0, 9);

                int cover_width = 0;
                int base_width  = 0;
                if (slits.slitWidth == 118)
                {
                    cover_width = 51;
                    base_width  = 67;
                }
                if (slits.slitWidth == 150)
                {
                    cover_width = 67;
                    base_width  = 83;
                }
                if (slits.slitWidth == 200)
                {
                    cover_width = 92;
                    base_width  = 108;
                }

                CodeQrBarcodeDraw  QRcode     = BarcodeDrawFactory.CodeQr;              // to generate QR code
                Code128BarcodeDraw barcode128 = BarcodeDrawFactory.Code128WithChecksum; // to generate barcode
                Image  img_QRcode             = null;
                Image  img_Barcode            = null;
                byte[] imgBytes;
                string imgString;

                var sql = "select * from GRAM_SYD_LIVE.dbo.X_COIL_MASTER where COILID = '" + coilID + "'";

                try
                {
                    using (var context = new DbContext(Global.ConnStr))
                    {
                        slits.CoilDetails = context.Database.SqlQuery <CoilMaster>(sql).ToList <CoilMaster>();
                    }
                }
                catch (Exception e)
                {
                    slits.errMsg = "SQL Exception: " + e + ";";
                }

                if (slits.CoilDetails.Count == 0)
                {
                    slits.errMsg = "No information found in the database.";
                    return(View(slits));
                }

                string M_color        = "";
                string S_color        = "";
                int    uniqueLocation = 0;
                if (slits.CoilDetails[0].COLOR.Length == 4)
                {
                    M_color = slits.CoilDetails[0].COLOR.Substring(0, 2);
                    S_color = slits.CoilDetails[0].COLOR.Substring(2, 2);
                }

                switch (slits.CoilDetails[0].TYPE)
                {
                case "RA":
                    slits.slitNumber = 4;
                    slits.slitWidth  = 170;
                    cover_width      = slits.slitWidth;
                    base_width       = slits.slitWidth;
                    break;

                case "SM":
                    break;

                case "PO":
                    slits.slitNumber = 8;
                    slits.slitWidth  = 135;
                    cover_width      = slits.slitWidth;
                    base_width       = slits.slitWidth;
                    break;

                case "PL":
                    slits.slitNumber = 4;
                    slits.slitWidth  = 255;
                    cover_width      = slits.slitWidth;
                    base_width       = slits.slitWidth;
                    break;

                case "IS":
                    slits.slitNumber = 8;
                    slits.slitWidth  = 116;
                    cover_width      = slits.slitWidth;
                    base_width       = slits.slitWidth;
                    break;

                default:
                    slits.errMsg = "Type not exist.";
                    break;
                }

                if (slits.slitNumber > 0 && slits.CoilDetails != null)
                {
                    string[] slitIDs    = new string[slits.slitNumber];
                    string[] slitLabels = new string[slits.slitNumber];
                    slits.QRcodes  = new string[8];
                    slits.Barcodes = new string[8];
                    for (int i = 1; i < slitIDs.Length + 1; i++)
                    {
                        slitIDs[i - 1] = slits.CoilDetails[0].COILID + "_" + i;
                        slits.slits.Add(new CoilSlit());
                        slits.slits[i - 1].COIL_SLIT_ID   = slitIDs[i - 1];
                        slits.slits[i - 1].TYPE           = slits.CoilDetails[0].TYPE;
                        slits.slits[i - 1].COLOR          = slits.CoilDetails[0].COLOR;
                        slits.slits[i - 1].M_COLOR        = M_color;
                        slits.slits[i - 1].S_COLOR        = S_color;
                        slits.slits[i - 1].WEIGHT         = (int)(slits.CoilDetails[0].WEIGHT / slits.slitNumber);
                        slits.slits[i - 1].GAUGE          = slits.CoilDetails[0].GAUGE;
                        slits.slits[i - 1].LENGTH         = slits.CoilDetails[0].CLENGTH;
                        slits.slits[i - 1].UNIQUELOCATION = uniqueLocation;
                        if (i % 2 != 0)
                        {
                            slits.slits[i - 1].WIDTH = cover_width;
                        }
                        else
                        {
                            slits.slits[i - 1].WIDTH = base_width;
                        }
                        slits.slits[i - 1].STATUS = 0; // new -> 0, used -> 1

                        slitLabels[i - 1] = slits.CoilDetails[0].COILID + "_" + i + "+" + slits.CoilDetails[0].TYPE + "+" + slits.CoilDetails[0].COLOR + "+" + (int)(slits.CoilDetails[0].WEIGHT / slits.slitNumber) + "+" + slits.CoilDetails[0].GAUGE + "+" + slits.slits[i - 1].WIDTH;
                        BarcodeMetrics barcodeMetrics = QRcode.GetDefaultMetrics(150);
                        barcodeMetrics.Scale = 3; //qrcode size
                        img_QRcode           = QRcode.Draw(slitLabels[i - 1], barcodeMetrics);
                        imgBytes             = turnImageToByteArray(img_QRcode);
                        imgString            = Convert.ToBase64String(imgBytes);
                        slits.QRcodes[i - 1] = String.Format("<img src=\"data:image/png;base64,{0}\"/>", imgString);

                        img_Barcode           = barcode128.Draw(slitLabels[i - 1], 100);
                        imgBytes              = turnImageToByteArray(img_Barcode);
                        imgString             = Convert.ToBase64String(imgBytes);
                        slits.Barcodes[i - 1] = String.Format("<img src=\"data:image/png;base64,{0}\"/>", imgString);
                    }
                    slits.CoilSlitIDs    = slitIDs;
                    slits.CoilSlitLabels = slitLabels;

                    if (slits.printFlag == "print")
                    {
                        for (int i = 0; i < slits.CoilSlitIDs.Count; i++)
                        {
                            var coilID_sql         = new SqlParameter("@coilID", slits.CoilDetails[0].COILID);
                            var coilSlitID_sql     = new SqlParameter("@coilSlitID", slits.slits[i].COIL_SLIT_ID);
                            var type_sql           = new SqlParameter("@type", slits.slits[i].TYPE);
                            var color_sql          = new SqlParameter("@color", slits.slits[i].COLOR);
                            var m_color_sql        = new SqlParameter("@m_color", slits.slits[i].M_COLOR);
                            var s_color_sql        = new SqlParameter("@s_color", slits.slits[i].S_COLOR);
                            var weight_sql         = new SqlParameter("@weight", slits.slits[i].WEIGHT);
                            var gauge_sql          = new SqlParameter("@gauge", slits.slits[i].GAUGE);
                            var width_sql          = new SqlParameter("@width", slits.slits[i].WIDTH);
                            var status_sql         = new SqlParameter("@status", slits.slits[i].STATUS);
                            var userID_sql         = new SqlParameter("@userID", ((Scanner.Models.User)Session["User"]).UserName);
                            var length_sql         = new SqlParameter("@length", DBNull.Value);
                            var uniqueLocation_sql = new SqlParameter("@uniqueLocation", slits.slits[i].UNIQUELOCATION);
                            if (slits.slits[i].LENGTH != null)
                            {
                                length_sql = new SqlParameter("@length", slits.slits[i].LENGTH);
                            }
                            else
                            {
                                length_sql = new SqlParameter("@length", DBNull.Value);
                            }

                            var sql_update = "exec GramOnline.dbo.proc_Y_AddCoilSlit " +
                                             "@coilID, " +
                                             "@coilSlitID, " +
                                             "@type, " +
                                             "@color, " +
                                             "@m_color, " +
                                             "@s_color, " +
                                             "@weight, " +
                                             "@gauge, " +
                                             "@width, " +
                                             "@status, " +
                                             "@userID, " +
                                             "@length, " +
                                             "@uniqueLocation ";

                            try
                            {
                                using (var context = new DbContext(Global.ConnStr))
                                {
                                    context.Database.ExecuteSqlCommand(sql_update,
                                                                       coilID_sql,
                                                                       coilSlitID_sql,
                                                                       type_sql,
                                                                       color_sql,
                                                                       m_color_sql,
                                                                       s_color_sql,
                                                                       weight_sql,
                                                                       gauge_sql,
                                                                       width_sql,
                                                                       status_sql,
                                                                       userID_sql,
                                                                       length_sql,
                                                                       uniqueLocation_sql);
                                }
                            }
                            catch (Exception e)
                            {
                                slits.errMsg = "SQL Exception: " + e.Message + ";";
                            }
                        }
                    }
                }
            }
            return(View(slits));
        }
示例#23
0
        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            Graphics g = e.Graphics;

            if (BackColorText.Text == "")
            {
                label = RackNumberText.Text + "+" + TypeText.Text + "+" + FrontColorText.Text + "+" + comboBox1.Text;
            }
            else
            {
                label = RackNumberText.Text + "+" + TypeText.Text + "+" + FrontColorText.Text.Substring(0, 2) + BackColorText.Text.Substring(0, 2) + "+" + comboBox1.Text;
            }

            CodeQrBarcodeDraw QRcode = BarcodeDrawFactory.CodeQr; // to generate QR code

            System.Drawing.Image QRcodeImage = QRcode.Draw(label, 100);
            // RectangleF(The coordinates of the upper-left corner of the rectangle, width, height)
            RectangleF QRcodeRect = new RectangleF(20.0F, 40.0F, 150.0F, 150.0F);

            g.DrawImage(QRcodeImage, QRcodeRect);

            BarcodeDraw bdraw = BarcodeDrawFactory.GetSymbology(BarcodeSymbology.Code128);

            System.Drawing.Image barcodeImage = bdraw.Draw(label, 100);
            RectangleF           barcodeRect  = new RectangleF(350.0F, 60.0F, 430.0F, 110.0F);

            g.DrawImage(barcodeImage, barcodeRect);

            // Create string to draw.
            String drawString = label.ToUpper();

            // center the text in a specified rectangle.
            StringFormat sf = new StringFormat();

            sf.LineAlignment = StringAlignment.Center;
            sf.Alignment     = StringAlignment.Center;

            SolidBrush drawBrush;

            // Back color
            if (BackColorText.Text != "")
            {
                drawBrush = new SolidBrush(Color.White);
                System.Drawing.Font colorFont2 = new System.Drawing.Font("Ariel", 40, FontStyle.Bold);
                g.FillRectangle(new SolidBrush(Color.Black), 170, 125, 170, 60);

                RectangleF colorRect2 = new RectangleF(160.0F, 120.0F, 180.0F, 80.0F);
                g.DrawString(BackColorText.Text.ToUpper(), colorFont2, drawBrush, colorRect2, sf);
            }

            // front color
            drawBrush = new SolidBrush(Color.Black);

            System.Drawing.Font colorFont = new System.Drawing.Font("Arial Black", 50, FontStyle.Bold);
            RectangleF          colorRect = new RectangleF(150.0F, 40.0F, 220.0F, 80.0F);

            g.DrawString(FrontColorText.Text.ToUpper(), colorFont, drawBrush, colorRect, sf);

            // type
            System.Drawing.Font typeFont = new System.Drawing.Font("Ariel", 30, FontStyle.Bold);
            RectangleF          typeRect = new RectangleF(400.0F, 15.0F, 100.0F, 60.0F);

            g.DrawString(TypeText.Text.ToUpper(), typeFont, drawBrush, typeRect, sf);

            // date
            string month_year = DateTime.Now.ToString("MMM").ToUpper() + "_" + DateTime.Now.ToString("yy");

            System.Drawing.Font timeFont = new System.Drawing.Font("Ariel", 20, FontStyle.Bold);
            RectangleF          timeRect = new RectangleF(550.0F, 15.0F, 150.0F, 60.0F);

            g.DrawString(month_year, timeFont, drawBrush, timeRect, sf);

            // width
            System.Drawing.Font widthFont = new System.Drawing.Font("Ariel", 30, FontStyle.Bold);
            RectangleF          widthRect = new RectangleF(700.0F, 15.0F, 100.0F, 60.0F);

            g.DrawString(comboBox1.Text, widthFont, drawBrush, widthRect, sf);

            // Coil ID
            System.Drawing.Font drawFont = new System.Drawing.Font("Ariel", 16);

            // Create point for upper-left corner of drawing.
            float x = 345.0F;
            float y = 170.0F;

            g.DrawString(drawString, drawFont, drawBrush, x, y);
            return;
        }
示例#24
0
        private void CreateMasterCoilPDFButton_Click(object sender, EventArgs e)
        {
            char[] delimiters = { ' ', ',' };
            string COILID, TYPE = "", COLOR, GAUGE, WIDTH;
            int    WEIGHT;

            if ((System.IO.File.Exists(@"C:\Coil master 28-02-2019.csv")) == true)
            {
                int       pageNumber = 1;
                int       fileNumber = 0;
                int       i          = 0; // number of columns
                int       j          = 0; // number of rows
                ArrayList lines      = new ArrayList();

                foreach (string line in System.IO.File.ReadLines(@"C:\Coil master 28-02-2019.csv"))
                {
                    lines.Add(line);
                }

                int totalFiles = (int)Math.Ceiling((double)lines.Count / 50);

                for (; fileNumber < totalFiles; fileNumber++)
                {
                    j = 0; // reset the number of rows for each new document
                    string path   = Application.StartupPath;
                    var    pgSize = new iTextSharp.text.Rectangle(2976, 4194);

                    Document  pdfdoc = new Document(pgSize);                                                                                                                                       // Setting the page size for the PDF
                    PdfWriter writer = PdfWriter.GetInstance(pdfdoc, new FileStream(path + "/MasterCoils/" + (1 + (50 * fileNumber)) + "-" + (50 + (fileNumber * 50)) + ".pdf", FileMode.Create)); //Using the PDF Writer class to generate the PDF
                    pdfdoc.Open();                                                                                                                                                                 // Opening the PDF to write the data from the textbox

                    int maxRows = 50;
                    if (fileNumber == totalFiles - 1)
                    {
                        maxRows = lines.Count - (50 * fileNumber) - 1;
                    }

                    // cannot write into new pdf
                    foreach (string line in lines.GetRange(1 + (fileNumber * 50), maxRows))
                    {
                        try
                        {
                            string[] inputArray = line.Split(delimiters); // split the input string by using the delimiter ','

                            COILID = inputArray[0];
                            TYPE   = inputArray[1];
                            COLOR  = inputArray[2];
                            WEIGHT = Int32.Parse(inputArray[3]);
                            GAUGE  = inputArray[4];
                            WIDTH  = inputArray[5];

                            CodeQrBarcodeDraw     QRcode      = BarcodeDrawFactory.CodeQr; // to generate QR code
                            System.Drawing.Image  QRcodeImage = QRcode.Draw(COILID + "+" + TYPE + "+" + COLOR + "+" + WEIGHT + "+" + GAUGE + "+" + WIDTH, 100);
                            iTextSharp.text.Image pic         = iTextSharp.text.Image.GetInstance(QRcodeImage, System.Drawing.Imaging.ImageFormat.Jpeg);
                            pic.ScaleAbsolute(90, 90);
                            pic.SetAbsolutePosition(20 + (595 * i), (419 * (9 - j)) + 300);

                            Code128BarcodeDraw    barcode128   = BarcodeDrawFactory.Code128WithChecksum; // to generate barcode
                            System.Drawing.Image  BarcodeImage = barcode128.Draw(COILID + "+" + TYPE + "+" + COLOR + "+" + WEIGHT + "+" + GAUGE + "+" + WIDTH, 100);
                            iTextSharp.text.Image pic2         = iTextSharp.text.Image.GetInstance(BarcodeImage, System.Drawing.Imaging.ImageFormat.Jpeg);
                            pic2.ScaleAbsolute(310, 90);
                            pic2.SetAbsolutePosition(250 + (595 * i), (419 * (9 - j)) + 300);

                            pdfdoc.Add(pic);
                            pdfdoc.Add(pic2);
                            PdfContentByte cb = writer.DirectContent;
                            // we tell the ContentByte we're ready to draw text
                            cb.BeginText();

                            // set up Font and Size for Content to be shown in PDF
                            BaseFont mybf = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

                            cb.SetFontAndSize(mybf, 15);
                            cb.SetTextMatrix(250 + (595 * i), (419 * (9 - j)) + 280);
                            cb.ShowText(COILID + "+" + TYPE + "+" + COLOR + "+" + WEIGHT + "+" + GAUGE + "+" + WIDTH);

                            cb.SetFontAndSize(mybf, 45);
                            if (COLOR.Length == 4)
                            {
                                cb.SetTextMatrix(120 + (595 * i), (419 * (9 - j)) + 350);
                            }
                            else
                            {
                                cb.SetTextMatrix(135 + (595 * i), (419 * (9 - j)) + 350);
                            }
                            cb.ShowText(COLOR);

                            cb.SetFontAndSize(mybf, 35);
                            cb.SetTextMatrix(160 + (595 * i), (419 * (9 - j)) + 320);
                            cb.ShowText(TYPE);

                            cb.SetFontAndSize(mybf, 25);
                            cb.SetTextMatrix(130 + (595 * i), (419 * (9 - j)) + 300);
                            string month_year = DateTime.Now.ToString("MMM").ToUpper() + "_" + DateTime.Now.ToString("yy");
                            cb.ShowText(month_year);

                            cb.SetFontAndSize(mybf, 150);
                            cb.SetTextMatrix(120 + (595 * i), (419 * (9 - j)) + 150);
                            cb.ShowText(COLOR);

                            cb.SetFontAndSize(mybf, 100);
                            cb.SetTextMatrix(140 + (595 * i), (419 * (9 - j)) + 50);
                            cb.ShowText(TYPE);

                            // we tell the contentByte, we've finished drawing text
                            cb.EndText();

                            // A5 size: 21cm x 14.8cm, (595, 419)
                            var A5Size = new iTextSharp.text.Rectangle(15 + (595 * i), (419 * (9 - j)) + 15, 580 + (595 * i), (419 * (9 - j)) + 404);
                            iTextSharp.text.Rectangle pageBorderRect = new iTextSharp.text.Rectangle(A5Size);

                            pageBorderRect.BorderWidth = 6;
                            i++;
                            if (i == 5)
                            {
                                j++;
                                i = 0;
                            }
                            pageNumber++;
                            cb.SetColorStroke(BaseColor.GRAY);
                            cb.Rectangle(pageBorderRect.Left, pageBorderRect.Bottom, pageBorderRect.Width, pageBorderRect.Height);
                            cb.Stroke();
                        }
                        catch (Exception ex)
                        {
                            ErrMsg.Text = "Input format is not corrent!" + ex.Message;
                            COILID      = null;
                            TYPE        = null;
                            COLOR       = null;
                            WEIGHT      = 0;
                            GAUGE       = null;
                            WIDTH       = null;
                            return;
                        }
                    }
                    pdfdoc.Close();
                }
            }
        }
示例#25
0
        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            while (pageNumber < slitLabels.Length)
            {
                Graphics g = e.Graphics;

                CodeQrBarcodeDraw    QRcode      = BarcodeDrawFactory.CodeQr; // to generate QR code
                System.Drawing.Image QRcodeImage = QRcode.Draw(slitLabels[pageNumber], 100);
                // RectangleF(The coordinates of the upper-left corner of the rectangle, width, height)
                RectangleF QRcodeRect = new RectangleF(20.0F, 40.0F, 150.0F, 150.0F);
                g.DrawImage(QRcodeImage, QRcodeRect);

                BarcodeDraw          bdraw        = BarcodeDrawFactory.GetSymbology(BarcodeSymbology.Code128);
                System.Drawing.Image barcodeImage = bdraw.Draw(slitLabels[pageNumber], 100);
                RectangleF           barcodeRect  = new RectangleF(350.0F, 60.0F, 430.0F, 110.0F);
                g.DrawImage(barcodeImage, barcodeRect);

                // Create string to draw.
                String drawString = slitLabels[pageNumber].ToUpper();

                // center the text in a specified rectangle.
                StringFormat sf = new StringFormat();
                sf.LineAlignment = StringAlignment.Center;
                sf.Alignment     = StringAlignment.Center;

                SolidBrush drawBrush;

                // Back color
                if (TYPE.ToUpper() == "SM")
                {
                    COLOR     = SMFrontColorText.Text;
                    drawBrush = new SolidBrush(Color.White);
                    System.Drawing.Font colorFont2 = new System.Drawing.Font("Ariel", 40, FontStyle.Bold);
                    g.FillRectangle(new SolidBrush(Color.Black), 170, 125, 170, 60);

                    RectangleF colorRect2 = new RectangleF(160.0F, 120.0F, 180.0F, 80.0F);
                    g.DrawString(SMBackColorText.Text.ToUpper(), colorFont2, drawBrush, colorRect2, sf);
                }

                // front color
                drawBrush = new SolidBrush(Color.Black);

                System.Drawing.Font colorFont = new System.Drawing.Font("Arial Black", 50, FontStyle.Bold);
                RectangleF          colorRect = new RectangleF(150.0F, 40.0F, 220.0F, 80.0F);
                g.DrawString(COLOR.ToUpper(), colorFont, drawBrush, colorRect, sf);

                // type
                System.Drawing.Font typeFont = new System.Drawing.Font("Ariel", 30, FontStyle.Bold);
                RectangleF          typeRect = new RectangleF(400.0F, 15.0F, 100.0F, 60.0F);
                g.DrawString(TYPE.ToUpper(), typeFont, drawBrush, typeRect, sf);

                // date
                string month_year            = DateTime.Now.ToString("MMM").ToUpper() + "_" + DateTime.Now.ToString("yy");
                System.Drawing.Font timeFont = new System.Drawing.Font("Ariel", 20, FontStyle.Bold);
                RectangleF          timeRect = new RectangleF(550.0F, 15.0F, 150.0F, 60.0F);
                g.DrawString(month_year, timeFont, drawBrush, timeRect, sf);

                // width
                string width = slitLabels[pageNumber].Split('+')[5];
                System.Drawing.Font widthFont = new System.Drawing.Font("Ariel", 30, FontStyle.Bold);
                RectangleF          widthRect = new RectangleF(700.0F, 15.0F, 100.0F, 60.0F);
                g.DrawString(width, widthFont, drawBrush, widthRect, sf);

                // Coil ID
                System.Drawing.Font drawFont = new System.Drawing.Font("Ariel", 16);

                // Create point for upper-left corner of drawing.
                float x = 345.0F;
                float y = 170.0F;
                g.DrawString(drawString, drawFont, drawBrush, x, y);

                if (TYPE.ToUpper() == "SM")
                {
                    pageNumber++;
                }
                else
                {
                    pageNumber += 2;
                }

                if (pageNumber < slitLabels.Length)
                {
                    e.HasMorePages = true; //e.HasMorePages raised the PrintPage event once per page .
                }
                return;
            }
        }
示例#26
0
        public static Image Generate(string text, int maxBarHeight)
        {
            CodeQrBarcodeDraw QRCode = BarcodeDrawFactory.CodeQr;

            return(QRCode.Draw(text, maxBarHeight));
        }