Пример #1
0
        private void txtNome_Leave(object sender, EventArgs e)
        {
            if (txtNome.Text.Trim() != "")
            {
                DALConexao cx  = new DALConexao(DadosDaConexao.StringDaConexao);
                BLLPratos  bll = new BLLPratos(cx);

                DataTable tabela = bll.LocalizarNome(txtNome.Text.Trim());

                if (tabela.Rows.Count == 0)
                {
                    txtNome.Text = txtNome.Text.Trim().ToUpper();
                    if (txtCodigoPrato.Text.Trim() == ".  .")
                    {
                        txtCodigoPrato.Text = CodigoNovo();
                    }
                }
                else
                {
                    if (liberado && tabela.Rows[0][0].ToString() != txtCodigoPrato.Text)
                    {
                        MessageBox.Show($"Já existe um prato chamado {txtNome.Text}.");
                        txtNome.Focus();
                        txtNome.Select();
                    }
                    else
                    {
                    }
                }
            }
            else
            {
            }
        }
Пример #2
0
        private string CodigoNovo()
        {
            DALConexao cx     = new DALConexao(DadosDaConexao.StringDaConexao);
            BLLPratos  bllCod = new BLLPratos(cx);

            DataTable tabela = bllCod.ListarCodigos();

            string codigo  = "";
            string prefixo = "20.01.";

            for (int i = 0; i < tabela.Rows.Count + 1; i++)
            {
                try
                {
                    codigo = prefixo + (i + 1).ToString("0000");
                    string CodigoProdutoE = tabela.Rows[i][0].ToString();

                    if (codigo != CodigoProdutoE)
                    {
                        i = tabela.Rows.Count + 1;
                    }
                }
                catch
                {
                    i = tabela.Rows.Count + 1;
                }
            }

            return(codigo);
        }
Пример #3
0
        public double CustoIngrediente(string codigo, int unidade)
        {
            DALConexao cx      = new DALConexao(DadosDaConexao.StringDaConexao);
            BLLPratos  bll     = new BLLPratos(cx);
            DataTable  tabela  = new DataTable();
            DataTable  tabela2 = new DataTable();


            double CustoTotal = 0;

            //Se for Prato
            if (codigo.Substring(0, 2) == "20")
            {
                tabela2 = bll.LocalizarPorCod(codigo);
                try
                {
                    CustoTotal += CalculaCustoFicha(codigo, unidade) / Convert.ToDouble(tabela2.Rows[0][7]);;
                }
                catch
                {
                    CustoTotal += 0;
                }
            }

            //Se for ingrediente
            else
            {
                CustoTotal += UltimaBaixaItem(codigo, unidade);
            }

            return(CustoTotal);
        }
Пример #4
0
        private Double CalculaCustoFicha3(string codigo, int unidade)
        {
            double     CustoTotal3 = 0;
            string     codItem     = "";
            DALConexao cx          = new DALConexao(DadosDaConexao.StringDaConexao);
            BLLPratos  bll         = new BLLPratos(cx);

            DataTable tabela  = new DataTable();
            DataTable Tabela2 = new DataTable();
            DataTable tabela3 = new DataTable();

            tabela = bll.ListarIngredientes(codigo);

            for (int i = 0; i < tabela.Rows.Count; i++)
            {
                codItem = tabela.Rows[i][0].ToString();

                //Se for Prato
                if (codItem.Substring(0, 2) == "20")
                {
                    CustoTotal3 += 0;
                }

                //Se for ingrediente
                else
                {
                    CustoTotal3 += (UltimaBaixaItem(codItem, unidade) * Convert.ToDouble(tabela.Rows[i][1].ToString()));
                }
            }

            return(CustoTotal3);
        }
Пример #5
0
        private void Alterar()
        {
            DTOPratos dto = new DTOPratos();

            DALConexao cx  = new DALConexao(DadosDaConexao.StringDaConexao);
            BLLPratos  bll = new BLLPratos(cx);

            dto.CodPrato         = txtCodigoPrato.Text;
            dto.NomePrato        = txtNome.Text.Trim().ToUpper();
            dto.IdSetor          = Convert.ToInt32(cbSetor.SelectedValue);
            dto.Cat              = Convert.ToInt32(cbCategoria.SelectedValue);
            dto.SubCat           = Convert.ToInt32(cbSubCategoria.SelectedValue);
            dto.RendimentoPrato  = Convert.ToDouble(txtRendimento.Text);
            dto.ModoPreparoPrato = txtPreparo.Text.Trim();
            dto.PesoPrato        = Convert.ToDouble(txtPeso.Text);
            dto.IdUsuario        = idUsuario;
            dto.DescPrato        = txtDescricao.Text.Trim().ToUpper();

            BLLAeB bllaeb = new BLLAeB(cx);
            DTOAeB dtoaeb = new DTOAeB();

            dtoaeb.CodAeb  = dto.CodPrato;
            dtoaeb.NomeAeb = dto.NomePrato;
            dtoaeb.UmAeb   = "KG";
            dtoaeb.Fc      = 0;

            try
            {
                bll.Alterar(dto);
                MessageBox.Show($"Ficha técnica {txtCodigoPrato.Text} - {txtNome.Text} alterada com sucesso.");


                DataTable tabelaAeb;

                tabelaAeb = bllaeb.Localizar(dto.CodPrato);

                if (tabelaAeb.Rows.Count == 0)
                {
                    bllaeb.Incluir(dtoaeb);
                }
                else
                {
                    bllaeb.AlterarPorCod(dtoaeb);
                }


                gbFicha.Enabled        = false;
                gbIngredientes.Enabled = true;
                txtCodItem.Focus();
            }
            catch
            {
                MessageBox.Show("Erro ao alterar Ficha técnica.");
            }
        }
