Page Index Toggle Pages: 1 [2]  Send TopicPrint
Hot Topic (More than 10 Replies) Not as easy as it sounds... (Read 14485 times)
lahai
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 17
Joined: May 13th, 2009
Re: Not as easy as it sounds...
Reply #15 - Jul 24th, 2009 at 6:35am
Print Post  
System.ArgumentException was unhandled
Message="Object of type 'System.Int16' cannot be converted to type 'System.Boolean'."
Source="System"
StackTrace:
at System.ComponentModel.ReflectPropertyDescriptor.SetValue(Object component, Object value)
at MindFusion.Scheduling.DataBinding.x8db18c2080b4ae64.xdf653366cdb56b9d(Object x337e217cb3ba0627, Object xaeebf6cdac58d859)
at MindFusion.Scheduling.DataBinding.x8db18c2080b4ae64.x9641f931b2968145(Object x1563b91fcacc4108)
at MindFusion.Scheduling.DataBinding.x8db18c2080b4ae64.x0d510b9a14a54e2f()
at MindFusion.Scheduling.DataBinding.xa7e178e5abda1bf4.xc278b192d73221db()
at MindFusion.Scheduling.WinForms.Calendar.LoadFromDataSource()
at Calendar1.Form1.Form1_Load(Object sender, EventArgs e) in C:\Documents and Settings\lahai\My Documents\Visual Studio 2005\Projects\calendar\Calendar1\Calendar1\Form1.vb:line 21
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicat
ionModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String
[] commandLine)
at Calendar1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Not as easy as it sounds...
Reply #16 - Jul 24th, 2009 at 8:41am
Print Post  
It seems there is no automatic conversion from integer to boolean during data-binding. What is it you expect as a result from such binding: 0 to be interpreted as false, everything else - as true?

Meppy
  
Back to top
 
IP Logged
 
lahai
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 17
Joined: May 13th, 2009
Re: Not as easy as it sounds...
Reply #17 - Jul 24th, 2009 at 10:05am
Print Post  
well thanks. Is there any info you can provide about how and where to do that?
  
Back to top
 
IP Logged
 
Harpoon
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 10
Joined: Nov 8th, 2009
Re: Not as easy as it sounds...
Reply #18 - Nov 10th, 2009 at 4:38pm
Print Post  
Meppy wrote on Jul 24th, 2009 at 8:41am:
It seems there is no automatic conversion from integer to boolean during data-binding. What is it you expect as a result from such binding: 0 to be interpreted as false, everything else - as true?

Meppy


I am also running into this issue with MySQL.  It seems MySQL saves boolean data types as TinyInt.

But, there is no implicit conversion from TinyInt (which in VS is a SmByte) to Boolean.  I would expect this to work as you describe above.  0's would return false and all other values true.

I suppose to get this to work properly the method Calendar.LoadFromDataSource would need to explicitly check for number data types and then convert them to boolean, unless there is a way that I am not aware of to change all the SmByte data formats that MySQL puts out to Boolean before calling the LoadFromDataSource method ???

Any help here would be appreciated.  We are beta-testing several schedule controls, really like Planner.NET, but this is holding us up from purchase.

Thanks in advance.
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Not as easy as it sounds...
Reply #19 - Nov 11th, 2009 at 9:16am
Print Post  
A new, preliminary build of the control can be downloaded from here:

https://mindfusion.eu/_pln_trial/MindFusion.Scheduling5.0f.zip

The Calendar.LoadFromDataSource method now exposes additional overload, which accepts an object of type IValueConverter as an argument. You can use this overload to specify explicit conversion for various data types during databinding. The following example illustrates how you can implement and use an IValueConverter:

Code
Select All
public class ByteToBoolConverter : IValueConverter
{
      public object Convert(object value, object destination, string destinationMember, Type destinationType)
      {
            if (value is byte && destinationType == typeof(bool))
                  return (byte)value != 0;

            return value;
      }

      public bool Supports(object value, object destination, string destinationMember, Type destinationType)
      {
            return value is byte && destinationType == typeof(bool);
      }
}

...

// Perform data loading using the converter
calendar1.LoadFromDataSource(new ByteToBoolConverter()); 


The implemented converter performs an unconditional conversion from byte to boolean. You might have to perform additional checks to see if this conversion is applicable for all values.

Let me know if this helps.

Regards,
Meppy
  
Back to top
 
IP Logged
 
Harpoon
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 10
Joined: Nov 8th, 2009
Re: Not as easy as it sounds...
Reply #20 - Nov 11th, 2009 at 10:40pm
Print Post  
Thanks for the quick support  Smiley

I will try it out and let you know.
  
Back to top
 
IP Logged
 
Harpoon
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 10
Joined: Nov 8th, 2009
Re: Not as easy as it sounds...
Reply #21 - Nov 12th, 2009 at 6:29pm
Print Post  
Harpoon wrote on Nov 11th, 2009 at 10:40pm:
Thanks for the quick support Smiley

I will try it out and let you know.


I have tried this and it works successfully. I am now able to save and load the database data to the calendar.

I will post my code in VB for anyone that is interested.

Create a class as follows:

