C# Hotel Management System Source Code

Hotel Management System Using C# And MySQL Database With Source Code

C# Hotel Management System Source Code


in this c# project tutorial we will create a simple desktop application to manage hotel reservations using csharp 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. 
sharing knowledge with others.


tools:
- c# programming language.
- visual studio express 2013.
- mysql database.
- canva.com for images.



Watch The Full Project Tutorial




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





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 in the first place  )

The Login Button: 

the "conn" is an instance of the class "CONNECT" in this w've our connection string and two function to open and close the connection. 

private void buttonLogin_Click(object sender, EventArgs e)

        {

            CONNECT conn = new CONNECT();

            DataTable table = new DataTable();
            MySqlDataAdapter adapter = new MySqlDataAdapter();
            MySqlCommand command = new MySqlCommand();
            String query = "SELECT * FROM `users` WHERE `username`=@usn AND `password`=@pass";

            command.CommandText = query;

            command.Connection = conn.getConnection();

            command.Parameters.Add("@usn", MySqlDbType.VarChar).Value = textBoxUsername.Text;

            command.Parameters.Add("@pass", MySqlDbType.VarChar).Value = textBoxPassword.Text;

            adapter.SelectCommand = command;

            adapter.Fill(table);

            // if the username and the password exists

            if(table.Rows.Count > 0)
            {
                // show the main form
                this.Hide();
                Main_Form mform = new Main_Form();
                mform.Show();
            }
            else
            {
                if(textBoxUsername.Text.Trim().Equals(""))
                {
                    MessageBox.Show("Enter Your Username to Login", "Empty Username", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (textBoxPassword.Text.Trim().Equals(""))
                {
                    MessageBox.Show("Enter Your Password to Login", "Empty Password", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show("This Username Or Password Doesn't Exists", "Wrong Data", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

        }










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 strip to manage this system forms.

 private void Main_Form_FormClosing(object sender, FormClosingEventArgs e)

        {

            Application.Exit();

        }



        private void manageClientsToolStripMenuItem_Click(object sender, EventArgs e)

        {

            ManageClientsForm manageCF = new ManageClientsForm();

            manageCF.ShowDialog();

        }



        private void manageRoomsToolStripMenuItem_Click(object sender, EventArgs e)

        {

            ManageRoomsForm manageRF = new ManageRoomsForm();

            manageRF.ShowDialog();

        }



        private void manageReservationsToolStripMenuItem_Click(object sender, EventArgs e)

        {

            ManageReservationsForm manageRSVF = new ManageReservationsForm();

            manageRSVF.ShowDialog();

        }

    }


3 - The Manage Clients Form

this form allow the user to manage the hotel clients.
this form contains a datagridview with all clients data.
we have created a class "ClIENT" with some function to use in the form. 

private void ManageClientsForm_Load(object sender, EventArgs e)
        {
            dataGridView1.DataSource = client.getClients();

        }

this form contains also an add, edit, delete button + a clear button to remove text from all textboxes


- Add New Client Button


private void buttonAddClient_Click(object sender, EventArgs e)

        {
            String fname = textBoxFirstName.Text;
            String lname = textBoxLastName.Text;
            String phone = textBoxPhone.Text;
            String country = textBoxCountry.Text;

            if (fname.Trim().Equals("") || lname.Trim().Equals("") || phone.Trim().Equals(""))

            {
                MessageBox.Show("Required Fields - First & Last Name + Phone Number", "Empty Fields", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                Boolean insertClient = client.insertClient(fname, lname, phone, country);

                if (insertClient)

                {
                    dataGridView1.DataSource = client.getClients();
                    MessageBox.Show("New Client Inserted Successfuly", "Add Client", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("ERROR - Client Not Inserted", "Add Client", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

            }


        }

- Edit The Selected Client Button


private void buttonEditClient_Click(object sender, EventArgs e)

        {
            int id;
            String fname = textBoxFirstName.Text;
            String lname = textBoxLastName.Text;
            String phone = textBoxPhone.Text;
            String country = textBoxCountry.Text;

            try

            {
                id = Convert.ToInt32(textBoxID.Text);

                if (fname.Trim().Equals("") || lname.Trim().Equals("") || phone.Trim().Equals(""))

                {
                    MessageBox.Show("Required Fields - First & Last Name + Phone Number", "Empty Fields", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    Boolean insertClient = client.editClient(id, fname, lname, phone, country);

                    if (insertClient)

                    {
                        dataGridView1.DataSource = client.getClients();
                        MessageBox.Show("New Client Updated Successfuly", "Edit Client", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("ERROR - Client Not Updated", "Edit Client", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }

            }catch(Exception ex)

            {
                MessageBox.Show(ex.Message, "ID Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }


        }

- Delete The Selected Client Button

private void buttonRemoveClient_Click(object sender, EventArgs e)
        {
            try
            {
                int id = Convert.ToInt32(textBoxID.Text);

                if(client.removeClient(id))
                {
                    dataGridView1.DataSource = client.getClients();
                    MessageBox.Show("Client Deleted Successfuly", "Delete Client", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    // you can clear all textboxes after the delete if you want
                    // by calling the clear button
                    buttonClear.PerformClick();
                   
                }
                else
                {
                    MessageBox.Show("ERROR - Client Not Deleted", "Delete Client", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

            }catch(Exception ex)
            {
                MessageBox.Show(ex.Message, "ID Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

- Clear All TextBoxes Button

        private void buttonClear_Click(object sender, EventArgs e)
        {
            textBoxID.Text = "";
            textBoxFirstName.Text = "";
            textBoxLastName.Text = "";
            textBoxPhone.Text = "";
            textBoxCountry.Text = "";
        }



4 - The Manage 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 and add, edit, remove the selecte one + a combobx populated with all room's categories.

- Add New Room Button
when you add a new room the "free" column will be set to yes automatically.

        private void buttonAddRoom_Click(object sender, EventArgs e)
        {
            
            int type = Convert.ToInt32(comboBoxRoomType.SelectedValue.ToString());
            string phone = textBoxPhone.Text;
            string free = "";
            
            try
            {
                int number = Convert.ToInt32(textBoxNumber.Text);
                if (radioButtonYES.Checked)
                {
                    free = "Yes";
                }
                else if (radioButtonNO.Checked)
                {
                    free = "No";
                }

                if (room.addRoom(number, type, phone, free))
                {
                    dataGridView1.DataSource = room.getRooms();
                    MessageBox.Show("Room Added Successfully", "Add Room", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Room Not Added", "Add Room", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Room Number Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            
        }

- Edit The Selected Room Button

        private void buttonEditRoom_Click(object sender, EventArgs e)
        {
            
            int type = Convert.ToInt32(comboBoxRoomType.SelectedValue.ToString());
            String phone = textBoxPhone.Text;
            String free = "";

            try
            {
                int number = Convert.ToInt32(textBoxNumber.Text);
                if (radioButtonYES.Checked)
                {
                    free = "Yes";
                }
                else if (radioButtonNO.Checked)
                {
                    free = "No";
                }

                if (room.editRoom(number, type, phone, free))
                {
                    dataGridView1.DataSource = room.getRooms();
                    MessageBox.Show("Room Data Updated", "Edit Room", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Room Data NOT Updated", "Edit Room", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

            }catch(Exception ex)
            {
                MessageBox.Show(ex.Message, "Room Number Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }

- Delete The Selected Room Button

        private void buttonRemoveRoom_Click(object sender, EventArgs e)
        {
            try
            {
                int number = Convert.ToInt32(textBoxNumber.Text);

                if (room.removeRoom(number))
                {
                    dataGridView1.DataSource = room.getRooms();
                    MessageBox.Show("Room Data Deleted", "Remove Room", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Room Data NOT Deleted", "Remove Room", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Room Number Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }


5 - The Manage 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 you entered all required informations.
- if the date in is equal or after the current day.
- if the day out is equal or after the date in day.

- Add a New Reservation Button

private void buttonAddReserv_Click(object sender, EventArgs e)
        {
            try
            {
                int clientID = Convert.ToInt32(textBoxClientID.Text);
                int roomNumber = Convert.ToInt32(comboBoxRoomNumber.SelectedValue);
                DateTime dateIn = dateTimePickerIN.Value;
                DateTime dateOut = dateTimePickerOUT.Value;

                // date in must be = or > today date
                // date out must be = or > date in
                if(DateTime.Compare(dateIn.Date,DateTime.Now.Date) < 0)
                {
                    MessageBox.Show("The Date In Must Be = or > To Today Date", "Invalid Date In", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else if(DateTime.Compare(dateOut.Date, dateIn.Date) < 0)
                {
                    MessageBox.Show("The Date Out Must Be = or > To Date In", "Invalid Date Out", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    if (reservation.addReservation(roomNumber, clientID, dateIn, dateOut))
                    {
                        // set the room free column to NO
                        // you can add a message if the room is edited
                        room.setRoomFree(roomNumber,"No");
                        dataGridView1.DataSource = reservation.getAllReserv();
                        MessageBox.Show("New Reservation Added", "Add Reservation", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("Reservation NOT Added", "Add Reservation", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message, "Add Reservation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            
        }

- Edit The Selected Reservation Button

        private void buttonEditReserv_Click(object sender, EventArgs e)
        {

            try
            {
                int rservID = Convert.ToInt32(textBoxReservId.Text);
                int clientID = Convert.ToInt32(textBoxClientID.Text);
                int roomNumber = Convert.ToInt32(dataGridView1.CurrentRow.Cells[1].Value.ToString());
                DateTime dateIn = dateTimePickerIN.Value;
                DateTime dateOut = dateTimePickerOUT.Value;

                // date in must be = or > today date
                // date out must be = or > date in
                if (dateIn < DateTime.Now)
                {
                    MessageBox.Show("The Date In Must Be = or > To Today Date", "Invalid Date In", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else if (dateOut < dateIn)
                {
                    MessageBox.Show("The Date Out Must Be = or > To Date In", "Invalid Date Out", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    //rservId
                    if (reservation.editReserv(rservID,roomNumber, clientID, dateIn, dateOut))
                    {
                        // set the room free column to NO
                        // you can add a message if the room is edited
                        room.setRoomFree(roomNumber,"No");
                        dataGridView1.DataSource = reservation.getAllReserv();
                        MessageBox.Show("Reservation Data Updated", "Edit Reservation", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("Reservation NOT Added", "Add Reservation", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Add Reservation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }

- Remove The Selected Reservation Button

private void buttonRemoveReserv_Click(object sender, EventArgs e)
        {
            try
            {
                int reservId = Convert.ToInt32(textBoxReservId.Text);
                int roomNumber = Convert.ToInt32(dataGridView1.CurrentRow.Cells[1].Value.ToString());
                if(reservation.removeReserv(reservId))
                {
                    dataGridView1.DataSource = reservation.getAllReserv();
                    // after deleting a reservation we need to set free column to 'Yes'

                    room.setRoomFree(roomNumber, "Yes");
                    MessageBox.Show("Reservation Deleted", "Delete Reservation", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Delete Reservation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }



VB.Net Login And Register Form With MySQL

How to Create Login and Register Form in Visual Basic.Net with MySQL Database

Visual Basic.Net Login And Register Form With MySQL


In This VB.NET Tutorial We Will See How To Make a SignIn and a SignUp Form With Design and Connection With MySQL Database To Allow The Users To Create Their Account or To Login Into The Application Using Visual Basic.Net Windows Form and Visual Studio Editor .

What We Are Gonna Use In This Project:

- Visual Basic.Net Programming Language.
- Visual Studio Editor.
xampp server.
- MySQL Database.
- PhpMyAdmin.
- Canva.com( to create the images )

What We Will Do In This Project:

- Design Two Forms For The Login and Register Using Panels, TextBoxes, Buttons and Labels.
- Create a Custom Buttons To Close The Application .
- Create a Class For The Connection With MySQL Database.
- Connect VB.Net To MySQL Database.
- Allow The Users To Create Their Accounts On Register Form.
- Allow The Users To Access The Application On Login Form 
- Check If The User Leave Some Fields Empty.
- Check if The Username Already Exists.
- Check If The User Enter a Wrong Password In The Confirmation Field.   



WATCH THIS VB.Net TUTORIAL



Project Source Code:


' Create a Class To Connect Our Application With The MySQL Database

Imports MySql.Data.MySqlClient

Public Class MY_CONNECTION

    ' first we need to download the mysql connector & add it to our project
    ' https://dev.mysql.com/downloads/connector/net/8.0.html
    ' open xampp
    ' create the mysql database using phpmyadmin
    ' create the database and name it "vbnet_users_db"
    ' create a table and name it "users"
    ' create the connection

    Private connection As New MySqlConnection("datasource=localhost;port=3306;username=root;password=;database=vbnet_users_db")

    ' return the connection
    ReadOnly Property getConnection() As MySqlConnection
        Get
            Return connection
        End Get
    End Property

    ' open the connection
    Sub openConnection()

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

    End Sub

    ' close the connection
    Sub closeConnection()

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

    End Sub

End Class



' Create The Register Form To Allow Users To Create Their Account  

Imports MySql.Data.MySqlClient

Public Class RegisterForm

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

        ' transparent black background for panel2
        Panel2.BackColor = Color.FromArgb(120, 0, 0, 0)
        ' transparent blue background for panel3
        Panel3.BackColor = Color.FromArgb(100, 17, 97, 238)

        ButtonClose.BackColor = Color.FromArgb(100, 0, 0, 0)

    End Sub

     ' button close click
    Private Sub ButtonClose_Click(sender As Object, e As EventArgs) Handles ButtonClose.Click

        Application.Exit()

    End Sub

    ' textbox first name enter
    Private Sub TextBoxFirstname_Enter(sender As Object, e As EventArgs) Handles TextBoxFirstname.Enter

        LabelFN.ForeColor = Color.Red

    End Sub

    ' textbox first name leave
    Private Sub TextBoxFirstname_Leave(sender As Object, e As EventArgs) Handles TextBoxFirstname.Leave

        LabelFN.ForeColor = Color.White

    End Sub

    ' textbox last name enter
    Private Sub TextBoxLastname_Enter(sender As Object, e As EventArgs) Handles TextBoxLastname.Enter

        LabelLN.ForeColor = Color.Red

    End Sub

    ' textbox last name leave
    Private Sub TextBoxLastname_Leave(sender As Object, e As EventArgs) Handles TextBoxLastname.Leave

        LabelLN.ForeColor = Color.White

    End Sub

    ' textbox username enter
    Private Sub TextBoxUsername_Enter(sender As Object, e As EventArgs) Handles TextBoxUsername.Enter

        LabelUN.ForeColor = Color.Red

    End Sub

    ' textbox username leave
    Private Sub TextBoxUsername_Leave(sender As Object, e As EventArgs) Handles TextBoxUsername.Leave

        LabelUN.ForeColor = Color.White

    End Sub

    ' textbox email enter
    Private Sub TextBoxEmail_Enter(sender As Object, e As EventArgs) Handles TextBoxEmail.Enter

        LabelEM.ForeColor = Color.Red

    End Sub

    ' textbox email leave
    Private Sub TextBoxEmail_Leave(sender As Object, e As EventArgs) Handles TextBoxEmail.Leave

        LabelEM.ForeColor = Color.White

    End Sub

     ' textbox password enter
    Private Sub TextBoxPassword_Enter(sender As Object, e As EventArgs) Handles TextBoxPassword.Enter

        LabelPASS1.ForeColor = Color.Red

    End Sub

     ' textbox password leave
    Private Sub TextBoxPassword_Leave(sender As Object, e As EventArgs) Handles TextBoxPassword.Leave

        LabelPASS1.ForeColor = Color.White

    End Sub

    ' textbox confirm password enter
    Private Sub TextBoxConfirmPassword_Enter(sender As Object, e As EventArgs) Handles TextBoxConfirmPassword.Enter

        LabelPASS2.ForeColor = Color.Red

    End Sub

     ' textbox confirm password leave
    Private Sub TextBoxConfirmPassword_Leave(sender As Object, e As EventArgs) Handles TextBoxConfirmPassword.Leave

        LabelPASS2.ForeColor = Color.White

    End Sub

    ' button register click
    Private Sub ButtonRegister_Click(sender As Object, e As EventArgs) Handles ButtonRegister.Click

        ' check if the fields are empty
        ' check if the password = the confirm password
        ' check if the username already exists

        ' get textboxes values
        Dim fname As String = TextBoxFirstname.Text
        Dim lname As String = TextBoxLastname.Text
        Dim username As String = TextBoxUsername.Text
        Dim email As String = TextBoxEmail.Text
        Dim password As String = TextBoxPassword.Text
        Dim cpassword As String = TextBoxConfirmPassword.Text


        If fname.Trim() = "" Or lname.Trim() = "" Or username.Trim() = "" Or email.Trim() = "" Or password.Trim() = "" Then

            MessageBox.Show("One Or More Fields Are Empty", "Missing Data", MessageBoxButtons.OK, MessageBoxIcon.Stop)

        ElseIf Not String.Equals(password, cpassword) Then

            MessageBox.Show("Wrong Confirmation Password", "password Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

        ElseIf usernameExist(username) Then

            MessageBox.Show("This Username Already Exists, Choose Another One", "Duplicate Username", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

        Else

            ' add the new user
            Dim conn As New MY_CONNECTION()
            Dim command As New MySqlCommand("INSERT INTO `users`(`first_name`, `last_name`, `email`, `username`, `password`) VALUES (@fn, @ln, @mail, @usn, @pass)", conn.getConnection)

            command.Parameters.Add("@fn", MySqlDbType.VarChar).Value = fname
            command.Parameters.Add("@ln", MySqlDbType.VarChar).Value = lname
            command.Parameters.Add("@mail", MySqlDbType.VarChar).Value = email
            command.Parameters.Add("@usn", MySqlDbType.VarChar).Value = username
            command.Parameters.Add("@pass", MySqlDbType.VarChar).Value = password

            conn.openConnection()

            If command.ExecuteNonQuery() = 1 Then

                MessageBox.Show("Registration Completed Successfully", "User Added", MessageBoxButtons.OK, MessageBoxIcon.Information)
                conn.closeConnection()

            Else

                MessageBox.Show("Something Happen", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
                conn.closeConnection()

            End If


        End If



    End Sub


    ' create a function to check if the username already exists
    Public Function usernameExist(ByVal username As String) As Boolean

        Dim con As New MY_CONNECTION()
        Dim table As New DataTable()
        Dim adapter As New MySqlDataAdapter()
        Dim command As New MySqlCommand("SELECT * FROM `users` WHERE `username` = @usn", con.getConnection())
        command.Parameters.Add("@usn", MySqlDbType.VarChar).Value = username

        adapter.SelectCommand = command
        adapter.Fill(table)

        ' if the username exist return true
        If table.Rows.Count > 0 Then

            Return True

            ' if not return false  
        Else

            Return False

        End If

    End Function

    ' button close mouse enter
    Private Sub ButtonClose_MouseEnter(sender As Object, e As EventArgs) Handles ButtonClose.MouseEnter

        ButtonClose.ForeColor = Color.White

    End Sub

    ' button close mouse leave
    Private Sub ButtonClose_MouseLeave(sender As Object, e As EventArgs) Handles ButtonClose.MouseLeave

        ButtonClose.ForeColor = Color.Black

    End Sub

    ' label go to signin mouse enter
    Private Sub LabelGoToSignIn_MouseEnter(sender As Object, e As EventArgs) Handles LabelGoToSignIn.MouseEnter

        LabelGoToSignIn.ForeColor = Color.White

    End Sub

    ' label go to signin mouse leave
    Private Sub LabelGoToSignIn_MouseLeave(sender As Object, e As EventArgs) Handles LabelGoToSignIn.MouseLeave

        LabelGoToSignIn.ForeColor = Color.Black

    End Sub

    ' label go to signin mouse click
    Private Sub LabelGoToSignIn_Click(sender As Object, e As EventArgs) Handles LabelGoToSignIn.Click

        Me.Hide()
        Dim lForm As New Login_Form()
        lForm.Show()

    End Sub
End Class


' Create The Login Form To Allow The User To Access The Application

Imports MySql.Data.MySqlClient

Public Class Login_Form

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

        ' transparent black background for panel2
        Panel2.BackColor = Color.FromArgb(120, 0, 0, 0)
        ' transparent blue background for panel3
        Panel3.BackColor = Color.FromArgb(100, 17, 97, 238)

        ButtonClose.BackColor = Color.FromArgb(100, 0, 0, 0)

    End Sub

    ' button close mouse enter
    Private Sub ButtonClose_MouseEnter(sender As Object, e As EventArgs) Handles ButtonClose.MouseEnter

        ButtonClose.ForeColor = Color.White

    End Sub

    ' button close mouse leave
    Private Sub ButtonClose_MouseLeave(sender As Object, e As EventArgs) Handles ButtonClose.MouseLeave

        ButtonClose.ForeColor = Color.LightGray

    End Sub

    ' button close click
    Private Sub ButtonClose_Click(sender As Object, e As EventArgs) Handles ButtonClose.Click

        Application.Exit()

    End Sub

    ' textbox username enter
    Private Sub TextBoxUsername_Enter(sender As Object, e As EventArgs) Handles TextBoxUsername.Enter

        ' clear the textbox when the textbox get the focus
        Dim username As String = TextBoxUsername.Text
        ' check if the username is empty
        ' check if the textbox contains the default value "username"
        If username.Trim().ToLower() = "username" Or username.Trim() = "" Then

            ' clear the textbox
            TextBoxUsername.Text = ""
            ' change the textbox for color
            TextBoxUsername.ForeColor = Color.Black

        End If

    End Sub

    ' textbox username leave
    Private Sub TextBoxUsername_Leave(sender As Object, e As EventArgs) Handles TextBoxUsername.Leave

        ' when the textbox get lost the focus
        Dim username As String = TextBoxUsername.Text
        ' check if the username is empty
        ' check if the textbox contains the default value "username"
        If username.Trim().ToLower() = "username" Or username.Trim() = "" Then

            ' set the textbox text
            TextBoxUsername.Text = "username"
            ' change the textbox for color
            TextBoxUsername.ForeColor = Color.DarkGray

        End If

    End Sub

    ' textbox password enter
    Private Sub TextBoxPassword_Enter(sender As Object, e As EventArgs) Handles TextBoxPassword.Enter

        ' when textbox password has focus
        Dim pass As String = TextBoxPassword.Text
        If pass.Trim().ToLower() = "password" Or pass.Trim() = "" Then

            ' clear the textbox text
            TextBoxPassword.Text = ""
            ' change the textbox font color
            TextBoxPassword.ForeColor = Color.Black
            ' use system password
            TextBoxPassword.UseSystemPasswordChar = True

        End If

    End Sub

    ' textbox password leave
    Private Sub TextBoxPassword_Leave(sender As Object, e As EventArgs) Handles TextBoxPassword.Leave

        ' when textbox password lost focus
        Dim pass As String = TextBoxPassword.Text
        If pass.Trim().ToLower() = "password" Or pass.Trim() = "" Then

            ' set the textbox text
            TextBoxPassword.Text = "password"
            ' change the textbox font color
            TextBoxPassword.ForeColor = Color.DarkGray
            ' set system password to false
            TextBoxPassword.UseSystemPasswordChar = False

        End If

    End Sub

    ' button login click
    Private Sub ButtonLogin_Click(sender As Object, e As EventArgs) Handles ButtonLogin.Click

        ' before the user can login we need to check if the textboxes are empty
        ' if they contains the default values( username & password )
        ' check if this user exist in the database

        Dim conn As New MY_CONNECTION()
        Dim adapter As New MySqlDataAdapter()
        Dim table As New DataTable()
        Dim command As New MySqlCommand("SELECT `username`, `password` FROM `users` WHERE `username` = @usn AND `password` = @pass", conn.getConnection())

        command.Parameters.Add("@usn", MySqlDbType.VarChar).Value = TextBoxUsername.Text
        command.Parameters.Add("@pass", MySqlDbType.VarChar).Value = TextBoxPassword.Text

        If TextBoxUsername.Text.Trim() = "" Or TextBoxUsername.Text.Trim().ToLower() = "username" Then

            MessageBox.Show("Enter Your Username To Login", "Missing Username", MessageBoxButtons.OK, MessageBoxIcon.Error)

        ElseIf TextBoxPassword.Text.Trim() = "" Or TextBoxPassword.Text.Trim().ToLower() = "password" Then

            MessageBox.Show("Enter Your Password To Login", "Missing Password", MessageBoxButtons.OK, MessageBoxIcon.Error)

        Else

            adapter.SelectCommand = command
            adapter.Fill(table)

            If table.Rows.Count > 0 Then

                Me.Hide()
                Dim mainAppForm As New ApplicationMainForm()
                mainAppForm.Show()

            Else

                MessageBox.Show("This Username Or/And Password Doesn't Exists", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

            End If

        End If


    End Sub

    ' label go to signup form mouse enter
    Private Sub LabelGoToSignUp_MouseEnter(sender As Object, e As EventArgs) Handles LabelGoToSignUp.MouseEnter

        LabelGoToSignUp.ForeColor = Color.White

    End Sub

  ' label go to signup form mouse leave
    Private Sub LabelGoToSignUp_MouseLeave(sender As Object, e As EventArgs) Handles LabelGoToSignUp.MouseLeave

        LabelGoToSignUp.ForeColor = Color.Black

    End Sub

    ' label go to signup form click
    Private Sub LabelGoToSignUp_Click(sender As Object, e As EventArgs) Handles LabelGoToSignUp.Click

        Me.Hide()
        Dim rForm As New RegisterForm()
        rForm.Show()

    End Sub

End Class





OUTPUT:


Sign Up Form
Register Form

Register Form
Register Form - TextBox Enter

Create Account Form
Register Form - Error

Sign In Form
Login Form

Login Form
Login Form - Error

Main Application Form
Main Application Form




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




VB.Net Students Information System Source Code
VB.Net Hotel System Source Code