I am working on recording orders for a database application. Basically, there is this order form where I will enter order details. Since an order may include many products in it, I will be needing a facility listing products contained in that order. The form also contains a data grid containing the products ordered, prices, quantities, subtotals, and total.
To choose a product, I have this button that when clicked pops out another form (order line form) containing a data grid of product listings, including price, stocks on-hand, and description. Then I have a textbox where the value of the quantity ordered is put. When the 'Add Product' button is clicked, it closes the pop-up form and shows the order form containing now (in the data grid) the products added, quantities, price, subtotal, and total cost so far.
Unfortunately, I'm having trouble implementing this plan. It is successful adding a product to the datagrid in the order form, but once I add another product, an exception appears in the order line pop-up form:
ObjectDisposedException
Cannot access a disposed object.
Object name: 'orderForm'.
Also, even if that error does not appear and another product is added successfully, I am certain that it might just overwrite the previously added product to row number 1. Ideally, another product added must be placed in the next row after the previous one.
Here is my orderForm:
Attachment 91993
Here is the pop-out order line form:
Attachment 91995
And here's what it looks like after adding:
Attachment 91997
Here is my code for the orderForm:
And here is some code snippet for the pop-out form (addOLForm):
As you can see, I instantiated an object of the orderForm class inside the addOLForm and changed its contents according to what was chosen and entered. You might also notice that I'm hiding the orderForm once the 'Add a product' button is clicked since it's not updating values if i it is not loaded again. Also, I cannot close the pop-up form after the 'Add Product' button in it is clicked since the data grid does won't contain anything if I close it.
I know there are still a lot of flaws in this implementation. But how will I make it work? Any help is appreciated. Thanks a lot.
PS: Do you think this is the efficient and ideal way of working with order and order lines or is there another way? I've seen the interface of a SAP software and it has circular buttons at the side of a cell that when clicked pops out a form for options. I've also thought of using combo boxes in the datagrid instead but scrolling down might be tiresome if there are lots of values. Any opinions? Thanks!
To choose a product, I have this button that when clicked pops out another form (order line form) containing a data grid of product listings, including price, stocks on-hand, and description. Then I have a textbox where the value of the quantity ordered is put. When the 'Add Product' button is clicked, it closes the pop-up form and shows the order form containing now (in the data grid) the products added, quantities, price, subtotal, and total cost so far.
Unfortunately, I'm having trouble implementing this plan. It is successful adding a product to the datagrid in the order form, but once I add another product, an exception appears in the order line pop-up form:
ObjectDisposedException
Cannot access a disposed object.
Object name: 'orderForm'.
Also, even if that error does not appear and another product is added successfully, I am certain that it might just overwrite the previously added product to row number 1. Ideally, another product added must be placed in the next row after the previous one.
Here is my orderForm:
Attachment 91993
Here is the pop-out order line form:
Attachment 91995
And here's what it looks like after adding:
Attachment 91997
Here is my code for the orderForm:
Code:
Public Class orderForm
Private Sub addProduct_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addProduct.Click
Me.Close()
addOLForm.ShowDialog()
End Sub
End Class
Code:
Public Class addOLForm
Dim cnn As New OleDb.OleDbConnection
Public dt As New DataTable
Public dt_pick As New DataTable
Dim orderFrm As New orderForm
Private Sub addOLForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cnn = New OleDb.OleDbConnection
Dim dbprovider As String = "Provider=OraOLEDB.Oracle;"
Dim dbsource As String = "Data Source=Galiboy-PC:1521/XE;User Id=sims;Password=gali;"
cnn.ConnectionString = dbprovider & dbsource
If Not cnn.State = ConnectionState.Open Then
cnn.Open()
End If
Dim da As New OleDb.OleDbDataAdapter("SELECT product_id, description, standard_price, qty_on_hand " & _
"FROM products ORDER BY product_id ", cnn)
da.Fill(dt_pick)
addProductDataGrid.DataSource = dt_pick
End Sub
Private Sub addProductButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addProductButton.Click
fillGrid()
Me.Hide()
orderFrm.Show()
End Sub
Public Sub fillGrid()
Dim qty As Integer = Me.qtyField.Text
' Dim rowNum = New orderFrm.orCount
If Me.addProductDataGrid.Rows.Count > 0 Then
If Me.addProductDataGrid.SelectedRows.Count > 0 Then
If Not cnn.State = ConnectionState.Open Then
cnn.Open()
End If
Dim intproduct_id As Integer = Me.addProductDataGrid.SelectedRows(0).Cells("product_id").Value
Dim da As New OleDb.OleDbDataAdapter("SELECT description, " & qty & " " & Chr(34) & "QUANTITY" & Chr(34) & ", standard_price, standard_price * " & qty & " " & Chr(34) & "SUBTOTAL" & Chr(34) & _
"FROM products WHERE product_id=" & intproduct_id & " ", cnn)
Dim dt As New DataTable
da.Fill(dt)
orderFrm.orderLineGrid.DataSource = dt
End If
End If
End Sub
End Class
I know there are still a lot of flaws in this implementation. But how will I make it work? Any help is appreciated. Thanks a lot.
PS: Do you think this is the efficient and ideal way of working with order and order lines or is there another way? I've seen the interface of a SAP software and it has circular buttons at the side of a cell that when clicked pops out a form for options. I've also thought of using combo boxes in the datagrid instead but scrolling down might be tiresome if there are lots of values. Any opinions? Thanks!