Merge branch 'main' of https://git-eng.ukwms.ac.id/5803025001/Python-Menu
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,7 @@
|
||||
import tkinter as tk
|
||||
|
||||
class AdminDashboard(tk.Frame):
|
||||
def __init__(self, parent, controller):
|
||||
super().__init__(parent)
|
||||
tk.Label(self, text="ADMIN DASHBOARD", font=("Arial", 20, "bold")).pack(pady=20)
|
||||
tk.Button(self, text="Logout", command=lambda: controller.show_frame("Login")).pack()
|
||||
@@ -0,0 +1,44 @@
|
||||
import sqlite3
|
||||
|
||||
def connect():
|
||||
return sqlite3.connect("cafe.db")
|
||||
|
||||
def setup_database():
|
||||
db = connect()
|
||||
cur = db.cursor()
|
||||
|
||||
# Table users
|
||||
cur.execute("""
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
username TEXT,
|
||||
password TEXT,
|
||||
role TEXT
|
||||
)
|
||||
""")
|
||||
|
||||
# Table menu (buat nanti)
|
||||
cur.execute("""
|
||||
CREATE TABLE IF NOT EXISTS menu (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
nama TEXT,
|
||||
kategori TEXT,
|
||||
harga REAL,
|
||||
stok INTEGER
|
||||
)
|
||||
""")
|
||||
|
||||
# Tambah user default
|
||||
cur.execute("SELECT COUNT(*) FROM users")
|
||||
if cur.fetchone()[0] == 0:
|
||||
users = [
|
||||
("admin", "admin", "admin"),
|
||||
("kasir", "kasir", "kasir"),
|
||||
("waiter", "waiter", "waiter"),
|
||||
("pembeli", "pembeli", "pembeli"),
|
||||
("pemilik", "pemilik", "pemilik cafe")
|
||||
]
|
||||
cur.executemany("INSERT INTO users(username,password,role) VALUES (?,?,?)", users)
|
||||
db.commit()
|
||||
|
||||
db.close()
|
||||
@@ -0,0 +1,7 @@
|
||||
import tkinter as tk
|
||||
|
||||
class KasirDashboard(tk.Frame):
|
||||
def __init__(self, parent, controller):
|
||||
super().__init__(parent)
|
||||
tk.Label(self, text="KASIR DASHBOARD", font=("Arial", 20, "bold")).pack(pady=20)
|
||||
tk.Button(self, text="Logout", command=lambda: controller.show_frame("Login")).pack()
|
||||
@@ -0,0 +1,94 @@
|
||||
import tkinter as tk
|
||||
from tkinter import messagebox
|
||||
from database import setup_database, connect
|
||||
|
||||
from admin_dashboard import AdminDashboard
|
||||
from kasir_dashboard import KasirDashboard
|
||||
from waiter_dashboard import WaiterDashboard
|
||||
from pembeli_menu import PembeliMenu
|
||||
from pemilik_dashboard import PemilikDashboard
|
||||
|
||||
|
||||
class App(tk.Tk):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.title("Sistem Cafe")
|
||||
self.geometry("500x400")
|
||||
|
||||
self.container = tk.Frame(self)
|
||||
self.container.pack(fill="both", expand=True)
|
||||
|
||||
self.frames = {}
|
||||
|
||||
# Register screens
|
||||
for name, FrameClass in {
|
||||
"Login": LoginScreen,
|
||||
"Admin": AdminDashboard,
|
||||
"Kasir": KasirDashboard,
|
||||
"Waiter": WaiterDashboard,
|
||||
"Pembeli": PembeliMenu,
|
||||
"Pemilik": PemilikDashboard
|
||||
}.items():
|
||||
frame = FrameClass(self.container, self)
|
||||
self.frames[name] = frame
|
||||
frame.grid(row=0, column=0, sticky="nsew")
|
||||
|
||||
self.show_frame("Login")
|
||||
|
||||
def show_frame(self, name):
|
||||
frame = self.frames[name]
|
||||
frame.tkraise()
|
||||
|
||||
|
||||
class LoginScreen(tk.Frame):
|
||||
def __init__(self, parent, controller):
|
||||
super().__init__(parent)
|
||||
self.controller = controller
|
||||
|
||||
tk.Label(self, text="LOGIN SISTEM CAFE", font=("Arial", 20, "bold")).pack(pady=20)
|
||||
|
||||
tk.Label(self, text="Username").pack()
|
||||
self.username_entry = tk.Entry(self, width=30)
|
||||
self.username_entry.pack()
|
||||
|
||||
tk.Label(self, text="Password").pack()
|
||||
self.password_entry = tk.Entry(self, width=30, show="*")
|
||||
self.password_entry.pack()
|
||||
|
||||
tk.Button(self, text="Login", width=20, command=self.login).pack(pady=15)
|
||||
|
||||
def login(self):
|
||||
username = self.username_entry.get()
|
||||
password = self.password_entry.get()
|
||||
|
||||
db = connect()
|
||||
cur = db.cursor()
|
||||
|
||||
cur.execute("SELECT role FROM users WHERE username=? AND password=?", (username, password))
|
||||
result = cur.fetchone()
|
||||
|
||||
if result:
|
||||
role = result[0]
|
||||
|
||||
if role == "admin":
|
||||
self.controller.show_frame("Admin")
|
||||
elif role == "kasir":
|
||||
self.controller.show_frame("Kasir")
|
||||
elif role == "waiter":
|
||||
self.controller.show_frame("Waiter")
|
||||
elif role == "pembeli":
|
||||
self.controller.show_frame("Pembeli")
|
||||
elif role == "pemilik cafe":
|
||||
self.controller.show_frame("Pemilik")
|
||||
|
||||
else:
|
||||
messagebox.showerror("Error", "Username atau password salah")
|
||||
|
||||
db.close()
|
||||
|
||||
|
||||
# RUN PROGRAM
|
||||
if __name__ == "__main__":
|
||||
setup_database()
|
||||
app = App()
|
||||
app.mainloop()
|
||||
@@ -0,0 +1,7 @@
|
||||
import tkinter as tk
|
||||
|
||||
class PembeliMenu(tk.Frame):
|
||||
def __init__(self, parent, controller):
|
||||
super().__init__(parent)
|
||||
tk.Label(self, text="MENU PEMBELI", font=("Arial", 20, "bold")).pack(pady=20)
|
||||
tk.Button(self, text="Logout", command=lambda: controller.show_frame("Login")).pack()
|
||||
@@ -0,0 +1,7 @@
|
||||
import tkinter as tk
|
||||
|
||||
class PemilikDashboard(tk.Frame):
|
||||
def __init__(self, parent, controller):
|
||||
super().__init__(parent)
|
||||
tk.Label(self, text="PEMILIK CAFE DASHBOARD", font=("Arial", 20, "bold")).pack(pady=20)
|
||||
tk.Button(self, text="Logout", command=lambda: controller.show_frame("Login")).pack()
|
||||
@@ -0,0 +1,8 @@
|
||||
project/
|
||||
│ main.py
|
||||
│ database.py
|
||||
│ admin_dashboard.py
|
||||
│ kasir_dashboard.py
|
||||
│ waiter_dashboard.py
|
||||
│ pembeli_menu.py
|
||||
│ pemilik_dashboard.py
|
||||
@@ -0,0 +1,7 @@
|
||||
import tkinter as tk
|
||||
|
||||
class WaiterDashboard(tk.Frame):
|
||||
def __init__(self, parent, controller):
|
||||
super().__init__(parent)
|
||||
tk.Label(self, text="WAITER DASHBOARD", font=("Arial", 20, "bold")).pack(pady=20)
|
||||
tk.Button(self, text="Logout", command=lambda: controller.show_frame("Login")).pack()
|
||||
Reference in New Issue
Block a user