home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.wwiv.com
/
ftp.wwiv.com.zip
/
ftp.wwiv.com
/
pub
/
MISC
/
TGARTS.ZIP
/
SAMPLE.ZIP
/
TGUSER.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1998-12-19
|
8KB
|
199 lines
Program Tguser;
Uses Crt;
{$I Telegard.inc}
Var User_File : File of userrec;
User_Record : Userrec;
Total_Users : Integer;
Male, Female : Integer;
RecN : Integer; (* Reocrd # *)
Stop_Now : Boolean;
Procedure Read_Totals;
Begin
{This procedure is used twice so made it one procedure}
Assign(User_file,'users.dat');
Reset(User_file);
Total_Users := 0; {Total users on your bbs set to 0}
Male := 0; Female := 0;
While not eof(User_File) do
Begin
Read(User_File,User_record);
Inc(Total_Users); (* add 1 to total users *)
IF User_record.gender = 'M' then Inc(Male) else Inc(Female);
end;
Close(User_file);
end;
Procedure User_Summary;
Var MPercent, FPercent : Real;
MString, Fstring : String;
Begin
ClrScr;GotoXY(10,10);Textcolor(14);
Read_Totals;
Mstring := ''; Fstring :='';
Writeln('Users Summary');
MPercent := (Male / Total_users)*100;
FPercent := (Female / Total_users)*100;
Textcolor(11); Write('Total number of Users :');
Textcolor(15); Writeln(Total_Users);
Textcolor(11); Write(' Total Male Users :');
Textcolor(15); Write(Male);Write(' ');Textcolor(14);
Write(mpercent:0:2); (* This is a special way of doing things ! *)
Textcolor(10); Writeln('% of total users');
Textcolor(11); Write(' Total Female Users :');
Textcolor(15); Write(Female); Write(' ');Textcolor(14);
Write(fpercent:0:2); (* This is a special way of doing things ! *)
Textcolor(10); Writeln('% of total users');
Textcolor(12); Writeln('Press any key to continue...');
Repeat until Keypressed;
end;
Procedure Edit_Data;
Var Loop : Byte;
Key2: Char;
EndNow : Boolean;
Label 1;
Begin
{Labels and gotos are bad but for this demo they work :)}
EndNow := False;
1: (* Labels are highly bad coding but just this once :) Gotos eek *)
Textcolor(9);
For Loop := 1 to 4 do Begin Gotoxy(1,13+loop);Write(chr(64+loop)+'.'); end;
For Loop := 1 to 4 do Begin Gotoxy(33,13+loop);Write(chr(68+loop)+'.'); end;
Gotoxy(4,19);Textcolor(14);
Writeln('Enter A-H to toggle the flag on or off for this user, Q to end edit mode');
Repeat
Key2 := Readkey;Key2 := Upcase(Key2);
Until (Keypressed) or (Key2>='A') and (Key2<='H') or (key2='Q');
Case Key2 of
'A' : IF lockedout in user_record.status then
Exclude(user_record.status,lockedout) else Include(user_record.status,lockedout);
'B' : IF trapactivity in user_record.status then
Exclude(user_record.status,trapactivity) else Include(user_record.status,trapactivity);
'C' : IF chatauto in user_record.status then
Exclude(user_record.status,chatauto) else Include(user_record.status,chatauto);
'D' : IF slogseparate in user_record.status then
Exclude(user_record.status,slogseparate) else Include(user_record.status,slogseparate);
'E' : IF udeleted in user_record.status then
Exclude(user_record.status,udeleted) else Include(user_record.status,udeleted);
'F' : IF trapseparate in user_record.status then
Exclude(user_record.status,trapseparate) else Include(user_record.status,trapseparate);
'G' : IF chatseparate in user_record.status then
Exclude(user_record.status,chatseparate) else Include(user_record.status,chatseparate);
'H' : IF alert in user_record.status then
Exclude(user_record.status,alert) else Include(user_record.status,alert);
'Q' : EndNow := True;
end;
{see Include/Exclude functions in pascal help to see what they do}
If lockedout In user_record.status then begin Gotoxy(5,14); Write('X'); end else begin Gotoxy(5,14); Write(' '); end;
If udeleted In user_record.status then begin Gotoxy(37,14);Write('X'); end;
If trapactivity In user_record.status then begin Gotoxy(5,15); Write('X'); end;
If trapseparate In user_record.status then begin Gotoxy(37,15);Write('X'); end;
If chatauto In user_record.status then begin Gotoxy(5,16); Write('X'); end;
If chatseparate In user_record.status then begin Gotoxy(37,16);Write('X'); end;
If slogseparate In user_record.status then begin Gotoxy(5,17); Write('X'); end;
If alert In user_record.status then begin Gotoxy(37,17);Write('X'); end;
If EndNow = false then goto 1;
{You use the IN relational operator to check to see if a element is in
a set by a true/false selection}
Gotoxy(10,20);
Writeln('Save the changes? (if any) (Y or N)');
Repeat
Key2 := Readkey;Key2 := Upcase(Key2);
Until (Keypressed) or (Key2='Y') or (Key2<='N');
If Key2='Y' then
Begin
{Finds the record you are editing by seek and saves it}
Seek(User_file,recN);
Write(User_File,user_record);
end;
end;
Procedure Show_Stats;
Var Key : Char;
Stop:Boolean;
Begin
Read_Totals;
Assign(User_file,'users.dat');
Reset(User_file);
RecN := 1;
Read(User_File, User_record);
Repeat
Begin
ClrScr;GotoXY(1,10);Textcolor(11);
Stop:=False;
Write('User Stats - user #');Write(RecN+1);Write(' of ');Writeln(Total_users);
Textcolor(14);
Writeln('User Name :'+user_record.name);
Writeln('Real Name :'+user_record.realname);
Writeln('User Status flags (IF X then its set for this user)');
Textcolor(15);
Writeln(' [ ] User Locked out [ ] User deleted');
Writeln(' [ ] Trapping user Activity [ ] Trapping to separate TRAP File');
Writeln(' [ ] Auto Chat Trapping [ ] Separate chat file to trap');
Writeln(' [ ] Separate Sysop Log [ ] Alert sysop when user logs on');
Textcolor(10);
If lockedout In user_record.status then begin Gotoxy(5,14); Write('X'); end;
If udeleted In user_record.status then begin Gotoxy(37,14);Write('X'); end;
If trapactivity In user_record.status then begin Gotoxy(5,15); Write('X'); end;
If trapseparate In user_record.status then begin Gotoxy(37,15);Write('X'); end;
If chatauto In user_record.status then begin Gotoxy(5,16); Write('X'); end;
If chatseparate In user_record.status then begin Gotoxy(37,16);Write('X'); end;
If slogseparate In user_record.status then begin Gotoxy(5,17); Write('X'); end;
If alert In user_record.status then begin Gotoxy(37,17);Write('X'); end;
Gotoxy(4,18);Writeln('Press [, ] for next, previous record or E to edit that user (Q to quit)');
Repeat
Key := Readkey;Key := Upcase(Key);
Until (Keypressed) or (Key='[') or (Key=']') or (key='Q') or (Key='E');
Case Key of
'[','-': Dec(RecN);
']','+': Inc(RecN);
'Q': Stop:=True;
'E': Edit_data;
end;
If Stop=False then
Begin
If RecN<1 then RecN:=0; {minor error checking}
If RecN>=total_users then RecN:=Total_users-1;
Seek(User_file,RecN);
Read(user_file,user_record);
end;
end;
until Stop;
Close(User_file);
end;
Procedure Main_menu;
Var Key : Char;
Begin
ClrScr;GotoXY(10,10);Textcolor(14);
Writeln('Users.dat Demo');
Writeln(' ** Menu **');
Writeln(' A. Show Users Summary');
Writeln(' B. Show User Stats');
Writeln(' Q. Quit');
Writeln;
Writeln('Press A, B or Q please');
Repeat
Key := Readkey;Key := Upcase(Key);
Until (Keypressed) or (Key>=chr(65)) and (Key<=chr(67)) or (key='Q');
Case Key of
'A': User_Summary;
'B': Show_Stats;
'Q': Stop_Now := True;
end;
end;
Begin
Stop_Now := False;
Repeat
Main_Menu;
Until Stop_Now;
end.