-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmindash.py
More file actions
104 lines (82 loc) · 4.39 KB
/
admindash.py
File metadata and controls
104 lines (82 loc) · 4.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import tkinter as tk
from tkinter import filedialog, messagebox
import pymysql
# Database connection setup
def connect_to_db():
return pymysql.connect(
host='localhost',
user='root',
password='admin@123', # Replace with your MySQL password
database='admin' # Replace with your database name
)
# Admin Dashboard UI
def open_admin_dashboard():
def add_document():
add_window = tk.Toplevel(window_dashboard)
add_window.title("Add Document")
add_window.geometry("400x300")
add_window.configure(bg="#E1F5FE") # Light cyan background for Add Document window
# Title and description fields
tk.Label(add_window, text="Document Title:", font=("Helvetica", 12, "bold"), bg="#E1F5FE").pack(pady=5)
title_entry = tk.Entry(add_window, width=30, font=("Helvetica", 12))
title_entry.pack(pady=5)
tk.Label(add_window, text="Description:", font=("Helvetica", 12, "bold"), bg="#E1F5FE").pack(pady=5)
desc_entry = tk.Entry(add_window, width=30, font=("Helvetica", 12))
desc_entry.pack(pady=5)
# Upload file function
def upload_file():
file_path = filedialog.askopenfilename(title="Select a Document")
if file_path:
with open(file_path, 'rb') as file:
file_content = file.read()
title = title_entry.get()
desc = desc_entry.get()
if not title or not desc:
messagebox.showerror("Error", "All fields are required!")
return
conn = connect_to_db()
cursor = conn.cursor()
query = "INSERT INTO docs (title, description, content) VALUES (%s, %s, %s)"
cursor.execute(query, (title, desc, file_content))
conn.commit()
conn.close()
messagebox.showinfo("Success", "Document added successfully!")
add_window.destroy()
tk.Button(add_window, text="Upload and Save Document", font=("Helvetica", 12, "bold"), bg="#4CAF50", fg="white", relief="raised", command=upload_file).pack(pady=10)
def delete_document():
delete_window = tk.Toplevel(window_dashboard)
delete_window.title("Delete Document")
delete_window.geometry("300x200")
delete_window.configure(bg="#FFEBEE") # Light red-pink background for Delete Document window
# Document ID input field
tk.Label(delete_window, text="Document ID:", font=("Helvetica", 12, "bold"), bg="#FFEBEE").pack(pady=5)
doc_id_entry = tk.Entry(delete_window, font=("Helvetica", 12))
doc_id_entry.pack(pady=5)
# Confirm deletion function
def confirm_delete():
doc_id = doc_id_entry.get()
if not doc_id:
messagebox.showerror("Error", "Document ID is required!")
return
conn = connect_to_db()
cursor = conn.cursor()
query = "DELETE FROM docs WHERE id = %s"
cursor.execute(query, (doc_id,))
conn.commit()
conn.close()
messagebox.showinfo("Success", "Document deleted successfully!")
delete_window.destroy()
tk.Button(delete_window, text="Delete", font=("Helvetica", 12, "bold"), bg="#F44336", fg="white", relief="raised", command=confirm_delete).pack(pady=10)
# Main admin dashboard window
window_dashboard = tk.Tk()
window_dashboard.title("Admin Dashboard")
window_dashboard.geometry("500x400") # Adjusted size for a more spacious layout
window_dashboard.configure(bg="#FFCDD2") # Light pink background for the main window
# Admin Dashboard header
tk.Label(window_dashboard, text="Admin Dashboard", font=("Helvetica", 24, "bold"), fg="white", bg="#FFCDD2").pack(pady=20)
# Buttons for Add and Delete Document
tk.Button(window_dashboard, text="Add Document", width=20, font=("Helvetica", 14, "bold"), bg="#4CAF50", fg="white", relief="raised", command=add_document).pack(pady=10)
tk.Button(window_dashboard, text="Delete Document", width=20, font=("Helvetica", 14, "bold"), bg="#F44336", fg="white", relief="raised", command=delete_document).pack(pady=10)
window_dashboard.mainloop()
# Call the function to open the admin dashboard
#open_admin_dashboard()