水晶報表動態加載磁盤圖片

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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章