コード例 #1
0
def main():
    filepath = os.path.join(os.getcwd(), "allusers.txt")

    f = open(filepath, "rb")

    allUsers = pickle.load(f)

    admin1 = int(input("请输入你的卡号:"))
    admin = Admin(allUsers,admin1)               #将登陆账户传入到用户类中储存

    atm = Atm(allUsers,admin1)                    #将登陆账户传入到atm类中储存
    if admin.login():

        admin.welcomeView()

        print("*********************************************************")
        # print(allUsers)
        print("请选择一下功能选项:")
        time.sleep(2)

        while True:
            admin.startView()
            option = input("请输入你要办理的业务号:")
            if option == '1':
                atm.createUser()
            elif option == '2':
                atm.selectInfor()
            elif option == '3':
                atm.get_Money()
            elif option == '4':
                atm.save_Money()
            elif option == '5':
                atm.transfer_Accounts()
            elif option == '6':
                atm.change_Password()
            elif option == '7':
                atm.card_Lock()
            elif option == '8':
                atm.card_ReLock()
            elif option == '9':
                atm.fill_Card()
            elif option == '0':
                atm.del_User()
            elif option == 't':
                f = open(filepath,"wb")
                pickle.dump(allUsers,f)
                f.close()
                break
            # time.sleep(2)
    else:
        atm.createUser()
        while True:
            admin.startView()
            option = input("请输入你要办理的业务号:")
            if option == '1':
                atm.createUser()
            elif option == '2':
                atm.selectInfor()
            elif option == '3':
                atm.get_Money()
            elif option == '4':
                atm.save_Money()
            elif option == '5':
                atm.transfer_Accounts()
            elif option == '6':
                atm.change_Password()
            elif option == '7':
                atm.card_Lock()
            elif option == '8':
                atm.card_ReLock()
            elif option == '9':
                atm.fill_Card()
            elif option == '0':
                atm.del_User()
            elif option == 't':
                f = open(filepath, "wb")
                pickle.dump(allUsers, f)
                # f.write(allUsers.encode("utf-8"))
                f.close()
                # return -1
                break
コード例 #2
0
def main():
    allUserInfo = {}

    try:
        f = open("peoplelist.txt", "rb")
        if len(f.read()) > 0:
            f.seek(0, 0)
            allUserInfo = pickle.load(f)
    except Exception as msg:
        print(msg)
        f = open("peoplelist.txt", "wb")
        print(msg)
    finally:
        f.close()

    adminview = View()
    adminview.printSysUI()

    atm = Atm(allUserInfo)

    #选择角色
    print("请选择角色:")
    print("1:管理员")
    print("2:普通用户")
    roleNum = input()  #角色序号
    if roleNum == '1':
        if not adminview.adminlogin():
            print("管理员登录失败")
            return
        time.sleep(1)
        print("管理员登录成功!请稍候...")

    elif roleNum == '2':
        #验证卡号是否存在
        while True:
            inputCard = input("请输入您的卡号:")
            isExist = atm.isExistCard(inputCard)
            if isExist:
                break

        #验证密码是否正确
        if not atm.isExistPwd(inputCard):
            #文件中写入所有用户信息
            f = open("peoplelist.txt", "wb")
            pickle.dump(atm.allUserInfo, f)
            f.close()
            return

    while True:
        adminview.printUI(roleNum)
        inputNum = input("请输入操作选项(数字):")

        if inputNum == '1' and roleNum == '1':
            print(atm.allUserInfo)
            atm.createUser()
            print(atm.allUserInfo)

        elif inputNum == '2' and roleNum == '2':
            #取款操作
            atm.nomony(inputCard)
        elif inputNum == '3' and roleNum == '2':
            atm.cunqian(inputCard)
        elif inputNum == '4' and roleNum == '2':
            atm.transMoney(inputCard)
        elif inputNum == '5' and roleNum == '2':
            atm.allpeople(inputCard)
        elif inputNum == '6' and roleNum == '2':
            atm.newpassword(inputCard)
        elif inputNum == '7' and roleNum == '1':
            if atm.jiechusuooding():
                print("解卡成功")
        elif inputNum == '0':
            exit()
        else:
            print("您操作有误,请重新操作!")

        #文件中写入所有用户信息
        f = open("peoplelist.txt", "wb")
        pickle.dump(atm.allUserInfo, f)
        f.close()