StrataFrame Forum

Crystal reports datasource and filter conditions

http://forum.strataframe.net/Topic15401.aspx

By Jiri Brazda - 4/6/2008

Hi,

I need to create a crystal report to return records list from my application. I need to specify some search criteria to retrieve records. With the standard VS controls I create user controls (one for filter conditions and second for list of retrieved records).

My question is whether it is possible to use SF Browse dialog to specify a datasource of crystal report (e.g. is it possible to get list of records displayed in Browse dialog as a datatable or dataset, or at least get a query statement?). Or is there another solution?

Thanks a lot

George

By Trent L. Taylor - 4/6/2008

Well, you could do this is you needed to.  The BrowseDialog just populates a BO, so you could call the BrowseDialog prior to executing the report so that it would populate the data set for you.  You can do this in code and it would look something like this:

Dim myBrowse As New MyBrowseDialog()
Dim myBo As New MyBoClass()

myBrowse.BusinessObjectToPopulate = myBo

If myBrowse.ShowDialog() <> OK Then
    '-- Exit since the browse was cancelled
End If

'-- Place report logic here

By Jiri Brazda - 4/23/2008

Thank You for Your answer.

Now I have more general question - is it possible to use Search criteria from Browse dialog somewhere in my own form? With my previous applications (before using StrataFrame) I have used the layout where there were 3 user controls in one form - filter control on the top (where users can specify search criteria), list control (with the grid where records matching criteria from filter control were displayed) and the detail control (where all information about the selected record is displayed and can be modified - just like on Your standard form).

I know that I can create my own filter control but I like the functionality of how filtering in Browse dialog works so I would like to use it if possible.

Thank You

George

By Trent L. Taylor - 4/23/2008

Well, you could capture the data on your form and then pass it over to the BrowseDialog by setting the SearchField values or by passing it into the InitialSearchValue.  The latter gets a bit more complex but will give you the ultimate control over the search values coming in.  When you call the ShowDialog, there is an option to pass in initial search values, but when you do this you will need to override the ParseInitialValue method on the BrowseDialog (which means that you will need to be inheriting the BrowseDialog) and then add your logic. 

In the below example, you can get an idea of how to implement this:

''' <summary>
''' Determines how to parse the initial value string
''' </summary>
''' <param name="initialValue"></param>
''' <returns></returns>
''' <remarks></remarks>
Protected Overrides Function ParseInitialValue(ByVal initialValue As String) As Boolean
    '-- Establish Locals
    Dim parts() As String
    '-- Determine if there is anything to parse
    If initialValue.Trim().Length <> 0 Then
        '-- If something was passed, then the type is being filtered so we don't want to let the end-user choose
        '    the type in the criteria.
        Me.SearchFields("cc_Type").InitiallyEnabled = False


        '-- Get the values into an array.  The are separated by a comma in this example.
        parts = initialValue.Split(","c)


        '-- Set the part values.  These are just privates in this class that I will use later in the OnSearching method
        '    to provide additiona query logic.
        _AllowAutoCodes = Boolean.Parse(parts(0))
        _AllowCpt = Boolean.Parse(parts(1))
        _AllowSupplies = Boolean.Parse(parts(2))
        _UpdateSearch = True
    End If


    '-- By returning False, the browse will not automatically perform a search.  In this case, we just wanted to
    '   setup the control, so do not automatically perform the query.  You would probably want to set all of your search logic
    '   and return True to execute the query.
    Return False
End Function

By Jiri Brazda - 4/23/2008

Well, I have not clearly described what I want to achieve.

Simply - I do not want to open any dialog for searching records. I just want to have one form with upper part for searching criteria, middle part for list of records and the bottom part for record detail info and editing.

So the question states whether it is possible to use searching functionality used in BrowseDialog anywhere else on my form.

Is there any possibility how to achieve this?

Thank You

By Trent L. Taylor - 4/23/2008

So if I understand your correctly then you don't want the BrowseDialog to come up at all.  In that case, no.  You will have to write your own.