GARANTIR DESCONTO

Fórum Dificudade para usar IF...BEGIN...END na aplicação? #344326

09/08/2007

0

Pessoal, tive que acressentar um [b:e57df5582d]CANCEL[/b:e57df5582d] no Application. [b:e57df5582d]MessageBox.[/b:e57df5582d]

Tenho que fazer mais uma condiçao de IF para poder cancelar a operação?

if application.MessageBox(´Atenção! Existe Proventos/Descontos vinculados a este Funcionário. Deletar em cascata?´, ´Informação´, [b:e57df5582d][color=red:e57df5582d]MB_YESNOCANCEL[/color:e57df5582d][/b:e57df5582d]) = mrNo then


Antes funcionava corretamente desta forma
procedure TfAlteraFolha.Button1Click(Sender: TObject);
begin
  dm.zspSomaFuncC.Close;
  dm.zspSomaFuncC.sql.Clear; 
  dm.zspSomaFuncC.sql.Text := ´select id_gerarformula, nome from essqlfunc where id_Formula >= 2´
    + ´and id_gerarformula =´ + QuotedSTR(L7.Caption); 
  dm.zspSomaFuncC.Open; 
  if not dm.zspSomaFuncC.IsEmpty then 
  begin
    if application.MessageBox(´Atenção! Existe Proventos/Descontos vinculados a este Funcionário. Deletar em cascata?´, ´Informação´, MB_YESNOCANCEL) = mrNo then
    begin
      if L6.Caption = ´1´ then
      begin
        ShowMessage(´Este código só pode ser deletado em cascata´);
        Abort;
      end;
      dm.zspAltFuncU.Close; //-- Comandos da SP
      dm.zspAltFuncU.Params[0].Value := LMarcar.Caption;
      dm.zSPAltFuncU.Params[1].Value := L6.Caption;
      dm.zSPAltFuncU.Params[2].Value := L7.Caption;
      dm.zspAltFuncU.ExecProc; //executando a Stored Procedure
    end
    else
    begin
      dm.zspAltFunc.Close; //-- Comandos da SP
      dm.zspAltFunc.Params[0].Value := LMarcar.Caption;
      dm.zSPAltFunc.Params[1].Value := L7.Caption;
      dm.zspAltFunc.ExecProc; //executando a Stored Procedure
    end;
    {executando a SP fora do bloco acima}
  end else {referente a if not}
  begin
    {Essa procedure dispara fora pq as vezes o funcionario nao
    tem vinculo entao eh necessario desta SP aqui tambem}
    dm.zspAltFuncU.Close; //-- Comandos da SP
    dm.zspAltFuncU.Params[0].Value := LMarcar.Caption;
    dm.zSPAltFuncU.Params[1].Value := L6.Caption;
    dm.zSPAltFuncU.Params[2].Value := L7.Caption;
    dm.zspAltFuncU.ExecProc; //executando a Stored Procedure
  end;
  ShowMessage(´Dados Atualizado´);
end;


Tem jeito nao depois de velho a gente nao aprende mais mesmo :x

Fiz assim agora e nao funciona certo:
procedure TfAlteraFolha.Button1Click(Sender: TObject);
begin
  dm.zspSomaFuncC.Close;
  dm.zspSomaFuncC.sql.Clear; 
  dm.zspSomaFuncC.sql.Text := ´select id_gerarformula, nome from essqlfunc where id_Formula >= 2´
    + ´and id_gerarformula =´ + QuotedSTR(L7.Caption); 
  dm.zspSomaFuncC.Open; 
  if not dm.zspSomaFuncC.IsEmpty then 
  begin
    if application.MessageBox(´Atenção! Existe Proventos/Descontos vinculados a este Funcionário. Deletar em cascata?´, ´Informação´, MB_YESNOCANCEL) = mrNo then
    begin
      if L6.Caption = ´1´ then
      begin
        ShowMessage(´Este código só pode ser deletado em cascata´);
        Abort;
      end;
      dm.zspAltFuncU.Close; //-- Comandos da SP
      dm.zspAltFuncU.Params[0].Value := LMarcar.Caption;
      dm.zSPAltFuncU.Params[1].Value := L6.Caption;
      dm.zSPAltFuncU.Params[2].Value := L7.Caption;
      dm.zspAltFuncU.ExecProc; //executando a Stored Procedure
    end else
    begin
      dm.zspAltFunc.Close; //-- Comandos da SP
      dm.zspAltFunc.Params[0].Value := LMarcar.Caption;
      dm.zSPAltFunc.Params[1].Value := L7.Caption;
      dm.zspAltFunc.ExecProc; //executando a Stored Procedure
    end;
    {executando a SP fora do bloco acima}
  end else {referente a if not}
  begin
    {Essa procedure dispara fora pq as vezes o funcionario nao
    tem vinculo entao eh necessario esta SP aqui tambem}
    if application.MessageBox(´Deletar este Provento/Desconto?´, ´Informação´, MB_YESNO) = mrYes then
    begin
      dm.zspAltFuncU.Close; //-- Comandos da SP
      dm.zspAltFuncU.Params[0].Value := LMarcar.Caption;
      dm.zSPAltFuncU.Params[1].Value := L6.Caption;
      dm.zSPAltFuncU.Params[2].Value := L7.Caption;
      dm.zspAltFuncU.ExecProc; //executando a Stored Procedure
    end else
    begin
      Abort;
    end;
    Abort;
  end;
  ShowMessage(´Dados Atualizado´);
