rem ' Customer master file maintenance (Visual PRO/5 GUI user interface)

dim customer$:"id:c(6),name:c(32),phone:c(24)"
filename$ = "customer.dat"
customer = unt
open (customer,err=makefile)filename$
goto init

makefile:
mkeyed filename$,[0:1:6],0,64
open (customer)filename$
while 1
   dread customer.id$,customer.name$,customer.phone$,err=eof
   write record(customer)customer$
   continue
eof:
   break
wend
data "BASIS","BASIS International Ltd.","+1.505.345.5232"
data "CHILE","Chile Company","+1.555.555.1212"

init:
sysgui = unt
open (sysgui)"X0"; rem ' ALIAS X0 SYSGUI

print (sysgui)'window'(100,100,280,170,"Customers",$00010003$,$00c00000$)
print (sysgui)'text'(101,10,10,80,30,"ID:",$8000$)
print (sysgui)'edit'(102,100,10,70,30,$$,$$)
print (sysgui)'text'(103,10,50,80,30,"Name:",$8000$)
print (sysgui)'edit'(104,100,50,170,30,$$,$$)
print (sysgui)'text'(105,10,90,80,30,"Phone:",$8000$)
print (sysgui)'edit'(106,100,90,170,30,$$,$$)
print (sysgui)'button'(201,10,130,80,30,"Update",$$)
print (sysgui)'button'(202,100,130,80,30,"Delete",$$)
print (sysgui)'button'(203,190,130,80,30,"Clear",$$)

print (sysgui)'title'(102,"BASIS"),'focus'(102)
gosub fetch

dim event$:tmpl(sysgui)
repeat
    read record (sysgui,siz=10)event$
    if event.code$ = "e" and event.id = 102 then gosub toggle
    if event.code$ = "f" and event.id = 102 and event.flags = 0 then gosub fetch
    if event.code$ = "B" and event.id = 201 then gosub update
    if event.code$ = "B" and event.id = 202 then gosub remove
    if event.code$ = "B" and event.id = 203 then gosub clear
until event.code$="X"

release

toggle:
    id$ = cvs(ctrl(sysgui,102,1),7)
    if len(id$) then print (sysgui)'enable'(201,202) else print (sysgui)'disable'(201,202)
return

fetch:
    id$ = pad(cvs(ctrl(sysgui,102,1),7),6)
    if customer.id$ = id$ then return
    dim customer$:fattr(customer$)
    let customer.id$ = id$
    read record(customer,key=customer.id$,dom=notfound)customer$
notfound:
    gosub display
return

update:
    customer.id$ = ctrl(sysgui,102,1)
    customer.name$ = ctrl(sysgui,104,1)
    customer.phone$ = ctrl(sysgui,106,1)
    write record (customer)customer$
    i = msgbox("Customer "+customer.id$+" updated.",0,"Updated")
    gosub clear
return

remove:
    remove (customer,key=customer.id$,dom=nodelete)
    i = msgbox("Customer "+customer.id$+" deleted.",0,"Deleted")
nodelete:
    gosub clear
return

clear:
    dim customer$:fattr(customer$)
    gosub display
    print (sysgui)'focus'(102)
return

display:
    print (sysgui)'title'(102,cvs(customer.id$,3))
    print (sysgui)'title'(104,cvs(customer.name$,3))
    print (sysgui)'title'(106,cvs(customer.phone$,3))
return
