Writing Code
 Crystal Reports Forum : Crystal Reports .NET 2003 : Writing Code
Message Icon Topic: newbie .net windows application Post Reply Post New Topic
Author Message
aleplgr
Newbie
Newbie


Joined: 09 Dec 2006
Online Status: Offline
Posts: 23
Quote aleplgr Replybullet Topic: newbie .net windows application
    Posted: 24 Feb 2007 at 11:31am
Hi! I was asked to launch a CR report from a vb.net form, it works fine when the parameters are discrete (for example select two cities and display all the clients from the cities) Now I have a range of dates and I need to display all the clients who came between the dates and don't know how to do it, is there any tutorial or example? It will be fantastic if the user could select the initial and final dates from a calendar, clicking the day, I think that could be possible, is it??
I know there's the book but I'm just starting and I think that if this works I'll keep on working with CR
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 24 Feb 2007 at 12:58pm
Yes, all the code for working with parameters is in my CR.NET book, however, there is a much easier way of doing this (also covered in the book of cource). What I would do is create two formulas and each has either the beginning date or the ending date. Then set your record selection formula to use these dates and make sure it works. Once it works, use the following code to override the formula values so that they filter on the user dates instead.

myReport.DataDefinition.FormulaFields("StartDate")=StartDate
myReport.DataDefinition.FormulaFields("EndDate")=EndDate

That's all there is to it, and its MUCH easier than dealing with all the code to override parameters.
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
aleplgr
Newbie
Newbie


Joined: 09 Dec 2006
Online Status: Offline
Posts: 23
Quote aleplgr Replybullet Posted: 25 Feb 2007 at 7:01am

Let me see if i get it: first i defined 2 formulas: @initial and @final, for example @initial is #01/01/2006# and @final is #31/12/2006# for all clients of last year. Then i defined this record selection formula:

{Orders.Order Date}>{@initial} And {Orders.Order Date}< {@final}
 
then i binded the report to the form,compiled and run it to test if worked and it's ok, this works.
 
Now the part that I think I didn't understand: I need to drag 2 DateTimePickers to the form and code them with this?
myReport.DataDefinition.FormulaFields("StartDate")=StartDate
myReport.DataDefinition.FormulaFields("EndDate")=EndDate
 
and then I have to drag a button tu launch the report after the user selected the 2 dates??
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 25 Feb 2007 at 10:38am
Yes, you've almost got it. Drag the two datetime pickers to your form and a button called "Print". When the user clicks the Print button, you the code I gave you to assign the datetime picker values to the formula. Here is a bit more pseudo-code to point you in the right direction.

Print_OnClick(...)
   Dim myReport as New CustomReportClass
   myReport.DataDefinition.FormulaFields("StartDate")=DateTimePicker1.Text
   myReport.DataDefinition.FormulaFields("EndDate")=DateTimePicker2.Text
   CrystalReportViewer1.ReportSource=myReport

Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
aleplgr
Newbie
Newbie


Joined: 09 Dec 2006
Online Status: Offline
Posts: 23
Quote aleplgr Replybullet Posted: 25 Feb 2007 at 12:16pm

 doesn't work...Cry the selection formula is ok, it shows the records according to the initial and final formulas, but it doesn't compile the Print_Click..

This is my Form class:
 
Public Class Form1
    Inherits System.Windows.Forms.Form
    Private customersByCityReport As CustomersByCity

    Private Sub ConfigureCrystalReports()
        customersByCityReport = New CustomersByCity
        myCrystalReportViewer.ReportSource = customersByCityReport
    End Sub
 
 
####Here is the Print Click:
 
    Private Sub Print_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Print.Click
        Dim myReport As New CustomReportClass
        myReport.DataDefinition.FormulaFields("initial") = DateTimePicker1.Text
        myReport.DataDefinition.FormulaFields("final") = DateTimePicker2.Text
        myCrystalReportViewer.ReportSource = myReport
    End Sub
End Class
 
Doesn't compile the CustomReportClass...
my report name is CustomersByCity...I created the ConfigureCrystalReports() following this tutorial and I use it to bind the report and i think that's ok
 
