[Python] 纯文本查看 复制代码
#作者 TokeyJs
import tkinter as tk
import tkinter.messagebox
import json
import random
import time
import os
# # 邮件发送相关模块###使用时请取消注释
# import smtplib
# from email.mime.text import MIMEText
# from email.utils import formataddr
"""为了存储数据将在与源文件相同路径下新建两个json文件,请不要随意删除"""
"""
普通管理员:可以完成对银行卡的各种操作
用户名:admin
密码:6818
超级管理员:可以查看所有用户的部分信息
用户名:superadmin
密码:000000
"""
"""有关Bank,Person,Card,Admin类的定义"""
class Admin:
def __init__(self):
self.num = 'admin'
self.password = '6818'
self.superadmin = 'superadmin'
self.superpassword = '000000'
class Card:
def __init__(self, cardid, password, money):
self.cardid = cardid
self.password = password
self.money = money
self.lock = False
class Person:
def __init__(self, name, age, phone, person_id,e_mail, card):
self.name = name # 姓名
self.person_id = person_id # 身份证号
self.age = age # 出生年份
self.phone = phone # 电话
self.e_mail = e_mail # 邮箱
self.card = card # Card类的实例化对象
class Bank:
def __init__(self, user_all, user_error):
self.user_all = user_all
self.user_error = user_error
def superlogin(self):
super_win = tk.Tk()
super_win.title('超级管理后台')
super_win.geometry('600x480')
all_list = []
lab_ti = tk.Label(super_win,text='银行系统信息统计', font=('宋体', 28))
lab_ti.place(x=160,y=60)
lab_ti = tk.Label(super_win, text='本系统共注册{}位用户'.format(self.user_all['count']), font=('宋体', 16))
lab_ti.place(x=170, y=128)
lab_titl = tk.Label(super_win, text="银行卡号"+' '*6+"户主姓名"+' '*6+"身份证号", font=('宋体', 12))
lab_titl.place(x=150, y=210)
for dic in self.user_all['users']:
st = (dic['card']['cardid']+' '*12+dic['person']['name'])
if len(st) <= 50:
y = 50 - len(st)
st += ' '*y
st += dic['person']['person_id']
all_list.append(st)
sc = tkinter.Scrollbar(super_win)
sc.pack(side=tkinter.RIGHT, fill=tkinter.Y)
lb = tk.Listbox(super_win, width=50, yscrollcommand=sc.set)
sc.config(command=lb.yview)
#
lb.place(x=140, y=240)
for item in all_list:
lb.insert(tk.END, item)
super_win.mainloop()
def getid(self,n=6):
"""生成随机卡号"""
s = ''
for i in range(n):
ch = chr(random.randrange(ord('0'), ord('9')+1))
s += ch
return s
def bankmain(self):
"""银行系统执行逻辑主程序"""
# 实例化一些对象
ad = Admin()
# 含有admin登录界面
win_admin_log = tk.Tk()
win_admin_log.title('银行系统管理员登录')
win_admin_log.geometry('680x460')
win_admin_log.resizable(0, 0)
# 标题
tit_lab = tk.Label(win_admin_log, text='银行管理系统', font=('华文彩云', 30))
tit_lab.place(x=250, y=80)
# 登录框
name_log = tk.Label(win_admin_log, text='管理员用户名', font=('宋体', 14))
name_log.place(x=140, y=240)
pasword_log = tk.Label(win_admin_log, text='管理员密码', font=('宋体', 14))
pasword_log.place(x=160, y=300)
# 登录entry
var_name = tk.StringVar()
var_name.set('') # 非测试时为空
en_name = tk.Entry(win_admin_log, textvariable=var_name, bd=4, font=('宋体', 14))
en_name.place(x=260, y=240)
var_pasw = tk.StringVar()
var_pasw.set('') # 非测试时为空
en_pasw = tk.Entry(win_admin_log, textvariable=var_pasw, bd=4, font=('宋体', 14), show='*')
en_pasw.place(x=260, y=300)
tk.Label(win_admin_log, text='当前时间:', font=('宋体', 12)).place(x=10, y=420)
clock = tk.Label(win_admin_log, text='', font=('ds-digital', 12))
clock.place(x=86, y=420)
def get_time():
"""获取时间"""
time2 = time.strftime('%Y-%m-%d %H:%M:%S')
clock.configure(text=time2)
clock.after(1000, get_time)
def check_admin():
"""检验身份"""
ad_name = var_name.get()
ad_pasw = var_pasw.get()
if ad_name == ad.num and ad_pasw == ad.password:
st = '登录成功!欢迎您,管理员!'
self.show_get('系统登录', st)
#win_admin_log.destroy()
# win_admin_log.withdraw()
self.menu_main()
else:
st = '密码错误或用户名错误!'
self.show_error('系统登录', st)
def check_superlogin():
ad_name = var_name.get()
ad_pasw = var_pasw.get()
if ad_name == ad.superadmin and ad_pasw == ad.superpassword:
st = '登录成功!欢迎您,超级管理员!'
self.show_get('系统登录', st)
# win_admin_log.destroy()
self.superlogin()
else:
st = '密码错误或用户名错误!'
self.show_error('系统登录', st)
# 程序说明界面驱动按钮
expl_a = tk.Button(win_admin_log, text='使用说明', font=('宋体', 10), command=self.explain)
expl_a.place(x=580, y=390)
# 登录按钮
login_a = tk.Button(win_admin_log, text='普通管理员登录', font=('宋体', 14), command=check_admin)
login_a.place(x=180, y=360)
# 按回车键可以进行普通管理员登录
def fucgo(event):
check_admin()
win_admin_log.bind('<Return>', fucgo)
# 超级管理员登录
login_super = tk.Button(win_admin_log, text='超级管理员登录', font=('宋体', 14), command=check_superlogin)
login_super.place(x=360, y=360)
# 获取时间
get_time()
# 系统用户数量
ls = tk.Label(win_admin_log, text='v2.0系统信息:本系统已注册{}位用户。'.format(user_all['count']), font=('宋体', 12))
ls.place(x=380, y=422)
# main loop
win_admin_log.mainloop()
def menu_main(self):
"""操作菜单及可视化页面"""
menu_win = tk.Tk()
menu_win.title('银行系统操作')
menu_win.geometry('600x500')
menu_win.resizable(0, 0)
# 标题
lab_maintitle = tk.Label(menu_win, text='功 能 菜 单', font=('华文琥珀',30))
lab_maintitle.place(x=200, y=70)
# 开户
n_getnew_card = tk.Button(menu_win, text='开 户', font=('宋体', 12), command=self.getnew_card, width=9, height=2)
n_getnew_card.place(x=70, y=160)
n_sech_card = tk.Button(menu_win, text='查 询', font=('宋体', 12), command=self.sech_card, width=9, height=2)
n_sech_card.place(x=270, y=160)
n_getmoney = tk.Button(menu_win, text='取 款', font=('宋体', 12), command=self.getmoney, width=9, height=2)
n_getmoney.place(x=470, y=160)
n_putmoney = tk.Button(menu_win, text='存 款', font=('宋体', 12), command=self.putmoney, width=9, height=2)
n_putmoney.place(x=70, y=260)
n_changemoney = tk.Button(menu_win, text='转 账', font=('宋体', 12), command=self.changemoney, width=9, height=2)
n_changemoney.place(x=270, y=260)
n_dellock = tk.Button(menu_win, text='解 锁', font=('宋体', 12), command=self.dellock, width=9, height=2)
n_dellock.place(x=470, y=260)
n_getlock = tk.Button(menu_win, text='锁 定', font=('宋体', 12), command=self.getlock, width=9, height=2)
n_getlock.place(x=70, y=360)
n_get_newpas = tk.Button(menu_win, text='改密(测试)', font=('宋体', 12), command=self.get_newpsw, width=10, height=2)
n_get_newpas.place(x=266, y=360)
n_del_card = tk.Button(menu_win, text='销 户', font=('宋体', 12), command=self.del_card, width=9, height=2)
n_del_card.place(x=470, y=360)
lab_ti = tk.Label(menu_win, text='温馨提示:请在完成所有操作后再关闭此页面!', font=('宋体', 12))
lab_ti.place(x=130, y=460)
menu_win.mainloop()
def id_is(self, st_id):
"""判断生成的卡号是否重复"""
for dic in user_all['users']:
if st_id == dic['card']['cardid']:
return 1
return 0
def getnew_card(self):
"""开户及可视化页面"""
getnew_card_win = tk.Tk()
getnew_card_win.title('开户页面')
getnew_card_win.geometry('600x560')
lab_m = tk.Label(getnew_card_win, text='开 户', font=('宋体', 30))
lab_m.place(x=250, y=40)
# 得到卡号
while True:
st = self.getid()
if not self.id_is(st):
break
lab_tx = tk.Label(getnew_card_win, text='请正确填写以下信息\n邮箱一经确认不可再次更改', font=('宋体', 12))
lab_tx.place(x=210, y=114)
#
lab_name = tk.Label(getnew_card_win, text='姓 名:', font=('宋体', 16))
lab_name.place(x=150, y=160)
v_name = tk.StringVar()
v_name.set('')
e_name = tk.Entry(getnew_card_win, textvariable=v_name, bd=4, font=('宋体', 12))
e_name.place(x=240, y=160)
#
lab_person_id = tk.Label(getnew_card_win, text='身份证号码:', font=('宋体', 16))
lab_person_id.place(x=115, y=200)
v_person_id = tk.StringVar()
v_person_id.set('')
e_person_id = tk.Entry(getnew_card_win, textvariable=v_person_id, bd=4, font=('宋体', 12))
e_person_id.place(x=240, y=200)
#
lab_age = tk.Label(getnew_card_win, text='出生年份:', font=('宋体', 16))
lab_age.place(x=120, y=240)
v_age = tk.StringVar()
v_age.set('')
e_age = tk.Entry(getnew_card_win, textvariable=v_age, bd=4, font=('宋体', 12))
e_age.place(x=240, y=240)
#
lab_phone = tk.Label(getnew_card_win, text='电 话:', font=('宋体', 16))
lab_phone.place(x=120, y=280)
v_phone = tk.StringVar()
v_phone.set('')
e_phone = tk.Entry(getnew_card_win, textvariable=v_phone, bd=4, font=('宋体', 12))
e_phone.place(x=240, y=280)
#
lab_password = tk.Label(getnew_card_win, text='设置密码:', font=('宋体', 16))
lab_password.place(x=120, y=320)
v_password = tk.StringVar()
v_password.set('')
e_password = tk.Entry(getnew_card_win, textvariable=v_password, bd=4, font=('宋体', 12), show='*')
e_password.place(x=240, y=320)
#
lab_password_c = tk.Label(getnew_card_win, text='再次确认密码:', font=('宋体', 16))
lab_password_c.place(x=105, y=360)
v_password_c = tk.StringVar()
v_password_c.set('')
e_password_c = tk.Entry(getnew_card_win, textvariable=v_password_c, bd=4, font=('宋体', 12), show='*')
e_password_c.place(x=240, y=360)
#
lab_money = tk.Label(getnew_card_win, text='预存金额: ', font=('宋体', 16))
lab_money.place(x=120, y=400)
v_money = tk.StringVar()
v_money.set('')
e_money = tk.Entry(getnew_card_win, textvariable=v_money, bd=4, font=('宋体', 12))
e_money.place(x=240, y=400)
#
lab_email = tk.Label(getnew_card_win, text='邮箱(用于改密):', font=('宋体', 16))
lab_email.place(x=50, y=440)
v_email = tk.StringVar()
v_email.set('')
e_email = tk.Entry(getnew_card_win, textvariable=v_email, bd=4, font=('宋体', 12))
e_email.place(x=240, y=440)
def check_op():
name_i = e_name.get()
person_id_i = e_person_id.get()
age_i = e_age.get()
phone_i = e_phone.get()
password_i = e_password.get()
password_c_i = e_password_c.get()
money_i = e_money.get()
card_id = st
email_i = e_email.get()
try:
age_i = int(age_i)
money_i = float(money_i)
except:
self.show_error('信息错误', '输入的出生年份或者预存金额出错!')
return
if money_i < 0:
self.show_error('金额错误', '预存金额出错!')
elif len(name_i) == 0 or len(person_id_i) == 0 or len(e_age.get()) == 0 or len(phone_i) == 0 or len(password_i) == 0 or len(email_i)==0:
self.show_error('信息错误', '请将信息填写完整!')
else:
if password_i != password_c_i:
self.show_error('密码错误', '两次输入的密码不一致!')
elif age_i <= 1900 or age_i >= 2022:
self.show_error('信息错误', '输入的出生年份出错!')
else:
card = Card(card_id, password_i, money_i)
person = Person(name_i, age_i, phone_i, person_id_i, email_i, card)
user = {
'person': {'name': name_i, 'age': age_i, 'phone': phone_i, 'person_id': person_id_i,'e_mail':email_i},
'card': {'cardid': card_id, 'password': password_i, 'money': money_i, 'lock': False}
}
user_all['users'].append(user)
user_all['count'] += 1
user_er = {
'cardid': card_id,
'chance': 0
}
user_error['users'].append(user_er)
user_error['count'] += 1
# 将信息存储
self.dump_user()
self.show_get('注册成功', '*'*20+'\n注册成功!\n你的卡号为:{}\n请牢记卡号!\n'.format(card_id)+20*'*')
getnew_card_win.destroy()
# 按回车开户
def fucgo(event):
check_op()
getnew_card_win.bind('<Return>', fucgo)
# 按键
an_a = tk.Button(getnew_card_win, text='确认开户', font=('宋体', 14), command=check_op)
an_a.place(x=280, y=496)
getnew_card_win.mainloop()
def sech_card(self):
"""查询及可视化页面"""
sech_card_win = tk.Tk()
sech_card_win.title('查询页面')
sech_card_win.geometry('700x580')
lab_ma = tk.Label(sech_card_win,text='查 询', font=('宋体',30))
lab_ma.place(x=310,y=50)
#
lad_cardid = tk.Label(sech_card_win,text='卡号:', font=('宋体',12))
lad_cardid.place(x=140,y=140)
v_cardid = tk.StringVar()
v_cardid.set('')
e_cardid = tk.Entry(sech_card_win, textvariable=v_cardid, bd=4, font=('宋体', 14))
e_cardid.place(x=200,y=140)
#
lad_password = tk.Label(sech_card_win, text='密码:', font=('宋体', 12))
lad_password.place(x=140, y=190)
v_password = tk.StringVar()
v_password.set('')
e_password = tk.Entry(sech_card_win, textvariable=v_password,bd=4, font=('宋体', 14),show='*')
e_password.place(x=200, y=190)
#
# 结果显示
lab_sec = tk.Label(sech_card_win, text=20*'='+'查*询*结*果*如*下'+20*'=', font=('宋体', 14))
lab_sec.place(x=60, y=240)
lab_mes = tk.Label(sech_card_win, text='', font=('宋体', 16))
lab_mes.place(x=100, y=320)
def check_one():
get_cardid = e_cardid.get()
get_password = e_password.get()
# 寻找卡
flag = 0
for dic in self.user_all['users']:
if dic['card']['cardid'] == get_cardid:
# 找错误次数
flag = 1
for di in self.user_error['users']:
if di['cardid'] == get_cardid:
if di['chance'] >= 3:
self.show_error('查询失败', '对不起,此银行卡已被锁定!')
sech_card_win.destroy()
elif dic['card']['lock'] == True:
self.show_error('查询失败', '对不起,此银行卡已被锁定!')
sech_card_win.destroy()
else:
if dic['card']['password'] == get_password:
di['chance'] = 0
self.show_get('查询成功', '密码正确,查询成功!')
st = '户主姓名:{}\n\n卡号:{}\n\n余额:{}'.format(dic['person']['name'], get_cardid, dic['card']['money'])
lab_mes.configure(text=st)
self.dump_user()
else:
di['chance'] += 1
if di['chance'] >= 3:
self.show_error('锁定信息', '对不起,您的银行卡已被锁定!')
dic['card']['lock'] = True
else:
self.show_error('密码错误', '您输入的密码错误!\n您还有{}次机会'.format(3 - di['chance']))
self.dump_user()
# sech_card_win.destroy()
break
if flag == 0:
self.show_error('查询结果', '未查询到此银行卡信息!')
# sech_card_win.destroy()
return
# 按回车查询
def fucgo(event):
check_one()
sech_card_win.bind('<Return>', fucgo)
an_end = tk.Button(sech_card_win,text='查询结果', font=('宋体', 14),command=check_one)
an_end.place(x=450, y=165)
sech_card_win.mainloop()
def getmoney(self):
"""取款及可视化页面"""
getmoney_win = tk.Tk()
getmoney_win.title('取款页面')
getmoney_win.geometry('700x580')
lab_ma = tk.Label(getmoney_win, text='取 款', font=('宋体', 30))
lab_ma.place(x=310, y=50)
#
lad_cardid = tk.Label(getmoney_win, text='卡号:', font=('宋体', 12))
lad_cardid.place(x=150, y=200)
v_cardid = tk.StringVar()
v_cardid.set('')
e_cardid = tk.Entry(getmoney_win, textvariable=v_cardid, bd=4, font=('宋体', 14))
e_cardid.place(x=210, y=200)
#
lad_password = tk.Label(getmoney_win, text='密码:', font=('宋体', 12))
lad_password.place(x=150, y=250)
v_password = tk.StringVar()
v_password.set('')
e_password = tk.Entry(getmoney_win, textvariable=v_password,bd=4, font=('宋体', 14), show='*')
e_password.place(x=210, y=250)
#
lad_money = tk.Label(getmoney_win, text='取款金额:', font=('宋体', 12))
lad_money.place(x=130, y=300)
v_money = tk.StringVar()
v_money.set('')
e_money = tk.Entry(getmoney_win, textvariable=v_money, bd=4, font=('宋体', 14))
e_money.place(x=210, y=300)
#流水单
lad_mss = tk.Label(getmoney_win, text='', font=('宋体', 12))
lad_mss.place(x=130, y=350)
def check_tree():
ga_cardid = e_cardid.get()
ga_password = e_password.get()
# 使用异常处理可能报错的代码
try:
ga_money = float(e_money.get())
except:
self.show_error('输入错误', '取款金额输入错误!')
return
flag = 0
for dic in self.user_all['users']:
if dic['card']['cardid'] == ga_cardid:
flag = 1
if dic['card']['lock'] == True:
self.show_error('错误', '操作失败,此银行卡已被锁定!\n请解锁后在再进行此操作。')
getmoney_win.destroy()
else:
for di in self.user_error['users']:
if di['cardid'] == ga_cardid:
if dic['card']['password'] == ga_password:
if ga_money < 0:
self.show_error('输入错误','取款金额输入错误!')
return
elif ga_money > dic['card']['money']:
self.show_error('输入错误', '您的余额不足!')
return
else:
dic['card']['money'] -= ga_money
sy_money = dic['card']['money']
self.dump_user()
self.show_get('操作成功', '取款成功!')
st = """\n银行卡号:{}\n\n取款金额:{}元\n\n余额:{}元\n\n取款时间:{}""".format(ga_cardid,ga_money,sy_money,time.strftime('%Y-%m-%d %H:%M:%S'))
# 流水单显示
lad_ms = tk.Label(getmoney_win, text=26*'*'+'凭 条'+26*'*', font=('宋体', 12))
lad_ms.place(x=130, y=330)
lad_mss.configure(text=st)
else:
di['chance'] += 1
if di['chance'] >= 3:
self.show_error('锁定信息', '对不起,您的银行卡已被锁定!')
dic['card']['lock'] = True
else:
self.show_error('密码错误', '您输入的密码错误!\n您还有{}次机会'.format(3 - di['chance']))
self.dump_user()
return
break
if flag == 0:
self.show_error('查询结果', '未查询到此银行卡信息!')
# getmoney_win.destroy()
return
# 按回车取款
def fucgo(event):
check_tree()
getmoney_win.bind('<Return>', fucgo)
# 按钮
an_h = tk.Button(getmoney_win, text='确认取款', font=('宋体', 14), command=check_tree)
an_h.place(x=480, y=250)
getmoney_win.mainloop()
def putmoney(self):
"""存款及可视化页面"""
putmoney_win = tk.Tk()
putmoney_win.title('存款页面')
putmoney_win.geometry('700x580')
lab_ma = tk.Label(putmoney_win, text='存 款', font=('宋体', 30))
lab_ma.place(x=310, y=50)
#
lad_cardid = tk.Label(putmoney_win, text='卡号:', font=('宋体', 12))
lad_cardid.place(x=150, y=200)
v_cardid = tk.StringVar()
v_cardid.set('')
e_cardid = tk.Entry(putmoney_win, textvariable=v_cardid, bd=4, font=('宋体', 14))
e_cardid.place(x=210, y=200)
#
lad_password = tk.Label(putmoney_win, text='密码:', font=('宋体', 12))
lad_password.place(x=150, y=250)
v_password = tk.StringVar()
v_password.set('')
e_password = tk.Entry(putmoney_win, textvariable=v_password, bd=4, font=('宋体', 14), show='*')
e_password.place(x=210, y=250)
#
lad_money = tk.Label(putmoney_win, text='存款金额:', font=('宋体', 12))
lad_money.place(x=130, y=300)
v_money = tk.StringVar()
v_money.set('')
e_money = tk.Entry(putmoney_win, textvariable=v_money, bd=4, font=('宋体', 14))
e_money.place(x=210, y=300)
# 流水单
lad_mss = tk.Label(putmoney_win, text='', font=('宋体', 12))
lad_mss.place(x=130, y=350)
def check_tree():
ga_cardid = e_cardid.get()
ga_password = e_password.get()
try:
ga_money = float(e_money.get())
except:
self.show_error('输入错误', '存款金额输入错误!')
return
flag = 0
for dic in self.user_all['users']:
if dic['card']['cardid'] == ga_cardid:
flag = 1
if dic['card']['lock'] == True:
self.show_error('错误', '操作失败,此银行卡已被锁定!\n请解锁后再进行此操作。')
putmoney_win.destroy()
else:
for di in self.user_error['users']:
if di['cardid'] == ga_cardid:
if dic['card']['password'] == ga_password:
if ga_money < 0:
self.show_error('输入错误', '存款金额输入错误!')
return
else:
self.show_get('操作成功', '存款成功!')
dic['card']['money'] += ga_money
sy_money = dic['card']['money']
st = """\n银行卡号:{}\n\n存款金额:{}元\n\n余额:{}元\n\n存款时间:{}""".format(ga_cardid, ga_money, sy_money,time.strftime('%Y-%m-%d %H:%M:%S'))
self.dump_user()
# 流水单显示
lad_ms = tk.Label(putmoney_win, text=26 * '*' + '凭 条' + 26 * '*',
font=('宋体', 12))
lad_ms.place(x=130, y=330)
lad_mss.configure(text=st)
else:
di['chance'] += 1
if di['chance'] >= 3:
self.show_error('锁定信息', '对不起,您的银行卡已被锁定!')
dic['card']['lock'] = True
else:
self.show_error('密码错误', '您输入的密码错误!\n您还有{}次机会'.format(3 - di['chance']))
self.dump_user()
return
break
if flag == 0:
self.show_error('查询结果', '未查询到此银行卡信息!')
# putmoney_win.destroy()
return
# 按回车存款
def fucgo(event):
check_tree()
putmoney_win.bind('<Return>', fucgo)
# 按钮
an_h = tk.Button(putmoney_win, text='确认存款', font=('宋体', 14), command=check_tree)
an_h.place(x=480, y=250)
putmoney_win.mainloop()
def changemoney(self):
"""转账及可视化页面"""
changemoney_win = tk.Tk()
changemoney_win.title('转账页面')
changemoney_win.geometry('700x580')
lab_ma = tk.Label(changemoney_win, text='转 账', font=('宋体', 30))
lab_ma.place(x=310, y=50)
#
lad_cardid = tk.Label(changemoney_win, text='转出银行卡号:', font=('宋体', 12))
lad_cardid.place(x=100, y=150)
v_cardid = tk.StringVar()
v_cardid.set('')
e_cardid = tk.Entry(changemoney_win, textvariable=v_cardid,bd=4, font=('宋体', 14))
e_cardid.place(x=210, y=150)
#
lad_password = tk.Label(changemoney_win, text='转出银行卡密码:', font=('宋体', 12))
lad_password.place(x=90, y=200)
v_password = tk.StringVar()
v_password.set('')
e_password = tk.Entry(changemoney_win, textvariable=v_password, bd=4, font=('宋体', 14), show='*')
e_password.place(x=210, y=200)
#
lad_money = tk.Label(changemoney_win, text='转账金额:', font=('宋体', 12))
lad_money.place(x=130, y=250)
v_money = tk.StringVar()
v_money.set('')
e_money = tk.Entry(changemoney_win, textvariable=v_money, bd=4, font=('宋体', 14))
e_money.place(x=210, y=250)
#
lad_card2 = tk.Label(changemoney_win, text='转账卡号:', font=('宋体', 12))
lad_card2.place(x=130, y=300)
v_card2 = tk.StringVar()
v_card2.set('')
e_card2 = tk.Entry(changemoney_win, textvariable=v_card2, bd=4, font=('宋体', 14))
e_card2.place(x=210, y=300)
# 流水单
lad_mss = tk.Label(changemoney_win, text='', font=('宋体', 12))
lad_mss.place(x=130, y=350)
def check_fo():
ga_cardid = e_cardid.get()
ga_password = e_password.get()
ga_card2 = e_card2.get()
try:
ga_money = float(e_money.get())
except:
self.show_error('输入错误', '转账金额输入错误!')
return
flag = 0
kk = 0
dic2 = {}
for dic in self.user_all['users']:
if dic['card']['cardid'] == ga_card2:
dic2 = dic
kk = 1
if dic2['card']['lock'] == True:
kk = -1
break
if kk == 1:
for dic in self.user_all['users']:
if dic['card']['cardid'] == ga_cardid:
flag = 1
if dic['card']['lock'] == True:
self.show_error('错误', '操作失败,此银行卡已被锁定!\n请解锁后在再进行此操作。')
changemoney_win.destroy()
else:
for di in self.user_error['users']:
if di['cardid'] == ga_cardid:
if dic['card']['password'] == ga_password:
if ga_money < 0:
self.show_error('输入错误', '转账金额输入错误!')
return
elif ga_money > dic['card']['money']:
self.show_error('输入错误', '您的余额不足!')
return
else:
v = tk.messagebox.askyesno('转账确认', '信息正确,是否转账?')
if v:
dic2['card']['money'] += ga_money
self.show_get('操作成功', '转账成功!')
dic['card']['money'] -= ga_money
sy_money = dic['card']['money']
st = """\n转出银行卡号:{}\n\n转入银行卡号:{}\n\n转账金额:{}元\n\n转出银行卡余额:{}元\n\n转账时间:{}""".format(ga_cardid,ga_card2, ga_money, sy_money,time.strftime('%Y-%m-%d %H:%M:%S'))
self.dump_user()
# 流水单显示
lad_ms = tk.Label(changemoney_win, text=26 * '*' + '凭 条' + 26 * '*',
font=('宋体', 12))
lad_ms.place(x=130, y=330)
lad_mss.configure(text=st)
else:
self.show_get('操作成功', '取消成功!程序将返回菜单!')
changemoney_win.destroy()
else:
di['chance'] += 1
if di['chance'] >= 3:
self.show_error('锁定信息', '对不起,您的银行卡已被锁定!')
dic['card']['lock'] = True
else:
self.show_error('密码错误', '您输入的密码错误!\n您还有{}次机会'.format(3 - di['chance']))
self.dump_user()
return
break
if flag == 0:
self.show_error('查询结果', '未查询到转出银行卡信息!')
# changemoney_win.destroy()
return
elif kk == -1:
self.show_error('转账结果', '转入银行卡已被锁定,不能执行此操作!')
# changemoney_win.destroy()
return
else:
self.show_error('转账结果', '未查询到转入银行卡信息!')
# changemoney_win.destroy()
return
# 按回车转账
def fucgo(event):
check_fo()
changemoney_win.bind('<Return>', fucgo)
# 按钮
an_h = tk.Button(changemoney_win, text='确认转账', font=('宋体', 14), command=check_fo)
an_h.place(x=480, y=250)
changemoney_win.mainloop()
def getlock(self):
"""锁定及可视化页面"""
getlock_win = tk.Tk()
getlock_win.title('锁定页面')
getlock_win.geometry('700x580')
lab_ma = tk.Label(getlock_win, text='锁 定', font=('宋体', 30))
lab_ma.place(x=310, y=50)
#
lad_cardid = tk.Label(getlock_win, text='银行卡号:', font=('宋体', 12))
lad_cardid.place(x=150, y=250)
v_cardid = tk.StringVar()
v_cardid.set('')
e_cardid = tk.Entry(getlock_win, textvariable=v_cardid, bd=4, font=('宋体', 14))
e_cardid.place(x=240, y=250)
#
lad_password = tk.Label(getlock_win, text='银行卡密码:', font=('宋体', 12))
lad_password.place(x=150, y=300)
v_password = tk.StringVar()
v_password.set('')
e_password = tk.Entry(getlock_win, textvariable=v_password, bd=4, font=('宋体', 14), show='*')
e_password.place(x=240, y=300)
#
lad_person_id = tk.Label(getlock_win, text='身份证号:', font=('宋体', 12))
lad_person_id.place(x=160, y=350)
v_person_id = tk.StringVar()
v_person_id.set('')
e_person_id = tk.Entry(getlock_win, textvariable=v_person_id, bd=4, font=('宋体', 14))
e_person_id.place(x=240, y=350)
def check_five():
gain_card = e_cardid.get()
gain_password = e_password.get()
gain_person_id = e_person_id.get()
#
flag = 0
dicc = {}
dii = {}
for dic in self.user_all['users']:
if dic['card']['cardid'] == gain_card:
dicc = dic
flag = 1
break
for di in self.user_error['users']:
if di['cardid'] == gain_card:
dii = di
break
#
if flag == 0:
self.show_error('卡号错误','卡号不存在!')
return
else:
if dicc['card']['lock'] == True:
self.show_error('结果显示', '无效操作,此卡已被锁定!')
return
else:
if dicc['card']['password'] != gain_password:
self.show_error('锁定', '密码错误!锁定失败!')
dii['chance'] += 1
if dii['chance'] >= 3:
self.show_error('锁定', '因密码错误次数过多,银行卡已被锁定!')
dicc['card']['lock'] = True
self.dump_user()
else:
if dicc['person']['person_id'] == gain_person_id:
v = tk.messagebox.askyesno('锁定确认', '锁定确认,是否锁定此银行卡?')
if v:
dicc['card']['lock'] = True
self.dump_user()
self.show_get('锁定', '银行卡锁定成功!')
else:
self.show_get('锁定', '取消锁定成功')
return
else:
self.show_error('锁定', '信息错误,银行卡锁定失败!')
# 按回车锁定
def fucgo(event):
check_five()
getlock_win.bind('<Return>', fucgo)
an_cloc = tk.Button(getlock_win,text='锁定', font=('宋体', 14), command=check_five, width=8, height=2)
an_cloc.place(x=310, y=460)
getlock_win.mainloop()
def dellock(self):
"""解锁及可视化页面"""
dellock_win = tk.Tk()
dellock_win.title('解锁页面')
dellock_win.geometry('700x580')
lab_ma = tk.Label(dellock_win, text='解 锁', font=('宋体', 30))
lab_ma.place(x=310, y=50)
#
lad_name = tk.Label(dellock_win, text='户主姓名:', font=('宋体', 12))
lad_name.place(x=160, y=200)
v_name = tk.StringVar()
v_name.set('')
e_name = tk.Entry(dellock_win, textvariable=v_name,bd=4, font=('宋体', 14))
e_name.place(x=240, y=200)
#
lad_cardid = tk.Label(dellock_win, text='银行卡号:', font=('宋体', 12))
lad_cardid.place(x=150, y=250)
v_cardid = tk.StringVar()
v_cardid.set('')
e_cardid = tk.Entry(dellock_win, textvariable=v_cardid, bd=4, font=('宋体', 14))
e_cardid.place(x=240, y=250)
#
lad_password = tk.Label(dellock_win, text='银行卡密码:', font=('宋体', 12))
lad_password.place(x=150, y=300)
v_password = tk.StringVar()
v_password.set('')
e_password = tk.Entry(dellock_win, textvariable=v_password, bd=4, font=('宋体', 14), show='*')
e_password.place(x=240, y=300)
#
lad_person_id = tk.Label(dellock_win, text='身份证号:', font=('宋体', 12))
lad_person_id.place(x=160, y=350)
v_person_id = tk.StringVar()
v_person_id.set('')
e_person_id = tk.Entry(dellock_win, textvariable=v_person_id,bd=4, font=('宋体', 14))
e_person_id.place(x=240, y=350)
def check_five():
gain_card = e_cardid.get()
gain_password = e_password.get()
gain_person_id = e_person_id.get()
gain_name = e_name.get()
#
flag = 0
dicc = {}
dii = {}
for dic in self.user_all['users']:
if dic['card']['cardid'] == gain_card:
dicc = dic
flag = 1
break
for di in self.user_error['users']:
if di['cardid'] == gain_card:
dii = di
break
#
if flag == 0:
self.show_error('卡号错误', '卡号不存在!')
return
else:
if dicc['card']['password'] != gain_password:
self.show_error('解锁', '密码错误!解锁失败!')
else:
if dicc['person']['person_id'] == gain_person_id and dicc['person']['name'] == gain_name:
dii['chance'] = 0
dicc['card']['lock'] = False
self.dump_user()
self.show_get('解锁', '银行卡解锁成功!')
else:
self.show_error('解锁', '信息错误,银行卡解锁失败!')
# 按回车解锁
def fucgo(event):
check_five()
dellock_win.bind('<Return>', fucgo)
an_e = tk.Button(dellock_win, text='解锁', font=('宋体', 14), command=check_five, width=8, height=2)
an_e.place(x=270, y=420)
dellock_win.mainloop()
def del_card(self):
"""销户及可视化页面"""
del_card_win = tk.Tk()
del_card_win.title('销户页面')
del_card_win.geometry('600x560')
lab_m = tk.Label(del_card_win, text='销 户', font=('宋体', 30))
lab_m.place(x=250, y=60)
lab_tip = tk.Label(del_card_win,text='请正确填写以下信息', font=('宋体', 11))
lab_tip.place(x=230,y=140)
#
lab_name = tk.Label(del_card_win, text='姓 名:', font=('宋体', 16))
lab_name.place(x=120, y=180)
v_name = tk.StringVar()
v_name.set('')
e_name = tk.Entry(del_card_win, textvariable=v_name, bd=4, font=('宋体', 12))
e_name.place(x=240, y=180)
#
lab_person_id = tk.Label(del_card_win, text='身份证号码:', font=('宋体', 16))
lab_person_id.place(x=115, y=220)
v_person_id = tk.StringVar()
v_person_id.set('')
e_person_id = tk.Entry(del_card_win, textvariable=v_person_id, bd=4, font=('宋体', 12))
e_person_id.place(x=240, y=220)
#
lab_phone = tk.Label(del_card_win, text='电 话:', font=('宋体', 16))
lab_phone.place(x=120, y=260)
v_phone = tk.StringVar()
v_phone.set('')
e_phone = tk.Entry(del_card_win, textvariable=v_phone, bd=4, font=('宋体', 12))
e_phone.place(x=240, y=270)
#
lab_cardid = tk.Label(del_card_win, text='银行卡号:', font=('宋体', 16))
lab_cardid.place(x=120, y=300)
v_card = tk.StringVar()
v_card.set('')
e_card = tk.Entry(del_card_win, textvariable=v_card, bd=4, font=('宋体', 12))
e_card.place(x=240, y=310)
#
lab_password = tk.Label(del_card_win, text='密 码:', font=('宋体', 16))
lab_password.place(x=130, y=350)
v_password = tk.StringVar()
v_password.set('')
e_password = tk.Entry(del_card_win, textvariable=v_password, bd=4, font=('宋体', 12), show='*')
e_password.place(x=240, y=360)
#
def check_two():
gain_cardid = e_card.get()
gain_password = e_password.get()
gain_name = e_name.get()
gain_person_id = e_person_id.get()
gain_phone = e_phone.get()
flag = 0
for dic in self.user_all['users']:
if dic['card']['cardid'] == gain_cardid:
flag = 1
if dic['card']['lock'] == True:
self.show_error('操作错误', '操作失败,此银行卡已被锁定!\n请解锁后在执行此操作!')
else:
for di in self.user_error['users']:
if di['cardid'] == gain_cardid:
# 判断密码
if dic['card']['password'] != gain_password:
di['chance'] += 1
if di['chance'] >= 3:
self.show_error('锁定信息', '对不起,密码错误,您的银行卡已被锁定!')
dic['card']['lock'] = True
else:
self.show_error('密码错误', '您输入的密码错误!\n您还有{}次机会'.format(3 - di['chance']))
self.dump_user()
# del_card_win.destroy()
return
else:
if dic['person']['name'] == gain_name and dic['person']['person_id'] == gain_person_id and dic['person']['phone'] == gain_phone:
# 发送最后的确认
v = tk.messagebox.askyesno('销户确认', '信息正确,是否销户?\n销户后银行卡中的剩余金钱将不予退还!')
if v:
self.user_all['users'].remove(dic)
self.user_error['users'].remove(di)
self.user_error['count'] -= 1
self.user_all['count'] -= 1
self.dump_user()
self.show_get('操作成功', '操作成功,账户已注销!\n程序将返回菜单!')
del_card_win.destroy()
else:
self.show_get('操作成功', '取消成功!程序将返回菜单!')
del_card_win.destroy()
else:
self.show_error('销户操作', '信息错误,销户失败!')
# del_card_win.destroy()
return
break
if flag == 0:
self.show_error('信息错误','未查询到此银行卡!')
# del_card_win.destroy()
return
# 按回车销户
def fucgo(event):
check_two()
del_card_win.bind('<Return>', fucgo)
# 按键
an_del = tk.Button(del_card_win, text='销户', font=('宋体', 14), command=check_two, width=8, height=1)
an_del.place(x=290, y=440)
def get_newpsw(self):
"""修改密码及可视化页面"""
getnewpsw_win = tk.Tk()
getnewpsw_win.title('改密页面')
getnewpsw_win.geometry('700x580')
lab_ma = tk.Label(getnewpsw_win, text='改 密', font=('宋体', 30))
lab_ma.place(x=310, y=50)
lab_ma = tk.Label(getnewpsw_win, text='测试性功能,试运行。', font=('宋体', 12))
lab_ma.place(x=280, y=160)
#
lad_cardid = tk.Label(getnewpsw_win, text='银行卡号:', font=('宋体', 12))
lad_cardid.place(x=150, y=250)
v_cardid = tk.StringVar()
v_cardid.set('')
e_cardid = tk.Entry(getnewpsw_win, textvariable=v_cardid, bd=4, font=('宋体', 14))
e_cardid.place(x=240, y=250)
#
lad_personid = tk.Label(getnewpsw_win, text='身份证号:', font=('宋体', 12))
lad_personid.place(x=150, y=310)
v_personid = tk.StringVar()
v_personid.set('')
e_personid = tk.Entry(getnewpsw_win, textvariable=v_personid, bd=4, font=('宋体', 14))
e_personid.place(x=240, y=310)
#
lad_a = tk.Label(getnewpsw_win, text='验证码:', font=('宋体', 12))
lad_a.place(x=150, y=370)
v_a = tk.StringVar()
v_a.set('')
e_a = tk.Entry(getnewpsw_win, textvariable=v_a, bd=4, font=('宋体', 14))
e_a.place(x=240, y=370)
#
lad_new = tk.Label(getnewpsw_win, text='新密码:', font=('宋体', 12))
lad_new.place(x=150, y=430)
v_new = tk.StringVar()
v_new.set('')
e_new = tk.Entry(getnewpsw_win, textvariable=v_new, bd=4, font=('宋体', 14), show='*')
e_new.place(x=240, y=430)
# 验证码
sa = ''
def send_c():
nonlocal sa
personid = e_personid.get()
e_add = ''
for dic in self.user_all['users']:
if dic['person']['person_id'] == personid:
e_add = dic['person']['e_mail']
break
if e_add == '':
self.show_error('验证码', '身份证信息错误验证码发送失败!')
else:
sa = self.getid(n=4)
try:
self.send_email(sa, e_add)
self.show_get('验证码', '验证码发送成功,请注意查收!')
except:
self.show_error('验证码', '验证码发送失败,邮箱地址出错或者未连接网络!\n如果以上均正确,请联系开发者。')
def check_end():
cardid_i = e_cardid.get()
personid_i = e_personid.get()
sa_i = e_a.get()
pasnew_i = e_new.get()
dicc = {}
dii = {}
for dic in self.user_all['users']:
if dic['card']['cardid'] == cardid_i:
dicc = dic
break
if dicc:
for di in self.user_error['users']:
if di['cardid'] == cardid_i:
dii = di
break
if dicc['card']['lock']:
self.show_error('操作错误', '此银行卡已被锁定,请解锁后再进行此操作!')
else:
if dicc['person']['person_id'] == personid_i and sa == sa_i:
dicc['card']['password'] = pasnew_i
dii['chance'] = 0
self.dump_user()
self.show_get('操作成功', '密码修改成功!')
getnewpsw_win.destroy()
else:
self.show_error('操作失败', '信息错误!密码修改失败!')
else:
self.show_error('信息错误', '卡号不存在!')
# 按回车改密
def fucgo(event):
check_end()
getnewpsw_win.bind('<Return>', fucgo)
an_del = tk.Button(getnewpsw_win, text='发送验证码', font=('宋体', 14), command=send_c, width=10, height=1)
an_del.place(x=500, y=310)
an_del = tk.Button(getnewpsw_win, text='确认修改', font=('宋体', 14), command=check_end, width=8, height=1)
an_del.place(x=300, y=480)
getnewpsw_win.mainloop()
def explain(self):
"""对程序进行一些说明"""
win_say = tk.Tk()
win_say.title('程序使用说明')
win_say.geometry('480x360')
win_say.resizable(0, 0)
# 标题
tit_lab = tk.Label(win_say, text='使用说明', font=('华文彩云', 16))
tit_lab.place(x=200, y=50)
# 信息
mesg = "登录:在登录成功后,建议不要关闭登录界面。\n(统计的用户数不能实时更新)\n\n" \
"菜单界面:请在完成所有操作后再关闭菜单界面,否则你将会找不到它。\n\n" \
"开户:填写的信息(认真仔细填写)请记牢,有些信息将不可被再次查询。\n\n" \
"卡号:开户所得的卡号非常重要。\n\n" \
"改密:此功能可能由于邮件的发送而出现错误,这是一个不稳定的功能!\n" \
"请在联网的情况下使用改密功能。\n\n"\
"界面之间可能会有重叠。\n\n" \
"登录等主要操作按键可以使用回车执行。\n\n" \
"程序创建的json文件请不要删除!\n\n"
ms_lab = tk.Label(win_say, text=mesg, font=('宋体', 10))
ms_lab.place(x=20, y=100)
def show_get(self, tite, mesg):
"""发送需要的弹窗信息"""
tk.messagebox.showinfo(tite,mesg)
def show_error(self, tite, mesg):
"""发送错误的弹窗信息"""
tk.messagebox.showerror(tite,mesg)
def dump_user(self):
"""将用户数据存储"""
with open('usersofbank.json', 'w') as f:
json.dump(user_all, f)
with open('usersoferror.json', 'w') as fp:
json.dump(user_error, fp)
def send_email(self,st, emil_add):
"""发送邮件"""
pass
# # 邮件文本
# ss = "【银行系统】{}(银行卡修改密码的验证码),此验证码仅用于修改密码验证,提供给他人可能导致银行卡被盗,请勿转发。".format(st)
# msg = MIMEText(ss, 'html', 'utf-8')
# # 显示发件人
# msg['From'] = formataddr(["银行系统", "【这里填你的发件邮箱地址】"])
# msg['Subject'] = '银行系统修改密码验证'
#
# server = smtplib.SMTP_SSL('smtp.qq.com')
# server.login("【这里填你的发件邮箱地址】", "【这里填你的密码(并不是登录密码)】")
# server.sendmail("【这里填你的发件邮箱地址】", emil_add, msg.as_string())
# server.quit()
if __name__ == '__main__':
"""程序开始执行的地方"""
"""载入用户信息与用户密码错误累计次数文件"""
# 用户信息
if os.path.exists('usersofbank.json'):
file = 'usersofbank.json'
else:
f = open('./usersofbank.json', 'w')
f.close()
file = 'usersofbank.json'
if os.path.getsize(file):
with open(file, 'r') as f:
user_all = json.load(f)
else:
user_all = {'users': [], 'count': 0}
# 用户密码错误次数
if os.path.exists('usersoferror.json'):
file = 'usersoferror.json'
else:
f = open('./usersoferror.json', 'w')
f.close()
file = 'usersoferror.json'
if os.path.getsize(file):
with open(file, 'r') as f:
user_error = json.load(f)
else:
user_error = {'users': [], 'count': 0}
# 开始运行
bank = Bank(user_all, user_error)
bank.bankmain()