rdlc报表 打印图片功能如何实现

来源:互联网 发布:阿里云短信服务java 编辑:程序博客网 时间:2024/05/13 02:45

1. 首先你要在数据库建字段,当然是 image 类型。

  2.将图片以二进制的方式保存在 这个字段里面。

主要代码如下

FileStream fs = new FileStream(fileroute, FileMode.Open);//文件流
            int len = (int)fs.Length;//流长度
            byte[] fileData = new byte[len];
            fs.Read(fileData, 0, len);
            fs.Close();
            openfileinsertpicturebox(scinvcode, filename, fileData, "");//保存附件函数

private void openfileinsertpicturebox(string cinvCode, string filename, byte[] sfile, string remark)//往SQLserver 插入附件函数
        {
            //先删除,再插入
            string insql = "delete Apicturebox where cinvCode = @cinvCode " +
                         "insert into Apicturebox(cinvCode,filename,sfile,remark,date1) " +
                        "values(@cinvCode,@filename,@sfile,@remark,GETDATE())  " +
                        "update Ainventory set Define20=@filename where cinvCode= @cinvCode ";
            SqlConnection conn = new SqlConnection(command.Class1.cn);
            SqlCommand cmd = new SqlCommand(insql, conn);
            SqlParameter pm1 = new SqlParameter("@cinvCode", SqlDbType.VarChar, 100);
            SqlParameter pm2 = new SqlParameter("@filename", SqlDbType.VarChar, 300);
            SqlParameter pm3 = new SqlParameter("@sfile", SqlDbType.Image);
            SqlParameter pm4 = new SqlParameter("@remark", SqlDbType.VarChar, 300);
            pm1.Value = cinvCode;
            pm2.Value = filename;
            pm3.Value = sfile;
            pm4.Value = remark;
            cmd.Parameters.Add(pm1);
            cmd.Parameters.Add(pm2);
            cmd.Parameters.Add(pm3);
            cmd.Parameters.Add(pm4);
            conn.Open();
            cmd.ExecuteNonQuery();
            conn.Close();
        }

3. 在rdlc报表中 建一个字段 格式是 

 <Field Name="sfile">
          <DataField>sfile</DataField>
          <rd:TypeName>System.image</rd:TypeName>
        </Field>
      </Fields>

4.在rdlc报表上 先添加列表框 ,选好数据源,在列表框中  添加 图片控件,参数设置如下,关键是选择图像源 为数据库。

5.最后一步简单,跟普通打印一样

private void toolStripButton2_Click(object sender, EventArgs e)
        {
            string socode = bsocode.Text;//获取当前的销售订单号码
            //string sql1 = "select a.*,b.codestr,'"+command.Class1.company+"销售订单' as company from dsale a left join Dcustomer b on a.salea = b.codestr where a.socode = '" + socode + "'";
            string sql1 = "select a.*,b.str2 as str2,'" + command.Class1.company + "销售订单' as company,c.sfile from dsale a left join Dcustomer b on a.salea = b.codestr left join Dsalefile c on a.socode=c.socode where a.socode = '" + socode + "'";
            string sql2 = "select * from Dsaleson where socode = '" + socode + "'";
            string sql3 = "select a.cinvcode,a.strf from abasiccode a right join "+
                        "(select substring(sase,1,6) as yz from Dsaleson  where socode = '" + socode + "' group by substring(sase,1,6)) b " +
                        "on a.cinvcode = b.yz where a.cinvccode like 'D%' ";
            Dsalereport drp = new Dsalereport(sql1, sql2,sql3);
            drp.MdiParent = this.MdiParent;
            drp.Show();
        }

 private void Dsalereport_Load(object sender, EventArgs e)
        {


            this.reportViewer1.RefreshReport();
            DataSet ds = sdc.ads(sqlreport);//生产dataset
            //ds.Tables[0].Merge(ds.Tables[1]);//合并一下,但并不知道缘由      
            ReportDataSource rds1 = new ReportDataSource("Drdlc_Dsale", ds.Tables[0]);
            ReportDataSource rds2 = new ReportDataSource("Drdlc_Dsaleson", ds.Tables[1]);
            ReportDataSource rds3 = new ReportDataSource("Drdlc_abasiccode", ds.Tables[2]);
            reportViewer1.LocalReport.DataSources.Clear();
            reportViewer1.LocalReport.DataSources.Add(rds1);
            reportViewer1.LocalReport.DataSources.Add(rds2);
            reportViewer1.LocalReport.DataSources.Add(rds3);
            this.reportViewer1.RefreshReport();//处理呈现当前报表
        }



0 0
原创粉丝点击