示例#1
0
        private void button1_Click(object sender, EventArgs e)

        /*{
         *  QRCode barcode = new QRCode();
         *  string url = "http://www.naver.com";    // QR코드에 저장할 내용
         *  barcode.Code = url;
         *  barcode.ModuleSize = 6.0f;
         *  barcode.Resolution = 300;
         *  barcode.drawBarcode2ImageFile("naver.png");  // 프로젝트 폴더의 Debug 경로내에 파일이 생성됩니다.
         *
         *  MessageBox.Show("done.");
         * }*/
        {
            ZXing.BarcodeWriter barcodeWriter = new ZXing.BarcodeWriter();
            barcodeWriter.Format = ZXing.BarcodeFormat.QR_CODE;

            barcodeWriter.Options.Width  = this.pictureBox1.Width;
            barcodeWriter.Options.Height = this.pictureBox1.Height;

            string strQRCode = "http://www.google.com";

            this.pictureBox1.Image = barcodeWriter.Write(strQRCode);
            string deskPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);

            barcodeWriter.Write(strQRCode).Save(deskPath + @"\test.jpg", ImageFormat.Jpeg);
        }
示例#2
0
        /// <summary>
        /// 打印的格式
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PalletLabelDocumentA5_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {/*
          * 如果需要改变 可以在new Font(new FontFamily("Arial"), 11)中的“Arial”改成自己要的字体就行了,黑体 后面的数字代表字体的大小
          *  System.Drawing.Brushes.Blue, 170, 10 中的 System.Drawing.Brushes.Blue 为颜色,后面的为输出的位置*/
            var             top          = 100;
            var             left         = 10;
            var             pallet       = model as PalletLabelModel;
            EncodingOptions encodeOption = new EncodingOptions();

            encodeOption.Height      = 10;
            encodeOption.Width       = 80;
            encodeOption.PureBarcode = true;
            ZXing.BarcodeWriter wr = new ZXing.BarcodeWriter();
            wr.Options = encodeOption;
            wr.Format  = ZXing.BarcodeFormat.CODE_128;
            string printTime = DateTime.Now.ToString();
            Bitmap qtyImg    = wr.Write(pallet.qty.ToString());
            Bitmap modelImg  = wr.Write(pallet.model_family);

            e.Graphics.DrawString("W/H:" + pallet.warehouse_code, new Font(new FontFamily("Arial"), 10f, FontStyle.Bold), Brushes.Black, 40, 26);
            e.Graphics.DrawString("STORE-IN SHEET", new Font(new FontFamily("Arial"), 18f, FontStyle.Bold), Brushes.Black, 190, 5);
            e.Graphics.DrawString("Print time: " + printTime, new Font(new FontFamily("Arial"), 7f), Brushes.Black, 420, 18);
            //Qty 条形码
            e.Graphics.DrawImage(qtyImg, 265, 76);
            e.Graphics.DrawString("Pallet No: " + pallet.label_id, new Font(new FontFamily("Arial"), 10f, FontStyle.Bold), Brushes.Black, 10, 48);
            e.Graphics.DrawString("Model: " + pallet.model_family, new Font(new FontFamily("Arial"), 10f, FontStyle.Bold), Brushes.Black, 10, 60);
            e.Graphics.DrawImage(modelImg, 260, 48);
            e.Graphics.DrawString("Model Desc: " + pallet.model_desc, new Font(new FontFamily("Arial"), 10f, FontStyle.Bold), Brushes.Black, 200, 60);
            e.Graphics.DrawString("Part No: " + pallet.material_code, new Font(new FontFamily("Arial"), 10f, FontStyle.Bold), Brushes.Black, 10, 72);
            e.Graphics.DrawString("Qty: " + pallet.qty, new Font(new FontFamily("Arial"), 10f, FontStyle.Bold), Brushes.Black, 200, 72);
            e.Graphics.DrawString("Bin: " + pallet.bin_code, new Font(new FontFamily("Arial"), 10f, FontStyle.Bold), Brushes.Black, 440, 72);
            //双细线画粗线
            e.Graphics.DrawLine(Pens.Black, 195, 30, 405, 30);
            e.Graphics.DrawLine(Pens.Black, 195, 31, 405, 31);
            e.Graphics.DrawLine(Pens.Black, 10, 92, 570, 92);

            var num  = 0;
            var num2 = 0;

            for (var i = page * pageSize; i < pallet.usn_list.Count; i++)
            {
                var usn = pallet.usn_list[i];
                var img = wr.Write(usn.usn);
                var row = ((num % 3) * 197);
                num2 = (num > 0 && num % 3 == 0) ? num2 + 1 : num2;
                var col = num2 * 37.0f;
                e.Graphics.DrawString("MO:" + usn.mo, new Font(new FontFamily("Arial"), 7f), Brushes.Black, left + row, top + col);
                e.Graphics.DrawImage(img, 7 + row, 113 + col);
                e.Graphics.DrawString(usn.usn, new Font(new FontFamily("Arial"), 7f), Brushes.Black, 10 + row, 124 + col);
                num++;
                if (num % pageSize == 0)
                {
                    break;
                }
            }

            page++;
            e.HasMorePages = (page * pageSize < pallet.usn_list.Count);
            e.Graphics.DrawString($"Page: {page}", new Font(new FontFamily("Arial"), 10f, FontStyle.Bold), Brushes.Black, 510, 37);
        }
        private void BtnGenerateQR_Click(object sender, RoutedEventArgs e)
        {
            //grab values
            var text = this.txtText.Text;

            //verify they are filled in
            if (string.IsNullOrEmpty(text))
            {
                MessageManager.ShowMessageToUserAsync("Text is empty.");
                return;
            }



            //create image
            var options = new QrCodeEncodingOptions
            {
                DisableECI   = true,
                CharacterSet = "UTF-8",
                Width        = 512,
                Height       = 512,
            };
            var qr = new ZXing.BarcodeWriter();

            qr.Options = options;
            qr.Format  = ZXing.BarcodeFormat.QR_CODE;
            var result = qr.Write(text);

            //set as source
            this.imgQrCode.Source = result;
            //TODO NEEDED? //this.lastQrSSid = wifiData.ssid;
            //make save button visible
            this.btnSaveFile.Visibility = Visibility.Visible;
        }
        public System.Web.Mvc.FileResult GetBarcode2(string code, string name, string batchNumber, string lotNumber,
                                                     bool includeLotBatchInCode = false, int width = 300, int height = 100,
                                                     int fontSize = 20, int codeType = (int)ZXing.BarcodeFormat.CODE_128, string label1 = "Batch No", string label2 = "Lot No")
        {
            var options = new QrCodeEncodingOptions
            {
                DisableECI   = true,
                CharacterSet = "UTF-8",
                Width        = width,
                Height       = height
            };

            var qr = new ZXing.BarcodeWriter();

            qr.Options = options;
            qr.Format  = (ZXing.BarcodeFormat)codeType;

            if (includeLotBatchInCode)
            {
                code += batchNumber + lotNumber;
            }

            var img      = new Bitmap(qr.Write(code));
            var imgName  = new Bitmap(Helper.ImageFromText(name, fontSize));
            var imgBatch = new Bitmap(Helper.ImageFromText($"{label1}: {batchNumber}", fontSize));
            var imgLot   = new Bitmap(Helper.ImageFromText($"{label2}: {lotNumber}", fontSize));

            var c1       = Helper.MergeTwoImages(img, imgName);
            var c2       = Helper.MergeTwoImages(imgBatch, imgLot);
            var finalImg = Helper.MergeTwoImages(c1, c2);

            var bytes = Helper.ConvertToByteArray(finalImg);

            return(File(bytes, "image/png"));
        }
