Home

Database Application: Fun Department Store

   

Description

As its name indicates, a table adapter is an object that gives access to a database's table. This is a review of the automatically generated data set and its data tables created by the Data Source Configuration Wizard of Microsoft Visual Studio 2008.  To illustrate the features, we create an application for a department store.

     
Author Note

The clothes (manufacturers, names, sizes, categories, and prices used in the database of this application were retrieved/taken from the Lord & Taylor and the Ann Taylor web sites (http://www.lordandtaylor.com and http://www.anntaylor.com) (This just in case you want to know; this is not an advertisement) during the month of November 2009 (most, if not all, of the items without a manufacturer are from Ann Taylor).

Practical LearningPractical Learning: Introducing Data Sets

  1. Open the FunDS1.htm file
  2. Select its content and copy it
  3. Start Microsoft SQL Server and connect to the server
  4. Create a Query window and paste the code in it
  5. To create the database, press F5
  6. Start Microsoft Visual Studio and create a Windows Application named FunDepartmentStore1
  7. In the Solution Explorer, right-click Form1.cs and click Rename
  8. Type Central.vb and press Enter
  9. From the Components section of the Toolbox, click Timer and click the form
  10. Design the form as follows:
     
    Department Store
    Control Text Name
    Button Process a Customer Order btnProcessOrder
    Button Create a New Store Item btnCreateStoreItem
    Button View Current Inventory btnCurrentInventory
    Button Manage a Store Items btnManageStoreItem
    Button Close btnClose
  11. To add a new form, on the menu, click Project -> Add Windows Form...
  12. Set the Name to ShoppingSession and click Add
  13. Design the form as follows:
     
    Department Store
    Control Text Name Other Properties
    Form Fun Department Store - Shopping Session   ShowInTaskbar: False
    StartPosition: CenterScreen
    Panel     BorderStyle: Fixed3D
    Label Item #   Font: Times New Roman, 20.25pt, style=Bold
    ForeColor: Blue
    Label Item Name/Description   Font: Times New Roman, 20.25pt, style=Bold
    ForeColor: Blue
    Label Size   Font: Times New Roman, 20.25pt, style=Bold
    ForeColor: Blue
    Label Unit Price   Font: Times New Roman, 20.25pt, style=Bold
    ForeColor: Blue
    TextBox   txtItemNumber Font: Times New Roman, 20.25pt
    TextAlign: Center
    TextBox   txtItemName Font: Times New Roman, 20.25pt
    TextBox   txtItemSize Font: Times New Roman, 20.25pt
    TextBox   txtUnitPrice Font: Times New Roman, 20.25pt
    TextAlign: Right
    ListView   lvwShoppingSession Anchor: Top, Bottom, Left, Right
    Font: Times New Roman, 20.25pt
    FullRowSelect: True
    GridLines: True
    View: Details
      Columns
    (Name) Text TextAlign Width
    colItemNumber Item #   100
    colItemName Item Name/Description   446
    colItemSize Size Center 100
    colUnitPrice Unit Price Right 124
    Label Type of Payment:   Font: Times New Roman, 20.25pt, style=Bold
    ForeColor: Blue
    ComboBox   cbxCurrencyType Font: Times New Roman, 20.25pt, style=Bold
    Items: Cash
              Check
              Visa
              Master Card
              Store Card
    Label Order Total:   Font: Times New Roman, 20.25pt, style=Bold
    ForeColor: Blue
    TextBox   txtOrderTotal Anchor: Bottom, Right
    Font: Times New Roman, 20.25pt, style=Bold
    Text: 0.00
    TextAlign: Right
    Label Order Time:   Font: Times New Roman, 20.25pt, style=Bold
    ForeColor: Blue
    Label Order Date:   Font: Times New Roman, 20.25pt, style=Bold
    ForeColor: Blue
    Label Amount Tended:   Font: Times New Roman, 20.25pt, style=Bold
    ForeColor: Blue
    TextBox   txtAmountTended Anchor: Bottom, Right
    Font: Times New Roman, 20.25pt, style=Bold
    Text: 0.00
    TextAlign: Right
    Button   btnSubmitOrder Anchor: Bottom, Left, Right
    Font: Times New Roman, 20.25pt, style=Bold
    Label Change:   Font: Times New Roman, 20.25pt, style=Bold
    ForeColor: Blue
    TextBox   txtChange Anchor: Bottom, Right
    Font: Times New Roman, 20.25pt, style=Bold
    Text: 0.00
    TextAlign: Right
    Label Receipt #:   Font: Times New Roman, 20.25pt, style=Bold
    ForeColor: Blue
    TextBox   txtReceiptNumber Anchor: Bottom, Right
    Font: Times New Roman, 20.25pt, style=Bold
    Button   btnCancelOrder Anchor: Bottom, Left, Right
    Font: Times New Roman, 20.25pt, style=Bold
    Panel     BorderStyle: Fixed3D
    Label   lblDate Font: Times New Roman, 20.25pt, style=Bold
    ForeColor: Blue
    Label   lblTime Font: Times New Roman, 20.25pt, style=Bold
    ForeColor: Blue
    Button   btnClose Anchor: Bottom, Left, Right
    Font: Times New Roman, 20.25pt, style=Bold
    Timer   tmrDateTime Enabled: True
  14. Double-click the timer
  15. Implement its event as follows:
    Private Sub tmrDateTime_Tick(ByVal sender As System.Object, _
                                     ByVal e As System.EventArgs) _
                                     Handles tmrDateTime.Tick
            lblDate.Text = DateTime.Today.ToLongDateString()
            lblTime.Text = DateTime.Now.ToLongTimeString()
    End Sub
  16. Save All

Practical LearningPractical Learning: Generating a Table Adapter

  1. On the main menu, click Data -> Add New Data Source...
  2. On the first page of the wizard, make sure Database is selected and click Next
  3. In the second page of the wizard, click New Connection...
  4. In the Server Name combo box, select the server or type (local)
  5. In the Select or Enter a Database Name combo box, select FunDS1
  6. Click Test Connection
  7. Click OK twice
  8. On the Data Source Configuration Wizard, make sure the new connection is selected
    Click the + button of Connection String
  9. Click Next
  10. Change the connection string to CstrFunDS and click Next
  11. Click the check box of Tables (to select all tables)
  12. Change the name of the data set to DsFunDS
     
    Data Source Configuration Wizard
  13. Click Finish
  14. In the Solution Explorer, double-click dsFunDS.Designer.cs to open and view the file
  15. Press Ctrl + F5 to execute
  16. After viewing the main form, close it
  17. Display the ShoppingSession form
  18. In the top section of the Toolbox, click dsFunDS and click the form
  19. In the top section of the Toolbox, click CustomersOrdersTableAdapter and click the form
  20. In the Properties window, change its name to TaCustomersOrders
  21. In the top section of the Toolbox, click ReceiptsSummariesTableAdapter and click the form
  22. In the Properties window, change its name to TaReceiptsSummaries
  23. In the top section of the Toolbox, click StoreItemsTableAdapter and click the form
  24. In the Properties window, change its name to TaStoreItems
  25. Save the form

Practical LearningPractical Learning: Getting the Records

  1. To add another form, on the main menu, click Project -> Add Windows Form
  2. Set the Name to CurrentStoreInventory and click Add
  3. In the top section of the Toolbox, click DsFunDS and click the form
  4. In the top section of the Toolbox, click StoreItemsTableAdapter and click the form
  5. In the Properties window, change its name to TaStoreItems
  6. Design the form as follows: 
    Department Store - Store Inventory
    Control Text Name Other Properties
    ListView   lvwStoreItems FullRowSelect: True
    GridLines: True
    View: Details
      Columns
    (Name) Text TextAlign Width
    colItemNumber Item #   100
    colManufacturer Manufacturer   80
    colCategory Category    
    colSCategoryub Sub-Category   80
    colItemName Item Name/Description   200
    colItemSize Size Center 100
    colUnitPrice Unit Price Right  
    Button Show Store Items Inventory btnShowCurrentInventory  
  7. Double-click the Show Store Items Inventory button and implement its Click event as follows:
    ''' <summary>
    ''' When the Show Current Inventory button is clicked, the form shows
    ''' a list of the items that have been added to the Store Items table
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub btnShowCurrentInventory_Click(ByVal sender As System.Object, _
                                              ByVal e As System.EventArgs) _
                                              Handles btnShowCurrentInventory.Click
        Dim i As Integer
    
        For i = 0 To TaStoreItems.GetData().Rows.Count - 1
                Dim RcdStoreItem As DataRow = TaStoreItems.GetData().Rows(i)
    
                Dim LviStoreItem As ListViewItem = New ListViewItem(CStr((i + 1)))
    
                LviStoreItem.SubItems.Add(CStr(RcdStoreItem("ItemNumber")))
    
                If IsDBNull(RcdStoreItem("Manufacturer")) Then
                    LviStoreItem.SubItems.Add("")
                Else
                    LviStoreItem.SubItems.Add(CStr(RcdStoreItem("Manufacturer")))
                End If
    
                If IsDBNull(RcdStoreItem("Category")) Then
                    LviStoreItem.SubItems.Add("")
                Else
                    LviStoreItem.SubItems.Add(CStr(RcdStoreItem("Category")))
                End If
    
                If IsDBNull(RcdStoreItem("SubCategory")) Then
                    LviStoreItem.SubItems.Add("")
                Else
                    LviStoreItem.SubItems.Add(CStr(RcdStoreItem("SubCategory")))
                End If
    
                If IsDBNull(RcdStoreItem("ItemName")) Then
                    LviStoreItem.SubItems.Add("")
                Else
                    LviStoreItem.SubItems.Add(CStr(RcdStoreItem("ItemName")))
                End If
    
                If IsDBNull(RcdStoreItem("ItemSize")) Then
                    LviStoreItem.SubItems.Add("")
                Else
                    LviStoreItem.SubItems.Add(CStr(RcdStoreItem("ItemSize")))
                End If
    
                If IsDBNull(RcdStoreItem("UnitPrice")) Then
                    LviStoreItem.SubItems.Add("")
                Else
                    LviStoreItem.SubItems.Add(CDbl(FormatNumber(RcdStoreItem("UnitPrice"))))
                End If
    
                If IsDBNull(RcdStoreItem("SaleStatus")) Then
                    LviStoreItem.SubItems.Add("")
                Else
                    LviStoreItem.SubItems.Add(CStr(RcdStoreItem("SaleStatus")))
                End If
    
                lvwStoreItems.Items.Add(LviStoreItem)
        Next
    End Sub
  8. Save all
  9. Show the Central form
  10. Double-click the View Current Inventory
  11. Implement its Click event as follows:
    Private Sub btnCurrentInventory_Click(ByVal sender As System.Object, _
                                              ByVal e As System.EventArgs) _
                                              Handles btnCurrentInventory.Click
            Dim csi As CurrentStoreInventory = New CurrentStoreInventory()
            csi.ShowDialog()
    End Sub
  12. Press Ctrl + F5 to execute
  13. Open the Current Inventory form
  14. Click the Show Store Items Inventory button
  15. Close the forms and return to your programming environment

Department Store - Store Inventory

Practical LearningPractical Learning: Locating a Record Based on a Column Name

  1. In the Solution Explorer, right-click the ShoppingSession.vb and click View Code
  2. Import the System.Data.SqlClient namespace and declare two global variables as follows:
    Imports System.Data.SqlClient
    
    Public Class ShoppingSession
        ' The ReceiptNumber variable will represent the receipt number
        Dim ReceiptNumber As Integer
        ' This variable will represent the total value of the shopping  
        Dim TotalOrder As Double
    
        . . .
        
    End Class
  3. In the Class Name combo box, select the btnCancelOrder
  4. In the Method Name combo box, select Click
  5. Implement its event as follows:
    Private Sub btnCancelOrder_Click(ByVal sender As Object, _
                                         ByVal e As System.EventArgs) _
                                         Handles btnCancelOrder.Click
            REM First reset the form
            TotalOrder = 0.0
            txtItemNumber.Text = ""
            txtItemName.Text = ""
            txtUnitPrice.Text = "0.00"
            lvwShoppingSession.Items.Clear()
            txtOrderTotal.Text = "0.00"
            txtAmountTended.Text = "0.00"
            txtChange.Text = "0.00"
    
            If TaCustomersOrders.GetData().Rows.Count > 0 Then
                For Each RcdCustomerOrder As DataRow In TaCustomersOrders.GetData().Rows
                    ReceiptNumber = CInt(CStr(RcdCustomerOrder("ReceiptNumber"))) + 1
                Next
            End If
    
            txtReceiptNumber.Text = CStr(ReceiptNumber)
    End Sub
  6. In the Class Name combo box, select (ShoppingSession Events)
  7. In the Method Name combo box, select Load
  8. Implement its event as follows:
    Private Sub ShoppingSession_Load(ByVal sender As Object, _
                                         ByVal e As System.EventArgs) _
                                         Handles Me.Load
            TotalOrder = 0.0
            ReceiptNumber = 100000
            btnCancelOrder_Click(sender, e)
    End Sub
  9. Save all

Practical LearningPractical Learning: Finding a Record

  1. The ShoppingSession form (the ShoppingSession.vb (Design) tab) should be displaying.
    In the Class name combo box, select txtItemNumber
  2. In the Method Name combo box, select Leave
  3. Implement the event as follows:
    Private Sub txtItemNumber_Leave(ByVal sender As Object, _
                                        ByVal e As System.EventArgs) _
                                        Handles txtItemNumber.Leave
            Dim unitPrice As Double = 0.0
    
            If txtItemNumber.Text.Equals("") Then
                Exit Sub
            End If
    
            Try
                Dim rcdStoreItem As DataRow = TaStoreItems.GetData().Rows.Find(txtItemNumber.Text)
    
                If IsDBNull(rcdStoreItem("ItemName")) Then
                    txtItemName.Text = ""
                Else
                    txtItemName.Text = CStr(rcdStoreItem("ItemName"))
                End If
    
                If IsDBNull(rcdStoreItem("ItemSize")) Then
                    txtItemSize.Text = ""
                Else
                    txtItemSize.Text = CStr(rcdStoreItem("ItemSize"))
                End If
    
                If IsDBNull(rcdStoreItem("UnitPrice")) Then
                    txtUnitPrice.Text = "0.00"
                Else
                    unitPrice = CDbl(CStr(rcdStoreItem("UnitPrice")))
    
                    TotalOrder = TotalOrder + unitPrice
                    txtUnitPrice.Text = CStr(unitPrice)
                End If
    
                Dim LviStoreItem As ListViewItem = New ListViewItem(txtItemNumber.Text)
    
                LviStoreItem.SubItems.Add(txtItemName.Text)
                LviStoreItem.SubItems.Add(txtItemSize.Text)
                LviStoreItem.SubItems.Add(FormatNumber(unitPrice))
                lvwShoppingSession.Items.Add(LviStoreItem)
    
                txtOrderTotal.Text = FormatNumber(TotalOrder)
    
                txtItemNumber.Text = ""
                txtItemName.Text = ""
                txtItemSize.Text = ""
                txtUnitPrice.Text = "0.00"
                txtItemNumber.Focus()
            Catch nre As NullReferenceException
                MsgBox("There is no store item with that number")
            Catch ioore As IndexOutOfRangeException
                MsgBox("There is no store item with that number")
            End Try
    End Sub
  4. In the Class Name combo box, select txtAmountTended
  5. In the Method Name combo box, select Leave
  6. Implement the event as follows:
    Private Sub txtAmountTended_Leave(ByVal sender As Object, _
                                          ByVal e As System.EventArgs) _
                                          Handles txtAmountTended.Leave
            Dim totalOrder As Double
            Dim amountTended As Double
            Dim change As Double
    
            Try
                totalOrder = CDbl(txtOrderTotal.Text)
                amountTended = CDbl(txtAmountTended.Text)
                change = amountTended - totalOrder
    
                txtChange.Text = FormatNumber(change)
                btnSubmitOrder.Focus()
            Catch fe As FormatException
                MsgBox("Invalid Value!")
            End Try
    End Sub
  7. Return to the Central form
  8. Double-click the Process Customer Order
  9. Implement its Click event as follows:
    Private Sub btnProcessOrder_Click(ByVal sender As Object, _
                                          ByVal e As System.EventArgs) _
                                          Handles btnProcessOrder.Click
            Dim shop As ShoppingSession = New ShoppingSession()
            shop.ShowDialog()
    End Sub
  10. To create a new form, on the main menu, click Project -> Add Windows Form...
  11. Set the Name to ManageStoreItem and click Add
  12. In the top section of the Toolbox, click dsFunDS and click the form
  13. In the top section of the Toolbox, click StoreItemsTableAdapter and click the form
  14. In the Properties window, change its name to TaStoreItems
  15. Design the form as follows:
     
    Department Store
    Control Text Name Other Properties
    Label Item #:    
    TextBox   btnItemNumber  
    Button Find btnFind  
    Label Manufacturer    
    TextBox   Manufacturer  
    Label Category:    
    ComboBox   cbxCategories Items: Men
             Girls
             Boys
             Babies
             Women
             Other
    Label Sub-Category:    
    ComboBox   cbxSubCategories Items:
    Skirts
    Pants
    Shirts
    Shoes
    Beauty
    Dresses
    Clothing
    Sweater
    Watches
    Handbags
    Miscellaneous
    Label Item Name:    
    TextBox   btnItemName  
    Label Size:    
    TextBox   btnItemSize  
    Label Unit Price:    
    TextBox   btnUnitPrice Text: 0.00
    TextAlign: Right
    Label Sale Status:    
    ComboBox   cbxSaleStatus Items:
    Available
    Sold
    Processing
    Other
    Button Reset btnReset  
    Button Submit Changes btnSubmitChanges  
    Button Delete this Item btnDeleteStoreItem  
    Button Close btnClose  
  16. Double-click the Reset button
  17. Implement the event as follows:
    Private Sub btnReset_Click(ByVal sender As System.Object, _
                                   ByVal e As System.EventArgs) _
                                   Handles btnReset.Click
            txtItemNumber.Text = ""
            txtManufacturer.Text = ""
            cbxCategories.Text = "Women"
            txtItemName.Text = ""
            txtItemSize.Text = ""
            txtUnitPrice.Text = "0.00"
            txtManufacturer.Focus()
    End Sub
  18. In the Class Name combo box, select btnFind
  19. In the Method Name combo box, select Click
  20. Implement its event as follows:
    Private Sub btnFind_Click(ByVal sender As Object, _
                                  ByVal e As System.EventArgs) _
                                  Handles btnFind.Click
            Dim unitPrice As Double = 0.0
    
            If txtItemNumber.Text = "" Then
                Exit Sub
            End If
            Try
                Dim rcdStoreItem As DataRow = _
                    TaStoreItems.GetData().Rows.Find(txtItemNumber.Text)
    
                If IsDBNull(rcdStoreItem("ItemName")) Then
                    txtItemName.Text = ""
                Else
                    txtItemName.Text = CStr(rcdStoreItem("ItemName"))
                End If
    
                If IsDBNull(rcdStoreItem("Manufacturer")) Then
                    txtManufacturer.Text = ""
                Else
                    txtManufacturer.Text = CStr(rcdStoreItem("Manufacturer"))
                End If
    
                If IsDBNull(rcdStoreItem("Category")) Then
                    cbxCategories.Text = ""
                Else
                    cbxCategories.Text = CStr(rcdStoreItem("Category"))
                End If
    
                If IsDBNull(rcdStoreItem("SubCategory")) Then
                    cbxSubCategories.Text = ""
                Else
                    cbxSubCategories.Text = CStr(rcdStoreItem("SubCategory"))
                End If
    
                If IsDBNull(rcdStoreItem("itemName")) Then
                    txtItemName.Text = ""
                Else
                    txtItemName.Text = CStr(rcdStoreItem("itemName"))
                End If
    
                If IsDBNull(rcdStoreItem("ItemSize")) Then
                    txtItemSize.Text = ""
                Else
                    txtItemSize.Text = CStr(rcdStoreItem("ItemSize"))
                End If
    
                If IsDBNull(rcdStoreItem("UnitPrice")) Then
                    txtUnitPrice.Text = "0.00"
                Else
                    unitPrice = CDbl(CStr(rcdStoreItem("UnitPrice")))
                    txtUnitPrice.Text = CStr(unitPrice)
                End If
    
                If IsDBNull(rcdStoreItem("SaleStatus")) Then
                    cbxSaleStatus.Text = ""
                Else
                    cbxSaleStatus.Text = CStr(rcdStoreItem("SaleStatus"))
                End If
            Catch nre As NullReferenceException
                MsgBox("There is no store item with that number")
                btnReset_Click(sender, e)
            Catch ioore As IndexOutOfRangeException
                MsgBox("There is no store item with that number")
                btnReset_Click(sender, e)
            End Try
    End Sub
  21. Display the Central form
  22. Double-click the Manage Store Item
  23. Implement the event as follows:
    Private Sub btnManageStoreItem_Click(ByVal sender As Object, _
                                             ByVal e As System.EventArgs) _
                                             Handles btnManageStoreItem.Click
            Dim msi As ManageStoreItem = New ManageStoreItem()
            msi.ShowDialog()
    End Sub
  24. Press Ctrl + F5 to execute
  25. Display the Manage Store Item form
  26. In the Item # text box, enter 294725 and click Find
  27. Enter 557504 and click Find
  28. Close the forms and return to your programming environment
  29. Save all

Practical LearningPractical Learning: Adding and/or Updating a Record

  1. Display the Shopping Session form
  2. Double-click the Submit Current Order button
  3. Implement its event as follows:
    Private Sub btnSubmitOrder_Click(ByVal sender As Object, _
                                         ByVal e As System.EventArgs) _
                                         Handles btnSubmitOrder.Click
            Dim i As Integer
            If lvwShoppingSession.Items.Count = 0 Then
                MsgBox("There is no record to create.")
                Exit Sub
            End If
    
            REM Add the list of items to the CustomersOrders table
            Try
                For i = 0 To lvwShoppingSession.Items.Count - 1
                    TaCustomersOrders.Insert(CStr(ReceiptNumber), _
                                             lblDate.Text, _
                                             lblTime.Text, _
                                             lvwShoppingSession.Items(i).Text, _
                                             lvwShoppingSession.Items(i).SubItems(1).Text, _
                                             lvwShoppingSession.Items(i).SubItems(2).Text, _
                                             CDec(lvwShoppingSession.Items(i).SubItems(3).Text))
    
    
                    Dim RcdStoreItem As DataRow = _
                    TaStoreItems.GetData().Rows.Find(lvwShoppingSession.Items(i).Text)
                    RcdStoreItem("SaleStatus") = "Sold"
                    TaStoreItems.Update(RcdStoreItem)
                Next
    
                REM Let the user know
                MsgBox("The customer order has been saved.")
            Catch ioore As IndexOutOfRangeException
                MsgBox("There is no store item with that number")
            End Try
    
            REM Create a record in the ReceiptSummaries table
            Try
                TaReceiptsSummaries.Insert(txtReceiptNumber.Text, _
                                           lblDate.Text, _
                                           lblTime.Text, _
                                           CDec(txtOrderTotal.Text), _
                                           cbxCurrencyType.Text, _
                                           CDec(txtAmountTended.Text), _
                                           CDec(txtChange.Text))
    
                REM Receipt the form
                btnCancelOrder_Click(sender, e)
            Catch ioore As IndexOutOfRangeException
                MsgBox("There is no store item with that number")
            End Try
    End Sub
  4. Press Ctrl + F5 to execute the application
  5. Click Process a Customer Order
  6. Create a customer order that uses
     
    Item #: 952735
  7. Change the Amount Tended to 500 and press Tab
  8. Click Submit Current Order
  9. Create another customer order that uses
     
    Item #: 927940
    Item #: 790064
  10. Change the Amount Tended to 300 and press Tab
  11. Click Submit Current Order
  12. Create another customer order that uses
     
    Item #: 290030
    Item #: 790402
    Item #: 729741
    Item #: 297030
  13. Change the Amount Tended to 300 and press Tab
  14. Click Submit Current Order
  15. Create another customer order that uses
     
    Item #: 797140
  16. Change the Amount Tended to 20 and press Tab
  17. Click Submit Current Order
  18. Close the forms and return to your programming environment
  19. Display the Manage Store Item form
  20. Double-click the Submit Changes button
  21. Implement its Click event as follows:
    Private Sub btnSubmitChanges_Click(ByVal sender As System.Object, _
                                           ByVal e As System.EventArgs) _
                                           Handles btnSubmitChanges.Click
            If txtItemNumber.Text.Length = 0 Then
                MsgBox("You must provide a (unique) item number.")
                Exit Sub
            End If
    
            If txtItemName.Text.Length = 0 Then
                MsgBox("You must provide a name for the item.")
                Exit Sub
            End If
    
            If txtUnitPrice.Text.Length = 0 Then
                MsgBox("You must provide a price for the item.")
                Exit Sub
            End If
    
            Try
                Dim rcdStoreItem As DataRow = _
    		TaStoreItems.GetData().Rows.Find(txtItemNumber.Text)
    
                If txtManufacturer.Text.Length <> 0 Then
                    rcdStoreItem("Manufacturer") = txtManufacturer.Text
                End If
    
                If cbxCategories.Text.Length <> 0 Then
                    rcdStoreItem("Category") = cbxCategories.Text
                End If
    
                If cbxSubCategories.Text.Length <> 0 Then
                    rcdStoreItem("SubCategory") = cbxSubCategories.Text
                End If
    
                rcdStoreItem("ItemName") = txtItemName.Text
    
                If txtItemSize.Text.Length <> 0 Then
                    rcdStoreItem("ItemSize") = txtItemSize.Text
                End If
    
                rcdStoreItem("UnitPrice") = CStr(txtUnitPrice.Text)
    
                TaStoreItems.Update(rcdStoreItem)
    
                REM Let the user know
                MsgBox("The item has been updated")
    
                btnReset_Click(sender, e)
            Catch ioore As IndexOutOfRangeException
                MsgBox("There is no store item with that number")
            End Try
    End Sub
  22. Press Ctrl + F5 to execute the application
  23. Click the Manage a Store Item button
  24. Item the item number, enter 582604 and click Find
  25. If the record is found, change the values as follows:
     
    Dress Manufacturer Delete Dress
    Item Name Sleeveless Sweater Dress
    Size L
    Unit Price 125
    Sale Status Available
  26. Click Submit Changes
  27. In the item number, enter 770240 and click Find
  28. If the record is found, change the values as follows:
     
    Manufacturer Caparros
    Sub Category Shoes
    Item Name Peep-Toe Silk Stiletto Sandals
    Size 7.5
    Unit Price 65.00
    Sale Status Available
  29. Click Submit Changes
  30. Close the forms and return to your programming environment
 
 
 

 

Practical LearningPractical Learning: Creating a Record

  1. Start Microsoft Visual Studio and open the FunDepartmentStore1 from the previous lesson
  2. To create a new form, on the main menu, click Project -> Add Windows Form...
  3. Set the Name to CreateStoreItem and click Add
  4. In the top section of the Toolbox, click dsFunDS and click the form
  5. In the top section of the Toolbox, click StoreItemsTableAdapter and click the form
  6. In the Properties window, change its name to TaStoreItems
  7. Design the form as follows:
     
    Department Store
    Control Text Name Other Properties
    Label Item #:    
    TextBox   txtItemNumber  
    Label Manufacturer:    
    TextBox   txtManufacturer  
    Label Category:    
    TextBox   cbxCategories Items: Men
             Girls
             Boys
             Babies
             Women
             Other
    Label Sub-Category:    
    TextBox   cbxSubCategories Items:
    Skirts
    Pants
    Shoes
    Shirts
    Beauty
    Dresses
    Clothing
    Sweater
    Watches
    Handbags
    Miscellaneous
    Label Item Name:    
    TextBox   btnItemName  
    Label Size:    
    TextBox   btnItemSize  
    Label Unit Price:    
    TextBox   btnUnitPrice Text: 0.00
    TextAlign: Right
    Label Sale Status:    
    ComboBox   cbxSaleStatus Items:
    Available
    Sold
    Processing
    Other
    Button Reset btnReset  
    Button Create btnCreate  
    Button Close btnClose  
  8. Double-click the Reset button
  9. Implement the event as follows:
    Private Sub btnReset_Click(ByVal sender As System.Object, _
                                   ByVal e As System.EventArgs) _
                                   Handles btnReset.Click
            txtItemNumber.Text = "000000"
    
            txtManufacturer.Text = ""
            cbxCategories.Text = "Women"
            txtItemName.Text = ""
            txtSize.Text = ""
            txtUnitPrice.Text = "0.00"
            txtManufacturer.Focus()
    End Sub
  10. In the Class Name combo box, select (CreateStoreItem Events)
  11. In the Method Name combo box, select Load
  12. Implement the event as follows:
    Private Sub CreateStoreItem_Load(ByVal sender As Object, _
                                         ByVal e As System.EventArgs) _
                                         Handles Me.Load
            btnReset_Click(sender, e)
    End Sub
  13. In the Class Name combo box, select btnCreate
  14. In the Method Name combo box, select Click
  15. Implement the event as follows:
    Private Sub btnCreate_Click(ByVal sender As Object, _
                                    ByVal e As System.EventArgs) _
                                    Handles btnCreate.Click
            If txtItemNumber.Text.Length = 0 Then
                MsgBox("You must provide a (unique) item number.")
                Exit Sub
            End If
    
            If txtItemName.Text.Length = 0 Then
                MsgBox("You must provide a name for the item.")
                Exit Sub
            End If
    
            If txtUnitPrice.Text.Length = 0 Then
                MsgBox("You must provide a price for the item.")
                Exit Sub
            End If
    
            REM Create a record in the ReceiptSummaries table
            Try
                Dim rcdStoreItems As DataRow = DsFunDS1.Tables("StoreItems").NewRow()
    
                rcdStoreItems("ItemNumber") = txtItemNumber.Text
                rcdStoreItems("Manufacturer") = txtManufacturer.Text
                rcdStoreItems("Category") = cbxCategories.Text
                rcdStoreItems("SubCategory") = cbxSubCategories.Text
                rcdStoreItems("ItemName") = txtItemName.Text
                rcdStoreItems("ItemSize") = txtSize.Text
                rcdStoreItems("UnitPrice") = txtUnitPrice.Text
    
                DsFunDS1.Tables("StoreItems").Rows.Add(rcdStoreItems)
                TaStoreItems.Update(DsFunDS1)
    
                REM Let the user know
                MsgBox("The item has been created")
    
                btnReset_Click(sender, e)
            Catch ioore As IndexOutOfRangeException
                MsgBox("There is no store item with that number")
            End Try
    End Sub
  16. In the Class Name combo box, select btnClose
  17. In the Method Name combo box, select Click
  18. Implement the event as follows:
    Private Sub btnClose_Click(ByVal sender As Object, _
                                   ByVal e As System.EventArgs) _
                                   Handles btnClose.Click
        Close()
    End Sub
  19. Display to the Central form
  20. Double-click the Create a New Store Item
  21. Implement the event as follows:
    Private Sub btnCreateStoreItem_Click(ByVal sender As System.Object, _
                                         ByVal e As System.EventArgs) _
                                         Handles btnCreateStoreItem.Click
        Dim csi As CreateStoreItem = New CreateStoreItem()
        csi.ShowDialog()
    End Sub
  22. In the Class Name combo box, select btnClose
  23. In the Method Name combo box, select Click
  24. Implement the event as follows:
    Private Sub btnClose_Click(ByVal sender As Object, _
                                   ByVal e As System.EventArgs) _
                                   Handles btnClose.Click
            Close()
    End Sub
  25. Press Ctrl + F5 to execute the application
  26. Click the Create a New Store Item button
  27. Enter information for a new store item as follows:
     
    Item #: 779208 Dress
    Manufacturer: Adrianna Papell
    Category: Women
    Sub-Category: Dresses
    Item Name: Taffeta Ruffled Dress & Bolero Jacket
    Size: 4
    Unit Price: 288.00
    Sale Status Processing
    Department Store - New Item
  28. Click Create
  29. Enter information for a new item as follows:
     
    Item #: 794754
    Manufacturer Calvin Klein
    Category Men
    Sub-Category Pants
    Item Name Black Striped Flat-Front Pants
    Size 34W - 30L
    Unit Price 99.95
    Sale Status Processing
  30. Click Create
  31. Close the forms and return to your programming environment

Practical LearningPractical Learning: Locating a Record

  1. If necessary, display the Create Store Item form and double-click the Reset button
  2. Change its code as follows:
    Private Sub btnReset_Click(ByVal sender As System.Object, _
                                   ByVal e As System.EventArgs) _
                                   Handles btnReset.Click
            Dim i As Integer
            REM We will use this variable to create a new item number
            Dim newRecordNumber As Integer = 1
    
            '  Check each record
            For i = 0 To TaStoreItems.GetData().Rows.Count
                '  Get the current record
                Dim rcdCurrentStoreItem As DataRow = TaStoreItems.GetData().Rows(i)
                '  Get the next record
                Dim rcdNextStoreItem As DataRow = TaStoreItems.GetData().Rows(i + 1)
    
                '  If the item number + 1 of the current record is different from the next
                If ((CInt(CStr(rcdCurrentStoreItem("ItemNumber"))) + 1) <> _
                     CInt(CStr(rcdNextStoreItem("ItemNumber")))) Then
                    '  Then use the current item number + 1 as the new item number
                    newRecordNumber = CInt(rcdCurrentStoreItem("ItemNumber")) + 1
                    Exit For
                End If
            Next
    
            txtItemNumber.Text = newRecordNumber
    
            txtManufacturer.Text = ""
            cbxCategories.Text = "Women"
            txtItemName.Text = ""
            txtSize.Text = ""
            txtUnitPrice.Text = "0.00"
            txtManufacturer.Focus()
    End Sub
  3. Save all

Practical LearningPractical Learning: Deleting a Record

  1. Display the Manage Store Item form
  2. Double-click the Delete this Item button
  3. Implement its event as follows:
    Private Sub btnDeleteStoreItem_Click(ByVal sender As System.Object, _
                                             ByVal e As System.EventArgs) _
                                             Handles btnDeleteStoreItem.Click
            If txtItemNumber.Text.Length = 0 Then
                MsgBox("There is no item to delete." & vbCrLf & _
                       "You must provide an item number")
                Exit Sub
            End If
    
            '  Just in case the user had just entered an item number
            '  but didn't click the Find button, try to locate that item now
            btnFind_Click(sender, e)
    
            '  Check with the user to confirm that the item must be deleted
            If MsgBox("Are you sure you want to delete this item?", _
                      MsgBoxStyle.YesNo Or MsgBoxStyle.Question, _
                      "Fun DS - Department Store - Deleting an Item") _
                      = MsgBoxResult.Yes Then
                '  If the user answers Yes, first identify the item
                Dim rcdStoreItem As DataRow = _
                    TaStoreItems.GetData().Rows.Find(txtItemNumber.Text)
    
                rcdStoreItem("Manufacturer") = txtManufacturer.Text
                rcdStoreItem("Category") = cbxCategories.Text
                rcdStoreItem("SubCategory") = cbxSubCategories.Text
                rcdStoreItem("ItemName") = txtItemName.Text
                rcdStoreItem("ItemSize") = txtItemSize.Text
                rcdStoreItem("UnitPrice") = CStr(txtUnitPrice.Text)
                '  Delete the record
                rcdStoreItem.Delete()
                '  Update the table adapter
                TaStoreItems.Update(rcdStoreItem)
    
                '  Reset the form
                btnReset_Click(sender, e)
    
                '  Let the user know
                MsgBox("The item has been deleted")
            End If
    End Sub
  4. In the Class Name combo box, select btnClose
  5. In the Method Name combo box, select Click
  6. Implement the event as follows:
    Private Sub btnClose_Click(ByVal sender As Object, _
                                   ByVal e As System.EventArgs) _
                                   Handles btnClose.Click
            Close()
    End Sub
  7. Press Ctrl + F5 to execute the application
  8. Click the Manage a Store Item button
  9. Enter an item number as 790279 and click Find
  10. If the item is found, click Delete
  11. Click Yes
  12. Close the forms and return to your programming environment

Practical LearningPractical Learning: Introducing Data Analysis

  1. Display the Store Inventory form and change its design as follows: 
    Department Store
    Control Text Name Other Properties
    Label Select a Column    
    ComboBox   cbxColumns  
    Label Show records that    
    ComboBox cbxOperators    
    TextBox   txtCriterion  
    Button Find Record(s) btnFindRecords  
    Button Show Whole Store Items Inventory Exists already  
    Button Close btnClose  
  2. Right-click the form and click View Code
  3. Import the the System.Collections.Generic
  4. Declare two global generic List variables as follows:
    Imports System.Collections.Generic
    
    Public Class CurrentStoreInventory
        Private NumericOperators As List(Of String)
        Private StringOperators As List(Of String)
  5. In the Class Name combo box, select btnShowCurrentInventory
  6. Change the code as follows:
    Private Sub btnShowCurrentInventory_Click(ByVal sender As System.Object, _
                                                  ByVal e As System.EventArgs) _
                                                  Handles btnShowCurrentInventory.Click
        Dim i As Integer
    
        For i = 0 To TaStoreItems.GetData().Rows.Count - 1
                Dim RcdStoreItem As DataRow = TaStoreItems.GetData().Rows(i)
    
                Dim LviStoreItem As ListViewItem = New ListViewItem(CStr((i + 1)))
    
                LviStoreItem.SubItems.Add(CStr(RcdStoreItem("ItemNumber")))
    
                If IsDBNull(RcdStoreItem("Manufacturer")) Then
                    LviStoreItem.SubItems.Add("")
                Else
                    LviStoreItem.SubItems.Add(CStr(RcdStoreItem("Manufacturer")))
                End If
    
                If IsDBNull(RcdStoreItem("Category")) Then
                    LviStoreItem.SubItems.Add("")
                Else
                    LviStoreItem.SubItems.Add(CStr(RcdStoreItem("Category")))
                End If
    
                If IsDBNull(RcdStoreItem("SubCategory")) Then
                    LviStoreItem.SubItems.Add("")
                Else
                    LviStoreItem.SubItems.Add(CStr(RcdStoreItem("SubCategory")))
                End If
    
                If IsDBNull(RcdStoreItem("ItemName")) Then
                    LviStoreItem.SubItems.Add("")
                Else
                    LviStoreItem.SubItems.Add(CStr(RcdStoreItem("ItemName")))
                End If
    
                If IsDBNull(RcdStoreItem("ItemSize")) Then
                    LviStoreItem.SubItems.Add("")
                Else
                    LviStoreItem.SubItems.Add(CStr(RcdStoreItem("ItemSize")))
                End If
    
                If IsDBNull(RcdStoreItem("UnitPrice")) Then
                    LviStoreItem.SubItems.Add("")
                Else
                    LviStoreItem.SubItems.Add(CDbl(FormatNumber(RcdStoreItem("UnitPrice"))))
                End If
    
                If IsDBNull(RcdStoreItem("SaleStatus")) Then
                    LviStoreItem.SubItems.Add("")
                Else
                    LviStoreItem.SubItems.Add(CStr(RcdStoreItem("SaleStatus")))
                End If
    
                lvwStoreItems.Items.Add(LviStoreItem)
        Next
    
        For Each col As DataColumn In TaStoreItems.GetData().Columns
                cbxColumns.Items.Add(col.ColumnName)
    
                NumericOperators = New List(Of String)
                NumericOperators.Add("Equal To")
                NumericOperators.Add("Is Not Equal To")
                NumericOperators.Add("Less Than")
                NumericOperators.Add("Less Than Or Equal To")
                NumericOperators.Add("Greater Than")
                NumericOperators.Add("Greater Than Or Equal To")
    
                StringOperators = New List(Of String)
    
                StringOperators.Add("Equal To")
                StringOperators.Add("Different From")
                StringOperators.Add("Starts With")
                StringOperators.Add("Doesn't Start With")
                StringOperators.Add("Contains")
                StringOperators.Add("Doesn't Contain")
                StringOperators.Add("Ends With")
                StringOperators.Add("Doesn't End With")
        Next
    End Sub
  7. In the Class Name combo box, select cbxColumns
  8. In the Method Name combo box, select SelectedIndexChanged
  9. Implement the event as follows:
    Private Sub cbxColumns_SelectedIndexChanged(ByVal sender As Object, _
                                                    ByVal e As System.EventArgs) _
                                                    Handles cbxColumns.SelectedIndexChanged
            For Each col As DataColumn In TaStoreItems.GetData().Columns
                If col.ColumnName.Equals(cbxColumns.Text) Then
                    cbxOperators.Items.Clear()
    
                    If col.DataType.Equals(Type.GetType("System.Int32")) Then
                        For Each strOperator As String In NumericOperators
                            cbxOperators.Items.Add(strOperator)
                        Next
    
                        cbxOperators.SelectedIndex = 0
                    ElseIf col.DataType.Equals(Type.GetType("System.Decimal")) Then
                        For Each strOperator As String In NumericOperators
                            cbxOperators.Items.Add(strOperator)
                        Next
    
                        cbxOperators.SelectedIndex = 0
                    ElseIf col.DataType.Equals(Type.GetType("System.String")) Then
                        For Each strOperator As String In StringOperators
                            cbxOperators.Items.Add(strOperator)
                        Next
    
                        cbxOperators.SelectedIndex = 0
                    Else
                        cbxOperators.Items.Clear()
                        cbxOperators.Text = ""
                    End If
                End If
            Next
    End Sub
  10. Save all

Practical LearningPractical Learning: Analyzing Data With Strings

  1. In the Class Name combo box, select btnFindRecords
  2. In the Method Name combo box, select Click
  3. Implement the event as follows:
    Private Sub ShowRecords(ByVal RowStoreItem As DataRow, ByVal counter As Integer)
            Dim LviStoreItem As ListViewItem = New ListViewItem(counter)
            LviStoreItem.SubItems.Add(CStr(RowStoreItem("ItemNumber")))
    
            If IsDBNull(RowStoreItem("Manufacturer")) Then
                LviStoreItem.SubItems.Add("")
            Else
                LviStoreItem.SubItems.Add(CStr(RowStoreItem("Manufacturer")))
            End If
    
            If IsDBNull(RowStoreItem("Category")) Then
                LviStoreItem.SubItems.Add("")
            Else
                LviStoreItem.SubItems.Add(CStr(RowStoreItem("Category")))
            End If
    
            If IsDBNull(RowStoreItem("SubCategory")) Then
                LviStoreItem.SubItems.Add("")
            Else
                LviStoreItem.SubItems.Add(CStr(RowStoreItem("SubCategory")))
            End If
    
            If IsDBNull(RowStoreItem("ItemName")) Then
                LviStoreItem.SubItems.Add("")
            Else
                LviStoreItem.SubItems.Add(CStr(RowStoreItem("ItemName")))
            End If
    
            If IsDBNull(RowStoreItem("ItemSize")) Then
                LviStoreItem.SubItems.Add("")
            Else
                LviStoreItem.SubItems.Add(CStr(RowStoreItem("ItemSize")))
            End If
    
            If IsDBNull(RowStoreItem("UnitPrice")) Then
                LviStoreItem.SubItems.Add("")
            Else
                LviStoreItem.SubItems.Add(FormatNumber(RowStoreItem("UnitPrice")))
            End If
    
        If IsDBNull(RowStoreItem("SaleStatus")) Then
            LviStoreItem.SubItems.Add("")
        Else
            LviStoreItem.SubItems.Add(CStr(RowStoreItem("SaleStatus")))
        End If
    
        LvwStoreItems.Items.Add(LviStoreItem)
    End Sub
    
    Private Sub btnFindRecords_Click(ByVal sender As Object, _
                                         ByVal e As System.EventArgs) _
                                         Handles BtnFindRecords.Click
            Dim i As Integer
             
            LvwStoreItems.Items.Clear()
    
            TaStoreItems.Fill(DsFunDS1.StoreItems)
    
            i = 1
    
            ' Check the value from the Operator combo box.
            ' If it is Equal To, you will use the = operator
            If CbxOperators.Text.Equals("Equal To") Then
                '                 Check all records
                For Each Record As DataRow In DsFunDS1.StoreItems.Rows
                    ' If the data type of a column is integer-based
                    If Record(CbxColumns.Text).GetType().Equals(Type.GetType("System.Int32")) Then
                        ' Get the value in the Criterion text box.
                        ' If the value in the Criterion text box = the value in the corresponding record
                        If CInt(CStr(Record(CbxColumns.Text))) = CInt(TxtCriterion.Text) Then
                            ShowRecords(Record, i)
                            i = i + 1
                        End If
    
                    ElseIf Record(CbxColumns.Text).GetType().Equals(Type.GetType("System.Decimal")) Then
                        If CDec(CStr(Record(CbxColumns.Text))) = CDec(TxtCriterion.Text) Then
                            ShowRecords(Record, i)
                            i = i + 1
                        End If
                    Else ' (record(cbxColumns.Text).GetType() == Type.GetType("System.String"))
                        If Not IsDBNull(Record(CbxColumns.Text)) Then
                            If CStr(Record(CbxColumns.Text)).ToLower().Equals(TxtCriterion.Text.ToLower()) Then
                                ShowRecords(Record, i)
                                i = i + 1
                            End If
                        End If
                    End If
                Next
            ElseIf CbxOperators.Text.Equals("Different From") Then
                For Each Record As DataRow In DsFunDS1.StoreItems.Rows
                    If Not IsDBNull(Record(CbxColumns.Text)) Then
                        If CStr(Record(CbxColumns.Text)).ToLower() <> TxtCriterion.Text.ToLower() Then
                            ShowRecords(Record, i)
                            i = i + 1
                        End If
                    End If
                Next
            ElseIf CbxOperators.Text.Equals("Starts With") Then
                For Each Record As DataRow In DsFunDS1.StoreItems.Rows
                    If Not IsDBNull(Record(CbxColumns.Text)) Then
                        If CStr(Record(CbxColumns.Text)).ToLower().StartsWith(TxtCriterion.Text.ToLower()) Then
                            ShowRecords(Record, i)
                            i = i + 1
                        End If
                    End If
                Next
            ElseIf CbxOperators.Text.Equals("Doesn't Start With") Then
                For Each Record As DataRow In DsFunDS1.StoreItems.Rows
                    If Not IsDBNull(Record(CbxColumns.Text)) Then
                        If Not CStr(Record(CbxColumns.Text)).ToLower().StartsWith(TxtCriterion.Text.ToLower()) Then
                            ShowRecords(Record, i)
                            i = i + 1
                        End If
                    End If
                Next
            ElseIf CbxOperators.Text.Equals("Contains") Then
                For Each Record As DataRow In DsFunDS1.StoreItems.Rows
                    If Not IsDBNull(Record(CbxColumns.Text)) Then
                        If CStr(Record(CbxColumns.Text)).ToLower().Contains(TxtCriterion.Text.ToLower()) Then
                            ShowRecords(Record, i)
                            i = i + 1
                        End If
                    End If
                Next
            ElseIf CbxOperators.Text.Equals("Doesn't Contain") Then
                For Each Record As DataRow In DsFunDS1.StoreItems.Rows
                    If Not IsDBNull(Record(CbxColumns.Text)) Then
                        If Not CStr(Record(CbxColumns.Text)).ToLower().Contains(TxtCriterion.Text.ToLower()) Then
                            ShowRecords(Record, i)
                            i = i + 1
                        End If
                    End If
                Next
            ElseIf CbxOperators.Text.Equals("Ends With") Then
                For Each Record As DataRow In DsFunDS1.StoreItems.Rows
                    If Not IsDBNull(Record(CbxColumns.Text)) Then
                        If CStr(Record(CbxColumns.Text)).ToLower().EndsWith(TxtCriterion.Text.ToLower()) Then
                            ShowRecords(Record, i)
                            i = i + 1
                        End If
                    End If
                Next
            ElseIf CbxOperators.Text.Equals("Doesn't End With") Then
                For Each Record As DataRow In DsFunDS1.StoreItems.Rows
                    If Not IsDBNull(Record(CbxColumns.Text)) Then
                        If Not CStr(Record(CbxColumns.Text)).ToLower().EndsWith(TxtCriterion.Text.ToLower()) Then
                            ShowRecords(Record, i)
                            i = i + 1
                        End If
                    End If
                Next
            ElseIf CbxOperators.Text.Equals("Doesn't Start With") Then
                For Each Record As DataRow In DsFunDS1.StoreItems.Rows
                    If Not IsDBNull(Record(CbxColumns.Text)) Then
                        If Not CStr(Record(CbxColumns.Text)).ToLower().StartsWith(TxtCriterion.Text.ToLower()) Then
                            ShowRecords(Record, i)
                            i = i + 1
                        End If
                    End If
                Next
            ElseIf CbxOperators.Text.Equals("Less Than") Then
                For Each Record As DataRow In DsFunDS1.StoreItems.Rows
                    If Record(CbxColumns.Text).GetType().Equals(Type.GetType("System.Int32")) Then
                        If CInt(Record(CbxColumns.Text)) < CInt(TxtCriterion.Text) Then
                            ShowRecords(Record, i)
                            i = i + 1
                        End If
    
                    ElseIf Record(CbxColumns.Text).GetType().Equals(Type.GetType("System.Decimal")) Then
                        If CDec(CStr(Record(CbxColumns.Text))) < CDec(TxtCriterion.Text) Then
                            ShowRecords(Record, i)
                            i = i + 1
                        End If
                    Else
                        Exit Sub
                    End If
                Next
            ElseIf CbxOperators.Text.StartsWith("Less Than or Equal") Then
                For Each Record As DataRow In DsFunDS1.StoreItems.Rows
                    If Record(CbxColumns.Text).GetType().Equals(Type.GetType("System.Int32")) Then
                        If CInt(CStr(Record(CbxColumns.Text))) <= CInt(TxtCriterion.Text) Then
                            ShowRecords(Record, i)
                            i = i + 1
                        End If
                    ElseIf Record(CbxColumns.Text).GetType().Equals(Type.GetType("System.Decimal")) Then
                        If CDec(CStr(Record(CbxColumns.Text))) <= CDec(TxtCriterion.Text) Then
                            ShowRecords(Record, i)
                            i = i + 1
                        End If
                    Else
                        Exit Sub
                    End If
                Next
            ElseIf CbxOperators.Text.Equals("Greater Than") Then
                For Each Record As DataRow In DsFunDS1.StoreItems.Rows
                    If Record(CbxColumns.Text).GetType().Equals(Type.GetType("System.Int32")) Then
                        If CInt(CStr(Record(CbxColumns.Text))) > CInt(TxtCriterion.Text) Then
                            ShowRecords(Record, i)
                            i = i + 1
                        End If
                    ElseIf Record(CbxColumns.Text).GetType().Equals(Type.GetType("System.Decimal")) Then
                        If CDec(CStr(Record(CbxColumns.Text))) > CDec(TxtCriterion.Text) Then
                            ShowRecords(Record, i)
                            i = i + 1
                        End If
                    Else
                        Exit Sub
                    End If
                Next
            ElseIf CbxOperators.Text.StartsWith("Greater Than or Equal") Then
                For Each Record As DataRow In DsFunDS1.StoreItems.Rows
                    If Record(CbxColumns.Text).GetType().Equals(Type.GetType("System.Int32")) Then
                        If CInt(CStr(Record(CbxColumns.Text))) >= CInt(TxtCriterion.Text) Then
                            ShowRecords(Record, i)
                            i = i + 1
                        End If
                    ElseIf Record(CbxColumns.Text).GetType().Equals(Type.GetType("System.Decimal")) Then
                        If CDec(CStr(Record(CbxColumns.Text))) >= CDec(TxtCriterion.Text) Then
                            ShowRecords(Record, i)
                            i = i + 1
                        End If
                    Else
                        Exit Sub
                    End If
                Next
            ElseIf CbxOperators.Text.StartsWith("Is Not Equal") Then
                For Each Record As DataRow In DsFunDS1.StoreItems.Rows
                    If Record(CbxColumns.Text).GetType().Equals(Type.GetType("System.Int32")) Then
                        If CInt(CStr(Record(CbxColumns.Text))) <> CInt(TxtCriterion.Text) Then
                            ShowRecords(Record, i)
                            i = i + 1
                        End If
                    ElseIf Record(CbxColumns.Text).GetType().Equals(Type.GetType("System.Decimal")) Then
                        If CDec(CStr(Record(CbxColumns.Text))) <> CDec(TxtCriterion.Text) Then
                            ShowRecords(Record, i)
                            i = i + 1
                        End If
                    Else
                        Exit Sub
                    End If
                Next
            Else
                Exit Sub
            End If
    End Sub
  4. In the Class Name combo box, select btnClose
  5. In the Method Name combo box, select Click
  6. Implement the event as follows:
    Private Sub btnClose_Click(ByVal sender As Object, _
                                   ByVal e As System.EventArgs) _
                                   Handles btnClose.Click
            Close()
    End Sub
  7. Execute the application to test it
  8. Display the Store Inventory form and click the Show Whole Store Items Inventory button

Department Store - All store items

Department Store - Items that do not have a manufacturer

Department Store - Items manufactured by Ralph Lauren

Department Store - Items whose prices are over 280

 

 

 
 
   
 

Home Copyright © 2009-2016, FunctionX, Inc.