33import sys
44import backend
55backend .connect_database ()
6+
67employee_data = None
78# Page Constants (for reference)
89HOME_PAGE = 0
1516EMPLOYEE_LIST_PAGE = 7
1617ADMIN_TOTAL_MONEY = 8
1718EMPLOYEE_MENU_PAGE = 9
19+ EMPLOYEE_CREATE_ACCOUNT_PAGE = 10
1820# -------------------------------------------------------------------------------------------------------------
1921# === Reusable UI Component Functions ===
2022# -------------------------------------------------------------------------------------------------------------
@@ -85,7 +87,7 @@ def create_input_field(parent, label_text, min_label_size=(120, 0)):
8587 layout .addWidget (line_edit )
8688 return frame , line_edit
8789
88- def show_popup_message (parent , message : str , page : int = None , show_cancel : bool = True ,cancel_page : int = HOME_PAGE ):
90+ def show_popup_message (parent , message : str , page : int = None , show_cancel : bool = False ,cancel_page : int = HOME_PAGE ):
8991 """Reusable popup message box.
9092
9193 Args:
@@ -261,7 +263,7 @@ def on_login_button_clicked(parent, name_field, password_field):
261263 password = password_field .text ().strip ()
262264
263265 if not name or not password :
264- show_popup_message (parent , "Please enter your name and password." , 0 )
266+ show_popup_message (parent , "Please enter your name and password." ,HOME_PAGE )
265267 else :
266268 try :
267269 # Ideally, here you'd call a backend authentication check
@@ -650,7 +652,7 @@ def create_account_page(parent, title):
650652# === Main Window Setup ===
651653# -------------------------------------------------------------------------------------------------------------
652654
653- def setup_main_window (main_window ):
655+ def setup_main_window (main_window : QtWidgets . QMainWindow ):
654656 """Set up the main window with a stacked widget containing home, admin, and employee pages."""
655657 main_window .setObjectName ("MainWindow" )
656658 main_window .resize (800 , 600 )
@@ -692,11 +694,11 @@ def add_employee_form_submit(name, password, salary, position):
692694 and len (position ) != 0
693695 ):
694696 backend .create_employee (name , password , salary , position )
695- show_popup_message (stacked_widget ,"Employee added successfully" ,3 , False )
697+ show_popup_message (stacked_widget ,"Employee added successfully" ,ADMIN_MENU_PAGE )
696698
697699 else :
698700 print ("Please fill in all fields" )
699- show_popup_message (stacked_widget ,"Please fill in all fields" ,3 )
701+ show_popup_message (stacked_widget ,"Please fill in all fields" ,ADD_EMPLOYEE_PAGE )
700702 def update_employee_data (name , password , salary , position , name_to_update ):
701703 try :
702704 cur = backend .cur
@@ -708,10 +710,10 @@ def update_employee_data(name, password, salary, position, name_to_update):
708710 cur .execute ("UPDATE staff SET salary = ? WHERE name = ?" , (salary , name ))
709711 cur .execute ("UPDATE staff SET position = ? WHERE name = ?" , (position , name ))
710712 backend .conn .commit ()
711- show_popup_message (stacked_widget ,"Employee Upadate successfully" ,3 , False )
713+ show_popup_message (stacked_widget ,"Employee Upadate successfully" ,UPDATE_EMPLOYEE_PAGE2 )
712714
713715 except :
714- show_popup_message (stacked_widget ,"Please fill in all fields" ,3 )
716+ show_popup_message (stacked_widget ,"Please fill in all fields" ,UPDATE_EMPLOYEE_PAGE2 )
715717
716718
717719
@@ -789,10 +791,10 @@ def on_page_changed(index):
789791 def update_employee_data (name , password , salary , position , name_to_update ):
790792 try :
791793 if not name_to_update :
792- show_popup_message (stacked_widget , "Original employee name is missing." , 5 )
794+ show_popup_message (stacked_widget , "Original employee name is missing." , UPDATE_EMPLOYEE_PAGE2 )
793795 return
794796 if not (name or password or salary or position ):
795- show_popup_message (stacked_widget , "Please fill at least one field to update." , 5 )
797+ show_popup_message (stacked_widget , "Please fill at least one field to update." , UPDATE_EMPLOYEE_PAGE2 )
796798 return
797799 if name :
798800 backend .update_employee_name (name , name_to_update )
@@ -807,9 +809,9 @@ def update_employee_data(name, password, salary, position, name_to_update):
807809 return
808810 if position :
809811 backend .update_employee_position (position , name_to_update )
810- show_popup_message (stacked_widget , "Employee updated successfully." , 3 , False )
812+ show_popup_message (stacked_widget , "Employee updated successfully." , ADMIN_MENU_PAGE )
811813 except Exception as e :
812- show_popup_message (stacked_widget , f"Error updating employee: { str (e )} " , 5 )
814+ show_popup_message (stacked_widget , f"Error updating employee: { str (e )} " ,UPDATE_EMPLOYEE_PAGE2 , show_cancel = True , cancel_page = ADMIN_MENU_PAGE )
813815 u_employee_update .clicked .connect (
814816 lambda : update_employee_data (
815817 u_employee_name .text ().strip (),
@@ -925,7 +927,7 @@ def add_account_form_submit(name, age, address, balance, account_type, mobile):
925927 main_window .setCentralWidget (central_widget )
926928
927929 # Set initial page
928- stacked_widget .setCurrentIndex (EMPLOYEE_MENU_PAGE )
930+ stacked_widget .setCurrentIndex (HOME_PAGE )
929931
930932 return stacked_widget , {
931933 "admin_name" : admin_name ,
@@ -951,4 +953,6 @@ def main():
951953
952954if __name__ == "__main__" :
953955 main ()
956+ # TO-DO:
957+ # 1.refese the employee list page after add or delete or update employee
954958
0 commit comments