Пример #1
0
 //-------------------------------------------------------------------------------------------------------------------
 private void txtCategoria_Leave(object sender, EventArgs e)
 {
     if (operacao == "inserir")
     {
         int          r   = 0;
         BLLCategoria bll = new BLLCategoria();
         r = bll.VerificaCategoria(txtCategoria.Text);
         if (r > 0)
         {
             DialogResult d = MessageBox.Show("Já existe um registro com esse valor. Deseja alterar o registro?", "Aviso", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
             if (d.ToString() == "Yes")
             {
                 DialogResult di = MessageBox.Show("Deseja realmente sobreescrever esse registro? Ao aceitar a operação, o registro antes cadastrado será permanentemente deletado!", "Aviso", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                 if (di.ToString() == "Yes")
                 {
                     this.operacao = "alterar";
                     ModeloCategoria modelo = bll.carregaModelo(r);
                     txtCodigo.Text    = modelo.cat_cod.ToString();
                     txtCategoria.Text = modelo.cat_nome;
                     //this.alteraBotoes(3);
                 }
                 else
                 {
                     txtCategoria.Clear();
                     txtCategoria.Focus();
                 }
             }
             else
             {
                 txtCategoria.Clear();
                 txtCategoria.Focus();
             }
         }
     }
 }
 private void txtNome_Leave(object sender, EventArgs e)
 {
     if (this.operacao == "Inserir")
     {
         int          r   = 0;
         DALConexao   cnx = new DALConexao(DadosDaConexao.StringDeConexao);
         BLLCategoria bll = new BLLCategoria(cnx);
         r = bll.VerificaCategoria(txtNome.Text);
         if (r > 0)
         {
             DialogResult d = MessageBox.Show("Já existe um registro com esse valor. Deseja Alterar o registro?", "Aviso", MessageBoxButtons.YesNo);
             if (d.ToString() == "Yes")
             {
                 this.operacao = "Alterar";
                 ModeloCategoria modelo = bll.CarregaModeloCategoria(r);
                 txtCodigo.Text = modelo.CatCod.ToString();
                 txtNome.Text   = modelo.CatNome.ToString();
                 this.alteraBotoes(3);
             }
         }
     }
 }