home *** CD-ROM | disk | FTP | other *** search
- *!******************************************************
- *!
- *! Program: SpreadEm
- *! Purpose: Pseudo-spreadsheet demonstrating
- *! creative use of SAVESCREEN()
- *! Author: Greg Lief
- *! Copyright (c) 1990 Greg Lief
- *!
- *!******************************************************
- #include "gkeys.ch"
- LOCAL fields := { "REP" }, heads := { "Sales Rep" }, ;
- botrow, oldcolor, buffer, mrep, mrep_no, ;
- key := 0, mrow := 4, mcol := 6, marray, ;
- oldcursor := SETCURSOR(0), oldscoreb := SET(_SET_SCOREBOARD, .F.)
- PRIVATE box_color
- box_color := "+W/RB"
- SETCOLOR(main_color := "N/BG")
- CLEAR
- IF ! FILE('visit.dbf')
- marray := {}
- AADD(marray, { "Rep_No", "C", 2, 0 } )
- AADD(marray, { "Date", "D", 8, 0 } )
- AADD(marray, { "Branch", "C", 3, 0 } )
- AADD(marray, { "Comments", "M", 10, 0 } )
- DBCREATE('visit', marray)
- ENDIF
- USE visit NEW
- IF ! FILE('visit.ntx')
- INDEX ON Rep_No + Branch + DTOS(Date) TO visit
- ELSE
- SET INDEX TO visit
- ENDIF
- USE rep NEW
- IF ! FILE('rep.ntx')
- INDEX ON Rep_No TO rep
- ELSE
- SET INDEX TO rep
- ENDIF
- USE repbranc NEW
- IF ! FILE('repbranc.ntx')
- INDEX ON Rep_No + Branch TO repbranc
- ELSE
- SET INDEX TO repbranc
- ENDIF
- USE branch NEW
- IF ! FILE('branch.ntx')
- INDEX ON Number TO branch
- ELSE
- SET INDEX TO branch
- ENDIF
- SELECT rep
- GO TOP
- SETCOLOR(box_color)
- buffer = SAVESCREEN(6, 19, 18, 60)
- BOX2(6, 19, 18, 60)
- Center(18, '┤ ' + CHR(17) + CHR(217) + ;
- ' to select, Esc to exit ├')
- DBEDIT(7, 20, 17, 59, fields, '', '', heads)
- RESTSCREEN(6, 19, 18, 60, buffer)
- SETCOLOR(main_color)
- mrep = TRIM(Rep)
- mrep_no = Rep_No
- SELECT repbranc
- SEEK mrep_no
- IF ! FOUND()
- TONE(400,1)
- TONE(400,1)
- CENTER(12, "Sorry, no branches for " + mrep)
- INKEY(0)
- ELSE
- CLEAR
- CENTER(1, "Branch visits for " + mrep)
- @ 3, 6 SAY "JAN FEB MAR APR MAY JUN " + ;
- "JUL AUG SEP OCT NOV DEC"
- DO WHILE repbranc->Rep_No == mrep_no
- @ ROW()+1, 0 SAY Branch
- SELECT visit
- SEEK mrep_no + repbranc->Branch
- IF FOUND()
- DO WHILE Rep_No == mrep_no .AND. ;
- Branch == repbranc->Branch
- @ ROW(), MONTH(date) * 6 SAY ;
- DAY(date) PICTURE "##"
- SKIP
- ENDDO
- ENDIF
- SELECT repbranc
- SKIP
- ENDDO
- botrow = ROW() && can't sink any lower than this
- SELECT visit
- *** begin keystroke trapping routine
- DO WHILE key != ESC
- ChangeColor(mrow, mcol, mrow, mcol + 2, 78)
- key = INKEY(0)
- ChangeColor(mrow, mcol, mrow, mcol + 2, 48)
- DO CASE
-
- CASE key = LTARROW
- mcol = IF(mcol = 0, 72, mcol - 6)
-
- CASE key = UPARROW .AND. botrow != 4
- IF mrow = 4
- mrow = botrow
- ELSE
- mrow--
- ENDIF
-
- CASE key = DNARROW .AND. botrow != 4
- IF mrow = botrow
- mrow = 4
- ELSE
- mrow++
- ENDIF
-
- CASE key = RTARROW
- mcol = IF(mcol = 72, 0, mcol + 6)
-
- CASE key = CTRL_LEFT
- mcol = 6
-
- CASE key = CTRL_RIGHT
- mcol = 72
-
- CASE key = HOME
- mcol = 6
- mrow = 4
-
- CASE key = END
- mcol = 72
- mrow = botrow
-
- CASE key = PGUP
- mrow = 4
-
- CASE key = PGDN
- mrow = botrow
-
- CASE key = ENTER
- *** derive branch number for this row
- mbranch = ;
- LEFT(SAVESCREEN(mrow, 0, mrow, 0), 1) + ;
- LEFT(SAVESCREEN(mrow, 1, mrow, 1), 1) + ;
- LEFT(SAVESCREEN(mrow, 2, mrow, 2), 1)
- IF mcol = 0
- Br_Info(mbranch) && show branch information
- ELSE
- *** determine whether this spot is empty
- *** (no visit) or not
- mmonth = INT(mcol / 6)
- mdate = ;
- LTRIM(LEFT(SAVESCREEN(mrow, mcol, ;
- mrow, mcol), 1) + ;
- LEFT(SAVESCREEN(mrow, mcol+1, mrow, ;
- mcol+1), 1))
- IF EMPTY(mdate)
- oldcolor = SETCOLOR(box_color)
- *** derive default date based on this column
- mdate = CTOD(IF(mmonth < 10, '0', '') + ;
- LTRIM(STR(mmonth)) + '/01/' + ;
- SUBSTR(STR(YEAR(DATE()), 4), 3))
- *** force them to enter a date within this month
- tdate = CTOD("")
- DO WHILE MONTH(tdate) != mmonth ;
- .AND. LASTKEY() != ESC
- tdate = getdate(mdate)
- ENDDO
- IF LASTKEY() != ESC
- APPEND BLANK
- REPLACE date WITH tdate, ;
- rep_no WITH mrep_no, ;
- branch WITH mbranch
- Edit_Memo()
- @ mrow, mcol SAY DAY(date) PICTURE '##'
- ENDIF
- ELSE
- *** locate this record in VISIT.dbf
- mdate = CTOD(IF(mmonth < 10, '0', '') + ;
- LTRIM(STR(mmonth)) + '/' + ;
- IF(VAL(mdate) < 10, '0', '') + ;
- mdate + '/' + ;
- SUBSTR(STR(YEAR(DATE()), 4), 3))
- SEEK mrep_no + mbranch + DTOS(mdate)
- Edit_Memo(NIL)
- ENDIF
- ENDIF
- ENDCASE
- ENDDO
- ENDIF
- SETCURSOR(oldcursor)
- SET(_SET_SCOREBOARD, oldscoreb)
- CLOSE DATA
- RETURN
-
- *!******************************************************
- *!
- *! FUNCTION: ChangeColor() - change color in desired
- *! desired screen buffer
- *!
- *!******************************************************
- FUNCTION ChangeColor(top, left, bottom, right, color)
- LOCAL buffer, ret_val, xx
- ret_val = ""
- buffer = SAVESCREEN(top, left, bottom, right)
- FOR xx = 1 TO LEN(buffer) STEP 2
- ret_val = ret_val + SUBSTR(buffer, xx, 1) + CHR(color)
- NEXT
- RESTSCREEN(top, left, bottom, right, ret_val)
- RETURN NIL
-
-
- *!******************************************************
- *!
- *! FUNCTION: Edit_Memo() - view/edit comments for
- *! each visit
- *!
- *!******************************************************
- PROCEDURE Edit_Memo(view_only)
- LOCAL oldcolor, buffer, mcomments
- view_only = (PCOUNT() = 1)
- oldcolor = SETCOLOR(box_color)
- buffer = SAVESCREEN(06, 13, 12, 66)
- BOX2(6, 13, 12, 66)
- Center(6, 'Comments for ' + DATEWORD(date))
- Center(12, "┤ " + ;
- IF(! view_only, "Ctrl-W to save, ", "") + ;
- "Esc to exit ├")
- IF view_only
- MEMOEDIT(COMMENTS, 07, 14, 11, 65, .F.)
- ELSE
- SETCURSOR(3) && large block cursor
- mcomments = MEMOEDIT(COMMENTS, 07, 14, 11, 65, ;
- .T., 'Esc_Func' , '', 3)
- SETCURSOR(0)
- modified = (LASTKEY() <> ESC)
- IF modified
- REPLACE comments WITH mcomments
- ELSE
- INKEY(1)
- ENDIF
- ENDIF
- SETCOLOR(oldcolor)
- RESTSCREEN(6, 13, 12, 66, buffer)
- RETURN
-
-
- *!******************************************************
- *!
- *! FUNCTION: Esc_Func() - Handle ESC keypress
- *! in MEMOEDIT()
- *!
- *!******************************************************
- FUNCTION Esc_Func(status, line, column)
- IF LASTKEY() = ESC
- SETCOLOR("+W/R")
- BOX1(8, 26, 10, 53)
- @ 09, 28 SAY "Edits Will Not Be Saved!"
- ENDIF
- RETURN 0
-
-
- *!******************************************************
- *!
- *! FUNCTION: Br_Info() - Display Branch Information
- *!
- *!******************************************************
- FUNCTION Br_Info(mbranch)
- PRIVATE buffer, oldcolor
- oldcolor = SETCOLOR(box_color)
- buffer = SAVESCREEN(8, 21, 15, 58)
- BOX1(8, 21, 15, 58)
- SELECT branch
- SEEK mbranch
- CENTER(8, "Branch Number " + number)
- CENTER(15, "┤ Press any key ├")
- @ 9, 23 SAY "Address: " + ADDRESS
- @ 10, 23 SAY "City: " + CITY
- @ 10, 47 SAY "St: " + STATE
- @ 11, 23 SAY "Zip: " + ZIP
- @ 12, 23 SAY "Phone: " + PHONE
- @ 13, 23 SAY "Fax: " + FAX
- @ 14, 23 SAY "Contact: " + CONTACT
- INKEY(0)
- RESTSCREEN(8, 21, 15, 58, buffer)
- SETCOLOR(oldcolor)
- SELECT visit
- RETURN NIL
-