Beispiel #1
0
        // Fourth stage. For each Order ID create a detailed document that will be inserted in place of the DOCVARIABLE field.
        // This is the final stage and the Product.Orders template does not contain DOCVARIABLE fields. So, further processing is not required.
        void richServerDetail_CalculateDocumentVariable(object sender, CalculateDocumentVariableEventArgs e)
        {
            int currentProductID = GetID(e.Arguments[0].Value);

            if (currentProductID == -1)
            {
                return;
            }

            if (productID != currentProductID)
            {
                // Get data source that contains orders for the specified product.
                // The data source is obtained from the data already filtered by supplier.
                dataDetailedForOrders = GetOrderDataFilteredbyProductAndSupplier(currentProductID);
                productID             = currentProductID;
            }

            if (e.VariableName == "OrderDetails")
            {
                RichEditDocumentServer richServerDetailDetail = new RichEditDocumentServer();
                MailMergeOptions       options = ordersRichEdit.CreateMailMergeOptions();
                options.DataSource = dataDetailedForOrders;
                options.MergeMode  = MergeMode.JoinTables;
                ordersRichEdit.MailMerge(options, richServerDetailDetail);
                e.Value   = richServerDetailDetail;
                e.Handled = true;
            }
        }
        // Fourth stage. For each Order ID create a detailed document that will be inserted in place of the DOCVARIABLE field.
        // This is the final stage and the Product.Orders template does not contain DOCVARIABLE fields. So, further processing is not required.
        void richServerDetailProcessor_CalculateDocumentVariable(object sender, CalculateDocumentVariableEventArgs e)
        {
            int currentProductID = GetID(e.Arguments[0].Value);

            if (currentProductID == -1)
            {
                return;
            }

            if (productID != currentProductID)
            {
                // Get data source that contains orders for the specified product and supplier.
                dataDetailedForOrders = (List <OrderDetail>)GetOrderDataFilteredbyProductAndSupplier(supplierID, currentProductID);
                productID             = currentProductID;
            }

            if (e.VariableName == "OrderDetails")
            {
                IRichEditDocumentServer richServerOrdersTemplate = mainRichEdit.CreateDocumentServer();
                RtfLoadHelper.Load("detaildetail.rtf", richServerOrdersTemplate);
                richServerOrdersTemplate.Options.MailMerge.DataSource = dataDetailedForOrders;

                IRichEditDocumentServer richServerDetailDetailProcessor = mainRichEdit.CreateDocumentServer();

                MailMergeOptions options = richServerOrdersTemplate.CreateMailMergeOptions();
                options.MergeMode = MergeMode.JoinTables;

                richServerOrdersTemplate.MailMerge(options, richServerDetailDetailProcessor);

                e.Value   = richServerDetailDetailProcessor;
                e.Handled = true;
            }
        }
        void eventHandler_CalculateDocumentVariable(object sender, CalculateDocumentVariableEventArgs e)
        {
            string location = e.Arguments[0].Value.ToString();

            Console.WriteLine(e.VariableName + " " + location);

            if ((location.Trim() == String.Empty) || (location.Contains("<")))
            {
                e.Value   = " ";
                e.Handled = true;
                return;
            }

            switch (e.VariableName)
            {
            //case "Weather":
            //    Conditions conditions = new Conditions();
            //    conditions = Weather.GetCurrentConditions(location);
            //    e.Value = String.Format("Forecast for {0}: \nConditions: {1}\nTemperature (C) :{2}\nHumidity: {3}\nWind: {4}\n",
            //        conditions.City, conditions.Condition, conditions.TempC, conditions.Humidity, conditions.Wind);
            //    break;
            case "Location":
                GeoLocation[] loc = GeoLocation.GeocodeAddress(location);
                e.Value = String.Format(" {0}\nLatitude: {1}\nLongitude: {2}\n",
                                        loc[0].Address, loc[0].Latitude.ToString(), loc[0].Longitude.ToString());
                break;
            }
            e.Handled = true;
        }
        private void ResultRichEdit_CalculateDocumentVariable(object sender, CalculateDocumentVariableEventArgs e)
        {
            //Check whether the event is raised to the required field:
            if (e.VariableName == "Categories")
            {
                //Provide the data source for the next document part:
                masterRichEdit.Options.MailMerge.DataSource = categories;

                //Create a new RichEditDocumentServer for further processing:
                IRichEditDocumentServer result = masterRichEdit.CreateDocumentServer();

                //Subscribe the new instance to the CalculateDocumentVariable event to handle the detail part:
                result.CalculateDocumentVariable += result_CalculateDocumentVariable;

                //Set additional mail merge options if necessary:
                MailMergeOptions options = masterRichEdit.CreateMailMergeOptions();
                options.LastRecordIndex = 4;

                //Merge the document and pass it to the RichEditDocumentServer:
                masterRichEdit.MailMerge(options, result.Document);
                result.CalculateDocumentVariable -= result_CalculateDocumentVariable;

                e.Value   = result;
                e.Handled = true;
            }
        }
        private void richEditControl1_CalculateDocumentVariable(object sender, CalculateDocumentVariableEventArgs e)
        {
            e.Value = e.VariableName + "'s value";

            if (e.Arguments.Count > 0)
            {
                e.Value += string.Format(" (first argument: {0})", e.Arguments[0].Value);
            }

            e.Handled = true;
        }
