コード例 #1
0
        private void btSalvar_Click(object sender, EventArgs e)
        {
            try
            {

                ModeloSubCategoria modelo = new ModeloSubCategoria();
                modelo.SCatNome = txtSnome.Text;
                modelo.CatCod = Convert.ToInt32(cbCatCod.SelectedValue);
                DALConexao cx = new DALConexao(DadosDaConexao.srtConexao);
                BLLSubCategoria bll = new BLLSubCategoria(cx);

                if (operacao == "inserir")
                {
                    //cadastrar categoria
                    bll.Incluir(modelo);
                    Ferramentas.MessageBoxHelper.PrepToCenterMessageBoxOnForm(this);
                    MessageBox.Show("Cadastro efetuado -  Código " + modelo.SCatCod.ToString(), "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    // alterar categoria
                    modelo.SCatCod= Convert.ToInt32(txtSCatCod.Text);
                    bll.Alterar(modelo);
                    Ferramentas.MessageBoxHelper.PrepToCenterMessageBoxOnForm(this);
                    MessageBox.Show("Cadastro Alterado", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                this.LimpaTela();
                this.AlteraBotoes(1);
            }
            catch (Exception erro)
            {
                Ferramentas.MessageBoxHelper.PrepToCenterMessageBoxOnForm(this);
                MessageBox.Show(erro.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #2
0
        // Botão Salvar
        private void btSalvar_Click(object sender, EventArgs e)
        {            
            try
            {
                // Leitura dos dados nos campos
                ModeloSubCategoria modelo = new ModeloSubCategoria();
                modelo.ScatNome = txtNomeSubCategoria.Text;
                modelo.CatCod = Convert.ToInt32(cbCatCod.SelectedValue);

                // Objeto para conexão e gravação no banco
                DALConexao cx = new DALConexao(DadosDaConexao.StringDeConexao);
                BLLSubCategoria bll = new BLLSubCategoria(cx);

                if (this.operacao == "inserir")
                {
                    // Cadastrar uma categoria
                    bll.Incluir(modelo);
                    MessageBox.Show("Cadastro efetuado: Código " + modelo.ScatCod.ToString());
                }
                else
                {
                    // Alterar uma categoria
                    modelo.ScatCod = Convert.ToInt32(txtSubcatcod.Text);
                    bll.Alterar(modelo);
                    MessageBox.Show("Cadastro alterado");
                }
                this.LimpaTela();
                this.alteraBotoes(1);
            }
            catch (Exception erro)
            {
                MessageBox.Show(erro.Message);
            }
        }
コード例 #3
0
        private void btnSalvar_Click(object sender, EventArgs e)
        {
            try
            {
                ModeloSubCategoria m = new ModeloSubCategoria();
                m.SubCategoriaNome = txtNomeSubCategoria.Text;
                m.FKCatCod = Convert.ToInt32(cbCategoria.SelectedValue);

                DALConexao con = new DALConexao(DadosConexao.StringConexao);

                BLLSubCategoria sc = new BLLSubCategoria(con);

                if (this.operacao.Equals("INSERIR"))
                {
                    sc.Incluir(m);

                    MessageBox.Show("Cadastro efetuado com sucesso: Código " + m.CodSubCat.ToString());
                }
                else
                {
                    m.CodSubCat = Convert.ToInt32(txtCodigoSubCategoria.Text);

                    sc.Alterar(m);

                    MessageBox.Show("Cadastro alterado com sucesso.");
                }

                this.LimparCampos();

                this.AlteraBotoes(1);
            }
            catch (Exception erro)
            {
                MessageBox.Show("Erro: " + erro.Message);
            }
        }
コード例 #4
0
        private void btSalvar_Click(object sender, EventArgs e)
        {
            try
            {
                //leitura dos dados
                ModeloSubCategoria modelo = new ModeloSubCategoria();
                modelo.ScatNome = txtNome.Text;
                modelo.CatCod = Convert.ToInt32(cbxCategoria.SelectedValue);

                //obj para gravar os dados no banco
                DALConexao cx = new DALConexao(DadosConexao.StringDeConexao);
                BLLSubCategoria bll = new BLLSubCategoria(cx);

                if (this.operacao == "inserir")
                {
                    //cadastrar uma categoria
                    bll.Incluir(modelo);
                    MessageBox.Show("Cadastro efetuado: Código: " +modelo.ScatCod.ToString());

                }
                else
                {
                    //alterar uma Subcategoria
                    modelo.ScatCod = Convert.ToInt32(txtCodigo.Text);
                    bll.Alterar(modelo);
                    MessageBox.Show("Cadastro alterado");
                }
                this.LimpaTela();
                this.alteraBotoes(1);
            }
            catch (SqlException)
            {
                MessageBox.Show("A Subcategoria " + txtNome.Text + " já está cadastrada", "Verifique!");
            }
            catch (Exception erro)
            {
                MessageBox.Show(erro.Message);
            }
        }