Skip to content

Commit 57452c5

Browse files
committed
optimize add and withdraw money page
1 parent 3743717 commit 57452c5

File tree

1 file changed

+80
-56
lines changed

1 file changed

+80
-56
lines changed

bank_managment_system/QTFrontend.py

Lines changed: 80 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,62 +1106,86 @@ def show_bank_user_data_page1_submit_btn(name:int):
11061106
else:
11071107
show_popup_message(stacked_widget, "Account not found", EMPLOYEE_SHOW_DETAILS_PAGE1)
11081108

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
1155-
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("")
1109+
def setup_balance_operation_flow(
1110+
stacked_widget,
1111+
title_search,
1112+
placeholder,
1113+
title_form,
1114+
action_button_text,
1115+
success_message,
1116+
backend_action_fn,
1117+
stacked_page_index,
1118+
search_index,
1119+
page_index
1120+
):
1121+
# Create search UI
1122+
search_page, search_widgets = search_result(stacked_widget, title_search, placeholder)
1123+
search_input = search_widgets[0]
1124+
search_button = search_widgets[1]
1125+
1126+
# Create update UI
1127+
form_page, form_widgets = update_user(stacked_widget, title_form, action_button_text)
1128+
name_field, balance_field, amount_field, action_button = form_widgets
1129+
1130+
def on_search_submit():
1131+
try:
1132+
account_number = int(search_input.text().strip())
1133+
except ValueError:
1134+
show_popup_message(stacked_widget, "Please enter a valid account number.", search_index)
1135+
return
1136+
1137+
if backend.check_acc_no(account_number):
1138+
account_data = backend.get_details(account_number)
1139+
name_field.setText(str(account_data[1]))
1140+
balance_field.setText(str(account_data[4]))
1141+
stacked_widget.setCurrentIndex(page_index)
1142+
else:
1143+
show_popup_message(stacked_widget, "Account not found", search_index, show_cancel=True, cancel_page=EMPLOYEE_MENU_PAGE)
1144+
1145+
def on_action_submit():
1146+
try:
1147+
account_number = int(search_input.text().strip())
1148+
amount = int(amount_field.text().strip())
1149+
backend_action_fn(amount, account_number)
1150+
name_field.setText("")
1151+
balance_field.setText("")
1152+
search_input.setText("")
1153+
show_popup_message(stacked_widget, success_message, EMPLOYEE_MENU_PAGE)
1154+
except ValueError:
1155+
show_popup_message(stacked_widget, "Enter valid numeric amount.", page_index)
1156+
1157+
search_button.clicked.connect(on_search_submit)
1158+
action_button.clicked.connect(on_action_submit)
1159+
1160+
return search_page, form_page
1161+
# Add Balance Flow
1162+
add_balance_search_page, add_balance_page = setup_balance_operation_flow(
1163+
stacked_widget=stacked_widget,
1164+
title_search="Add Balance",
1165+
placeholder="Enter Account Number: ",
1166+
title_form="Add Balance User Account",
1167+
action_button_text="Enter Amount: ",
1168+
success_message="Balance updated successfully",
1169+
backend_action_fn=backend.update_balance,
1170+
stacked_page_index=EMPLOYEE_ADD_BALANCE_SEARCH,
1171+
search_index=EMPLOYEE_ADD_BALANCE_SEARCH,
1172+
page_index=EMPLOYEE_ADD_BALANCE_PAGE,
1173+
)
1174+
1175+
# Withdraw Money Flow
1176+
withdraw_money_search_page, withdraw_money_page = setup_balance_operation_flow(
1177+
stacked_widget=stacked_widget,
1178+
title_search="Withdraw Money",
1179+
placeholder="Enter Account Number: ",
1180+
title_form="Withdraw Money From User Account",
1181+
action_button_text="Withdraw Amount: ",
1182+
success_message="Amount withdrawn successfully",
1183+
backend_action_fn=backend.deduct_balance,
1184+
stacked_page_index=EMPLOYEE_WITHDRAW_MONEY_SEARCH,
1185+
search_index=EMPLOYEE_WITHDRAW_MONEY_SEARCH,
1186+
page_index=EMPLOYEE_WITHDRAW_MONEY_PAGE,
1187+
)
1188+
11651189

11661190
stacked_widget.addWidget(home_page)#0
11671191
stacked_widget.addWidget(admin_page)#1

0 commit comments

Comments
 (0)