Пример #6
0
        private void VerificarNomePrato()
        {
            DALConexao cx     = new DALConexao(DadosDaConexao.StringDaConexao);
            BLLPratos  bll    = new BLLPratos(cx);
            DataTable  tabela = bll.LocalizarNome(txtNome.Text);

            if (tabela.Rows.Count > 0 && liberado)
            {
                MessageBox.Show("Já existe um prato chamado \"" + txtNome.Text.Trim().ToUpper() + "\".");
            }
        }
Пример #7
0
        private void CarregarIngredientesPorCodigo(string cod)
        {
            dgvFicha.Rows.Clear();

            //Linha por linha busca ingrediente com custo
            DALConexao cx  = new DALConexao(DadosDaConexao.StringDaConexao);
            BLLPratos  bll = new BLLPratos(cx);
            DataTable  tabelaIngredientes = bll.ListarIngredientes(txtCodigoPrato.Text);

            BLLAeB    bllaeb = new BLLAeB(cx);
            DataTable tabelaAeb;

            Augoritmos a = new Augoritmos();


            if (tabelaIngredientes.Rows.Count > 0)
            {
                for (int i = 0; i < tabelaIngredientes.Rows.Count; i++)
                {
                    //cod_item, quant_ingrediente

                    tabelaAeb = bllaeb.LocalizarPorCod(tabelaIngredientes.Rows[i][0].ToString());

                    string codIngrediente, nomeingrediente, um;
                    double quant, custoUnit, custoTotal, fc;

                    codIngrediente  = tabelaIngredientes.Rows[i][0].ToString();
                    nomeingrediente = tabelaAeb.Rows[0][0].ToString();
                    um = tabelaAeb.Rows[0][1].ToString();
                    if (string.IsNullOrEmpty(tabelaAeb.Rows[0][2].ToString()))
                    {
                        fc = 0;
                    }
                    else
                    {
                        fc = Convert.ToDouble(tabelaAeb.Rows[0][2]);
                    }

                    quant = Convert.ToDouble(tabelaIngredientes.Rows[i][1]);

                    custoUnit  = a.CustoIngrediente(codIngrediente, Convert.ToInt32(cbUnidade.SelectedValue));
                    custoTotal = custoUnit * quant;


                    String[] V = new string[] { codIngrediente, nomeingrediente, quant.ToString("#,0.0000"), um, fc.ToString("#,0.0000"), custoUnit.ToString("#,0.00"), custoTotal.ToString("#,0.00") };
                    dgvFicha.Rows.Add(V);
                }
                RecalcularCusto();
            }
        }
Пример #8
0
        public void ExcluirPrato(string cod)
        {
            DALConexao cx = new DALConexao(DadosDaConexao.StringDaConexao);

            // Exclui prato
            BLLPratos bllp = new BLLPratos(cx);

            try
            {
                bllp.Excluir(cod);
            }
            catch
            {
                throw new Exception("Erro ao excluir Prato!");
            }

            //Exclui ingredientes referentes ao prato
            BLLIngredientes blli = new BLLIngredientes(cx);

            try
            {
                blli.ExcluirPorPrato(cod);
            }
            catch
            {
                throw new Exception("Erro ao excluir Ingrediente!");
            }

            //excluir prato da tabela AEB
            BLLAeB bllaeb = new BLLAeB(cx);

            try
            {
                bllaeb.ExcluirPorCod(cod);
            }
            catch
            {
                throw new Exception("Erro ao excluir Aeb!");
            }

            //Exclui imagem referente ao prato (se houver)
            IncluiFoto(cod, "del");
        }
        private double CalculaCustoFicha(string codigo)
        {
            double CustoTotal = 0;

            DALConexao cx  = new DALConexao(DadosDaConexao.StringDaConexao);
            BLLPratos  bll = new BLLPratos(cx);

            DataTable tabela  = new DataTable();
            DataTable Tabela2 = new DataTable();

            tabela = bll.ListarIngredientes(codigo);

            for (int i = 0; i < tabela.Rows.Count; i++)
            {
                Tabela2 = bll.CustoIngrediente(tabela.Rows[i][0].ToString(), Convert.ToInt32(cbUnidade.SelectedValue));

                CustoTotal += Convert.ToDouble(Tabela2.Rows[0][0]) * Convert.ToDouble(tabela.Rows[i][1]);
            }

            return(CustoTotal);
        }
