Program On DBMS MYSQL
Program On DBMS MYSQL
Program On DBMS MYSQL
Host: localhost
User: root
Pass: root
DataBase: fashion
Product Table:
Purchase Table:
Stock Table;
Sales Table:
Python Code:
import os
import platform
import mysql.connector
import pandas as pd
import datetime
mydb=mysql.connector.connect(host="localhost",\
user="root",\
passwd="root",\
database="fashion")
mycursor=mydb.cursor()
def AddProduct():
L=[]
stk=[]
L.append(IName)
L.append(brnd)
L.append(fr)
L.append(sn)
L.append(rate)
product=(L)
mycursor.execute(sql,product)
mydb.commit()
stk.append(pid)
stk.append(0)
stk.append("No")
st=(stk)
mycursor.execute(sql,st)
mydb.commit()
def EditProduct():
ed=(pid,)
mycursor.execute(sql,ed)
res=mycursor.fetchall()
for x in res:
print(x)
print("")
sql="Update product set " + fld +"='" + val + "' where product_id='" + pid + "'"
sq=sql
mycursor.execute(sql)
ed=(pid,)
mycursor.execute(sql,ed)
res=mycursor.fetchall()
for x in res:
print(x)
mydb.commit()
def DelProduct():
id=(pid,)
mycursor.execute(sql,id)
mydb.commit()
mycursor.execute(sql,id)
mydb.commit()
mycursor.execute(sql,id)
mydb.commit()
mycursor.execute(sql,id)
mydb.commit()
def ViewProduct():
x=0
if ch==1:
mycursor.execute(sql)
res=mycursor.fetchall()
for x in res:
print(x)
x=1
elif ch==2:
var='PName'
elif ch==3:
var='brand'
elif ch==4:
var='Product_for'
elif ch==5:
var='season'
elif ch==6:
var='product_id'
if x==0:
sq=sql
tp=(val,)
mycursor.execute(sq,tp)
res=mycursor.fetchall()
for x in res:
print(x)
def PurchaseProduct():
mn=""
dy=""
now=datetime.datetime.now()
purchaseID="P"+str(now.year)+str(now.month)+str(now.day)+str(now.hour)+str(now.minute)
+str(now.second)
L=[]
Lst=[]
L.append(purchaseID)
L.append(itemId)
L.append(itemNo)
pid=(itemId,)
mycursor.execute(sql,pid)
res=mycursor.fetchone()
for x in res:
print("rate is : ", x)
amount=x*itemNo
L.append(amount)
mnth=now.month
if mnth<=9:
mn="0"+str(mnth)
else:
mn=str(mnth)
day=now.day
if day<=9:
dy="0"+str(day)
else:
dy=str(day)
dt=str(now.year)+"-"+mn+"-"+dy
L.append(dt)
tp=(L)
mycursor.execute(sql,tp)
mydb.commit()
mycursor.execute(sql,pid)
res=mycursor.fetchall()
status="No"
for x in res:
print(x)
instock=x[0]+itemNo
if instock>0:
status="Yes"
Lst.append(instock)
Lst.append(status)
Lst.append(itemId)
tp=(Lst)
mycursor.execute(sql,tp)
mydb.commit()
sql="select product.product_id,
product.PName,product.brand,purchase.no_of_items,purchase.purchase_date,purchase.amount from
product
itm=(item,)
mycursor.execute(sql,itm)
res=mycursor.fetchall()
for x in res:
print(x)
def ViewStock():
sql="select product.product_id,product.PName,stock.Instock,\
itm=(item,)
mycursor.execute(sql,itm)
res=mycursor.fetchall()
for x in res:
print(x)
def SaleProduct():
now=datetime.datetime.now()
saleID="S"+str(now.year)+str(now.month)+str(now.day)+str(now.hour)+str(now.minute)
+str(now.second)
L=[]
L.append(saleID)
L.append(itemId)
L.append(itemNo)
pid=(itemId,)
mycursor.execute(sql,pid)
res=mycursor.fetchall()
for x in res:
saleRate=x[0]-(x[0]*dis/100)
L.append(saleRate)
amount=itemNo*saleRate
L.append(amount)
mnth=now.month
if mnth<=9:
mn="0"+str(mnth)
else:
mn=str(mnth)
day=now.day
if day<=9:
dy="0"+str(day)
else:
dy=str(day)
dt=str(now.year)+"-"+mn+"-"+dy
L.append(dt)
tp=(L)
sale_rate,amount,date_of_sale) values(%s,%s,%s,%s,%s,%s)"
mycursor.execute(sql,tp)
mydb.commit()
mycursor.execute(sql,pid)
res=mycursor.fetchall()
for x in res:
instock=x[0]-itemNo
if instock>0:
status="Yes"
tp=(instock,status,itemId)
mycursor.execute(sql,tp)
mydb.commit()
def ViewSales():
sales.no_of_item_sold,sales.date_of_sale,sales.amount \
from sales, product where product.product_id=sales.item_id \
and product.PName=%s"
itm=(item,)
mycursor.execute(sql,itm)
res=mycursor.fetchall()
for x in res:
print(x)
userInput = int(input("Please Select An Above Option: ")) #Will Take Input From User
except ValueError:
else:
if(userInput == 1):
AddProduct()
elif(userInput == 2):
EditProduct()
elif (userInput==3):
DelProduct()
elif (userInput==4):
ViewProduct()
elif (userInput==5):
PurchaseProduct()
elif (userInput==6):
ViewPurchase()
elif (userInput==7):
ViewStock()
elif (userInput==8):
SaleProduct()
elif (userInput==9):
ViewSales()
else:
print("*"*80)
print("* * * * Developed by: Neha Tyagi, PGT CS, KV no. 5 Jaipur : * * * * ")
print("*"*80)
print("")
MenuSet()
def runAgain():
while(runAgn.lower() == 'y'):
if(platform.system() == "Windows"):
print(os.system('cls'))
else:
print(os.system('clear'))
MenuSet()
runAgain()