Cafe Management System Code

Splash Page Code

Public Class Form1
Private Sub imgClose_Click(sender As Object, e As EventArgs) Handles imgClose.Click
Application.Exit()
End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    ProgressBar1.Increment(1)
    If ProgressBar1.Value = 100 Then
        Me.Hide()
        Dim log = New Login
        log.Show()
        Timer1.Enabled = False
    End If
End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Timer1.Start()
End Sub

End Class

Login Page Code

Public Class Login
Private Sub imgClose_Click(sender As Object, e As EventArgs) Handles imgClose.Click
Application.Exit()
End Sub

Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
    If txtUsername.Text = "" Or txtPassword.Text = "" Then
        MsgBox("Enter Username and Password")
    ElseIf txtUsername.Text = "Admin" And txtPassword.Text = "Password" Then
        Dim Obj = New Items
        Obj.Show()
        Me.Hide()
    Else
        MsgBox("You have entered wrong Username or Password")
        txtUsername.Text = ""
        txtPassword.Text = ""
    End If
End Sub

Private Sub btnSeller_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles btnSeller.LinkClicked
    Dim Obj = New Order
    Obj.Show()
    Me.Hide()
End Sub

End Class

Items Page Code

Imports System.Data.SqlClient
Public Class Items
Dim Con = New SqlConnection(“Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Full Projects\UI Cafe Management System\UI Cafe Management System\UIDB.mdf;Integrated Security=True”)
Private Sub imgClose_Click(sender As Object, e As EventArgs) Handles imgClose.Click
Application.Exit()
End Sub

Private Sub btnSeller_Click(sender As Object, e As EventArgs) Handles btnSeller.Click
    Dim Obj = New Order
    Obj.Show()
    Me.Hide()
End Sub

Private Sub btnLogout_Click(sender As Object, e As EventArgs) Handles btnLogout.Click
    Dim Obj = New Login
    Obj.Show()
    Me.Hide()
End Sub

Private Sub imgLogout_Click(sender As Object, e As EventArgs) Handles imgLogout.Click
    Dim Obj = New Login
    Obj.Show()
    Me.Hide()
End Sub

Private Sub imgSeller_Click(sender As Object, e As EventArgs) Handles imgSeller.Click
    Dim Obj = New Order
    Obj.Show()
    Me.Hide()
End Sub
Private Sub Reset()
    txtItemname.Text = ""
    CbCategory.SelectedIndex = 0
    txtItemPrice.Text = ""
    txtItemQnty.Text = ""
End Sub
Private Sub FillCategory()
    Con.Open()
    Dim cmd = New SqlCommand("select * from CategoryTbl", Con)
    Dim adapter = New SqlDataAdapter(cmd)
    Dim Tbl = New DataTable()
    adapter.Fill(Tbl)
    CbCategory.DataSource = Tbl
    CbCategory.DisplayMember = "CategoryName"
    CbCategory.ValueMember = "CategoryName"
    Con.Close()
End Sub
Private Sub btnAddCategory_Click(sender As Object, e As EventArgs) Handles btnAddCategory.Click
    If txtCategory.Text = "" Then
        MsgBox("Enter Category Name")
    Else
        Con.Open()
        Dim query = "insert into CategoryTbl values('" & txtCategory.Text & "')"
        Dim cmd As SqlCommand
        cmd = New SqlCommand(query, Con)
        cmd.ExecuteNonQuery()
        MsgBox("Category Added")
        Con.Close()
        txtCategory.Text = ""
        FillCategory()
    End If
End Sub
Private Sub DisplayItems()
    Con.Open()
    Dim query = "select * from ItemsTbl"
    Dim cmd = New SqlCommand(query, Con)
    Dim adapter = New SqlDataAdapter(cmd)
    Dim builder = New SqlCommandBuilder(adapter)
    builder = New SqlCommandBuilder(adapter)
    Dim ds = New DataSet()
    adapter.Fill(ds)
    DGVItems.DataSource = ds.Tables(0)
    Con.Close()
End Sub
Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
    If txtItemname.Text = "" Or CbCategory.SelectedIndex = -1 Or txtItemPrice.Text = "" Or txtItemQnty.Text = "" Then
        MsgBox("Missing Information!")
    Else
        Con.Open()
        Dim query = "insert into ItemsTbl values('" & txtItemname.Text & "','" & CbCategory.SelectedValue.ToString() & "','" & txtItemPrice.Text & "'," & txtItemQnty.Text & ")"
        Dim cmd As SqlCommand
        cmd = New SqlCommand(query, Con)
        cmd.ExecuteNonQuery()
        MsgBox("Item Added")
        Con.Close()
        Reset()
        DisplayItems()
    End If
End Sub

Private Sub btnUpdate_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click
    If txtItemname.Text = "" Or CbCategory.SelectedIndex = -1 Or txtItemPrice.Text = "" Or txtItemQnty.Text = "" Then
        MsgBox("Missing Information!")
    Else
        Try
            Con.Open()
            Dim query = "update ItemsTbl set ItemName='" & txtItemname.Text & "',ItemCategory='" & CbCategory.SelectedValue.ToString() & "',ItemPrice=" & txtItemPrice.Text & ", ItemQnty=" & txtItemQnty.Text & " where ItemId=" & Key & ""
            Dim cmd As SqlCommand
            cmd = New SqlCommand(query, Con)
            cmd.ExecuteNonQuery()
            MsgBox("Item Updated")
            Con.Close()
            Reset()
            DisplayItems()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End If
End Sub

Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click
    If Key = 0 Then
        MsgBox("Select Details to Delete!")
    Else
        Con.Open()
        Dim query = "delete from ItemsTbl where ItemId=" & Key & ""
        Dim cmd As SqlCommand
        cmd = New SqlCommand(query, Con)
        cmd.ExecuteNonQuery()
        MsgBox("Item Deleted")
        Con.Close()
        Reset()
        DisplayItems()
    End If
End Sub

Private Sub btnReset_Click(sender As Object, e As EventArgs) Handles btnReset.Click
    Reset()
End Sub
Dim Key = 0
Private Sub DGVItems_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DGVItems.CellContentClick
    Dim row As DataGridViewRow = DGVItems.Rows(e.RowIndex)
    txtItemname.Text = row.Cells(1).Value.ToString
    CbCategory.SelectedValue = row.Cells(2).Value.ToString
    txtItemPrice.Text = row.Cells(3).Value.ToString
    txtItemQnty.Text = row.Cells(4).Value.ToString
    If txtItemname.Text = "" Then
        Key = 0
    Else
        Key = Convert.ToInt32(row.Cells(0).Value.ToString)
    End If
End Sub

Private Sub Items_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    FillCategory()
    DisplayItems()
End Sub

End Class

Billing Page Code

Imports System.Data.SqlClient
Public Class Order
Dim Con = New SqlConnection(“Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Full Projects\UI Cafe Management System\UI Cafe Management System\UIDB.mdf;Integrated Security=True”)
Private Sub imgClose_Click(sender As Object, e As EventArgs) Handles imgClose.Click
Application.Exit()
End Sub

Private Sub btnItems_Click(sender As Object, e As EventArgs) Handles btnItems.Click
    Dim Obj = New Login
    Obj.Show()
    Me.Hide()
End Sub

Private Sub imgItem_Click(sender As Object, e As EventArgs) Handles imgItem.Click
    Dim Obj = New Login
    Obj.Show()
    Me.Hide()
End Sub

Private Sub btnLogout_Click(sender As Object, e As EventArgs) Handles btnLogout.Click
    Dim Obj = New Login
    Obj.Show()
    Me.Hide()
End Sub

Private Sub imgLogout_Click(sender As Object, e As EventArgs) Handles imgLogout.Click
    Dim Obj = New Login
    Obj.Show()
    Me.Hide()
End Sub

Private Sub Label9_Click(sender As Object, e As EventArgs) Handles Label9.Click
    Dim Obj = New View_Orders
    Obj.Show()
    Me.Hide()
End Sub
Private Sub DisplayItems()
    Con.Open()
    Dim query = "select * from ItemsTbl"
    Dim cmd = New SqlCommand(query, Con)
    Dim adapter = New SqlDataAdapter(cmd)
    Dim builder = New SqlCommandBuilder(adapter)
    builder = New SqlCommandBuilder(adapter)
    Dim ds = New DataSet()
    adapter.Fill(ds)
    DGVItems.DataSource = ds.Tables(0)
    Con.Close()
End Sub
Private Sub btnRefresh_Click(sender As Object, e As EventArgs) Handles btnRefresh.Click
    DisplayItems()
End Sub
Private Sub FilterByCategory()
    Con.Open()
    Dim query = "select * from ItemsTbl where ItemCategory='" & CbCategory.SelectedValue.ToString() & "'"
    Dim cmd = New SqlCommand(query, Con)
    Dim adapter = New SqlDataAdapter(cmd)
    Dim builder = New SqlCommandBuilder(adapter)
    builder = New SqlCommandBuilder(adapter)
    Dim ds = New DataSet()
    adapter.Fill(ds)
    DGVItems.DataSource = ds.Tables(0)
    Con.Close()
End Sub
Private Sub FillCategory()
    Con.Open()
    Dim cmd = New SqlCommand("select * from CategoryTbl", Con)
    Dim adapter = New SqlDataAdapter(cmd)
    Dim Tbl = New DataTable()
    adapter.Fill(Tbl)
    CbCategory.DataSource = Tbl
    CbCategory.DisplayMember = "CategoryName"
    CbCategory.ValueMember = "CategoryName"
    Con.Close()
End Sub
Private Sub CbCategory_SelectionChangeCommitted(sender As Object, e As EventArgs) Handles CbCategory.SelectionChangeCommitted
    FilterByCategory()
End Sub

Private Sub Order_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    FillCategory()
    DisplayItems()
End Sub
Dim ProdName As String
Dim i = 0, GrandTotal = 0, Price, Qnty
Private Sub UpdateItem()
    Try
        Dim NewQnty = Stock - Convert.ToInt32(txtItemQnty.Text)
        Con.Open()
        Dim query = "update ItemsTbl set ItemQnty=" & NewQnty & " where ItemId=" & Key & ""
        Dim cmd As SqlCommand
        cmd = New SqlCommand(query, Con)
        cmd.ExecuteNonQuery()
        MsgBox("Item Updated")
        Con.Close()
        DisplayItems()
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
End Sub
Private Sub btnAddtoBill_Click(sender As Object, e As EventArgs) Handles btnAddtoBill.Click
    If Key = 0 Then
        MsgBox("Select an Item")
    ElseIf Convert.ToInt32(txtItemQnty.Text) > Stock Then
        MsgBox("No Enough Stock")
    Else
        Dim rnum As Integer = DGVBills.Rows.Add()
        Dim total = Convert.ToInt32(txtItemQnty.Text) * Price
        i = i + 1
        DGVBills.Rows.Item(rnum).Cells("Column1").Value = i
        DGVBills.Rows.Item(rnum).Cells("Column2").Value = ProdName
        DGVBills.Rows.Item(rnum).Cells("Column3").Value = Price
        DGVBills.Rows.Item(rnum).Cells("Column4").Value = txtItemQnty.Text
        DGVBills.Rows.Item(rnum).Cells("Column5").Value = total
        GrandTotal = GrandTotal + total
        LblTotal.Text = "Rs " + Convert.ToString(GrandTotal)
        UpdateItem()
        txtItemQnty.Text = ""
        Key = 0
    End If
End Sub
Dim Key = 0, Stock
Private Sub DGVItems_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DGVItems.CellContentClick
    Dim row As DataGridViewRow = DGVItems.Rows(e.RowIndex)
    ProdName = row.Cells(1).Value.ToString
    If ProdName = "" Then
        Key = 0
        Stock = 0
    Else
        Key = Convert.ToInt32(row.Cells(0).Value.ToString)
        Stock = Convert.ToInt32(row.Cells(4).Value.ToString)
        Price = Convert.ToInt32(row.Cells(3).Value.ToString)
    End If
End Sub

Private Sub PrintDocument_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument.PrintPage
    e.Graphics.DrawString("Cafe Shop", New Font("Arial", 22), Brushes.BlueViolet, 335, 35)
    e.Graphics.DrawString("***YourBill***", New Font("Arial", 14), Brushes.BlueViolet, 350, 60)
    Dim bm As New Bitmap(Me.DGVBills.Width, Me.DGVBills.Height)
    DGVBills.DrawToBitmap(bm, New Rectangle(0, 0, Me.DGVBills.Width, Me.DGVBills.Height))
    e.Graphics.DrawImage(bm, 0, 90)
    e.Graphics.DrawString("Total Amount " + GrandTotal.ToString(), New Font("Arial", 15), Brushes.Crimson, 325, 580)
    e.Graphics.DrawString("************** Thanks for Buying in Our Cafe ****************", New Font("Arial", 15), Brushes.Crimson, 130, 600)
End Sub

Private Sub AddBill()
    Con.Open()
    Dim query = "insert into OrdersTbl values('" & DateTime.Today.Date & "'," & GrandTotal & ")"
    Dim cmd As SqlCommand
    cmd = New SqlCommand(query, Con)
    cmd.ExecuteNonQuery()
    MsgBox("Bill Added")
    Con.Close()
End Sub
Private Sub Label6_Click(sender As Object, e As EventArgs) Handles Label6.Click
    AddBill()
    PrintPreviewDialog.Show()
End Sub

End Class

View Orders

Imports System.Data.SqlClient
Public Class View_Orders
Dim Con = New SqlConnection(“Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Full Projects\UI Cafe Management System\UI Cafe Management System\UIDB.mdf;Integrated Security=True”)
Private Sub imgLogout_Click(sender As Object, e As EventArgs) Handles imgLogout.Click
Dim Obj = New Login
Obj.Show()
Me.Hide()
End Sub

Private Sub btnLogout_Click(sender As Object, e As EventArgs) Handles btnLogout.Click
    Dim Obj = New Login
    Obj.Show()
    Me.Hide()
End Sub

Private Sub btnItems_Click(sender As Object, e As EventArgs) Handles btnItems.Click
    Dim Obj = New Login
    Obj.Show()
    Me.Hide()
End Sub

Private Sub imgItem_Click(sender As Object, e As EventArgs) Handles imgItem.Click
    Dim Obj = New Login
    Obj.Show()
    Me.Hide()
End Sub

Private Sub btnBack_Click(sender As Object, e As EventArgs) Handles btnBack.Click
    Dim Obj = New Order
    Obj.Show()
    Me.Hide()
End Sub

Private Sub imgClose_Click(sender As Object, e As EventArgs) Handles imgClose.Click
    Application.Exit()
End Sub
Private Sub DisplayBills()
    Con.Open()
    Dim query = "select * from OrdersTbl"
    Dim cmd = New SqlCommand(query, Con)
    Dim adapter = New SqlDataAdapter(cmd)
    Dim builder = New SqlCommandBuilder(adapter)
    builder = New SqlCommandBuilder(adapter)
    Dim ds = New DataSet()
    adapter.Fill(ds)
    DGVOrderList.DataSource = ds.Tables(0)
    Con.Close()
End Sub

Private Sub View_Orders_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    DisplayBills()
End Sub

End Class

Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Cart