Beispiel #6
0
 private static void WordProcessor_CalculateDocumentVariable(object sender, CalculateDocumentVariableEventArgs e)
 {
     if (e.VariableName == "rssFeed")
     {
         e.KeepLastParagraph = true;
         e.Value             = GenerateRssFeed();
         if (e.Value != null)
         {
             e.Handled = true;
         }
         e.FieldLocked = true;
     }
 }
        void result_CalculateDocumentVariable(object sender, CalculateDocumentVariableEventArgs e)
        {
            ArgumentCollection arguments = e.Arguments;
            int currentCategoryID        = GetID(arguments[0].Value);

            if (currentCategoryID == -1)
            {
                return;
            }
            if (categoryID != currentCategoryID)
            {
                currentDataSetProducts = GetData(currentCategoryID).ToList();
                categoryID             = currentCategoryID;
            }

            if (e.VariableName == "Products")
            {
                detailRichEditControl.Options.MailMerge.DataSource = currentDataSetProducts;

                IRichEditDocumentServer result = detailRichEditControl.CreateDocumentServer();

                MailMergeOptions options = detailRichEditControl.CreateMailMergeOptions();
                options.MergeMode = MergeMode.JoinTables;
                result.CalculateDocumentVariable += detail_CalculateDocumentVariable;
                detailRichEditControl.MailMerge(options, result.Document);
                result.CalculateDocumentVariable -= detail_CalculateDocumentVariable;

                e.Value   = result;
                e.Handled = true;
            }
            if (e.VariableName == "LowestPrice")
            {
                e.Value   = currentDataSetProducts.Min(p => p.UnitPrice);
                e.Handled = true;
            }
            if (e.VariableName == "HighestPrice")
            {
                e.Value   = currentDataSetProducts.Max(p => p.UnitPrice);
                e.Handled = true;
            }
            if (e.VariableName == "ItemsCount")
            {
                e.Value   = currentDataSetProducts.Count();
                e.Handled = true;
            }
            if (e.VariableName == "TotalSales")
            {
                e.Value   = GetTotalSales(arguments);
                e.Handled = true;
            }
        }
        void resultingRichEditControl_CalculateDocumentVariable(object sender, CalculateDocumentVariableEventArgs e)
        {
            if (e.VariableName == "Categories")
            {
                masterRichEditControl.Options.MailMerge.DataSource = dataSetCategories.ToList();

                IRichEditDocumentServer result = masterRichEditControl.CreateDocumentServer();
                result.CalculateDocumentVariable += result_CalculateDocumentVariable;
                masterRichEditControl.MailMerge(result.Document);
                result.CalculateDocumentVariable -= result_CalculateDocumentVariable;

                e.Value   = result;
                e.Handled = true;
            }
        }
            public static void OnCalculateDocumentVariable(object sender, CalculateDocumentVariableEventArgs e)
            {
                if (e.Arguments.Count == 0 || e.VariableName != "CustomProperty")
                {
                    return;
                }

                string name           = e.Arguments[0].Value;
                object customProperty = ((RichEditDocumentServer)sender).Document.CustomProperties[name];

                if (customProperty != null)
                {
                    e.Value = customProperty.ToString();
                }
                e.Handled = true;
            }
        void server_CalculateDocumentVariable(object sender, CalculateDocumentVariableEventArgs e)
        {
            if (e.VariableName == "Prod")
            {
                int productId = -1;

                if (Int32.TryParse(e.Arguments[0].Value, out productId))
                {
                    DataRow row          = ((DataTable)richEditControl1.Options.MailMerge.DataSource).Rows.Find(productId);
                    int     unitsInStock = Convert.ToInt32(row[e.Arguments[1].Value]);
                    decimal unitPrice    = Convert.ToDecimal(row[e.Arguments[2].Value]);

                    e.Value   = unitsInStock * unitPrice;
                    e.Handled = true;
                }
            }
        }
        void detail_CalculateDocumentVariable(object sender, CalculateDocumentVariableEventArgs e)
        {
            int productId = GetID(e.Arguments[0].Value);

            if (productId == -1)
            {
                return;
            }

            //Format the UnitPrice field:
            if (e.VariableName == "UnitPrice")
            {
                string expression = String.Format("ProductID = {0}", productId);
                e.Value   = String.Format(cultureInfo, "{0:C2}", products.Select(expression)[0]["UnitPrice"]);
                e.Handled = true;
            }
        }
        private void result_CalculateDocumentVariable(object sender, CalculateDocumentVariableEventArgs e)
        {
            //Check whether the event is raised for the required field:
            if (e.VariableName == "Products")
            {
                //Provide the detail part with the data source:
                detailRichEdit.Options.MailMerge.DataSource = products;

                //Create an intermediate document server instance:
                IRichEditDocumentServer result = detailRichEdit.CreateDocumentServer();

                //Set the merged ranges delimitation and a number of records to be merged:
                MailMergeOptions options = detailRichEdit.CreateMailMergeOptions();
                options.MergeMode       = MergeMode.JoinTables;
                options.LastRecordIndex = 10;

                //Provide a procedure for further processing:
                result.CalculateDocumentVariable += detail_CalculateDocumentVariable;

                // Create a merged document with a detail template:
                detailRichEdit.MailMerge(options, result.Document);
                result.CalculateDocumentVariable -= detail_CalculateDocumentVariable;

                e.Value   = result;
                e.Handled = true;
            }


            //Format other merged fields:
            if (e.VariableName == "LowestPrice")
            {
                e.Value   = String.Format(cultureInfo, "{0:C2}", products.Compute("Min(UnitPrice)", String.Empty));
                e.Handled = true;
            }
            if (e.VariableName == "HighestPrice")
            {
                e.Value   = String.Format(cultureInfo, "{0:C2}", products.Compute("Max(UnitPrice)", String.Empty));
                e.Handled = true;
            }
            if (e.VariableName == "ItemsCount")
            {
                e.Value   = products.Rows.Count;
                e.Handled = true;
            }
        }
Beispiel #13
0
        void richEditResult_CalculateDocumentVariable(object sender, CalculateDocumentVariableEventArgs e)
        {
            int categoryId = -1;

            if (Int32.TryParse(e.Arguments[0].Value, out categoryId))
            {
                richEditProductTemplate.Options.MailMerge.DataSource = NorthwindDataProvider.GetProductsByCategoryId(categoryId);

                RichEditDocumentServer documentServerProducts = new RichEditDocumentServer();
                MailMergeOptions       mailMergeOptions       = richEditProductTemplate.CreateMailMergeOptions();
                mailMergeOptions.MergeMode = MergeMode.JoinTables;

                richEditProductTemplate.MailMerge(mailMergeOptions, documentServerProducts);

                e.Value   = documentServerProducts;
                e.Handled = true;
            }
        }
Beispiel #14
0
 // Second stage. For each Supplier ID create a detailed document that will be inserted in place of the DOCVARIABLE field.
 void resultRichEdit_CalculateDocumentVariable(object sender, CalculateDocumentVariableEventArgs e)
 {
     if (e.VariableName == "Supplier")
     {
         // Create a text engine to process a document after the mail merge.
         RichEditDocumentServer richServerMaster = new RichEditDocumentServer();
         // Provide a procedure for further processing
         richServerMaster.CalculateDocumentVariable += richServerMaster_CalculateDocumentVariable;
         // Create a merged document using the Supplier template. The document will contain DOCVARIABLE fields with ProductID arguments.
         // The CalculateDocumentVariable event for the richServerMaster fires.
         suppllierRichEdit.MailMerge(richServerMaster);
         richServerMaster.CalculateDocumentVariable -= richServerMaster_CalculateDocumentVariable;
         // Return the document to insert.
         e.Value = richServerMaster;
         // Required to use e.Value. Otherwise it will be ignored.
         e.Handled = true;
     }
 }
