예제 #1
0
        private void CreateHeaderAndFooter(DocX doc)
        {
            var    pngPath     = Path.Combine(_hostingEnvironment.WebRootPath, "nccsoftlogo.png");
            string titleHeader = "NCCPLUS VIET NAM JSC";

            doc.AddHeaders();
            Header h = doc.Headers.Odd;

            Xceed.Document.NET.Image   image = doc.AddImage(pngPath);
            Xceed.Document.NET.Picture p     = image.CreatePicture(29, 72);

            h.InsertParagraph(titleHeader).Alignment       = Alignment.left;
            h.InsertParagraph().AppendPicture(p).Alignment = Alignment.right;
            h.InsertParagraph();

            doc.AddFooters();
            Footer footer = doc.Footers.Odd;

            footer.InsertParagraph().Append("Page ").AppendPageNumber(PageNumberFormat.normal).Append(" of  ").AppendPageCount(PageNumberFormat.normal).Alignment = Alignment.center;
        }
예제 #2
0
        //public FormattedText(string textToFormat, Typeface typeface, double emSize, System.Windows.Media.Brush foreground)
        //{

        //}



        //public String titleFormat { get; set; }
        //private void CreateDocument()
        //{

        //    DateTime Datum = DateTime.Now;
        //    string selected = cmbKl.Text;

        //    string id = cmbKl.SelectedValue.ToString();
        //    var klt = Convert.ToInt32(id);

        //    string file = ($"{selected}{Datum:yyyy.M.dd}.pdf");

        //    //         string fileName = @"C:\Users\HP\source\repos\ProjectInlog\ProjectInlog\bin\Debug\temp1.docx";
        //    //         var doc = DocX.Create(file);


        //    //         using (ProjectContext ctx = new ProjectContext())
        //    //         {

        //    //             var sell = ctx.OrderLines.Join(ctx.Orders,
        //    //         s => s.Order.OrderId,
        //    //         a => a.OrderId,
        //    //         (s, a) => new { s, a })
        //    //             .Where(z => z.a.ClientId == klt);
        //    //             var best = sell.Join(ctx.Products,
        //    //                 sa => sa.s.ProductId,
        //    //                 alb => alb.ProductId,
        //    //             //  (sa, alb) => new { Name = alb.Description, Price = alb.Price, Aantal = sa.s.O_Aantal, Kl = sa.a.ClientId, Ordr = sa.a.OrderId, Tot = Math.Round(alb.Price * sa.s.O_Aantal) }).ToList();
        //    //             (sa, alb) => new { sa, alb });
        //    //             var ok = best.Join(ctx.Clients,
        //    //                 b => b.sa.a.ClientId,
        //    //                 c => c.ClientId,
        //    //                 (b, c) => new
        //    //                 {
        //    //                     Name = b.alb.Description,
        //    //                     Price = b.alb.Price,
        //    //                     Aantal = b.sa.s.O_Aantal,
        //    //                     Kl = b.sa.a.ClientId,
        //    //                     Ordr = b.sa.a.OrderId,
        //    //                     KL_name = c.C_Name,
        //    //                     KL_adres = c.C_Adress,
        //    //                     KL_woonplaats = c.C_Woonplaats,
        //    //                     KL_postcode = c.C_PostCode,
        //    //                     KL_btw = c.C_BtwNr,
        //    //                     Tot = Math.Round(b.alb.Price * b.sa.s.O_Aantal)
        //    //                 }).ToList();



        //    using (PdfDocument pdf = new PdfDocument())
        //    {
        //        PdfPage Page = pdf.AddPage();
        //        PdfPage page = pdf.Pages.Add();
        //        PdfGraphics graph = page.Graphics;

        //        //PdfSharp.Pdf.PdfDocument pdf = new PdfSharp.Pdf.PdfDocument();
        //        ////Add a page
        //        //PdfSharp.Pdf.PdfPage page = pdf.AddPage();
        //        // PdfGraphics graph = ;
        //        PdfFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 24, PdfFontStyle.Bold);
        //        PdfFont font1 = new PdfStandardFont(PdfFontFamily.TimesRoman, 14);
        //        graph.DrawString("Factuur", font, PdfBrushes.Black, new PointF(10, 50));
        //        ;
        //        //string file = ($"{selected}{Datum:yyyy.M.dd}.txt");

        //        using (ProjectContext ctx = new ProjectContext())
        //        {

        //            var sell = ctx.OrderLines.Join(ctx.Orders,
        //        s => s.Order.OrderId,
        //        a => a.OrderId,
        //        (s, a) => new { s, a })
        //            .Where(z => z.a.ClientId == klt);
        //            var best = sell.Join(ctx.Products,
        //                sa => sa.s.ProductId,
        //                alb => alb.ProductId,
        //            //  (sa, alb) => new { Name = alb.Description, Price = alb.Price, Aantal = sa.s.O_Aantal, Kl = sa.a.ClientId, Ordr = sa.a.OrderId, Tot = Math.Round(alb.Price * sa.s.O_Aantal) }).ToList();
        //            (sa, alb) => new { sa, alb });
        //            var ok = best.Join(ctx.Clients,
        //                b => b.sa.a.ClientId,
        //                c => c.ClientId,
        //                (b, c) => new
        //                {
        //                    Name = b.alb.Description,
        //                    Price = b.alb.Price,
        //                    Aantal = b.sa.s.O_Aantal,
        //                    Kl = b.sa.a.ClientId,
        //                    Ordr = b.sa.a.OrderId,
        //                    KL_name = c.C_Name,
        //                    KL_adres = c.C_Adress,
        //                    KL_woonplaats = c.C_Woonplaats,
        //                    KL_postcode = c.C_PostCode,
        //                    KL_btw = c.C_BtwNr,
        //                    Tot = Math.Round(b.alb.Price * b.sa.s.O_Aantal)
        //                }).ToList();


        //            var eind = false;
        //            var tel = 0;
        //            double tota = 0;
        //            //   graph.DrawString(, font, XBrushes.Black, new XRect(0, 0, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);
        //            var i = 150;
        //            var j = 50;
        //            foreach (var item in ok)
        //            {
        //                if (tel == 0)
        //                {
        //                    var gem = item.KL_postcode + " " + item.KL_woonplaats;
        //                    graph.DrawString(item.KL_name, font1, PdfBrushes.Black, new PointF(10, 30));
        //                    graph.DrawString(item.KL_adres, font1, PdfBrushes.Black, new PointF(10, 40));
        //                    graph.DrawString(gem, font1, PdfBrushes.Black, new PointF(10, 50));
        //                    graph.DrawString(item.KL_btw, font1, PdfBrushes.Black, new PointF(10, 60));
        //                    graph.DrawString("Product", font1, PdfBrushes.Black, new PointF(10, 70));
        //                    DataTable datatable = new DataTable();

        //                    datatable.Columns.Add("Product");
        //                    datatable.Columns.Add("Description");
        //                    datatable.Columns.Add("Quantity");
        //                    datatable.Columns.Add("Price");
        //                    tel = 1;
        //                }

        //                graph.DrawString(item.Name, font1, PdfBrushes.Black, new PointF(0, 160));
        //                graph.DrawString((item.Aantal).ToString(), font1, PdfBrushes.Black, new PointF(10, 30));
        //                graph.DrawString((item.Price).ToString(), font1, PdfBrushes.Black, new PointF(10, 30));
        //                graph.DrawString((item.Tot).ToString(), font1, PdfBrushes.Black, new PointF(10, 30));
        //            }
        //        }
        //        pdf.Save("firstpage.pdf");
        //        Process.Start("Firstpage.pdf");

        //        pdf.Close(true);

        //    }
        //}
        private void CreateTest()
        {
            DateTime Datum    = DateTime.Now;
            string   selected = cmbKl.Text;

            if (selected == "")
            {
                MessageBox.Show("Kies een klant voor het maken van de factuur");
            }
            else
            {
                string id  = cmbKl.SelectedValue.ToString();
                var    klt = Convert.ToInt32(id);

                string file = ($"{selected}{Datum:yyyy.M.dd}.docx");
                //string file2 = ($"{selected}{Datum:yyyy.M.dd}.pdf");
                string     dat         = Datum.ToString("dd  MMMM  yyyy");
                string     title       = "Factuur ";
                Formatting titleFormat = new Formatting();
                //Specify font family
                titleFormat.FontFamily = new Xceed.Document.NET.Font("arial");
                //Specify font size
                titleFormat.Size           = 25D;
                titleFormat.Position       = 30;
                titleFormat.FontColor      = System.Drawing.Color.Orange;
                titleFormat.UnderlineColor = System.Drawing.Color.Gray;
                titleFormat.Italic         = true;
                titleFormat.Bold           = true;
                titleFormat.Spacing        = 20;


                Formatting textParagraphFormat = new Formatting();
                textParagraphFormat.FontFamily = new Xceed.Document.NET.Font("times new roman");
                textParagraphFormat.Size       = 20D;
                textParagraphFormat.Spacing    = 1;


                //string fileName = @"firstpage.docx";
                var doc = DocX.Create(file);
                // doc.InsertParagraph("Factuur");
                Table v = doc.AddTable(1, 2);
                v.Alignment = Alignment.center;
                v.Design    = TableDesign.ColorfulList;



                Image     img = doc.AddImage(@"C:\Users\HP\source\repos\ProjectInlog\ProjectInlog\Images\meubels.png");
                Picture   pic = img.CreatePicture();
                Paragraph p1  = doc.InsertParagraph();
                p1.AppendPicture(pic);
                // Paragraph.AppendPicture(pic);
                Paragraph paragraphTitle = doc.InsertParagraph(title, false, titleFormat);

                //v.Rows[0].Cells[0].Paragraphs.First().Append(p1);
                //v.Rows[0].Cells[1].Paragraphs.First().Append("BB");



                using (ProjectContext ctx = new ProjectContext())
                {
                    //DataRow LastRow = ctx.Invoices.Rows.Count() ;
                    //var aan = Convert.ToInt32(ctx.Invoices.LastOrDefault());


                    var sell = ctx.OrderLines.Join(ctx.Orders,
                                                   s => s.Order.OrderId,
                                                   a => a.OrderId,
                                                   (s, a) => new { s, a })
                               .Where(z => z.a.ClientId == klt);
                    var best = sell.Join(ctx.Products,
                                         sa => sa.s.ProductId,
                                         alb => alb.ProductId,
                                         //  (sa, alb) => new { Name = alb.Description, Price = alb.Price, Aantal = sa.s.O_Aantal, Kl = sa.a.ClientId, Ordr = sa.a.OrderId, Tot = Math.Round(alb.Price * sa.s.O_Aantal) }).ToList();
                                         (sa, alb) => new { sa, alb });
                    var ok = best.Join(ctx.Clients,
                                       b => b.sa.a.ClientId,
                                       c => c.ClientId,
                                       (b, c) => new
                    {
                        Name          = b.alb.Description,
                        Price         = b.alb.Price,
                        Aantal        = b.sa.s.O_Aantal,
                        Kl            = b.sa.a.ClientId,
                        Ordr          = b.sa.a.OrderId,
                        KL_name       = c.C_Name,
                        KL_adres      = c.C_Adress,
                        KL_woonplaats = c.C_Woonplaats,
                        KL_postcode   = c.C_PostCode,
                        KL_btw        = c.C_BtwNr,
                        Tot           = Math.Round((b.alb.Price * b.sa.s.O_Aantal), 2)
                    }).ToList();

                    if (ok.Count != 0)
                    {
                        //var eind = false;
                        var    tel  = 0;
                        double tota = 0;
                        var    tt   = 0;
                        //
                        //var ord = 0;
                        Table t = doc.AddTable(21, 5);
                        t.Alignment = Alignment.center;
                        t.Design    = TableDesign.ColorfulList;
                        var i = 1;
                        foreach (var item in ok)
                        {
                            if (tel == 0)
                            {
                                var gem = item.KL_postcode + " " + item.KL_woonplaats;
                                doc.InsertParagraph($"FACTUUR { item.Ordr}                                                                                                         FURNITURE");
                                doc.InsertParagraph();
                                doc.InsertParagraph($"{item.KL_name}                                                                                                                        Industrieweg 20");
                                doc.InsertParagraph($"{item.KL_adres}                                                                                                                2440 GEEL");
                                doc.InsertParagraph(gem);
                                doc.InsertParagraph($"BTW {item.KL_btw}");
                                doc.InsertParagraph();

                                tel = 1;
                                t.Rows[0].Cells[0].Paragraphs.First().Append("Omschrijving");
                                t.Rows[0].Cells[1].Paragraphs.First().Append("Aantal");
                                t.Rows[0].Cells[2].Paragraphs.First().Append("EenheidsPrijs");
                                t.Rows[0].Cells[3].Paragraphs.First().Append("Totaal");
                                t.Rows[0].Cells[4].Paragraphs.First().Append("Order");
                                tt = item.Ordr;
                            }



                            //Create Table with 24 rows and 5 columns.

                            //Fill cells by adding text.
                            t.Rows[i].Cells[0].Paragraphs.First().Append(item.Name);
                            t.Rows[i].Cells[1].Paragraphs.First().Append(item.Aantal.ToString());
                            t.Rows[i].Cells[2].Paragraphs.First().Append("€" + item.Price.ToString());
                            t.Rows[i].Cells[3].Paragraphs.First().Append("€" + item.Tot.ToString());
                            t.Rows[i].Cells[4].Paragraphs.First().Append(item.Ordr.ToString());
                            tota += item.Tot;
                            i    += 1;
                        }
                        ctx.Invoices.Add(new Invoice()
                        {
                            Amount    = tota,
                            Status    = false,
                            CreatedAt = Datum,
                            PayedAt   = Datum,
                            OrderId   = tt
                        });
                        ctx.SaveChanges();

                        t.Rows[18].Cells[2].Paragraphs.First().Append("Totaal zonder BTW");
                        t.Rows[18].Cells[3].Paragraphs.First().Append("€" + tota.ToString());
                        // t.Rows[21].Cells[0].);


                        var btw = Math.Round((tota * 0.21), 2);
                        t.Rows[19].Cells[2].Paragraphs.First().Append("BTW bedrag");
                        t.Rows[19].Cells[3].Paragraphs.First().Append("€" + btw.ToString());
                        var total = Math.Round((tota + btw), 2);
                        t.Rows[20].Cells[2].Paragraphs.First().Append("Totaal met BTW");
                        t.Rows[20].Cells[3].Paragraphs.First().Append("€" + total.ToString());
                        doc.InsertTable(t);

                        doc.InsertParagraph();
                        doc.InsertParagraph("Ondernemingsnummer: 0123 456 789");
                        doc.InsertParagraph("Bank              : ING Belgium NV");
                        doc.InsertParagraph("SWIFT/BIC         : BBRUBEBB");
                        doc.InsertParagraph("IBAN              : BE33 7894 6324 4587");


                        doc.Save();



                        MessageBoxResult result = MessageBox.Show("Wenst u het factuur te beijken?", "Factuur aangemaakt", MessageBoxButton.YesNo, MessageBoxImage.Information);
                        if (result == MessageBoxResult.Yes)
                        {
                            //Process process = new Process();
                            //process.StartInfo.FileName = file;
                            //process.Start();

                            Process.Start("WINWORD.EXE", file);
                        }

                        // Process.Start("WINWORD.EXE", file);
                    }
                    else
                    {
                        MessageBox.Show("er is geen verkoop voor de gekozen klant");
                    }
                }
            }
        }