Robertonio
asked on
Load a picture in runtime
Hello everybody!!
First, is it possible to load a picture on runtime using de RDC version from vb.net? what a have to do is to load diferent pictures from their paths information. I also have to change some labels' caption when the report is loading. Is it possible to do it using RDC or do I need to change to other different version of Crystal Repots?
Could anyone tell me how to develop this?
thanx.
First, is it possible to load a picture on runtime using de RDC version from vb.net? what a have to do is to load diferent pictures from their paths information. I also have to change some labels' caption when the report is loading. Is it possible to do it using RDC or do I need to change to other different version of Crystal Repots?
Could anyone tell me how to develop this?
thanx.
This is how I do it. Hopefully it helps. If you need explanation, let me know
Regards
Emre
private void DynamicImages()
{
DataSet MyDataSet = new DataSet();
DataTable MyDataTable;
DataRow MyDataRow;
MyDataTable = new DataTable();
DataColumn MyDataColumn = new DataColumn();
//Create the first column
MyDataColumn = new DataColumn("PicNumber", Type.GetType("System.Int32 "));
MyDataTable.Columns.Add(My DataColumn );
//Field that points to the image file
MyDataColumn = new DataColumn("ImagePath", Type.GetType("System.Strin g"));
MyDataTable.Columns.Add(My DataColumn );
//populate the table with dummy data
MyDataRow = MyDataTable.NewRow();
MyDataRow["PicNumber"] = 1;
MyDataRow["ImagePath"] = "C:\\Image1.jpg";
MyDataTable.Rows.Add(MyDat aRow);
MyDataSet.Tables.Add(MyDat aTable);
//Add the image column to the table
AddImageColumn(MyDataTable , "Image");
//only do this when you first design the report
MyDataSet.WriteXmlSchema(@ "c:\ImageT able.xsd") ;
//Load the images into the dataset
LoadAllImages(MyDataTable, "ImagePath", "Image");
}
public void AddImageColumn(DataTable MyDataTable, string FieldName)
{
//create the column to hold the binary image
DataColumn MyDataColumn = new DataColumn(FieldName,Type. GetType("S ystem.Byte []"));
MyDataTable.Columns.Add(My DataColumn );
}
public void LoadAllImages(DataTable MyDataTable,string FilePathField, string ImageField)
{
foreach(DataRow MyDataRow in MyDataTable.Rows )
{
LoadImage(MyDataRow, ImageField, MyDataRow[FilePathField].T oString()) ;
}
}
public void LoadImage(DataRow MyDataRow, string ImageField, string FilePath)
{
FilePath = "c:\\Image1.jpg";
System.IO.FileStream fs = new System.IO.FileStream(FileP ath, System.IO.FileMode.Open,Sy stem.IO.Fi leAccess.R ead);
Byte[] Image = new Byte[fs.Length];
fs.Read(Image, 0, (int)fs.Length);
fs.Close();
MyDataRow[ImageField] = Image;
}
public void CreateXMLSchemaFile(string XMLFileName, DataSet XMLDataSet)
{
XMLDataSet.WriteXmlSchema( "ImageData Schema") ;
}
public DataSet FillDataSet(DataSet MyDataSet)
{
SqlConnection MyConnectionString = new SqlConnection("server=OMEG A_DEV;data base=omega _test;UID= OmegaWeb;P WD=JascPSP 6;");
string SQL;
SQL = "uspReportData";
//Create a DataAdapter, and then provide the name of the stored procedure.
SqlDataAdapter MyDataAdapter = new SqlDataAdapter(SQL, MyConnectionString);
//Set the command type as StoredProcedure.
MyDataAdapter.SelectComman d.CommandT ype = CommandType.StoredProcedur e;
//Create and add a parameter to Parameters collection for the stored procedure.
MyDataAdapter.SelectComman d.Paramete rs.Add(new SqlParameter("@CaseID", SqlDbType.VarChar, 25));
MyDataAdapter.SelectComman d.Paramete rs.Add(new SqlParameter("@line_number ", SqlDbType.Int));
MyDataAdapter.SelectComman d.Paramete rs.Add(new SqlParameter("@company_id" , SqlDbType.VarChar, 4));
//Assign the search value to the parameter.
MyDataAdapter.SelectComman d.Paramete rs["@CaseI D"].Value = _parametervalues[0];
MyDataAdapter.SelectComman d.Paramete rs["@line_ number"].V alue = _parametervalues[1];
MyDataAdapter.SelectComman d.Paramete rs["@compa ny_id"].Va lue = _parametervalues[2];
MyDataAdapter.Fill(MyDataS et.Tables[ "uspReport Data"]);
return MyDataSet;
}
private bool HasParameter(CrystalDecisi ons.Crysta lReports.E ngine.Repo rtDocument MyReport)
{
if (MyReport.DataDefinition.P arameterFi elds.Count == 0)
{
_HasParameters = false;
return _HasParameters;
}
else
{
_HasParameters = true;
return _HasParameters;
}
}
Regards
Emre
private void DynamicImages()
{
DataSet MyDataSet = new DataSet();
DataTable MyDataTable;
DataRow MyDataRow;
MyDataTable = new DataTable();
DataColumn MyDataColumn = new DataColumn();
//Create the first column
MyDataColumn = new DataColumn("PicNumber", Type.GetType("System.Int32
MyDataTable.Columns.Add(My
//Field that points to the image file
MyDataColumn = new DataColumn("ImagePath", Type.GetType("System.Strin
MyDataTable.Columns.Add(My
//populate the table with dummy data
MyDataRow = MyDataTable.NewRow();
MyDataRow["PicNumber"] = 1;
MyDataRow["ImagePath"] = "C:\\Image1.jpg";
MyDataTable.Rows.Add(MyDat
MyDataSet.Tables.Add(MyDat
//Add the image column to the table
AddImageColumn(MyDataTable
//only do this when you first design the report
MyDataSet.WriteXmlSchema(@
//Load the images into the dataset
LoadAllImages(MyDataTable,
}
public void AddImageColumn(DataTable MyDataTable, string FieldName)
{
//create the column to hold the binary image
DataColumn MyDataColumn = new DataColumn(FieldName,Type.
MyDataTable.Columns.Add(My
}
public void LoadAllImages(DataTable MyDataTable,string FilePathField, string ImageField)
{
foreach(DataRow MyDataRow in MyDataTable.Rows )
{
LoadImage(MyDataRow, ImageField, MyDataRow[FilePathField].T
}
}
public void LoadImage(DataRow MyDataRow, string ImageField, string FilePath)
{
FilePath = "c:\\Image1.jpg";
System.IO.FileStream fs = new System.IO.FileStream(FileP
Byte[] Image = new Byte[fs.Length];
fs.Read(Image, 0, (int)fs.Length);
fs.Close();
MyDataRow[ImageField] = Image;
}
public void CreateXMLSchemaFile(string
{
XMLDataSet.WriteXmlSchema(
}
public DataSet FillDataSet(DataSet MyDataSet)
{
SqlConnection MyConnectionString = new SqlConnection("server=OMEG
string SQL;
SQL = "uspReportData";
//Create a DataAdapter, and then provide the name of the stored procedure.
SqlDataAdapter MyDataAdapter = new SqlDataAdapter(SQL, MyConnectionString);
//Set the command type as StoredProcedure.
MyDataAdapter.SelectComman
//Create and add a parameter to Parameters collection for the stored procedure.
MyDataAdapter.SelectComman
MyDataAdapter.SelectComman
MyDataAdapter.SelectComman
//Assign the search value to the parameter.
MyDataAdapter.SelectComman
MyDataAdapter.SelectComman
MyDataAdapter.SelectComman
MyDataAdapter.Fill(MyDataS
return MyDataSet;
}
private bool HasParameter(CrystalDecisi
{
if (MyReport.DataDefinition.P
{
_HasParameters = false;
return _HasParameters;
}
else
{
_HasParameters = true;
return _HasParameters;
}
}
ASKER
It seems to be useful, but, every crystal reports have objects witch I cannot access (with VB.net) in order to modify them and insert the text and pictures I need. Do you know how to do it using VB.NET, there are a loads of examples with VB6.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok. thanx I was making a mistake when passing this code to .net, thanx ebolex
ASKER
Ebolek the code you sent me works correctly
but? how can I insert a column (wich contains the path information) that i have already loaded into my data set instead using those rows and columns that you use in your example
when you create your dataset, you add extra columns like report path and file name etc. Then you ssave your report with that dataset as dtaasource. Then you use my code to set the values of thiose cloumns and populate the images
Hi,
Cool thread, another thing that it is great if you can help...
Can we resize of change some properties to make make image is the same aspect with it origin size. ie. currently the image is strected full control size. I can do it in VB6& CR by resize the controls in run-time, but for ASP.NET I don't know how to do now.
Thanks in advanced.
Buu.
Cool thread, another thing that it is great if you can help...
Can we resize of change some properties to make make image is the same aspect with it origin size. ie. currently the image is strected full control size. I can do it in VB6& CR by resize the controls in run-time, but for ASP.NET I don't know how to do now.
Thanks in advanced.
Buu.
i think you can there is image to respect ratio and that should solve your problem. I dont know exactly the code to write because i never tries it but if you can it should be under
reportdefinitions.pictureo bjects properties
Regards
Emre
reportdefinitions.pictureo
Regards
Emre
http://support.businessobjects.com/communityCS/FilesAndUpdates/cr9_vb_rdc_loadpic.exe.asp
This should help you with the text formattiing you require
http://support.businessobjects.com/communityCS/FilesAndUpdates/employeeprofiledemo.zip.asp
Gary