Transformar orcamento em venda

MySQL

27/05/2011

bom dia...pessoal estou com codigo em um botao para transformar um orçamento em venda, porem quando clico neste botao me da a mensagem:   ' dataset not in edit or insert mode' - estranho mesmo dando esta mensagem ele transforma em o orcamento em venda, porem so transfere um item do orcamento(produto) para a tabela itensvendas... Alguem pode me ajudar a corrigir este erro? segue o codigo do botao....uso ado/delphi 7/mysql 5...   procedure Tfrmtelaorca.spdtransformarClick(Sender: TObject);
begin
if dmlojas.ADOTablevendas.State in [dsEdit, DsInsert] then
dmlojas.ADOTablevendas.insert;
dmlojas.ADOTablevendas.Append;
//dmlojas.ADOTablevendas.Edit;
dmlojas.ADOTablevendasDataVenda.Value:=date;
dmlojas.ADOTablevendasCliente.Value:=dmlojas.ADOTableorcaCliente.Value;
dmlojas.ADOTablevendasCodCli.Value:=dmlojas.ADOTableorcaCodcli.Value;
dmlojas.ADOTablevendasTipoVenda.Value:='A VISTA';
dmlojas.ADOTablevendasVendedor.Value:=dmlojas.ADOTableorcaVendedor.Value;
dmlojas.ADOTablevendasCodFunc.Value:=dmlojas.ADOTableorcaCodfunc.Value;
dmlojas.ADOTablevendasCondPagto.Value:=dmlojas.ADOTableorcaCondpagto.Value;
dmlojas.ADOTablevendasFormaPagto.Value:=dmlojas.ADOTableorcaFormapagto.Value;
dmlojas.ADOTablevendasObservacao.Value:=dmlojas.ADOTableorcaObservacao.Value;
dmlojas.ADOTablevendasSubTotal.Value:=dmlojas.ADOTableorcaSubtotal.Value;
dmlojas.ADOTablevendasDesconto.Value:=dmlojas.ADOTableorcaDesconto.Value;
dmlojas.ADOTablevendasValorDesconto.Value:=dmlojas.ADOTableorcaValordesconto.Value;
dmlojas.ADOTablevendasTotalVenda.Value:=dmlojas.ADOTableorcaTotalorca.Value;
dmlojas.ADOTablevendas.Post;
with dmlojas.ADOTableitensorca do
begin
first;
while dmlojas.ADOTableitensorca.Eof = false do
begin
dmlojas.ADOTableItens2.Insert;
dmlojas.ADOTableItens2.Append;
dmlojas.ADOTableItens2Codprod.Value:=dmlojas.ADOTableitensorcaCodprod.Value;
dmlojas.ADOTableItens2Referencia.Value:=dmlojas.ADOTableitensorcaReferencia.Value;
dmlojas.ADOTableItens2Descricao.Value:=dmlojas.ADOTableitensorcaDescricao.Value;
dmlojas.ADOTableItens2UN.Value:=dmlojas.ADOTableitensorcaUN.Value;
dmlojas.ADOTableItens2Quantidade.Value:=dmlojas.ADOTableitensorcaQuantidade.Value;
dmlojas.ADOTableItens2ValorUnit.Value:=dmlojas.ADOTableitensorcaValorunit.Value;
dmlojas.ADOTableItens2Total.Value:=dmlojas.ADOTableitensorcaTotal.Value;
dmlojas.ADOTableItens2.Post;
Delete;
end;
Next;
End;
dmlojas.ADOTableorca.Delete;
dmlojas.ADOTablevendas.Insert;
ShowMessage('Orçamento transformado em venda com sucesso.');
end;
end;     Aguardo retorno...
Jose Maria

Jose Maria

Curtidas 0

Respostas

Fernando Ferreira

Fernando Ferreira

27/05/2011

Tenta desta forma é como eu faço em meu sistema de Pedidos.


dm.Tbitens.First;
  if not dm.Tbitens.Eof then
     repeat
       dm.Tbhistorico.Append;
       dm.TbhistoricoDATA.Value:=strtodate(maskedit1.Text);
       dm.TbhistoricoHORA.Value:=timetostr(time);
       dm.TbhistoricoCUPON.Value:=dm.TbparametrosN_PEDIDO.Value;
       dm.TbhistoricoCLIENTE.Value:=dbl1.Text;
       dm.TbhistoricoCODIGO.Value:=dm.TbitensCODIGO.Value;
       dm.TbhistoricoDESCRICA.Value:=dm.TbitensDESCRICAO.Value;
       dm.TbhistoricoQUANT.Value:=dm.TbitensQUANTIDADE.Value;
       dm.TbhistoricoVL_UNIT.Value:=dm.TbitensVL_UNIT.Value;
       dm.TbhistoricoVL_TOTAL.Value:=dm.TbitensVL_TOTAL.Value;
       dm.TbhistoricoDESCONTO.Value:=currencyedit2.Value;
       dm.TbhistoricoVENDA.Value:=currencyedit5.Value;
       dm.Tbhistorico.Post;
       dm.Tbitens.Next;
  until dm.Tbitens.Eof;

GOSTEI 0
POSTAR