controle de acesso hora de entrada e hora de saida

Delphi

26/05/2020

alguem me ajuda urgente porvafor estou fazendo um programa que controla acesso de funcionarios
quando alguem passa pela porta o programa mostra assim um exemplo
quando eu entro
nome | cod_pessoa |matricula | codigoDeBarras | departamento |Data_Entrada | Data_Saida | perfil_Acesso
lucas| 1 |123 |555 |Sala |2020-05-21 11:00 | 'nuloo n aparece nd'| teste
qunado eu saio
nome | cod_pessoa |matricula | codigoDeBarras | departamento |Data_Entrada | Data_Saida | perfil_Acesso
lucas| 1 |123 |555 |Sala |2020-05-21 11:00 | 2020-05-21 11:10 | teste
quando outro funcionario entra
nome | cod_pessoa |matricula | codigoDeBarras | departamento |Data_Entrada | Data_Saida | perfil_Acesso
teste| 2 |123 |555 |Sala |2020-05-21 12:00 | 'nuloo n aparece nd'| teste
lucas| 1 |123 |555 |Sala |2020-05-21 11:00 | 2020-05-21 11:10 | teste
qunado eu saio
nome | cod_pessoa |matricula | codigoDeBarras | departamento |Data_Entrada | Data_Saida | perfil_Acesso
teste| 2 |123 |555 |Sala |2020-05-21 12:00 | 2020-05-21 13:10| teste
lucas| 1 |123 |555 |Sala |2020-05-21 11:00 | 2020-05-21 11:10 | teste
e assim vai
eu estava fazendo assim porem quando eu entro ele deixa o valo da saida do outro funicionario no grid
nome | cod_pessoa |matricula | codigoDeBarras | departamento |Data_Entrada | Data_Saida | perfil_Acesso
teste| 2 |123 |555 |Sala |2020-05-21 12:00 | 2020-05-21 13:10| teste
lucas| 1 |123 |555 |Sala |2020-05-21 11:00 |'aqui ele deixa vazio e o valor de sima da saida é dessa pessoa ' | teste
procedure TformEasyInnerOnLine.Pesquisar_Registros;
begin
with ADO_ult_atualiza, SQL do
begin
Clear;
Close;
Add('select max(cast(a.DataHora as date)) ult_data from [TopAcesso].[dbo].[Bilhetes] a');
Open;
end;
with ADO_Funcionario, SQL do
begin
Clear;
Close;
Add('select a.nome, a.COD_PESSOA, a.MATRICULA,C.CodigoDeBarras, CAST(b.DataHora as datetime) data_acesso ');
Add('from [TopAcesso].[dbo].[Funcionarios] a, ');
Add(' [TopAcesso].[dbo].[Bilhetes] b, ');
Add(' [TopAcesso].[dbo].[Cartoes] c ');
Add('where a.COD_PESSOA = b.COD_PESSOA AND A.COD_PESSOA = C.COD_PESSOA ');
Add('and b.Tipo = 10 ');
if ((Copy(CB_Departamentos.Text,1,2) = '00') OR (Copy(CB_Departamentos.Text,1,2) = '**')) then
begin
Add(' UNION all ');
Add(' select x.nome, x.COD_PESSOA, x.DOCUMENTO, '''+'Visitante'+''', CAST(y.DataHora as date) data_acesso ');
Add(' from [TopAcesso].[dbo].[Visitantes] x, ');
Add(' [TopAcesso].[dbo].[Bilhetes] y ');
Add(' where x.COD_PESSOA = y.COD_PESSOA ');
Add(' and y.Tipo = 10 ');
end;
Add(' order by data_acesso desc');
Open;
end;
begin
for lin := 1 to StringGrid1.RowCount - 1 do
for col := 0 to StringGrid1.ColCount - 1 do
StringGrid1.Cells[col, lin] := '';
end;
StringGrid1.CELLS[0, I] := ' ';
StringGrid1.CELLS[1, I] := ' ';
StringGrid1.CELLS[2, I] := ' ';
StringGrid1.CELLS[3, I] := ' ';
StringGrid1.CELLS[4, I] := ' ';
StringGrid1.CELLS[5, I] := ' ';
StringGrid1.CELLS[6, I] := ' ';
StringGrid1.CELLS[7, I] := ' ';
StringGrid1.ColWidths[0] := 130;
StringGrid1.ColWidths[1] := 350;
StringGrid1.ColWidths[2] := 135;
StringGrid1.ColWidths[3] := 105;
StringGrid1.ColWidths[4] := 95;
StringGrid1.ColWidths[5] := 95;
StringGrid1.ColWidths[6] := 200;
StringGrid1.ColWidths[7] := 150;
StringGrid1.CELLS[0, 0] := 'Matricula/Doc.';
StringGrid1.CELLS[1, 0] := 'Nome';
StringGrid1.CELLS[2, 0] := 'Cartão';
StringGrid1.CELLS[3, 0] := 'Data';
StringGrid1.CELLS[4, 0] := 'Entrada';
StringGrid1.CELLS[5, 0] := 'Saida';
StringGrid1.CELLS[6, 0] := 'Departamento';
StringGrid1.CELLS[7, 0] := 'Perfil Acesso';
StringGrid1.RowCount := 1;
while not ADO_Funcionario.EOF DO
begin
for i := 0 to ADO_Funcionario.RecordCount - 1 do
begin
if ADO_Funcionario.FieldByName('CodigoDeBarras').AsString <> 'Visitante' then
begin
with ADO_pesquisa, SQL do
begin
Clear;
Close;
Add('select distinct b.descricao ');
Add('from [TopAcesso].[dbo].[Funcionarios] a, [TopAcesso].[dbo].[departamentos] b where a.COD_departamento = b.COD_departamento ');
Add('and a.cod_pessoa = :wpessoa_dep ');
Parameters.ParamByName('wpessoa_dep').Value := ADO_Funcionario.FieldByName('COD_PESSOA').AsInteger;
Open;
end;
sdepartamento := ADO_pesquisa.FieldByName('DESCRICAO').AsString;

with ADO_pesquisa, SQL do
begin
Clear;
Close;
Add('select distinct b.descricao ');
Add('from [TopAcesso].[dbo].[Funcionarios] a, [TopAcesso].[dbo].[PerfisDeAcesso] b where a.COD_PERFIL = b.COD_PERFIL');
Add('and a.cod_pessoa = :wpessoa_dep');
Parameters.ParamByName('wpessoa_dep').Value := ADO_Funcionario.FieldByName('COD_PESSOA').AsInteger;
Open;
end;
sperfilacesso := ADO_pesquisa.FieldByName('DESCRICAO').AsString;
end
else
begin
sdepartamento := 'Externo';
with ADO_pesquisa, SQL do
begin
Clear;
Close;
Add('select distinct b.descricao ');
Add('from [TopAcesso].[dbo].[Visitantes] a, [TopAcesso].[dbo].[PerfisDeAcesso] b where a.COD_PERFIL = b.COD_PERFIL ');
Add('and a.cod_pessoa = :wpessoa_dep');
Parameters.ParamByName('wpessoa_dep').Value := ADO_Funcionario.FieldByName('COD_PESSOA').AsInteger;
Open;
end;
sperfilacesso := ADO_pesquisa.FieldByName('DESCRICAO').AsString;
end;
data_movimento := Copy(ADO_Funcionario.fieldbyName('data_acesso').AsString,1,2) + '/' +
Copy(ADO_Funcionario.fieldbyName('data_acesso').AsString,4,2) + '/' +
Copy(ADO_Funcionario.fieldbyName('data_acesso').AsString,7,4);
StringGrid1.CELLS[0, I+1] := ADO_Funcionario.FieldByName('MATRICULA').AsString;
StringGrid1.CELLS[1, I+1] := ADO_Funcionario.FieldByName('NOME').AsString;
StringGrid1.CELLS[2, I+1] := ADO_Funcionario.FieldByName('CodigoDeBarras').AsString;
StringGrid1.CELLS[3, I+1] := data_movimento ;
StringGrid1.CELLS[6, I+1] := sdepartamento;
StringGrid1.CELLS[7, I+1] := sperfilacesso;
DATA_ENTRADA := copy(ADO_Funcionario.FieldByname('data_acesso').value,11,3)+':'+copy(ADO_Funcionario.FieldByname('data_acesso').value,15,2)+':'
+copy(ADO_Funcionario.FieldByname('data_acesso').value,18,2);
StringGrid1.CELLS[4,I+1] := DATA_ENTRADA;
ADO_Funcionario.Next;
end;
end;
with ADO_Funcionarios, SQL do
begin
Clear;
Close;
Add('select a.nome, a.COD_PESSOA, a.MATRICULA,C.CodigoDeBarras, CAST(b.DataHora as datetime) data_acesso ');
Add('from [TopAcesso].[dbo].[Funcionarios] a Add('from [TopAcesso].[dbo].[Funcionarios] a, ');
Add(' [TopAcesso].[dbo].[Bilhetes] b, ');
Add(' [TopAcesso].[dbo].[Cartoes] c ');
Add('where a.COD_PESSOA = b.COD_PESSOA AND A.COD_PESSOA = C.COD_PESSOA ');
Add('and b.Tipo = 11 ');
if ((Copy(CB_Departamentos.Text,1,2) = '00') OR (Copy(CB_Departamentos.Text,1,2) = '**')) then
begin
Add(' UNION all ');
Add(' select x.nome, x.COD_PESSOA, x.DOCUMENTO, '''+'Visitante'+''', CAST(y.DataHora as date) data_acesso ');
Add(' from [TopAcesso].[dbo].[Visitantes] x, ');
Add(' [TopAcesso].[dbo].[Bilhetes] y ');
Add(' where x.COD_PESSOA ');
Add(' and y.Tipo = 11 ');
end;
Add('order by data_acesso desc');
Open;
while not ADO_Funcionarios.EOF DO
begin
for i := 0 to ADO_Funcionarios.RecordCount - 1 do
begin
StringGrid1.RowCount := StringGrid1.RowCount + 1;
DATA_saida := copy(ADO_Funcionarios.FieldByname('data_acesso').value,11,3)+':'+copy(ADO_Funcionarios.FieldByname('data_acesso').value,15,2)+':'
+copy(ADO_Funcionarios.FieldByname('data_acesso').value,18,2);
StringGrid1.CELLS[5,I+1] := DATA_saida;
ADO_Funcionarios.Next;
end;
end;
//y.tipo 10 seria entrada y.tipo 11 saida
Lucas

Lucas

Curtidas 0

Melhor post

Leandro Carvalho

Leandro Carvalho

01/06/2020

Pergunta 1: Está salvando corretamente no BD? Pergunta 2: Por que fazer todo esse trabalho em apresentar em um StringGrid? Por que não usar o DBGrid?
GOSTEI 1

Mais Respostas

Lucas

Lucas

26/05/2020

Pergunta 1: Está salvando corretamente no BD? Pergunta 2: Por que fazer todo esse trabalho em apresentar em um StringGrid? Por que não usar o DBGrid?

ja consegui arrumar obrigado
GOSTEI 0
POSTAR