Пример #1
0
        private void CreateBarcode128()
        {
            string strBarcode = txtMa_Vt.Text.Trim();
            //string strTen1 = txtTen_Vt2.Text.Trim();
            //string strTen2 = txtTen_Vt.Text + "\n" + String.Format("{0:0,0 vnđ}", numGia_Ban.Value);

            string strTen1 = "";
            string strTen2 = "";

            int W = picBarCode.Width;  //Convert.ToInt32(this.txtWidth.Text.Trim());
            int H = picBarCode.Height; // Convert.ToInt32(this.txtHeight.Text.Trim());

            //Barcode alignment
            barcodeLib.Alignment = BarcodeLib.AlignmentPositions.CENTER;

            BarcodeLib.TYPE type = BarcodeLib.TYPE.UNSPECIFIED;
            type = BarcodeLib.TYPE.CODE128;

            //Hien thi so ma vach
            //barcodeLib.IncludeLabel = true;
            barcodeLib.IncludeLabel = false; //--> khong can hien thi label ma code

            try
            {
                if (type != BarcodeLib.TYPE.UNSPECIFIED)
                {
                    barcodeLib.RotateFlipType = (RotateFlipType)Enum.Parse(typeof(RotateFlipType), "RotateNoneFlipNone", true);

                    //label alignment and position
                    barcodeLib.LabelPosition = BarcodeLib.LabelPositions.BOTTOMCENTER;
                    //switch (this.cbLabelLocation.SelectedItem.ToString().Trim().ToUpper())
                    //{
                    //    case "BOTTOMLEFT": barcodeLib.LabelPosition = BarcodeLib.LabelPositions.BOTTOMLEFT; break;
                    //    case "BOTTOMRIGHT": barcodeLib.LabelPosition = BarcodeLib.LabelPositions.BOTTOMRIGHT; break;
                    //    case "TOPCENTER": barcodeLib.LabelPosition = BarcodeLib.LabelPositions.TOPCENTER; break;
                    //    case "TOPLEFT": barcodeLib.LabelPosition = BarcodeLib.LabelPositions.TOPLEFT; break;
                    //    case "TOPRIGHT": barcodeLib.LabelPosition = BarcodeLib.LabelPositions.TOPRIGHT; break;
                    //    default: barcodeLib.LabelPosition = BarcodeLib.LabelPositions.BOTTOMCENTER; break;
                    //}//switch

                    //===== Encoding performed here =====
                    picBarCode.Image = barcodeLib.Encode(type, strBarcode, strTen1, strTen2, this.color, Color.White, W, H);
                    //===================================

                    //txtEncoded.Text = barcodeLib.EncodedValue;

                    //tsslEncodedType.Text = "Encoding Type: " + barcodeLib.EncodedType.ToString();
                }//if

                picBarCode.Width  = picBarCode.Image.Width;
                picBarCode.Height = picBarCode.Image.Height;

                //Tu dong luu Barcode
                Auto_Save_FileBarcode();
            }//try
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }//catch
        }
Пример #2
0
        public static string GetBarcodeString(int height, int width, BarcodeLib.TYPE type, string code, out System.Drawing.Image image)
        {
            image = null;
            BarcodeLib.Barcode b = new BarcodeLib.Barcode();
            b.BackColor     = System.Drawing.Color.White; //图片背景颜色
            b.ForeColor     = System.Drawing.Color.Black; //条码颜色
            b.IncludeLabel  = true;
            b.Alignment     = BarcodeLib.AlignmentPositions.CENTER;
            b.LabelPosition = BarcodeLib.LabelPositions.BOTTOMCENTER;
            b.ImageFormat   = System.Drawing.Imaging.ImageFormat.Jpeg;          //图片格式
            System.Drawing.Font font = new System.Drawing.Font("verdana", 10f); //字体设置
            b.LabelFont = font;

            b.Height = height;                             //图片高度设置(px单位)
            b.Width  = width;                              //图片宽度设置(px单位)

            image = b.Encode(type, code);                  //生成图片
            byte[] buffer = b.GetImageData(SaveTypes.GIF); //转换byte格式
            //byte转换图片格式
            MemoryStream oMemoryStream = new MemoryStream(buffer);

            //設定資料流位置
            oMemoryStream.Position = 0;
            //return buffer;
            //return image;
            return(System.Convert.ToBase64String(buffer, 0, buffer.Length));
        }
