示例#1
0
        public void When_serializing_and_deserializing_data_with_group_lines()
        {
            //Arrange
            var originalDocumentData = new DocumentData();
            var tableData            = new DocumentDataTable("A");

            tableData.AddGroup("Group1");
            tableData.AddRow(new Dictionary <string, string> {
                { "Col1", "Data1A" }, { "Col2", "Data2A" }
            });
            tableData.AddRow(new Dictionary <string, string> {
                { "Col1", "Data1B" }, { "Col2", "Data2B" }
            });
            tableData.AddGroup("Group2");
            tableData.AddRow(new Dictionary <string, string> {
                { "Col1", "Data1C" }, { "Col2", "Data2C" }
            });
            originalDocumentData.Add(tableData);
            var xmlDocumentData = originalDocumentData.ToXml();

            //Act
            var loadedDocumentData = DocumentData.Load(xmlDocumentData);

            //Assert
            Assert.AreEqual(originalDocumentData.GetDataTable("A").Rows.Count, loadedDocumentData.GetDataTable("A").Rows.Count);
            Assert.AreEqual(originalDocumentData.GetDataTable("A").Rows.Count(x => x is DocumentDataTableData), loadedDocumentData.GetDataTable("A").Rows.Count(x => x is DocumentDataTableData));
            Assert.AreEqual(originalDocumentData.GetDataTable("A").Rows.Count(x => x is DocumentDataTableGroup), loadedDocumentData.GetDataTable("A").Rows.Count(x => x is DocumentDataTableGroup));
            Assert.AreEqual((originalDocumentData.GetDataTable("A").Rows.First(x => x is DocumentDataTableGroup) as DocumentDataTableGroup).Content, (loadedDocumentData.GetDataTable("A").Rows.First(x => x is DocumentDataTableGroup) as DocumentDataTableGroup).Content);
            Assert.AreEqual((originalDocumentData.GetDataTable("A").Rows.Last(x => x is DocumentDataTableGroup) as DocumentDataTableGroup).Content, (loadedDocumentData.GetDataTable("A").Rows.Last(x => x is DocumentDataTableGroup) as DocumentDataTableGroup).Content);
            Assert.AreEqual((originalDocumentData.GetDataTable("A").Rows.First(x => x is DocumentDataTableData) as DocumentDataTableData).Columns.First().Key, (loadedDocumentData.GetDataTable("A").Rows.First(x => x is DocumentDataTableData) as DocumentDataTableData).Columns.First().Key);
            Assert.AreEqual((originalDocumentData.GetDataTable("A").Rows.First(x => x is DocumentDataTableData) as DocumentDataTableData).Columns.First().Value, (loadedDocumentData.GetDataTable("A").Rows.First(x => x is DocumentDataTableData) as DocumentDataTableData).Columns.First().Value);
        }
        public void Document_with_table()
        {
            //Arrange
            var documentData = new DocumentData();
            var t            = new DocumentDataTable("TableA");
            var row          = new Dictionary <string, string>();

            row.Add("Row1A", "RowData1A");
            row.Add("Row1B", "RowData1B");
            row.Add("Row1C", "RowData1C");
            t.AddRow(row);

            var row2 = new Dictionary <string, string>();

            row2.Add("Row2A", "RowData2A");
            row2.Add("Row2B", "RowData2A");
            row2.Add("Row2C", "RowData2A");
            t.AddRow(row2);

            documentData.Add(t);
            var xml = documentData.ToXml();

            //Act
            var other = DocumentData.Load(xml);

            //Assert
            Assert.AreEqual(documentData.Get("A"), other.Get("A"));
            Assert.AreEqual(documentData.GetDataTable("TableA").Rows.Count, other.GetDataTable("TableA").Rows.Count);
            Assert.AreEqual(((DocumentDataTableData)documentData.GetDataTable("TableA").Rows[0]).Columns.First().Key, ((DocumentDataTableData)other.GetDataTable("TableA").Rows[0]).Columns.First().Key);
            Assert.AreEqual(((DocumentDataTableData)documentData.GetDataTable("TableA").Rows[0]).Columns.First().Value, ((DocumentDataTableData)other.GetDataTable("TableA").Rows[0]).Columns.First().Value);
            Assert.AreEqual(((DocumentDataTableData)documentData.GetDataTable("TableA").Rows[1]).Columns.First().Key, ((DocumentDataTableData)other.GetDataTable("TableA").Rows[1]).Columns.First().Key);
            Assert.AreEqual(((DocumentDataTableData)documentData.GetDataTable("TableA").Rows[1]).Columns.First().Value, ((DocumentDataTableData)other.GetDataTable("TableA").Rows[1]).Columns.First().Value);
            Assert.AreEqual(xml.OuterXml, other.ToXml().OuterXml);
        }
