/
Form1.vb
241 lines (204 loc) · 10.7 KB
/
Form1.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
Imports DevExpress.XtraScheduler
Imports DevExpress.XtraScheduler.Drawing
Imports DevExpress.XtraScheduler.Services
Imports System
Imports System.Windows.Forms
Namespace FormattingServicesExample
Partial Public Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
LoadData()
CreateAppointmentFormatStringService()
CreateTimeRulerFormatStringService()
CreateHeaderCaptionService()
CreateHeaderToolTipService()
schedulerControl1.DayView.TopRowTime = New TimeSpan(9, 0, 0)
schedulerControl1.WorkWeekView.TopRowTime = New TimeSpan(9, 0, 0)
End Sub
Private prevTimeRulerFormatStringService As ITimeRulerFormatStringService
Private customTimeRulerFormatStringService As CustomTimeRulerFormatStringService
Private prevAppointmentFormatStringService As IAppointmentFormatStringService
Private customAppointmentFormatStringService As CustomAppointmentFormatStringService
Private prevHeaderCaptionService As IHeaderCaptionService
Private customHeaderCaptionService As CustomHeaderCaptionService
Private prevHeaderToolTipService As IHeaderToolTipService
Private customHeaderToolTipService As CustomHeaderToolTipService
Public Sub CreateAppointmentFormatStringService()
Me.prevAppointmentFormatStringService = DirectCast(schedulerControl1.GetService(GetType(IAppointmentFormatStringService)), IAppointmentFormatStringService)
Me.customAppointmentFormatStringService = New CustomAppointmentFormatStringService(prevAppointmentFormatStringService)
End Sub
Public Sub CreateTimeRulerFormatStringService()
Me.prevTimeRulerFormatStringService = DirectCast(schedulerControl1.GetService(GetType(ITimeRulerFormatStringService)), ITimeRulerFormatStringService)
Me.customTimeRulerFormatStringService = New CustomTimeRulerFormatStringService(prevTimeRulerFormatStringService)
End Sub
Public Sub CreateHeaderCaptionService()
Me.prevHeaderCaptionService = DirectCast(schedulerControl1.GetService(GetType(IHeaderCaptionService)), IHeaderCaptionService)
Me.customHeaderCaptionService = New CustomHeaderCaptionService(prevHeaderCaptionService)
End Sub
Public Sub CreateHeaderToolTipService()
Me.prevHeaderToolTipService = DirectCast(schedulerControl1.GetService(GetType(IHeaderToolTipService)), IHeaderToolTipService)
Me.customHeaderToolTipService = New CustomHeaderToolTipService(prevHeaderToolTipService)
End Sub
Private Sub checkButton1_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs) Handles checkButton1.CheckedChanged
If checkButton1.Checked Then
schedulerControl1.RemoveService(GetType(IAppointmentFormatStringService))
schedulerControl1.AddService(GetType(IAppointmentFormatStringService), customAppointmentFormatStringService)
schedulerControl1.RemoveService(GetType(ITimeRulerFormatStringService))
schedulerControl1.AddService(GetType(ITimeRulerFormatStringService), customTimeRulerFormatStringService)
schedulerControl1.RemoveService(GetType(IHeaderCaptionService))
schedulerControl1.AddService(GetType(IHeaderCaptionService), customHeaderCaptionService)
schedulerControl1.RemoveService(GetType(IHeaderToolTipService))
schedulerControl1.AddService(GetType(IHeaderToolTipService), customHeaderToolTipService)
schedulerControl1.ActiveView.LayoutChanged()
Else
schedulerControl1.RemoveService(GetType(IAppointmentFormatStringService))
schedulerControl1.AddService(GetType(IAppointmentFormatStringService), prevAppointmentFormatStringService)
schedulerControl1.RemoveService(GetType(ITimeRulerFormatStringService))
schedulerControl1.AddService(GetType(ITimeRulerFormatStringService), prevTimeRulerFormatStringService)
schedulerControl1.RemoveService(GetType(IHeaderCaptionService))
schedulerControl1.AddService(GetType(IHeaderCaptionService), prevHeaderCaptionService)
schedulerControl1.RemoveService(GetType(IHeaderToolTipService))
schedulerControl1.AddService(GetType(IHeaderToolTipService), prevHeaderToolTipService)
schedulerControl1.ActiveView.LayoutChanged()
End If
End Sub
End Class
Public Class CustomTimeRulerFormatStringService
Inherits TimeRulerFormatStringServiceWrapper
Public Sub New(ByVal service As ITimeRulerFormatStringService)
MyBase.New(service)
End Sub
#Region "ITimeRulerFormatStringService Members"
Public Overrides Function GetHalfDayHourFormat(ByVal ruler As TimeRuler) As String
Return If(ruler.UseClientTimeZone, "hh:mm", "HH:mm")
End Function
Public Overrides Function GetHourFormat(ByVal ruler As TimeRuler) As String
Return If(ruler.UseClientTimeZone, "hh:mm", "HH:mm")
End Function
Public Overrides Function GetHourOnlyFormat(ByVal ruler As TimeRuler) As String
Return If(ruler.UseClientTimeZone, "hh", "HH")
End Function
Public Overrides Function GetMinutesOnlyFormat(ByVal ruler As TimeRuler) As String
Return "mm"
End Function
Public Overrides Function GetTimeDesignatorOnlyFormat(ByVal ruler As TimeRuler) As String
Return If(ruler.UseClientTimeZone, "tt", "mm")
End Function
#End Region
End Class
Public Class CustomAppointmentFormatStringService
Inherits AppointmentFormatStringServiceWrapper
Public Sub New(ByVal service As IAppointmentFormatStringService)
MyBase.New(service)
End Sub
#Region "IAppointmentFormatStringService Members"
Public Overrides Function GetVerticalAppointmentStartFormat(ByVal aptViewInfo As IAppointmentViewInfo) As String
Return "{0: HHmm:ss}"
End Function
Public Overrides Function GetVerticalAppointmentEndFormat(ByVal aptViewInfo As IAppointmentViewInfo) As String
Return "{0: HHmm:ss}"
End Function
Public Overrides Function GetHorizontalAppointmentEndFormat(ByVal aptViewInfo As IAppointmentViewInfo) As String
Return "{0: HHmm}"
End Function
Public Overrides Function GetHorizontalAppointmentStartFormat(ByVal aptViewInfo As IAppointmentViewInfo) As String
Return "{0: HHmm}"
End Function
Public Overrides Function GetContinueItemStartFormat(ByVal aptViewInfo As IAppointmentViewInfo) As String
Return "{0: HHmm MMM dd}"
End Function
Public Overrides Function GetContinueItemEndFormat(ByVal aptViewInfo As IAppointmentViewInfo) As String
Return "{0: HHmm MMM dd}"
End Function
#End Region
End Class
Public Class CustomHeaderCaptionService
Inherits HeaderCaptionServiceWrapper
Public Sub New(ByVal service As IHeaderCaptionService)
MyBase.New(service)
End Sub
#Region "IHeaderCaptionService Members"
Public Overrides Function GetDayColumnHeaderCaption(ByVal header As DayHeader) As String
Dim [date] As Date = header.Interval.Start.Date
If [date].Month = 1 AndAlso [date].Day = 1 Then
Return "DayColumnHeader"
Else
Return MyBase.GetDayColumnHeaderCaption(header)
End If
End Function
Public Overrides Function GetDayOfWeekAbbreviatedHeaderCaption(ByVal header As DayOfWeekHeader) As String
Dim [date] As DayOfWeek = header.DayOfWeek
If [date] = DayOfWeek.Thursday Then
Return "DOW"
Else
Return MyBase.GetDayOfWeekAbbreviatedHeaderCaption(header)
End If
End Function
Public Overrides Function GetDayOfWeekHeaderCaption(ByVal header As DayOfWeekHeader) As String
Dim [date] As DayOfWeek = header.DayOfWeek
If [date] = DayOfWeek.Thursday Then
Return "DayOfWeekHeader"
Else
Return MyBase.GetDayOfWeekHeaderCaption(header)
End If
End Function
Public Overrides Function GetHorizontalWeekCellHeaderCaption(ByVal header As SchedulerHeader) As String
Dim [date] As Date = header.Interval.Start.Date
If [date].Month = 1 AndAlso [date].Day = 1 Then
Return "HorizontalWeekCellHeader"
Else
Return MyBase.GetHorizontalWeekCellHeaderCaption(header)
End If
End Function
Public Overrides Function GetTimeScaleHeaderCaption(ByVal header As TimeScaleHeader) As String
Dim [date] As Date = header.Interval.Start.Date
If [date].Month = 1 AndAlso [date].Day = 1 Then
Return "TimeScaleHeader"
Else
Return MyBase.GetTimeScaleHeaderCaption(header)
End If
End Function
Public Overrides Function GetVerticalWeekCellHeaderCaption(ByVal header As SchedulerHeader) As String
Dim [date] As Date = header.Interval.Start.Date
If [date].Month = 1 AndAlso [date].Day = 1 Then
Return "VerticalWeekCellHeader"
Else
Return MyBase.GetVerticalWeekCellHeaderCaption(header)
End If
End Function
#End Region
End Class
Public Class CustomHeaderToolTipService
Inherits HeaderToolTipServiceWrapper
Public Sub New(ByVal service As IHeaderToolTipService)
MyBase.New(service)
End Sub
#Region "IHeaderToolTipService Members"
Public Overrides Function GetDayColumnHeaderToolTip(ByVal header As DayHeader) As String
Dim [date] As Date = header.Interval.Start.Date
If [date].Month = 1 AndAlso [date].Day = 1 Then
Return "Let's celebrate!"
Else
Return MyBase.GetDayColumnHeaderToolTip(header)
End If
End Function
Public Overrides Function GetDayOfWeekHeaderToolTip(ByVal header As DayOfWeekHeader) As String
If header.Interval.Contains(New Date(2009,1,1)) Then
Return "Let's celebrate!"
Else
Return MyBase.GetDayOfWeekHeaderToolTip(header)
End If
End Function
Public Overrides Function GetTimeScaleHeaderToolTip(ByVal header As TimeScaleHeader) As String
If header.Interval.Contains(New Date(2009,1,1)) Then
Return "Let's celebrate!"
Else
Return MyBase.GetTimeScaleHeaderToolTip(header)
End If
End Function
#End Region
End Class
End Namespace