Best place (event) to put BO data access code to fill 3rd party control?


Author
Message
William Fields
William Fields
StrataFrame User (252 reputation)StrataFrame User (252 reputation)StrataFrame User (252 reputation)StrataFrame User (252 reputation)StrataFrame User (252 reputation)StrataFrame User (252 reputation)StrataFrame User (252 reputation)StrataFrame User (252 reputation)StrataFrame User (252 reputation)
Group: StrataFrame Users
Posts: 80, Visits: 239
Hello,

Working on my first SF Maintenance Form and have a couple BO's that are retrieving data just fine.

Now, I need to take the data contained within the BO's and load it into a 3rd party calendar control. Basically, I have to cycle through the data tables and create an object the calendar control can use for each data row. I'd love to be able to bind the calendar control directly to the BO's, but I'm not sure that's possible. All the sample code from the calendar vendor shows methods that take data and push it into collections of "appointment" objects, which the control then uses for it's data.

Also, since this is my first sample SF app, I'm trying to take the path of least resistance. So I'm just going with the vendor's examples for now.

BTW - the calendar control is the dbiMonth control from DBI Technologies. http://www.dbi-tech.com/

So, my question is, "What event should I use to load the data into the calendar control?"

I'm still a .NET WinForms newbie, but in VFP I would do this in the INIT event of the form since all the form controls would be available, but the form would not be visible yet. I have a working example of loading the data into the calendar control in the click of a button on the form, but I woud like to load the data before the form becomes visible.

Suggestions?

Thanks.

Bill
Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
William, mostly all 3rd party controls will bind to a list which in SF case will be a BusinessBindingSource control or a data table.  I have no experience with DBI controls in .Net, I only used coupled of their controls back in VFP days.

Take a look at the following links which are for DevExpress scheduler control, but may relate to your case:
http://forum.strataframe.net/Topic25460.aspx?Keywords=schedule#bm25461
http://forum.strataframe.net/Topic8003.aspx#bm8050

Edhy Rijo

William Fields
William Fields
StrataFrame User (252 reputation)StrataFrame User (252 reputation)StrataFrame User (252 reputation)StrataFrame User (252 reputation)StrataFrame User (252 reputation)StrataFrame User (252 reputation)StrataFrame User (252 reputation)StrataFrame User (252 reputation)StrataFrame User (252 reputation)
Group: StrataFrame Users
Posts: 80, Visits: 239
Thanks for the reply Edhy,

There is no mention of binding to anything directly in DBI's documentation. The samples and docs all demonstrate scanning through a datatable and creating appointment objects that then are added to the control.

If I take this route, what event in the form or the DBI control, should I use? I guess I would need an event that fires after the "ParentFormLoading" event, and one that fires when the form controls are all available, but before the form becomes visible.

And this is most likely not an SF quesion, since it's directed towards the .NET Winforms Event sequence, but maybe there's a custom SF event where this type of code should live?

If not, then what standard event would I want to use?

Thanks.
Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi William,

William Fields (4/11/2011)
If I take this route, what event in the form or the DBI control, should I use? I guess I would need an event that fires after the "ParentFormLoading" event, and one that fires when the form controls are all available, but before the form becomes visible.


What I usually do to get the effect of loading the data after the form is shown is use a timer control with a an interval of 500 or more based on your needs,  an SF Wait Window control to let the user know that the data is being loaded and a Background Worker to actually load the data.

Here is a sample of the events I use loading data for DevExpress scheduler:

