private void btSalvar_Click(object sender, EventArgs e) { //Alterna imagens dos botões btSalvar.ImageIndex = 9; //o try é para tratamento de erros ao inserir objeto try { ModeloSubCategoria modelo = new ModeloSubCategoria(); modelo.CatCod = Convert.ToInt32(cbCatCod.SelectedValue); modelo.ScatNome = txtNome.Text; modelo.ScatData = DateTime.Now.ToShortDateString(); modelo.ScatTime = DateTime.Now.ToShortTimeString(); modelo.ScatStatus = "local"; //Obj para gravar os dados da conexão DALConexao cx = new DALConexao(DadosDaConexao.StringDeConexao); DLLSubCategoria dll = new DLLSubCategoria(cx); if (this.operacao == "inserir") { //Cadastrar nova categoria dll.Incluir(modelo); MessageBox.Show("Cadastro realizado: Código " + modelo.ScatCod.ToString()); //toolStripBarStatus.Text = "Procedimento OK! Item " + modelo.CatCod.ToString() + " cadastrado!"; } else { //Alterar Categoria modelo.ScatCod = Convert.ToInt32(txtSCatCod.Text); dll.Alterar(modelo); MessageBox.Show("Cadastro Alterado!"); //toolStripBarStatus.Text = "Procedimento OK! Item " + txtcodigo.Text + " alterado!"; label1.Visible = false; } this.LimpaTela(); this.alteraBotoes(1); closeCadSubCategoria = 1; } catch (Exception erro) { MessageBox.Show(erro.Message); //toolStripBarStatus.Text = "Erro! Cadastro não realizado!"; } //Retorna parâmetros originais btSalvar.ImageIndex = 8; btInserir.ImageIndex = 0; btLocalizar.ImageIndex = 2; this.operacao = ""; }