Imports System.Net
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Documents
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Animation
Imports System.Windows.Shapes
Imports ComponentPro

Partial Public Class MainPage
    Inherits UserControl
    Public Sub New()
        InitializeComponent()

        txtTemplate.Text = "Dear $User.FullName$," & vbCrLf & "{%set orders=User.GetOrders() /}" & vbCrLf & "Thank you for your order of $orders.Length$ items, We believe you will be very satisfied with the quality of costume pieces included in each. It is this quality that makes our imaginative play apparel so unique." & vbCrLf & vbCrLf & "We created an account for you to track your orders. Here is the login information:" & vbCrLf & "Email: $User.EmailAddress$" & vbCrLf & "Password: $User.Password$" & vbCrLf & vbCrLf & "Following is the details of your order (OrderId: $OrderId$):" & vbCrLf & "#   Part ID    Name            Quantity     Price(per unit)       Sub Total" & vbCrLf & "{%set Total=0.0 /}{%foreach orderproduct,i in orders%}{%set Total = Total + orderproduct.Price * orderproduct.Quantity/}" & vbCrLf & "{%rendertemplate orderproducttemplate item=orderproduct/}{$foreach%}" & vbCrLf & "												                                               Total: $PadLeft(Format(Total,""$$#.##""),11)$" & vbCrLf & vbCrLf & "If you have any concern, please call us at 913-555-0115." & vbCrLf & vbCrLf & "Sincerely," & vbCrLf & vbCrLf & "$CompanyName$" & vbCrLf & "{%template orderproducttemplate%}$PadLeft(i,4)$$PadLeft(item.PartId, 7)$    $PadRight(item.ProductName, 15)$        $PadRight(item.Quantity, 5)$        $PadLeft(Format(item.Price,""$$#.##""), 7)$   $PadLeft(Format(item.Price*item.Quantity,""$$#.##""), 12)${$template%}"
    End Sub

    Private Sub btnGenerate_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        Dim dt As New TemplateEngine()

        dt.LoadFromString(txtTemplate.Text)
        ' Create an user defined object.
        Dim u As New User()
        u.EmailAddress = "myemail@somedomain.com"
        u.FullName = "John Borders"
        u.Password = "123abc"

        ' Assign variables.
        dt.SetValue("CompanyName", "My Company Name")
        dt.SetValue("User", u)
        dt.SetValue("OrderId", "1625DGHJ")

        txtOutput.Text = dt.Run()
    End Sub
End Class