示例#3
0
        private static DocumentData GetData()
        {
            var data = new DocumentData();

            //Prepare the data for the table
            var documentDataTable = new DocumentDataTable("MyTable");
            var totalSum          = 0;

            for (var i = 0; i < 100; i++)
            {
                var val = i * 70;
                totalSum += val;

                documentDataTable.AddRow(new Dictionary <string, string>
                {
                    { "FirstCol", "Col 1 Row " + i },
                    { "SecondCol", val.ToString("#,##0.00") },
                    { "ThirdCol", new string((char)(65 + (i / 4)), 1 + (i % 20)) }
                });
            }

            data.Add(documentDataTable);

            //Prepare some other data
            data.Add("SomeOtherData", "This is some custom data");
            data.Add("TotalSum", totalSum.ToString("#,##0.00"));

            return(data);
        }
示例#4
0
        public void When_rendering_several_times_with_the_same_template()
        {
            //Arrange
            var table1 = new Table {
                Name = "TableA", Top = "2cm", Height = "5cm"
            };

            table1.AddColumn(new TableColumn {
                Value = "ColumnA1", Title = "Column A", Width = "2cm", WidthMode = Table.WidthMode.Auto, Align = Table.Alignment.Left, HideValue = string.Empty
            });
            var section = new Section();

            section.Pane.ElementList.Add(table1);
            var template      = new Template(section);
            var documentData1 = new DocumentData();
            var tbl1          = new DocumentDataTable("TableA");

            documentData1.Add(tbl1);
            for (var i = 0; i < 30; i++)
            {
                var row1 = new Dictionary <string, string>();
                row1.Add("ColumnA1", "DataA" + i);
                tbl1.AddRow(row1);
            }

            var documentData2 = new DocumentData();
            var tbl2          = new DocumentDataTable("TableA");

            documentData2.Add(tbl2);
            for (var i = 0; i < 10; i++)
            {
                var row2 = new Dictionary <string, string>();
                row2.Add("ColumnA1", "DataA" + i);
                tbl2.AddRow(row2);
            }

            var documentData3 = new DocumentData();
            var tbl3          = new DocumentDataTable("TableA");

            documentData3.Add(tbl3);
            for (var i = 0; i < 20; i++)
            {
                var row3 = new Dictionary <string, string>();
                row3.Add("ColumnA1", "DataA" + i);
                tbl3.AddRow(row3);
            }

            var graphicsMock = new Mock <IGraphics>(MockBehavior.Strict);

            graphicsMock.Setup(x => x.MeasureString(It.IsAny <string>(), It.IsAny <XFont>())).Returns(new XSize());
            graphicsMock.Setup(x => x.MeasureString(It.IsAny <string>(), It.IsAny <XFont>(), It.IsAny <XStringFormat>())).Returns(new XSize());
            graphicsMock.Setup(x => x.DrawString(It.IsAny <string>(), It.IsAny <XFont>(), It.IsAny <XBrush>(), It.IsAny <XPoint>(), It.IsAny <XStringFormat>()));

            var graphicsFactoryMock = new Mock <IGraphicsFactory>(MockBehavior.Strict);

            graphicsFactoryMock.Setup(x => x.PrepareGraphics(It.IsAny <PdfPage>(), It.IsAny <DocumentRenderer>(), It.IsAny <int>())).Returns(graphicsMock.Object);

            var renderer1 = new Renderer(graphicsFactoryMock.Object, template, documentData1);
            var renderer2 = new Renderer(graphicsFactoryMock.Object, template, documentData2);
            var renderer3 = new Renderer(graphicsFactoryMock.Object, template, documentData3);

            //Act
            var data1 = renderer1.GetPdfBinary();
            var data2 = renderer2.GetPdfBinary();
            var data3 = renderer3.GetPdfBinary();

            //Assert
            //Assert.AreEqual(data1, data2);
        }
示例#5
0
        public async override Task <bool> InvokeAsync(string paramList)
        {
            //TODO: Put code that creates an example invoice here
            var sections = GetSections();
            var template = new Template(sections.First());

            foreach (var section in sections.TakeAllButFirst())
            {
                template.SectionList.Add(section);
            }

            var documentProperties = new DocumentProperties();
            var sampleData         = new DocumentData();
            var documentDataTable  = new DocumentDataTable("OrderItems");

            documentDataTable.AddGroup("ABC");
            documentDataTable.AddRow(
                new Dictionary <string, string>
            {
                { "Description", "Begonina extrapris röda fina" },
                { "Details", "ABC123_xAB111x" },
                { "DateAdded", "2015-01-01" },
                { "AddedBy", "DB" },
                { "AmountDescription", "12x24" },
                { "Count", "1'000" },
                { "NetNormalItemPrice", "1'000.00" },
                { "DiscountPercentage", "10" },
                { "NetSaleItemPrice", "1'000.00" },
                { "NetSaleTotalPrice", "1'000.00" },
            });
            for (var i = 0; i < 60; i++)
            {
                documentDataTable.AddRow(
                    new Dictionary <string, string>
                {
                    { "Description", "A" },
                    { "Details", "" },
                    { "DateAdded", "C" },
                    { "AddedBy", "" },
                    { "AmountDescription", "E" },
                    { "Count", "F" },
                    { "NetNormalItemPrice", "G" },
                    { "DiscountPercentage", "H" },
                    { "NetSaleItemPrice", "" },
                    { "NetSaleTotalPrice", "J" },
                });
            }
            sampleData.Add(documentDataTable);

            var paymentDataTable = new DocumentDataTable("Payments");

            paymentDataTable.AddRow(new Dictionary <string, string>
            {
                { "PaymentMethod", "A1" },
                { "PaymentDate", "" },
                { "PaymentSum", "C1" }
            });

            paymentDataTable.AddRow(new Dictionary <string, string>
            {
                { "PaymentMethod", "A2" },
                { "PaymentDate", "B2" },
                { "PaymentSum", "C2" }
            });

            sampleData.Add(paymentDataTable);

            //System.IO.File.WriteAllText(@"C:\a.xml", template.ToXml().OuterXml);

            //await PdfCommand.RenderPrinterAsync(template, documentProperties, sampleData, null, false);

            var sw = new Stopwatch();

            sw.Start();

            //TODO: Time this function and try to make it as fast as possible
            var pageSizeInfo    = new PageSizeInfo("A4");
            var renderer        = new Renderer(template, sampleData, documentProperties, pageSizeInfo, false, PrinterInteractionMode.None);
            var printerSettings = new PrinterSettings {
                PrinterName = "Microsoft XPS Document Writer", PrintFileName = @"C:\temp\a.xps", PrintToFile = true
            };

            renderer.Print(printerSettings, true);

            OutputInformation("It took " + sw.Elapsed.TotalSeconds + "s to send to printer."); //BEFORE: 01 519,796ms

            return(true);
        }
示例#6
0
        public override async Task <bool> InvokeAsync(string paramList)
        {
            var section = new Section();
            var table   = new Table
            {
                Name   = "A",
                Top    = "100",
                Bottom = "100",
                Left   = "50",
                Right  = "50",

                HeaderBackgroundColor = Color.Pink,
                //HeaderBorderColor = Color.Blue,
                //ColumnBorderColor = Color.Green,
                //ContentBorderColor = Color.DeepPink,
                //GroupBorderColor = Color.Chocolate,

                SkipLine = new SkipLine
                {
                    Height      = "5",
                    Interval    = 3,
                    BorderColor = Color.Red
                }
            };

            table.AddColumn(new TableColumn {
                Title = "First", Value = "{A1}"
            });
            table.AddColumn(new TableColumn {
                Title = "Second", Value = "{A2}"
            });
            section.Pane.ElementList.Add(table);
            var template = new Template(section);

            var documentProperties = new DocumentProperties();

            var sampleData        = new DocumentData();
            var documentDataTable = new DocumentDataTable("A");

            documentDataTable.AddRow(new Dictionary <string, string> {
                { "A1", "Some stuff" }, { "A2", "Some stuff" },
            });
            documentDataTable.AddRow(new Dictionary <string, string> {
                { "A1", "Some stuff on the second row" }, { "A2", "Blah" },
            });
            documentDataTable.AddRow(new Dictionary <string, string> {
                { "A1", "And on the third row" }, { "A2", "blah blah blah" },
            });
            for (var i = 0; i < 10; i++)
            {
                documentDataTable.AddRow(new Dictionary <string, string> {
                    { "A1", i.ToString() }, { "A2", "hästmos" },
                });
            }

            sampleData.Add(documentDataTable);

            var pageSizeInfo = new PageSizeInfo("A4");

            await PdfCommand.RenderPdfAsync(template, documentProperties, sampleData, pageSizeInfo, false, true);

            return(true);
        }