Protected Overrides Sub OnLoad(e As System.EventArgs)
         MyBase.OnLoad(e)
         With Me.SchedulerControl1
             '-- Setup working hours from 9:30am to 8:00pm
             .DayView.ShowWorkTimeOnly = True
             .DayView.WorkTime.Start = New TimeSpan(0, 9, 30, 0)
             .DayView.WorkTime.End = New TimeSpan(0, 20, 0, 0)
             .DayView.AppointmentDisplayOptions.StartTimeVisibility = AppointmentTimeVisibility.Never
             .DayView.AppointmentDisplayOptions.EndTimeVisibility = AppointmentTimeVisibility.Never
             .WeekView.AppointmentDisplayOptions.StartTimeVisibility = AppointmentTimeVisibility.Never
             .WeekView.AppointmentDisplayOptions.EndTimeVisibility = AppointmentTimeVisibility.Never
             .WorkWeekView.AppointmentDisplayOptions.StartTimeVisibility = AppointmentTimeVisibility.Never
             .WorkWeekView.AppointmentDisplayOptions.EndTimeVisibility = AppointmentTimeVisibility.Never
             .MonthView.AppointmentDisplayOptions.StartTimeVisibility = AppointmentTimeVisibility.Never
             .MonthView.AppointmentDisplayOptions.EndTimeVisibility = AppointmentTimeVisibility.Never

             '-- Disable Create, Delete, Copy and multi-select appointments.
             '   The appointments can only be moved from one date to another. 
             '   Other data changes should only be made via the Service Call maintenance form.
             .OptionsCustomization.AllowAppointmentCreate = UsedAppointmentType.None
             .OptionsCustomization.AllowAppointmentDelete = UsedAppointmentType.None
             .OptionsCustomization.AllowAppointmentCopy = UsedAppointmentType.None
             .OptionsCustomization.AllowAppointmentMultiSelect = False
             .OptionsCustomization.AllowInplaceEditor = False

             '-- Show today's appointments
             .Start = Now.Date
         End With

         '-- Start the timer that will load the data for the schedule.
         '   A timer is used to show the empty scheduler control and then the data.
         Me.ScheduleDataLoadTimer.Start()
     End Sub

     Private Sub ScheduleDataLoadTimer_Tick(sender As System.Object, e As System.EventArgsHandles ScheduleDataLoadTimer.Tick
         Me.ScheduleDataLoadTimer.Stop()
         Me.LoadAllDataForSchedulerAsync()
     End Sub

     Private Sub LoadAllDataForSchedulerAsync()
        '-- Use a background worker to allow the form to show complete showing, then
        '   use the Wait Window to show the message that the data is being loaded.
         With Me.WaitWindow1
             .ShowInScreen = False
             .WaitWindowLocation = MicroFour.StrataFrame.Messaging.MessagingCardinalPosition.Center
             .Title = My.Application.Info.Title
             .Message = "Please wait, loading scheduler records..."
             .ShowWaitWindow()
         End With

         Me.Cursor = Cursors.WaitCursor
         Me.bwMainData.RunWorkerAsync()
     End Sub

     Private Sub bwMainData_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgsHandles bwMainData.DoWork
         Me.LoadAllDataForScheduler(MeNew EventArgs)
     End Sub

     Private Sub bwMainData_RunWorkerCompleted(sender As Object, e As System.ComponentModel.RunWorkerCompletedEventArgsHandles bwMainData.RunWorkerCompleted
         Me.WaitWindow1.HideWaitWindow()
         Me.Cursor = Cursors.Default
     End Sub

For your DBI control, you may do the following:
  1. Load all your data into your BO at once using the FillMultipleDataTables method.
  2. Loop all the BO using the bo.GetEnumerable() to create your schedule collection, in this process use the DBI control Tag property or some other to save the Primary Key of the record.  Pretty much as the ListView does internally, this way you can always navigate to the correct record in the BO via the scheduler events.
Hope above code can give you some ideas on handling this situation.

Edhy Rijo

William Fields
William Fields
StrataFrame User (252 reputation)StrataFrame User (252 reputation)StrataFrame User (252 reputation)StrataFrame User (252 reputation)StrataFrame User (252 reputation)StrataFrame User (252 reputation)StrataFrame User (252 reputation)StrataFrame User (252 reputation)StrataFrame User (252 reputation)
Group: StrataFrame Users
Posts: 80, Visits: 239
Thanks Edhy, you gave me a few helpful tips.

First, I imagine the call to MyBase.OnLoad(e) is what would cause the ParentFormLoading event to fire, which means the BO's would have all thier data at that point, correct?

Second, I'm very interested in the multithreading capabilities in SF. You're example is right on target and I will be able to incorporate it into my sample app.

Thanks.

Bill
Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
You are welcome William!

William Fields (4/11/2011)
First, I imagine the call to MyBase.OnLoad(e) is what would cause the ParentFormLoading event to fire, which means the BO's would have all thier data at that point, correct?

Yes and no.  You are responsible for loading the data into the BO, for that you can use whatever event you prefer that will suit your application's needs.  In my case, I prefer to always have a custom method responsible for loading the data, in this form, I created the LoadAllDataForScheduler() which will simply do just that, fill the BOs needed by the form with the correct data so I can use them later.  In this particular case, I do that in the DoWork event of the background worker object (see .Net help or Google for more info).  Again, this is the way I have found the correct timing to work so it will show the form to the user and then a wait window letting then know that the data is being loaded.  I am sure there are other ways to do the same, and probably easier.


    Private Sub bwMainData_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgsHandles bwMainData.DoWork
         Me.LoadAllDataForScheduler(MeNew EventArgs)
    End Sub


William Fields (4/11/2011)
Second, I'm very interested in the multithreading capabilities in SF. You're example is right on target and I will be able to incorporate it into my sample app.

Yes, Background workers are very easy to use without all the complications of having to handle all the multithreading complexities of the past.  VS 2010 added a lot of functionality for more complex operation like Task, but in this case a simple Background Worker will do the trick easier.

Edhy Rijo

Michel Levy
Michel Levy
StrataFrame User (437 reputation)StrataFrame User (437 reputation)StrataFrame User (437 reputation)StrataFrame User (437 reputation)StrataFrame User (437 reputation)StrataFrame User (437 reputation)StrataFrame User (437 reputation)StrataFrame User (437 reputation)StrataFrame User (437 reputation)
Group: StrataFrame Users
Posts: 193, Visits: 9K
Hi William,

I had a similar job to do for one of our customers. It was not a third party calendar, but the .net native System.Windows.MonthCalendar, on which we needed to show working days and the days worked, for each plant, on a set of 4 months at a time.

Of course, working days and days worked are retrieved in a BO, and there is no databinding enabled for this control...

The ParentFormLoading Event is the right place to code, the controls are already created (this event is more similar to the init VFP event, than to the load VFP event).

here is some code:

   Private Sub BO_JoursTravailSites_ParentFormLoading() Handles BO_JoursTravailSites.ParentFormLoading

Dim andeb As Integer = Today.Year - 5
Dim anfin As Integer = Today.Year + 10
Me.BO_JoursTravailSites.FillJoursTravail(andeb, anfin, "")
' définir la plage du calendrier sur les dates maxi et mini du BO
' let's define the calendar's range from the min and max dates in the BO
Me.MonthCalendar.MinDate = DateValue("01/01/" & andeb.ToString)
Me.MonthCalendar.MaxDate = DateValue("31/12/" & anfin.ToString)
' sur cette plage, mettre en gras les week-ends et jours fériés
' on this range, display in BOLD weekends and holidays


With Me.BO_JoursTravailSites

If .MoveFirst() Then

Do

If .WeekEnd = True _
Or .JourFerie = True Then

Me.MonthCalendar.AddBoldedDate(.DateJour)

End If

Loop While .MoveNext()

End If

End With

End Sub



When a date is selected on the calendar, I run some code to add a check in a list.



Private Sub MonthCalendar_DateSelected(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) _
       
Handles MonthCalendar.DateSelected

Me.ActualiseListeSites(e.Start)

End Sub



the ActualiseListeSites is pretty identic as the code above. I put a filter on the BO based on the value received in the parameter, and then I process a scan/endscan in a loop.
William Fields
William Fields
StrataFrame User (252 reputation)StrataFrame User (252 reputation)StrataFrame User (252 reputation)StrataFrame User (252 reputation)StrataFrame User (252 reputation)StrataFrame User (252 reputation)StrataFrame User (252 reputation)StrataFrame User (252 reputation)StrataFrame User (252 reputation)
Group: StrataFrame Users
Posts: 80, Visits: 239
Hi Michel,

I'm sure there's a number of ways to go about this, but in general, would a call to MyBase.OnLoad(e) in the form load cause the StrataFram ParentFormLoading event to fire?

I guess I'm curious how the "custom" SF events fit into the normal .NET event sequence.

Thanks.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search