0% found this document useful (0 votes)
14 views

Bms Frontend Code

Uploaded by

Rishi Ram
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Bms Frontend Code

Uploaded by

Rishi Ram
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

import cx_Oracle

import tkinter as tk
from tkinter import ttk
from tkinter import simpledialog

# Connect to the Oracle database


connection = cx_Oracle.connect("admin/Rishi*[email protected]
1.rds.amazonaws.com:1521/ORCL")
cursor = connection.cursor()

# Create the main window


root = tk.Tk()
root.title("Bank Management System")

# Switch frame function


def switch_frame(frame):
frame.tkraise()

# Function to handle login


def login_user():
username = username_entry.get()
password = password_entry.get()
cursor.execute("SELECT * FROM Users WHERE username = :username AND password
= :password AND user_type = 'Customer'", {'username': username, 'password':
password})
user = cursor.fetchone()
if user:
switch_frame(customer_frame)
# Retrieve and display person details for the logged-in customer
cursor.execute("SELECT * FROM Person WHERE PersonID = :person_id",
{'person_id': user[3]})
person_details = cursor.fetchone()
if person_details:
person_details_label.config(text=f"Personal Details:\nFirst Name:
{person_details[1]}\nLast Name: {person_details[2]}\nDate of Birth:
{person_details[3]}\nAddress: {person_details[4]}\nPhone: {person_details[5]}\
nEmail: {person_details[6]}")
else:
error_label.config(text="Invalid username or password")

# Function to handle checking balance


def check_balance():
account_number = simpledialog.askinteger("Input", "Enter Account Number:")
if account_number is not None:
cursor.execute("SELECT Balance FROM Account WHERE AccountNumber
= :account_number", {'account_number': account_number})
balance = cursor.fetchone()
if balance:
balance_label.config(text=f"Account Balance: {balance[0]}")
else:
balance_label.config(text="Account not found")

# Function to handle withdrawing money


def withdraw_money():
account_number = simpledialog.askinteger("Input", "Enter Account Number:")
if account_number is not None:
cursor.execute("SELECT Balance FROM Account WHERE AccountNumber
= :account_number", {'account_number': account_number})
balance = cursor.fetchone()
if balance:
amount = simpledialog.askfloat("Input", "Enter Amount to Withdraw:")
if amount is not None:
if amount <= balance[0]:
new_balance = balance[0] - amount
cursor.execute("UPDATE Account SET Balance = :new_balance WHERE
AccountNumber = :account_number", {'new_balance': new_balance, 'account_number':
account_number})
connection.commit()
balance_label.config(text=f"New Account Balance:
{new_balance}")
else:
balance_label.config(text="Insufficient balance")
else:
balance_label.config(text="Account not found")

# Function to handle depositing money


def deposit_money():
account_number = simpledialog.askinteger("Input", "Enter Account Number:")
if account_number is not None:
cursor.execute("SELECT Balance FROM Account WHERE AccountNumber
= :account_number", {'account_number': account_number})
balance = cursor.fetchone()
if balance:
amount = simpledialog.askfloat("Input", "Enter Amount to Deposit:")
if amount is not None:
new_balance = balance[0] + amount
cursor.execute("UPDATE Account SET Balance = :new_balance WHERE
AccountNumber = :account_number", {'new_balance': new_balance, 'account_number':
account_number})
connection.commit()
balance_label.config(text=f"New Account Balance: {new_balance}")
else:
balance_label.config(text="Account not found")

# Login frame
login_frame = tk.Frame(root)
login_frame.grid(row=0, column=0, sticky="nsew")

# Customer frame
customer_frame = tk.Frame(root)
customer_frame.grid(row=0, column=0, sticky="nsew")

# Create GUI elements for login frame


login_label = tk.Label(login_frame, text="Customer Login", font=("Helvetica", 16))
login_label.grid(row=0, column=0, columnspan=2, pady=10)

username_label = tk.Label(login_frame, text="Username:", font=("Helvetica", 12))


username_label.grid(row=1, column=0, sticky="e", padx=10, pady=5)
username_entry = tk.Entry(login_frame, font=("Helvetica", 12))
username_entry.grid(row=1, column=1, padx=10, pady=5)

password_label = tk.Label(login_frame, text="Password:", font=("Helvetica", 12))


password_label.grid(row=2, column=0, sticky="e", padx=10, pady=5)
password_entry = tk.Entry(login_frame, show="*", font=("Helvetica", 12))
password_entry.grid(row=2, column=1, padx=10, pady=5)

login_button = tk.Button(login_frame, text="Login", command=login_user,


font=("Helvetica", 12))
login_button.grid(row=3, column=0, columnspan=2, pady=10)

error_label = tk.Label(login_frame, text="", fg="red", font=("Helvetica", 12))


error_label.grid(row=4, column=0, columnspan=2)

# Create GUI elements for customer frame


customer_label = tk.Label(customer_frame, text="Customer Dashboard",
font=("Helvetica", 16))
customer_label.grid(row=0, column=0, columnspan=3, pady=10)

person_details_label = tk.Label(customer_frame, text="", font=("Helvetica", 12))


person_details_label.grid(row=1, column=0, padx=10, pady=5)

check_balance_button = tk.Button(customer_frame, text="Check Balance",


command=check_balance, font=("Helvetica", 12))
check_balance_button.grid(row=2, column=0, pady=10)

withdraw_button = tk.Button(customer_frame, text="Withdraw Money",


command=withdraw_money, font=("Helvetica", 12))
withdraw_button.grid(row=2, column=1, pady=10)

deposit_button = tk.Button(customer_frame, text="Deposit Money",


command=deposit_money, font=("Helvetica", 12))
deposit_button.grid(row=2, column=2, pady=10)

balance_label = tk.Label(customer_frame, text="", font=("Helvetica", 12))


balance_label.grid(row=3, column=0, padx=10, pady=5)

# Set initial frame to login frame


switch_frame(login_frame)

root.mainloop()

You might also like