private void frmCadastroProduto_Load(object sender, EventArgs e)
        {
            //Combo da Categoria
            this.alteraBotoes(1);
            DALConexao   cx  = new DALConexao(DadosDaConexao.StringDeConexao);
            BBLCategoria bll = new BBLCategoria(cx);

            cboCategoria.DataSource    = bll.Localizar("");
            cboCategoria.DisplayMember = "cat_nome";
            cboCategoria.ValueMember   = "cat_cod";
            try
            {
                //Combo da SubCategoria
                BBLSubCategoria sbll = new BBLSubCategoria(cx);
                cboSubCategoria.DataSource    = sbll.LocalizaPorCategoria((int)cboCategoria.SelectedValue);
                cboSubCategoria.DisplayMember = "scat_nome";
                cboSubCategoria.ValueMember   = "scat_cod";
            }
            catch
            {
                MessageBox.Show("Ops! Não Existe Nenhuma Categoria Cadastrada!");
            }
            //Combo Unidade Medida
            BBLUnidadeMedida mbll = new BBLUnidadeMedida(cx);

            cboUnidadeMedida.DataSource    = mbll.Localizar("");
            cboUnidadeMedida.DisplayMember = "umed_nome";
            cboUnidadeMedida.ValueMember   = "umed_cod";
        }
 private void btsalvar_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.StringDeConexao);
         BBLCategoria bbl = new BBLCategoria(cx);
         if (this.operacao == "inserir")
         {
             //cadastra uma categoria
             bbl.Incluir(modelo);
             MessageBox.Show("Cadastro efetuado: Código " + modelo.CatCod.ToString());
         }
         else
         {
             //alterar uma categoria
             modelo.CatCod = Convert.ToInt32(txtCodigo.Text);
             bbl.Alterar(modelo);
             MessageBox.Show("Cadastro Alterado");
         }
         this.LimpaTela();
         this.alteraBotoes(1);
     }
     catch (Exception erro)
     {
         MessageBox.Show(erro.Message);
     }
 }
        private void btLocalizar_Click(object sender, EventArgs e)
        {
            DALConexao   cx  = new DALConexao(DadosDaConexao.StringDeConexao);
            BBLCategoria bbl = new BBLCategoria(cx);

            dgvDados.DataSource = bbl.Localizar(txtValor.Text);
        }
        private void frmCadastroSubCategoria_Load(object sender, EventArgs e)
        {
            this.alteraBotoes(1);
            DALConexao   cx  = new DALConexao(DadosDaConexao.StringDeConexao);
            BBLCategoria bll = new BBLCategoria(cx);

            cbCatCod.DataSource    = bll.Localizar("");
            cbCatCod.DisplayMember = "cat_nome";
            cbCatCod.ValueMember   = "cat_cod";
        }
 private void btExcluir_Click(object sender, EventArgs e)
 {
     try
     {
         DialogResult d = MessageBox.Show("Deseja escluir o registro?", "Aviso", MessageBoxButtons.YesNo);
         if (d.ToString() == "Yes")
         {
             DALConexao   cx  = new DALConexao(DadosDaConexao.StringDeConexao);
             BBLCategoria bbl = new BBLCategoria(cx);
             bbl.Excluir(Convert.ToInt32(txtCodigo.Text));
             this.LimpaTela();
             this.alteraBotoes(1);
         }
     }
     catch
     {
         MessageBox.Show("Impossivel excluir o registro, \n O registro esta sendo ultilizado em outro local.");
         this.alteraBotoes(3);
     }
 }
        private void btlocalizar_Click(object sender, EventArgs e)
        {
            frmConsultaCategoria f = new frmConsultaCategoria();

            f.ShowDialog();
            if (f.codigo != 0)
            {
                DALConexao      cx     = new DALConexao(DadosDaConexao.StringDeConexao);
                BBLCategoria    bbl    = new BBLCategoria(cx);
                ModeloCategoria modelo = bbl.CarregaModeloCategoria(f.codigo);
                txtCodigo.Text = modelo.CatCod.ToString();
                txtNome.Text   = modelo.CatNome;
                this.alteraBotoes(3);
            }
            else
            {
                this.LimpaTela();
                this.alteraBotoes(1);
            }
            f.Dispose();
        }