Purchase Order Form source code

Here is the source code of PurchaseOrderForm
Option Explicit
Dim skuhome As Object ' SKUHome
Dim purchaseorderhome As Object ' PurchaseOrderHome
Public hostStr As String
Public sidStr As String
Public jvmStr As String
' This method validates the hostname, SID, and registered JVM and if they
' are Ok, it creates a SKUHome object
Private Sub btnActivate_Click()
On Error GoTo errh
Dim e As Object
Dim xItem As ListItem
Dim skustr As String
    ' Disables action buttons in case the operation failed
    btnAdd.Enabled = False
    btnDelete.Enabled = False
    btnUpdate.Enabled = False
    btnSubmit.Enabled = False
    btnQuery.Enabled = False
    
    lstSKU.ListItems.Clear
    ' Gets the address of computer hosting Oracle Application Server
    hostStr = edtServerAddress.Text
    ' Gets the SID of the database in which the Purchase Order EJBs have been deployed
    sidStr = edtSID.Text
    ' Gets the name of J-Integra® bridging server
    jvmStr = edtJVM.Text
    If Len(hostStr) > 0 And Len(sidStr) > 0 And Len(jvmStr) Then
        ' Creates the JNDI name of SKUHome EJB
        skustr = jvmStr + ":sess_iiop://" + hostStr + ":2481:" + sidStr + "/test/SKUBean"
        ' Creates a new SKUHome EJB object
        Set skuhome = GetObject(skustr)
        ' Finds all SKU records on the database
        Set e = skuhome.findAllSkus("")
        ' Fills lstSKU list with the SKU records data
        While e.hasMoreElements
            Dim sku As Object
            Dim skunumber As String
            Dim skudesc As String
            Dim skuprice As String
            Set sku = e.nextElement()
            skunumber = sku.getSKUNumber()
            skudesc = sku.getDescription()
            skuprice = sku.getPrice()
            Set xItem = lstSKU.ListItems.Add(Text:=skunumber)
            xItem.SubItems(1) = skudesc
            xItem.SubItems(2) = skuprice
        Wend
        ' Enables action buttons so user can create a purchase order and submit it.
        btnAdd.Enabled = True
        btnDelete.Enabled = True
        btnUpdate.Enabled = True
        btnSubmit.Enabled = True
        btnQuery.Enabled = True
    Else
        MsgBox "Please specify the Address of DB Server, the SID, and the JVM!"
    End If
Exit Sub
errh:
MsgBox "Failed to create EJBs:" + Err.description
End Sub

' Adds the new purchase order item to the current purchase order
Private Sub btnAdd_Click()
Dim xItem As ListItem
Dim skunumber As String
Dim skudesc As String
Dim skuprice As String
Dim skutotalprice As String
Dim amount As String

    Set xItem = lstSKU.SelectedItem
    If Not IsNull(xItem) Then
        amount = edtAmount.Text
        skunumber = xItem.Text
        If IsNumeric(amount) Then
            skudesc = xItem.SubItems(1)
            skuprice = xItem.SubItems(2)
            skutotalprice = Str(Val(amount) * Val(skuprice))
            
            Set xItem = lstPurchaseOrder.ListItems.Add(Text:=skunumber)
            xItem.SubItems(1) = skudesc
            xItem.SubItems(2) = skuprice
            xItem.SubItems(3) = amount
            xItem.SubItems(4) = skutotalprice
        End If
    End If

End Sub

' Removes a purchase order item from the current purchase order
Private Sub btnDelete_Click()
Dim xItem As ListItem
    Set xItem = lstPurchaseOrder.SelectedItem
    If Not IsNull(xItem) Then
        lstPurchaseOrder.ListItems.Remove (xItem.Index)
    End If
End Sub

' Updates a purchase order item on the current purchase order
Private Sub btnUpdate_Click()
Dim xItem As ListItem
Dim yItem As ListItem
Dim skunumber As String
Dim skudesc As String
Dim skuprice As String
Dim skutotalprice As String
Dim amount As String
    Set xItem = lstSKU.SelectedItem
    Set yItem = lstPurchaseOrder.SelectedItem
    If Not IsNull(xItem) And Not IsNull(yItem) Then
        amount = edtAmount.Text
        skunumber = xItem.Text
        If IsNumeric(amount) Then
            skudesc = xItem.SubItems(1)
            skuprice = xItem.SubItems(2)
            skutotalprice = Str(Val(amount) * Val(skuprice))
            
            yItem.SubItems(1) = skudesc
            yItem.SubItems(2) = skuprice
            yItem.SubItems(3) = amount
            yItem.SubItems(4) = skutotalprice
        End If
    End If
End Sub

' Submits the current purchase order
Private Sub btnSubmit_Click()
Dim purchaseorderstr As String
Dim xItem As ListItem
Dim utstr As String
Dim I As Integer
Dim po As Object
    If lstPurchaseOrder.ListItems.count > 0 Then
        ' Creates the JNDI name of PurchaseOrderHome EJB
        purchaseorderstr = jvmStr + ":sess_iiop://" + hostStr + ":2481:" + sidStr + "/test/PurchaseOrderBean"
        ' Creates a new PurchaseOrderHome EJB object
        Set purchaseorderhome = GetObject(purchaseorderstr)
        ' Creates a new PurchaseOrder EJB object
        Set po = purchaseorderhome.Create()
        For I = 1 To lstPurchaseOrder.ListItems.count
            Set xItem = lstPurchaseOrder.ListItems(I)
            ' Adds the current purchase order items to the new PurchaseOrder EJB object
            po.AddItem Val(xItem.Text), Val(xItem.SubItems(3))
        Next I
        MsgBox "Purchase Order successfully submitted."
        ' Clears the current purchase order
        lstPurchaseOrder.ListItems.Clear
    End If
End Sub

' Displays the QueryForm
Private Sub btnQuery_Click()
QueryForm.Show
End Sub

Private Sub Form_Load()
    lstSKU.ColumnHeaders.Clear
    ' lstSKU ColumnHeaders.
    lstSKU.ColumnHeaders.Add , , "SKUNumber"
    lstSKU.ColumnHeaders.Add , , "Description", 3800
    lstSKU.ColumnHeaders.Add , , "Unit Price"
    
    lstPurchaseOrder.ColumnHeaders.Clear
    ' lstPurchaseOrder ColumnHeaders.
    lstPurchaseOrder.ColumnHeaders.Add , , "SKUNumber"
    lstPurchaseOrder.ColumnHeaders.Add , , "Description", 3800
    lstPurchaseOrder.ColumnHeaders.Add , , "Unit Price"
    lstPurchaseOrder.ColumnHeaders.Add , , "Amount", 800
    lstPurchaseOrder.ColumnHeaders.Add , , "Total Price"
    ' Calls Activate button to connect to the Oracle Application Server
    btnActivate_Click
End Sub

        
Note: The default values for the host name, SID, and J-Integra® bridging server are: localhost, ORCL, and oraclejvm; respectively. When you run the application, upon loading the form the VB client will try to connect to Oracle Application Server using default values. If the default values are not cirrent in your case, you will see an error message. Enter the correct values for these items and click on the "Activate" button. If the new values are valid, the aplication will enable the other action buttons and you can start using the system.