Beispiel #15
0
 void OnCalculateDocumentVariable(object sender, CalculateDocumentVariableEventArgs e)
 {
     if (Order == null || e.VariableName != "Products")
     {
         return;
     }
     using (var server = new RichEditDocumentServer()) {
         using (var stream = MailMergeTemplatesHelper.GetTemplateStream("Sales Order Follow-Up Detail.rtf")) {
             server.LoadDocument(stream, DocumentFormat.Rtf);
             var options = server.CreateMailMergeOptions();
             options.DataSource = Order.OrderItems;
             server.MailMerge(options, detailTemplate.Document);
         }
     }
     e.Value             = detailTemplate;
     e.KeepLastParagraph = true;
     e.Handled           = true;
 }
        // Third stage. For each Product ID create a detailed document that will be inserted in place of the DOCVARIABLE field.
        void richServerMasterProcessor_CalculateDocumentVariable(object sender, CalculateDocumentVariableEventArgs e)
        {
            int currentSupplierID = GetID(e.Arguments[0].Value);

            if (currentSupplierID == -1)
            {
                return;
            }

            if (supplierID != currentSupplierID)
            {
                // Get data source that contains products for the specified supplier.
                dataDetailedForProducts = (List <Product>)GetProductsDataFilteredbySupplier(currentSupplierID);
                supplierID = currentSupplierID;
            }

            if (e.VariableName == "Product")
            {
                // Create a document container and load a document containing the Product header section (detail section)
                IRichEditDocumentServer richServerProductsTemplate = mainRichEdit.CreateDocumentServer();
                RtfLoadHelper.Load("detail.rtf", richServerProductsTemplate);
                // Create a text engine to process a document after the mail merge.
                IRichEditDocumentServer richServerDetailProcessor = mainRichEdit.CreateDocumentServer();

                // Specify data source for mail merge.
                richServerProductsTemplate.Options.MailMerge.DataSource = dataDetailedForProducts;
                // Specify that the resulting table should be joined with the header table.
                // Do not specify this option if calculated fields are not within table cells.
                MailMergeOptions options = richServerProductsTemplate.CreateMailMergeOptions();
                options.MergeMode = MergeMode.JoinTables;
                // Provide a procedure for further processing.
                richServerDetailProcessor.CalculateDocumentVariable += new CalculateDocumentVariableEventHandler(richServerDetailProcessor_CalculateDocumentVariable);
                // Create a merged document using the Product template. The document will contain DOCVARIABLE fields with OrderID arguments.
                // The CalculateDocumentVariable event for the richServerDetail fires.
                richServerProductsTemplate.MailMerge(options, richServerDetailProcessor);
                richServerDetailProcessor.CalculateDocumentVariable -= richServerDetailProcessor_CalculateDocumentVariable;
                // Return the document to insert.
                e.Value = richServerDetailProcessor;
                // This setting is required for inserting e.Value into the source document. Otherwise it will be ignored.
                e.Handled = true;
            }
        }
