home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR22 / JORF21_2.ZIP / MAILLIST.J < prev    next >
Text File  |  1993-07-05  |  16KB  |  430 lines

  1. Class:Contact           | Class definition for a Contact structure
  2.   Index:FullName        | Full name
  3.   Index:Company         | Company
  4.   Index:WorkPhone       | Work Phone
  5.   Index:LastName        | Last Name
  6.   Index:ZipCode         | Zip Code
  7.   Addr1                 | Address
  8.   Addr2
  9.   Addr3
  10.   HomePhone             | Home Phone
  11.   WorkPhone
  12.   FaxPhone
  13.   Birthday
  14.   Anniversary
  15.   Dear
  16.   Comment
  17.   Notes                 | Notepad
  18.   Type
  19.  
  20. MailList:Start                     | Little Mail List Program
  21.   New (Contact:Con)                | Create Contact Structure
  22.   Jorf:File ("CONTACT.JCM",Here)   | Set Database File to CONTACT.JCM
  23.   Event:Add ("MailKey","Key",Here) | Set MailKey as a keystroke handler
  24.   Mem:Ptr->IndexName = "FullName"  | Index Name
  25.  
  26.   | The main screen with menu options
  27.   Win:Add ("Josephine's Mail List Manager", 2, 2, 22, 78, Here)
  28.     Menu:"&File"
  29.       Menu:"&About            "  Action:"MailList:About"
  30.       Menu:
  31.       Menu:"&Rebuild        ",   Action:"Jorf:Rebuild"
  32.       Menu:
  33.       Menu:"E&xit        Alt-X", Action:"Kbd:Put('Esc_Key')"
  34.  
  35.     Menu:"&Edit"
  36.       Menu:"&Add     Alt-A", Action:"MailList:Add(Con)"    HotKey:"Alt_A_Key"
  37.       Menu:"&Change  Alt-C", Action:"MailList:Change(Con)"
  38.       Menu:"&Delete  Alt-D", Action:"MailList:Delete(Con)" HotKey:"Alt_D_Key"
  39.  
  40.     Menu:"&Search",
  41.       Menu:"&Name       ",  Action:"MailList:KeySearch (Con, 'FullName' )
  42.       Menu:"&Company    ",  Action:"MailList:KeySearch (Con, 'Company'  )
  43.       Menu:"&Last Name  ",  Action:"MailList:KeySearch (Con, 'LastName' )
  44.       Menu:"&Phone      ",  Action:"MailList:KeySearch (Con, 'WorkPhone')
  45.       Menu:"&Zip        ",  Action:"MailList:KeySearch (Con, 'ZipCode'  )
  46.  
  47.     Menu:"&Reports"
  48.       Menu:"&Mail List    ", Action:"MailList:List()"
  49.       Menu:"&This Contact ", Action:"MailList:PrintData(Con)"
  50.       Menu:"&Lotsa Labels ", Action:"MailList:ContinLabels(Con,'All')"
  51.       Menu:"&One Label",     Action:"MailList:ContinLabels(Con,'One')"
  52.  
  53.     InpBefore:"MailList:Lock(Con)"
  54.     Group:"&Browse List", Row:1 Col:41, Len:6, Wid:36
  55.     List:""
  56.       Field:"Con"
  57.       Next:"MailList:NextRecord(Con,'Next')"
  58.       Prev:"MailList:NextRecord(Con,'Prev')"
  59.       Show:"MailList:Show(Con)"
  60.       Before:"MailList:Write()"
  61.       Display:"(Mem:Ptr->Locked==Null)"
  62.  
  63.     Group:"&Contact Name and Address", Row:1, Col:1, Wid:38, Len:6
  64.     Input:"Name   ",    Wid:30, Field:"Con->FullName"
  65.       After:"MailList:SplitName(Con)"
  66.     Input:"Company", Wid:30,    Field:"Con->Company"
  67.     Input:"Address", Wid:30,    Field:"Con->Addr1"
  68.     Input:"       ", Wid:30,    Field:"Con->Addr2"
  69.     Input:"       ", Wid:30,    Field:"Con->Addr3"
  70.       After:"MailList:ZipCode(Con)"
  71.  
  72.     Group:"Mail List Fields"
  73.       Row:9  Col:1  Len:11  Wid:76
  74.     Input:"&Work Phone" Field:"Con->WorkPhone"
  75.       Row:10  Col:2  Wid:20
  76.     Input:"&Home Phone"  Field:"Con->Homephone"
  77.       Row:11  Col:2  Wid:20
  78.     Input:"Fax &Phone " Field:"Con->FaxPhone"
  79.       Row:12  Col:2  Wid:20
  80.     Input:"Birthda&y  " Field:"Con->BirthDay"
  81.       Row:13  Col:2  Wid:20
  82.     Input:"C&omment   "  Field:"Con->Comment"
  83.       Row:15  Col:2  Wid:50
  84.     Input:"&Last Name " Field:"Con->LastName"
  85.       Row:10  Col:35  Wid:14
  86.     Input:"Dear      " Field:"Con->Dear"
  87.       Row:11  Col:35  Wid:14
  88.     Input:"Zip Code  " Field:"Con->Zipcode"
  89.       Row:12  Col:35  Wid:14
  90.     Radio:"Fr&iend"
  91.       Check:"Con->Type=='Friend'"
  92.       Action:"Con->Type='Friend'"
  93.       UnAction:"Con->Type= Null"
  94.       Row:10  Col:62
  95.     Radio:"Fa&mily"
  96.       Check:"Con->Type=='Family'"
  97.       Action:"Con->Type='Family'"
  98.       UnAction:"Con->Type= Null"
  99.       Row:11  Col:62
  100.     Radio:"Clien&t"
  101.       Check:"Con->Type=='Client'"
  102.       Action:"Con->Type='Client'"
  103.       UnAction:"Con->Type= Null"
  104.       Row:12  Col:62
  105.     Radio:"&Vendor"
  106.       Check:"Con->Type=='Vendor'"
  107.       Action:"Con->Type='Vendor'"
  108.       UnAction:"Con->Type= Null"
  109.       Row:13  Col:62
  110.     HLine:"&Notes"
  111.       Row:16  Col:2  Len:1  Wid:76
  112.     Text:"" Field:"Con->Notes"
  113.       Row:17  Col:2  Len:4  Wid:76
  114.   Return (Ok)                         | That is all, Folks!
  115.  
  116. MailList:About
  117.   Msg:Add ("The JORF Mail List Manager", "Ok")
  118.     The JORF MailList Manager   Version 1.0     December 22, 1992
  119.  
  120.     Copyright (C) 1992 by Wayland Bruns, All Rights Reserved
  121.  
  122.     This program is a small version of the CONTACT.J contact manager. &
  123.     It features a name/address/phone number file, and limited &
  124.     label printing.  It does not support multiple files, filters &
  125.     and mail merge capability all found in CONTACT.J.
  126.  
  127.     Use this program as a base for new data base applications.  It &
  128.     is less complex than CONTACT.J but contains multiple keys, &
  129.     record locking and screen management functions needed by all &
  130.     data bases. For an even simpler example, see FILTER.J
  131.   Return (Ok)
  132.  
  133. MailList:Add(*Con)                 | Create a new record
  134.   | The key to creating a new record is to use the New function.
  135.   | The new function must be the first function used in a method.
  136.   | The new function is the only way in JORF to allocate memory
  137.   | and disk resources to create a new piece of data.
  138.   New (Contact:NewCon)            | Create and new empty maillist structure
  139.   NewCon->FullName = "New Record"  | Set a piece of data in it
  140.   Jorf:Write(NewCon)               | Write it to the correct file
  141.   Con = NewCon                      | And reset "Con" to point to our new one.
  142.   Win:Dsp                         | Redisplay everything
  143.   Kbd:Put("Alt_C_Key")            | Move the cursor to "Name"
  144.   Return(Ok)
  145.  
  146. MailList:Change()               | Change the current Con record
  147.   Kbd:Put("Alt_C_Key")          | stuff Alt_C to move the cursor to Name
  148.   Return(Ok)                    | That is all!
  149.  
  150. MailList:ContinLabels(Con,Flag)
  151.   New (Dest,Count,i)
  152.   Dest=Jorf:Printer()
  153.   If (Dest)
  154.     | Report format for Continuous labels, 6 lines per label, 1 line between
  155.     |
  156.     Rep:Add ("Continuous Labels")
  157.       Next:"MailList:Nextlabel(Con,Flag,Count)"
  158.       Item:"" NewRow:1 Col:26 Wid:12
  159.       Item:"Con->FullName"    NewRow:1 Col:1  Wid:40
  160.       Item:"Con->Company"     NewRow:1 Col:1  Wid:40
  161.         Before:"Con->Company!=Null"
  162.       Item:"Con->Addr1"       NewRow:1 Col:1  Wid:40
  163.       Item:"Con->Addr2"       NewRow:1 Col:1  Wid:40
  164.       Item:"Con->Addr3"       NewRow:1 Col:1  Wid:40
  165.       Item:"" NewRow:1
  166.         Before:"Con->Company==Null"
  167.  
  168.     | I like to append one blank label to advance the printer so I can
  169.     |  tear off the label just printed.
  170.     For (i=1 Thru 5)
  171.       File:Append("JREPORT.LST")
  172.  
  173.     | The Rep:Add function does not actually print, it just makes
  174.     | a report file called JREPORT.LST.  We can print this file
  175.     | using the File:Print function.
  176.     File:Print("JREPORT.LST",Dest,TRUE)
  177.   Return(Ok)
  178.  
  179. MailList:Delete(Con)             | Delete MailList Record
  180.   New (Result)
  181.  
  182.   | Pop up a nice screen to ask if they are sure
  183.   Result=Msg:Add('MailList Delete','No')
  184.     Delete this contact?
  185.  
  186.     Name:     {Bold:5}{Str:Pad(Con->FullName,30)}{Bold:0}
  187.     Company:  {Bold:5}{Str:Pad(Con->Company ,30)}{Bold:0}
  188.     Address : {Bold:5}{Str:Pad(Con->Addr1,30)}{Bold:0}
  189.               {Bold:5}{Str:Pad(Con->Addr2,30)}{Bold:0}
  190.               {Bold:5}{Str:Pad(Con->Addr3,30)}{Bold:0}
  191.  
  192.   | If they said "Yes", then Result will equal Ok (1)
  193.   If (Result==Ok)
  194.     Jorf:Del(Con)
  195.     Win:Dsp
  196.   Return (Ok)
  197.  
  198. MailList:KeySearch (*Con, Field)
  199.   New (Value,Prompt)
  200.  
  201.   Event:Add               | Block "MailKey" Events so Alt-C won't work
  202.   Switch (Field)
  203.     Case ("FullName")
  204.       Prompt="Name"
  205.     Case ("Company")
  206.       Prompt="Company"
  207.     Case ("WorkPhone")
  208.       Prompt="Phone"
  209.     Case ("LastName")
  210.       Prompt="Last Name"
  211.     Case ("ZipCode")
  212.       Prompt="Zip Code"
  213.     Else
  214.       Msg:Add
  215.         Unknown Field {Field}
  216.       Return (Ok)
  217.  
  218.   Win:Add ("Key Search", 10, 15, 6, 60, Here)
  219.     Input:"Search for {Prompt}", Row: 2 Col:5 Wid:30, Field:"Value"
  220.     Button:"&Search"  Row:4 Col:5  Wid:20 Action:"Return (Null)"
  221.     Button:"&Cancel"  Row:4 Col:35 Wid:20 Action:"Return ('Esc_Key')"
  222.  
  223.   If (Kbd:Got <> "Esc_Key")
  224.     Mem:Ptr->IndexName=Field
  225.     Con=Struct:Find('Contact',Mem:Ptr->IndexName,Value)
  226.     If (Con==Null)
  227.       If (Value)
  228.         Msg:Add
  229.           Cannot find {Prompt} {Value}
  230.       Con=Struct:Find('Contact',Mem:Ptr->IndexName,Null)
  231.     Win:Dsp
  232.   Return (Ok)
  233.  
  234. MailList:List()
  235.   New (Dest,Date,Page,Con,Count)
  236.   Dest=Jorf:Printer()
  237.   If (Dest)
  238.     Date = Date:Str(Date:Get,"s d, yyyy")
  239.     Rep:Add ("MailList Listing", 5, 5, 60, 75, Here)
  240.       Header:"'MailList Listing Report'"    NewRow:1 Col:30
  241.       Header:"'Page '+Page"        NewRow:1 Col:1
  242.         Before:"MailList:NextPage(Page)"
  243.       Header:"'Date '+Date"                Col:54
  244.       Header:"Str:AtSet(Null,1,'-',70)"     NewRow:1 Col:1
  245.       Next:"MailList:NextLabel(Con,'All',Count)"
  246.       Item:"Con->FullName"      NewRow:2 Col:1  Len:28
  247.       Item:"Con->Company "               Col:30 Len:32
  248.       Item:"Con->WorkPhone"              Col:62 Len:28
  249.       Item:"Con->Addr1+', '+Con->Addr2+' '+Con->Addr3"
  250.         NewRow:1 Col:5  Len:70
  251.     File:Print("Jreport.lst",Dest)
  252.   Return (Ok)
  253.  
  254. MailList:Lock(Con)
  255.   If (Mem:Ptr->Locked==Con)
  256.     If (Win:Ptr->InpField = "Con->Notes")
  257.       Win:Msg("Press Alt-B to finish note and return to Browse Area")
  258.     Else
  259.       Win:Msg("You have locked this Record")
  260.     Return (Ok)
  261.   MailList:Write()
  262.   If (Jorf:Lock(Con))
  263.     Mem:Ptr->Locked=Con
  264.     Win:Msg("You have locked this Record")
  265.     Return (Ok)
  266.   If (Con <> Mem:Ptr->Unlocked)         | If first time
  267.     Msg:Add("Record is Locked")         |  show message
  268.       Either someone else has this
  269.       record locked now, or it has
  270.       been locked before but never
  271.       unlocked.
  272.  
  273.       If no one else is in the data
  274.       base, you can unlock this
  275.       record by rebuilding the file.
  276.     Mem:Ptr->Unlocked = Con              | Make a record that message is shown
  277.   Return(Null)
  278.  
  279. MailList:NextLabel(*Con,Flag,*Count)     | Label "Next function
  280.   | If Flag = "All", Returns next record according to index.
  281.   | If Flag = One, returns Con if count is 1 and Null if Count > 1
  282.   |  returning null indicates that there is no "Next" record and the
  283.   |  report is finished.
  284.   Count = Count + 1
  285.   If (Flag=='All')
  286.     If (Count == 1)
  287.       Con = Null
  288.     Con = MailList:NextRecord(Con,'Next')
  289.   Else
  290.     If (Count > 1)
  291.       Con=Null
  292.   Return (Con)
  293.  
  294. MailList:NextPage(*Page)                | Increment page counter
  295.   ++Page
  296.   Return (Ok)
  297.  
  298. MailList:NextRecord(*Con,Flag)           | Return next or prev record
  299.   | Gets the next (or previous) record depending on Flag
  300.   | Flag is "Next" or "Prev" Easy!
  301.   MailList:Write()                      | Write current record if necessary
  302.   If (Flag=='Prev')
  303.     Con=Struct:Prev('Contact',Mem:Ptr->IndexName,Con)
  304.   Else
  305.     Con=Struct:Next('Contact',Mem:Ptr->IndexName,Con)
  306.   Return(Con)
  307.  
  308. MailList:PrintData(Con)
  309.   | Print the data from this entry - Uses a report "Format" in
  310.   |  the file MAILLIST.RPT.  This format is an ASCII file that
  311.   |  can easily be modified.
  312.   New (Dest,MailList,Date,Page)
  313.   If (File:Exist("MailList.Rpt")==False) | If file not found.
  314.     Msg:Add
  315.       Print format "MailList.Rpt" is
  316.       not in the current directory.
  317.     Return (Ok)
  318.   Dest=Jorf:Printer()                           | Get printer
  319.   If (Dest)
  320.     Date = Date:Str(Date:Get,"s d, yyyy")       | Set Date
  321.     Rep:Add ("MailList Information", 5, 5, 60, 75,Here)
  322.       | Report header . . .
  323.       Header:"'MailList Information Report'"    NewRow:1 Col:30
  324.       Header:"'Page '+Page"                     NewRow:1 Col:1
  325.         Before:"MailList:NextPage(Page)"
  326.       Header:"'Date '+Date"                              Col:54
  327.       Header:"Str:AtSet(Null,1,'-',70)"         NewRow:1 Col:1
  328.       | To print report text, Ust say "Text"
  329.       Text:"File:Load('MailList.Rpt')"
  330.       | Rep:Add system uses a "Next" to get the next record.
  331.       | For this report, we only want to show one record, so
  332.       | we make the next function return "Null" indicating that
  333.       | there is no next record and the report is finished.
  334.       Next:"Null"
  335.     | The JORF report system only makes a print file called JREPORT.LST.
  336.     | Once created, we use File:Print to print it.
  337.     File:Print("Jreport.lst",Dest)
  338.   Return (Ok)
  339.  
  340. MailList:Show (Con)
  341.   | The "Show" routine is used for the browser window.  The data that
  342.   | is shown changes depending on the index in use - (try switching to
  343.   | the phone number or zip code indexes to see the difference).
  344.   New (Display)                        | Create "Display"
  345.   Switch (Mem:Ptr->IndexName)
  346.     Case ("FullName")
  347.       Display = Str:Pad(Con->FullName,17)+' '+Str:Pad(Con->Company,17)
  348.     Case ("Company")
  349.       Display = Str:Pad(Con->Company,17)+' '+Str:Pad(Con->FullName,17)
  350.     Case ("WorkPhone")
  351.       Display = Str:Pad(Con->WorkPhone,17)+' '+Str:Pad(Con->FullName,17)
  352.     Case ("LastName")
  353.       Display = Str:Pad(Con->LastName,10)+' '+Str:Pad(Con->Dear,12)
  354.       Display = Display +' '+Str:Pad(Con->Company,17)
  355.     Case ("ZipCode")
  356.       Display = Str:Pad(Con->ZipCode,5)+' '+Str:Pad(Con->Company,16)
  357.       Display = Display +' '+Str:Pad(Con->FullName,12)
  358.   Return (Display)
  359.  
  360. MailList:SplitName(Con)          | "After" function to find Dear and lastname
  361.   If (Con->FullName)                     | If there is a name
  362.     If (Con->Dear==Null)                 |  But dear is still empty
  363.       Con->Dear=Word:At(Con->FullName,1)  | Dear is the first word
  364.     If (Con->LastName==Null)             | Last name is the last word
  365.       Con->LastName=Word:At(Con->FullName,Word:Len(Con->FullName))
  366.   Return (Ok)                   | This works in most cases.
  367.  
  368. MailList:Write()
  369.   New (Result,Con)
  370.   If (Mem:Ptr->Locked)           | If there is a locked record
  371.     Jorf:Write(Mem:Ptr->Locked)  |   write it
  372.     Win:Dsp                      |   and redisplay browse box
  373.     Mem:Ptr->Locked=Null         | No longer locked
  374.     Win:Msg()                    | Erase "Locked" message
  375.   Return (Ok)                    | That is all
  376.  
  377. MailList:ZipCode (Con)           | "After" function to set zip code
  378.   New (Field)                    | Create new variable "Field"
  379.   If (Con->ZipCode==Null)        | If zip code is still blank
  380.     If (Con->Addr3)              | Find the last line of the address
  381.       Field=Con->Addr3           |   is it line 3?
  382.     Else
  383.       Field=Con->Addr2           |   or line 2.
  384.     While (Str:In(Field," "))   |               While there is a space
  385.       Field=Str:At(Field,Str:In(Field," ")+1)  | take away up to space+1
  386.     Con->ZipCode=Field           | Now we have the last expression of the
  387.     Win:Dsp                     |  line - set zip.  Redisplay everything.
  388.   Return (Ok)
  389.  
  390. MailKey:Alt_F4_Key
  391.   Return (MailKey:Esc_Key())   | Alt_F4 (Windows exit) - same as Esc_Key
  392.  
  393. MailKey:Alt_X_Key
  394.   Return (MailKey:Esc_Key())   | Alt_X - does same as Esc_Key
  395.  
  396. MailKey:Enter_Key
  397.   | Change enter key - to tab key.  This makes a lot of PC people
  398.   | happier.  In Windows land, the Tab key moves between fields,
  399.   | but in DOS land, the Enter key does this.  JORF defaults to Windows
  400.   | "Common User Access" Standard, but this routine lets us also
  401.   | support the common DOS practice (Even though this is not "Standard".
  402.   |
  403.   | Test if we are in an input then InpLen is set to the
  404.   |  number of input lines.
  405.   If (Win:Ptr->InpLen == 1)
  406.     Return ("Tab_Key")
  407.   Return (Null)
  408.  
  409. MailKey:Esc_Key         | Block the escape key - provide an exit routine.
  410.   New (Res)
  411.   MailList:Write()
  412.   Res=Msg:Add(Null,"Cancel")
  413.     This will end your session with
  414.     Josephine's MailList Manager
  415.   If (Res)
  416.     Return ("Esc_Key")
  417.   Return (Ok)
  418.  
  419. MailKey:Shift_F5_Key
  420.   Jorf:Status
  421.   Jorf:StatusClear
  422.   Return (Ok)
  423.  
  424. MailKey:Alt_F5_Key
  425.   Win:Add
  426.     Flushing
  427.   Jorf:Flush
  428.   Return (Ok)
  429.  
  430.