A Project Report cs
A Project Report cs
On
HARDWARE STORE
MANAGEMENT SYSTEM
…………………………… ……………………………
Signature of teacher guide Signature of teacher guide
Index
1 Acknowledgement 4
2 Introduction 5-7
3 Setup Descriptions 8
5 Python Code
6 Output Screens
7 Bibliography
Acknowledgement
Jaikrit Sethi
Introduction
Software Specifications:
S.N Name of Component Specifications
O
1. Operation System Windows XP or
above Windows 8
2. IDE IDLE Python
3. Database MYSQL Server
4. Browser Chrome, Opera etc
5. Front End Python
6. Back End MYSQL
Setup Description
Main Menu
Owner Customer
ADD ITEM
SELECT ITEM
UPDATE ITEM
SELECT
QUANTITY
DELETE ITEM
TOTAL PRICE
CHECK SALES
WITH THE BILL
PRINTED
CHECK PROFIT
Modules Imported
1. Mysql Connector
A MySQL Connector is a software
component that enables interaction
between a MySQL database and python
allowing data exchange and manipulation.
2. Tkinter Import
Tkinter is python’s built in GUI (Graphical
User Interface) library. It is used import all
functions and built in modules in the
tkinter library.
3. Messagebox Module
This module is used to display message
boxes in the python application.
4. Partial function from the functools
modules
This module allows us to create new
functions by partially applying arguments
to an existing function.
FUNCTIONS USED IN CODE
5.
Python Source Code
###########################################################################
# Imports for the app
###########################################################################
import mysql.connector as pm
from tkinter import *
import tkinter as TK
from tkinter import messagebox
from functools import partial
###########################################################################
# Initializing TKINTER for UI
###########################################################################
root=Tk()
root.title("Main Menu")
root.geometry("600x300")
topFrame = Frame(root)
topFrame.grid(row=0, column=0)
botFrame = Frame(root)
botFrame.grid(row=0, column=1)
billFrame = Frame(root)
billFrame.grid(row=1, column=0)
prodLabel = Label(root,
text=" Welcome to Hardware Store ",
bg="lightblue",
font=("Arial", 16, "bold"),
fg="maroon",
padx=15,
pady=15,
relief=TK.RAISED
)
prodLabel.place(x=100,y=100)
###########################################################################
# Initializing database connection
###########################################################################
mydb = pm.connect(host="localhost", user="root", password="firstdb")
cur = mydb.cursor()
cur.execute("use project")
###########################################################################
# Global variables
###########################################################################
currItemSNo = StringVar()
currItemName = StringVar()
currItemQty = StringVar()
currItemPrice = StringVar()
currItemReadState = False
currItemReport = StringVar()
buyTr = 0
buyitemno = StringVar()
buyitemqty = StringVar()
buyitemtotalprice = StringVar()
makepurchaseprice = 0
validItemNo = [0,1]
###########################################################################
# Function to clear the widgets in BotFrame
###########################################################################
def ClearBotFrame():
global botFrame
for widget in botFrame.winfo_children():
widget.destroy()
botFrame.destroy()
botFrame = Frame(root)
botFrame.grid(row=0, column=1)
###########################################################################
# Function to clear the widgets in TopFrame
###########################################################################
def ClearTopFrame():
global topFrame
prodLabel.destroy()
for widget in topFrame.winfo_children():
widget.destroy()
topFrame.destroy()
topFrame = Frame(root)
topFrame.grid(row=0, column=0)
###########################################################################
# Function to clear the widgets in BillFrame
###########################################################################
def ClearBillFrame():
global billFrame
for widget in billFrame.winfo_children():
widget.destroy()
billFrame.destroy();
billFrame = Frame(root)
billFrame.grid(row=1, column=0)
###########################################################################
# Function to clear the values in global item state
###########################################################################
def ClearCurrItemInfo():
currItemSNo = ""
currItemName = ""
currItemQty = ""
currItemPrice = ""
currItemReadState = False
###########################################################################
# Function to set the values in global item state
###########################################################################
def SetCurrItemInfo(si1, si2, si3, si4):
currItemSNo.set(si1)
currItemName.set(si2)
currItemQty.set(si3)
currItemPrice.set(si4)
currItemReadState = True
PrintCurrItemInfo("SetCurrItemInfo")
###########################################################################
# Function to print the global item state - for debugging
###########################################################################
def PrintCurrItemInfo(sm):
msg = "From {0} - CurrItemInfo values('{1}','{2}',{3},{4})".format(sm, currItemSNo.get(),
currItemName.get(), currItemQty.get(), currItemPrice.get())
messagebox.showinfo("CurrItemInfo", msg)
###########################################################################
# Function to save a new item in database
###########################################################################
def GuiNewItemSave():
#PrintCurrItemInfo("NEW ITEM SAVE")
sno = currItemSNo.get()
if(sno.isdigit() != True):
messagebox.showerror("Get Item Detail Error", "Item No should be a numeric value")
return
try:
cur.execute(query)
mydb.commit()
except (pm.Error, pm.Warning) as e:
messagebox.showerror("New Item Save Error", e)
return
###########################################################################
# Function to update the values of an item in database for given item no
###########################################################################
def GuiItemUpdate():
sno = currItemSNo.get()
if(sno.isdigit() != True):
messagebox.showerror("Update Item Error", "Item No should be a numeric value")
return
try:
cur.execute(query)
mydb.commit()
except (pm.Error, pm.Warning) as e:
messagebox.showerror("Update Item Error", e)
return
###########################################################################
# Function to delete an item from database for given item no
###########################################################################
def GuiItemDelete():
sno = currItemSNo.get()
if(sno.isdigit() != True):
messagebox.showerror("Delete Item Error", "Item No should be a numeric value")
return
update_query1="delete from inventory where sno=%s"
input_query1=[currItemSNo.get()]
try:
cur.execute(update_query1,input_query1)
mydb.commit()
except (pm.Error, pm.Warning) as e:
messagebox.showerror("Delete Item Error", e)
return
###########################################################################
# Function to read the item details from database for given item no
###########################################################################
def getItemDetail():
sno = currItemSNo.get()
if(sno.isdigit() != True):
messagebox.showerror("Get Item Detail Error", "Item No should be a numeric value")
return
try:
cur.execute(update_query1,input_query1)
except (pm.Error, pm.Warning) as e:
messagebox.showerror("Get Item Detail Error", e)
return
try:
result = cur.fetchone()
currItemSNo.set(result[0])
currItemName.set(result[1])
currItemQty.set(result[2])
currItemPrice.set(result[3])
except TypeError as e:
messagebox.showerror("Fetch Item Detail Error", e)
return
###########################################################################
# Function to get sales (total quantity) for a given item no
###########################################################################
def getItemSalesDetail():
currItemReport.set("")
cir = " "
sno = currItemSNo.get()
if(sno.isdigit() != True):
messagebox.showerror("Get Item Detail Error", "Item No should be a numeric value")
return
s=0
p=0
try:
cur.execute(query)
except (pm.Error, pm.Warning) as e:
messagebox.showerror("Get Item Sales Error", e)
return
try:
result = cur.fetchall()
for rec in result:
s = s + rec[1]
except TypeError as e:
messagebox.showerror("Fetch Item Detail Error", e)
return
currItemReport.set(cir)
###########################################################################
# Function to get total profit from the sale of a given item no
###########################################################################
def getItemProfitDetail():
currItemReport.set("")
cir = " "
sno = currItemSNo.get()
if(sno.isdigit() != True):
messagebox.showerror("Get Item Detail Error", "Item No should be a numeric value")
return
s=0
p=0
try:
cur.execute(query)
except (pm.Error, pm.Warning) as e:
messagebox.showerror("Get Item Sales Error", e)
return
try:
result = cur.fetchall()
for rec in result:
s = s + rec[1]
except TypeError as e:
messagebox.showerror("Fetch Item Detail Error", e)
return
try:
cur.execute(query)
except (pm.Error, pm.Warning) as e:
messagebox.showerror("Get Item Sales Error", e)
return
try:
result = cur.fetchone()
p = result[3]
except TypeError as e:
messagebox.showerror("Fetch Item Detail Error", e)
return
profit = p*s
cir += "Profit is Rs. {0}".format(profit)
currItemReport.set(cir)
###########################################################################
# Function to create the UI Form for Add New Item
###########################################################################
def addItem():
ClearBotFrame()
botFrame.grid()
label1 = Label(
botFrame,
text="Item No:").grid(column=0,row=0)
label2 = Label(
botFrame,
text="Item Name:").grid(column=0,row=1)
label3 = Label(
botFrame,
text="Item Price:").grid(column=0,row=2)
label4 = Label(
botFrame,
text="Item Qty:").grid(column=0,row=3)
buttonx = Button(
botFrame,
text="Save",
command=GuiNewItemSave
).grid(column=0,row=4)
###########################################################################
# Function to create the UI Form for Update Item
###########################################################################
def updateItem():
ClearCurrItemInfo()
ClearBotFrame()
botFrame.grid()
label1 = Label(
botFrame,
text="Item No:").grid(column=0,row=0)
entry1 = Entry(botFrame, textvariable=currItemSNo).grid(column=1,row=0)
buttonx = Button(
botFrame,
text="Get",
command=getItemDetail
).grid(column=2,row=0)
label2 = Label(
botFrame,
text="Item Name:").grid(column=0,row=1)
label3 = Label(
botFrame,
text="Item Price:").grid(column=0,row=2)
label4 = Label(
botFrame,
text="Item Qty:").grid(column=0,row=3)
buttony = Button(
botFrame,
text="Update",
command=GuiItemUpdate
).grid(column=0,row=4)
###########################################################################
# Function to create the UI for Delete Item
###########################################################################
def deleteItem():
ClearCurrItemInfo()
ClearBotFrame()
botFrame.grid()
label1 = Label(
botFrame,
text="Item No:").grid(column=0,row=0)
entry1 = Entry(botFrame, textvariable=currItemSNo).grid(column=1,row=0)
buttonx = Button(
botFrame,
text="Get",
command=getItemDetail
).grid(column=2,row=0)
label2 = Label(
botFrame,
text="Item Name:").grid(column=0,row=1)
label3 = Label(
botFrame,
text="Item Price:").grid(column=0,row=2)
label4 = Label(
botFrame,
text="Item Qty:").grid(column=0,row=3)
buttony = Button(
botFrame,
text="Delete",
command=GuiItemDelete
).grid(column=0,row=4)
###########################################################################
# Function to create the UI Buttons to let user Add/Update/Delete items
###########################################################################
def checkInventory():
ClearTopFrame()
ClearBotFrame()
ClearBillFrame()
###########################################################################
# Function to create UI form to get Item no. for sales details
###########################################################################
def checkFinanceSales():
ClearCurrItemInfo()
ClearBotFrame()
botFrame.grid()
label1 = Label(
botFrame,
text="Item No:").grid(column=0,row=0)
entry1 = Entry(botFrame, textvariable=currItemSNo).grid(column=1,row=0)
buttonx = Button(
botFrame,
text="Show Sales",
command=getItemSalesDetail
).grid(column=2,row=0)
entry2 = Entry(botFrame, textvariable=currItemReport,
state='readonly').grid(column=1,row=1)
###########################################################################
# Function to create UI form to get Item no. for profit calculations
###########################################################################
def checkFinanceProfit():
ClearCurrItemInfo()
ClearBotFrame()
botFrame.grid()
label1 = Label(
botFrame,
text="Item No:").grid(column=0,row=0)
entry1 = Entry(botFrame, textvariable=currItemSNo).grid(column=1,row=0)
buttonx = Button(
botFrame,
text="Show Profit",
command=getItemProfitDetail
).grid(column=2,row=0)
entry2 = Entry(botFrame, textvariable=currItemReport,
state='readonly').grid(column=1,row=1)
###########################################################################
# Function to show UI Buttons to let user check Sales/Profit for items
###########################################################################
def checkFinance():
ClearTopFrame()
ClearBotFrame()
ClearBillFrame()
###########################################################################
# Function to show the full inventory in tabular form
###########################################################################
def showAllItems():
global buyTr
global buyitemtotalprice
global makepurchaseprice
buyTr = 0
buyitemno.set("")
buyitemqty.set("")
validItemNo.clear()
buyitemtotalprice.set("0")
makepurchaseprice = 0
label1 = Label(
topFrame,
width=70,
text="All Items",
bg='lightblue').grid(column=0,row=buyTr, columnspan=4)
buyTr+=1
try:
cur.execute(query)
except (pm.Error, pm.Warning) as e:
messagebox.showerror("Get Item Sales Error", e)
return
try:
cur.execute("drop table bill")
except (pm.Error, pm.Warning) as e:
pass
try:
result = cur.fetchall()
total_rows = len(result)
total_cols = len(result[0])
e1 = Entry(topFrame, width=20, fg='blue')
e1.grid(row=buyTr, column=0)
e1.insert(END, "S.No.")
e1.config(state='readonly')
e2 = Entry(topFrame, width=20, fg='blue')
e2.grid(row=buyTr, column=1)
e2.insert(END, "Name")
e2.config(state='readonly')
e3 = Entry(topFrame, width=20, fg='blue')
e3.grid(row=buyTr, column=2)
e3.insert(END, "Qty")
e3.config(state='readonly')
e4 = Entry(topFrame, width=20, fg='blue')
e4.grid(row=buyTr, column=3)
e4.insert(END, "Price")
e4.config(state='readonly')
for i in range(total_rows):
buyTr += 1
for j in range(total_cols):
e = Entry(topFrame, width=20)
e.grid(row=buyTr, column=j)
e.insert(END, str(result[i][j]))
e.config(state='readonly')
validItemNo.append(str(result[i][0]))
except TypeError as e:
messagebox.showerror("Fetch Item Detail Error", e)
return
try:
cur.execute("create table if not exists bill(sno varchar(5), number int(11))")
cur.execute("create table if not exists billhistory(sno varchar(5), number int(11))")
except (pm.Error, pm.Warning) as e:
messagebox.showerror("Get Item Sales Error", e)
return
buyTr += 1
l1 = Label(
topFrame,
text="Items No:").grid(column=0,row=buyTr)
ebuyno = Entry(topFrame, width = 20, textvariable=buyitemno)
ebuyno.grid(column=1, row=buyTr)
buyTr += 1
l2 = Label(
topFrame,
text="Qty").grid(column=0,row=buyTr)
ebuyqty = Entry(topFrame, width = 20, textvariable=buyitemqty)
ebuyqty.grid(column=1, row=buyTr)
buyTr+=1
bb = Button(topFrame, text="Add To Bill", command=addItemToBill,
activebackground='lightblue').grid(column=1, row=buyTr)
buyTr = 0
l4 = Label(
billFrame,
fg='blue',
text="Total Price (Rs.):").grid(column=0,row=buyTr)
ebuytotalprice = Entry(billFrame, width = 20,
fg='blue', textvariable=buyitemtotalprice)
ebuytotalprice.grid(column=1, row=buyTr)
ebuytotalprice.config(state='readonly')
bf = Button(billFrame,
text="Make Purchase",
command=makeFinalPurchase,
activebackground='lightblue').grid(column=2, row=buyTr)
buyTr += 1
l3 = Label(
billFrame,
width=52, bg='lightblue',
text="Your Bill").grid(column=0, row=buyTr, columnspan=3)
buyTr+=1
e5 = Entry(billFrame, width=20, fg='blue')
e5.grid(row=buyTr, column=0)
e5.insert(END, "S.No.")
e5.config(state='readonly')
e6 = Entry(billFrame, width=20, fg='blue')
e6.grid(row=buyTr, column=1)
e6.insert(END, "Qty")
e6.config(state='readonly')
###########################################################################
# Function to create UI to add a given item into a Bill table
###########################################################################
def addItemToBill():
global buyTr
global makepurchaseprice
global buyitemtotalprice
sno = buyitemno.get()
nbr = buyitemqty.get()
try:
query3 = "select * from inventory where sno={0}".format(sno)
cur.execute(query3)
rec = cur.fetchone()
recsno = rec[0]
recname = rec[1]
recqty = rec[2]
recprice = rec[3]
except (pm.Error, pm.Warning) as e:
messagebox.showerror("Get Item Sales Error", e)
return
try:
query1 = "insert into bill values('{0}',{1})".format(sno,nbr)
query2= "insert into billhistory values('{0}',{1})".format(sno,nbr)
cur.execute(query1)
cur.execute(query2)
mydb.commit()
except (pm.Error, pm.Warning) as e:
messagebox.showerror("Get Item Sales Error", e)
return
pp = int(recprice) * int(nbr)
makepurchaseprice += pp
buyitemtotalprice.set(str(makepurchaseprice))
buyTr+=1
e7 = Entry(billFrame, width=20)
e7.grid(row=buyTr, column=0)
e7.insert(END, sno)
e7.config(state='readonly')
e8 = Entry(billFrame, width=20)
e8.grid(row=buyTr, column=1)
e8.insert(END, nbr)
e8.config(state='readonly')
e9 = Entry(billFrame, width=20)
e9.grid(row=buyTr, column=2)
e9.insert(END, pp)
e9.config(state='readonly')
buyitemno.set("")
buyitemqty.set("")
###########################################################################
# Function to make the final purchase for items added to the Bill
###########################################################################
def makeFinalPurchase():
try:
cur.execute("create table if not exists invoice(sno varchar(5), name varchar(20), number
int(11), price int(11), cost int(11))")
cur.execute("select * from bill")
record1 = cur.fetchall()
for i in record1 :
a = i[0]
b = i[1]
for j in record2 :
a1 = j[0]
a2 = j[1]
a3 = j[2]
a4 = j[3]
a5 = b * a4
if a == a1 :
query = "insert into invoice values('{0}','{1}',{2},{3},{4})".format(a1,a2,b,a4,a5)
cur.execute(query)
mydb.commit()
###########################################################################
# Function as entry show inventory and create buill for final purchase
###########################################################################
def purchaseItems():
ClearTopFrame()
ClearBotFrame()
ClearBillFrame()
topFrame.grid(row=0,column=0, sticky="ew", padx="5", pady="5")
billFrame.grid(row=1,column=0, sticky="ew", padx="5", pady="5")
showAllItems()
###########################################################################
# Function to exit the App
###########################################################################
def remove():
frm = Frame(root)
frm.grid()
###########################################################################
# Main app continues
# Add meu options to the window
###########################################################################
menubar=Menu(root)
editmenu1=Menu(root)
editmenu2=Menu(root)
filemenu= Menu(menubar,tearoff=0)
editmenu1= Menu(menubar,tearoff=0)
editmenu2= Menu(menubar,tearoff=0)
filemenu.add_separator()
filemenu.add_command(label="Exit",command=root.destroy)
menubar.add_cascade(label="File",menu=filemenu)
editmenu1.add_separator()
editmenu1.add_command(label="Inventory", command=checkInventory)
editmenu1.add_command(label="Finance", command=checkFinance)
menubar.add_cascade(label="Owner", menu=editmenu1)
editmenu2.add_separator()
editmenu2.add_command(label="Purchase", command=purchaseItems)
menubar.add_cascade(label="Customer",menu=editmenu2)
###########################################################################
# Run app message loop
###########################################################################
root.config(menu=menubar)
root.mainloop()
Output Screens
Opening Screen
Accessing Drop down menu under
Owner tab
Add items to inventory
Update items in inventory
Wikipedia