Ticket T299256
Visible to All Users

ASPxScheduler loop all appointment infomration to keep a running total

created 9 years ago

I am using the ASPxScheduler to store working shift information.
I want to present to the user a running total of hours for the duration of the date limits set for the scheduler.

Which is the best event to use, that fires for the scheduler when appointments are loaded to iterate all appointment information.

And could you please provide a code sample of the fastest/most efficient method to iterate all the appointments, in that event ?

The hours total will be presented to the user via a simple text lablel at the top of the page.

thanks

Comments (1)

    Also it has to be an event that fires after a appointment change is made by the user so that update totals can be presented after each change.

    Answers approved by DevExpress Support

    created 9 years ago (modified 9 years ago)

    Hi,

    To calculate the duration of appointments every time the appointments are modified, I suggest you handle the ASPxScheduler.Storage.AppointmentsInsertedASPxScheduler.Storage.AppointmentsChanged and ASPxScheduler.Storage.AppointmentsDeleted events to be notified if an appointment is created, changed, or deleted. Also, handle the ASPxScheduler.Storage.AppointmentCollectionLoaded event to be notified if ASPxScheduler loads appointments from a datasource. To calculate the duration of the appointments, please use the following code:

    C#
    protected void Page_Load(object sender, EventArgs e) { ASPxScheduler1.Storage.AppointmentsInserted += Storage_AppointmentsInsertedChangedDeleted; ASPxScheduler1.Storage.AppointmentsChanged += Storage_AppointmentsInsertedChangedDeleted; ASPxScheduler1.Storage.AppointmentsDeleted += Storage_AppointmentsInsertedChangedDeleted; ASPxScheduler1.Storage.AppointmentCollectionLoaded += Storage_AppointmentCollectionLoaded; } void Storage_AppointmentCollectionLoaded(object sender, EventArgs e) { DevExpress.Web.ASPxScheduler.ASPxSchedulerStorage storage = (DevExpress.Web.ASPxScheduler.ASPxSchedulerStorage)sender; CalcAppointmentsDuration(storage); } void Storage_AppointmentsInsertedChangedDeleted(object sender, DevExpress.XtraScheduler.PersistentObjectsEventArgs e) { DevExpress.Web.ASPxScheduler.ASPxSchedulerStorage storage = (DevExpress.Web.ASPxScheduler.ASPxSchedulerStorage)sender; CalcAppointmentsDuration(storage); } private void CalcAppointmentsDuration(DevExpress.Web.ASPxScheduler.ASPxSchedulerStorage storage) { TimeSpan duration = new TimeSpan(storage.GetAppointments(new DevExpress.XtraScheduler.TimeInterval(DateTime.Today.AddDays(-7), DateTime.Today.AddDays(7))).Sum(a => a.Duration.Ticks)); ASPxLabel1.Text = duration.ToString(); }

    If you need further assistance, let me know.

      Comments (3)

        thanks.
        This worked though I could not get the .Sum extension to be recognised so I just looped the items.
        thanks.
        foreach (Appointment item in apptsCollection)
                   {
                       dTotalRosterWorkingHours += item.Duration.TotalHours;
                       dRate = Convert.ToDecimal(item.CustomFields["CurrentRate_h"].ToString());
                       dTotalRosterWorkingCost += Convert.ToDecimal(item.Duration.TotalHours) * dRate;
                   }

          One more thing.
          I had to hook up the event
          ASPxScheduler1.Storage.AppointmentCollectionLoaded
          manually in code behind like you have here in this sample.
          The event item was listed in the designer properties editor as an event, but it would not let me assign any events via the visual studio property editor for the storage object. There was no error message, it just would not let me.
          I don't know if this is deliberate or not, but Im using vs2012.

          DevExpress Support Team 9 years ago

            Hi,

            To process your recent post more efficiently, I created a separate ticket on your behalf: T299679: ASPxScheduler has a wrong category of events in the Properties window. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.

            Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

            Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.