Skip to content

Commit aa0a6d1

Browse files
committed
update employee page created
1 parent 1a4a919 commit aa0a6d1

File tree

1 file changed

+77
-10
lines changed

1 file changed

+77
-10
lines changed

bank_managment_system/QTFrontend.py

Lines changed: 77 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,31 @@ def on_reject():
131131
button_box.rejected.connect(on_reject)
132132

133133
dialog.exec_()
134+
def get_employee_name(parent,name_field_text="Enter Employee Name"):
135+
page, main_layout = create_page_with_header(parent, "Employee Data Update")
136+
137+
# Content frame
138+
content_frame = create_styled_frame(page)
139+
content_frame.setSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Expanding)
140+
content_layout = QtWidgets.QVBoxLayout(content_frame)
141+
# Form frame
142+
form_frame = create_styled_frame(content_frame, min_size=(340, 200), style="background-color: #ffffff; border-radius: 15px; padding: 10px;")
143+
form_layout = QtWidgets.QVBoxLayout(form_frame)
144+
# Form fields
145+
name_label, name_field = create_input_field(form_frame, name_field_text)
146+
search_button = create_styled_button(form_frame, "Search", min_size=(100, 30))
147+
form_layout.addWidget(name_label)
148+
form_layout.addWidget(search_button)
149+
150+
search_button.clicked.connect(lambda: backend.check_name_in_staff())
151+
def on_search_button_clicked():
152+
fetch = backend.check_name_in_staff()
153+
if fetch:
154+
print(f"Employee data: {fetch[0]}, {fetch[1]}, {fetch[2]}, {fetch[3]},")
155+
else:
156+
print("Employee not found.")
157+
158+
#backend.check_name_in_staff()
134159
def create_login_page(parent ,title, name_field_text="Name :", password_field_text="Password :", submit_text="Submit",):
135160
"""Create a login page with a title, name and password fields, and a submit button."""
136161
page, main_layout = create_page_with_header(parent, "Admin Menu")
@@ -267,7 +292,7 @@ def create_admin_menu_page(parent):
267292
return page, *buttons # Unpack as add_button, update_employee, etc.
268293

269294

270-
def create_add_employee_page(parent, title, submit_text="Submit"):
295+
def create_add_employee_page(parent, title, submit_text="Submit",update_btn:bool=False):
271296
page, main_layout = create_page_with_header(parent, title)
272297

273298
content_frame = create_styled_frame(page)
@@ -290,15 +315,22 @@ def create_add_employee_page(parent, title, submit_text="Submit"):
290315
# Submit button
291316
button_frame = create_styled_frame(form_frame, style="padding: 7px;")
292317
button_layout = QtWidgets.QVBoxLayout(button_frame)
318+
update_button = create_styled_button(button_frame, "Update", min_size=(150, 0))
293319
submit_button = create_styled_button(button_frame, submit_text, min_size=(150, 0))
294-
button_layout.addWidget(submit_button, 0, QtCore.Qt.AlignHCenter)
320+
if update_btn:
321+
button_layout.addWidget(update_button, 0, QtCore.Qt.AlignHCenter)
322+
else:
323+
button_layout.addWidget(submit_button, 0, QtCore.Qt.AlignHCenter)
324+
295325

296326
form_layout.addWidget(button_frame)
297327
content_layout.addWidget(form_frame, 0, QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter)
298328
main_layout.addWidget(content_frame)
299-
300-
return page, *edits, submit_button # Unpack as name_edit, password_edit, etc.
301-
329+
if update_btn:
330+
return page, *edits, update_button
331+
else:
332+
return page, *edits, submit_button # Unpack as name_edit, password_edit, etc.
333+
302334
def setup_main_window(main_window):
303335
"""Set up the main window with a stacked widget containing home, admin, and employee pages."""
304336
main_window.setObjectName("MainWindow")
@@ -341,6 +373,31 @@ def add_employee_form_submit(name, password, salary, position):
341373
else:
342374
print("Please fill in all fields")
343375
show_popup_message(stacked_widget,"Please fill in all fields",3)
376+
def update_employee_data(name, password, salary, position, name_to_update):
377+
try:
378+
cur = backend.cur
379+
if name_to_update:
380+
cur.execute("UPDATE staff SET Name = ? WHERE name = ?", (name, name_to_update))
381+
382+
cur.execute("UPDATE staff SET Name = ? WHERE name = ?", (password, name))
383+
cur.execute("UPDATE staff SET password = ? WHERE name = ?", (password, name))
384+
cur.execute("UPDATE staff SET salary = ? WHERE name = ?", (salary, name))
385+
cur.execute("UPDATE staff SET position = ? WHERE name = ?", (position, name))
386+
backend.conn.commit()
387+
show_popup_message(stacked_widget,"Employee Upadate successfully",3,False)
388+
389+
except:
390+
show_popup_message(stacked_widget,"Please fill in all fields",3)
391+
392+
def fetch_employee_data(name):
393+
try:
394+
cur = backend.cur
395+
cur.execute("SELECT * FROM staff WHERE name = ?", (name,))
396+
employee_data = cur.fetchone()
397+
return employee_data
398+
except:
399+
print("Error fetching employee data")
400+
return None
344401

345402

346403
# Create Home Page
@@ -375,13 +432,22 @@ def add_employee_form_submit(name, password, salary, position):
375432
)
376433

377434
add_button.clicked.connect(lambda: stacked_widget.setCurrentIndex(4))
435+
update_button.clicked.connect(lambda: stacked_widget.setCurrentIndex(5))
378436

379437
# Create Add Employee Page
380438
add_employee_page, emp_name, emp_password, emp_salary, emp_position, emp_submit = create_add_employee_page(
381439
stacked_widget,
382440
title="Add Employee"
383441
)
442+
443+
# Update Employee Page
444+
update_employee_page1 = get_employee_name(stacked_widget)
445+
# apply the update_employee_data function to the submit button
446+
447+
448+
384449

450+
# ///////////////////////////
385451
emp_submit.clicked.connect(
386452
lambda: add_employee_form_submit(
387453
emp_name.text(),
@@ -399,11 +465,12 @@ def add_employee_form_submit(name, password, salary, position):
399465

400466

401467
# Add pages to stacked widget
402-
stacked_widget.addWidget(home_page)#1
403-
stacked_widget.addWidget(admin_page)#2
404-
stacked_widget.addWidget(employee_page)#3
405-
stacked_widget.addWidget(admin_menu_page)#4
406-
stacked_widget.addWidget(add_employee_page)#5
468+
stacked_widget.addWidget(home_page)#0
469+
stacked_widget.addWidget(admin_page)#1
470+
stacked_widget.addWidget(employee_page)#2
471+
stacked_widget.addWidget(admin_menu_page)#3
472+
stacked_widget.addWidget(add_employee_page)#4
473+
stacked_widget.addWidget(update_employee_page1)#5
407474

408475
main_layout.addWidget(stacked_widget)
409476
main_window.setCentralWidget(central_widget)

0 commit comments

Comments
 (0)