Option Explicit Dim lineitemshome As Object ' LienItemsHome Dim skuhome As Object ' SKUHome Dim poqueryhome As Object ' POQueryHome ' Performs a query against Purchase Order tables Private Sub btnQuery_Click() Dim where As String Dim e As Object Dim xItem As ListItem ' Clears the current query result lstPOQuery.ListItems.Clear ' Builds the where string If Len(edtOrderNo.Text) > 0 And IsNumeric(edtOrderNo.Text) Then where = " Where ponumber = " + edtOrderNo.Text End If If Len(cmbStatus.Text) > 0 Then If Len(where) > 0 Then where = where + " And Status = '" + cmbStatus.Text + "'" Else where = " Where Status = '" + cmbStatus.Text + "'" End If End If ' Invokes POQueryHome EJB's findAllPos to get all the Purchase Order ' records that match the query criteria If Len(where) > 0 Then Set e = poqueryhome.findAllPos(where) Else Set e = poqueryhome.findAllPos("") End If ' Displays the query result in lstPOQuery list ' Each element in iterator represents a POQuery EJB object While e.hasMoreElements Dim poquery As Object Dim ponumber As String Dim status As String ' Get the Purchase Order status by invoking POQuery EJB object's get getStatus method Set poquery = e.nextElement() ' Get the Purchase Order number by invoking POQuery EJB object's get PONumber method ponumber = poquery.getPONumber() ' Get the Purchase Order status by invoking POQuery EJB object's get getStatus method status = poquery.getStatus() Set xItem = lstPOQuery.ListItems.Add(Text:=ponumber) xItem.SubItems(1) = status Wend End Sub Private Sub Form_Load() Dim poqerystr As String lstPOQuery.ColumnHeaders.Clear ' lstPOQuery ColumnHeaders. lstPOQuery.ColumnHeaders.Add , , "Purchase Order Number" lstPOQuery.ColumnHeaders.Add , , "Status" ' lstPODetail ColumnHeaders. lstPODetail.ColumnHeaders.Add , , "Description", 3800 lstPODetail.ColumnHeaders.Add , , "Unit Price" lstPODetail.ColumnHeaders.Add , , "Amount", 800 lstPODetail.ColumnHeaders.Add , , "Total Price" ' Creates the JNDI name of POQueryHome EJB poqerystr = PurchaseOrderForm.jvmStr + ":sess_iiop://" + PurchaseOrderForm.hostStr + ":2481:" + PurchaseOrderForm.sidStr + "/test/POQueryBean" ' Creates a new POQueryHome EJB object Set poqueryhome = GetObject(poqerystr) End Sub ' Updates the lstPODetail list to show the content of currently selected ' Purchase Order item on lstPOQuery list Private Sub lstPOQuery_ItemClick(ByVal item As ComctlLib.ListItem) Dim e As Object Dim sku As Object Dim lineitemsstr As String Dim skustr As String Dim xItem As ListItem Dim ponumber As String Dim where As String Dim lineitem As Object lstPODetail.ListItems.Clear If Not IsNull(item) Then ponumber = item.Text ' Creates the JNDI name of SKUHome EJB skustr = PurchaseOrderForm.jvmStr + ":sess_iiop://" + PurchaseOrderForm.hostStr + ":2481:" + PurchaseOrderForm.sidStr + "/test/SKUBean" ' Creates the JNDI name of LineItemsHome EJB lineitemsstr = PurchaseOrderForm.jvmStr + ":sess_iiop://" + PurchaseOrderForm.hostStr + ":2481:" + PurchaseOrderForm.sidStr + "/test/LineItemsBean" Set lineitemshome = GetObject(lineitemsstr) ' Creates a new SKUHome EJB object Set skuhome = GetObject(skustr) where = " Where ponumber = " + ponumber ' Finds all line items belong to the selected purchase rder Set e = lineitemshome.findAllLineItems(where) ' Each element in iterator represents a LineItems EJB object While e.hasMoreElements Dim skunumber As String Dim count As String Dim price As String Dim description As String Set lineitem = e.nextElement() ' Gets the SKU Number of the current line item by invoking LineItems EJB object's get SKUNumber method skunumber = lineitem.getSKUNumber() ' Gets the Count of the current line item by invoking LineItems EJB object's get getCount method count = lineitem.getCount() ' Finds the SKU record of this line item by invoking SKUHome object's findByPrimaryKey method Set sku = skuhome.findByPrimaryKey(skunumber) ' Gets the unit price of the current line item by invoking SKUHome object's getPrice method price = sku.getPrice() ' Gets the description of the current line item by invoking SKUHome object's getDescription method description = sku.getDescription() Set xItem = lstPODetail.ListItems.Add(Text:=description) xItem.SubItems(1) = price xItem.SubItems(2) = count xItem.SubItems(3) = Str(Val(price) * Val(count)) Wend End If End Sub |