1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
if (this.Page.IsValid)
{
System.Data.OleDb.OleDbConnection oleDBcn = new System.Data.OleDb.OleDbConnection();
oleDBcn.ConnectionString = Session["ChaineConnexion"].ToString();
StatCommercial.rptDataSet1 MonDataSet = new StatCommercial.rptDataSet1();
System.Data.OleDb.OleDbParameter paramCmd1 = new OleDbParameter("@DateDeb", Convert.ToDateTime(this.txtDateDeb.Text + " 00:00:00"));
System.Data.OleDb.OleDbParameter paramCmd2 = new OleDbParameter("@DateFin", Convert.ToDateTime(this.txtDateFin.Text + " 23:59:59"));
string sRqy = " ... ici c'est ma requete sql";
System.Data.OleDb.OleDbDataAdapter myAdapter = new System.Data.OleDb.OleDbDataAdapter(sRqy, oleDBcn);
myAdapter.SelectCommand.Parameters.Add(paramCmd1);
myAdapter.SelectCommand.Parameters.Add(paramCmd2);
oleDBcn.Open();
myAdapter.Fill(MonDataSet.rqyRESULTAT);
oleDBcn.Close();
StatCommercial.rptClassementClient MonEtat = new rptClassementClient();
MonEtat.SetParameterValue("DateDeb",this.txtDateDeb.Text + " 00:00:00");
MonEtat.SetParameterValue("DateFin",this.txtDateFin.Text + " 23:59:59");
MonEtat.SetDataSource(MonDataSet);
// dans le code ci dessous plutot que de faire la liaison entre l'etat
// et le CrystalReportViewer, on procède directement à un export de l'etat en PDF.
//CRViewer.ReportSource = MonEtat;
CrystalDecisions.Shared.ExportOptions crExportOptions = new ExportOptions() ;
CrystalDecisions.Shared.DiskFileDestinationOptions crDiskFileDestinationOptions = new DiskFileDestinationOptions();
string Fname = "C:\\Inetpub\\wwwroot\\StatCommercial\\" + Session.SessionID.ToString() + ".pdf";
crDiskFileDestinationOptions.DiskFileName = Fname;
crExportOptions = MonEtat.ExportOptions;
crExportOptions.DestinationOptions = crDiskFileDestinationOptions;
crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
switch (this.DropDownList1.SelectedIndex)
{
case 0:
crExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
break;
case 1:
crExportOptions.ExportFormatType = ExportFormatType.WordForWindows;
break;
case 2:
crExportOptions.ExportFormatType = ExportFormatType.Excel;
break;
}
MonEtat.Export();
//Le code suivant permet d'écrire le fichier pdf dans le navigateur du client.
Response.ClearContent();
Response.ClearHeaders();
switch (this.DropDownList1.SelectedIndex)
{
case 0:
Response.ContentType = "application/pdf";
break;
case 1:
Response.ContentType = "application/msword";
break;
case 2:
Response.ContentType = "application/vnd.ms-excel";
break;
}
Response.WriteFile(Fname);
Response.Flush();
Response.Close();
//supprimer le fichier exporté du disque
System.IO.File.Delete(Fname);
// liberer le dataset
MonDataSet.Clear();
MonDataSet.Dispose();
} |
Partager