Exemplo n.º 1
0
        private void btnEncode_Click(object sender, EventArgs e)
        {
            errorProvider1.Clear();
            int W = Convert.ToInt32(txtWidth.Text.Trim());
            int H = Convert.ToInt32(txtHeight.Text.Trim());

            BarcodeLib.AlignmentPositions alignment = BarcodeLib.AlignmentPositions.CENTER;
            BarcodeLib.TYPE type = BarcodeLib.TYPE.UNSPECIFIED;
            type                  = BarcodeLib.TYPE.CODE39;
            btnSave.Enabled       = true;
            btn_Save_Info.Enabled = true;
            try
            {
                if (type != BarcodeLib.TYPE.UNSPECIFIED)
                {
                    RotateFlipType rotateFlipType = (RotateFlipType)Enum.Parse(typeof(RotateFlipType), cbRotateFlip.SelectedItem.ToString(), true);
                    //label alignment and position
                    BarcodeLib.LabelPositions labelPosition = (BarcodeLib.LabelPositions)Enum.Parse(typeof(BarcodeLib.LabelPositions), cbLabelLocation.SelectedItem.ToString(), true);
                    barcode.Image   = b.Encode(type, txtData.Text.Trim(), b.ForeColor, b.BackColor, W, H, alignment, rotateFlipType, chkGenerateLabel.Checked, labelPosition);
                    txtEncoded.Text = b.EncodedValue;
                }
                barcode.Width  = barcode.Image.Width;
                barcode.Height = barcode.Image.Height;
                //reposition the barcode image to the middle
                barcode.Location = new Point((groupBox2.Location.X + groupBox2.Width / 2) - barcode.Width / 2, (groupBox2.Location.Y + groupBox2.Height / 2) - barcode.Height / 2);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 2
0
        public ReportDataSource ReportData_Load(string datasetName, SearchCondition condition)
        {
            ICTPmMsNoARDao  d      = ComponentLocator.Instance().Resolve <ICTPmMsNoARDao>();
            LoginUserInfoVo uservo = (LoginUserInfoVo)SessionUtils.GetSession(SessionUtils.COMMON_LOGIN_USER_INFO);

            SearchCondition condition1 = new SearchCondition();

            condition1.AddCondition("companyCd", uservo.CompanyCondition.ICompanyCd);
            condition1.AddCondition("langCd", LangUtils.GetCurrentLanguage());

            condition1.SetAddtionalCondition("ALLFACTORY", false);

            IList <CTPmMsNoAR> list = d.GetPmMsDetail(condition1);
            DataSet            ds   = new DataSet();
            DataTable          dt   = DataTableUtils.ToDataTable(list);
            DataColumn         col  = new DataColumn();

            col.DataType   = typeof(byte[]);
            col.ColumnName = "BarCode";
            dt.Columns.Add(col);

            dt.TableName = "TPmMs";
            ds.Tables.Add(dt);



            foreach (DataRow row in dt.Rows)
            {
                int W = Convert.ToInt32(200);
                int H = Convert.ToInt32(40);
                BarcodeLib.AlignmentPositions Align = BarcodeLib.AlignmentPositions.CENTER;
                BarcodeLib.TYPE    type             = BarcodeLib.TYPE.CODE39;
                BarcodeLib.Barcode b = new BarcodeLib.Barcode();
                b.IncludeLabel  = true;
                b.Alignment     = Align;
                b.LabelPosition = BarcodeLib.LabelPositions.BOTTOMCENTER;
                b.LabelFont     = new Font("宋体", 6);
                b.Encode(type, row["IDrwNo"].ToString(), Color.Black, Color.White, W, H);
                row["BarCode"] = b.GetImageData(BarcodeLib.SaveTypes.PNG);
            }

            ReportDataSource result = new ReportDataSource(datasetName, ds.Tables["TPmMs"]);

            return(result);
        }
Exemplo n.º 3
0
        public static bool GenerateBarcode(
            int barcodeEncoding
            , int width
            , int height
            , BarcodeLib.AlignmentPositions alignmentPosition
            , System.Drawing.RotateFlipType rotateFlipType
            , BarcodeLib.LabelPositions labelPosition
            , string stringToEncode
            , string imagePathAndName
            , BarcodeLib.SaveTypes saveType
            , System.Windows.Forms.GroupBox barcode
            , ref string errorMessage
            )
        {
            errorMessage = string.Empty;

            BarcodeLib.Barcode b = new BarcodeLib.Barcode();
            b.Alignment = alignmentPosition;

            BarcodeLib.TYPE type = BarcodeLib.TYPE.UNSPECIFIED;

            if (barcodeEncoding > 1)
            {
                barcodeEncoding = 1;
            }

            switch (barcodeEncoding)
            {
            ////case 0: type = BarcodeLib.TYPE.UPCA; break;                             //"UPC-A"
            ////case 1: type = BarcodeLib.TYPE.UPCE; break;                             //"UPC-E"
            ////case 2: type = BarcodeLib.TYPE.UPC_SUPPLEMENTAL_2DIGIT; break;          //"UPC 2 Digit Ext."
            ////case 3: type = BarcodeLib.TYPE.UPC_SUPPLEMENTAL_5DIGIT; break;          //"UPC 5 Digit Ext".
            ////case 4: type = BarcodeLib.TYPE.EAN13; break;                            //"EAN-13"
            ////case 5: type = BarcodeLib.TYPE.JAN13; break;                            //"JAN-13"
            ////case 6: type = BarcodeLib.TYPE.EAN8; break;                             //"EAN-8"
            ////case 7: type = BarcodeLib.TYPE.ITF14; break;                            //"ITF-14"
            //case 0: type = BarcodeLib.TYPE.Interleaved2of5; break;                  //"Interleaved 2 of 5"
            //case 1: type = BarcodeLib.TYPE.Standard2of5; break;                     //"Standard 2 of 5"
            ////case 10: type = BarcodeLib.TYPE.Codabar; break;                          //"Codabar"
            ////case 11: type = BarcodeLib.TYPE.PostNet; break;                          //"PostNet"
            //case 2: type = BarcodeLib.TYPE.BOOKLAND; break;                        //"Bookland/ISBN"
            //case 3: type = BarcodeLib.TYPE.CODE11; break;                          //"Code 11"
            case 0: type = BarcodeLib.TYPE.CODE39; break;                              //"Code 39"

            //case 5: type = BarcodeLib.TYPE.CODE39Extended; break;                  //"Code 39 Extended"
            //case 6: type = BarcodeLib.TYPE.CODE39_Mod43; break;                    //"Code 39 Mod 43"
            //case 7: type = BarcodeLib.TYPE.CODE93; break;                          //"Code 93"
            case 1: type = BarcodeLib.TYPE.CODE128; break;                             //"Code 128"

            //case 9: type = BarcodeLib.TYPE.CODE128A; break;                        //"Code 128-A"
            //case 10: type = BarcodeLib.TYPE.CODE128B; break;                        //"Code 128-B"
            //case 11: type = BarcodeLib.TYPE.CODE128C; break;                        //"Code 128-C"
            //case 12: type = BarcodeLib.TYPE.LOGMARS; break;                         //"LOGMARS"
            //case 13: type = BarcodeLib.TYPE.MSI_Mod10; break;                       //"MSI"
            //case 14: type = BarcodeLib.TYPE.TELEPEN; break;                         //"Telepen"
            ////case 25: type = BarcodeLib.TYPE.FIM; break;                             //"FIM"
            ////case 26: type = BarcodeLib.TYPE.PHARMACODE; break;                      //"Pharmacode"
            default: type = BarcodeLib.TYPE.CODE128; break;                             //"Code 128"
            }//switch

            try
            {
                if (type != BarcodeLib.TYPE.UNSPECIFIED)
                {
                    b.IncludeLabel = true;

                    b.RotateFlipType = rotateFlipType;
                    b.LabelPosition  = labelPosition;
                    if (barcode == null)
                    {
                        barcode = new System.Windows.Forms.GroupBox();
                        //
                        // barcode
                        //
                        barcode.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
                        barcode.Dock     = System.Windows.Forms.DockStyle.Fill;
                        barcode.Location = new System.Drawing.Point(0, 0);
                        barcode.Margin   = new System.Windows.Forms.Padding(4, 4, 4, 4);
                        barcode.Name     = "barcode";
                        barcode.Padding  = new System.Windows.Forms.Padding(4, 4, 4, 4);
                        barcode.Size     = new System.Drawing.Size(754, 414);
                        barcode.TabIndex = 36;
                        barcode.TabStop  = false;
                        barcode.Text     = "Barcode Image";
                        barcode.Visible  = false;
                    }

                    //===== Encoding performed here =====
                    barcode.BackgroundImage = b.Encode(type, stringToEncode, System.Drawing.Color.Black, System.Drawing.Color.White, width, height);
                    //===================================
                    //reposition the barcode image to the middle
                    barcode.Location = new System.Drawing.Point((barcode.Location.X + barcode.Width / 2) - barcode.Width / 2, (barcode.Location.Y + barcode.Height / 2) - barcode.Height / 2);

                    if (!string.IsNullOrEmpty(imagePathAndName))
                    {
                        b.SaveImage(imagePathAndName, saveType);
                    }
                } //if
            }     //try
            catch (Exception ex)
            {
                errorMessage = ex.Message;
                return(false);
            }//catch

            return(true);
        }
Exemplo n.º 4
0
        }//Form1_Load

        private void btnEncode_Click(object sender, EventArgs e)
        {
            //errorProvider1.Clear();》
            int W = Convert.ToInt32(this.txtWidth.Text.Trim());
            int H = Convert.ToInt32(this.txtHeight.Text.Trim());
            BarcodeLib.AlignmentPositions Align = BarcodeLib.AlignmentPositions.CENTER;

            //barcode alignment
            switch (cbBarcodeAlign.SelectedItem.ToString().Trim().ToLower())
            {
                case "left": Align = BarcodeLib.AlignmentPositions.LEFT; break;
                case "right": Align = BarcodeLib.AlignmentPositions.RIGHT; break;
                default: Align = BarcodeLib.AlignmentPositions.CENTER; break;
            }//switch

            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 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;
                default: MessageBox.Show("请选择一个编码类型"); break;
                //default: MessageBox.Show("Please specify the encoding type."); break;
            }//switch

            try
            {
                if (type != BarcodeLib.TYPE.UNSPECIFIED)
                {
                    b.IncludeLabel = this.chkGenerateLabel.Checked;

                    b.Alignment = Align;
                    b.RotateFlipType = (RotateFlipType)Enum.Parse(typeof(RotateFlipType), this.cbRotateFlip.SelectedItem.ToString(), true);

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

                    //===== Encoding performed here =====
                    barcode.Image = b.Encode(type, this.txtData.Text.Trim(), this.btnForeColor.BackColor, this.btnBackColor.BackColor, W, H);
                    //===================================

                    //show the encoding time
                    this.lblEncodingTime.Text = "(" + Math.Round(b.EncodingTime, 0, MidpointRounding.AwayFromZero).ToString() + "ms)";
                    
                    txtEncoded.Text = b.EncodedValue;

                    tsslEncodedType.Text = "编码类型: " + b.EncodedType.ToString();
                    //tsslEncodedType.Text = "Encoding Type: " + b.EncodedType.ToString();
                }//if

                barcode.Width = barcode.Image.Width;
                barcode.Height = barcode.Image.Height;
                
                //reposition the barcode image to the middle
                barcode.Location = new Point((this.groupBox2.Location.X + this.groupBox2.Width / 2) - barcode.Width / 2, (this.groupBox2.Location.Y + this.groupBox2.Height / 2) - barcode.Height / 2);
            }//try
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }//catch
        }//btnEncode_Click