VB.NET Inventory System Source Code

Inventory Management System Source Code Using VB.NET And MySQL Database

vb.net inventory management system project

in this vb.net project demo we will see how to use our visual basic .net inventory management system with a mysql database.

goals of this project:
- give students / curious persons an example so they can learn from.
helping people create their first project. 
sharing knowledge with others.

this project is not for:
- people who want to use it as their final year project.
- a real life store.

- visual basic .net programming language.
- visual studio express 2013.
- mysql database
- canva.com for images
- flatuicolorpicker.com for colors
- iTextSharp (PDF library)

Watch This Full Demo

1 - Login Form

the login form allow the ADMIN and the other USERS to login into the application main form

vb.net inventory system - login form

if the user enter wrong username or password a message will show up

vb.net inventory system - login form error

as you can see there is a checkbox that allow you to show and hide the password

vb.net inventory system - login form show pass

so, if everything is ok when you click on the login button the main/home form will show up and the login form will close it self.

2 - Home Form

if the user type is ADMIN a "user" tab will be visible on the top menu

vb.net inventory system - home form

if the user type is USER the "user" tab will be invisible

vb.net inventory system - user home form

3 - Product Section

when you click on the Product tab, the MANAGE_PRODUCT_FORM will show up

vb.net inventory system - manage products

- on the form load all products will be displayed into a datagridview.

- when you enter a value in the search box and click search button, only the products that contain this value will be shown in the datagridview.

vb.net inventory system - search products

if you click on the "New Product" button the ADD_NEW_PRODUCT_FORM will show up, this form allow to enter the new product data and insert it into mysql database.

vb.net inventory system - add new product

on the top form you can see a combobox categories, this combobox is populated from category table in the mysql database.
if you want to add a new category without leaving the current form you can easly click on the "Add New Category" button and small form will show up and you can add a new category.

vb.net inventory system - add product category

and if you want to update a product just select the product you want to edit from the datagridview and click on the "Update Product" and the UPDATE_PRODUCT_FORM will show up with all the selected product data displayed on the form.

- NOTE: the number "11" you see on the right of  the combobox category is a label with the id of the product you want to edit, you can make this label invisible if you want. 

vb.net inventory system - update selected product

when you want to delete a product just select the product you want to remove and click on the "Remove Product" button.

vb.net inventory system - delete selected product

4 - Category Section

now if you want to manage the categories you have to go to the category tab.

- you can insert a new category by just entering the name on the textbox and clicking insert.

- when you click on the category tab the MANAGE_CATEGORIES_FORM will show up.

- the MANAGE_CATEGORIES_FORM contain a datagridview with all the categories name and id.

- if you select a category from the datagridview : 1) the data of the selected one will be displayed on the textboxes, 2) the products on the selected category will be displayed on a lisbox. 

- also a navigation buttons for next and previous + a reset button to clear the textboxes text.

vb.net inventory system - manage categories

if you double click on a datagridview row, a list of products will show up on a new form

vb.net inventory system - show products in a category

5 - Customer Section

in this section you can:

- see all the customers on database displayed in datagridview.

- get the selected customer data from datagridview and set it into tetboxes on datagridview click.

- insert a new customer.

- update the selected customer data.

- delete the selected customer.

- navigate using "Next" & "Previous".

- clear all textboxes text using the "Reset" buttons.

- display the selected customer orders count.

- display the selected customer total orders amount.

- display the selected customer last order date.

vb.net inventory system - manage customers

6 - Order Section

when you click on the order tab MANAGE_ORDERS_FORM will show up, and this form contain:

- 1 datagridview with all customers.

- 1 datagridview for products ( show products depending on combobox category ).

- 1 datagridview to display the products you want to add into the order .

vb.net inventory system - manage orders

on the datagridview for customers, if you select a row the customer id will be set into the textbox id,

and if you double click a form will show up with the selected customer orders, and when you select an order you can see all products on this order in a listbox.

vb.net inventory system - customer orders