Public Class Converter
Implements MindFusion.Scheduling.DataBinding.IValueConverter
Public Function Convert(ByVal value As Object, ByVal destination As Object, ByVal destinationMember As String, ByVal destinationType As System.Type) As Object Implements MindFusion.Scheduling.DataBinding.IValueConverter.Convert
If (TypeOf value Is SByte OrElse TypeOf value Is Byte) AndAlso destinationType Is GetType(Boolean) Then
Return CBool(value <> 0)
End If
Return value
End Function

Public Function Supports(ByVal value As Object, ByVal destination As Object, ByVal destinationMember As String, ByVal destinationType As System.Type) As Boolean Implements MindFusion.Scheduling.DataBinding.IValueConverter.Supports
If (TypeOf value Is SByte OrElse TypeOf value Is Byte) AndAlso destinationType Is GetType(Boolean) Then Return True
End Function
End Class

-------------

Use the overloaded method
_schedule.LoadFromDataSource(New Converter)

to load the data.

Thanks for your help on this issue.
  
Back to top
 
IP Logged
 
Harpoon
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 10
Joined: Nov 8th, 2009
Re: Not as easy as it sounds...
Reply #22 - Nov 12th, 2009 at 9:44pm
Print Post  
Here is a twist.

If I create a test appointment and then save to an empty database using.
_schedule.SaveToDataSource( _
ReminderTableAdapter1, _
StyleTableAdapter1, _
CustombrushesTableAdapter1, _
ContactTableAdapter1, _
LocationTableAdapter1, _
ResourceTableAdapter1, _
TaskTableAdapter1, _
ItemTableAdapter1, _
ItemcontactsTableAdapter1, _
ItemresourcesTableAdapter1, _
RecurrenceTableAdapter1, _
RecurrenceexceptionTableAdapter1, _
RecurrenceexceptionsTableAdapter1)

Then I repeat the Save using the same code above.

The Style table record does not get updated. Instead the original record is deleted and a new record is added. But, the item.style cell of the test appointment contains "1" which is a reference to the Style.Key record that was deleted. The only record in the Style table has Key = 2.

Then, if I try and load the data from the database using:
_schedule.Schedule.Clear()
PlannerDataSet.Clear()

ReminderTableAdapter1.Fill(PlannerDataSet.reminder)
StyleTableAdapter1.Fill(PlannerDataSet.style)
CustombrushesTableAdapter1.Fill(PlannerDataSet.custombrushes)
ContactTableAdapter1.Fill(PlannerDataSet.contact)
LocationTableAdapter1.Fill(PlannerDataSet.location)
ResourceTableAdapter1.Fill(PlannerDataSet.resource)
TaskTableAdapter1.Fill(PlannerDataSet.task)
ItemTableAdapter1.Fill(PlannerDataSet.item)
ItemcontactsTableAdapter1.Fill(PlannerDataSet.itemcontacts)
ItemresourcesTableAdapter1.Fill(PlannerDataSet.itemresources)
RecurrenceTableAdapter1.Fill(PlannerDataSet.recurrence)
RecurrenceexceptionTableAdapter1.Fill(PlannerDataSet.recurrenceexception)
RecurrenceexceptionsTableAdapter1.Fill(PlannerDataSet.recurrenceexceptions)

_schedule.LoadFromDataSource(New Converter)

Then I get a constraint error from the ItemAdapter1.fill method: Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.

I have checked that the one-to-many relationship between style.key and item.style is assigned.

Not sure what is going on here. Thoughts?
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Not as easy as it sounds...
Reply #23 - Nov 16th, 2009 at 3:03pm
Print Post  
I have made some modifications to the control which should fix this problem. The workaround is rather "ugly" at this point and we may think of a more intuitive API for the future.

First, you need to define a function which should attach an event handler to the RowUpdated event of the MySqlDataAdapter objects:

Code
Select All
Private Sub AttachRowUpdated(ByVal adapter As DataAdapter)

      AddHandler (CType(adapter, MySqlDataAdapter)).RowUpdated, AddressOf OnRowUpdated

End Sub 


The event handler should look similar to the following:

Code
Select All
Sub OnRowUpdated(ByVal sender As Object, ByVal e As MySqlRowUpdatedEventArgs)

      If (e.StatementType <> StatementType.Insert) Then
            Exit Sub
      End If

      Dim command As New MySqlCommand( _
            "SELECT LAST_INSERT_ID()", e.Command.Connection)
      Calendar1.UpdateRow(CType(sender, DataAdapter), e.Row, command)

End Sub 


Then you need to assign the AttachRowUpdated method to a new field defined in the Calendar class. Do this before calling SaveToDataSource:

Code
Select All
Calendar1.AttachRowUpdated = AddressOf AttachRowUpdated
' Save here 


Try this solution and let me know if it works.

Regards,
Meppy
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Not as easy as it sounds...
Reply #24 - Nov 16th, 2009 at 3:10pm
Print Post  
The new version can be downloaded from here:

https://mindfusion.eu/_pln_trial/MindFusion.Scheduling5.0.1.zip

Meppy
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1 [2] 
Send TopicPrint