Results 1 to 2 of 2

Thread: Help me Improve my CrystalReport Class

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2014
    Location
    Philippines
    Posts
    9

    Help me Improve my CrystalReport Class

    Good day,

    I am writing my sqlReport class in my project..The thing is, my dataset is designed to accept any field, any datatype, and then shows the result of the sql query to the crystalreportviewer. But then I am stuck with this problem. I will try my best to explain why I'm stuck in it.

    Please take a look at my dataset.xsd.

    Name:  Untitled.png
Views: 313
Size:  5.9 KB

    and here's my sqlreport.rpt.
    Name:  Untitled2.jpg
Views: 322
Size:  26.6 KB

    annndd.. this is my class that will populate the dataset and then pass the values to crystal report columns.

    Code:
    Public Function rptSQL(ByVal CrystalReportViewer As CrystalReportViewer, ByVal fields_As As String()) As sqlreport
            Dim objRpt As New sqlreport
            Dim server As New servercon
            Dim ds As New sqlDataset
            Dim cnn As MySqlConnection
    
    'There are more lines of code here
    In the code highlighted above, What if I want to target a new crystal report design? I have 5 crystal report designs, and all of those reports uses the same function, but I rename the function, and give a new reportname. Take a look at this code below:

    Code:
    Public Function rptSQL1(ByVal CrystalReportViewer As CrystalReportViewer, ByVal fields_As As String()) As sqlreport
    'code of lines here
    End Function
    
    Public Function rptSQL2(ByVal CrystalReportViewer As CrystalReportViewer, ByVal fields_As As String()) As anotherReport
    
    'code of lines here
    End Function
    
    Public Function rptSQL3(ByVal CrystalReportViewer As CrystalReportViewer, ByVal fields_As As String()) As ironReport
    
    'code of lines here
    End Function
    Is there a way I could say something like this:

    Code:
    Public Function rptSQL(ByVal CrystalReportViewer As CrystalReportViewer, ByVal fields_As As String()) As Any Report I Want
    So that I will not duplicate the functions. Thank you for your time reading.

    -JL

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,927

    Re: Help me Improve my CrystalReport Class

    Dealing with the return type of the function is something that could be done, by simply using a less specific data type than sqlreport etc (and casting it to the correct type in the caller). I don't know if the different types you are using have a common parent data type (perhaps something like CrystalReport), but in the worst case you could use the data type Object.


    The bigger problem here is that the function creates a variable of the same data type:
    Dim objRpt As New sqlreport
    I suspect that changing this to a more generic data type will cause problems for the rest of the code in the function, especially if you need to resort to using Object.

    While you could create the variable in the caller and pass it in, you would need to pass it in using a data type you specify in the function parameter, so it wouldn't eliminate this issue.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width