Ejemplo n.º 1
0
        public async Task <IActionResult> Servisi()
        {
            string naslov = "Popis servisa";

            var servisi = ctx.Servis.ToList();

            PdfReport report = CreateReport(naslov);

            List <ServisDenorm> servisiDenorm = new List <ServisDenorm>();

            foreach (var s in servisi)
            {
                var tipServis     = ctx.TipServisa.Where(tip => tip.IdServis == s.Id).FirstOrDefault();
                var serviseri     = ctx.Serviser.Where(serviser => serviser.IdServis == s.Id).ToList();
                var uredajIdNaziv = (from ur in ctx.Uredaj
                                     join servisira in ctx.Servisira on ur.Id equals servisira.IdUredaj
                                     where (servisira.IdServis == s.Id)
                                     select ur.Naziv).ToList();

                servisiDenorm.Add(Denormalize(s, tipServis, serviseri, uredajIdNaziv));
            }

            #region Podnožje i zaglavlje
            report.PagesFooter(footer =>
            {
                footer.DefaultFooter(DateTime.Now.ToString("dd.MM.yyyy."));
            })
            .PagesHeader(header =>
            {
                header.CacheHeader(cache: true); // It's a default setting to improve the performance.
                header.DefaultHeader(defaultHeader =>
                {
                    defaultHeader.RunDirection(PdfRunDirection.LeftToRight);
                    defaultHeader.Message(naslov);
                });
            });
            #endregion

            #region Postavljanje izvora podataka i stupaca
            report.MainTableDataSource(dataSource => dataSource.StronglyTypedList(servisiDenorm));
            report.MainTableSummarySettings(summarySettings =>
            {
                summarySettings.OverallSummarySettings("Suma");
            });

            report.MainTableColumns(columns =>
            {
                columns.AddColumn(column =>
                {
                    column.IsRowNumber(true);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Right);
                    column.IsVisible(true);
                    column.Order(0);
                    column.Width(2);
                    column.HeaderCell("#", horizontalAlignment: HorizontalAlignment.Right);
                });

                columns.AddColumn(column =>
                {
                    column.PropertyName(nameof(ServisDenorm.Id));
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(1);
                    column.Width(1);
                    column.HeaderCell("Id ");
                    //column.ColumnItemsTemplate(template =>
                    //{
                    //    template.TextBlock();
                    //    template.DisplayFormatFormula(obj => obj == null || string.IsNullOrEmpty(obj.ToString())
                    //                                        ? string.Empty : string.Format("{0:2}", obj));
                    //});
                    column.AggregateFunction(aggregateFunction =>
                    {
                        aggregateFunction.NumericAggregateFunction(AggregateFunction.Sum);
                        //aggregateFunction.DisplayFormatFormula(obj => obj == null || string.IsNullOrEmpty(obj.ToString())
                        //                                    ? string.Empty : string.Format("{0:C2}", obj));
                    });
                });

                columns.AddColumn(column =>
                {
                    column.PropertyName(nameof(ServisDenorm.ImeServisa));
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(1);
                    column.Width(2);
                    column.HeaderCell("Ime servisa");
                });

                columns.AddColumn(column =>
                {
                    column.PropertyName(nameof(ServisDenorm.OpisServisa));
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(2);
                    column.Width(3);
                    column.HeaderCell("Opis servisa", horizontalAlignment: HorizontalAlignment.Center);
                });

                columns.AddColumn(column =>
                {
                    column.PropertyName(nameof(ServisDenorm.Tip));
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(3);
                    column.Width(2);
                    column.HeaderCell("Tip servisa", horizontalAlignment: HorizontalAlignment.Center);
                });

                columns.AddColumn(column =>
                {
                    column.PropertyName(nameof(ServisDenorm.Serviseri));
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(4);
                    column.Width(5);
                    column.HeaderCell("Serviseri", horizontalAlignment: HorizontalAlignment.Center);
                });

                columns.AddColumn(column =>
                {
                    column.PropertyName(nameof(ServisDenorm.Uredaji));
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(5);
                    column.Width(6);
                    column.HeaderCell("Uređaji", horizontalAlignment: HorizontalAlignment.Center);
                });
            });

            #endregion
            byte[] pdf = report.GenerateAsByteArray();

            if (pdf != null)
            {
                Response.Headers.Add("content-disposition", "inline; filename=servisi.pdf");
                return(File(pdf, "application/pdf"));
                //return File(pdf, "application/pdf", "drzave.pdf"); //Otvara save as dialog
            }
            else
            {
                return(NotFound());
            }
        }
