Exemple #1
0
        //-------------------------------------------------------------------------------------------------------------------
        public void Incluir(ModeloCategoria obj)
        {
            try
            {
                //command
                SqlCommand cmd = new SqlCommand();
                cmd.Connection  = cn.Conexao;
                cmd.CommandText = "insert into categoria(cat_nome) values (@nome); select @@IDENTITY;";

                cmd.Parameters.AddWithValue("@nome", obj.cat_nome);

                cn.Conectar();
                obj.cat_cod = Convert.ToInt32(cmd.ExecuteScalar());
            }
            catch (SqlException ex)
            {
                throw new Exception("SQL ERROR: " + ex.Message);
            }
            catch (Exception ex)
            {
                throw new Exception("ERROR: " + ex.Message);
            }
            finally
            {
                //cn.Desconectar();
            }
        }
Exemple #2
0
 //-------------------------------------------------------------------------------------------------------------------
 public void Alterar(ModeloCategoria obj)
 {
     try
     {
         SqlCommand cmd = new SqlCommand();
         cmd.Connection  = cn.Conexao;
         cmd.CommandText = "UPDATE categoria SET cat_nome = @nome WHERE cat_cod = @cod";
         cmd.Parameters.AddWithValue("@nome", obj.cat_nome);
         cmd.Parameters.AddWithValue("@cod", obj.cat_cod);
         cn.Conectar();
         cmd.ExecuteNonQuery();
     }
     catch (SqlException ex)
     {
         throw new Exception("Servidor SQL Erro: " + ex.Message);
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
     finally
     {
         //cn.Desconectar();
     }
 }
Exemple #3
0
 private void btnSalvar_Click(object sender, EventArgs e)
 {
     try
     {
         //Leitura dos dados;
         ModeloCategoria modelo = new ModeloCategoria();
         modelo.catnome = txtNome.Text;
         //Objeto para gravar os dados no banco
         DALConexao   cx  = new DALConexao(DadosDaConexao.StringDeConexão);
         BLLCategoria bll = new BLLCategoria(cx);
         if (txtCodigo.Text == "")
         {
             //Cadastrar uma categoria
             bll.Incluir(modelo);
             Mensagem("CATEGORIA INSERIDA, CÓDIGO: " + modelo.cat_cod.ToString(), Color.Blue);
         }
         else
         {
             //Alterar uma categoria
             modelo.cat_cod = Convert.ToInt32(txtCodigo.Text);
             bll.Alterar(modelo);
             Mensagem("CATEGORIA ALTERADA ", Color.Blue);
         }
         LimpaTela();
         alteraBotoes();
     }
     catch (Exception erro)
     {
         Erro(erro.Message);
     }
 }
Exemple #4
0
 private void btnSalvar_Click(object sender, EventArgs e)
 {
     try {
         ModeloCategoria mCategoria = new ModeloCategoria();
         mCategoria.CatNome = txtNome.Text;
         DAOConexao   daoConexao = new DAOConexao(DadosDaConexao.StringDeConexao);
         BLLCategoria bll        = new BLLCategoria(daoConexao);
         if (operacao == "Incluir")
         {
             // cadastrar uma categoria
             bll.incluir(mCategoria);
             MessageBox.Show("Cadastro efetuado - codigo: " + mCategoria.CatCod.ToString());
         }
         else
         {
             // alterar uma categoria
             mCategoria.CatCod = int.Parse(txtCodigo.Text);
             bll.alterar(mCategoria);
             MessageBox.Show("Cadastro alterado");
         }
         limpaCampos();
         alteraBotoes(1);
     }catch (Exception a) {
         MessageBox.Show(a.Message);
     }
 }
Exemple #5
0
        private void btnSalvar_Click(object sender, EventArgs e)
        {
            try
            {
                ModeloCategoria modelo = new ModeloCategoria();
                modelo.Cat_nome = txtNome.Text;
                DALConexao   cx  = new DALConexao(DadosDaConexao.StringDeConexao);
                BLLCategoria bll = new BLLCategoria(cx);

                if (this.operacao == "inserir")
                {
                    bll.Incluir(modelo);
                    MessageBox.Show("Cadastro Realizado. Código: " + modelo.Cat_cod.ToString());
                }
                else
                {
                    modelo.Cat_cod = Convert.ToInt32(txtCodigo.Text);
                    bll.Alterar(modelo);
                    MessageBox.Show("Cadastro Alterado.");
                }
                this.LimpaTela();
                this.alteraBotoes(1);
            }
            catch (Exception erro)
            {
                MessageBox.Show(erro.Message);
            }
        }
Exemple #6
0
 private void btnSalvar_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(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.alterarBotoes(1);
     }
     catch (Exception erro)
     {
         MessageBox.Show(erro.Message);
     }
 }
Exemple #7
0
        private void btSalvar_Click(object sender, EventArgs e)
        {
            try
            {
                //criar uma conexao
                ModeloCategoria modelo = new ModeloCategoria();
                modelo.CatNome = txtNome.Text;
                //objeto para gravar os dados do banco
                DALConexao   cx  = new DALConexao(DadosDaConexao.StringDeConexao);
                BLLCategoria BLL = new BLLCategoria(cx);

                if (Operacao == "inserir")
                {
                    BLL.Incluir(modelo);                        //CADASTRA NOVA CATEGORIA
                    MessageBox.Show("Cadastro efetuado : codigo " + modelo.CatCod.ToString());
                }
                else
                {
                    modelo.CatCod = Convert.ToInt32(txtCodigo.Text);    //ALTERA UMA CATEGORIA
                    BLL.Alterar(modelo);
                    MessageBox.Show("Cadastro alterado");
                }
                LimpaTela();
                AlterarBotoes(1);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        private void btnLocalizar_Click(object sender, EventArgs e)
        {
            frmConsultaCategoria tela = new frmConsultaCategoria();

            tela.ShowDialog();

            if (tela.codigo != 0)
            {
                DALConexao con = new DALConexao(DadosConexao.StringConexao);

                BLLCategoria c = new BLLCategoria(con);

                ModeloCategoria m = c.carregaCategoria(tela.codigo);

                txtCodigo.Text    = m.CodCategoria.ToString();
                txtDescricao.Text = m.NomeCategoria;

                this.AlteraBotoes(3);
            }
            else
            {
                this.LimparCampos();
                this.AlteraBotoes(1);
            }

            tela.Dispose();
        }
        private void btSalvar_Click(object sender, EventArgs e)
        {
            try {
                ModeloCategoria categoria = new ModeloCategoria();
                categoria.CatNome = txtNome.Text;
                DALConexao   cx  = new DALConexao(DadosDaConexao.StringDaConexao);
                BLLCategoria bll = new BLLCategoria(cx);

                if (this.operacao.Equals("inserir"))
                {
                    bll.Incluir(categoria);
                    MessageBox.Show("Cadastro efetuado com sucesso. Codigo: " + categoria.CatCod.ToString());
                }
                else
                {
                    categoria.CatCod = Convert.ToInt32(txtCodigo.Text);
                    bll.Alterar(categoria);
                    MessageBox.Show("Alteração efetuada com sucesso.");
                }
                this.LimpaTela();
                this.alteraBotoes(1);
            } catch (Exception erro)
            {
                MessageBox.Show(erro.Message);
            }
        }
Exemple #10
0
        private void btLocalizar_Click(object sender, EventArgs e)
        {
            //Alterna imagens dos botões
            btLocalizar.ImageIndex = 3;

            //Abre o cadastro do item retornado nos campos
            frmConsultaCategoria frmCCateg = new frmConsultaCategoria();

            frmCCateg.ShowDialog();
            if (frmCCateg.codigo != 0)
            {
                DALConexao      cx     = new DALConexao(DadosDaConexao.StringDeConexao);
                DLLCategoria    dll    = new DLLCategoria(cx);
                ModeloCategoria modelo = dll.CarregaModeloCategoria(frmCCateg.codigo);
                txtcodigo.Text  = modelo.CatCod.ToString();
                txtnome.Text    = modelo.CatNome;
                txtcatdata.Text = modelo.CatData;
                txtcodigo.Text  = Convert.ToString(modelo.CatCod);
                label1.Visible  = true;
                this.alteraBotoes(3);
            }
            else
            {
                //Limpa os campos
                this.LimpaTela();
                //Altera os botões
                this.alteraBotoes(1);
                //Altera se o controle pode ser fechado
                closeCadCategoria = 1;
                //Altera Imagem do botão
                btLocalizar.ImageIndex = 2;
            }
            frmCCateg.Dispose();
        }
Exemple #11
0
        protected void btnInserir_Click(object sender, EventArgs e)
        {
            String          msg = "";
            DalCategoria    dal = new DalCategoria();
            ModeloCategoria obj = new ModeloCategoria();

            obj.categoria = txtNome.Text;

            try
            {
                if (btnInserir.Text == "Inserir")
                {
                    //inserir
                    dal.Inserir(obj);
                    msg = "<script> alert('O código gerado foi o : " + obj.id.ToString() + "'); </script>";
                }
                else
                {
                    //alterar
                    obj.id = Convert.ToInt32(txtID.Text);
                    dal.Alterar(obj);
                    msg = "<script> alert('O registro foi alterado corretamente!'); </script>";
                }
                Response.Write(msg);
                this.LimparCampos();
            }
            catch (Exception erro)
            {
                //colocar um javascript
                Response.Write("<script> alert('" + erro.Message + "'); </script>");
            }
            AtualizarGrid();
        }
Exemple #12
0
        private void btSalvar_Click(object sender, EventArgs e)
        {
            try
            {
                //leitura de dados
                ModeloCategoria modelo = new ModeloCategoria();
                modelo.CatNome = txtNome.Text;
                // obj para gravar os dados 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 com sucesso! O código da categoria é: " + modelo.CatCod.ToString());
                }
                else
                {
                    //alterar uma categoria
                    modelo.CatCod = Convert.ToInt32(txtCodigo.Text);
                    bll.Alterar(modelo);
                    MessageBox.Show("Cadastro atualizado com sucesso!");
                }
                this.limpaTela();
                this.alteraBotoes(1);
            }
            catch (Exception erro)
            {
                MessageBox.Show(erro.Message);
            }
        }
Exemple #13
0
 private void BtnSalvar_Click(object sender, EventArgs e)
 {
     try
     {
         //leitura dos dados
         ModeloCategoria modelo = new ModeloCategoria();
         modelo.cat_nome = txtNome.Text;
         //obj para gravar no banco
         DALConexao   cx           = new DALConexao(DadosDaConexao.stringDeConexao);
         DAOCategoria dAOCategoria = new DAOCategoria(cx);
         if (this.operacao.Equals("inserir"))
         {
             //Cadastrar categoria
             dAOCategoria.Incluir(modelo);
             MessageBox.Show("Cadastro efetuado com sucesso, Código " + modelo.cat_cod.ToString());
         }
         else
         {
             //alterar uma categoria
             modelo.cat_cod = Convert.ToInt32(txtCodigo.Text);
             dAOCategoria.Alterar(modelo);
             MessageBox.Show("Cadstro alterado");
         }
         this.limparTela();
         this.alteraBotoes(1);
     }
     catch (Exception ex)
     {
         MessageBox.Show("Erro" + ex.Message);
     }
 }
        public void Incluir(ModeloCategoria modelo)
        {
            ValidarCampos(modelo);
            DALCategoria DALobj = new DALCategoria(conexao);

            DALobj.Incluir(modelo);
        }
 private void btnSalvar_Click(object sender, EventArgs e)
 {
     try
     {
         ModeloCategoria modelo = new ModeloCategoria();
         modelo.Cat_nome = txtCategoria.Text;
         DALConexao   dao       = new DALConexao(DadosDaConexao.StringDeConexao);
         BLLCategoria categoria = new BLLCategoria(dao);
         if (this.operacao == "inserir")
         {
             //cadastrar
             categoria.Incluir(modelo);
             MetroFramework.MetroMessageBox.Show(this, "Cadastrado com sucesso! ", "OK", MessageBoxButtons.OK, MessageBoxIcon.Information);
             this.limparTela();
             this.alterarBotoes(1);
         }
         else
         {
             //alterar
             modelo.Cat_cod = Convert.ToInt32(txtCodigo.Text);
             categoria.Alterar(modelo);
             MetroFramework.MetroMessageBox.Show(this, "Editado com sucesso! ", "OK", MessageBoxButtons.OK, MessageBoxIcon.Information);
             this.limparTela();
             this.alterarBotoes(1);
         }
     }
     catch (Exception ex)
     {
         MetroFramework.MetroMessageBox.Show(this, "Ops Ocorreu algum erro! " + ex.Message, "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        private void btnSalvar_Click(object sender, EventArgs e)
        {
            try
            {
                ModeloCategoria modeloCategoria = new ModeloCategoria();

                modeloCategoria.CatNome = txtNome.Text;

                if (this.operacao == Inserir)
                {
                    QueryDB.IncluirCategoria(modeloCategoria);
                    MessageBox.Show("Cadastro efetuado com sucesso!! \nCódigo: " + modeloCategoria.CatCod.ToString());
                }
                else
                {
                    modeloCategoria.CatCod = Convert.ToInt32(txtCodigo.Text);

                    QueryDB.AlterarCategoria(modeloCategoria);
                    MessageBox.Show("Cadastro alterado com sucesso!!");
                }

                this.LimparDadosDaTela();
                this.AlteraBotoes(Convert.ToInt32(OperacaoFormulario.Inserir_Localizar));
            }
            catch (Exception Error)
            {
                MessageBox.Show(Error.Message);
            }
        }
        private void btnLocalizar_Click(object sender, EventArgs e)
        {
            frmConsultaCategoria consultaCategoria = new frmConsultaCategoria();

            consultaCategoria.ShowDialog();

            try
            {
                if (consultaCategoria.codigo != 0)
                {
                    DALConexao      conexao   = new DALConexao(DadosDaConexao.StringDeConexao);
                    BLLCategoria    categoria = new BLLCategoria(conexao);
                    ModeloCategoria modelo    = categoria.carregaModeloCategoria(consultaCategoria.codigo);
                    txtCodigo.Text    = modelo.Cat_cod.ToString();
                    txtCategoria.Text = modelo.Cat_nome;
                    this.alterarBotoes(3);
                }
                else
                {
                    this.limparTela();
                    this.alterarBotoes(1);
                }
                consultaCategoria.Dispose();
            }
            catch (Exception ex)
            {
                MetroFramework.MetroMessageBox.Show(this, "Impossivel encontrar o registro. \n O resistro esta sendo utilizado em outro local " + ex.Message, "OK", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btnSalvar_Click(object sender, EventArgs e)
        {
            try
            {
                ModeloCategoria m = new ModeloCategoria();
                m.NomeCategoria = txtDescricao.Text;

                DALConexao con = new DALConexao(DadosConexao.StringConexao);

                BLLCategoria c = new BLLCategoria(con);

                if (this.operacao == "INSERIR") //Cadastro
                {
                    c.Incluir(m);

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

                    c.Alterar(m);

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

                this.LimparCampos();

                this.AlteraBotoes(1);
            }
            catch (Exception erro)
            {
                MessageBox.Show("Erro: " + erro.Message);
            }
        }
Exemple #19
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 ValidarCampos(ModeloCategoria modelo)
 {
     if (modelo.catnome.Trim().Length == 0)
     {
         throw new Exception("nome");
     }
     modelo.catnome = modelo.catnome.ToUpper();
 }
Exemple #21
0
        public void LocalizarCategoria()
        {
            DALConexao      cx     = new DALConexao(DadosDaConexao.StringDeConexão);
            BLLCategoria    bll    = new BLLCategoria(cx);
            ModeloCategoria modelo = bll.CarregaModeloCategoria(codigo);

            PreencheCampos(modelo);
            alteraBotoes();
        }
Exemple #22
0
        public void IncluirCategoria(ModeloCategoria modelo)
        {
            if (modelo.CatNome.Trim().Length == 0)
            {
                throw new Exception("O nome da categoria é obrigatória");
            }

            DALObj.Incluir(modelo);
        }
        public void Incluir(ModeloCategoria modelo)
        {
            if (modelo.CatNome.Trim().Length == 0)
            {
                throw new Exception("O nome da categoria é obrigatorio");
            }
            DALCategoria DALobj = new DALCategoria(conexao);

            DALobj.Incluir(modelo);
        }
        // INCLUIR NO BANCO
        public void incluir(ModeloCategoria mCategoria)
        {
            SqlCommand cmd = new SqlCommand();

            cmd.Connection  = daoConexao.Conexao;
            cmd.CommandText = "insert into categoria(cat_nome) values(@nome); select @@IDENTITY;";
            cmd.Parameters.AddWithValue("@nome", mCategoria.CatNome);
            daoConexao.conectar();
            mCategoria.CatCod = Convert.ToInt32(cmd.ExecuteScalar());
            daoConexao.desconectar();
        }
Exemple #25
0
        public void Incluir(ModeloCategoria c)
        {
            if (c.NomeCategoria.Trim().Length == 0)
            {
                throw new Exception("O nome da categoria é obrigatorio.");
            }

            DALCategoria da = new DALCategoria(CONEXAO);

            da.Incluir(c);
        }
Exemple #26
0
        public void Alterar(ModeloCategoria c)
        {
            if (c.CodCategoria <= 0)
            {
                throw new Exception("Selecione uma categoria.");
            }

            DALCategoria da = new DALCategoria(CONEXAO);

            da.Alterar(c);
        }
        public void Incluir(ModeloCategoria modelo)                        //criando método com variável do tipo modelo
        {
            if (modelo.CatNome.Trim().Length == 0)                         //retirando os espaços em branco do parâmetro/variável nome e verificando se o que há nele é igual a 0
            {
                throw new Exception("O nome da categoria é obrigatório!"); //retornando uma mensagem através do throw que vai direto no tratamento, sem precisar de um catch
            }

            DALCategoria DALobj = new DALCategoria(conexao); //perguntar

            DALobj.Incluir(modelo);
        }
Exemple #28
0
        public void Incluir(ModeloCategoria modelo)
        {
            if (modelo.cat_nome.Trim().Length.Equals(0))
            {
                throw new Exception("O nome da categoria é obrigatório");
            }
            //modelo.cat_nome = modelo.cat_nome.ToUpper();
            DAOCategoria DAOobj = new DAOCategoria(conexao);

            DAOobj.Incluir(modelo);
        }
        public void Incluir(ModeloCategoria modelo) //METEDO INSERIR CATEGORIA
        {
            if (modelo.Cat_nome.Trim().Length == 0)
            {
                throw new Exception("O nome da categoria é OBRIGATORIO");
            }
            modelo.Cat_nome = modelo.Cat_nome.ToUpper();
            DALCategoria daoCategoria = new DALCategoria(conexao);

            daoCategoria.Incluir(modelo);
        }
        public void Incluir(ModeloCategoria modelo)
        {
            SqlCommand cmd = new SqlCommand();

            cmd.Connection  = conexao.ObjetoConexao;
            cmd.CommandText = "insert into categoria_produto(cat_nome) values (@nome); select @@IDENTITY;";
            cmd.Parameters.AddWithValue("@nome", modelo.CatNome);
            conexao.Conectar();
            modelo.CatCod = Convert.ToInt32(cmd.ExecuteScalar());
            conexao.Desconectar();
        }