Lightswitch Inventory Application Column Mapping using Office Integration Pack Print Reports to Word Problem RRS feed

  • Question

  • Firstly please view my image here for database tables and results rendered

    i have search high and low for this answer, ive tried literally every every possible solution, i guess i need some professional help. Im designing an inventory app with lightswitch. thus far i have everything perfectly working, including deducting stock when making invoices and adding stock when making orders. I have the invoices half correct, the only issue im having is mapping the tables to show products associated with the order. I know exactly where my issue is however i cant find the answer how to fix this.

    1. I followed this tutorial for using the office integration pack with word templates.

    2. I changed the code to be compatible with c#.

    3. I now have a word template with all the correct book marks and mapping to columns.

    4. If you check in the image attachment i have placed the results of the table results column mapping, i get the "quantity" correct however the product names and prices are not correct they all show the same names and price.

    5. This is where i think my issue is, however you can guide me.

    partial void CreateInvoice_Execute()
                // Write your code here.
                Func<decimal, string> formatPrice = (decimal x) => { return string.Format("{0:c}", x); };

                Func<string, string> formatTitle = (string x) => { return x.ToUpper(); };

                Func<int, string> formatCategory = (int x) =>
                    switch (x)
                        case 0:
                            return "COM+";
                        case 1:
                            return "LightSwitch";
                        case 2:
                            return "VB6";
                            return "Other";

                Func<DateTime, string> formatDate = (System.DateTime x) => { return string.Format("{0:d}", x); };
                //Book fields = Content Controls (See BookReport.docx)
                List<ColumnMapping> mapContent = new List<ColumnMapping>();
                mapContent.Add(new ColumnMapping("sale_name", "sale_name"));
                mapContent.Add(new ColumnMapping("Sale_invoice_number", "Sale_invoice_number"));

                //Book reviews (collection) = Bookmarked Tables
                List<ColumnMapping> mapTable = new List<ColumnMapping>();
                mapTable.Add(new ColumnMapping("Sale_invoice_quantity", "Sale_invoice_quantity"));
                mapTable.Add(new ColumnMapping("Product_name", "Product_name", this.SaleInvoiceDetail.SelectedItem.Products.Product_name));
                mapTable.Add(new ColumnMapping("product_selling_price", "product_selling_price", this.SaleInvoiceDetail.SelectedItem.Products.product_selling_price));

                dynamic doc = Word.GenerateDocument(this.Application.WordReportDocument, this.SaleInvoices.SelectedItem, mapContent);
                Word.Export(doc, "InvoiceDetailsTable", 2, false, this.SaleInvoices.SelectedItem.SaleInvoiceDetail, mapTable);

                    Word.SaveAsPDF(doc, this.Application.MyDocsLocation + "\\BookReport.pdf", true);

    Ok so as you can see there is an issue with this line

    Word.Export(doc, "InvoiceDetailsTable", 2, false, this.SaleInvoices.SelectedItem.SaleInvoiceDetail, mapTable);

    I need to get the SaleInvoiceDetail Products, what happens is that the SaleInvoices has SaleInvoiceDetail, i created SaleInvoiceDetail to show the products needed, as well as cover some calculations. However SaleInvoices also has a relationship with products, which now renders the first product chosen instead of rendering the results of the SaleInvoiceDetail.

    I would like to make sure that the invoice template has all product names from SaleInvoiceDetail and prices. The issue is that i need to do something like this that would work, this does not work however it will give you an example of what im looking for.

    Word.Export(doc, "InvoiceDetailsTable", 2, false, this.SaleInvoices.SelectedItem.SaleInvoiceDetail.Products, mapTable);

    I get an error when i try to debug this. Any other ways to map the products from SaleInvoiceDetails to the columns i created with word template table mapping?

    Kind regards, please view image Above

    • Edited by Kernelmeyer Thursday, March 20, 2014 7:15 AM image illustration
    Tuesday, March 18, 2014 12:38 PM