forked from ventrian/Property-Agent
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathEditReviewFields.ascx.vb
executable file
·308 lines (201 loc) · 11.3 KB
/
EditReviewFields.ascx.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
Imports DotNetNuke.Common
Imports DotNetNuke.Common.Utilities
Imports DotNetNuke.Services.Exceptions
Imports DotNetNuke.Services.Localization
Namespace Ventrian.PropertyAgent
Partial Public Class EditReviewFields
Inherits PropertyAgentBase
#Region " Private Members "
Dim _currentPage As Integer = 1
Dim _pageRecords As Integer = Null.NullInteger
Dim _reviewFields As List(Of ReviewFieldInfo)
#End Region
#Region " Private Methods "
Private Sub ReadQueryString()
If Not (Request("CurrentPage") Is Nothing) Then
_currentPage = Convert.ToInt32(Request("CurrentPage"))
End If
If Not (Request("PageRecords") Is Nothing) Then
_pageRecords = Convert.ToInt32(Request("PageRecords"))
End If
End Sub
Private Sub BindPageCount()
If (Request.Cookies("PA-RFM-PageSize") IsNot Nothing) Then
If Not (drpRecordsPerPage.Items.FindByValue(Request.Cookies("PA-RFM-PageSize").Value) Is Nothing) Then
drpRecordsPerPage.SelectedValue = Request.Cookies("PA-RFM-PageSize").Value
Return
End If
End If
If (_pageRecords <> Null.NullInteger) Then
If Not (drpRecordsPerPage.Items.FindByValue(_pageRecords.ToString()) Is Nothing) Then
drpRecordsPerPage.SelectedValue = _pageRecords.ToString()
End If
End If
End Sub
Private Sub BindCrumbs()
Dim crumbs As New ArrayList
Dim objCrumbMain As New CrumbInfo
objCrumbMain.Caption = PropertySettings.MainLabel
objCrumbMain.Url = NavigateURL()
crumbs.Add(objCrumbMain)
Dim objCustomFieldManager As New CrumbInfo
objCustomFieldManager.Caption = Localization.GetString("ReviewFieldManager", LocalResourceFile)
objCustomFieldManager.Url = NavigateURL(Me.TabId, "", PropertySettings.SEOAgentType & "=EditReviewFields")
crumbs.Add(objCustomFieldManager)
If (PropertySettings.BreadcrumbPlacement = BreadcrumbType.Portal) Then
For i As Integer = 0 To crumbs.Count - 1
Dim objCrumb As CrumbInfo = crumbs(i)
If (i > 0) Then
Dim objTab As New DotNetNuke.Entities.Tabs.TabInfo
objTab.TabID = -8888 + i
objTab.TabName = objCrumb.Caption
objTab.Url = objCrumb.Url
PortalSettings.ActiveTab.BreadCrumbs.Add(objTab)
End If
Next
End If
If (PropertySettings.BreadcrumbPlacement = BreadcrumbType.Module) Then
rptBreadCrumbs.DataSource = crumbs
rptBreadCrumbs.DataBind()
End If
End Sub
Private Sub BindReviewFields()
Dim PageSize As Integer = Convert.ToInt32(drpRecordsPerPage.SelectedItem.Value)
Dim objReviewFieldController As New ReviewFieldController
Localization.LocalizeDataGrid(grdReviewFields, Me.LocalResourceFile)
_reviewFields = objReviewFieldController.List(Me.ModuleId)
If (_reviewFields.Count > 1) Then
' Sort Order must be messed up, fix now..
For i As Integer = 0 To _reviewFields.Count - 1
Dim objReviewField As ReviewFieldInfo = CType(_reviewFields(i), ReviewFieldInfo)
objReviewField.SortOrder = i
objReviewFieldController.Update(objReviewField)
Next
End If
Dim objPagedDataSource As New PagedDataSource
objPagedDataSource.AllowPaging = True
objPagedDataSource.DataSource = _reviewFields
objPagedDataSource.PageSize = PageSize
objPagedDataSource.CurrentPageIndex = _currentPage - 1
If (_reviewFields.Count > 0) Then
grdReviewFields.DataSource = objPagedDataSource
grdReviewFields.DataBind()
grdReviewFields.Visible = True
lblNoReviewFields.Visible = False
ctlPagingControl.Visible = True
ctlPagingControl.Visible = True
ctlPagingControl.TotalRecords = _reviewFields.Count
ctlPagingControl.PageSize = PageSize
ctlPagingControl.CurrentPage = _currentPage
ctlPagingControl.QuerystringParams = PropertySettings.SEOAgentType & "=EditReviewFields"
If (drpRecordsPerPage.SelectedIndex <> 1) Then
ctlPagingControl.QuerystringParams = ctlPagingControl.QuerystringParams & "&PageRecords=" + drpRecordsPerPage.SelectedValue
End If
ctlPagingControl.TabID = TabId
Else
grdReviewFields.Visible = False
lblNoReviewFields.Visible = True
ctlPagingControl.Visible = False
End If
End Sub
#End Region
#Region " Protected Methods "
Protected Function GetReviewFieldEditUrl(ByVal reviewFieldID As String) As String
Return NavigateURL(Me.TabId, "", PropertySettings.SEOAgentType & "=EditReviewField", "reviewFieldID=" & reviewFieldID)
End Function
#End Region
#Region " Event Handlers "
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
Try
BindCrumbs()
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
End Sub
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
ReadQueryString()
If (Page.IsPostBack = False) Then
BindPageCount()
BindReviewFields()
End If
cmdAddReviewField.CssClass = PropertySettings.ButtonClass
cmdReturnToModule.CssClass = PropertySettings.ButtonClass
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
End Sub
Private Sub drpRecordsPerPage_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles drpRecordsPerPage.SelectedIndexChanged
Try
_currentPage = 1
Response.Cookies.Add(New HttpCookie("PA-RFM-PageSize", drpRecordsPerPage.SelectedValue))
Response.Redirect(NavigateURL(Me.TabId, "", PropertySettings.SEOAgentType & "=EditReviewFields", "PageRecords=" & drpRecordsPerPage.SelectedValue), True)
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
End Sub
Private Sub cmdAddCustomField_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAddReviewField.Click
Try
Response.Redirect(NavigateURL(Me.TabId, "", PropertySettings.SEOAgentType & "=EditReviewField"), True)
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
End Sub
Private Sub cmdReturnToModule_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdReturnToModule.Click
Try
Response.Redirect(NavigateURL(), True)
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
End Sub
Private Sub grdReviewFields_ItemDataBound(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles grdReviewFields.ItemDataBound
If (e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem) Then
Dim btnUp As ImageButton = CType(e.Item.FindControl("btnUp"), ImageButton)
Dim btnDown As ImageButton = CType(e.Item.FindControl("btnDown"), ImageButton)
Dim objReviewField As ReviewFieldInfo = CType(e.Item.DataItem, ReviewFieldInfo)
If Not (btnUp Is Nothing And btnDown Is Nothing) Then
If (objReviewField.ReviewFieldID = CType(_reviewFields(0), ReviewFieldInfo).ReviewFieldID) Then
btnUp.Visible = False
End If
If (objReviewField.ReviewFieldID = CType(_reviewFields(_reviewFields.Count - 1), ReviewFieldInfo).ReviewFieldID) Then
btnDown.Visible = False
End If
btnUp.CommandArgument = objReviewField.ReviewFieldID.ToString()
btnUp.CommandName = "Up"
btnDown.CommandArgument = objReviewField.ReviewFieldID.ToString()
btnDown.CommandName = "Down"
End If
End If
End Sub
Private Sub grdReviewFields_ItemCommand(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles grdReviewFields.ItemCommand
Dim objReviewFieldController As New ReviewFieldController
_reviewFields = objReviewFieldController.List(Me.ModuleId)
Dim reviewFieldID As Integer = Convert.ToInt32(e.CommandArgument)
For i As Integer = 0 To _reviewFields.Count - 1
Dim objReviewField As ReviewFieldInfo = CType(_reviewFields(i), ReviewFieldInfo)
If (reviewFieldID = objReviewField.ReviewFieldID) Then
If (e.CommandName = "Up") Then
Dim objReviewFieldToSwap As ReviewFieldInfo = CType(_reviewFields(i - 1), ReviewFieldInfo)
Dim sortOrder As Integer = objReviewField.SortOrder
Dim sortOrderPrevious As Integer = objReviewFieldToSwap.SortOrder
objReviewField.SortOrder = sortOrderPrevious
objReviewFieldToSwap.SortOrder = sortOrder
objReviewFieldController.Update(objReviewField)
objReviewFieldController.Update(objReviewFieldToSwap)
End If
If (e.CommandName = "Down") Then
Dim objReviewFieldToSwap As ReviewFieldInfo = CType(_reviewFields(i + 1), ReviewFieldInfo)
Dim sortOrder As Integer = objReviewField.SortOrder
Dim sortOrderNext As Integer = objReviewFieldToSwap.SortOrder
objReviewField.SortOrder = sortOrderNext
objReviewFieldToSwap.SortOrder = sortOrder
objReviewFieldController.Update(objReviewField)
objReviewFieldController.Update(objReviewFieldToSwap)
End If
End If
Next
Response.Redirect(Request.RawUrl, True)
End Sub
#End Region
End Class
End Namespace