7 лабараторная

uses
  System.SysUtils,
  System.Classes,
  Laba1 in 'Laba1.pas',
  laba2 in 'laba2.pas',
  Laba3 in 'Laba3.pas',
  Laba4 in 'Laba4.pas',
  Laba5 in 'Laba5.pas',
  Laba6 in 'Laba6.pas';

type
Tuser=record    //сюда записывается инфа из файла
typeofuser:string;
login,pass:string;
whichprogr:string;
end;
type
   Tsort = record      //для сортировки по алфавиту для  сравнения логинов и паролей
     login:  string[20];
     password: string [20];
   end;
  var  User:array[0..100] of Tuser;
  us:array[0..100] of Tsort;
  index:integer;
   function Compare (T1,T2: Tsort): integer;    //для сортировки
begin
     if T1.login > T2.login then
        Compare := 1
     else
        if T1.login = T2.login then
           Compare := 0
        else
           Compare := -1
end;
procedure Sort;          //сама сортировка
var
  i, j: integer;
  temp: Tsort;
begin
  For I := 0 To Pred (index) Do
    For J := Succ (I) To index Do
      if Compare (Us[i], Us[j]) > 0 then
        Begin
          temp := us[i];
          us[i] := us[j];
          us[j] := temp;
        End;
end;
procedure free;    //очищаем массив
var
  I: Integer;
