Re: Budget Builder file: dbtools.e edit 1

new topic     » goto parent     » topic index » view thread      » older message » newer message

Edit 1 note: Moved routines init_db() and quit() to file: register.ex

-- 
-- db_tools.e edit 1 
-- 
include std/text.e 
include std/eds.e 
include std/io.e 
include std/datetime.e 
include std/filesys.e 
public include std/graphics.e 
public include reg_graphics.e 
public include formtext.e 
 
public sequence tables, current_table 
integer table_size 
 
public constant DB = "check_register.edb" 
-- tables 
public constant REGISTER = "register", REG = REGISTER, 
                        BUDGET = "budget", 
                                CASH = "CASH", 
                                   RESERVE = "RESERVE" 
                                    
                                    
public procedure list_tables() -- list tables, highlights current table 
sequence text = "\n\n\t\tDatabase Table List" 
    update_tables() 
    set_foreground_color(FGC) 
    display(text) 
    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 
    any_key("\n\n\tPress Any Key to Continue...") 
end procedure 
 
public procedure update_tables() 
    tables = db_table_list() 
    current_table = db_current_table() 
    table_size = db_table_size() 
end procedure 
 
-- public procedure quit() db_close() abort(0) 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 -- 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() 
file_number FN 
datetime dt = now() 
sequence dtstr, dump_file, db = db_current() 
    db= filebase(db) 
    dtstr = text:format("[]:[]:[]:[]:[]-",{dt[YEAR],dt[MONTH],dt[DAY],dt[HOUR],dt[MINUTE]}) 
    dump_file = dtstr & db & "-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 
-- end dbtools.e 

Regards, Ken

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu