📄 client.pas
字号:
unit client;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,wininet, Buttons, ScktComp, DB, ADODB;
type
TForm1 = class(TForm)
edthost: TEdit;
Label1: TLabel;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
cs1: TClientSocket;
Label2: TLabel;
Edit1: TEdit;
JIESHOU: TClientSocket;
rs: TADODataSet;
procedure SpeedButton2Click(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure cs1Read(Sender: TObject; Socket: TCustomWinSocket);
procedure JIESHOURead(Sender: TObject; Socket: TCustomWinSocket);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
x:integer;
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.dfm}
procedure TForm1.SpeedButton2Click(Sender: TObject);
begin
cs1.Socket.Close;
close();
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
if edthost.Text='' then
begin
MessageBox(handle, '请输入服务器IP地址!', '提示', mb_IconInformation + mb_Ok);
edthost.SetFocus;
exit;
end;
if edit1.Text='' then
begin
MessageBox(handle, '请输入学号!', '提示', mb_IconInformation + mb_Ok);
edit1.SetFocus;
exit;
end;
cs1.address:=edthost.Text;
cs1.Active:=true;
JIESHOU.Address:=edthost.Text;
JIESHOU.Active:=TRUE;
try
//---------------向服务器端发送要考试学号--------------------------
except
MessageBox(handle, '连不上服务器!', '提示', mb_IconInformation + mb_Ok);
end;
form2.StatusBar1.Panels[0].Text:=' 您的学号是:'+edit1.Text;
form2.sno:=edit1.Text;
form2.ip:=edthost.Text;
end;
procedure TForm1.cs1Read(Sender: TObject; Socket: TCustomWinSocket);
var
xinxi:string;
begin
xinxi:=cs1.Socket.ReceiveText; //-----------从服务器端传来的信息-----------
if xinxi='登录成功!' then //-------------如果传来的是‘登录成功’则表示该学号存在允许考试----------
begin
MessageBox(handle, pchar(xinxi), '提示', mb_IconInformation + mb_Ok);
cs1.Socket.Close;
form1.Visible:=false;
form2.Label2.Caption:=edit1.Text;
form2.Visible:=true;
jieshou.Socket.SendText('d');
//JIESHOU
exit;
end ;
if xinxi='ksfs' then
begin
cs1.Socket.SendText(edit1.Text);
exit;
end;
begin //----------------否则该学生的学号有误或和别的同学输入了同样的号------------
MessageBox(handle, pchar(xinxi), '提示', mb_IconInformation + mb_Ok);
cs1.Socket.Close;
edit1.Clear;
edit1.SetFocus;
exit;
end;
end;
procedure TForm1.JIESHOURead(Sender: TObject; Socket: TCustomWinSocket);
var
s,temp:string;
fs: array[1..19] of string;
i,t,index,i2:integer;
begin
s:=socket.ReceiveText;
for i2:=1 to 19 do
begin
fs[i2]:='';
end;
temp:='';
t:=1;
index:=1;
//////////////begin do//////////////
for i:=1 to length(s) do
begin
if s[i]<>chr(1) then
temp:=temp+s[i]
else
begin
fs[t]:=temp;
temp:='';
if t>=17 then
begin
rs.CommandText:='select * from [temp]';
rs.Open;
rs.Insert;
rs.Fields.Fields[0].AsInteger:=index;
for i2:=1 to 17 do
begin
rs.Fields.Fields[i2].AsString:=fs[i2];
end;
rs.Post;
rs.Close;
index:=index+1;
t:=1;
for i2:=1 to 19 do
begin
fs[i2]:='';
end;
end
else
t:=t+1;
end;
end;
/////////////end do///////////////
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
x:=0;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -