# Property of Four Js* # (c) Copyright Four Js 1995, 2019. All Rights Reserved. # * Trademark of Four Js Development Tools Europe Ltd # in the United States and elsewhere # # Four Js and its suppliers do not warrant or guarantee that these # samples are accurate and suitable for your purposes. Their inclusion is # purely for information purposes only. TYPE schema_rec RECORD table_name STRING, -- customer field_name STRING, -- customer_name field_type SMALLINT, -- 0 field_strtype STRING, -- CHAR(30) field_length SMALLINT -- 80 END RECORD DEFINE col_arr DYNAMIC ARRAY OF schema_rec DEFINE tab_arr DYNAMIC ARRAY OF STRING DEFINE currtable STRING --current table in combobox --a(vailable) fields DEFINE afields DYNAMIC ARRAY OF RECORD atable STRING, acol STRING END RECORD --c(hosen) fields DEFINE cfields DYNAMIC ARRAY OF RECORD ctable STRING, ccol STRING END RECORD -- Current wizard page DEFINE currpage SMALLINT DEFINE myd ui.Dialog CONSTANT TOTAL_PAGES = 5 MAIN CLOSE WINDOW screen CALL wizard() END MAIN --contains the wizard MD dialog FUNCTION wizard() DEFINE i INT CALL readTables("stores.sch") OPEN WINDOW formwizard WITH FORM "formwizard" CALL init_tables() OPTIONS FIELD ORDER FORM DIALOG ATTRIBUTES(UNBUFFERED) INPUT BY NAME currtable ATTRIBUTES(WITHOUT DEFAULTS=TRUE) ON CHANGE currtable CALL on_change_currtable() CALL setup(DIALOG) END INPUT DISPLAY ARRAY afields TO a.* END DISPLAY DISPLAY ARRAY cfields TO c.* END DISPLAY ON ACTION right CALL right(DIALOG) ON ACTION allright CALL allright(DIALOG) ON ACTION left CALL left(DIALOG) ON ACTION allleft CALL allleft(DIALOG) ON ACTION prevwiz DISPLAY "prevwiz" EXIT DIALOG ON ACTION nextwiz DISPLAY "nextwiz" EXIT DIALOG ON ACTION cancel EXIT DIALOG ON ACTION accept ACCEPT DIALOG BEFORE DIALOG LET currpage = 1 CALL setup(DIALOG) AFTER DIALOG --we just show all chosen columns in the terminal FOR i=1 TO cfields.getLength() DISPLAY sfmt("table:%1,column:%2",cfields[i].ctable,cfields[i].ccol) END FOR END DIALOG LET myd=NULL CLOSE WINDOW formwizard END FUNCTION --fill the combobox with all table names FUNCTION init_tables() DEFINE cb ui.ComboBox DEFINE i INTEGER LET cb = ui.ComboBox.forName("formonly.currtable") IF cb IS NULL THEN CALL myerror("combobox not found") END IF FOR i=1 TO tab_arr.getLength() CALL cb.addItem(tab_arr[i],tab_arr[i]) END FOR LET currtable=tab_arr[1] CALL on_change_currtable() END FUNCTION --combo value has changed,refill the left array and omit --values of the right hand side FUNCTION on_change_currtable() DEFINE tab,col STRING DEFINE col_len,used_col_len,idx,i,j,foundUsed INT IF myd IS NOT NULL THEN CALL myd.deleteAllRows("a") ELSE CALL afields.clear() END IF LET idx=0 LET col_len=col_arr.getLength() FOR i=1 TO col_len LET tab=col_arr[i].table_name LET col=col_arr[i].field_name LET used_col_len=cfields.getLength() LET foundUsed=FALSE FOR j=1 TO used_col_len IF cfields[j].ctable=tab AND cfields[j].ccol=col THEN LET foundUsed=TRUE EXIT FOR END IF END FOR IF NOT foundUsed AND tab=currtable THEN LET idx=idx+1 IF myd IS NOT NULL THEN CALL myd.appendRow("a") ELSE CALL afields.appendElement() END IF LET afields[idx].atable=tab LET afields[idx].acol=col END IF END FOR END FUNCTION FUNCTION setup(d) DEFINE d ui.Dialog DEFINE rl,rr INT LET myd=d LET rl = afields.getLength() LET rr = cfields.getLength() CALL d.setActionActive("right", rl>0) CALL d.setActionActive("allright", rl>0) CALL d.setActionActive("left", rr>0) CALL d.setActionActive("allleft", rr>0) CALL d.setActionActive("prevwiz", currpage>1) CALL d.setActionActive("nextwiz", currpage prevTabName THEN LET tab_arr[tab_arr.getLength()+1]=sch.table_name LET prevTabName=sch.table_name END IF END WHILE CALL ch.close() IF tab_arr.getLength()==0 THEN CALL myerror("did not find any coluns in "||schemaFile) END IF END FUNCTION FUNCTION myerror(str) DEFINE str STRING DISPLAY "ERROR:",str EXIT PROGRAM 1 END FUNCTION