Exemplo n.º 1
0
        private void SaveAllbutton_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult result = MessageBox.Show("Are You Sure?", DateTime.Now.ToString(), MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
                    {
                        DataTable barcodes     = barcodesTableAdapter.GetData();
                        string    selectedPath = folderBrowserDialog1.SelectedPath;

                        StreamWriter swExtLogFile = new StreamWriter(selectedPath + "\\Barcodes.txt", true);
                        swExtLogFile.Write(Environment.NewLine);

                        progressBar1.Minimum = System.IO.Directory.GetFiles(selectedPath).Length;

                        progressBar1.Maximum = barcodes.Rows.Count + System.IO.Directory.GetFiles(selectedPath).Length;

                        foreach (DataRow item in barcodes.Rows)
                        {
                            string barcode = item[0].ToString();
                            string path    = selectedPath + "\\" + barcode + ".png";

                            //.ResizeTo(600, 525).SetMargins(25).ChangeBackgroundColor(Color.Transparent).AddBarcodeValueTextBelowBarcode()
                            BarcodeWriter br = new BarcodeWriter();
                            br.Format         = BarcodeFormat.CODE_128;
                            br.Options.Margin = 20;
                            br.Options.Height = 450;
                            br.Options.Width  = 750;

                            ZXing.Rendering.BitmapRenderer rend = new ZXing.Rendering.BitmapRenderer();
                            rend.Background = Color.Transparent;

                            rend.TextFont = new Font("arial", 55);

                            br.Renderer = rend;

                            br.Write(barcode).Save(path, System.Drawing.Imaging.ImageFormat.Png);

                            swExtLogFile.WriteLine(barcode);

                            progressBar1.Value = System.IO.Directory.GetFiles(selectedPath).Length;
                        }

                        swExtLogFile.Write(Environment.NewLine);
                        swExtLogFile.Write("***** END OF DATA [" + barcodes.Rows.Count + " Barcode] **** " + DateTime.Now.ToString());
                        swExtLogFile.Flush();
                        swExtLogFile.Close();

                        MessageBox.Show("Done !");
                        progressBar1.Value = progressBar1.Minimum;
                    }
                }
            }
            catch (Exception error)
            {
                MessageBox.Show(error.ToString());
            }
        }
        protected virtual void EncodeBarcodeBmp()
        {
            var encodingOptions = new ZXing.Common.EncodingOptions
            {
                Width  = WidthPx,
                Height = HeightPx
            };

            ZXing.Rendering.BitmapRenderer renderer = new ZXing.Rendering.BitmapRenderer()
            {
                Foreground = System.Drawing.Color.Black,
                Background = System.Drawing.Color.White
            };
            var w = new ZXing.BarcodeWriter()
            {
                Format   = BarcodeFormat,
                Options  = encodingOptions,
                Renderer = renderer
            };

            BarcodeImageBmp = w.Write(BarcodeContent);

            using (var imageStream = new System.IO.MemoryStream())
            {
                BarcodeImageBmp.Save(imageStream, ImageFormat);
                BarcodeImageEncoded = imageStream.ToArray();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Draws the barcode and returns the image object.
        /// </summary>
        /// <returns></returns>
        private Image DrawBarCode()
        {
            barcode.Format = (ZXing.BarcodeFormat) this.BarcodeType;
            barcode.Options.PureBarcode = !this.ShowLabel;
            barcode.Options.Width       = this.Width - this.Padding.Horizontal;
            barcode.Options.Height      = this.Height - this.Padding.Vertical;
            ZXing.Rendering.BitmapRenderer renderer = (ZXing.Rendering.BitmapRenderer)barcode.Renderer;
            renderer.Background = ResolveColor(this.BackColor);
            renderer.Foreground = ResolveColor(this.ForeColor);
            renderer.TextFont   = this.Font;

            return(barcode.Write(this.Text));
        }
Exemplo n.º 4
0
        private void button1_Click(object sender, EventArgs e)
        {
            MultiFormatWriter mutiWriter = new MultiFormatWriter();
            BitMatrix         bm         = mutiWriter.encode("http://www.vgo2013.com/WebService/QR.aspx?ID=" + "111111", BarcodeFormat.QR_CODE, 300, 300);

            ZXing.Rendering.BitmapRenderer br = new ZXing.Rendering.BitmapRenderer();
            Bitmap img = br.Render(bm, BarcodeFormat.QR_CODE, "http://www.vgo2013.com/WebService/QR.aspx?ID=" + "111111");

            img = KiResizeImage(img, 90, 90, 0);
            string filename = System.Environment.CurrentDirectory + "\\QR" + DateTime.Now.Ticks.ToString() + ".jpg";

            img.Save(filename, System.Drawing.Imaging.ImageFormat.Jpeg);
        }
Exemplo n.º 5
0
        public Bitmap serializePattern()
        {
            MemoryStream ms = new MemoryStream();

            BinaryWriter br = new BinaryWriter(ms);

            br.Write(padBytes(0));

            byte[] nameBytes = UnicodeEncoding.Unicode.GetBytes(designName);
            int pad = 41 - nameBytes.Length;

            br.Write(nameBytes);
            if (pad > 0)
            br.Write(padBytes(pad));

            // These are *1 and 2, the first two bytes of the unique id.
            br.Write(padBytes(2));

            byte[] creatorBytes = UnicodeEncoding.Unicode.GetBytes(creatorName);
            pad = 20 - nameBytes.Length;

            br.Write(creatorBytes);
            if (pad > 0)
            br.Write(padBytes(pad));

            // Special bytes 3 and 4.
            br.Write(padBytes(2));

            byte[] cityBytes = UnicodeEncoding.Unicode.GetBytes(cityName);

            pad = 18 - nameBytes.Length;

            br.Write(cityBytes);
            if (pad > 0)
            br.Write(padBytes(pad));

            br.Write(padBytes(4));

            for (int i = 0; i < 15; i++)
            {
                br.Write(new byte[]{NewLeafBitmap.findPalIndexInv(this.design.filepal[i])});
            }

            // Special byte 7.
            br.Write(padBytes(1));

            br.Write(new byte[] { (byte)0x0A });
            br.Write(new byte[] { (byte)0x09 });

            br.Write(padBytes(2));

            BitArray halfBytes = new BitArray(1024*4);

            int counter = 0;

            List<byte> blist = new List<byte>();

            for (int i = 0; i < 32; i++)
                for (int j = 0; j < 32; j++)
                {
                    blist.Add((byte)(this.design.falseColor.GetPixel(j,i).ToArgb()));

                }

            int counterR = 0;
            for (int i = 0; i < blist.Count; )
            {
                BitArray halfWord = new BitArray(new byte[] { blist[i] });
                halfBytes[counterR + 4] =     halfWord[0];
                halfBytes[counterR + 5]= halfWord[1];
                halfBytes[counterR + 6] = halfWord[2];
                halfBytes[counterR + 7] = halfWord[3];
                halfWord = new BitArray(new byte[] { blist[i + 1] });
                halfBytes[counterR + 0] = halfWord[0];
                halfBytes[counterR + 1] = halfWord[1];
                halfBytes[counterR + 2] = halfWord[2];
                halfBytes[counterR + 3] = halfWord[3];
                counterR += 8;

                i += 2;
            }

            FileStream fs = File.Open("C:/DATASETS/serialize.txt", FileMode.Create);
               // ms.CopyTo(fs);

            byte[] junk = copyOctetwiseReverse(ms.ToArray());
            BitArray a = new BitArray(junk);

              //  a = a.Append(new BitArray(4));

            BitArray ab = a.Append(halfBytes);

            BitArray header = new BitArray(new byte[]{QR_MAGIC});
            header.Reverse();
            BitArray header2 = new BitArray(new byte[] { 38 });
            header2.Reverse();

            BitArray header3 = new BitArray(4);

            header3.Set(1, true);
            header3.Set(1, true);
            header3.Set(0, true);
            header3.Set(0, true);

            //header = header2.Prepend(header);

             BitArray all = header.Append(header2);
             all = all.Append(header3);

             all = all.Append(ab);

            byte[] omni = all.ToByteArray();

            MessageBox.Show(BitConverter.ToString(omni));

            fs.Write(omni,0,omni.Length);

               // fs.WriteByte(0xEC);
              //  fs.WriteByte(0x11);
               // fs.WriteByte(0xEC);
               // fs.WriteByte(0x11);
            System.Text.Encoding iso_8859_1 = System.Text.Encoding.GetEncoding("iso-8859-1");

            QRCodeWriter qrw = new QRCodeWriter();

               // for (int i = 0; i < omni.Length; i++)
               // {
               //     omni[i] = (byte)((sbyte)omni[i]);
               // }

            Dictionary<EncodeHintType, object> h = new Dictionary<EncodeHintType, object>();
            h.Add(ZXing.EncodeHintType.CHARACTER_SET, "CP437");

            h.Add(ZXing.EncodeHintType.DISABLE_ECI, true);
            h.Add(ZXing.EncodeHintType.ERROR_CORRECTION,ZXing.QrCode.Internal.ErrorCorrectionLevel.H);

            ZXing.QrCode.QrCodeEncodingOptions qrec = new QrCodeEncodingOptions();

            var writer = new BarcodeWriter
            {
                Format = BarcodeFormat.QR_CODE,
                Options = new QrCodeEncodingOptions
                {
                    Height = 188,
                    Width = 188,
                    CharacterSet = "CP437",
                    PureBarcode = true,
                    ErrorCorrection = ZXing.QrCode.Internal.ErrorCorrectionLevel.L,
                    DisableECI = false,

                }

            };

            char[] chars = new char[omni.Length];

            for (int i = 0; i < omni.Length; i++)
            {
                chars[i] = (char) omni[i];
            }

            ZXing.Common.BitMatrix bmx =  writer.
               Encode(Encoding.GetEncoding("CP437").GetString(omni));//qrw.encode(new String(), ZXing.BarcodeFormat.QR_CODE, 300, 300);

            //bmx = createBinQRCode(omni, omni.Length, 0);

            fs.Close();

            ms.Close();

              //return bmx.ToBitmap();

               ZXing.BarcodeWriter ss= new ZXing.BarcodeWriter();

               ZXing.IBarcodeWriter reader = new BarcodeWriter();

             ZXing.Rendering.BitmapRenderer bmpr = new ZXing.Rendering.BitmapRenderer();
             MessageBox.Show(Encoding.GetEncoding("CP437").GetString(omni).Substring(0, 10));
             return bmpr.Render(bmx, writer.Format,  Encoding.GetEncoding("CP437").GetString(omni));

            //   Gma.QrCodeNet.Encoding.QrEncoder hi = new Gma.QrCodeNet.Encoding.QrEncoder();
             //  Gma.QrCodeNet.Encoding.QrCode qr = new Gma.QrCodeNet.Encoding.QrCode();
             //

             //  hi.ErrorCorrectionLevel = Gma.QrCodeNet.Encoding.ErrorCorrectionLevel.L;

             //  hi.TryEncode(omni, out qr);

             //  SVGRenderer svg = new SVGRenderer(new FixedModuleSize(6, QuietZoneModules.Two), new FormColor(Color.Black), new FormColor(Color.White));

               // FileStream FSX = new FileStream("C:/DATASETS/QR.svg", FileMode.Create);
            //svg.WriteToStream(qr.Matrix, FSX);
              //  FSX.Close();

             // Bitmap bmp2 = new Bitmap(qr.Matrix.Width, qr.Matrix.Height);
             //  for (int i = 0; i < qr.Matrix.Width; i++)
             //      for (int j = 0; j < qr.Matrix.Height; j++)
             //          bmp2.SetPixel(i, j, qr.Matrix.InternalArray[i, j] ? Color.Black : Color.White);

             //  bmp2.Save("C:/DATASETS/gma");

            //   return bmp2;
        }
Exemplo n.º 6
0
        /*
         * txtKdNr
         * txtUnte
         * txtAnsp
         * txtBran
         * txtMail
         * txtTele
         * txtWeb
         *
         */
        private void Daten_Load(object sender, EventArgs e)
        {
            string[] d = kahba.Split(new string[] { "_~_" }, StringSplitOptions.None);
            KdNr         = d[0];
            txtKdNr.Text = KdNr;
            string sin = d[1];

            txtUnte.Text = d[2];
            txtAnsp.Text = d[3];
            txtBran.Text = d[4];
            txtMail.Text = d[5];
            txtTele.Text = d[6];
            txtWeb.Text  = d[7];


            // MessageBox.Show((new System.Net.WebClient()).DownloadString("http://178.33.211.91:1337/get_auftrag.php?s=" + KdNr));
            string string_to_parse = (new System.Net.WebClient()).DownloadString("http://178.33.211.91:1337/get_auftrag.php?s=" + KdNr);

            int i = 0;

            while (i < string_to_parse.Split(new string[] { "\n" }, StringSplitOptions.None).Length)
            {
                string[] lol = string_to_parse.Split(new string[] { "\n" }, StringSplitOptions.None);
                if (lol[i] != "")
                {
                    string[] lel = lol[i].Split(new string[] { "_~_" }, StringSplitOptions.None);
                    listBox1.Items.Add("AufNr:" + lel[0] + "  |  " + "Art:" + lel[1]);
                }
                i++;
            }
            //Erstelle V-Card & Plante QR-Code
            string alz = txtAnsp.Text;
            string n1  = "";
            string n2  = "";


            //string[] name = alz.Split(new string[] { " " }, StringSplitOptions.None);
            //  n1 = name[0];
            // n1 = name[1];
            // FileIOPermission fileIOPerm = new FileIOPermission(FileIOPermissionAccess.Write, @"C:\Users\r11pl\Desktop");

            // fileIOPerm.Demand();

            //// MessageBox.Show(test);

            //  string path = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            System.IO.Directory.CreateDirectory("Data");

            string path1 = "Data/" + txtKdNr.Text + ".vcf";

            string[] lines =
            {
                "BEGIN:VCARD",
                "VERSION:3.0",
                "FN:" + txtAnsp.Text,
                "N:" + n2 + ";" + n1,
                "ORG:" + txtUnte.Text,
                "TEL;TYPE=WORK,VOICE:" + txtTele.Text,
                "EMAIL;TYPE=INTERNET:" + txtMail.Text,
                "URL:" + txtWeb.Text,
                "END:VCARD"
            };
            System.IO.File.WriteAllLines(path1, lines);

            string        contacts   = File.ReadAllText("Data/" + txtKdNr.Text + ".vcf");
            BarcodeWriter bcWriter   = new BarcodeWriter();
            var           encOptions = new ZXing.Common.EncodingOptions()
            {
                Width = 200, Height = 200, Margin = 0
            };

            bcWriter.Options = encOptions;

            ZXing.Rendering.BitmapRenderer renderer = new ZXing.Rendering.BitmapRenderer();

            bcWriter.Renderer = renderer;
            bcWriter.Format   = BarcodeFormat.QR_CODE;
            Bitmap bm = bcWriter.Write(contacts);

            pictureBox1.Image    = bm;
            pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
        }
Exemplo n.º 7
0
        private void GetCouponData(object strService)
        {
            Object o = new Object();

            lock (o)
            {
                while (!bGDateIsExit)
                {
                    try
                    {
                        Thread.Sleep(2000);
                        DataSet dsPhoto = wsGetPrindCode.GetPrintPhoto(strSiteCode, strClientID);
                        if (null != dsPhoto && dsPhoto.Tables.Count > 0 && dsPhoto.Tables[0].Rows.Count > 0)
                        {
                            wsGetPrindCode.UpdatePrintState(strHappyPhotoID, "2");

                            strHappyPhotoID = dsPhoto.Tables[0].Rows[0]["ID"].ToString();
                            strPrintCode    = dsPhoto.Tables[0].Rows[0]["PrintCode"].ToString();
                            //strImg = "http://localhost:1156/HP_Photo/" + dsPhoto.Tables[0].Rows[0]["Img"].ToString();
                            strImg        = "http://114.215.108.27//HP_Photo/" + dsPhoto.Tables[0].Rows[0]["Img"].ToString();
                            strAttachText = dsPhoto.Tables[0].Rows[0]["AttachText"].ToString();

                            strPrintImg = "PrintPhoto." + strImg.Split('.').Last();
                            //取打印的图片
                            using (System.Net.WebClient wc = new System.Net.WebClient())
                            {
                                wc.Headers.Add("User-Agent", "Chrome");
                                wc.DownloadFile(strImg, Application.StartupPath + "/" + strPrintImg);
                            }

                            //生成二维码

                            MultiFormatWriter mutiWriter      = new MultiFormatWriter(); //new com.google.zxing.MultiFormatWriter();
                            BitMatrix         bm              = mutiWriter.encode("http://www.vgo2013.com/PalmShop/ShopCode/CodeAward.aspx?ID=" + strHappyPhotoID, BarcodeFormat.QR_CODE, 300, 300);
                            ZXing.Rendering.BitmapRenderer br = new ZXing.Rendering.BitmapRenderer();
                            Bitmap img = br.Render(bm, BarcodeFormat.QR_CODE, "http://www.vgo2013.com/PalmShop/ShopCode/CodeAward.aspx?ID=" + strHappyPhotoID);
                            img = KiResizeImage(img, 65, 65, 0);
                            string filename = System.Environment.CurrentDirectory + "\\log.jpg";
                            img.Save(filename, System.Drawing.Imaging.ImageFormat.Jpeg);

                            #region 打印过程
                            //printDocument.PrinterSettings.PrinterName = "TM58";//设置打印机

                            //printDocument.PrinterSettings.PrinterName = "Microsoft XPS Document Writer";
                            printDocument.PrinterSettings.PrinterName = "PhotoPrint";
                            //设置页边距
                            printDocument.PrinterSettings.DefaultPageSettings.Margins.Left   = 0;
                            printDocument.PrinterSettings.DefaultPageSettings.Margins.Top    = 0;
                            printDocument.PrinterSettings.DefaultPageSettings.Margins.Right  = 0;
                            printDocument.PrinterSettings.DefaultPageSettings.Margins.Bottom = 0;

                            printDocument.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("Custom", 290, 414); //页面大小
                            printDocument.DefaultPageSettings.Landscape = false;                                                     //横向打印

                            //打印开始前
                            printDocument.BeginPrint += new PrintEventHandler(printDocument_BeginPrint);
                            //打印输出(过程)
                            printDocument.PrintPage += new PrintPageEventHandler(printDocument_PrintPage);
                            //打印结束
                            printDocument.EndPrint += new PrintEventHandler(printDocument_EndPrint);

                            printDocument.Print();
                            //PrintDialog pd = new PrintDialog();
                            //pd.Document = printDocument;
                            //if (DialogResult.OK == pd.ShowDialog())
                            //{
                            //    //预览
                            //    PrintPreviewDialog ppd = new PrintPreviewDialog();
                            //    ppd.Document = printDocument;
                            //    if (DialogResult.OK == ppd.ShowDialog()) printDocument.Print();
                            //}
                            #endregion

                            this.BeginInvoke(new Action(() =>
                            {
                            }));
                        }
                        Application.DoEvents();
                        Thread.Sleep(2000);
                    }
                    catch //(Exception ex)
                    {
                        //MessageBox.Show(ex.Message);
                        Thread.Sleep(20000);
                    }
                }
            }
        }