G4C

; DBase.gc
; This gui shows the simple use of DataBase listviews
; --------------------------------------------------------------
;       First make a DataBase file - This is done on loading
;       The file will have 0 records, and 4 fields.
;       Note : We only do this because we don't have any
;	existing file we can load..
; --------------------------------------------------------------

TEXTFILE ram:test.db
GCDB
0
5
%Number  4 N
%Item   10 S
%Units  8 N
%Price  10 N
%bal 20 S
###

; --------------------------------------------------------------
;       This is the actual start : The global commands
; --------------------------------------------------------------

WINBIG 75 22 515 169 "DataBase example"
WinType 11110001

; --------------------------------------------------------------
;       On Loading we use a "while" loop to give the DBase
;       file some records - again.. not needed
; --------------------------------------------------------------

xONLOAD
   ; use our database file (which we already created above)
   lvuse dbase.gc 1

   ; start the while loop
   count = 0
   while $count < 50
      ++count
      ; Add a line - we give '', but since this is a dbase file,
      ; the line that will be added will be the same length as
      ; all the other records. The new record will be blank.
      lvadd ''
      ; now give the fields some values
      %Number = $count
      %Item   = 'Line $count'
      %Units  = $($count * 1000)
      %Price  = $(($count * 120)/4)
      %bal    = 'This is line $%number'
   endwhile

   ; now open the window
   guiopen dbase.gc

   ; save the data, so you can have a look at the file
   lvsave ram:test.db


; ------ On closing, quit.

xONCLOSE
   guiquit dbase.gc


; --------------------------------------------------------------
;       The ListView 
;       - It's a normal multi-select lv..
; --------------------------------------------------------------

XLISTVIEW 0 13 514 157 "" var ram:test.db 0 MULTI
   gadid 1
   ; use the default proportional font (although monospace looks better)
   gadfont #screen 8 000
   
   ; use the ATTR gadget modifier to modify how fields will appear..
   ; note the field names (unlike variables) are case insensitive
   attr flstyle %number/2031    ; colors : front, bgnd, selected bgnd, shadow
   attr fljust %units/0         ; left justify %units 

   ; if an item is double clicked, print some stuff..
   Say '$%number[-2][2]\. $%item : $%units x $%price = $($%units *$%price)\n'


; --------------------------------------------------------------
;       Use these buttons to sort the list according to
;       %number or %item fields
; --------------------------------------------------------------

CTEXT 6 0 "Sort by:" #screen 8 2 0 0001

XBUTTON 77 0 70 12 "Number"
   lvuse dbase.gc 1
   lvsort %number

XBUTTON 147 0 70 12 "Item"
   lvuse dbase.gc 1
   lvsort %item

; --------------------------------------------------------------
;	These buttons will move the list left/right
; --------------------------------------------------------------

XBUTTON 235 0 20 12 "<<"
	lvuse dbase.gc 1
	lvmove -5

XBUTTON 255 0 20 12 "<"
	lvuse dbase.gc 1
	lvmove -1

XBUTTON 275 0 20 12 "[]"
	lvuse dbase.gc 1
	lvmove -1000		; i.e. move back to start..

XBUTTON 295 0 20 12 ">"
	lvuse dbase.gc 1
	lvmove 1

XBUTTON 315 0 20 12 ">>"
	lvuse dbase.gc 1
	lvmove 5

; --------------------------------------------------------------
;	The dbsum command
; --------------------------------------------------------------

XBUTTON 335 0 100 12 "DBSum"
	; sum some records..
	lvuse dbase.gc 1
	dbsum all %number num
	dbsum selected %units uni
	dbsum unselected %price pri
	say 'All numbers = $num\nSelected units = $uni\nUnselected price = $pri\n'




