GARANTIR DESCONTO

Fórum Erro: is not a valid Integer value ! #365725

01/11/2008

0

Bom erro acontece neste código abaixo, não estou encontrado o motivo e o local do erro, preciso de ajuda !

if (rgTipoRel.ItemIndex = 1) and checkbox2.Checked then
     begin
      DM.ibdVendCliente.Close;
      DM.ibdVendCliente.SelectSQL.Clear;
      DM.ibdVendCliente.SelectSQL.Add(´SELECT T1.nome,T3.idproduto,T4.descricao,T2.datavenda,T3.quantidade,T3.vlrunitario,T3.desconto, sum(T3.quantidade * T3.vlrunitario) as total´);
      DM.ibdVendCliente.SelectSQL.Add(´FROM tb_cliente T1 INNER JOIN tb_venda T2 ON (T1.idcliente = T2.idcliente)´);
      DM.ibdVendCliente.SelectSQL.Add(´INNER JOIN tb_itemvenda T3 ON (T2.numvenda = T3.idvenda)´);
      DM.ibdVendCliente.SelectSQL.Add(´INNER JOIN tb_produto T4 ON (T3.idproduto = T4.idproduto)´);
      DM.ibdVendCliente.selectSQL.Add(´WHERE T2.datavenda BETWEEN :pDataIni and :pDataFin´);
      DM.ibdVendCliente.SelectSQL.Add(´GROUP BY T1.nome,T3.idproduto,T4.descricao,T2.datavenda,T3.quantidade,T3.vlrunitario,T3.desconto´);

      DM.ibdVendCliente.Active:= False;
      DM.ibdVendCliente.ParamByName(´pDataIni´).AsDate:= strtodate(DataIni.Text);
      DM.ibdVendCliente.ParamByName(´pDatafin´).AsDate:= strtodate(DataFin.Text);
      DM.ibdVendCliente.Open;

      DM.rvVendCliente.SetParam(´pDataIni´,DataIni.Text);
      DM.rvVendCliente.SetParam(´pDataFin´,DataFin.Text);
      DM.rvVendCliente.ExecuteReport(´Report1´);
     end
     else
     begin
      DM.ibdVendCliente.Close;
      DM.ibdVendCliente.SelectSQL.Clear;
      DM.ibdVendCliente.SelectSQL.Add(´SELECT T1.nome,T3.idproduto,T4.descricao,T2.datavenda,T3.quantidade,T3.vlrunitario,T3.desconto, sum(T3.quantidade * T3.vlrunitario) as total´);
      DM.ibdVendCliente.SelectSQL.Add(´FROM tb_cliente T1 INNER JOIN tb_venda T2 ON (T1.idcliente = T2.idcliente)´);
      DM.ibdVendCliente.SelectSQL.Add(´INNER JOIN tb_itemvenda T3 ON (T2.numvenda = T3.idvenda)´);
      DM.ibdVendCliente.SelectSQL.Add(´INNER JOIN tb_produto T4 ON (T3.idproduto = T4.idproduto)´);
      DM.ibdVendCliente.selectSQL.Add(´WHERE T2.datavenda BETWEEN :pDataIni and :pDataFin´);
      DM.ibdVendCliente.SelectSQL.Add(´AND T2.idcliente = :pCodigo´);
      DM.ibdVendCliente.SelectSQL.Add(´GROUP BY T1.nome,T3.idproduto,T4.descricao,T2.datavenda,T3.quantidade,T3.vlrunitario,T3.desconto´);

      DM.ibdVendCliente.Active:= False;
      DM.ibdVendCliente.ParamByName(´pDataIni´).AsDate:= strtodate(DataIni.Text);
      DM.ibdVendCliente.ParamByName(´pDatafin´).AsDate:= strtodate(DataFin.Text);
      DM.ibdVendCliente.ParamByName(´pCodigo´).AsInteger:= strtoint(Edit2.Text);
      DM.ibdVendCliente.Open;
      DM.rvVendCliente.SetParam(´pDataIni´,DataIni.Text);
      DM.rvVendCliente.SetParam(´pDataFin´,DataFin.Text);
      DM.rvVendCliente.SetParam(´pCodigo´,Edit2.Text);
      DM.rvVendCliente.ExecuteReport(´Report1´);
     end;
  end;



Afterdev

Afterdev

Responder

Posts

01/11/2008

