This is a migrated thread and some comments may be shown as answers.

How to validate the RecurrenceRule

3 Answers 107 Views
ScheduleView
This is a migrated thread and some comments may be shown as answers.
samy
Top achievements
Rank 1
samy asked on 12 Oct 2011, 03:58 PM
I'd like to be able to validate the RecurrenceRule, especially the RecursUntil part which should not be greater than a certain fixed date in the future. I've seen plenty of examples regarding the validation of a custom appointment but i couldn't find anything regarding the RecurrenceRule.

So far what i've found is that i could possibly inherit from RecurrenceDialogViewModel and override the CanConfirm method, but i couldn't find the points where i could attach myself.
I also tried to attach myself to the PropertyChanged event of the RecurrenceDialogViewModel to disallow the change with an alert, but the RecurrenDialog gets in the way!

Here is the code sample i used to check the RecursUntil
private void RSVPlanning_ShowDialog(object sender, ShowDialogEventArgs e)
        {
            var rdvm = e.DialogViewModel as RecurrenceDialogViewModel;
            if (rdvm != null)
            {
                if (rdvm.RecurrenceRangeType == RecurrenceRangeType.NoEndDate)
                {
                // we don't want the "no ending mode" and it's hidden in the template
                    rdvm.RecurrenceRangeType = RecurrenceRangeType.RepeatUntil;
                    rdvm.RecursUntil = DateTime.Now.AddDays(7);
                }
 
                rdvm.PropertyChanged += ((innerSender, pcea) => {
                    if (pcea.PropertyName == "RecursUntil")
                    {
                        var rdvmCallback = innerSender as RecurrenceDialogViewModel;
                        if (rdvmCallback.RecursUntil > DateTime.Now.AddDays(7))
                        {
                            RadWindow.Alert("That's too far away! Back to one week from now");
                            rdvmCallback.RecursUntil = DateTime.Now.AddDays(7);
                        }
                    }
                });
            }
        }
When you run this code with this method attached to the OpenDialog event of the RadScheduler, the alert window is pushed back between the edit appointment window and the edit reccurence window. Is it a bug, or have i forgotten something (saying the alert to be topmost?)

3 Answers, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 18 Oct 2011, 03:44 PM
Hi Samy,

This seems a problem in RadWindow which we'll research. For now, please modify your code like this in order to workaround it:

private void scheduleView1_ShowDialog(object sender, ShowDialogEventArgs e)
{
    var rdvm = e.DialogViewModel as RecurrenceDialogViewModel;
    if (rdvm != null)
    {
        if (rdvm.RecurrenceRangeType == RecurrenceRangeType.NoEndDate)
        {
            // we don't want the "no ending mode" and it's hidden in the template
            rdvm.RecurrenceRangeType = RecurrenceRangeType.RepeatUntil;
            rdvm.RecursUntil = DateTime.Now.AddDays(7);
        }
 
        rdvm.PropertyChanged += ((innerSender, pcea) =>
        {
            if (pcea.PropertyName == "RecursUntil")
            {
                var rdvmCallback = innerSender as RecurrenceDialogViewModel;
                if (rdvmCallback.RecursUntil > DateTime.Now.AddDays(7))
                {
                    rdvmCallback.RecursUntil = DateTime.Now.AddDays(7);
 
                    var textbl = new TextBlock { Text = "That's too far away! Back to one week from now" };
                    textbl.Loaded += new RoutedEventHandler(textbl_Loaded);
                    RadWindow.Alert(new DialogParameters()
                    {
                        Content = textbl
                    });
                }
            }
        });
    }
}
 
void textbl_Loaded(object sender, RoutedEventArgs e)
{
    (sender as TextBlock).ParentOfType<RadWindow>().BringToFront();
}

Hope this helps.

Greetings,
Yana
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
samy
Top achievements
Rank 1
answered on 19 Oct 2011, 09:34 AM
Hello Yana,

Unfortunately, adding the RoutedEvent to bring the RadWindow alert back to the front doesn't seem to work for me.
There seems to be a very small amount of time when the alert gets back to the front but the recurrence dialog comes back almost immediately.

I initially had set the
rdvmCallback.RecursUntil = DateTime.Now.AddDays(7);
line after the alert, but i thought it could be the reason for the reappearance of the edit recurrence as the topmost window so i moved it before the Alert call, but no luck.

Are there any others workarounds, or tests i could do to pinpoint the problem?

Thanks
0
Yana
Telerik team
answered on 21 Oct 2011, 11:38 AM
Hi Samy,

The code works as expected at our side, please check the attached project for a reference.

You could also open the RadWindow using a Dispatcher - try it and let us know the result.

Regards,
Yana
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
ScheduleView
Asked by
samy
Top achievements
Rank 1
Answers by
Yana
Telerik team
samy
Top achievements
Rank 1
Share this question
or