3
3
import sys
4
4
import backend
5
5
backend .connect_database ()
6
+
6
7
employee_data = None
7
8
# Page Constants (for reference)
8
9
HOME_PAGE = 0
15
16
EMPLOYEE_LIST_PAGE = 7
16
17
ADMIN_TOTAL_MONEY = 8
17
18
EMPLOYEE_MENU_PAGE = 9
19
+ EMPLOYEE_CREATE_ACCOUNT_PAGE = 10
18
20
# -------------------------------------------------------------------------------------------------------------
19
21
# === Reusable UI Component Functions ===
20
22
# -------------------------------------------------------------------------------------------------------------
@@ -85,7 +87,7 @@ def create_input_field(parent, label_text, min_label_size=(120, 0)):
85
87
layout .addWidget (line_edit )
86
88
return frame , line_edit
87
89
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 ):
89
91
"""Reusable popup message box.
90
92
91
93
Args:
@@ -261,7 +263,7 @@ def on_login_button_clicked(parent, name_field, password_field):
261
263
password = password_field .text ().strip ()
262
264
263
265
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 )
265
267
else :
266
268
try :
267
269
# Ideally, here you'd call a backend authentication check
@@ -650,7 +652,7 @@ def create_account_page(parent, title):
650
652
# === Main Window Setup ===
651
653
# -------------------------------------------------------------------------------------------------------------
652
654
653
- def setup_main_window (main_window ):
655
+ def setup_main_window (main_window : QtWidgets . QMainWindow ):
654
656
"""Set up the main window with a stacked widget containing home, admin, and employee pages."""
655
657
main_window .setObjectName ("MainWindow" )
656
658
main_window .resize (800 , 600 )
@@ -692,11 +694,11 @@ def add_employee_form_submit(name, password, salary, position):
692
694
and len (position ) != 0
693
695
):
694
696
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 )
696
698
697
699
else :
698
700
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 )
700
702
def update_employee_data (name , password , salary , position , name_to_update ):
701
703
try :
702
704
cur = backend .cur
@@ -708,10 +710,10 @@ def update_employee_data(name, password, salary, position, name_to_update):
708
710
cur .execute ("UPDATE staff SET salary = ? WHERE name = ?" , (salary , name ))
709
711
cur .execute ("UPDATE staff SET position = ? WHERE name = ?" , (position , name ))
710
712
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 )
712
714
713
715
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 )
715
717
716
718
717
719
@@ -789,10 +791,10 @@ def on_page_changed(index):
789
791
def update_employee_data (name , password , salary , position , name_to_update ):
790
792
try :
791
793
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 )
793
795
return
794
796
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 )
796
798
return
797
799
if name :
798
800
backend .update_employee_name (name , name_to_update )
@@ -807,9 +809,9 @@ def update_employee_data(name, password, salary, position, name_to_update):
807
809
return
808
810
if position :
809
811
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 )
811
813
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 )
813
815
u_employee_update .clicked .connect (
814
816
lambda : update_employee_data (
815
817
u_employee_name .text ().strip (),
@@ -925,7 +927,7 @@ def add_account_form_submit(name, age, address, balance, account_type, mobile):
925
927
main_window .setCentralWidget (central_widget )
926
928
927
929
# Set initial page
928
- stacked_widget .setCurrentIndex (EMPLOYEE_MENU_PAGE )
930
+ stacked_widget .setCurrentIndex (HOME_PAGE )
929
931
930
932
return stacked_widget , {
931
933
"admin_name" : admin_name ,
@@ -951,4 +953,6 @@ def main():
951
953
952
954
if __name__ == "__main__" :
953
955
main ()
956
+ # TO-DO:
957
+ # 1.refese the employee list page after add or delete or update employee
954
958
0 commit comments