Beispiel #17
0
        private static void Document_CalculateDocumentVariable(object sender, CalculateDocumentVariableEventArgs e)
        {
            if (e.Arguments.Count > 0)
            {
                string location = e.Arguments[0].Value.ToString();
                if ((location.Trim() == String.Empty) || (location.Contains("<")))
                {
                    e.Value   = " ";
                    e.Handled = true;
                    return;
                }
                switch (e.VariableName)
                {
                case "Weather":
                    Conditions conditions = new Conditions();
                    conditions = Weather.GetCurrentConditions(location);
                    e.Value    = String.Format("Weather for {0}: \nConditions: {1}\nTemperature (C) :{2}\nHumidity: {3}\nWind: {4}\n",
                                               location, conditions.Condition, conditions.TempC, conditions.Humidity, conditions.Wind);
                    break;

                case "LOCATION":
                    if (location == "DO NOT CHANGE!")
                    {
                        e.Value = DocVariableValue.Current;
                    }
                    break;

                default:
                    e.Value = "LOCKED FIELD UPDATED";
                    break;
                }
            }
            else
            {
                e.Value = "LOCKED FIELD UPDATED";
            }
            e.Handled = true;
        }
Beispiel #18
0
    protected void DemoRichEdit_CalculateDocumentVariable(object sender, CalculateDocumentVariableEventArgs e)
    {
        switch (e.VariableName)
        {
        case "Chart":
            var sales = GetSales(e.Arguments[0].Value);
            DocumentImageSource    chart = DocumentImageSource.FromStream(CreateChart(sales));
            RichEditDocumentServer srv   = new RichEditDocumentServer();
            srv.Document.Images.Append(chart);
            e.Value   = srv.Document;
            e.Handled = true;
            break;

        case "CommonSales":
            var commonSales = GetCommonSales(e.Arguments[0].Value);
            e.Value   = commonSales.ToString("C");
            e.Handled = true;
            break;

        default:
            break;
        }
    }
 // Second stage. For each Supplier ID create a detailed document that will be inserted in place of the DOCVARIABLE field.
 void resultRichEdit_CalculateDocumentVariable(object sender, CalculateDocumentVariableEventArgs e)
 {
     if (e.VariableName == "Supplier")
     {
         // Create a document container and load a document containing the Supplier header section (master section)
         IRichEditDocumentServer richServerSupplierTemplate = mainRichEdit.CreateDocumentServer();
         RtfLoadHelper.Load("supplier.rtf", richServerSupplierTemplate);
         // Create a text engine to process a document after the mail merge.
         IRichEditDocumentServer richServerMasterProcessor = mainRichEdit.CreateDocumentServer();
         // Provide a procedure for further processing
         richServerMasterProcessor.CalculateDocumentVariable += new CalculateDocumentVariableEventHandler(richServerMasterProcessor_CalculateDocumentVariable);
         // Create a merged document using the Supplier template. The document will contain DOCVARIABLE fields with ProductID arguments.
         // The CalculateDocumentVariable event for the richServerMasterProcessor fires.
         // Note that the data source for mail merge should be specified via the RichEditDocumentServer.Options.MailMerge.DataSource property.
         richServerSupplierTemplate.Options.MailMerge.DataSource = dataSuppliers;
         richServerSupplierTemplate.MailMerge(richServerMasterProcessor.Document);
         richServerMasterProcessor.CalculateDocumentVariable -= richServerMasterProcessor_CalculateDocumentVariable;
         // Return the document to insert in place of the DOCVARIABLE field.
         e.Value = richServerMasterProcessor;
         // Required. Otherwise e.Value will be ignored.
         e.Handled = true;
     }
 }
        protected internal virtual void detail_CalculateDocumentVariable(object sender, CalculateDocumentVariableEventArgs e)
        {
            int productId = GetID(e.Arguments[0].Value);

            if (productId == -1)
            {
                return;
            }
            if (e.VariableName == "UnitPrice")
            {
                e.Value   = GetUnitPrice(e.Arguments);
                e.Handled = true;
            }
        }