Extended appointment properties not updated

7 posts, 0 answers
  1. Håkan
    Håkan avatar
    183 posts
    Member since:
    May 2011

    Posted 20 Oct 2011 Link to this post

    Hi,

    I have a class (TimeScheduleShift) that extends Appointment.
    It adds a few extra properties for example EmployeeId and EmployeeName.
    It looks like this (other properties revoved for clarity):

    public class TimeScheduleShift : Appointment
        {
            private int employeeId;
            public int EmployeeId
            {
                get
                {
                    return this.Storage<TimeScheduleShift>().employeeId;
                }
                set
                {
                    var storage = this.Storage<TimeScheduleShift>();
                    if (storage.employeeId != value)
                    {
                        storage.employeeId = value;
                        this.OnPropertyChanged(() => this.EmployeeId);
                    }
                }
            }
     
     private string employeeName;
            public string EmployeeName
            {
                get
                {
                    return this.Storage<TimeScheduleShift>().employeeName;
                }
                set
                {
                    var storage = this.Storage<TimeScheduleShift>();
                    if (storage.employeeName != value)
                    {
                        storage.employeeName = value;
                        this.OnPropertyChanged(() => this.EmployeeName);
                    }
                }
            }
     
            public override IAppointment Copy()
            {
                var newShift = new TimeScheduleShift();
                newShift.CopyFrom(this);
     
                return newShift;
            }
     
            public override void CopyFrom(IAppointment other)
            {
                var shift = other as TimeScheduleShift;
                if (shift != null)
                {
                    this.UniqueId = shift.UniqueId;
                    this.EmployeeId = shift.EmployeeId;
                    this.EmployeeName = shift.EmployeeName;
                }
     
                base.CopyFrom(other);
            }
     
            protected override void OnPropertyChanged(string propertyName)
            {
                base.OnPropertyChanged(propertyName);
     
                // Update label
                if (propertyName == "Start" || propertyName == "End" || propertyName == "EmployeeName")
                {
                    SetLabel();
                }
            }
     
            public void SetLabel(bool includeBreak = true, bool includeEmployeeName = true)
            {
                string subject = String.Format("{0}-{1}", this.Start.ToShortTimeString(), this.End.ToShortTimeString());
                    subject += String.Format(" {0}", this.EmployeeName);
     
                this.Subject = subject;
            }
        }

    I also have my own edit appointment dialog, which is a standard ChildWindow which implements the IScheduleViewDialogHost interface.
    I pass the selected appointment in the constructor of my dialog, store it in a public property there so I can fetch it when the dialog is closed.

    Inside the dialog I have a ComboBox with employees.
    If I open an existing appointment and change the Employee, the EmployeeId and EmployeeName properties are changed correctly on the appointment storde in the dialog.
    But in my Dialog_Closed event, if I examine the appointment the EmployeeId property has the new value, but the employeeId property still has the old value.

    I guess there must be some glitch in the copy method?
    I tried to add employeeId to the CopyFrom method also, but with no luck.

    It's the same problem with all my extended properties.

    Regards,
    Håkan





  2. Ivo
    Admin
    Ivo avatar
    390 posts

    Posted 25 Oct 2011 Link to this post

    Hi Håkan,

    I could not reproduce what you have mentioned.. You can find attached a sample project using IScheduleViewDialogHost and custom appointment. My only suspicion is that you are not bound to a collection of TimeScheduleShift elements. 

    Kind regards,
    Ivo
    the Telerik team

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

  3. DevCraft banner
  4. Håkan
    Håkan avatar
    183 posts
    Member since:
    May 2011

    Posted 26 Oct 2011 Link to this post

    My view model has this property:
    private ObservableCollection<TimeScheduleShift> appointments;
         public ObservableCollection<TimeScheduleShift> Appointments
         {
             get { return this.appointments; }
             set
             {
                 this.appointments = value;
                 this.OnPropertyChanged("Appointments");
             }
         }

    And I have two different collections depending on which ViewDefinition that is active.
    But in this specific case it is a ViewDefinition that is using the Appointments collection.

    Some code in my page looks like this:
    ScheduleView.AppointmentsSource = null;
    if (ScheduleView.ActiveViewDefinition == CalendarViewDefinition)
        ScheduleView.AppointmentsSource = periods;
    else
        ScheduleView.AppointmentsSource = viewModel.Appointments;

    - Håkan
  5. Ivo
    Admin
    Ivo avatar
    390 posts

    Posted 26 Oct 2011 Link to this post

    Hi Håkan,

    It would be great if you edit the project I sent you and send it back to us or send us sample application showing this issue, so we could investigate this further. 

    Greetings,
    Ivo
    the Telerik team

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

  6. Håkan
    Håkan avatar
    183 posts
    Member since:
    May 2011

    Posted 07 Feb 2012 Link to this post

    Hi there again!

    I have ignored this problem until now, because it has not actually affected my, but now it might do so?
    I have reproduced the problem in you test project attached to a previous post.
    It occurs if I change an extended property in code behind.

    I can't send you a test project but I try to explain the differences in big.
    The difference in my solution from your test project is that I don't use the standard edit appointment dialog, I have a compleately different ChildWindow, which implements the IScheduleViewDialogHost interface.

    The dialog has a public property where I set the selected appointment from the ScheduleView when opening the dialog.
    I also populate fields in the dialog from this property (they are not bound in XAML, but set in code behind).

    When the dialog is closing, I update the public appointment property with modifications made in the dialog.
    In the dialog factory I subscribe to the dialog closed event and fetch the appointment from the public property in the dialog.
    Then I update the appointment in my viewmodel with modifications made in the dialog.

    As you can see I pass a copy of the appointment between the ScheduleView and the dialog and back again.
    The reason is that my edit dialog it quite advanced so I can not bind everyting as simple as you can.

    This hasn't really been a problem, because I have always saved and refetched the appointment immediately after closing the dialog.
    Now I'm implementing a function where the user should be able to add and modify several appointments before saving all of them in a batch. The problem that occurs now is that I create a new appointment by double clicking an empty slot. I double click it again and it opens up correctly in the edit dialog. I cancel the dialog and double click it again, this time a get a new appointment though...
    The second time, just before opening the dialog, it goes into the CopyFrom method in my custom appointment class, but not the first time.

    This was a very long explanation and I don't know if the original problem posted has anything to do with this.
    But an easy repro of the extended properties not updated in your test project is to add a closed event in the factory and in that event do this:

     private void editShiftDialog_Closed(object sender, WindowClosedEventArgs e)
            {
                Window dialog = sender as Window;
                if (dialog != null)
                {
                    CustomAppointment app = dialog.ScheduleView.SelectedAppointment as CustomAppointment;
                    if (app != null)
                        app.IsDone = true;
                }
            }

    Create a new appointment, open it again, do not check 'Is Done', put a breakpoint in the closed event at the line where IsDone is set to true, inspect the appointment, then the private property isDone will still be false...

    Regards,
    Håkan
  7. Ivo
    Admin
    Ivo avatar
    390 posts

    Posted 15 Feb 2012 Link to this post

    Hi,

    The isDone field is not updated immediately after the IsDone property, because of the Storage usage into your custom appointment. This is the way RadScheduleView is designed to work.

    Your scenario is complicated and we will not be able to investigate the other issue further without a sample project. To send us a sample project you will have to open a support ticket.

    Regards,
    Ivo
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  8. mike okon
    mike okon avatar
    40 posts
    Member since:
    Dec 2009

    Posted 19 Feb 2013 Link to this post

    Hi

    I have tried to run this project however it is missing the .web portion. Please can you submit the project again.

    My issue is slightly different but similar to this thread.I am trying to implement a custom field however I am using the EF sql data structure and would like to insert into the sql table SQLAppointments. Can you provide an example how this can be achieved. IE have an additional field in the table and have the edit appointment window show it in a textbox. Eventually I would like to have this field auto populated with the user ID each time a new appointment is created.

    Thanks in advance for your help

    regards
    mike
Back to Top
DevCraft banner