首先創建水晶報表rpt文件方法還是采用xsd數據集的方式簡便容易操作記得將數據集中的相關字段設為你想要在報表中呈現的字段比如說在內容左邊加入一個圖片就將相應的圖片字段拖放過去能不能直接在水晶報表上添加一個圖片然後修改?我做了幾次實驗好像都不得要領所以還是放棄走最老式的方式先在數據庫中創建一個准備在水晶報表中使用到的字段的表然後再通過這張表創建數據集xsd文件再通過數據集創建水晶報表雖然方法繞了路但是絕對是可行的
通過數據集創建dataset
DataSetpictureTabDataTable pt = new DataSetpictureTabDataTable();
DataSetTableAdapterspictureTabTableAdapter da =
new DataSetTableAdapterspictureTabTableAdapter();
daFill(pt);
CrystalReport cr = new CrystalReport();
crSetDataSource((DataTable)pt);
thiscrystalReportViewerReportSource = 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();
daFill(ds NewTable);
CrystalDecisionsCrystalReportsEngineReportDocument doc = new CrystalDecisionsCrystalReportsEngineReportDocument();
docLoad(@C:\Documents and Settings\jiez\桌面\CrystalReportsApplication\CrystalReportsApplication\CrystalReportrpt);
docSetDataSource(dsTables[NewTable]);
thiscrystalReportViewerReportSource = doc;
這個其實也沒什麼好說的只是修改了一下報表加載的方式而已
厲害的來了本地圖片加載
DataSet ds = new DataSet();
dsTablesAdd(NewTable);
dsTables[]ColumnsAdd(id TypeGetType(SystemInt));
dsTables[]ColumnsAdd(picture TypeGetType(SystemByte[]));
dsTables[]ColumnsAdd(name TypeGetType(SystemString));
string picPath = @C:\Documents and Settings\jiez\My Documents\My Pictures\logojpg;
AddOneRow(dsTables[NewTable] picPath Jackey);
CrystalDecisionsCrystalReportsEngineReportDocument doc = new CrystalDecisionsCrystalReportsEngineReportDocument();
docLoad(@C:\Documents and Settings\jiez\桌面\CrystalReportsApplication\CrystalReportsApplication\CrystalReportrpt);
docSetDataSource(dsTables[NewTable]);
thiscrystalReportViewerReportSource = doc;
public void AddOneRow(DataTable tbl string c string c string c)
{
FileStream fs = new FileStream(c FileModeOpen);
BinaryReader br = new BinaryReader(fs);
DataRow row = tblNewRow();
row[] = c;
row[] = c;
row[] = brReadBytes((int)brBaseStreamLength);
tblRowsAdd(row);
}
這裡自己創建了一個dataset並且往裡面添加了數據都是自己進行設定這樣靈活性就很高了要注意的是這裡的數據讀取采用的是BinaryReader直接就用二進制的方式進行了讀取
是可以實現的
注釋:AddOneRow 函數中並沒有關閉數據流 fsClose();fsClose();
public void AddOneRow(DataTable tbl string c string c string c)
{
FileStream fs = new FileStream(c FileModeOpen);
FileStream fs = new FileStream(c FileModeOpen);
BinaryReader br = new BinaryReader(fs);
BinaryReader br = new BinaryReader(fs);
DataRow row = tblNewRow();
row[] = brReadBytes((int)brBaseStreamLength);
row[] = brReadBytes((int)brBaseStreamLength);
tblRowsAdd(row);
fsClose();
fsClose();
}
protected void Page_Load(object sender EventArgs e)
{
//sql
SqlConnection conn = new SqlConnection(PublicVarstrCon_SHATDB);
SqlDataAdapter da = new SqlDataAdapter(select * from stamp conn);
DataSet ds = new DataSet();
daFill(ds NewTable);
//存儲過程取得ds
SqlParameter[] parms = new SqlParameter[];
parms[] = new SqlParameter(@id SqlDbTypeInt);
parms[]Value = ; //部門
DataSet ds = new DataSet();
ds = DataAccessDataAccessSHDBGetTableByStore(test parms)DataSet;
//DataSet ds = new DataSet();
string picPath = @C:\test\jpg;
string picPath = @C:\test\jpg;
AddOneRow(dsTables[] picPath picPath);
CrystalDecisionsCrystalReportsEngineReportDocument doc = new CrystalDecisionsCrystalReportsEngineReportDocument();
docLoad(@C:\test\rpt);//報表已經設置簽名的image字段
docSetDataSource(dsTables[]);
CrystalReportViewerReportSource = doc;
CrystalReportViewerDataBind();
}
後來我根據思路重構了一下
報表的dataset中設置需要簽名的字段一定要是IMAGE 路徑保存在數據中
public void AddOneRow(DataTable tbl string c string c string c string c string cstring cstring c)
{
//FileStream fs = new FileStream(c FileModeOpen);
//FileStream fs = new FileStream(c FileModeOpen);
//BinaryReader br = new BinaryReader(fs);
//BinaryReader br = new BinaryReader(fs);
//DataRow row = tblNewRow();
//row[] = c;
//row[] = brReadBytes((int)brBaseStreamLength);
//row[] = brReadBytes((int)brBaseStreamLength);
//fsClose();
//fsClose();
//tblRowsAdd(row);
for (int i = ; i < tblRowsCount; i++) //如果在頭部那麼第一行就夠了 如果在尾部最後一行就OK 如果在Group 中就必須所有行
{
FileStream fs = new FileStream(c FileModeOpen);
FileStream fs = new FileStream(c FileModeOpen);
FileStream fs = new FileStream(c FileModeOpen);
FileStream fs = new FileStream(c FileModeOpen);
FileStream fs = new FileStream(c FileModeOpen);
FileStream fs = new FileStream(c FileModeOpen);
FileStream fs = new FileStream(c FileModeOpen);
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);
tblRows[i][] = brReadBytes((int)brBaseStreamLength);
tblRows[i][] = brReadBytes((int)brBaseStreamLength);
tblRows[i][] = brReadBytes((int)brBaseStreamLength);
tblRows[i][] = brReadBytes((int)brBaseStreamLength);
tblRows[i][] = brReadBytes((int)brBaseStreamLength);
tblRows[i][] = brReadBytes((int)brBaseStreamLength);
tblRows[i][] = brReadBytes((int)brBaseStreamLength);
fsClose();
fsClose();
fsClose();
fsClose();
fsClose();
fsClose();
fsClose();
//tblRowsAdd(row);
}
}
private void CrystalReportDataBind(int id)
{
SqlParameter[] parms = new SqlParameter[];
parms[] = new SqlParameter(@id SqlDbTypeInt);
parms[]Value = id; //部門
DataSet ds = new DataSet();
ds = DataAccessDataAccessSHDBGetTableByStore(project parms)DataSet;
//以下部分是讀取本地圖片
string strURL =select ustamp_path from taskline tl left join users u on tlUserID=u[ID] where taskcode=+lbl_taskcodeText+ and TurnTo= AND Result=Y ;
string[] picPath=new string[];
for(int i=;i<=;i++)
{
if (stringIsNullOrEmpty(PublicFunctionStringGetValue(strURL + and taskline= + (i + ) )) == false) //取得已經審批人的本地簽名地址
{
//picPath[i] = @ + PublicFunctionStringGetValue(strURL + and taskline= + (i + ) );
//string urlPath = ServerMapPath(\\Reports\\+PublicFunctionStringGetValue(strURL + and taskline= + (i + ) ));//無法動態解析服務器地址
picPath[i] = PublicFunctionStringGetValue(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(dsTables[] picPath[] picPath[] picPath[] picPath[] picPath[] picPath[] picPath[]);
CrystalDecisionsCrystalReportsEngineReportDocument doc = new CrystalDecisionsCrystalReportsEngineReportDocument();
string reportPath = ServerMapPath(\\Reports\\projectrpt);
//docLoad(@C:\test\rpt);
docLoad(reportPath);
docSetDataSource(dsTables[]);
CrystalReportViewerReportSource = doc;
CrystalReportViewerDataBind();
}
From:http://tw.wingwit.com/Article/program/net/201311/12882.html