コード例 #1
0
        public List<Categoria> ListaCategoriaBanco()
        {
            List<Categoria> categorias = new List<Categoria>();
            string comando = @"SELECT ID_CATEGORIA,DESCRICAO_CATEGORIA FROM CATEGORIA WITH(NOLOCK) ORDER BY DESCRICAO_CATEGORIA";
            using (conn = new ConexaoBD())
            {
                conn.openConnection();
                SqlCommand cmd = new SqlCommand(comando, conn.getConnection());
                var rd = cmd.ExecuteReader();

                while (rd.Read())
                {
                    Categoria categoria = new Categoria();

                    categoria.idCategoria = rd.GetInt32(0);
                    categoria.descricaoCategoria = rd.GetString(1);

                    categorias.Add(categoria);
                }
                conn.closeConnection();
            }

            return categorias;
        }
コード例 #2
0
 public SubCategoria()
 {
     categoria = new Categoria();
 }
コード例 #3
0
        /// <summary>
        /// Evento para Cadastrar uma Categoria ou SubCategoria
        /// Caso der erro abre um modal com a informaçao do erro
        /// Se der certo vai chamar um metodo do banco para inserir e abrir o modal informando o sucesso
        /// </summary>
        protected void btnCadastrarCategoria_Click(object sender, EventArgs e)
        {
            var categoria = new Categoria();
            var subCategoria = new SubCategoria(categoria);

            if (PanelCategoria.Visible)
            {

                VerificaCampoVazio(txtCategoria.Text, "Categoria");
                VerificaCampoVazio(txtCategoriaSubCategoria.Text, "SubCategoria");

                if (alerta == "")
                {

                    categoria.descricaoCategoria = txtCategoria.Text;

                    subCategoria.descricaoSubCategoria = txtCategoriaSubCategoria.Text;

                    int retorno = categoriaBanco.CadastrarCategoria(subCategoria);

                    if (retorno == 0)
                    {
                        alerta = "Sucesso!!";

                        ModalAlerta.Visible = true;
                        txtAlerta.Text = alerta;
                    }
                    else
                    {
                        alerta = "Não foi possivel cadastrar essa Categoria!";

                        ModalAlerta.Visible = true;
                        txtAlerta.Text = alerta;
                    }
                }
                else
                {
                    ModalAlerta.Visible = true;
                    txtAlerta.Text = alerta;
                }
            }
            else
            {
                VerificaCategoriaDDL();
                VerificaCampoVazio(txtSubCategoriaSubCategoria.Text, "SubCategoria");

                if (alerta == "")
                {

                    categoria.idCategoria = Int32.Parse(ddlCategoria.SelectedValue);

                    if (categoria.idCategoria == 0)
                    {
                        alerta = "Você deve selecionar uma Categoria!";

                        ModalAlerta.Visible = true;
                        txtAlerta.Text = alerta;
                        return;
                    }

                    subCategoria.descricaoSubCategoria = txtSubCategoriaSubCategoria.Text;

                    int retorno = categoriaBanco.CadastrarSubCategoria(subCategoria);

                    if (retorno == 0)
                    {
                        ModalAlerta.Visible = true;
                        txtAlerta.Text = "Sucesso!!";
                    }
                    else
                    {
                        ModalAlerta.Visible = true;
                        txtAlerta.Text = "Não foi possivel cadastrar essa SubCategoria!";
                    }
                }
                else
                {
                    ModalAlerta.Visible = true;
                    txtAlerta.Text = alerta;
                }

            }

            LimparCampos();

            PanelCategoria.Visible = false;
            PanelSubCategoria.Visible = false;
            PanelRodape.Visible = false;
        }
コード例 #4
0
 public SubCategoria(Categoria categoria)
 {
     this.categoria = categoria;
 }