One line information of the first StringGrid (Delphi)

0

Follow the code:

    procedure TfrmGrid.sgCuponsDblClick(Sender: TObject);
var
  txt: TextFile;
  l, i : integer;
  lTemp, CFF, COO: String;
begin
    i:=0;
    l:=0;
    CFF := sgCupons.Cells[0,sgCupons.Row];
    COO := sgCupons.Cells[1,sgCupons.Row];

      AssignFile(txt, lbCaminho.Caption);
      Reset(txt);
      while not eof(txt) do
          begin
            Readln(txt, lTemp);
              if (copy(lTemp, 1, 3) = 'E15')
              and (copy(lTemp,47,6 = CFF))
              and (copy(lTemp,53,6) = COO)
              then
              begin
              inc(i);
              sgItens.RowCount:=i;
              ShowMessage(CFF+' '+COO);
              end;
          end;
      CloseFile(txt);
      ShowMessage('Existem '+IntToStr(i)+' linhas.');


    if (sgCupons.Row <> 0) then
    begin
      AssignFile(txt, lbCaminho.Caption);
      Reset(txt);
      while not eof(txt) do
          begin
          Readln(txt, lTemp);
              if (copy(lTemp, 1, 3) = 'E15')
              and (copy(lTemp,47,6) = CFF)
              and (copy(lTemp,53,6) = COO)
              then
                  begin
                  sgItens.Enabled := True;
                  inc(l);
                  //Ordem
                  //sgItens.Cells[0,l] := copy();
                  //Codigo
                  sgItens.Cells[1,l] := copy(lTemp,62 ,14);
                  //Descricao
                  sgItens.Cells[2,l] := copy(lTemp,76, 100);
                  //Qtde
                  sgItens.Cells[3,l] := copy(lTemp,176, 7);
                  //Pr. Unitario
                  sgItens.Cells[4,l] := copy(lTemp, 186, 8);
                  //Pr. Total
                  sgItens.Cells[5,l] := copy(lTemp, 210, 14);
                  //Antiquota
                  sgItens.Cells[6,l] := copy(lTemp, 0, 0);
                  end;
          end;
      CloseFile(txt);
    end;
    if not (sgCupons.Row <> 0) then
    sgItens.Enabled := false;
end;

In fact, something is missing, but I would like you to help me ...

What I want is the following, in the first StringGrid has the Coupons (E14), and the Coupons have subitems (E13), that is, when I double click on a coupon (StringGrid1), the subitems of the selected coupon would go to StringGrid2.

I know it's basically a loop, but does anyone have any suggestions or ideas?

The code informed is of the subitems

    
asked by anonymous 07.05.2014 / 15:46

1 answer

1

Here is the answer:

procedure TfrmGrid.sgCuponsDblClick(Sender: TObject);
var
  txt: TextFile;
  l, mp, i: integer;
  lTemp, CCF, COO: String;
  cont, valorTotal, valorPago, troco: double;
begin
    CCF := sgCupons.Cells[1,sgCupons.Row];
    COO := sgCupons.Cells[0,sgCupons.Row];

    if (sgCupons.Row <> 0) then
      begin
        i:=0;
        l:=0;
        AssignFile(txt, lbCaminho.Caption);
        Reset(txt);
        while not eof(txt) do
          begin
            Readln(txt, lTemp);
            if (copy(lTemp, 1, 3) = 'E15')
            and (copy(lTemp, 53, 6) = CCF)
            and (copy(lTemp,47,6) = COO)
            then
              begin
                inc(i);
                sgItens.RowCount:=i+1;

                inc(l);
                //Ordem
                sgItens.Cells[0,l] := COO;
                //Codigo
                sgItens.Cells[1,l] := copy(lTemp,62 ,14);
                //Descricao
                sgItens.Cells[2,l] := copy(lTemp,76, 100);
                //Qtde
                sgItens.Cells[3,l] := FloatToStr(StrToFloat(copy(lTemp,176, 7)) / 1000);
                //Pr. Unitario
                sgItens.Cells[4,l] := FloatToStr(StrToFloat(copy(lTemp, 186, 8)) / 100);
                //Pr. Total
                sgItens.Cells[5,l] := FloatToStr(StrToFloat(copy(lTemp, 210, 14)) / 100);
                if (copy(lTemp, 231, 1) = 'N') then
                begin
                cont :=  StrToFloat(sgItens.Cells[5,l]);
                valorTotal:=valorTotal+cont;
                end;

                //Anliquota
                sgItens.Cells[6,l] := copy(lTemp, 224, 7);
              end;
          end;
        CloseFile(txt);
       StatusBar1.Panels[1].Text := 'Existem '+IntToStr(i)+' Itens.';

        AssignFile(txt, lbCaminho.Caption);
        Reset(txt);

        mp:= 0;
        l := 0;
        while not eof(txt) do
            begin
            Readln(txt, lTemp);
              if (copy(lTemp, 1, 3) = 'E21')
              and (copy(lTemp, 53, 6) = CCF)
              and (copy(lTemp,47,6) = COO)
              then
                begin
                  inc(mp);
                  sgFinalizadoras.RowCount := mp+1;

                  inc(l);
                  //COO
                  sgFinalizadoras.Cells[0,l] := copy(lTemp,47,6);
                  //CCF
                  sgFinalizadoras.Cells[1,l] := copy(lTemp, 53, 6);
                  //Meio de pagamento
                  sgFinalizadoras.Cells[2,l] := copy(lTemp, 65, 15);
                  //Valor Pago
                  sgFinalizadoras.Cells[3,l] := FloatToStr(StrToFloat(copy(lTemp, 80, 13)) /100);
                  valorPago:=StrToFloat(copy(lTemp, 80, 13))/100;
                end;
            end;
            CloseFile(txt);
            StatusBar1.Panels[0].Text := 'Existem ' + IntToStr(mp)+' Meios de pagamento.';

          //Valor Líquido Total
          Edit1.Text := FloatToStr(valorTotal);

          //Troco
          troco:= (valorPago - valorTotal);
          Edit2.Text := FormatFloat('#,##0.00',troco);
      end;
end;

It is working correctly and without errors. If you need, code is partially commented.

    
21.05.2014 / 14:08