Пример #3
0
        public static void GetBarcode(int height, int width, BarcodeLib.TYPE type, string code, out System.Drawing.Image image, string fileSaveUrl)
        {
            try
            {
                image = null;

                BarcodeLib.Barcode b = new BarcodeLib.Barcode();
                b.BackColor     = System.Drawing.Color.White; //图片背景颜色
                b.ForeColor     = System.Drawing.Color.Black; //条码颜色
                b.IncludeLabel  = true;
                b.Alignment     = BarcodeLib.AlignmentPositions.LEFT;
                b.LabelPosition = BarcodeLib.LabelPositions.BOTTOMCENTER;           //code的显示位置
                b.ImageFormat   = System.Drawing.Imaging.ImageFormat.Jpeg;          //图片格式
                System.Drawing.Font font = new System.Drawing.Font("verdana", 10f); //字体设置
                b.LabelFont = font;
                b.Height    = height;                                               //图片高度设置(px单位)
                b.Width     = width;                                                //图片宽度设置(px单位)

                image = b.Encode(type, code);                                       //生成图片
                image.Save(fileSaveUrl, System.Drawing.Imaging.ImageFormat.Jpeg);
            }
            catch (Exception err)
            {
                err.ToString();
                image = null;
            }
        }
Пример #4
0
        private void buttonGenerate_Click(object sender, EventArgs e)
        {
            this.textBoxBarcode.Text = thingForDatat.generateNewBarcodeNumeric();
            // generate here barcode and show it
            BarcodeLib.TYPE type = TYPE.EAN13; // maybe, add input field with additional symbologies to select?
            int             W    = pictureBoxBarCode.Width - 10;
            int             H    = pictureBoxBarCode.Height - 10;

            pictureBoxBarCode.BackgroundImage = b.Encode(type, this.textBoxBarcode.Text.Trim(), Color.Black, Color.White, W, H);
        }
        protected override void OnPrintPage(PrintPageEventArgs e)
        {
            //条码高度和宽度
            try
            {
                StringFormat sf = new StringFormat();
                sf.Alignment     = StringAlignment.Center;
                sf.LineAlignment = StringAlignment.Center;
                Font Regularfont   = new System.Drawing.Font("Times New Roman, Times, serif", 25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
                Font Regularfont1  = new System.Drawing.Font("Times New Roman, Times, serif", 40F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
                Font Regularfont2  = new System.Drawing.Font("Times New Roman, Times, serif", 30F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
                Font Regularfont3  = new System.Drawing.Font("Times New Roman, Times, serif", 15F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
                Font Regularfont4  = new System.Drawing.Font("Times New Roman, Times, serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
                Font Regularfont5  = new System.Drawing.Font("Times New Roman, Times, serif", 17F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
                Font Regularfont6  = new System.Drawing.Font("Times New Roman, Times, serif", 14F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
                Font Regularfont7  = new System.Drawing.Font("Times New Roman, Times, serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
                Font Regularfont8  = new System.Drawing.Font("Times New Roman, Times, serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
                Font Regularfont9  = new System.Drawing.Font("Times New Roman, Times, serif", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
                Font Regularfont10 = new System.Drawing.Font("Times New Roman, Times, serif", 7F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));

                BarcodeLib.Barcode b    = new BarcodeLib.Barcode();
                BarcodeLib.TYPE    type = BarcodeLib.TYPE.CODE128;
                b.IncludeLabel = false;
                if (_packingLog.PostTypeNames.Length > 12)
                {
                    _packingLog.PostTypeNames = _packingLog.PostTypeNames.Insert(12, "\n");
                }
                string _countryArea = "BG国家/分区 : ";
                if (_packingLog.CountryNames.IndexOf(",") < 0)
                {
                    _countryArea += _packingLog.CountryNames;
                }
                var PostTypeNames = OrderSortService.GetPostTypeName(_packingLog.PostTypeIds);

                e.Graphics.DrawString(_countryArea, Regularfont4, Brushes.Black, 30, 30);
                string _dayPackage = _packingLog.OperationTime.ToString("MM/dd");
                e.Graphics.DrawImage(b.Encode(type, _packingLog.PackNumber, 150, 30), 80, 90);
                e.Graphics.DrawString(_packingLog.PackNumber, Regularfont7, Brushes.Black, 105, 125);
                e.Graphics.DrawString("运输方式:" + PostTypeNames, Regularfont4, Brushes.Black, 30, 150);
                e.Graphics.DrawString("日期:" + _dayPackage, Regularfont4, Brushes.Black, 30, 190);
                e.Graphics.DrawString("操作人:", Regularfont4, Brushes.Black, 30, 220);
                e.Graphics.DrawString("件数:" + _packingLog.OrderQty, Regularfont4, Brushes.Black, 30, 250);
                e.Graphics.DrawString("BGHZ  " + _packingLog.LatticeId, Regularfont4, Brushes.Black, 30, 280);
                e.Graphics.DrawString("重量:", Regularfont4, Brushes.Black, 130, 280);
                var image = GenerateQRByQrCodeNet(_packingLog.PackNumber);
                e.Graphics.DrawImage(image, 130, 170, 100, 100);

                this.Dispose();
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Пример #6
0
        private void cmbPart_Leave(object sender, EventArgs e)
        {
            bool someViablePartWasSelected = (cmbPart.SelectedItem != null);

            this.buttonGenerate.Enabled = !(someViablePartWasSelected) && cmbPart.Text != "";
            if (someViablePartWasSelected)
            { // show barcode for part
                BarcodePartDataClass partToResolve = cmbPart.SelectedItem as BarcodePartDataClass;
                this.textBoxBarcode.Text = partToResolve.BarcodeRaw;
                // generate here barcode and show it
                BarcodeLib.TYPE type = TYPE.EAN13; // maybe, add input field with additional symbologies to select?
                int             W    = pictureBoxBarCode.Width - 10;
                int             H    = pictureBoxBarCode.Height - 10;
                pictureBoxBarCode.BackgroundImage = b.Encode(type, this.textBoxBarcode.Text.Trim(), Color.Black, Color.White, W, H);
            }
        }
Пример #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string IdChar    = "";
            bool   checkChar = false;
            string code      = "";
            bool   hasText   = false;

            string topleft  = "";
            string topright = "";

            try
            {
                IdChar = Request["IdChar"].ToString();
            }
            catch (Exception)
            {
            }

            try
            {
                code = Request["code"].ToString();
            }
            catch (Exception)
            {
            }

            try
            {
                hasText = bool.Parse(Request["hasText"]);
            }
            catch (Exception)
            {
            }

            try
            {
                topleft = Request["topleft"];
            }
            catch (Exception)
            {
            }

            try
            {
                topright = Request["topright"];
            }
            catch (Exception)
            {
            }

            try
            {
                checkChar = bool.Parse(Request["checkChar"]);
            }
            catch (Exception)
            {
            }

            BarcodeLib.Barcode b    = new BarcodeLib.Barcode();
            BarcodeLib.TYPE    type = BarcodeLib.TYPE.CODE128;

            try
            {
                b.IncludeLabel = hasText;

                System.Drawing.Image img;

                int width = 100;
                //if (IdChar.Length + code.Length > 20)
                //    width = 350;

                //===== Encoding performed here =====

                string showString = "";
                if (IdChar == BarcodeBLL.DINIdChar)
                {
                    showString = IdChar + code.Substring(0, 5) + " " + code.Substring(5, 2) + " " + code.Substring(7, 6) + " " + code.Substring(13, 2);
                }
                else if (IdChar == BarcodeBLL.peopleIdChar)
                {
                    showString = IdChar + code.Substring(0, 4) + " " + code.Substring(4, 4) + " " + code.Substring(8, 4) + " " + code.Substring(12, 4);
                }

                if (hasText)
                {
                    img = b.Encode(type, IdChar + code, Color.Black, Color.White, width, 50, showString);
                }
                else
                {
                    img = b.Encode(type, IdChar + code, Color.Black, Color.White, width, 40, showString);
                }
                //===================================

                MemoryStream m = new MemoryStream();

                img.Save(m, ImageFormat.Png);

                Response.ContentType = "image/png";

                m.WriteTo(Response.OutputStream);

                m.Dispose();
            }//try
            catch (Exception)
            {
            }//catch
        }
Пример #8
0
        /// <summary>
        /// 输出条码
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnEncode_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtContent.Text))
            {
                TipHelper.TipMsg(this, $"请输入标签内容!");
            }

            errorProvider1.Clear();
            int W = Convert.ToInt32(this.txtWidth.Text.Trim());
            int H = Convert.ToInt32(this.txtHeight.Text.Trim());

            bar.Alignment = BarcodeLib.AlignmentPositions.CENTER;

            //条形码对齐
            switch (cbBarcodeAlign.SelectedItem.ToString().Trim().ToLower())
            {
            case "left": bar.Alignment = BarcodeLib.AlignmentPositions.LEFT; break;

            case "right": bar.Alignment = BarcodeLib.AlignmentPositions.RIGHT; break;

            default: bar.Alignment = BarcodeLib.AlignmentPositions.CENTER; break;
            }

            BarcodeLib.TYPE type = BarcodeLib.TYPE.UNSPECIFIED;
            switch (cbEncodeType.SelectedItem.ToString().Trim())
            {
            case "UPC-A": type = BarcodeLib.TYPE.UPCA; break;

            case "UPC-E": type = BarcodeLib.TYPE.UPCE; break;

            case "UPC 2 Digit Ext.": type = BarcodeLib.TYPE.UPC_SUPPLEMENTAL_2DIGIT; break;

            case "UPC 5 Digit Ext.": type = BarcodeLib.TYPE.UPC_SUPPLEMENTAL_5DIGIT; break;

            case "EAN-13": type = BarcodeLib.TYPE.EAN13; break;

            case "JAN-13": type = BarcodeLib.TYPE.JAN13; break;

            case "EAN-8": type = BarcodeLib.TYPE.EAN8; break;

            case "ITF-14": type = BarcodeLib.TYPE.ITF14; break;

            case "Codabar": type = BarcodeLib.TYPE.Codabar; break;

            case "PostNet": type = BarcodeLib.TYPE.PostNet; break;

            case "Bookland/ISBN": type = BarcodeLib.TYPE.BOOKLAND; break;

            case "Code 11": type = BarcodeLib.TYPE.CODE11; break;

            case "Code 39": type = BarcodeLib.TYPE.CODE39; break;

            case "Code 39 Extended": type = BarcodeLib.TYPE.CODE39Extended; break;

            case "Code 39 Mod 43": type = BarcodeLib.TYPE.CODE39_Mod43; break;

            case "Code 93": type = BarcodeLib.TYPE.CODE93; break;

            case "LOGMARS": type = BarcodeLib.TYPE.LOGMARS; break;

            case "MSI": type = BarcodeLib.TYPE.MSI_Mod10; break;

            case "Interleaved 2 of 5": type = BarcodeLib.TYPE.Interleaved2of5; break;

            case "Standard 2 of 5": type = BarcodeLib.TYPE.Standard2of5; break;

            case "Code 128": type = BarcodeLib.TYPE.CODE128; break;

            case "Code 128-A": type = BarcodeLib.TYPE.CODE128A; break;

            case "Code 128-B": type = BarcodeLib.TYPE.CODE128B; break;

            case "Code 128-C": type = BarcodeLib.TYPE.CODE128C; break;

            case "Telepen": type = BarcodeLib.TYPE.TELEPEN; break;

            case "FIM": type = BarcodeLib.TYPE.FIM; break;

            case "Pharmacode": type = BarcodeLib.TYPE.PHARMACODE; break;

            default: TipHelper.TipMsg(this, "请指定条码编码类型!"); break;
            }

            try
            {
                if (type != BarcodeLib.TYPE.UNSPECIFIED)
                {
                    try
                    {
                        bar.BarWidth = textBoxBarWidth.Text.Trim().Length < 1 ? null : (int?)Convert.ToInt32(textBoxBarWidth.Text.Trim());
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Unable to parse BarWidth: " + ex.Message, ex);
                    }
                    try
                    {
                        bar.AspectRatio = textBoxAspectRatio.Text.Trim().Length < 1 ? null : (double?)Convert.ToDouble(textBoxAspectRatio.Text.Trim());
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Unable to parse AspectRatio: " + ex.Message, ex);
                    }

                    bar.IncludeLabel = this.chkGenerateLabel.Checked;

                    bar.RotateFlipType = (RotateFlipType)Enum.Parse(typeof(RotateFlipType), this.cbRotateFlip.SelectedItem.ToString(), true);

                    //标签对齐和位置
                    switch (this.cbLabelLocation.SelectedItem.ToString().Trim().ToUpper())
                    {
                    case "BOTTOMLEFT": bar.LabelPosition = BarcodeLib.LabelPositions.BOTTOMLEFT; break;

                    case "BOTTOMRIGHT": bar.LabelPosition = BarcodeLib.LabelPositions.BOTTOMRIGHT; break;

                    case "TOPCENTER": bar.LabelPosition = BarcodeLib.LabelPositions.TOPCENTER; break;

                    case "TOPLEFT": bar.LabelPosition = BarcodeLib.LabelPositions.TOPLEFT; break;

                    case "TOPRIGHT": bar.LabelPosition = BarcodeLib.LabelPositions.TOPRIGHT; break;

                    default: bar.LabelPosition = BarcodeLib.LabelPositions.BOTTOMCENTER; break;
                    }

                    //===== 此处执行编码 =====
                    gbxBarCoder.BackgroundImage = bar.Encode(type, this.txtContent.Text.Trim(), this.btnForeColor.BackColor, this.btnBackColor.BackColor, W, H);
                    //===================================

                    //显示编码耗时
                    this.lblEncodingTime.Text = "(" + Math.Round(bar.EncodingTime, 0, MidpointRounding.AwayFromZero).ToString() + "ms)";

                    txtEncoded.Text = bar.EncodedValue;

                    //读取动态计算的宽度/高度,因为用户感兴趣。
                    if (bar.BarWidth.HasValue)
                    {
                        txtWidth.Text = bar.Width.ToString();
                    }
                    if (bar.AspectRatio.HasValue)
                    {
                        txtHeight.Text = bar.Height.ToString();
                    }
                }//if

                //条形码图像重新定位到中间
                gbxBarCoder.Location = new Point((this.gbxBarCoder.Location.X + this.gbxBarCoder.Width / 2) - gbxBarCoder.Width / 2, (this.gbxBarCoder.Location.Y + this.gbxBarCoder.Height / 2) - gbxBarCoder.Height / 2);
            }
            catch (Exception ex)
            {
                TipHelper.TipMsg(this, $"{ex.Message}");
            }
        }