Imports WorkshopsLibrary |
|
Partial Public Class addons |
Inherits System.Web.UI.Page |
|
Protected sUserID As String |
Protected sWorkshopID As String |
Protected bNewOrder As Boolean = False |
Protected bSomethingChecked As Boolean = False |
|
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load |
|
Dim cPageRoutines As New CPageRoutines |
Dim cRegistration As New CRegistration |
|
cPageRoutines.VerifyWorkshop("wid") |
cPageRoutines.VerifyPageNotVisited("AddOnsPageNotVisited") |
|
sWorkshopID = HttpContext.Current.Request.QueryString("wid") |
|
If (HttpContext.Current.Session("UserID") Is Nothing) Then |
sUserID = "" |
Else |
sUserID = HttpContext.Current.Session("UserID").ToString |
End If |
|
If (HttpContext.Current.Session(sWorkshopID & "-RegistrationID") Is Nothing) Then |
Response.Redirect("search.aspx?wid=" & sWorkshopID) |
Else |
hidRegistrationID.Value = HttpContext.Current.Session(sWorkshopID & "-RegistrationID").ToString |
End If |
|
cRegistration.LoadRegistrationTypeID(sUserID, hidRegistrationID.Value) |
hidRegistrationTypeID.Value = cRegistration.RegistrationTypeID.ToString |
|
If (HttpContext.Current.Session(sWorkshopID & "-OrderID") Is Nothing) Then |
bNewOrder = True |
End If |
|
End Sub |
|
Private Sub cmdSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdSave.Click |
|
If Page.IsValid Then |
If CustomValidation() Then |
If bSomethingChecked Then |
SaveAddOns() |
Else |
Response.Redirect("payment.aspx?wid=" & sWorkshopID) |
End If |
Else |
lblStatus.Visible = True |
End If |
End If |
|
End Sub |
|
Private Function CustomValidation() As Boolean |
|
Dim bValid As Boolean = True |
Dim bMismatchItem As Boolean = False |
Dim bMismatchQuantity As Boolean = False |
|
For Each row As GridViewRow In gvAddOns.Rows |
Dim chkItem As CheckBox = CType(row.FindControl("chkItem"), CheckBox) |
Dim txtQuantity As TextBox = CType(row.FindControl("txtQuantity"), TextBox) |
If chkItem IsNot Nothing AndAlso chkItem.Checked Then |
bSomethingChecked = True |
If txtQuantity.Text = "" Then |
bMismatchItem = True |
End If |
Else |
If txtQuantity.Text <> "" Then |
bMismatchQuantity = True |
End If |
End If |
Next |
|
If bMismatchItem Then |
bValid = False |
lblStatus.Text = "Error: You must enter the quantity for the item you selected." |
End If |
|
If bMismatchQuantity Then |
bValid = False |
lblStatus.Text = "Error: You must check the item for which you have entered a quantity." |
End If |
|
Return bValid |
|
End Function |
|
Private Sub SaveAddOns() |
|
Dim cRegistration As New CRegistration |
Dim iRet As Integer |
Dim bRet As Boolean = False |
|
If bNewOrder Then |
iRet = cRegistration.AddOrder(sUserID, hidRegistrationID.Value, sWorkshopID) |
HttpContext.Current.Session(sWorkshopID & "-OrderID") = CStr(iRet) |
End If |
|
For Each row As GridViewRow In gvAddOns.Rows |
Dim chkItem As CheckBox = CType(row.FindControl("chkItem"), CheckBox) |
Dim txtQuantity As TextBox = CType(row.FindControl("txtQuantity"), TextBox) |
If chkItem IsNot Nothing AndAlso chkItem.Checked Then |
bRet = cRegistration.AddUpOrderItem(sUserID, _ |
HttpContext.Current.Session(sWorkshopID & "-OrderID").ToString, _ |
gvAddOns.DataKeys(row.RowIndex).Value.ToString, _ |
txtQuantity.Text) |
If Not bRet Then |
Exit For |
End If |
End If |
Next |
|
If bRet Then |
HttpContext.Current.Session("AddOnsPageNotVisited") = Nothing |
Response.Redirect("payment.aspx?wid=" & sWorkshopID) |
Else |
lblStatus.Text = "Save failed!" |
lblStatus.Visible = True |
End If |
|
End Sub |
End Class |