コード例 #1
0
ファイル: ReportController.cs プロジェクト: ngajski/videozid
        public async Task <IActionResult> VideozidoviExcel()
        {
            var list   = new List <VideozidDenorm>();
            var zidovi = _context.Videozid
                         .ToList();

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

            foreach (var v in zidovi)
            {
                var ekrani = _context.EkranZida.Where(u => u.IdZida == v.Id).Include(u => u.IdUredajaNavigation).ToList();
                var vi     = new VideozidDetailsViewModel(v, ekrani).GetInfo();
                list.Add(vi);
            }
            list.Sort((a, b) => a.Naziv.CompareTo(b.Naziv));

            byte[] content;
            using (ExcelPackage excel = list.CreateExcel("Videozidovi"))
            {
                content = excel.GetAsByteArray();
            }
            return(File(content, ExcelContentType, "videozidovi.xlsx"));
        }
コード例 #2
0
        // GET: Videozid/Details/5
        /// <summary>
        /// Postupak za dohvat ekrana koji prikazuje informacije o jednom videozidu.
        /// </summary>
        /// <param name="id">ID videozida</param>
        /// <returns>Pogled koji prikazuje podatke o videozidu</returns>
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var videozid = await _context.Videozid
                           .SingleOrDefaultAsync(m => m.Id == id);

            if (videozid == null)
            {
                return(NotFound());
            }

            var ekrani = _context.EkranZida.Where(u => u.IdZida == videozid.Id).Include(u => u.IdUredajaNavigation).ToList();

            VideozidDetailsViewModel v = new VideozidDetailsViewModel(videozid, ekrani);

            return(View(v));
        }
コード例 #3
0
ファイル: ReportController.cs プロジェクト: ngajski/videozid
        public async Task <IActionResult> Videozidovi()
        {
            string naslov = "Popis videozidova";
            var    list   = new List <VideozidDenorm>();
            var    zidovi = _context.Videozid
                            .ToList();

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

            foreach (var v in zidovi)
            {
                var ekrani = _context.EkranZida.Where(u => u.IdZida == v.Id).Include(u => u.IdUredajaNavigation).ToList();
                var vi     = new VideozidDetailsViewModel(v, ekrani).GetInfo();
                list.Add(vi);
            }

            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.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 <VideozidDenorm>(x => x.Naziv);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(1);
                    column.Width(2);
                    column.HeaderCell("Naziv Videozida");
                });

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

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

                columns.AddColumn(column =>
                {
                    column.PropertyName <VideozidDenorm>(x => x.Visina);
                    column.CellsHorizontalAlignment(HorizontalAlignment.Center);
                    column.IsVisible(true);
                    column.Order(4);
                    column.Width(1);
                    column.HeaderCell("Visina", horizontalAlignment: HorizontalAlignment.Center);
                });

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

            #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());
            }
        }