end;


Mais esta [b:e57df5582d][size=18:e57df5582d]ERRADO[/size:e57df5582d][/b:e57df5582d] :evil:


Adriano_servitec

Adriano_servitec

Responder

Posts

09/08/2007

Fknyght

pq vc nao usa o case tipo
case application.MessageBox(´Atenção! Existe Proventos/Descontos vinculados a este Funcionário. Deletar em cascata?´, ´Informação´,   MB_YESNOCANCEL) of
  id_yes :  faz alguma coisa
  id_no   : faz outra coisa
  id_cancel : faz qualquer coisa
end; // CASE


tenta ai


Responder

Gostei + 0

09/08/2007

Emerson Nascimento

ou crie uma variável e guarde a resposta do usuário:
procedure TfAlteraFolha.Button1Click(Sender: TObject);
var
  resposta: integer;
begin
  dm.zspSomaFuncC.Close;
  dm.zspSomaFuncC.sql.Clear;
  dm.zspSomaFuncC.sql.Text := ´select id_gerarformula, nome from essqlfunc where id_Formula >= 2´
    + ´and id_gerarformula =´ + QuotedSTR(L7.Caption);
  dm.zspSomaFuncC.Open;
  if not dm.zspSomaFuncC.IsEmpty then
  begin
    resposta := application.MessageBox(´Atenção! Existe Proventos/Descontos vinculados a este Funcionário. Deletar em cascata?´, ´Informação´, MB_YESNOCANCEL);
    if resposta = mrNo then
    begin
      if L6.Caption = ´1´ then
      begin
        ShowMessage(´Este código só pode ser deletado em cascata´);
        Abort;
      end;
      dm.zspAltFuncU.Close; //-- Comandos da SP
      dm.zspAltFuncU.Params[0].Value := LMarcar.Caption;
      dm.zSPAltFuncU.Params[1].Value := L6.Caption;
      dm.zSPAltFuncU.Params[2].Value := L7.Caption;
      dm.zspAltFuncU.ExecProc; //executando a Stored Procedure
    end
    else
    if resposta = mrYes then
    begin
      dm.zspAltFunc.Close; //-- Comandos da SP
      dm.zspAltFunc.Params[0].Value := LMarcar.Caption;
      dm.zSPAltFunc.Params[1].Value := L7.Caption;
      dm.zspAltFunc.ExecProc; //executando a Stored Procedure
    end;
    {executando a SP fora do bloco acima}
  end else {referente a if not}
  begin
    {Essa procedure dispara fora pq as vezes o funcionario nao
    tem vinculo entao eh necessario esta SP aqui tambem}
    if application.MessageBox(´Deletar este Provento/Desconto?´, ´Informação´, MB_YESNO) = mrYes then
    begin
      dm.zspAltFuncU.Close; //-- Comandos da SP
      dm.zspAltFuncU.Params[0].Value := LMarcar.Caption;
      dm.zSPAltFuncU.Params[1].Value := L6.Caption;
      dm.zSPAltFuncU.Params[2].Value := L7.Caption;
      dm.zspAltFuncU.ExecProc; //executando a Stored Procedure
    end else
    begin
      Abort;
    end;
    Abort;
  end;
  ShowMessage(´Dados Atualizados´);
end;



Responder

Gostei + 0

09/08/2007

Adriano_servitec

Blz, funcionou.

Valeu pessoal, obrigado mais uma vez


Responder

Gostei + 0

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

Aceitar