2323EMPLOYEE_ADD_BALANCE_PAGE = 14
2424EMPLOYEE_WITHDRAW_MONEY_SEARCH = 15
2525EMPLOYEE_WITHDRAW_MONEY_PAGE = 16
26+ EMPLOYEE_CHECK_BALANCE_SEARCH = 17
27+ EMPLOYEE_CHECK_BALANCE_PAGE = 18
28+ EMPLOYEE_UPDATE_ACCOUNT_SEARCH = 19
29+ EMPLOYEE_UPDATE_ACCOUNT_PAGE = 20
2630
2731FONT_SIZE = QtGui .QFont ("Segoe UI" , 12 )
2832# -------------------------------------------------------------------------------------------------------------
@@ -604,7 +608,7 @@ def create_employee_menu_page(parent, title):
604608
605609 return page , * buttons # Unpack as add_button, update_employee, etc.
606610
607- def create_account_page (parent , title ):
611+ def create_account_page (parent , title , update_btn = False ):
608612 page , main_layout = create_page_with_header (parent , title )
609613
610614 content_frame = create_styled_frame (page )
@@ -673,8 +677,10 @@ def create_account_page(parent, title):
673677 button_frame = create_styled_frame (form_frame , style = "padding: 7px;" )
674678 button_layout = QtWidgets .QVBoxLayout (button_frame )
675679
676-
677- submit_button = create_styled_button (button_frame , "Submit" , min_size = (100 , 50 ))
680+ if update_btn :
681+ submit_button = create_styled_button (button_frame , "Update" , min_size = (100 , 50 ))
682+ else :
683+ submit_button = create_styled_button (button_frame , "Submit" , min_size = (100 , 50 ))
678684 button_layout .addWidget (submit_button , 0 , QtCore .Qt .AlignHCenter )
679685
680686
@@ -775,7 +781,7 @@ def create_show_details_page2(parent, title):
775781
776782 return page ,(account_no_field ,name_field ,age_field ,address_field ,balance_field ,mobile_number_field ,account_type_field ,exite_btn )
777783
778- def update_user (parent , title ,input_fields_label ):
784+ def update_user (parent , title ,input_fields_label , input_fielf : bool = True ):
779785 page , main_layout = create_page_with_header (parent , title )
780786 content_frame = create_styled_frame (page )
781787 content_frame .setSizePolicy (QtWidgets .QSizePolicy .Preferred , QtWidgets .QSizePolicy .Expanding )
@@ -788,12 +794,14 @@ def update_user(parent, title,input_fields_label):
788794 # Define input fields
789795 user = create_input_field (form_frame , "User Name: " , min_label_size = (180 , 0 ))
790796 user_balance = create_input_field (form_frame , "Balance: " , min_label_size = (180 , 0 ))
791- user_update_balance = create_input_field_V ( form_frame , input_fields_label , min_label_size = ( 180 , 0 ))
797+
792798
793799 # Add input fields to the form layout
794800 form_layout .addWidget (user [0 ])
795801 form_layout .addWidget (user_balance [0 ])
796- form_layout .addWidget (user_update_balance [0 ])
802+ if input_fielf :
803+ user_update_balance = create_input_field_V (form_frame , input_fields_label , min_label_size = (180 , 0 ))
804+ form_layout .addWidget (user_update_balance [0 ])
797805
798806 # Store the input fields in variables
799807 user_account_name = user [1 ]
@@ -802,22 +810,42 @@ def update_user(parent, title,input_fields_label):
802810 user_balance_field = user_balance [1 ]
803811 user_balance_field .setReadOnly (True )
804812 user_balance_field .setStyleSheet ("background-color: #8a8a8a; border: 1px solid #ccc; border-radius: 4px; padding: 8px;" )
805- user_update_balance_field = user_update_balance [1 ]
806- user_update_balance_field .setStyleSheet ("background-color: #f0f0f0; border: 1px solid #ccc; border-radius: 4px; padding: 8px;" )
813+ if input_fielf :
814+ user_update_balance_field = user_update_balance [1 ]
815+ user_update_balance_field .setStyleSheet ("background-color: #f0f0f0; border: 1px solid #ccc; border-radius: 4px; padding: 8px;" )
807816
808817
809818 # Set the font size for the input fields
810819 user_account_name .setFont (FONT_SIZE )
811820 user_balance_field .setFont (FONT_SIZE )
812- user_update_balance_field .setFont (FONT_SIZE )
821+ if input_fielf :
822+ user_update_balance_field .setFont (FONT_SIZE )
813823
814824 # Add a submit button
815825 submit_button = create_styled_button (form_frame , "Submit" , min_size = (100 , 50 ))
816826 form_layout .addWidget (submit_button )
817827 content_layout .addWidget (form_frame , 0 , QtCore .Qt .AlignHCenter | QtCore .Qt .AlignVCenter )
818828 main_layout .addWidget (content_frame )
819-
820- return page ,(user_account_name ,user_balance_field ,user_update_balance_field ,submit_button )
829+ back_btn = create_styled_button (content_frame , "Back" , min_size = (100 , 50 ))
830+ back_btn .setStyleSheet ("""
831+ QPushButton {
832+ background-color: #6c757d;
833+ color: white;
834+ border: none;
835+ border-radius: 4px;
836+ padding: 8px 16px;
837+ font-size: 14px;
838+ }
839+ QPushButton:hover {
840+ background-color: #5a6268;
841+ }
842+ """ )
843+ back_btn .clicked .connect (lambda : parent .setCurrentIndex (EMPLOYEE_MENU_PAGE ))
844+ backend
845+ if input_fielf :
846+ return page ,(user_account_name ,user_balance_field ,user_update_balance_field ,submit_button )
847+ else :
848+ return page ,(user_account_name ,user_balance_field ,submit_button )
821849
822850# -------------------------------------------------------------------------------------------------------------
823851# === Main Window Setup ===
@@ -1021,8 +1049,8 @@ def update_employee_data(name, password, salary, position, name_to_update):
10211049 E_Show_Details .clicked .connect (lambda : stacked_widget .setCurrentIndex (EMPLOYEE_SHOW_DETAILS_PAGE1 ))
10221050 E_add_Balance .clicked .connect (lambda : stacked_widget .setCurrentIndex (EMPLOYEE_ADD_BALANCE_SEARCH ))
10231051 E_Withdraw_Money .clicked .connect (lambda : stacked_widget .setCurrentIndex (EMPLOYEE_WITHDRAW_MONEY_SEARCH ))
1024- # E_Chack_Balanace.clicked.connect(lambda: stacked_widget.setCurrentIndex(EMPLOYEE_CHECK_BALANCE_PAGE ))
1025- # E_Update_Account.clicked.connect(lambda: stacked_widget.setCurrentIndex(EMPLOYEE_UPDATE_ACCOUNT_PAGE ))
1052+ E_Chack_Balanace .clicked .connect (lambda : stacked_widget .setCurrentIndex (EMPLOYEE_CHECK_BALANCE_SEARCH ))
1053+ E_Update_Account .clicked .connect (lambda : stacked_widget .setCurrentIndex (EMPLOYEE_UPDATE_ACCOUNT_SEARCH ))
10261054 # E_list_of_all_Members.clicked.connect(lambda: stacked_widget.setCurrentIndex(EMPLOYEE_LIST_OF_ALL_MEMBERS_PAGE))
10271055 # E_Delete_Account.clicked.connect(lambda: stacked_widget.setCurrentIndex(EMPLOYEE_DELETE_ACCOUNT_PAGE))
10281056 # E_Back.clicked.connect(lambda: stacked_widget.setCurrentIndex(EMPLOYEE_MENU_PAGE))
@@ -1106,63 +1134,164 @@ def show_bank_user_data_page1_submit_btn(name:int):
11061134 else :
11071135 show_popup_message (stacked_widget , "Account not found" , EMPLOYEE_SHOW_DETAILS_PAGE1 )
11081136
1109- # Add balance page
1110- add_balance_search_page ,add_balance_search_other = search_result (stacked_widget , "Add Balance" ,"Enter Account Number: " )
1111- add_balance_search_other [1 ].clicked .connect (lambda : add_balance_page_submit_btn (int (add_balance_search_other [0 ].text ().strip ())))
1112-
1113-
1114- add_balance_page ,add_balance_other = update_user (stacked_widget , "Add Balance User Account" ,"Enter Ammount: " )
1115- add_balance_other [3 ].clicked .connect (lambda :update_user_account_balance (add_balance_other [2 ].text ().strip ()))
1116-
1117-
1118- def add_balance_page_submit_btn (account_number :int ):
1119- check = backend .check_acc_no (account_number )
1120- if check :
1121- account_data = backend .get_details (account_number )
1122- add_balance_other [0 ].setText (str (account_data [1 ]))
1123- add_balance_other [1 ].setText (str (account_data [4 ]))
1124- stacked_widget .setCurrentIndex (14 )
1125- return account_data
1126- else :
1127- show_popup_message (stacked_widget , "Account not found" , EMPLOYEE_ADD_BALANCE_SEARCH ,show_cancel = True ,cancel_page = EMPLOYEE_MENU_PAGE )
1128-
1129- def update_user_account_balance (add_money :int ):
1130- account_number = int (add_balance_search_other [0 ].text ().strip ())
1131- backend .update_balance (add_money ,account_number )
1132- add_balance_other [0 ].setText ("" )
1133- add_balance_other [1 ].setText ("" )
1134- show_popup_message (stacked_widget , "Balance updated successfully" , EMPLOYEE_MENU_PAGE )
1135- add_balance_search_other [0 ].setText ("" )
1136-
1137- # Withdraw money page
1138- withdraw_money_search_page ,withdraw_money_search_other = search_result (stacked_widget , "Withdraw Money" ,"Enter Account Number: " )
1139- withdraw_money_search_other [1 ].clicked .connect (lambda : withdraw_money_page_submit_btn (int (withdraw_money_search_other [0 ].text ().strip ())))
1140-
1141-
1142- withdraw_money_page ,withdraw_money_other = update_user (stacked_widget , "Withdraw Money From User Account" ,"Withdraw Amount: " )
1143- withdraw_money_other [3 ].clicked .connect (lambda :update_user_account_withdraw (withdraw_money_other [2 ].text ().strip ()))
1144-
1145- def withdraw_money_page_submit_btn (account_number :int ):
1146- print (account_number )
1147- check = backend .check_acc_no (account_number )
1148- print (check )
1149- if check :
1150- account_data = backend .get_details (account_number )
1151- withdraw_money_other [0 ].setText (str (account_data [1 ]))
1152- withdraw_money_other [1 ].setText (str (account_data [4 ]))
1153- stacked_widget .setCurrentIndex (16 )
1154- return account_data
1137+ def setup_balance_operation_flow (
1138+ stacked_widget ,
1139+ title_search ,
1140+ placeholder ,
1141+ title_form ,
1142+ action_button_text ,
1143+ success_message ,
1144+ backend_action_fn ,
1145+ stacked_page_index ,
1146+ search_index ,
1147+ page_index ,
1148+ need_input = True
1149+ ):
1150+ # Create search UI
1151+ search_page , search_widgets = search_result (stacked_widget , title_search , placeholder )
1152+ search_input = search_widgets [0 ]
1153+ search_button = search_widgets [1 ]
1154+
1155+ # Create update UI
1156+ form_page , form_widgets = update_user (stacked_widget , title_form , action_button_text ,need_input )
1157+ if need_input :
1158+ name_field , balance_field , amount_field , action_button = form_widgets
11551159 else :
1156- show_popup_message (stacked_widget , "Account not found" , EMPLOYEE_WITHDRAW_MONEY_SEARCH ,show_cancel = True ,cancel_page = EMPLOYEE_MENU_PAGE )
1157-
1158- def update_user_account_withdraw (withdraw_money :int ):
1159- account_number = int (withdraw_money_search_other [0 ].text ().strip ())
1160- backend .deduct_balance (int (withdraw_money ),int (account_number ))
1161- withdraw_money_other [0 ].setText ("" )
1162- withdraw_money_other [1 ].setText ("" )
1163- show_popup_message (stacked_widget , "Balance updated successfully" , EMPLOYEE_MENU_PAGE )
1164- withdraw_money_search_other [0 ].setText ("" )
1160+ name_field , balance_field , action_button = form_widgets
1161+
1162+ def on_search_submit ():
1163+ try :
1164+ account_number = int (search_input .text ().strip ())
1165+ except ValueError :
1166+ show_popup_message (stacked_widget , "Please enter a valid account number." , search_index )
1167+ return
1168+
1169+ if backend .check_acc_no (account_number ):
1170+ account_data = backend .get_details (account_number )
1171+ name_field .setText (str (account_data [1 ]))
1172+ balance_field .setText (str (account_data [4 ]))
1173+ stacked_widget .setCurrentIndex (page_index )
1174+ else :
1175+ show_popup_message (stacked_widget , "Account not found" , search_index , show_cancel = True , cancel_page = EMPLOYEE_MENU_PAGE )
1176+
1177+ def on_action_submit ():
1178+ try :
1179+ account_number = int (search_input .text ().strip ())
1180+ amount = int (amount_field .text ().strip ())
1181+ backend_action_fn (amount , account_number )
1182+ name_field .setText ("" )
1183+ balance_field .setText ("" )
1184+ search_input .setText ("" )
1185+ show_popup_message (stacked_widget , success_message , EMPLOYEE_MENU_PAGE )
1186+ except ValueError :
1187+ show_popup_message (stacked_widget , "Enter valid numeric amount." , page_index )
1188+
1189+ search_button .clicked .connect (on_search_submit )
1190+ action_button .clicked .connect (on_action_submit )
1191+
1192+ return search_page , form_page
1193+ # Add Balance Flow
1194+ add_balance_search_page , add_balance_page = setup_balance_operation_flow (
1195+ stacked_widget = stacked_widget ,
1196+ title_search = "Add Balance" ,
1197+ placeholder = "Enter Account Number: " ,
1198+ title_form = "Add Balance User Account" ,
1199+ action_button_text = "Enter Amount: " ,
1200+ success_message = "Balance updated successfully" ,
1201+ backend_action_fn = backend .update_balance ,
1202+ stacked_page_index = EMPLOYEE_ADD_BALANCE_SEARCH ,
1203+ search_index = EMPLOYEE_ADD_BALANCE_SEARCH ,
1204+ page_index = EMPLOYEE_ADD_BALANCE_PAGE ,
1205+ )
1206+
1207+ # Withdraw Money Flow
1208+ withdraw_money_search_page , withdraw_money_page = setup_balance_operation_flow (
1209+ stacked_widget = stacked_widget ,
1210+ title_search = "Withdraw Money" ,
1211+ placeholder = "Enter Account Number: " ,
1212+ title_form = "Withdraw Money From User Account" ,
1213+ action_button_text = "Withdraw Amount: " ,
1214+ success_message = "Amount withdrawn successfully" ,
1215+ backend_action_fn = backend .deduct_balance ,
1216+ stacked_page_index = EMPLOYEE_WITHDRAW_MONEY_SEARCH ,
1217+ search_index = EMPLOYEE_WITHDRAW_MONEY_SEARCH ,
1218+ page_index = EMPLOYEE_WITHDRAW_MONEY_PAGE ,
1219+ )
1220+
1221+ check_balance_search_page , check_balance_page = setup_balance_operation_flow (
1222+ stacked_widget = stacked_widget ,
1223+ title_search = "Check Balance" ,
1224+ placeholder = "Enter Account Number: " ,
1225+ title_form = "Check Balance" ,
1226+ action_button_text = "Check Balance: " ,
1227+ success_message = "Balance checked successfully" ,
1228+ backend_action_fn = backend .check_balance ,
1229+ stacked_page_index = EMPLOYEE_CHECK_BALANCE_SEARCH ,
1230+ search_index = EMPLOYEE_CHECK_BALANCE_SEARCH ,
1231+ page_index = EMPLOYEE_CHECK_BALANCE_PAGE ,
1232+ need_input = False
1233+ )
1234+ def find_and_hide_submit_button (page ):
1235+ # Find all QPushButton widgets in the page
1236+ buttons = page .findChildren (QtWidgets .QPushButton )
1237+ for button in buttons :
1238+ if button .text () == "Submit" :
1239+ button .hide ()
1240+ break
1241+
1242+ find_and_hide_submit_button (check_balance_page )
1243+
1244+ # Update Employee details
1245+ update_empolyee_search_page ,update_empolyee_search_other = search_result (stacked_widget , "Update Employee Details" , "Enter Employee ID: " )
1246+ update_employee_page ,update_employee_other = create_account_page (stacked_widget , "Update Employee" , True )
1247+ name_edit = update_employee_other [0 ]
1248+ Age_edit = update_employee_other [1 ]
1249+ Address_edit = update_employee_other [2 ]
1250+ Balance_edit = update_employee_other [3 ]
1251+ Mobile_number_edit = update_employee_other [4 ]
1252+ account_type_dropdown = update_employee_other [5 ]
1253+ # name_edit, Age_edit,Address_edit,Balance_edit,Mobile_number_edit, account_type_dropdown ,submit_button
1254+
1255+ update_empolyee_search_other [1 ].clicked .connect (lambda :update_employee_search_submit ())
1256+ update_employee_other [6 ].clicked .connect (lambda :update_employee_submit ())
1257+ def update_employee_search_submit ():
1258+ try :
1259+ user_data = backend .get_details (int (update_empolyee_search_other [0 ].text ().strip ()))
1260+ print ("Featch data: " ,user_data )
1261+ name_edit .setText (str (user_data [1 ]))
1262+ Age_edit .setText (str (user_data [2 ]))
1263+ Address_edit .setText (str (user_data [3 ]))
1264+ Balance_edit .setText (str (user_data [4 ]))
1265+ Mobile_number_edit .setText (str (user_data [6 ]))
1266+ Balance_edit .setDisabled (True )
1267+ account_type_dropdown .setCurrentText (str (user_data [5 ]))
1268+ stacked_widget .setCurrentIndex (EMPLOYEE_UPDATE_ACCOUNT_PAGE )
1269+ except ValueError :
1270+ show_popup_message (stacked_widget , "Enter valid numeric employee ID." , EMPLOYEE_MENU_PAGE )
1271+
1272+ def update_employee_submit ():
1273+ try :
1274+ user_data = backend .get_details (int (update_empolyee_search_other [0 ].text ().strip ()))
1275+ name = name_edit .text ().strip ()
1276+ age = int (Age_edit .text ().strip ())
1277+ address = Address_edit .text ().strip ()
1278+ mobile_number = int (Mobile_number_edit .text ().strip ())
1279+ account_type = account_type_dropdown .currentText ()
1280+ print (name ,age ,address ,mobile_number ,account_type )
1281+ backend .update_name_in_bank_table (name ,user_data [0 ])
1282+ backend .update_age_in_bank_table (age ,user_data [0 ])
1283+ backend .update_address_in_bank_table (address ,user_data [0 ])
1284+ backend .update_address_in_bank_table (address ,user_data [0 ])
1285+ backend .update_mobile_number_in_bank_table (mobile_number ,user_data [0 ])
1286+ backend .update_acc_type_in_bank_table (account_type ,user_data [0 ])
1287+
1288+ show_popup_message (stacked_widget , "Employee details updated successfully" , EMPLOYEE_MENU_PAGE )
1289+ stacked_widget .setCurrentIndex (EMPLOYEE_MENU_PAGE )
1290+ except ValueError as e :
1291+ print (e )
1292+ show_popup_message (stacked_widget , "Enter valid numeric employee ID." , EMPLOYEE_MENU_PAGE )
11651293
1294+
11661295 stacked_widget .addWidget (home_page )#0
11671296 stacked_widget .addWidget (admin_page )#1
11681297 stacked_widget .addWidget (employee_page )#2
@@ -1180,6 +1309,10 @@ def update_user_account_withdraw(withdraw_money:int):
11801309 stacked_widget .addWidget (add_balance_page )#14
11811310 stacked_widget .addWidget (withdraw_money_search_page )#15
11821311 stacked_widget .addWidget (withdraw_money_page )#16
1312+ stacked_widget .addWidget (check_balance_search_page )#17
1313+ stacked_widget .addWidget (check_balance_page )#18
1314+ stacked_widget .addWidget (update_empolyee_search_page )#19
1315+ stacked_widget .addWidget (update_employee_page )#20
11831316
11841317
11851318
0 commit comments