Private Framework. Win . Library . Database _ DB = Null ; Private Crystaldecisions. Crystalreports . Engine . ReportDocument Rptdoc ; Private Bool printreport ( ) { Dataview dv ; String strrepver = "" ; DV = Getreporthd ( Convert. Toint32 ( Cmbreportname. Selectedvalue .Tostring ( ) ) ) ; Strrepver = DV [ 0 ] [ "Version" ] . Tostring ( ) ; String strreportname = DV [ 0 ] [ "Reppath" ] . Tostring ( ) + DV [ 0 ] [ "Repid" ] . Tostring ( ) ; // String strreportname = "W: \ wgerp \ reports \ wgerp004_test.rpt "; Rptdoc = New ReportDocument ( ) ; Try { Rptdoc.Load ( Strreportname ) ; Connectioninfo = New Connectioninfo ( ) ; Connectioninfo. Servername = _ DB. Server ; Connectioninfo.Databasename = _ DB. Databasename ; Connectioninfo. Userid = _ DB. Userid ; Connectioninfo. Password = _ DB. Password ; Setdblogonforreport ( Connectioninfo, rptdoc) ; Setdblogonforsubreports ( Connectioninfo, rptdoc ) ; String strbeginstyleno = "" ; String strendstyleno = "" ; Datetime begindate = Dtpbegindate. Value .Date ; Datetime enddate = Dtpenddate. Value . Date ; Strbeginstyleno = Txtso. Text . Trim ( ) . Tostring ( ) ; Strendstyleno = Txtstyleendno. Text . Trim ( ) . Tostring ( ) ; If ( Cmbreportname. Text . Trim ( ) = "Daily workshop Flow Meter-" ) { Setreportparameter ( Rptdoc, "@ Fr_mo" , Ctextbox1. Text . Trim ( ) . Tostring ( ) ) ; Setreportparameter ( Rptdoc, "@ To_mo" , Ctextbox2. Text . Trim ( ) . Tostring ( ) ) ; Setreportparameter ( Rptdoc, "@ Fr_day" , Dtp1.Value . Date . Tostring ( ) ) ; } Else If ( Cmbreportname. Text . Trim ( ) = "Style price-" ) { Setreportparameter ( Rptdoc, "@ Beginstyle_no" , Strbeginstyleno ) ; Setreportparameter ( Rptdoc, "@ Endstyle_no" , Strendstyleno ) ; // Setreportparameter (rptdoc, "@ begindate", begindate. tostring ()); // Setreportparameter (rptdoc, "@ enddate", begindate. tostring ()); } Else { Setreportparameter ( Rptdoc, "@ Beginstyle_no" , Strbeginstyleno ) ; Setreportparameter ( Rptdoc, "@ Endstyle_no" , Strendstyleno) ; } } Catch ( Exception Ex ) { _ DB. Disconnect ( ) ; MessageBox. Show ( Ex.Message . Tostring ( ) ) ; } Finally { _ DB. Disconnect ( ) ; } Return True ; } Private Void Setdblogonforreport ( Connectioninfo, reportdocument ) { Tables tables = ReportDocument. Database . Tables ; Foreach ( Crystaldecisions. Crystalreports . Engine . Table Table in tables ) { Tablelogoninfo = Table. Logoninfo ; Tablelogoninfo. Connectioninfo = Connectioninfo ; Table. Applylogoninfo ( Tablelogoninfo ) ; } } Private Void Setdblogonforsubreports ( Connectioninfo, reportdocument ) { Sections sections= ReportDocument. Reportdefinition . Sections ; Foreach ( Section section in Sections ) { Reportobjects = Section. Reportobjects ; Foreach ( Reportobject in reportobjects) { If ( Reportobject. Kind = Reportobjectkind. Subreportobject ) { Subreportobject = ( Subreportobject ) Reportobject ; ReportDocument subreportdocument= Subreportobject. Opensubreport ( Subreportobject. Subreportname ) ; Setdblogonforreport ( Connectioninfo, subreportdocument ) ; } } } } Private Void Setreportparameter ( ReportDocument rptdoc, string strpara, string strparavalue ) { Parametervalues currentparametervalues = New Parametervalues ( ) ; Parameterdiscretevalue = New Parameterdiscretevalue ( ) ; Parameterdiscretevalue. Value = Strparavalue. Tostring ( ) ; Currentparametervalues. Add ( Parameterdiscretevalue ) ; Parameterfielddefinitions= Rptdoc. Datadefinition . Parameterfields ; Parameterfielddefinition = Parameterfielddefinitions [ Strpara ] ; Parameterfielddefinition. Applycurrentvalues ( Currentparametervalues ) ; } |