if you want to add a new customer click on "Add New Customer" button and enter the customer data

vb.net inventory system - add customer

now if you want to add products to the order flow those steps:

1 - select the category you want from the combobox.

2 - double click on the product you want, the QUANTITY_FORM will show up and you can enter the quantity you want, you can't enter 0 or let the box empty or enter a heigher quantity than the one available on the database.

vb.net inventory system - quantity
quantity form
vb.net inventory system - 0 quantity
quantity = 0
vb.net inventory system - unavailable quantity
unavailable quantity

and if everything is ok, the selected product will be add to the order datagridview with the quantity you want.

add product to order with valid quantity
now lets add more products to the order

- in the datagridview you can see a column "Quantity X Price" where we calculate the total price for this product.
- the checkbox "Select All" allow you to select all the products in the datagridview and if you want to delete them click on the "Delete Selected Products".
- on the bottom you can see the total amount of all products.

if all is good, click the "Insert Order" button to add the new order with the details into the database.

vb.net inventory system - insert order

if you want to show all the orders click on the "Show All Orders" button and ALL_ORDERS_FORM will show up with all the orders displayed on a datagridview.

vb.net inventory system - show all orders

when you click on "Print Selected Order" the selected order will be printed into a pdf file using iTextSharp (PDF library)

vb.net inventory system - printed order

7 - User Section

and the last one is the user tab, so when you click on it the MANAGE_USERS_FORM will show up
with all the users displayed on a datagridview.

vb.net inventory system - manage users

if you select a user from the datagridview all the data will be set into textboxes so you can delete it or edit his informations.

vb.net inventory system - select user

and to add a new user click on the "Create New User" button so the ADD_NEW_USER_FORM will show up, and all you have to do is enter the user informations and click add.

vb.net inventory system - add new user

if you want the source code click on the download button below

disclaimer: you will get the source code + the database script
                    and to make it work in your machine is your responsibility
                    and to debug any error/exception is your responsibility
                    this project is for the students who want to see an example and read                                      the code not to get and run

Java Populate JCombobox From Text File

How To Fill A JComboBox With Items From Txt File Using Java NetBeans

Fill JCombobox From Text File Using Java

In this Java Tutorial we will see How To Add Items To JCombobox From Text File Using For Loop + Array + BufferedReader In Java NetBeans .

Project Source Code:

public void fillComboFromTxtFile(){
        String filePath = "C:\\Users\\Desktop\\file1.txt";
        File file = new File(filePath);
        try {
            BufferedReader br = new BufferedReader(new FileReader(file));
            Object[] lines = br.lines().toArray();
            for(int i = 0; i < lines.length; i++){
                String line = lines[i].toString();
        } catch (FileNotFoundException ex) {
            Logger.getLogger(jcombo_items_from_txt_file.class.getName()).log(Level.SEVERE, null, ex);


insert items to jcombobx from txt file using java

Java Two Dates Difference In Days

How To Get Days Difference Between 2 Dates Using Java NetBeans

Days Difference Between Two Dates In Java

In this Java Tutorial we will see How To Get The Number Of Days Diffrence Between Two Date Using Calendar On Button Click Event In Java NetBeans .

Project Source Code:

private void jButtonDaysDiffActionPerformed(java.awt.event.ActionEvent evt) {                                                
        Calendar c1 = new GregorianCalendar(2000,Calendar.JULY,25);
        Calendar c2 = new GregorianCalendar(2007,Calendar.DECEMBER,31);
        // 1000 x 60 X 60 X 24 = MS per Day
        System.out.println("Days Diff = " + (c2.getTimeInMillis() - c1.getTimeInMillis()) / (1000*60*60*24));

Days Diff = 2715

Java Using Regex

How To Use Regular Expressions In Java NetBeans

Regular Expressions In Java

In this Java Tutorial we will see How To Use Regex (Regular Expressions) To Validate An Email Address And A Phone Number On Button "Check" Click Event Using Java NetBeans .

Project Source Code:

    private void jButtonCheckActionPerformed(java.awt.event.ActionEvent evt) {                                             
        //Email Like: mail@mail.com          => ^([\w]+)@([\w]+)\.([\w]+)$
       //URL Like:   http://www.google.com   => ^(http://www\.)([\w]+)\.([\w]+)$
       // email
       Pattern pMail = Pattern.compile("^([\\w]+)@([\\w]+)\\.([\\w]+)$");
       Matcher mMail = pMail.matcher(jTextFieldEmail.getText());
       boolean isEmailValid = mMail.matches();
            jLabelEmail.setText("Valid Email");
           jLabelEmail.setText("InValid Email");
       // URL
       Pattern pURL = Pattern.compile("^(http://www\\.)([\\w]+)\\.([\\w]+)$");
       Matcher mURL = pURL.matcher(jTextFieldURL.getText());
       boolean isURLValid = mURL.matches();
            jLabelURL.setText("Valid URL");
           jLabelURL.setText("InValid URL");


Regular Expressions example In Java

Java Add Action To All JButtons

How To Add Action To All Buttons In A JPanel Using Java

add action to all buttons in java

In this Java Tutorial we will see How To Create A Function To Set An ActionListener To All The JButtons Inside A JFrame Using JPanel In Java Programming Language NetBeans IDE .

Project Source Code:

public void addAction()
        Component[] components = jPanel1.getComponents();
        for(Component component : components)
            if(component instanceof JButton)
                JButton button = (JButton) component;
                button.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {

////// OUTPUT : 

add ActionListener to all jbuttons in java

Java JTable Style

How To Style A JTable Using Java NetBeans

JTable Style In Java

In this Java Tutorial we will see How To Style The Jtable By Changeing Row Height, Show Grid, Set Grid Color, Set Background, Set Foreground, Set Selection Background,  Set Selection Foreground, Set Font In Java NetBeans .

Project Source Code:

        //jTable1.setRowHeight(1, 100);


        jTable1.setFont(new Font("Comic Sans MS", Font.ITALIC, 20)); 


Style JTable Using Java

Java Placeholder

How To Create A Placeholder String Using Java NetBeans

Placeholder In Java

In this Java Tutorial we will see How To Make A JTextField With A PlaceHolder Text Using Events => jTextFieldFocusGained + jTextFieldFocusLost In Java NetBeans .

Project Source Code:

private void jTextField1FocusGained(java.awt.event.FocusEvent evt) {                                        

    private void jTextField1FocusLost(java.awt.event.FocusEvent evt) {                                      
        if(jTextField1.getText().trim().equals("") || jTextField1.getText().trim().toLowerCase().equals("email")){
            jTextField1.setForeground(new Color(236, 240, 241));

    private void jTextField2FocusGained(java.awt.event.FocusEvent evt) {                                        

    private void jTextField2FocusLost(java.awt.event.FocusEvent evt) {                                      
        if(jTextField2.getText().trim().equals("") || jTextField2.getText().trim().toLowerCase().equals("username")){
            jTextField2.setForeground(new Color(236, 240, 241));


Placeholder String In Java

VB.NET Tic Tac Toe Game Source Code

How To Make A TIC TAC TOE Game In VBNET 

VB.NET Tic-Tac-Toe Game

In This VB.NET Tutorial we will See How To Build A Tic-Tac-Toe Game With Replay And Get The Winner And Change Winning Boxes Color Using Visual Basic.Net And Visual Studio Editor .

Part 1

                                                                          Part 2

Part 3

                                                                          Part 4

Project Source Code:

Public Class VB_TIC_TAC_TOE

    Private Sub VB_TIC_TAC_TOE_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        ' add event to all buttons inside the panel2 
        For Each c As Control In Panel2.Controls

            If c.GetType() = GetType(Button) Then

                AddHandler c.Click, AddressOf btn_Click

            End If


    End Sub

    Dim XorO As Integer = 0
    ' create button event 
    Private Sub btn_Click(sender As Object, e As EventArgs)

        Dim btn As Button = sender

        ' we will clear buttons text later 
        If btn.Text.Equals("") Then

            If XorO Mod 2 = 0 Then

                btn.Text = "X"
                btn.ForeColor = Color.Red
                Label1.Text = "[O] Turn"

                btn.Text = "O"
                btn.ForeColor = Color.Blue
                Label1.Text = "[X] Turn"
            End If

            XorO += 1

        End If

    End Sub

    Dim win As Boolean = False

    ' create a function to get the winner 
    Private Sub getTheWinner()

        If Not Button1.Text.Equals("") AndAlso Button1.Text.Equals(Button2.Text) AndAlso Button1.Text.Equals(Button3.Text) Then
            win = True
            winEffect(Button1, Button2, Button3)
        End If

        If Not Button4.Text.Equals("") AndAlso Button4.Text.Equals(Button5.Text) AndAlso Button4.Text.Equals(Button6.Text) Then
            win = True
            winEffect(Button4, Button5, Button6)
        End If

        If Not Button7.Text.Equals("") AndAlso Button7.Text.Equals(Button8.Text) AndAlso Button7.Text.Equals(Button9.Text) Then
            win = True
            winEffect(Button7, Button8, Button9)
        End If

        If Not Button1.Text.Equals("") AndAlso Button1.Text.Equals(Button4.Text) AndAlso Button1.Text.Equals(Button7.Text) Then
            win = True
            winEffect(Button1, Button4, Button7)
        End If

        If Not Button2.Text.Equals("") AndAlso Button2.Text.Equals(Button5.Text) AndAlso Button2.Text.Equals(Button8.Text) Then
            win = True
            winEffect(Button2, Button5, Button8)
        End If

        If Not Button3.Text.Equals("") AndAlso Button3.Text.Equals(Button6.Text) AndAlso Button3.Text.Equals(Button9.Text) Then
            win = True
            winEffect(Button3, Button6, Button9)
        End If

        If Not Button1.Text.Equals("") AndAlso Button1.Text.Equals(Button5.Text) AndAlso Button1.Text.Equals(Button9.Text) Then
            win = True
            winEffect(Button1, Button5, Button9)
        End If

        If Not Button3.Text.Equals("") AndAlso Button3.Text.Equals(Button5.Text) AndAlso Button3.Text.Equals(Button7.Text) Then
            win = True
            winEffect(Button3, Button5, Button7)
        End If

        ' if no one win later 
        ' 9 buttons with X or O mean 9 char = no button is empty 
        If allbuttonsTextLength() = 9 AndAlso win = False Then

            Label1.Text = "NO Winner"

        End If

    End Sub

   ' get all buttons text length 
    Function allbuttonsTextLength() As Integer

        Dim btnsTxtLength As Integer = 0

        For Each c As Control In Panel2.Controls

            If c.GetType() = GetType(Button) Then

                btnsTxtLength += c.Text.Length

            End If


        Return btnsTxtLength

    End Function

    ' win effect function to change buttons 
    ' background color + foreColor when one player win 
    Private Sub winEffect(ByVal b1 As Button, ByVal b2 As Button, ByVal b3 As Button)

        b1.BackColor = Color.Red
        b2.BackColor = Color.Red
        b3.BackColor = Color.Red

        b1.ForeColor = Color.White
        b2.ForeColor = Color.White
        b3.ForeColor = Color.White

        Label1.Text = b1.Text + " Win"

    End Sub

     ' new partie button 
    Private Sub ButtonNewPartie_Click(sender As Object, e As EventArgs) Handles ButtonNewPartie.Click

        XorO = 0
        win = False
        Label1.Text = "Play"
        For Each c As Control In Panel2.Controls

            If c.GetType() = GetType(Button) Then

                c.BackColor = Color.White
                c.Text = ""

            End If


    End Sub
End Class

download the source code


Make A Tic Tac Toe Game In Visual Basic.Net