-
Notifications
You must be signed in to change notification settings - Fork 0
/
EditProduct.ascx.vb
executable file
·346 lines (236 loc) · 13 KB
/
EditProduct.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
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
'
' Feedback Center for DotNetNuke - http://www.dotnetnuke.com
' Copyright (c) 2002-2005
' by Scott McCulloch ( [email protected] ) ( http://www.smcculloch.net )
'
Imports System.IO
Imports System.Web
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls
Imports DotNetNuke
Imports DotNetNuke.Common
Imports DotNetNuke.Common.Utilities
Imports DotNetNuke.Entities.Modules
Imports DotNetNuke.Services.Exceptions
Imports DotNetNuke.Services.Localization
Imports Ventrian.FeedbackCenter.Entities
Imports DotNetNuke.Security.Roles
Namespace Ventrian.FeedbackCenter
Public MustInherit Class EditProduct
Inherits FeedbackCenterBase
#Region " Controls "
Protected WithEvents lblProductSettingsHelp As System.Web.UI.WebControls.Label
Protected WithEvents txtName As System.Web.UI.WebControls.TextBox
Protected WithEvents valName As System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents chkIsActive As System.Web.UI.WebControls.CheckBox
Protected WithEvents pnlSettings As System.Web.UI.WebControls.Panel
Protected WithEvents cmdUpdate As System.Web.UI.WebControls.LinkButton
Protected WithEvents cmdCancel As System.Web.UI.WebControls.LinkButton
Protected WithEvents cmdDelete As System.Web.UI.WebControls.LinkButton
Protected WithEvents tblProduct As System.Web.UI.HtmlControls.HtmlTable
Protected WithEvents rptBreadCrumbs As System.Web.UI.WebControls.Repeater
Protected WithEvents drpParentProduct As System.Web.UI.WebControls.DropDownList
Protected WithEvents valInvalidParentProduct As System.Web.UI.WebControls.CustomValidator
Protected WithEvents txtEmailNotification As System.Web.UI.WebControls.TextBox
Protected WithEvents chkInheritSecurity As System.Web.UI.WebControls.CheckBox
Protected WithEvents trPermissions As System.Web.UI.HtmlControls.HtmlTableRow
Protected WithEvents grdProductPermissions As System.Web.UI.WebControls.DataGrid
#End Region
#Region " Private Members "
Private _productID As Integer = Null.NullInteger
Private _parentID As Integer = Null.NullInteger
#End Region
#Region " Private Methods "
Private Sub ReadQueryString()
If Not (Request("ProductID") Is Nothing) Then
_productID = Convert.ToInt32(Request("ProductID"))
End If
If Not (Request("ParentID") Is Nothing) Then
_parentID = Convert.ToInt32(Request("ParentID"))
End If
End Sub
Private Sub BindProduct()
If (_productID = Null.NullInteger) Then
cmdDelete.Visible = False
Else
cmdDelete.Visible = True
cmdDelete.Attributes.Add("onClick", "javascript:return confirm('Are You Sure You Wish To Delete This Item ?');")
Dim objProductController As New ProductController
Dim objProduct As ProductInfo = objProductController.Get(_productID)
If Not (objProduct Is Nothing) Then
txtName.Text = objProduct.Name
chkIsActive.Checked = objProduct.IsActive
If (drpParentProduct.Items.FindByValue(objProduct.ParentID.ToString) IsNot Nothing) Then
drpParentProduct.SelectedValue = objProduct.ParentID.ToString()
End If
txtEmailNotification.Text = objProduct.Email
chkInheritSecurity.Checked = objProduct.InheritSecurity
trPermissions.Visible = Not chkInheritSecurity.Checked
End If
End If
End Sub
Private Sub BindParentProducts()
Dim objProductController As New ProductController
drpParentProduct.DataSource = objProductController.ListAll(ModuleId)
drpParentProduct.DataBind()
drpParentProduct.Items.Insert(0, New ListItem(Localization.GetString("SelectParentProduct", Me.LocalResourceFile), "-1"))
If (_parentID <> Null.NullInteger) Then
If (drpParentProduct.Items.FindByValue(_parentID.ToString()) IsNot Nothing) Then
drpParentProduct.SelectedValue = _parentID.ToString()
End If
End If
End Sub
Private Sub BindRoles()
Dim objRole As New RoleController
Dim availableRoles As New ArrayList
Dim roles As ArrayList = objRole.GetPortalRoles(PortalId)
If Not roles Is Nothing Then
For Each Role As RoleInfo In roles
availableRoles.Add(New ListItem(Role.RoleName, Role.RoleName))
Next
End If
grdProductPermissions.DataSource = availableRoles
grdProductPermissions.DataBind()
End Sub
Private Function IsInRole(ByVal roleName As String, ByVal roles As String()) As Boolean
For Each role As String In roles
If (roleName = role) Then
Return True
End If
Next
Return False
End Function
#End Region
#Region " Event Handlers "
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ReadQueryString()
If (IsPostBack = False) Then
BindRoles()
BindParentProducts()
BindProduct()
End If
End Sub
Private Sub cmdUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUpdate.Click
If (Page.IsValid) Then
Dim objProductController As New ProductController
Dim objProduct As New ProductInfo
If (_productID <> Null.NullInteger) Then
objProduct = objProductController.Get(_productID)
Else
objProduct = CType(CBO.InitializeObject(objProduct, GetType(ProductInfo)), ProductInfo)
End If
objProduct.ModuleID = Me.ModuleId
objProduct.Name = txtName.Text
objProduct.IsActive = chkIsActive.Checked
objProduct.ParentID = Convert.ToInt32(drpParentProduct.SelectedValue)
objProduct.Email = txtEmailNotification.Text
objProduct.InheritSecurity = chkInheritSecurity.Checked
If (_productID = Null.NullInteger) Then
objProduct.ProductID = objProductController.Add(objProduct)
Else
objProductController.Update(objProduct)
End If
Dim viewRoles As String = ""
Dim submitRoles As String = ""
For Each item As DataGridItem In grdProductPermissions.Items
Dim role As String = grdProductPermissions.DataKeys(item.ItemIndex).ToString()
Dim chkView As CheckBox = CType(item.FindControl("chkView"), CheckBox)
If (chkView.Checked) Then
If (viewRoles = "") Then
viewRoles = role
Else
viewRoles = viewRoles & ";" & role
End If
End If
Dim chkSubmit As CheckBox = CType(item.FindControl("chkSubmit"), CheckBox)
If (chkSubmit.Checked) Then
If (submitRoles = "") Then
submitRoles = role
Else
submitRoles = submitRoles & ";" & role
End If
End If
Next
Dim objModuleController As New ModuleController()
objModuleController.UpdateModuleSetting(Me.ModuleId, objProduct.ProductID.ToString() & "-" & Constants.PERMISSION_CATEGORY_VIEW_SETTING, viewRoles)
objModuleController.UpdateModuleSetting(Me.ModuleId, objProduct.ProductID.ToString() & "-" & Constants.PERMISSION_CATEGORY_SUBMIT_SETTING, submitRoles)
Response.Redirect(EditUrl("EditProducts"), True)
End If
End Sub
Private Sub cmdDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDelete.Click
Dim objProductController As New ProductController
objProductController.Delete(_productID)
Response.Redirect(EditUrl("EditProducts"), True)
End Sub
Private Sub cmdCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancel.Click
Response.Redirect(EditUrl("EditProducts"), True)
End Sub
Private Sub valInvalidParentProduct_ServerValidate(ByVal source As System.Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles valInvalidParentProduct.ServerValidate
Try
If (_productID = Null.NullInteger Or drpParentProduct.SelectedValue = "-1") Then
args.IsValid = True
Return
End If
Dim objProductController As New ProductController
Dim objProduct As ProductInfo = objProductController.Get(Convert.ToInt32(drpParentProduct.SelectedValue))
While Not objProduct Is Nothing
If (_productID = objProduct.ProductID) Then
args.IsValid = False
Return
End If
objProduct = objProductController.Get(objProduct.ParentID)
End While
args.IsValid = True
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
End Sub
Private Sub grdProductPermissions_ItemDataBound(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles grdProductPermissions.ItemDataBound
Try
If (e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem) Then
Dim objListItem As ListItem = CType(e.Item.DataItem, ListItem)
If Not (objListItem Is Nothing) Then
Dim role As String = CType(e.Item.DataItem, ListItem).Value
Dim chkView As CheckBox = CType(e.Item.FindControl("chkView"), CheckBox)
Dim chkSubmit As CheckBox = CType(e.Item.FindControl("chkSubmit"), CheckBox)
If (objListItem.Value = PortalSettings.AdministratorRoleName.ToString()) Then
chkView.Enabled = False
chkView.Checked = True
chkSubmit.Enabled = False
chkSubmit.Checked = True
Else
If (_productID <> Null.NullInteger) Then
If (Settings.Contains(_productID.ToString() & "-" & Constants.PERMISSION_CATEGORY_VIEW_SETTING)) Then
chkView.Checked = IsInRole(role, Settings(_productID.ToString() & "-" & Constants.PERMISSION_CATEGORY_VIEW_SETTING).ToString().Split(";"c))
End If
If (Settings.Contains(_productID.ToString() & "-" & Constants.PERMISSION_CATEGORY_SUBMIT_SETTING)) Then
chkSubmit.Checked = IsInRole(role, Settings(_productID.ToString() & "-" & Constants.PERMISSION_CATEGORY_SUBMIT_SETTING).ToString().Split(";"c))
End If
End If
End If
End If
End If
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
End Sub
Protected Sub chkInheritSecurity_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs) Handles chkInheritSecurity.CheckedChanged
Try
trPermissions.Visible = Not chkInheritSecurity.Checked
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
End Sub
#End Region
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
End Class
End Namespace