/
MappingConverterLabel.vb
45 lines (39 loc) · 1.96 KB
/
MappingConverterLabel.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
Imports DevExpress.XtraScheduler
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Drawing
Imports System.Collections
Namespace SchedulerMappingConverterExample
#Region "#MappingConverterLabel"
Friend Class MappingConverterLabel
Implements ISchedulerMappingConverter
Private storage As SchedulerStorage
Public Sub New(ByVal dataStorage As SchedulerStorage)
storage = dataStorage
End Sub
Public Function Convert(ByVal obj As Object, ByVal targetType As Type, ByVal parameter As Object) As Object Implements ISchedulerMappingConverter.Convert
Dim lbl As IAppointmentLabel = storage.Appointments.Labels.FirstOrDefault(Function(label) label.GetColor().ToArgb() = DirectCast(obj, Integer))
Return If(lbl IsNot Nothing, lbl.Id, CreateNewLabel(DirectCast(obj, Integer)))
End Function
Public Function ConvertBack(ByVal obj As Object, ByVal targetType As Type, ByVal parameter As Object) As Object Implements ISchedulerMappingConverter.ConvertBack
Return storage.GetLabelColor(obj).ToArgb()
End Function
Private Function CreateNewLabel(ByVal intColor As Integer) As Object
Dim color As Color = System.Drawing.Color.FromArgb(intColor)
Dim labelName As String = "x" & intColor.ToString("X")
For Each kColor As KnownColor In System.Enum.GetValues(GetType(KnownColor))
Dim known As Color = System.Drawing.Color.FromKnownColor(kColor)
If intColor = known.ToArgb() Then
labelName = known.Name
End If
Next kColor
Dim label As AppointmentLabel = storage.Appointments.Labels.CreateNewLabel(labelName)
label.SetColor(color)
storage.Appointments.Labels.Add(label)
Return label.Id
End Function
End Class
#End Region ' #MappingConverterLabel
End Namespace