示例#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);
        }
示例#2
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);
        }