-
Notifications
You must be signed in to change notification settings - Fork 2
/
AdminPromo.ascx.vb
366 lines (294 loc) · 15.7 KB
/
AdminPromo.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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
' --- Copyright (c) notice NevoWeb ---
' Copyright (c) 2008 SARL NevoWeb. www.nevoweb.com. BSD License.
' Author: D.C.Lee
' ------------------------------------------------------------------------
' 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.
' ------------------------------------------------------------------------
' This copyright notice may NOT be removed, obscured or modified without written consent from the author.
' --- End copyright notice ---
Imports DotNetNuke
Imports DotNetNuke.Common
Imports DotNetNuke.Services.Exceptions
Imports DotNetNuke.Services.Localization
Imports NEvoWeb.Modules.NB_Store.SharedFunctions
Namespace NEvoWeb.Modules.NB_Store
Partial Public Class AdminPromo
Inherits BaseAdminModule
Private _CodeType As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
'Sample code to get data
If Not Request.QueryString("spg") Is Nothing Then
Select Case Request.QueryString("spg").ToUpper
Case "COU"
_CodeType = Request.QueryString("spg").ToUpper
Case "CAR"
_CodeType = Request.QueryString("spg").ToUpper
Case "STO"
_CodeType = Request.QueryString("spg").ToUpper
End Select
If Not Page.IsPostBack Then
cmdDelete.Visible = False
Select Case _CodeType.ToUpper
Case "COU"
pnlProduct.Visible = True
Case "CAR"
pnlProduct.Visible = False
Case "STO"
pnlProduct.Visible = False
Case Else
pnlEdit.Visible = False
End Select
Dim chk As String = GetStoreSetting(PortalId, "allowmultidiscount.flag", "None")
If chk = "" Then chk = "false"
chkAllowMultiDiscount.Checked = CBool(chk)
populateGV()
End If
End If
Catch exc As Exception
ProcessModuleLoadException(Me, exc)
End Try
End Sub
Private Sub cmdNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNew.Click
AddNewRecord(-1, "")
Response.Redirect(Request.Url.ToString)
End Sub
Private Sub cmdSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdSearch.Click
populateGV()
End Sub
Private Sub chkAllowMultiDiscount_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkAllowMultiDiscount.CheckedChanged
SetStoreSetting(PortalId, "allowmultidiscount.flag", chkAllowMultiDiscount.Checked.ToString, "None", False)
End Sub
#Region "Procedures"
Private Sub AddNewRecord(ByVal ObjectID As Integer, ByVal Description As String)
Dim objCtrl As New PromoController
Dim objInfo As New NB_Store_PromoInfo
objInfo.PromoID = 0
objInfo.ObjectID = ObjectID
objInfo.Range1 = 0
objInfo.Range2 = 0
objInfo.PromoName = Localization.GetString("New_Promotion", LocalResourceFile)
objInfo.PromoType = _CodeType.ToUpper
objInfo.Disabled = False
objInfo.PromoAmount = 0
objInfo.PromoGroup = ""
objInfo.PromoPercent = 0
objInfo.PortalID = PortalId
objInfo.RangeEndDate = DateAdd(DateInterval.Year, 10, Today).ToString
objInfo.RangeStartDate = Today.ToString
objInfo.PromoCode = ""
objInfo.QtyRange1 = 0
objInfo.QtyRange2 = 0
objInfo.MaxUsagePerUser = 0
objCtrl.UpdateObjPromo(objInfo)
UpdateLog(UserId, Me.ControlName & " - " & System.Reflection.MethodBase.GetCurrentMethod.Name & " - " & DotNetNuke.Common.Utilities.XmlUtils.Serialize(objInfo))
End Sub
#End Region
#Region "gvDiscount Methods - Events"
#Region "gvDiscount Events"
Private Sub gvPromo_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles gvPromo.RowCancelingEdit
gvPromo.EditIndex = -1
populateGV()
End Sub
Private Sub gvDiscount_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles gvPromo.RowEditing
gvPromo.EditIndex = e.NewEditIndex
populateGV()
setupFields()
End Sub
Private Sub gvDiscount_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvPromo.RowDataBound
Dim row As GridViewRow = e.Row
If row.RowType = DataControlRowType.DataRow Then
Dim cmd As LinkButton
cmd = e.Row.FindControl("cmdDelete")
cmd.Text = "<img src=""" + StoreInstallPath + "img/delete.png"" border=""0"" />"
cmd.Attributes.Add("onClick", "javascript:return confirm('" & Localization.GetString("cmdDelete", LocalResourceFile) & "');")
If row.RowIndex = gvPromo.EditIndex Then
Dim hyp As HyperLink
Dim txt As TextBox
hyp = e.Row.FindControl("hypDateRange1")
If Not hyp Is Nothing Then
txt = e.Row.FindControl("txtDateRange1")
If Not txt Is Nothing Then
hyp.Text = "<img src=""" + DotNetNuke.Common.Globals.ApplicationPath + "/images/calendar.png"" border=""0"" />"
hyp.NavigateUrl = DotNetNuke.Common.Utilities.Calendar.InvokePopupCal(txt)
End If
End If
hyp = e.Row.FindControl("hypDateRange2")
If Not hyp Is Nothing Then
txt = e.Row.FindControl("txtDateRange2")
If Not txt Is Nothing Then
hyp.Text = "<img src=""" + DotNetNuke.Common.Globals.ApplicationPath + "/images/calendar.png"" border=""0"" />"
hyp.NavigateUrl = DotNetNuke.Common.Utilities.Calendar.InvokePopupCal(txt)
End If
End If
Dim ddl As DropDownList
ddl = e.Row.FindControl("ddlCategories")
If Not ddl Is Nothing Then
populateCategoryList(PortalId, ddl, -1, "All Categories", CType(row.DataItem, NB_Store_PromoInfo).ObjectID.ToString)
End If
Dim ddl2 As DropDownList
ddl2 = e.Row.FindControl("ddlPromoGroup")
If Not ddl2 Is Nothing Then
populateRoleList(ddl2, CType(row.DataItem, NB_Store_PromoInfo).PromoGroup)
End If
End If
End If
End Sub
Private Sub populateRoleList(ByVal ddl As DropDownList, ByVal SelectedRole As String)
Dim objSCtrl As New SettingsController
Dim objSInfo As NB_Store_SettingsInfo
Dim PromoRoles As String()
Dim rtnPrice As Double = -1
Dim strList As String = ""
ddl.Items.Clear()
objSInfo = objSCtrl.GetSetting(PortalId, "promo.roles", "None")
If Not objSInfo Is Nothing Then
strList = "," & objSInfo.SettingValue
PromoRoles = strList.Split(","c)
For lp As Integer = 0 To PromoRoles.GetUpperBound(0)
ddl.Items.Add(PromoRoles(lp))
Next
If ddl.Items.Count = 1 Then
ddl.Enabled = False
End If
Else
ddl.Enabled = False
End If
If Not ddl.Items.FindByValue(SelectedRole) Is Nothing Then
ddl.ClearSelection()
ddl.Items.FindByValue(SelectedRole).Selected = True
End If
End Sub
Private Sub gvDiscount_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gvPromo.RowUpdating
If Page.IsValid Then
Dim row As GridViewRow = gvPromo.Rows(e.RowIndex)
Dim SDate As Date = CDate(getGridViewValueDate(row, "txtDateRange1"))
Dim EDate As Date = CDate(getGridViewValueDate(row, "txtDateRange2"))
updateGVrow(e)
gvPromo.EditIndex = -1
populateGV()
If _CodeType.ToUpper = "STO" Then
'recalulate salepricetable if active today
If SDate <= Today And EDate >= Today Then
Dim objCtrl As New PromoController
objCtrl.createSalePriceTable(PortalId)
End If
End If
End If
End Sub
Private Sub gvPromo_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles gvPromo.RowDeleting
Dim row As GridViewRow = gvPromo.Rows(e.RowIndex)
Dim SDate As Date = CDate(getGridViewValueDate(row, "txtDateRange1"))
Dim EDate As Date = CDate(getGridViewValueDate(row, "txtDateRange2"))
deleteGVrow(e)
gvPromo.EditIndex = -1
populateGV()
If _CodeType.ToUpper = "STO" Then
'recalulate salepricetable if active today
If SDate <= Today And EDate >= Today Then
Dim objCtrl As New PromoController
objCtrl.createSalePriceTable(PortalId)
End If
End If
End Sub
#End Region
#Region "gvDiscount Methods"
Private Sub populateGV()
Dim objCtrl As New PromoController
Dim list As ArrayList
DotNetNuke.Services.Localization.Localization.LocalizeGridView(gvPromo, LocalResourceFile)
list = objCtrl.GetPromoList(PortalId, _CodeType.ToUpper, txtSearch.Text)
gvPromo.DataSource = list
gvPromo.DataBind()
End Sub
Private Sub updateGVrow(ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs)
Dim objCtrl As New PromoController
Dim objInfo As New NB_Store_PromoInfo
Dim row As GridViewRow = gvPromo.Rows(e.RowIndex)
objInfo.Disabled = Not (getGridViewValueBool(row, "chkDisable"))
objInfo.PromoAmount = getGridViewValueDbl(row, "txtAmount")
objInfo.PromoCode = getGridViewValue(row, "txtPromoCode")
objInfo.PromoGroup = getGridViewValue(row, "ddlPromoGroup")
objInfo.PromoUser = getGridViewValue(row, "txtPromoUser")
objInfo.PromoID = getGridViewValueInt(row, "PromoID")
objInfo.PromoName = getGridViewValue(row, "txtName")
objInfo.PromoPercent = getGridViewValueDbl(row, "txtPercent")
objInfo.PromoType = getGridViewValue(row, "PromoType")
objInfo.ObjectID = getGridViewValueInt(row, "ObjectID")
objInfo.PortalID = PortalId
objInfo.Range1 = getGridViewValueDbl(row, "txtRange1")
objInfo.Range2 = getGridViewValueDbl(row, "txtRange2")
objInfo.RangeEndDate = getGridViewValueDate(row, "txtDateRange2")
objInfo.RangeStartDate = getGridViewValueDate(row, "txtDateRange1")
objInfo.QtyRange1 = getGridViewValueInt(row, "txtQtyRange1")
objInfo.QtyRange2 = getGridViewValueInt(row, "txtQtyRange2")
objInfo.PromoEmail = getGridViewValue(row, "txtPromoEmail")
objInfo.ObjectID = getGridViewValueInt(row, "ddlCategories")
objInfo.MaxUsagePerUser = getGridViewValueInt(row, "txtMaxUsagePerUser")
objInfo.MaxUsage = getGridViewValueInt(row, "txtMaxUsage")
objCtrl.UpdateObjPromo(objInfo)
UpdateLog(UserId, Me.ControlName & " - " & System.Reflection.MethodBase.GetCurrentMethod.Name & " - " & DotNetNuke.Common.Utilities.XmlUtils.Serialize(objInfo))
End Sub
Private Sub deleteGVrow(ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs)
Dim objCtrl As New PromoController
Dim objInfo As New NB_Store_PromoInfo
Dim row As GridViewRow = gvPromo.Rows(e.RowIndex)
objCtrl.DeletePromo(getGridViewValueInt(row, "PromoID"))
UpdateLog(UserId, Me.ControlName & " - " & System.Reflection.MethodBase.GetCurrentMethod.Name & " - " & DotNetNuke.Common.Utilities.XmlUtils.Serialize(objInfo))
End Sub
Private Sub setupFields()
Dim row As GridViewRow = gvPromo.Rows(gvPromo.EditIndex)
Dim strList As String = ""
Select Case _CodeType.ToUpper
Case "COU"
'strList = "plCategories,"
'strList &= "ddlCategories"
Case "CAR"
strList = "plPromoCode,"
strList &= "plCategories,"
strList &= "txtPromoCode,"
strList &= "ddlCategories,"
'hide MaxUsagePerUser controls for category discounts
strList &= "plMaxUsagePerUser,"
strList &= "txtMaxUsagePerUser,"
strList &= "plMaxUsage,"
strList &= "txtMaxUsage"
Case "STO"
strList = "plPromoCode,"
strList &= "lblQtySep,"
strList &= "lblPriceSep,"
strList &= "plPromoUser,"
strList &= "plPromoCode,"
strList &= "plPromoUser,"
strList &= "plQtyRange,"
strList &= "plRange,"
strList &= "plPromoEmail,"
strList &= "txtPromoCode,"
strList &= "txtPromoUser,"
strList &= "txtPromoCode,"
strList &= "txtPromoUser,"
strList &= "txtQtyRange1,"
strList &= "txtQtyRange2,"
strList &= "txtRange1,"
strList &= "txtRange2,"
strList &= "txtPromoEmail,"
'hide MaxUsagePerUser controls for cart discounts
strList &= "plMaxUsagePerUser,"
strList &= "txtMaxUsagePerUser,"
strList &= "plMaxUsage,"
strList &= "txtMaxUsage"
Case Else
pnlEdit.Visible = False
End Select
If strList <> "" Then
setGridViewVisible(row, strList, False)
End If
End Sub
#End Region
#End Region
End Class
End Namespace