Having an issue when adding custom objects onto the Appointment.tag as ExtendedAppointmentInfo. the appointment is saving to the SQL Appointments table, but upon loading the schedule back up the Appointment is not getting serialized and I get no error. How Do I enable exceptions in the serialize of Appointment objects so I can get a clue on what to be looking for. I do have my custom objects decorated as <serializable>.,
Thanks All!
Hi Aaron,
Thank you for contacting Infragistics Developer Support.
You can configure VS to break on all exceptions. In order to do this go to Debug, click Exceptions and then you could select Thrown for an entire category of exceptions, for example, Common Language Runtime Exceptions.
Let me know if you still have issues implementing this.
I don't know what I need to enable to be able to see errors when the winschedule is databinding existing appointments. I do not know why some appointments are not being shown when the dayview is loaded up. I have enabled all Common Language Runtime exceptions and still do not see an error. The appointment does save to the dayview control during runtime, and does persist back to the SQL appointmnents table, but doesn't get loaded back up into the dayview if I exit the test app and come back in. I need to see excepctions why that appointment with the custom properties I have added into the ExtendedAppointmentInfo are not being created.
I will also attach a video showing how my sample works on my machine.
Below is my SaveAppointment on the frmAppointmentDialog. I am using a custom appointment dialog, overriding the BeforeDisplayAppointmentDialog event (e.cancel = true then I show the appointment dialog form passing in the Calendarinfo and the Owner.)
Do you see anything wrong here on the SaveAppointment? Thanks for your help!
Private Sub SaveAppointment()
' Subject
Me.appointment.Subject = Me.txtSubject.Text
' Location
Me.appointment.Location = Me.cboLocation.Text
' StartDateTime
Try
Dim tempStartTime As DateTime = DateTime.Parse(Me.cboStartTime.Text)
Dim tempStartDate As DateTime = Me.dtpStartTime.Value
Me.appointment.StartDateTime = New DateTime(tempStartDate.Year, tempStartDate.Month, tempStartDate.Day, tempStartTime.Hour, tempStartTime.Minute, 0)
Catch
' If we couldn't successfully parse the date, revert to the time
' of the original, untouched appointment.
Me.appointment.StartDateTime = Me.oldAppointment.StartDateTime
End Try
' EndDateTime
Dim tempEndTime As DateTime = DateTime.Parse(Me.cboEndTime.Text)
Dim tempEndDate As DateTime = Me.dtpEndTime.Value
Me.appointment.EndDateTime = New DateTime(tempEndDate.Year, tempEndDate.Month, tempEndDate.Day, tempEndTime.Hour, tempEndTime.Minute, 0)
Me.appointment.EndDateTime = Me.oldAppointment.EndDateTime
' AllDayEvent
Me.appointment.AllDayEvent = Me.chkAllDayEvent.Checked
' Reminder
If Me.chkReminder.Checked Then
Me.appointment.Reminder.DisplayIntervalUnits = DisplayIntervalUnits.Minutes
Dim reminderDisplayInterval As TimeSpan = DirectCast(Me.cboReminder.SelectedItem.DataValue, TimeSpan)
Me.appointment.Reminder.DisplayInterval = reminderDisplayInterval.TotalMinutes
Me.appointment.Reminder.Enabled = True
Else
Me.appointment.Reminder = Nothing
End If
'Appointment Owner
appointment.Owner = Me.ApptOwner
' ExtendedAppointmentInfo
' First, see if the Appointment already has an ExtendedAppointmentInfo;
' if it does, we will continue to use it.
Dim info As ExtendedAppointmentInfo = Nothing
info = DirectCast(Me.appointment.Tag, ExtendedAppointmentInfo)
If info Is Nothing Then info = New ExtendedAppointmentInfo(Me.appointment)
''Appointment Preloaded.
'' Assign the value in the Label combo to the
'' ExtendedAppointmentInfo object's Label property
''testing commenting out this see if issue is Preloaded or not..
If Me.cboPreloaded.SelectedItem Is Nothing Then
info.Label = Nothing
info.Label = DirectCast(Me.cboPreloaded.SelectedItem.DataValue, AppointmentLabel)
If Me.cboPreloaded.SelectedIndex > 0 Then
' Assign the color for the label item to the BackColor property
' of the Appointment's Appearance.
' Me.appointment.Appearance.BackColor = info.Label.Color
Me.appointment.Appearance.ForeColor = SystemColors.WindowText
Me.appointment.Appearance.Reset()
'appointment Status
' Assign the value in the Label combo to the
' ExtendedAppointmentInfo object's Label property
If Me.cboStatus.SelectedItem Is Nothing Then
info.Status = Nothing
info.Status = DirectCast(Me.cboStatus.SelectedItem.DataValue, AppointmentStatus)
If Me.cboStatus.SelectedIndex > 0 Then
' Assign the barcolor for the AppointmnetStatus
Me.appointment.BarColor = info.Status.Color
'TrailerNum
info.TrailerNum = txtTrailerNum.Text
'Arrive and Depart times
info.ArriveTime = cboArriveTime.Value
info.DepartTime = cboDepartTime.Value
' Store the ExtendedAppointmentInfo object in the Appointment's Tag
Me.appointment.Tag = info
' Description
Me.appointment.Description = Me.txtDescription.Text
' If the appointment does not belong to the CalendarInfo's Appointments
' collection, we must clone it and add it.
If Not Me.isExistingAppointment Then
' Add the appointment
Dim apptAsClone As ICloneable = DirectCast(Me.appointment, ICloneable)
Dim addedAppointment As Appointment = Me.calendarInfo.Appointments.Add(DirectCast(apptAsClone.Clone(), Appointment))
' Update the member variable to reflect the fact that the Appointment
' now belongs to the CalendarInfo's Appointments collection, so we know
' not to add it again in the event that it is saved more than once in a
' dialog session.
Me.isExistingAppointment = Me.calendarInfo.Appointments.Contains(addedAppointment)
' Make sure the appointment was successfully added (i.e., the
' BeforeAppointmentAdded event was not canceled).
If (Me.isExistingAppointment) Then
' Reassign the member that holds a reference to the appointment
Me.appointment = addedAppointment
Me.oldAppointment = Me.appointment
End Sub
I am also using the WinScheduleMSSQLServerSupport class from the database sample. Seemed to work before I added the AppointmentStatus and AppointmentLabel custom classes into the extendedappointmnetinfo.
I have removed both custom objects from ExtendedAppointmentInfo and no luck still wont serialize the appointment upon loading. The only way the appointment will load back up from SQL table is if I do not store the Appointment.Tag = info on the SaveAppointment sub. Then and only then I am able to see the appointments load back up and get serialized back into the Dayview. I'm outta ideas here. Its got to be something simple.... Always is.. right?
Ok could it be an issue in the DataAdapterForAppointments? Is the AllProperties column defined correctly ?
Protected Overrides ReadOnly Property DataAdapterForAppointments() As SqlDataAdapter
Get
If Me._sqlDBDataAdapterForAppointments Is Nothing Then
Me._sqlDBDataAdapterForAppointments = New SqlDataAdapter()
' Configure the SELECT command
Dim selectCommandText As String = String.Format(WinScheduleMSSQLServerSupport.SELECT_APPOINTMENTS_TEMPLATE, WinScheduleMSSQLServerSupport.APPOINTMENTS_TABLE_NAME)
Me._sqlDBDataAdapterForAppointments.SelectCommand = New SqlCommand(selectCommandText, Me.Connection)
' Configure the INSERT command
Dim insertCommand As SqlCommand = New SqlCommand()
Dim commandTextTemplate As String = "INSERT INTO {0}(AllProperties, StartDateTime, EndDateTime, Subject, AllDayEvent, OwnerKey) VALUES (@AllProperties, @StartDateTime, @EndDateTime, @Subject, @AllDayEvent, @OwnerKey) SELECT AppointmentID, AllProperties, StartDateTime, EndDateTime, Subject, AllDayEvent, OwnerKey FROM {0} WHERE (AppointmentID = @@IDENTITY)"
insertCommand.CommandText = String.Format(commandTextTemplate, WinScheduleMSSQLServerSupport.APPOINTMENTS_TABLE_NAME)
insertCommand.Connection = Me.Connection
insertCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@AllProperties", System.Data.SqlDbType.VarBinary, 1024, "AllProperties"))
insertCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@StartDateTime", System.Data.SqlDbType.DateTime, 8, "StartDateTime"))
insertCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@EndDateTime", System.Data.SqlDbType.DateTime, 8, "EndDateTime"))
insertCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Subject", System.Data.SqlDbType.VarChar, 50, "Subject"))
insertCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@AllDayEvent", System.Data.SqlDbType.Bit, 1, "AllDayEvent"))
insertCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@OwnerKey", System.Data.SqlDbType.VarChar, 50, "OwnerKey"))
Me._sqlDBDataAdapterForAppointments.InsertCommand = insertCommand
' Configure the UPDATE command
Dim updateCommand As SqlCommand = New SqlCommand()
'Changed this update from = '' to IS NULL for all the AllProperties checks. 7-17-14
commandTextTemplate = "UPDATE {0} SET AllProperties = @AllProperties, StartDateTime = @StartDateTime, EndDateTime = @EndDateTime, Subject = @Subject, AllDayEvent = @AllDayEvent, OwnerKey = @OwnerKey WHERE (AppointmentID = @Original_AppointmentID) AND (AllDayEvent = @Original_AllDayEvent) AND (AllProperties = @Original_AllProperties OR @Original_AllProperties1 IS NULL AND AllProperties IS NULL) AND (EndDateTime = @Original_EndDateTime) AND (OwnerKey = @Original_OwnerKey OR @Original_OwnerKey1 IS NULL AND OwnerKey IS NULL) AND (StartDateTime = @Original_StartDateTime) AND (Subject = @Original_Subject) SELECT AppointmentID, AllProperties, StartDateTime, EndDateTime, Subject, AllDayEvent, OwnerKey FROM {0} WHERE (AppointmentID = @Original_AppointmentID)"
updateCommand.CommandText = String.Format(commandTextTemplate, WinScheduleMSSQLServerSupport.APPOINTMENTS_TABLE_NAME)
updateCommand.Connection = Me.Connection
updateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@AllProperties", System.Data.SqlDbType.VarBinary, 1024, "AllProperties"))
updateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@StartDateTime", System.Data.SqlDbType.DateTime, 8, "StartDateTime"))
updateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@EndDateTime", System.Data.SqlDbType.DateTime, 8, "EndDateTime"))
updateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Subject", System.Data.SqlDbType.VarChar, 50, "Subject"))
updateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@AllDayEvent", System.Data.SqlDbType.Bit, 1, "AllDayEvent"))
updateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@OwnerKey", System.Data.SqlDbType.VarChar, 50, "OwnerKey"))
updateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_AppointmentID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "AppointmentID", System.Data.DataRowVersion.Original, Nothing))
updateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_AllDayEvent", System.Data.SqlDbType.Bit, 1, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "AllDayEvent", System.Data.DataRowVersion.Original, Nothing))
updateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_AllProperties", System.Data.SqlDbType.VarBinary, 1024, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "AllProperties", System.Data.DataRowVersion.Original, Nothing))
updateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_AllProperties1", System.Data.SqlDbType.VarBinary, 1024, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "AllProperties", System.Data.DataRowVersion.Original, Nothing))
updateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_EndDateTime", System.Data.SqlDbType.DateTime, 8, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "EndDateTime", System.Data.DataRowVersion.Original, Nothing))
updateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_OwnerKey", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "OwnerKey", System.Data.DataRowVersion.Original, Nothing))
updateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_OwnerKey1", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "OwnerKey", System.Data.DataRowVersion.Original, Nothing))
updateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_StartDateTime", System.Data.SqlDbType.DateTime, 8, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "StartDateTime", System.Data.DataRowVersion.Original, Nothing))
updateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_Subject", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Subject", System.Data.DataRowVersion.Original, Nothing))
updateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Select_AppointmentID", System.Data.SqlDbType.Int, 4, "AppointmentID"))
Me._sqlDBDataAdapterForAppointments.UpdateCommand = updateCommand
' Configure the DELETE command
Dim deleteCommand As SqlCommand = New SqlCommand()
'CHnaged Delete command from = '' to IS NULL 7-17-14
commandTextTemplate = "DELETE FROM {0} WHERE (AppointmentID = @Original_AppointmentID) AND (AllDayEvent = @Original_AllDayEvent) AND (AllProperties = @Original_AllProperties OR @Original_AllProperties1 IS NULL AND AllProperties IS NULL) AND (EndDateTime = @Original_EndDateTime) AND (OwnerKey = @Original_OwnerKey OR @Original_OwnerKey1 IS NULL AND OwnerKey IS NULL) AND (StartDateTime = @Original_StartDateTime) AND (Subject = @Original_Subject)"
deleteCommand.CommandText = String.Format(commandTextTemplate, WinScheduleMSSQLServerSupport.APPOINTMENTS_TABLE_NAME)
deleteCommand.Connection = Me.Connection
deleteCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_AppointmentID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "AppointmentID", System.Data.DataRowVersion.Original, Nothing))
deleteCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_AllDayEvent", System.Data.SqlDbType.Bit, 1, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "AllDayEvent", System.Data.DataRowVersion.Original, Nothing))
deleteCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_AllProperties", System.Data.SqlDbType.VarBinary, 1024, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "AllProperties", System.Data.DataRowVersion.Original, Nothing))
deleteCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_AllProperties1", System.Data.SqlDbType.VarBinary, 1024, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "AllProperties", System.Data.DataRowVersion.Original, Nothing))
deleteCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_EndDateTime", System.Data.SqlDbType.DateTime, 8, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "EndDateTime", System.Data.DataRowVersion.Original, Nothing))
deleteCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_OwnerKey", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "OwnerKey", System.Data.DataRowVersion.Original, Nothing))
deleteCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_OwnerKey1", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "OwnerKey", System.Data.DataRowVersion.Original, Nothing))
deleteCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_StartDateTime", System.Data.SqlDbType.DateTime, 8, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "StartDateTime", System.Data.DataRowVersion.Original, Nothing))
deleteCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_Subject", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Subject", System.Data.DataRowVersion.Original, Nothing))
Me._sqlDBDataAdapterForAppointments.DeleteCommand = deleteCommand
Return Me._sqlDBDataAdapterForAppointments
End Get
End Property
Thank you for the provided code snipped.
What could be the reason for the issue is that the size of the AllProperties field might be too small. I tried using a varbinary(1024) field with ExtendedAppointmentInfo object as the tag and I wasn’t able to save the appointment. After removing the AppointmentStatus and AppointmentLabel properties I was able to save the appointment to the varbinary(1024) field. Then I tested the sample with varbinary(8000), which I was using previously, and everything worked fine.
So please try using a varbinary with bigger size (for example 8000) and try to save the appointment again.
Let me know if this suggestion fixes your issue.
Bingo! Went from varbinary 1024 to varbinary 8000 on the AllProperties field and now all extendedappointmentinfo is saving and serializing fine! Thanks so much for this solution!
Hi Aarron,
I am glad that your issue is resolved. Let me know if you have any additional questions on this matter.
Thank you for using Infragistics components.