Python codes for bank system.
main.py
import pymysql
from Atm import Atm
from CashDispenser import CashDispenser
from Customer import User
from Transaction import Transaction
# database connection
connection = pymysql.connect(host="localhost", user="root", passwd="", database="atm")
cursor = connection.cursor()
atmSql = """CREATE TABLE Atm(
ID INT(20) PRIMARY KEY AUTO_INCREMENT,
location VARCHAR(256) NOT NULL,
branch_name VARCHAR(256) NOT NULL,
branch_code VARCHAR(256))"""
cursor.execute(atmSql)
print("Atm Table created")
customerSql = """CREATE TABLE Customer(
ID INT(20) PRIMARY KEY AUTO_INCREMENT,
customer_name VARCHAR (256) NOT NULL,
customer_con_no VARCHAR (256) NOT NULL,
card_id VARCHAR (256),
card_pic INT(4),
account_number VARCHAR (256),
balance INT(20))"""
cursor.execute(customerSql)
print("Customer Table Created")
transactionSql = """CREATE TABLE transaction(
ID INT(20) PRIMARY KEY AUTO_INCREMENT,
withdraw_amount INT (20) NOT NULL,
reciept_no INT (20) NOT NULL)"""
cursor.execute(transactionSql)
print("Transaction Table created")
cashSql = """CREATE TABLE cash(
ID INT(20) PRIMARY KEY AUTO_INCREMENT,
available INT (20) NOT NULL,
cash_limit INT (20) NOT NULL)"""
cursor.execute(cashSql)
print("Cash Table Created")
atm = Atm()
atm.location = "Islamabad"
atm.branchCode = 123
atm.branchName = "United"
cashDispenser = CashDispenser()
cashDispenser.availableCash = 150000
cashDispenser.totalLimitPerDay = 100000
customer = User()
customer.customerName = "Nabeel"
customer.pin = 1234
customer.cardID = 123456789
customer.balance = 150000
customer.accountNumber = 12354674
customer.contactNumber = "03015846"
transaction = Transaction()
transaction.receiptNumber = 51462
transaction.withdrawAmount = 15203
cursor.execute("INSERT INTO atm(location,branch_name,branch_code) VALUES(%s,%s,%s)",(atm.location,atm.branchName,atm.branchCode))
cursor.execute("INSERT INTO cash(available,cash_limit) VALUES(%s,%s)", (cashDispenser.availableCash,cashDispenser.totalLimitPerDay))
cursor.execute("INSERT INTO customer(customer_name,customer_con_no,"
"card_id,card_pic,account_number,balance) VALUES (%s,%s,%s,%s,%s,%s)",
(customer.customerName,customer.contactNumber,customer.cardID,customer.pin,customer.accountNumber,customer.balance))
cursor.execute("INSERT INTO transaction(withdraw_amount,reciept_no)VALUES (%s,%s)",(transaction.withdrawAmount,transaction.receiptNumber))
print("Data inserted")
print("")
print("ATM")
retriveATM = "SELECT * FROM atm"
cursor.execute(retriveATM)
rows = cursor.fetchall()
for row in rows:
print(row)
print("Cash")
retriveCash = "SELECT * FROM cash"
cursor.execute(retriveCash)
rows = cursor.fetchall()
for row in rows:
print(row)
print("Customer")
retriveCustomer = "SELECT * FROM customer"
cursor.execute(retriveCustomer)
rows = cursor.fetchall()
for row in rows:
print(row)
print("Transaction")
retriveInstructor = "SELECT * FROM transaction"
cursor.execute(retriveInstructor)
rows = cursor.fetchall()
for row in rows:
print(row)
connection.commit()
connection.close()
Atm.py code:
class Atm:
def __init__(self, location=None, branchName=None, branchCode=0):
super().__init__()
self.__loc = location
self.__name = branchName
self.__code = branchCode
@property
def location(self) -> str:
return self.__loc
@location.setter
def location(self, location) -> None:
self.__loc = location
@property
def branchName(self) -> str:
return self.__name
@branchName.setter
def branchName(self, name) -> None:
self.__name = name
@property
def branchCode(self) -> int:
return self.__code
@branchCode.setter
def branchCode(self, code) -> None:
self.__code = code
CashDispenser.py code:
class CashDispenser:
def __init__(self, availableCash=0, totalLimit=0):
super().__init__()
self.__cash = availableCash
self.__limit = totalLimit
@property
def availableCash(self) -> int:
return self.__cash
@availableCash.setter
def availableCash(self, availableCash) -> None:
self.__cash = availableCash
@property
def totalLimitPerDay(self) -> int:
return self.__limit
@totalLimitPerDay.setter
def totalLimitPerDay(self, totalLimit) -> None:
self.__limit = totalLimit
Customer.py code:
class User:
def __init__(self, name=None, contactNo=None, pin=0,
cardID=None, accountNumber=None, balance=0):
super().__init__()
self.__name = name
self.__contact = contactNo
self.__pin = pin
self.__cardID = cardID
self.__accNo = accountNumber
self.__balance = balance
@property
def customerName(self) -> str:
return self.__name
@customerName.setter
def customerName(self, name) -> None:
self.__name = name
@property
def contactNumber(self) -> str:
return self.__contact
@contactNumber.setter
def contactNumber(self, contactNo) -> None:
self.__contact = contactNo
@property
def pin(self) -> int:
return self.__pin
@pin.setter
def pin(self, pin) -> None:
self.__pin = pin
@property
def cardID(self) -> str:
return self.__cardID
@cardID.setter
def cardID(self, cardID) -> None:
self.__cardID = cardID
@property
def accountNumber(self) -> str:
return self.__accNo
@accountNumber.setter
def accountNumber(self, accountNumber) -> None:
self.__accNo = accountNumber
@property
def balance(self) -> int:
return self.__balance
@balance.setter
def balance(self, balance) -> None:
self.__balance = balance
Transaction.py
class Transaction:
def __init__(self, withdrawAmount=0, receiptNumber=0):
super().__init__()
self.__amount = withdrawAmount
self.__receipt = receiptNumber
@property
def withdrawAmount(self) -> int:
return self.__amount
@withdrawAmount.setter
def withdrawAmount(self, withdrawAmount) -> None:
self.__amount = withdrawAmount
@property
def receiptNumber(self) -> int:
return self.__receipt
@receiptNumber.setter
def receiptNumber(self, receiptNumber) -> None:
self.__receipt = receiptNumber
No comments:
Post a Comment