Load a crystal report

Source: Internet
Author: User

There are two ways to load a crystal report.

     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 )  ;          } 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.