0
procedure TfrmGrid.btnLoadClick(Sender: TObject);
var
txt: TextFile;
treg, lreg, dc: integer;
valortxt, valorbd : double;
dt1, dt2,lTemp, valor, dtcompratxt, numnf, coo,ccf: String;
dtcompra: TDateTime;
begin
lreg:= 1;
treg:= 0;
dc := 0;
StatusBar1.Panels[0].Text:= 'Abrindo arquivo de txt';
AssignFile(txt, frmSelection.FileListBox1.FileName);
Reset(txt);
while not eof(txt) do
begin
Readln(txt, lTemp);
if (copy(lTemp, 1, 3) = 'E14') then
begin
StatusBar1.Panels[0].Text:= 'Executando a query';
dtcompra:=StrToDate(copy(lTemp,65,2)+'/'+copy(lTemp,63,2)+'/'+copy(lTemp,59,4));
dtcompratxt:= FormatDateTime('dd/MM/yyyy', dtcompra);
DModuleGrid.ZQuery1.Close;
DModuleGrid.ZQuery1.SQL.Clear;
DModuleGrid.ZQuery1.SQL.Add('SELECT dtcompra, impcaixa, numcupom, ccf, valor FROM tdcupant');
DModuleGrid.ZQuery1.SQL.Add('WHERE numcupom = :co2 AND ccf = :cc3 AND dtcompra = :dtc4 AND impcaixa = :ip5');
DModuleGrid.ZQuery1.ParamByName('co2').AsString := copy(lTemp,53,6);
DModuleGrid.ZQuery1.ParamByName('cc3').AsString := copy(lTemp,47,6);
DModuleGrid.ZQuery1.ParamByName('ip5').AsString := copy(lTemp,4,20);
DModuleGrid.ZQuery1.ParamByName('dtc4').AsDate := StrToDate(dtcompratxt);
DModuleGrid.ZQuery1.Open;
if not (DModuleGrid.ZQuery1.IsEmpty) then
begin
StatusBar1.Panels[0].Text:= 'Executando o loop de consulta/comparação';
DModuleGrid.ZQuery1.First;
if (DModuleGrid.ZQuery1.FieldByName('numcupom').AsString = DModuleGrid.ZQuery1.ParamByName('co2').AsString)
and (DModuleGrid.ZQuery1.FieldByName('ccf').AsString = DModuleGrid.ZQuery1.ParamByName('cc3').AsString)
and (DModuleGrid.ZQuery1.FieldByName('dtcompra').AsDateTime = DModuleGrid.ZQuery1.ParamByName('dtc4').AsDate)
and (DModuleGrid.ZQuery1.FieldByName('impcaixa').AsString = DModuleGrid.ZQuery1.ParamByName('ip5').AsString)
then
begin
StatusBar1.Panels[0].Text:= 'Incrementando registros';
inc(lreg);
//Valor no BD
valorbd := DModuleGrid.ZQuery1.FieldByName('valor').AsFloat;
//Valor no TXT
valortxt := StrToFloat(copy(lTemp, 109, 14))/100;
//Diferença nos valores
if (valorbd <> valortxt) then
begin
inc(treg);
if (valor = '') then
begin
valor := IntToStr(0);
end
else
valor := IntToStr(treg);
end;
end
else
begin
inc(dc);
StatusBar1.Panels[0].Text:= 'Próximo registro';
end;
DModuleGrid.ZQuery1.Next;
end;
end;
end;
Label1.Caption := 'Divergências '+'Valor'+' Cupons: '+valor;
Label7.Caption := 'Divergência de cupons: '+ IntToStr(dc);
StatusBar1.Panels[0].Text:= 'Existem '+ IntToStr(lreg) + ' linhas de Cupons(E14)';
CloseFile(txt);
end;
Optimize database query and compress code
The context of the question is in the comments, but I will make it clear.
What I tried to do was a comparison of a . txt file with the data contained in DB. I managed to make the comparison with this code, remembering, the code works for comparison, but is not working for the data listing in Other Dbgrid.
It is using Dbgrid only for comparison and not for listing. Any idea?
The ping
@usuario
only works within the Comments for people involved in the post (question author, commentators, editors). Each Question should be self-sufficient by allowing anyone to answer. Please add details that better explain your problem.– brasofilo
@Ramonruan If this question is based on another, please put the link to understand the context.
– user7261
@Andrey, Follow the link and a brief explanation of what I did, Excuse the mistake. Thank you, I hope you can help me.
– Ramon Ruan
@Crood, I know yes dear... kkk, is why the following, the problem is that the selection was coming with the WHERE clause and with parameters, consequently was just comparing the data, had no pure selection function. I’ll post the code so you’ll understand better
– Ramon Ruan
@Crood, haha, really, I was only able to finish after allmoçar, but I’m down there. Please take a look. ;]
– Ramon Ruan