Exemple #1
0
 public static Bitmap GenerateQR(int width,int height,string text)
 {
     var bw = new ZXing.BarcodeWriter();
     var encOptions = new ZXing.Common.EncodingOptions() { Width = width, Height = height, Margin = 0 };
     bw.Options = encOptions;
     bw.Format = ZXing.BarcodeFormat.CODE_128;
     var result = new Bitmap(bw.Write(text));
     return result;
 }
Exemple #2
0
        public static Bitmap generateQr(int width, int height, string text)
        {
            var bw           = new ZXing.BarcodeWriter();
            var encodeOptons = new ZXing.Common.EncodingOptions()
            {
                Width = width, Height = height, Margin = 0
            };

            bw.Options = encodeOptons;
            bw.Format  = ZXing.BarcodeFormat.QR_CODE;
            return(new Bitmap(bw.Write(text)));
        }
        public static void GenerateQRCode(string Text)
        {
            Bitmap wvImage;
            BarcodeWriter wvQRCodeWriter = new BarcodeWriter();
            wvQRCodeWriter.Format = BarcodeFormat.QR_CODE;
            ZXing.Common.EncodingOptions encOptions = new ZXing.Common.EncodingOptions() { Width = 500, Height = 500, Margin = 1 };
            wvQRCodeWriter.Options = encOptions;

            wvImage = wvQRCodeWriter.Write(Text);

            ///implementare per il salvataggio/stampa del QRCode
        }
        public IItemInfo CreateNewBarcode(string productName, int maxHeatingTimeInSeconds,
                                          string recognitionType, string category)
        {
            IItemInfo itemInfo = null;

            if (productName != null && maxHeatingTimeInSeconds > 0 && recognitionType != null && category != null)
            {
                // Created barcodes directory in case there is no existing one.
                Directory.CreateDirectory(BarcodesDirectoryPath);

                // Generate uniqe string and creates QR-Code from it.
                Guid guid = Guid.NewGuid();
                mLogger.WriteLine($"Generating string to encode: {guid}");
                string stringToEncode = guid.ToString();

                ZXing.Common.EncodingOptions encodingOptions = new ZXing.Common.EncodingOptions
                {
                    Width  = 750,
                    Height = 750
                };

                BarcodeWriter barcodeWriter = new BarcodeWriter
                {
                    Format  = BarcodeFormat.QR_CODE,
                    Options = encodingOptions
                };

                string qrCodePath = Path.Combine(BarcodesDirectoryPath, $"{productName}{PNG_EXTENSION}");
                Bitmap qrCode     = barcodeWriter.Write(stringToEncode);
                qrCode.Save(qrCodePath);

                // Adding the new item to DB.
                itemInfo = new ItemInfo(
                    stringToEncode, maxHeatingTimeInSeconds, productName);
                mItemsDictionary.Add(stringToEncode, itemInfo);
                mLogger.WriteLine($"{itemInfo.ItemName} added to database");

                // Remember the recognition algorithm and item category.
                SaveDatabases(itemInfo, recognitionType, category);
            }
            else
            {
                mLogger.WriteError($@"One of more of the next variables is invalid:
{nameof(productName)}:{productName}
{nameof(maxHeatingTimeInSeconds)}:{maxHeatingTimeInSeconds}
{nameof(recognitionType)}:{recognitionType}
{nameof(category)}:{category}");
            }

            return(itemInfo);
        }
Exemple #5
0
        //Gera QrCode. Necessário uso de dll para geração. Estão dentro da pasta NuGet. Se quiserem fazer o download diretamente http://zxingnet.codeplex.com/
        public static Image GerarQrCode(int larg, int alt, string qrCode)
        {
            var bw         = new ZXing.BarcodeWriter();
            var encOptions = new ZXing.Common.EncodingOptions()
            {
                Width = larg, Height = alt, Margin = 0
            };

            bw.Options = encOptions;
            bw.Format  = ZXing.BarcodeFormat.QR_CODE;
            var imageQrCode = new Bitmap(bw.Write(qrCode));

            return(imageQrCode);
        }
Exemple #6
0
        public Bitmap GenerateQR(string text)
        {
            var bw         = new ZXing.BarcodeWriter();
            var encOptions = new ZXing.Common.EncodingOptions()
            {
                Width = 400, Height = 400, Margin = 0
            };

            bw.Options = encOptions;
            bw.Format  = ZXing.BarcodeFormat.QR_CODE;
            var result = Bitmap.CreateBitmap(bw.Write(text));

            return(result);
        }
Exemple #7
0
        Bitmap CreateQRCode(int size, string text)
        {
            var qrCode        = new ZXing.BarcodeWriter();
            var encodeOptions = new ZXing.Common.EncodingOptions()
            {
                Width = size, Height = size, Margin = 0
            };

            qrCode.Options = encodeOptions;
            qrCode.Format  = ZXing.BarcodeFormat.QR_CODE;
            var result = new Bitmap(qrCode.Write(text));

            return(result);
        } //Gera o QRcode da string com base no tamanho (Configurações fixas) (.bmp)
Exemple #8
0
        public static Bitmap GenerateQR(int width, int height, string text)
        {
            var bw         = new ZXing.BarcodeWriter();
            var encOptions = new ZXing.Common.EncodingOptions()
            {
                Width = width, Height = height, Margin = 0
            };

            bw.Options = encOptions;
            bw.Format  = ZXing.BarcodeFormat.QR_CODE;
            Bitmap result = new Bitmap(bw.Write(text), width, height);

            return(result);
        }
Exemple #9
0
        private static Bitmap generateQR(string text)
        {
            var bw         = new ZXing.BarcodeWriter();
            var encOptions = new ZXing.Common.EncodingOptions()
            {
                Width = 250, Height = 250, Margin = 0
            };

            bw.Options = encOptions;
            bw.Format  = ZXing.BarcodeFormat.QR_CODE;
            var result = new Bitmap(bw.Write(text));

            return(result);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            RedirectToLoginIfAnonymous();
            RedirectToLoginIfNecessary();

            service = new OrganizationService("Xrm");
            Guid id;

            if (Guid.TryParse(Request.QueryString["id"], out id))
            {
                XrmContext.CreateQuery("adx_membership").FirstOrDefault(c => c.GetAttributeValue <Guid>("adx_membershipid") == id);
            }

            Guid            redeemGuid = id;
            QueryExpression qe         = new QueryExpression("adx_membership");

            qe.ColumnSet.AllColumns = true;
            EntityCollection ec = service.RetrieveMultiple(qe);

            if (ec.Entities.Count > 0)
            {
                // img_qrcode
                QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
                string        encoding      = ec.Entities[0]["adx_membershipid"].ToString();
                qrCodeEncoder.QRCodeEncodeMode   = QRCodeEncoder.ENCODE_MODE.BYTE;
                qrCodeEncoder.QRCodeScale        = 3;
                qrCodeEncoder.QRCodeVersion      = 7;
                qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;

                var bw         = new ZXing.BarcodeWriter();
                var encOptions = new ZXing.Common.EncodingOptions()
                {
                    Width = 150, Height = 150, Margin = 0
                };
                bw.Options = encOptions;
                bw.Format  = ZXing.BarcodeFormat.QR_CODE;
                var          result  = new Bitmap(bw.Write(encoding));
                MemoryStream _stream = new MemoryStream();
                result.Save(_stream, ImageFormat.Jpeg);
                result.Dispose();

                ImageConverter converter    = new ImageConverter();
                byte[]         qrByte       = (byte[])converter.ConvertTo(new Bitmap(_stream), typeof(byte[]));
                string         base64String = Convert.ToBase64String(qrByte, 0, qrByte.Length);
                membershipQrImage.ImageUrl = "data:image/jpeg;base64," + base64String;
            }
        }
        protected virtual void EncodeBarcodeSvg()
        {
            var encodingOptions = new ZXing.Common.EncodingOptions
            {
                Width  = WidthPx,
                Height = HeightPx
            };

            var svgWriter = new ZXing.BarcodeWriterSvg()
            {
                Options = encodingOptions,
                Format  = BarcodeFormat
            };

            var svgImage = svgWriter.Write(BarcodeContent);

            BarcodeImageSvg = svgImage.ToString();
        }
Exemple #12
0
 public static Bitmap GerarQRCode(int width, int height, string text)
 {
     try
     {
         ZXing.BarcodeWriter          bw         = new ZXing.BarcodeWriter();
         ZXing.Common.EncodingOptions encOptions = new ZXing.Common.EncodingOptions()
         {
             Width = width, Height = height, Margin = 0
         };
         bw.Options = encOptions;
         bw.Format  = ZXing.BarcodeFormat.QR_CODE;
         Bitmap resultado = new Bitmap(bw.Write(text));
         return(resultado);
     }
     catch
     {
         throw;
     }
 }
Exemple #13
0
        public static Image gerarQRCode(Int16 vlLargura, Int16 vlAltura, String dsInformacao)
        {
            /*
             * pictureBox1.Image = Utilidades.GerarQRCode(1, 2, 3);
             * 1 - Largura do QRCode
             * 2 - Altura do QRCode
             * 3 - Texto a virar o QRCode
             */
            var bw         = new ZXing.BarcodeWriter();
            var encOptions = new ZXing.Common.EncodingOptions()
            {
                Width = vlLargura, Height = vlAltura, Margin = 0
            };

            bw.Options = encOptions;
            bw.Format  = ZXing.BarcodeFormat.QR_CODE;
            var resultado = new Bitmap(bw.Write(dsInformacao));

            return(resultado);
        }
Exemple #14
0
 private Bitmap GerarQRCode(int width, int height, string text)
 {
     try
     {
         var bw         = new ZXing.BarcodeWriter();
         var encOptions = new ZXing.Common.EncodingOptions()
         {
             Width  = width,
             Height = height,
             Margin = 0
         };
         bw.Options = encOptions;
         bw.Format  = ZXing.BarcodeFormat.QR_CODE;
         var resultado = new Bitmap(bw.Write(text));
         return(resultado);
     }
     catch (Exception ex)
     {
         throw new Exception("Erro na geração do QrCode - " + ex.Message);
     }
 }
        public Bitmap GerarQRCode(int width, int height, string text)
        {
            try
            {
                var bw         = new ZXing.BarcodeWriter();
                var encOptions = new ZXing.Common.EncodingOptions()
                {
                    Width = width, Height = height, Margin = 2
                };
                bw.Options = encOptions;
                bw.Format  = ZXing.BarcodeFormat.QR_CODE;
                var resultado = new Bitmap(bw.Write(text));

                resultado = Converte_Texto_Para_Imagem(resultado, text, "Arial", Convert.ToInt32(txtFonte.Text), Convert.ToInt32(txtEspacamento.Text));

                return(resultado);
            }
            catch
            {
                throw;
            }
        }
Exemple #16
0
        private Bitmap GenerateQR(int width, int height, string text)
        {
            var bw         = new ZXing.BarcodeWriter();
            var encOptions = new ZXing.Common.EncodingOptions()
            {
                Width = width, Height = height, Margin = 0
            };

            //
            // Error correction
            // Sometimes your QRCode will get damaged or covered up by something – like an image overlay for instance –
            // therefore the designers of the QRCode has added four levels; 7% (L), 15 % (M), 25% (Q), 30% (H) of error
            // correction were a error correction of level H should result in a QRCode that are still valid even when it’s
            // 30% obscured – for more info on error correction check this
            encOptions.Hints.Add(ZXing.EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
            bw.Options = encOptions;
            bw.Format  = ZXing.BarcodeFormat.QR_CODE;

            var result = new Bitmap(bw.Write(text));

            return(result);
        }
Exemple #17
0
        public void GenerateQR(string path)
        {
            var bw = new ZXing.BarcodeWriter();

            var encOptions = new ZXing.Common.EncodingOptions
            {
                Width       = this.Width,
                Height      = this.Height,
                Margin      = 0,
                PureBarcode = false
            };

            encOptions.Hints.Add(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);

            bw.Renderer = new BitmapRenderer();
            bw.Options  = encOptions;
            bw.Format   = ZXing.BarcodeFormat.QR_CODE;
            Bitmap bm = bw.Write(this.Text);

            if (this.OverlayImage)
            {
                Bitmap   overlay        = new Bitmap(ImagePath);
                Bitmap   resizedOverlay = ResizeBitmap(overlay, 100, 100);
                int      deltaHeigth    = bm.Height - resizedOverlay.Height;
                int      deltaWidth     = bm.Width - resizedOverlay.Width;
                Graphics g = Graphics.FromImage(bm);
                g.DrawImage(resizedOverlay, new Point(deltaWidth / 2, deltaHeigth / 2));
            }
            else
            {
                int      deltaHeigth = bm.Height;
                int      deltaWidth  = bm.Width;
                Graphics g           = Graphics.FromImage(bm);
                g.DrawImage(bm, new Point(deltaWidth / 2, deltaHeigth / 2));
            }

            saveQR(path, bm);
        }
Exemple #18
0
 /// <summary>
 /// Generate Code From Text Input
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void GenerateCodeClick(object sender, EventArgs e)
 {
     if (contentInput.Text != "")
     {
         string content      = contentInput.Text;
         var    QRCodeWriter = new ZXing.BarcodeWriter();
         var    QROptions    = new ZXing.Common.EncodingOptions
         {
             Margin = 5,
             Width  = 200,
             Height = 200,
         };
         QRCodeWriter.Options = QROptions;
         QRCodeWriter.Format  = ZXing.BarcodeFormat.QR_CODE;
         var result = QRCodeWriter.Write(content);
         codeDisplay.Image = result;
     }
     else
     {
         MessageBox.Show("Please Input Content You Want To Generate Code", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         contentInput.Focus();
     }
 }
 public Bitmap GenerateQR(int width, int height, string text)
 {
     var bw = new ZXing.BarcodeWriter();
     
     var encOptions = new ZXing.Common.EncodingOptions
     {
         Width = width,
         Height = height,
         Margin = 0,
         PureBarcode = false
     };
     encOptions.Hints.Add(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
     bw.Renderer = new BitmapRenderer();
     bw.Options = encOptions;
     bw.Format = ZXing.BarcodeFormat.QR_CODE;
     Bitmap bm = bw.Write(text);
     Bitmap overlay = new Bitmap(imagePath);
     int deltaHeigth = bm.Height - overlay.Height;
     int deltaWidth = bm.Width - overlay.Width;
     Graphics g = Graphics.FromImage(bm);
     g.DrawImage(overlay, new Point(deltaWidth/2,deltaHeigth/2));
     
     return bm;
 }
        private void RenderCard()
        {
            var bounds = ApplicationView.GetForCurrentView().VisibleBounds;
            if (App.IsMobile)
            {
                bcImage.Width = bounds.Width;
                bcImage.Height = bounds.Width * .5625;
                bcGrid.Height = bcImage.Height + 20;
                bcGrid.Width = bounds.Width;
                bcGrid.Margin = new Thickness(0, 70, 0, 0);
                bcNumber.Width = bounds.Width;
            }
            else
            {
                bcImage.Width = bounds.Width * .40;
                bcImage.Height = (bounds.Width * .40) * .5625;
                bcGrid.Height = bcImage.Height + 20;
                bcGrid.Width = (bounds.Width * .40);
                bcGrid.Margin = new Thickness(0, 70, 0, 0);
                bcNumber.Width = bounds.Width * .40;
            }

            bcNumber.Text = theCard.Number;
            bcNumber.TextAlignment = TextAlignment.Center;

            ZXing.MultiFormatWriter mfw = new ZXing.MultiFormatWriter();
            try
            {
                ZXing.Common.BitMatrix bm = mfw.encode(theCard.Number, theCard.Format, (int)bcImage.Width, (int)bcImage.Height);
                ZXing.Mobile.WriteableBitmapRenderer w = new WriteableBitmapRenderer();
                ZXing.Common.EncodingOptions eo = new ZXing.Common.EncodingOptions();
                eo.Height = (int)bcImage.Height;
                eo.Width = (int)bcImage.Width;
                WriteableBitmap wbm = w.Render(bm, theCard.Format, theCard.Number, eo);
                bcImage.Source = wbm;
            }
            catch(Exception e)
            {
                CardEncodeErr.Text = e.Message;
                CardEncodeErr.Visibility = Visibility.Visible;
            }
        }
 internal EncodingOptions(ZXing.Common.EncodingOptions other)
 {
     wrappedEncodingOptions = other;
 }
Exemple #22
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;
        }
Exemple #23
0
        public Bitmap GenerateQRCode(string contents, PictureBox qrimage, string codeType,
                                     string codeColor, string erroCorrectionLevel, bool isShowCode = false)
        {
            if (contents == string.Empty)
            {
                MessageBox.Show("invalid input");
                return(null);
            }

            if (codeColor == null)
            {
                codeColor = "Black";
            }

            BarcodeWriter writer = new BarcodeWriter();

            var encOptions = new ZXing.Common.EncodingOptions
            {
                Width       = qrimage.Width,
                Height      = qrimage.Height,
                Margin      = 0,
                PureBarcode = false
            };

            switch (erroCorrectionLevel)
            {
            case "L":
                encOptions.Hints.Add(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
                break;

            case "M":
                encOptions.Hints.Add(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);
                break;

            case "Q":
                encOptions.Hints.Add(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.Q);
                break;

            case "H":
                encOptions.Hints.Add(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
                break;

            default:
                encOptions.Hints.Add(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
                break;
            }

            encOptions.Hints.Add(EncodeHintType.CHARACTER_SET, "UTF-8");

            writer.Renderer = new BitmapRenderer()
            {
                Foreground = Color.FromName(codeColor)
            };

            writer.Options = encOptions;

            switch (codeType)
            {
            case "CODE_128":
                writer.Format = ZXing.BarcodeFormat.CODE_128;
                break;

            case "QR_CODE":
                writer.Format = ZXing.BarcodeFormat.QR_CODE;
                break;

            case "PDF_417":
                writer.Format = ZXing.BarcodeFormat.PDF_417;
                break;

            default:
                writer.Format = ZXing.BarcodeFormat.QR_CODE;
                break;
            }

            Bitmap bitmap = writer.Write(contents);

            if (isShowCode == true)
            {
                qrimage.Image = bitmap;
            }

            return(bitmap);
        }
        private void RenderCard()
        {
            var bounds = ApplicationView.GetForCurrentView().VisibleBounds;
            if (App.IsMobile)
            {
                bcImage.Width = bounds.Width;
                if (theCard.Format == ZXing.BarcodeFormat.PDF_417)
                {
                    bcImage.Height = bounds.Width * .35;
                    bcNumber.Margin = new Thickness(0, 0, 0, 3);
                }
                else
                {
                    bcImage.Height = bounds.Width * .4;
                    bcNumber.Margin = new Thickness(0, 0, 0, 0);
                }

                bcGrid.VerticalAlignment = VerticalAlignment.Top;
                bcGrid.Height = bcImage.Height + 20;
                bcGrid.Width = bounds.Width;
                bcGrid.Margin = new Thickness(0, 70, 0, 0);
                bcNumber.Width = bounds.Width;
            }
            else
            {
                if (theCard.Format == ZXing.BarcodeFormat.PDF_417)
                {
                    bcImage.Height = (bounds.Width * .40) * .3;
                }
                else
                {
                    bcImage.Height = (bounds.Width * .40) * .5625;
                }                
                bcImage.Width = bounds.Width * .40;
                bcImage.HorizontalAlignment = HorizontalAlignment.Center;
                bcImage.VerticalAlignment = VerticalAlignment.Center;
                bcGrid.Height = bcImage.Height + 20;
                bcGrid.Width = (bounds.Width * .40);
                bcGrid.Margin = new Thickness(0, 70, 0, 0);
                bcNumber.Width = bounds.Width * .40;

                if (bounds.Width > 800)
                    bcNumber.FontSize = 20;
                else if (bounds.Width > 600 && Width <= 800)
                    bcNumber.FontSize = 16;
                else if (bounds.Width <= 600)
                    bcNumber.FontSize = 11;
            }

            bcNumber.Text = theCard.Number;
            bcNumber.TextAlignment = TextAlignment.Center;

            ZXing.MultiFormatWriter mfw = new ZXing.MultiFormatWriter();
            try
            {
                var scaleFactor = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;

                ZXing.Common.BitMatrix bm;
                if (App.IsMobile)
                    bm = mfw.encode(theCard.Number, theCard.Format, (int)(bcImage.Width * (scaleFactor - 1)), (int)(bcImage.Height * (scaleFactor - 1)));
                else
                    bm = mfw.encode(theCard.Number, theCard.Format, (int)bcImage.Width, (int)bcImage.Height);

                ZXing.Mobile.WriteableBitmapRenderer w = new WriteableBitmapRenderer();
                ZXing.Common.EncodingOptions eo = new ZXing.Common.EncodingOptions();
                eo.Height = (int)bcImage.Height;
                eo.Width = (int)bcImage.Width;
                WriteableBitmap wbm = w.Render(bm, theCard.Format, theCard.Number, eo);
                bcImage.Source = wbm;
            }
            catch(Exception e)
            {
                CardEncodeErr.Text = e.Message;
                CardEncodeErr.Visibility = Visibility.Visible;
            }
        }
        /// <summary>
        /// 打印文件
        /// </summary>
        /// <param name="FileName">原始文件名</param>
        /// <param name="BarCode">美的条码</param>
        /// <param name="JiXing">美的机型</param>
        /// <param name="DingDan">订单名称</param>
        /// <param name="barTime">条码时间</param>
        /// <param name="boshiBarCode">博世条码</param>
        /// <param name="boshiMode">博世机型</param>
        public bool PrintFile(string FileName, string BarCode, string JiXing, string DingDan, string boshiBarCode, string boshiMode, DateTime barTime, string boshiOrder, string waiXiaoBarCode)
        {
            bool result = false;

            if (App == null)
            {
                Load();
            }
            if (App == null)
            {
                frmMain.mMain.AddInfo("当前启动Ai失败,请关闭尝试重启程序");
            }
            //替换字符
            if (frmMain.mMain.AiReplace == null ||
                (frmMain.mMain.AiReplace.RReplace == null && frmMain.mMain.AiReplace.TReplace == null))
            {
                frmMain.mMain.AddInfo("AI文件替换方案不存在,不能找到须要替换的内容");
                return(result);
            }
            if ((frmMain.mMain.AiReplace.RReplace == null || frmMain.mMain.AiReplace.RReplace.Count <= 0) &&
                (frmMain.mMain.AiReplace.TReplace == null || frmMain.mMain.AiReplace.TReplace.Count <= 0))
            {
                frmMain.mMain.AiReplace.Load();
            }
            if ((frmMain.mMain.AiReplace.RReplace == null || frmMain.mMain.AiReplace.RReplace.Count <= 0) &&
                (frmMain.mMain.AiReplace.TReplace == null || frmMain.mMain.AiReplace.TReplace.Count <= 0))
            {
                frmMain.mMain.AddInfo("AI文件替换方案为空,不能进行替换指定内容");
                return(result);
            }
            try
            {
                //生成二维码
                if (!System.IO.File.Exists(string.Format("{0}\\DEMO{1}.png", fileDirectory, boshiBarCode)) && boshiBarCode.Length > 0)
                {
                    DataMatrix.net.DmtxImageEncoder        de  = new DataMatrix.net.DmtxImageEncoder();
                    DataMatrix.net.DmtxImageEncoderOptions dme = new DataMatrix.net.DmtxImageEncoderOptions();
                    dme.Scheme     = DataMatrix.net.DmtxScheme.DmtxSchemeAscii;
                    dme.MarginSize = 0;
                    dme.SizeIdx    = DataMatrix.net.DmtxSymbolSize.DmtxSymbol16x36;
                    Image datamatrix = de.EncodeImage(string.Format("DEMO{0}", boshiBarCode), dme);
                    datamatrix.Save(string.Format("{0}\\DEMO{1}.png", fileDirectory, boshiBarCode), System.Drawing.Imaging.ImageFormat.Png);
                    datamatrix.Dispose();
                    dme = null;
                    de  = null;
                }
                //生成条码
                ZXing.BarcodeWriter          bw;
                ZXing.Common.EncodingOptions eo;
                //生成美的条码
                if (!System.IO.File.Exists(string.Format("{0}\\{1}.png", fileDirectory, BarCode)) && BarCode.Length > 0)
                {
                    bw             = new ZXing.BarcodeWriter();
                    bw.Format      = ZXing.BarcodeFormat.CODE_128;
                    eo             = new ZXing.Common.EncodingOptions();
                    eo.PureBarcode = true;
                    eo.Width       = 45;
                    eo.Height      = 20;
                    eo.Margin      = 0;
                    bw.Options     = eo;
                    bw.Write(BarCode).Save(string.Format("{0}\\{1}.png", fileDirectory, BarCode));
                }
                //生成博世条码
                if (!System.IO.File.Exists(string.Format("{0}\\{1}.png", fileDirectory, boshiBarCode)) && boshiBarCode.Length > 0)
                {
                    bw             = new ZXing.BarcodeWriter();
                    bw.Format      = ZXing.BarcodeFormat.CODE_128;
                    eo             = new ZXing.Common.EncodingOptions();
                    eo.PureBarcode = true;
                    eo.Width       = 45;
                    eo.Height      = 20;
                    eo.Margin      = 0;
                    bw.Options     = eo;
                    bw.Write(boshiBarCode).Save(string.Format("{0}\\{1}.png", fileDirectory, boshiBarCode));
                }
                //生成美的出口条码
                if (!System.IO.File.Exists(string.Format("{0}\\{1}.png", fileDirectory, waiXiaoBarCode)) && waiXiaoBarCode.Length > 0)
                {
                    bw             = new ZXing.BarcodeWriter();
                    bw.Format      = ZXing.BarcodeFormat.CODE_128;
                    eo             = new ZXing.Common.EncodingOptions();
                    eo.PureBarcode = true;
                    eo.Width       = 45;
                    eo.Height      = 20;
                    eo.Margin      = 0;
                    bw.Options     = eo;
                    bw.Write(waiXiaoBarCode).Save(string.Format("{0}\\{1}.png", fileDirectory, waiXiaoBarCode));
                }
                //打开AI进行替换文件
                Illustrator.Document doc = App.Open(FileName, Illustrator.AiDocumentColorSpace.aiDocumentRGBColor, null);
                if (doc == null)
                {
                    frmMain.mMain.AddInfo(string.Format("打开指定AI文件{0}失败,无法打印标贴", FileName));
                    return(result);
                }
                //替换图形
                Dictionary <int, RectangleDouble> allReplace    = new Dictionary <int, RectangleDouble>();
                List <Illustrator.PathItem>       allRemovePath = new List <Illustrator.PathItem>();
                int allReplaceIndex = 0;
                if (frmMain.mMain.AiReplace.RReplace != null)
                {
                    double c = 0, m = 0, y = 0, k = 0;
                    foreach (Illustrator.PathItem pi in doc.PathItems)
                    {
                        if (pi.Filled && pi.FillColor != null)
                        {
                            Illustrator.CMYKColor rgb = pi.FillColor as Illustrator.CMYKColor;
                            if (rgb != null)
                            {
                                c = Convert.ToInt16(rgb.Cyan);
                                m = Convert.ToInt16(rgb.Magenta);
                                y = Convert.ToInt16(rgb.Yellow);
                                k = Convert.ToInt16(rgb.Black);
                                for (int i = 0; i < frmMain.mMain.AiReplace.RReplace.Count; i++)
                                {
                                    if (c == frmMain.mMain.AiReplace.RReplace[i].CValue &&
                                        m == frmMain.mMain.AiReplace.RReplace[i].MValue &&
                                        y == frmMain.mMain.AiReplace.RReplace[i].YValue &&
                                        k == frmMain.mMain.AiReplace.RReplace[i].KValue)
                                    {
                                        allReplace.Add(allReplaceIndex, new RectangleDouble(pi.Left, pi.Top, pi.Width, pi.Height, frmMain.mMain.AiReplace.RReplace[i].NewRegion));
                                        allReplaceIndex++;
                                        allRemovePath.Add(pi);
                                        break;
                                    }
                                }
                                if (allReplaceIndex > 0 && frmMain.mMain.AllDataXml.LocalSettings.TestNo == 9)
                                {
                                    break;
                                }
                            }
                        }
                    }
                    allRemovePath.ForEach(//删除所有原始路径
                        path =>
                    {
                        path.Delete();
                    });
                    for (int i = 0; i < allReplaceIndex; i++)
                    {
                        if (allReplace.ContainsKey(i))
                        {
                            Illustrator.PlacedItem placeitem = doc.PlacedItems.Add();
                            switch (allReplace[i].Region)
                            {
                            case cAiReplace.RegionReplace.RegionList.博世条码:
                                if (System.IO.File.Exists(string.Format("{0}\\{1}.png", fileDirectory, boshiBarCode)))
                                {
                                    placeitem.File = string.Format("{0}\\{1}.png", fileDirectory, boshiBarCode);
                                }
                                break;

                            case cAiReplace.RegionReplace.RegionList.美的条码:
                                if (System.IO.File.Exists(string.Format("{0}\\{1}.png", fileDirectory, BarCode)))
                                {
                                    placeitem.File = string.Format("{0}\\{1}.png", fileDirectory, BarCode);
                                }
                                break;

                            case cAiReplace.RegionReplace.RegionList.二维码:
                                if (System.IO.File.Exists(string.Format("{0}\\DEMO{1}.png", fileDirectory, boshiBarCode)))
                                {
                                    placeitem.File = string.Format("{0}\\DEMO{1}.png", fileDirectory, boshiBarCode);
                                }
                                break;

                            case cAiReplace.RegionReplace.RegionList.出口条码:
                                if (System.IO.File.Exists(string.Format("{0}\\{1}.png", fileDirectory, waiXiaoBarCode)))
                                {
                                    placeitem.File = string.Format("{0}\\{1}.png", fileDirectory, waiXiaoBarCode);
                                }
                                break;
                            }
                            placeitem.Left   = allReplace[i].Left;
                            placeitem.Top    = allReplace[i].Top;
                            placeitem.Width  = allReplace[i].Width;
                            placeitem.Height = allReplace[i].Height;
                            placeitem.Embed();
                        }
                    }
                }
                //替换文本
                if (frmMain.mMain.AiReplace.TReplace != null)
                {
                    foreach (Illustrator.TextFrame tf in doc.TextFrames)
                    {
                        Console.WriteLine(tf.Contents);
                        for (int i = 0; i < frmMain.mMain.AiReplace.TReplace.Count; i++)
                        {
                            if (tf.Contents != null && tf.Contents == frmMain.mMain.AiReplace.TReplace[i].OldText)
                            {
                                switch (frmMain.mMain.AiReplace.TReplace[i].NewText)
                                {
                                case cAiReplace.TextReplace.TextList.订单_订单名称:
                                    tf.Contents = DingDan;
                                    break;

                                case cAiReplace.TextReplace.TextList.机型_博世机型:
                                    tf.Contents = boshiMode;
                                    break;

                                case cAiReplace.TextReplace.TextList.机型_美的机型:
                                    tf.Contents = JiXing;
                                    break;

                                case cAiReplace.TextReplace.TextList.日期_3位博世日期:
                                    tf.Contents = All.Class.BoShi.GetBoShiTime(barTime);
                                    break;

                                case cAiReplace.TextReplace.TextList.日期_年年:
                                    tf.Contents = string.Format("{0:yy}", barTime);
                                    break;

                                case cAiReplace.TextReplace.TextList.日期_年年年年:
                                    tf.Contents = string.Format("{0:yyyy}", barTime);
                                    break;

                                case cAiReplace.TextReplace.TextList.日期_年年年年月月日日:
                                    tf.Contents = string.Format("{0:yyyyMMdd}", barTime);
                                    break;

                                case cAiReplace.TextReplace.TextList.日期_年年月月:
                                    tf.Contents = string.Format("{0:yyMM}", barTime);
                                    break;

                                case cAiReplace.TextReplace.TextList.日期_日日:
                                    tf.Contents = string.Format("{0:dd}", barTime);
                                    break;

                                case cAiReplace.TextReplace.TextList.日期_月:
                                    tf.Contents = string.Format("{0:X}", barTime.Month);
                                    break;

                                case cAiReplace.TextReplace.TextList.日期_月月:
                                    tf.Contents = string.Format("{0:MM}", barTime);
                                    break;

                                case cAiReplace.TextReplace.TextList.条码_博世条码:
                                    tf.Contents = boshiBarCode;
                                    break;

                                case cAiReplace.TextReplace.TextList.条码_美的条码:
                                    tf.Contents = BarCode;
                                    break;

                                case cAiReplace.TextReplace.TextList.订单_出口订单名称:
                                    tf.Contents = boshiOrder;
                                    break;

                                case cAiReplace.TextReplace.TextList.条码_美的出口条码:
                                    tf.Contents = waiXiaoBarCode;
                                    break;
                                }
                                break;
                            }
                        }
                    }
                }
                doc.SaveAs(string.Format("{0}\\{1}.Ai", fileDirectory, boshiBarCode));
                doc.PrintOut();
                doc.Close(Illustrator.AiSaveOptions.aiDoNotSaveChanges);
                doc    = null;
                result = true;
            }
            catch (Exception e)
            {
                result = false;
                frmMain.mMain.AddInfo("打印标贴失败,请稍后重新尝试");
                All.Class.Error.Add(e);
            }
            return(result);
        }
Exemple #26
0
        public ResultResponse SaveBarcodes(BarcodeGenarateModal barcodeGenarateModal, int userId)
        {
            ResultResponse resultResponse   = new ResultResponse();
            int            masterPrimaryKey = 0;

            try
            {
                accessManager.SqlConnectionOpen(DataBase.WorkerInsentive);
                List <SqlParameter> aParameters = new List <SqlParameter>();
                aParameters.Add(new SqlParameter("@StyleNo", barcodeGenarateModal.StyleID));
                aParameters.Add(new SqlParameter("@GenarateDate", barcodeGenarateModal.SelectDate));
                aParameters.Add(new SqlParameter("@BundleQuantity", barcodeGenarateModal.Quantity));
                aParameters.Add(new SqlParameter("@Size", barcodeGenarateModal.BundleSize));
                aParameters.Add(new SqlParameter("@Color", barcodeGenarateModal.Color));
                aParameters.Add(new SqlParameter("@CreateBy", userId));
                aParameters.Add(new SqlParameter("@CutNo", barcodeGenarateModal.CutNo));
                aParameters.Add(new SqlParameter("@ShadeNo", barcodeGenarateModal.ShadeNO));
                aParameters.Add(new SqlParameter("@BuyerId", barcodeGenarateModal.BuyerID));
                aParameters.Add(new SqlParameter("@PONumber", barcodeGenarateModal.PONumber));
                aParameters.Add(new SqlParameter("@QuantityGenarate", (barcodeGenarateModal.Quantity * barcodeGenarateModal.NoOfBundle)));
                aParameters.Add(new SqlParameter("@BusinessUnitId", barcodeGenarateModal.BusinessUnitId));
                masterPrimaryKey = accessManager.SaveDataReturnPrimaryKey("sp_SaveGenaratedMasterTable", aParameters);
            }
            catch (Exception exception)
            {
                accessManager.SqlConnectionClose(true);
                throw exception;
            }
            finally
            {
                accessManager.SqlConnectionClose();
            }

            var pgSize = new iTextSharp.text.Rectangle(100, 65);

            iTextSharp.text.Document doc = new iTextSharp.text.Document(pgSize, 0, 0, 0, 0);
            string   path     = HttpContext.Current.Server.MapPath("~/GenaratePDF/");
            DateTime dt       = DateTime.Now;
            string   fileName = dt.Minute.ToString() + dt.Second.ToString() + dt.Millisecond.ToString();

            PdfWriter.GetInstance(doc, new FileStream(path + fileName + ".pdf", FileMode.Create));
            //open the document for writing
            doc.Open();
            // doc.SetPageSize(new iTextSharp.text.Rectangle(100,65));
            PdfPTable pdftable = new PdfPTable(1);

            for (int i = 0; i < barcodeGenarateModal.NoOfBundle; i++)
            {
                int count = 0;
                iTextSharp.text.Font font     = FontFactory.GetFont("Calibri", 5.5f, BaseColor.BLACK); // from 5.0f
                iTextSharp.text.Font fontlast = FontFactory.GetFont("Calibri", 5.5f, BaseColor.BLACK); // from 5.0f
                String header = "Buyer Name : " + barcodeGenarateModal.BuyerName + "\nStyle : " + barcodeGenarateModal.StyleName + "\nBundle Quantity : " + barcodeGenarateModal.Quantity +
                                " Bundle No : " + (i + 1) + "\nColor : " + barcodeGenarateModal.Color + " Size : " + barcodeGenarateModal.BundleSize;
                iTextSharp.text.Paragraph paraheader = new iTextSharp.text.Paragraph(header, font);
                PdfPCell cell1 = new PdfPCell {
                    PaddingLeft = 0, PaddingTop = 1, PaddingBottom = 3, PaddingRight = 0
                };
                cell1.AddElement(paraheader);
                cell1.Border = 0;
                pdftable.AddCell(cell1);
                foreach (CommonModel barcodeGenarate in barcodeGenarateModal.OprationList)
                {
                    count++;
                    int barcodeNo  = BarcodePrimaryKey(masterPrimaryKey, i + 1, barcodeGenarate, barcodeGenarateModal.BusinessUnitId);
                    var bw         = new ZXing.BarcodeWriter();
                    var encOptions = new ZXing.Common.EncodingOptions()
                    {
                        Margin = 0
                    };                                                                     // margin 0 to 1
                    bw.Options = encOptions;
                    bw.Format  = ZXing.BarcodeFormat.PDF_417;
                    var result = new Bitmap(bw.Write(barcodeNo + "," + barcodeGenarate.OperationSMV.ToString()));
                    result.Save(path + barcodeGenarate.OperationName, System.Drawing.Imaging.ImageFormat.Png);
                    string first = barcodeNo + "-" + barcodeGenarateModal.StyleName + ", " + barcodeGenarate.OperationName + "," + barcodeGenarateModal.BundleSize;
                    string last  = barcodeGenarate.OperationSMV +
                                   ", " + barcodeGenarateModal.SelectDate + ","
                                   + barcodeGenarateModal.Quantity +
                                   ", " + (i + 1) + "-" + count + ", " + barcodeGenarateModal.Color;

                    iTextSharp.text.Paragraph paragraph     = new iTextSharp.text.Paragraph(first, font);
                    iTextSharp.text.Paragraph lastparagraph = new iTextSharp.text.Paragraph(last, fontlast);
                    paragraph.SetLeading(1.0f, 1.0f);
                    paragraph.SpacingAfter = 2;
                    lastparagraph.SetLeading(1.0f, 1.0f);
                    iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(path + barcodeGenarate.OperationName);
                    image.ScaleAbsolute(85, 25);
                    // image.PaddingTop = 3.0f;
                    PdfPCell cell = new PdfPCell {
                        PaddingLeft = 0, PaddingTop = 0, PaddingBottom = 0, PaddingRight = 0
                    };
                    // cell.FixedHeight = 60;
                    cell.AddElement(paragraph);
                    cell.AddElement(image);
                    cell.AddElement(lastparagraph);
                    cell.Border = 0;
                    pdftable.AddCell(cell);
                    File.Delete(path + barcodeGenarate.OperationName);
                }
            }
            doc.Add(pdftable);
            doc.Close();
            resultResponse.isSuccess = true;
            resultResponse.data      = path + fileName + ".pdf";
            return(resultResponse);
        }