begin
for I := 0 to index-1 do
begin
us[i].login:='';
us[i].password:='';
end;
end;
var
file_name:string;
login,pass:string;
t1,t2:Textfile;
i,j,k:Integer;
a:Boolean=False;
log,password:TStringList;
whatcando:integer;
logforchange:string;
whatchange:integer;
changelog,changepass,changetype,changeprogr:string;
newlog,newpass,newtype,whatcanexe:string;
exe:Integer;
quite:Integer;
str:array[0..100] of string[20];
s:string[20];
str1:array[0..100] of string[20];
str2,str3:Tstringlist;
s1:string[20];
f1,f2,f3,f4:string;
begin
write('Имя файла: ');
readln(file_name);
if FileExists(file_name+'.txt') then
begin
repeat
AssignFile(t1,file_name+'.txt');
Reset(t1);
while not Eof(t1) do          //читаем инфу из файла
begin
Readln(t1,User[index].login);
Readln(t1,User[index].pass);
Us[index].login:=User[index].login;
Us[index].password:=User[index].pass;
Readln(t1,User[index].typeofuser);
Readln(t1,User[index].whichprogr);
Readln(t1);
Inc(index);
end;
CloseFile(t1); //закрываем файл
Sort;
for i := 1 to index do
if (Us[i].login=us[i+1].login) or (Us[i].password=us[i+1].password) then  //если повторяются лог или пароли то
Writeln('Есть одинаковые логины или пароли!');
write('Введите логин-');
Readln(login);
write('Введите пароль-');
Readln(pass);
for I := 0 to index-1 do
if (login=User[i].login) and (pass=User[i].pass)then  //если найден польз
begin
if User[i].typeofuser='superuser' then  //если суперпольз
begin
write('Создать пользователя-1,Изменить данные пользователя-2,удалить пользователя-3,запустить лабу-4: ');
readln(whatcando);
if whatcando=1 then
begin
Write('логин-');
Readln(newlog);
Write('Пароль-');
Readln(newpass);
Write('user/superuser-');
Readln(newtype);
Write('Номер лабы для запуска-');
Readln(whatcanexe);
AssignFile(t2,file_name+'.txt');
Rewrite(t2);
User[index].login:=newlog;
User[index].pass:=newpass;
User[index].typeofuser:=newtype;
User[index].whichprogr:=whatcanexe;
Inc(index);
for k := 0 to index-1 do
begin
Writeln(t2,User[k].login);
Writeln(t2,User[k].pass);
Writeln(t2,User[k].typeofuser);
Writeln(t2,User[k].whichprogr);
if k<> index-1 then Writeln(t2,'');//если последний раз записываем строчку то пробел не ставим в конце иначе и дальше разделяем юзеров
end;
CloseFile(t2);
end;
if whatcando=2 then
begin
Writeln('');
for j := 0 to index-1 do
begin
Writeln(User[j].login);
Writeln(User[j].pass);
Writeln(User[j].typeofuser);
Writeln(User[j].whichprogr);
Writeln('');
end;
write('Введите логин пользователя для внесения изменений: ');
Readln(logforchange);
for j := 0 to index-1 do
if logforchange=user[j].login then
begin
write('Изменить:Логин-1,Пароль-2,тип юзера-3,программу-4,все поля-5 :');
readln(whatchange);
AssignFile(t2,file_name+'.txt');
Rewrite(t2);
if whatchange=1 then
begin
write('Логин: ');
Readln(changelog);
user[j].login:=changelog;
end;
if whatchange=2 then
begin
write('Пароль: ');
Readln(changepass);
user[j].pass:=changepass;
end;
if whatchange=3 then
begin
write('superuser\user: ');
Readln(changetype);
user[j].typeofuser:=changetype;
end;
if whatchange=4 then
begin
write('Лаба: ');
Readln(changeprogr);
user[j].whichprogr:=changeprogr;
end;
if whatchange=5 then
begin
write('Логин: ');
Readln(changelog);
user[j].login:=changelog;
write('Пароль: ');
Readln(changepass);
user[j].pass:=changepass;
write('superuser\user: ');
Readln(changetype);
user[j].typeofuser:=changetype;
write('Лаба: ');
Readln(changeprogr);
user[j].whichprogr:=changeprogr;
end;
for k := 0 to index-1 do
begin
Writeln(t2,User[k].login);
Writeln(t2,User[k].pass);
Writeln(t2,User[k].typeofuser);
Writeln(t2,User[k].whichprogr);
if k<> index-1 then Writeln(t2,'');
end;
CloseFile(t2);
end;
end;
if whatcando=3 then
begin
Writeln('');
for j := 0 to index-1 do
begin
Writeln(User[j].login);
Writeln(User[j].pass);
Writeln(User[j].typeofuser);
Writeln(User[j].whichprogr);
Writeln('');
end;
Write('Логин-');
Readln(newlog);
for j := 0 to index-1 do
if User[j].login=newlog then
begin
User[j].login:='';
User[j].pass:='';
User[j].typeofuser:='';
User[j].whichprogr:='';
end;
AssignFile(t2,file_name+'.txt');
Rewrite(t2);
for k := 0 to index-1 do
if User[k].login<>'' then
begin
Writeln(t2,User[k].login);
Writeln(t2,User[k].pass);
Writeln(t2,User[k].typeofuser);
Writeln(t2,User[k].whichprogr);
Writeln(t2,'');
end;
CloseFile(t2);
end;
if whatcando=4 then
begin
write('1-не понял что за шифр,2-шифрование перестановкой,3-шифр Цезаря,4-Шифр Плейфера,5-Кодировочная книга,6-RLE: ');
Readln(exe);
if exe=1 then RunLaba1;
if exe=2 then RunLaba2;
if exe=3 then RunLaba3;
if exe=4 then RunLaba4;
if exe=5 then RunLaba5;
if exe=6 then RunLaba6;
end;
end
else
if User[i].typeofuser='user' then
begin
write('запустить лабу-1: ');
readln(whatcando);
if User[i].whichprogr='1' then  RunLaba1;
if User[i].whichprogr='2' then  RunLaba2;
if User[i].whichprogr='3' then  RunLaba3;
if User[i].whichprogr='4' then  RunLaba4;
if User[i].whichprogr='5' then  RunLaba5;
if User[i].whichprogr='6' then  RunLaba6;
Break;
end;
end;
write('1-Выйти из сеанса,2-завершить работу:');
readln(quite);
free;
index:=0;
 until quite=2;
end;
end.
Теги:
Writeln, index, login, begin, Readln, then, whichprogr, write, string, typeofuser, whatcando, whatchange, password, changeprogr, newlog, readln, changetype, changelog, changepass, Compare, integer, Логин, array, Пароль, superuser, Integer, CloseFile, пользователя, AssignFile, Tsort, logforchange, else, whatcanexe, newtype, логин
Добавлено: 01 Декабря 2015 20:12:44 Добавил: Илья Добряк Нравится 0
Добавить
Комментарии:
Нету комментариев для вывода...