home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / OBJTBA.ZIP / MMGR.DOC < prev    next >
Encoding:
Text File  |  1993-01-04  |  35.1 KB  |  907 lines

  1.    
  2.    
  3.                                            MMGR.PAS LISTING   PAGE  1    
  4.    
  5.    
  6.    PROGRAM MMGR;
  7.    { *******************************************************************
  8.       Author: Thomas W. Harden
  9.       Version: 1.0
  10.    
  11.                         (C) 1990 Thomas W. Harden
  12.                            All rights reserved
  13.    
  14.      Demonstration program for Harden Consulting.  Utilizes Copyrighted
  15.      program developement tools for DataBase manipulation, Menus, and
  16.      Data input/output forms.  A relational data base is used with a
  17.      many to many relationship between the inities (Companies and Persons)
  18.      via a Third file (Contacts).  This is the extent of the programing
  19.      required to implement this application.
  20.    
  21.      ******************************************************************* }
  22.    
  23.    USES Crt,
  24.         Dos,
  25.         OopBase,     { ObjectBase Compiled Unit.              }
  26.         UserIO,      { ObjectInterFace Module                 }
  27.         Windows,     {     "            "                     }
  28.         Forms,       {     "            "                     }
  29.         Fields,      {     "            "                     }
  30.         Utility,     {     "            "                     }
  31.         SysIntro,    { Creates The First Screen Image.        }
  32.         MMgrVar,     { Unit containing Applications variables }
  33.                      {  and initialization routines.          }
  34.         MMgrRpts;    { Unit containing Application specific   }
  35.                      {  report routines.                      }
  36.    
  37.    PROCEDURE InitDB(Var D : DB);
  38.    {
  39.    This procedure is passed the Database variable and calls the the objects
  40.    initialization (D.Init), loads the Datafile information and indexfile
  41.    information, opens the database then sets up the first records to view.
  42.    Note the use of Constants for the FileNames. This makes it easier to
  43.    remember and write the proper term when searching for a file to SwitchTo.
  44.    }
  45.    BEGIN      { InitDB }
  46.      D.Init;
  47.      D.LoadDataFile(New(DFilePtr,init(CompanyData,'',SizeOf(Company),
  48.                      @Company)));
  49.      D.LoadIndexFile(New(IFilePtr,init(CompanySysNdx,'',SizeOf(Company.Code),
  50.                       @Company.Code,0)),CompanyData);
  51.      D.LoadIndexFile(New(IFilePtr,init(CompanyUserNdx,'',SizeOf(Company.Alpha),
  52.                       @Company.Alpha,1)),CompanyData);
  53.      D.LoadDataFile(New(DFilePtr,init(PersonData,'',SizeOf(Person),@Person)));
  54.      D.LoadIndexFile(New(IFilePtr,init(PersonSysNdx,'',SizeOf(Person.Code),
  55.                       @Person.Code,0)),PersonData);
  56.      D.LoadIndexFile(New(IFilePtr,init(PersonUserNdx,'',SizeOf(Person.AlphaK),
  57.                       @Person.AlphaK,1)),PersonData);
  58.      D.LoadDataFile(New(DFilePtr,init(ContactData,'',SizeOf(Contact),@Contact)));
  59.      D.LoadIndexFile(New(IFilePtr,init(ContactCompAccess,'',
  60.                       SizeOf(Contact.Ckey),
  61.                       @Contact.ckey,0)),ContactData);
  62.    
  63.    
  64.                                            MMGR.PAS LISTING   PAGE  2    
  65.    
  66.    
  67.      D.LoadIndexFile(New(IFilePtr,init(ContactPrsnAccess,'',
  68.                       SizeOf(Contact.PKey),
  69.                       @Contact.PKey,0)),ContactData);
  70.      D.Open;
  71.      D.SwitchTo(CompanyData);    { Sets 'COMPANY.DAT' to primary file  }
  72.      D.SetIndex(CompanyUserNdx); { Sets 'COMPALPH.NDX' as ordering Ndx }
  73.      D.Top;                      { Sets Company to the 1st alphabetic  }
  74.                                  {  entry in file                      }
  75.      D.SwitchTo(PersonData);     { Sets 'PERSON.DAT' to primary file   }
  76.      D.SetIndex(PersonUserNdx);  { Sets 'PRSNALPH.NDX' as ordering Ndx }
  77.      D.Top;                      { Sets Person to the 1st alphabetic   }
  78.                                  {  entry  in file                     }
  79.    END;       { InitDB }
  80.    
  81.    
  82.    PROCEDURE CompanyMaint;
  83.    VAR
  84.      Choice,
  85.      Choice1 : Integer;          { Menu selection variables }
  86.      Finished,
  87.      Finished1 : Boolean;        { Loop Control variables   }
  88.      Key : String;
  89.      Ch  : Char;                 { Dummy receiver for pause }
  90.    
  91.    BEGIN
  92.    { Set up relations for viewing data from company perspective }
  93.    { Company  --> Contact --> Person                            }
  94.    {    code  <--         --> code                              }
  95.      DBase.LoadRelation( CompanyData,ContactData,ContactCompAccess,
  96.                          @Company.Code);
  97.      DBase.loadRelation( ContactData,PersonData,PersonSysNdx,
  98.                          @Contact.personCode);
  99.      Choice := 0;
  100.      Finished := False;
  101.      PushHelp(ord(CompanyHelp));     { Sets context sinsitive help system}
  102.      DBase.Switchto(CompanyData);
  103.      DBase.SetIndex(CompanyUserNdx);
  104.      DBase.get;
  105.      DBase.Associate(CompanyData);   { Sets Record variables to values based }
  106.                                      { on the Relations just loaded          }
  107.      CompForm.Show;                  { This an instance of the Form object   }
  108.      REPEAT
  109.        CompForm.Leave;               { Informs CompForm that it is inactive, }
  110.                                      {  Still visible.                       }
  111.        Choice := CompanyMenu.Pop;    { Displays PopUp Menu and Returns Choice}
  112.        CompanyMenu.Hide;             { Removes Menu From Screen              }
  113.        Case Choice of
  114.          1: BEGIN  { Record Edit }
  115.               PushHelp(ord(CompanyeditHelp));  { Sets help to Edit Help }
  116.               if Not DBase.Empty then
  117.               begin
  118.                 compform.edit;
  119.                 company.rcst.upstamp := timeStamp;
  120.                 dbase.put;
  121.               end
  122.               else
  123.    
  124.    
  125.                                            MMGR.PAS LISTING   PAGE  3    
  126.    
  127.    
  128.                 with EmptyFileMsg do     { <-- EmptyFileMsg is a Message }
  129.                 begin                    {     object.                   }
  130.                   show;
  131.                   Ch := ReadKey;
  132.                   hide;
  133.                 end;
  134.               PopHelp;                    { Returns help to prevs state }
  135.             END;  { Record Edit }
  136.          2: BEGIN { Find Record }
  137.               if Not DBase.Empty then
  138.               begin
  139.                 PushHelp(ord(CompanyFindHelp));
  140.                 Key := query('Enter Alpha Key of Company desired?',
  141.                              Rpt('U',SizeOf(company.alpha)-1),
  142.                              SizeOf(company.alpha)-1);
  143.                 DBase.Search(Key);
  144.                 DBase.Associate(CompanyData);
  145.                 CompForm.show;
  146.                 popHelp;
  147.               end
  148.               else
  149.                 with EmptyFileMsg do
  150.                 begin
  151.                   show;
  152.                   Ch := ReadKey;
  153.                   hide;
  154.                 end;
  155.             END;  { Find Record }
  156.          3: BEGIN { Get Next Record }
  157.               if Not DBase.Empty then
  158.               begin
  159.                 dbase.next;                    { Returns the next record in }
  160.                                                { the primary file, orderd by}
  161.                                                { the active index.          }
  162.                 DBase.Associate(CompanyData);  { Aligns Dbase based on the  }
  163.                                                { the active relations       }
  164.                 compform.show;
  165.               end
  166.               else
  167.                 with EmptyFileMsg do
  168.                 begin
  169.                   show;
  170.                   Ch := ReadKey;
  171.                   hide;
  172.                 end;
  173.             END;
  174.          4: BEGIN
  175.               if Not DBase.Empty then
  176.               begin
  177.                 dbase.Prev;                    { Returns the Prevs record in }
  178.                                                { the primary file, orderd by }
  179.                                                { the active index.           }
  180.                 DBase.Associate(CompanyData);  { Aligns Dbase based on the   }
  181.                                                { the active relations        }
  182.                 compform.show;
  183.               end
  184.    
  185.    
  186.                                            MMGR.PAS LISTING   PAGE  4    
  187.    
  188.    
  189.               else
  190.                 with EmptyFileMsg do
  191.                 begin
  192.                   show;
  193.                   Ch := ReadKey;
  194.                   hide;
  195.                 end;
  196.             END;   { get Previous record }
  197.          5: BEGIN  { Add a Company record }
  198.               PushHelp(ord(CompanyaddHelp));
  199.               dbase.blankrecord;        { Initializes the Pimary Data Record }
  200.               DBase.Associate(CompanyData);
  201.               company.rcst.instamp := timeStamp;
  202.               company.code := nextcode(dbase.lastcode(companysysndx),
  203.                                         sizeof(company.code)-1);
  204.               compform.edit;            { CompForm object will edit itself }
  205.               compform.leave;
  206.               company.rcst.upstamp := timeStamp;
  207.               if YesNo(concat('Do really want to add this record to ',
  208.                       CompanyData,'?')) Then
  209.                  dbase.add                    { yes add record to file }
  210.               ELSE
  211.               BEGIN                           { No reset file to prev state }
  212.                 DBase.prev;
  213.                 DBAse.Associate(CompanyData);
  214.                 CompForm.show;                { show reset data }
  215.               END;
  216.               PopHelp;
  217.             END;  { Add Record }
  218.          6: BEGIN { Set Flag Field }
  219.               if Not DBase.Empty then
  220.               begin
  221.                 Company.Flag := Not (Company.flag);
  222.                 DBase.put;
  223.                 CompForm.show;
  224.               end
  225.               else
  226.                 with EmptyFileMsg do
  227.                 begin
  228.                   show;
  229.                   Ch := ReadKey;
  230.                   hide;
  231.                 end;
  232.             END;
  233.          7: BEGIN  { Add a Contact }
  234.               if Not DBase.Empty then
  235.               begin
  236.                 PushHelp(ord(companycontacthelp));
  237.                 DBase.Switchto(PersonData);
  238.                 DBase.SetIndex(PersonUserNdx);
  239.               { Get Person Key }
  240.                 Key := '';
  241.                 Key := Query('Enter last name of Contact->',
  242.                              rpt('U',sizeof(person.LName)-2),
  243.                              sizeof(Person.LName)-2);
  244.               { Show located person record }
  245.    
  246.    
  247.                                            MMGR.PAS LISTING   PAGE  5    
  248.    
  249.    
  250.                 DBase.Search(Key);
  251.                 PrsnContForm.Show;
  252.               { Get correct person record }
  253.                 Finished1 := False;
  254.                 REPEAT
  255.                   PrsnContForm.Leave;
  256.                   Choice1 := CompContMenu.Pop;
  257.                   CompContMenu.Hide;
  258.                   Case Choice1 of
  259.                     1 : BEGIN                         { Correct    }
  260.                           if Not DBase.Empty then
  261.                           begin
  262.                             pushHelp(ord(Comp2PrsnAddHelp));
  263.                             DBase.SwitchTo(ContactData);
  264.                             DBAse.BlankRecord;
  265.                             Contact.Position := Query(
  266.                                Concat('Enter ',Person.FName,' ',Person.LName,
  267.                                '''s position with ',Company.alpha,'->'),
  268.                                rpt('W',sizeof(contact.Position)-1),
  269.                                sizeof(Contact.Position)-1);
  270.                             Contact.PersonCode := Person.Code;
  271.                             Contact.CompanyCode := Company.Code;
  272.                             Contact.PKey := Concat(Contact.PersonCode,
  273.                                                    Contact.CompanyCode);
  274.                             Contact.CKey := Concat(Contact.CompanyCode,
  275.                                                    Contact.PersonCode);
  276.                             dbase.setindex(ContactCompAccess);
  277.                             if DBase.keyexist(contact.cKey) then
  278.                             begin
  279.                               RecordExists.show;
  280.                               ch := Readkey;
  281.                               RecordExists.hide;
  282.                             end
  283.                             else
  284.                             DBase.add;
  285.                             Finished1 := True;
  286.                             PopHelp;
  287.                           end
  288.                           else
  289.                             with EmptyFileMsg do
  290.                             begin
  291.                               show;
  292.                               Ch := ReadKey;
  293.                               hide;
  294.                             end;
  295.                         END;
  296.                     2 : BEGIN                         { Next       }
  297.                           if Not DBase.Empty then
  298.                           begin
  299.                             DBase.Next;
  300.                             PrsnContForm.show;
  301.                           end
  302.                           else
  303.                             with EmptyFileMsg do
  304.                             begin
  305.                               show;
  306.    
  307.    
  308.                                            MMGR.PAS LISTING   PAGE  6    
  309.    
  310.    
  311.                               Ch := ReadKey;
  312.                               hide;
  313.                             end;
  314.                         END;
  315.                     3 : BEGIN                         { Prev       }
  316.                           if Not DBase.Empty then
  317.                           begin
  318.                             DBase.Prev;
  319.                             PrsnContForm.Show;
  320.                           end
  321.                           else
  322.                             with EmptyFileMsg do
  323.                             begin
  324.                               show;
  325.                               Ch := ReadKey;
  326.                               hide;
  327.                             end;
  328.                         END;
  329.                     4 : BEGIN                         { Add Person }
  330.                           PushHelp(ord(PersonAddHelp));
  331.                           dbase.blankrecord;
  332.                           dbase.Switchto(contactdata);
  333.                           dbase.blankrecord;
  334.                           dbase.switchto(persondata);
  335.                           Person.rcst.instamp := timeStamp;
  336.                           Person.code := nextcode(dbase.lastcode(Personsysndx),
  337.                                          sizeof(Person.code)-1);
  338.                           PersonForm.edit;
  339.                           Person.rcst.upstamp := timeStamp;
  340.                           Person.AlphaK := UpcaseStr(concat(copy(Person.LName,1,
  341.                                            sizeof(person.AlphaK)-2),
  342.                                            copy(person.fname,1,1)));
  343.                           personform.leave;
  344.                           if YesNo(concat('Do really want to add this record to ',
  345.                                   PersonData,'?')) Then
  346.                              dbase.add
  347.                           ELSE
  348.                             DBAse.Associate(companyData);
  349.                           PersonForm.Hide;
  350.                           prsnContform.show;
  351.                           popHelp;
  352.                         END;
  353.                     5 : Finished1 := True;           { Abandon    }
  354.                   END;
  355.                 UNTIL Finished1;
  356.                 PrsnContForm.hide;
  357.                 Dbase.SwitchTo(CompanyData);
  358.                 DBase.SetIndex(CompanyUserNdx);
  359.                 CompForm.Show;
  360.                 PopHelp;
  361.               end
  362.               else
  363.                 with EmptyFileMsg do
  364.                 begin
  365.                   show;
  366.                   Ch := ReadKey;
  367.    
  368.    
  369.                                            MMGR.PAS LISTING   PAGE  7    
  370.    
  371.    
  372.                   hide;
  373.                 end;
  374.             END;
  375.          8: BEGIN                          { View Next Contact }
  376.               if Not DBase.Empty then
  377.               begin
  378.                 DBase.NextAssoc(CompanyData);
  379.                 CompForm.Show;
  380.               end
  381.               else
  382.                 with EmptyFileMsg do
  383.                 begin
  384.                   show;
  385.                   Ch := ReadKey;
  386.                   hide;
  387.                 end;
  388.             END;
  389.          9: BEGIN  { Delete a Contact relationship }
  390.               if Not DBase.Empty then
  391.               begin
  392.                 Finished1 := False;
  393.                 REPEAT
  394.                   PushHelp(ord(contactDel));
  395.                 { present menu of choices }
  396.                   Choice1 := PersonContDelMenu.pop;
  397.                   PersonContDelMenu.Hide;
  398.                   Case Choice1 of
  399.                     1 : BEGIN     { Delete this one }
  400.                           Dbase.Switchto(ContactData);
  401.                           DBase.DelRec;
  402.                           Dbase.SwitchTo(CompanyData);
  403.                           Dbase.Associate(CompanyData);
  404.                           CompForm.Show;
  405.                           Finished1 := True;
  406.                         END;
  407.                     2 : BEGIN     { Get Next Relation }
  408.                           DBase.Nextassoc(PersonData);
  409.                           CompForm.Show;
  410.                         END;
  411.                     3 : BEGIN     { Abort }
  412.                           finished1 := True;
  413.                         END;
  414.                   END;
  415.                   Compform.leave;
  416.                 UNTIL finished1;
  417.                 PopHelp;
  418.               end
  419.               else
  420.                 with EmptyFileMsg do
  421.                 begin
  422.                   show;
  423.                   Ch := ReadKey;
  424.                   hide;
  425.                 end;
  426.             END;
  427.         10: Finished := True;
  428.    
  429.    
  430.                                            MMGR.PAS LISTING   PAGE  8    
  431.    
  432.    
  433.        END;
  434.      UNTIL Finished;
  435.      CompForm.Hide;
  436.      DBase.ClearRelations;           { Removes set of relations loaded for }
  437.                                      { this application.                   }
  438.                                      { At this time there are no known     }
  439.                                      { relations                           }
  440.      PopHelp;
  441.    END;
  442.    
  443.    PROCEDURE PersonMaint;
  444.    VAR
  445.      Choice,
  446.      Choice1 : Integer;
  447.      Finished,
  448.      Finished1 : Boolean;
  449.      Key : String;
  450.      Ch  : Char;
  451.    
  452.    BEGIN
  453.      Choice := 0;
  454.      Finished := False;
  455.      pushhelp(ord(personhelp));
  456.    { Set up relations for this section of code.                     }
  457.    { Person --> Contact --> Company                                 }
  458.    {   Code <--/       \--> Code                                    }
  459.      DBase.LoadRelation( PersonData,ContactData,ContactPrsnAccess,
  460.                          @Person.Code);
  461.      DBase.loadRelation( ContactData,CompanyData,CompanySysNdx,
  462.                          @Contact.CompanyCode);
  463.      DBase.Switchto(PersonData);
  464.      DBase.SetIndex(PersonUserNdx);
  465.      dbase.get;
  466.      DBase.Associate(PersonData);
  467.      PersonForm.Show;
  468.      REPEAT
  469.        PersonForm.Leave;
  470.        Choice := PersonMenu.Pop;
  471.        PersonMenu.Hide;
  472.        Case Choice of
  473.          1: BEGIN
  474.               if Not DBase.Empty then
  475.               begin
  476.                 pushhelp(ord(PersonEdithelp));
  477.                 PersonForm.edit;
  478.                 Person.rcst.upstamp := timeStamp;
  479.                 Person.AlphaK := UpcaseStr(concat(copy(Person.LName,1,
  480.                                      sizeof(person.AlphaK)-2),
  481.                                      copy(person.fname,1,1)));
  482.                 dbase.Put;
  483.                 pophelp;
  484.               end
  485.               else
  486.                 with EmptyFileMsg do
  487.                 begin
  488.                   show;
  489.    
  490.    
  491.                                            MMGR.PAS LISTING   PAGE  9    
  492.    
  493.    
  494.                   Ch := ReadKey;
  495.                   hide;
  496.                 end;
  497.             END;
  498.          2: BEGIN
  499.               if Not DBase.Empty then
  500.               begin
  501.                 pushhelp(ord(Personfindhelp));
  502.                 Key := query('Enter Last Name of Individual desired?',
  503.                              rpt('U',sizeof(Person.LName)-2),
  504.                              sizeof(Person.LName)-2);
  505.                 DBase.Search(Key);
  506.                 DBase.Associate(PersonData);
  507.                 PersonForm.show;
  508.                 pophelp;
  509.               end
  510.               else
  511.                 with EmptyFileMsg do
  512.                 begin
  513.                   show;
  514.                   Ch := ReadKey;
  515.                   hide;
  516.                 end;
  517.             END;
  518.          3: BEGIN
  519.               if Not DBase.Empty then
  520.               begin
  521.                 dbase.next;                    { Returns the Next record in  }
  522.                                                { the primary file, orderd by }
  523.                                                { the active index.           }
  524.                 DBase.Associate(PersonData);   { Aligns Dbase based on the   }
  525.                                                { the active relations        }
  526.                 PersonForm.show;
  527.               end
  528.               else
  529.                 with EmptyFileMsg do
  530.                 begin
  531.                   show;
  532.                   Ch := ReadKey;
  533.                   hide;
  534.                 end;
  535.             END;
  536.          4: BEGIN
  537.               if Not DBase.Empty then
  538.               begin
  539.                 dbase.Prev;                    { Returns the Prevs record in }
  540.                                                { the primary file, orderd by }
  541.                                                { the active index.           }
  542.                 DBase.Associate(PersonData);   { Aligns Dbase based on the   }
  543.                                                { the active relations        }
  544.                 PersonForm.show;
  545.               end
  546.               else
  547.                 with EmptyFileMsg do
  548.                 begin
  549.                   show;
  550.    
  551.    
  552.                                            MMGR.PAS LISTING   PAGE  10   
  553.    
  554.    
  555.                   Ch := ReadKey;
  556.                   hide;
  557.                 end;
  558.             END;
  559.          5: BEGIN
  560.               PushHelp(ord(PersonAddHelp));
  561.               dbase.blankrecord;
  562.               DBase.associate(PersonData);
  563.               Person.rcst.instamp := timeStamp;
  564.               Person.code := nextcode(dbase.lastcode(Personsysndx),
  565.                              sizeof(Person.code)-1);
  566.               PersonForm.edit;
  567.               PersonForm.Leave;
  568.               Person.rcst.upstamp := timeStamp;
  569.               Person.AlphaK := UpcaseStr(concat(copy(Person.LName,1,
  570.                                sizeof(person.AlphaK)-2),
  571.                                copy(person.fname,1,1)));
  572.               if YesNo(concat('Do really want to add this record to ',
  573.                       PersonData,'?')) Then
  574.                  dbase.add
  575.               ELSE
  576.               BEGIN
  577.                 DBase.get;
  578.                 DBAse.Associate(PersonData);
  579.                 PersonForm.show;
  580.               END;
  581.               PopHelp;
  582.             END;
  583.          6: BEGIN
  584.               if Not DBase.Empty then
  585.               begin
  586.                 Person.Flag := Not (Person.Flag);
  587.                 Dbase.put;
  588.                 PersonForm.show;
  589.               end
  590.               else
  591.                 with EmptyFileMsg do
  592.                 begin
  593.                   show;
  594.                   Ch := ReadKey;
  595.                   hide;
  596.                 end;
  597.             END;
  598.          7: BEGIN
  599.               if Not DBase.Empty then
  600.               begin
  601.                 PushHelp(Ord(PersonContactHelp));
  602.                 DBase.Switchto(companyData);
  603.                 DBase.SetIndex(companyUserNdx);
  604.                 { Get company Key }
  605.                 Key := '';
  606.                 Key := Query('Enter Company AlphaKey->',
  607.                        rpt('U',sizeof(Company.alpha)-1),
  608.                        sizeof(company.alpha)-1);
  609.                 { Show located company record }
  610.                 DBase.Search(Key);
  611.    
  612.    
  613.                                            MMGR.PAS LISTING   PAGE  11   
  614.    
  615.    
  616.                 CompContForm.Show;
  617.                 { Get correct company record }
  618.                 Finished1 := False;
  619.                 REPEAT
  620.                   CompContForm.Leave;
  621.                   Choice1 := PrsnContMenu.Pop;
  622.                   PrsnContMenu.Hide;
  623.                   Case Choice1 of
  624.                     1 : BEGIN                         { Correct    }
  625.                           if Not DBase.Empty then
  626.                           begin
  627.                             PushHelp(Ord(Prsn2CompAddHelp));
  628.                             DBase.SwitchTo(ContactData);
  629.                             DBAse.BlankRecord;
  630.                             Contact.Position := Query(
  631.                                Concat('Enter ',Person.FName,' ',Person.LName,
  632.                                '''s position with ',Company.Alpha,'->'),
  633.                                rpt('W',sizeof(contact.Position)-1),
  634.                                sizeof(Contact.Position)-1);
  635.                             Contact.PersonCode := Person.Code;
  636.                             Contact.CompanyCode := Company.Code;
  637.                             Contact.PKey := Concat(Contact.PersonCode,
  638.                                                    Contact.CompanyCode);
  639.                             Contact.CKey := Concat(Contact.CompanyCode,
  640.                                                    Contact.PersonCode);
  641.                             dbase.setindex(ContactPrsnAccess);
  642.                             if DBase.keyexist(contact.PKey) then
  643.                             begin
  644.                               RecordExists.show;
  645.                               ch := Readkey;
  646.                               RecordExists.hide;
  647.                             end
  648.                             else
  649.                               DBase.Add;
  650.                             Finished1 := True;
  651.                             popHelp;
  652.                           end
  653.                           else
  654.                             with EmptyFileMsg do
  655.                             begin
  656.                               show;
  657.                               Ch := ReadKey;
  658.                               hide;
  659.                             end;
  660.                         END;
  661.                     2 : BEGIN                         { Next       }
  662.                           if Not DBase.Empty then
  663.                           begin
  664.                             DBase.Next;
  665.                             CompContForm.show;
  666.                           end
  667.                           else
  668.                             with EmptyFileMsg do
  669.                             begin
  670.                               show;
  671.                               Ch := ReadKey;
  672.    
  673.    
  674.                                            MMGR.PAS LISTING   PAGE  12   
  675.    
  676.    
  677.                               hide;
  678.                             end;
  679.                         END;
  680.                     3 : BEGIN                         { Prev       }
  681.                           if Not DBase.Empty then
  682.                           begin
  683.                             DBase.Prev;
  684.                             CompContForm.Show;
  685.                           end
  686.                           else
  687.                             with EmptyFileMsg do
  688.                             begin
  689.                               show;
  690.                               Ch := ReadKey;
  691.                               hide;
  692.                             end;
  693.                         END;
  694.                     4 : BEGIN                         { Add company }
  695.                           PushHelp(ord(CompanyAddhelp));
  696.                           dbase.blankrecord;
  697.                           dbase.Switchto(contactdata);
  698.                           dbase.blankrecord;
  699.                           dbase.switchto(companydata);
  700.                           company.rcst.instamp := timeStamp;
  701.                           company.code := nextcode(dbase.lastcode(companysysndx),
  702.                                          sizeof(company.code)-1);
  703.                           compForm.edit;
  704.                           company.rcst.upstamp := timeStamp;
  705.                           Compform.leave;
  706.                           if YesNo(concat('Do really want to add this record to ',
  707.                                 CompanyData,'?')) Then
  708.                             dbase.add
  709.                           ELSE
  710.                             DBAse.Associate(PersonData);
  711.                           CompForm.Hide;
  712.                           CompContform.show;
  713.                           popHelp;
  714.                         END;
  715.                     5 : Finished1 := True;           { Abandon    }
  716.                   END;
  717.                 UNTIL Finished1;
  718.                 CompContForm.hide;
  719.                 Dbase.SwitchTo(CompanyData);
  720.                 DBase.SetIndex(CompanyUserNdx);
  721.                 PersonForm.Show;
  722.                 PopHelp;
  723.               end
  724.               else
  725.                 with EmptyFileMsg do
  726.                 begin
  727.                   show;
  728.                   Ch := ReadKey;
  729.                   hide;
  730.                 end;
  731.             END;
  732.          8: BEGIN
  733.    
  734.    
  735.                                            MMGR.PAS LISTING   PAGE  13   
  736.    
  737.    
  738.               if Not DBase.Empty then
  739.               begin
  740.                 DBase.NextAssoc(PersonData);
  741.                 PersonForm.Show;
  742.               end
  743.               else
  744.                 with EmptyFileMsg do
  745.                 begin
  746.                   show;
  747.                   Ch := ReadKey;
  748.                   hide;
  749.                 end;
  750.             END;
  751.          9: BEGIN
  752.               if Not DBase.Empty then
  753.               begin
  754.                 Finished1 := False;
  755.                 REPEAT
  756.                   { present menu of choices }
  757.                   Choice1 := PersonContDelMenu.pop;
  758.                   PersonContDelMenu.Hide;
  759.                   Case Choice1 of
  760.                     1 : BEGIN     { Delete this one }
  761.                           Dbase.Switchto(ContactData);
  762.                           DBase.DelRec;
  763.                           Dbase.SwitchTo(PersonData);
  764.                           Dbase.Associate(PersonData);
  765.                           PersonForm.Show;
  766.                           Finished1 := True;
  767.                         END;
  768.                     2 : BEGIN     { Get Next Relation }
  769.                           DBase.Nextassoc(PersonData);
  770.                           PersonForm.Show;
  771.                         END;
  772.                     3 : BEGIN     { Abort }
  773.                          finished1 := True;
  774.                         END;
  775.                   END;
  776.                   Personform.leave;
  777.                 UNTIL finished1;
  778.               end
  779.               else
  780.                 with EmptyFileMsg do
  781.                 begin
  782.                   show;
  783.                   Ch := ReadKey;
  784.                   hide;
  785.                 end;
  786.             END;
  787.         10: Finished := True;
  788.        END;
  789.      UNTIL Finished;
  790.      PersonForm.Hide;
  791.      DBase.ClearRelations;           { Removes set of relations loaded for }
  792.                                      { this application.                   }
  793.                                      { At this time there are no known     }
  794.    
  795.    
  796.                                            MMGR.PAS LISTING   PAGE  14   
  797.    
  798.    
  799.                                      { relations                           }
  800.      popHelp;
  801.    END;
  802.    
  803.    Procedure reports;
  804.    { Calls routines found in MMGRRPTS.PAS }
  805.    
  806.    var
  807.      choice : integer;
  808.      Finished : Boolean;
  809.    
  810.    begin
  811.      pushhelp(ord(reporthelp));
  812.      Finished := False;
  813.      Repeat
  814.        Choice := ReportMenu.Pop;
  815.        ReportMenu.Leave;
  816.        CASE Choice of
  817.          1 : MailLabels;
  818.          2 : CompanyReports;
  819.          3 : ContactReports;
  820.          4 : Finished := True;
  821.        End;
  822.      Until Finished;
  823.      ReportMenu.Hide;
  824.      pophelp;
  825.    end;
  826.    
  827.    Procedure Utilities;
  828.    var Choice : integer;
  829.        Finished : boolean;
  830.        DBSaveMsg: message;
  831.    begin
  832.      PushHelp(ord(UtilHelp));
  833.      Finished := False;
  834.      Repeat
  835.        choice := utilMenu.pop;
  836.        UtilMenu.leave;
  837.        case choice of
  838.          1 : Begin
  839.                PushHelp(ord(ColorHelp));
  840.                Set_Colors;                { ObjectInterFace - User can set }
  841.                                           { colors to any value he wants   }
  842.                PopHelp;
  843.              end;
  844.          2 : Begin
  845.                DbSaveMsg.init(
  846.                  'Saving Data and Index files to disk. Please be Patient.');
  847.                Dbsavemsg.show;
  848.                DBase.Save;
  849.                dbsavemsg.done;
  850.              end;
  851.          3 : finished := true;
  852.        end
  853.      Until finished;
  854.      UtilMenu.hide;
  855.    
  856.    
  857.                                            MMGR.PAS LISTING   PAGE  15   
  858.    
  859.    
  860.      PopHelp;
  861.    end;
  862.    
  863.    {$F+}
  864.    PROCEDURE MyExitProc;
  865.    { This is done to insure that the data files are closed should a }
  866.    { problem occur and program is prematurly terminated.            }
  867.    BEGIN      { MyExitProc }
  868.      ExitProc := SysExit;
  869.      dbclosemsg.show;
  870.      DBase.Close;
  871.      dbclosemsg.hide;
  872.      textmode(OldMode);
  873.      DBase.Done;
  874.    END;       { MyExitProc }
  875.    {$F-}
  876.    
  877.    BEGIN  { Main }
  878.    { Set up for Exit Code }
  879.      SysExit := ExitProc;
  880.      ExitProc:= @MyExitProc;
  881.    { Save current video mode }
  882.      OldMode := LastMode;
  883.    
  884.      InitHelp(HelpFileName);  { Part of the ObjectInterFace }
  885.      PushHelp(Ord(OverView));
  886.      InitMsgs;
  887.      Introduction;
  888.      dbloadMsg.show;  { Message object method (ObjectInterFace) - displays }
  889.                       { Text passed when object was initialized.           }
  890.      dbloadmsg.leave; { Message Object method (ObjectInterFace) - DeActivates }
  891.                       { the Message window but leaves it visible. (Lets    }
  892.                       { program address other portions of the screen.)     }
  893.      Initdb(DBase);   { Loads Data and Index Files into Dbase, opens files,}
  894.                       { and sets record variables to first alphabetic record}
  895.      InitMenus;       { Defines the Menus used in program MMGRVARS.PAS      }
  896.      InitForms;       { Defines the Forms used in program MMGRVARS.PAS      }
  897.      dbloadmsg.hide;  { Message object method (ObjectInterFace) - Restores  }
  898.                       { Screen to state previous to show call.              }
  899.      Finished := False;
  900.      REPEAT
  901.        Pushhelp(Ord(MMhelp));{ Sets helpdata to MainMenu date(ObjectInterFace)}
  902.        choice := MainMenu.pop;{ Shows and returns user selection from MainMenu}
  903.                               { Menu Object(ObjectInterface)                  }
  904.        mainmenu.hide;         { Removes Menu from screen.                     }
  905.        case choice of
  906.          1 : CompanyMaint;
  907.          2 : PersonMaint;
  908.          3 : Reports;
  909.          4 : Utilities;
  910.          5 : Finished := YesNo('Do you really want to leave program?');
  911.        END;
  912.      UNTIL Finished;
  913.      PopHelp;
  914.    { Remember exit code will execute at this time or any time the program is }
  915.    { terminated.                                                             }
  916.    
  917.    
  918.                                            MMGR.PAS LISTING   PAGE  16   
  919.    
  920.    
  921.    END.   { program }
  922.    
  923.