Merge data from a table

Now, let’s create a program which will display data from a table.
We will use an HTML template for the program called WebProducts.html (right Click -> save link as)

  1. In Northwind, create a new BussinessProcess named "WebProcess"
  2. Add the Products table:
namespace Northwind
{
    public class WebProducts : BusinessProcessBase
    {
        public readonly Models.Products Products = new Models.Products();
        public WebProducts()
        {
            From = Products;
        }
        public void Run()
        {
            Execute();
        }
    }
} 
  1. Add WebWriter and TextTemplate objects and initiate them in the OnLoad method:
namespace Northwind
{
    public class WebProducts : BusinessProcessBase
    {
        public readonly Models.Products Products = new Models.Products();

        ENV.IO.WebWriter ioRequester;
        ENV.IO.TextTemplate htmlPage;
        
        public WebProducts()
        {
            From = Products;
        }
        public void Run()
        {
            Execute();
        }
        protected override void OnLoad()
        {
            ioRequester = new ENV.IO.WebWriter();
            htmlPage = new ENV.IO.TextTemplate(@"c:\WebProducts.html");
        }
    }
} 
  1. Add Streams object:
  protected override void OnLoad()
        {
            ioRequester = new ENV.IO.WebWriter();
            htmlPage = new ENV.IO.TextTemplate(@"c:\WebProducts.html");
            Streams.Add(ioRequester);
        } 
  1. Add the HTML tags:
  protected override void OnLoad()
        {
            ioRequester = new ENV.IO.WebWriter();
            htmlPage = new ENV.IO.TextTemplate(@"c:\WebProducts.html");

            htmlPage.Add(
                new Tag("ProductID", Products.ProductID),
                new Tag("ProductName", Products.ProductName)
                );

            Streams.Add(ioRequester);
        } 

The first parameter is the tag name inside the HTML template (case-sensitive) without the !$MG_ - <!$MG_ProductID>.
The second parameter is the value which will replace the tag during runtime.

  1. In the OnLeaveRow, Write the HTML page to the requester
        protected override void OnLeaveRow()
        {
             htmlPage.WriteTo(ioRequester);
        } 
  1. Add the program to ApplicationPrograms.cs:
namespace Northwind
{
    class ApplicationPrograms : ENV.ProgramCollection 
    {
        public ApplicationPrograms()
        {
            Add(3, "Show Customers", "", typeof(ShowCustomers));
            Add(4, "Show Products", "", typeof(ShowProducts));
            Add(5, "Show Orders", "", typeof(ShowOrders));
            Add(6, "Print - Order", "", typeof(Print_Order));
            Add(7, "Print - Orders", "", typeof(Print_Orders));
            Add("WebDemo", typeof(WebDemo));
            Add("WebProducts", typeof(WebProducts));           
        }
    }
} 
  1. In the project settings, based on the previous page, update the URL with the new public name:
    http://localhost:61988/Request.aspx?prgname=WebProducts

  2. Build and run (click "Google Chrome" or "Internet Explorer")


Help us improve, Edit this page on GitHub
or email us at info@fireflymigration.com