     {$I Equates.pas}
     {$I Allcaps.pas}
     {$I Exist.pas}
     {$I Cursor.pas}
     {$I Video.pas}
     {$I Status.pas}
     {$I Menu.pas}
     {$I Getinstr.pas}
     {$I Getyesno.pas}
     {$I Erase.pas}
     {$I Date.pas}
     {$C-}
     const
          Changed  : Boolean = False;
          DiskFull : Boolean = False;
          Finished : Boolean = False;
          Init     : Boolean = False;
          MaxLine1 = 8;
          MaxLine2 = 6;
          Lines1   : Array[0..MaxLine1] of String[40] =
                     ('* What Do You Want To Do *',
                      ' First Name (Search) ',
                      ' Last Name (Search)',
                      ' City (Search)',
                      ' State (Search)',
                      ' Topic (Search)',
                      ' Generate Labels',
                      ' Enter New Member',
                      ' Quit: Go to CP/M');
          Lines2   : Array[0..Maxline2] of String[40] =
                     ('* Print Labels For *',
                      ' Test Label',
                      ' All Members',
                      ' Paid Members',
                      ' Expired Members ',
                      ' Non - Members',
                      ' Go To Main Menu');
     type
          Entry = record
               First_Name     : String[20];
               Last_Name      : String[20];
               Address1       : String[30];
               Address2       : String[30];
               City           : String[15];
               State          : String[2];
               Zip_Code       : String[10];
               Home_Phone     : String[17];
               Business_Phone : String[17];
               Occupation     : String[30];
               Computer1      : String[15];
               Computer2      : String[15];
               Topics         : String[30];
               MemberID       : String[20];
               Joined_Date    : String[8];
               Exp_Date       : String[8];
               Extra          : String[30];
          end;
     var
          Reply                     : Char;
          Choice                    : Integer;
          DataFile                  : File of Entry;
          Individual                : Entry;
          Search_For                : String[30];
          Today                     : Integer;
          DTAFile                   : String[12];
          InFile                    : String[8];

     {$I Modem.lib}
     {$I Dial.pas}
     {$I Print.pas}
     {$I Entrname.pas}

     procedure Open_File (FileName : Str20);
          begin
               BDOS(13);
               assign(DataFile,FileName);
               if not Exist(FileName) then
               begin
                    Draw_Status_Border;
                    Write_Status('**   CANNOT FIND DATA FILE   **');
                    Close(Datafile);
                    halt;
               end;
               reset(DataFile)
          end;

     {$I Chngname.pas}

     procedure Search_Names (Search_Type : Str80; Len : Integer);
          label Rewrite,Option;
          var
               I,J            : Integer;
               Ch             : Char;
               Search_Key     : String[30];
          begin
               ClrScr;
               Get_InStr(4,12,'Enter '+Search_Type+' : ',Len);
               Search_Key := InStr;
               Open_File (DTAFile);
               with Individual do
               begin
                    I := 0; ClrScr; LowVideo;
                    GotoXY(3,1);
                    write('          FULL NAME :');
                    GotoXY(3,2);
                    write('          ADDRESS 1 :');
                    GotoXY(3,3);
                    write('          ADDRESS 2 :');
                    GotoXY(3,4);
                    write('  CITY, STATE & ZIP :');
                    GotoXY(3,6);
                    write('    AREA/HOME PHONE :');
                    GotoXY(3,7);
                    write('AREA/BUSINESS PHONE :');
                    GotoXY(3,9);
                    write('         OCCUPATION :');
                    GotoXY(3,11);
                    write('    MEMBERSHIP I.D. :');
                    GotoXY(3,13);
                    write('   PRIMARY COMPUTER :');
                    GotoXY(3,14);
                    write(' SECONDARY COMPUTER :');
                    GotoXY(3,16);
                    write('   KNOWLEDGEABLE IN :');
                    GotoXY(3,18);
                    write('      MEMBER JOINED :');
                    GotoXY(3,19);
                    write(' MEMBERSHIP EXPIRES :');
                    NormVideo;
                    Draw_Status_Border;
                    Write_Status('Searching ...');
                    while not EOF(DataFile) do
                    begin
                         seek(DataFile,I); read(DataFile,Individual);
                         case Choice of
                              1 : Search_For := First_Name;
                              2 : Search_For := Last_Name;
                              3 : Search_For := City;
                              4 : Search_For := State;
                              5 : Search_For := Topics;
                         end;
                         if ((Choice = 5) and (Pos(AllCaps(Search_Key),AllCaps(Search_For)) > 0)) or
                            ((Choice in [1..4]) and (AllCaps(Copy(Search_For,1,length(Search_Key))) =
                            AllCaps(Search_Key))) then
                         begin
