text of code cs project
text of code cs project
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()]
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("---------------------------------------------")
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:
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 = 'INSERT INTO Orders (DishIDs, cost, Date, customer, phno) VALUES (%s,
%s, %s, %s, %s)'
execute_sql(sql, data)
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.")
connection = connect_db()
setup_database(connection)
signin()