Пример #10
0
        public double CalculaCustoFicha(string codigo, int unidade)
        {
            double     CustoTotal = 0;
            string     codItem    = "";
            DALConexao cx         = new DALConexao(DadosDaConexao.StringDaConexao);
            BLLPratos  bll        = new BLLPratos(cx);

            DataTable tabela  = new DataTable();
            DataTable tabela3 = new DataTable();

            tabela = bll.ListarIngredientes(codigo);

            for (int i = 0; i < tabela.Rows.Count; i++)
            {
                codItem = tabela.Rows[i][0].ToString();

                //Se for Prato
                if (codItem.Substring(0, 2) == "20")
                {
                    tabela3 = bll.LocalizarPorCod(codItem);
                    try
                    {
                        CustoTotal += ((CalculaCustoFicha2(codItem, unidade) / Convert.ToDouble(tabela3.Rows[0][7])) * Convert.ToDouble(tabela.Rows[i][1].ToString()));
                    }
                    catch
                    {
                        CustoTotal += 0;
                    }
                }

                //Se for ingrediente
                else
                {
                    CustoTotal += (UltimaBaixaItem(codItem, unidade) * Convert.ToDouble(tabela.Rows[i][1].ToString()));
                }
            }

            return(CustoTotal);
        }
        private void CarregaDgv()
        {
            string busca = $"select p.cod_prato, p.nome_prato,  b.nome_buffet, c.nome_cat, s.nome_scat," +
                           "p.peso_prato, p.rendimento_prato, p.desc_prato from prato p join buffet b on p.id_setor = b.id_buffet " +
                           $"left join categoria c on p.cat = c.id_cat left join subcategoria s on p.subcat = s.id_scat where nome_prato like '%{txtNome.Text}%'";

            if (cbSetor.Text != "")
            {
                busca += $" and id_setor = {Convert.ToInt32(cbSetor.SelectedValue)}";
            }

            if (cbCategoria.Text != "")
            {
                busca += $" and cat = {Convert.ToInt32(cbCategoria.SelectedValue)}";
            }

            if (cbSubCategoria.Text != "")
            {
                busca += $" and subcat = {Convert.ToInt32(cbSubCategoria.SelectedValue)}";
            }

            busca += "order by p.cod_prato;";

            DALConexao  cx      = new DALConexao(DadosDaConexao.StringDaConexao);
            BLLPratos   bll     = new BLLPratos(cx);
            DataTable   tabela  = bll.BuscaFichas(busca);
            DTOCaminhos caminho = new DTOCaminhos();


            //this.dgvFichas.Columns[9].ValueType = typeof(double);

            DataTable dados = new DataTable();

            Image ver  = Image.FromFile(caminho.Icones + "document.png");
            Image edit = Image.FromFile(caminho.Icones + "pencil.png");
            Image del  = Image.FromFile(caminho.Icones + "trash.png");

            dados.Clear();
            dados.Columns.Add("CODIGO");
            dados.Columns.Add("NOME");
            dados.Columns.Add("SETOR");
            dados.Columns.Add("CAT");
            dados.Columns.Add("SCAT");
            dados.Columns.Add("PESO", typeof(double));
            dados.Columns.Add("RENDIMENTO", typeof(double));
            dados.Columns.Add("CUSTO/KG", typeof(double));
            dados.Columns.Add("CUSTO/PORCAO", typeof(double));
            dados.Columns.Add("TOTAL", typeof(double));
            dados.Columns.Add("VER", typeof(System.Drawing.Bitmap));
            dados.Columns.Add("EDT", typeof(System.Drawing.Bitmap));
            dados.Columns.Add("DEL", typeof(System.Drawing.Bitmap));



            DataRow _ravi = dados.NewRow();

            dgvFichas.Visible = false;
            for (int i = 0; i < tabela.Rows.Count; i++)
            {
                string categoria      = "";
                string subcategoria   = "";
                double peso           = 0;
                double rendimento     = 0;
                double custo          = 0;
                double custoPorKg     = 0;
                double custoPorPorcao = 0;

                peso       = Convert.ToDouble(tabela.Rows[i][5]);
                rendimento = Convert.ToDouble(tabela.Rows[i][6]);

                try
                {
                    Augoritmos au = new Augoritmos();
                    custo = au.CalculaCustoFicha(tabela.Rows[i][0].ToString(), Convert.ToInt32(cbUnidade.SelectedValue));
                }

                catch
                {
                }

                if (peso > 0)
                {
                    custoPorKg = custo / peso;
                }

                if (rendimento > 0)
                {
                    custoPorPorcao = custo / rendimento;
                }

                if (!(string.IsNullOrEmpty(tabela.Rows[i][3].ToString())))
                {
                    categoria = tabela.Rows[i][3].ToString();
                }

                if (!(string.IsNullOrEmpty(tabela.Rows[i][4].ToString())))
                {
                    subcategoria = tabela.Rows[i][4].ToString();
                }

                dados.Rows.Add(new object[] { tabela.Rows[i][0].ToString(), tabela.Rows[i][1].ToString(), tabela.Rows[i][2].ToString(), categoria, subcategoria, Convert.ToDouble(Math.Round(peso, 4)), Convert.ToDouble(Math.Round(rendimento, 2)), Convert.ToDouble(Math.Round(custoPorKg, 2)), Convert.ToDouble(Math.Round(custoPorPorcao, 2)), Convert.ToDouble(Math.Round(custo, 2)), ver, edit, del });
            }

            dgvFichas.DataSource = dados;
            dgvFichas.Visible    = true;
            FormatarDGV();
        }
Пример #12
0
        private void CarregaFicha(string cod)
        {
            DALConexao cx     = new DALConexao(DadosDaConexao.StringDaConexao);
            BLLPratos  bllp   = new BLLPratos(cx);
            DataTable  tabela = bllp.LocalizarPorCod(cod);

            DTOCaminhos dto = new DTOCaminhos();

            string nomePrato, codigo, desc, preparo;
            double rendimento, peso;
            int    setor, cat, subcat;

            // Preenche dados da Ficha
            codigo     = cod;
            nomePrato  = tabela.Rows[0][1].ToString();
            desc       = tabela.Rows[0][8].ToString();
            preparo    = tabela.Rows[0][6].ToString();
            rendimento = Convert.ToDouble(tabela.Rows[0][5]);
            peso       = Convert.ToDouble(tabela.Rows[0][7]);
            setor      = Convert.ToInt32(tabela.Rows[0][2]);
            cat        = Convert.ToInt32(tabela.Rows[0][3]);
            subcat     = Convert.ToInt32(tabela.Rows[0][4]);

            lbTitulo.Text = $"{nomePrato} ({cod})";


            if (string.IsNullOrEmpty(preparo))
            {
                lbPreparo.Text = "";
            }
            else
            {
                lbPreparo.Text = preparo;
            }

            if (string.IsNullOrEmpty(peso.ToString()))
            {
                lbPeso.Text = "0,0000";
            }
            else
            {
                lbPeso.Text = peso.ToString("#,0.0000");
            }

            lbRendimento.Text = rendimento.ToString("#,0.00");

            //Carrega setor, categoria e subcategoria

            BLLBuffet bllsetor    = new BLLBuffet(cx);
            DataTable tabelasetor = bllsetor.localizarPorId(setor);

            lbSetor.Text = tabelasetor.Rows[0][0].ToString();

            BLLCategoria bllcat    = new BLLCategoria(cx);
            DataTable    tabelacat = bllcat.localizarPorId(cat);

            if (tabelacat.Rows.Count > 0)
            {
                lbCategoria.Text = tabelacat.Rows[0][0].ToString();
            }
            else
            {
                lbCategoria.Text = "";
            }

            BLLSubCategoria bllscat    = new BLLSubCategoria(cx);
            DataTable       tabelascat = bllscat.localizarPorId(subcat);

            if (tabelascat.Rows.Count > 0)
            {
                lbSubcategoria.Text = tabelascat.Rows[0][0].ToString();
            }
            else
            {
                lbSubcategoria.Text = "";
            }

            //Verifica se existe foto

            if (File.Exists(dto.FT + cod + ".jpg"))
            {
                pbImagem.Visible = true;
                pbimagem1.Load(dto.FT + cod + ".jpg");
            }
            else
            {
                pbImagem.Visible = false;
            }
        }
Пример #13
0
        private void CarregarIngredientesPorCodigo(string cod)
        {
            dgvDados.Rows.Clear();

            //Linha por linha busca ingrediente com custo
            DALConexao cx  = new DALConexao(DadosDaConexao.StringDaConexao);
            BLLPratos  bll = new BLLPratos(cx);
            DataTable  tabelaIngredientes = bll.ListarIngredientes(cod);

            BLLAeB    bllaeb = new BLLAeB(cx);
            DataTable tabelaAeb;

            Augoritmos a = new Augoritmos();

            double TotalFicha = 0;

            if (tabelaIngredientes.Rows.Count > 0)
            {
                for (int i = 0; i < tabelaIngredientes.Rows.Count; i++)
                {
                    //cod_item, quant_ingrediente

                    tabelaAeb = bllaeb.LocalizarPorCod(tabelaIngredientes.Rows[i][0].ToString());

                    string codIngrediente, nomeingrediente, um;
                    double quant, custoUnit, custoTotal, fc;

                    codIngrediente  = tabelaIngredientes.Rows[i][0].ToString();
                    nomeingrediente = tabelaAeb.Rows[0][0].ToString();
                    um = tabelaAeb.Rows[0][1].ToString();
                    if (string.IsNullOrEmpty(tabelaAeb.Rows[0][2].ToString()))
                    {
                        fc = 0;
                    }
                    else
                    {
                        fc = Convert.ToDouble(tabelaAeb.Rows[0][2]);
                    }

                    quant = Convert.ToDouble(tabelaIngredientes.Rows[i][1]);

                    custoUnit  = a.CustoIngrediente(codIngrediente, unidade);
                    custoTotal = custoUnit * quant;


                    String[] V = new string[] { codIngrediente, nomeingrediente, um, fc.ToString("#,0.0000"), quant.ToString("#,0.0000"), custoUnit.ToString("#,0.00"), custoTotal.ToString("#,0.00") };
                    dgvDados.Rows.Add(V);

                    TotalFicha += custoTotal;
                }

                lbTotal.Text = TotalFicha.ToString("#,0.00");

                if (Convert.ToDouble(lbPeso.Text) > 0)
                {
                    lbTotalKg.Text = (TotalFicha / Convert.ToDouble(lbPeso.Text)).ToString("#,0.00");
                }
                else
                {
                    lbTotalKg.Text = "0,00";
                }

                lbcustoPorcao.Text = (TotalFicha / Convert.ToDouble(lbRendimento.Text)).ToString("#,0.00");
            }
        }
Пример #14
0
        private void Salvar()
        {
            // Salvar dados da ficha

            DTOPratos  dto = new DTOPratos();
            Augoritmos a   = new Augoritmos();
            DALConexao cx  = new DALConexao(DadosDaConexao.StringDaConexao);
            BLLPratos  bll = new BLLPratos(cx);

            dto.CodPrato         = txtCodigoPrato.Text;
            dto.NomePrato        = txtNome.Text.Trim().ToUpper();
            dto.IdSetor          = Convert.ToInt32(cbSetor.SelectedValue);
            dto.Cat              = Convert.ToInt32(cbCategoria.SelectedValue);
            dto.SubCat           = Convert.ToInt32(cbSubCategoria.SelectedValue);
            dto.RendimentoPrato  = Convert.ToDouble(txtRendimento.Text);
            dto.ModoPreparoPrato = txtPreparo.Text.Trim();
            dto.PesoPrato        = Convert.ToDouble(txtPeso.Text);
            dto.IdUsuario        = idUsuario;
            dto.DescPrato        = txtDescricao.Text.Trim().ToUpper();

            try
            {
                dto.IdPrato = Convert.ToInt32(txtId.Text);
            }
            catch
            {
            }

            //Dados de AEB

            DTOAeB dtoaeb = new DTOAeB();
            BLLAeB bllaeb = new BLLAeB(cx);

            dtoaeb.CodAeb  = dto.CodPrato;
            dtoaeb.NomeAeb = dto.NomePrato;
            dtoaeb.UmAeb   = "KG";
            dtoaeb.Fc      = 0;


            if (operacao == "inserir")
            {
                try
                {
                    bll.Incluir(dto);
                    bllaeb.Incluir(dtoaeb);
                    SalvarIngredientes();

                    a.IncluiFoto(txtCodigoPrato.Text, foto);

                    MessageBox.Show($"Ficha técnica {dto.CodPrato} - {dto.NomePrato} salva com sucesso.");
                    operacao = "consultar";
                    AlteraBotoes();
                }
                catch (Exception e)
                {
                    MessageBox.Show("Erro ao salvar a ficha.\n" + e.ToString());
                }
            }
            else if (operacao == "editar")
            {
                try
                {
                    bll.Alterar(dto);
                    bllaeb.AlterarPorCod(dtoaeb);
                    SalvarIngredientes();

                    a.IncluiFoto(txtCodigoPrato.Text, foto);

                    MessageBox.Show($"Ficha técnica {dto.CodPrato} - {dto.NomePrato} alterada com sucesso.");
                    operacao = "consultar";
                    AlteraBotoes();
                }
                catch (Exception e)
                {
                    MessageBox.Show("Erro ao alterar a ficha.\n" + e.ToString());
                }
            }
        }
Пример #15
0
        private void CarregaFicha(string cod)
        {
            DefaultValues();

            DALConexao cx     = new DALConexao(DadosDaConexao.StringDaConexao);
            BLLPratos  bllp   = new BLLPratos(cx);
            DataTable  tabela = bllp.LocalizarPorCod(cod);

            string nomePrato, codigo, desc, preparo;
            double rendimento, peso;
            int    setor, cat, subcat;

            if (tabela.Rows.Count == 0)
            {
                MessageBox.Show("Não foi possível Localizar a ficha técnica selecionada.");
            }
            else
            {
                // Preenche dados da Ficha
                codigo     = cod;
                nomePrato  = tabela.Rows[0][1].ToString();
                desc       = tabela.Rows[0][8].ToString();
                preparo    = tabela.Rows[0][6].ToString();
                rendimento = Convert.ToDouble(tabela.Rows[0][5]);
                peso       = Convert.ToDouble(tabela.Rows[0][7]);
                setor      = Convert.ToInt32(tabela.Rows[0][2]);
                cat        = Convert.ToInt32(tabela.Rows[0][3]);
                subcat     = Convert.ToInt32(tabela.Rows[0][4]);

                txtCodigoPrato.Text = cod;
                txtNome.Text        = nomePrato;
                if (string.IsNullOrEmpty(desc))
                {
                    txtDescricao.Text = "";
                }
                else
                {
                    txtDescricao.Text = desc;
                }

                if (string.IsNullOrEmpty(preparo))
                {
                    txtPreparo.Text = "";
                }
                else
                {
                    txtPreparo.Text = preparo;
                }

                if (string.IsNullOrEmpty(peso.ToString()))
                {
                    txtPeso.Text = "0,0000";
                }
                else
                {
                    txtPeso.Text = peso.ToString("#,0.0000");
                }

                txtRendimento.Text = rendimento.ToString("#,0.00");


                //Carrega setor, categoria e subcategoria

                BLLBuffet bllsetor    = new BLLBuffet(cx);
                DataTable tabelasetor = bllsetor.localizarPorId(setor);

                cbSetor.Text = tabelasetor.Rows[0][0].ToString();

                BLLCategoria bllcat    = new BLLCategoria(cx);
                DataTable    tabelacat = bllcat.localizarPorId(cat);

                if (tabelacat.Rows.Count > 0)
                {
                    cbCategoria.Text = tabelacat.Rows[0][0].ToString();
                }

                BLLSubCategoria bllscat    = new BLLSubCategoria(cx);
                DataTable       tabelascat = bllscat.localizarPorId(cat);

                if (tabelascat.Rows.Count > 0)
                {
                    cbSubCategoria.Text = tabelascat.Rows[0][0].ToString();
                }

                CarregarIngredientesPorCodigo(cod);

                DTOCaminhos dtocaminhos = new DTOCaminhos();

                try
                {
                    pbFoto.Load(dtocaminhos.FT + cod + ".jpg");
                }
                catch
                {
                    pbFoto.Load(dtocaminhos.Produtos + "0.jpg");
                    btDeletaFoto.Enabled = false;
                }
            }
        }
