@@ -203,29 +203,7 @@ def on_login_button_clicked(parent,name_field, password_field):
203
203
# Check if the entered name and password are correct
204
204
if name == "" and password == "" :
205
205
# Show a message box with the entered name and password
206
- Dialog = QtWidgets .QDialog ()
207
- Dialog .setObjectName ("Dialog" )
208
- Dialog .resize (317 , 60 )
209
- verticalLayout = QtWidgets .QVBoxLayout (Dialog )
210
- verticalLayout .setObjectName ("verticalLayout" )
211
- label = QtWidgets .QLabel (Dialog )
212
- label .setObjectName ("label" )
213
- label .setText ("Please enter both name and password" )
214
- verticalLayout .addWidget (label , 0 , QtCore .Qt .AlignTop )
215
- buttonBox = QtWidgets .QDialogButtonBox (Dialog )
216
- buttonBox .setOrientation (QtCore .Qt .Horizontal )
217
- buttonBox .setStandardButtons (QtWidgets .QDialogButtonBox .Cancel | QtWidgets .QDialogButtonBox .Ok )
218
- buttonBox .setObjectName ("buttonBox" )
219
- verticalLayout .addWidget (buttonBox )
220
-
221
- buttonBox .accepted .connect (Dialog .accept ) # type: ignore
222
- buttonBox .rejected .connect (lambda :rejectBTN ())# type: ignore
223
- QtCore .QMetaObject .connectSlotsByName (Dialog )
224
- def rejectBTN ():
225
- parent .setCurrentIndex (0 )
226
- Dialog .reject ()
227
- # Show the dialog
228
- Dialog .exec_ ()
206
+ pop_up_message (parent , "Please enter your name and password." ,0 )
229
207
else :
230
208
print (f"Name: { name } , Password: { password } " )
231
209
@@ -331,9 +309,53 @@ def create_admin_menu_page(perent):
331
309
# employee_list.clicked.connect(on_employee_list_clicked)
332
310
# total_money.clicked.connect(on_total_money_clicked)
333
311
# back_to_home.clicked.connect(on_back_to_home_clicked)
334
- return page
312
+ return page , add_button , update_employee , employee_list , total_money , back_to_home
335
313
336
-
314
+ def create_add_employe_page (parent ,title , name_field_text = "Name :" , password_field_text = "Password :" ,position_fielld_text = "Position :" ,salary_field_text = "Salary :" ,submit_text = "Submit" ,):
315
+ """Create a login page with a title, name and password fields, and a submit button."""
316
+ page = QtWidgets .QWidget (parent )
317
+ main_layout = QtWidgets .QVBoxLayout (page )
318
+
319
+ # Header frame with title
320
+ header_frame = create_styled_frame (page , style = "background-color: #ffffff; border-radius: 10px; padding: 10px;" )
321
+ header_layout = QtWidgets .QVBoxLayout (header_frame )
322
+ title_label = create_styled_label (header_frame , title , font_size = 30 )
323
+ header_layout .addWidget (title_label , 0 , QtCore .Qt .AlignHCenter | QtCore .Qt .AlignTop )
324
+ main_layout .addWidget (header_frame , 0 , QtCore .Qt .AlignTop )
325
+
326
+ # Content frame
327
+ content_frame = create_styled_frame (page )
328
+ content_frame .setSizePolicy (QtWidgets .QSizePolicy .Preferred , QtWidgets .QSizePolicy .Expanding )
329
+ content_layout = QtWidgets .QVBoxLayout (content_frame )
330
+
331
+ # Form frame
332
+ form_frame = create_styled_frame (content_frame , min_size = (340 , 200 ), style = "background-color: #ffffff; border-radius: 15px; padding: 10px;" )
333
+ form_layout = QtWidgets .QVBoxLayout (form_frame )
334
+ form_layout .setSpacing (20 )
335
+
336
+ # Input fields
337
+ name_frame , name_edit = create_input_field (form_frame , name_field_text )
338
+ password_frame , password_edit = create_input_field (form_frame , password_field_text )
339
+ salary_frame , salary_edit = create_input_field (form_frame , salary_field_text )
340
+ position_frame , position_edit = create_input_field (form_frame , position_fielld_text )
341
+
342
+ # Submit button
343
+ button_frame = create_styled_frame (form_frame , style = "padding: 7px;" )
344
+ button_layout = QtWidgets .QVBoxLayout (button_frame )
345
+ button_layout .setSpacing (60 )
346
+ submit_button = create_styled_button (button_frame , submit_text , min_size = (150 , 0 ))
347
+ button_layout .addWidget (submit_button , 0 , QtCore .Qt .AlignHCenter )
348
+
349
+ form_layout .addWidget (name_frame )
350
+ form_layout .addWidget (password_frame )
351
+ form_layout .addWidget (salary_frame )
352
+ form_layout .addWidget (position_frame )
353
+ form_layout .addWidget (button_frame )
354
+
355
+ content_layout .addWidget (form_frame , 0 , QtCore .Qt .AlignHCenter | QtCore .Qt .AlignVCenter )
356
+ main_layout .addWidget (content_frame )
357
+
358
+ return page , name_edit , password_edit , salary_edit , position_edit ,submit_button
337
359
def setup_main_window (main_window ):
338
360
"""Set up the main window with a stacked widget containing home, admin, and employee pages."""
339
361
main_window .setObjectName ("MainWindow" )
@@ -360,23 +382,44 @@ def admin_login_menu_page(name, password):
360
382
if result :
361
383
stacked_widget .setCurrentIndex (3 )
362
384
else :
363
- print ("Invalid admin credentials" )
385
+ print ("Invalid admin credentials" )
386
+
387
+ def add_employee_form_submit (name , password , salary , position ):
388
+ if (
389
+ len (name ) != 0
390
+ and len (password ) != 0
391
+ and len (salary ) != 0
392
+ and len (position ) != 0
393
+ ):
394
+ backend .create_employee (name , password , salary , position )
395
+ pop_up_message_with_only_ok (stacked_widget ,"Employee added successfully" ,3 )
396
+
397
+ else :
398
+ print ("Please fill in all fields" )
399
+ pop_up_message (stacked_widget ,"Please fill in all fields" ,3 )
400
+
364
401
365
402
home_page = create_home_page (stacked_widget , switch_to_admin , switch_to_employee , exit_app )
366
403
admin_page , admin_name , admin_password , admin_submit = create_login_page (stacked_widget , "Admin Login" )
367
404
admin_submit .clicked .connect (
368
405
lambda : admin_login_menu_page (admin_name .text (), admin_password .text ())
369
406
)
370
- admin_menu_page = create_admin_menu_page (stacked_widget )
371
-
407
+ admin_menu_page ,add_button ,update_employee ,employee_list ,total_money ,back_to_home = create_admin_menu_page (stacked_widget )
408
+ add_button .clicked .connect (lambda :stacked_widget .setCurrentIndex (4 ))
409
+ # create employee page
410
+ add_employe_page , new_employee_name , new_employee_password , new_employe_salary , new_employe_position , new_employee_submit = create_add_employe_page (stacked_widget , "Add Employee" )
411
+ new_employee_submit .clicked .connect (
412
+ lambda : add_employee_form_submit (new_employee_name .text (), new_employee_password .text (), new_employe_salary .text (), new_employe_position .text ())
413
+ )
372
414
employee_page , employee_name , employee_password , employee_submit = create_login_page (stacked_widget , "Employee Login" )
373
415
374
416
375
417
# Add pages to stacked widget
376
- stacked_widget .addWidget (home_page )
377
- stacked_widget .addWidget (admin_page )
378
- stacked_widget .addWidget (employee_page )
379
- stacked_widget .addWidget (admin_menu_page )
418
+ stacked_widget .addWidget (home_page )#1
419
+ stacked_widget .addWidget (admin_page )#2
420
+ stacked_widget .addWidget (employee_page )#3
421
+ stacked_widget .addWidget (admin_menu_page )#4
422
+ stacked_widget .addWidget (add_employe_page )#5
380
423
381
424
main_layout .addWidget (stacked_widget )
382
425
main_window .setCentralWidget (central_widget )
0 commit comments