?? uclient.~pas
字號(hào):
unit uClient;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Grids, Buttons, ComCtrls, Mask, ScktComp,IniFiles,
DB, ADODB, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
IdTime;
type
TFrClient = class(TForm)
GroupBox1: TGroupBox;
StringGrid1: TStringGrid;
Panel1: TPanel;
Label1: TLabel;
StatusBar1: TStatusBar;
CBox_ID: TComboBox;
Label2: TLabel;
Ed_Pwd: TEdit;
Btn_login: TSpeedButton;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
Ed_host: TLabeledEdit;
Ed_port: TLabeledEdit;
Btn_Go: TSpeedButton;
Btn_Over: TSpeedButton;
ClientSocket1: TClientSocket;
Btn_History: TSpeedButton;
Label4: TLabel;
DatetimePicker1: TDateTimePicker;
ADOQuery1: TADOQuery;
CBox_local: TCheckBox;
CBox_Record: TCheckBox;
CBox_Time: TCheckBox;
IdTime1: TIdTime;
ADOConnection1: TADOConnection;
Btn_Search: TBitBtn;
procedure Btn_loginClick(Sender: TObject);
procedure ClientSocket1Connect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);
procedure ClientSocket1Connecting(Sender: TObject;
Socket: TCustomWinSocket);
procedure ClientSocket1Disconnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ClientSocket1Error(Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent; var ErrorCode: Integer);
procedure Btn_GoClick(Sender: TObject);
procedure Btn_OverClick(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure FormShow(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Btn_HistoryClick(Sender: TObject);
procedure Btn_SearchClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FrClient: TFrClient;
MiniFile: TiniFile;
Function Search(tempID:string;tempstatus:string):bool;
procedure worked(str:string);
procedure working;
implementation
{$R *.dfm}
procedure TFrClient.Btn_loginClick(Sender: TObject);
begin
if CBox_ID.Text='' then exit;
if ((CBox_local.Checked) and (Btn_login.Caption='登錄')) then
begin
ADOQuery1.Connection:=FrClient.ADOConnection1;
With ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('select * from Client');
SQL.Add('where 員工編號(hào)='+''''+CBox_ID.Text+'''');
SQL.Add('and 登錄口令='+''''+Ed_pwd.Text+'''');
Open;
end;
if ADOQuery1.RecordCount>0 then
begin
Showmessage('本地登錄成功,你可以瀏覽你的考勤歷史記錄!');
Btn_History.Enabled:=True;
Btn_Search.Enabled:=True;
Statusbar1.Panels[0].Text:='本地登錄完成!';
CBox_ID.Enabled:=False;
end
else Showmessage('本地登錄失敗!');
Exit;
end;
if Btn_login.Caption='登錄' then
begin
Clientsocket1.Host:=Ed_host.Text;
Clientsocket1.Port:=strtoint(Ed_port.text);
Clientsocket1.Active:=True;
Statusbar1.Panels[0].Text:='開始連接....';
end
else
begin
Clientsocket1.Active:=False;
Statusbar1.Panels[0].Text:='已和服務(wù)器斷開!';
Btn_login.Caption:='登錄';
CBox_ID.Enabled:=True;
end;
end;
procedure TFrClient.ClientSocket1Connect(Sender: TObject;
Socket: TCustomWinSocket);
var Data:Tstringlist;
begin
try
Data:=Tstringlist.Create;
Data.Clear;
Data.Values['login']:='login';
Data.Values['user']:=CBox_ID.Text;
Data.Values['password']:=Ed_Pwd.Text;
socket.SendText(data.text);
finally
data.free;
end;
end;
procedure TFrClient.ClientSocket1Read(Sender: TObject;
Socket: TCustomWinSocket);
var temp:string;
begin
temp:=socket.ReceiveText;
if temp='登錄成功' then
begin
Btn_Go.Enabled:=True;
Btn_Over.Enabled:=True;
Btn_History.Enabled:=True;
Statusbar1.Panels[0].Text:='登錄成功';
CBox_ID.Enabled:=False;
Btn_Search.Enabled:=True;
if not CBox_record.Checked then Ed_Pwd.Text:='';
Btn_login.Caption:='斷開';
end;
if temp='登錄失敗' then
begin
Btn_Go.Enabled:=False;
Btn_Over.Enabled:=False;
Btn_History.Enabled:=False;
ClientSocket1.Active:=False;
Statusbar1.Panels[0].Text:='非法員工,登錄失敗';
CBox_ID.Enabled:=True;
Ed_Pwd.Text:='';
end;
showmessage(temp);
end;
procedure TFrClient.ClientSocket1Connecting(Sender: TObject;
Socket: TCustomWinSocket);
begin
Statusbar1.Panels[0].Text:='請(qǐng)稍等,正在連接....';
end;
procedure TFrClient.ClientSocket1Disconnect(Sender: TObject;
Socket: TCustomWinSocket);
var Data:Tstringlist;
begin
try
Data:=Tstringlist.Create;
Data.Clear;
Data.Values['Close']:='Close';
Data.Values['user']:=CBox_ID.Text;
socket.SendText(data.text);
finally
data.free;
end;
end;
procedure TFrClient.ClientSocket1Error(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
begin
if errorcode=10061 then
if messageBox(Handle,'遠(yuǎn)程服務(wù)器沒有啟動(dòng),是否用本地登錄?','登錄確認(rèn)',Mb_iconQuestion or Mb_YesNo)=IDYES then
begin
CBox_local.Checked:=True;
Statusbar1.Panels[0].Text:='正在進(jìn)行本地登錄...';
Btn_login.Click;
end
else Statusbar1.Panels[0].Text:='服務(wù)器沒有啟動(dòng),登錄失敗!';
errorcode:=0;
end;
procedure TFrClient.Btn_GoClick(Sender: TObject);
var Data:Tstringlist;
begin
try
Data:=Tstringlist.Create;
Data.Clear;
Data.Values['GoWork']:='GoWork';
Data.Values['user']:=CBox_ID.Text;
Clientsocket1.socket.SendText(data.text);
if CBox_record.Checked then
begin
ADOQuery1.Connection:=FrClient.ADOConnection1;
if Search(CBox_ID.Text,'正在上班') then Exit;
with ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('insert into Client(員工編號(hào),登錄口令,考勤日期,上班時(shí)間,上班狀態(tài))');
SQL.Add('values('+''''+CBox_ID.Text+''''+','+''''+Ed_pwd.Text+''''+','+''''+datetostr(date)+''''+','+''''+timetostr(time)+''''+','+'"正在上班"'+')');
ExecSQL;
end;
end;
finally
data.free;
Working;
end;
end;
procedure TFrClient.Btn_OverClick(Sender: TObject);
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -