e.ModifiedAppointment have old appointment's values

2 posts, 0 answers
  1. Lasly
    Lasly avatar
    115 posts
    Member since:
    Nov 2009

    Posted 01 Sep 2011 Link to this post

    Hi,
    I'm using RadScheduler control with AdvancedInsertTemplate and AvancedEditTemplate.
    I'm using the same ascx to declare the template, and when I create an Appointment it works correctly, but when I try to edit it or another appointment I don't find the new values in e.ModifiedAppointment object but in e.Appointment.

    I've fired the event AppointmentCommand e AppointmetInsert, AppointmentUpdate.
    In the first event I check the CommandName to find the correct template in which find the controls (eg: textbox, dropdownlist)
    After fire the   AppointmetInsert and it works.

    In EditMode this not works.

    This is my ASCX codebehind

    /// <summary>
    /// Restituisce o imposta la modalità di accesso alla form
    /// </summary>
    [Bindable(BindableSupport.Yes, BindingDirection.TwoWay)]
    public SchedulerFormMode Modalita { get; set; } // qui non è necessario usare il viewstate perchè non viene agganciata da un datareader
    /// <summary>
    /// Restituisce o imposta il titolo della form
    /// </summary>
    [Bindable(BindableSupport.Yes, BindingDirection.TwoWay)]
    public string FormTitle { get; set; } // qui non è necessario usare il viewstate perchè non viene agganciata da un datareader
    /// <summary>
    /// Restituisce o imposta l'id dell'attività
    /// </summary>
    [Bindable(BindableSupport.Yes, BindingDirection.TwoWay)]
    public int AppointmentId
    {
        get { return Convert.ToInt32(this.ViewState["AppointmentId"]); }
        set { this.ViewState["AppointmentId"] = value; }
    }
    /// <summary>
    /// Restituisce o imposta l'oggetto dell'attività
    /// </summary>
    [Bindable(BindableSupport.Yes, BindingDirection.TwoWay)]
    public string Subject
    {
        get { return this.ViewState["Subject"].ToString(); }
        set { this.ViewState["Subject"] = value; }
    }
    /// <summary>
    /// Restituisce o imposta l'autore dell'attività
    /// </summary>
    [Bindable(BindableSupport.Yes, BindingDirection.TwoWay)]
    public string Author 
    {
        get { return this.ViewState["Author"].ToString(); }
        set { this.ViewState["Author"] = value; }
    }
    /// <summary>
    /// Restituisce o imposta a descrizione dell'attività
    /// </summary>
    [Bindable(BindableSupport.Yes, BindingDirection.TwoWay)]
    public string Description
    {
        get { return this.ViewState["Description"].ToString(); }
        set { this.ViewState["Description"] = value; }
    }
    /// <summary>
    /// Restituisce o imposta la data e l'ora di inizio dell'attività
    /// </summary>
    [Bindable(BindableSupport.Yes, BindingDirection.TwoWay)]
    public DateTime Start
    {
        get { return Convert.ToDateTime(this.ViewState["Start"]); }
        set { this.ViewState["Start"] = value; }
    }
    /// <summary>
    /// Restituisce o imposta la data e l'ora di fine dell'attività
    /// </summary>
    [Bindable(BindableSupport.Yes, BindingDirection.TwoWay)]
    public DateTime End
    {
        get { return Convert.ToDateTime(this.ViewState["End"]); }
        set { this.ViewState["End"] = value; }
    }
    /// <summary>
    /// Restituisce o imposta la regola di ripetizione dell'attività
    /// </summary>
    [Bindable(BindableSupport.Yes, BindingDirection.TwoWay)]
    public string RecurrenceRule
    {
        get { return this.ViewState["RecurrenceRule"].ToString(); }
        set { this.ViewState["RecurrenceRule"] = value; }
    }
    /// <summary>
    /// Restituisce o imposta la regole di promemoria dell'attività
    /// </summary>
    [Bindable(BindableSupport.Yes, BindingDirection.TwoWay)]
    public string Reminders
    {
        get { return this.ViewState["Reminders"].ToString(); }
        set { this.ViewState["Reminders"] = value; }
    }
     
    And this are the three events in ASPX code behind

    protected void Scheduler_AppointmentUpdate(object sender, AppointmentUpdateEventArgs e)
    {
        SchedulerTask taskToEdit = Scheduler[Convert.ToInt32(e.Appointment.ID)];
        taskToEdit.Comments = e.ModifiedAppointment.Description;
        taskToEdit.StartTime = e.ModifiedAppointment.Start;
        taskToEdit.EndTime = e.ModifiedAppointment.End;
        taskToEdit.Subject = e.ModifiedAppointment.Subject;
        taskToEdit.Tipologia = e.ModifiedAppointment.Resources.GetResourceByType("Tipologia") != null ?
            (TipologiaTask)Convert.ToInt32(e.ModifiedAppointment.Resources.GetResourceByType("Tipologia").Key) : TipologiaTask.Varie_Note;
        taskToEdit.Reminder = e.ModifiedAppointment.Reminders.ToString();
        taskToEdit.Recurrence = e.ModifiedAppointment.RecurrenceRule;
        taskToEdit.RecurrenceParentID = e.ModifiedAppointment.RecurrenceParentID;
        taskToEdit.Stato = StatoTask.MODIFICA;
          
        taskToEdit.Salva();
        this.schGestioneLocazioni.DataSource = Scheduler.CopyToDataTable();
    }
     
    protected void Scheduler_AppointmentInsert(object sender, AppointmentInsertEventArgs e)
    {
        try
        {
            // recupero la tipologia selezionata dall'utente tramite la finestra modale di editing
            // se non ha impostato nulla imposto io una tipologia di default
            TipologiaTask tipologia = e.Appointment.Resources.GetResourceByType("Tipologia") == null ?
                TipologiaTask.Property_Management_Note : (TipologiaTask)Convert.ToInt32(e.Appointment.Resources.GetResourceByType("Tipologia").Key);
              
            string autore = e.Appointment.Attributes["Autore"] == null ?
                SchedulerConstants.Autori.SCH_AUTORE_SYS : e.Appointment.Attributes["Autore"].ToString();
     
     
            SchedulerTask taskToAdd = Scheduler.NewSchedulerTask(
                                        e.Appointment.Subject,                  // oggetto
                                        e.Appointment.Description,              // descrizione
                                        e.Appointment.Start,                    // inizio
                                        e.Appointment.End,                      // fine
                                        tipologia,                              // tipologia
                                        e.Appointment.Reminders.ToString(),     // promemoria (basta fare il ToString della Collection e ottengo il reminder formattato
                                        e.Appointment.RecurrenceRule,           // regola di ricorrenza   
                                        e.Appointment.RecurrenceParentID,       // parent ID
                                        StatoTask.INSERIMENTO,
                                        SchedulerTaskAvvisato.NO,
                                        autore,
                                        DateTime.Now);
     
     
            Scheduler.Add(taskToAdd);
            this.schGestioneLocazioni.DataSource = Scheduler.CopyToDataTable();
            RadAjaxManager.GetCurrent(this).Alert("Appointment was inserted successfully.");
        }
        catch (SqlForeignKeyConstraintException ex)
        {
            RadAjaxManager.GetCurrent(this).Alert(ex.Message);
        }
        catch (SqlException ex)
        {
            RadAjaxManager.GetCurrent(this).Alert(ex.Message);
        }
        catch (Exception)
        {
            RadAjaxManager.GetCurrent(this).Alert(MessaggiException.Exception);
        }
    }
     
     
    protected void Scheduler_AppointmentCommand(object sender, AppointmentCommandEventArgs e)
    {
        Control SchedulerAdvancedForm;
        switch (e.CommandName.ToLower())
        {
            case "insert":
                SchedulerAdvancedForm = e.Container.FindControl("advTemplateInsert"); break;
            case "update":
                Scheduler.ReadTasks();  // rileggo per avere eventuali nuove task inserite sul db
                SchedulerAdvancedForm = e.Container.FindControl("advTemplateEdit"); break;
            default:
                SchedulerAdvancedForm = e.Container.FindControl("advTemplateInsert"); break;
        }
     
        if (SchedulerAdvancedForm != null)
        {
            e.Container.Appointment.Subject = ((RadTextBox)SchedulerAdvancedForm.FindControl("txtAdvInsertSubject")).Text;
            e.Container.Appointment.Description = ((RadTextBox)SchedulerAdvancedForm.FindControl("txtAdvInsertDescription")).Text;
            e.Container.Appointment.Attributes["Autore"] = ((RadTextBox)SchedulerAdvancedForm.FindControl("txtAdvInsertAuthor")).Text;
            e.Container.Appointment.Start = ((RadDateTimePicker)SchedulerAdvancedForm.FindControl("rtpAdvInsertStartTime")).SelectedDate.Value;
            e.Container.Appointment.End = ((RadDateTimePicker)SchedulerAdvancedForm.FindControl("rtpAdvInsertEndTime")).SelectedDate.Value;
              
        }
    }

    Where I wrong?

    Best Regards
  2. Plamen
    Admin
    Plamen avatar
    2933 posts

    Posted 06 Sep 2011 Link to this post

    Hi Lasly,

    I inspected the code that you send but unfortunately could not find out where the problem comes from. Here is an example project that shows how the Update method is working.

    Hope this will be helpful.

    Regards,
    Plamen Zdravkov
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Back to Top