From 34f67a95597ca1a2343f478bf47fa459ffce0c54 Mon Sep 17 00:00:00 2001 From: Pratyanj <109451378+pratyanj@users.noreply.github.com> Date: Fri, 4 Apr 2025 17:02:07 +0530 Subject: [PATCH 01/12] Change GUI TK to customtkinter I have change the normal tkinter gui with customtkinter that similar to tkinter but morden looking. --- AI Game/Tic-Tac-Toe-AI/tictactoe.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/AI Game/Tic-Tac-Toe-AI/tictactoe.py b/AI Game/Tic-Tac-Toe-AI/tictactoe.py index 0488e5acfdf..0cd5bd0dc36 100644 --- a/AI Game/Tic-Tac-Toe-AI/tictactoe.py +++ b/AI Game/Tic-Tac-Toe-AI/tictactoe.py @@ -1,7 +1,6 @@ -import tkinter as tk #provides a library of basic elements of GUI widgets from tkinter import messagebox #provides a different set of dialogues that are used to display message boxes -import random - +import customtkinter as ctk +import customtkinter as messagebox def check_winner(board, player): # Check rows, columns, and diagonals for a win for i in range(3): @@ -63,7 +62,8 @@ def best_move(board): def make_move(row, col): if board[row][col] == ' ': board[row][col] = 'X' - buttons[row][col].config(text='X') + # in tk we use the config but in customtkinter we use configure for + buttons[row][col].configure(text='X') if check_winner(board, 'X'): messagebox.showinfo("Tic-Tac-Toe", "You win!") root.quit() @@ -79,15 +79,15 @@ def make_move(row, col): def ai_move(): row, col = best_move(board) board[row][col] = 'O' - buttons[row][col].config(text='O') + buttons[row][col].configure(text='O') if check_winner(board, 'O'): messagebox.showinfo("Tic-Tac-Toe", "AI wins!") root.quit() elif is_board_full(board): messagebox.showinfo("Tic-Tac-Toe", "It's a draw!") root.quit() - -root = tk.Tk() +# change old UI code to customtkinter UI +root = ctk.CTk() root.title("Tic-Tac-Toe") board = [[' ' for _ in range(3)] for _ in range(3)] @@ -96,8 +96,8 @@ def ai_move(): for i in range(3): row_buttons = [] for j in range(3): - button = tk.Button(root, text=' ', font=('normal', 30), width=5, height=2, command=lambda row=i, col=j: make_move(row, col)) - button.grid(row=i, column=j) + button = ctk.CTkButton(root, text=' ', font=('normal', 30), width=100, height=100, command=lambda row=i, col=j: make_move(row, col)) + button.grid(row=i, column=j, padx=2, pady=2) row_buttons.append(button) buttons.append(row_buttons) From 1b2dae5f0e5745a7894df31320f0d72fce60bbf9 Mon Sep 17 00:00:00 2001 From: Pratyanj <109451378+pratyanj@users.noreply.github.com> Date: Fri, 30 May 2025 09:58:16 +0530 Subject: [PATCH 02/12] QT design softer file --- bank_managment_system/untitled.ui | 862 ++++++++++++++++++++++++++++++ 1 file changed, 862 insertions(+) create mode 100644 bank_managment_system/untitled.ui diff --git a/bank_managment_system/untitled.ui b/bank_managment_system/untitled.ui new file mode 100644 index 00000000000..12c130fb4e7 --- /dev/null +++ b/bank_managment_system/untitled.ui @@ -0,0 +1,862 @@ + + + MainWindow + + + + 0 + 0 + 800 + 600 + + + + MainWindow + + + + background-color: #f0f2f5; +QPushButton { + background-color: #3498db; + color: white; + font-family: 'Segoe UI'; + font-size: 16px; + font-weight: bold; + border-radius: 8px; + padding: 12px; + border: none; + } + QPushButton:hover { + background-color: #2980b9; + } + QPushButton:pressed { + background-color: #1c6ea4; + } + + + + + + + 2 + + + + + + + + background-color: #ffffff; + border-radius: 10px; + padding: 10px; + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + 30 + + + + + color: #2c3e50; + padding: 10px; + + + + Bank Management system + + + + + + + + + + + 0 + 0 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + 300 + 0 + + + + + 16 + + + + + + background-color: #ffffff; + border-radius: 15px; + padding: 20px; + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + QPushButton { + background-color: #3498db; + color: white; + font-family: 'Segoe UI'; + font-size: 16px; + font-weight: bold; + border-radius: 8px; + padding: 12px; + border: none; + } + QPushButton:hover { + background-color: #2980b9; + } + QPushButton:pressed { + background-color: #1c6ea4; + } + + + Admin + + + + + + + QPushButton { + background-color: #3498db; + color: white; + font-family: 'Segoe UI'; + font-size: 16px; + font-weight: bold; + border-radius: 8px; + padding: 12px; + border: none; + } + QPushButton:hover { + background-color: #2980b9; + } + QPushButton:pressed { + background-color: #1c6ea4; + } + + + Employee + + + + + + + QPushButton { + background-color: #3498db; + color: white; + font-family: 'Segoe UI'; + font-size: 16px; + font-weight: bold; + border-radius: 8px; + padding: 12px; + border: none; + } + QPushButton:hover { + background-color: #2980b9; + } + QPushButton:pressed { + background-color: #1c6ea4; + } + + + Exit + + + + + + + + + + + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + 340 + 210 + 261 + 231 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + 20 + 20 + 75 + 23 + + + + PushButton + + + + + + + + + + + + + + background-color: #ffffff; + border-radius: 10px; + padding: 10px; + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + 30 + + + + + color: #2c3e50; + padding: 10px; + + + + Employee Login + + + + + + + + + + + 0 + 0 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + 340 + 200 + + + + + 16 + + + + + + background-color: #ffffff; + border-radius: 15px; + padding: 10px; + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + padding:7 + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 120 + 0 + + + + + 12 + 75 + true + + + + + color: #2c3e50; + + + + Name : + + + + + + + background-color: rgb(168, 168, 168); + + + + + + + + + + + + + padding:7 + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 120 + 0 + + + + + 12 + 75 + true + + + + + color: #2c3e50; + + + + Password : + + + + + + + background-color: rgb(168, 168, 168); + + + + + + + + + + + + + padding:7 + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 60 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 150 + 0 + + + + QPushButton { + background-color: #3498db; + color: white; + font-family: 'Segoe UI'; + font-size: 16px; + font-weight: bold; + border-radius: 8px; + padding: 12px; + border: none; + } + QPushButton:hover { + background-color: #2980b9; + } + QPushButton:pressed { + background-color: #1c6ea4; + } + + + Submit + + + + + + + + + + + + + + + + + + + + + background-color: #ffffff; + border-radius: 10px; + padding: 10px; + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + 30 + + + + + color: #2c3e50; + padding: 10px; + + + + Admin Login + + + + + + + + + + + 0 + 0 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + 340 + 200 + + + + + 16 + + + + + + background-color: #ffffff; + border-radius: 15px; + padding: 10px; + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + padding:7 + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 120 + 0 + + + + + 12 + 75 + true + + + + + color: #2c3e50; + + + + Name : + + + + + + + background-color: rgb(168, 168, 168); + + + + + + + + + + + + + padding:7 + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 120 + 0 + + + + + 12 + 75 + true + + + + + color: #2c3e50; + + + + Password : + + + + + + + background-color: rgb(168, 168, 168); + + + + + + + + + + + + + padding:7 + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 60 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 150 + 0 + + + + QPushButton { + background-color: #3498db; + color: white; + font-family: 'Segoe UI'; + font-size: 16px; + font-weight: bold; + border-radius: 8px; + padding: 12px; + border: none; + } + QPushButton:hover { + background-color: #2980b9; + } + QPushButton:pressed { + background-color: #1c6ea4; + } + + + Submit + + + + + + + + + + + + + + + + + + + + + + From 45cac8ba7a37d42b1f385985fc92d35fd28a3f4d Mon Sep 17 00:00:00 2001 From: Pratyanj <109451378+pratyanj@users.noreply.github.com> Date: Fri, 30 May 2025 09:58:47 +0530 Subject: [PATCH 03/12] Custom new Qt lib base forntend started --- bank_managment_system/QTFrontend.py | 271 ++++++++++++++++++++++++++++ 1 file changed, 271 insertions(+) create mode 100644 bank_managment_system/QTFrontend.py diff --git a/bank_managment_system/QTFrontend.py b/bank_managment_system/QTFrontend.py new file mode 100644 index 00000000000..97485ce791d --- /dev/null +++ b/bank_managment_system/QTFrontend.py @@ -0,0 +1,271 @@ + +from PyQt5 import QtCore, QtGui, QtWidgets +import sys +import backend + +def create_styled_frame(parent, min_size=None, style=""): + """Create a styled QFrame with optional minimum size and custom style.""" + frame = QtWidgets.QFrame(parent) + frame.setFrameShape(QtWidgets.QFrame.StyledPanel) + frame.setFrameShadow(QtWidgets.QFrame.Raised) + if min_size: + frame.setMinimumSize(QtCore.QSize(*min_size)) + frame.setStyleSheet(style) + return frame + +def create_styled_label(parent, text, font_size=12, bold=False, style="color: #2c3e50; padding: 10px;"): + """Create a styled QLabel with customizable font size and boldness.""" + label = QtWidgets.QLabel(parent) + font = QtGui.QFont("Segoe UI", font_size) + if bold: + font.setBold(True) + font.setWeight(75) + label.setFont(font) + label.setStyleSheet(style) + label.setText(text) + return label + +def create_styled_button(parent, text, min_size=None): + """Create a styled QPushButton with hover and pressed effects.""" + button = QtWidgets.QPushButton(parent) + if min_size: + button.setMinimumSize(QtCore.QSize(*min_size)) + button.setStyleSheet(""" + QPushButton { + background-color: #3498db; + color: white; + font-family: 'Segoe UI'; + font-size: 16px; + font-weight: bold; + border-radius: 8px; + padding: 12px; + border: none; + } + QPushButton:hover { + background-color: #2980b9; + } + QPushButton:pressed { + background-color: #1c6ea4; + } + """) + button.setText(text) + return button + +def create_input_field(parent, label_text, min_label_size=(120, 0)): + """Create a horizontal layout with a label and a QLineEdit.""" + frame = create_styled_frame(parent, style="padding: 7px;") + layout = QtWidgets.QHBoxLayout(frame) + layout.setContentsMargins(0, 0, 0, 0) + layout.setSpacing(0) + + label = create_styled_label(frame, label_text, font_size=12, bold=True, style="color: #2c3e50;") + if min_label_size: + label.setMinimumSize(QtCore.QSize(*min_label_size)) + + line_edit = QtWidgets.QLineEdit(frame) + line_edit.setStyleSheet("background-color: rgb(168, 168, 168);") + + layout.addWidget(label) + layout.addWidget(line_edit) + return frame, line_edit + +def create_login_page(parent ,title, name_field_text="Name :", password_field_text="Password :", submit_text="Submit",): + """Create a login page with a title, name and password fields, and a submit button.""" + page = QtWidgets.QWidget(parent) + main_layout = QtWidgets.QVBoxLayout(page) + + # Header frame with title + header_frame = create_styled_frame(page, style="background-color: #ffffff; border-radius: 10px; padding: 10px;") + header_layout = QtWidgets.QVBoxLayout(header_frame) + title_label = create_styled_label(header_frame, title, font_size=30) + header_layout.addWidget(title_label, 0, QtCore.Qt.AlignHCenter | QtCore.Qt.AlignTop) + main_layout.addWidget(header_frame, 0, QtCore.Qt.AlignTop) + + # Content frame + content_frame = create_styled_frame(page) + content_frame.setSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Expanding) + content_layout = QtWidgets.QVBoxLayout(content_frame) + + # Form frame + form_frame = create_styled_frame(content_frame, min_size=(340, 200), style="background-color: #ffffff; border-radius: 15px; padding: 10px;") + form_layout = QtWidgets.QVBoxLayout(form_frame) + form_layout.setSpacing(20) + + # Input fields + name_frame, name_edit = create_input_field(form_frame, name_field_text) + password_frame, password_edit = create_input_field(form_frame, password_field_text) + + # Submit button + button_frame = create_styled_frame(form_frame, style="padding: 7px;") + button_layout = QtWidgets.QVBoxLayout(button_frame) + button_layout.setSpacing(60) + submit_button = create_styled_button(button_frame, submit_text, min_size=(150, 0)) + button_layout.addWidget(submit_button, 0, QtCore.Qt.AlignHCenter) + + form_layout.addWidget(name_frame) + form_layout.addWidget(password_frame) + form_layout.addWidget(button_frame) + + content_layout.addWidget(form_frame, 0, QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter) + main_layout.addWidget(content_frame) + + submit_button.clicked.connect(lambda: on_login_button_clicked(parent,name_edit, password_edit)) + + return page, name_edit, password_edit, submit_button +def on_login_button_clicked(parent,name_field, password_field): + # Get the entered name and password + name = name_field.text() + password = password_field.text() + # Check if the entered name and password are correct + if name == "" and password == "": + # Show a message box with the entered name and password + Dialog = QtWidgets.QDialog() + Dialog.setObjectName("Dialog") + Dialog.resize(317, 60) + verticalLayout = QtWidgets.QVBoxLayout(Dialog) + verticalLayout.setObjectName("verticalLayout") + label = QtWidgets.QLabel(Dialog) + label.setObjectName("label") + label.setText("Please enter both name and password") + verticalLayout.addWidget(label, 0, QtCore.Qt.AlignTop) + buttonBox = QtWidgets.QDialogButtonBox(Dialog) + buttonBox.setOrientation(QtCore.Qt.Horizontal) + buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok) + buttonBox.setObjectName("buttonBox") + verticalLayout.addWidget(buttonBox) + + buttonBox.accepted.connect(Dialog.accept) # type: ignore + buttonBox.rejected.connect(lambda:rejectBTN())# type: ignore + QtCore.QMetaObject.connectSlotsByName(Dialog) + def rejectBTN(): + parent.setCurrentIndex(0) + Dialog.reject() + # Show the dialog + Dialog.exec_() + else: + print(f"Name: {name}, Password: {password}") + +def create_home_page(parent, on_admin_clicked, on_employee_clicked, on_exit_clicked): + """Create the home page with Admin, Employee, and Exit buttons.""" + page = QtWidgets.QWidget(parent) + main_layout = QtWidgets.QVBoxLayout(page) + main_layout.setContentsMargins(20, 20, 20, 20) + main_layout.setSpacing(20) + + # Header frame with title + header_frame = create_styled_frame(page, style="background-color: #ffffff; border-radius: 10px; padding: 10px;") + header_layout = QtWidgets.QVBoxLayout(header_frame) + title_label = create_styled_label(header_frame, "Bank Management System", font_size=30) + header_layout.addWidget(title_label, 0, QtCore.Qt.AlignHCenter) + main_layout.addWidget(header_frame, 0, QtCore.Qt.AlignTop) + + # Button frame + button_frame = create_styled_frame(page) + button_frame.setSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Expanding) + button_layout = QtWidgets.QVBoxLayout(button_frame) + + # Button container + button_container = create_styled_frame(button_frame, min_size=(300, 0), style="background-color: #ffffff; border-radius: 15px; padding: 20px;") + button_container_layout = QtWidgets.QVBoxLayout(button_container) + button_container_layout.setSpacing(15) + + # Buttons + admin_button = create_styled_button(button_container, "Admin") + employee_button = create_styled_button(button_container, "Employee") + exit_button = create_styled_button(button_container, "Exit") + exit_button.setStyleSheet(""" + QPushButton { + background-color: #e74c3c; + color: white; + font-family: 'Segoe UI'; + font-size: 16px; + font-weight: bold; + border-radius: 8px; + padding: 12px; + border: none; + } + QPushButton:hover { + background-color: #c0392b; + } + QPushButton:pressed { + background-color: #992d22; + } + """) + + button_container_layout.addWidget(admin_button) + button_container_layout.addWidget(employee_button) + button_container_layout.addWidget(exit_button) + + button_layout.addWidget(button_container, 0, QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter) + main_layout.addWidget(button_frame) + + # Connect button signals + admin_button.clicked.connect(on_admin_clicked) + employee_button.clicked.connect(on_employee_clicked) + exit_button.clicked.connect(on_exit_clicked) + + return page + +def setup_main_window(main_window): + """Set up the main window with a stacked widget containing home, admin, and employee pages.""" + main_window.setObjectName("MainWindow") + main_window.resize(800, 600) + main_window.setStyleSheet("background-color: #f0f2f5;") + + central_widget = QtWidgets.QWidget(main_window) + main_layout = QtWidgets.QHBoxLayout(central_widget) + + stacked_widget = QtWidgets.QStackedWidget(central_widget) + + # Create pages + def switch_to_admin(): + stacked_widget.setCurrentIndex(1) + + def switch_to_employee(): + stacked_widget.setCurrentIndex(2) + + def exit_app(): + QtWidgets.QApplication.quit() + + home_page = create_home_page(stacked_widget, switch_to_admin, switch_to_employee, exit_app) + admin_page, admin_name, admin_password, admin_submit = create_login_page(stacked_widget, "Admin Login") + result = backend.check_admin(admin_name, admin_password) + + employee_page, employee_name, employee_password, employee_submit = create_login_page(stacked_widget, "Employee Login") + + + # Add pages to stacked widget + stacked_widget.addWidget(home_page) + stacked_widget.addWidget(admin_page) + stacked_widget.addWidget(employee_page) + + main_layout.addWidget(stacked_widget) + main_window.setCentralWidget(central_widget) + + # Set initial page + stacked_widget.setCurrentIndex(0) + + return stacked_widget, { + "admin_name": admin_name, + "admin_password": admin_password, + "admin_submit": admin_submit, + "employee_name": employee_name, + "employee_password": employee_password, + "employee_submit": employee_submit + } + +def main(): + """Main function to launch the application.""" + app = QtWidgets.QApplication(sys.argv) + main_window = QtWidgets.QMainWindow() + stacked_widget, widgets = setup_main_window(main_window) + + # Example: Connect submit buttons to print input values + + + main_window.show() + sys.exit(app.exec_()) + +if __name__ == "__main__": + main() + From 2820a5400f62a5d19afd60394d66b3b9f14c96c9 Mon Sep 17 00:00:00 2001 From: Pratyanj <109451378+pratyanj@users.noreply.github.com> Date: Fri, 30 May 2025 10:46:08 +0530 Subject: [PATCH 04/12] add admin menu page --- bank_managment_system/QTFrontend.py | 61 +++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/bank_managment_system/QTFrontend.py b/bank_managment_system/QTFrontend.py index 97485ce791d..c6d67e5ccde 100644 --- a/bank_managment_system/QTFrontend.py +++ b/bank_managment_system/QTFrontend.py @@ -2,7 +2,7 @@ from PyQt5 import QtCore, QtGui, QtWidgets import sys import backend - +backend.connect_database() def create_styled_frame(parent, min_size=None, style=""): """Create a styled QFrame with optional minimum size and custom style.""" frame = QtWidgets.QFrame(parent) @@ -206,6 +206,50 @@ def create_home_page(parent, on_admin_clicked, on_employee_clicked, on_exit_clic return page +def create_admin_menu_page(perent): + """Create the admin menu page with buttons for adding, deleting, and viewing accounts.""" + page = QtWidgets.QWidget(perent) + main_layout = QtWidgets.QVBoxLayout(page) + main_layout.setContentsMargins(20, 20, 20, 20) + main_layout.setSpacing(20) + + # Header frame with title + header_frame = create_styled_frame(page, style="background-color: #ffffff; border-radius: 10px; padding: 10px;") + header_layout = QtWidgets.QVBoxLayout(header_frame) + title_label = create_styled_label(header_frame, "Admin Menu", font_size=30) + header_layout.addWidget(title_label, 0, QtCore.Qt.AlignHCenter) + main_layout.addWidget(header_frame, 0, QtCore.Qt.AlignTop) + + # Button frame + button_frame = create_styled_frame(page) + button_frame.setSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Expanding) + button_layout = QtWidgets.QVBoxLayout(button_frame) + # Button container + button_container = create_styled_frame(button_frame, min_size=(300, 0), style="background-color: #ffffff; border-radius: 15px; padding: 20px;") + button_container_layout = QtWidgets.QVBoxLayout(button_container) + button_container_layout.setSpacing(15) + # Buttons + add_button = create_styled_button(button_container, "Add Employee") + update_employee = create_styled_button(button_container, "Update Employee") + employee_list = create_styled_button(button_container, "Employee List") + total_money = create_styled_button(button_container, "Total Money") + back_to_home = create_styled_button(button_container, "Back") + button_container_layout.addWidget(add_button) + button_container_layout.addWidget(update_employee) + button_container_layout.addWidget(employee_list) + button_container_layout.addWidget(total_money) + button_container_layout.addWidget(back_to_home) + button_layout.addWidget(button_container, 0, QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter) + main_layout.addWidget(button_frame) + # Connect button signals + # add_button.clicked.connect(on_add_employee_clicked) + # update_employee.clicked.connect(on_update_employee_clicked) + # employee_list.clicked.connect(on_employee_list_clicked) + # total_money.clicked.connect(on_total_money_clicked) + # back_to_home.clicked.connect(on_back_to_home_clicked) + return page + + def setup_main_window(main_window): """Set up the main window with a stacked widget containing home, admin, and employee pages.""" main_window.setObjectName("MainWindow") @@ -226,10 +270,20 @@ def switch_to_employee(): def exit_app(): QtWidgets.QApplication.quit() - + + def admin_login_menu_page(name, password): + result = backend.check_admin(name, password) + if result: + stacked_widget.setCurrentIndex(3) + else: + print("Invalid admin credentials") + home_page = create_home_page(stacked_widget, switch_to_admin, switch_to_employee, exit_app) admin_page, admin_name, admin_password, admin_submit = create_login_page(stacked_widget, "Admin Login") - result = backend.check_admin(admin_name, admin_password) + admin_submit.clicked.connect( + lambda: admin_login_menu_page(admin_name.text(), admin_password.text()) + ) + admin_menu_page = create_admin_menu_page(stacked_widget) employee_page, employee_name, employee_password, employee_submit = create_login_page(stacked_widget, "Employee Login") @@ -238,6 +292,7 @@ def exit_app(): stacked_widget.addWidget(home_page) stacked_widget.addWidget(admin_page) stacked_widget.addWidget(employee_page) + stacked_widget.addWidget(admin_menu_page) main_layout.addWidget(stacked_widget) main_window.setCentralWidget(central_widget) From 068c3f28a84c6bf1352503af52e5eb2ddcffdb59 Mon Sep 17 00:00:00 2001 From: Pratyanj <109451378+pratyanj@users.noreply.github.com> Date: Fri, 30 May 2025 12:10:46 +0530 Subject: [PATCH 05/12] change admin name and psw --- bank_managment_system/backend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bank_managment_system/backend.py b/bank_managment_system/backend.py index 62f9c2b36b8..c60dae4c4e4 100644 --- a/bank_managment_system/backend.py +++ b/bank_managment_system/backend.py @@ -35,7 +35,7 @@ def connect_database(): # Only insert admin if not exists cur.execute("SELECT COUNT(*) FROM admin") if cur.fetchone()[0] == 0: - cur.execute("INSERT INTO admin VALUES (?, ?)", ('arpit', '123')) + cur.execute("INSERT INTO admin VALUES (?, ?)", ('admin', 'admin123')) conn.commit() From 20be99f14349f8254ef62e8af2f3266577376f48 Mon Sep 17 00:00:00 2001 From: Pratyanj <109451378+pratyanj@users.noreply.github.com> Date: Fri, 30 May 2025 16:06:49 +0530 Subject: [PATCH 06/12] add pop msg notification --- bank_managment_system/QTFrontend.py | 84 +++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/bank_managment_system/QTFrontend.py b/bank_managment_system/QTFrontend.py index c6d67e5ccde..4d8c0b63508 100644 --- a/bank_managment_system/QTFrontend.py +++ b/bank_managment_system/QTFrontend.py @@ -68,7 +68,91 @@ def create_input_field(parent, label_text, min_label_size=(120, 0)): layout.addWidget(label) layout.addWidget(line_edit) return frame, line_edit +def pop_up_message(parent, message: str, page: int): + """Create a popup message box with a given message.""" + dialog = QtWidgets.QDialog(parent) + dialog.setWindowTitle("Message") + dialog.setFixedSize(350, 100) + dialog.setStyleSheet("background-color: #f0f0f0;") + + layout = QtWidgets.QVBoxLayout(dialog) + layout.setSpacing(10) + layout.setContentsMargins(15, 15, 15, 15) + + label = QtWidgets.QLabel(message) + label.setStyleSheet("font-size: 12px; color: #2c3e50;") + label.setWordWrap(True) + layout.addWidget(label) + + button_box = QtWidgets.QDialogButtonBox( + QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Cancel + ) + button_box.setStyleSheet(""" + QPushButton { + background-color: #3498db; + color: white; + border-radius: 4px; + padding: 6px 12px; + min-width: 80px; + } + QPushButton:hover { + background-color: #2980b9; + } + QPushButton:pressed { + background-color: #1c6ea4; + } + """) + layout.addWidget(button_box) + + button_box.accepted.connect(dialog.accept) + button_box.rejected.connect(lambda: reject_clicked(dialog, parent, page)) + + dialog.exec_() +def reject_clicked(dialog, parent, page): + parent.setCurrentIndex(page) + dialog.reject() + +def pop_up_message_with_only_ok(parent, message: str, page: int): + """Create a popup message box with only an OK button.""" + dialog = QtWidgets.QDialog(parent) + dialog.setWindowTitle("Message") + dialog.setFixedSize(350, 100) + dialog.setStyleSheet("background-color: #f0f0f0;") + + layout = QtWidgets.QVBoxLayout(dialog) + layout.setSpacing(10) + layout.setContentsMargins(15, 15, 15, 15) + + label = QtWidgets.QLabel(message) + label.setStyleSheet("font-size: 12px; color: #2c3e50;") + label.setWordWrap(True) + layout.addWidget(label) + + button_box = QtWidgets.QDialogButtonBox(QtWidgets.QDialogButtonBox.Ok) + button_box.setStyleSheet(""" + QPushButton { + background-color: #3498db; + color: white; + border-radius: 4px; + padding: 6px 12px; + min-width: 80px; + } + QPushButton:hover { + background-color: #2980b9; + } + QPushButton:pressed { + background-color: #1c6ea4; + } + """) + layout.addWidget(button_box) + + button_box.accepted.connect(lambda: accepted_clicked()) + def accepted_clicked(): + parent.setCurrentIndex(page) + dialog.close() + + dialog.exec_() def create_login_page(parent ,title, name_field_text="Name :", password_field_text="Password :", submit_text="Submit",): """Create a login page with a title, name and password fields, and a submit button.""" page = QtWidgets.QWidget(parent) From 06281a03a790be89287627febff79a2b312a1f3b Mon Sep 17 00:00:00 2001 From: Pratyanj <109451378+pratyanj@users.noreply.github.com> Date: Fri, 30 May 2025 16:07:15 +0530 Subject: [PATCH 07/12] add employe page done --- bank_managment_system/QTFrontend.py | 107 +++++++++++++++++++--------- 1 file changed, 75 insertions(+), 32 deletions(-) diff --git a/bank_managment_system/QTFrontend.py b/bank_managment_system/QTFrontend.py index 4d8c0b63508..38ff99ce869 100644 --- a/bank_managment_system/QTFrontend.py +++ b/bank_managment_system/QTFrontend.py @@ -203,29 +203,7 @@ def on_login_button_clicked(parent,name_field, password_field): # Check if the entered name and password are correct if name == "" and password == "": # Show a message box with the entered name and password - Dialog = QtWidgets.QDialog() - Dialog.setObjectName("Dialog") - Dialog.resize(317, 60) - verticalLayout = QtWidgets.QVBoxLayout(Dialog) - verticalLayout.setObjectName("verticalLayout") - label = QtWidgets.QLabel(Dialog) - label.setObjectName("label") - label.setText("Please enter both name and password") - verticalLayout.addWidget(label, 0, QtCore.Qt.AlignTop) - buttonBox = QtWidgets.QDialogButtonBox(Dialog) - buttonBox.setOrientation(QtCore.Qt.Horizontal) - buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok) - buttonBox.setObjectName("buttonBox") - verticalLayout.addWidget(buttonBox) - - buttonBox.accepted.connect(Dialog.accept) # type: ignore - buttonBox.rejected.connect(lambda:rejectBTN())# type: ignore - QtCore.QMetaObject.connectSlotsByName(Dialog) - def rejectBTN(): - parent.setCurrentIndex(0) - Dialog.reject() - # Show the dialog - Dialog.exec_() + pop_up_message(parent, "Please enter your name and password.",0) else: print(f"Name: {name}, Password: {password}") @@ -331,9 +309,53 @@ def create_admin_menu_page(perent): # employee_list.clicked.connect(on_employee_list_clicked) # total_money.clicked.connect(on_total_money_clicked) # back_to_home.clicked.connect(on_back_to_home_clicked) - return page + return page,add_button,update_employee,employee_list,total_money,back_to_home - +def create_add_employe_page(parent ,title, name_field_text="Name :", password_field_text="Password :",position_fielld_text="Position :",salary_field_text="Salary :",submit_text="Submit",): + """Create a login page with a title, name and password fields, and a submit button.""" + page = QtWidgets.QWidget(parent) + main_layout = QtWidgets.QVBoxLayout(page) + + # Header frame with title + header_frame = create_styled_frame(page, style="background-color: #ffffff; border-radius: 10px; padding: 10px;") + header_layout = QtWidgets.QVBoxLayout(header_frame) + title_label = create_styled_label(header_frame, title, font_size=30) + header_layout.addWidget(title_label, 0, QtCore.Qt.AlignHCenter | QtCore.Qt.AlignTop) + main_layout.addWidget(header_frame, 0, QtCore.Qt.AlignTop) + + # Content frame + content_frame = create_styled_frame(page) + content_frame.setSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Expanding) + content_layout = QtWidgets.QVBoxLayout(content_frame) + + # Form frame + form_frame = create_styled_frame(content_frame, min_size=(340, 200), style="background-color: #ffffff; border-radius: 15px; padding: 10px;") + form_layout = QtWidgets.QVBoxLayout(form_frame) + form_layout.setSpacing(20) + + # Input fields + name_frame, name_edit = create_input_field(form_frame, name_field_text) + password_frame, password_edit = create_input_field(form_frame, password_field_text) + salary_frame, salary_edit = create_input_field(form_frame, salary_field_text) + position_frame, position_edit = create_input_field(form_frame, position_fielld_text) + + # Submit button + button_frame = create_styled_frame(form_frame, style="padding: 7px;") + button_layout = QtWidgets.QVBoxLayout(button_frame) + button_layout.setSpacing(60) + submit_button = create_styled_button(button_frame, submit_text, min_size=(150, 0)) + button_layout.addWidget(submit_button, 0, QtCore.Qt.AlignHCenter) + + form_layout.addWidget(name_frame) + form_layout.addWidget(password_frame) + form_layout.addWidget(salary_frame) + form_layout.addWidget(position_frame) + form_layout.addWidget(button_frame) + + content_layout.addWidget(form_frame, 0, QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter) + main_layout.addWidget(content_frame) + + return page, name_edit, password_edit, salary_edit, position_edit,submit_button def setup_main_window(main_window): """Set up the main window with a stacked widget containing home, admin, and employee pages.""" main_window.setObjectName("MainWindow") @@ -360,23 +382,44 @@ def admin_login_menu_page(name, password): if result: stacked_widget.setCurrentIndex(3) else: - print("Invalid admin credentials") + print("Invalid admin credentials") + + def add_employee_form_submit(name, password, salary, position): + if ( + len(name) != 0 + and len(password) != 0 + and len(salary) != 0 + and len(position) != 0 + ): + backend.create_employee(name, password, salary, position) + pop_up_message_with_only_ok(stacked_widget,"Employee added successfully",3) + + else: + print("Please fill in all fields") + pop_up_message(stacked_widget,"Please fill in all fields",3) + home_page = create_home_page(stacked_widget, switch_to_admin, switch_to_employee, exit_app) admin_page, admin_name, admin_password, admin_submit = create_login_page(stacked_widget, "Admin Login") admin_submit.clicked.connect( lambda: admin_login_menu_page(admin_name.text(), admin_password.text()) ) - admin_menu_page = create_admin_menu_page(stacked_widget) - + admin_menu_page,add_button,update_employee,employee_list,total_money,back_to_home = create_admin_menu_page(stacked_widget) + add_button.clicked.connect(lambda:stacked_widget.setCurrentIndex(4)) + # create employee page + add_employe_page , new_employee_name, new_employee_password, new_employe_salary, new_employe_position, new_employee_submit = create_add_employe_page(stacked_widget, "Add Employee") + new_employee_submit.clicked.connect( + lambda: add_employee_form_submit(new_employee_name.text(), new_employee_password.text(), new_employe_salary.text(), new_employe_position.text()) + ) employee_page, employee_name, employee_password, employee_submit = create_login_page(stacked_widget, "Employee Login") # Add pages to stacked widget - stacked_widget.addWidget(home_page) - stacked_widget.addWidget(admin_page) - stacked_widget.addWidget(employee_page) - stacked_widget.addWidget(admin_menu_page) + stacked_widget.addWidget(home_page)#1 + stacked_widget.addWidget(admin_page)#2 + stacked_widget.addWidget(employee_page)#3 + stacked_widget.addWidget(admin_menu_page)#4 + stacked_widget.addWidget(add_employe_page)#5 main_layout.addWidget(stacked_widget) main_window.setCentralWidget(central_widget) From d285037ead956f269c707e1854727515a5ef904e Mon Sep 17 00:00:00 2001 From: Pratyanj <109451378+pratyanj@users.noreply.github.com> Date: Fri, 30 May 2025 16:07:32 +0530 Subject: [PATCH 08/12] small change --- bank_managment_system/backend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bank_managment_system/backend.py b/bank_managment_system/backend.py index c60dae4c4e4..42475416fa0 100644 --- a/bank_managment_system/backend.py +++ b/bank_managment_system/backend.py @@ -167,4 +167,4 @@ def get_detail(acc_no): # Check if employee exists def check_name_in_staff(name): cur.execute("SELECT 1 FROM staff WHERE name = ?", (name,)) - return cur.fetchone() is not Non \ No newline at end of file + return cur.fetchone() is not None \ No newline at end of file From 1a4a91927ad15b97bf23276d36bfe5bbf1f33a77 Mon Sep 17 00:00:00 2001 From: Pratyanj <109451378+pratyanj@users.noreply.github.com> Date: Fri, 30 May 2025 17:25:40 +0530 Subject: [PATCH 09/12] reduce code and improve it by reusable function block --- bank_managment_system/QTFrontend.py | 268 +++++++++++++--------------- 1 file changed, 126 insertions(+), 142 deletions(-) diff --git a/bank_managment_system/QTFrontend.py b/bank_managment_system/QTFrontend.py index 38ff99ce869..33f104aca31 100644 --- a/bank_managment_system/QTFrontend.py +++ b/bank_managment_system/QTFrontend.py @@ -68,8 +68,15 @@ def create_input_field(parent, label_text, min_label_size=(120, 0)): layout.addWidget(label) layout.addWidget(line_edit) return frame, line_edit -def pop_up_message(parent, message: str, page: int): - """Create a popup message box with a given message.""" +def show_popup_message(parent, message: str, page: int = None, show_cancel: bool = True): + """Reusable popup message box. + + Args: + parent: The parent widget. + message (str): The message to display. + page (int, optional): Page index to switch to after dialog closes. + show_cancel (bool): Whether to show the Cancel button. + """ dialog = QtWidgets.QDialog(parent) dialog.setWindowTitle("Message") dialog.setFixedSize(350, 100) @@ -84,9 +91,14 @@ def pop_up_message(parent, message: str, page: int): label.setWordWrap(True) layout.addWidget(label) - button_box = QtWidgets.QDialogButtonBox( - QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Cancel - ) + # Decide which buttons to show + if show_cancel: + button_box = QtWidgets.QDialogButtonBox( + QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Cancel + ) + else: + button_box = QtWidgets.QDialogButtonBox(QtWidgets.QDialogButtonBox.Ok) + button_box.setStyleSheet(""" QPushButton { background-color: #3498db; @@ -104,66 +116,24 @@ def pop_up_message(parent, message: str, page: int): """) layout.addWidget(button_box) - button_box.accepted.connect(dialog.accept) - button_box.rejected.connect(lambda: reject_clicked(dialog, parent, page)) - - dialog.exec_() - -def reject_clicked(dialog, parent, page): - parent.setCurrentIndex(page) - dialog.reject() - -def pop_up_message_with_only_ok(parent, message: str, page: int): - """Create a popup message box with only an OK button.""" - dialog = QtWidgets.QDialog(parent) - dialog.setWindowTitle("Message") - dialog.setFixedSize(350, 100) - dialog.setStyleSheet("background-color: #f0f0f0;") + # Connect buttons + def on_accept(): + if page is not None: + parent.setCurrentIndex(page) + dialog.accept() - layout = QtWidgets.QVBoxLayout(dialog) - layout.setSpacing(10) - layout.setContentsMargins(15, 15, 15, 15) - - label = QtWidgets.QLabel(message) - label.setStyleSheet("font-size: 12px; color: #2c3e50;") - label.setWordWrap(True) - layout.addWidget(label) - - button_box = QtWidgets.QDialogButtonBox(QtWidgets.QDialogButtonBox.Ok) - button_box.setStyleSheet(""" - QPushButton { - background-color: #3498db; - color: white; - border-radius: 4px; - padding: 6px 12px; - min-width: 80px; - } - QPushButton:hover { - background-color: #2980b9; - } - QPushButton:pressed { - background-color: #1c6ea4; - } - """) - layout.addWidget(button_box) + def on_reject(): + if page is not None: + parent.setCurrentIndex(page) + dialog.reject() - button_box.accepted.connect(lambda: accepted_clicked()) - def accepted_clicked(): - parent.setCurrentIndex(page) - dialog.close() + button_box.accepted.connect(on_accept) + button_box.rejected.connect(on_reject) dialog.exec_() def create_login_page(parent ,title, name_field_text="Name :", password_field_text="Password :", submit_text="Submit",): """Create a login page with a title, name and password fields, and a submit button.""" - page = QtWidgets.QWidget(parent) - main_layout = QtWidgets.QVBoxLayout(page) - - # Header frame with title - header_frame = create_styled_frame(page, style="background-color: #ffffff; border-radius: 10px; padding: 10px;") - header_layout = QtWidgets.QVBoxLayout(header_frame) - title_label = create_styled_label(header_frame, title, font_size=30) - header_layout.addWidget(title_label, 0, QtCore.Qt.AlignHCenter | QtCore.Qt.AlignTop) - main_layout.addWidget(header_frame, 0, QtCore.Qt.AlignTop) + page, main_layout = create_page_with_header(parent, "Admin Menu") # Content frame content_frame = create_styled_frame(page) @@ -203,23 +173,13 @@ def on_login_button_clicked(parent,name_field, password_field): # Check if the entered name and password are correct if name == "" and password == "": # Show a message box with the entered name and password - pop_up_message(parent, "Please enter your name and password.",0) + show_popup_message(parent, "Please enter your name and password.",0) else: print(f"Name: {name}, Password: {password}") def create_home_page(parent, on_admin_clicked, on_employee_clicked, on_exit_clicked): """Create the home page with Admin, Employee, and Exit buttons.""" - page = QtWidgets.QWidget(parent) - main_layout = QtWidgets.QVBoxLayout(page) - main_layout.setContentsMargins(20, 20, 20, 20) - main_layout.setSpacing(20) - - # Header frame with title - header_frame = create_styled_frame(page, style="background-color: #ffffff; border-radius: 10px; padding: 10px;") - header_layout = QtWidgets.QVBoxLayout(header_frame) - title_label = create_styled_label(header_frame, "Bank Management System", font_size=30) - header_layout.addWidget(title_label, 0, QtCore.Qt.AlignHCenter) - main_layout.addWidget(header_frame, 0, QtCore.Qt.AlignTop) + page, main_layout = create_page_with_header(parent, "Admin Menu") # Button frame button_frame = create_styled_frame(page) @@ -267,95 +227,78 @@ def create_home_page(parent, on_admin_clicked, on_employee_clicked, on_exit_clic exit_button.clicked.connect(on_exit_clicked) return page - -def create_admin_menu_page(perent): - """Create the admin menu page with buttons for adding, deleting, and viewing accounts.""" - page = QtWidgets.QWidget(perent) +def create_page_with_header(parent, title_text): + """Create a page with a styled header and return the page + main layout.""" + page = QtWidgets.QWidget(parent) main_layout = QtWidgets.QVBoxLayout(page) main_layout.setContentsMargins(20, 20, 20, 20) main_layout.setSpacing(20) - # Header frame with title header_frame = create_styled_frame(page, style="background-color: #ffffff; border-radius: 10px; padding: 10px;") header_layout = QtWidgets.QVBoxLayout(header_frame) - title_label = create_styled_label(header_frame, "Admin Menu", font_size=30) - header_layout.addWidget(title_label, 0, QtCore.Qt.AlignHCenter) + title_label = create_styled_label(header_frame, title_text, font_size=30) + header_layout.addWidget(title_label, 0, QtCore.Qt.AlignHCenter | QtCore.Qt.AlignTop) + main_layout.addWidget(header_frame, 0, QtCore.Qt.AlignTop) + return page, main_layout +def create_admin_menu_page(parent): + page, main_layout = create_page_with_header(parent, "Admin Menu") - # Button frame button_frame = create_styled_frame(page) button_frame.setSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Expanding) button_layout = QtWidgets.QVBoxLayout(button_frame) - # Button container + button_container = create_styled_frame(button_frame, min_size=(300, 0), style="background-color: #ffffff; border-radius: 15px; padding: 20px;") button_container_layout = QtWidgets.QVBoxLayout(button_container) button_container_layout.setSpacing(15) - # Buttons - add_button = create_styled_button(button_container, "Add Employee") - update_employee = create_styled_button(button_container, "Update Employee") - employee_list = create_styled_button(button_container, "Employee List") - total_money = create_styled_button(button_container, "Total Money") - back_to_home = create_styled_button(button_container, "Back") - button_container_layout.addWidget(add_button) - button_container_layout.addWidget(update_employee) - button_container_layout.addWidget(employee_list) - button_container_layout.addWidget(total_money) - button_container_layout.addWidget(back_to_home) + + # Define button labels + button_labels = ["Add Employee", "Update Employee", "Employee List", "Total Money", "Back"] + buttons = [] + + for label in button_labels: + btn = create_styled_button(button_container, label) + button_container_layout.addWidget(btn) + buttons.append(btn) + button_layout.addWidget(button_container, 0, QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter) main_layout.addWidget(button_frame) - # Connect button signals - # add_button.clicked.connect(on_add_employee_clicked) - # update_employee.clicked.connect(on_update_employee_clicked) - # employee_list.clicked.connect(on_employee_list_clicked) - # total_money.clicked.connect(on_total_money_clicked) - # back_to_home.clicked.connect(on_back_to_home_clicked) - return page,add_button,update_employee,employee_list,total_money,back_to_home - -def create_add_employe_page(parent ,title, name_field_text="Name :", password_field_text="Password :",position_fielld_text="Position :",salary_field_text="Salary :",submit_text="Submit",): - """Create a login page with a title, name and password fields, and a submit button.""" - page = QtWidgets.QWidget(parent) - main_layout = QtWidgets.QVBoxLayout(page) - - # Header frame with title - header_frame = create_styled_frame(page, style="background-color: #ffffff; border-radius: 10px; padding: 10px;") - header_layout = QtWidgets.QVBoxLayout(header_frame) - title_label = create_styled_label(header_frame, title, font_size=30) - header_layout.addWidget(title_label, 0, QtCore.Qt.AlignHCenter | QtCore.Qt.AlignTop) - main_layout.addWidget(header_frame, 0, QtCore.Qt.AlignTop) + + return page, *buttons # Unpack as add_button, update_employee, etc. + - # Content frame +def create_add_employee_page(parent, title, submit_text="Submit"): + page, main_layout = create_page_with_header(parent, title) + content_frame = create_styled_frame(page) content_frame.setSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Expanding) content_layout = QtWidgets.QVBoxLayout(content_frame) - - # Form frame + form_frame = create_styled_frame(content_frame, min_size=(340, 200), style="background-color: #ffffff; border-radius: 15px; padding: 10px;") form_layout = QtWidgets.QVBoxLayout(form_frame) form_layout.setSpacing(20) - - # Input fields - name_frame, name_edit = create_input_field(form_frame, name_field_text) - password_frame, password_edit = create_input_field(form_frame, password_field_text) - salary_frame, salary_edit = create_input_field(form_frame, salary_field_text) - position_frame, position_edit = create_input_field(form_frame, position_fielld_text) - + + # Define input fields + fields = ["Name :", "Password :", "Salary :", "Position :"] + edits = [] + + for field in fields: + field_frame, field_edit = create_input_field(form_frame, field) + form_layout.addWidget(field_frame) + edits.append(field_edit) + # Submit button button_frame = create_styled_frame(form_frame, style="padding: 7px;") button_layout = QtWidgets.QVBoxLayout(button_frame) - button_layout.setSpacing(60) submit_button = create_styled_button(button_frame, submit_text, min_size=(150, 0)) button_layout.addWidget(submit_button, 0, QtCore.Qt.AlignHCenter) - - form_layout.addWidget(name_frame) - form_layout.addWidget(password_frame) - form_layout.addWidget(salary_frame) - form_layout.addWidget(position_frame) + form_layout.addWidget(button_frame) - content_layout.addWidget(form_frame, 0, QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter) main_layout.addWidget(content_frame) - - return page, name_edit, password_edit, salary_edit, position_edit,submit_button + + return page, *edits, submit_button # Unpack as name_edit, password_edit, etc. + def setup_main_window(main_window): """Set up the main window with a stacked widget containing home, admin, and employee pages.""" main_window.setObjectName("MainWindow") @@ -383,6 +326,7 @@ def admin_login_menu_page(name, password): stacked_widget.setCurrentIndex(3) else: print("Invalid admin credentials") + show_popup_message(stacked_widget,"Invalid admin credentials",0) def add_employee_form_submit(name, password, salary, position): if ( @@ -392,26 +336,66 @@ def add_employee_form_submit(name, password, salary, position): and len(position) != 0 ): backend.create_employee(name, password, salary, position) - pop_up_message_with_only_ok(stacked_widget,"Employee added successfully",3) + show_popup_message(stacked_widget,"Employee added successfully",3,False) else: print("Please fill in all fields") - pop_up_message(stacked_widget,"Please fill in all fields",3) + show_popup_message(stacked_widget,"Please fill in all fields",3) - home_page = create_home_page(stacked_widget, switch_to_admin, switch_to_employee, exit_app) - admin_page, admin_name, admin_password, admin_submit = create_login_page(stacked_widget, "Admin Login") + # Create Home Page + home_page = create_home_page( + stacked_widget, + switch_to_admin, + switch_to_employee, + exit_app + ) + + # Create Admin Login Page + admin_page, admin_name, admin_password, admin_submit = create_login_page( + stacked_widget, + title="Admin Login" + ) + admin_password.setEchoMode(QtWidgets.QLineEdit.Password) + admin_name.setFont(QtGui.QFont("Arial", 10)) + admin_password.setFont(QtGui.QFont("Arial", 10)) + admin_name.setPlaceholderText("Enter your name") + admin_password.setPlaceholderText("Enter your password") + admin_submit.clicked.connect( - lambda: admin_login_menu_page(admin_name.text(), admin_password.text()) + lambda: admin_login_menu_page( + admin_name.text(), + admin_password.text() + ) + ) + + # Create Admin Menu Page + admin_menu_page, add_button, update_button, list_button, money_button, back_button = create_admin_menu_page( + stacked_widget ) - admin_menu_page,add_button,update_employee,employee_list,total_money,back_to_home = create_admin_menu_page(stacked_widget) - add_button.clicked.connect(lambda:stacked_widget.setCurrentIndex(4)) - # create employee page - add_employe_page , new_employee_name, new_employee_password, new_employe_salary, new_employe_position, new_employee_submit = create_add_employe_page(stacked_widget, "Add Employee") - new_employee_submit.clicked.connect( - lambda: add_employee_form_submit(new_employee_name.text(), new_employee_password.text(), new_employe_salary.text(), new_employe_position.text()) + + add_button.clicked.connect(lambda: stacked_widget.setCurrentIndex(4)) + + # Create Add Employee Page + add_employee_page, emp_name, emp_password, emp_salary, emp_position, emp_submit = create_add_employee_page( + stacked_widget, + title="Add Employee" + ) + + emp_submit.clicked.connect( + lambda: add_employee_form_submit( + emp_name.text(), + emp_password.text(), + emp_salary.text(), + emp_position.text() + ) + ) + + # Create Employee Login Page + employee_page, employee_name, employee_password, employee_submit = create_login_page( + stacked_widget, + title="Employee Login" ) - employee_page, employee_name, employee_password, employee_submit = create_login_page(stacked_widget, "Employee Login") # Add pages to stacked widget @@ -419,7 +403,7 @@ def add_employee_form_submit(name, password, salary, position): stacked_widget.addWidget(admin_page)#2 stacked_widget.addWidget(employee_page)#3 stacked_widget.addWidget(admin_menu_page)#4 - stacked_widget.addWidget(add_employe_page)#5 + stacked_widget.addWidget(add_employee_page)#5 main_layout.addWidget(stacked_widget) main_window.setCentralWidget(central_widget) From aa0a6d1217358f56811cb1011bd9da98f167999e Mon Sep 17 00:00:00 2001 From: Pratyanj <109451378+pratyanj@users.noreply.github.com> Date: Sat, 31 May 2025 16:38:53 +0530 Subject: [PATCH 10/12] update employee page created --- bank_managment_system/QTFrontend.py | 87 +++++++++++++++++++++++++---- 1 file changed, 77 insertions(+), 10 deletions(-) diff --git a/bank_managment_system/QTFrontend.py b/bank_managment_system/QTFrontend.py index 33f104aca31..145a743749b 100644 --- a/bank_managment_system/QTFrontend.py +++ b/bank_managment_system/QTFrontend.py @@ -131,6 +131,31 @@ def on_reject(): button_box.rejected.connect(on_reject) dialog.exec_() +def get_employee_name(parent,name_field_text="Enter Employee Name"): + page, main_layout = create_page_with_header(parent, "Employee Data Update") + + # Content frame + content_frame = create_styled_frame(page) + content_frame.setSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Expanding) + content_layout = QtWidgets.QVBoxLayout(content_frame) + # Form frame + form_frame = create_styled_frame(content_frame, min_size=(340, 200), style="background-color: #ffffff; border-radius: 15px; padding: 10px;") + form_layout = QtWidgets.QVBoxLayout(form_frame) + # Form fields + name_label, name_field = create_input_field(form_frame, name_field_text) + search_button = create_styled_button(form_frame, "Search", min_size=(100, 30)) + form_layout.addWidget(name_label) + form_layout.addWidget(search_button) + + search_button.clicked.connect(lambda: backend.check_name_in_staff()) + def on_search_button_clicked(): + fetch = backend.check_name_in_staff() + if fetch: + print(f"Employee data: {fetch[0]}, {fetch[1]}, {fetch[2]}, {fetch[3]},") + else: + print("Employee not found.") + + #backend.check_name_in_staff() def create_login_page(parent ,title, name_field_text="Name :", password_field_text="Password :", submit_text="Submit",): """Create a login page with a title, name and password fields, and a submit button.""" page, main_layout = create_page_with_header(parent, "Admin Menu") @@ -267,7 +292,7 @@ def create_admin_menu_page(parent): return page, *buttons # Unpack as add_button, update_employee, etc. -def create_add_employee_page(parent, title, submit_text="Submit"): +def create_add_employee_page(parent, title, submit_text="Submit",update_btn:bool=False): page, main_layout = create_page_with_header(parent, title) content_frame = create_styled_frame(page) @@ -290,15 +315,22 @@ def create_add_employee_page(parent, title, submit_text="Submit"): # Submit button button_frame = create_styled_frame(form_frame, style="padding: 7px;") button_layout = QtWidgets.QVBoxLayout(button_frame) + update_button = create_styled_button(button_frame, "Update", min_size=(150, 0)) submit_button = create_styled_button(button_frame, submit_text, min_size=(150, 0)) - button_layout.addWidget(submit_button, 0, QtCore.Qt.AlignHCenter) + if update_btn: + button_layout.addWidget(update_button, 0, QtCore.Qt.AlignHCenter) + else: + button_layout.addWidget(submit_button, 0, QtCore.Qt.AlignHCenter) + form_layout.addWidget(button_frame) content_layout.addWidget(form_frame, 0, QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter) main_layout.addWidget(content_frame) - - return page, *edits, submit_button # Unpack as name_edit, password_edit, etc. - + if update_btn: + return page, *edits, update_button + else: + return page, *edits, submit_button # Unpack as name_edit, password_edit, etc. + def setup_main_window(main_window): """Set up the main window with a stacked widget containing home, admin, and employee pages.""" main_window.setObjectName("MainWindow") @@ -341,6 +373,31 @@ def add_employee_form_submit(name, password, salary, position): else: print("Please fill in all fields") show_popup_message(stacked_widget,"Please fill in all fields",3) + def update_employee_data(name, password, salary, position, name_to_update): + try: + cur = backend.cur + if name_to_update: + cur.execute("UPDATE staff SET Name = ? WHERE name = ?", (name, name_to_update)) + + cur.execute("UPDATE staff SET Name = ? WHERE name = ?", (password, name)) + cur.execute("UPDATE staff SET password = ? WHERE name = ?", (password, name)) + cur.execute("UPDATE staff SET salary = ? WHERE name = ?", (salary, name)) + cur.execute("UPDATE staff SET position = ? WHERE name = ?", (position, name)) + backend.conn.commit() + show_popup_message(stacked_widget,"Employee Upadate successfully",3,False) + + except: + show_popup_message(stacked_widget,"Please fill in all fields",3) + + def fetch_employee_data(name): + try: + cur = backend.cur + cur.execute("SELECT * FROM staff WHERE name = ?", (name,)) + employee_data = cur.fetchone() + return employee_data + except: + print("Error fetching employee data") + return None # Create Home Page @@ -375,13 +432,22 @@ def add_employee_form_submit(name, password, salary, position): ) add_button.clicked.connect(lambda: stacked_widget.setCurrentIndex(4)) + update_button.clicked.connect(lambda: stacked_widget.setCurrentIndex(5)) # Create Add Employee Page add_employee_page, emp_name, emp_password, emp_salary, emp_position, emp_submit = create_add_employee_page( stacked_widget, title="Add Employee" ) + + # Update Employee Page + update_employee_page1 = get_employee_name(stacked_widget) + # apply the update_employee_data function to the submit button + + + + # /////////////////////////// emp_submit.clicked.connect( lambda: add_employee_form_submit( emp_name.text(), @@ -399,11 +465,12 @@ def add_employee_form_submit(name, password, salary, position): # Add pages to stacked widget - stacked_widget.addWidget(home_page)#1 - stacked_widget.addWidget(admin_page)#2 - stacked_widget.addWidget(employee_page)#3 - stacked_widget.addWidget(admin_menu_page)#4 - stacked_widget.addWidget(add_employee_page)#5 + stacked_widget.addWidget(home_page)#0 + stacked_widget.addWidget(admin_page)#1 + stacked_widget.addWidget(employee_page)#2 + stacked_widget.addWidget(admin_menu_page)#3 + stacked_widget.addWidget(add_employee_page)#4 + stacked_widget.addWidget(update_employee_page1)#5 main_layout.addWidget(stacked_widget) main_window.setCentralWidget(central_widget) From 0ef17a1f083818f94d7518adf8b4ec1da9212ded Mon Sep 17 00:00:00 2001 From: Pratyanj <109451378+pratyanj@users.noreply.github.com> Date: Sat, 31 May 2025 16:40:19 +0530 Subject: [PATCH 11/12] add database in gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 1f15459f4de..0f3717818e6 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,4 @@ print(lower+upper+odd+even) # thumbnail cache on Windows Thumbs.db +bankmanaging.db \ No newline at end of file From a24cb1b68dbcb90dca1657ea950601999a1d6de2 Mon Sep 17 00:00:00 2001 From: Pratyanj <109451378+pratyanj@users.noreply.github.com> Date: Tue, 3 Jun 2025 15:27:24 +0530 Subject: [PATCH 12/12] employee search page done --- bank_managment_system/QTFrontend.py | 82 ++++++++++++++++++++--------- 1 file changed, 56 insertions(+), 26 deletions(-) diff --git a/bank_managment_system/QTFrontend.py b/bank_managment_system/QTFrontend.py index 145a743749b..08fa1143ef5 100644 --- a/bank_managment_system/QTFrontend.py +++ b/bank_managment_system/QTFrontend.py @@ -131,29 +131,48 @@ def on_reject(): button_box.rejected.connect(on_reject) dialog.exec_() -def get_employee_name(parent,name_field_text="Enter Employee Name"): +def get_employee_name(parent, name_field_text="Enter Employee Name"): page, main_layout = create_page_with_header(parent, "Employee Data Update") # Content frame content_frame = create_styled_frame(page) content_frame.setSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Expanding) content_layout = QtWidgets.QVBoxLayout(content_frame) + # Form frame form_frame = create_styled_frame(content_frame, min_size=(340, 200), style="background-color: #ffffff; border-radius: 15px; padding: 10px;") form_layout = QtWidgets.QVBoxLayout(form_frame) + # Form fields name_label, name_field = create_input_field(form_frame, name_field_text) search_button = create_styled_button(form_frame, "Search", min_size=(100, 30)) form_layout.addWidget(name_label) form_layout.addWidget(search_button) + content_layout.addWidget(form_frame, 0, QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter) + main_layout.addWidget(content_frame) - search_button.clicked.connect(lambda: backend.check_name_in_staff()) def on_search_button_clicked(): - fetch = backend.check_name_in_staff() - if fetch: - print(f"Employee data: {fetch[0]}, {fetch[1]}, {fetch[2]}, {fetch[3]},") - else: - print("Employee not found.") + entered_name = name_field.text().strip() + if not entered_name: + QtWidgets.QMessageBox.warning(parent, "Input Error", "Please enter an employee name.") + return + + try: + cur = backend.cur + cur.execute("SELECT * FROM staff WHERE name = ?", (entered_name,)) + fetch = cur.fetchone() + if fetch: + QtWidgets.QMessageBox.information(parent, "Employee Found", + f"Employee data:\nID: {fetch[0]}\nName: {fetch[1]}\nDept: {fetch[2]}\nRole: {fetch[3]}") + else: + QtWidgets.QMessageBox.information(parent, "Not Found", "Employee not found.") + except Exception as e: + QtWidgets.QMessageBox.critical(parent, "Error", f"An error occurred: {str(e)}") + + search_button.clicked.connect(on_search_button_clicked) + + return page + #backend.check_name_in_staff() def create_login_page(parent ,title, name_field_text="Name :", password_field_text="Password :", submit_text="Submit",): @@ -188,19 +207,25 @@ def create_login_page(parent ,title, name_field_text="Name :", password_field_te content_layout.addWidget(form_frame, 0, QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter) main_layout.addWidget(content_frame) - submit_button.clicked.connect(lambda: on_login_button_clicked(parent,name_edit, password_edit)) + return page, name_edit, password_edit, submit_button -def on_login_button_clicked(parent,name_field, password_field): - # Get the entered name and password - name = name_field.text() - password = password_field.text() - # Check if the entered name and password are correct - if name == "" and password == "": - # Show a message box with the entered name and password - show_popup_message(parent, "Please enter your name and password.",0) +def on_login_button_clicked(parent, name_field, password_field): + name = name_field.text().strip() + password = password_field.text().strip() + + if not name or not password: + show_popup_message(parent, "Please enter your name and password.", 0) else: - print(f"Name: {name}, Password: {password}") + try: + # Ideally, here you'd call a backend authentication check + success = backend.check_admin(name, password) + if success: + QtWidgets.QMessageBox.information(parent, "Login Successful", f"Welcome, {name}!") + else: + QtWidgets.QMessageBox.warning(parent, "Login Failed", "Incorrect name or password.") + except Exception as e: + QtWidgets.QMessageBox.critical(parent, "Error", f"An error occurred during login: {str(e)}") def create_home_page(parent, on_admin_clicked, on_employee_clicked, on_exit_clicked): """Create the home page with Admin, Employee, and Exit buttons.""" @@ -315,11 +340,11 @@ def create_add_employee_page(parent, title, submit_text="Submit",update_btn:bool # Submit button button_frame = create_styled_frame(form_frame, style="padding: 7px;") button_layout = QtWidgets.QVBoxLayout(button_frame) - update_button = create_styled_button(button_frame, "Update", min_size=(150, 0)) - submit_button = create_styled_button(button_frame, submit_text, min_size=(150, 0)) if update_btn: + update_button = create_styled_button(button_frame, "Update", min_size=(150, 0)) button_layout.addWidget(update_button, 0, QtCore.Qt.AlignHCenter) else: + submit_button = create_styled_button(button_frame, submit_text, min_size=(150, 0)) button_layout.addWidget(submit_button, 0, QtCore.Qt.AlignHCenter) @@ -353,12 +378,17 @@ def exit_app(): QtWidgets.QApplication.quit() def admin_login_menu_page(name, password): - result = backend.check_admin(name, password) - if result: - stacked_widget.setCurrentIndex(3) - else: - print("Invalid admin credentials") - show_popup_message(stacked_widget,"Invalid admin credentials",0) + try: + # Ideally, here you'd call a backend authentication check + success = backend.check_admin(name, password) + if success: + QtWidgets.QMessageBox.information(stacked_widget, "Login Successful", f"Welcome, {name}!") + stacked_widget.setCurrentIndex(3) + else: + QtWidgets.QMessageBox.warning(stacked_widget, "Login Failed", "Incorrect name or password.") + except Exception as e: + QtWidgets.QMessageBox.critical(stacked_widget, "Error", f"An error occurred during login: {str(e)}") + # show_popup_message(stacked_widget,"Invalid admin credentials",0) def add_employee_form_submit(name, password, salary, position): if ( @@ -476,7 +506,7 @@ def fetch_employee_data(name): main_window.setCentralWidget(central_widget) # Set initial page - stacked_widget.setCurrentIndex(0) + stacked_widget.setCurrentIndex(5) return stacked_widget, { "admin_name": admin_name,