Rewrite:                      GotoXY(1,21); ClrEol;
                              GotoXY(25,1); ClrEol;
                              write(Last_Name + ', ' + First_Name);
                              GotoXY(25,2); ClrEol;
                              write(Address1);
                              GotoXY(25,3); ClrEol;
                              write(Address2);
                              GotoXY(25,4); ClrEol;
                              write(City + ', ' + State + '  ' + Zip_Code);
                              GotoXY(25,6); ClrEol;
                              write(Home_Phone);
                              GotoXY(25,7); ClrEol;
                              write(Business_Phone);
                              GotoXY(25,9); ClrEol;
                              write(Occupation);
                              GotoXY(25,11); ClrEol;
                              write(MemberID);
                              GotoXY(25,13); ClrEol;
                              write(Computer1);
                              GotoXY(25,14); ClrEol;
                              write(Computer2);
                              GotoXY(25,16); ClrEol;
                              write(Topics);
                              GotoXY(25,18); ClrEol;
                              write(Joined_Date);
                              GotoXY(25,19); ClrEol;
                              write(Exp_Date);
Option:                       Write_Status('{C}hange  {D}ial  {P}rint  {Q}uit  {ANY KEY} to CONTINUE');
                              read(Kbd,Ch);
                              case Ch of
                                   'D','d' : begin
                                                  Dial_Number;
                                                  Goto Option
                                             end;
                                   'P','p' : begin
                                                  Print_Name;
                                                  Goto Option
                                             end;
                                   'Q','q' : Exit;
                                   'C','c' : begin
                                                  Change_Names;
                                                  if Changed then
                                                  begin
                                                       Seek(DataFile,I);
                                                       Write(DataFile,Individual);
                                                       Changed := False;
                                                  end;
                                                  Goto Rewrite;
                                             end;
                              end;
                         end;
                         I := I + 1;
                    end;
                    Close(DataFile);
               end;
          end;

     procedure Generate_Labels;
          var
               I              : Integer;
          begin
               ClrScr; Get_Date(4,12,'Enter Today''s Date : ');
               Today := Int_Date (Date);
               repeat
                    Choice := Menu(MaxLine2,Lines2);
                    If Choice = 1 then Print_Test_Label;
                    If Choice = 6 then Exit;
                    Open_File (DTAFile);
                    with Individual do
                    begin
                         Write_Status('Printing . . .');
                         I := 0;
                         while not EOF(DataFile) and not KeyPressed do
                         begin
                              seek(DataFile,I); read(DataFile,Individual);
                              if (Choice = 2) then
                                   Print_Label
                              else if (Choice = 3) and (Int_Date (Exp_Date) >= Today) and (Exp_Date <> '') then
                                   Print_Label
                              else if (Choice = 4) and (Int_Date (Exp_Date) < Today) then
                                   Print_Label
                              else if (Choice = 5) and (Exp_Date = '') then
                                   Print_Label;
                              I := I + 1;
                         end
                    end;
               until Choice = 6
          end;

{ ************************************************************************
  *                                                                      *
  *                        MAIN PROGRAM                                  *
  *                                                                      *
  ************************************************************************ }

     {$I Sign-off.pas}

     begin
          If ParamCount = 0 then
               begin
                    writeln(BEL,'+++ ERROR +++');
                    writeln('Command Syntax : MEMBER <Datafile name>');
                    Halt
               end
          else
               begin
                    InFile := ParamStr(1);
                    DTAFile := InFile + '.DTA'
               end;
          Repeat
               Choice := Menu(MaxLine1,Lines1);
               Case Choice of
                    1 : Search_Names('First Name',20);
                    2 : Search_Names('Last Name',20);
                    3 : Search_Names('City',15);
                    4 : Search_Names('Two Letter State Code',2);
                    5 : Search_Names('Area of Expertise',30);
                    6 : Generate_Labels;
                    7 : Enter_Names;
                    8 : begin
                             ClrScr;
                             Get_YesNo (1,10,'Exit to CP/M (Y/N) ');
                             If YesNo in ['Y','y'] then Sign_Off;
                        end
               end
          Until Finished;
          Cursor_On;
     end.
