home *** CD-ROM | disk | FTP | other *** search
- Program FETCH32; { ljr, 07/23/89, }
-
- { (DPMAX) Tech Support Systems LAN INFO TO MEMO GRABBER }
- { the maintainance program with all kinds of locking going on }
-
- {$M 32768,13100,65530}
-
- USES CRT, MAXVAR, MAXUTIL, MAXKBRD, MAXDBF, MAXLOCK;
-
- { used db3 compatable tpu package from: }
- { Max Software Consultants Inc }
- { 4101 Greenmount Ave. }
- { Baltimore, Maryland 21218 }
- { 301-323-5996 }
-
- const
- NormalVideo = $07;
- ReverseVideo = $70;
- ScrnSize = 79;
- type
- BuffType = array [1..61] of char;
- String12 = string[12];
- Var
- Menu : char;
- Dbf : dFile;
- F : string12;
- FileName : string12;
- Key_1 : string12;
- Key_2 : string12;
- Key_3 : string12;
- Key_4 : string12;
- Buffer1 : BuffType; { first get }
- Buffer2 : BuffType; { working got }
- Buffer3 : BuffType; { re-get before put }
- StrBuf : array[1..5] of String12;
- FldName : array[1..5] of Str10;
- RecNum : RecNr;
- Status : integer;
- Chr1 : char; { in CharAdd }
- Sel : boolean;
- SearchFld : integer;
- Format : integer;
- LSTDEV : Text;
- DeviceName : String12;
- OutBuf : String[80];
- Abort : boolean;
- ReReadOk : boolean;
-
- Procedure Scrn;
- begin
- ClrScr;
- TextAttr := (ReverseVideo);
- GoToXY(11,1);
- WriteLn( ' TEXT FILE ''FETCH'' ( DATABASE MAINTAINANCE PROGRAM ) ');
- TextAttr := (NormalVideo);
- end;
-
- Procedure ReadIn(Var S: String12);
- var
- PosE,PosS,PosC: integer;
- OverWrite : boolean;
-
- Procedure ChrRgt;
- begin
- If PosE < PosC then PosE := PosE + 1 ;
- GoToXY(dp_Abs2X(PosS+PosE,ScrnSize),dp_Abs2Y(PosS+PosE,ScrnSize));
- end;
-
- Procedure ChrLft;
- begin
- If PosE > 0 then PosE := PosE - 1 ;
- GoToXY(dp_Abs2X(PosS+PosE,ScrnSize),dp_Abs2Y(PosS+PosE,ScrnSize));
- end;
-
- Procedure BackSpace; { Procedure local to ReadIn }
- begin
- If PosE > 0 then
- begin
- GoToXY(dp_Abs2X(PosS+PosE-1,ScrnSize),dp_Abs2Y(PosS+PosE-1,ScrnSize));
- Write(Copy(S, PosE + 1, PosC - PosE)+' ');
- S := Copy(S,1,PosE-1)+Copy(S,PosE+1,PosC-PosE);
- PosE := PosE - 1;
- PosC := PosC - 1;
- GoToXY(dp_Abs2X(PosS+PosE,ScrnSize),dp_Abs2Y(PosS+PosE,ScrnSize));
- end;
- end;
-
- Procedure ChrAdd; { Procedure local to ReadIn }
- begin
- If Not OverWrite then
- { Insert Characters Mode }
- begin
- if PosC < 12 then
- begin
- GoToXY(dp_Abs2X(PosS+PosE,ScrnSize),dp_Abs2Y(PosS+PosE,ScrnSize));
- Write(Chr1,Copy(S,PosE+1,PosC-PosE));
- S := Copy(S,1,PosE)+Chr1+Copy(S,PosE+1,PosC-PosE);
- PosC := PosC + 1;
- PosE := PosE + 1;
- GoToXY(dp_Abs2X(PosS+PosE,ScrnSize),dp_Abs2Y(PosS+PosE,ScrnSize));
- end
- end
- else
- { Overwrite Characters Mode }
- begin
- if PosC < 12 then
- begin
- GoToXY(dp_Abs2X(PosS+PosE,ScrnSize),dp_Abs2Y(PosS+PosE,ScrnSize));
- Write(Chr1,Copy(S,PosE+2,PosC-PosE-1));
- S := Copy(S,1,PosE)+Chr1+Copy(S,PosE+2,PosC-PosE-1);
- If (PosE = PosC) then PosC := PosC + 1;
- PosE := PosE + 1;
- GoToXY(dp_Abs2X(PosS+PosE,ScrnSize),dp_Abs2Y(PosS+PosE,ScrnSize));
- end;
- end;
- end;
-
- Procedure ChrDel; { Procedure local to ReadIn }
- begin
- if PosE < PosC Then
- begin
- GoToXY(dp_Abs2X(PosS+PosE,ScrnSize),dp_Abs2Y(PosS+PosE,ScrnSize));
- Write(Copy(S,PosE+2,PosC-PosE-1),' ');
- S := Copy(S, 1, PosE) + Copy(S, PosE + 2, PosC - PosE-1);
- PosC := PosC - 1;
- GoToXY(dp_Abs2X(PosS+PosE,ScrnSize),dp_Abs2Y(PosS+PosE,ScrnSize));
- end;
- end;
-
- Procedure OverWriteChar;
- begin
- OverWrite := NOT Overwrite;
- end;
-
- begin
- S := dp_Trim(S);
- PosS := dp_XY2Abs(WhereX,WhereY,ScrnSize);
- PosC := Length(S);
- PosE := PosC;
- Write(S);
- gotoXY (dp_Abs2X(PosC+PosS,ScrnSize),dp_Abs2Y(PosC+PosS,ScrnSize));
- OverWrite := TRUE;
- Abort := TRUE;
- Repeat
- Repeat Until dp_kbrd (Chr1);
- if chr1 = #27 then
- begin
- WriteLn;
- exit;
- end;
- Case Chr1 of
- #8 : if (Length(S)>0) then BackSpace; { Backspace}
- #203 : ChrLft; { Left Arrow}
- #205 : ChrRgt; { Rght Arrow}
- #211 : ChrDel; { Delete Chr1}
- #210 : OverWriteChar; { Insert Chr1}
- else if Chr1 <> #13 then ChrAdd;
- end;
- until Chr1 = #13;
- WriteLn;
- Abort := FALSE;
- end;
-
- Procedure Menu1;
- begin
- GoToXY (22,5); Write ('Select Function:');
- GoToXY (25,8); Write ('(1) E N T E R');
- GoToXY (25,10); Write ('(2) E D I T');
- GoToXY (25,12); Write ('(3) R E M O V E');
- GoToXY (25,14); Write ('(4) P R I N T');
- GoToXY (25,16); Write ('(5) E X I T');
-
- TextAttr := (ReverseVideo);
- GoToXY (29,8); Write ('E');
- GoToXY (31,10); Write ('D');
- GoToXY (29,12); Write ('R');
- GoToXY (29,14); Write ('P');
- GoToXY (31,16); Write ('X');
- TextAttr := (NormalVideo);
- Sel := FALSE;
- Repeat
- GoToXY (29,20);
- Repeat Until dp_kbrd (Chr1);
- if Chr1 IN ['1','2','3','4','5','e','E','d','D','r','R','p','P','x','X'] then sel := TRUE;
- Until Sel;
- menu := chr1;
- { Menu := ORD(Chr1) - 48; }
- WriteLn(Menu);
- end;
-
- Procedure Extract;
- begin
- FileName := strbuf[1];
- Key_1 := strbuf[2];
- Key_2 := strbuf[3];
- Key_3 := strbuf[4];
- Key_4 := strbuf[5];
- end;
-
- Procedure FldNm;
- begin
- FldName[1] := 'FILENAME';
- FldName[2] := 'KEY_1';
- FldName[3] := 'KEY_2';
- FldName[4] := 'KEY_3';
- FldName[5] := 'KEY_4';
- end;
-
- Procedure ClrStrBuf;
- var
- i : integer;
- begin
- For i := 1 to 5 do StrBuf[i] := '';
- end;
-
- Procedure ClrVar;
- begin
- FileName[0] := #0;
- Key_1[0] := #0;
- Key_2[0] := #0;
- Key_3[0] := #0;
- Key_4[0] := #0;
- end;
-
- Procedure OpenFiles;
- var
- i : integer;
- begin
- Scrn;
- GoToXY (25,5);
- Write (' Please Wait - Opening Files ');
- F := 'FETCH.DBF';
- Result := dp_OpenDBF(F,dplShared,Dbf);
- if Result <> Success then
- begin
- GoToXY (25,12); Write( #07,' ERROR WITH FILE ',F,'.');
- GoToXY (34,14); Write( ' Error #',Result:3,'.');
- GoToXY (30,16); Write( ' Program terminating.');
- Halt;
- end;
- end;
-
- Procedure CloseFiles;
- var
- i : integer;
- begin
- Scrn;
- GoToXY (25,5);
- Write (' Please Wait - Closing Files ');
- Result := dp_CloseDBF(Dbf);
- if Result <> Success then
- begin
- GoToXY (25,12); Write( #07,' ERROR WITH FILE ',F,'.');
- GoToXY (34,14); Write( ' Error #',Result:3,'.');
- Delay(3000);
- end;
- end;
-
- Procedure PutValues; { use buffer #2 }
- var
- X : Char;
- i : integer;
- begin
- FillChar (Buffer2,Sizeof(Buffer2),#32);
- For i := 1 to 5 do
- begin
- Result := dp_PutValue(Dbf,FldName[i],X,Buffer2,StrBuf[i]);
- if Result <> Success then
- begin
- GoToXY (25,12); Write( #07,' ERROR WITH FILE ',F,'.');
- GoToXY (34,14); Write( ' Error #',Result:3,'.');
- GoToXY (26,16); Write( 'Values Not Put into Buffer !');
- GoToXY (28,18); Write( 'Field Name: ',FldName[i]:10,'.');
- Delay(3000);
- end;
- end;
- end;
-
- Procedure GetValues; { use buffer #2 }
- var
- X : Char;
- i : integer;
- begin
- For i := 1 to 5 do
- begin
- Result := dp_Value(Dbf,FldName[i],X,Buffer2,StrBuf[i]);
- if Result <> Success then
- begin
- GoToXY (25,12); Write( #07,' ERROR WITH FILE ',F,'.');
- GoToXY (34,14); Write( ' Error #',Result:3,'.');
- GoToXY (26,16); Write( 'Values Not Put into Buffer !');
- GoToXY (28,18); Write( 'Field Name: ',FldName[i]:10,'.');
- Delay(3000);
- end;
- end;
- end;
-
- Procedure ReadRecord; { use buffer #1 }
- begin
- Abort := TRUE;
- Result := dp_LockRec(Dbf,RecNum,1,0); { lock wait }
- if Result = Success then
- Result := dp_GetRec(Dbf,RecNum,Buffer1,Status); { get }
- Result := dp_LockRec(Dbf,RecNum,1,2); { unlock }
- if Result <> Success then
- begin
- GoToXY (25,12); Write( #07,' ERROR WITH FILE ',F,'.');
- GoToXY (34,14); Write( ' Error #',Result:3,'.');
- GoToXY (26,16); Write( ' - Can`t Get Record! ');
- Delay(3000);
- end;
- if Status <> Active then exit;
- Buffer2 := Buffer1; { **** pass the salt, please }
- GetValues;
- Abort := FALSE;
- end;
-
- Procedure ReReadRecord; { use buffer #3 }
- begin
- Abort := TRUE;
- Result := dp_LockRec(Dbf,RecNum,1,0); { lock wait }
- if Result = Success then
- Result := dp_GetRec(Dbf,RecNum,Buffer3,Status); { get }
- Result := dp_LockRec(Dbf,RecNum,1,2); { unlock }
-
- if Buffer3 <> Buffer1 then ReReadOk := false; { the BIG test! }
- if Result <> Success then
- begin
- GoToXY (25,12); Write( #07,' ERROR WITH FILE ',F,'.');
- GoToXY (34,14); Write( ' Error #',Result:3,'.');
- GoToXY (26,16); Write( ' - Can`t Re-Get Record! ');
- Delay(3000);
- end;
- if Status <> Active then exit;
- Abort := FALSE;
- end;
-
- Procedure AppendRecord;
- begin
- Result := dp_LockRec(Dbf,RecNum,1,0); { lock wait }
- if Result = Success then
- Result := dp_PutRec(Dbf,Append,Buffer2); { put }
- Result := dp_LockRec(Dbf,RecNum,1,2); { unlock }
- RecNum := Dbf^.hdr.RecCnt;
- if Result <> Success then
- begin
- GoToXY (25,12); Write( #07,' ERROR WITH FILE ',F,'.');
- GoToXY (34,14); Write( ' Error #',Result:3,'.');
- GoToXY (26,16); Write( 'Values Not Put into DBF !');
- Delay(3000);
- end;
- end;
-
- Procedure ReSaveRecord;
- begin
- { first test the original buf ( got a while back ) with the buf right now }
- { if they are the same, write it out. if they are different, tell the user }
- { that his rec was changed by someone else. }
- ReReadOk := true;
- ReReadRecord;
- if ReReadOk = true then
- begin
- Result := dp_LockRec(Dbf,RecNum,1,0); { lock wait }
- if Result = Success then
- Result := dp_UpDr(Dbf,RecNum,Buffer2); { re-save }
- Result := dp_LockRec(Dbf,RecNum,1,2); { unlock }
- if Result <> Success then
- begin
- GoToXY (25,12); Write( #07,' ERROR WITH FILE ',F,'.');
- GoToXY (34,14); Write( ' Error #',Result:3,'.');
- GoToXY (26,16); Write( 'Values Not Put into DBF!');
- Delay(3000);
- end;
- end
- else
- begin
- GoToXY (25,12); Write( #07,' ERROR WITH FILE ',F,'.');
- GoToXY (26,14); Write( 'Values Not Put into DBF !');
- GoToXY (26,16); Write( 'Someone changed your Record !');
- Delay(3500);
- end;
- end;
-
- procedure Mini_wipe;
- begin
- GoToXY(1,5);
- Writeln(' '); {5}
- Writeln(' '); {6}
- Writeln(' '); {7}
- Writeln(' '); {8}
- Writeln(' '); {9}
- Writeln(' '); {10}
- Writeln(' '); {11}
- Writeln(' '); {12}
- Writeln(' '); {13}
- Writeln(' '); {14}
- Writeln(' '); {15}
- Writeln(' '); {16}
- Writeln(' '); {17}
- GoToXY(1,5);
- end;
-
- Procedure Enter;
- var
- i : integer;
- done : boolean;
- begin
- Abort := TRUE;
- done := false;
- Scrn;
- GoToXY(1,25);
- Write(' To exit press the <ESC> key...');
- GoToXY(1,3);
- WriteLn( 'ENTER FUNCTION ');
- WriteLn;
- { ??? }
- repeat
- WriteLn( 'Current Record Count is ',Dbf^.hdr.RecCnt,'.');
- WriteLn;
- ClrStrBuf;
- For i := 1 to 5 do
- begin
- Write(FldName[i],'? ');
- ReadIn(StrBuf[i]);
- if Abort then exit;
- end;
- PutValues;
- if Result = Success then AppendRecord; { of the put action }
- if Result = Success then { of the append action }
- begin
- WriteLn;
- WriteLn(' Success, Record Count is now ',Dbf^.hdr.RecCnt,'.');
- Delay(500);
- end;
- Writeln;
- Write(' Add another at this time? ');
- Repeat Until dp_kbrd (Chr1);
- WriteLn(Chr1);
- if not (Chr1 IN [ 'Y','y']) then done := true;
- if (Chr1 IN [ 'Y','y']) then mini_wipe;
-
- until done;
- Abort := FALSE;
- end;
-
- Procedure Edit;
- var
- i : integer;
- Temp : string12;
- begin
- Abort := TRUE;
- Scrn;
- GoToXY(1,25);
- Write(' To exit press the <ESC> key...');
- GoToXY(1,3);
- WriteLn( 'EDIT FUNCTION ');
- WriteLn;
- Temp := '';
- repeat
- GoToXY(1,5);
- Write( 'Type Record Number to edit: ');
- ReadIn(Temp);
- if Abort then exit;
- Val (Temp,RecNum,i);
- if (Recnum < 1) or (RecNum > Dbf^.hdr.RecCnt) then
- begin
- Write('Record Number out of range.');
- i := 1;
- end;
- Until i = 0;
- WriteLn;
- ReadRecord;
- if Abort then exit;
- For i := 1 to 5 do
- begin
- WriteLn(FldName[i]+': ':12,StrBuf[i]);
- Write('New ? ':12);
- Temp := StrBuf[i];
- ReadIn(Temp);
- if Abort then exit;
- StrBuf[i] := Temp
- end;
- PutValues;
- ResaveRecord;
-
- while not ReReadOk do { do it over till okay }
- begin
- ReadRecord;
- if Abort then exit;
- GoToXY(1,7);
- For i := 1 to 5 do
- begin
- WriteLn(FldName[i]+': ':12,StrBuf[i]);
- Write('New ? ':12);
- Temp := StrBuf[i];
- ReadIn(Temp);
- if Abort then exit;
- StrBuf[i] := Temp
- end;
- PutValues;
- if Result = Success then ResaveRecord;
- end;
- if ReReadOk then
- begin
- WriteLn;
- WriteLn(' Success! Record edit saved.');
- Delay(2000);
- end;
- Abort := FALSE;
- end;
-
- Procedure Remove;
- var
- Temp : string12;
- i : integer;
- LongInteger, Max : LongInt;
- begin
- Scrn;
- GoToXY(1,25);
- Write(' To exit press the <ESC> key...');
- GoToXY(1,3);
- WriteLn( 'REMOVAL FUNCTION ');
- WriteLn;
- Temp := '';
- repeat
- GoToXY(1,5);
- Write( 'Type Record Number to remove: ');
- ReadIn(Temp);
- if Abort then exit;
- Val (Temp,RecNum,i);
- if (Recnum < 1) or (RecNum > Dbf^.hdr.RecCnt) then
- begin
- Write('Record Number out of range.');
- i := 1;
- end;
- Until i = 0;
- WriteLn;
- ReadRecord;
- if Abort then exit;
- For i := 1 to 5 do WriteLn(FldName[i]+': ':12,StrBuf[i]);
- WriteLn;
- Write('Remove this record, are you sure? ');
- Repeat Until dp_kbrd (Chr1);
- WriteLn(Chr1);
- if not (Chr1 IN [ 'Y','y']) then exit;
- WriteLn(' Deletion in progress. ');
-
- { mark it for deletion }
- Result := dp_delrec ( Dbf,RecNum );
- if Result <> Success then
- begin
- GoToXY (25,18); Write( #07,' ERROR WITH FILE ',F,'.');
- GoToXY (34,20); Write( ' Error #',Result:3,'.');
- GoToXY (26,22); Write( 'Record not marked for removal !');
- Delay(3000);
- end;
-
- if Result = Success then { walk through the db and PACK it }
- begin
- Max := Dbf^.hdr.RecCnt;
- LongInteger := 1;
- while (LongInteger <= Max) do
- begin
- RecNum := LongInteger; { convert type }
- Result := dp_LockRec(Dbf,RecNum,1,0); { lock it }
- if Result = Success then
- Result := dp_GetRec(Dbf,RecNum,Buffer1,Status); { get it }
- Result := dp_LockRec(Dbf,RecNum,1,2); { unlock it }
- if (Result = Success) and (Status = Inactive) then
- begin
- Result := dp_LockRec(Dbf,RecNum,1,0); { lock again }
- if Result = Success then
- Result := dp_rmvrec ( Dbf,RecNum ); { remove! }
- Result := dp_LockRec(Dbf,RecNum,1,2); { unlock again }
- if ( Result = Success ) then
- LongInteger := LongInteger - 1
- else
- begin
- GoToXY (25,18); Write( #07,' ERROR WITH FILE ',F,'.');
- GoToXY (34,20); Write( ' Error #',Result:3,'.');
- GoToXY (26,22); Write( 'Record not removed !');
- Delay(3000);
- end;
- end;
- LongInteger := LongInteger + 1;
- end;
- end;
- if Result = Success then
- begin
- WriteLn;
- WriteLn(' Success! Record marked, removed, repacked.');
- Delay(2000);
- end;
- end;
-
- Procedure PrintMaster;
- begin
- OutBuf := '';
- OutBuf := FileName + ' ' + Key_1 + ' ' + Key_2 + ' ' + Key_3 + ' ' + Key_4;
- Writeln(LSTDEV,OutBuf);
- end;
-
- Procedure PrintRecords;
- var
- i : integer;
- begin
- RecNum := 1;
- WriteLn(LSTDEV,'Total Available Records are ',Dbf^.hdr.RecCnt,'.');
- WriteLn(LSTDEV,'═════════════════════════════════════════════════════════════════════');
- For i := 1 to Dbf^.hdr.RecCnt do
- begin
- ReadRecord;
- GetValues;
- Extract;
- PrintMaster;
- RecNum := RecNum + 1;
- end;
- if (DeviceName = 'CON') or (DeviceName = 'con') then
- begin
- Write(LSTDEV,'Press any key to continue...');
- repeat until keypressed;
- end;
- end;
-
- Procedure SelectDevice;
- begin
- Abort := TRUE;
- Sel := FALSE;
- DeviceName := 'PRN';
- Repeat
- GoToXY(1,3);
- WriteLn ( 'Select Output Device');
- GoToXY(1,10);
- WriteLn ( '["CON" is okay, a File are okay also, however, it will be overwritten.]');
- Write ( 'Device Name: ');
- ReadIn ( DeviceName );
- if Abort then exit;
- {$I-} Assign (LSTDEV,DeviceName); {$I+}
- Result := IOResult;
- if Result = Success then
- begin
- {$I-} ReWrite (LSTDEV); {$I+}
- Result := IOResult;
- end;
- if Result = Success then Sel := TRUE;
- Until Sel;
- Abort := FALSE;
- end;
-
- Procedure Print;
- begin
- Abort := TRUE;
- Scrn;
- GoToXY(1,25);
- Write(' To exit press the <ESC> key...');
- GoToXY(1,3);
- WriteLn( 'PRINT FUNCTION ');
- SelectDevice;
- if Abort then Exit;
- PrintRecords;
- Abort := FALSE;
- end;
-
- { M A I N }
- begin
- directvideo := false;
- TextAttr := (NormalVideo);
- FileMode := $42; { LAN sharing mode, full access permitted }
- { see Dos Tech Ref, INT 21, funct 3D, file open }
- OpenFiles;
- FldNm;
- ClrStrBuf;
- ClrVar;
- Repeat
- Scrn;
- Menu1;
- Case Menu of
- '1','E','e' : Enter;
- '2','D','d' : Edit;
- '3','R','r' : Remove;
- '4','P','p' : Print;
- end;
- Until ((Menu = '5') or (Menu = 'X') or (Menu = 'x'));
- CloseFiles;
- ClrScr;
- end.