@@ -131,6 +131,31 @@ def on_reject():
131
131
button_box .rejected .connect (on_reject )
132
132
133
133
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()
134
159
def create_login_page (parent ,title , name_field_text = "Name :" , password_field_text = "Password :" , submit_text = "Submit" ,):
135
160
"""Create a login page with a title, name and password fields, and a submit button."""
136
161
page , main_layout = create_page_with_header (parent , "Admin Menu" )
@@ -267,7 +292,7 @@ def create_admin_menu_page(parent):
267
292
return page , * buttons # Unpack as add_button, update_employee, etc.
268
293
269
294
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 ):
271
296
page , main_layout = create_page_with_header (parent , title )
272
297
273
298
content_frame = create_styled_frame (page )
@@ -290,15 +315,22 @@ def create_add_employee_page(parent, title, submit_text="Submit"):
290
315
# Submit button
291
316
button_frame = create_styled_frame (form_frame , style = "padding: 7px;" )
292
317
button_layout = QtWidgets .QVBoxLayout (button_frame )
318
+ update_button = create_styled_button (button_frame , "Update" , min_size = (150 , 0 ))
293
319
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
+
295
325
296
326
form_layout .addWidget (button_frame )
297
327
content_layout .addWidget (form_frame , 0 , QtCore .Qt .AlignHCenter | QtCore .Qt .AlignVCenter )
298
328
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
+
302
334
def setup_main_window (main_window ):
303
335
"""Set up the main window with a stacked widget containing home, admin, and employee pages."""
304
336
main_window .setObjectName ("MainWindow" )
@@ -341,6 +373,31 @@ def add_employee_form_submit(name, password, salary, position):
341
373
else :
342
374
print ("Please fill in all fields" )
343
375
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
344
401
345
402
346
403
# Create Home Page
@@ -375,13 +432,22 @@ def add_employee_form_submit(name, password, salary, position):
375
432
)
376
433
377
434
add_button .clicked .connect (lambda : stacked_widget .setCurrentIndex (4 ))
435
+ update_button .clicked .connect (lambda : stacked_widget .setCurrentIndex (5 ))
378
436
379
437
# Create Add Employee Page
380
438
add_employee_page , emp_name , emp_password , emp_salary , emp_position , emp_submit = create_add_employee_page (
381
439
stacked_widget ,
382
440
title = "Add Employee"
383
441
)
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
+
384
449
450
+ # ///////////////////////////
385
451
emp_submit .clicked .connect (
386
452
lambda : add_employee_form_submit (
387
453
emp_name .text (),
@@ -399,11 +465,12 @@ def add_employee_form_submit(name, password, salary, position):
399
465
400
466
401
467
# 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
407
474
408
475
main_layout .addWidget (stacked_widget )
409
476
main_window .setCentralWidget (central_widget )
0 commit comments