Click here to Skip to main content
15,886,864 members
Articles / Web Development / HTML

DayPilot Gantt Chart for ASP.NET

Rate me:
Please Sign up or sign in to vote.
4.85/5 (21 votes)
21 Mar 2016Apache3 min read 99.3K   4.2K   62  
How to display AJAX Gantt Chart in ASP.NET application.
'
'Copyright � 2010 - 2013 Annpoint, s.r.o.
'
'Licensed under the Apache License, Version 2.0 (the "License");
'you may not use this file except in compliance with the License.
'You may obtain a copy of the License at
'
'http://www.apache.org/licenses/LICENSE-2.0
'
'Unless required by applicable law or agreed to in writing, software
'distributed under the License is distributed on an "AS IS" BASIS,
'WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
'See the License for the specific language governing permissions and
'limitations under the License.
'
'-------------------------------------------------------------------------
'
'NOTE: Reuse requires the following acknowledgement (see also NOTICE):
'This product includes DayPilot (http://www.daypilot.org) developed by Annpoint, s.r.o.
'

Imports System
Imports System.Data
Imports System.Reflection
Imports System.Web.UI
Imports PropertyAttributes = System.Data.PropertyAttributes

Namespace Util
	Public Class Binder
		Public Shared Function [Get](ByVal o As Object, ByVal [property] As String) As DataItem
			If TypeOf o Is DataRow Then
				Dim dr As DataRow = CType(o, DataRow)
				Return New DataItem() With {.Source = dr([property])}
			End If
			Return New DataItem() With {.Source = ReadPropertyValue(o, [property])}

		End Function

		Private Shared Function ReadPropertyValue(ByVal o As Object, ByVal [property] As String) As Object
			Dim type As Type = o.GetType()
			Dim pi As PropertyInfo = type.GetProperty([property])
			If pi IsNot Nothing Then
				Return pi.GetValue(o, Nothing)
			Else ' try to read using indexed property
				Dim mi As MethodInfo = type.GetMethod("get_Item", New Type() {GetType(String)})
				If mi IsNot Nothing Then
					Return mi.Invoke(o, New Object() {[property]})
				End If
			End If

			Throw New ArgumentException("Property or index not found.")
		End Function

		Public Shared Function [Get](ByVal value As Object) As DataItem
			Return New DataItem() With {.Source = value}
		End Function

		Public Class DataItem
			Friend Source As Object

			Public ReadOnly Property [Object]() As Object
				Get
					If Source Is DBNull.Value Then
						Return Nothing
					End If
					Return Source
				End Get
			End Property
			Public ReadOnly Property [String]() As String
				Get
					If Source Is DBNull.Value OrElse Source Is Nothing Then
						Return Nothing
					End If
					Return Convert.ToString(Source)
				End Get
			End Property

            Public ReadOnly Property [Date]() As Date?
                Get
                    If Source Is DBNull.Value OrElse Source Is Nothing Then
                        Return Nothing
                    End If
                    If TypeOf Source Is String AndAlso CStr(Source) = [String].Empty Then
                        Return Nothing
                    End If
                    Return Convert.ToDateTime(Source)
                End Get
            End Property

			Public ReadOnly Property Int32() As Integer?
				Get
					If Source Is DBNull.Value OrElse Source Is Nothing Then
						Return Nothing
					End If
					If TypeOf Source Is String AndAlso CStr(Source) = [String].Empty Then
						Return Nothing
					End If
					Return Convert.ToInt32(Source)
				End Get
			End Property

			Public ReadOnly Property [Double]() As Double?
				Get
					If Source Is DBNull.Value OrElse Source Is Nothing Then
						Return Nothing
					End If
					If TypeOf Source Is String AndAlso CStr(Source) = [String].Empty Then
						Return Nothing
					End If
					Return Convert.ToDouble(Source)
				End Get
			End Property

			Public ReadOnly Property IsNull() As Boolean
				Get
					Return Source Is Nothing OrElse Source Is DBNull.Value
				End Get
			End Property

			Public ReadOnly Property IsNotNull() As Boolean
				Get
					Return Not IsNull
				End Get
			End Property

			Public ReadOnly Property TimeSpanFromMinutes() As TimeSpan
				Get
					If IsNull Then
						Return TimeSpan.Zero
					End If
					Return TimeSpan.FromMinutes(CDbl([Double]))
				End Get
			End Property
		End Class

	End Class


End Namespace

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Apache License, Version 2.0


Written By
Czech Republic Czech Republic
My open-source event calendar/scheduling web UI components:

DayPilot for JavaScript, Angular, React and Vue

Comments and Discussions