您的位置:首页 > 其它

水晶报表动态加载磁盘图片

2017-03-09 11:26 686 查看
1、首先,我们先创建一个DataSet.xsd文件,如下图所示,这是一个表



2、查看此表的代码,注意字段LIMG的数据类型为base64Binary。

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="DataSet8" targetNamespace="http://tempuri.org/DataSet8.xsd" xmlns:mstns="http://tempuri.org/DataSet8.xsd" xmlns="http://tempuri.org/DataSet8.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:msprop="urn:schemas-microsoft-com:xml-msprop" attributeFormDefault="qualified" elementFormDefault="qualified">
<xs:annotation>
<xs:appinfo source="urn:schemas-microsoft-com:xml-msdatasource">
<DataSource DefaultConnectionIndex="0" FunctionsComponentName="QueriesTableAdapter" Modifier="AutoLayout, AnsiClass, Class, Public" SchemaSerializationMode="IncludeSchema" xmlns="urn:schemas-microsoft-com:xml-msdatasource">
<Connections>
</Connections>
<Tables>
</Tables>
<Sources>
</Sources>
</DataSource>
</xs:appinfo>
</xs:annotation>
<xs:element name="DataSet8" msdata:IsDataSet="true" msdata:UseCurrentLocale="true" msprop:Generator_UserDSName="DataSet8" msprop:Generator_DataSetName="DataSet8">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="BoxLabelTable" msprop:Generator_UserTableName="BoxLabelTable" msprop:Generator_RowDeletedName="BoxLabelTableRowDeleted" msprop:Generator_RowChangedName="BoxLabelTableRowChanged" msprop:Generator_RowClassName="BoxLabelTableRow" msprop:Generator_RowChangingName="BoxLabelTableRowChanging" msprop:Generator_RowEvArgName="BoxLabelTableRowChangeEvent" msprop:Generator_RowEvHandlerName="BoxLabelTableRowChangeEventHandler" msprop:Generator_TableClassName="BoxLabelTableDataTable" msprop:Generator_TableVarName="tableBoxLabelTable" msprop:Generator_RowDeletingName="BoxLabelTableRowDeleting" msprop:Generator_TablePropName="BoxLabelTable">
<xs:complexType>
<xs:sequence>
<xs:element name="LIMG" msprop:Generator_UserColumnName="LIMG" msprop:Generator_ColumnPropNameInRow="LIMG" msprop:Generator_ColumnVarNameInTable="columnLIMG" msprop:Generator_ColumnPropNameInTable="LIMGColumn" type="xs:base64Binary" minOccurs="0" />
<xs:element name="SCIMG" msprop:Generator_UserColumnName="SCIMG" msprop:Generator_ColumnVarNameInTable="columnSCIMG" msprop:Generator_ColumnPropNameInRow="SCIMG" msprop:Generator_ColumnPropNameInTable="SCIMGColumn" type="xs:string" minOccurs="0" />
<xs:element name="PO" msprop:Generator_UserColumnName="PO" msprop:Generator_ColumnVarNameInTable="columnPO" msprop:Generator_ColumnPropNameInRow="PO" msprop:Generator_ColumnPropNameInTable="POColumn" type="xs:string" minOccurs="0" />
<xs:element name="ITEMNO" msprop:Generator_UserColumnName="ITEMNO" msprop:Generator_ColumnVarNameInTable="columnITEMNO" msprop:Generator_ColumnPropNameInRow="ITEMNO" msprop:Generator_ColumnPropNameInTable="ITEMNOColumn" type="xs:string" minOccurs="0" />
<xs:element name="QTY" msprop:Generator_UserColumnName="QTY" msprop:Generator_ColumnVarNameInTable="columnQTY" msprop:Generator_ColumnPropNameInRow="QTY" msprop:Generator_ColumnPropNameInTable="QTYColumn" type="xs:decimal" minOccurs="0" />
<xs:element name="NW" msprop:Generator_UserColumnName="NW" msprop:Generator_ColumnVarNameInTable="columnNW" msprop:Generator_ColumnPropNameInRow="NW" msprop:Generator_ColumnPropNameInTable="NWColumn" type="xs:decimal" minOccurs="0" />
<xs:element name="GW" msprop:Generator_UserColumnName="GW" msprop:Generator_ColumnVarNameInTable="columnGW" msprop:Generator_ColumnPropNameInRow="GW" msprop:Generator_ColumnPropNameInTable="GWColumn" type="xs:decimal" minOccurs="0" />
<xs:element name="MEAS" msprop:Generator_UserColumnName="MEAS" msprop:Generator_ColumnVarNameInTable="columnMEAS" msprop:Generator_ColumnPropNameInRow="MEAS" msprop:Generator_ColumnPropNameInTable="MEASColumn" type="xs:string" minOccurs="0" />
<xs:element name="CARTONNO" msprop:Generator_UserColumnName="CARTONNO" msprop:Generator_ColumnVarNameInTable="columnCARTONNO" msprop:Generator_ColumnPropNameInRow="CARTONNO" msprop:Generator_ColumnPropNameInTable="CARTONNOColumn" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>


3、填充DataSet.xsd数据,关键代码如下:注意本案例中的DataSet.xsd的文件名为DataSet8

DataSet8 ds8 = new DataSet8();
object[] objs ={ReadImages(), Request.QueryString["SCIMG"],Request.QueryString["PO"],Request.QueryString["ITEMNO"],
Request.QueryString["QTY"],Request.QueryString["NW"],Request.QueryString["GW"],Request.QueryString["MEAS"]};

ds8.Tables["BoxLabelTable"].Rows.Add(objs);//注意此名字必须是本例步骤1中DataSet的表名


4、读取磁盘中的图片

private byte[] ReadImages()
{
string[] dir = Directory.GetFiles(Server.MapPath(@"~/Upload/BoxLabel/"));
byte[] photo = null;
foreach (string img in dir)
{
string imgPath = Path.GetFileName(img);
if (imgPath.IndexOf(Request.QueryString["SCIMG"]) > -1)
{
FileStream fs = new FileStream(img, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
photo = br.ReadBytes((int)fs.Length);
br.Close();
fs.Close();
}
}
return photo;
}


5、我们转到水晶报表中的设置,如图所示:



6、大功告成,让我们看看显示的效果





注意:本报表使用的是CrystalReport10,即VS2005自带的水晶报表

本文参考:http://www.cnblogs.com/babyt/archive/2005/04/21/142789.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息