- 主函数
'''
人
类名:user
属性:姓名,身份证号,电话号,卡
行为(方法):
银行
类名:bank
属性:用户列表,提款机
卡
类名:card
属性:卡号,密码,余额,锁定
行为:
取款机
类名:ATM
属性:
行为:开户, 查询,取款,存款,转账,改密,锁定,解锁,补卡,销户,退出
管理员
类名:admin
属性:
行为:管理员界面,管理员登入,管理员操作,系统功能界面,退出
'''
import time
from admin import Admin
from atm import ATM
import pickle
import os
def main():
#界面对象
view = Admin()
view.printAdminView()
#管理员开机
#if view.printAdminView():
if view.adminLogin():
return -1
#view.printSystemFunctionView()
#储存所有用户的信息
allUserInformation = {}
#提款机对象
path = 'E:\pycharm project\Tkinter1/allUser.txt'
file2 = open(path,"rb")
alluser = pickle.load(file2)
#print("***********")
#print(alluser)
atm = ATM(alluser)
while True:
view.printSystemFunctionView()
time.sleep(1)
#等待用户的操作
option = input('请输入您的操作:')
if option =='open':
atm.createUser()
elif option == 'search':
atm.searchUserinformation()
elif option == 'withdram':
atm.withDram()
elif option == 'deposit':
atm.Deposit()
elif option == 'transfer':
atm.Transfer()
elif option == 'tighten':
atm.Tighten()
elif option == 'locking':
atm.Locking()
elif option ==' deblocking':
atm.Deblocking()
elif option == 'supcard':
atm.Supcard()
elif option == 'colsing':
atm.Colsing()
elif option == 'quit':
if not view.adminoption():
#将当前系统中的用户信息保存到文件中
absPath = os.getcwd()
filePath = os.path.join(absPath,'allUser.txt')
print(filePath)
file = open(filePath,"wb")
pickle.dump(atm.allUser,file)
file.close()
return -1
time.sleep(1)
if __name__ =="__main__":
main()
- admin.py
import time
class Admin(object):
#def __init__(self,admin,passKey):
# self.__admin = admin
# self.__passKey = passKey
admin='1'
passKey='123'
def printAdminView(self):
print("***************************************************************")
print("* *")
print("* *")
print("* 欢迎使用杰哥银行 *")
print("* *")
print("* *")
print("***************************************************************")
'''
inputAdmin= input("请输入管理员账号:")
if self.admin != inputAdmin:
print("账号输入错误")
return -1
inputPassKey = input("请输入管理员密码:")
if self.passKey != inputPassKey:
print("密码输入有误")
return -1
#能执行到这里说明密码输入正确
print("登入成功!请稍后....")
time.sleep(3)
return 0
'''
def printSystemFunctionView(self):
print("***************************************************************")
print("* 开户(open) 查询(search) *")
print("* 取款(withdram) 存款(deposit) *")
print("* 转账(transfer) 改密(tighten) *")
print("* 锁定(locking) 解锁(deblocking) *")
print("* 补卡(Supcard) 销户(colsing) *")
print("* *")
print("* 退出(quit) *")
print("***************************************************************")
def adminLogin(self):
inputAdmin= input("请输入管理员账号:")
if self.admin != inputAdmin:
print("账号输入错误")
return -1
inputPassKey = input("请输入管理员密码:")
if self.passKey != inputPassKey:
print("密码输入有误")
return -1
#能执行到这里说明密码输入正确
print("登入成功!请稍后....")
time.sleep(1)
return 0
def adminoption(self):
inputAdmin= input("请输入管理员账号:")
if self.admin != inputAdmin:
print("账号输入错误")
return -1
inputPassKey = input("请输入管理员密码:")
if self.passKey != inputPassKey:
print("密码输入有误")
return -1
#能执行到这里说明密码输入正确
print("已退出!感谢使用!")
time.sleep(1)
return 0
- atm.py
from card import Card
from user import User
import random
class ATM(object):
def __init__(self,allUser):
self.allUser = allUser #卡号--用户
def createUser(self):
name = input("请输入您的姓名:")
idCard = input("请输入您的身份证号码:")
phone = input("请输入您的电话号码:")
prestoreMoney = input("请输入您的预存款:")
if int(prestoreMoney) < 0:
print("预存款输入有误!开户失败....")
return -1
onePasswd = input("请设置密码:")
#验证密码
if not self.checkPasswd(onePasswd):
print("两次输入密码不一致!开户失败....")
#
cardstr = self.randomCardId()
print(cardstr)
card = Card(cardstr,onePasswd,prestoreMoney)
user = User(name,idCard,phone,card)
#存到字典
self.allUser[cardstr] = user
print("开户成功!请记住账户: %s "%cardstr)
def searchUserinformation(self):
cardNumber = input("请输入您的卡号:")
'''
user = self.allUser.get(cardNumber)
#验证是否存在该卡号
if not user:
print("该卡号不存在!!查询失败....")
return -1
#判断账号是否被锁定
if user.card.cardLock:
print("该账户已被锁定!!,请解锁后在操作.....")
return -1
#验证密码
if not self.checkPasswd(user.card.cardPasswd):
print("密码输入错误!!该卡已被锁定!请解锁后再进行其他操作.....")
user.card.cardLock = True
return -1
'''
#用键从字典中取出值赋给变量user,若无匹配的键则返回False
user = self.allUser.get(cardNumber)
self.validate(cardNumber,user)
print("姓名:%s 账号:%s 余额:%s" %(user.name,user.card.cardId, user.card.cardMoney))
def withDram(self):
cardNumber = input("请输入卡号:")
'''
#判断是否存在该卡号
user = self.allUser.get(cardNumber)
if not user:
print("该卡号不存在!")
return -1
#验证密码
if not self.checkPasswd(user.card.cardPasswd):
print("密码输入错误!")
return -1
'''
#用键从字典中取出值赋给变量user,若无匹配的键则返回False
user = self.allUser.get(cardNumber)
self.validate(cardNumber,user)
#取钱
moneyNumber = int(input("请输入你要取出的金额:"))
if moneyNumber>int(user.card.cardMoney):
print("余额不足!")
return -1
user.card.cardMoney = int(user.card.cardMoney)-int(moneyNumber)
print("操作成功!")
def Deposit(self):
cardNumber = input("请输入卡号:")
'''
#判断是否存在该卡号
user = self.allUser.get(cardNumber)
#判断账号是否被锁定
if user.card.cardLock:
print("该账户已被锁定!!,请解锁后在操作.....")
return -1
if not user:
print("该卡号不存在!")
return -1
#验证密码
if not self.checkPasswd(user.card.cardPasswd):
print("密码输入错误!")
return -1
'''
#用键从字典中取出值赋给变量user,若无匹配的键则返回False
user = self.allUser.get(cardNumber)
self.validate(cardNumber,user)
#存钱
moneyNumber = input("请输入你要存入的金额:")
user.card.cardMoney = int(user.card.cardMoney)+int(moneyNumber)
print("操作成功!")
def Transfer(self):
cardNumber = input("请输入卡号:")
'''
#判断是否存在该卡号
user = self.allUser.get(cardNumber)
#判断账号是否被锁定
if user.card.cardLock:
print("该账户已被锁定!!,请解锁后在操作.....")
return -1
if not user:
print("该卡号不存在!")
return -1
#验证密码
if not self.checkPasswd(user.card.cardPasswd):
print("密码输入错误!")
return -1
'''
#用键从字典中取出值赋给变量user,若无匹配的键则返回False
user = self.allUser.get(cardNumber)
self.validate(cardNumber,user)
#转账
transferMoney = int(input("请输入转账的金额:"))
if transferMoney>int(user.card.cardMoney):
print("余额不足!")
return -1
#exporter = input("请输入输出者账号:")
receiver = input("请输入接受者账号:")
#user2 = self.allUser.get(exporter)
user1 = self.allUser.get(receiver)
user.card.cardMoney = int(user.card.cardMoney)-transferMoney
user1.card.cardMoney = int(user1.card.cardMoney)+transferMoney
print("操作成功!")
def Tighten(self):
cardNumber = input("请输入卡号:")
'''
#判断是否存在该卡号
user = self.allUser.get(cardNumber)
#判断账号是否被锁定
if user.card.cardLock:
print("该账户已被锁定!!,请解锁后在操作.....")
return -1
if not user:
print("该卡号不存在!")
return -1
#验证密码
if not self.checkPasswd(user.card.cardPasswd):
print("密码输入错误!")
return -1
'''
#用键从字典中取出值赋给变量user,若无匹配的键则返回False
user = self.allUser.get(cardNumber)
self.validate(cardNumber,user)
#改密
changeKey = input("请输入新密码:")
user.card.cardPasswd = changeKey
print("操作成功!")
def Locking(self):
cardNumber = input("请输入您的卡号:")
'''
# 验证是否存在该卡号
user = self.allUser.get(cardNumber)
if not user:
print("该卡号不存在!!锁定失败....")
return -1
if user.card.cardLock:
print("该卡已被锁定!!请在解锁后使用其他功能.....")
return -1
#判断是否锁定
if user.card.cardLock:
print("该卡已被锁定!请解锁后再进行其他操作.....")
return -1
# 验证密码
if not self.checkPasswd(user.card.cardPasswd):
print("密码输入错误!!该卡已被锁定!请解锁后再进行其他操作.....")
user.card.cardLock = True
return -1
'''
#用键从字典中取出值赋给变量user,若无匹配的键则返回False
user = self.allUser.get(cardNumber)
self.validate(cardNumber,user)
#验证身份证号
tempIdCard = input("请输入您的身份证号:")
if tempIdCard != user.idCard:
print("身份证号输入错误!!锁定失败....")
return -1
#锁定
user.card.cardLock = True
print("锁定成功!")
def Deblocking(self):
cardNumber = input("请输入您的卡号:")
'''
# 验证是否存在该卡号
user = self.allUser.get(cardNumber)
if not user:
print("该卡号不存在!!解锁失败....")
return -1
#判断是否锁定
if not user.card.cardLock:
print("该卡已解锁!")
return -1
# 验证密码
if not self.checkPasswd(user.card.cardPasswd):
print("密码输入错误!!")
user.card.cardLock = True
return -1
'''
#用键从字典中取出值赋给变量user,若无匹配的键则返回False
user = self.allUser.get(cardNumber)
self.validate(cardNumber,user)
#验证身份证号
tempIdCard = input("请输入您的身份证号:")
if tempIdCard != user.idCard:
print("身份证号输入错误!!解锁失败....")
return -1
#锁定
user.card.cardLock = False
print("解锁成功!")
def Supcard(self):
cardNumber = input("请输入卡号:")
'''
#判断是否存在该卡号
user = self.allUser.get(cardNumber)
#判断账号是否被锁定
if user.card.cardLock:
print("该账户已被锁定!!,请解锁后在操作.....")
return -1
if not user:
print("该卡号不存在!")
return -1
#验证身份证号
Id = input("请输入身份证号:")
if Id != user.idCard:
print("输入错误!")
return -1
#验证密码
if not self.checkPasswd(user.card.cardPasswd):
print("密码输入错误!")
return -1
'''
#用键从字典中取出值赋给变量user,若无匹配的键则返回False
user = self.allUser.get(cardNumber)
self.validate(cardNumber,user)
#补卡
newNumber = self.randomCardId()
self.allUser[newNumber]=user
self.allUser.pop(cardNumber)
print("新卡号为:%s"%(newNumber)+'\n'+"操作成功!")
def Colsing(self):
''''
cardNumber = input("请输入卡号:")
#判断是否存在该卡号
user = self.allUser.get(cardNumber)
#判断账号是否被锁定
if user.card.cardLock:
print("该账户已被锁定!!,请解锁后在操作.....")
return -1
if not user:
print("该卡号不存在!")
return - 1
# 验证密码
if not self.checkPasswd(user.card.cardPasswd):
print("密码输入错误!")
return -1
'''
cardNumber = input("请输入卡号:")
#用键从字典中取出值赋给变量user,若无匹配的键则返回False
user = self.allUser.get(cardNumber)
#验证
self.validate(cardNumber,user)
#销户
self.allUser.pop(cardNumber)
print("操作成功!")
#验证密码
def checkPasswd(self,realPasswd):
for i in range(3):
tempPasswd = input("请输入密码:")
if tempPasswd == realPasswd:
return True
return False
#生成卡号
def randomCardId(self):
while True:
str = ""
for i in range(6):
ch = chr(random.randrange(ord('0'),ord('9')+1))
str += ch
#判断是否重复
if not self.allUser.get(str):
return str
#验证
def validate(self,cardNumber,user):
#用键从字典中取出值赋给变量user,若无匹配的键则返回False
#user = self.allUser.get(cardNumber)
# 判断是否存在该卡号
if not user:
print("该卡号不存在!")
return - 1
#判断账号是否被锁定
if user.card.cardLock:
print("该账户已被锁定!!,请解锁后在操作.....")
return -1
# 验证密码
if not self.checkPasswd(user.card.cardPasswd):
print("密码输入错误!账户已锁定,请解锁后使用!")
user.card.cardLock=True
return -1
- card.py
class Card(object):
def __init__(self,cardId,cardPasswd,cardMoney):
self.cardId = cardId
self.cardPasswd = cardPasswd
self.cardMoney = cardMoney
self.cardLock = False
- user.py
class User(object):
def __init__(self,name,idCard,phone,card):
self.name = name
self.idCard = idCard
self.phone = phone
self.card = card
来源:CSDN
作者:kyle-fang
链接:https://blog.csdn.net/fangweijiex/article/details/103653287