but now I dont' know what's wrong Ouch
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 25 Feb 2007 at 12:42pm
Hmmm... everything should be fine. First off, you didn't say what the error message was or what line of code is triggering it. Secondly, the link you gave for the code you are using is just a link to the first page. I can't determine what example you are referring to. Need more info....
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
aleplgr
Newbie
Newbie


Joined: 09 Dec 2006
Online Status: Offline
Posts: 23
Quote aleplgr Replybullet Posted: 26 Feb 2007 at 2:13am
Yes, there's only one error message :
"Type CustomReportClass is not defined"
 
 
Here is the whole Form Class:

Imports CrystalDecisions.CrystalReports.Engine

Imports CrystalDecisions.Shared

Public Class Form1

Inherits System.Windows.Forms.Form

Private customersByCityReport As CustomersByCity

 

 

Private Sub ConfigureCrystalReports()

customersByCityReport = New CustomersByCity

myCrystalReportViewer.ReportSource = customersByCityReport

End Sub

 

 

#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeComponent()

'Add any initialization after the InitializeComponent() call

ConfigureCrystalReports()

 

End Sub

#End Region

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim myReport As New CustomReportClass

myReport.DataDefinition.FormulaFields("initial") = DateTimePicker1.Text

myReport.DataDefinition.FormulaFields("final") = DateTimePicker2.Text

myCrystalReportViewer.ReportSource = myReport

End Sub

End Class

I ommited the rest of the Region because I didn't change anything there.

From the tutorial I followed this route:
Tutorials-ReportDocumentObject Model Tutorials - Reading and Setting Discrete Parameters - Introduction
I followed the Set-Up instructions and then the Binding instructions because i did my own report and for the parameters i followed your indications, I think it's almost done, the only problem is the CustomReportClass...Ouch


Edited by aleplgr - 26 Feb 2007 at 2:16am
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 26 Feb 2007 at 10:24am
Oh - I see. SORRY for the confusion. When I wrote 'CustomReportClass' I meant that you should put your report class here. Since I didn't know the name of it then I had to make up something. I should have been more clear.  
 
You would replace that with your class called CustomersByCity.  The same applies for the DateTimePicker. Use whatever class name you assigned it.

Sorry again.

Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
aleplgr
Newbie
Newbie


Joined: 09 Dec 2006
Online Status: Offline
Posts: 23
Quote aleplgr Replybullet Posted: 27 Feb 2007 at 12:15am

 thank you for your patience...

Now I'm getting the error message: "Property Item is ReadOnly",  for this 2 lines:

myReport.DataDefinition.FormulaFields("initial") = DateTimePicker1.Text

myReport.DataDefinition.FormulaFields("final") = DateTimePicker2.Text
 
initial and final are the names of my formulas, (they are: @initial and @final) DateTimePicker1 and 2 are the names of the date pickers, I left the default names, the  whole Click code now is this:
 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim myReport As New CustomersByCity

myReport.DataDefinition.FormulaFields("initial") = DateTimePicker1.Text

myReport.DataDefinition.FormulaFields("final") = DateTimePicker2.Text

myCrystalReportViewer.ReportSource = myReport

End Sub

I'm guessing it could be because of  some property of  the DateTimePickers, maybe I need to change something there..
And thanks again
IP IP Logged
aleplgr
Newbie
Newbie


Joined: 09 Dec 2006
Online Status: Offline
Posts: 23
Quote aleplgr Replybullet Posted: 04 Mar 2007 at 3:47am


Now it compiles, but shows a blank report. I think it's because the DateTimePickers date format is different than the formula date format in the report:

In the DateTimePickers I've selected the Short format : (for example today is represented like this: 04/03/2007)
In the report, the initial formula is represented like this:  Date (1997, 04, 02), this is (YYYY,MM,DD) and the final formula is this: Date (1998, 04, 10)
 
and in the Click button I have this:
myReport.DataDefinition.FormulaFields("inicial").Text = "CDate(" + DateTimePicker1.Text + ")"
myReport.DataDefinition.FormulaFields("final").Text = "CDate(" + DateTimePicker2.Text + ")"

I think I need to convert one to the other I think that this should be done with the CDate, I need a CDate that converts the format DD/MM/YYYY to the format  (YYYY, MM,DD) and can't find out how to do it Ouch

IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.018 seconds.