Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms



Download 59,89 Kb.
bet1/6
Sana04.04.2022
Hajmi59,89 Kb.
#528031
  1   2   3   4   5   6
Bog'liq
dastur holati


unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, ToolWin, Menus, Grids, StdCtrls, Buttons,
IdBaseComponent, IdComponent, IdTCPServer, HttpApp, IniFiles, ExtCtrls,
OleCtrls, SHDocVw;
type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
File1: TMenuItem;
ool1: TMenuItem;
Help1: TMenuItem;
Help2: TMenuItem;
N1: TMenuItem;
About1: TMenuItem;
View1: TMenuItem;
StatusBar1: TStatusBar;
IdTCPServer1: TIdTCPServer;
Options1: TMenuItem;
Timer1: TTimer;
N2: TMenuItem;
N3: TMenuItem;
N4: TMenuItem;
N5: TMenuItem;
SaveDialog1: TSaveDialog;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
ToolBar1: TToolBar;
ToolButton3: TToolButton;
BitBtn1: TBitBtn;
ToolButton1: TToolButton;
BitBtn2: TBitBtn;
ToolButton2: TToolButton;
BitBtn3: TBitBtn;
StringGrid1: TStringGrid;
TabSheet2: TTabSheet;
ToolBar2: TToolBar;
ToolButton4: TToolButton;
BitBtn4: TBitBtn;
WebBrowser1: TWebBrowser;
CheckBox1: TCheckBox;
ToolButton5: TToolButton;
Label1: TLabel;
Edit1: TEdit;
Label2: TLabel;
ToolButton7: TToolButton;
ToolButton8: TToolButton;
CheckBox2: TCheckBox;
Edit3: TEdit;
Button1: TButton;
OpenDialog1: TOpenDialog;
Edit2: TEdit;
ToolButton6: TToolButton;
procedure FormCreate(Sender: TObject);
procedure SettingsLoad;
procedure SettingsSave;
procedure BitBtn1Click(Sender: TObject);
procedure IdTCPServer1Connect(AThread: TIdPeerThread);
procedure IdTCPServer1Execute(AThread: TIdPeerThread);
procedure IdTCPServer1TIdCommandHandler0Command(ASender: TIdCommand);
procedure IdTCPServer1TIdCommandHandler1Command(ASender: TIdCommand);
procedure About1Click(Sender: TObject);
procedure IdTCPServer1TIdCommandHandler2Command(ASender: TIdCommand);
procedure FormDestroy(Sender: TObject);
procedure IdTCPServer1TIdCommandHandler3Command(ASender: TIdCommand);
procedure Options1Click(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure N4Click(Sender: TObject);
procedure Edit1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure N2Click(Sender: TObject);
procedure N5Click(Sender: TObject);
procedure BitBtn4Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure CheckBox1Click(Sender: TObject);
procedure CheckBox2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Stats, SSDFile: TextFile;
Form1: TForm1;
CPassword, CSurname, CName, SMessage: string;
TestName, HtmlFolder: string;
TimeOfTest: integer;
RightAnswers: TStrings;
Settings: TIniFile;
ProgramDir: string;
TheTime: Integer;
SPassword: string;
MaxBall: integer;
implementation
uses Start, Modul, IdTCPConnection, IdIOHandlerSocket, {Unit3,} Options,
Info, Unit3, Tahlil;
{$R *.dfm}
Procedure Statistics;
begin
end;
Procedure SaveServerData; //àâòîìàòè÷åñêîå ñîõðàíåíèå äàííûõ ñåðâåðà, äëÿ íåïðåäâèäåííûõ ñëó÷àÿõ (ïåðåçàãðóçêà è ò.ä.)
var
i,j:integer;
begin
AssignFile(SSDFile, ProgramDir + 'server.tmp');
{$I-}
Rewrite(SSDFile);
{$I+}
if IOResult = 0 then
begin
for i := 0 to 8 do Writeln(SSDFile, Form5.StringGrid1.Cells[i,1]);
with Form1.StringGrid1 do
begin
Writeln(SSDFile, RowCount);
Writeln(SSDFile, ColCount);
for i := 1 to RowCount - 1 do
for j := 1 to ColCount - 1 do Writeln(SSDFile, Cells[j,i]);
end;
CloseFile(SSDFile);
end;
end;
Procedure LoadServerData; //çàãðóçêà íå ñîõðàí¸ííûõ äàííûõ
var
i,j,itmp,jtmp:integer;
strtmp: string;
begin
AssignFile(SSDFile, ProgramDir + 'server.tmp');
Reset(SSDFile);
with Form1.StringGrid1 do
begin
for i := 0 to 8 do
begin
Readln(SSDFile, strtmp);
Form5.StringGrid1.Cells[i,1];
end;
Readln(SSDFile, itmp);
Readln(SSDFile, jtmp);
RowCount := itmp;
for i := 1 to itmp - 1 do
for j := 1 to jtmp - 1 do
begin
Readln(SSDFile, strtmp);
Cells[j,i] := strtmp;
end;
end;
CloseFile(SSDFile);
end;
procedure TForm1.SettingsLoad;
begin
Settings := TIniFile.Create(ProgramDir + 'settings.ini');
with Settings do
begin
Form4.Edit1.Text := ReadString('Options', 'Port', '1313');
Form4.Edit2.Text := ReadString('Options', 'Password', '123');
end;
SPassword := Form4.Edit2.Text;
IdTCPServer1.DefaultPort := StrToInt(Form4.Edit1.Text);
Settings.Free;
end;
procedure TForm1.settingsSave;
begin
Settings := TIniFile.Create(ProgramDir + 'settings.ini');
with Settings do
begin
WriteString('Options', 'Port', Form4.Edit1.Text);
WriteString('Options', 'Password', Form4.Edit2.Text);
end;
SPassword := Form4.Edit2.Text;
IdTCPServer1.DefaultPort := StrToInt(Form4.Edit1.Text);
Settings.Free;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
with StringGrid1 do
begin
RowCount := 2;
ColCount := 11;
Cells[0,0] := '¹';
Cells[1,0] := 'Familiya';
Cells[2,0] := 'Ism';
Cells[3,0] := 'Ip-manzil';
Cells[4,0] := 'boglandi';
Cells[5,0] := 'test boshlandi';
Cells[6,0] := 'tugatdi';
Cells[7,0] := 'ball';
Cells[8,0] := 'savollar';
Cells[9,0] := 'kalit';
Cells[10,0] := 'javob';
ColWidths[0] := 40;
end;
BitBtn1.Enabled := True;
BitBtn2.Enabled := False;
BitBtn3.Enabled := False;
ProgramDir := ExtractFilePath(Application.ExeName);
//âîçîáíîâëåíèå ðàáîòû ñåðâåðà
{If FileExists(ProgramDir + 'server.tmp') then
if MessageDlg('Utggan safar server uz ishini notugri tugatdi'+#013+
'Uni ish faoliyatini tiklash',
mtConfirmation, [mbYes, mbNo], 0) = mrYes then
begin
IdTCPServer1.Active := True;
LoadServerData;
end;}
Edit1.Enabled := False;
Edit2.Enabled := False;
Edit3.Enabled := False;
Button1.Enabled := False;
//PageControl1.Pages[2].
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
Form2.ShowModal;
end;
procedure TForm1.IdTCPServer1Connect(AThread: TIdPeerThread);
begin
AThread.Connection.WriteLn('MyTest Server');
end;
procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
begin
//:)
end;
procedure TForm1.IdTCPServer1TIdCommandHandler0Command(
ASender: TIdCommand); //GetHtml
var
Stream: TMemoryStream;
i,j : integer;
str: string;
begin
CSurname := ASender.Thread.Connection.ReadLn;
CName := ASender.Thread.Connection.ReadLn;
CPassword := ASender.Thread.Connection.ReadLn;
if CPassword = Form4.Edit2.Text then
Begin
i := 1;
while not((StringGrid1.Cells[1,i] = CSurname)and
(StringGrid1.Cells[2,i] = CName)and
(StringGrid1.Cells[3,i] = ASender.Thread.Connection.Socket.Binding.PeerIP)
and (i < StringGrid1.RowCount - 1)) do inc(i);
if i < StringGrid1.RowCount - 1 then
begin
ASender.Thread.Connection.WriteLn('Ok!');
GetTest; //create one test
str := ''; // êëþ÷ ê òåñòó
for j := 0 to COfQ - 1 do str := str + chr(65 + OneTest[j].RightAnswer);
StringGrid1.Cells[8,i] := LOfQStr;
StringGrid1.Cells[9,i] := str; //êëþ÷
StringGrid1.Cells[5,i] := TimeToStr(Time); //âðåìÿ íà÷àëà òåñòà
Stream := TMemoryStream.Create;
Stream.Write(TestString[1], Length(TestString));
SaveServerData; //ñîõðàíåíèå äàííûõ
//Stream.SaveToFile('c:\test.html');
try
ASender.Thread.Connection.WriteLn(IntToStr(Stream.Size));
ASender.Thread.Connection.WriteStream(Stream);
finally Stream.Free; TestString := ''; end;
end else ASender.Thread.Connection.WriteLn('ReConnect To Server');
End else ASender.Thread.Connection.WriteLn('Invalid Password');;
end;
procedure TForm1.IdTCPServer1TIdCommandHandler1Command(
ASender: TIdCommand); //GetFile
var
Stream: TMemoryStream;
FileName: string;
begin
FileName := ASender.Params[0];
FileName := CurDir + HtmlFolder + FileName;
if FileExists(FileName) then
begin
Asender.Thread.Connection.WriteLn('Ok!');
Stream := TMemoryStream.Create;
Stream.LoadFromFile(FileName);
try
ASender.Thread.Connection.WriteLn(IntToStr(Stream.Size));
ASender.Thread.Connection.WriteStream(Stream);
finally Stream.Free end;
end else ASender.Thread.Connection.WriteLn('File not Exist');
end;
procedure TForm1.About1Click(Sender: TObject);
begin
Form3.ShowModal;
end;
procedure TForm1.IdTCPServer1TIdCommandHandler2Command(
ASender: TIdCommand); //connect
var
i, CurUser: integer;
flag : boolean;
begin
with ASender.Thread.Connection do
BEGIN
CSurname := Readln;
CName := Readln;
CPassword := Readln;
SMessage := 'Ok!';
flag := true;
If CPassword = Form4.Edit2.Text then //ïàðîëü ñåðâåðà è êëèåíòà ñîâïàäàþò
Begin
for i := 1 to StringGrid1.RowCount - 2 do
if ((StringGrid1.Cells[1,i] = CSurname)and(StringGrid1.Cells[2,i] = CName))or
(StringGrid1.Cells[3,i] = Socket.Binding.PeerIP) then
begin
if (StringGrid1.Cells[3,i] = Socket.Binding.PeerIP)and
(StringGrid1.Cells[6,i] = '') then //íå çàêîí÷èë òåñò
begin
flag := false;
StringGrid1.Cells[1,i] := CSurname;
StringGrid1.Cells[2,i] := CName;
StringGrid1.Cells[4,i] := TimeToStr(Time);
end;
if ((StringGrid1.Cells[1,i] = CSurname)and(StringGrid1.Cells[2,i] = CName))
and(StringGrid1.Cells[6,i] <> '') then
begin
flag := false;
SMessage := 'Siz sinovdan utgansiz!';
end;
if (StringGrid1.Cells[3,i] <> Socket.Binding.PeerIP)and
((StringGrid1.Cells[1,i] = CSurname)and(StringGrid1.Cells[2,i] = CName)) then
begin
flag := false;
SMessage := 'Bunday foydalanuvchi ruyxatga olingan!';
end;
end;
if flag then
begin
CurUser := StringGrid1.RowCount - 1;
StringGrid1.RowCount := CurUser + 2;
With StringGrid1 do
begin
Cells[0,CurUser] := IntToStr(CurUser);
Cells[1,CurUser] := CSurname;
Cells[2,CurUser] := CName;
Cells[3,CurUser] := Socket.Binding.PeerIP;
Cells[4,CurUser] := TimeToStr(Time);
end;
end;
End else SMessage := 'Parol notugri!';
WriteLn(SMessage);
if SMessage = 'Ok!' then
begin
WriteLn(TestName);
WriteLn(HtmlFolder);
WriteLn(IntToStr(TimeOfTest)); //â ñåêóíäàõ
WriteLn(IntToStr(COfQ)); //êîëè÷åñòâî âîïðîñîâ â òåñòå
WriteLn(IntToStr(MaxBall)); //ìàêñèìàëüíûé áàëë
end;
END;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
RightAnswers.Free;
end;
procedure TForm1.IdTCPServer1TIdCommandHandler3Command(
ASender: TIdCommand); //GetBall
var
str : String;
Qs: array of integer;
Ckeys: string;
i, j: integer;
l,m,k: integer;
RightAnswers, BallInProcent, Ball:integer;
begin
CSurname := ASender.Thread.Connection.ReadLn;
CName := ASender.Thread.Connection.ReadLn;
CPassword := ASender.Thread.Connection.ReadLn;
//ÑKeys := ASender.Thread.Connection.ReadLn;
if CPassword = Form4.Edit2.Text then
Begin
i := 1;
while not((StringGrid1.Cells[1,i] = CSurname)and
(StringGrid1.Cells[2,i] = CName)and
(StringGrid1.Cells[3,i] = ASender.Thread.Connection.Socket.Binding.PeerIP)
and (i < StringGrid1.RowCount - 1)) do inc(i);
if i < StringGrid1.RowCount - 1 then
begin
ASender.Thread.Connection.WriteLn('Ok!');
StringGrid1.Cells[6,i] := TimeToStr(Time); //âðåìÿ îêî÷àíèÿ òåñòà
CKeys := ASender.Thread.Connection.ReadLn; //êëþ÷ îòâåòîâ òåñòèðóåìîãî
StringGrid1.Cells[10,i] := CKeys;
RightAnswers := 0;
{------ Ïîëó÷åíèå íîìåðîâ âîïðîñîâ--------}
SetLength(Qs, COfQ);
l := 1;
m := 1;
k := 0;
while (k < COfQ) do
begin
while StringGrid1.Cells[8,i][l] <> ';' do inc(l);
str := copy(StringGrid1.Cells[8,i],m,l-m);
l := l + 1;
m := l;
Qs[k] := StrToInt(str);
inc(k);
end;
{-------------------------------------------}

for j := 1 to COfQ do


if StringGrid1.Cells[10,i][j] = StringGrid1.Cells[9,i][j] then
begin
inc(RightAnswers);
WriteLn(Stats, Qs[j-1],#009, '1');
end
else
WriteLn(Stats, Qs[j-1],#009, '0');
Flush(Stats);
BallInProcent := round((100*RightAnswers)/COfQ);
Ball := round(RightAnswers*MaxBall/COfQ);
StringGrid1.Cells[7,i] := IntToStr(Ball) + ' (' + IntToStr(BallInProcent) + '%)';
SaveServerData; //ñîõðàíåíèå äàííûõ
ASender.Thread.Connection.WriteLn(IntToStr(RightAnswers));
ASender.Thread.Connection.WriteLn(IntToStr(Ball));
ASender.Thread.Connection.WriteLn(IntToStr(BallInProcent));
end else ASender.Thread.Connection.WriteLn('Yana bir bor urinib kuring!');
End else ASender.Thread.Connection.WriteLn('Parol notugri');;
end;
procedure TForm1.Options1Click(Sender: TObject);
begin
Form4.ShowModal;
end;
procedure TForm1.BitBtn3Click(Sender: TObject);
var
Text:Textfile;
itmp:integer;
TimeStr: string;
begin
{-------- Çàêðûòèå ôàéëà ñòàòèñòèêè---------}
Flush(Stats);
CloseFile(Stats);
{-----------------------}

IdTCPServer1.Active := False;


Timer1.Enabled := False;
StatusBar1.Panels[8].Text := 'Tuxtatilgan';
Form5.StringGrid1.Cells[1,7] := 'Tuxtatilgan';;
BitBtn3.Enabled := False;
BitBtn1.Enabled := True;
if FileExists(ProgramDir + 'server.tmp') then DeleteFile(ProgramDir + 'server.tmp');
//àòîìàòè÷åñêîå ñîõðàíåíèå ðåçóëüòàòîâ òåñòèðîâàíèÿ ïî îêàí÷àíèþ òåñòà â ïàïêå Results
TimeStr := '';
ShowMessage(Form5.StringGrid1.Cells[1,6]);
For itmp := 1 to Length(Form5.StringGrid1.Cells[1,6]) do
if Form5.StringGrid1.Cells[1,6][itmp] = ':' then TimeStr := TimeStr + '-'
else TimeStr := TimeStr + Form5.StringGrid1.Cells[1,6][itmp];
AssignFile(Text, ProgramDir + 'Results\' + TestName + ' [' + TimeStr + '].txt');
Rewrite(Text);
Writeln(Text, 'Fan: ' + Form2.edit4.text +' ['+ DateTimeToStr(Now) +']');
Writeln(Text);
Writeln(Text,'¹'+#009+'Familiya'+#009+'Ism'+#009+'Ball');
with StringGrid1 do
begin
for itmp := 1 to RowCount-2 do
Writeln(Text,IntToStr(itmp)+#009+Cells[1,itmp]+#009+Cells[2,itmp]+#009+Cells[7,itmp] + ' %');
end;
CloseFile(Text);
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
TheTime := TheTime + 1;
StatusBar1.Panels[6].Text := IntToStr(TheTime);
Form5.StringGrid1.Cells[1,8] := StatusBar1.Panels[6].Text;
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
begin
Form5.ShowModal;
end;
procedure TForm1.N4Click(Sender: TObject);
begin
Form1.Close;
end;
procedure TForm1.Edit1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
ShowMessage(IntToStr(ord(Key)));
end;
procedure TForm1.N2Click(Sender: TObject);
var
Text: TextFile;
i: integer;
begin
SaveDialog1.Filter := 'Matnli hujjat (*.txt)|*.txt|Ixtiyoriy fayl (*.*)|*.*';
if SaveDialog1.Execute then
begin
AssignFile(Text, SaveDialog1.FileName);
Rewrite(Text);
Writeln(Text, 'Fan: ' + Form2.edit4.text +' ['+ DateTimeToStr(Date) +']');
Writeln(Text);
Writeln(Text,'¹'+#009+'Familiya'+#009+'Ism'+#009+'Ball');
with StringGrid1 do
begin
for i := 1 to RowCount-2 do
Writeln(Text,IntToStr(i)+#009+Cells[1,i]+#009+Cells[2,i]+#009+Cells[7,i] + ' %');
end;
CloseFile(Text);
end;
SaveServerData;
end;
procedure TForm1.N5Click(Sender: TObject);
begin
LoadServerData;
end;
procedure TForm1.BitBtn4Click(Sender: TObject);
begin
GetBinMat(Matrix, Testers);
GetRedBinMat(Matrix1,Matrix2,Matrix4);
Disp(Sx2, Sx);
GetKorMat(Matrix3);
NadTest(rt1,rt2,rt3,NadMat);
ShowResults;
WebBrowser1.Navigate(ProgramDir + 'Analysis\'+'analysis.html');
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
edit3.Text:=OpenDialog1.FileName;
end;
end;
procedure TForm1.CheckBox1Click(Sender: TObject);
begin
if CheckBox1.Checked then
begin
Edit1.Enabled:=True;
Edit2.Enabled:=True;
Edit3.Enabled:=False;
CheckBox2.Checked:=False;
Button1.Enabled:=False;
end
else
begin
Edit1.Enabled := False;
Edit2.Enabled := False;
Edit3.Enabled := False;
CheckBox2.Checked := False;
Button1.Enabled := False;
end
end;
procedure TForm1.CheckBox2Click(Sender: TObject);
begin
if CheckBox2.Checked then
begin
Edit1.Enabled := False;
Edit2.Enabled := False;
Edit3.Enabled := True;
CheckBox1.Checked := False;
Button1.Enabled := True;
end
else
begin
Edit1.Enabled := False;
Edit2.Enabled := False;
Edit3.Enabled := False;
CheckBox1.Checked := False;
Button1.Enabled := False;
end
end;
end.
**** info *****
unit Info;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, StdCtrls;
type
TForm5 = class(TForm)
StringGrid1: TStringGrid;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form5: TForm5;
implementation
{$R *.dfm}
procedure TForm5.FormCreate(Sender: TObject);
begin
with StringGrid1 do
Begin
RowCount := 9;
Cells[0,0] := 'Fan:';
Cells[0,1] := 'Test fayli:';
Cells[0,2] := 'Savollar soni:';
Cells[0,3] := 'Test topshiriqlar soni:';
Cells[0,4] := 'Maksimal bal:';
Cells[0,5] := 'Sinov vaqti:';
Cells[0,6] := 'Server ishini boshladi:';
Cells[0,7] := 'Server holati:';
Cells[0,8] := 'O`tgan vaqt (sek.):';
End;
end;
procedure TForm5.Button1Click(Sender: TObject);
begin
Form5.Close;
end;
end.

Download 59,89 Kb.

Do'stlaringiz bilan baham:
  1   2   3   4   5   6




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish