Exemplo n.º 1
0
        private void CarregarDgv()
        {
            dgvCat.Rows.Clear();
            DALConexao cx = new DALConexao(DadosDaConexao.StringDaConexao);

            DataTable tabela;

            if (tipo == "Setor")
            {
                BLLBuffet blls = new BLLBuffet(cx);
                tabela = blls.Listar();

                if (tabela.Rows.Count > 0)
                {
                    for (int i = 0; tabela.Rows.Count > i; i++)
                    {
                        String[] V = new string[] { tabela.Rows[i][0].ToString(), tabela.Rows[i][1].ToString(), tabela.Rows[i][2].ToString() };
                        dgvCat.Rows.Add(V);
                    }
                }
            }
            else if (tipo == "Categoria")
            {
                BLLCategoria bllc = new BLLCategoria(cx);
                tabela = bllc.Listar();

                if (tabela.Rows.Count > 0)
                {
                    for (int i = 0; tabela.Rows.Count > i; i++)
                    {
                        String[] V = new string[] { tabela.Rows[i][0].ToString(), tabela.Rows[i][1].ToString(), tabela.Rows[i][2].ToString() };
                        dgvCat.Rows.Add(V);
                    }
                }
            }
            else
            {
                BLLSubCategoria bllsc = new BLLSubCategoria(cx);
                tabela = bllsc.Listar();

                if (tabela.Rows.Count > 0)
                {
                    for (int i = 0; tabela.Rows.Count > i; i++)
                    {
                        String[] V = new string[] { tabela.Rows[i][0].ToString(), tabela.Rows[i][1].ToString(), tabela.Rows[i][2].ToString() };
                        dgvCat.Rows.Add(V);
                    }
                }
            }
        }
        private void CarregaCat()
        {
            DALConexao cx = new DALConexao(DadosDaConexao.StringDaConexao);

            BLLBuffet bllsetor    = new BLLBuffet(cx);
            DataTable tabelaSetor = bllsetor.Listar();

            BLLCategoria bllCat    = new BLLCategoria(cx);
            DataTable    tabelaCat = bllCat.Listar();

            BLLSubCategoria bllSCat    = new BLLSubCategoria(cx);
            DataTable       tabelaSCat = bllSCat.Listar();

            List <Language> dataSource1 = NewMethod();

            dataSource1.Add(new Language()
            {
                setor = "", Value = "0"
            });

            for (int i = 0; i < tabelaSetor.Rows.Count; i++)
            {
                dataSource1.Add(new Language()
                {
                    setor = tabelaSetor.Rows[i][1].ToString(), Value = Convert.ToInt32(tabelaSetor.Rows[i][0]).ToString()
                });
            }
            var dataSource2 = new List <Language>();

            dataSource2.Add(new Language()
            {
                cat = "", Value1 = "0"
            });

            for (int i = 0; i < tabelaCat.Rows.Count; i++)
            {
                dataSource2.Add(new Language()
                {
                    cat = tabelaCat.Rows[i][1].ToString(), Value1 = Convert.ToInt32(tabelaCat.Rows[i][0]).ToString()
                });
            }
            var dataSource3 = new List <Language>();

            dataSource3.Add(new Language()
            {
                scat = "", Value2 = "0"
            });
            for (int i = 0; i < tabelaSCat.Rows.Count; i++)
            {
                dataSource3.Add(new Language()
                {
                    scat = tabelaSCat.Rows[i][1].ToString(), Value2 = Convert.ToInt32(tabelaSCat.Rows[i][0]).ToString()
                });
            }

            //Atualiza Combobox Setor
            this.cbSetor.DataSource    = dataSource1;
            this.cbSetor.DisplayMember = "setor";
            this.cbSetor.ValueMember   = "Value";

            //Atualiza Combobox Categoria
            this.cbCategoria.DataSource    = dataSource2;
            this.cbCategoria.DisplayMember = "cat";
            this.cbCategoria.ValueMember   = "Value1";

            //Atualiza Combobox Subcategoria
            this.cbSubCategoria.DataSource    = dataSource3;
            this.cbSubCategoria.DisplayMember = "scat";
            this.cbSubCategoria.ValueMember   = "Value2";
        }