Stock Inventory System: Creating the Stock Master

Submitted by: 
Visitors have accessed this post 7612 times.

In this tutorial, I’m going to show you how to create a stock master. This stock master will cater all the data entry for the new acquired stocks or Item(s). And the loading, updating and deleting of a specific stocks or Items. To start in this lesson, first we need to open our project called “Stockinven”. Then, were going to add new form and we will name it as “Stock Master”. To do this, go to solution explorer right click the project name, then point the mouse pointer to “Add” then choose “Windows Form”. And it looks like as shown below:

After creating the form for Stock Master, you need to set the Name Property of all then design it, and the stock master will looks like as shown below.


To test this application, we need to set first the Stock Master to be the first form to load when we run the program. To do this, here are the following steps:

1. On the menu bar, click the Project.
2. And select Stockinven Properties.

3. Then the properties of stockinven will show.
4. Next, click the ApplicationTabbed.
5. Then on the Startup form.
6. Choose Stock Master.
7. Then press “F5” to test your program.

At this time, we will be going to manually populate the following combobox.

For color, here are the items:
Black,White,Red,Blue,Green,Violet,Brown,Purple

For bbrand here are the items:
Toshiba,Samsung,Dell,Sony,Polytron,Acer,Labtech,Red Fox

For Category, Here are the following items:
Computer parts, School supplies, Consumables, Books

And for Unit and quantity:
Set, Kilograms, Grams, Yard, Piece, Box

Next, let’s start adding code to our application. First Double click the txtprice and add the following code:

This code will activate when you input some value to the txtprice. And it will be computted if the input is numeric else it will be reset to nothing.

  1. 'it check if the value of txtprice is not numeric
  2. If Not IsNumeric(txtprice.Text) Then
  3. txtprice.Text = ""
  4. Else
  5. Dim total As Double
  6. 'it computes for total price
  7. total = FormatNumber(Val(txtprice.Text), 2) * Val(txtnumqty.Text)
  8. 'it passed the value to txttotprice
  9. txttotprice.Text = FormatNumber(total, 2)
  10. End If

Then, were we going to copy some for database connectivity from form1. And we will paste the declaration of variables below the public class and the connection string inside the Stock_Master_load sub. And the code we now look like as shown below:

  1. Public Class Stock_Master
  2. Dim con As New OleDb.OleDbConnection
  3.  
  4.  
  5. Private Sub Stock_Master_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  6. con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\stocksdb.mdb"
  7. End Sub
  8. Private Sub txtprice_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtprice.TextChanged
  9. 'it check if the value of txtprice is not numeric
  10. If Not IsNumeric(txtprice.Text) Then
  11. txtprice.Text = ""
  12. Else
  13. Dim total As Double
  14. 'it computes for total price
  15. total = FormatNumber(Val(txtprice.Text), 2) * Val(txtnumqty.Text)
  16. 'it passed the value to txttotprice
  17. txttotprice.Text = FormatNumber(total, 2)
  18. End If
  19. End Sub
  20. End Class

This time, double click the save button and add the following code:
The code below will do the insertion of data inputted bby the user and store it into the database.

  1. Dim result As Integer
  2. 'we declare cmd to represent an SQL Statements or a stored procedure
  3. 'to execute against a data source
  4. Dim cmd As New OleDb.OleDbCommand
  5. 'gather all information for item description
  6. Dim a As String
  7. a = "Color: " & cbColor.SelectedItem & " " & "Brand: " & cbBrand.SelectedItem & " " & "Other Desc: " & txtitemdescription.Text
  8.  
  9. Try
  10. Dim sql As String
  11. 'we set up an sql statement intended for inserting a data
  12. sql = "INSERT INTO tblitemmaster(itemname, itemdescription, " & _
  13. " itemremarks, itembarcodeno, itemcategory, itemnoqty,itemavailqty, " & _
  14. " itemqty, itempricce, itemtotalprice, dateencoded) " & _
  15. " VALUES('" & txtitemname.Text & "'," & _
  16. "'" & a & "','" & txtitemremarks.Text & "'," & _
  17. "'" & txtitembarcode.Text & "','" & cbcategory.SelectedValue & "'," & _
  18. "'" & txtnumqty.Text & "','" & txtnumqty.Text & "','" & cbunitqty.SelectedValue & "'," & _
  19. "" & Val(txtprice.Text) & "," & Val(txttotprice.Text) & ", " & _
  20. " #" & DateValue(itemdate.Value) & "#)"
  21. 'open the connection
  22. con.Open()
  23.  
  24. With cmd
  25. .Connection = con
  26. .CommandText = sql
  27. 'execute query and return the affected rows
  28. result = cmd.ExecuteNonQuery
  29. 'check if result is zero it means that no data has inserted
  30. If result = 0 Then
  31. MsgBox("No Data has been Inserted!")
  32. Else
  33. 'else greater than one it insert the data successfully
  34. MsgBox("New Data is inseted succesfully!")
  35. End If
  36. End With
  37.  
  38. Catch ex As Exception
  39. 'if something went wrong, it will give a message about the error
  40. MsgBox(ex.Message, MsgBoxStyle.Information)
  41. End Try
  42. 'close the connection
  43. con.Close()

After adding the code above, press “F5” to test the application. then fill up all the fields provided, then click the save button. If successfully save, a message box will appear. And the output now will look like as shown below:

And my next lesson will focus on loading, updating and deleting of an item.


Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.