基于python实现银行管理系统
程序员文章站
2022-06-27 10:41:37
一、python银行管理系统二、分析部分三、代码部分import randomclass bankuser: # 卡号,用户姓名,身份证号,手机,预存,密码 count_id = ""...
一、python银行管理系统
二、分析部分
三、代码部分
import random class bankuser: # 卡号,用户姓名,身份证号,手机,预存,密码 count_id = "" count_name = "" count_idcard = "" count_phone = "" count_money = 0.00 count_password = "" count_root = true def __init__(self, count_id, count_idcard, count_name, count_phone, count_money, count_password, count_root): self.count_id = count_id self.count_idcard = count_idcard self.count_phone = count_phone self.count_money = count_money self.count_password = count_password self.count_root = count_root self.count_name = count_name class daoserver: # 检测账号是否已经被锁 def islock(self, i_id): with open("f:\\userfile.txt", 'r') as seafile: mes = seafile.readlines() for index in mes: matchid = index.split("~")[0] if matchid == i_id and index.split("~")[6] is false: return true pass return false # 作用1:开户匹配是否有同样的身份证注册这个账户,有就返回假,没有返回真。传的参数是身份证号 # 作用2:在查询时看看是否存在这个账号 def searchblock(self, idcard): with open("f:\\userfile.txt", 'r') as seafile: mes = seafile.readlines() # id~pass~idcard~name~phone~money for index in mes: matchidcard = index.split("~")[1] matchid = index.split("~")[0] if matchidcard == idcard or matchid == idcard: return false pass return true # 注册账户 def register(self, user): if self.searchblock(user.count_idcard): # 开始开户 a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] # 产生的一个账号 numarray = random.sample(a, 6) # id~pass~idcard~name~phone~money # count_id, count_idcard, count_phone, count_money, count_password, count_root # user.count_id = ''.join(str(k) for k in numarray) # 用于生成的账户是否已经存在,如果存在就重新生成 while not self.searchblock(user.count_id): numarray = random.sample(a, 6) # count_id, count_idcard, count_phone, count_money, count_password, count_root user.count_id = ''.join(str(k) for k in numarray) line = user.count_id + "~" + user.count_idcard + "~" + user.count_name + "~" + user.count_phone + "~" + str( user.count_money) + "~" + user.count_password + "~" + str(user.count_root) + "\n" with open("f:\\userfile.txt", 'a+') as writefile: writefile.writelines(line) pass return true else: return false # 验证密码和账号是否一致 # 正确返回user对象,否则返回null def proof(self, pid, ppassword): with open("f:\\userfile.txt", 'r') as prooffile: proofmes = prooffile.readlines() for pindex in proofmes: fid = pindex.split("~")[0] fpassword = pindex.split("~")[5] if fid == pid and fpassword == ppassword: f = bankuser(pindex.split("~")[0], pindex.split("~")[1], pindex.split("~")[2], pindex.split("~")[3], pindex.split("~")[4], pindex.split("~")[5], pindex.split("~")[6]) return f return none # 锁控制函数 + 还可以进行重新数据更新后重新写入数据 # 数据更新函数 def lock(self, locku, res): lid = locku.count_id r_mes = [] with open('f:\\userfile.txt', 'r') as rfile: r_mes = rfile.readlines() for r_index in r_mes: if r_index.split("~")[0] == lid: line = lid + "~" + r_index.split("~")[1] + "~" + r_index.split("~")[2] + "~" + r_index.split("~")[ 3] + "~" + str(locku.count_money) + "~" + r_index.split("~")[5] + "~" + str(res) + "\n" r_mes.remove(r_index) r_mes.append(line) break pass with open('f:\\userfile.txt', 'w') as file: pass with open('f:\\userfile.txt', 'w') as file: for i in r_mes: file.writelines(i) pass # 查询账户 def search(self, sid, spassword): # 看看有没有这个账户 # 参数:账户 if not self.searchblock(sid): # 存在这个账户,然后进行账户密码验证 # 查看是否被锁定 if self.islock(sid): print("账号有危险,程序自动退出!") exit(0) res = self.proof(sid, spassword) n = 1 while res is none and n <= 3: spassword = input("密码有误,请重新输入:") n = n + 1 res = self.proof(sid, spassword) if res is none: # 锁住,返回 self.lock(sid, false) print("有危险,账号已经锁住!") return none else: # 打印信息 print("=" * 50) print("||", " " * 13, res.count_name, " 先生(女士)", " " * 13, "||") print("||\t账户:", res.count_id, " " * 6, "金额:", res.count_money, " " * 13, "||") print("=" * 50) return res else: print("本行没有这个账户!") return none pass # 取款 | 存款 # 1 2 def getorsavemoney(self, flag, gid, gpassword): getres = self.search(gid, gpassword) if getres is none: return none else: if flag is 1: money = int(input("请输入你要取的金额:")) getres.count_money = int(getres.count_money) - money if money <= 0 or money > int(getres.count_money): print("输入有误") return getres else: money = int(input("请输入你要存的金额:")) getres.count_money = int(getres.count_money) + money self.lock(getres, true) print(getres.count_money) return getres # 获取转向那个人的目标钱数 def getgoalmoey(self, goalid): with open("f:\\userfile.txt", 'r') as seafile: mes = seafile.readlines() for index in mes: if index.split("~")[0] == goalid: return int(index.split("~")[4]) pass # 转账 def transfer(self, tid, tpa): rres = self.search(tid, tpa) if rres is not none: if self.islock(tid): print("此账号有危险,程序自动退出!") exit(0) # 转向账号 goalid = input("请输入你要转向的那个人的账号:") if self.searchblock(goalid): print("本行没有 ", goalid, " 这个账户") else: much = int(input("请输入你要转的金额:")) if much < 0 or much > int(rres.count_money): print("输入有误,即将退出...") return none else: u = bankuser(goalid, "", "", "", str(self.getgoalmoey(goalid) + much), "", true) # def lock(self, locku, res): self.lock(u, true) rres.count_money = int(rres.count_money) - much self.lock(rres, true) print("已经完成转账!") else: print("本行没有 ", tid, " 这个账户") def welcomeview(): print("*" * 40) print("***", " " * 32, "***") print("***", " " * 32, "***") print("***", " " * 7, "欢迎登录银行管理系统", " " * 7, "***") print("***", " " * 32, "***") print("***", " " * 32, "***") print("*" * 40) def functionview(): print("*" * 50) print("***", " " * 42, "***") print("***\t1.开户(1)", " " * 20, "2.查询(2)\t ***") print("***\t3.取款(3)", " " * 20, "5.存款(4)\t ***") print("***\t5.转账(5)", " " * 20, "6.锁定(6)\t ***") print("***\t7.解锁(7)", " " * 32, "***") print("***", " " * 42, "***") print("***\t退出(q)", " " * 35, "***") print("***", " " * 42, "***") print("*" * 50) welcomeview() print("欢迎管理员前来工作:") b = true m_id = input("请输入管理员账号:") while b: if m_id == "admine": break else: m_id = input("请重新输入管理员账号:") pas = input("请输入管理员密码:") a = true m_pas = input("请输入管理员密码:") while a: if m_pas == "123": break else: m_pas = input("请重新输入管理员密码:") functionview() type = input("请输入你的操作:") while type is not 'q': if type == "1": u_name = input("请输入你的姓名:") u_phone = input("请输入你的电话:") u_idcard = input("请输入你的身份证号:") u_money = input("请输入你的预存金额:") u_pass = input("请输入你的密码:") u_user = bankuser("", u_idcard, u_name, u_phone, int(u_money), u_pass, true) d1 = daoserver() boo = d1.register(u_user) if boo: print("注册成功!") else: print("注册失败!") elif type == "2": s_id = input("请输入你的账户:") s_pass = input("请输入你的密码:") d2 = daoserver() d2.search(s_id, s_pass) elif type == "3": d3 = daoserver() g_id = input("请输入你的账户:") g_pass = input("请输入你的密码:") d3.getorsavemoney(1, g_id, g_pass) elif type == "4": d4 = daoserver() s_id = input("请输入你的账户:") s_pass = input("请输入你的密码:") d4.getorsavemoney(2, s_id, s_pass) elif type == "5": t_id = input("请输入你的账户:") t_pass = input("请输入你的密码:") d5 = daoserver() d5.transfer(t_id, t_pass) elif type == "6": d5 = daoserver() p_id = input("请输入你的账户:") p_pass = input("请输入你的密码:") flag = d5.proof(p_id, p_pass) if flag is not none: d5.lock(flag, false) print("锁定成功!") else: print("锁定失败") elif type == "7": d6 = daoserver() ul_id = input("请输入你的账户:") ul_pass = input("请输入你的密码:") flag = d6.proof(ul_id, ul_pass) if flag is not none: d5.lock(flag, true) print("解锁成功") else: print("解锁失败") elif type =="q" or type == "q": exit(0) else: print("输入有误请重新输入:") type = input("请输入你的操作:") functionview()
到此这篇关于基于python实现银行管理系统的文章就介绍到这了,更多相关python银行管理系统内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!