Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require "iuplua"
- bankAccounts = {}
- bankAccounts.__index = bankAccounts
- accounts = {}
- try = 0
- function loadAccounts()
- file = io.open("accounts/dir.txt","r")
- for i in file:lines() do
- table.insert(accounts,i)
- end
- for i = 1,#accounts do
- file = io.open("accounts/"..accounts[i],"r")
- for i in file:lines() do
- if try == 0 then
- name = i
- try = try + 1
- elseif try == 1 then
- code = i
- try = try + 1
- elseif try == 2 then
- balance = i
- end
- end
- accounts[name] = createAccount( name, balance, code )
- end
- end
- function createAccount( name, balance, code )
- account = {}
- setmetatable(account,bankAccounts)
- account.name = name
- account.balance = balance
- account.code = code
- updateUserInfo( name, balance,code )
- return account
- end
- function updateUserInfo( name,balance,code )
- file = io.open("accounts/"..name,"w")
- file:write(name)
- file:write("\n"..code)
- file:write("\n"..balance)
- file:close()
- end
- function bankAccounts:withdrawFunds( code, amount )
- if self.code ~= nil then
- if code == self.code then
- if tonumber(self.balance) >= tonumber(amount) then
- self.balance = tonumber(self.balance) - amount
- updateUserInfo( self.name , self.balance, code)
- transaction = self.balance
- else
- transaction = "Withdraw To Large", self.balance
- end
- else
- transaction = "Invalid Code"
- end
- else
- transaction = "No Such Account"
- end
- return transaction
- end
- function bankAccounts:addFunds( code, amount )
- if self.code ~= nil then
- if code == self.code then
- self.balance = tonumber(self.balance) + amount
- updateUserInfo( self.name, self.balance, code)
- transaction = self.balance
- else
- transaction = "Invalid Code"
- end
- else
- transaction = "No Such Account"
- end
- return transaction
- end
- function bankAccounts:deleteAccount()
- os.remove("accounts/"..self.name..".txt")
- self.name = nil
- self.balance = nil
- self.code = nil
- return true
- end
- function loadInterface()
- --Elements
- withdraw = iup.button {
- title = "Withdraw Funds",
- padding = "25x5",
- action = function() loadWithdraw() window:hide() end
- }
- create = iup.button {
- title = "Create Account",
- padding = "27x5"
- }
- add = iup.button {
- title = "Add Funds",
- padding = "38x5"
- }
- delete = iup.button {
- title = "Delete Account",
- padding = "26x5"
- }
- --Dialog
- window = iup.dialog {
- iup.vbox {
- iup.hbox {
- iup.vbox {
- iup.hbox {
- withdraw,
- add,
- },
- iup.hbox {
- create,
- delete,
- },
- },
- },
- },
- title = "Banker",
- size = "200x55"
- }
- window:show()
- end
- function loadWithdraw()
- --Elements
- title = iup.label {title = "Withdraw Funds", padding = "95x0"}
- five = iup.button {
- title = "$5",
- padding = "50x5",
- }
- ten = iup.button {
- title = "$10",
- padding = "49x5",
- }
- twenty = iup.button {
- title = "$25",
- padding = "49x5",
- }
- fifty = iup.button {
- title = "$50",
- padding = "49x5",
- }
- --Dialog
- withdrawWindow = iup.dialog {
- iup.vbox {
- iup.hbox {
- five,
- ten
- },
- iup.hbox{
- twenty,
- fifty
- },
- },
- title = "Banker",
- size = "200x55"
- }
- withdrawWindow:show()
- end
- loadInterface()
- if (iup.MainLoopLevel() == 0) then
- iup.MainLoop()
- end
Add Comment
Please, Sign In to add comment