Fórum quot;MODO ADOQueryquot; #181029

09/09/2003

0

Oi pessoal. esse é o código do button incluir . No projeto, uso um DataModule(DM) que contém dois ADOQuerys(Qaux1 e Qaux1)

Minhas dúvidas:
- Antes da inclusão, terá que ser feita uma consulta que verifique se já existe um endereço ´OU´ telefone ´OU´ celular ´OU´ email na base. Caso exista, mostrar a mensagem:

*** 1ª DÚVIDA ***
Como fazer para pular linha no Showmessage para que fique por ex:

-----------------------
|Dados duplicados
|NOME: ......
|ENDEREÇO: ......
|CIDADE: ......
-----------------------
na caixa, serão mostrados o dados que a consulta encontrar no banco

*** 2ª DÚVIDA***
na inclusão, poderá ser incluido algum campo em branco, como tratar isto,
pois dá erro.

*** 3ª DÚVIDA***
Neste sistema, eu estava utilizando ADOTable, mas achei que com ADOQuery seria masi fácil realizar essas etapas, Só que tive dificuldades por ex: não consegui utilizar o ParamByName na hora do insert. Sei que existe aquele jeito bonito de se programar, mas não consegui. Abaixo segue o código, qualquer ajuda será muito bem vinda. Obrigada desde já.

OBS: A Base é MS Access

procedure TFCadCli.Button1Click(Sender: TObject);
begin
With DM do
Begin
try
Qaux1.active := false;
Qaux1.SQL.Clear;
Qaux1.SQL.Add(´select count(*) as qtd from tbCLIENTES WHERE ENDEREÇO = ´´ + EENDERECO.Text

+ ´´ OR TELEFONE = ´´ + ETELEFONE.Text + ´´ OR CELULAR = ´´ + ECELULAR.Text + ´´ OR EMAIL = ´´ +

EEMAIL.Text + ´´´);
Qaux1.Open;

if (DM.Qaux1.FieldByName(´qtd´).AsInteger > 0) then
begin
Showmessage(´Duplicados .NOME: ´+ENOME.text+ ´´);

end
else

if (length(ENome.Text)= 0) then
ENome.Text := ´´;
if (length(EEndereco.Text)= 0) then
EEndereco.Text := ´´;
if (length(ECidade.Text)= 0) then
ECidade.Text := ´´;
if (length(EBairro.Text)= 0) then
EBairro.Text := ´´;
if (length(ECep.Text)= 0) then
ECep.Text := ´´;
if (length(EUf.Text)= 0) then
EUf.Text := ´´;
if (length(ENascimento.Text)= 0) then
ENascimento.Text := ´´;
if (length(EDddt.Text)= 0) then
EDddt.Text := null;
if (length(ETelefone.Text)= 0) then
ETelefone.Text := ´´;
if (length(EDddc.Text)= 0) then
EDddc.Text := ´´;
if (length(ECelular.Text)= 0) then
ECelular.Text := ´´;
if (length(EEmail.Text)= 0) then
EEmail.Text := ´´;
if (length(ESEXO.Text)= 0) then
ESEXO.Text := ´´;
if (length(EVIP.Text)= 0) then
EVIP.Text := ´´;

Qaux2.active := false;
Qaux2.SQL.Clear;
Qaux2.SQL.Add(´ INSERT INTO tbCLIENTES´);
Qaux2.SQL.Add(´

(NOME,ENDEREÇO,CIDADE,BAIRRO,CEP,UF,NASCIMENTO,DDDT,TELEFONE,DDDC,CELULAR,EMAIL,SEXO,VIP)´);
Qaux2.SQL.Add(´ VALUES (´´ + ENome.Text + ´´,´´ + EEndereco.Text + ´´,´´ + ECidade.Text +

´´,´´ + EBairro.Text + ´´,´´ + ECep.Text + ´´,´´ + EUf.Text + ´´,´´ + ENascimento.Text + ´´,´´ +

EDddt.Text + ´´,´´ + ETelefone.Text + ´´,´´ + EDddc.Text + ´´,´´ + ECelular.Text + ´´,´´ +

EEmail.Text + ´´ ,´´ + ESEXO.Text + ´´,´´ + EVIP.Text + ´´)´);
Qaux2.ExecSql;
Qaux2.Refresh;
except
end;
end;
end;


