public List <ProizvodIzvestaj> KreirajIzvestaj(ProizvodIzvestaj pi) { TransferKlasa transfer = new TransferKlasa(); transfer.Operacija = Operacije.KreirajIzvestaj; transfer.TransferObjekat = pi; formater.Serialize(tok, transfer); transfer = formater.Deserialize(tok) as TransferKlasa; return(transfer.Rezultat as List <ProizvodIzvestaj>); }
public bool KreirajIzvestaj(ComboBox cmbMesec) { try { List <Narudzbenica> lista = kom.VratiSveNarudzbenice(); if (cmbMesec.SelectedItem == null) { MessageBox.Show("Niste odabrali mesec"); return(false); } ProizvodIzvestaj pi = new ProizvodIzvestaj(); pi.Mesec = cmbMesec.SelectedIndex + 1; Izvestaj(lista, pi); System.Diagnostics.Process.Start(@"PDF\Izvestaj\Izvestaj-" + pi.Mesec.ToString() + ".pdf"); return(true); } catch (Exception) { MessageBox.Show("Sistem ne moze da kreira izvestaj"); return(false); } }
private void Izvestaj(List <Narudzbenica> lista, ProizvodIzvestaj pi) { string pdfFilePath = @"PDF\Izvestaj\"; string imeFajla = pdfFilePath + "Izvestaj-" + pi.Mesec.ToString(); if (File.Exists(imeFajla + ".pdf")) { MessageBox.Show("Postoji izvestaj za taj mesec"); return; } FileStream fs = new FileStream(@"PDF\Izvestaj\Izvestaj-" + pi.Mesec.ToString() + ".pdf", FileMode.Create, FileAccess.Write, FileShare.None); Document doc = new Document(); doc.SetPageSize(iTextSharp.text.PageSize.A4); PdfWriter writer = PdfWriter.GetInstance(doc, fs); doc.Open(); //Header BaseFont bf = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1250, BaseFont.EMBEDDED); iTextSharp.text.Font fHeader = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 16, 1, iTextSharp.text.BaseColor.BLACK); Paragraph pHeader = new Paragraph(); pHeader.Alignment = Element.ALIGN_LEFT; pHeader.Add(new Chunk("Izveštaj o prodatim proizvodima", fHeader)); doc.Add(pHeader); Paragraph pRadnik = new Paragraph(); iTextSharp.text.Font fRadnik = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 8, 2, iTextSharp.text.BaseColor.GRAY); pRadnik.Alignment = Element.ALIGN_RIGHT; pRadnik.Add(new Chunk("Radnik: " + radnik.ToString() + "", fRadnik)); pRadnik.Add(new Chunk("\nDatum: " + DateTime.Now.ToShortDateString() + "", fRadnik)); doc.Add(pRadnik); //Line Paragraph line = new Paragraph(new Chunk(new iTextSharp.text.pdf.draw.LineSeparator(0.0F, 100.0F, iTextSharp.text.BaseColor.BLACK, Element.ALIGN_LEFT, 0))); doc.Add(line); doc.Add(new Chunk("\n", fHeader)); //Firma iTextSharp.text.Font fPDF = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 12, 1, iTextSharp.text.BaseColor.BLACK); doc.Add(new Chunk("\n", fHeader)); Paragraph pFirma = new Paragraph(); pFirma.Alignment = Element.ALIGN_LEFT; pFirma.Add(new Chunk(" Sportex d.o.o", fPDF)); pFirma.Add(new Chunk("\n Adresa: Bogdana Teofilovića 20", fPDF)); pFirma.Add(new Chunk("\n Email: [email protected]", fPDF)); pFirma.Add(new Chunk("\n Telefon: 123456", fPDF)); pFirma.Add(new Chunk("\n PIB: 43215", fPDF)); doc.Add(pFirma); doc.Add(new Chunk("\n", fHeader)); //Tabela PdfPTable tabela = new PdfPTable(3); iTextSharp.text.Font fTH = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 10, 1, iTextSharp.text.BaseColor.BLACK); PdfPCell cell1 = new PdfPCell(new Phrase("Naziv proizvoda", fTH)); cell1.BackgroundColor = iTextSharp.text.BaseColor.WHITE; tabela.AddCell(cell1); PdfPCell cell2 = new PdfPCell(new Phrase("Količina", fTH)); cell2.BackgroundColor = iTextSharp.text.BaseColor.WHITE; tabela.AddCell(cell2); PdfPCell cell3 = new PdfPCell(new Phrase("Vrednost", fTH)); cell3.BackgroundColor = iTextSharp.text.BaseColor.WHITE; tabela.AddCell(cell3); iTextSharp.text.Font fTC = new iTextSharp.text.Font(bf, 10, 1, iTextSharp.text.BaseColor.BLACK); int UK = 0; double UV = 0; List <ProizvodIzvestaj> proizvodi = new List <ProizvodIzvestaj>(); try { proizvodi = kom.KreirajIzvestaj(pi); } catch (Exception) { if (File.Exists(imeFajla + ".pdf")) { File.Delete(imeFajla + ".pdf"); } return; } foreach (ProizvodIzvestaj p in proizvodi) { UK += p.Kolicina; UV += p.Cena; tabela.AddCell(new Phrase(p.Naziv, fTC)); tabela.AddCell(new Phrase(p.Kolicina.ToString(), fTC)); tabela.AddCell(new Phrase(p.Cena.ToString(), fTC)); } doc.Add(tabela); doc.Add(new Chunk("\n", fHeader)); doc.Add(new Chunk("Ukupan promet robe: " + UK + " prodatih proizvoda.\n")); doc.Add(new Chunk("Ukupna vrednost prodate robe: " + UV + " RSD")); doc.Close(); writer.Close(); fs.Close(); if (tabela.Rows.Count < 2) { MessageBox.Show("Ne postoje prodati proizvodi u prethdnom mesecu za date narudžbenice"); if (File.Exists(imeFajla + ".pdf")) { File.Delete(imeFajla + ".pdf"); } return; } MessageBox.Show("Sistem je kreirao izvestaj"); }