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

Urgent! Can't save appointment changes to appointment object

4 Answers 60 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Steven asked on 24 Jul 2012, 09:51 PM
I have a major client issue and I'm days away from UAT.

I'm using the code below to save the information back to the appointment object when I click Save on the Advanced Form.  The problem is, when I open the appointment again, none of my changes persist. 

I have a feeling that this is due to my scheduler not being tied to a datasource.  Currently, I have a class that creates fake data and sends it to the scheduler on load.  The scheduler is not tied to a datasource because I would like to manipulate the schedule and make many changes, then batch them up and send them to the database at one time.  My plan is to iterate through the calendar and find any events that had changes and send them to my update/insert. 

To recap, my problems are:
- The changes are not getting saved to my appointment object
- Is it possible to send all of the changes to the database at once, instead of every time save is pressed?

Let me know what other code you need to help.

protected void Page_Load(object sender, EventArgs e)
            if (!Page.IsPostBack)
                ProductionRunMock productionRunBL = new ProductionRunMock();
                List<ProductionRun> productionRuns = productionRunBL.GetProductionRuns();
                schMasterScheduler.DataSource = productionRuns;
                schMasterScheduler.GroupBy = ddlPlant.SelectedValue.ToString();

protected void schMasterScheduler_AppointmentUpdate(object sender, AppointmentUpdateEventArgs e)
           //This event runs on click of save from the form. Therefore we need to check to see if it's an insert or update.
           //moveAppointsRight(e.ModifiedAppointment, e.Appointment);
           //pull all the controls out of session so we can find their values
           RadComboBox ddlMatereial = Session["ddlMaterial"] as RadComboBox;
           RadTextBox txtBatchNumber = Session["txtBatchNumber"] as RadTextBox;
           RadNumericTextBox txtBatchSize = Session["txtBatchSize"] as RadNumericTextBox;
           RadComboBox ddlUnitOfMeasure = Session["ddlUnitOfMeasure"] as RadComboBox;
           RadDateTimePicker dtpStartDateTime = Session["dtpStartDateTime"] as RadDateTimePicker;
           RadNumericTextBox txtDuration = Session["txtDuration"] as RadNumericTextBox;
           RadDateTimePicker dtpEndDateTime = Session["dtpEndDateTime"] as RadDateTimePicker;
           ResourceControl ResVessel = Session["ResVessel"] as ResourceControl;
           CheckBox cbNonProdTime = Session["cbNonProdTime"] as CheckBox;
           RadDatePicker calShippingDate = Session["calShippingDate"] as RadDatePicker;
           RadTextBox txtWashPrep = Session["txtWashPrep"] as RadTextBox;
           RadComboBox ddlPriority = Session["ddlPriority"] as RadComboBox;
           CheckBox cbWorkOff = Session["cbWorkOff"] as CheckBox;
           CheckBox cbLocked = Session["cbLocked"] as CheckBox;
           RadTextBox txtRawMaterialDependency = Session["txtRawMaterialDependency"] as RadTextBox;
           RadTextBox txtComments = Session["txtComments"] as RadTextBox;
           Repeater rtpContainering = Session["rptContainering"] as Repeater;
           RadComboBox ddlContainerType = Session["ddlContainerType"] as RadComboBox;
           RadTextBox txtContainerQuantity = Session["txtContainerQuantity"] as RadTextBox;
           //write the values of the controls into the appointment object
           e.ModifiedAppointment.Subject = ddlMatereial.SelectedValue;
           e.ModifiedAppointment.Start = Convert.ToDateTime(dtpStartDateTime.SelectedDate);
           e.ModifiedAppointment.End = Convert.ToDateTime(dtpEndDateTime.SelectedDate);
           e.ModifiedAppointment.Attributes["BatchNumber"] = txtBatchNumber.Text;
           e.ModifiedAppointment.Attributes["UnitOfMeasure"] = ddlUnitOfMeasure.SelectedValue;
           e.ModifiedAppointment.Attributes["BatchSize"] = txtBatchSize.Text;
           e.ModifiedAppointment.Attributes["NonProdTime"] = (cbNonProdTime.Checked) ? "true" : "false";
           e.ModifiedAppointment.Attributes["ShipDate"] = Convert.ToDateTime(calShippingDate.SelectedDate).ToShortDateString();
           e.ModifiedAppointment.Attributes["WashPrep"] = txtWashPrep.Text;
           e.ModifiedAppointment.Attributes["Priority"] = ddlPriority.SelectedValue;
           e.ModifiedAppointment.Attributes["WorkOff"] = (cbWorkOff.Checked) ? "true" : "false";
           e.ModifiedAppointment.Attributes["RawMaterialDependency"] = txtRawMaterialDependency.Text;
           e.ModifiedAppointment.Attributes["Comments"] = txtComments.Text;
           e.ModifiedAppointment.Attributes["IsLocked"] = (cbLocked.Checked) ? "true" : "false";
           e.ModifiedAppointment.Attributes["IsDirty"] = "true";
           //e.Appointment.Resources[0] = Convert.ToInt32(e.Appointment.Resources.GetResourceByType(plantNumber.ToString()));

protected void schMasterScheduler_FormCreated(object sender, SchedulerFormCreatedEventArgs e)
      //gets all of the fields
      //required fields
      RadComboBox ddlMaterial = e.Container.FindControl("ddlMaterial") as RadComboBox;
      RadTextBox txtBatchNumber = e.Container.FindControl("txtBatchNumber") as RadTextBox;
      RadNumericTextBox txtBatchSize = e.Container.FindControl("txtBatchSize") as RadNumericTextBox;
      RadComboBox ddlUnitOfMeasure = e.Container.FindControl("ddlUnitOfMeasure") as RadComboBox;
      RadDateTimePicker dtpStartDateTime = e.Container.FindControl("dtpStartDateTime") as RadDateTimePicker;
      RadNumericTextBox txtDuration = e.Container.FindControl("txtDuration") as RadNumericTextBox;
      RadDateTimePicker dtpEndDateTime = e.Container.FindControl("dtpEndDateTime") as RadDateTimePicker;
      ResourceControl resVessel = e.Container.FindControl("ResVessel") as ResourceControl;
      CheckBox cbNonProdTime = e.Container.FindControl("cbNonProdTime") as CheckBox;
      Label lblError = e.Container.FindControl("lblError") as Label;
      //optional fields
      Panel pnlNonProdOrder = e.Container.FindControl("pnlNonProdOrder") as Panel;
      RadDatePicker calShippingDate = e.Container.FindControl("calShippingDate") as RadDatePicker;
      RadTextBox txtWashPrep = e.Container.FindControl("txtWashPrep") as RadTextBox;
      RadComboBox ddlPriority = e.Container.FindControl("ddlPriority") as RadComboBox;
      CheckBox cbWorkOff = e.Container.FindControl("cbWorkOff") as CheckBox;
      CheckBox cbLocked = e.Container.FindControl("cbLocked") as CheckBox;
      RadTextBox txtRawMaterialDependency = e.Container.FindControl("txtRawMaterialDependency") as RadTextBox;
      RadTextBox txtComments = e.Container.FindControl("txtComments") as RadTextBox;
      Repeater rptContainering = e.Container.FindControl("rptContainering") as Repeater;
      RadComboBox ddlContainerType = e.Container.FindControl("ddlContainerType") as RadComboBox;
      TextBox txtContainerQuantity = e.Container.FindControl("txtContainerQuantity") as TextBox;
      //add the controls to session that we need in other places
      Session["ddlMaterial"] = ddlMaterial;
      Session["txtBatchNumber"] = txtBatchNumber;
      Session["txtBatchSize"] = txtBatchSize;
      Session["ddlUnitOfMeasure"] = ddlUnitOfMeasure;
      Session["dtpStartDateTime"] = dtpStartDateTime;
      Session["txtDuration"] = txtDuration;
      Session["dtpEndDateTime"] = dtpEndDateTime;
      Session["ResVessel"] = resVessel;
      Session["cbNonProdTime"] = cbNonProdTime;
      Session["lblError"] = lblError;
      Session["pnlNonProdOrder"] = pnlNonProdOrder;
      Session["calShippingDate"] = calShippingDate;
      Session["txtWashPrep"] = txtWashPrep;
      Session["ddlPriority"] = ddlPriority;
      Session["cbWorkOff"] = cbWorkOff;
      Session["cbLocked"] = cbLocked;
      Session["txtRawMaterialDependency"] = txtRawMaterialDependency;
      Session["txtComments"] = txtComments;
      Session["rptContainering"] = rptContainering;
      Session["ddlContainerType"] = ddlContainerType;
      Session["txtContainerQuantity"] = txtContainerQuantity;
      //load materials drop down
      LoadMaterialsDropdown(ddlMaterial, plantNumber);
      //fill the form out with the information from appointment object
      if (ViewState["mode"].ToString() == "update")
          ddlMaterial.SelectedValue = e.Appointment.Subject;
          txtBatchNumber.Text = e.Appointment.Attributes["BatchNumber"];
          txtBatchSize.Text = e.Appointment.Attributes["BatchSize"];
          ddlUnitOfMeasure.SelectedValue = e.Appointment.Attributes["UnitOfMeasure"];
          txtDuration.Text = e.Appointment.End.Subtract(e.Appointment.Start).TotalHours.ToString();
          cbNonProdTime.Checked = (e.Appointment.Attributes["NonProdTime"].ToLower() == "true") ? true : false;
          calShippingDate.SelectedDate = DateTime.Parse(e.Appointment.Attributes["ShipDate"]);
          txtWashPrep.Text = e.Appointment.Attributes["WashPrep"];
          cbWorkOff.Checked = (e.Appointment.Attributes["WorkOff"].ToLower() == "true") ? true : false;
          cbLocked.Checked = (e.Appointment.Attributes["IsLocked"].ToLower() == "true") ? true : false;
          txtRawMaterialDependency.Text = e.Appointment.Attributes["RawMaterialDependency"];
          txtComments.Text = e.Appointment.Attributes["Comments"];
          ddlPriority.SelectedValue = e.Appointment.Attributes["Priority"];
          //enable/diable fields based on nonProdTime
          //redo this part with the container information
          //mock up the containers to fill the middle section of the popup
          ContainersMock containerBL = new ContainersMock();
          List<Container> containers = containerBL.GetContainers();
          rptContainering.DataSource = containers;
      else if (ViewState["mode"].ToString() == "insert")

4 Answers, 1 is accepted

Sort by
Telerik team
answered on 25 Jul 2012, 02:12 PM
Hello Steven,

Please, follow the approach used in the Bind to List demo. Once you bind RadScheduler successfully, please don't use the advanced form templates, but check if everything is working fine with the default advanced form. If yes, then you can proceed customizing it using the Templates demo or the Customizing the Advanced Insert and Edit Forms demo.

All the best, Peter
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Top achievements
Rank 1
answered on 25 Jul 2012, 09:43 PM
So far so good...My next question is around custom attributes.  As you can see in the code, I'm using my own appointment object called ProductionRun.  For all of the primitive types there is no problem. 

However, if I do e.Appointment.Attributes["Contianer"], I get System.Collections.Generic.List`1[Capgemini.Gateway.BusinessLayer.Model.Container].

How do I access the properties which are objects (Container, Priority, UnitOfMeasure)?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Gateway.BusinessLayer.Model
    public class ProductionRun
        public int ID { get; set; }
        public string BatchNumber { get; set; }
        public string Material { get; set; }
        public DateTime Start { get; set; }
        public DateTime End { get; set; }
        public TimeSpan Duration { get; set; }
        public int VesselID { get; set; }
        public double BatchSize { get; set; }
        //public UnitOfMeasure UnitOfMeasure { get; set; }
        public string UnitOfMeasure { get; set; }
        public DateTime? ShipDate { get; set; }
        public string WashPrep { get; set; }
        //public Priority Priority { get; set; }
        public int Priority { get; set; }
        public bool WorkOff { get; set; }       
        public string RawMaterialDependency { get; set; }
        public string Comments { get; set; }
        public string ContainerType { get; set; }
        public int ContainerQuantity { get; set; }
        public bool IsDirty { get; set; }
        public bool IsLocked { get; set; }
        public bool NonProdTime { get; set; }
        public List<Container> Containers { get; set; }
    public class Priority
        public int ID { get; set; }
        public string Description { get; set; }
        public Priority(int id, string description)
            ID = id;
            Description = description;
    public class UnitOfMeasure
        public int ID { get; set; }
        public string Description { get; set; }
        public UnitOfMeasure(int id, string description)
            ID = id;
            Description = description;
Top achievements
Rank 1
answered on 26 Jul 2012, 06:30 PM
Is there a way to do this?
Telerik team
answered on 27 Jul 2012, 01:53 PM
Hi Steven,

I don't think this is possible, since custom attributes for appointments can carry data of type string only.

the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Asked by
Top achievements
Rank 1
Answers by
Telerik team
Top achievements
Rank 1
Share this question