Ejemplo n.º 2
0
        public IPdfReportData CreatePdfReport()
        {
            var report = new PdfReport();

            report.DocumentPreferences(doc =>
            {
                doc.RunDirection(PdfRunDirection.LeftToRight);
                doc.Orientation(PageOrientation.Portrait);
                doc.PageSize(PdfPageSize.A4);
                doc.DocumentMetadata(new DocumentMetadata {
                    Author = "Vios", Application = "PdfRpt", Keywords = "IList Rpt.", Subject = "Test Rpt", Title = "Test"
                });
                doc.Compression(new CompressionSettings
                {
                    EnableCompression     = true,
                    EnableFullCompression = true
                });
                doc.PrintingPreferences(new PrintingPreferences
                {
                    ShowPrintDialogAutomatically = true
                });
            }
                                       );

            report.DefaultFonts(fonts =>
            {
                fonts.Path(System.IO.Path.Combine(Environment.GetEnvironmentVariable("SystemRoot"), "fonts\\arial.ttf"),
                           System.IO.Path.Combine(Environment.GetEnvironmentVariable("SystemRoot"), "fonts\\verdana.ttf"));
                fonts.Size(9);
                fonts.Color(System.Drawing.Color.Black);
            });

            report.PagesFooter(footer =>
            {
                footer.DefaultFooter(DateTime.Now.ToString("MM/dd/yyyy"));
            });

            report.PagesHeader(header =>
            {
                header.DefaultHeader(defaultHeader =>
                {
                    defaultHeader.RunDirection(PdfRunDirection.LeftToRight);
                    defaultHeader.ImagePath(System.IO.Path.Combine(AppPath.ApplicationPath, "Images\\01.png"));
                    defaultHeader.Message("Our new rpt.");
                });
            });



            report.MainTableTemplate(template =>
            {
                template.BasicTemplate(BasicTemplate.ClassicTemplate);
            });

            report.MainTablePreferences(table =>
            {
                table.ColumnsWidthsType(TableColumnWidthType.Relative);
                table.NumberOfDataRowsPerPage(15);
            });

            report.MainTableDataSource(dataSource =>
            {
                var listOfRows = new List <User>();
                for (int i = 0; i < 200; i++)
                {
                    listOfRows.Add(new User {
                        Id = i, LastName = "LastName " + i, Name = "Name " + i, Balance = i + 1000
                    });
                }
                dataSource.StronglyTypedList(listOfRows);
            });

            report.MainTableSummarySettings(summarySettings =>
            {
                summarySettings.OverallSummarySettings("Summary");
                summarySettings.PreviousPageSummarySettings("Previous Page Summary");
                summarySettings.PageSummarySettings("Page Summary");
            });

            report.MainTableColumns(columns =>
            {
                columns.AddColumn(column =>
                {
                    column.PropertyName("rowNo");
                    column.IsRowNumber(true);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(0);
                    column.Width(1);
                    column.HeaderCell("#");
                });


                columns.AddColumn(column =>
                {
                    column.PropertyName <User>(x => x.Id);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(1);
                    column.Width(2);
                    column.HeaderCell("Id");
                });

                columns.AddColumn(column =>
                {
                    column.PropertyName <User>(x => x.Name);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(2);
                    column.Width(3);
                    column.HeaderCell("Name", horizontalAlignment: HorizontalAlignment.Left);
                    column.Font(font =>
                    {
                        font.Size(10);
                        font.Color(System.Drawing.Color.Brown);
                    });
                });

                columns.AddColumn(column =>
                {
                    column.PropertyName <User>(x => x.LastName);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(3);
                    column.Width(3);
                    column.HeaderCell("Last Name");
                });

                columns.AddColumn(column =>
                {
                    column.PropertyName <User>(x => x.Balance);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(4);
                    column.Width(2);
                    column.HeaderCell("Balance");
                    column.ColumnItemsTemplate(template =>
                    {
                        template.TextBlock();
                        template.DisplayFormatFormula(obj => obj == null ? string.Empty : string.Format("{0:n0}", obj));
                    });
                    column.AggregateFunction(aggregateFunction =>
                    {
                        aggregateFunction.NumericAggregateFunction(AggregateFunction.Sum);
                        aggregateFunction.DisplayFormatFormula(obj => obj == null ? string.Empty : string.Format("{0:n0}", obj));
                    });
                });
            });

            report.MainTableEvents(events =>
            {
                events.DataSourceIsEmpty(message: "There is no data available to display.");
            });

            report.Export(export =>
            {
                export.ToExcel();
                export.ToCsv();
                export.ToXml();
            });

            var reportHlp = report.Generate(data => data.AsPdfFile(string.Format("{0}\\Pdf\\RptTDSample-{1}.pdf", AppPath.ApplicationPath, Guid.NewGuid().ToString("N"))));

            //return report as IPdfReportData;
            return(reportHlp);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Dokumenti()
        {
            int    n      = 10;
            var    param  = new SqlParameter("N", n);
            string naslov = $"{n} najvećih kupnji";
            var    stavke = await ctx.StavkaDenorm
                            .AsNoTracking()
                            .FromSql("SELECT * FROM fn_NajveceKupnje(@N)", param)
                            .OrderBy(s => s.IdDokumenta)
                            .ThenBy(s => s.NazArtikla)
                            .ToListAsync();

            stavke.ForEach(s => s.UrlDokumenta = Url.Action("Edit", "Dokument", new { id = s.IdDokumenta }));
            PdfReport report = CreateReport(naslov);

            #region Podnožje i zaglavlje
            report.PagesFooter(footer =>
            {
                footer.DefaultFooter(DateTime.Now.ToString("dd.MM.yyyy."));
            })
            .PagesHeader(header =>
            {
                header.CacheHeader(cache: true); // It's a default setting to improve the performance.
                header.CustomHeader(new MasterDetailsHeaders(naslov)
                {
                    PdfRptFont = header.PdfFont
                });
            });
            #endregion
            #region Postavljanje izvora podataka i stupaca
            report.MainTableDataSource(dataSource => dataSource.StronglyTypedList(stavke));

            report.MainTableSummarySettings(summarySettings =>
            {
                summarySettings.OverallSummarySettings("Ukupno");
            });

            report.MainTableColumns(columns =>
            {
                #region Stupci po kojima se grupira
                columns.AddColumn(column =>
                {
                    column.PropertyName <StavkaDenorm>(s => s.IdDokumenta);
                    column.Group(
                        (val1, val2) =>
                    {
                        return((int)val1 == (int)val2);
                    });
                });
                #endregion
                columns.AddColumn(column =>
                {
                    column.IsRowNumber(true);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Right);
                    column.IsVisible(true);
                    column.Width(1);
                    column.HeaderCell("#", horizontalAlignment: HorizontalAlignment.Right);
                });
                columns.AddColumn(column =>
                {
                    column.PropertyName <StavkaDenorm>(x => x.NazArtikla);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Width(4);
                    column.HeaderCell("Naziv artikla", horizontalAlignment: HorizontalAlignment.Center);
                });

                columns.AddColumn(column =>
                {
                    column.PropertyName <StavkaDenorm>(x => x.KolArtikla);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Right);
                    column.IsVisible(true);
                    column.Width(1);
                    column.HeaderCell("Količina", horizontalAlignment: HorizontalAlignment.Center);
                    column.ColumnItemsTemplate(template =>
                    {
                        template.TextBlock();
                        template.DisplayFormatFormula(obj => obj == null || string.IsNullOrEmpty(obj.ToString())
                                                ? string.Empty : string.Format("{0:.00}", obj));
                    });
                });

                columns.AddColumn(column =>
                {
                    column.PropertyName <StavkaDenorm>(x => x.JedCijArtikla);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Right);
                    column.IsVisible(true);
                    column.Width(1);
                    column.HeaderCell("Jedinična cijena", horizontalAlignment: HorizontalAlignment.Center);
                    column.ColumnItemsTemplate(template =>
                    {
                        template.TextBlock();
                        template.DisplayFormatFormula(obj => obj == null || string.IsNullOrEmpty(obj.ToString())
                                                ? string.Empty : string.Format("{0:C2}", obj));
                    });
                });

                columns.AddColumn(column =>
                {
                    column.PropertyName <StavkaDenorm>(x => x.PostoRabat);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Right);
                    column.IsVisible(true);
                    column.Width(1);
                    column.HeaderCell("Rabat", horizontalAlignment: HorizontalAlignment.Center);
                    column.ColumnItemsTemplate(template =>
                    {
                        template.TextBlock();
                        template.DisplayFormatFormula(obj => obj == null || string.IsNullOrEmpty(obj.ToString())
                                                ? string.Empty : string.Format("{0:P2}", obj));
                    });
                });

                columns.AddColumn(column =>
                {
                    column.PropertyName("Ukupno");
                    column.CellsHorizontalAlignment(HorizontalAlignment.Right);
                    column.IsVisible(true);
                    column.Width(1);
                    column.HeaderCell("Ukupno", horizontalAlignment: HorizontalAlignment.Center);
                    column.ColumnItemsTemplate(template =>
                    {
                        template.TextBlock();
                        template.DisplayFormatFormula(obj => obj == null || string.IsNullOrEmpty(obj.ToString())
                                                ? string.Empty : string.Format("{0:C2}", obj));
                    });
                    column.AggregateFunction(aggregateFunction =>
                    {
                        aggregateFunction.NumericAggregateFunction(AggregateFunction.Sum);
                        aggregateFunction.DisplayFormatFormula(obj => obj == null || string.IsNullOrEmpty(obj.ToString())
                                                ? string.Empty : string.Format("{0:C2}", obj));
                    });
                    column.CalculatedField(
                        list =>
                    {
                        if (list == null)
                        {
                            return(string.Empty);
                        }
                        decimal kolArtikla    = (decimal)list.GetValueOf(nameof(StavkaDenorm.KolArtikla));
                        decimal postoRabat    = (decimal)list.GetValueOf(nameof(StavkaDenorm.PostoRabat));
                        decimal jedCijArtikla = (decimal)list.GetValueOf(nameof(StavkaDenorm.JedCijArtikla));
                        var iznos             = jedCijArtikla * kolArtikla * (1 - postoRabat);
                        return(iznos);
                    });
                });
            });

            #endregion
            byte[] pdf = report.GenerateAsByteArray();

            if (pdf != null)
            {
                Response.Headers.Add("content-disposition", "inline; filename=artikli.pdf");
                return(File(pdf, "application/pdf"));
            }
            else
            {
                return(NotFound());
            }
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Artikli()
        {
            string naslov  = "Deset najskupljih artikala koji imaju sliku";
            var    artikli = await ctx.Artikl
                             .AsNoTracking()
                             .Where(a => a.SlikaArtikla != null)
                             .OrderByDescending(a => a.CijArtikla)
                             .Select(a => new
            {
                a.SifArtikla,
                a.NazArtikla,
                a.CijArtikla,
                a.SlikaArtikla
            })
                             .Take(10)
                             .ToListAsync();

            PdfReport report = CreateReport(naslov);

            #region Podnožje i zaglavlje
            report.PagesFooter(footer =>
            {
                footer.DefaultFooter(DateTime.Now.ToString("dd.MM.yyyy."));
            })
            .PagesHeader(header =>
            {
                header.CacheHeader(cache: true); // It's a default setting to improve the performance.
                header.DefaultHeader(defaultHeader =>
                {
                    defaultHeader.RunDirection(PdfRunDirection.LeftToRight);
                    defaultHeader.Message(naslov);
                });
            });
            #endregion
            #region Postavljanje izvora podataka i stupaca
            report.MainTableDataSource(dataSource => dataSource.StronglyTypedList(artikli));

            report.MainTableSummarySettings(summarySettings =>
            {
                summarySettings.OverallSummarySettings("Ukupno");
            });

            report.MainTableColumns(columns =>
            {
                columns.AddColumn(column =>
                {
                    column.IsRowNumber(true);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Right);
                    column.IsVisible(true);
                    column.Order(0);
                    column.Width(1);
                    column.HeaderCell("#", horizontalAlignment: HorizontalAlignment.Right);
                });

                columns.AddColumn(column =>
                {
                    column.PropertyName(nameof(Artikl.SlikaArtikla));
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(1);
                    column.Width(1);
                    column.HeaderCell(" ");
                    column.ColumnItemsTemplate(t => t.ByteArrayImage(string.Empty, fitImages: true));
                });

                columns.AddColumn(column =>
                {
                    column.PropertyName(nameof(Artikl.SifArtikla));
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(2);
                    column.Width(1);
                    column.HeaderCell("Šifra");
                });

                columns.AddColumn(column =>
                {
                    column.PropertyName <Artikl>(x => x.NazArtikla);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(3);
                    column.Width(4);
                    column.HeaderCell("Naziv artikla", horizontalAlignment: HorizontalAlignment.Center);
                });

                columns.AddColumn(column =>
                {
                    column.PropertyName <Artikl>(x => x.CijArtikla);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(4);
                    column.Width(1);
                    column.HeaderCell("Cijena", horizontalAlignment: HorizontalAlignment.Center);
                    column.ColumnItemsTemplate(template =>
                    {
                        template.TextBlock();
                        template.DisplayFormatFormula(obj => obj == null || string.IsNullOrEmpty(obj.ToString())
                                                ? string.Empty : string.Format("{0:C2}", obj));
                    });
                    column.AggregateFunction(aggregateFunction =>
                    {
                        aggregateFunction.NumericAggregateFunction(AggregateFunction.Sum);
                        aggregateFunction.DisplayFormatFormula(obj => obj == null || string.IsNullOrEmpty(obj.ToString())
                                                ? string.Empty : string.Format("{0:C2}", obj));
                    });
                });
            });

            #endregion
            byte[] pdf = report.GenerateAsByteArray();

            if (pdf != null)
            {
                Response.Headers.Add("content-disposition", "inline; filename=artikli.pdf");
                return(File(pdf, "application/pdf"));
            }
            else
            {
                return(NotFound());
            }
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Oprema()
        {
            string naslov = $"Popis dostupne opreme";
            var    oprema = await ctx.Oprema
                            .AsNoTracking()
                            .Where(a => a.Dostupnost == true)
                            .OrderBy(s => s.IdOprema)
                            .ThenBy(s => s.Naziv)
                            .ToListAsync();

            PdfReport report = CreateReport(naslov);

            #region Podnožje i zaglavlje
            report.PagesFooter(footer =>
            {
                footer.DefaultFooter(DateTime.Now.ToString("dd.MM.yyyy."));
            })
            .PagesHeader(header =>
            {
                header.CacheHeader(cache: true); // It's a default setting to improve the performance. !!!!!!!!!!!!
                header.DefaultHeader(defaultHeader =>
                {
                    defaultHeader.RunDirection(PdfRunDirection.LeftToRight);
                    defaultHeader.Message(naslov);
                });
            });
            #endregion
            #region Postavljanje izvora podataka i stupaca
            report.MainTableDataSource(dataSource => dataSource.StronglyTypedList(oprema));

            report.MainTableSummarySettings(summarySettings =>
            {
                summarySettings.OverallSummarySettings("Ukupno");
            });

            report.MainTableColumns(columns =>
            {
                columns.AddColumn(column =>
                {
                    column.IsRowNumber(true);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Right);
                    column.IsVisible(true);
                    column.Width(1);
                    column.HeaderCell("#", horizontalAlignment: HorizontalAlignment.Right);
                    column.AggregateFunction(aggregateFunction =>
                    {
                        aggregateFunction.NumericAggregateFunction(AggregateFunction.Sum);
                        aggregateFunction.DisplayFormatFormula(obj => obj == null || string.IsNullOrEmpty(obj.ToString())
                                                ? string.Empty : string.Format("{0:C2}", obj));
                    });
                });
                columns.AddColumn(column =>
                {
                    column.PropertyName <Oprema>(x => x.IdOprema);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Width(4);
                    column.HeaderCell("Šifra", horizontalAlignment: HorizontalAlignment.Center);
                });

                columns.AddColumn(column =>
                {
                    column.PropertyName <Oprema>(x => x.Naziv);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Right);
                    column.IsVisible(true);
                    column.Width(1);
                    column.HeaderCell("Naziv", horizontalAlignment: HorizontalAlignment.Center);
                });
                columns.AddColumn(column =>
                {
                    column.PropertyName <Oprema>(x => x.Status);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Right);
                    column.IsVisible(true);
                    column.Width(1);
                    column.HeaderCell("Opis", horizontalAlignment: HorizontalAlignment.Center);
                });
            });

            #endregion
            byte[] pdf = report.GenerateAsByteArray();

            if (pdf != null)
            {
                Response.Headers.Add("content-disposition", "inline; filename=artikli.pdf");
                return(File(pdf, "application/pdf"));
            }
            else
            {
                return(NotFound());
            }
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Korisnici()
        {
            string naslov = "Popis korisnika";

            var korisnici = ctx.Korisnik.ToList().OrderBy(k => k.Prezime);


            List <KorisnikDenorm> korisniciDenorm = new List <KorisnikDenorm>();
            var broj = 1;

            foreach (var k in korisnici)
            {
                var fer      = ctx.FerWebAcc.Where(f => f.Id == k.FerId).FirstOrDefault();
                var dhmz     = ctx.DhmzAcc.Where(d => d.Id == k.DhmzId).FirstOrDefault();
                var autori   = ctx.Sadrzaj.Where(s => s.IdAutora == k.Id).ToList().OrderBy(s => s.Ime);
                var autor    = autori.Select(s => s.Ime).ToList();
                var odobrioo = ctx.Sadrzaj.Where(s => s.IdOdobrenOd == k.Id).ToList().OrderBy(s => s.Ime);
                var odobrio  = odobrioo.Select(s => s.Ime).ToList();


                korisniciDenorm.Add(Denormalize(k, fer, dhmz, autor, odobrio, broj));
                broj++;
            }

            PdfReport report = CreateReport(naslov);

            #region Podnožje i zaglavlje
            report.PagesFooter(footer =>
            {
                footer.DefaultFooter(DateTime.Now.ToString("dd.MM.yyyy."));
            })
            .PagesHeader(header =>
            {
                header.CacheHeader(cache: true); // It's a default setting to improve the performance.
                header.DefaultHeader(defaultHeader =>
                {
                    defaultHeader.RunDirection(PdfRunDirection.LeftToRight);
                    defaultHeader.Message(naslov);
                });
            });
            #endregion
            #region Postavljanje izvora podataka i stupaca
            report.MainTableDataSource(dataSource => dataSource.StronglyTypedList(korisniciDenorm));
            report.MainTableSummarySettings(summarySettings =>
            {
                summarySettings.OverallSummarySettings("Sum");
            });
            var admin = ctx.Administrator.Select(a => a.IdKorisnika).ToList();
            report.MainTableColumns(columns =>

            {
                columns.AddColumn(column =>
                {
                    column.IsRowNumber(true);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(0);
                    column.Width((float)0.5);
                    column.HeaderCell("#", horizontalAlignment: HorizontalAlignment.Center);
                });
                columns.AddColumn(column =>
                {
                    column.PropertyName(nameof(KorisnikDenorm.Id));
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(1);
                    column.Width((float)0.5);
                    column.HeaderCell("ID", horizontalAlignment: HorizontalAlignment.Center);
                    column.AggregateFunction(aggregateFunction =>
                    {
                        aggregateFunction.NumericAggregateFunction(AggregateFunction.Sum);
                    });
                });

                columns.AddColumn(column =>
                {
                    column.PropertyName <KorisnikDenorm>(k => k.PrezimeIme);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(2);
                    column.Width((float)1.75);
                    column.HeaderCell("Ime i prezime ", horizontalAlignment: HorizontalAlignment.Center);
                });

                columns.AddColumn(column =>
                {
                    column.PropertyName <KorisnikDenorm>(k => k.Email);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(3);
                    column.Width(2);
                    column.HeaderCell("Email", horizontalAlignment: HorizontalAlignment.Center);
                });

                columns.AddColumn(column =>
                {
                    column.PropertyName <KorisnikDenorm>(k => k.KorisnickoIme);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(4);
                    column.Width((float)1.5);
                    column.HeaderCell("Korisničko ime", horizontalAlignment: HorizontalAlignment.Center);
                });
                columns.AddColumn(column =>
                {
                    column.PropertyName <KorisnikDenorm>(k => k.Fer);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(5);
                    column.Width(1);
                    column.HeaderCell("FerWeb račun", horizontalAlignment: HorizontalAlignment.Center);
                });
                columns.AddColumn(column =>
                {
                    column.PropertyName <KorisnikDenorm>(k => k.DHMZ);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(6);
                    column.Width(1);
                    column.HeaderCell("DHMZ račun", horizontalAlignment: HorizontalAlignment.Center);
                });
                columns.AddColumn(column =>
                {
                    column.PropertyName(nameof(KorisnikDenorm.Autor));
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(7);
                    column.Width((float)1.5);
                    column.HeaderCell("Autor sadržaja", horizontalAlignment: HorizontalAlignment.Center);
                });
                columns.AddColumn(column =>
                {
                    column.PropertyName(nameof(KorisnikDenorm.Odobrio));
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(8);
                    column.Width((float)1.5);
                    column.HeaderCell("Odobrio sadržaje", horizontalAlignment: HorizontalAlignment.Center);
                });
            });

            #endregion
            byte[] pdf = report.GenerateAsByteArray();

            if (pdf != null)
            {
                Response.Headers.Add("content-disposition", "inline; filename=korisnici.pdf");
                return(File(pdf, "application/pdf"));
                //return File(pdf, "application/pdf", "drzave.pdf"); //Otvara save as dialog
            }
            else
            {
                return(NotFound());
            }
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> Uredaji()
        {
            string naslov  = "Popis uredaja";
            var    list    = new List <UredajDenorm>();
            var    uredaji = _context.Uredaj
                             .Include(u => u.IdNadredeneKomponenteNavigation)
                             .Include(u => u.IdStatusaNavigation)
                             .Include(u => u.IdZidaNavigation)
                             .ToList();

            if (uredaji.Count <= 0)
            {
                return(NotFound());
            }

            foreach (var u in uredaji)
            {
                var ur = LoadDetails(u);
                list.Add(ur.GetInfo());
            }

            PdfReport report = CreateReport(naslov);

            #region Podnožje i zaglavlje
            report.PagesFooter(footer =>
            {
                footer.DefaultFooter(DateTime.Now.ToString("dd.MM.yyyy."));
            })
            .PagesHeader(header =>
            {
                header.CacheHeader(cache: true); // It's a default setting to improve the performance.
                header.DefaultHeader(defaultHeader =>
                {
                    defaultHeader.RunDirection(PdfRunDirection.LeftToRight);
                    defaultHeader.Message(naslov);
                });
            });
            #endregion
            #region Postavljanje izvora podataka i stupaca
            report.MainTableDataSource(dataSource => dataSource.StronglyTypedList(list));


            report.MainTableSummarySettings(summarySettings =>
            {
                summarySettings.OverallSummarySettings("Ukupno");
            });

            report.MainTableColumns(columns =>
            {
                columns.AddColumn(column =>
                {
                    column.IsRowNumber(true);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Right);
                    column.IsVisible(true);
                    column.Order(0);
                    column.Width(1);
                    column.HeaderCell("#", horizontalAlignment: HorizontalAlignment.Right);
                });

                columns.AddColumn(column =>
                {
                    column.PropertyName <UredajDenorm>(x => x.Naziv);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(1);
                    column.Width(2);
                    column.HeaderCell("Naziv ureðaja");
                });

                columns.AddColumn(column =>
                {
                    column.PropertyName <UredajDenorm>(x => x.DatumNabavke);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(2);
                    column.Width(2);
                    column.HeaderCell("Datum Nabavke", horizontalAlignment: HorizontalAlignment.Center);
                });

                /*columns.AddColumn(column =>
                 * {
                 *  column.PropertyName<UredajDenorm>(x => x.NabavnaCijena);
                 *  column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                 *  column.IsVisible(true);
                 *  column.Order(3);
                 *  column.Width(1);
                 *  column.HeaderCell("Nabavna Cijena", horizontalAlignment: HorizontalAlignment.Center);
                 * });
                 */
                /*columns.AddColumn(column =>
                 * {
                 *  column.PropertyName<UredajDenorm>(x => x.AktualnaCijena);
                 *  column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                 *  column.IsVisible(true);
                 *  column.Order(4);
                 *  column.Width(1);
                 *  column.HeaderCell("Aktualna Cijena", horizontalAlignment: HorizontalAlignment.Center);
                 * });
                 *
                 * columns.AddColumn(column =>
                 * {
                 *  column.PropertyName<UredajDenorm>(x => x.Zida);
                 *  column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                 *  column.IsVisible(true);
                 *  column.Order(5);
                 *  column.Width(1);
                 *  column.HeaderCell("Videozid", horizontalAlignment: HorizontalAlignment.Center);
                 * });
                 *
                 * columns.AddColumn(column =>
                 * {
                 *  column.PropertyName<UredajDenorm>(x => x.Status);
                 *  column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                 *  column.IsVisible(true);
                 *  column.Order(6);
                 *  column.Width(1);
                 *  column.HeaderCell("Status", horizontalAlignment: HorizontalAlignment.Center);
                 * });
                 */
                columns.AddColumn(column =>
                {
                    column.PropertyName <UredajDenorm>(x => x.Zamjena);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(3);
                    column.Width(3);
                    column.HeaderCell("Zamjenski ureðaji", horizontalAlignment: HorizontalAlignment.Center);
                });

                columns.AddColumn(column =>
                {
                    column.PropertyName <UredajDenorm>(x => x.ZamjenaZa);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(4);
                    column.Width(3);
                    column.HeaderCell("Zamjena Za", horizontalAlignment: HorizontalAlignment.Center);
                });

                columns.AddColumn(column =>
                {
                    column.PropertyName <UredajDenorm>(x => x.Servisi);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(5);
                    column.Width(3);
                    column.HeaderCell("Servisi", horizontalAlignment: HorizontalAlignment.Center);
                });


                columns.AddColumn(column =>
                {
                    column.PropertyName("Nabavna Cijena");
                    column.CellsHorizontalAlignment(HorizontalAlignment.Right);
                    column.IsVisible(true);
                    column.Order(6);
                    column.Width(2);
                    column.HeaderCell("Nabavna Cijena", horizontalAlignment: HorizontalAlignment.Center);
                    column.ColumnItemsTemplate(template =>
                    {
                        template.TextBlock();
                        template.DisplayFormatFormula(obj => obj == null || string.IsNullOrEmpty(obj.ToString())
                                                            ? string.Empty : string.Format("{0:C2}", obj));
                    });
                    column.AggregateFunction(aggregateFunction =>
                    {
                        aggregateFunction.NumericAggregateFunction(AggregateFunction.Sum);
                        aggregateFunction.DisplayFormatFormula(obj => obj == null || string.IsNullOrEmpty(obj.ToString())
                                                            ? string.Empty : string.Format("{0:C2}", obj));
                    });
                    column.CalculatedField(
                        l =>
                    {
                        if (l == null)
                        {
                            return(string.Empty);
                        }
                        var iznos = l.GetValueOf(nameof(UredajDenorm.NabavnaCijena));
                        return(iznos);
                    });
                });
            });

            #endregion
            byte[] pdf = report.GenerateAsByteArray();

            if (pdf != null)
            {
                Response.Headers.Add("content-disposition", "inline; filename=drzave.pdf");
                return(File(pdf, "application/pdf"));
                //return File(pdf, "application/pdf", "drzave.pdf"); //Otvara save as dialog
            }
            else
            {
                return(NotFound());
            }
        }