// Botão Salvar private void btSalvar_Click(object sender, EventArgs e) { try { // Leitura dos dados nos campos ModeloCategoria modelo = new ModeloCategoria(); modelo.CatNome = txtNome.Text; // Objeto para conexão e gravação no banco DALConexao cx = new DALConexao(DadosDaConexao.StringDeConexao); BLLCategoria bll = new BLLCategoria(cx); if (this.operacao == "Inserir") { // Cadastrar uma categoria bll.Incluir(modelo); MessageBox.Show("Cadastro efetuado: Código " + modelo.CatCod.ToString()); } else { // Alterar uma categoria modelo.CatCod = Convert.ToInt32(txtCodigo.Text); bll.Alterar(modelo); MessageBox.Show("Cadastro alterado"); } this.LimpaTela(); this.alteraBotoes(1); } catch (Exception erro) { MessageBox.Show(erro.Message); } }
private void btSalvar_Click(object sender, EventArgs e) { try { ModeloCategoria modelo = new ModeloCategoria(); txtNome.Text = txtNome.Text.ToUpper(); modelo.CatNome = txtNome.Text; DALConexao cx = new DALConexao(DadosDaConexao.srtConexao); BLLCategoria bll = new BLLCategoria(cx); if (operacao == "inserir") { //cadastrar categoria bll.Incluir(modelo); Ferramentas.MessageBoxHelper.PrepToCenterMessageBoxOnForm(this); MessageBox.Show("Cadastro efetuado - Código " + modelo.CatCod.ToString(),"Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { // alterar categoria modelo.CatCod = Convert.ToInt32(txtCodigo.Text); bll.Alterar(modelo); Ferramentas.MessageBoxHelper.PrepToCenterMessageBoxOnForm(this); MessageBox.Show("Cadastro Alterado", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information); } this.LimpaCampos(); this.AlteraBotoes(1); } catch(Exception erro) { Ferramentas.MessageBoxHelper.PrepToCenterMessageBoxOnForm(this); MessageBox.Show(erro.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void Incluir(ModeloCategoria modelo) { if (modelo.CatNome.Trim().Length == 0) { throw new Exception("O nome da categoria é obrigatorio!"); //modelo.CatNome = modelo.CatNome.ToUpper(); } BLLCategoria DALobj = new BLLCategoria(conexao); DALobj.Incluir(modelo); }
public void btSalvar_Click(object sender, EventArgs e) { try { //leitura dos dados ModeloCategoria modelo = new ModeloCategoria(); modelo.CatNome = txtNome.Text; //obj para gravar os dados no banco DALConexao cx = new DALConexao(DadosConexao.StringDeConexao); BLLCategoria bll = new BLLCategoria(cx); if (this.operacao == "inserir") { //cadastrar uma categoria bll.Incluir(modelo); MessageBox.Show("Cadastro efetuado: Código: "+modelo.CatCod.ToString()); } else { //alterar uma categoria modelo.CatCod = Convert.ToInt32(txtCodigo.Text); bll.Alterar(modelo); MessageBox.Show("Cadastro alterado"); } this.LimpaTela(); this.alteraBotoes(1); } catch (SqlException) { MessageBox.Show("A categoria " + txtNome.Text + " já está cadastrada", "Verifique!"); } catch (Exception erro) { MessageBox.Show(erro.Message); } }