Afterdev

Na verdade o que estou tentando fazer é o seguinte: tenho um filtro para um relatório de vendas, onde há um radiogroup com quantro opções de relatórios: vendas por produto, por cliente, por categoria e convenio, a partir disso no botão imprimir faço a seguinte condição: se radiogroup.itemIndex = 0 e checkbox1.checked então imprime todas as vendas de todos os produtos naquele período senão digito o código do produto no edit para imprimir somente aquele produto no período, o problema é já na segunda opção esse erro aparece, e aparentemente está igual ao primeiro que funciona corretamente.

Qual saio do erro o delphi retorna nessa nessas linhas

procedure TmenuPrin.acRelVendasExecute(Sender: TObject);
    begin
      FiltroRelVendas.ShowModal;
    end;


aguardo ajuda ........


Responder

Gostei + 0

01/11/2008

Martins

Você está montando um relatório no Rave é isso?

Esse parametro pCodigo é Integer ou String?

DM.rvVendCliente.SetParam(´pCodigo´,Edit2.Text); 


Pq se ele for Integer, vc terá q fazer a conversão.


Responder

Gostei + 0

01/11/2008

Afterdev

Você está montando um relatório no Rave é isso? Esse parametro pCodigo é Integer ou String?
DM.rvVendCliente.SetParam(´pCodigo´,Edit2.Text); 
Pq se ele for Integer, vc terá q fazer a conversão.


Martins, obrigado pela resposta, fiz nesta linha anterior essa conversão ! ou é outra conversão, e o relatório é no Rave sim.

DM.ibdVendCliente.ParamByName(´pCodigo´).AsInteger:= strtoint(Edit2.Text); 


valeu....


Responder

Gostei + 0

01/11/2008

Martins

DM.rvVendCliente.SetParam(´pCodigo´,Edit2.Text);

Não trablho com Rave, mas acho q vc vai ter q depurar para ver se o erro está neste trecho de código.

DM.ibdVendCliente.Active:= False; 
      DM.ibdVendCliente.ParamByName(´pDataIni´).AsDate:= strtodate(DataIni.Text); 
      DM.ibdVendCliente.ParamByName(´pDatafin´).AsDate:= strtodate(DataFin.Text); 
      DM.ibdVendCliente.ParamByName(´pCodigo´).AsInteger:= strtoint(Edit2.Text); 
      DM.ibdVendCliente.Open; 
      DM.rvVendCliente.SetParam(´pDataIni´,DataIni.Text); 
      DM.rvVendCliente.SetParam(´pDataFin´,DataFin.Text); 
      DM.rvVendCliente.SetParam(´pCodigo´,Edit2.Text); 
      DM.rvVendCliente.ExecuteReport(´Report1´); 


Tente mudar.

      DM.ibdVendCliente.ParamByName(´pCodigo´).AsInteger:= strtoint(Edit2.Text); 


Para

      DM.ibdVendCliente.ParamByName(´pCodigo´).AsString:= Edit2.Text; 


Sinto não poder ajudar mais.


Responder

Gostei + 0

01/11/2008

Martins

Dê uma olhada na voncersão de String para Inteiro, pq a mensagem de erro diz: [b:95a6018ae6]Não é uma valor inteiro válido[/b:95a6018ae6].

Boa sorte.


Responder

Gostei + 0

01/11/2008

Afterdev

Esse é o codigo no botão de Imprimir do filtro e o código abaixo é da primeira opção do radiogroup vendas por produtos e está funcionando normalmente, mas quando tento fazer as outras opções me retorna esse erro infeliz ........

