Пример #1
0
        private void btExcluir_Click(object sender, EventArgs e)
        {
            //Alterna imagens dos botões
            btExcluir.ImageIndex = 7;

            //o try é para tratamento de erros ao inserir objeto
            try
            {
                DialogResult d = MessageBox.Show("Tem certeza que deseja excluir o registro?", "Excluir?", MessageBoxButtons.YesNo);
                if (d.ToString() == "Yes")
                {
                    //MessageBox.Show("Excluindo o registro!");
                    DALConexao      cx  = new DALConexao(DadosDaConexao.StringDeConexao);
                    DLLSubCategoria dll = new DLLSubCategoria(cx);
                    dll.Excluir(Convert.ToInt32(txtSCatCod.Text));
                    this.LimpaTela();
                    this.alteraBotoes(1);
                    closeCadSubCategoria = 1;
                }
                else
                {
                    MessageBox.Show("Erro no valor passado!" + d.ToString());
                }
            }
            catch
            {
                MessageBox.Show("Impossível excluir o registro. \n O registro está sendo utilizado em outro local.");
                this.alteraBotoes(3);
                closeCadSubCategoria = 3;
                //FormPrincipal.toolStripBarStatus.Text = "ERRO! Impossível excluir o registro.";
            }
            btExcluir.ImageIndex   = 6;
            btLocalizar.ImageIndex = 2;
            this.operacao          = "";
        }