0% found this document useful (0 votes)
17 views7 pages

text of code cs project

Uploaded by

dhonipavithran84
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views7 pages

text of code cs project

Uploaded by

dhonipavithran84
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 7

import mysql.

connector
from mysql.connector import Error

def connect_db():
try:
connection = mysql.connector.connect(
host="localhost",
user="root",
password="rootadmin@123",
database="dharshin"
)
return connection
except Error as e:
print(f"Error: {e}")
exit(1)

def setup_database(connection):
try:
cursor = connection.cursor()
cursor.execute("SHOW TABLES")
tables = [table[0] for table in cursor.fetchall()]

if 'Dish' not in tables:


cursor.execute("CREATE TABLE Dish (Dish VARCHAR(20), cost INTEGER,
DishID VARCHAR(20))")
if 'Orders' not in tables:
cursor.execute("CREATE TABLE Orders (DishIDs VARCHAR(150), cost
DECIMAL(9,2), Date VARCHAR(120), customer VARCHAR(50), phno VARCHAR(30))")
if 'Employees' not in tables:
cursor.execute("CREATE TABLE Employees (Name VARCHAR(200), phno
VARCHAR(30), Salary INTEGER, DOJ VARCHAR(30))")
if 'Salary' not in tables:
cursor.execute("CREATE TABLE Salary (Name VARCHAR(100), phno
VARCHAR(20), bank VARCHAR(30), Month VARCHAR(20), salary INTEGER, Days INTEGER, Net
INTEGER)")
if 'Expenditure' not in tables:
cursor.execute("CREATE TABLE Expenditure (Type VARCHAR(100), Cost
INTEGER, Date VARCHAR(30))")

connection.commit()
except Error as e:
print(f"Error: {e}")
connection.rollback()

def signin():
print("\n **********HOTEL-CBE********** \n")
p = input("System Password: ")
if p == "rootadmin@123":
option()
else:
print("Incorrect Password")
signin()

def option():
print("""
1. DISHES
2. EMPLOYEES
3. SALARY
4. ORDERS
5. INCOME
6. BILLS
""")
choice = input("Select Option: ")
options = {
'1': Dish,
'2': Employees,
'3': PaySalary,
'4': NewOrder,
'5': NetIncome,
'6': Expenditure
}
func = options.get(choice, lambda: print("Wrong choice......"))
func()

def Dish():
while True:
choice = input("1.Add 2.Remove 3.Display 4.Main Menu: ")
if choice == '1':
dn = input("Dish Name: ")
try:
dc = int(input("Dish Cost: "))
except ValueError:
print("Invalid cost. Please enter a number.")
continue
did = str(DishID())
data = (dn, dc, did)
sql = 'INSERT INTO Dish (Dish, cost, DishID) VALUES (%s, %s, %s)'
execute_sql(sql, data)
print("Data Entered Successfully")
elif choice == '2':
did = input("Dish ID: ")
sql = 'DELETE FROM Dish WHERE DishID = %s'
execute_sql(sql, (did,))
print("Data Deleted Successfully")
elif choice == '3':
sql = "SELECT * FROM Dish"
dishes = fetch_all(sql)
for dish in dishes:
print(dish[0], "-", dish[1], "-", dish[2])
print("\n")
elif choice == '4':
option()
else:
print("Invalid choice. Please try again.")

def DishID():
sql = 'SELECT COUNT(*), MAX(DishID) FROM Dish'
result = fetch_one(sql)
if result[0] == 0:
return 1
else:
return int(result[1]) + 1

def Employees():
while True:
choice = input("1.Add 2.Remove 3.Display 4.Main Menu: ")
if choice == '1':
en = input("Employee Name: ")
ep = input("PHno: ")
try:
s = int(input("Salary: "))
except ValueError:
print("Invalid salary. Please enter a number.")
continue
doj = input("Date of Joining (D/M/Y): ")
data = (en, ep, s, doj)
sql = 'INSERT INTO Employees (Name, phno, Salary, DOJ) VALUES (%s, %s,
%s, %s)'
execute_sql(sql, data)
print("Data Entered Successfully")
elif choice == '2':
ep = input("PHno: ")
data = (ep,)
sql = 'DELETE FROM Employees WHERE phno = %s'
execute_sql(sql, data)
print("Data Deleted Successfully")
elif choice == '3':
sql = "SELECT * FROM Employees"
employees = fetch_all(sql)
for emp in employees:
print(emp[0], "-", emp[1], "-", emp[2], "-", emp[3])
print("\n")
elif choice == '4':
option()
else:
print("Invalid choice. Please try again.")

def PaySalary():
while True:
sql = "SELECT * FROM Employees"
employees = fetch_all(sql)
for emp in employees:
print(emp[0], "-", emp[1], "-", emp[2], "-", emp[3])
print("---------------------------------------------")

en = input("Employee Name: ")


ep = input("PHno: ")
ba = input("KVB Account: ")
mn = input("Date (D/M/Y): ")
try:
s = int(input("Salary: "))
d = int(input("Working days: "))
except ValueError:
print("Invalid salary or days. Please enter a number.")
continue

days_in_month = 31
if mn[3:5] in ['04', '06', '09', '11']:
days_in_month = 30
elif mn[3:5] == '02':
days_in_month = 28

