Crystalreport sous VB.net

jonardcy Messages postés 1 Date d'inscription mercredi 15 février 2006 Statut Membre Dernière intervention 20 février 2006 - 20 févr. 2006 à 10:58
gaa179 Messages postés 361 Date d'inscription mercredi 21 mai 2003 Statut Membre Dernière intervention 12 novembre 2009 - 20 févr. 2006 à 11:24
bonjour,
j'essaye de developper actuellement un code sous VB.net permettant la generation de rapports grace a crystal report.
tres peu de code sources sont disponibles et j'aimerais comprendre comment on peut initialiser les variables utilises sur le rapport grace au fichier code cristalreport.vb
et ainsi creer des tableaux et des rapports faisant des paragraphes automatiquement indexer 1.1 ; 1.1.1 ; 1.2 ; 1.2.1 ; 1.2.2 etc...

Merci pour votre aide

1 réponse

gaa179 Messages postés 361 Date d'inscription mercredi 21 mai 2003 Statut Membre Dernière intervention 12 novembre 2009 2
20 févr. 2006 à 11:24
Bonjour,

Si tu parles de passer les valeurs aux paramètres que tu as définis dans ton rapport, voici le code:
Tu dois ajouter la ligne suivante:

cr.SetParameterValue(0, 6) ou 0 est l'index de ton paramètre et 6 la valeur. Tu peux aussi donner le nom du paramètre plutôt que son indexe.



Public
Sub PrintFrm(
ByVal ReportFile
As
String,
ByRef WindowTitle
As
String,
Optional
ByRef RecordSelector
As
String = "",
Optional
ByRef PrintReport
As
Boolean =
False,
Optional
ByRef ReportHeader
As
Boolean =
False,
Optional
ByRef ExportEnable
As
Boolean =
False,
Optional
ByRef ReportLandscape
As
Boolean =
False)



Dim FrmPrint
As
New frmPrint



Dim cr
As
New ReportDocument



Dim crInfo
As SummaryInfo



On
Error
GoTo Err_Print


ReportFile = Application.StartupPath & "\report" & ReportFile & ".rpt"


cr.Load(ReportFile, CrystalDecisions.[Shared].OpenReportMethod.OpenReportByDefault)

crInfo = cr.SummaryInfo


cr.PrintOptions.PrinterName = PrinterA4


If ReportHeader
Then crInfo.ReportTitle = WindowTitle



'Sélection de l'imprimante



If ReportLandscape
Then cr.PrintOptions.PaperOrientation = CrystalDecisions.[Shared].PaperOrientation.Landscape



If RecordSelector.Length > 0
Then cr.RecordSelectionFormula = RecordSelector



If PrintReport
Then


cr.Refresh()


cr.PrintToPrinter(1,
False, 0, 0)



Else


FrmPrint.Show()



With FrmPrint.crViewer1


.ReportSource = cr



'Modification affichage


.Refresh()


.Zoom(1)


.Top = 0


.Height = FrmPrint.Height


.Width = FrmPrint.Width


.DisplayGroupTree =
False



'.dEnableExportButton = ExportEnable


.DisplayGroupTree =
False


.DisplayBackgroundEdge =
False


.Show()



End
With



With FrmPrint


.Text = WindowTitle


.Show()



End
With



End
If


cr =
Nothing


crInfo =
Nothing



Exit
Sub


Err_Print:


cr =
Nothing


crInfo =
Nothing



'WriteToLog("PrintForm : " & Err.Description)


MsgBox(Err.Description, MsgBoxStyle.Critical + MsgBoxStyle.OKOnly, "Impression")



End
Sub
0
Rejoignez-nous