rdlc报表 打印图片功能如何实现
2016-08-25 19:55
531 查看
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();//处理呈现当前报表
}
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();//处理呈现当前报表
}
相关文章推荐
- RDLC报表实现二维码打印功能
- jsp如何实现报表打印功能?简单点,不要太复杂的。在此先谢谢各位大虾。。。
- 如何让Web应用程序在Client端实现导出报表功能
- 如何让Web应用程序在Client端实现导出报表功能
- 实例讲解Android中如何实现图片的异步加载功能
- 在vs2005中的ReportViewer(RDLC报表)中使用直接打印功能,在vs2005使用ReportViewer2008
- VS 2005 RDLC报表实现WEB客户端打印(1)
- 如何用润乾报表实现进度条功能
- 实现SWT打印表格与图片功能(ZT)
- Crystal Report 水晶报表如何实现类似表格单元格合并的功能
- 在vs2005中的ReportViewer(RDLC报表)中使用直接打印功能,在vs2005使用ReportViewer2008
- Crystal Report 水晶报表如何实现类似表格单元格合并的功能
- J2EE 0.7.1—报表功能。传入封装数据的list实现打印标签报表。。
- 如何在JPG或BMP图片上显示输入的订单数据内容,并在报表打印时显示出来,后台数据库是SQL SERVER 2000 ,先谢了.高分!
- ASP.NET水晶报表实现打印功能
- VS 2005 RDLC报表实现WEB客户端打印(3)
- 老大要求把Word文档加上公司的标识,公司名文字或者logo图片都可以,但要求是用电脑打开(电子文档时)能看见标识,如果打印出来(纸质文档)就不显示出来,如何实现?
- 新版本浏览器中如何实现图片预览功能
- 在vs2005中的ReportViewer(RDLC报表)中使用直接打印功能,在vs2005使用ReportViewer2008[转]
- 如何在ASPNET2.0中实现打印功能