Пример #1
0
        public ReportController(IBlogService _blogService, IHostingEnvironment _hostingEnvironment, IConverter converter)
        {
            this._blogService = _blogService;

            this._hostingEnvironment = _hostingEnvironment;
            myPDF    = new MyPDF(_hostingEnvironment, converter);
            rootPath = _hostingEnvironment.ContentRootPath;
        }
Пример #2
0
 public HomeController(IPageAssignService pageAssignService, INavbarService navbarService, ILostAndFoundType lostAndFoundType,
                       LAFDbContext db, IModuleAssignService moduleAssignService, ILostAndFoundService lostAndFoundService,
                       UserManager <ApplicationUser> userManager, IHostingEnvironment _hostingEnvironment, IConverter converter)
 {
     this.pageAssignService   = pageAssignService;
     this.navbarService       = navbarService;
     this.moduleAssignService = moduleAssignService;
     this.lostAndFoundType    = lostAndFoundType;
     this.lostAndFoundService = lostAndFoundService;
     _userManager             = userManager;
     _db = db;
     this._hostingEnvironment = _hostingEnvironment;
     _lang    = new LangGenerate <DashboardLn>(_hostingEnvironment.ContentRootPath);
     _sLang   = new LangGenerate <SearchLn>(_hostingEnvironment.ContentRootPath);
     myPDF    = new MyPDF(_hostingEnvironment, converter);
     rootPath = _hostingEnvironment.ContentRootPath;
 }
    private void CreatePDF()
    {
        // Recalculate
        // Create a MyPdf object
        // Using the displayed GridViews on the page, creates a pdf document to save or display
        this.Recalculate();
        MyPDF myPDF = new MyPDF {
            GVComponent    = this.gvComponent,
            GVDiscount     = this.gvDiscount,
            GVTargetMargin = this.gvTargetMargin,
            Server         = this.Server,
            Response       = this.Response,
            CompanyName    = lblCompanyName.Text,
            QuoteNumber    = txtQuoteID.Text
        };

        myPDF.Create();
    }
        public async Task <FileResult> DetailsPdf(int?id, string[] column)
        {
            var invoice = await _context.Invoices.SingleOrDefaultAsync(m => m.Id == id);

            var spareparts = _context.Spareparts.Include(s => s.Country).Include(s => s.Equipment).Include(s => s.Manufacturer).Include(i => i.InvoiceSpareparts).ToList();
            var listSparepartsInInvoice = new List <Sparepart>();

            foreach (var sparepart in spareparts)
            {
                foreach (var item in sparepart.InvoiceSpareparts)
                {
                    if (item.InvoiceId == id)
                    {
                        listSparepartsInInvoice.Add(sparepart);
                    }
                }
            }
            var ms     = new MemoryStream();
            var pdfDoc = new Document(PageSize.A4);

            PdfWriter.GetInstance(pdfDoc, ms);
            var tahomaFont     = MyPDF.GetUnicodeFont("Tahoma", MyPDF.GetTahomaFontPath(), 11, Font.NORMAL, BaseColor.Black);
            var tahomaFontBold = MyPDF.GetUnicodeFont("Tahoma", MyPDF.GetTahomaFontPath(), 13, Font.BOLD, BaseColor.Black);
            var tahomaFontRed  = MyPDF.GetUnicodeFont("Tahoma", MyPDF.GetTahomaFontPath(), 13, Font.BOLD, BaseColor.Red);

            pdfDoc.AddAuthor("FreseBel and K");
            pdfDoc.Header = new HeaderFooter(new Phrase("Invoice: " + invoice.Num), false);
            pdfDoc.Open();
            string    st;
            Font      font        = tahomaFont;
            PdfPTable table       = new PdfPTable(2);
            var       pdfCellNull = new PdfPCell(new Phrase("                 ", tahomaFont))
            {
                Border = 0
            };

            table.AddCell(pdfCellNull);
            var pdfCell = new PdfPCell(new Phrase("ИНВОЙС", tahomaFontBold))
            {
                Border = 0
            };

            table.AddCell(pdfCell);
            table.AddCell(pdfCellNull);
            st      = invoice.Num + " / " + invoice.Date;
            pdfCell = new PdfPCell(new Phrase(@st, tahomaFontBold))
            {
                Border = 0
            };
            table.AddCell(pdfCell);
            table.AddCell(pdfCellNull);
            st      = "Отправитель: " + invoice.Sender;
            pdfCell = new PdfPCell(new Phrase(@st, tahomaFont))
            {
                Border = 0
            };
            table.AddCell(pdfCell);
            table.AddCell(pdfCellNull);
            table.AddCell(pdfCellNull);
            table.AddCell(pdfCellNull);
            st      = "Получатель: " + invoice.Recipient;
            pdfCell = new PdfPCell(new Phrase(@st, tahomaFont))
            {
                Border = 0,
            };
            table.AddCell(pdfCell);
            table.AddCell(pdfCellNull);
            table.AddCell(pdfCellNull);
            // Paragraph p;
            pdfDoc.Add(table);

            // Image img;
            string[] nameImg;

            int      iter        = 0;
            DateTime dateTimenow = new DateTime();

            dateTimenow = DateTime.Now;
            foreach (var item in listSparepartsInInvoice)
            {
                var      tahomaBold = tahomaFontBold;
                DateTime date       = new DateTime();
                date = ParseDate(item.Equipment.Ps);
                if (dateTimenow > date)
                {
                    tahomaBold = tahomaFontRed;
                }
                else
                {
                    tahomaBold = tahomaFontBold;
                }
                table = new PdfPTable(2)
                {
                    KeepTogether = true
                };
                iter++;
                //p = new Paragraph("" + item.FullName, tahomaFont); pdfDoc.Add(p);
                nameImg = item.Image.Split("/");
                //img = Image.GetInstance(MyPDF.GetImagePath(nameImg[2]));
                //img.ScaleAbsolute(159f, 159f);
                //pdfDoc.Add(img);
                //p = new Paragraph("" + item.Description, tahomaFont); pdfDoc.Add(p);
                //p = new Paragraph("" + item.Manufacturer, tahomaFont); pdfDoc.Add(p);

                pdfCell = new PdfPCell(new Phrase("", tahomaBold))
                {
                    Border  = 0,
                    Colspan = 2
                };
                table.AddCell(pdfCell);

                pdfCell = new PdfPCell(new Phrase("", tahomaBold))
                {
                    Border  = 0,
                    Colspan = 2
                };
                table.AddCell(pdfCell);


                st = item.Number + " " + item.NameEn + " / " + item.NameRus + "/" + item.Country.Nam;

                pdfCell = new PdfPCell(new Phrase(st, tahomaBold))
                {
                    Border  = 0,
                    Colspan = 2
                };
                table.AddCell(pdfCell);



                pdfCell = new PdfPCell(new Phrase("", tahomaFont))
                {
                    Border = 0,
                    Image  = Image.GetInstance(MyPDF.GetImagePath(nameImg[2]))
                };
                table.AddCell(pdfCell);


                st = "";
                if (column.Contains("4"))
                {
                    st = st + " Описание: " + item.Description;
                }

                if (column.Contains("7"))
                {
                    st = st + " Используется в оборудовании: " + item.Equipment.Name;
                }
                if (column.Contains("8"))
                {
                    st = st + " Код: " + item.Equipment.Code;
                }
                if (column.Contains("9"))
                {
                    st = st + " " + item.Equipment.Description;
                }

                if (column.Contains("10"))
                {
                    st = st + " Рег.номер: " + item.Equipment.RegNumber;
                }

                if (column.Contains("11"))
                {
                    st = st + " Действительно до: " + item.Equipment.Ps;
                }

                pdfCell = new PdfPCell(new Phrase(st, tahomaFont))
                {
                    Border = 0,
                };
                table.AddCell(pdfCell);
                st = "";
                if (column.Contains("13"))
                {
                    st = st + "Изготовитель " + item.Manufacturer.NameFull + "/" + item.Manufacturer.NameShort;
                }
                if (column.Contains("15"))
                {
                    st = st + "Код изготовителя " + item.Manufacturer.Code;
                }
                if (column.Contains("16"))
                {
                    st = st + "Адрес " + item.Manufacturer.AdressOfDeparture;
                }
                pdfCell = new PdfPCell(new Phrase(st, tahomaFont))
                {
                    Border  = 0,
                    Colspan = 2
                };
                table.AddCell(pdfCell);
                if (column.Contains("17") && (column.Contains("12")))
                {
                    nameImg = item.Manufacturer.Logo.Split("/");
                    pdfCell = new PdfPCell()
                    {
                        Border = 0,
                        Image  = Image.GetInstance(MyPDF.GetImagePath(nameImg[2]))
                    };
                    table.AddCell(pdfCell);

                    nameImg = item.Equipment.Image.Split("/");
                    pdfCell = new PdfPCell()
                    {
                        Border = 0,
                        Image  = Image.GetInstance(MyPDF.GetImagePath(nameImg[2]))
                    };
                    table.AddCell(pdfCell);
                }
                else
                {
                    if (column.Contains("12"))
                    {
                        nameImg = item.Equipment.Image.Split("/");
                        pdfCell = new PdfPCell()
                        {
                            Border = 0,
                            Image  = Image.GetInstance(MyPDF.GetImagePath(nameImg[2]))
                        };
                        table.AddCell(pdfCell);
                        st      = "";
                        st      = st + item.Equipment.Name;
                        st      = st + " Код: " + item.Equipment.Code;
                        st      = st + " " + item.Equipment.Description;
                        st      = st + " Рег.номер: " + item.Equipment.RegNumber;
                        st      = st + " Действительно до: " + item.Equipment.Ps;
                        pdfCell = new PdfPCell(new Phrase(st, tahomaFont))
                        {
                            Border = 0
                        };
                        table.AddCell(pdfCell);
                    }
                    if (column.Contains("17"))
                    {
                        nameImg = item.Manufacturer.Logo.Split("/");
                        pdfCell = new PdfPCell()
                        {
                            Border = 0,
                            Image  = Image.GetInstance(MyPDF.GetImagePath(nameImg[2]))
                        };
                        table.AddCell(pdfCell);
                        st      = "";
                        st      = st + "" + item.Manufacturer.NameFull + "/" + item.Manufacturer.NameShort;
                        st      = st + "Код  " + item.Manufacturer.Code;
                        st      = st + " " + item.Manufacturer.AdressOfDeparture;
                        pdfCell = new PdfPCell(new Phrase(st, tahomaFont))
                        {
                            Border = 0
                        };
                        table.AddCell(pdfCell);
                    }
                }


                pdfDoc.Add(table);
                // if (iter%3==0) pdfDoc.NewPage();
            }
            pdfDoc.Close();
            var pdfBytes = ms.ToArray();

            ms.Dispose();
            MyPDF.VerifyPdfFileIsReadable(pdfBytes);
            string file_type = "application/pdf";
            string file_name = "Invoice" + invoice.Num + invoice.Date + ".pdf";

            return(File(pdfBytes, file_type, file_name));
        }