SSRS report 插入条形码

 

                              EMEX  BarcodeProcess

首先项目需求是:把一个条形码导入到一个SSRS report里面。有两种方法:一: 运用别人封装好的dll文件。二:自己创建dll文件。

一: 运用别人封装好的dll文件。

http://www.barcoderesource.com/reportingServicesBarcode.shtml

这个链接很详细的介绍了应用别人封装好的dll文件,大家可以按照步骤进行操作。 和对VS以及SQlServer配置文件的配置。当你打开这个连接的时候。要注意在向SSRS Report导入代码的时候。

在report的Customer code里面进行书写的时候代码如下:

                       

红框框里面的’代表是注释的意思。 所以如果要使那段代码起到作用,可以delete这个符号。

二:自己创建dll文件。

代码如下:

注意:

1.在写dll文件的时候,应该在本project的properties目录下的

AssemblyInfo.cs: 里面加上[assembly:AllowPartialyTrustedCallers]

2.  所有的dll文件都要和本项目下bin文件里面的dll文件相同。

 

 

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace Paabo.WordProcessing.Common
{
    public class BarCodeProvider
    {
        #region 单例
        private static BarCodeProvider _Intance;
        public static BarCodeProvider Intance
        {
            get
            {
                if (_Intance == null)
                {
                    _Intance = new BarCodeProvider();
                }
                return _Intance;
            }
        }
        #endregion

        #region Size
        /// <summary>
        /// 图片宽度
        /// </summary>
        private int _Width = 200;
        public int Width
        {
            get { return _Width; }
            set { _Width = value; }
        }


        /// <summary>
        /// 图片高度
        /// </summary>
        private int _Height = 80;
        public int Height 
        {
            get { return _Height; }
            set { _Height = value; }
        }

        /// <summary>
        /// 明文高度
        /// </summary>
        private int _TextHeight = 25;
        public int TextHeight
        {
            get { return _TextHeight; }
            set { _TextHeight = value; }
        }

        #endregion

        #region 边距
        private int _Margin_Top = 5;

        /// <summary>
        /// 上边距
        /// </summary>
        public int Margin_Top
        {
            get { return _Margin_Top; }
            set { _Margin_Top = value; }
        }

        private int _Margin_Left = 5;

        /// <summary>
        /// 左边距
        /// </summary>
        public int Margin_Left
        {
            get { return _Margin_Left; }
            set { _Margin_Left = value; }
        }


        private int _Margin_Right = 5;

        /// <summary>
        /// 右边距
        /// </summary>
        public int Margin_Right
        {
            get { return _Margin_Right; }
            set { _Margin_Right = value; }
        }

        private int _Margin_Bottom = 5;
        /// <summary>
        /// 下边距
        /// </summary>
        public int Margin_Bottom
        {
            get { return _Margin_Bottom; }
            set { _Margin_Bottom = value; }
        }
        #endregion

        private Font _TextFont = new Font("宋体", 12);

        /// <summary>
        /// 明文字体
        /// </summary>
        public Font TextFont
        {
            get { return _TextFont; }
            set { _TextFont = value; }
        }

        private Pen _BlackPen = new Pen(Brushes.Black);
        private Pen _WhitePen = new Pen(Brushes.White);

        /// <summary>
        /// 将明文装换为编码
        /// </summary>
        /// <param name="text">明文内容</param>
        /// <returns>编码</returns>
        private string ConvertToBarCode(string text)
        {
            string code = string.Empty;
            foreach (char item in text)
            {
                int itemValue = item;
                code += Convert.ToString(itemValue, 2) + ",";
            }
            return code;
        }

        /// <summary>
        /// 将字符串生成条形图片
        /// </summary>
        /// <param name="text">明文内容</param>
        /// <returns></returns>
        public Bitmap CreateBarCodeImage(string text)
        {
            Bitmap map = new Bitmap(Width, Height);
            Graphics g = Graphics.FromImage(map);
            try
            {
                string code = ConvertToBarCode(text);
                code = string.Format("101{0}101", code);
                char[] array = code.ToCharArray();
                char[] textArray = text.ToCharArray();
                int lineWidth = (Width - Margin_Left-Margin_Right) / (array.Length - textArray.Length);
                int lineHeight = Height - TextHeight - Margin_Bottom;

                _BlackPen.Width = lineWidth;
                _WhitePen.Width = lineWidth;

                int x = 5;
                int topY = 5;
                int bottonY = Height - Margin_Bottom - TextHeight;

                int index = 0;
                char pItem = ' ';
                Pen pen = null;
                foreach (char item in array)
                {

                    if (item == ',')
                    {
                        string t = textArray[index].ToString();
                        g.DrawString(t, TextFont, Brushes.Black, new PointF(x - (lineWidth * 5), bottonY + 3));
                        index++;
                    }
                    else
                    {
                        if (pItem == ' ')
                        {
                            pen = _BlackPen;
                        }
                        else
                        {
                            if (item != pItem)
                            {
                                pen = pen == _BlackPen ? _WhitePen : _BlackPen;
                            }
                        }
                        pItem = item;
                        g.DrawLine(pen, new Point(x, topY), new Point(x, bottonY));
                    }
                    x += lineWidth;
                }
            }
            catch (Exception ex)
            {
                g.Clear(Color.White);
                g.DrawString(ex.Message, TextFont, Brushes.Black, new PointF(0, 0));
            }
            g.Save();
            return map;
        }
    }
}

但是要注意自己生成的dll文件和被人封装好的dll文件,在导入SSRS reoport的时候,操作是一样的。 都需要根据SQL和VS的版本不同的URL下面去配置文件。

 

 

转载于:https://www.cnblogs.com/xuelan/p/SSRS.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值