Скачиваний:
35
Добавлен:
02.05.2014
Размер:
3.2 Кб
Скачать
unit Unit2;

interface

uses
SysUtils, Dialogs;

type
TCard = class(TObject)
fTypeOfCard:integer;
fPIN:integer;
fSumma:integer;
fBlocked:boolean;
fDateLimit:TDateTime;

//published
// property TypeOfCard:integer read fTypeOfCard write fTypeOfCard;
// property PIN:integer read fPIN write fPIN;
// property Summa:integer read fSumma write fSumma;
// property Blocked:boolean read fBlocked write fBlocked;
// property DateLimit:TDateTime read fDateLimit write fDateLimit;
// Constructor Create(TypeOfCard:integer;
// PIN:integer;
// pSumma:integer;
// Blocked:boolean;
// DateLimit:TDateTime);
end;

type
TProcessor = class(TObject)
fTryCount:integer;
fCard:TCard;
fFileName:String;
function CheckPIN(PIN:integer):Boolean;
function LoadAndCheckCard(fFile:integer;FileName:string): String;
function GetMoney():Boolean;
function BlockCard():Boolean;
//procedure EnableTrip();
end;

implementation

function TProcessor.CheckPIN(PIN:integer):Boolean;
begin
if PIN <> fCard.fPIN then
Result := FALSE
else
Result := TRUE;
end;

function TProcessor.LoadAndCheckCard(fFile:integer;FileName:string):String;
var
FileHandle:integer;
TypeOfCard:integer;
d:TDateTime;
Pbool:Boolean;
PIN, Summa:integer;
begin
fTryCount := 0;
fFileName := FileName;
FileHandle := fFile;
FileRead(FileHandle,TypeOfCard,SizeOf(integer));
fCard := TCard.Create;
if TypeOfCard <> 3 then
begin
fCard.Free;
Result := 'Неверный тип карты!';
exit;
end;
fCard.fTypeOfCard := TypeOfCard;
FileRead(FileHandle,d,SizeOf(TdateTime));
if d < Date() then
begin
fCard.Free;
Result := 'Карта просрочена!';
exit;
end;
fCard.fDateLimit := d;
FileRead(FileHandle,Pbool,SizeOf(boolean));
if Pbool then
begin
fCard.Free;
Result := 'Карта заблокирована!';
exit;
end;
fCard.fBlocked := Pbool;
FileRead(FileHandle,PIN,SizeOf(integer));
fCard.fPIN := PIN;
FileRead(FileHandle,Summa,SizeOf(integer));
fCard.fSumma := Summa;
Result := 'OK';
end;

function TProcessor.GetMoney():Boolean;
var FileHandle,Summa:integer;
begin
if fCard.fSumma < 50 then
Result := FALSE
else
begin
FileHandle := FileOpen(fFileName,fmOpenReadWrite);
FileSeek(FileHandle,SizeOf(integer)+SizeOf(TDateTime)
+SizeOf(boolean)+SizeOf(integer),0);
Summa := fCard.fSumma - 50;
FileWrite(FileHandle,Summa,SizeOf(integer));
FileClose(FileHandle);
Result := True;
end;
end;

function TProcessor.BlockCard():Boolean;
var FileHandle:integer;
PBool:Boolean;
begin
if fTryCount >= 2 then
begin
FileHandle := FileOpen(fFileName,fmOpenReadWrite);
FileSeek(FileHandle,SizeOf(integer)+SizeOf(TDateTime),0);
Pbool := True;
FileWrite(FileHandle,Pbool,SizeOf(boolean));
FileClose(FileHandle);
Result := true
end
else
begin
fTryCount := fTryCount+1;
Result := false;
end;
end;

end.
Соседние файлы в папке Программа
  • #
    02.05.20143.23 Кб33Project1.res
  • #
    02.05.201413.85 Кб33Unit1.dcu
  • #
    02.05.201414.04 Кб33Unit1.dfm
  • #
    02.05.20147.53 Кб35Unit1.pas
  • #
    02.05.20143.36 Кб33Unit2.dcu
  • #
    02.05.20143.2 Кб35Unit2.pas
  • #
    02.05.20146.76 Кб33Unit3.dcu
  • #
    02.05.20142.19 Кб33Unit3.dfm
  • #
    02.05.20142.71 Кб34Unit3.pas