First Stringgrid (Delphi) line information

Asked

Viewed 649 times

0

Follows 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’d like you to help me...

What I want is this, in the first Stringgrid has the Coupons(E14), and the Coupons have subitens(E13), that is, when I double click on a coupon(Stringgrid1), the subitens 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 reported is the subitens

  • @Crood, everything worked out, I ended this system, however ngm had repondido, passed away.

1 answer

1


Below 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’s working correctly and error free. In case you need it, code is partially commented.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.