Mini Kabibi Habibi

Current Path : C:/Users/Public/Documents/DXperience 13.1 Demos/WPF/VB/EditorsDemo.Wpf/
Upload File :
Current File : C:/Users/Public/Documents/DXperience 13.1 Demos/WPF/VB/EditorsDemo.Wpf/Utils.vb

Imports Microsoft.VisualBasic
Imports System
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Markup
Imports System.Windows.Data
Imports System.Collections
Imports System.ComponentModel
Imports DevExpress.XtraScheduler
Imports DevExpress.Xpf.Scheduler
Imports System.IO
Imports System.Xml.Serialization
Imports System.Windows.Media

Namespace EditorsDemo.Utils
	Public Class FormatWrapper
		Public Sub New()
		End Sub
		Public Sub New(ByVal name As String, ByVal format As String)
			FormatName = name
			FormatString = format
		End Sub
		Private privateFormatName As String
		Public Property FormatName() As String
			Get
				Return privateFormatName
			End Get
			Set(ByVal value As String)
				privateFormatName = value
			End Set
		End Property
		Private privateFormatString As String
		Public Property FormatString() As String
			Get
				Return privateFormatString
			End Get
			Set(ByVal value As String)
				privateFormatString = value
			End Set
		End Property
	End Class
	Public Class BaseKindHelper(Of T)
		Public Function GetEnumMemberList() As Array
			Return System.Enum.GetValues(GetType(T))
		End Function
	End Class
	Public Class ClickModeKindHelper
		Inherits BaseKindHelper(Of ClickMode)
	End Class
	Public Class TextWrappingKindHelper
		Inherits BaseKindHelper(Of TextWrapping)
	End Class
	Public Class ScrollBarVisibilityKindHelper
		Inherits BaseKindHelper(Of ScrollBarVisibility)
	End Class
	Public Class CharacterCasingKindHelper
		Inherits BaseKindHelper(Of CharacterCasing)
	End Class
	Public Class NullableToStringConverter
		Inherits MarkupExtension
		Implements IValueConverter
		Public Overrides Function ProvideValue(ByVal serviceProvider As IServiceProvider) As Object
			Return Me
		End Function
		Private nullString As String = "Null"
		#Region "IValueConverter Members"
		Private Function IValueConverter_Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert
			If value Is Nothing Then
				Return nullString
			End If
			Return value.ToString()
		End Function
		Private Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
			Throw New NotImplementedException()
		End Function
		#End Region
	End Class
	Public Class DecimalToConverter
		Inherits MarkupExtension
		Implements IValueConverter
		Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert
			Dim target As Type = TryCast(parameter, Type)
			If target Is Nothing Then
				Return value
			End If
			Return System.Convert.ChangeType(value, target, culture)
		End Function

		Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
			Return System.Convert.ToDecimal(value)
		End Function

		Public Overrides Function ProvideValue(ByVal serviceProvider As IServiceProvider) As Object
			Return Me
		End Function
	End Class

	Public Class IConvertibleConverter
		Implements IValueConverter
		Private privateToType As String
		Public Property ToType() As String
			Get
				Return privateToType
			End Get
			Set(ByVal value As String)
				privateToType = value
			End Set
		End Property
		Private privateFromType As String
		Public Property FromType() As String
			Get
				Return privateFromType
			End Get
			Set(ByVal value As String)
				privateFromType = value
			End Set
		End Property

		#Region "IValueConverter Members"

		Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert
			Dim target As Type = Type.GetType(ToType, False)
			If target Is Nothing Then
				Return value
			End If
			Return System.Convert.ChangeType(value, target, culture)
		End Function

		Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
			Dim target As Type = Type.GetType(FromType, False)
			If target Is Nothing Then
				Return value
			End If
			Return System.Convert.ChangeType(value, target, culture)
		End Function

		#End Region
	End Class

	Public NotInheritable Class SchedulerDataHelper
		Private Const ResourcePathData As String = "EditorsDemo.Data"

		Private Sub New()
		End Sub
		Public Shared Sub LoadTo(ByVal scheduler As SchedulerControl)
			Dim storage As SchedulerStorage = scheduler.Storage

			InitCustomAppointmentStatuses(storage)

			storage.AppointmentStorage.Mappings.AllDay = "AllDay"
			storage.AppointmentStorage.Mappings.Description = "Description"
			storage.AppointmentStorage.Mappings.End = "EndTime"
			storage.AppointmentStorage.Mappings.Label = "Label"
			storage.AppointmentStorage.Mappings.Location = "Location"
			storage.AppointmentStorage.Mappings.RecurrenceInfo = "RecurrenceInfo"
			storage.AppointmentStorage.Mappings.ReminderInfo = "ReminderInfo"
			storage.AppointmentStorage.Mappings.Start = "StartTime"
			storage.AppointmentStorage.Mappings.Status = "Status"
			storage.AppointmentStorage.Mappings.Subject = "Subject"
			storage.AppointmentStorage.Mappings.Type = "Type"

			scheduler.Storage.AppointmentStorage.DataSource = LoadFromXml(Of EventItem)("Events.xml")
		End Sub

		Private Shared Sub InitCustomAppointmentStatuses(ByVal storage As SchedulerStorage)
			storage.BeginUpdate()
			Try
				Dim statuses As AppointmentStatusCollection = storage.AppointmentStorage.Statuses
				statuses.Clear()
				statuses.Add(New AppointmentStatus(AppointmentStatusType.Free, Colors.White, "Free", "Free"))
				statuses.Add(New AppointmentStatus(AppointmentStatusType.Custom, Colors.SkyBlue, "Wash", "Wash"))
				statuses.Add(New AppointmentStatus(AppointmentStatusType.Custom, Colors.SteelBlue, "Maintenance", "Maintenance"))
				statuses.Add(New AppointmentStatus(AppointmentStatusType.Custom, Colors.YellowGreen, "Rent", "Rent"))
				statuses.Add(New AppointmentStatus(AppointmentStatusType.Custom, Colors.Coral, "CheckUp", "CheckUp"))
			Finally
				storage.EndUpdate()
			End Try
		End Sub

		Private Shared Function LoadFromXml(Of T As New)(ByVal fileName As String) As IBindingList
			Dim eventList As New SchedulerBindingList(Of T)()
			Using stream As Stream = GetDataStream(fileName)
				Dim s As New XmlSerializer(GetType(SchedulerBindingList(Of T)))
				eventList = CType(s.Deserialize(stream), SchedulerBindingList(Of T))
				stream.Close()
			End Using
			Return eventList
		End Function
		Private Shared Function GetDataStream(ByVal fileName As String) As Stream
			Return GetResourceStream(ResourcePathData, fileName)
		End Function
		Private Shared Function GetResourceStream(ByVal resourcePath As String, ByVal resourceName As String) As Stream
			Dim fullResourceName As String = String.Format("{0}.{1}", resourcePath, resourceName)
			Dim result As Stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(fullResourceName)
			If result IsNot Nothing Then
				Return result
			End If
			Return System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)
		End Function
	End Class
	#Region "SchedulerBindingList"
	Public Class SchedulerBindingList(Of T As New)
		Inherits CollectionBase
		Implements IBindingList
		Default Public ReadOnly Property Item(ByVal idx As Integer) As T
			Get
				Return CType(MyBase.List(idx), T)
			End Get
		End Property

		Public Sub Add(ByVal appointment As T)
			MyBase.List.Add(appointment)
		End Sub
		Public Overridable Function AddNew() As Object Implements IBindingList.AddNew
			Dim newItem As New T()
			List.Add(newItem)
			Return newItem
		End Function
		Public ReadOnly Property AllowEdit() As Boolean Implements IBindingList.AllowEdit
			Get
				Return True
			End Get
		End Property
		Public ReadOnly Property AllowNew() As Boolean Implements IBindingList.AllowNew
			Get
				Return True
			End Get
		End Property
		Public ReadOnly Property AllowRemove() As Boolean Implements IBindingList.AllowRemove
			Get
				Return True
			End Get
		End Property

		Private Event listChangedHandler As ListChangedEventHandler
		Public Custom Event ListChanged As ListChangedEventHandler Implements IBindingList.ListChanged
			AddHandler(ByVal value As ListChangedEventHandler)
				AddHandler listChangedHandler, value
			End AddHandler
			RemoveHandler(ByVal value As ListChangedEventHandler)
				RemoveHandler listChangedHandler, value
			End RemoveHandler
			RaiseEvent(ByVal sender As System.Object, ByVal e As System.ComponentModel.ListChangedEventArgs)
			End RaiseEvent
		End Event

		Public Sub AddIndex(ByVal pd As PropertyDescriptor) Implements IBindingList.AddIndex
			Throw New NotSupportedException()
		End Sub
		Public Sub ApplySort(ByVal pd As PropertyDescriptor, ByVal dir As ListSortDirection) Implements IBindingList.ApplySort
			Throw New NotSupportedException()
		End Sub
		Public Function Find(ByVal [property] As PropertyDescriptor, ByVal key As Object) As Integer Implements IBindingList.Find
			Throw New NotSupportedException()
		End Function
		Public ReadOnly Property IsSorted() As Boolean Implements IBindingList.IsSorted
			Get
				Return False
			End Get
		End Property
		Public Sub RemoveIndex(ByVal pd As PropertyDescriptor) Implements IBindingList.RemoveIndex
			Throw New NotSupportedException()
		End Sub
		Public Sub RemoveSort() Implements IBindingList.RemoveSort
			Throw New NotSupportedException()
		End Sub
		Public ReadOnly Property SortDirection() As ListSortDirection Implements IBindingList.SortDirection
			Get
				Throw New NotSupportedException()
			End Get
		End Property
		Public ReadOnly Property SortProperty() As PropertyDescriptor Implements IBindingList.SortProperty
			Get
				Throw New NotSupportedException()
			End Get
		End Property
		Public ReadOnly Property SupportsChangeNotification() As Boolean Implements IBindingList.SupportsChangeNotification
			Get
				Return True
			End Get
		End Property
		Public ReadOnly Property SupportsSearching() As Boolean Implements IBindingList.SupportsSearching
			Get
				Return False
			End Get
		End Property
		Public ReadOnly Property SupportsSorting() As Boolean Implements IBindingList.SupportsSorting
			Get
				Return False
			End Get
		End Property
	End Class
	#End Region
	#Region "EventItem"
	Public Class EventItem
		Private privateType As Object
		Public Property Type() As Object
			Get
				Return privateType
			End Get
			Set(ByVal value As Object)
				privateType = value
			End Set
		End Property
		Private privateStartTime As Object
		Public Property StartTime() As Object
			Get
				Return privateStartTime
			End Get
			Set(ByVal value As Object)
				privateStartTime = value
			End Set
		End Property
		Private privateEndTime As Object
		Public Property EndTime() As Object
			Get
				Return privateEndTime
			End Get
			Set(ByVal value As Object)
				privateEndTime = value
			End Set
		End Property
		Private privateDescription As String
		Public Property Description() As String
			Get
				Return privateDescription
			End Get
			Set(ByVal value As String)
				privateDescription = value
			End Set
		End Property
		Private privateAllDay As Boolean
		Public Property AllDay() As Boolean
			Get
				Return privateAllDay
			End Get
			Set(ByVal value As Boolean)
				privateAllDay = value
			End Set
		End Property
		Private privateLabel As Integer
		Public Property Label() As Integer
			Get
				Return privateLabel
			End Get
			Set(ByVal value As Integer)
				privateLabel = value
			End Set
		End Property
		Private privateLocation As String
		Public Property Location() As String
			Get
				Return privateLocation
			End Get
			Set(ByVal value As String)
				privateLocation = value
			End Set
		End Property
		Private privateResourceId As Object
		Public Property ResourceId() As Object
			Get
				Return privateResourceId
			End Get
			Set(ByVal value As Object)
				privateResourceId = value
			End Set
		End Property
		Private privateStatus As Integer
		Public Property Status() As Integer
			Get
				Return privateStatus
			End Get
			Set(ByVal value As Integer)
				privateStatus = value
			End Set
		End Property
		Private privateSubject As String
		Public Property Subject() As String
			Get
				Return privateSubject
			End Get
			Set(ByVal value As String)
				privateSubject = value
			End Set
		End Property
		Private privatePrice As Object
		Public Property Price() As Object
			Get
				Return privatePrice
			End Get
			Set(ByVal value As Object)
				privatePrice = value
			End Set
		End Property
		Private privateRecurrenceInfo As String
		Public Property RecurrenceInfo() As String
			Get
				Return privateRecurrenceInfo
			End Get
			Set(ByVal value As String)
				privateRecurrenceInfo = value
			End Set
		End Property
		Private privateReminderInfo As String
		Public Property ReminderInfo() As String
			Get
				Return privateReminderInfo
			End Get
			Set(ByVal value As String)
				privateReminderInfo = value
			End Set
		End Property

		Public Sub New()
			Type = CInt(Fix(AppointmentType.Normal))
			StartTime = DateTime.MinValue
			EndTime = DateTime.MinValue + DevExpress.XtraScheduler.Native.DateTimeHelper.HalfHourSpan
			Description = String.Empty
			AllDay = False
			Label = 0
			Location = String.Empty
			ResourceId = Resource.Empty.Id
			Status = CInt(Fix(AppointmentStatusType.Free))
			Subject = String.Empty
			Price = 0.0
			RecurrenceInfo = String.Empty
			ReminderInfo = String.Empty
		End Sub
	End Class
	#End Region
End Namespace