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

Custom field does not recover

0 Answers 7 Views
Scheduler and Reminder
This is a migrated thread and some comments may be shown as answers.
Emmanuel
Top achievements
Rank 1
Emmanuel asked on 17 Oct 2018, 06:18 PM

Hello,

I've gone through the tutorial here: https://docs.telerik.com/devtools/winforms/scheduler/appointments-and-dialogs/adding-a-custom-field-to-the-editappointment-dialog

I have been able to add my custom field to the scheduler, however, when I save the appointment and edit the same appointment again, the value I put in the "IdPaciente" field is not recovered, it simply recovers the empty value.
But if you are saving in the database the field "IdPaciente"
I'm seeing that in the LoadSettingsFromEvent method, IEvent the custom field retrieves empty. 
What am I doing wrong, could you help me please?

 public partial class CustomAppointmentEditForm: Telerik.WinControls.UI.Scheduler.Dialogs.EditAppointmentDialog
    {
        public CustomAppointmentEditForm()
        {
            InitializeComponent();
        }

        protected override void LoadSettingsFromEvent(IEvent ev)
        {
            base.LoadSettingsFromEvent(ev);
            AppointmentWithIdPaciente appointmentWithIdPaciente = ev as AppointmentWithIdPaciente;

            if(appointmentWithIdPaciente != null)
            {
                radTextBoxIdPaciente.Text = appointmentWithIdPaciente.IdPaciente;
            }
        }

        protected override void ApplySettingsToEvent(IEvent ev)
        {
            AppointmentWithIdPaciente appointmentWithIdPaciente = ev as AppointmentWithIdPaciente;
            if(appointmentWithIdPaciente != null)
            {
                appointmentWithIdPaciente.IdPaciente = radTextBoxIdPaciente.Text;
            }
            base.ApplySettingsToEvent(ev);
        }
        protected override IEvent CreateNewEvent()
        {
            return new AppointmentWithIdPaciente();
        }
    }
}


    public class AppointmentWithIdPaciente : Appointment
    {
        public AppointmentWithIdPaciente() : base()
        {
        }

        protected override Event CreateOccurrenceInstance()
        {
            return new AppointmentWithIdPaciente();
        }

        string _IdPaciente = string.Empty;

        public string IdPaciente
        {
            get 
            { 
                return this._IdPaciente; 
            }
            set 
            {
                if (this._IdPaciente != value)
                {
                    this._IdPaciente = value;
                    OnPropertyChanged("IdPaciente");
                }
            }
        }
    }
}


    public class AppointmentWithIdPacienteFactory : IAppointmentFactory
    {
        public IEvent CreateNewAppointment()
        {
            return new AppointmentWithIdPaciente();
        }
    }


 public partial class radForm1 : Telerik.WinControls.UI.RadForm
    {
        public radForm1()
        {
            InitializeComponent();

         
            this.radScheduler1.AppointmentFactory = new AppointmentWithIdPacienteFactory();
            SchedulerBindingDataSource dataSource = this.schedulerBindingDataSource1;
            dataSource.EventProvider.AppointmentFactory = this.radScheduler1.AppointmentFactory;

            AppointmentMappingInfo appointmentMappingInfo = (AppointmentMappingInfo)dataSource.EventProvider.Mapping;
            appointmentMappingInfo.Mappings.Add(new SchedulerMapping("IdPaciente", "IdPaciente"));

            schedulerBindingDataSource1.EventProvider.DataSource = this.testDataSet.Appointments;
            this.radScheduler1.DataSource = dataSource;
            schedulerBindingDataSource1.EventProvider.Mapping = appointmentMappingInfo;
           
            AppointmentsTableAdapter appointmentsTableAdapter = new AppointmentsTableAdapter();
            appointmentsTableAdapter.Fill(testDataSet.Appointments);

            ResourcesTableAdapter resourcesTableAdapter = new ResourcesTableAdapter();
            resourcesTableAdapter.Fill(testDataSet.Empleados);

            AppointmentsResourcesTableAdapter appointmentsResourcesTableAdapter = new AppointmentsResourcesTableAdapter();
            appointmentsResourcesTableAdapter.Fill(testDataSet.AppointmentsResources);

            radScheduler1.GroupType = GroupType.Resource;
             
            this.schedulerBindingDataSource1.Rebind();
        }


 CustomAppointmentEditForm appointmentDialog = null;
        private void radScheduler1_AppointmentEditDialogShowing(object sender, AppointmentEditDialogShowingEventArgs e)
        {
            if(this.appointmentDialog == null)
            {
                this.appointmentDialog = new CustomAppointmentEditForm();
            }
            e.AppointmentEditDialog = this.appointmentDialog;
        }
   private void radButtonSave_Click(object sender, EventArgs e)
        {
            AppointmentsTableAdapter appointmentsTableAdapter = new AppointmentsTableAdapter();
            AppointmentsResourcesTableAdapter appointmentsResourcesTableAdapter = new AppointmentsResourcesTableAdapter();

            TestDataSet.AppointmentsResourcesDataTable deletedChildRecords = 
                this.testDataSet.AppointmentsResources.GetChanges(DataRowState.Deleted)
                as TestDataSet.AppointmentsResourcesDataTable;

            TestDataSet.AppointmentsResourcesDataTable newChildRecords =
              this.testDataSet.AppointmentsResources.GetChanges(DataRowState.Added)
              as TestDataSet.AppointmentsResourcesDataTable;

            TestDataSet.AppointmentsResourcesDataTable modifiedChildRecords =
            this.testDataSet.AppointmentsResources.GetChanges(DataRowState.Modified)
            as TestDataSet.AppointmentsResourcesDataTable;

            try
            {
                if (deletedChildRecords != null)
                {
                    appointmentsResourcesTableAdapter.Update(deletedChildRecords);
                }
                appointmentsTableAdapter.Update(this.testDataSet.Appointments);

                if (newChildRecords != null)
                {
                    appointmentsResourcesTableAdapter.Update(newChildRecords);
                }

                if(modifiedChildRecords != null)
                {
                    appointmentsResourcesTableAdapter.Update(modifiedChildRecords);
                }

                this.testDataSet.AcceptChanges();
                
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (deletedChildRecords != null)
                    deletedChildRecords.Dispose();

                if (newChildRecords != null)
                    newChildRecords.Dispose();

                if (modifiedChildRecords != null)
                    modifiedChildRecords.Dispose();

            }
        }

No answers yet. Maybe you can help?

Tags
Scheduler and Reminder
Asked by
Emmanuel
Top achievements
Rank 1
Share this question
or