home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a070 / 3.ddi / FOXPRO / TEMPLGEN / AP1PROC.INC < prev    next >
Encoding:
Text File  |  1988-05-05  |  11.3 KB  |  542 lines

  1. <<* APPPROC.INC *>>
  2.  
  3. <<procedure GenProcStandard>>
  4. <<string alpha>>
  5. <<begin>>
  6.  
  7. PROCEDURE SayRec
  8.    * ---"SayRec" is used by the EDIT program and PROCEDURE DoCONT.
  9.    *
  10.    DO StatLine WITH RECNO(),DELETED()
  11.    DO {fileprefix}_SAYS
  12.    *
  13.    * ---If you are calling "SayRec" from more than one
  14.    * ---application, you may wish to replace the above
  15.    * ---line with a DO CASE structure, as follows:
  16.    *
  17.    *    * ---"appnum" is the application ID number.
  18.    *    DO CASE
  19.    *    CASE appnum = 1
  20.    *       DO AP1_SAYS
  21.    *    CASE appnum = 2
  22.    *       DO AP2_SAYS
  23.    *    ENDCASE
  24.    *
  25. RETURN
  26.  
  27.  
  28. PROCEDURE GetKey
  29. PARAMETER choice,keychars
  30. PRIVATE keycode
  31.    choice = "*"
  32.    DO WHILE .NOT. (choice $ keychars)
  33.       keycode = INKEY()
  34.       IF keycode > 0
  35.          choice = UPPER(CHR(keycode))
  36.       ENDIF
  37.       * ---A keyfilter can be implemented here, as follows:
  38.       *
  39.       *    * ---FROM:  {{}F1}  ^leftarrow  ^rightarrow
  40.       *    * ---INTO:  "H"    leftarrow   rightarrow
  41.       *    fromkeys = CHR(28) + CHR(26) + CHR(2)
  42.       *    intokeys = "H" + CHR(19) + CHR(4)
  43.       *    choice = SUBSTR( "*"+intokeys,AT(choice,fromkeys) + 1,1 )
  44.    ENDDO
  45. RETURN
  46.  
  47. <<if ismultipage>>
  48.  
  49. PROCEDURE Page
  50. PARAMETER pageno,pagedir,PageMax
  51.    pageno = pageno + pagedir
  52.    DO CASE
  53.    CASE pageno < 1
  54.       * ---Circle to last page.
  55.       pageno = PageMax
  56.    CASE pageno > PageMax
  57.       * ---Circle to first page.
  58.       pageno = 1
  59.    ENDCASE
  60. RETURN
  61.  
  62. <<endif>>
  63.  
  64. PROCEDURE StatLine
  65. PARAMETER recnum,IsDeleted
  66.    <<GenColor( 1,'STATUS' )>>
  67.    @ 0, 8 SAY SUBSTR( STR( recnum + 1000000,7 ),2 )
  68.    <<if ismultipage>>
  69.    @ 0,23 SAY STR( pageno,2 )
  70.    <<endif>>
  71.    <<if ismultials>>
  72.    @ 0,29 SAY "<        >"
  73.    @ 0,30 SAY SUBSTR( DBFname,1,AT( ".",DBFname )-1 )
  74.    <<endif>>
  75.    IF IsDeleted
  76.       @ 0,50 SAY "*DELETED*"
  77.    ELSE
  78.       @ 0,50 SAY "         "
  79.    ENDIF
  80. RETURN
  81.  
  82.  
  83. PROCEDURE SayEOF
  84. PARAMETER row,oldrecnum
  85.    <<GenColor( 1,'PROMPT' )>>
  86.    @ row,0 CLEAR
  87.    IF EOF()
  88.       @ row,0 SAY "END-OF-FILE encountered"
  89.    ELSE
  90.       @ row,0 SAY "BEGINNING-OF-FILE encountered"
  91.    ENDIF
  92.    WAIT
  93.    @ row,0 CLEAR
  94.    IF oldrecnum > 0
  95.       GOTO oldrecnum
  96.    ENDIF
  97. RETURN
  98.  
  99.  
  100. PROCEDURE SayLine
  101. PARAMETER row,strg
  102.    <<GenColor( 1,'PROMPT' )>>
  103.    @ row,0 CLEAR
  104.    @ row,0 SAY strg
  105. RETURN
  106.  
  107.  
  108. PROCEDURE GotoRec
  109. PARAMETER row,recnum,lastrecnum
  110.    recnum = 0
  111.    <<GenColor( 1,'PROMPT' )>>
  112.    @ row,0 CLEAR
  113.    @ row+1,17 SAY "{ 1 to "
  114.    @ row+1,24 SAY SUBSTR( STR( lastrecnum + 1000000,7 ),2 ) + " } + {Return}"
  115.    @ row,0 SAY "Enter RECORD number" GET recnum;
  116.            PICTURE "@Z 9999999" RANGE 0,lastrecnum
  117.    READ
  118.    @ row,0 CLEAR
  119.    IF recnum > 0
  120.       GOTO recnum
  121.    ENDIF
  122. RETURN
  123.  
  124.  
  125. PROCEDURE DoGOTO
  126. PARAMETER row,recnum,lastrecnum
  127.    recnum = 0
  128.    <<GenColor( 1,'PROMPT' )>>
  129.    @ row,0 CLEAR
  130. <<if LiteBar>>
  131.    menuchoice = 4
  132.    @ row,0 SAY "GOTO:"
  133.    @ row, 7 PROMPT "Top"
  134.    @ row,12 PROMPT "Bottom"
  135.    @ row,20 PROMPT "Number"
  136.    @ row,28 PROMPT "Return"
  137.    MENU TO menuchoice
  138.    choice = SUBSTR( Returnkey+"TBR"+Returnkey,menuchoice + 1,1 )
  139. <<else>>
  140.   <<if Bracketed>>
  141.    @ row,0 SAY "GOTO:  {T}op  {B}ottom  {R}ecord#  {Return} "
  142.   <<else>>  <<*Simple*>>
  143.    @ row,0 SAY "GOTO:  (T)op  (B)ottom  (R)ecord#  <Return> "
  144.   <<endif>>
  145.    DO GetKey WITH choice,"TBR"+Returnkey
  146. <<endif>>
  147.    @ row,0 CLEAR
  148.    DO CASE
  149.    CASE choice = Returnkey
  150.       RETURN
  151.    CASE choice = "T"
  152.       GOTO TOP
  153.       recnum = RECNO()
  154.    CASE choice = "B"
  155.       GOTO BOTTOM
  156.       recnum = RECNO()
  157.    CASE choice = "R"
  158.       DO GotoRec WITH row,recnum,lastrecnum
  159.    ENDCASE
  160. RETURN
  161.  
  162.  
  163. PROCEDURE DoLOCATE
  164. PARAMETER row,expr
  165. PRIVATE oldrecnum
  166.    oldrecnum = RECNO()
  167.    DO SayLine WITH row,"Locating..."
  168.    LOCATE FOR &expr
  169.    IF EOF()
  170.       DO SayEOF WITH row,oldrecnum
  171.    ELSE
  172.       @ row,0 CLEAR
  173.       @ row,0 SAY "LOCATE FOR" GET expr
  174.       CLEAR GETS
  175.       DO DoCONT WITH row
  176.    ENDIF
  177. RETURN
  178.  
  179.  
  180. PROCEDURE DoCONT
  181. PARAMETER row
  182. PRIVATE oldrecnum
  183.    choice = "Y"
  184.    DO WHILE choice = "Y" .AND. .NOT. EOF()
  185.       oldrecnum = RECNO()
  186.       DO SayRec
  187.       DO SayLine WITH row+1,"Continue? (y/n)"
  188.       DO GetKey WITH choice,"YN"+Returnkey
  189.       @ row+1,0 CLEAR
  190.       IF choice = "Y"
  191.          CONTINUE
  192.       ENDIF
  193.    ENDDO
  194.    IF EOF()
  195.       DO SayEOF WITH row,oldrecnum
  196.    ENDIF
  197. RETURN
  198.  
  199. <<end>> <<*GenProcStandard*>>
  200.  
  201.  
  202. <<#
  203. procedure GenFuncStandard
  204. begin
  205.   select all
  206.   select fields on ("VLU(" $ upper(fldval))
  207.   if (fldtotal > 0)
  208. #>>
  209.  
  210. PROCEDURE VLU
  211. PARAMETER lookals,lookexp,lookmsg
  212. PRIVATE origals,notvalid
  213.    origals = STR( SELECT(),2 )
  214.    SELECT &lookals
  215.    SEEK lookexp
  216.    notvalid = EOF()
  217.    IF notvalid
  218.       * ---Could not find <exp> in <LOOKUP> file.
  219.       DO SayLine WITH PromptRow,lookmsg
  220.       WAIT
  221.       @ PromptRow,0 CLEAR
  222.    ENDIF
  223.    SELECT &origals
  224. RETURN .NOT. notvalid
  225.  
  226.   <<endif>>
  227.   <<select all fields>>
  228. <<end GenFuncStandard>>
  229.  
  230.  
  231. <<procedure GenExecSeek>>
  232. <<string fixedkey>>
  233. <<begin>>
  234.   <<fixedkey := fixautomem(ndxkey)>>
  235.   <<if ndxtyp = 'C'>>
  236.       expr = TRIM( {fixedkey} )
  237.       IF "" <> expr
  238.          SEEK expr
  239.       ENDIF
  240.   <<elsif ndxtyp = 'N'>>
  241.       expr = {fixedkey}
  242.       IF expr <> 0
  243.          SEEK expr
  244.       ENDIF
  245.   <<else>>  <<*DATE type*>>
  246.       expr = {fixedkey}
  247.       IF DTOC(expr) <> "  /  /  "
  248.          SEEK expr
  249.       ENDIF
  250.   <<endif>>
  251. <<end GenExecSeek>>
  252.  
  253.  
  254. <<#
  255. procedure GenKeySeek
  256. string  pic,firstpart,keyfld
  257. integer count
  258. begin
  259.   select all fields
  260.   select fields on (fldtyp $ 'CDN') and (fldals <> 'M')
  261.   forall (upper(fldnam) $ upper(ndxkey)) and (forcount <= 2)
  262.     keyfld := fixfldnam
  263. #>>
  264.     <<if fldtyp = 'C'>>
  265.       {keyfld} = SPACE({fldwid})
  266.     <<elsif fldtyp = 'N'>>
  267.       {keyfld} = 0.0
  268.     <<else>>
  269.       {keyfld} = CTOD("  /  /  ")
  270.     <<endif>>
  271. <<#
  272.   endfor
  273.   count := 0
  274.   forall (upper(fldnam) $ upper(ndxkey)) and (forcount <= 2)
  275.     count := count + 1
  276.     keyfld := fixfldnam
  277.  
  278.     if forcount = 1
  279.       firstpart := '@ row,  0 SAY "Enter ' + fldnam + '"'
  280.     else
  281.       firstpart := '@ row+1,0 SAY "      ' + fldnam + '"'
  282.     endif
  283.  
  284.     <<*---PICTURE---*>>
  285.     pic := fldpic
  286.     if fldtyp = 'N'  <<*Force PICTURE on Numerics*>>
  287.       pic := replicate( '9',fldwid )
  288.       if flddec
  289.         pic[ fldwid-flddec ] := '.'
  290.       endif
  291.     endif
  292. #>>
  293.     <<if pic>>
  294.       {firstpart} GET {keyfld} PICTURE {"}{pic}{"}
  295.     <<else>>
  296.       {firstpart} GET {keyfld}
  297.     <<endif>>
  298.   <<endfor>>
  299.   <<if count = 0>>
  300.       * ---Key expression:  {ndxkey}
  301.       DO SayLine WITH row,"Key expression does not match database file."
  302.       WAIT
  303.       @ row,0 CLEAR
  304.   <<else>>
  305.       READ
  306.     <<GenExecSeek>>
  307.   <<endif>>
  308.   <<select all fields>>
  309. <<end GenKeySeek>>
  310.  
  311.  
  312. <<procedure GenSingleSEEK>>
  313. <<string alpha,fixedkey>>
  314. <<begin>>
  315.  
  316. <<alpha := chr( dbfcount + 64 )>>
  317. <<if ismultials>>
  318. PROCEDURE {fileprefix}_{alpha}SEE
  319. <<else>>
  320. PROCEDURE {fileprefix}_SEEK
  321. <<endif>>
  322. PARAMETER row
  323. PRIVATE expr
  324.   <<if not ismultials>>
  325.    IF NdxOrder = "0"
  326.       RETURN
  327.    ENDIF
  328.   <<endif>>
  329.   <<GenColor( 1,'PROMPT' )>>
  330.    @ row,0 CLEAR
  331.    DO CASE
  332.   <<forall indexes>>
  333.    CASE NdxOrder = {"}{ndxcount}{"}
  334.     <<GenKeySeek>>
  335.   <<endfor>>
  336.    ENDCASE
  337. RETURN
  338.  
  339. <<end GenSingleSEEK>>
  340.  
  341.  
  342. <<procedure GenMultiSEEK>>
  343. <<string alpha>>
  344. <<begin>>
  345.  
  346. PROCEDURE {fileprefix}_SEEK
  347. PARAMETER row
  348.    IF NdxOrder = "0"
  349.       RETURN
  350.    ENDIF
  351.    DO CASE
  352.   <<forall databases>>
  353.    CASE dbfarea = {"}{dbfcount}{"}
  354.     <<alpha := chr( dbfcount + 64 )>>
  355.     <<if ndxtotal > 0>>
  356.       DO {fileprefix}_{alpha}SEE WITH row
  357.     <<else>>
  358.       * ---<none>.
  359.     <<endif>>
  360.   <<endfor>>
  361.    ENDCASE
  362. RETURN
  363.  
  364. <<end>> <<*GenMultiSEEK*>>
  365.  
  366.  
  367. <<procedure GenSetIndex( procname : string )>>
  368. <<string keydisp,keyopts,ndxnames>>
  369. <<integer width>>
  370. <<begin>>
  371.  
  372. PROCEDURE {procname}
  373. PARAMETER row,ndxchoice
  374.    <<GenColor( 1,'PROMPT' )>>
  375.    @ row,0 CLEAR
  376. <<#
  377.    forall indexes
  378.      filespec( ndxnam,fpath,fname,fext )
  379.      keydisp := keydisp + ' ' + str( ndxcount ) + '-' + fname + ' '
  380.      keyopts := keyopts + str( ndxcount )
  381.    endfor
  382. #>>
  383.    @ row,0 SAY {"}SET INDEX: {keydisp}{"}
  384.    DO GetKey WITH ndxchoice,{"}{keyopts}{"}+Returnkey
  385.    IF ndxchoice = Returnkey
  386.       RETURN
  387.    ENDIF
  388.    NdxOrder = ndxchoice
  389.    SET ORDER TO &NdxOrder
  390. RETURN
  391.  
  392. <<end>> <<*GenSetIndex*>>
  393.  
  394.  
  395. <<procedure GenSetNdxs>>
  396. <<string alpha,keydisp,keyopts,ndxnames>>
  397. <<begin>>
  398.  
  399. PROCEDURE {fileprefix}_NDXS
  400. PARAMETER row,ndxchoice
  401.    DO CASE
  402.  <<forall databases>>
  403.    CASE dbfarea = {"}{dbfcount}{"}
  404.    <<alpha := chr( dbfcount + 64 )>>
  405.    <<if ndxtotal > 1>>
  406.       DO {fileprefix}_{alpha}NDX WITH row,ndxchoice
  407.    <<elsif ndxtotal = 1>>
  408.       * ---Only one index.
  409.       ndxchoice = "1"
  410.    <<else>>
  411.       * ---No indexes.
  412.    <<endif>>
  413.  <<endfor>>
  414.    ENDCASE
  415. RETURN
  416.  
  417. <<end>> <<*GenSetNdxs*>>
  418.  
  419.  
  420. <<procedure GenSetFile>>
  421. <<string keydisp1,keyopts1,keydisp2,keyopts2,ndxnames>>
  422. <<integer width>>
  423. <<begin>>
  424.  
  425. PROCEDURE {fileprefix}_FILE
  426. PARAMETER row,dbfchoice
  427.    <<GenColor( 1,'PROMPT' )>>
  428.    @ row,0 CLEAR
  429. <<#
  430.    forall databases
  431.      filespec( dbfnam,fpath,fname,fext )
  432.      if forcount <= 5
  433.        keydisp1 := keydisp1 + ' ' + str( dbfcount ) + '-' + fname + ' '
  434.        keyopts1 := keyopts1 + str( dbfcount )
  435.      else
  436.        keydisp2 := keydisp2 + ' ' + str( dbfcount ) + '-' + fname + ' '
  437.        keyopts2 := keyopts2 + str( dbfcount )
  438.      endif
  439.    endfor
  440.    select all databases
  441. #>>
  442.  <<if dbftotal <= 5>>
  443.    @ row,0 SAY {"}SELECT: {keydisp1}{"}
  444.  <<else>>
  445.    @ row+1,0 SAY {"}        {keydisp2}{"}
  446.    @ row,0 SAY {"}SELECT: {keydisp1}{"}
  447.  <<endif>>
  448.    DO GetKey WITH dbfchoice,{"}{keyopts1}{keyopts2}{"}+Returnkey
  449.    IF dbfchoice = Returnkey
  450.       RETURN
  451.    ENDIF
  452.    dbfarea = dbfchoice
  453.    DO {fileprefix}_AREA
  454. RETURN
  455.  
  456. <<end>> <<*GenSetFile*>>
  457.  
  458.  
  459. <<procedure GenSetArea>>
  460. <<begin>>
  461.  
  462. PROCEDURE {fileprefix}_AREA
  463.    SELECT &dbfarea
  464.   <<if ismultials>>
  465.    DO CASE
  466.   <<endif>>
  467. <<forall databases>>
  468.   <<if ismultials>>
  469.    CASE dbfarea = {"}{dbfcount}{"}
  470.     <<pushmargin( 2 )>>
  471.   <<else>>
  472.     <<pushmargin( 1 )>>
  473.   <<endif>>
  474. <<#
  475.    GenFileVars
  476.    if ndxtotal = 0
  477.      genln( '* ---<No indexes>.' )
  478.      genln( 'NdxOrder = "0"' )
  479.    else
  480.      GenIndexVars
  481.      genln( 'NdxOrder = "1"' )
  482.    endif
  483.    if ismultipage
  484.      select field 1
  485.      genln( 'pageno = ',fldpag )
  486.      genln( 'dbfpagemax = ',pagtotal )
  487.    endif
  488.    popmargin
  489.  endfor
  490. #>>
  491.   <<if ismultials>>
  492.    ENDCASE
  493.   <<endif>>
  494.    LastRec = RECCOUNT()
  495. RETURN
  496.  
  497. <<end GenSetArea>>
  498.  
  499.  
  500. <<#
  501. procedure GenProcSecond
  502. begin
  503.   GenSetArea
  504.   if ismultials
  505.     GenSetFile
  506.   endif
  507.   GenFuncStandard
  508.   select all
  509.   if ndxtotal > 1
  510.     if ismultials
  511.       forall databases
  512.         if ndxtotal > 1
  513.           GenSetIndex( fileprefix + '_' + chr( 64 + dbfcount ) + 'NDX' )
  514.         endif
  515.       endfor
  516.       if ismultindx
  517.         GenSetNdxs
  518.       endif
  519.     else
  520.       select database 1
  521.       GenSetIndex( fileprefix + '_NDXS' )
  522.     endif
  523.   endif
  524.   select all
  525.   if ndxtotal > 0  <<*Total ndxs for entire system*>>
  526.     if ismultials
  527.       forall databases
  528.         if ndxtotal > 0  <<*Total ndxs for each dbf*>>
  529.           GenSingleSEEK
  530.         endif
  531.       endfor
  532.       GenMultiSEEK
  533.     else
  534.       select database 1
  535.       GenSingleSEEK
  536.     endif
  537.   endif
  538. end>> <<*GenProcSecond*>>
  539.  
  540. <<* EOF: APPPROC.INC *>>
  541. #>>
  542.