Affichage des articles dont le libellé est vb.net project source code. Afficher tous les articles
Affichage des articles dont le libellé est vb.net project source code. Afficher tous les articles

VB.Net Products Manager Project With MySQL Database

How To Make a VB.Net Products Manager Project With MySQL Database Using Visual Studio

VB.Net Products Manager Project With MySQL Database


in this visual basic .net tutorial we will see how to Create a products manager project in one form using windowForm in vb.net programming language and mysql database.

tools:
- visual basic .net programming language.
- microsoft visual studio express 2013.
- mysql database.
- phpmyadmin.
- pixabay.com.

Watch The Full Tutorial


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



- The Project Source Code


Imports MySql.Data.MySqlClient


Public Class ManagementForm

    ' variables
    Dim connection As MySqlConnection = New MySqlConnection("datasource = localhost;port = 3306; initial catalog = csharp_products; username = root; password =")
    Dim table As DataTable = New DataTable()
    Dim productIndex As Integer = 0



    ' form load
    Private Sub ManagementForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load

         ' custom datagridview
        dataGridViewProducts.RowTemplate.Height = 40
        pictureBoxClose.Image = My.Resources.close
        ' populate datagridview
        showProducts()
        comboBoxCategories.SelectedIndex = 0
        dataGridViewProducts.ColumnHeadersDefaultCellStyle.BackColor = Color.FromArgb(47, 54, 64)
        dataGridViewProducts.ColumnHeadersDefaultCellStyle.ForeColor = Color.White
        dataGridViewProducts.ColumnHeadersDefaultCellStyle.Font = New System.Drawing.Font("Verdana", 15, FontStyle.Italic)
        dataGridViewProducts.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        dataGridViewProducts.GridColor = Color.DarkBlue
        dataGridViewProducts.AllowUserToAddRows = False
        dataGridViewProducts.EnableHeadersVisualStyles = False

    End Sub

    ' picturebox close
    Private Sub pictureBoxClose_Click(sender As Object, e As EventArgs) Handles pictureBoxClose.Click

        ' close the connection
        If ConnectionState.Open = connection.State Then
            connection.Close()
        End If

        System.Environment.[Exit](System.Environment.ExitCode)

    End Sub

    ' button search
    Private Sub buttonSearch_Click(sender As Object, e As EventArgs) Handles buttonSearch.Click

        Try
            Dim id As Integer = CInt(numericUpDownID.Value)
            Dim row As DataRow() = table.[Select]("id = " & id)

            If row.Length > 0 Then
                textBoxName.Text = row(0)(1).ToString()
                comboBoxCategories.Text = row(0)(2).ToString()
                NumericUpDownQuantity.Text = row(0)(3).ToString()
                textBoxPrice.Text = row(0)(4).ToString()
                textBoxImagePath.Text = row(0)(5).ToString()
                pictureBoxProduct.Image = Image.FromFile(row(0)(5).ToString())
            Else
                textBoxName.Text = ""
                comboBoxCategories.SelectedIndex = 0
                NumericUpDownQuantity.Text = ""
                textBoxPrice.Text = ""
                textBoxImagePath.Text = ""
                pictureBoxProduct.Image = Nothing
                MessageBox.Show("No Product With This ID, Enter a New One", "Product Not found", MessageBoxButtons.OK, MessageBoxIcon.Information)
            End If

        Catch ex As Exception
            MessageBox.Show("Error -> " & ex.Message, "Product Not found", MessageBoxButtons.OK, MessageBoxIcon.[Error])
        End Try

    End Sub

    ' button browse image
    Private Sub buttonBrowse_Click(sender As Object, e As EventArgs) Handles buttonBrowse.Click

        Dim opf As OpenFileDialog = New OpenFileDialog()
        opf.Filter = "Choose Image(*.jpg;*.png;*.gif)|*.jpg;*.png;*.gif"

        If opf.ShowDialog() = DialogResult.OK Then
            pictureBoxProduct.Image = Image.FromFile(opf.FileName)
            textBoxImagePath.Text = opf.FileName
        End If

    End Sub

    ' button add product
    Private Sub Button_Add_Click(sender As Object, e As EventArgs) Handles Button_Add.Click

        Try
            Dim name As String = textBoxName.Text
            Dim category As String = comboBoxCategories.Text
            Dim quantity As Integer = Integer.Parse(NumericUpDownQuantity.Text)
            Dim price As Single = Single.Parse(textBoxPrice.Text)
            Dim imagePath As String = textBoxImagePath.Text
            Dim command As MySqlCommand = New MySqlCommand("INSERT INTO `product`(`name`, `category`, `quantity`, `price`, `picture`) VALUES (@nm,@ctg,@qty,@prc,@pic)", connection)
            command.Parameters.Add("@nm", MySqlDbType.VarChar).Value = name
            command.Parameters.Add("@ctg", MySqlDbType.VarChar).Value = category
            command.Parameters.Add("@qty", MySqlDbType.Int16).Value = quantity
            command.Parameters.Add("@prc", MySqlDbType.Float).Value = price
            command.Parameters.Add("@pic", MySqlDbType.VarChar).Value = imagePath

            If ConnectionState.Closed = connection.State Then
                connection.Open()
            End If

            If command.ExecuteNonQuery() = 1 Then
                showProducts()
                MessageBox.Show("The Product Has Been Added Successfully", "Product Added", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Else
                MessageBox.Show("The Product Hasn't Been Added", "Product Not Added", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            End If

        Catch ex As Exception
            MessageBox.Show("Enter The Product Info", "Empty Fileds", MessageBoxButtons.OK, MessageBoxIcon.[Stop])
        End Try


    End Sub


    ' button edit product
    Private Sub Button_Edit_Click(sender As Object, e As EventArgs) Handles Button_Edit.Click

        Try
            Dim id As Integer = CInt(numericUpDownID.Value)
            Dim name As String = textBoxName.Text
            Dim category As String = comboBoxCategories.Text
            Dim quantity As Integer = Integer.Parse(NumericUpDownQuantity.Text)
            Dim price As Single = Single.Parse(textBoxPrice.Text)
            Dim imagePath As String = textBoxImagePath.Text
            Dim command As MySqlCommand = New MySqlCommand("UPDATE `product` SET `name`=@nm,`category`=@ctg,`quantity`=@qty,`price`=@prc,`picture`=@pic WHERE `id` = @id", connection)
            command.Parameters.Add("@nm", MySqlDbType.VarChar).Value = name
            command.Parameters.Add("@ctg", MySqlDbType.VarChar).Value = category
            command.Parameters.Add("@qty", MySqlDbType.Int16).Value = quantity
            command.Parameters.Add("@prc", MySqlDbType.Float).Value = price
            command.Parameters.Add("@pic", MySqlDbType.VarChar).Value = imagePath
            command.Parameters.Add("@id", MySqlDbType.Int16).Value = id

            If ConnectionState.Closed = connection.State Then
                connection.Open()
            End If

            If command.ExecuteNonQuery() = 1 Then
                showProducts()
                MessageBox.Show("The Product Info Has Been Edited Successfully", "Edit Product", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Else
                MessageBox.Show("The Product Info Hasn't Been Edited", "Product Not Edited", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            End If

        Catch ex As Exception
            MessageBox.Show("Enter The Product Info", "Empty Fileds", MessageBoxButtons.OK, MessageBoxIcon.[Stop])
        End Try

    End Sub

    ' button remove product
    Private Sub Button_Remove_Click(sender As Object, e As EventArgs) Handles Button_Remove.Click

        Dim id As Integer = CInt(numericUpDownID.Value)
        Dim command As MySqlCommand = New MySqlCommand("DELETE FROM `product` WHERE `id` = @id", connection)
        command.Parameters.Add("@id", MySqlDbType.Int16).Value = id

        If ConnectionState.Closed = connection.State Then
            connection.Open()
        End If

        If MessageBox.Show("Are You Sure You Want To Remove This Product", "Remove Product", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = System.Windows.Forms.DialogResult.Yes Then

            If command.ExecuteNonQuery() = 1 Then
                numericUpDownID.Value = 0
                textBoxName.Text = ""
                comboBoxCategories.SelectedIndex = 0
                NumericUpDownQuantity.Text = ""
                textBoxPrice.Text = ""
                textBoxImagePath.Text = ""
                pictureBoxProduct.Image = Nothing
                showProducts()
                MessageBox.Show("Product Removed Successfully", "Remove Product", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Else
                MessageBox.Show("Product NOT Removed", "Remove Product", MessageBoxButtons.OK, MessageBoxIcon.[Error])
            End If
        End If


    End Sub


    ' button clear fields
    Private Sub buttonClear_Click(sender As Object, e As EventArgs) Handles buttonClear.Click

        textBoxName.Text = ""
        comboBoxCategories.SelectedIndex = 0
        NumericUpDownQuantity.Text = ""
        textBoxPrice.Text = ""
        textBoxImagePath.Text = ""
        pictureBoxProduct.Image = Nothing

    End Sub


    ' button display first product
    Private Sub buttonFirst_Click(sender As Object, e As EventArgs) Handles buttonFirst.Click

        productIndex = 0
        displayInfo(productIndex)

    End Sub


    ' button display next product
    Private Sub buttonNext_Click(sender As Object, e As EventArgs) Handles buttonNext.Click

        productIndex += 1

        If productIndex > table.Rows.Count - 1 Then
            productIndex = table.Rows.Count - 1
        End If

        displayInfo(productIndex)

    End Sub


    ' button display previous product
    Private Sub buttonPrevious_Click(sender As Object, e As EventArgs) Handles buttonPrevious.Click

        productIndex -= 1

        If productIndex < 0 Then
            productIndex = 0
        End If

        displayInfo(productIndex)

    End Sub


    ' button display last product
    Private Sub buttonLast_Click(sender As Object, e As EventArgs) Handles buttonLast.Click

        productIndex = table.Rows.Count - 1
        displayInfo(productIndex)

    End Sub

    ' display the selected product from datagridview
    Private Sub dataGridViewProducts_Click(sender As Object, e As EventArgs) Handles dataGridViewProducts.Click

        Dim selectedRow As DataGridViewRow = dataGridViewProducts.CurrentRow
        numericUpDownID.Value = Integer.Parse(selectedRow.Cells(0).Value.ToString())
        textBoxName.Text = selectedRow.Cells(1).Value.ToString()
        comboBoxCategories.Text = selectedRow.Cells(2).Value.ToString()
        NumericUpDownQuantity.Text = selectedRow.Cells(3).Value.ToString()
        textBoxPrice.Text = selectedRow.Cells(4).Value.ToString()
        textBoxImagePath.Text = selectedRow.Cells(5).Value.ToString()
        pictureBoxProduct.Image = Image.FromFile(selectedRow.Cells(5).Value.ToString())

    End Sub


   ' textBox Price KeyUp - check if the price is correct
    Private Sub textBoxPrice_KeyUp(sender As Object, e As KeyEventArgs) Handles textBoxPrice.KeyUp

        Try
            Dim price As Single = Single.Parse(textBoxPrice.Text)
        Catch ex As Exception
            MessageBox.Show("Enter a Valid Price ( " & ex.Message & " )", "Invalid Price", MessageBoxButtons.OK, MessageBoxIcon.[Error])
            textBoxPrice.Text = ""
        End Try

    End Sub


    ' create a function to display product in textboxes and picturebox
    Public Sub displayInfo(ByVal index As Integer)
        dataGridViewProducts.ClearSelection()
        dataGridViewProducts.Rows(index).Selected = True
        numericUpDownID.Value = CInt(table.Rows(index)(0))
        textBoxName.Text = table.Rows(index)(1).ToString()
        comboBoxCategories.Text = table.Rows(index)(2).ToString()
        NumericUpDownQuantity.Text = table.Rows(index)(3).ToString()
        textBoxPrice.Text = table.Rows(index)(4).ToString()
        textBoxImagePath.Text = table.Rows(index)(5).ToString()
        pictureBoxProduct.Image = Image.FromFile(table.Rows(index)(5).ToString())
    End Sub


    ' create a function to show products in the datagridview
    Public Sub showProducts()
        table.Clear()
        dataGridViewProducts.DataSource = table
        Dim adapter As MySqlDataAdapter = New MySqlDataAdapter("SELECT * FROM `product`", connection)
        adapter.Fill(table)
        dataGridViewProducts.DataSource = table
        label_ProductsCount.Text = table.Rows.Count.ToString() & " Product"
    End Sub


End Class


OUTPUT:

VB.Net Project Source Code With MySQL Database

VB.Net Project Source Code With MySQL Database


VB.Net - Real Estate Management System Source Code

Real Estate Management System Project Source Code Using Visual Basic .Net And MySQL Database

Real Estate Management System Project Using VB.Net

in this vb.net project tutorial serie we will see how to make a real estate management system project using windowForm in visual basic .net programming language and mysql database.

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

tools:
- vb.net programming language.
- microsoft visual studio express 2013.
- mysql database.
- phpmyadmin.
- xampp server.
- pixabay.com ( website for free images ).

Watch This Full Demo


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




1 - The Login Form

the login form will allow the Users to login into the Real-Estate application Main Form.
the user need to enter his username and password before clicking the login button.


login from


if the user let the username or password empty, the textbox and label background color will become red.


login from 2


login from 3

if the user enter wrong username or password an error message will show up under the password fields.


login from 4


and if the user enter the correct data and click on the login button the main real estate management system form will show up and the login form will closed.


2 - The Real Estate System Main Project Form

after the user successffully login, he will see this main project window with a menu using panels and buttons.
the user can select where he want to go by clicking the on the item from the menu.

main form

this form contains a menu on the top to make it easy for the user to navigate on the application.

menu

with the menu this form contains also statics part in the middle of the form to show the user how many properties, owners, clients, and sales are in the application.
+ a refresh button to see the new statics when ever he add or remove an item.

statics


3 - The Real Estate System, Manage Clients Form


- this form contains a datagridview with all clients data.

- to add a new client, enter his data and click on "Add" button.

- to edit a client you need to select the one you wan to edit from the datagridview and enter his new data.

- when you want to delete a client just select the client you want to remove and click on the "Remove" button.
- to make it easy for the user when he want to add a new client, he can clear all textboxes by clicking on the "Clear Fields" button.

clients form

4 - The Real Estate System, Manage Owners Form


this form is pretty much like the clients form.

you can add, edit, remove selected owner and all the good stuff.

owners form

if you want to see the selected owner properties, just select the owner from the datagridview and click the "Show This Owner's Properties" button, and a form will show up with all owner's properties in it.


owner's properties

5 - The Real Estate System - Manage Property's Types Form


in this form the user can manage the types of properties in the system project.
all types are displayed in a listbox, if you select an item from the listbox it will be displayed on the textboxes.



types form


7 - The Real Estate System , Manage Property Form


this form contains textBoxes, numericUpDown, checkBoxes and one comboBox populated  with all types.


properties form


in this form the user can add, edit, search and remove a property.
when the user want to add/edit a property he need to select an owner for this property, and he can do that by clicking on the "Select Owner" button and a form will show up with a datagrdview filled with all owners, allowing the user to select an owner.
when the user double click on the datagridview the "select owner" form will be closed and the owner id will be set into the textbox.


owners list

if the user want to search for a property all he need to do is to enter the property's id and click on the "Search" button.

search for a property


Some Notes: each property need to be assigned to a type, which can be selected from the combobx.
if the user let the age at "0" it mean that the real estate is brand new
( except for the lands because ... well it's a land :/ )

if the user want to see the selected property images by clicking on the "Show This Property Images".


property images slider


if the user want to see all properties list by clicking on the "Show All Properties" button .


properties list form

8 - The Real Estate System , Manage Property's Images Form


this form contains 2 datagridviews,1 listbox and 1 picturebox.
- datagridview 1 is filled with all types.
- datagridview 2 is filled with all properties, when the user select a type from datagridview 1 all properties in this type will be displayed in datagridview 2.
- the listbox is populated with all properties images, when the user select a property from datagridview 2 all images of this property will be displayed in listbox.
- when the user select an image from the listbox, the selected image will be displayed in the picturebox.

the user can browse a photo from his computer and add it to the selected property.
the user can remove the selected image by selecting it from the listbox.
there is no edit image, just add and remove.


manage property images form


manage property images form 2


when you click on the "Show This Property Images" a form will show up with a SlideShow to display the images and two buttons to navigate + a label displaying the total images for the selected property.


images slider

9 - The Real Estate System , Manage Sales Form


in this form the user can manage the properties sales.
this form contains 2 datagridviews:
1 - display the sales.
2 - display the properties.
and you can add, edit remove the selected sale.


sales form

to display only the clients the user need to click on the "Show Clients" button. 


show clients

the properties are displayed by default but if the user click to show the clients and want to see the properties again he need to click on the "Show Properties" button. 


show properties


to display only the properties sold, click on the "Properties Sold" button under the  datagridview. 


Properties Sold

to display only the properties NOT sold, click on the "Properties Not Sold" button under the  datagridview. 


Properties Not Sold



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


VB.Net Hotel Management System Source Code

Hotel Management System In Visual Basic.Net And MySQL Database With Source Code

VB.Net Hotel Management System Project


in this visual basic .net project tutorial we will see how to create a simple desktop application with winforms to manage hotel reservations using vb.net programming language and mysql database.


goals of this project:
- give students / curious persons an example so they can learn from.
- give beginners a step by step project so they can create their own. 
- help people to learn vb.net by making projects.
- sharing knowledge with others.


tools:
- visual basic .net programming language.
- visual studio express 2013.
- mysql database.
- xampp server.
- phpmyadmin.



Watch The Full Project Tutorial




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





in this project we will create 4 classes and 4 forms:
- classes: 
* CONNECTION > create the connection with mysql database.
* ClIENT > where we will add functions for the client.
* ROOMS > where we will add functions for the room. 
* RESERVATIONS > where we will add functions for the reservation.  

- forms: 
* Login > where the user can enter his username to login.
* Manage Clients > where we will manage the hotel client informations.
* Manage Rooms > where we will mange the hotel's rooms. 
* Manage Reservations > where we will add functions for the reservation.  

> and you need to download mysql connector from here -> https://dev.mysql.com/downloads/connector/net/8.0.html


1 - The Login Form 

before getting access to the main form the user need to login first by entering his username and password.
and we will check if the username/password textbox are empty.
and if the user enter the wrong username or password or this user doesn't exists at all.

The Login Button: 

Private Sub ButtonLogin_Click(sender As Object, e As EventArgs) Handles ButtonLogin.Click

        Dim connection As New CONNECTION()
        Dim adapter As New MySqlDataAdapter()
        Dim command As New MySqlCommand()
        Dim table As New DataTable()
        Dim username As String = TextBoxUsername.Text
        Dim password As String = TextBoxPassword.Text
        Dim selectQuery As String = "SELECT * FROM `users` WHERE `username`=@un AND `password`=@pass"

        command.CommandText = selectQuery
        command.Connection = connection.getConnection()

        command.Parameters.Add("@un", MySqlDbType.VarChar).Value = username
        command.Parameters.Add("@pass", MySqlDbType.VarChar).Value = password

        adapter.SelectCommand = command
        adapter.Fill(table)

        If table.Rows.Count > 0 Then

            Dim mainForm As New MainForm()
            mainForm.Show()
            Me.Hide()

        Else

            MessageBox.Show("Invalid Username Or Password", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

        End If

    End Sub



vb.net hotel management system - login form



if the user enter the correct username and password we will show him the main form.

2 - The Main Form

this is a quick and easy from with a menu created with a panel and labels to take the user to the selected form on label click. 

    Private Sub LabelMClients_Click(sender As Object, e As EventArgs) Handles LabelMClients.Click

        Dim manage_Cl_Form As New ManageClientsForm()
        manage_Cl_Form.ShowDialog()

    End Sub

    Private Sub LabelMRooms_Click(sender As Object, e As EventArgs) Handles LabelMRooms.Click

        Dim manage_Rm_Form As New ManageRoomsForm()
        manage_Rm_Form.ShowDialog()

    End Sub

    Private Sub LabelMReservastions_Click(sender As Object, e As EventArgs) Handles LabelMReservastions.Click

        Dim manage_Rv_Form As New ManageReservationsForm()
        manage_Rv_Form.ShowDialog()

    End Sub


vb.net hotel management system - main form menu

3 - The Manage Hotel Clients Form

this form allow the user to manage the hotel clients.
this form contains a datagridview filled with all clients data.
this form call functions from the class "CLIENT". 

- Add New Client Button

 Private Sub ButtonAdd_Click(sender As Object, e As EventArgs) Handles ButtonAdd.Click

        Dim fname As String = TextBoxFname.Text
        Dim lname As String = TextBoxLname.Text
        Dim phone As String = TextBoxPhone.Text
        Dim email As String = TextBoxEmail.Text

        If fname.Trim().Equals("") Or lname.Trim().Equals("") Or phone.Trim().Equals("") Then

            MessageBox.Show("Required First & Last Name, Phone", "Missing Information", MessageBoxButtons.OK, MessageBoxIcon.Error)

        Else

            If client.addClient(fname, lname, phone, email) Then

                MessageBox.Show("New Client Added Successfully", "Add Client", MessageBoxButtons.OK, MessageBoxIcon.Information)
                DataGridView1.DataSource = client.getAllClients()

            Else

                MessageBox.Show("Client Not Added", "Add Client", MessageBoxButtons.OK, MessageBoxIcon.Warning)

            End If

        End If


    End Sub

- Edit The Selected Client Button


  Private Sub ButtonEdit_Click(sender As Object, e As EventArgs) Handles ButtonEdit.Click

        Dim fname As String = TextBoxFname.Text
        Dim lname As String = TextBoxLname.Text
        Dim phone As String = TextBoxPhone.Text
        Dim email As String = TextBoxEmail.Text

        If TextBoxId.Text.Trim().Equals("") Then

            MessageBox.Show("Select The User You Want to Edit", "Missing ID", MessageBoxButtons.OK, MessageBoxIcon.Error)

        Else

            If fname.Trim().Equals("") Or lname.Trim().Equals("") Or phone.Trim().Equals("") Then

                MessageBox.Show("Required First & Last Name, Phone", "Missing Information", MessageBoxButtons.OK, MessageBoxIcon.Error)

            Else

                Dim id As Integer = Convert.ToInt32(TextBoxId.Text)

                If client.editClient(id, fname, lname, phone, email) Then

                    MessageBox.Show("Client Updated Successfully", "Edit Client", MessageBoxButtons.OK, MessageBoxIcon.Information)
                    DataGridView1.DataSource = client.getAllClients()

                Else

                    MessageBox.Show("Client Not Updated", "Edit Client", MessageBoxButtons.OK, MessageBoxIcon.Warning)

                End If

            End If

        End If

    End Sub


- Delete The Selected Client Button

  Private Sub ButtonRemove_Click(sender As Object, e As EventArgs) Handles ButtonRemove.Click


        If TextBoxId.Text.Trim().Equals("") Then

            MessageBox.Show("Enter The Client Id", "Missing ID", MessageBoxButtons.OK, MessageBoxIcon.Error)

        Else
            Dim id As Integer = Convert.ToInt32(TextBoxId.Text)

            If client.removeClient(id) Then

                MessageBox.Show("Client Deleted Successfully", "Delte Client", MessageBoxButtons.OK, MessageBoxIcon.Information)
                DataGridView1.DataSource = client.getAllClients()

                ' clear boxes
                TextBoxId.Text = ""
                TextBoxFname.Text = ""
                TextBoxLname.Text = ""
                TextBoxPhone.Text = ""
                TextBoxEmail.Text = ""

            Else

                MessageBox.Show("Client Not Deleted", "Delete Client", MessageBoxButtons.OK, MessageBoxIcon.Warning)

            End If

        End If

    End Sub


vb.net hotel management system - manage clients form


4 - The Manage Hotel Rooms Form

here the user can add a new room to the hotel system.
when you add a new room you need to select the type of room (single, double, family, suite). 

and like the client form you can view all rooms in a datagridview + how many rooms this hotel have, and add, edit, remove the selecte one + a combobx populated with all room's categories.


vb.net hotel management system - room's categories

- Add New Room Button
when you add a new room the "reserved" column will be set to no by default.

           Private Sub ButtonAdd_Click(sender As Object, e As EventArgs) Handles ButtonAdd.Click

        Try

            Dim type As Integer = Convert.ToInt32(ComboBoxType.SelectedValue)
            Dim phone As String = TextBoxPhone.Text
            Dim reserved As String = ""

            If RadioButtonYes.Checked Then

                reserved = "Yes"

            ElseIf RadioButtonNo.Checked Then

                reserved = "No"

            End If

            If TextBoxNumber.Text.Trim().Equals("") Or TextBoxPhone.Text.Trim().Equals("") Then

                MessageBox.Show("Make Sure to Enter The Room Number and The Phone Number", "Empty Fields", MessageBoxButtons.OK, MessageBoxIcon.Error)

            Else

                Dim number As Integer = Convert.ToInt32(TextBoxNumber.Text)

                If room.addRoom(number, type, phone, reserved) Then

                    MessageBox.Show("Room Added Successfully", "Add Room", MessageBoxButtons.OK, MessageBoxIcon.Information)
                    DataGridView1.DataSource = room.getAllRooms()
                    ' display the number of rooms on the LabelRoomsCount
                    LabelRoomsCount.Text = room.getAllRooms().Rows.Count.ToString() + " Room"

                Else

                    MessageBox.Show("Room Not Added", "Add Room", MessageBoxButtons.OK, MessageBoxIcon.Error)

                End If

            End If

        Catch ex As Exception

            MessageBox.Show(ex.Message, "Duplicate Room Number", MessageBoxButtons.OK, MessageBoxIcon.Warning)

        End Try
        
    End Sub

- Edit The Selected Room Button

            Private Sub ButtonEdit_Click(sender As Object, e As EventArgs) Handles ButtonEdit.Click

        Try

            Dim type As Integer = Convert.ToInt32(ComboBoxType.SelectedValue)
            Dim phone As String = TextBoxPhone.Text
            Dim reserved As String = ""

            If RadioButtonYes.Checked Then

                reserved = "Yes"

            ElseIf RadioButtonNo.Checked Then

                reserved = "No"

            End If

            If TextBoxNumber.Text.Trim().Equals("") Or TextBoxPhone.Text.Trim().Equals("") Then

                MessageBox.Show("Make Sure to Enter The Room Number and The Phone Number", "Empty Fields", MessageBoxButtons.OK, MessageBoxIcon.Error)

            Else

                Dim number As Integer = Convert.ToInt32(TextBoxNumber.Text)

                If room.editRoom(number, type, phone, reserved) Then

                    MessageBox.Show("Room Updated Successfully", "Edit Room", MessageBoxButtons.OK, MessageBoxIcon.Information)
                    DataGridView1.DataSource = room.getAllRooms()

                Else

                    MessageBox.Show("Room Not Updated", "Edit Room", MessageBoxButtons.OK, MessageBoxIcon.Error)

                End If

            End If

        Catch ex As Exception

            MessageBox.Show(ex.Message)

        End Try

    End Sub

- Delete The Selected Room Button

            Private Sub ButtonRemove_Click(sender As Object, e As EventArgs) Handles ButtonRemove.Click

        Try

            Dim number As Integer = Convert.ToInt32(TextBoxNumber.Text)

            If room.removeRoom(number) Then

                MessageBox.Show("Room Deleted Successfully", "Delete Room", MessageBoxButtons.OK, MessageBoxIcon.Information)
                DataGridView1.DataSource = room.getAllRooms()

                ' reset and clear fields
                TextBoxNumber.Text = ""
                ComboBoxType.SelectedIndex = 0
                TextBoxPhone.Text = ""
                RadioButtonYes.Checked = True

                ' display the number of rooms on the LabelRoomsCount
                LabelRoomsCount.Text = room.getAllRooms().Rows.Count.ToString() + " Room"

            Else

                MessageBox.Show("Room Not Deleted", "Delete Room", MessageBoxButtons.OK, MessageBoxIcon.Warning)

            End If

        Catch ex As Exception

            MessageBox.Show(ex.Message)

        End Try

    End Sub

vb.net hotel management system - manage rooms form

5 - The Manage Hotel Reservations Form

This form allow the user to manage the clients room reservations.
to create a reservation you need: 1) enter the reservation id, 2) select the client who will reserve, 3) you need to select the room where the client will stay.

when you add a new reservation the system will check:
- if the user enter all required informations.
- if the user enter a date in that is equal or come after the current day date.
- if the user enter a date out that is equal or come after the date in.

- Add a New Reservation Button

Private Sub ButtonAdd_Click(sender As Object, e As EventArgs) Handles ButtonAdd.Click

        Try

            Dim clientId As Integer = Convert.ToInt32(TextBoxClientID.Text)
            Dim roomNumber As Integer = Convert.ToInt32(ComboBoxRoomNumber.SelectedValue.ToString())
            Dim dateIn As Date = DateTimePickerIN.Value
            Dim dateOut As Date = DateTimePickerOUT.Value

            If DateTime.Compare(dateIn.Date, DateTime.Now.Date) < 0 Then

                MessageBox.Show("The Date In Must be = Or > to Today Date", "Invalid Date IN", MessageBoxButtons.OK, MessageBoxIcon.Error)

            ElseIf DateTime.Compare(dateOut.Date, dateIn.Date) < 0 Then

                MessageBox.Show("The Date Out Must be = Or > to The Date In", "Invalid Date OUT", MessageBoxButtons.OK, MessageBoxIcon.Error)

            Else

                If reservation.addReservation(roomNumber, clientId, dateIn, dateOut) Then

                    MessageBox.Show("Reservation Added Successfully", "Add Reservation", MessageBoxButtons.OK, MessageBoxIcon.Information)
                    DataGridView1.DataSource = reservation.getAllReservations()
                    ' we need to refresh the combobox to show only the not reserved rooms
                    ComboBoxType.DataSource = room.getAllRoomsType()

                Else

                    MessageBox.Show("Reservation NOT Added", "Add Reservation", MessageBoxButtons.OK, MessageBoxIcon.Error)

                End If

            End If

            
        Catch ex As Exception

            MessageBox.Show(ex.Message, "Add Reservation Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try
        
    End Sub

- Edit The Selected Reservation Button

     Private Sub ButtonEdit_Click(sender As Object, e As EventArgs) Handles ButtonEdit.Click

        Try

            Dim reservationId As Integer = Convert.ToInt32(TextBoxReservationID.Text)
            Dim clientId As Integer = Convert.ToInt32(TextBoxClientID.Text)
            Dim roomNumber As Integer = Convert.ToInt32(DataGridView1.CurrentRow.Cells(2).Value.ToString())
            Dim dateIn As Date = DateTimePickerIN.Value
            Dim dateOut As Date = DateTimePickerOUT.Value

            If DateTime.Compare(dateIn.Date, DateTime.Now.Date) < 0 Then

                MessageBox.Show("The Date In Must be = Or > to Today Date", "Invalid Date IN", MessageBoxButtons.OK, MessageBoxIcon.Error)

            ElseIf DateTime.Compare(dateOut.Date, dateIn.Date) < 0 Then

                MessageBox.Show("The Date Out Must be = Or > to The Date In", "Invalid Date OUT", MessageBoxButtons.OK, MessageBoxIcon.Error)

            Else

                If reservation.editReservation(reservationId, roomNumber, clientId, dateIn, dateOut) Then

                    MessageBox.Show("Reservation Updated Successfully", "Edit Reservation", MessageBoxButtons.OK, MessageBoxIcon.Information)
                    DataGridView1.DataSource = reservation.getAllReservations()

                Else

                    MessageBox.Show("Reservation NOT Updated", "Edit Reservation", MessageBoxButtons.OK, MessageBoxIcon.Error)

                End If

            End If

        Catch ex As Exception

            MessageBox.Show(ex.Message, "Edit Reservation Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try
        
    End Sub

- Remove The Selected Reservation Button

  Private Sub ButtonRemove_Click(sender As Object, e As EventArgs) Handles ButtonRemove.Click

        Try

            Dim reservationId As Integer = Convert.ToInt32(TextBoxReservationID.Text)
            Dim roomNumber As Integer = Convert.ToInt32(DataGridView1.CurrentRow.Cells(2).Value.ToString())

            If reservation.removeReservation(reservationId, roomNumber) Then

                MessageBox.Show("Reservation Deleted Successfully", "Remove Reservation", MessageBoxButtons.OK, MessageBoxIcon.Information)
                DataGridView1.DataSource = reservation.getAllReservations()

            Else

                MessageBox.Show("Reservation NOT Deleted", "Remove Reservation", MessageBoxButtons.OK, MessageBoxIcon.Error)

            End If

        Catch ex As Exception

            MessageBox.Show(ex.Message, "Remove Reservation Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try

    End Sub



vb.net hotel management system - manage reservations form