示例#5
0
        protected void process(string code)
        {
            MessageBox.Show(code);
            var brcode     = new ZXing.BarcodeWriter();
            var encOptions = new ZXing.Common.EncodingOptions()
            {
                Width = Convert.ToInt32(width.Value), Height = Convert.ToInt32(height.Value), Margin = Convert.ToInt32(margin.Value)
            };

            brcode.Options = encOptions;
            switch (format.Text)
            {
            case "EAN_13":
                brcode.Format = ZXing.BarcodeFormat.EAN_13;
                break;

            case "UPC_A":
                brcode.Format = ZXing.BarcodeFormat.UPC_A;
                break;

            default:
                MessageBox.Show("Unsupported");
                return;
            }
            Bitmap result = new Bitmap(brcode.Write(code));

            result.Save("test.bmp");
            picture.ImageLocation = "test.bmp";
        }
示例#6
0
        /// <summary>
        /// 打印的格式
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CartonLabelDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {/*
          * 如果需要改变 可以在new Font(new FontFamily("Arial"), 11)中的“Arial”改成自己要的字体就行了,黑体 后面的数字代表字体的大小
          *  System.Drawing.Brushes.Blue, 170, 10 中的 System.Drawing.Brushes.Blue 为颜色,后面的为输出的位置*/
            EncodingOptions encodeOption = new EncodingOptions();

            encodeOption.Height      = 13;
            encodeOption.Width       = 200;
            encodeOption.PureBarcode = true;
            ZXing.BarcodeWriter wr = new ZXing.BarcodeWriter();
            wr.Options = encodeOption;
            wr.Format  = ZXing.BarcodeFormat.CODE_128;
            var    code = "L2014021700000008";
            Bitmap img  = wr.Write(code);

            e.Graphics.DrawString($"CartonID: {code}", new Font(new FontFamily("Arial"), 10f, FontStyle.Bold), Brushes.Black, 10, 0);
            e.Graphics.DrawImage(img, 9, 20);
            e.Graphics.DrawString("Print time: " + DateTime.Now.ToString(), new Font(new FontFamily("Arial"), 10f), Brushes.Black, 10, 35);
            e.Graphics.DrawLine(Pens.Black, 10, 50, 220, 50);
            e.Graphics.DrawString("Material:", new Font(new FontFamily("Arial"), 10f, FontStyle.Bold), Brushes.Black, 10, 55);
            e.Graphics.DrawString("Vendor: ", new Font(new FontFamily("Arial"), 10f, FontStyle.Bold), Brushes.Black, 10, 67);
            e.Graphics.DrawString("Quantity: ", new Font(new FontFamily("Arial"), 10f, FontStyle.Bold), Brushes.Black, 10, 79);
            e.Graphics.DrawString("Lot Code: ", new Font(new FontFamily("Arial"), 10f, FontStyle.Bold), Brushes.Black, 10, 91);
            e.Graphics.DrawString("Date Code:", new Font(new FontFamily("Arial"), 10f, FontStyle.Bold), Brushes.Black, 10, 103);
            e.Graphics.DrawString("Batch#: ", new Font(new FontFamily("Arial"), 10f, FontStyle.Bold), Brushes.Black, 10, 115);
            e.Graphics.DrawString("Tooling#: ", new Font(new FontFamily("Arial"), 10f, FontStyle.Bold), Brushes.Black, 10, 127);
            e.Graphics.DrawLine(Pens.Black, 10, 144, 220, 144);
            e.HasMorePages = false;
        }
        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();
            }
        }
示例#8
0
        /// <summary>
        /// 打印的格式
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FGLabelDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {/*
          * 如果需要改变 可以在new Font(new FontFamily("Arial"), 11)中的“黑体”改成自己要的字体就行了,黑体 后面的数字代表字体的大小
          *  System.Drawing.Brushes.Blue, 170, 10 中的 System.Drawing.Brushes.Blue 为颜色,后面的为输出的位置*/
            var bin = model as BinLabelModel;

            EncodingOptions encodeOption = new EncodingOptions();

            encodeOption.Height      = 13;
            encodeOption.Width       = 200;
            encodeOption.PureBarcode = true;
            ZXing.BarcodeWriter wr = new ZXing.BarcodeWriter();
            wr.Options = encodeOption;
            wr.Format  = ZXing.BarcodeFormat.CODE_128;
            Bitmap img = wr.Write(bin.label_id.ToString());

            e.Graphics.DrawString($"Label ID: " + bin.label_id, new Font(new FontFamily("Arial"), 9f, FontStyle.Bold), Brushes.Black, 23, 0);
            e.Graphics.DrawImage(img, 6, 20);
            e.Graphics.DrawString("Print time: " + DateTime.Now.ToString() + " " + bin.user_name, new Font(new FontFamily("Arial"), 6f), Brushes.Black, 25, 37);
            e.Graphics.DrawLine(Pens.Black, 10, 50, 245, 50);
            e.Graphics.DrawString("Material:" + "          " + bin.material_code, new Font(new FontFamily("Arial"), 7f), Brushes.Black, 25, 52);
            e.Graphics.DrawString("Bin: " + "                " + bin.bin_code, new Font(new FontFamily("Arial"), 7f), Brushes.Black, 25, 65);
            e.Graphics.DrawString("Vendor: " + "        " + bin.vendor_code, new Font(new FontFamily("Arial"), 7f), Brushes.Black, 25, 78);
            e.Graphics.DrawString("GR Date/DC: " + "  " + bin.date_code, new Font(new FontFamily("Arial"), 7f), Brushes.Black, 25, 91);
            e.Graphics.DrawString("Quantity:" + "         " + bin.qty, new Font(new FontFamily("Arial"), 7f), Brushes.Black, 25, 103);
            e.Graphics.DrawString("Version/GP: ", new Font(new FontFamily("Arial"), 7f), Brushes.Black, 25, 116);
            e.Graphics.DrawString("UP Point: ", new Font(new FontFamily("Arial"), 7f), Brushes.Black, 25, 129);
            e.Graphics.DrawString("Keeper/Pos: " + "   " + bin.keeper_code, new Font(new FontFamily("Arial"), 7f), Brushes.Black, 25, 142);
            e.Graphics.DrawLine(Pens.Black, 10, 159, 245, 159);
            e.Graphics.DrawLine(Pens.Black, 87, 50, 87, 159);
            e.HasMorePages = false;
        }
示例#9
0
        /// <summary>
        /// 打印的格式
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FGLabelDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {/*
          * 如果需要改变 可以在new Font(new FontFamily("Arial"), 11)中的“黑体”改成自己要的字体就行了,黑体 后面的数字代表字体的大小
          *  System.Drawing.Brushes.Blue, 170, 10 中的 System.Drawing.Brushes.Blue 为颜色,后面的为输出的位置*/
            EncodingOptions encodeOption = new EncodingOptions();

            encodeOption.Height      = 13;
            encodeOption.Width       = 200;
            encodeOption.PureBarcode = true;
            ZXing.BarcodeWriter wr = new ZXing.BarcodeWriter();
            wr.Options = encodeOption;
            wr.Format  = ZXing.BarcodeFormat.CODE_128;
            var    code = "L2014021700000008";
            Bitmap img  = wr.Write(code);

            e.Graphics.DrawString($"Label ID: {code}", new Font(new FontFamily("Arial"), 10f, FontStyle.Bold), Brushes.Black, 10, 0);
            e.Graphics.DrawImage(img, 9, 20);
            e.Graphics.DrawString("Print time: " + DateTime.Now.ToString(), new Font(new FontFamily("Arial"), 7.5f), Brushes.Black, 10, 35);
            e.Graphics.DrawString("K14070391 ", new Font(new FontFamily("Arial"), 7.5f), Brushes.Black, 165, 35);
            e.Graphics.DrawLine(Pens.Black, 10, 50, 245, 50);
            e.Graphics.DrawString("Material:", new Font(new FontFamily("Arial"), 10f), Brushes.Black, 10, 52);
            e.Graphics.DrawString("Bin: ", new Font(new FontFamily("Arial"), 10f), Brushes.Black, 10, 65);
            e.Graphics.DrawString("Vendor: ", new Font(new FontFamily("Arial"), 10f), Brushes.Black, 10, 78);
            e.Graphics.DrawString("GR Date/DC: ", new Font(new FontFamily("Arial"), 10f), Brushes.Black, 10, 91);
            e.Graphics.DrawString("Quantity:", new Font(new FontFamily("Arial"), 10f), Brushes.Black, 10, 103);
            e.Graphics.DrawString("Version/GP: ", new Font(new FontFamily("Arial"), 10), Brushes.Black, 10, 116);
            e.Graphics.DrawString("UP Point: ", new Font(new FontFamily("Arial"), 10f), Brushes.Black, 10, 129);
            e.Graphics.DrawString("Keeper/Pos: ", new Font(new FontFamily("Arial"), 10f), Brushes.Black, 10, 142);
            e.Graphics.DrawLine(Pens.Black, 10, 159, 245, 159);
            e.Graphics.DrawLine(Pens.Black, 100, 50, 100, 159);
            e.HasMorePages = false;
        }
        public void ProcessRequest(HttpContext context)
        {
            var code = context.Request.QueryString["code"];
            if (string.IsNullOrEmpty(code))
            {
                return;
            }

            var url = string.Format("{0}?SecretCode={1}",
                GRA.Tools.WebTools.GetBaseUrl(context.Request),
                code);

            int size = 200;
            var sizeString = context.Request.QueryString["size"];
            if (!string.IsNullOrEmpty(sizeString))
            {
                int.TryParse(sizeString, out size);
            }

            var barcodeWriter = new ZXing.BarcodeWriter
            {
                Format = ZXing.BarcodeFormat.QR_CODE,
                Options = new ZXing.Common.EncodingOptions
                {
                    Height = size,
                    Width = size
                }
            };
            using (var bitmap = barcodeWriter.Write(url))
            {
                context.Response.ContentType = "image/png";
                bitmap.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Png);
            }
        }
示例#11
0
        private static Bitmap GerarQRCodeDataMatrix(string text)
        {
            var width  = 94;
            var height = 94;

            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.DATA_MATRIX;

                var resultado = new Bitmap(bw.Write(text), width, height);
                return(resultado);
            }
            catch (Exception ex)
            {
                throw new Exception("Erro na geração do QrCode - " + ex.Message);
            }
        }
        public FileResult Index(int id)
        {
            // if (HttpContext.Request.Url.Host ==  "localhost") {
            var items = db.Items.ToArray();
            var item  = db.Items.FirstOrDefault(n => n.Id == id);

            if (item == null)
            {
                item = db.Inventories.FirstOrDefault(n => n.Id == id);
            }

            var writer = new ZXing.BarcodeWriter()
            {
                Format = ZXing.BarcodeFormat.CODE_39
            };
            var bmp = writer.Write(item.NonExclusiveRef);

            byte[] bytes = null;
            using (System.IO.MemoryStream stream = new System.IO.MemoryStream()) {
                bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
                bytes = stream.GetBuffer();
            }
            return(File(bytes, @"image/png", "barcode.png"));
            // }
            //   return new HttpUnauthorizedResult("F**k of!");
        }
示例#13
0
        public FileContentResult CaptchaImage(string qrcode)
        {
            var rand = new Random((int)DateTime.Now.Ticks);


            //image stream
            FileContentResult img = null;

            using (var mem = new MemoryStream())
            //using (var bmp = new Bitmap(130, 30))
            //using (var gfx = Graphics.FromImage((Image)bmp))
            {
                QRCodeWriter qr = new QRCodeWriter();

                string url = qrcode;

                var matrix = qr.encode(url, ZXing.BarcodeFormat.QR_CODE, 200, 200);

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

                w.Format = ZXing.BarcodeFormat.QR_CODE;

                Bitmap img1 = w.Write(matrix);



                //render as Png
                img1.Save(mem, System.Drawing.Imaging.ImageFormat.Png);
                img = this.File(mem.GetBuffer(), "image/png");
            }

            var file = File(img.FileContents, img.ContentType);

            return(File(img.FileContents, img.ContentType));
        }
        public LoggedMainPage()
        {
            InitializeComponent();
            // Código de ejemplo para traducir ApplicationBar
            BuildLocalizedApplicationBar();
            LoggedUser user = LoggedUser.Instance;

            LoggedUser.Instance.RemoveFriend();
            string          codigo = "http://pis2013.azurewebsites.net/?id=" + user.GetLoggedUser().Id;
            EncodingOptions options;

            options = new ZXing.QrCode.QrCodeEncodingOptions
            {
                Height = 500,
                Width  = 500
            };

            var writer = new ZXing.BarcodeWriter {
                Format = ZXing.BarcodeFormat.QR_CODE, Options = options
            };
            var writeableBitmap = writer.Write(codigo);

            ImgQR.Source = writeableBitmap;

            //UserName.Text =user.GetLoggedUser().Name;
            if (PageTitle.Text == "share")
            {
                PageTitle.FontSize = 95;
            }
        }
示例#15
0
        private void PrintDocument_PrintPage(object sender, PrintPageEventArgs e)
        {
            var g = e.Graphics;

            if (App.Settings.Rotation180 == true)
            {
                g.TranslateTransform(138, 118);
                g.RotateTransform(180);
            }

            var titleM = g.MeasureString("样本保存液", fntTitle);
            var titleX = (138f - titleM.Width) / 2;

            g.DrawString("样本保存液", fntTitle, Brushes.Black, titleX, 8);

            var m2 = g.MeasureString("五混一", fntName);
            var x2 = (138f - m2.Width) / 2;
            var y2 = 8 + titleM.Height + 2;

            g.DrawString("五混一", fntName, Brushes.Black, x2, y2);

            var writer = new ZXing.BarcodeWriter();

            writer.Format              = ZXing.BarcodeFormat.CODE_128;
            writer.Options.Width       = 138;
            writer.Options.Height      = 45;
            writer.Options.PureBarcode = true;
            var bm = writer.Write(number);

            g.DrawImage(bm, 0, 40, 138, 45);
            var numberM = g.MeasureString(number, fntNumber);
            var numberX = (138f - numberM.Width) / 2;

            g.DrawString(number, fntNumber, Brushes.Black, numberX, 84);
        }
示例#16
0
        private void PrintDocument_PrintPage(object sender, PrintPageEventArgs e)
        {
            var g = e.Graphics;

            if (App.Settings.Rotation180 == true)
            {
                g.TranslateTransform(138, 118);
                g.RotateTransform(180);
            }

            var titleM = g.MeasureString("样本保存液", fntTitle);
            var titleX = (138f - titleM.Width) / 2;

            g.DrawString("样本保存液", fntTitle, Brushes.Black, titleX, 8);
            g.DrawString("姓名:", fntName, Brushes.Black, 5, 28);
            g.DrawString("编号:", fntName, Brushes.Black, 75, 28);
            g.DrawString("采样时间:", fntName, Brushes.Black, 5, 44);
            var writer = new ZXing.BarcodeWriter();

            writer.Format              = ZXing.BarcodeFormat.CODE_128;
            writer.Options.Width       = 138;
            writer.Options.Height      = 20;
            writer.Options.PureBarcode = true;
            var bm = writer.Write(number);

            g.DrawImage(bm, 0, 54, 138, 30);
            var numberM = g.MeasureString(number, fntNumber);
            var numberX = (138f - numberM.Width) / 2;

            g.DrawString(number, fntNumber, Brushes.Black, numberX, 83);
        }
示例#17
0
        private string GerarQRCodeImagemSTR(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));

                MemoryStream ms = new MemoryStream();
                resultado.Save(ms, ImageFormat.Jpeg);
                var    base64Data   = Convert.ToBase64String(ms.ToArray());
                string imagemString = "data:image/gif;base64," + base64Data;



                return(imagemString);
            }
            catch
            {
                throw;
            }
        }
示例#18
0
        public static Bitmap Encode(
            string strToBeEncoded,
            int width      = 180,
            int height     = 180,
            string charSet = "UTF-8")
        {
            ZXing.BarcodeWriter writer = new ZXing.BarcodeWriter
            {
                Format  = ZXing.BarcodeFormat.QR_CODE,
                Options = new ZXing.QrCode.QrCodeEncodingOptions
                {
                    //生成出图片的高度
                    Height = height,
                    //生成出图片的寬度
                    Width = width,
                    //文字是使用哪種編碼方式
                    CharacterSet = charSet,

                    //錯誤修正容量
                    //L水平    7%的字碼可被修正
                    //M水平    15%的字碼可被修正
                    //Q水平    25%的字碼可被修正
                    //H水平    30%的字碼可被修正
                    ErrorCorrection = ZXing.QrCode.Internal.ErrorCorrectionLevel.H
                }
            };
            //将要編碼的文字生成出QRCode的图檔
            return(writer.Write(strToBeEncoded));
        }
示例#19
0
        private byte[] GerarQRCodeImagemBYTE(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));

                MemoryStream ms = new MemoryStream();
                resultado.Save(ms, ImageFormat.Jpeg);
                BinaryReader reader = new BinaryReader(ms);
                byte[]       photo  = ConvertImageToByteArray(resultado, System.Drawing.Imaging.ImageFormat.Jpeg);

                return(photo);
            }
            catch
            {
                throw;
            }
        }
        public static Bitmap GetQRCodeImage(string code)
        {
            var writer        = new ZXing.QrCode.QRCodeWriter();
            var encodedString = writer.encode(code, ZXing.BarcodeFormat.QR_CODE, 4, 4);
            var qrCodeWriter  = new ZXing.BarcodeWriter();

            return(qrCodeWriter.Write(encodedString));
        }
示例#21
0
        protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
        {
            string link = (String) navigationParameter;

            ZXing.BarcodeWriter barcodeWriter = new ZXing.BarcodeWriter { Format = ZXing.BarcodeFormat.QR_CODE, Options = { Height = 500, Width = 500 } };
            QrCodeWriteableBitmap = barcodeWriter.Write(link);
            qrCode.Source = QrCodeWriteableBitmap;
        }
示例#22
0
        public ResultResponse GenerateWorkerBarcode(List <UserInformation> users)
        {
            ResultResponse resultResponse = new ResultResponse();

            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 < users.Count; i++)
            {
                int count = 0;
                iTextSharp.text.Font font = FontFactory.GetFont("Calibri", 6.0f, BaseColor.BLACK); // from 5.0f
                count++;
                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(users[i].UserSQNumber));
                result.Save(path + users[i].UserSQNumber, System.Drawing.Imaging.ImageFormat.Png);
                string first = "Employee Code : " + users[i].UserSQNumber;
                string last  = users[i].UserInformationName.ToString() + "\n" + users[i].DesignationName.ToString();
                iTextSharp.text.Paragraph paragraph     = new iTextSharp.text.Paragraph(first, font);
                iTextSharp.text.Paragraph lastparagraph = new iTextSharp.text.Paragraph(last, font);
                paragraph.SetLeading(1.0f, 1.0f);
                lastparagraph.SetLeading(1.0f, 1.0f);
                iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(path + users[i].UserSQNumber);
                image.ScaleToFit(new iTextSharp.text.Rectangle(85, 100));
                image.SetAbsolutePosition(0.0f, 0.0f);
                image.PaddingTop = 2;
                PdfPCell cell = new PdfPCell {
                    PaddingLeft = 0, PaddingTop = 2, 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 + users[i].UserSQNumber);
            }
            doc.Add(pdftable);
            doc.Close();
            resultResponse.isSuccess = true;
            resultResponse.data      = path + fileName + ".pdf";
            return(resultResponse);
        }
示例#23
0
        private static Image GenerateQRCode(string Content)
        {
            ZXing.QrCode.QRCodeWriter qrc = new ZXing.QrCode.QRCodeWriter();
            ZXing.Common.BitMatrix    bmx = qrc.encode(Content, ZXing.BarcodeFormat.QR_CODE, 100, 100);
            ZXing.BarcodeWriter       bcw = new ZXing.BarcodeWriter();
            Bitmap bmp = bcw.Write(bmx);

            return((Image)bmp);
        }
示例#24
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;
 }
示例#25
0
        /// <summary>
        /// 打印的格式
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PalletLabelDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {/*
          * 如果需要改变 可以在new Font(new FontFamily("Arial"), 11)中的“Arial”改成自己要的字体就行了,黑体 后面的数字代表字体的大小
          *  System.Drawing.Brushes.Blue, 170, 10 中的 System.Drawing.Brushes.Blue 为颜色,后面的为输出的位置*/
            EncodingOptions encodeOption = new EncodingOptions();

            encodeOption.Height      = 15;
            encodeOption.Width       = 110;
            encodeOption.PureBarcode = true;
            ZXing.BarcodeWriter wr = new ZXing.BarcodeWriter();
            wr.Options = encodeOption;
            wr.Format  = ZXing.BarcodeFormat.CODE_128;

            var    code      = "L2014021700000008";
            string printTime = DateTime.Now.ToString();
            Bitmap img       = wr.Write(code);
            Bitmap timeImg   = wr.Write(printTime);

            e.Graphics.DrawString("W/H:", new Font(new FontFamily("Arial"), 13f, FontStyle.Bold), Brushes.Black, 50, 5);
            e.Graphics.DrawString("STORE-IN SHEET", new Font(new FontFamily("Arial"), 20f, FontStyle.Bold), Brushes.Black, 260, 2);
            e.Graphics.DrawString("Print time: " + printTime, new Font(new FontFamily("Arial"), 9f), Brushes.Black, 600, 15);
            //打印一串显示时间段 条形码
            e.Graphics.DrawImage(timeImg, 410, 33);
            e.Graphics.DrawString("Pallet No: ", new Font(new FontFamily("Arial"), 13f, FontStyle.Bold), Brushes.Black, 10, 25);
            /*graphics.DrawString(MduLabelPrint.toBarcode(this.m_PalletLabel.LabelID), this.ftCode39, Brushes.Black, (float)intBeginX, (float)checked(intBeginY + num * 2 + 17));*/
            e.Graphics.DrawString("Page: ", new Font(new FontFamily("Arial"), 13f, FontStyle.Bold), Brushes.Black, 660, 27);
            e.Graphics.DrawString("Model: ", new Font(new FontFamily("Arial"), 13f, FontStyle.Bold), Brushes.Black, 10, 47);
            e.Graphics.DrawString("Model Desc: ", new Font(new FontFamily("Arial"), 13f, FontStyle.Bold), Brushes.Black, 305, 47);
            e.Graphics.DrawString("Part No: ", new Font(new FontFamily("Arial"), 13f, FontStyle.Bold), Brushes.Black, 10, 69);
            e.Graphics.DrawString("Qty: ", new Font(new FontFamily("Arial"), 13f, FontStyle.Bold), Brushes.Black, 305, 69);
            /*graphics.DrawString(MduLabelPrint.toBarcode(this.m_PalletLabel.Qty.ToString()), this.ftCode39, Brushes.Black, 120f, (float)checked(intBeginY + num * 5 + 17));*/
            e.Graphics.DrawString("Bin: ", new Font(new FontFamily("Arial"), 13f, FontStyle.Bold), Brushes.Black, 540, 69);
            //双细线画粗线
            e.Graphics.DrawLine(Pens.Black, 265, 30, 500, 30);
            e.Graphics.DrawLine(Pens.Black, 265, 31, 500, 31);
            e.Graphics.DrawLine(Pens.Black, 11, 91, 800, 91);

            e.Graphics.DrawString("MO:", new Font(new FontFamily("Arial"), 10f), Brushes.Black, 10, 92);
            e.Graphics.DrawImage(img, 9, 106);
            e.Graphics.DrawString($"{code}", new Font(new FontFamily("Arial"), 10f), Brushes.Black, 10, 121);
            e.HasMorePages = false;
        }
示例#26
0
        public void RenderQRCode(string otpauth)
        {
            var writer = new ZXing.BarcodeWriter
            {
                Format = ZXing.BarcodeFormat.QR_CODE
            };

            var newBitmap = writer.Write(otpauth);

            pbQRCode.Image = ResizeImage(newBitmap, new Size(300, 300));
        }
示例#27
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)));
        }
示例#28
0
 private void txtBarCode_TextChanged(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(txtBarCode.Text))
     {
         ZXing.BarcodeWriter writer = new ZXing.BarcodeWriter()
         {
             Format = ZXing.BarcodeFormat.CODE_128
         };
         pbBarcode.Image = writer.Write(txtBarCode.Text);
         CalculateAfterStopTyping();
     }
 }
示例#29
0
        public object GetStdPicture(string contents)
        {
            var writer = new ZXing.BarcodeWriter
            {
                Format  = Format.ToZXing(),
                Options = options.wrappedEncodingOptions
            };

            using (var bitmap = writer.Write(contents))
            {
                return(ImageUtils.ConvertToIPicture(bitmap));
            }
        }
示例#30
0
        public Bitmap QRCodeGenerator(int width, int height, string url)
        {
            var barCode = new ZXing.BarcodeWriter <ZXing.IBarcodeWriter>
            {
                Format  = ZXing.BarcodeFormat.QR_CODE,
                Options = new ZXing.Common.EncodingOptions()
                {
                    Width = width, Height = height, Margin = 0
                }
            };

            return(new Bitmap((Image)barCode.Write(url)));
        }
        void LoadData(string orderNo)
        {
            try
            {
                var qr      = new ZXing.BarcodeWriter();
                var options = new QrCodeEncodingOptions
                {
                    DisableECI   = true,
                    CharacterSet = "UTF-8",
                    Width        = 100,
                    Height       = 100,
                };
                qr.Options = options;
                qr.Format  = ZXing.BarcodeFormat.QR_CODE;

                var    fName    = Path.GetTempPath() + "/" + Guid.NewGuid().ToString().Replace("-", "_") + ".jpg";
                string FilePath = @"file:\" + fName;
                var    result   = new Bitmap(qr.Write(orderNo));
                result.Save(fName, ImageFormat.Jpeg);

                //setup report
                reportViewer.LocalReport.EnableExternalImages = true;

                reportViewer.ProcessingMode         = ProcessingMode.Local;
                reportViewer.LocalReport.ReportPath = Server.MapPath("~/Reports") + "/QRcode.rdlc";

                using (var db = new smlpobDB())
                {
                    var orderData = (from x in db.ordermastertbls
                                     where x.orderNo == orderNo
                                     select x).FirstOrDefault();

                    if (orderData != null)
                    {
                        ReportParameter ImageQRParam = new ReportParameter();
                        ImageQRParam.Name = "ImageQR";
                        ImageQRParam.Values.Add(FilePath);

                        reportViewer.LocalReport.SetParameters(new ReportParameter[] { ImageQRParam });
                    }
                }
            }
            catch (Exception ex)
            {
                CommonWeb.Alert(this, "Terjadi kesalahan, silahkan coba kembali.");
                LogHelpers.source  = this.GetType().ToString();
                LogHelpers.message = "Failed to print QR code with the following error:" + ex.Message;
                LogHelpers.user    = CommonWeb.GetCurrentUser();
                LogHelpers.WriteLog();
            }
        }
示例#32
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)
示例#33
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);
        }
 public string GetQrCode(string qrValue, int size) {
     var barcodeWriter = new ZXing.BarcodeWriter {
         Format = ZXing.BarcodeFormat.QR_CODE,
         Options = new ZXing.Common.EncodingOptions
         {
             Height = size, // height,
             Width = size, // width,
             Margin = 0, // margin
         }
     };
     using (var bitmap = barcodeWriter.Write(qrValue))
     using (var stream = new System.IO.MemoryStream()) {
         bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Gif);
         return String.Format("data:image/gif;base64,{0}", 
             Convert.ToBase64String(stream.ToArray()));
     }            
 }
示例#35
0
		public override void ViewDidLoad ()
		{
			this.Root.Add(new Section() { 

				new EntryElement("Value:", "Barcode Value to Generate", ""),
				new StyledStringElement("Generate Barcode", () => {

					string val = string.Empty;

					this.InvokeOnMainThread(() => {
						var ee = this.Root[0][0] as EntryElement;
						ee.FetchValue();
						val = ee.Value;
					});

					var writer = new ZXing.BarcodeWriter() { Format = this.Format };

					this.InvokeOnMainThread(() => {

						this.Root[1].Clear();

						try
						{
							var img = writer.Write(val);							
							this.Root[1].Add(new BarcodeElement(this.Format, val, 160f));
						}
						catch (Exception ex)
						{
							this.Root[1].Add(new StyledMultilineElement(null, ex.ToString()));
						}
					});
				})
			});

			this.Root.Add(new Section() {



			});




		}
示例#36
0
        /// <summary>
        /// Does the actual drawing of the image.
        /// </summary>
        /// <param name="bm"></param>
        /// <param name="AztecCode"></param>
        internal void DrawImage(ref System.Drawing.Bitmap bm, string aztecCode)
        {
            var writer = new ZXing.BarcodeWriter();
            writer.Format = ZXing.BarcodeFormat.AZTEC;

            Graphics g = null;
            g = Graphics.FromImage(bm);
            float mag = PixelConversions.GetMagnification(g, bm.Width, bm.Height, OptimalHeight, OptimalWidth);

            int barHeight = PixelConversions.PixelXFromMm(g, OptimalHeight * mag);
            int barWidth = PixelConversions.PixelYFromMm(g, OptimalWidth * mag);

            writer.Options.Height = barHeight;
            writer.Options.Width = barWidth;


            bm = writer.Write(aztecCode);

        }
示例#37
0
        public void DrawImage(ref Bitmap bm, string code39)
        {
			var writer = new ZXing.BarcodeWriter();
			writer.Format = ZXing.BarcodeFormat.CODE_39;

            Graphics g = null;
            g = Graphics.FromImage(bm);
            float mag = PixelConversions.GetMagnification(g, bm.Width, bm.Height, 
                OptimalHeight, OptimalWidth);

            int barHeight = PixelConversions.PixelXFromMm(g, OptimalHeight * mag);
            int barWidth = PixelConversions.PixelYFromMm(g, OptimalWidth * mag);


			writer.Options.Height = barHeight;
			writer.Options.Width = barWidth;


			bm = writer.Write(code39);
        }
        public ActionResult GetQrCode(int id)
        {
            ZXing.BarcodeWriter barcodeWriter = new ZXing.BarcodeWriter { Format = ZXing.BarcodeFormat.QR_CODE };
            barcodeWriter.Options.Width = 200;
            barcodeWriter.Options.Height = 200;

            // The QR code should point users to /api/activity/{id}/checkin
            string path = this.Request.Path.ToString();
            string checkinPath = path.Substring(0, path.Length - "qrcode".Length) + "checkin";

            var bitmap = barcodeWriter.Write(String.Format("https://{0}/{1}", this.Request.Host, checkinPath));
            using (MemoryStream stream = new MemoryStream())
            {
                bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
                return File(stream.ToArray(), "image/png");
            }
        }
示例#39
0
        public ActionResult GetQrCode(int id)
        {
            var barcodeWriter = new ZXing.BarcodeWriter
            {
                Format = ZXing.BarcodeFormat.QR_CODE,
                Options = { Width = 200, Height = 200 }
            };

            // The QR code should point users to /api/event/{id}/checkin
            var path = Request.Path.ToString();
            var checkinPath = path.Substring(0, path.Length - "qrcode".Length) + "checkin";

            var bitmap = barcodeWriter.Write($"https://{Request.Host}/{checkinPath}");
            using (var stream = new MemoryStream())
            {
                bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
                return File(stream.ToArray(), "image/png");
            }
        }