ns = (s / days_in_month) * d
data = (en, ep, ba, mn, s, d, ns)
sql = 'INSERT INTO Salary (Name, phno, bank, Month, salary, Days, Net)
VALUES (%s, %s, %s, %s, %s, %s, %s)'
execute_sql(sql, data)
print("Net Salary Paid:", ns, "Rs")
print("--------------------------------------------")
xy = input("1.Salary Menu 2.Main Menu: ")
if xy == '1':
continue
elif xy == '2':
option()
else:
print("Invalid choice. Returning to main menu.")
option()

def NewOrder():
while True:

sql = "SELECT * FROM Dish"


dishes = fetch_all(sql)
print("NAME_____COST____DISHID")
for dish in dishes:
print(dish[0], "-", dish[1], "-", dish[2])
print("\n")

dil = []
while True:
di = input("Select Dish ID { 0 When Done }: ")
if di == '0':
break
else:
dil.append(di)

if not dil:
print("No dishes selected. Returning to menu.")
continue

sql = "SELECT DishID, Cost FROM Dish WHERE DishID IN (%s)" %


','.join(['%s'] * len(dil))
dish_costs = fetch_all(sql, dil)

total_cost = sum(dish[1] for dish in dish_costs)

dt = input("Date (D/M/Y): ")


cn = input("Customer Name: ")
cp = input("PHno: ")
lis = ','.join(dil)

data = (lis, total_cost, dt, cn, cp)

sql = 'INSERT INTO Orders (DishIDs, cost, Date, customer, phno) VALUES (%s,
%s, %s, %s, %s)'
execute_sql(sql, data)

print("Data Entered Successfully. Total Cost: Rs", total_cost)


print("---------------------------------------")
xy = input("1.Order Menu 2.Main Menu: ")
if xy == '1':
continue
elif xy == '2':
option()
else:
print("Invalid choice. Returning to main menu.")
option()

def NetIncome():
while True:
t = input("1.All 2.Year 3.Month 4.Date 5.Main Menu: ")
if t == '1':
sql = 'SELECT Cost FROM Orders'
total_income = sum(row[0] for row in fetch_all(sql))
print("Total Income from Orders:", total_income, "Rs")
elif t == '2':
y = input("Enter Year: ")
sql = 'SELECT Cost, Date FROM Orders'
total_income = sum(row[0] for row in fetch_all(sql) if y in row[1])
print("Total Income from Orders:", total_income, "Rs")
elif t == '3':
my = input("Enter Month/Year: ")
sql = 'SELECT Cost, Date FROM Orders'
total_income = sum(row[0] for row in fetch_all(sql) if my in row[1])
print("Total Income from Orders:", total_income, "Rs")
elif t == '4':
d = input("Enter Date: ")
sql = 'SELECT Cost FROM Orders WHERE Date LIKE %s'
total_income = sum(row[0] for row in fetch_all(sql, (d,)))
print("Total Income from Orders:", total_income, "Rs")
elif t == '5':
option()
else:
print("Invalid choice. Please try again.")

def Expenditure():
while True:
choice = input("1.BILL ENTRY 2.SHOW BILLS 3.Main Menu: ")
if choice == '1':
t = input("Type: ")
try:
c = int(input("Cost: "))
except ValueError:
print("Invalid cost. Please enter a number.")
continue
d = input("Date (D/M/Y): ")
data = (t, c, d)
sql = 'INSERT INTO Expenditure (Type, Cost, Date) VALUES (%s, %s, %s)'
execute_sql(sql, data)
print("Data Entered Successfully")
elif choice == '2':
t = input("1.All 2.Year 3.Month 4.Date: ")
if t == '1':
sql = 'SELECT * FROM Expenditure'
expenditures = fetch_all(sql)
for exp in expenditures:
print(exp)
elif t == '2':
y = input("Enter Year: ")
sql = 'SELECT * FROM Expenditure'
expenditures = fetch_all(sql)
for exp in expenditures:
if y in exp[2]:
print(exp)
elif t == '3':
my = input("Enter YEAR/MONTH: ")
sql = 'SELECT * FROM Expenditure'
expenditures = fetch_all(sql)
for exp in expenditures:
if my in exp[2]:
print(exp)
elif t == '4':
d = input("Enter Date: ")
sql = 'SELECT * FROM Expenditure'
expenditures = fetch_all(sql)
for exp in expenditures:
if d in exp[2]:
print(exp)
else:
print("Invalid choice. Returning to main menu.")
option()
elif choice == '3':
option()
else:
print("Invalid choice. Please try again.")

def execute_sql(sql, data=None):


try:
cursor = connection.cursor()
cursor.execute(sql, data)
connection.commit()
except Error as e:
print(f"Error: {e}")
connection.rollback()

def fetch_all(sql, params=None, fetch_as_dict=False):


try:
cursor = connection.cursor(dictionary=fetch_as_dict) if fetch_as_dict else
connection.cursor()
cursor.execute(sql, params)
return cursor.fetchall()
except Error as e:
print(f"Error: {e}")
return []

def fetch_one(sql, params=None):


try:
cursor = connection.cursor()
cursor.execute(sql, params)
return cursor.fetchone()
except Error as e:
print(f"Error: {e}")
return None

connection = connect_db()
setup_database(connection)

signin()

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy