forum-msg-id-135085-edit

Original date:2020-10-01 19:24:06 Edited by: Senator Subject: Re: Budget Builder

-- 
-- db_tools.e 
--  Kenneth Rhodes 
-- 
include std/text.e 
include std/eds.e 
include std/io.e 
include std/datetime.e 
include std/filesys.e 
include std/graphics.e 
include reg_graphics.e 
include formtext.e 
include register.e 
 
public constant DB = "check_register.edb" 
-- tables 
public constant REGISTER = "register", REG = REGISTER, BUDGET = "budget", 
CASH = "CASH",RESERVE = "RESERVE" 
 
public sequence tables, current_table  
public integer table_size 
 
public procedure update_tables() 
    tables        =     db_table_list() 
    current_table =     db_current_table() 
    table_size    =     db_table_size() 
--    list() 
end procedure 
 
public procedure list_tables() -- list tables, highlights current table 
    update_tables() 
    set_foreground_color(FGC) 
    display("\n\n\t\tDatabase Table List") 
    for i = 1 to length(tables) do  
        text = text:format("\n\t\t[]: []",{i,tables[i]}) 
        if equal(tables[i],current_table) then hilite(text, HLC,0) 
        else display(text,{},0)  
        end if  
    end for 
end procedure 
 
public procedure quit() db_close() abort(0) end procedure 
 
public 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("Could not Select table: []", {REGISTER})  any_key("")  
    end if 
    update_tables() 
end procedure 
 
public procedure select_table() 
integer t, x, ct -- ct = create table 
sequence text, initial_table = db_current_table() 
    list_tables() 
    ct = length(tables)+1 
    x  = length(tables)*-1 
    text=text:format(   "\n\n\t\t\tSelect table Enter table # " &  
                        "\n\t\t\tEnter  0 to continue with current table" & 
                        "\n\t\t\tEnter -# of table to delete the table"  & 
                        "\n\t\t\tEnter [] to create a new table: ",ct) 
    t = prompt_number(text,{x,ct}) 
    if t>0 then 
        if t = ct then -- create new table 
            text = prompt_string("\n\t\t\tEnter name of new table: ") 
            text = upper(text) 
            if db_create_table(text) != DB_OK then 
                any_key("\n\t\t\tERROR! Failed to create new table...") 
            end if 
        else -- select table 
            if db_select_table(tables[t]) != DB_OK then  
                display("\n\t\t\tERROR! Could not select: ",0) 
                hilite(sprintf("%s",{tables[t]})) 
            end if 
        end if 
    elsif t = 0 then return -- do nothing continue with current table 
    else -- t < 0  -- delete table  
        t*=-1 -- convert x to positive table # 
        text=text:format("\n\n\t\t\tDelete table []? yes = 1, no = 0: ", {tables[t]}) 
        x = prompt_number(text,{0,1}) 
        if x then db_delete_table(tables[t]) 
            db_select_table(initial_table) 
        end if 
    end if 
update_tables() 
end procedure 
 
public procedure DbDump(sequence db = db_current()) 
file_number FN 
datetime dt = now() 
sequence dtstr, dump_file, db_name = filebase(db) 
    dtstr = text:format("[]:[]:[]:[]:[]-",{dt[YEAR],dt[MONTH],dt[DAY],dt[HOUR],dt[MINUTE]}) 
    dump_file = dtstr & db_name & "-Db-Dump.txt"  
    FN = open(dump_file,"w")  
    db_dump(FN)  
    close(FN) 
    system("less " & dump_file)  
end procedure 
 
public procedure rename_table() 
integer t 
sequence tmenu, new_table_name, text 
    list_tables() 
    tmenu=text:format(  "\n\n\t\t\tSelect table to rename" &  
                        "\n\t\t\tEnter 0 to abort #: " ) 
    t = prompt_number(tmenu,{0,length(tables)}) 
    if t then -- rename table 
       text = text:format("\n\n\t\t\t\Enter new name for table: [] : ", {tables[t]}) 
       new_table_name = prompt_string(text) 
       new_table_name = upper(new_table_name) 
       db_rename_table(tables[t],new_table_name) 
       update_tables() 
       list_tables() 
    end if 
end procedure 

Regards, Ken

Not Categorized, Please Help

Search



Quick Links

User menu

Not signed in.

Misc Menu