private void configuraçõesToolStripMenuItem2_Click(object sender, EventArgs e) { DTOCaminhos dt = new DTOCaminhos(); Forms.Comuns.Config f = new Forms.Comuns.Config(Convert.ToInt32(txtId.Text)); this.Hide(); pbWallpaper.Load(dt.Wallpaper + "default.jpg"); f.ShowDialog(); f.Dispose(); if (File.Exists(dt.Wallpaper + txtId.Text + ".jpg")) { pbWallpaper.Load(dt.Wallpaper + txtId.Text + ".jpg"); } else { try { pbWallpaper.Load(dt.Wallpaper + "default.jpg"); } catch { } } this.Show(); }
private void pbPrint_Click(object sender, EventArgs e) { DTOCaminhos dto = new DTOCaminhos(); bool img = false; if (File.Exists(dto.FT + codFicha + ".jpg")) { DialogResult d = MessageBox.Show("Esta ficha contém uma imagem anexada. Deseja exportar a imagem para PDF também?", "ATENÇÃO!", MessageBoxButtons.YesNo); if (d.ToString() == "Yes") { img = true; } } try { SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Filter = "Arquivos PDF (*.pdf)|*.pdf"; saveFileDialog1.FilterIndex = 2; saveFileDialog1.FileName = lbTitulo.Text; saveFileDialog1.RestoreDirectory = true; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { ExportaPdf(img, codFicha, saveFileDialog1.FileName, unidade); } } catch { MessageBox.Show("Impossível exportar a ficha técnica para PDF. Verifique se não exite um arquivo em PDF aberto que esteja impedindo esta operação."); } }
private void TentaConexao() { SqlConnection conn = new SqlConnection() { ConnectionString = DadosDaConexao.StringDaConexao }; DTOCaminhos dto = new DTOCaminhos(); if (!File.Exists(dto.ConfigDatabase + CaminhoLog)) { File.Create(dto.ConfigDatabase + CaminhoLog); } try { conn.Open(); conn.Close(); Conecta(); } catch { frmConfigDatabase c = new frmConfigDatabase(); c.ShowDialog(); c.Dispose(); this.Close(); } }
private void DefaultState() { pnAparencia.Visible = false; selecionado = ""; opcao = "0"; DTOCaminhos dt = new DTOCaminhos(); if (File.Exists(dt.Wallpaper + idUsuario.ToString() + ".jpg")) { pbWallpaper.Load(dt.Wallpaper + idUsuario.ToString() + ".jpg"); btDeletaFoto.Enabled = true; } else { try { pbWallpaper.Load(dt.Wallpaper + "default.jpg"); } catch { } btDeletaFoto.Enabled = false; } }
private void zerarPagina() { DTOCaminhos dto = new DTOCaminhos(); liberado = false; pbFoto.Load(dto.Produtos + "0.jpg"); txtCodItem.Clear(); txtNomeItem.Clear(); txtQuant.Clear(); txtPreparo.Clear(); txtUm.Clear(); txtFc.Clear(); txtCodItem.Focus(); txtDescricao.Clear(); dgvFicha.Rows.Clear(); lbCustoKg2.Text = "0,00"; lbCustoPorcao2.Text = "0,00"; lbCustoTotal2.Text = "0,00"; txtCodigoPrato.Clear(); gbFicha.Enabled = true; gbIngredientes.Enabled = false; DefaultValues(); txtDescricao.Clear(); AlteraBotoes(); liberado = true; }
private void btDeleta_Click(object sender, EventArgs e) { DTOCaminhos mc = new DTOCaminhos(); pbFotoProduto.Load(mc.Produtos + "0.jpg"); foto = "del"; }
private void btDeletaFoto_Click(object sender, EventArgs e) { DTOCaminhos dto = new DTOCaminhos(); pbFoto.Load(dto.Produtos + "0.jpg"); foto = "del"; btDeletaFoto.Enabled = false; }
private void btLocalizar_Click(object sender, EventArgs e) { frmConsultaBasica_Produto f = new frmConsultaBasica_Produto(2, IdUsuario); f.ShowDialog(); if (f.codigo != 0) { this.alteraBotoes(3); this.operacao = "alterar"; DALConexao cx = new DALConexao(DadosDaConexao.StringDaConexao); BLLProduto bll = new BLLProduto(cx); DTOProduto modelo = bll.CarregaModeloProduto(f.codigo); txtId.Text = modelo.IdProduto.ToString(); txtNomeProduto.Text = modelo.NomeProduto.ToString(); DALConexao cxg = new DALConexao(DadosDaConexao.StringDaConexao); BLLGrupo bllg = new BLLGrupo(cxg); DTOGrupo modelog = bllg.CarregaModeloGrupo(modelo.GrupoProduto); grupoAtual = modelo.GrupoProduto; cbGrupo.Text = modelog.NomeGrupo.ToString(); txtMarca.Text = modelo.MarcaProduto.ToString(); txtModelo.Text = modelo.ModelodoProduto.ToString(); txtCodigo.Text = modelo.CodProduto.ToString(); DTOCaminhos mc = new DTOCaminhos(); try { pbFotoProduto.Load(mc.Produtos + modelo.IdProduto.ToString() + ".jpg"); } catch { pbFotoProduto.Load(mc.Produtos + "0.jpg"); } if (modelo.AtivoProduto) { cbAtivo.Checked = true; } else { cbAtivo.Checked = false; } txtDesc.Text = modelo.DescProduto.ToString(); } else { this.LimpaCampos(); this.alteraBotoes(1); } f.Dispose(); }
private void frmDadosProduto_Load(object sender, EventArgs e) { try { DALConexao cx = new DALConexao(DadosDaConexao.StringDaConexao); BLLProduto bll = new BLLProduto(cx); DTOProduto modelo = bll.CarregaModeloProduto(idProd); lbNome2.Text = modelo.NomeProduto.ToString(); DALConexao cxg = new DALConexao(DadosDaConexao.StringDaConexao); BLLGrupo bllg = new BLLGrupo(cxg); DTOGrupo modelog = bllg.CarregaModeloGrupo(modelo.GrupoProduto); lbGrupo2.Text = modelog.NomeGrupo.ToString(); lbMarca2.Text = modelo.MarcaProduto.ToString(); lbModelo2.Text = modelo.ModelodoProduto.ToString(); lbDesc2.Text = modelo.DescProduto.ToString(); lbDataCadastro2.Text = modelo.DataCriacaoProduto.ToString("dd/MM/yyyy"); DALConexao cxu = new DALConexao(DadosDaConexao.StringDaConexao); BLLUsuario bllu = new BLLUsuario(cxg); DTOUsuario modelou = bllu.CarregaModeloUsuario(modelo.UsuarioCriacaoProduto); lbUsuario2.Text = modelou.LoginUsuario.ToString() + " (" + modelou.IniciaisUsuario.ToString() + ")"; DTOCaminhos mc = new DTOCaminhos(); try { pbFoto.Load(mc.Produtos + modelo.IdProduto.ToString() + ".jpg"); } catch { pbFoto.Load(mc.Produtos + "0.jpg"); } if (modelo.AtivoProduto) { lbAtivo.Text = "Ativo"; } else { lbAtivo.Text = "Inativo"; } } catch { } }
private void frmConfigDatabase_Load(object sender, EventArgs e) { DTOCaminhos dto = new DTOCaminhos(); string caminho = dto.ConfigDatabase; if (banco == false && folder == true) { txtFolder.Text = ""; txtBancoDeDados.Text = ""; txtServidor.Text = ""; } else { txtFolder.Text = Properties.Settings.Default.pastaConfig; txtServidor.Text = Properties.Settings.Default.servidor; txtBancoDeDados.Text = Properties.Settings.Default.banco; } }
private void Salvar() { DTOCaminhos dto = new DTOCaminhos(); if (txtFolder.Text != "" && txtBancoDeDados.Text == "" && txtServidor.Text == "") { Properties.Settings.Default.pastaConfig = txtFolder.Text; Properties.Settings.Default.Save(); RetornaConfigs(); txtBancoDeDados.Enabled = true; txtFolder.Enabled = true; } else { string caminho = $@"{dto.ConfigDatabase}\conn.txt"; try { if (File.Exists(caminho)) { File.Delete(caminho); } StreamWriter arquivo = new StreamWriter(caminho); arquivo.WriteLine(txtServidor.Text); arquivo.WriteLine(txtBancoDeDados.Text); arquivo.Close(); Properties.Settings.Default.servidor = txtServidor.Text; Properties.Settings.Default.banco = txtBancoDeDados.Text; Properties.Settings.Default.Save(); MessageBox.Show("Configuração realizada com sucesso!\nO programa será reiniciado"); this.Close(); } catch { MessageBox.Show("Ocorreu um erro grave.\nPor favor contate o administrador do sistema."); } } }
public void IncluiFoto(String id, string foto) { DTOCaminhos mc = new DTOCaminhos(); if (foto != "") { if (foto == "del") { if (File.Exists(mc.Wallpaper + id + ".jpg")) { pbWallpaper.Load(mc.Wallpaper + "default.jpg"); File.Delete(mc.Wallpaper + id + ".jpg"); } } else { try { var path = Path.Combine(mc.Wallpaper, Path.GetFileName(foto)); if (!Directory.Exists(mc.Wallpaper)) { Directory.CreateDirectory(mc.Wallpaper); File.Copy(foto, mc.Wallpaper + id + Path.GetExtension(foto)); } else { if (File.Exists(mc.Wallpaper + id + Path.GetExtension(foto))) { File.Delete(mc.Wallpaper + id + Path.GetExtension(foto)); } File.Copy(foto, mc.Wallpaper + id + Path.GetExtension(foto)); } } catch { } } } }
public void IncluiFoto(String cod, string foto) { DTOCaminhos mc = new DTOCaminhos(); if (foto != "") { if (foto == "del") { if (File.Exists(mc.FT + cod + ".jpg")) { File.Delete(mc.FT + cod + ".jpg"); } } else { try { var path = Path.Combine(mc.FT, Path.GetFileName(foto)); if (!Directory.Exists(mc.FT)) { Directory.CreateDirectory(mc.FT); File.Copy(foto, mc.FT + cod + Path.GetExtension(foto)); } else { if (File.Exists(mc.FT + cod + Path.GetExtension(foto))) { File.Delete(mc.FT + cod + Path.GetExtension(foto)); } File.Copy(foto, mc.FT + cod + Path.GetExtension(foto)); } } catch { } } } }
private void PreencheCampos() { string AcessoUsuario = ""; //Altera o titulo do Form this.Text += $" - {txtLogin.Text} ({txtIniciais.Text})"; this.BloqueioTela(Convert.ToInt32(txtPermissao.Text)); this.LimpaTela(Convert.ToInt32(txtPermissao.Text)); if (Convert.ToInt32(txtPermissao.Text) == 1) { AcessoUsuario = "Visualizador"; } else if (Convert.ToInt32(txtPermissao.Text) == 2) { AcessoUsuario = "Operador"; } else if (Convert.ToInt32(txtPermissao.Text) == 3) { AcessoUsuario = "Líder"; } else if (Convert.ToInt32(txtPermissao.Text) >= 4) { AcessoUsuario = "Administrador"; } if (Convert.ToInt32(txtPermissao.Text) == -1) { lbUsuarioLogado.Text = AcessoUsuario + ": Admin ( 99 ) - ADM"; } else { lbUsuarioLogado.Text = txtUsuario.Text + " (" + txtIniciais.Text + ") - " + txtNomeUnidade.Text + " - " + AcessoUsuario.ToUpper(); } DTOCaminhos dt = new DTOCaminhos(); if (File.Exists(dt.Wallpaper + txtId.Text + ".jpg")) { pbWallpaper.Load(dt.Wallpaper + txtId.Text + ".jpg"); } else { try { pbWallpaper.Load(dt.Wallpaper + "default.jpg"); } catch { } } AcessoUsuario = null; }
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; } } }
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(); }
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; } }
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(); }