Adicionar PRODUTOS ao APLICATIVO de MESA/CARTÃO, tentando UPDATE
Boa noite estou tentando fazer um aplicativo de celular que funcione em rede, estou recuperando os dados do banco e tentando fazer uma comparação com os campos de tabelas diferentes (se o PRODUTO da tabela PRODUTOS for diferente dos PRODUTOS da tabela MESACARTAO, inserir o PRODUTO com QUANTIDADE 1 e se for IGUAL aumentar sua QUANTIDADE em + 1), mas não estou conseguindo meu UPDATE não está funcionando e esta dando erro, sou iniciante no Delphi;
Eu estou fazendo correto ? qual a melhor maneira de comprar esses campos ?
Eu estou fazendo correto ? qual a melhor maneira de comprar esses campos ?
[quoteprocedure TFrmPrincipal.rct_inserirprodClick(Sender: TObject);
var
inserirP,codbarra,nomepro: string;
prodcodigo,numesa,operador,empresa,codigo: integer;
prodprecvend,quantidade,preco,totalitem,produto,contquant: double;
begin
inserirP := edt_inserirprod.Text;
if inserirP <> '''' then
begin
inserirP := AnsiUpperCase(inserirP) + ''%'';
DM_Comanda.FDQueryInsProd.Close;
DM_Comanda.FDQueryInsProd.SQL.text := ''select * from PRODUTO where upper(descricao) like''+QuotedStr(inserirP);
DM_Comanda.FDQueryInsProd.Open;
numesa := lbl_numesa.Text.ToInteger;
prodcodigo := DM_Comanda.FDQueryInsProd.FieldByName(''codigo'').AsInteger;
codbarra := DM_Comanda.FDQueryInsProd.FieldByName(''codbarra'').AsString;
//quantidade fazer algo a respeito
preco := DM_Comanda.FDQueryInsProd.FieldByName(''precovenda'').AsFloat;
operador := DM_Comanda.FDQueryInsProd.FieldByName(''operador'').AsInteger;
empresa := DM_Comanda.FDQueryInsProd.FieldByName(''empresa'').AsInteger;
//TOTALITEM FAZER A MULTIPLICAÇÃO PELA QUANTIDADE;
nomepro := DM_Comanda.FDQueryInsProd.FieldByName(''descricao'').AsString;
DM_Comanda.FDQueryInsProd.Close;
DM_Comanda.FDQueryInsProd.SQL.Text := ''select produto from MESACARTAO'';
DM_Comanda.FDQueryInsProd.Open;
produto := DM_Comanda.FDQueryInsProd.FieldByName(''produto'').AsInteger;
if prodcodigo <> produto then // CÓDIGO DO PRODUTO DIFERENTE DO CÓDIGO DO PRODUTO QUE ESTÁ NA TABELA MESACARTÃO;
begin
DM_Comanda.FDQueryInsProd.Close;
DM_Comanda.FDQueryInsProd.SQL.Text := ''insert into MESACARTAO (codigo,mesa,produto,codbarra,quantidade,preco,operador,empresa,data,totalitem,nomepro) values (:codigo, :numesa, :prodcodigo, :codbarra, :quantidade, :preco, :operador, :empresa, :data, :totalitem, :nomepro)'';
DM_Comanda.FDQueryInsProd.ParamByName(''codigo'').AsInteger := getContadores(''mesacartao'');
DM_Comanda.FDQueryInsProd.ParamByName(''numesa'').AsInteger := numesa;
DM_Comanda.FDQueryInsProd.ParamByName(''prodcodigo'').AsInteger := prodcodigo;
DM_Comanda.FDQueryInsProd.ParamByName(''codbarra'').AsString := codbarra;
DM_Comanda.FDQueryInsProd.ParamByName(''quantidade'').AsFloat := 1;
DM_Comanda.FDQueryInsProd.ParamByName(''preco'').AsFloat := preco;
DM_Comanda.FDQueryInsProd.ParamByName(''operador'').AsInteger := operador;
DM_Comanda.FDQueryInsProd.ParamByName(''empresa'').AsInteger := empresa;
DM_Comanda.FDQueryInsProd.ParamByName(''data'').AsDateTime := now;
DM_Comanda.FDQueryInsProd.ParamByName(''totalitem'').AsFloat := totalitem;
DM_Comanda.FDQueryInsProd.ParamByName(''nomepro'').AsString := nomepro;
DM_Comanda.FDQueryInsProd.ExecSQL;
end
else
begin
DM_Comanda.FDQueryInsProd.Close;
DM_Comanda.FDQueryInsProd.SQL.Text := ''UPDATE MESACARTAO SET quantidade = +1 WHERE codigo = procodigo'';
DM_Comanda.FDQueryInsProd.ExecSQL;
end;
end;
end;]Helton Faria
Curtidas 0
Melhor post
Emerson Nascimento
29/06/2021
tente assim:
procedure TFrmPrincipal.rct_inserirprodClick(Sender: TObject);
var
inserirP,codbarra,nomepro: string;
prodcodigo,numesa,operador,empresa,codigo: integer;
prodprecvend,quantidade,preco,totalitem,produto,contquant: double;
insere: boolean;
begin
inserirP := edt_inserirprod.Text;
if inserirP <> '' then exit;
inserirP := AnsiUpperCase(inserirP) + '%';
numesa := lbl_numesa.Text.ToInteger;
//quantidade fazer algo a respeito
prodquant := StrToIntDef(edt_quantidade.Text,1); // quantidade???
// DADOS DO PRODUTO E MESA
DM_Comanda.FDQueryInsProd.Close;
DM_Comanda.FDQueryInsProd.SQL.text :=
' select p.codigo, p.codbarra, p.precovenda, p.operador, p.empresa, p.descricao, m.mesa '+
' from PRODUTO p '+
' left join MESACARTAO m on m.produto = p.codigo and m.mesa = '+lbl_numesa.Text+
' where upper(p.descricao) like '+QuotedStr(inserirP);
DM_Comanda.FDQueryInsProd.Open;
prodcodigo := DM_Comanda.FDQueryInsProd.FieldByName('codigo').AsInteger;
codbarra := DM_Comanda.FDQueryInsProd.FieldByName('codbarra').AsString;
preco := DM_Comanda.FDQueryInsProd.FieldByName('precovenda').AsFloat;
operador := DM_Comanda.FDQueryInsProd.FieldByName('operador').AsInteger;
empresa := DM_Comanda.FDQueryInsProd.FieldByName('empresa').AsInteger;
nomepro := DM_Comanda.FDQueryInsProd.FieldByName('descricao').AsString;
insere := DM_Comanda.FDQueryInsProd.FieldByName('mesa').IsNull;
//TOTALITEM FAZER A MULTIPLICAÇÃO PELA QUANTIDADE;
totalitem := preco * prodquant;
DM_Comanda.FDQueryInsProd.Close;
if insere then // INSERIR PRODUTO PARA MESA INFORMADA
begin
DM_Comanda.FDQueryInsProd.SQL.Text :=
'insert into MESACARTAO (codigo,mesa,produto,codbarra,quantidade,preco,operador,empresa,data,totalitem,nomepro) '+
'values (:codigo, :numesa, :prodcodigo, :codbarra, :prodquant, :preco, :operador, :empresa, :data, :totalitem, :nomepro)';
DM_Comanda.FDQueryInsProd.ParamByName('codigo').AsInteger := getContadores('mesacartao');
DM_Comanda.FDQueryInsProd.ParamByName('codbarra').AsString := codbarra;
DM_Comanda.FDQueryInsProd.ParamByName('preco').AsFloat := preco;
DM_Comanda.FDQueryInsProd.ParamByName('operador').AsInteger := operador;
DM_Comanda.FDQueryInsProd.ParamByName('empresa').AsInteger := empresa;
DM_Comanda.FDQueryInsProd.ParamByName('data').AsDateTime := now;
DM_Comanda.FDQueryInsProd.ParamByName('totalitem').AsFloat := totalitem;
DM_Comanda.FDQueryInsProd.ParamByName('nomepro').AsString := nomepro;
end
else
begin // PRODUTO JÁ EXISTE NA MESA, INCREMENTA A QUANTIDADE E ALTERA O TOTAL
DM_Comanda.FDQueryInsProd.SQL.Text :=
'UPDATE MESACARTAO SET '+
' totalitem = preco * (quantidade + :prodquant), '+
' quantidade = (quantidade + :prodquant) '+
'WHERE mesa = :numesa and produto = :procodigo';
end;
DM_Comanda.FDQueryInsProd.ParamByName('numesa').AsInteger := numesa;
DM_Comanda.FDQueryInsProd.ParamByName('prodcodigo').AsInteger := prodcodigo;
DM_Comanda.FDQueryInsProd.ParamByName('prodquant').AsFloat := prodquant;
DM_Comanda.FDQueryInsProd.ExecSQL;
end;GOSTEI 2
Mais Respostas
Chromusmaster
28/06/2021
DM_Comanda.FDQueryInsProd.SQL.Text := ''UPDATE MESACARTAO SET quantidade = +1 WHERE codigo = procodigo'';
O seu upodate não deveria ser ''UPDATE MESACARTAO SET quantidade = quantidade +1 WHERE codigo = procodigo'' ?
GOSTEI 1