Ejemplo n.º 1
0
        void fillContent(Fahrt f)
        {
            int    km           = (int)(f.End_KM - f.Start_KM);
            int    stunden      = (int)Math.Ceiling(((TimeSpan)(f.Endzeit - f.Startzeit)).TotalHours);
            double faktorKm     = 0.3;
            double faktorStunde = 0.75;
            double preisKm      = km * faktorKm;
            double preisStunde  = stunden * faktorStunde;
            double preisFahrt   = preisKm + preisStunde;


            // Each item fills two rows
            Row row1 = this.table.AddRow();

            row1.TopPadding       = 1.5;
            row1.Format.Alignment = ParagraphAlignment.Center;
            row1.Cells[0].AddParagraph(f.Fahrt_ID.ToString());
            row1.Cells[1].AddParagraph(km.ToString());
            row1.Cells[2].AddParagraph(stunden.ToString());
            row1.Cells[3].AddParagraph(preisKm.ToString("0.00") + " €");
            row1.Cells[4].AddParagraph(preisStunde.ToString("0.00") + " €");
            row1.Cells[5].AddParagraph(preisFahrt.ToString("0.00") + " €");

            totalPrice = totalPrice + preisFahrt;
            this.table.SetEdge(0, this.table.Rows.Count - 2, 6, 2, Edge.Box, BorderStyle.Single, 0.75);
        }
Ejemplo n.º 2
0
        public Document createDocument(Fahrt f)
        {
            totalPrice = 0;
            // Create a new MigraDoc document
            document              = new Document();
            document.Info.Title   = "Rechnung der eCar GmbH";
            document.Info.Subject = "Rechnung für " + f.Kunde.Vorname + " " + f.Kunde.Name;
            document.Info.Author  = "Vincent Mang";

            defineStyles();

            createPage(f);

            return(document);
        }
Ejemplo n.º 3
0
        void createPage(Fahrt f)
        {
            // Each MigraDoc document needs at least one section.
            Section   section = document.AddSection();
            TextFrame addressFrame;
            TextFrame textFrame;
            TextFrame header;
            // Put a logo in the header
            Image image = section.Headers.Primary.AddImage("../../ecar_logo.png");

            image.Height             = "2.0cm";
            image.Width              = "5 cm";
            image.LockAspectRatio    = true;
            image.RelativeVertical   = RelativeVertical.Line;
            image.RelativeHorizontal = RelativeHorizontal.Margin;
            image.Top              = ShapePosition.Top;
            image.Left             = ShapePosition.Right;
            image.WrapFormat.Style = WrapStyle.Through;
            string footer = "eCar GmbH · Badstr. 42 · 77654 Offenburg · Deutschland";
            // Create footer
            Paragraph paragraph = section.Footers.Primary.AddParagraph();

            paragraph.AddText(footer);
            paragraph.Format.Font.Size = 9;
            paragraph.Format.Alignment = ParagraphAlignment.Center;
            // Create Header
            header       = section.AddTextFrame();
            header.Width = "5 cm";
            Paragraph h = header.AddParagraph("eCar GmbH");

            h.Format.Font.Name  = "Times New Roman";
            h.Format.Font.Size  = 26;
            h.Format.SpaceAfter = 4;
            h.Format.Font.Bold  = true;
            h.Format.Alignment  = ParagraphAlignment.Center;

            //Create textframe
            textFrame = section.AddTextFrame();

            textFrame.Top  = "20 cm";
            textFrame.Left = ShapePosition.Left;
            textFrame.RelativeHorizontal = RelativeHorizontal.Column;
            textFrame.RelativeVertical   = RelativeVertical.Page;
            textFrame.Width = "20 cm";
            Paragraph rt = textFrame.AddParagraph("Der o.g. Gesamtbetrag wird Ihnen in den nächsten Tagen von folgendem Konto abgebucht:");

            rt.Format.Font.Name  = "Times New Roman";
            rt.Format.Font.Size  = 12;
            rt.Format.SpaceAfter = 4;
            rt.AddLineBreak();
            rt.AddLineBreak();
            rt.AddText("Kontoinhaber:\t" + f.Kunde.Vorname + " " + f.Kunde.Name);
            rt.AddLineBreak();
            rt.AddText("BIC:\t\t" + f.Kunde.Bank.BIC);
            rt.AddLineBreak();
            rt.AddText("IBAN:\t\t" + f.Kunde.Bank.IBAN);


            // Create the text frame for the address
            addressFrame                    = section.AddTextFrame();
            addressFrame.Height             = "3.0cm";
            addressFrame.Width              = "7.0cm";
            addressFrame.Left               = ShapePosition.Left;
            addressFrame.RelativeHorizontal = RelativeHorizontal.Margin;
            addressFrame.Top                = "5.0cm";
            addressFrame.RelativeVertical   = RelativeVertical.Page;

            // Put sender in address frame
            paragraph = addressFrame.AddParagraph(footer);
            paragraph.Format.Font.Name  = "Times New Roman";
            paragraph.Format.Font.Size  = 7;
            paragraph.Format.SpaceAfter = 3;

            // Fill address in address text frame
            Paragraph pg = addressFrame.AddParagraph();

            pg.AddText(f.Kunde.Vorname + " " + f.Kunde.Name);
            pg.AddLineBreak();
            pg.AddText(f.Kunde.Adresse.Strasse + " " + f.Kunde.Adresse.Hausnummer);
            pg.AddLineBreak();
            pg.AddText(f.Kunde.Adresse.PLZ + " " + f.Kunde.Adresse.Ort);

            // Add the print date field
            CultureInfo ci = new CultureInfo("de-DE");

            paragraph = section.AddParagraph();
            paragraph.Format.SpaceBefore = "8cm";
            paragraph.Style = "Reference";
            paragraph.AddFormattedText("eCar Rechnung für den Monat " + ci.DateTimeFormat.MonthNames[DateTime.Now.AddMonths(-2).Month], TextFormat.Bold);
            paragraph.AddTab();
            paragraph.AddText("Offenburg, ");
            paragraph.AddDateField("dd.MM.yyyy");

            // Create the item table
            this.table                     = section.AddTable();
            this.table.Style               = "Table";
            this.table.Borders.Width       = 0.25;
            this.table.Borders.Left.Width  = 0.5;
            this.table.Borders.Right.Width = 0.5;
            this.table.Rows.LeftIndent     = 0;

            // Before you can add a row, you must define the columns 16cm
            Column column = this.table.AddColumn("1cm");

            column.Format.Alignment = ParagraphAlignment.Center;

            column = this.table.AddColumn("2.5cm");
            column.Format.Alignment = ParagraphAlignment.Right;

            column = this.table.AddColumn("3cm");
            column.Format.Alignment = ParagraphAlignment.Right;

            column = this.table.AddColumn("3.5cm");
            column.Format.Alignment = ParagraphAlignment.Right;

            column = this.table.AddColumn("2cm");
            column.Format.Alignment = ParagraphAlignment.Center;

            column = this.table.AddColumn("4cm");
            column.Format.Alignment = ParagraphAlignment.Right;

            // Create the header of the table
            Row row = table.AddRow();

            row.HeadingFormat    = true;
            row.Format.Alignment = ParagraphAlignment.Center;
            row.Format.Font.Bold = true;
            row.Shading.Color    = Color.FromRgbColor((byte)255, Color.Parse("0xb2b9be"));
            row.Cells[0].AddParagraph("Fahrt-ID");
            row.Cells[1].AddParagraph("Kilometer");
            row.Cells[2].AddParagraph("Stunden");
            row.Cells[3].AddParagraph("Preis KM");
            row.Cells[4].AddParagraph("Preis Stunden");
            row.Cells[5].AddParagraph("Preis pro Fahrt");



            this.table.SetEdge(0, 0, 6, 1, Edge.Box, MigraDoc.DocumentObjectModel.BorderStyle.Single, 0.75, Color.Empty);
        }