eRace System Sales and Member Lookup Functions

eRace System Sales and Member Lookup

BtnFetch_Click Event

This code handles the Click event of the BtnFetch button. It retrieves member information based on the provided MemberID and selected sales type.

Protected Sub BtnFetch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnFetch.Click
    Search.Text = Search.Text.Trim
    If SalesType.SelectedIndex = 3 Then
        If Search.Text.Length = 0 Then
            FormMessage.Text = "Please enter a MemberID to be searched."
        Else
            Dim SystemMgr As New eRaceSystem.eRace
            Dim MemberInfo As DataSet
            Try
                MemberInfo = SystemMgr.LookupMemberbyMemberID(Search.Text)
                If MemberInfo.Tables(0).Rows.Count = 0 Then
                    FormMessage.Text = "Member not found."
                    Name.Text = ""
                    Phone.Text = ""
                    Balance.Text = ""
                Else
                    With MemberInfo.Tables(0).Rows(0)
                        Name.Text = .Item("Name")
                        Phone.Text = .Item("Phone")
                        Balance.Text = Format(.Item("Balance"), "0.00")
                    End With
                    Dim aCookie As New HttpCookie("member")
                    aCookie("memberId") = Search.Text.Trim.ToString
                    aCookie("name") = Name.Text.Trim.ToString
                    aCookie("phone") = Phone.Text.Trim.ToString
                    aCookie("balance") = Balance.Text.Trim.ToString
                    aCookie("cardNo") = CreditCardNumber.Text.Trim.ToString
                    aCookie("SalesType") = SalesType.SelectedValue
                    Response.Cookies.Add(aCookie)
                End If
            Catch ex As Exception
                FormMessage.Text = ex.Message
            End Try
        End If
    Else
        FormMessage.Text = "Account payment only requires a Member ID"
        Name.Text = ""
        Phone.Text = ""
        Balance.Text = ""
        Search.Text = ""
    End If
End Sub

Key Functionalities:

  • Trims the search text.
  • Checks if SalesType is “Account Payment” (SelectedIndex = 3).
  • Validates that a MemberID is entered.
  • Looks up member information using LookupMemberbyMemberID.
  • Displays member details (Name, Phone, Balance) if found.
  • Sets an HttpCookie with member data.
  • Handles exceptions and displays error messages.

BtnSubmitSale_Click Event

This code handles the Click event of the BtnSubmitSale button. It processes sales transactions based on the selected sales type and provided information.

Protected Sub BtnSubmitSale_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnSubmitSale.Click
    Dim Cart As DataSet = RetrieveCart()
    Dim invoiceNumber As String = 0
    If Cart.Tables(0).Rows.Count > 0 Then
        Try
            Dim systemmgr As New eRaceSystem.eRace
            If SalesType.SelectedIndex = 0 Then
                invoiceNumber = systemmgr.UpdateSales(Search.Text.ToString, CreditCardNumber.Text.ToString, SalesType.SelectedIndex + 1, CDec(GST.Text), CDec(Total.Text), Cart)
                FormMessage.Text = "Success! Invoice number = " & invoiceNumber
                ClearData()
            ElseIf SalesType.SelectedIndex = 3 Then
                If Search.Text = "" Then
                    FormMessage.Text = "Only members can use Account payment."
                ElseIf Name.Text = "" Then
                    FormMessage.Text = "Member ID is required."
                Else
                    invoiceNumber = systemmgr.UpdateSales(Search.Text.ToString, CreditCardNumber.Text.ToString, SalesType.SelectedIndex + 1, CDec(GST.Text), CDec(Total.Text), Cart)
                    FormMessage.Text = "Success! Invoice number = " & invoiceNumber
                    ClearData()
                End If
            ElseIf SalesType.SelectedIndex = 1 Or SalesType.SelectedIndex = 2 Then
                If CreditCardNumber.Text.Length >= 12 And CreditCardNumber.Text.Length <= 16 Then
                    invoiceNumber = systemmgr.UpdateSales(Search.Text.ToString, CreditCardNumber.Text.ToString, SalesType.SelectedIndex + 1, CDec(GST.Text), CDec(Total.Text), Cart)
                    FormMessage.Text = "Success! Invoice number = " & invoiceNumber
                    ClearData()
                Else
                    FormMessage.Text = "Card number must be between 12 to 16 digits"
                End If
            Else
                FormMessage.Text = "Select payment method."
            End If
        Catch ex As Exception
            FormMessage.Text = ex.Message
        End Try
    Else
        FormMessage.Text = "No records to process."
    End If
End Sub

Key Functionalities:

  • Retrieves the shopping cart data using RetrieveCart().
  • Checks if the cart has items.
  • Processes sales based on SalesType (Cash, Debit, Credit, Account Payment).
  • Validates MemberID for “Account Payment”.
  • Validates credit card number length for “Debit” and “Credit”.
  • Calls UpdateSales to update the sales records.
  • Displays the invoice number upon successful transaction.
  • Clears data after processing using ClearData().
  • Handles exceptions and displays error messages.