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
     {
         ModeloSubCategoria modelo = new ModeloSubCategoria();
         modelo.ScatNome = txtNome.Text;
         modelo.CatCod   = Convert.ToInt32(cbCatCod.SelectedValue);
         //obj para gravar os dados no banco
         DALConexao      cx  = new DALConexao(DadosDaConexao.StringDeConexao);
         BBLSubCategoria bll = new BBLSubCategoria(cx);
         if (this.operacao == "inserir")
         {
             //cadastrar uma categoria
             bll.incluir(modelo);
             MessageBox.Show("Nova SubCategoria Cadastrada com sucesso: Código" + modelo.ScatCod.ToString());
         }
         else
         {
             //alterar uma categoria
             modelo.ScatCod = Convert.ToInt32(txtScatCod.Text);
             bll.alterar(modelo);
             MessageBox.Show("SubCategoria Alterada com Sucesso");
         }
         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);
            BBLSubCategoria bll = new BBLSubCategoria(cx);

            dgvDados.DataSource = bll.Localizar(txtValor.Text);
        }
        private void cboCategoria_SelectedValueChanged(object sender, EventArgs e)
        {
            DALConexao cx = new DALConexao(DadosDaConexao.StringDeConexao);

            try
            {
                //Combo da SubCategoria

                cboSubCategoria.Text = "";
                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!");
            }
        }
 private void btExcluir_Click(object sender, EventArgs e)
 {
     try
     {
         DialogResult d = MessageBox.Show("Realmente Deseja Excluir o Registro?", "Aviso", MessageBoxButtons.YesNo);
         if (d.ToString() == "Yes")
         {
             DALConexao      cx  = new DALConexao(DadosDaConexao.StringDeConexao);
             BBLSubCategoria bll = new BBLSubCategoria(cx);
             bll.Excluir(Convert.ToInt32(txtScatCod.Text));
             this.LimpaTela();
             this.alteraBotoes(1);
         }
     }
     catch
     {
         MessageBox.Show("Impossivel excluir o regitro desejado. \n ) registro esta sendo usado em outro local.");
         this.alteraBotoes(3);
     }
 }
        private void btlocalizar_Click(object sender, EventArgs e)
        {
            frmConsultaSubCategoria f = new frmConsultaSubCategoria();

            f.ShowDialog();
            if (f.codigo != 0)
            {
                DALConexao         cx     = new DALConexao(DadosDaConexao.StringDeConexao);
                BBLSubCategoria    bll    = new BBLSubCategoria(cx);
                ModeloSubCategoria modelo = bll.CarregaModeloSubCategoria(f.codigo);
                txtScatCod.Text        = modelo.ScatCod.ToString();
                txtNome.Text           = modelo.ScatNome;
                cbCatCod.SelectedValue = modelo.CatCod;
                alteraBotoes(3);
            }
            else
            {
                this.LimpaTela();
                this.alteraBotoes(1);
            }
            f.Dispose();
        }