示例#1
0
def perform_transaction():
    '''Function to add the entry the amount in the amount entry from the user balance and add an entry to the transaction list.'''
    global user
    global amount_entry
    global balance_label
    global balance_var
    global entry_type

    # Try to decrease the account balance and append the deposit to the account file
    try:

        # Get the cash amount to use. Note: We check legality inside account's withdraw_funds method
        balance = balance_var.get()
        balance = balance.strip()
        balance = balance.replace(" ", "")
        file = str(user_number_var.get())
        MoneyManager.add_entry(file, balance)
        fo = open(file + ".txt", "rb")
        fo.readline()
        fo.readline()
        fo.seek(12, 1)
        bal = fo.readline()
        bal = str(bal)
        bal = bal.replace("b", "")
        bal = bal.replace("r", "")
        bal = bal.replace("n", "")
        bal = bal.replace("\\", "")
        bal = bal.replace("'", "")
        bal = float(bal)
        fo.close()

        # Get the type of entry that will be added ie rent etc
        global variable
        v = variable.get()

        if float(balance) > float(bal):
            c = Tk()
            c.title('FedUni Money Manager')
            l = Label(c,
                      text='No Enough Amount in Account',
                      font=("Helvetica", 16))
            l.pack()
            c.mainloop()
            return

        # Withdraw funds from the balance
        bal = float(bal) - float(balance)

        # Update the transaction widget with the new transaction by calling user.get_transaction_string()
        # Note: Configure the text widget to be state='normal' first, then delete contents, then instert new
        #       contents, and finally configure back to state='disabled' so it cannot be user edited.
        MoneyManager.get_transaction_string(file, bal)

        # Change the balance label to reflect the new balance
        global y
        y.set("Balance : $ " + str(bal))
        MoneyManager.save_to_file(file, v, balance)
        fo = open(file + ".txt", "r")
        fo.readline().replace("\n", "")
        fo.readline().replace("\n", "")
        fo.readline().replace("\n", "")
        fo.readline().replace("\n", "")
        x = fo.readline()
        transaction_list = x
        while x:
            x = fo.readline()
            transaction_list = transaction_list + x
        fo.close()
        Textbox.delete(1.0, END)
        Textbox.insert(END, transaction_list)

        # Update the graph
        plot_spending_graph()

        # Clear the amount entry
        global balance_entry
        balance_entry.delete(0, END)

    # Catch and display any returned exception as a messagebox 'showerror'
    except:
        c = Tk()
        c.title('FedUni Money Manager')
        l = Label(c, text='Something Went Wrong', font=("Helvetica", 16))
        l.pack()
        c.mainloop()
示例#2
0
def perform_deposit():
    '''Function to add a deposit for the amount in the amount entry to the
       user's transaction list.'''
    global user
    global amount_entry
    global balance_label
    global balance_var

    try:
        bal = balance_var.get()
        bal = float(bal)
    except:
        c = Tk()
        c.title('FedUni Money Manager')
        l = Label(c, text='Enter Valid Data', font=("Helvetica", 16))
        l.pack()
        c.mainloop()
        return

    # Try to increase the account balance and append the deposit to the account file
    try:

        # Get the cash amount to deposit. Note: We check legality inside account's deposit method
        balance = balance_var.get()
        balance = balance.strip()
        balance = balance.replace(" ", "")
        file = str(user_number_var.get())
        MoneyManager.deposit_funds(file, balance)
        fo = open(file + ".txt", "rb")
        fo.readline()
        fo.readline()
        fo.seek(12, 1)
        bal = fo.readline()
        bal = str(bal)
        bal = bal.replace("b", "")
        bal = bal.replace("r", "")
        bal = bal.replace("n", "")
        bal = bal.replace("\\", "")
        bal = bal.replace("'", "")
        bal = float(bal)
        fo.close()

        # Deposit funds
        bal = float(bal) + float(balance)

        # Update the transaction widget with the new transaction by calling account.get_transaction_string()
        # Note: Configure the text widget to be state='normal' first, then delete contents, then instert new
        #       contents, and finally configure back to state='disabled' so it cannot be user edited.
        MoneyManager.get_transaction_string(file, bal)

        # Change the balance label to reflect the new balance
        global y, variable
        y.set("Balance : $ " + str(bal))
        v = "Deposit "
        MoneyManager.save_to_file(file, v, balance)
        fo = open(file + ".txt", "r")
        fo.readline().replace("\n", "")
        fo.readline().replace("\n", "")
        fo.readline().replace("\n", "")
        fo.readline().replace("\n", "")
        x = fo.readline()
        transaction_list = x
        while x:
            x = fo.readline()
            transaction_list = transaction_list + x
        fo.close()
        Textbox.delete(1.0, END)
        Textbox.insert(END, transaction_list)

        # Clear the amount entry
        global balance_entry
        balance_entry.delete(0, END)

        # Update the interest graph with our new balance
        plot_spending_graph()

    # Catch and display exception as a 'showerror' messagebox with a title of 'Transaction Error' and the text of the exception
    except:
        c = Tk()
        c.title('FedUni Money Manager')
        l = Label(c, text='Something Went Wrong', font=("Helvetica", 16))
        l.pack()
        c.mainloop()