⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uclient.~pas

📁 delphi简单的考勤系统 使用tcp ip 协议 包括服务器端和客户端 使用了 ClientSocket和ServerSocket组件
💻 ~PAS
📖 第 1 页 / 共 2 页
字号:
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 + -