Skip to content

Commit 4654bf3

Browse files
committed
update bank balance of user
1 parent a04a2fa commit 4654bf3

File tree

1 file changed

+118
-4
lines changed

1 file changed

+118
-4
lines changed

bank_managment_system/QTFrontend.py

Lines changed: 118 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
EMPLOYEE_CREATE_ACCOUNT_PAGE = 10
2020
EMPLOYEE_SHOW_DETAILS_PAGE1 = 11
2121
EMPLOYEE_SHOW_DETAILS_PAGE2 = 12
22+
EMPLOYEE_ADD_BALANCE_SEARCH = 13
23+
EMPLOYEE_ADD_BALANCE_PAGE = 14
24+
25+
FONT_SIZE = QtGui.QFont("Segoe UI", 12)
2226
# -------------------------------------------------------------------------------------------------------------
2327
# === Reusable UI Component Functions ===
2428
# -------------------------------------------------------------------------------------------------------------
@@ -83,7 +87,25 @@ def create_input_field(parent, label_text, min_label_size=(120, 0)):
8387
label.setMinimumSize(QtCore.QSize(*min_label_size))
8488

8589
line_edit = QtWidgets.QLineEdit(frame)
86-
line_edit.setStyleSheet("background-color: rgb(168, 168, 168);")
90+
line_edit.setStyleSheet("background-color: #f0f0f0; border: 1px solid #ccc; border-radius: 4px; padding: 8px;")
91+
92+
layout.addWidget(label)
93+
layout.addWidget(line_edit)
94+
return frame, line_edit
95+
96+
def create_input_field_V(parent, label_text, min_label_size=(120, 0)):
97+
"""Create a horizontal layout with a label and a QLineEdit."""
98+
frame = create_styled_frame(parent, style="padding: 7px;")
99+
layout = QtWidgets.QVBoxLayout(frame)
100+
layout.setContentsMargins(0, 0, 0, 0)
101+
layout.setSpacing(0)
102+
103+
label = create_styled_label(frame, label_text, font_size=12, bold=True, style="color: #2c3e50;")
104+
if min_label_size:
105+
label.setMinimumSize(QtCore.QSize(*min_label_size))
106+
107+
line_edit = QtWidgets.QLineEdit(frame)
108+
line_edit.setStyleSheet("background-color: #f0f0f0; border: 1px solid #ccc; border-radius: 4px; padding: 8px;")
87109

88110
layout.addWidget(label)
89111
layout.addWidget(line_edit)
@@ -152,6 +174,28 @@ def on_reject():
152174
button_box.rejected.connect(on_reject)
153175

154176
dialog.exec_()
177+
178+
def search_result(parent, title,label_text):
179+
page, main_layout = create_page_with_header(parent, title)
180+
content_frame = create_styled_frame(page)
181+
content_frame.setSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Expanding)
182+
content_layout = QtWidgets.QVBoxLayout(content_frame)
183+
content_layout.alignment
184+
185+
form_frame = create_styled_frame(content_frame, min_size=(400, 200), style="background-color: #ffffff; border-radius: 15px; padding: 10px;")
186+
form_layout = QtWidgets.QVBoxLayout(form_frame)
187+
form_layout.setSpacing(3)
188+
# Define input fields
189+
user = create_input_field(form_frame, label_text, min_label_size=(180, 0))
190+
form_layout.addWidget(user[0])
191+
user_account_number= user[1]
192+
user_account_number.setFont(QtGui.QFont("Segoe UI", 12))
193+
submit_button = create_styled_button(form_frame, "Submit", min_size=(100, 50))
194+
form_layout.addWidget(submit_button)
195+
content_layout.addWidget(form_frame, 0, QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter)
196+
main_layout.addWidget(content_frame)
197+
198+
return page,(user_account_number,submit_button)
155199
# -------------------------------------------------------------------------------------------------------------
156200
# === Page Creation Functions ==
157201
# -------------------------------------------------------------------------------------------------------------
@@ -727,6 +771,49 @@ def create_show_details_page2(parent, title):
727771

728772
return page,(account_no_field,name_field,age_field,address_field,balance_field,mobile_number_field,account_type_field,exite_btn)
729773

774+
def update_user_balance(parent, title):
775+
page, main_layout = create_page_with_header(parent, title)
776+
content_frame = create_styled_frame(page)
777+
content_frame.setSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Expanding)
778+
content_layout = QtWidgets.QVBoxLayout(content_frame)
779+
content_layout.alignment
780+
781+
form_frame = create_styled_frame(content_frame, min_size=(400, 200), style="background-color: #ffffff; border-radius: 15px; padding: 10px;")
782+
form_layout = QtWidgets.QVBoxLayout(form_frame)
783+
form_layout.setSpacing(3)
784+
# Define input fields
785+
user = create_input_field(form_frame, "User Name: ", min_label_size=(180, 0))
786+
user_balance = create_input_field(form_frame, "Balance: ", min_label_size=(180, 0))
787+
user_update_balance = create_input_field_V(form_frame, "Add amount: ", min_label_size=(180, 0))
788+
789+
# Add input fields to the form layout
790+
form_layout.addWidget(user[0])
791+
form_layout.addWidget(user_balance[0])
792+
form_layout.addWidget(user_update_balance[0])
793+
794+
# Store the input fields in variables
795+
user_account_name= user[1]
796+
user_account_name.setReadOnly(True)
797+
user_account_name.setStyleSheet("background-color: #8a8a8a; border: 1px solid #ccc; border-radius: 4px; padding: 8px;")
798+
user_balance_field = user_balance[1]
799+
user_balance_field.setReadOnly(True)
800+
user_balance_field.setStyleSheet("background-color: #8a8a8a; border: 1px solid #ccc; border-radius: 4px; padding: 8px;")
801+
user_update_balance_field = user_update_balance[1]
802+
user_update_balance_field.setStyleSheet("background-color: #f0f0f0; border: 1px solid #ccc; border-radius: 4px; padding: 8px;")
803+
804+
805+
# Set the font size for the input fields
806+
user_account_name.setFont(QtGui.QFont("Segoe UI", 12))
807+
user_balance_field.setFont(QtGui.QFont("Segoe UI", 12))
808+
user_update_balance_field.setFont(QtGui.QFont("Segoe UI", 12))
809+
810+
# Add a submit button
811+
submit_button = create_styled_button(form_frame, "Submit", min_size=(100, 50))
812+
form_layout.addWidget(submit_button)
813+
content_layout.addWidget(form_frame, 0, QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter)
814+
main_layout.addWidget(content_frame)
815+
816+
return page,(user_account_name,user_balance_field,user_update_balance_field,submit_button)
730817
# -------------------------------------------------------------------------------------------------------------
731818
# === Main Window Setup ===
732819
# -------------------------------------------------------------------------------------------------------------
@@ -927,7 +1014,7 @@ def update_employee_data(name, password, salary, position, name_to_update):
9271014
# List of all page
9281015
E_Create_Account.clicked.connect(lambda: stacked_widget.setCurrentIndex(EMPLOYEE_CREATE_ACCOUNT_PAGE))
9291016
E_Show_Details.clicked.connect(lambda: stacked_widget.setCurrentIndex(EMPLOYEE_SHOW_DETAILS_PAGE1))
930-
# E_add_Balance.clicked.connect(lambda: stacked_widget.setCurrentIndex(EMPLOYEE_ADD_BALANCE_PAGE))
1017+
E_add_Balance.clicked.connect(lambda: stacked_widget.setCurrentIndex(EMPLOYEE_ADD_BALANCE_SEARCH))
9311018
# E_Withdraw_Money.clicked.connect(lambda: stacked_widget.setCurrentIndex(EMPLOYEE_WITHDRAW_MONEY_PAGE))
9321019
# E_Chack_Balanace.clicked.connect(lambda: stacked_widget.setCurrentIndex(EMPLOYEE_CHECK_BALANCE_PAGE))
9331020
# E_Update_Account.clicked.connect(lambda: stacked_widget.setCurrentIndex(EMPLOYEE_UPDATE_ACCOUNT_PAGE))
@@ -1014,9 +1101,34 @@ def show_bank_user_data_page1_submit_btn(name:int):
10141101
else:
10151102
show_popup_message(stacked_widget, "Account not found", EMPLOYEE_SHOW_DETAILS_PAGE1)
10161103

1104+
add_balance_search_page,add_balance_search_other = search_result(stacked_widget, "Add Balance","Enter Account Number: ")
1105+
add_balance_search_other[1].clicked.connect(lambda: add_balance_page_submit_btn(int(add_balance_search_other[0].text().strip())))
10171106

10181107

1019-
1108+
add_balance_page,add_balance_other =update_user_balance(stacked_widget, "Add Balance User Account")
1109+
add_balance_other[3].clicked.connect(lambda:update_user_account_balance(add_balance_other[2].text().strip()))
1110+
# user_account_name,user_balance_field,user_update_balance_field,submit_button
1111+
1112+
1113+
def add_balance_page_submit_btn(account_number:int):
1114+
check = backend.check_acc_no(account_number)
1115+
if check:
1116+
account_data = backend.get_details(account_number)
1117+
add_balance_other[0].setText(str(account_data[1]))
1118+
add_balance_other[1].setText(str(account_data[4]))
1119+
stacked_widget.setCurrentIndex(14)
1120+
return account_data
1121+
else:
1122+
show_popup_message(stacked_widget, "Account not found", EMPLOYEE_ADD_BALANCE_SEARCH,show_cancel=True,cancel_page=EMPLOYEE_MENU_PAGE)
1123+
1124+
def update_user_account_balance(add_money:int):
1125+
account_number=int(add_balance_search_other[0].text().strip())
1126+
backend.update_balance(add_money,account_number)
1127+
add_balance_other[0].setText("")
1128+
add_balance_other[1].setText("")
1129+
show_popup_message(stacked_widget, "Balance updated successfully", EMPLOYEE_MENU_PAGE)
1130+
add_balance_search_other[0].setText("")
1131+
10201132
stacked_widget.addWidget(home_page)#0
10211133
stacked_widget.addWidget(admin_page)#1
10221134
stacked_widget.addWidget(employee_page)#2
@@ -1030,14 +1142,16 @@ def show_bank_user_data_page1_submit_btn(name:int):
10301142
stacked_widget.addWidget(employee_create_account_page)#10
10311143
stacked_widget.addWidget(show_bank_user_data_page1)#11
10321144
stacked_widget.addWidget(show_bank_user_data_page2)#12
1145+
stacked_widget.addWidget(add_balance_search_page)#13
1146+
stacked_widget.addWidget(add_balance_page)#14
10331147

10341148

10351149

10361150
main_layout.addWidget(stacked_widget)
10371151
main_window.setCentralWidget(central_widget)
10381152

10391153
# Set initial page
1040-
stacked_widget.setCurrentIndex(11)
1154+
stacked_widget.setCurrentIndex(13)
10411155

10421156
return stacked_widget, {
10431157
"admin_name": admin_name,

0 commit comments

Comments
 (0)