home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0020 - 0029 / ibm0020-0029 / ibm0028.tar / ibm0028 / PDXOS2-1.ZIP / SKSAMPLE / TPINSERT.SC < prev    next >
Encoding:
Text File  |  1988-12-29  |  17.9 KB  |  577 lines

  1. ;╔════════════════════════════════════════════════════════════════════════════╗
  2. ;║  SCRIPT NAME : TPINSERT.SC                                                 ║
  3. ;╚═══════╦════════════════════╦════════════════════╦═════════════════╦════════╝
  4. ;░░░░░░░░║  by Anthony Lee    ║  DATE : 12/11/88   ║  TIME :         ║░░░░░░░░░
  5. ;╔═══════╩════════════════════╩════════════════════╩═════════════════╩════════╗
  6. ;║  LIBRARY    : TPINSERT                                                     ║
  7. ;║  PROCEDURES :                                                              ║
  8. ;║                                                                            ║
  9. ;║  PURPOSE    :                                                              ║
  10. ;║                                                                            ║
  11. ;╚════════════════════════════════════════════════════════════════════════════╝
  12.  
  13. If isfile("TPINSERT.lib") then
  14.   Run "Del TPINSERT.lib"
  15. Endif
  16.  
  17. Libname = "TPINSERT"
  18. Createlib Libname
  19.  
  20. ;╔════════════════════════════════════════════════════════════════════════════╗
  21. ;║  Driver script : TPINSERT.SC                                               ║
  22. ;╚════════════════════════════════════════════════════════════════════════════╝
  23. ;Begin main script - TPINSERT.SC
  24. ;Necessary tables are: TPINSERT.DB, TPSTRUCT.DB, and TPLOOKUP.DB
  25. ;
  26. ;
  27. ;Autolib = "TPInsert"
  28. ;
  29. ;SetPopup("TPLOOKUP")
  30. ;GetTPTable()
  31. ;GetYears()
  32. ;GetDates()
  33. ;InsertDates()
  34. ;ExitTPInsert()
  35. ;
  36. ;Clearall
  37. ;View tptable
  38. ;
  39. ;Release Vars tptable
  40.  
  41.  
  42.  
  43. Proc GetTPTable() ;-----------------------------------------------------------
  44. ;Ask for a valid Time Planner table
  45. ;
  46. private TPFields,choice,tplen
  47.  
  48. clear
  49. clearall
  50.  
  51. style attribute 30
  52. @1,0  ?? format("W76,AC","SideKick Time Planner Utility")
  53. style attribute 27
  54. @2,0  ?? format("W76,AC","Posting Annual Events")
  55.  
  56.  
  57. style attribute 94
  58. @4,4  ??" ╔════════════════════════════════════════════════════════════════╗ "
  59. @5,4  ??" ║                                                                ║ "
  60. @6,4  ??" ║ Which SideKick Time Planner table do you wish to add to:       ║ "
  61. @7,4  ??" ║    <                                                      >    ║ "
  62. @8,4  ??" ║                                                                ║ "
  63. @9,4  ??" ╚════════════════════════════════════════════════════════════════╝ "
  64.  
  65. style attribute 31
  66. @22,7 ?? "Please enter an existing Time Planner tablename or press <Esc> to exit.  "
  67. style attribute 30
  68. @24,7 ?? "(For instructions, see the file SIDEKICK on your Sample Tables Disk)"
  69.  
  70. While true
  71.   Style Attribute 30
  72.   @7,12 Accept "A52" Picture "*!" to tptable
  73.   if retval = false then
  74.     ExitTPInsert()
  75.   endif
  76.   tplen = len(tptable)
  77.   cursor off
  78.   Switch
  79.     Case retval = false    :           ;User pressed <Esc>
  80.       ExitTPInsert()
  81.       Quit
  82.     Case substr(tptable,tplen,1) <> "A" :
  83.       @20,7 ??"The Time Planner filename must end with the letter A."
  84.       Clear eol
  85.     Case isblank(tptable)  :           ;User did not input a table name
  86.       @20,7 clear eol
  87.     Case tptable = "STRUCT":
  88.       @20,7 ??"You may not select the STRUCT table"
  89.       Clear eol
  90.     Case istable(tptable)  :           ;Check if valid TP Structure
  91.       @20,7 ??"Checking to see if valid Time Planner table"
  92.       Style Attribute 158
  93.       ??"....."
  94.       clear eol
  95.       style attribute 30
  96.  
  97.       {Tools} {Info} {Structure} select tptable
  98.       TPFields = nrecords("Struct")
  99.       Subtract "TPStruct" "Struct"
  100.       if isempty("Struct") and TPFields = 7 then
  101.         delete "struct"
  102.         quitloop
  103.       else
  104.         @20,7 ??TPTable," is not a valid Time Planner table."
  105.         Clear eol
  106.       endif
  107.     Otherwise              :           ;Table does not exist
  108.       @20,7 ?? tptable," is not a tablename."
  109.       Clear eol
  110.   Endswitch
  111. cursor normal
  112. Endwhile
  113.  
  114. Endproc
  115. Writelib Libname GetTPTable
  116. Release Procs GetTPTable
  117.  
  118.  
  119.  
  120. Proc GetYears() ;-------------------------------------------------------------
  121. ;Ask for a table to insert
  122. ;
  123.  
  124. Style Attribute 94
  125. @11,4 ??" ╔════════════════════════════════════════════════════════════════╗ "
  126. @12,4 ??" ║                                                                ║ "
  127. @13,4 ??" ║  Annual Event ------->    Starting Year:   <      >            ║ "
  128. @14,4 ??" ║                           Ending Year  :   <      >            ║ "
  129. @15,4 ??" ║                                                                ║ "
  130. @16,4 ??" ╚════════════════════════════════════════════════════════════════╝ "
  131.  
  132.  
  133. @20,7 Clear eol
  134. style attribute 31
  135. @22,7 ?? "Please enter a year or press <Esc> to exit.  "
  136. clear eol
  137.  
  138. While true
  139.   Style Attribute 30
  140.   @13,52 Accept "A4" Picture "{1{9},2{0}}##" to StartYear
  141.   cursor off
  142.   Switch
  143.     case retval = false    :           ;User pressed <Esc>
  144.       clearall
  145.       ExitTPInsert()
  146.       Quit
  147.     Case isblank(StartYear):           ;User didn't enter a year
  148.       @20,7 clear eol
  149.       Clear eol
  150.     Otherwise              :
  151.       quitloop
  152.   Endswitch
  153. cursor normal
  154. Endwhile
  155.  
  156.  
  157. While true
  158.   Style Attribute 30
  159.   @14,52 Accept "A4" Picture "{1{9},2{0}}##" to EndYear
  160.   cursor off
  161.   Switch
  162.     case retval = false    :           ;User pressed <Esc>
  163.       clearall
  164.       ExitTPInsert()
  165.       Quit
  166.     Case isblank(StartYear):           ;User didn't enter a year
  167.       @20,7 clear eol
  168.       Clear eol
  169.     Case numval(EndYear) < numval(StartYear) :
  170.       @20,7 ??"Ending year must be greater that Starting year"
  171.       Clear eol
  172.     Otherwise              :
  173.       quitloop
  174.   Endswitch
  175. cursor normal
  176. Endwhile
  177.  
  178.  
  179. Endproc
  180. Writelib Libname GetYears
  181. Release Procs GetYears
  182.  
  183.  
  184.  
  185.  
  186. Proc GetDates() ;-------------------------------------------------------------
  187. ;Ask for yearly events
  188. ;
  189. Private x
  190.  
  191. Clear
  192. Clearall
  193.  
  194. Edit "TPInser1"
  195. ;Pickform 1
  196.  
  197. While true
  198.   Wait Record
  199.   Prompt "Please enter annual events to post to the Time Planner:            ",
  200.          "<F1> list category icons <Esc> exit application <F2> Do_it!        "
  201.   Until "F1", "F2", "Up", "Down", "Esc", "Del", "Enter", "Tab", "Right"
  202.  
  203.   Switch
  204.     case retval = "Esc"   :            ;User pressed <Esc>
  205.       Menu {Cancel} {Yes} clearall
  206.       ExitTPInsert()
  207.       Quit
  208.     case retval = "F1"    :
  209.       Style Attribute 30
  210.       if field() = "Icon Type" then
  211.         echo normal  echo off
  212.         @21,13 ??"Please select the category icon for this event."
  213.         Popup(5,55,1,11)
  214.         [] = retval
  215.       else
  216.         @21,13 ??"No lookup help available for this field."
  217.         sleep 2000
  218.       endif
  219.     case retval = "F2"    :
  220.       quitloop
  221.     case ((retval = "Enter" or retval = "Tab" or retval = "Right")  and field() <> "Description") :
  222.       Right
  223.     case retval = "Up" and (isblank([Month]) or isblank([Day])) and recno() <> 1 :
  224.       keypress "Del"
  225.     case retval = "Up" or retval = "Down" or retval="Tab" or retval="Enter" or retval = "Right"  :
  226.       If retval = "Up" and recno() = 1 then
  227.         beep
  228.       Endif
  229. ;      baddate = False
  230. ;      If retval = "Up" and isblank([Month]) or isblank([Day]) then
  231. ;        keypress "Del"
  232. ;        baddate = True
  233. ;      Endif
  234.       x=dateval(strval([Month])+"/"+strval([Day])+"/87")
  235.       If x <> "Error" then
  236.         execute retval
  237.       else
  238.         if [Month] = "02" and [Day] = "29" then
  239.           @21,13 ??"No leap year entries allowed."
  240.           clear eol
  241.           sleep 2000
  242.         else
  243.           @21,13 ??"Invalid date.  Please re-enter."
  244.           clear eol
  245.           sleep 2000
  246.         endif
  247.       Endif
  248.     case retval = "Del" :
  249.       execute retval
  250.     Otherwise              :
  251.       quitloop
  252.   Endswitch
  253. Endwhile
  254. Do_it!
  255.  
  256. If isempty("TPInser1") then
  257.   ExitTPInsert()
  258.   echo normal echo off cursor off
  259.   @21,13 ??"No records will be posted."
  260.   clear eol
  261.   sleep 2500
  262.   quit
  263. Endif
  264.  
  265. echo normal echo off cursor off
  266. @21,13 ??"Processing query"
  267. Style Attribute 158
  268. ??"....."
  269. clear eol
  270. @22,0 clear eol
  271. @23,0 clear eol
  272.  
  273.  
  274. Menu {Ask} {Tpinsert} typein "insert"
  275. [Month] = "_a"
  276. [Day] = "_b"
  277. [Icon Type] = "_c"
  278. [Alarm] = "_d"
  279. [Description] = "_e"
  280.  
  281. Menu {Ask} {Tpinser1}
  282. [Month] = "_a"
  283. [Day] = "_b"
  284. [Icon Type] = "_c"
  285. [Alarm] = "_d"
  286. [Description] = "_e"
  287.  
  288. Do_it!
  289. clearall
  290.  
  291.  
  292. EndProc
  293. Writelib Libname GetDates
  294. Release Procs GetDates
  295.  
  296. Proc InsertDates() ;----------------------------------------------------------
  297. ;
  298. Private i,str
  299. Edit "TPInsert"
  300. Scan
  301.   If [Alarm] = "Y" then
  302.     [Alarm Time] = "12:00"
  303.   else
  304.     [Alarm Time] = "-1"
  305.   endif
  306. endscan
  307. Do_it!
  308.  
  309.  
  310. For i from Numval(startyear) to numval(endyear)
  311.  
  312. Edit "TPInsert"
  313.   scan
  314.     str = [month] + "/" + [day] + "/" + strval(i)
  315.     [date] = dateval(str)
  316.   endscan
  317. do_it!
  318.  
  319.  
  320. Menu {Ask} select tptable
  321. Menu {Ask} {TPInsert}
  322.  
  323.  
  324. moveto tptable
  325. typein "insert"
  326. [Date] = "_dateval"
  327. [Start Time]  = "12:00"
  328. [End Time]    = "12:00"
  329. [Order]  = 1
  330. [Alarm Time] = "_Alarm"
  331. [Type] = "_type"
  332. [Description] = "_desc"
  333.  
  334. moveto "TPInsert"
  335. [Date] = "_dateval"
  336. [Icon Type] = "_type"
  337. [Description] = "_desc"
  338. [Alarm Time] = "_alarm"
  339. do_it!
  340.  
  341. Clearall
  342. Endfor
  343.  
  344. Empty "Tpinsert"
  345. Empty "Tpinser1"
  346.  
  347. endproc
  348. Writelib Libname InsertDates
  349. Release Procs InsertDates
  350.  
  351.  
  352.  
  353.  
  354. Proc ExitTPInsert() ;--------------------------------------------------------
  355. ;Release all variables when user quits application
  356. ;
  357.  
  358. Release Vars Autolib, StartYear, EndYear,
  359.              PopupLen,PopupList,PopupNumber,PopupStart
  360.  
  361. if not isassigned(tptable) then quit
  362. endif
  363. If istable("Struct")   then Delete "Struct"   Endif
  364.  
  365. Play "AJL"
  366.  
  367. Endproc
  368. WriteLib Libname ExitTPInsert
  369. Release Procs ExitTPInsert
  370.  
  371.  
  372.  
  373.  
  374.  
  375.  
  376.  
  377. ;╔════════════════════════════════════════════════════════════════════════════╗
  378. ;║  Popup Procedures: SetPopup, Popup, PopDraw, PopRedraw                     ║
  379. ;╚════════════════════════════════════════════════════════════════════════════╝
  380.  
  381.  
  382. Proc SetPopup(Tables) ;-------------------------------------------------------
  383.    Private;Tables,            ;List of tables for which to define popup menus
  384.            TempName,          ;Array which stores the names of each table
  385.            NumMenus,          ;Number of tables specified in "Tables" parameter
  386.            NumItems,          ;Number of items in current table
  387.            CurrTable,         ;Current table being looked at
  388.            X                  ;Loop index
  389.    Array TempName[10]
  390.    Array PopupStart[10]       ;Stores pointer to beginning of item list
  391.    Array PopupNumber[10]      ;Stores number of items in menu list
  392.    Array PopupLen[10]         ;Stores length of longest menu choice
  393.    NumMenus=0
  394.    NumItems=0
  395.    Tables=Tables+","
  396.    While match(Tables,"..,..",CurrTable,Tables)    ;Process each table name
  397.       If not istable(CurrTable)
  398.          Then Quit "Table "+CurrTable+" does not exist."
  399.       Endif
  400.       NumMenus=NumMenus+1                          ;Update which menu this is
  401.       TempName[NumMenus]=CurrTable
  402.       PopupStart[NumMenus]=NumItems                ;NumItems is a running total
  403.       NumItems=NumItems+nrecords(CurrTable)
  404.    Endwhile
  405.    If NumItems<>0
  406.       Then Array PopupList[NumItems]  ;Stores all line items from data tables
  407.    Endif
  408.    For X from 1 to NumMenus
  409.       If isempty(TempName[X])
  410.          Then PopupNumber[X]=0
  411.          Else View TempName[X]
  412.               Right
  413.               PopupNumber[X]=0
  414.               PopupLen[X]=0
  415.               Scan
  416.                  PopupLen[X]=max(PopupLen[X],len([])+4)      ;Update max width
  417.                  PopupNumber[X]=PopupNumber[X]+1
  418.                  PopupList[PopupNumber[X]+PopupStart[X]]=[]  ;Store line item
  419.               Endscan
  420.               PopupLen[X]=max(PopupLen[X],10)
  421.               ClearImage
  422.       Endif
  423.    Endfor
  424. Endproc
  425. Writelib Libname SetPopup
  426. Release Procs SetPopup
  427.  
  428.  
  429. Proc Popup(R,C,Num,Size) ;----------------------------------------------------
  430.    Private;R,       ;Row position of popup window
  431.           ;C,       ;Column position of popup window
  432.           ;Num,     ;Popup menu number
  433.           ;Size,    ;Number of choices to be displayed at one time
  434.            Char,    ;Last key that was pressed
  435.            MenuPos, ;Current position within menu
  436.            Choice,  ;Current menu selection
  437.            X        ;Counter
  438.    If PopupNumber[Num]=0
  439.       Then Return ""
  440.    Endif
  441.    If Size>PopupNumber[Num]
  442.       Then Size=PopupNumber[Num]
  443.    Endif
  444.    Echo Off
  445.    Cursor Off
  446.    @0,0
  447.    ?? "Highlight the appropriate selection using the cursor movement keys."
  448.    Clear Eol
  449.    ? "Press [Enter] to accept, [Esc] to cancel menu selection."
  450.    Clear Eol
  451.    ;Draw menu box
  452.    @R,C
  453.    ?? "╔",fill("═",PopupLen[Num]-2),"╗"
  454.    @R+1,C
  455.    ?? "║ CHOOSE:",spaces(PopupLen[Num]-10),"║"
  456.    @R+2,C
  457.    ?? "╟",fill("─",PopupLen[Num]-2),"╢"
  458.    For X from 1 to Size
  459.       @R+2+X,C
  460.       ?? "║ ",substr(strval(PopupList[PopupStart[Num]+X])+
  461.               spaces(PopupLen[Num]),1,PopupLen[Num]-3),"║"
  462.    Endfor
  463.    @R+3+Size,C
  464.    ?? "╚",fill("═",PopupLen[Num]-2),"╝"
  465.    If Size<>PopupNumber[Num]      ;Is there more data that can't be displayed?
  466.       Then @R+2+Size,C+1
  467.            ?? ""                 ;Show that more items exist below
  468.    Endif
  469.    MenuPos=1
  470.    Choice=1
  471.    While True
  472.       Style Reverse               ;Highlight current selection
  473.       PopDraw()
  474.       Style
  475.       Char=getchar()
  476.       Switch
  477.          Case Char=-72:                          ;Key was [Up]
  478.             If Choice=1                          ;Are we already at the top?
  479.                Then Beep
  480.                Else If MenuPos>1                 ;Can we move within the menu?
  481.                        Then PopDraw()            ; Yes- Blank current selection
  482.                             MenuPos=MenuPos-1    ;      Move window position
  483.                        Else PopRedraw(Choice-2)  ; No-  Redraw entire menu
  484.                     Endif
  485.                     Choice=Choice-1              ;Select new choice
  486.             Endif
  487.          Case Char=-80:                          ;Key was [Down]
  488.             If Choice=PopupNumber[Num]           ;Are we already at the bottom?
  489.                Then Beep
  490.                Else If MenuPos<Size              ;Can we move within the menu?
  491.                        Then PopDraw()            ; Yes- Blank current selection
  492.                             MenuPos=MenuPos+1    ;      Move window position
  493.                        Else PopRedraw(Choice-Size+1); No-  Redraw entire menu
  494.                     Endif
  495.                     Choice=Choice+1              ;Select new choice
  496.             Endif
  497.          Case Char=-71:                          ;Key was [Home]
  498.             If MenuPos=Choice                    ;Is first selection on screen?
  499.                Then PopDraw()                    ; Yes- Blank current selection
  500.                Else PopRedraw(0)                 ; No-  Redraw menu from start
  501.             Endif
  502.             MenuPos=1                            ;Position at first item
  503.             Choice=1                             ;Select first item
  504.          Case Char=-79:                          ;Key was [End]
  505.             If Choice+Size-MenuPos=PopupNumber[Num];Is last selection on screen?
  506.                Then PopDraw()                    ; Yes- Blank current selection
  507.                Else PopRedraw(PopupNumber[Num]-Size); No-  Redraw end of menu
  508.             Endif
  509.             MenuPos=Size                         ;Position at bottom of menu
  510.             Choice=PopupNumber[Num]              ;Select last item
  511.          Case Char=-73:                          ;Key was [PgUp]
  512.             If MenuPos=Choice                    ;Are we within first screen?
  513.                Then Beep                         ; Yes- Disallow PgUp
  514.                Else If Choice-MenuPos-Size>0
  515.                        Then Choice=Choice-MenuPos-Size+1
  516.                        Else Choice=1
  517.                     Endif
  518.                     PopRedraw(Choice-1)          ; No-  Redraw previous page
  519.                     MenuPos=1                    ;   Position on that item
  520.             Endif
  521.          Case Char=-81:                          ;Key was [PgDn]
  522.             If Choice+Size-MenuPos=PopupNumber[Num];Are we within last screen?
  523.                Then Beep                           ; Yes- Disallow PgDn
  524.                Else If PopupNumber[Num]-Size<Choice+Size-MenuPos
  525.                        Then Choice=PopupNumber[Num]-Size+1
  526.                        Else Choice=Choice+Size-MenuPos+1
  527.                     Endif
  528.                     PopRedraw(Choice-1)            ; No- Redraw next page
  529.                     MenuPos=1                      ;     Position on that item
  530.             Endif
  531.          Case Char=13:                             ;Key was [Enter]
  532.             Cursor Normal
  533.             Return PopupList[PopupStart[Num]+Choice]       ;Return selection
  534.          Case Char=27:                             ;Key was [Esc]
  535.             Cursor Normal
  536.             Return ""
  537.          Otherwise:                                ;Illegal key
  538.             Beep
  539.       Endswitch
  540.    Endwhile
  541. Endproc
  542. Writelib Libname Popup
  543. Release Procs Popup
  544.  
  545.  
  546. Proc PopDraw() ;--------------------------------------------------------------
  547.    @MenuPos+R+2,C+2
  548.    ?? PopupList[PopupStart[Num]+Choice]
  549. Endproc
  550. Writelib Libname PopDraw
  551. Release Procs PopDraw
  552.  
  553.  
  554. Proc PopRedraw(Start) ;-------------------------------------------------------
  555. ;Private Start           ;Location within PopupList to begin redraw
  556.    For Z from 1 to Size            ;Redraw all information in the menu box
  557.       @R+Z+2,C+2
  558.       ?? substr(strval(PopupList[PopupStart[Num]+Start+Z])+
  559.          spaces(PopupLen[Num]),1,PopupLen[Num]-3)
  560.    Endfor
  561.    @R+3,C+1
  562.    If Start=0          ;Are there records above?
  563.       Then ?? " "      ; No- Remove up arrow
  564.       Else ?? ""      ; Yes- Place up arrow to signify more records
  565.    Endif
  566.    @R+Size+2,C+1
  567.    If Start+Size=PopupNumber[Num]  ;Are there records below?
  568.       Then ?? " "                  ; No- Remove down arrow
  569.       Else ?? ""                  ; Yes- Place down arrow to signify more
  570.    Endif
  571. Endproc
  572. Writelib Libname PopRedraw
  573. Release Procs PopRedraw
  574.  
  575.  
  576.  
  577.