Fortes Report + Masks

Asked

Viewed 1,379 times

0

Does anyone know how to format a CPF/CNPJ in a report in the Forte Report?

procedure TFRelMenLac.RLBand4BeforePrint(Sender: TObject; var PrintIt: Boolean);
var
  ltemp : string;
begin
  ltemp := dmretaguarda.qlac.fieldbyname('dccli').asstring;
  if length(ltemp) = 11 then
    begin
      rlldccli.Caption := 'CPF: ';
      //RLDBText29.DisplayMask := '000.000.000-00';

      RLDBText29.Text := copy(ltemp, 1,3)+'.'+copy(ltemp, 4,3)+'.'+copy(ltemp, 7,3)+'-'+copy(ltemp, 10,2);
    end
  else
    begin
      rlldccli.Caption := 'CNPJ: ';
      RLDBText29.Text := copy(ltemp, 1,3)+'.'+copy(ltemp, 4,3)+'.'+copy(ltemp,7,3)+'/'+copy(ltemp, 10,4)+'-'+copy(ltemp, 14,2);
    end;
      //RLDBText29.DisplayMask := '000.000.000/0000-00';

Aside from the commented areas, I tried with the Copy, but unsuccessfully, some idea?

----- Edit -----

 DMRetaguarda.QLac.close;
  DMRetaguarda.QLac.sql.clear;
  DMRetaguarda.QLac.SQL.Add('SELECT relinm.mattec, relinm.nmtec, relinm.nmequip, relinm.num_os, relinm.num_sel, relinm.dtpront, relinm.marca, relinm.modelo, relinm.matric, relinm.peso, relinm.num_lac, relinm.numinm,');
  DMRetaguarda.QLac.SQL.Add('cliente.razaosocial, cliente.cidade as clcid, cliente.uf as cluf, cliente.rua as clru, cliente.bairro as clbr, cliente.cep as clcp, cliente.chave, CASE WHEN cliente.cgc <> '''' THEN cliente.cgc ELSE cliente.cpf END AS dccli ');
  DMRetaguarda.QLac.SQL.Add('FROM relinm, cliente WHERE relinm.codcli = cliente.chave AND relinm.dtpront BETWEEN :pini AND :pfim ORDER BY relinm.mattec, relinm.nmequip, relinm.dtpront');
  DMRetaguarda.QLac.ParamByName('pini').AsDate := StrToDateTime(
    MaskEdit1.Text);
  DMRetaguarda.QLac.ParamByName('pfim').AsDate := StrToDateTime(
    MaskEdit2.Text);
  DMRetaguarda.QLac.open;

---- Edit2 ----

  if length(DMRetaguarda.QLac.FieldByName('dccli').AsString) = 11 then
  begin
    rlldccli.Caption := 'CPF: ';
    DMRetaguarda.QLac.FieldByName('dccli').EditMask := '999.999.999-99;0;_'
    //RLDBText29.DisplayMask := '000.000.000\-99;1;_';
    //RLDBText29.Text := copy(ltemp, 1,3)+'.'+copy(ltemp, 4,3)+'.'+copy(ltemp, 7,3)+'-'+copy(ltemp, 10,2);
  end
  else
  begin
    rlldccli.Caption := 'CNPJ: ';
    DMRetaguarda.QLac.FieldByName('dccli').EditMask := '99.999.999/9999-99;0;_';
    //RLDBText29.Text := copy(ltemp, 1,3)+'.'+copy(ltemp, 4,3)+'.'+copy(ltemp,7,3)+'/'+copy(ltemp, 10,4)+'-'+copy(ltemp, 14,2);
    //RLDBText29.DisplayMask := '000.000.000\0000-99;1;_';
  end;

Follow my Qlac. Any ideas?

It was like this my code but is all scrambled in some fields, IE, follows the image:

inserir a descrição da imagem aqui

I believe that by the format of to understand that it was wrong, however it is not at all, many are right, some idea of how to proceed?

  • Anyone? Any ideas? @Caputo

  • @Filipe.Fonseca, some idea?

  • You can implement this in Tfield’s Gettext or Set the Mask to Tfield, have tried?

  • @Caputo, I tried not dude :/, there’s some example of how I would do it?

  • Please add in the question the snippet where the query dtmretaguarda.qlac is open to report generation and the report is executed. I set the example right where it should be.

  • 1

    @Caputo, sorry for the delay, I was sick, I will post as soon as possible. Thanks

  • @Caputo, follow my query. Thanks, I await return.

  • What Query component you are using?

  • @wesleyluan, Tzquery, ZEOS component.

  • @wesleyluan, put the image and the code after edited.

  • When you change the field mask which is CPF the size of it is no longer 11, the field will have dots and dash.

Show 6 more comments

2 answers

1

Here’s what I do, on Afteropen of the component Query I determine the mask of self Tfield.

DataSet.FieldByName('CNPJ').EditMask := '99.999.999/9999-99;0;_';
DataSet.FieldByName('CPF').EditMask := '999.999.999-99;0;_';
  • Dude, it almost worked, only I made the changes put to get CPF when it’s CPF, and CNPJ when it’s CNPJ, however, some areas were changed, ie, Cpf no cnpj, and cnpj no Cpf...

  • What you can do is leave one field for CPF and another for CGC even, removing the case from SQL and placing a label for each field in the same position in the report. For one or the other will always be empty.

0


Gentlemen, I managed to solve this problem with Wesley’s help.

The only problem was the moment I was picking up the values, the Forts has 2 steps, Prepare and Show... so, in my code above, I was showing after picking up the Cpf/cnpj values, and before showing the report, consequently the problem was in the EVENTO.

So all I did was put on evento do relatório called, OnDataRecord, goes below:

procedure TFRelMenLac.RLReport1DataRecord(Sender: TObject; RecNo,
  CopyNo: Integer; var Eof: Boolean; var RecordAction: TRLRecordAction);
begin
  if length(DMRetaguarda.QLac.FieldByName('dccli').AsString) = 11 then
  begin
    rlldccli.Caption := 'CPF: ';
    DMRetaguarda.QLac.FieldByName('dccli').EditMask := '999.999.999-99;0;_';
  end;
  if length(DMRetaguarda.QLac.FieldByName('dccli').AsString) = 14 then
  begin
    rlldccli.Caption := 'CNPJ: ';
    DMRetaguarda.QLac.FieldByName('dccli').EditMask := '99.999.999/9999-99;0;_';
  end;
end;

And there, it worked like magic, thanks for the personal help.

Browser other questions tagged

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