''
'' This code is part of Document Solutions for Word demos.
'' Copyright (c) MESCIUS inc. All rights reserved.
''
Imports System.IO
Imports System.Drawing
Imports System.Text
Imports System.Data
Imports System.Linq
Imports System.Globalization
Imports GrapeCity.Documents.Word
'' The code in this example loads a DOCX document (created in MS Word)
'' containing a report template, and depending on the selected demo,
'' either adds a data source and generates the data bound report,
'' or simply returns the unmodified template for reference.
Public Class DataTplUseCases
Public Function CreateDocx(ByRef sampleParams As String()) As GcWordDocument
Dim doc = New GcWordDocument()
'' Load the template DOCX
doc.Load(Path.Combine("Resources", "WordDocs", sampleParams(3)))
Using ds = New DataSet()
'' Load the data set:
ds.ReadXml(Path.Combine("Resources", "data", "DsWordTplDataSet.xml"))
'' Return the unmodified template document for reference
If sampleParams.Length >= 6 AndAlso sampleParams(5) = "template" Then
Return doc
End If
'' Add the data source to the data template data sources
If sampleParams.Length >= 5 AndAlso Not String.IsNullOrEmpty(sampleParams(4)) Then
doc.DataTemplate.DataSources.Add("ds", ds.Tables(sampleParams(4)))
Else
doc.DataTemplate.DataSources.Add("ds", ds)
End If
'' The document already has all the necessary bindings,
'' so we only need to process the data template:
doc.DataTemplate.Process(CultureInfo.GetCultureInfo("en-US"))
End Using
'' Done
Return doc
End Function
Public Function CreateDocx(Optional parsIdx As Integer = 0) As GcWordDocument
Return CreateDocx(GetSampleParamsList()(parsIdx))
End Function
Public Shared Function GetSampleParamsList() As List(Of String())
'' Mandatory: name, description, info
'' Custom: template DOCX [[, table] , "template"]
Return New List(Of String()) From
{
New String() {"@use-data-tpl/Lease Agreement", "Generate a lease agreement", Nothing,
"Lease_Agreement_Template.docx", "LeaseAgreement"},
New String() {"@use-data-tpl/Consulting Agreement", "Generate a consultancy agreement", Nothing,
"Consulting_Agreement_Template.docx", "ConsAgreement"},
New String() {"@use-data-tpl/Rental Agreement", "Generate a house rental agreement", Nothing,
"House_Rental_Template.docx", "HouseRentalAgreement"},
New String() {"@use-data-tpl/Employment Contract", "Generate an employment contract", Nothing,
"Employment_Contract_Template.docx", "EmploymentContract"},
New String() {"@use-data-tpl-src/Lease Agreement", "Template Lease_Agreement_Template.docx", Nothing,
"Lease_Agreement_Template.docx", Nothing, "template"},
New String() {"@use-data-tpl-src/Consulting Agreement", "Template Consulting_Agreement_Template.docx", Nothing,
"Consulting_Agreement_Template.docx", Nothing, "template"},
New String() {"@use-data-tpl-src/Rental Agreement", "Template House_Rental_Template.docx", Nothing,
"House_Rental_Template.docx", Nothing, "template"},
New String() {"@use-data-tpl-src/Employment Contract", "Template Employment_Contract_Template.docx", Nothing,
"Employment_Contract_Template.docx", Nothing, "template"},
New String() {"@use-data-tpl-src/Order Invoice", "Template InvoiceTemplate.docx", Nothing,
"InvoiceTemplate.docx", Nothing, "template"},
New String() {"@use-data-tpl-src/Closing Disclosure", "Template Closing_Disclosure_Template.docx", Nothing,
"Closing_Disclosure_Template.docx", Nothing, "template"},
New String() {"@use-data-tpl-src/Vacation Itinerary", "Template Vacation_Itinerary_Template.docx", Nothing,
"Vacation_Itinerary_Template.docx", Nothing, "template"}
}
End Function
End Class