Re: Budget Builder - file: register.ex part 1 - edit 1
- Posted by Senator
Oct 05, 2020
-- register.ex
-- part 1, edit 1
include std/eds.e
include std/console.e
include std/io.e
include std/text.e
include std/datetime.e
include std/types.e
include std/filesys.e
include std/math.e
include std/utils.e
include std/error.e
include get_datetime.e
include reg_graphics.e
include formtext.e
include register.e
include db_tools.e
--
with type_check
with warning
warning_file("warning.log")
procedure init_db() -- initialize Db
if db_open(DB, DB_LOCK_NO) != DB_OK then
if db_create(DB, DB_LOCK_NO) != DB_OK then
display("Couldn't create database: []",{DB}) any_key("")
end if
if db_create_table(REGISTER) != DB_OK then
display("Could not create table: []", {REGISTER}) any_key("")
end if
if db_create_table(CASH) != DB_OK then
display("Could not create table: []", {CASH}) any_key("")
end if
if db_create_table(BUDGET) != DB_OK then
display("Could not create table: []", {BUDGET}) any_key("")
end if
if db_create_table(RESERVE) != DB_OK then
display("Could not create table: []", {RESERVE}) any_key("")
end if
end if
if db_select_table(REGISTER) != DB_OK then
display("\tCould not Select table: []", {REGISTER},1)
end if
end procedure
init_db()
function select_record()-- select record from current db table
sequence prompt = "\n\t\tEnter # of record to edit, Enter 0 to abort: "
integer rn -- rec #
list() puts(1,"\n")
rn=prompt_number(prompt, {0,db_table_size()})
if rn then return rn
else return 0 -- rn = 0, abort procedure
end if
end function
function remove_word(sequence note, sequence word)
integer start = match(word,note), stop = start+length(word)
return remove(note,start,stop)
end function
function replace_word(sequence note, sequence word, sequence new_word)
integer start = match(word,note), stop = start+length(word)
if stop != length(note) then new_word&=" " end if
return replace(note,new_word,start,stop)
end function
function edit_note(object note)-- edit transaction note
sequence word="", new_word=""
integer x
x=prompt_number("\n\t1. Append Keyword to transaction note"&
"\n\t2. Replace Keyword in transaction note"&
"\n\t3. Remove Keyword in transaction note"&
"\n\t4. Replace entire transaction note\n\t: ",{0,4})
if x = 1 then
new_word = prompt_string("\n\n\tAppend this Keyword to transaction note: ")
new_word = " "&new_word
note = splice(note,new_word,length(note)+1)
elsif x = 2 then
word = prompt_string("\n\tReplace this Keyword: ")
new_word = prompt_string("\n\tWith this Keyword: ")
note = replace_word(note,word,new_word)
elsif x = 3 then
word = prompt_string("\n\tRemove this word: ")
note = remove_word(note, word)
else note = prompt_string("\n\t\tEnter new transaction note\n\t: ")
end if
return note
end function
constant DEBIT=2, TA = {"Deposit", "Debit"}, -- transaction type
FIELDS = {"DATE: ", "Transaction Note: ", " $"} -- amount -- always enter without +- sign
public function debit_or_deposit() -- select transaction type:
integer t
set_foreground_color(FGC) puts(1, "\n\n\t\tTransaction Type\n\n")
for i = 1 to 2 do display("\t#[]. [] -- enter positive amount without sign",{i, TA[i]}) end for
t = prompt_number("\t#: ", {1,2})
if t = DEBIT then t = -1 end if
set_foreground_color(FGC)
return t
end function
-- end register.ex part 1, edit 1
Not Categorized, Please Help
|
|