-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEditSurvey.ascx.vb
271 lines (206 loc) · 11.1 KB
/
EditSurvey.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
'
' DotNetNuke® - http://www.dotnetnuke.com
' Copyright (c) 2002-2007
' by DotNetNuke Corporation
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
' to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions
' of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
' DEALINGS IN THE SOFTWARE.
' 4/15/2011 - Converted to WAP and Updated to DNN 5 Compliance by Robert J Collins
'
Imports DotNetNuke
Imports DotNetNuke.Services.Localization
Imports System.Collections.Generic
Imports DotNetNuke.Common
Imports DotNetNuke.Entities
Namespace DotNetNuke.Modules.Survey
Public Class EditSurvey
Inherits Entities.Modules.PortalModuleBase
Protected Label5 As System.Web.UI.WebControls.Label
Protected WithEvents ctlAudit As UI.UserControls.ModuleAuditControl
Dim SurveyId As Integer = -1
Dim arrSurveyOptions As List(Of SurveyOptionInfo)
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' get parameter
If Not (Request.QueryString("SurveyId") Is Nothing) Then
SurveyId = Integer.Parse(Request.QueryString("SurveyId"))
Else
SurveyId = -1
End If
If Page.IsPostBack = False Then
cmdDelete.Attributes.Add("onClick", "javascript:return confirm('" & Localization.GetString("DeleteItem") & "');")
If SurveyId > -1 Then
Dim objSurvey As SurveyInfo = SurveyController.GetSurvey(SurveyId, ModuleId)
If Not objSurvey Is Nothing Then
txtQuestion.Text = objSurvey.Question
cboOptionType.Items.FindByValue(objSurvey.OptionType).Selected = True
If objSurvey.ViewOrder > -1 Then
txtViewOrder.Text = objSurvey.ViewOrder.ToString
End If
arrSurveyOptions = SurveyOptionController.GetSurveyOptions(SurveyId)
Dim objSurveyOption As SurveyOptionInfo
Dim intIndex As Integer
For intIndex = 0 To arrSurveyOptions.Count - 1
objSurveyOption = CType(arrSurveyOptions(intIndex), SurveyOptionInfo)
objSurveyOption.OptionName = FormatSurveyOption(objSurveyOption.OptionName, objSurveyOption.IsCorrect)
arrSurveyOptions(intIndex) = objSurveyOption
Next
lstOptions.DataSource = arrSurveyOptions
lstOptions.DataBind()
ctlAudit.CreatedByUser = objSurvey.CreatedByUser.ToString
ctlAudit.CreatedDate = objSurvey.CreatedDate.ToShortDateString()
Else ' security violation attempt to access item not related to this Module
Response.Redirect(NavigateURL())
End If
Else ' new item
cmdDelete.Visible = False
ctlAudit.Visible = False
End If
End If
End Sub
Private Sub Update_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdUpdate.Click
Dim objSurvey As New SurveyInfo
objSurvey.SurveyId = SurveyId
objSurvey.ModuleId = ModuleId
objSurvey.Question = txtQuestion.Text
If txtViewOrder.Text <> "" Then
objSurvey.ViewOrder = Integer.Parse(txtViewOrder.Text)
Else
objSurvey.ViewOrder = -1
End If
objSurvey.OptionType = cboOptionType.SelectedItem.Value
objSurvey.CreatedByUser = UserId
If SurveyId = -1 Then
SurveyId = SurveyController.AddSurvey(objSurvey)
Else
SurveyController.UpdateSurvey(objSurvey)
End If
Dim intOption As Integer
For intOption = 0 To lstOptions.Items.Count - 1
Dim objSurveyOption As New SurveyOptionInfo
objSurveyOption.SurveyOptionId = Integer.Parse(lstOptions.Items(intOption).Value)
objSurveyOption.SurveyId = SurveyId
objSurveyOption.OptionName = lstOptions.Items(intOption).Text
objSurveyOption.ViewOrder = intOption
objSurveyOption.Votes = 0
objSurveyOption.IsCorrect = False
If objSurveyOption.OptionName = FormatSurveyOption(objSurveyOption.OptionName, True) Then
objSurveyOption.OptionName = FormatSurveyOption(objSurveyOption.OptionName, False)
objSurveyOption.IsCorrect = True
End If
' Determine if option is a new option or an existing one
If Not OptionExits(objSurveyOption) Then
SurveyOptionController.AddSurveyOption(objSurveyOption)
Else
SurveyOptionController.UpdateSurveyOption(objSurveyOption)
End If
Next
' Redirect back to the portal
Response.Redirect(NavigateURL())
End Sub
Private Sub Delete_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdDelete.Click
If SurveyId > -1 Then
Dim objSurvey As New SurveyInfo
objSurvey.SurveyId = SurveyId
objSurvey.ModuleId = ModuleId
SurveyController.DeleteSurvey(objSurvey)
End If
' Redirect back to the portal
Response.Redirect(NavigateURL())
End Sub
Private Sub cmdCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdCancel.Click
' Redirect back to the portal
Response.Redirect(NavigateURL())
End Sub
Private Sub cmdAddOption_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAddOption.Click
If txtOption.Text <> "" Then
Dim blnIsUnique As Boolean = True
Dim intItem As Integer
For intItem = 0 To lstOptions.Items.Count - 1
If lstOptions.Items(intItem).Text.ToLower = txtOption.Text.ToLower Then
blnIsUnique = False
End If
Next
If blnIsUnique Then
Dim strOption As String = FormatSurveyOption(txtOption.Text, chkCorrect.Checked)
lstOptions.Items.Add(New ListItem(strOption, lstOptions.Items.Count.ToString()))
chkCorrect.Checked = False
Else
UI.Skins.Skin.AddModuleMessage(Me, Localization.GetString("OptionExists", Me.LocalResourceFile), UI.Skins.Controls.ModuleMessage.ModuleMessageType.YellowWarning)
End If
txtOption.Text = ""
End If
End Sub
Private Sub cmdDeleteOption_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles cmdDeleteOption.Click
Dim objSurveyOptionInfo As New SurveyOptionInfo
If lstOptions.SelectedIndex <> -1 Then
If Integer.Parse(lstOptions.SelectedItem.Value) <> -1 Then
objSurveyOptionInfo.SurveyOptionId = Integer.Parse(lstOptions.SelectedItem.Value)
SurveyOptionController.DeleteSurveyOption(objSurveyOptionInfo)
End If
lstOptions.Items.RemoveAt(lstOptions.SelectedIndex)
End If
End Sub
Private Sub cmdUp_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles cmdUp.Click
If lstOptions.SelectedIndex > 0 Then
' save
Dim intSelectedIndex As Integer = lstOptions.SelectedIndex
Dim objListItem As ListItem = lstOptions.Items(lstOptions.SelectedIndex)
' remove
lstOptions.Items.Remove(objListItem)
' move up
lstOptions.Items.Insert(intSelectedIndex - 1, objListItem)
End If
End Sub
Private Sub cmdDown_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles cmdDown.Click
If lstOptions.SelectedIndex < lstOptions.Items.Count - 1 Then
' save
Dim intSelectedIndex As Integer = lstOptions.SelectedIndex
Dim objListItem As ListItem = lstOptions.Items(lstOptions.SelectedIndex)
' remove
lstOptions.Items.Remove(objListItem)
' move up
lstOptions.Items.Insert(intSelectedIndex + 1, objListItem)
End If
End Sub
Private Function FormatSurveyOption(ByVal OptionName As String, ByVal IsCorrect As Boolean) As String
If IsCorrect Then
If OptionName.StartsWith(">") = True And OptionName.EndsWith("<") = True Then
Return OptionName
Else
Return ">" & OptionName & "<"
End If
Else
If OptionName.StartsWith(">") = True And OptionName.EndsWith("<") = True Then
Return OptionName.Substring(1, OptionName.Length - 2)
Else
Return OptionName
End If
End If
End Function
Private Function OptionExits(ByVal OptionToFind As SurveyOptionInfo) As Boolean
Dim blnOptionExits As Boolean = False
arrSurveyOptions = SurveyOptionController.GetSurveyOptions(SurveyId)
If arrSurveyOptions Is Nothing Then
Return False
End If
Dim objSurveyOptionInfo As SurveyOptionInfo
For Each objSurveyOptionInfo In arrSurveyOptions
If objSurveyOptionInfo.OptionName.ToLower = OptionToFind.OptionName.ToLower Then
blnOptionExits = True
End If
Next
Return blnOptionExits
End Function
End Class
End Namespace