1 Erro na tela de cadastro Qui Abr 18, 2013 4:56 pm
Moedas : 12
Mensagens : 8
Humor : ^^
Reputação : 0
Mensagens : 8
Humor : ^^
Reputação : 0
felipe.alima
Novato
Pessoal,
é o seguinte:
Tenho uma tela de cadastro que separa a nacionalidade de clientes, exemplo: se o cara for angolano verifica se o documento de angola está preenchido ou não, se não for, valida o CPF, só que quando está marcado angolano, o sistema independente de o campo obrigatório estar preenchido ou não, deixa alterar ou confirmar, abaixo segue o trecho do código do botão de confirmar.
é o seguinte:
Tenho uma tela de cadastro que separa a nacionalidade de clientes, exemplo: se o cara for angolano verifica se o documento de angola está preenchido ou não, se não for, valida o CPF, só que quando está marcado angolano, o sistema independente de o campo obrigatório estar preenchido ou não, deixa alterar ou confirmar, abaixo segue o trecho do código do botão de confirmar.
- Código:
procedure TFrmCadCliente.BTConfirmarClick(Sender: TObject);
var RetCpf, NomeCliente, erroEmail: string;
UltimoCodigo: integer;
begin
RetCpf := SubstituirCaracteres(SubstituirCaracteres(SubstituirCaracteres(DBCpf.Text, '.', '0'), '-', '0'), '/', '0');
erroEmail := '';
erroEmail := EmailValido(DBEmail.Text);
if Trim(DBNome.Text) = '' then
begin
Application.MessageBox('O nome do cliente não pode ficar em branco', 'INFORMAÇÃO', MB_ICONINFORMATION + MB_OK);
PageControl1.ActivePageIndex := 0;
DBNome.SetFocus;
end
else if (trim(DBEmail.Text) <> '') and (erroEmail <> '') then
begin
Application.MessageBox(Pchar(erroEmail), 'INFORMAÇÃO', MB_ICONINFORMATION + MB_OK);
PageControl1.ActivePageIndex := 0;
DBEmail.SetFocus;
end
else if DBDataNascimento.Date > Today then
begin
Application.MessageBox('A Data de Nascimento não pode ser maior que a data atual.', 'INFORMAÇÃO', MB_ICONINFORMATION + MB_OK);
PageControl1.ActivePageIndex := 0;
DBDataNascimento.SetFocus;
end
else if DBDataNascimento.Date > Today then
begin
Application.MessageBox('A Data de Nascimento não pode ser maior que a data atual.', 'INFORMAÇÃO', MB_ICONINFORMATION + MB_OK);
PageControl1.ActivePageIndex := 0;
DBDataNascimento.SetFocus;
end;
if (DBLookupNacionalidade.Text = 'ANGOLANA') or (DBLookupNacionalidade.Text = 'ANGOLANO') or
(DBLookupNacionalidade.Text = 'ANGOLANO(A)') or (DBLookupNacionalidade.Text = 'ANGOLANA(O)') then
begin
if Trim(DBBilheteIdentidade.Text) = '' then
begin
Application.MessageBox('O Bilhete de Identidade não pode ficar em branco', 'INFORMAÇÃO', MB_ICONINFORMATION + MB_OK);
PageControl1.ActivePageIndex := 0;
DBBilheteIdentidade.SetFocus;
end
else if (DBLookupNacionalidade.Text <> 'ANGOLANA') then
begin
if (Trim(DBNatureza.Value) = '') then
begin
Application.MessageBox('A natureza do cliente não pode ficar em branco', 'INFORMAÇÃO', MB_ICONINFORMATION + MB_OK);
PageControl1.ActivePageIndex := 0;
DBNatureza.SetFocus;
end
else if Trim(DBCpf.Text) = '' then
begin
Application.MessageBox('O CPF/CNPJ do cliente não pode ficar em branco', 'INFORMAÇÃO', MB_ICONINFORMATION + MB_OK);
PageControl1.ActivePageIndex := 0;
DBCpf.SetFocus;
end;
end;
end;
if ControlePessoa = 'NOVO' then
begin
while (QueryLocate.Locate('CODIGO', UltimoCodigo, []) = true) do
begin
UltimoCodigo := UltimoCodigo + 1;
end;
qryClienteIDCLIENTE.AsInteger := RetornaCodigoProximoCliente;
InserirObservacaoAlerta;
PessoaDepoisAlterar := qryClienteIDCLIENTE.AsString;
NomeCliente := DBNome.Text;
qryClienteTIPOCLIENTE.AsString := '0';
qryCliente.Post;
with QuerySelect do
begin
Close;
SQL.Clear;
SQL.Add('INSERT INTO TBFAC (ID_CLIENTE,CODFAC) VALUES (:IDCLIENTE,0)');
ParamByName('IDCLIENTE').AsString := PessoaDepoisAlterar;
ExecSQL;
end;
with QuerySelect do
begin
Close;
SQL.Clear;
SQL.Add('UPDATE TBFAC SET CODFAC = (SELECT ID_FAC FROM TBFAC WHERE ID_CLIENTE = :IDCLIENTE) ');
SQL.Add('WHERE TBFAC.ID_CLIENTE = :IDCLIENTE ');
ParamByName('IDCLIENTE').AsString := PessoaDepoisAlterar;
ExecSQL;
end;
qryClienteNavigator.Locate('IDCLIENTE', PessoaDepoisAlterar, []);
AtualizarImovel;
SelectObsAlerta;
AtualizarTelas;
InserirOcorrencia('CLIENTE', 'INSERIR', 'CADASTROU O CLIENTE ' + PessoaDepoisAlterar + ' - ' + NomeCliente + '.');
Application.MessageBox('Cliente cadastrado com sucesso', 'INFORMAÇÃO', MB_OK + MB_ICONINFORMATION);
NacionalidadeAngolana;
end
else if ControlePessoa = 'ALTERAR' then
begin
PessoaDepoisAlterar := qryClienteIDCLIENTE.AsString;
NomeCliente := DBNome.Text;
InserirObservacaoAlerta;
qryCliente.Post;
qryClienteNavigator.Locate('IDCLIENTE', PessoaDepoisAlterar, []);
AtualizarImovel;
SelectObsAlerta;
AtualizarTelas;
InserirOcorrencia('CLIENTE', 'ALTERAR', 'ALTEROU O CLIENTE ' + PessoaDepoisAlterar + ' - ' + NomeCliente + '.');
Application.MessageBox('Cliente alterado com sucesso', 'INFORMAÇÃO', MB_OK + MB_ICONINFORMATION);
NacionalidadeAngolana;
end;
end;