Ejemplo n.º 1
0
        private void ReportFilm_OnClick(object sender, RoutedEventArgs e)
        {
            try
            {
                using (MsSqlContext db = new MsSqlContext())
                {
                    var film = db.films.Include(c => c.Sessions).ToList();
                    var dest = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/Отчёт по продажам билетов на фильм.pdf";
                    var file = new FileInfo(dest);
                    file.Directory.Create();
                    var pdf      = new PdfDocument(new PdfWriter(dest));
                    var document = new Document(pdf, PageSize.A2.Rotate());
                    var font     = PdfFontFactory.CreateFont(FONT, PdfEncodings.IDENTITY_H);

                    float[] columnWidths = { 10, 10, 10, 8 };
                    var     table        = new Table(UnitValue.CreatePercentArray(columnWidths));

                    var cell = new Cell(1, 4)
                               .Add(new Paragraph("Отчёт по фильмам"))
                               .SetFont(font)
                               .SetFontSize(13)
                               .SetFontColor(DeviceGray.WHITE)
                               .SetBackgroundColor(DeviceGray.BLACK)
                               .SetWidth(600)
                               .SetTextAlignment(TextAlignment.CENTER);
                    table.AddHeaderCell(cell);

                    Cell[] headerFooter =
                    {
                        new Cell().SetFont(font).SetWidth(100).SetBackgroundColor(new DeviceGray(0.75f)).Add(new Paragraph("Фильм")),
                        new Cell().SetFont(font).SetWidth(100).SetBackgroundColor(new DeviceGray(0.75f)).Add(new Paragraph("Количество сеансов")),
                        new Cell().SetFont(font).SetWidth(100).SetBackgroundColor(new DeviceGray(0.75f)).Add(new Paragraph("Количество купленных билетов")),
                        new Cell().SetFont(font).SetWidth(100).SetBackgroundColor(new DeviceGray(0.75f)).Add(new Paragraph("Общая сумма"))
                    };

                    foreach (var hfCell in headerFooter)
                    {
                        table.AddHeaderCell(hfCell);
                    }

                    int   Count_of_places = 0;
                    int   all_places      = 0;
                    float Summ_price      = 0;
                    for (int i = 0; i < film.Count; i++)
                    {
                        Summ_price = 0;
                        table.AddCell(new Cell().SetTextAlignment(TextAlignment.CENTER).SetFont(font).Add(new Paragraph(film[i].film_name)));
                        table.AddCell(new Cell().SetTextAlignment(TextAlignment.CENTER).SetFont(font).Add(new Paragraph($"{film[i].Sessions.Count}")));
                        for (int f = 0; f <= film[i].Sessions.Count - 1; f++)
                        {
                            ICollection <sessions> sess = film[i].Sessions;
                            sessions buff_ses           = sess.ElementAt(f);
                            var      places_list        = db.places_list.Where(c => c.status == "Куплено").Where(c => c.sessionsId == buff_ses.Id).ToList();
                            Count_of_places = places_list.Count;
                            all_places      = all_places + Count_of_places;
                            Summ_price      = Count_of_places * buff_ses.price_of_tickets + Summ_price;
                        }
                        table.AddCell(new Cell().SetTextAlignment(TextAlignment.CENTER).SetFont(font).Add(new Paragraph(all_places.ToString())));
                        table.AddCell(new Cell().SetTextAlignment(TextAlignment.CENTER).SetFont(font).Add(new Paragraph(Summ_price.ToString())));
                        all_places = 0;
                    }
                    document.Add(table);
                    document.Close();
                    var p = new Process
                    {
                        StartInfo = new ProcessStartInfo(dest)
                        {
                            UseShellExecute = true
                        }
                    };
                    p.Start();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 2
0
        private void ReportDate_OnClick(object sender, RoutedEventArgs e)
        {
            var date = new dates();

            date.ShowDialog();
            try
            {
                using (MsSqlContext db = new MsSqlContext())
                {
                    var places_list = db.places_list.Include(t => t.sessions).Include(g => g.User).Where(c => c.status == "Куплено").Where(x => x.date_of_operation >= dates.begin && x.date_of_operation <= dates.end).ToList();
                    var dest        = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/Отчёт по продажам за промежуток времени.pdf";
                    var file        = new FileInfo(dest);
                    file.Directory.Create();
                    var pdf      = new PdfDocument(new PdfWriter(dest));
                    var document = new Document(pdf, PageSize.A2.Rotate());
                    var font     = PdfFontFactory.CreateFont(FONT, PdfEncodings.IDENTITY_H);

                    float[] columnWidths = { 10, 10, 10, 8 };
                    var     table        = new Table(UnitValue.CreatePercentArray(columnWidths));

                    var cell = new Cell(1, 4)
                               .Add(new Paragraph("Отчёт за промежуток времени"))
                               .SetFont(font)
                               .SetFontSize(13)
                               .SetFontColor(DeviceGray.WHITE)
                               .SetBackgroundColor(DeviceGray.BLACK)
                               .SetWidth(600)
                               .SetTextAlignment(TextAlignment.CENTER);
                    table.AddHeaderCell(cell);

                    Cell[] headerFooter =
                    {
                        new Cell().SetFont(font).SetWidth(100).SetBackgroundColor(new DeviceGray(0.75f)).Add(new Paragraph("С")),
                        new Cell().SetFont(font).SetWidth(100).SetBackgroundColor(new DeviceGray(0.75f)).Add(new Paragraph("По")),
                        new Cell().SetFont(font).SetWidth(100).SetBackgroundColor(new DeviceGray(0.75f)).Add(new Paragraph("Количество купленных билетов")),
                        new Cell().SetFont(font).SetWidth(100).SetBackgroundColor(new DeviceGray(0.75f)).Add(new Paragraph("Общая сумма"))
                    };

                    foreach (var hfCell in headerFooter)
                    {
                        table.AddHeaderCell(hfCell);
                    }

                    int   Count_of_places = places_list.Count;
                    float Summ_price      = 0;

                    for (int i = 0; i < places_list.Count; i++)
                    {
                        Summ_price = places_list[i].sessions.price_of_tickets + Summ_price;
                    }
                    table.AddCell(new Cell().SetTextAlignment(TextAlignment.CENTER).SetFont(font).Add(new Paragraph(dates.begin.ToString())));
                    table.AddCell(new Cell().SetTextAlignment(TextAlignment.CENTER).SetFont(font).Add(new Paragraph(dates.end.ToString())));
                    table.AddCell(new Cell().SetTextAlignment(TextAlignment.CENTER).SetFont(font).Add(new Paragraph(Count_of_places.ToString())));
                    table.AddCell(new Cell().SetTextAlignment(TextAlignment.CENTER).SetFont(font).Add(new Paragraph(Summ_price.ToString())));
                    document.Add(table);
                    document.Close();
                    var p = new Process
                    {
                        StartInfo = new ProcessStartInfo(dest)
                        {
                            UseShellExecute = true
                        }
                    };
                    p.Start();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }