unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, sGroupBox, sButton, sLabel, sSkinManager, DB, ADODB,
  sRadioButton, DBCtrls, sDBMemo, Grids, DBGrids, sSkinProvider;

  procedure inittest(filen:string;n:integer);

type
  TForm1 = class(TForm)
    sButton2: TsButton;
    sButton1: TsButton;
    sSkinManager1: TsSkinManager;
    sLabel2: TsLabel;
    sLabel3: TsLabel;
    ADOTable1: TADOTable;
    DataSource1: TDataSource;
    sDBMemo1: TsDBMemo;
    sGroupBox1: TsGroupBox;
    sRadioButton1: TsRadioButton;
    sRadioButton2: TsRadioButton;
    sRadioButton3: TsRadioButton;
    sRadioButton4: TsRadioButton;
    sRadioButton5: TsRadioButton;
    ADOQuery1: TADOQuery;
    DataSource2: TDataSource;
    ADOConnection1: TADOConnection;
    DBGrid1: TDBGrid;
    sSkinProvider1: TsSkinProvider;
    sButton3: TsButton;
    ADOConnection2: TADOConnection;
    procedure FormCreate(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure sButton2Click(Sender: TObject);
    procedure sRadioGroup1Click(Sender: TObject);
    procedure sButton1Click(Sender: TObject);
    procedure sButton3Click(Sender: TObject);
    procedure sRadioButton1Click(Sender: TObject);
    procedure sRadioButton2Click(Sender: TObject);
    procedure sRadioButton4Click(Sender: TObject);
    procedure sRadioButton5Click(Sender: TObject);
    procedure sRadioButton3Click(Sender: TObject);
    procedure sDBMemo1Change(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  const
  vpered=1;
  nazad=-1;
var
  Form1: TForm1;


  implementation

uses Main, Unit2;

var
  vopnom: integer;
  otv: array [1..1900] of integer;
  recn: integer;

  {$R *.dfm}

function pravilnyh:integer;
var
res:integer;
a:integer;
begin
res:=0;
for a:=1 to nvoprosov do if otv[a]=voprosi[a].Otvets.GoodOtvet then inc(res);
pravilnyh:=res;
end;

{procedure pokazvop;
var
a:integer;
begin
form1.sLabel1.Caption:=voprosi[vopnom].TextVoprosa;
for a:=1 to 5 do form1.sRadioGroup1.Items.Strings[a-1]:=voprosi[vopnom].otvets.otvets[a];
if (otv[vopnom] in [1..5]) then form1.sRadioGroup1.ItemIndex:=otv[vopnom]-1 else form1.sRadioGroup1.ItemIndex:=-1;
form1.sLabel2.Caption:=inttostr(vopnom);
end;  }

procedure inittest(filen:string;n:integer);
const
ur1=0.5;
ur2=0.25 ;
var
a:integer;
urovni:turovni;
begin
for a:=1 to 1900 do otv[a]:=0;
loadtest(filen);
urovni[1]:=round(n*ur1);
urovni[2]:=round(n*ur2);
urovni[3]:=n-urovni[1]-urovni[2];
select_questions(urovni);
vopnom:=1;
//pokazvop;
end;


procedure stepvopros(direction:integer);
var
temp:integer;
begin
temp:=vopnom+direction;
if temp in [1..nvoprosov] then begin
 vopnom:=temp;
 //pokazvop;
end;

end;


procedure TForm1.Button6Click(Sender: TObject);

begin
showmessage(inttostr(pravilnyh));

end;

procedure TForm1.sButton2Click(Sender: TObject);
begin
//stepvopros(vpered);
If StrToInt(sLabel2.Caption)<StrToInt(Form2.sEdit3.Text) then
 begin
  ADOQuery1.Next;
  If ADOQuery1.FieldByName('ID_V').AsString <> '' then
  case Ord(ADOQuery1.FieldByName('ID_V').AsString[1]) of
  65: sRadioButton1.Checked := true;
  66: sRadioButton2.Checked := true;
  67: sRadioButton3.Checked := true;
  68: sRadioButton4.Checked := true;
  69: sRadioButton5.Checked := true;
  end
  else
  begin
  sRadioButton1.Checked := false;
  sRadioButton2.Checked := false;
  sRadioButton3.Checked := false;
  sRadioButton4.Checked := false;
  sRadioButton5.Checked := false;
  end;
  sLabel2.Caption:=IntToStr(StrToInt(sLabel2.Caption)+1);
 end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
randomize;
//inittest(extractfilepath(paramstr(0))+'w.tst');
ADOConnection1.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+extractfilepath(paramstr(0))+'data.mdb;Persist Security Info=False';
ADOConnection1.Open;
end;
procedure TForm1.sRadioGroup1Click(Sender: TObject);
begin
//otv[vopnom]:=Form1.sRadioGroup1.itemindex+1;
//showmessage(inttostr(Form1.sRadioGroup1.itemindex));
end;

procedure TForm1.sButton1Click(Sender: TObject);
begin
//stepvopros(-vpered);
If StrToInt(sLabel2.Caption)>1 then
 begin
  ADOQuery1.Prior;
  If ADOQuery1.FieldByName('ID_V').AsString <> '' then
  case Ord(ADOQuery1.FieldByName('ID_V').AsString[1]) of
  65: sRadioButton1.Checked := true;
  66: sRadioButton2.Checked := true;
  67: sRadioButton3.Checked := true;
  68: sRadioButton4.Checked := true;
  69: sRadioButton5.Checked := true;
  end
  else
  begin
  sRadioButton1.Checked := false;
  sRadioButton2.Checked := false;
  sRadioButton3.Checked := false;
  sRadioButton4.Checked := false;
  sRadioButton5.Checked := false;
  end;
  sLabel2.Caption:=IntToStr(StrToInt(sLabel2.Caption)-1);
 end;
end;

procedure TForm1.sButton3Click(Sender: TObject);
//showmessage(inttostr(pravilnyh));
 var
f:textfile;
s:string;
kol_pr,i: integer;
begin
  For i:=1 to ADOQuery1.RecordCount do
  begin
    If ADOQuery1['ID_V']=ADOQuery1['вариант'] then kol_pr:=kol_pr+1 ;
    ADOQuery1. RecNo:=i;
  end;
showmessage('Количество баллов='+inttostr(kol_pr));
assignfile(f,ExtractFilePath(ParamStr(0))+'log.txt');
system.append(f);
writeln(f);

s:=form2.sedit1.text+' '+form2.sedit2.text+' Количество баллов='+inttostr(kol_pr);crypt(s);
writeln(f,s);
closefile(f);
modalresult:=mrok;
end;

procedure TForm1.sRadioButton1Click(Sender: TObject);
begin
  ADOQuery1.Edit;
  ADOQuery1['ID_V'] := sRadioButton1.Caption;
  ADOQuery1.Post;
end;

procedure TForm1.sRadioButton2Click(Sender: TObject);
begin
  ADOQuery1.Edit;
  ADOQuery1['ID_V'] := sRadioButton2.Caption;
  ADOQuery1.Post;
end;

procedure TForm1.sRadioButton3Click(Sender: TObject);
begin
  ADOQuery1.Edit;
  ADOQuery1['ID_V'] := sRadioButton3.Caption;
  ADOQuery1.Post;
end;

procedure TForm1.sRadioButton4Click(Sender: TObject);
begin
  ADOQuery1.Edit;
  ADOQuery1['ID_V'] := sRadioButton4.Caption;
  ADOQuery1.Post;
end;

procedure TForm1.sRadioButton5Click(Sender: TObject);
begin
  ADOQuery1.Edit;
  ADOQuery1['ID_V'] := sRadioButton5.Caption;
  ADOQuery1.Post;
end;

procedure TForm1.sDBMemo1Change(Sender: TObject);
begin
 randomize;
end;

end.
