This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
/
MyDateFilterPopup.vb
358 lines (307 loc) · 15 KB
/
MyDateFilterPopup.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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Linq
Imports DevExpress.XtraGrid.Columns
Imports DevExpress.XtraGrid.Views.Base
Imports DevExpress.XtraEditors.Repository
Imports DevExpress.XtraEditors.Helpers
Imports System.Collections.Generic
Imports DevExpress.XtraEditors
Imports DevExpress.Data.Filtering
Imports DevExpress.XtraEditors.Controls
Imports DevExpress.XtraEditors.Popup
Namespace DateRange
Public Class MyDateFilterPopup
Inherits DateFilterPopup
Public Sub New(ByVal view As ColumnView, ByVal column As GridColumn, ByVal ownerControl As Control, ByVal creator As Object)
MyBase.New(view, column, ownerControl, creator)
End Sub
Private Const DateCalendarBorders As Integer = 10
Private BetweenWidth As Integer
Private dateCalendar_Renamed As DateControlEx
Private DateCalendar1 As DateControlEx
Private DateCalendar2 As DateControlEx
Private Greater As CheckEdit
Private Less As CheckEdit
Private Between As CheckEdit
Private ReadOnly Property DateCalendar() As DateControlEx
Get
If dateCalendar_Renamed Is Nothing Then
SetDateCalendar(DateFilterControl)
End If
Return dateCalendar_Renamed
End Get
End Property
Private dateFilterControl_Renamed As PopupOutlookDateFilterControl
Private ReadOnly Property DateFilterControl() As PopupOutlookDateFilterControl
Get
If dateFilterControl_Renamed Is Nothing Then
SetDateFilterControl(item)
End If
Return dateFilterControl_Renamed
End Get
End Property
#Region "Creators"
Private item As RepositoryItemPopupContainerEdit
Protected Overrides Function CreateRepositoryItem() As RepositoryItemPopupBase
item = TryCast(MyBase.CreateRepositoryItem(), RepositoryItemPopupContainerEdit)
If DateFilterControl.Controls.Count > 0 Then
DateCalendar1 = CreateCalendar(DateCalendar1, DateCalendar.SelectionStart, DateCalendar.Top, DateCalendar.Left)
DateCalendar1.Visible = False
DateCalendar2 = CreateCalendar(DateCalendar2, DateCalendar.SelectionStart, DateCalendar1.Top, DateCalendar.Left + DateCalendar1.Width)
DateCalendar2.Visible = False
Greater = GetCheckEditByName(Localizer.Active.GetLocalizedString(StringId.FilterClauseGreater))
Less = GetCheckEditByName(Localizer.Active.GetLocalizedString(StringId.FilterClauseLess))
Between = GetCheckEditByName(Localizer.Active.GetLocalizedString(StringId.FilterClauseBetween))
AddHandler Greater.CheckedChanged, AddressOf CheckedChanged
AddHandler Less.CheckedChanged, AddressOf CheckedChanged
AddHandler Between.CheckedChanged, AddressOf CheckedChanged
For Each ctrl As Control In DateFilterControl.Controls
If TypeOf ctrl Is CheckEdit Then
If NotOurControl(TryCast(ctrl, CheckEdit)) Then
AddHandler TryCast(ctrl, CheckEdit).CheckedChanged, AddressOf OriginalDateFilterPopup_CheckedChanged
End If
End If
Next ctrl
End If
Return item
End Function
Private Function FindOwnerForm(ByVal Owner As Control) As Control
If TypeOf Owner.Parent Is PopupContainerForm Then
Return Owner.Parent
Else
Return FindOwnerForm(Owner.Parent)
End If
End Function
Public OriginalLocation As Point
Protected Overridable Sub CreateRepositoryItemForOurFilterCriteria(ByVal Name As String)
DateCalendar.Visible = False
DateCalendar1.Visible = True
Dim Location As Point = FindOwnerForm(dateFilterControl_Renamed).Location
OriginalLocation = Location
BetweenWidth = FindOwnerForm(DateFilterControl).Width
If Name = Localizer.Active.GetLocalizedString(StringId.FilterClauseBetween) Then
FindOwnerForm(DateFilterControl).Width = DateCalendar1.Width + DateCalendar2.Width + DateCalendarBorders * 4
DateCalendar2.Visible = True
If Not Screen.PrimaryScreen.Bounds.Contains(FindOwnerForm(DateFilterControl).Bounds) Then
Location.X -= FindOwnerForm(dateFilterControl_Renamed).Width \ 2 - DateCalendarBorders * 2
End If
FindOwnerForm(dateFilterControl_Renamed).Location = Location
End If
End Sub
Private Sub ReturnOriginalView()
DateCalendar1.Visible = False
DateCalendar2.Visible = False
dateCalendar_Renamed.Visible = True
FindOwnerForm(DateFilterControl).Location = OriginalLocation
If BetweenWidth < DateFilterControl.Parent.Parent.Width Then
DateFilterControl.Parent.Parent.Width = BetweenWidth
End If
End Sub
Private Sub CalcControlsLocation(ByVal Name As String)
Dim FirstCheckEdit As CheckEdit = TryCast(DateFilterControl.Controls(0), CheckEdit)
Dim ChechEditControls As Integer = DateFilterControl.Controls.Count
Dim n As Integer = 0
For i As Integer = 0 To ChechEditControls - 1
Dim ctrl As Control = DateFilterControl.Controls(i)
If TypeOf ctrl Is CheckEdit Then
ctrl.Location = New Point(FirstCheckEdit.Location.X, FirstCheckEdit.Location.Y + FirstCheckEdit.Size.Height * (i - n))
If ctrl.Text = Name Then
Dim newLoc As Point = ctrl.Location
newLoc.Y += ctrl.Size.Height
DateCalendar1.Location = newLoc
newLoc.X += DateCalendar1.Width + DateCalendarBorders * 2
DateCalendar2.Location = newLoc
i = DateFilterControl.Controls.Count - 1
End If
Else
n += 1
End If
Next i
CreateRepositoryItemForOurFilterCriteria(Name)
End Sub
Private Function CreateCalendar(ByVal calendar As DateControlEx, ByVal dateTime As Date, ByVal top As Integer, ByVal left As Integer) As DateControlEx
calendar = New DateControlEx()
calendar.DateTime = dateTime
calendar.Top = top
calendar.Left = left
AddHandler calendar.EditDateModified, AddressOf DateCalendar_SelectionChanged
DateFilterControl.Controls.Add(calendar)
Return calendar
End Function
#End Region
#Region "Handlers&HandlersHelpers"
Private Sub CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
If (TryCast(sender, CheckEdit)).Checked Then
UpdateOurControlCheckedState((TryCast(sender, CheckEdit)).Text)
CalcControlsLocation((TryCast(sender, CheckEdit)).Text)
Me.View.ActiveFilterCriteria = GetFilterCriteriaByControlState()
Else
If DateCalendar1.Visible OrElse DateCalendar2.Visible Then
ReturnOriginalView()
ReturnOriginalControlsLocation()
End If
End If
End Sub
Protected Overridable Sub UpdateOurControlCheckedState(ByVal Name As String)
If Name = Localizer.Active.GetLocalizedString(StringId.FilterClauseBetween) Then
Less.Checked = False
Greater.Checked = False
End If
If Name = Localizer.Active.GetLocalizedString(StringId.FilterClauseGreater) Then
Less.Checked = False
Between.Checked = False
End If
If Name = Localizer.Active.GetLocalizedString(StringId.FilterClauseLess) Then
Greater.Checked = False
Between.Checked = False
End If
For Each ctrl As Control In DateFilterControl.Controls
If TypeOf ctrl Is CheckEdit Then
If NotOurControl(TryCast(ctrl, CheckEdit)) Then
TryCast(ctrl, CheckEdit).Checked = False
End If
End If
Next ctrl
End Sub
Private Sub OriginalDateFilterPopup_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
If (TryCast(sender, CheckEdit)).Checked Then
If NotOurControl(TryCast(sender, CheckEdit)) Then
Greater.Checked = False
Less.Checked = False
Between.Checked = False
End If
End If
End Sub
Private Sub ReturnOriginalControlsLocation()
For i As Integer = 0 To DateFilterControl.Controls.Count - 2
Dim ctrl As Control = DateFilterControl.Controls(i + 1)
Dim NewLocation As Point = DateFilterControl.Controls(i).Location
NewLocation.Y += DateFilterControl.Controls(i).Height
ctrl.Location = NewLocation
Next i
End Sub
Private Sub DateCalendar_SelectionChanged(ByVal sender As Object, ByVal e As EventArgs)
Me.View.ActiveFilterCriteria = GetFilterCriteriaByControlState()
If Not Greater.Checked AndAlso Not Less.Checked And Not Between.Checked Then
dateCalendar_Renamed.DateTime = DateCalendar1.DateTime
End If
End Sub
#End Region
Private Function GetFilterCriteriaByControlState() As CriteriaOperator
If Greater.Checked Then
Return GetBinaryOperatorByName(Localizer.Active.GetLocalizedString(StringId.FilterClauseGreater))
End If
If Less.Checked Then
Return GetBinaryOperatorByName(Localizer.Active.GetLocalizedString(StringId.FilterClauseLess))
End If
If Between.Checked Then
Return GetBetweenOperatorByName(Localizer.Active.GetLocalizedString(StringId.FilterClauseBetween))
End If
Return Nothing
End Function
Protected Shadows ReadOnly Property View() As MyGridView
Get
Return TryCast(MyBase.View, MyGridView)
End Get
End Property
#Region "ControlHelpers"
Public Function GetCheckEditByName(ByVal Name As String) As CheckEdit
For Each ctrl As Control In DateFilterControl.Controls
If ctrl.Text = Name Then
Return TryCast(ctrl, CheckEdit)
End If
Next ctrl
Return Nothing
End Function
Private Sub SetDateFilterControl(ByVal item As RepositoryItemPopupContainerEdit)
For Each ctrl As Control In item.PopupControl.Controls
If TypeOf ctrl Is PopupOutlookDateFilterControl Then
dateFilterControl_Renamed = TryCast(ctrl, PopupOutlookDateFilterControl)
Exit For
End If
Next ctrl
End Sub
Private Sub SetDateCalendar(ByVal dateFilterControl As PopupOutlookDateFilterControl)
For Each c As Control In dateFilterControl.Controls
If TypeOf c Is DateControlEx Then
dateCalendar_Renamed = TryCast(c, DateControlEx)
Exit For
End If
Next c
End Sub
Protected Overridable Function GetBinaryOperatorByName(ByVal Name As String) As BinaryOperator
If DateCalendar1 IsNot Nothing Then
If Name = Localizer.Active.GetLocalizedString(StringId.FilterClauseGreater) Then
Return New BinaryOperator(Me.Column.FieldName, DateCalendar1.DateTime, BinaryOperatorType.Greater)
End If
If Name = Localizer.Active.GetLocalizedString(StringId.FilterClauseLess) Then
Return New BinaryOperator(Me.Column.FieldName, DateCalendar1.DateTime, BinaryOperatorType.Less)
End If
End If
Return Nothing
End Function
Protected Overridable Function GetBetweenOperatorByName(ByVal Name As String) As BetweenOperator
If DateCalendar2 IsNot Nothing Then
If Name = Localizer.Active.GetLocalizedString(StringId.FilterClauseBetween) Then
Return New BetweenOperator(Me.Column.FieldName, DateCalendar1.DateTime, DateCalendar2.DateTime)
End If
End If
Return Nothing
End Function
#End Region
Protected Overridable Function NotOurControl(ByVal ctrl As CheckEdit) As Boolean
If ctrl.Text <> Localizer.Active.GetLocalizedString(StringId.FilterClauseGreater) AndAlso ctrl.Text <> Localizer.Active.GetLocalizedString(StringId.FilterClauseLess) AndAlso ctrl.Text <> Localizer.Active.GetLocalizedString(StringId.FilterClauseBetween) Then
Return True
End If
Return False
End Function
Public Overrides Sub Dispose()
If DateCalendar1 IsNot Nothing Then
RemoveHandler DateCalendar1.EditDateModified, AddressOf DateCalendar_SelectionChanged
End If
If DateCalendar2 IsNot Nothing Then
RemoveHandler DateCalendar2.EditDateModified, AddressOf DateCalendar_SelectionChanged
End If
For Each ctrl As Control In DateFilterControl.Controls
If TypeOf ctrl Is CheckEdit Then
If NotOurControl(TryCast(ctrl, CheckEdit)) Then
RemoveHandler TryCast(ctrl, CheckEdit).CheckedChanged, AddressOf OriginalDateFilterPopup_CheckedChanged
End If
End If
Next ctrl
Try
Me.View.ActiveFilterString = GetFilterCriteriaByControlState().ToString()
Catch
End Try
DateCalendar1.Dispose()
DateCalendar2.Dispose()
MyBase.Dispose()
If dateCalendar_Renamed IsNot Nothing Then
dateCalendar_Renamed.Dispose()
dateCalendar_Renamed = Nothing
End If
If Greater IsNot Nothing Then
Greater.Dispose()
Greater = Nothing
End If
If Less IsNot Nothing Then
Less.Dispose()
Less = Nothing
End If
If Between IsNot Nothing Then
Between.Dispose()
Between = Nothing
End If
If dateFilterControl_Renamed IsNot Nothing Then
dateFilterControl_Renamed.Dispose()
dateFilterControl_Renamed = Nothing
End If
If item IsNot Nothing Then
item.Dispose()
item = Nothing
End If
End Sub
End Class
End Namespace