示例#40
0
        void pdoc_PrintPage(object sender, PrintPageEventArgs e)
        {
            Graphics graphics = e.Graphics;
            string underLine;
            Font font;
            if (k < 1)
            {
                font = new Font("Courier New", 6);
                underLine = "-------------------------------------";
            }
            else
            {
                font = new Font("Arial", 8);
                underLine = "---------------------------------------";
            }

            float fontHeight = font.GetHeight();
            int startX = 0;
            int startY = 10;
            int Offset = Convert.ToInt32(fontHeight);

            int newLine15 = toValue(15);
            int newLine20 = toValue(20);

            // --------------------------
            int newLine10 = toValue(10);
            int newLine7 = toValue(7);
            font = new Font("Arial", 7);
            Font boldFont = new Font("Arial",8,FontStyle.Bold);
            Font smallFont = new Font("Arial", 6);
            Font smallFontBold = new Font("Arial", 6, FontStyle.Bold);
            Font smallFontUnderline = new Font("Arial", 8, FontStyle.Bold |FontStyle.Underline);

            graphics.DrawString("Иргэн танд очих баримт".PadLeft(50), boldFont, new SolidBrush(Color.Black), startX, startY + Offset);

            Offset = Offset + newLine15;

            if (resultData.lottery != "" && resultData.lottery!=null)
            {
                graphics.DrawString("Сугалаатай".PadLeft(50), font, new SolidBrush(Color.Black), startX, startY + Offset);
            }

            Offset = Offset + newLine15;

            graphics.DrawString(" Борлуулагч нь НӨАТ төлөгч мөн бол 20% урамшуулалтай".PadLeft(50), smallFont, new SolidBrush(Color.Black), startX, startY + Offset);

            Offset = Offset + newLine15;

            graphics.DrawString(" Борлуулагч нь НӨАТ төлөгч биш бол 20% урамшуулалгүй".PadLeft(50), smallFont, new SolidBrush(Color.Black), startX, startY + Offset);

            Offset = Offset + newLine15;

            graphics.DrawLine(new Pen(Color.Black, 2), new Point(startX, Offset + newLine15), new Point(startX + 300, Offset + newLine15));

            Offset = Offset + newLine15;

            graphics.DrawString("Таван Буянт Трейд".PadLeft(50), boldFont, new SolidBrush(Color.Black), startX, startY + Offset);

            Offset = Offset + newLine15;

            graphics.DrawString("ТТД :".PadRight(15) + this.resultData.merchantId,
                    font,
                    new SolidBrush(Color.Black), startX, startY + Offset);
            Offset = Offset + newLine15;

            graphics.DrawString("ДДТД :".PadRight(13) + this.resultData.billId,
                    font,
                     new SolidBrush(Color.Black), startX, startY + Offset);

            Offset = Offset + newLine15;
            graphics.DrawString("Огноо :".PadRight(15) + this.resultData.date,
                     font,
                     new SolidBrush(Color.Black), startX, startY + Offset);
            Offset = Offset + newLine15;

            graphics.DrawString("Касс :".PadRight(16) + "№122",
                     font,
                     new SolidBrush(Color.Black), startX, startY + Offset);
            Offset = Offset + newLine15;

            graphics.DrawString("Кассчин :".PadRight(14) + "№14566",
                  font,
                  new SolidBrush(Color.Black), startX, startY + Offset);
            Offset = Offset + newLine10;

            graphics.DrawLine(new Pen(Color.Black, 1), new Point(startX, Offset + newLine15), new Point(startX + 300, Offset + newLine15));

            Offset = Offset + newLine7;

            graphics.DrawString("Бараа",
                smallFontBold,
                new SolidBrush(Color.Black), startX, startY + Offset);
            Offset = Offset + newLine10;

            graphics.DrawLine(new Pen(Color.Black, 1), new Point(startX, Offset + newLine10), new Point(startX + 300, Offset + newLine10));

            graphics.DrawString("Т/Ш".PadRight(17) + "НӨАТ".PadRight(20) + "НХАТ".PadRight(20) + "НЭГЖ ҮНЭ".PadRight(20) +"НИЙТ",
                smallFontBold,
                new SolidBrush(Color.Black), startX, startY + Offset + 1);
            Offset = Offset + newLine10;

            graphics.DrawLine(new Pen(Color.Black, 1), new Point(startX, Offset + newLine10), new Point(startX + 300, Offset + newLine10));

            Offset = Offset + newLine15;

            if (this.resultData.stocks != null)
            {
                var count = 0;
                foreach (BillDetail stock in this.resultData.stocks)
                {

                    graphics.DrawString(stock.name,
                        stock.cityTax.Equals("0.00") ? font: smallFontUnderline, new SolidBrush(Color.Black), startX, startY + Offset-10);
                    Offset = Offset + newLine15;

                    graphics.DrawString(stock.qty.PadRight(20 - stock.qty.Length) + stock.vat.PadRight(18 -stock.vat.Length) + stock.cityTax.PadRight(20 - stock.cityTax.Length) + stock.unitPrice.PadRight(20-stock.unitPrice.Length) + stock.totalAmount,
                        stock.cityTax.Equals("0.00") ? font : boldFont, new SolidBrush(Color.Black), startX, startY + Offset - 10);

                    Offset = Offset + newLine15;
                }

            }

            graphics.DrawLine(new Pen(Color.Black, 1), new Point(startX, Offset + newLine10), new Point(startX + 300, Offset + newLine10));

            Offset = Offset + newLine10;

            graphics.DrawString(("Бонус:".PadRight(25 - "Бонус:".Length) + "0.00").PadRight(40) + "Нийт үнэ:".PadRight(10) + resultData.amount,
             font,
             new SolidBrush(Color.Black), startX, startY + Offset);
            Offset = Offset + newLine15;

            graphics.DrawString(("НӨАТ:".PadRight(25 - "НӨАТ:".Length) + resultData.vat).PadRight(40) + "НХАТ:".PadRight(10) + resultData.cityTax,
            font,
            new SolidBrush(Color.Black), startX, startY + Offset);
            Offset = Offset + newLine15;

            graphics.DrawString(("Бэлэн бус:".PadRight(25 - "Бэлэн бус:".Length) + resultData.nonCashAmount).PadRight(40) + "Бэлэн:".PadRight(10) + resultData.cashAmount,
               font,
               new SolidBrush(Color.Black), startX, startY + Offset);
            Offset = Offset + newLine15;

            graphics.DrawString(("Төлсөн:".PadRight(25 - "Төлсөн:".Length) + resultData.amount).PadRight(40) + "Хариулт:".PadRight(10) + "0.00",
              font,
              new SolidBrush(Color.Black), startX, startY + Offset);
            Offset = Offset + newLine15;

            if (resultData.bankTransactions != null && resultData.bankTransactions.Count != 0)
            {

                graphics.DrawString("Card No".PadRight(13) + "RRN".PadRight(12) + "App.Code".PadRight(9) + "Terminal ID" + "Amount", font,
                  new SolidBrush(Color.Black), startX, startY + Offset);

                Offset = Offset + newLine20;
                foreach (BillBankTransaction banktranscation in this.resultData.bankTransactions)
                {
                    graphics.DrawString("9231 23** **** 3234".PadRight(20) + banktranscation.rrn.PadRight(12) + banktranscation.approvalCode.PadRight(8) + banktranscation.amount,
                    font,
                     new SolidBrush(Color.Black),
                     startX, startY + Offset
                    );
                }
                Offset = Offset + newLine20;
            }

            graphics.DrawLine(new Pen(Color.Black, 1), new Point(startX, Offset + newLine10), new Point(startX + 300, Offset + newLine10));

            Offset = Offset + newLine10;

            var logo = new Bitmap("logo-bill.png");
            graphics.DrawImage(logo, startX + 20 , startY + Offset);
            Offset = Offset + newLine20;
            Offset = Offset + newLine20;
            Offset = Offset + newLine20;
            if (resultData.lottery != null)
            {
                graphics.DrawString("Сугалаа ".PadLeft(30) + resultData.lottery, boldFont, new SolidBrush(Color.Black), startX, startY + Offset);
            }

            Offset = Offset + newLine15;
            ///--------------------------

             //           graphics.DrawString("Мерчант :".PadRight(10) + this.resultData.merchantId,
             //                   font,
             //                   new SolidBrush(Color.Black), startX, startY + Offset);
             //           Offset = Offset + newLine15;

             //           graphics.DrawString("Баримт №: " + this.resultData.billId,
             //                   font,
             //                    new SolidBrush(Color.Black), startX, startY + Offset);

             //           Offset = Offset + newLine15;
             //           graphics.DrawString("Огноо :".PadRight(10) + this.resultData.date,
             //                    font,
             //                    new SolidBrush(Color.Black), startX, startY + Offset);
             //           Offset = Offset + newLine15;

             //           graphics.DrawString("Касс :".PadRight(10) + "122",
             //                    font,
             //                    new SolidBrush(Color.Black), startX, startY + Offset);
             //           Offset = Offset + newLine15;

             //           graphics.DrawString(underLine, font,
             //                    new SolidBrush(Color.Black), startX, startY + Offset);

             //           Offset = Offset + newLine20;

             //           string tmp = "Д/д Бараа".PadRight(10) + "Х/нэгж".PadRight(8) + "Код";
             //           graphics.DrawString(tmp, font,
             //                    new SolidBrush(Color.Black), startX, startY + Offset);
             //           Offset = Offset + newLine15;
             //           string tmp1 = "Үнэ".PadRight(7) + "НӨАТ".PadRight(6) + "НХАТ".PadRight(7) + "тоо/ш".PadRight(12) + "Дүн";
             //           tmp1 = tmp1.PadLeft(38);
             //           graphics.DrawString(tmp1, font,
             //                    new SolidBrush(Color.Black), startX, startY + Offset);

             //           Offset = Offset + newLine20;

             //           if (this.resultData.stocks != null)
             //           {
             //               var count = 0;
             //               foreach (BillDetail stock in this.resultData.stocks)
             //               {
             //                   graphics.DrawString(++count + " " + stock.name.PadRight(12) + stock.measureUnit.PadRight(4) + stock.code, font, new SolidBrush(Color.Black), startX, startY + Offset);
             //                   Offset = Offset + newLine20;
             //                   string unitPriceVat = (Convert.ToDouble(stock.unitPrice) + Convert.ToDouble(stock.vat)).ToString(Program.NUMBER_FORMAT);

             //                   var value = String.Format("   {0:F0}   {1:F0}   {2:F0}   x {3}", Convert.ToDouble(stock.unitPrice), Convert.ToDouble(stock.vat), Convert.ToDouble(stock.cityTax), stock.qty);
             //                   var amount = Convert.ToDouble(stock.totalAmount);
             //                   value += amount.ToString().PadLeft(10);
             //                   value = value.PadLeft(38);

             //                   graphics.DrawString(value, font,
             //                      new SolidBrush(Color.Black), startX, startY + Offset);
             //                   Offset = Offset + newLine15;
             //               }

             //           }

             //           graphics.DrawString(underLine, font,
             //                    new SolidBrush(Color.Black), startX, startY + Offset);
             //           Offset = Offset + newLine20;

             //           if (resultData.bankTransactions != null && resultData.bankTransactions.Count != 0)
             //           {
             //               string tmpb = String.Format("Банк/нэр".PadRight(13) + "RRN".PadRight(12) + "Approval".PadRight(9) + "Дүн");
             //               graphics.DrawString(tmpb, font,
             //                 new SolidBrush(Color.Black), startX, startY + Offset);

             //               Offset = Offset + newLine20;
             //               foreach (BillBankTransaction banktranscation in this.resultData.bankTransactions)
             //               {
             //                   graphics.DrawString(banktranscation.bankName.PadRight(12),
             //                   font,
             //                    new SolidBrush(Color.Black),
             //                   new Rectangle(startX, startY + Offset, 100, 50)
             //                   );
             //                   var value = banktranscation.bankName.PadRight(8) +banktranscation.rrn.PadRight(16) + banktranscation.approvalCode.PadRight(9)+ banktranscation.amount;
             //                   graphics.DrawString(value, font,
             //                     new SolidBrush(Color.Black), startX, startY + Offset);
             //                   Offset = Offset + newLine20; //newLine20;
             //               }

             //               graphics.DrawString(underLine, font,
             //                        new SolidBrush(Color.Black), startX, startY + Offset);
             //               Offset = Offset + newLine20;
             //           }

             //           graphics.DrawString("Бэлэн :".PadRight(13) + resultData.cashAmount, font,
             //                  new SolidBrush(Color.Black), startX, startY + Offset);

             //           Offset = Offset + newLine20;

             //           graphics.DrawString("Бэлэн Бус :".PadRight(13) + resultData.nonCashAmount, font,
             //                  new SolidBrush(Color.Black), startX, startY + Offset);

             //           Offset = Offset + newLine20;

             //           graphics.DrawString("НӨАТ :".PadRight(13) + resultData.vat, font,
             //                new SolidBrush(Color.Black), startX, startY + Offset);

             //           Offset = Offset + newLine20;

             //           graphics.DrawString("НХАТ :".PadRight(13) + resultData.cityTax, font,
             //              new SolidBrush(Color.Black), startX, startY + Offset);

             //           Offset = Offset + newLine20;

             //           graphics.DrawString("Нийт :".PadRight(13) + resultData.amount, font,
             //      new SolidBrush(Color.Black), startX, startY + Offset);

             //           Offset = Offset + newLine20;

             //           graphics.DrawString("Төлсөн :".PadRight(13) + Convert.ToDouble(textBoxPaidAmount.Text).ToString(Program.NUMBER_FORMAT), font,
             //new SolidBrush(Color.Black), startX, startY + Offset);

             //           Offset = Offset + newLine20;

             //           graphics.DrawString("Хариулт :".PadRight(13) + (Convert.ToDouble(textBoxPaidAmount.Text) - Convert.ToDouble(this.resultData.cashAmount)).ToString(Program.NUMBER_FORMAT), font,
             //new SolidBrush(Color.Black), startX, startY + Offset);

             //           Offset = Offset + newLine20;

             //           graphics.DrawString(underLine, font,
             //                    new SolidBrush(Color.Black), startX, startY + Offset);
             //           Offset = Offset + newLine20;

             //           if (resultData.lottery != null && resultData.lottery.Length != 0)
             //           {
             //               graphics.DrawString("Сугалаа :".PadRight(15) + this.resultData.lottery,
             //                   font,
             //                   new SolidBrush(Color.Black), startX, startY + Offset);
             //               Offset = Offset + newLine15;
             //           }

            if (resultData.lottery != null && resultData.lottery.Length != 0)
            {
                ZXing.IBarcodeWriter writer = new ZXing.BarcodeWriter
                {
                    Format = ZXing.BarcodeFormat.QR_CODE,
                    Options = new ZXing.QrCode.QrCodeEncodingOptions
                    {
                        Width = toValue(150),
                        Height = toValue(150)
                    }
                };
                var dataQr = writer.Write(resultData.qrData);
                var barcodeBitmap = new Bitmap(dataQr, new Size(toValue(150), toValue(150)));
                graphics.DrawImage(barcodeBitmap, toValue(startX + 55), startY + Offset);

                Offset = Offset + toValue(100 + 50);
            }

            var writerBarCode = new ZXing.BarcodeWriter
            {
                Format = ZXing.BarcodeFormat.CODE_128,
                Options = new ZXing.OneD.Code128EncodingOptions
                {
                    Width = toValue(180),
                    Height = toValue(50),
                }
            };

            var bitmap = writerBarCode.Write(this.resultData.billId);
            graphics.DrawImage(bitmap, k < 1 ? toValue(startX) : toValue(startX + 30), startY + Offset);

            Offset = Offset + toValue(70);

            graphics.Dispose();
        }
示例#41
0
        public void RenderQRCode()
        {
            if (IsKeyValid)
            {
                var writer = new ZXing.BarcodeWriter
                {
                    Format = ZXing.BarcodeFormat.QR_CODE
                };

                var otpauth = String.Format("otpauth://totp/{0}?secret={1}", AccountName, Key);
                var newBitmap = writer.Write(otpauth);
                pbQRCode.Image = ResizeImage(newBitmap, new Size(300, 300));
            }
            else
            {
                pbQRCode.Image = null;
            }
        }