Angela

Angela

Responder

Posts

09/09/2003

Angela

Eu nunca vi um showMessage assim, mas de qualquer forma vou dar uma pesquisada.


Ronaldo


Responder

Gostei + 0

09/09/2003

Hmattoso

Cara Amiga,

1º Para quebra linha no showmessage use #13, exemplo:
Showmessage(´LINHA 1´ + 13 + ´LINHA 2´ + 13 + ´LINHA3´)

2º Se houver algum campo definido com NOT NULL no banco de dados, você deverá tratá-lo antes da inclusão. Exemplo.

if Trim(txtCampo.text) = ´´ then
begin
ShowMessage(´O campo deve ser preenchido!´);
txtCampo.setfocus;
exit;
end;

3º Para execução de parametros ADO utilize ADOQUERY.Parameters[0].Value := valor;


Qualquer dúvida pode entrar em contato.

Heleno
hmatoso@technip.com


Responder

Gostei + 0

09/09/2003

Josemarlourenco

Angela,

1) Para criar multiplas linhas, basta concatenar a mensagem com #13.
ShowMessage(´Teste de multiplas linas:´+13+´Linha 2´+13+´Linha3´);
2) Se entendi direito, seu problema é qdo o usuário não digita informação em todos os edit, aí quando vc vai montar o SQL (comando Insert) dá erro concatenando a string. Se for isso, para evitar os erros no seu comando insert, utilize o seguinte:
Qaux2.active := false;
Qaux2.SQL.Clear;
Qaux2.SQL.Add(´ INSERT INTO tbCLIENTES´);
Qaux2.SQL.Add(´

(NOME,ENDEREÇO,CIDADE,BAIRRO,CEP,UF,NASCIMENTO,DDDT,TELEFONE,DDDC,CELULAR,EMAIL,SEXO,VIP)´);
Qaux2.SQL.Add(´ VALUES (´´ + nvl(ENome.Text, ´ ´) + ´´,´´ + nvl(EEndereco.Text, ´ ´) + ´´,´´ + nvl(ECidade.Text, ´ ´) +

´´,´´ + nvl(EBairro.Text, ´ ´) + ´´,´´ + nvl(ECep.Text, ´ ´) + ´´,´´ + nvl(EUf.Text, ´ ´) + ´´,´´ + nvl(ENascimento.Text, ´ / / ´) + ´´,´´ +

nvl(EDddt.Text, ´ / / ´) + ´´,´´ + nvl(ETelefone.Text, ´ ´) + ´´,´´ + nvl(EDddc.Text, ´ / / ´) + ´´,´´ + nvl(ECelular.Text, ´ ´) + ´´,´´ +

nvl(EEmail.Text, ´ ´) + ´´ ,´´ + nvl(ESEXO.Text, ´ ´) + ´´,´´ + nvl(EVIP.Text, ´ ´) + ´´)´);
Qaux2.ExecSql;

a função nvl recebe um valor, e caso seja Null, retorna o valor alternativo.
Segue o código:

Function nvl(Value, Alternative: Variant): Variant;
Begin
If Value = Null Then
Result := Alternative
Else
Result := Value;
End;

3) Quanto aos problemas com parâmetros, em alguns casos (quando a TDAOQuery é criada em tempo de execução, ocorrem alguns problemas, mas seria interessante vc descrever o que está exatamente ocorrendo no seu caso.

Espero ter ajudado.

Josemar


Responder

Gostei + 0

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

Aceitar