Пример #16
0
        public void paraPDF(bool img, string codigoP, string caminho, int unidade)
        {
            DALConexao cx     = new DALConexao(DadosDaConexao.StringDaConexao);
            BLLPratos  bllp   = new BLLPratos(cx);
            DataTable  tabela = bllp.LocalizarPorCod(codigoP);

            DTOCaminhos dto = new DTOCaminhos();

            string nomePrato, codigo, desc, preparo, imagem, nome_cat, nome_setor, nome_scat;
            double rendimento, peso, total, totalKg, totalPorcao;
            int    id_setor, id_cat, id_subcat;

            // Preenche dados da Ficha
            codigo      = codigoP;
            nomePrato   = tabela.Rows[0][1].ToString();
            desc        = tabela.Rows[0][8].ToString();
            preparo     = tabela.Rows[0][6].ToString();
            rendimento  = Convert.ToDouble(tabela.Rows[0][5]);
            peso        = Convert.ToDouble(tabela.Rows[0][7]);
            id_setor    = Convert.ToInt32(tabela.Rows[0][2]);
            id_cat      = Convert.ToInt32(tabela.Rows[0][3]);
            id_subcat   = Convert.ToInt32(tabela.Rows[0][4]);
            imagem      = "";
            nome_setor  = "";
            nome_cat    = "";
            nome_scat   = "";
            total       = CalculaCustoFicha(codigoP, unidade);
            totalKg     = 0;
            totalPorcao = 0;

            if (peso > 0)
            {
                totalKg = total / peso;
            }

            if (rendimento > 0)
            {
                totalPorcao = total / rendimento;
            }


            if (File.Exists(dto.FT + codigoP + ".jpg") && img)
            {
                imagem = (dto.FT + codigoP + ".jpg");
            }

            //Carrega setor, categoria e subcategoria

            BLLBuffet bllsetor    = new BLLBuffet(cx);
            DataTable tabelasetor = bllsetor.localizarPorId(id_setor);

            nome_setor = tabelasetor.Rows[0][0].ToString();

            BLLCategoria bllcat    = new BLLCategoria(cx);
            DataTable    tabelacat = bllcat.localizarPorId(id_cat);

            if (tabelacat.Rows.Count > 0)
            {
                nome_cat = tabelacat.Rows[0][0].ToString();
            }


            BLLSubCategoria bllscat    = new BLLSubCategoria(cx);
            DataTable       tabelascat = bllscat.localizarPorId(id_subcat);

            if (tabelascat.Rows.Count > 0)
            {
                nome_scat = tabelascat.Rows[0][0].ToString();
            }


            //Exportar para pdf

            iTextSharp.text.Font Titulo    = FontFactory.GetFont("Segoe UI Light", 15, BaseColor.BLACK);
            iTextSharp.text.Font subtitulo = FontFactory.GetFont("Verdana", 8, 1, BaseColor.BLACK);
            iTextSharp.text.Font texto     = FontFactory.GetFont("Segoe UI", 8, BaseColor.BLACK);


            Document doc = new Document(iTextSharp.text.PageSize.A4, 5, 5, 30, 30);

            PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream($"{caminho}", FileMode.Create));

            doc.Open();

            float larguraTotal = 550;

            float largura1 = 0.11f;
            float largura2 = 0.38f;
            float largura3 = 0.08f;
            float largura4 = 0.1f;
            float largura5 = 0.1f;
            float largura6 = 0.12f;
            float largura7 = 0.12f;

            largura1 *= larguraTotal;
            largura2 *= larguraTotal;
            largura3 *= larguraTotal;
            largura4 *= larguraTotal;
            largura5 *= larguraTotal;
            largura6 *= larguraTotal;
            largura7 *= larguraTotal;

            BaseColor CSTitulo        = BaseColor.GRAY;
            BaseColor linhaAlternada0 = BaseColor.WHITE;
            BaseColor linhaAlternada1 = BaseColor.LIGHT_GRAY;


            PdfPTable table = new PdfPTable(7);

            table.DefaultCell.Phrase = new Phrase()
            {
                Font = texto
            };
            table.TotalWidth  = larguraTotal;
            table.PaddingTop  = 0;
            table.LockedWidth = true;
            float[] widths = new float[] { largura1, largura2, largura3, largura4, largura5, largura6, largura7 };
            table.SetWidths(widths);

            if (imagem != "")

            {
                iTextSharp.text.Image pic = iTextSharp.text.Image.GetInstance(dto.FT + codigoP + ".jpg");

                float largura = 200;
                float alturai = 0.0f;
                float alturaNova;
                alturai    = pic.Height;
                alturaNova = (largura * alturai) / pic.Width;
                pic.ScaleAbsolute(largura, alturaNova);

                PdfPCell foto = new PdfPCell(pic);

                foto.Colspan             = 7;
                foto.VerticalAlignment   = PdfPCell.ALIGN_MIDDLE;
                foto.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                table.AddCell(foto);
            }


            PdfPCell cell = new PdfPCell(new Phrase($"{nomePrato} ({codigoP}) ", new iTextSharp.text.Font(Titulo)));

            cell.Colspan = 6;
            cell.Rowspan = 6;


            cell.FixedHeight         = 40f;
            cell.HorizontalAlignment = 1; //0=esquerda, 1 = centro, 2=direita
            cell.VerticalAlignment   = PdfPCell.ALIGN_MIDDLE;
            table.AddCell(cell);

            float altura = 15f;

            PdfPCell tctotal = new PdfPCell(new Phrase("CUSTO TOTAL", new iTextSharp.text.Font(subtitulo)));

            tctotal.BackgroundColor = (CSTitulo);

            tctotal.FixedHeight         = altura;
            tctotal.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
            tctotal.VerticalAlignment   = PdfPCell.ALIGN_MIDDLE;
            table.AddCell(tctotal);


            PdfPCell ctotal = new PdfPCell(new Phrase(total.ToString("#0,0.00"), new iTextSharp.text.Font(texto)));

            ctotal.FixedHeight         = altura;
            ctotal.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
            ctotal.VerticalAlignment   = PdfPCell.ALIGN_MIDDLE;
            table.AddCell(ctotal);

            PdfPCell tckg = new PdfPCell(new Phrase("CUSTO/Kg", new iTextSharp.text.Font(subtitulo)));

            tckg.BackgroundColor = (CSTitulo);

            tckg.FixedHeight         = altura;
            tckg.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
            tckg.VerticalAlignment   = PdfPCell.ALIGN_MIDDLE;
            table.AddCell(tckg);

            PdfPCell ckg = new PdfPCell(new Phrase(totalKg.ToString("#0,0.00"), new iTextSharp.text.Font(texto)));

            ckg.FixedHeight         = altura;
            ckg.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
            ckg.VerticalAlignment   = PdfPCell.ALIGN_MIDDLE;
            table.AddCell(ckg);

            PdfPCell tcporcao = new PdfPCell(new Phrase("CUSTO/PORÇÃO", new iTextSharp.text.Font(subtitulo)));

            tcporcao.BackgroundColor = (CSTitulo);

            tcporcao.FixedHeight         = altura;
            tcporcao.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
            tcporcao.VerticalAlignment   = PdfPCell.ALIGN_MIDDLE;
            table.AddCell(tcporcao);

            PdfPCell cporcao = new PdfPCell(new Phrase(totalPorcao.ToString("#0,0.00"), new iTextSharp.text.Font(texto)));

            cporcao.FixedHeight         = altura;
            cporcao.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
            cporcao.VerticalAlignment   = PdfPCell.ALIGN_MIDDLE;
            table.AddCell(cporcao);

            altura = 20f;

            PdfPCell tsetor = new PdfPCell(new Phrase("SETOR", new iTextSharp.text.Font(subtitulo)));

            tsetor.BackgroundColor = (CSTitulo);

            tsetor.FixedHeight         = altura;
            tsetor.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
            tsetor.VerticalAlignment   = PdfPCell.ALIGN_MIDDLE;
            table.AddCell(tsetor);

            PdfPCell tcategoria = new PdfPCell(new Phrase("CATEGORIZAÇÃO", new iTextSharp.text.Font(subtitulo)));

            tcategoria.BackgroundColor = (CSTitulo);

            tcategoria.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
            tcategoria.VerticalAlignment   = PdfPCell.ALIGN_MIDDLE;
            tcategoria.FixedHeight         = altura;
            tcategoria.Colspan             = 4;
            table.AddCell(tcategoria);

            PdfPCell tpeso = new PdfPCell(new Phrase("PESO", new iTextSharp.text.Font(subtitulo)));

            tpeso.BackgroundColor = (CSTitulo);

            tpeso.FixedHeight         = altura;
            tpeso.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
            tpeso.VerticalAlignment   = PdfPCell.ALIGN_MIDDLE;
            table.AddCell(tpeso);

            PdfPCell trendimento = new PdfPCell(new Phrase("RENDIMENTO", new iTextSharp.text.Font(subtitulo)));

            trendimento.BackgroundColor = (CSTitulo);

            trendimento.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
            trendimento.VerticalAlignment   = PdfPCell.ALIGN_MIDDLE;
            cell.FixedHeight = altura;
            table.AddCell(trendimento);


            altura = 15;

            PdfPCell setor = new PdfPCell(new Phrase(nome_setor, texto));

            setor.FixedHeight         = altura;
            setor.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
            setor.VerticalAlignment   = PdfPCell.ALIGN_MIDDLE;
            table.AddCell(setor);

            string categorias = "";

            if (nome_cat != "")
            {
                categorias = nome_cat;
            }
            if (nome_scat != "")
            {
                if (nome_cat == "")
                {
                    categorias += nome_scat;
                }
                else
                {
                    categorias += ", " + nome_scat;
                }
            }

            PdfPCell categoria = new PdfPCell(new Phrase(categorias, texto));

            categoria.FixedHeight         = altura;
            categoria.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
            categoria.VerticalAlignment   = PdfPCell.ALIGN_MIDDLE;
            categoria.Colspan             = 4;
            table.AddCell(categoria);

            PdfPCell pesopdf = new PdfPCell(new Phrase(peso.ToString("#,0.0000"), texto));

            pesopdf.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
            pesopdf.VerticalAlignment   = PdfPCell.ALIGN_MIDDLE;
            pesopdf.FixedHeight         = altura;
            table.AddCell(pesopdf);

            PdfPCell rendimentoPdf = new PdfPCell(new Phrase(rendimento.ToString("#0,0.00"), texto));

            rendimentoPdf.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
            rendimentoPdf.VerticalAlignment   = PdfPCell.ALIGN_MIDDLE;
            rendimentoPdf.FixedHeight         = altura;
            table.AddCell(rendimentoPdf);

            altura = 20;

            PdfPCell cod = new PdfPCell(new Phrase("CODIGO", new iTextSharp.text.Font(subtitulo)));

            cod.BackgroundColor = (CSTitulo);

            cod.FixedHeight         = altura;
            cod.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
            cod.VerticalAlignment   = PdfPCell.ALIGN_MIDDLE;
            table.AddCell(cod);

            PdfPCell item = new PdfPCell(new Phrase("ITEM", new iTextSharp.text.Font(subtitulo)));

            item.BackgroundColor = (CSTitulo);

            item.FixedHeight         = altura;
            item.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
            item.VerticalAlignment   = PdfPCell.ALIGN_MIDDLE;

            table.AddCell(item);

            PdfPCell fc = new PdfPCell(new Phrase("FC", new iTextSharp.text.Font(subtitulo)));

            fc.BackgroundColor = (CSTitulo);

            fc.FixedHeight         = altura;
            fc.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
            fc.VerticalAlignment   = PdfPCell.ALIGN_MIDDLE;

            table.AddCell(fc);

            PdfPCell um = new PdfPCell(new Phrase("U.M.", new iTextSharp.text.Font(subtitulo)));

            um.BackgroundColor = (CSTitulo);

            um.FixedHeight         = altura;
            um.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
            um.VerticalAlignment   = PdfPCell.ALIGN_MIDDLE;

            table.AddCell(um);


            PdfPCell quant = new PdfPCell(new Phrase("QUANT.", new iTextSharp.text.Font(subtitulo)));

            quant.BackgroundColor = (CSTitulo);

            quant.FixedHeight         = altura;
            quant.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
            quant.VerticalAlignment   = PdfPCell.ALIGN_MIDDLE;

            table.AddCell(quant);

            PdfPCell unit = new PdfPCell(new Phrase("$UNIT", new iTextSharp.text.Font(subtitulo)));

            unit.BackgroundColor = (CSTitulo);

            unit.FixedHeight         = altura;
            unit.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
            unit.VerticalAlignment   = PdfPCell.ALIGN_MIDDLE;

            table.AddCell(unit);

            PdfPCell totalpdf = new PdfPCell(new Phrase("$TOTAL", new iTextSharp.text.Font(subtitulo)));

            totalpdf.BackgroundColor = (CSTitulo);

            totalpdf.FixedHeight         = altura;
            totalpdf.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
            totalpdf.VerticalAlignment   = PdfPCell.ALIGN_MIDDLE;

            table.AddCell(totalpdf);

            altura = 15;

            PdfPCell linha = new PdfPCell();

            linha.FixedHeight         = altura;
            linha.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
            linha.VerticalAlignment   = PdfPCell.ALIGN_MIDDLE;


            //Linha por linha busca ingrediente com custo
            BLLPratos bll = new BLLPratos(cx);
            DataTable tabelaIngredientes = bll.ListarIngredientes(codigoP);

            BLLAeB    bllaeb = new BLLAeB(cx);
            DataTable tabelaAeb;


            string codIngrediente, nomeingrediente, uniMedida;
            double quantidade, custoUnit, custoTotal, correcao;


            if (tabelaIngredientes.Rows.Count > 0)
            {
                for (int i = 0; i < tabelaIngredientes.Rows.Count; i++)
                {
                    //cod_item, quant_ingrediente

                    tabelaAeb = bllaeb.LocalizarPorCod(tabelaIngredientes.Rows[i][0].ToString());


                    codIngrediente  = tabelaIngredientes.Rows[i][0].ToString();
                    nomeingrediente = tabelaAeb.Rows[0][0].ToString();
                    uniMedida       = tabelaAeb.Rows[0][1].ToString();

                    if (string.IsNullOrEmpty(tabelaAeb.Rows[0][2].ToString()))
                    {
                        correcao = 0;
                    }
                    else
                    {
                        correcao = Convert.ToDouble(tabelaAeb.Rows[0][2]);
                    }

                    quantidade = Convert.ToDouble(tabelaIngredientes.Rows[i][1]);

                    custoUnit  = CustoIngrediente(codIngrediente, unidade);
                    custoTotal = custoUnit * quantidade;


                    //add linhas

                    if (i % 2 > 0)
                    {
                        linha.BackgroundColor = (linhaAlternada1);
                    }
                    else
                    {
                        linha.BackgroundColor = (linhaAlternada0);
                    }

                    linha.Phrase = new Phrase(codIngrediente, texto);
                    table.AddCell(linha);

                    linha.Phrase = new Phrase(nomeingrediente, texto);
                    table.AddCell(linha);

                    linha.Phrase = new Phrase(correcao.ToString("#,0.00"), texto);
                    table.AddCell(linha);

                    linha.Phrase = new Phrase(uniMedida, texto);
                    table.AddCell(linha);

                    linha.Phrase = new Phrase(quantidade.ToString(), texto);
                    table.AddCell(linha);

                    linha.Phrase = new Phrase(custoUnit.ToString("#,0.00"), texto);
                    table.AddCell(linha);

                    linha.Phrase = new Phrase(custoTotal.ToString("#,0.00"), texto);
                    table.AddCell(linha);
                }
            }


            PdfPCell tModoPreparo = new PdfPCell(new Phrase("MODO DE PREPARO", new iTextSharp.text.Font(subtitulo)));

            tModoPreparo.BackgroundColor     = (CSTitulo);
            tModoPreparo.Colspan             = 7;
            tModoPreparo.FixedHeight         = 20f;
            tModoPreparo.HorizontalAlignment = 1; //0=esquerda, 1 = centro, 2=direita
            tModoPreparo.VerticalAlignment   = PdfPCell.ALIGN_MIDDLE;

            table.AddCell(tModoPreparo);

            PdfPCell ModoPreparo = new PdfPCell(new Phrase(preparo, texto));

            ModoPreparo.Colspan = 7;

            ModoPreparo.HorizontalAlignment = PdfPCell.ALIGN_JUSTIFIED;

            table.AddCell(ModoPreparo);


            doc.Add(table);

            doc.Close();
        }