?? uclient.~pas
字號:
var Data:Tstringlist;
begin
try
Data:=Tstringlist.Create;
Data.Clear;
Data.Values['OverWork']:='OverWork';
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
with ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('update Client set 下班時間='+''''+timetostr(time)+''''+',上班狀態='+'"結束上班"');
SQL.Add('where 員工編號='+''''+CBox_ID.Text+'''');
ExecSQL;
end;
end;
finally
data.free;
Working;
end;
end;
Function Search(tempID:string;tempstatus:string):bool;
var MADOQuery:TADOQuery;
begin
MADOQuery:=TADOQuery.Create(Application);
MADOQuery.Connection:=FrClient.ADOConnection1;
try
with MADOQuery do
begin
Close;
SQL.Clear;
SQL.Add('select * from Client');
SQL.Add('where 上班狀態='+''''+tempstatus+'''');
SQL.Add('and 員工編號='+''''+tempID+'''');
Open;
end;
if MADOQuery.RecordCount>0 then result:=True
else Result:=False;
finally
MADOQuery.Free;
end;
end;
procedure TFrClient.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
MiniFile:=Tinifile.Create(extractfilepath(application.exename)+'Client.ini');
MiniFile.WriteString('SET','host',Ed_host.Text);
MiniFile.WriteString('SET','port',Ed_port.Text);
MiniFile.WriteString('SET','id',CBox_id.Text);
MiniFile.WriteBool('SET','local',CBox_local.Checked);
MiniFile.WriteBool('SET','time',CBox_time.Checked);
MiniFile.WriteBool('SET','record',CBox_record.Checked);
MiniFile.Free;
ClientSocket1.Active:=False;
end;
procedure TFrClient.FormShow(Sender: TObject);
var temptime:string;
begin
working;
if fileexists(extractfilepath(application.exename)+'Client.ini') then
begin
MiniFile:=Tinifile.Create(extractfilepath(application.exename)+'Client.ini');
Ed_host.Text:=MiniFile.ReadString('SET','host','');
Ed_port.Text:=MiniFile.ReadString('SET','port','');
CBox_ID.Text:=MiniFile.ReadString('SET','ID','');
CBox_local.Checked:=MiniFile.ReadBool('SET','local',True);
CBox_time.Checked:=MiniFile.ReadBool('SET','time',True);
CBox_record.Checked:=MiniFile.ReadBool('SET','record',True);
MiniFile.Free;
end;
if CBox_time.Checked then
begin
try
IdTime1.Host:=Ed_host.Text;
temptime:=formatdatetime('yyyy-mm-dd hh:mm',IdTime1.DateTime);
if temptime<>formatdatetime('yyyy-mm-dd hh:mm',now) then
if MessageBox(handle,Pchar('服務器時間:'+datetimetostr(IdTime1.DateTime)+',本地時間和服務器時間不一致,是否修改?'),'時間確認',Mb_IconQuestion or Mb_YESNO)=IDYES then
winexec('rundll32.exe shell32.dll,Control_RunDLL timedate.cpl',9);
except
end;
end;
end;
procedure TFrClient.FormCreate(Sender: TObject);
begin
if not fileexists(extractfilepath(application.ExeName)+'Db\db_Client.mdb') then
begin
CBox_record.Checked:=False;
CBox_record.Enabled:=False;
MessageBox(handle,Pchar('數據庫文件找不到,請檢查'+extractfilepath(application.exename)+'Db目錄下的數據庫文件'),'數據庫文件丟失',Mb_iconinformation);
exit;
end;
ADOConnection1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+extractfilepath(application.ExeName)+'Db\db_Client.mdb'+';Persist Security Info=False';
ADOConnection1.Connected:=True;
end;
procedure worked(str:string);
var i,j:integer;
begin
With Frclient.ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('select 員工編號,考勤日期,上班時間,下班時間 from Client');
SQL.Add('where 員工編號='+''''+FrClient.CBox_ID.Text+'''');
SQL.Add('order by 考勤日期 desc');
open;
end;
with FrClient do
begin
for i:=0 to Stringgrid1.RowCount do
for j:=1 to 6 do
stringgrid1.Cells[j,i]:='';
if ADOQuery1.RecordCount>5 then Stringgrid1.RowCount:=ADOQuery1.RecordCount+1;
if ADOQuery1.RecordCount>0 then
for i:=1 to ADOQuery1.RecordCount do
begin
Stringgrid1.Cells[0,0]:='序號';
stringgrid1.Cells[1,0]:='員工編號';
Stringgrid1.Cells[2,0]:='考勤日期';
Stringgrid1.Cells[3,0]:='上班時間';
stringgrid1.Cells[4,0]:='下班時間';
Stringgrid1.Cells[0,i]:=inttostr(i);
Stringgrid1.Cells[1,i]:=AdoQuery1.fieldbyname('員工編號').AsString;
Stringgrid1.Cells[2,i]:=AdoQuery1.fieldbyname('考勤日期').AsString;
Stringgrid1.Cells[3,i]:=AdoQuery1.fieldbyname('上班時間').AsString;
Stringgrid1.Cells[4,i]:=AdoQuery1.fieldbyname('下班時間').AsString;
if not ADOQuery1.Eof then ADOQuery1.Next;
end;
end;
end;
procedure working;
var i,j:integer;
begin
FrClient.ADOQuery1.Connection:=FrClient.ADOConnection1;
With Frclient.ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('select distinct 員工編號,考勤日期,上班時間,下班時間 from Client');
SQL.Add('where 上班狀態='+'"正在上班"');
SQL.Add('order by 員工編號');
open;
end;
with FrClient do
begin
for i:=0 to Stringgrid1.RowCount do
for j:=1 to 6 do
stringgrid1.Cells[j,i]:='';
if ADOQuery1.RecordCount>5 then Stringgrid1.RowCount:=ADOQuery1.RecordCount+1;
if ADOQuery1.RecordCount>0 then
for i:=1 to ADOQuery1.RecordCount do
begin
CBox_ID.Items.Add(AdoQuery1.fieldbyname('員工編號').AsString);
Stringgrid1.Cells[0,0]:='序號';
stringgrid1.Cells[1,0]:='員工編號';
Stringgrid1.Cells[2,0]:='考勤日期';
Stringgrid1.Cells[3,0]:='上班時間';
stringgrid1.Cells[4,0]:='下班時間';
Stringgrid1.Cells[0,i]:=inttostr(i);
Stringgrid1.Cells[1,i]:=AdoQuery1.fieldbyname('員工編號').AsString;
Stringgrid1.Cells[2,i]:=AdoQuery1.fieldbyname('考勤日期').AsString;
Stringgrid1.Cells[3,i]:=AdoQuery1.fieldbyname('上班時間').AsString;
Stringgrid1.Cells[4,i]:=AdoQuery1.fieldbyname('下班時間').AsString;
if not ADOQuery1.Eof then ADOQuery1.Next;
end;
end;
end;
procedure TFrClient.Btn_HistoryClick(Sender: TObject);
begin
worked(CBox_ID.Text);
end;
procedure TFrClient.Btn_SearchClick(Sender: TObject);
var tempY,tempM,tempD:word;
temp:string;
i,j:integer;
begin
decodedate(datetimepicker1.Date,tempY,tempM,tempD);
temp:=inttostr(tempY)+'-'+inttostr(tempM)+'-'+inttostr(tempD);
delete(temp,1,2);
With Frclient.ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('select 員工編號,考勤日期,上班時間,下班時間 from Client');
SQL.Add('where 員工編號='+''''+FrClient.CBox_ID.Text+'''');
SQL.Add('and 考勤日期='+''''+temp+'''');
SQL.Add('order by 考勤日期 desc');
open;
end;
with FrClient do
begin
for i:=0 to Stringgrid1.RowCount do
for j:=1 to 6 do
stringgrid1.Cells[j,i]:='';
if ADOQuery1.RecordCount>5 then Stringgrid1.RowCount:=ADOQuery1.RecordCount+1;
if ADOQuery1.RecordCount>0 then
for i:=1 to ADOQuery1.RecordCount do
begin
Stringgrid1.Cells[0,0]:='序號';
stringgrid1.Cells[1,0]:='員工編號';
Stringgrid1.Cells[2,0]:='考勤日期';
Stringgrid1.Cells[3,0]:='上班時間';
stringgrid1.Cells[4,0]:='下班時間';
Stringgrid1.Cells[0,i]:=inttostr(i);
Stringgrid1.Cells[1,i]:=AdoQuery1.fieldbyname('員工編號').AsString;
Stringgrid1.Cells[2,i]:=AdoQuery1.fieldbyname('考勤日期').AsString;
Stringgrid1.Cells[3,i]:=AdoQuery1.fieldbyname('上班時間').AsString;
Stringgrid1.Cells[4,i]:=AdoQuery1.fieldbyname('下班時間').AsString;
if not ADOQuery1.Eof then ADOQuery1.Next;
end;
end;
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -