qq动态图片加载失败 水晶报表动态加载图片
水晶报表动态加载图片
首先创建水晶报表rpt文件 方法还是采用xsd数据集的方式 简便容易操作 记得将数据集中的相关字段设为你想要在报表中呈现的字段 比如说在内容左边加入一个图片 就将相应的图片字段拖放过去 能不能直接在水晶报表上添加一个图片然后修改?我做了几次实验 好像都不得要领 所以还是放弃 走最老式的方式 先在数据库中创建一个准备在水晶报表中使用到的字段的表 然后再通过这张表创建数据集xsd文件 再通过数据集创建水晶报表 虽然方法绕了路 但是绝对是可行的
通过数据集创建dataset
DataSet pictureTabDataTable pt = new DataSet pictureTabDataTable();
DataSet TableAdapters pictureTabTableAdapter da =
new DataSet TableAdapters pictureTabTableAdapter();
da Fill(pt);
CrystalReport cr = new CrystalReport ();
cr SetDataSource((DataTable)pt);
this crystalReportViewer ReportSource = cr;
表名叫做pictureTab 因此创建的数据集有表pictureTabDataTable类和适配器pictureTabTableAdapter 奇怪的是前面的命名空间 着实没有找到 不过无关要害
通过数据库创建Dataset
SqlConnection conn = new SqlConnection( Data Source=(Local);Initial Catalog=MyDB;User ID=sa;Password=yamato );
SqlDataAdapter da = new SqlDataAdapter( select * from pictureTab where name = e conn);
DataSet ds = new DataSet();
da Fill(ds NewTable );
CrystalDecisions CrystalReports Engine ReportDocument doc = new CrystalDecisions CrystalReports Engine ReportDocument();
doc Load(@ C:Documents and Settingsjiez桌面CrystalReportsApplication CrystalReportsApplication CrystalReport rpt );
doc SetDataSource(ds Tables[ NewTable ]);
this crystalReportViewer ReportSource = doc;
这个其实也没什么好说的 只是修改了一下报表加载的方式而已
厉害的来了 本地图片加载
DataSet ds = new DataSet();
ds Tables Add( NewTable );
ds Tables[ ] Columns Add( id Type GetType( System Int ));
ds Tables[ ] Columns Add( picture Type GetType( System Byte[] ));
ds Tables[ ] Columns Add( name Type GetType( System String ));
string picPath = @ C:Documents and SettingsjiezMy DocumentsMy Pictureslogo jpg ;
AddOneRow(ds Tables[ NewTable ] picPath Jackey );
CrystalDecisions CrystalReports Engine ReportDocument doc = new CrystalDecisions CrystalReports Engine ReportDocument();
doc Load(@ C:Documents and Settingsjiez桌面CrystalReportsApplication CrystalReportsApplication CrystalReport rpt );
doc SetDataSource(ds Tables[ NewTable ]);
this crystalReportViewer ReportSource = doc;
public void AddOneRow(DataTable tbl string c string c string c )
{
FileStream fs = new FileStream(c FileMode Open);
BinaryReader br = new BinaryReader(fs);
DataRow row = tbl NewRow();
row[ ] = c ;
row[ ] = c ;
row[ ] = br ReadBytes((int)br BaseStream Length);
tbl Rows Add(row);
}
这里自己创建了一个dataset 并且往里面添加了数据 都是自己进行设定 这样灵活性就很高了 要注意的是这里的数据读取采用的是BinaryReader直接就用二进制的方式进行了读取
是可以实现的
注释: AddOneRow 函数中并没有关闭数据流 fs Close();fs Close();
public void AddOneRow(DataTable tbl string c string c string c )
{
FileStream fs = new FileStream(c FileMode Open);
FileStream fs = new FileStream(c FileMode Open);
BinaryReader br = new BinaryReader(fs );
BinaryReader br = new BinaryReader(fs );
DataRow row = tbl NewRow();
row[ ] = br ReadBytes((int)br BaseStream Length);
row[ ] = br ReadBytes((int)br BaseStream Length);
tbl Rows Add(row);
fs Close();
fs Close();
}
protected void Page_Load(object sender EventArgs e)
{
//sql
SqlConnection conn = new SqlConnection(PublicVar strCon_SHATDB);
SqlDataAdapter da = new SqlDataAdapter( select * from stamp conn);
DataSet ds = new DataSet();
da Fill(ds NewTable );
//存储过程取得ds
SqlParameter[] parms = new SqlParameter[ ];
parms[ ] = new SqlParameter( @id SqlDbType Int);
parms[ ] Value = ; //部门
DataSet ds = new DataSet();
ds = DataAccess DataAccessSHDB GetTableByStore( test parms) DataSet;
//DataSet ds = new DataSet();
string picPath = @ C:test jpg ;
string picPath = @ C:test jpg ;
AddOneRow(ds Tables[ ] picPath picPath );
CrystalDecisions CrystalReports Engine ReportDocument doc = new CrystalDecisions CrystalReports Engine ReportDocument();
doc Load(@ C:test rpt );//报表已经设置签名的image字段
doc SetDataSource(ds Tables[ ]);
CrystalReportViewer ReportSource = doc;
CrystalReportViewer DataBind();
}
后来我根据思路重构了一下
报表的dataset中设置需要签名的字段一定要是IMAGE 路径保存在数据中
public void AddOneRow(DataTable tbl string c string c string c string c string c string c string c )
{
//FileStream fs = new FileStream(c FileMode Open);
//FileStream fs = new FileStream(c FileMode Open);
//BinaryReader br = new BinaryReader(fs );
//BinaryReader br = new BinaryReader(fs );
//DataRow row = tbl NewRow();
//row[ ] = c ;
//row[ ] = br ReadBytes((int)br BaseStream Length);
//row[ ] = br ReadBytes((int)br BaseStream Length);
//fs Close();
//fs Close();
//tbl Rows Add(row);
for (int i = ; i < tbl Rows Count; i++) //如果在头部那么第一行就够了 如果在尾部最后一行就OK 如果在Group 中就必须所有行
{
FileStream fs = new FileStream(c FileMode Open);
FileStream fs = new FileStream(c FileMode Open);
FileStream fs = new FileStream(c FileMode Open);
FileStream fs = new FileStream(c FileMode Open);
FileStream fs = new FileStream(c FileMode Open);
FileStream fs = new FileStream(c FileMode Open);
FileStream fs = new FileStream(c FileMode Open);
BinaryReader br = new BinaryReader(fs );
BinaryReader br = new BinaryReader(fs );
BinaryReader br = new BinaryReader(fs );
BinaryReader br = new BinaryReader(fs );
BinaryReader br = new BinaryReader(fs );
BinaryReader br = new BinaryReader(fs );
BinaryReader br = new BinaryReader(fs );
tbl Rows[i][ ] = br ReadBytes((int)br BaseStream Length);

tbl Rows[i][ ] = br ReadBytes((int)br BaseStream Length);
tbl Rows[i][ ] = br ReadBytes((int)br BaseStream Length);
tbl Rows[i][ ] = br ReadBytes((int)br BaseStream Length);
tbl Rows[i][ ] = br ReadBytes((int)br BaseStream Length);
tbl Rows[i][ ] = br ReadBytes((int)br BaseStream Length);
tbl Rows[i][ ] = br ReadBytes((int)br BaseStream Length);
fs Close();
fs Close();
fs Close();
fs Close();
fs Close();
fs Close();
fs Close();
//tbl Rows Add(row);
}
}
private void CrystalReportDataBind(int id)
{
SqlParameter[] parms = new SqlParameter[ ];
parms[ ] = new SqlParameter( @id SqlDbType Int);
parms[ ] Value = id; //部门
DataSet ds = new DataSet();
ds = DataAccess DataAccessSHDB GetTableByStore( project parms) DataSet;
//以下部分是读取本地图片
string strURL = select u stamp_path from taskline tl left join users u on tl UserID=u [ID] where taskcode= +lbl_taskcode Text+ and TurnTo= AND Result= Y ;
string[] picPath=new string[ ];
for(int i= ;i<= ;i++)
{
if (string IsNullOrEmpty(PublicFunction StringGetValue(strURL + and taskline= + (i + ) )) == false) //取得已经审批人的本地签名地址
{
//picPath[i] = @ + PublicFunction StringGetValue(strURL + and taskline= + (i + ) );
//string urlPath = Server MapPath( \Reports\ +PublicFunction StringGetValue(strURL + and taskline= + (i + ) ));//无法动态解析服务器地址
picPath[i] = PublicFunction StringGetValue(strURL + and taskline= + (i + ) ); //保存本地地址
}
else
{
switch (i)
{
case :
picPath[i] = @ C:stamp空白 jpg ; //空白地址页面 防止进程同时被占用
break;
case :
picPath[i] = @ C:stamp空白 jpg ;
break;
case :
picPath[i] = @ C:stamp空白 jpg ;
break;
case :
picPath[i] = @ C:stamp空白 jpg ;
break;
case :
picPath[i] = @ C:stamp空白 jpg ;
break;
case :
picPath[i] = @ C:stamp空白 jpg ;
break;
case :
picPath[i] = @ C:stamp空白 jpg ;
break;
}
}
}
//string picPath = @ C:test jpg ;
//string picPath = @ C:test jpg ;
AddOneRow(ds Tables[ ] picPath[ ] picPath[ ] picPath[ ] picPath[ ] picPath[ ] picPath[ ] picPath[ ]);
CrystalDecisions CrystalReports Engine ReportDocument doc = new CrystalDecisions CrystalReports Engine ReportDocument();
string reportPath = Server MapPath( \Reports\project rpt );
//doc Load(@ C:test rpt );
doc Load(reportPath);
doc SetDataSource(ds Tables[ ]);
CrystalReportViewer ReportSource = doc;
CrystalReportViewer DataBind();
lishixinzhi/Article/program/net/201311/12882