procedure TFiltroRelVendas.btnImprimirClick(Sender: TObject);
begin
  with DM.ibdVendProd do
  begin
    if (rgTipoRel.ItemIndex = 0) and checkbox1.Checked then
    begin
      DM.ibdVendProd.Close;
      DM.ibdVendProd.SelectSQL.Clear;
      DM.ibdVendProd.SelectSQL.Add(´SELECT T2.descricao, T1.datavenda, T2.unidade, SUM(T3.quantidade) as Quantidade, T3.vlrunitario, T3.desconto, sum(t3.quantidade * t3.vlrunitario) as total´);
      DM.ibdVendProd.SelectSQL.Add(´from tb_venda T1 inner join tb_itemvenda T3 on (T1.numvenda = T3.idvenda)´);
      DM.ibdVendProd.SelectSQL.Add(´inner join tb_produto T2 on (T2.idproduto = T3.idproduto)´);
      DM.ibdVendProd.SelectSQL.Add(´and t1.datavenda between :pDataIni and :pDataFin´);
      DM.ibdVendProd.SelectSQL.Add(´GROUP BY T2.descricao, T1.datavenda, T2.unidade, T3.quantidade, T3.vlrunitario, T3.desconto´);
      DM.ibdVendProd.ParamByName(´pDataIni´).AsDate:= strtodate(DataIni.Text);
      DM.ibdVendProd.ParamByName(´pDataFin´).AsDate:= strtodate(DataFin.Text);
      DM.ibdVendProd.Open;
      DM.rvVendProd.SetParam(´pDataIni´,DataIni.Text);
      DM.rvVendProd.SetParam(´pDataFin´,DataFin.Text);
      DM.rvVendProd.ExecuteReport(´Report2´);
    end
    else
    begin
      DM.ibdVendProd.Close;
      DM.ibdVendProd.SelectSQL.Clear;
      DM.ibdVendProd.SelectSQL.Add(´SELECT T2.descricao, T1.datavenda, T2.unidade, SUM(T3.quantidade) as Quantidade, T3.vlrunitario, T3.desconto, sum(t3.quantidade * t3.vlrunitario) as total´);
      DM.ibdVendProd.SelectSQL.Add(´from tb_venda T1 inner join tb_itemvenda T3 on (T1.numvenda = T3.idvenda)´);
      DM.ibdVendProd.SelectSQL.Add(´inner join tb_produto T2 on (T2.idproduto = T3.idproduto)´);
      DM.ibdVendProd.SelectSQL.Add(´and t1.datavenda between :pDataIni and :pDataFin´);
      DM.ibdVendProd.SelectSQL.Add(´and t3.idproduto = :pCodigo´);
      DM.ibdVendProd.SelectSQL.Add(´GROUP BY T2.descricao, T1.datavenda, T2.unidade, T3.quantidade, T3.vlrunitario, T3.desconto´);
      DM.ibdVendProd.ParamByName(´pDataIni´).AsDate:= strtodate(DataIni.Text);
      DM.ibdVendProd.ParamByName(´pDataFin´).AsDate:= strtodate(DataFin.Text);
      DM.ibdVendProd.ParamByName(´pCodigo´).AsInteger:= strtoint(Edit1.Text);
      DM.ibdVendProd.Open;
      DM.rvVendProd.SetParam(´pDataIni´,DataIni.Text);
      DM.rvVendProd.SetParam(´pDataFin´,DataFin.Text);
      DM.rvVendProd.SetParam(´pCodigo´,Edit1.Text);
      DM.rvVendProd.ExecuteReport(´Report2´);
    end;
  end;



Responder

Gostei + 0

01/11/2008

Martins

Você tem que lembrar que na conversão de String para Integer o campo Edit1.text deve conter apenas caracteres numéricos, lembre-se porém q ele estando vazio vai lhe retornar erro.

Verifique se o valor informado em Edit1 é um valor numérico.


Boa Sorte.


Responder

Gostei + 0

01/11/2008

Emerson Nascimento

vamos reduzir esse código pra melhor entendimento e avaliar o conteúdo do edit antes de passar para o parâmetro:

procedure TFiltroRelVendas.btnImprimirClick(Sender: TObject);
begin
  with DM.ibdVendProd do
  begin
    if (rgTipoRel.ItemIndex = 0) then
      with DM.ibdVendProd do
      begin
        Close;
        SelectSQL.Clear;
        SelectSQL.Add(´SELECT T2.descricao, T1.datavenda, T2.unidade,´);
        SelectSQL.Add(´       SUM(T3.quantidade) as Quantidade, T3.vlrunitario,´);
        SelectSQL.Add(´       T3.desconto, sum(t3.quantidade * t3.vlrunitario) as total´);
        SelectSQL.Add(´from tb_venda T1´);
        SelectSQL.Add(´inner join tb_itemvenda T3 on (T1.numvenda = T3.idvenda)´);
        SelectSQL.Add(´inner join tb_produto T2 on (T2.idproduto = T3.idproduto)´);
        SelectSQL.Add(´WHERE t1.datavenda between :pDataIni and :pDataFin´);

        if not checkbox1.Checked then
          SelectSQL.Add(´and t3.idproduto = :pCodigo´);

        SelectSQL.Add(´GROUP BY T2.descricao, T1.datavenda, T2.unidade, T3.quantidade,´);
        SelectSQL.Add(´         T3.vlrunitario, T3.desconto´);

        ParamByName(´pDataIni´).AsDate := strtodate(DataIni.Text);
        ParamByName(´pDataFin´).AsDate := strtodate(DataFin.Text);

        //** antes de passar o valor, verifico se é um inteiro **//
        if not checkbox1.Checked then
        begin
          try
            strtoint(trim(Edit1.Text));
          except
            ShowMessage(´O valor informado no Edit1 não é um inteiro válido!´);
          end;

          ParamByName(´pCodigo´).AsInteger:= strtoint(trim(Edit1.Text));
        end;

        Open;

        DM.rvVendProd.SetParam(´pDataIni´,DataIni.Text);
        DM.rvVendProd.SetParam(´pDataFin´,DataFin.Text);

        if not checkbox1.Checked then
          DM.rvVendProd.SetParam(´pCodigo´, Edit1.Text);

        DM.rvVendProd.ExecuteReport(´Report2´);
      end
    else
    if (rgTipoRel.ItemIndex = 1)
      with DM.ibdVendCliente do
      begin
        Close;
        SelectSQL.Clear;
        SelectSQL.Add(´SELECT T1.nome, T3.idproduto, T4.descricao, T2.datavenda,´);
        SelectSQL.Add(´       T3.quantidade, T3.vlrunitario, T3.desconto,´);
        SelectSQL.Add(´       sum(T3.quantidade * T3.vlrunitario) as total´);
        SelectSQL.Add(´FROM tb_cliente T1´);
        SelectSQL.Add(´INNER JOIN tb_venda T2 ON (T1.idcliente = T2.idcliente)´);
        SelectSQL.Add(´INNER JOIN tb_itemvenda T3 ON (T2.numvenda = T3.idvenda)´);
        SelectSQL.Add(´INNER JOIN tb_produto T4 ON (T3.idproduto = T4.idproduto)´);
        selectSQL.Add(´WHERE T2.datavenda BETWEEN :pDataIni and :pDataFin´);

        if not checkbox2.Checked then
          SelectSQL.Add(´AND T2.idcliente = :pCodigo´);

        SelectSQL.Add(´GROUP BY T1.nome, T3.idproduto, T4.descricao, T2.datavenda,´);
        SelectSQL.Add(´         T3.quantidade,T3.vlrunitario,T3.desconto´);

        ParamByName(´pDataIni´).AsDate:= strtodate(DataIni.Text);
        ParamByName(´pDatafin´).AsDate:= strtodate(DataFin.Text);

        if not checkbox2.Checked then
        begin
          //** antes de passar o valor, verifico se é um inteiro **//
          try
            strtoint(trim(Edit2.Text));
          except
            ShowMessage(´O valor informado no Edit2 não é um inteiro válido!´);
          end;
 
          ParamByName(´pCodigo´).AsInteger:= strtoint(trim(Edit2.Text));
        end;

        Open;

        DM.rvVendCliente.SetParam(´pDataIni´,DataIni.Text);
        DM.rvVendCliente.SetParam(´pDataFin´,DataFin.Text);

        if not checkbox2.Checked then
          DM.rvVendCliente.SetParam(´pCodigo´,Edit2.Text);

        DM.rvVendCliente.ExecuteReport(´Report1´);

      end;
  end;



Responder

Gostei + 0

02/11/2008

Afterdev

Emerson sua solução foi excelente resolveu corretamente o problema, mas gostaria de saber o erro que estava cometendo ! obrigado mesmo.

Martins valeu pela atenção ao meu problema, ajudou muito....


Responder

Gostei + 0

02/11/2008

Emerson Nascimento

não conheço seu programa e não sei como vocÊ está tratando os Edit´s, mas o que aconteceu foi exatamente o que o Martins disse: algum dos Edits não estava com um valor numerico.
De repente estava digitado ´ 2´ (espaço dois), ou uma letra, ou ainda estava vazio...


Responder

Gostei + 0

22/07/2009

Fausto.malheiros

Tem alguma função para testar se o campo a ser convertido de string para inteiro, tem letrar ou espaços no meio?


Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar