Compare commits
No commits in common. "787bf561e4df5272497dc352556a01fa6f10817b" and "a710f363937648f2bf5396a6f304a48baf8a5f6c" have entirely different histories.
787bf561e4
...
a710f36393
@ -6,167 +6,35 @@ class AdminMenu:
|
|||||||
def __init__(self, root):
|
def __init__(self, root):
|
||||||
self.root = root
|
self.root = root
|
||||||
self.frame = tk.Frame(root)
|
self.frame = tk.Frame(root)
|
||||||
self.frame.pack(fill="both", expand=True)
|
self.frame.pack()
|
||||||
|
|
||||||
# =====================
|
|
||||||
# JUDUL
|
|
||||||
# =====================
|
|
||||||
tk.Label(
|
tk.Label(
|
||||||
self.frame,
|
self.frame,
|
||||||
text="ADMIN - KELOLA MENU",
|
text="ADMIN - KELOLA MENU",
|
||||||
font=("Arial", 18, "bold")
|
font=("Arial", 18, "bold")
|
||||||
).pack(pady=15)
|
).pack(pady=10)
|
||||||
|
|
||||||
# =====================
|
self.nama = tk.Entry(self.frame)
|
||||||
# FORM INPUT (RAPI)
|
self.harga = tk.Entry(self.frame)
|
||||||
# =====================
|
self.gambar = tk.Entry(self.frame)
|
||||||
form = tk.Frame(self.frame)
|
|
||||||
form.pack(pady=10)
|
|
||||||
|
|
||||||
tk.Label(form, text="Nama Menu", width=15, anchor="w")\
|
for label, entry in [
|
||||||
.grid(row=0, column=0, pady=5)
|
("Nama Menu", self.nama),
|
||||||
self.nama = tk.Entry(form, width=30)
|
("Harga", self.harga),
|
||||||
self.nama.grid(row=0, column=1)
|
("Path Gambar", self.gambar)
|
||||||
|
]:
|
||||||
|
tk.Label(self.frame, text=label).pack()
|
||||||
|
entry.pack()
|
||||||
|
|
||||||
tk.Label(form, text="Harga", width=15, anchor="w")\
|
tk.Button(self.frame, text="Tambah Menu", command=self.tambah).pack(pady=5)
|
||||||
.grid(row=1, column=0, pady=5)
|
|
||||||
self.harga = tk.Entry(form, width=30)
|
|
||||||
self.harga.grid(row=1, column=1)
|
|
||||||
|
|
||||||
tk.Label(form, text="Path Gambar", width=15, anchor="w")\
|
|
||||||
.grid(row=2, column=0, pady=5)
|
|
||||||
self.gambar = tk.Entry(form, width=30)
|
|
||||||
self.gambar.grid(row=2, column=1)
|
|
||||||
|
|
||||||
# =====================
|
|
||||||
# BUTTON CRUD
|
|
||||||
# =====================
|
|
||||||
btn_frame = tk.Frame(self.frame)
|
|
||||||
btn_frame.pack(pady=10)
|
|
||||||
|
|
||||||
tk.Button(btn_frame, text="Tambah", bg="#d1e7dd",
|
|
||||||
width=10, command=self.tambah).grid(row=0, column=0, padx=5)
|
|
||||||
|
|
||||||
tk.Button(btn_frame, text="Update", bg="#cfe2ff",
|
|
||||||
width=10, command=self.update).grid(row=0, column=1, padx=5)
|
|
||||||
|
|
||||||
tk.Button(btn_frame, text="Hapus", bg="#f8d7da",
|
|
||||||
width=10, command=self.hapus).grid(row=0, column=2, padx=5)
|
|
||||||
|
|
||||||
tk.Button(btn_frame, text="Refresh",
|
|
||||||
width=10, command=self.load_menu).grid(row=0, column=3, padx=5)
|
|
||||||
|
|
||||||
tk.Button(btn_frame, text="Logout",
|
|
||||||
width=10, command=self.logout).grid(row=0, column=4, padx=5)
|
|
||||||
|
|
||||||
# =====================
|
|
||||||
# LIST MENU
|
|
||||||
# =====================
|
|
||||||
tk.Label(self.frame, text="Daftar Menu", font=("Arial", 12, "bold"))\
|
|
||||||
.pack(pady=5)
|
|
||||||
|
|
||||||
self.listbox = tk.Listbox(self.frame, width=60, height=10)
|
|
||||||
self.listbox.pack(pady=5)
|
|
||||||
self.listbox.bind("<<ListboxSelect>>", self.pilih_menu)
|
|
||||||
|
|
||||||
self.menu_data = []
|
|
||||||
self.load_menu()
|
|
||||||
|
|
||||||
# =====================
|
|
||||||
# DATABASE FUNCTION
|
|
||||||
# =====================
|
|
||||||
def load_menu(self):
|
|
||||||
self.listbox.delete(0, tk.END)
|
|
||||||
db = connect()
|
|
||||||
cur = db.cursor()
|
|
||||||
cur.execute("SELECT * FROM menu")
|
|
||||||
self.menu_data = cur.fetchall()
|
|
||||||
db.close()
|
|
||||||
|
|
||||||
for menu in self.menu_data:
|
|
||||||
self.listbox.insert(
|
|
||||||
tk.END,
|
|
||||||
f"{menu[0]} | {menu[1]} | Rp {menu[2]:,.0f}"
|
|
||||||
)
|
|
||||||
|
|
||||||
def pilih_menu(self, event):
|
|
||||||
idx = self.listbox.curselection()
|
|
||||||
if not idx:
|
|
||||||
return
|
|
||||||
|
|
||||||
menu = self.menu_data[idx[0]]
|
|
||||||
|
|
||||||
self.clear_form()
|
|
||||||
self.nama.insert(0, menu[1])
|
|
||||||
self.harga.insert(0, menu[2])
|
|
||||||
self.gambar.insert(0, menu[3])
|
|
||||||
|
|
||||||
# =====================
|
|
||||||
# CRUD
|
|
||||||
# =====================
|
|
||||||
def tambah(self):
|
def tambah(self):
|
||||||
if not self.nama.get() or not self.harga.get():
|
|
||||||
messagebox.showwarning("Error", "Nama dan Harga wajib diisi")
|
|
||||||
return
|
|
||||||
|
|
||||||
db = connect()
|
db = connect()
|
||||||
cur = db.cursor()
|
cur = db.cursor()
|
||||||
cur.execute(
|
cur.execute(
|
||||||
"INSERT INTO menu(nama,harga,gambar) VALUES (?,?,?)",
|
"INSERT INTO menu(nama,harga,gambar) VALUES (?,?,?)",
|
||||||
(self.nama.get(), float(self.harga.get()), self.gambar.get())
|
(self.nama.get(), self.harga.get(), self.gambar.get())
|
||||||
)
|
)
|
||||||
db.commit()
|
db.commit()
|
||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
messagebox.showinfo("Sukses", "Menu berhasil ditambahkan")
|
messagebox.showinfo("Sukses", "Menu berhasil ditambahkan")
|
||||||
self.load_menu()
|
|
||||||
self.clear_form()
|
|
||||||
|
|
||||||
def update(self):
|
|
||||||
idx = self.listbox.curselection()
|
|
||||||
if not idx:
|
|
||||||
messagebox.showwarning("Pilih", "Pilih menu yang ingin diupdate")
|
|
||||||
return
|
|
||||||
|
|
||||||
menu_id = self.menu_data[idx[0]][0]
|
|
||||||
|
|
||||||
db = connect()
|
|
||||||
cur = db.cursor()
|
|
||||||
cur.execute(
|
|
||||||
"UPDATE menu SET nama=?, harga=?, gambar=? WHERE id=?",
|
|
||||||
(self.nama.get(), float(self.harga.get()), self.gambar.get(), menu_id)
|
|
||||||
)
|
|
||||||
db.commit()
|
|
||||||
db.close()
|
|
||||||
|
|
||||||
messagebox.showinfo("Sukses", "Menu berhasil diupdate")
|
|
||||||
self.load_menu()
|
|
||||||
|
|
||||||
def hapus(self):
|
|
||||||
idx = self.listbox.curselection()
|
|
||||||
if not idx:
|
|
||||||
messagebox.showwarning("Pilih", "Pilih menu yang ingin dihapus")
|
|
||||||
return
|
|
||||||
|
|
||||||
menu_id = self.menu_data[idx[0]][0]
|
|
||||||
|
|
||||||
if messagebox.askyesno("Konfirmasi", "Yakin hapus menu ini?"):
|
|
||||||
db = connect()
|
|
||||||
cur = db.cursor()
|
|
||||||
cur.execute("DELETE FROM menu WHERE id=?", (menu_id,))
|
|
||||||
db.commit()
|
|
||||||
db.close()
|
|
||||||
|
|
||||||
messagebox.showinfo("Sukses", "Menu berhasil dihapus")
|
|
||||||
self.load_menu()
|
|
||||||
self.clear_form()
|
|
||||||
|
|
||||||
def clear_form(self):
|
|
||||||
self.nama.delete(0, tk.END)
|
|
||||||
self.harga.delete(0, tk.END)
|
|
||||||
self.gambar.delete(0, tk.END)
|
|
||||||
|
|
||||||
def logout(self):
|
|
||||||
self.frame.destroy()
|
|
||||||
from main import LoginScreen
|
|
||||||
LoginScreen(self.root)
|
|
||||||
|
|||||||
@ -27,12 +27,6 @@ def setup_database():
|
|||||||
)
|
)
|
||||||
""")
|
""")
|
||||||
|
|
||||||
# Tambah kolom kategori (aman)
|
|
||||||
try:
|
|
||||||
cur.execute("ALTER TABLE menu ADD COLUMN kategori TEXT")
|
|
||||||
except sqlite3.OperationalError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# Tabel Transaksi
|
# Tabel Transaksi
|
||||||
cur.execute("""
|
cur.execute("""
|
||||||
CREATE TABLE IF NOT EXISTS transaksi(
|
CREATE TABLE IF NOT EXISTS transaksi(
|
||||||
@ -66,27 +60,21 @@ def setup_database():
|
|||||||
("waiter","waiter","waiter"),
|
("waiter","waiter","waiter"),
|
||||||
("pemilik","pemilik","pemilik")
|
("pemilik","pemilik","pemilik")
|
||||||
]
|
]
|
||||||
cur.executemany(
|
cur.executemany("INSERT INTO users(username,password,role) VALUES (?,?,?)", users)
|
||||||
"INSERT INTO users(username,password,role) VALUES (?,?,?)",
|
|
||||||
users
|
|
||||||
)
|
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
# Insert Menu Default
|
# --- UPDATE DAFTAR MENU SESUAI FOLDER ASET ---
|
||||||
cur.execute("SELECT COUNT(*) FROM menu")
|
cur.execute("SELECT COUNT(*) FROM menu")
|
||||||
if cur.fetchone()[0] == 0:
|
if cur.fetchone()[0] == 0:
|
||||||
menus = [
|
menus = [
|
||||||
('Ayam Goreng', 'Makanan', 20000, 'aset/ayam_goreng.jpg'),
|
('Ayam Goreng', 20000, 'aset/ayam_goreng.jpg'),
|
||||||
('Bakso', 'Makanan', 15000, 'aset/bakso.jpg'),
|
('Bakso', 15000, 'aset/bakso.jpg'),
|
||||||
('Mie Ayam', 'Makanan', 12000, 'aset/mie_ayam.jpg'),
|
('Es Teh', 5000, 'aset/es_teh.jpg'),
|
||||||
('Es Teh', 'Minuman', 5000, 'aset/es_teh.jpg'),
|
('Es Teler', 15000, 'aset/es_teler.jpg'),
|
||||||
('Es Teler', 'Minuman', 15000, 'aset/es_teler.jpg'),
|
('Jus Jeruk', 8000, 'aset/jus_jeruk.jpg'),
|
||||||
('Jus Jeruk', 'Minuman', 8000, 'aset/jus_jeruk.jpg')
|
('Mie Ayam', 12000, 'aset/mie_ayam.jpg')
|
||||||
]
|
]
|
||||||
cur.executemany(
|
cur.executemany("INSERT INTO menu (nama, harga, gambar) VALUES (?,?,?)", menus)
|
||||||
"INSERT INTO menu (nama, kategori, harga, gambar) VALUES (?,?,?,?)",
|
|
||||||
menus
|
|
||||||
)
|
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
db.close()
|
db.close()
|
||||||
Loading…
x
Reference in New Issue
Block a user