Imports Microsoft.VisualBasic
Imports System
Imports System.Diagnostics
Imports System.IO
Imports System.Linq
Imports System.Windows
Imports System.Windows.Forms
Imports Telerik.Windows.Documents.Flow.FormatProviders.Docx
Imports Telerik.Windows.Documents.Flow.Model
Imports Telerik.Windows.Documents.Flow.Model.Editing
Imports Telerik.Windows.Documents.Flow.Model.Lists
Imports Telerik.Windows.Documents.Flow.Model.Shapes
Imports Telerik.Windows.Documents.Flow.Model.Styles
Imports Telerik.Windows.Documents.Media
Imports Telerik.Windows.Documents.Model
Imports Telerik.Windows.Documents.Spreadsheet.Model
Imports WordsProcessingBlogPart1.Properties

Namespace WordsProcessingBlogPart1
	Public Partial Class Form1
		Inherits Form
		Public Sub New()
			InitializeComponent()
		End Sub

		Private Sub radButton1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles radButton1.Click
'			#Region "Document"

			Dim document As RadFlowDocument = New RadFlowDocument()
			Dim editor As RadFlowDocumentEditor = New RadFlowDocumentEditor(document)

			Dim section As Section = New Telerik.Windows.Documents.Flow.Model.Section(document)
			document.Sections.Add(section)

			section.PageMargins = New Telerik.Windows.Documents.Primitives.Padding(40, 10, 40, 10)
			section.PageSize = PaperTypeConverter.ToSize(PaperTypes.A4) 'WindowsBase assembly should be referenced.

'			#End Region

'			#Region "Header"

			Dim defaultHeader As Header = document.Sections.First().Headers.Add()

			Dim defaultHeaderParagraph As Paragraph = defaultHeader.Blocks.AddParagraph()
			defaultHeaderParagraph.TextAlignment = Alignment.Left

			Dim title As Run = defaultHeaderParagraph.Inlines.AddRun("Job Openings")
			title.FontSize = 27
			'the presentation core assembly references required for the following properties.
			title.ForegroundColor = New ThemableColor(System.Windows.Media.Colors.DarkBlue)
			title.FontFamily = New ThemableFontFamily("Felix Titling")

			Dim logo As FloatingImage = defaultHeaderParagraph.Inlines.AddFloatingImage()
			Using ms As MemoryStream = New MemoryStream()
                Resources.logo.Save(ms, System.Drawing.Imaging.ImageFormat.Png)
				logo.Image.ImageSource = New ImageSource(ms, "png")
			End Using
			logo.Image.Width = 200
			logo.Image.Height = 72

			logo.HorizontalPosition.ValueType = PositionValueType.Alignment
			logo.VerticalPosition.ValueType = PositionValueType.Alignment

			logo.VerticalPosition.Alignment = RelativeVerticalAlignment.Top
			logo.HorizontalPosition.Alignment = RelativeHorizontalAlignment.Right

'			#End Region

'			#Region "List"

			Dim list As List = New List()

			document.Lists.Add(list)

			list.Levels(0).StartIndex = 1
			list.Levels(0).NumberingStyle = NumberingStyle.Decimal
			list.Levels(0).NumberTextFormat = 1 & "."

			list.Levels(1).StartIndex = 1
			list.Levels(1).NumberingStyle = NumberingStyle.Decimal
			list.Levels(1).NumberTextFormat = 2 & "."

			list.Levels(2).StartIndex = 1
			list.Levels(2).NumberingStyle = NumberingStyle.Decimal
			list.Levels(2).NumberTextFormat = 3 & "."

			list.Levels(3).NumberingStyle = NumberingStyle.None
			list.Levels(3).NumberTextFormat = ""
			list.Levels(3).ParagraphProperties.LeftIndent.LocalValue = 48

			list.Levels(4).NumberingStyle = NumberingStyle.Bullet
			list.Levels(4).NumberTextFormat = "o"
			list.Levels(4).ParagraphProperties.LeftIndent.LocalValue = 48

'			#End Region

'			#Region "Item 1"

			Dim posIdentificationParagraph As Paragraph = section.Blocks.AddParagraph()
			Dim posIdentificationListItem As Run = posIdentificationParagraph.Inlines.AddRun("Position Identification")
			posIdentificationListItem.FontWeight = FontWeights.Bold
			posIdentificationParagraph.ListId = list.Id
			posIdentificationParagraph.ListLevel = 0

			Dim posIdentificationTable As Table = New Table(document)
			posIdentificationTable.Indent = 60

			section.Blocks.Add(posIdentificationTable)

			Dim i As Integer = 0
			Do While i < tableData.GetLength(0)
				Dim row As TableRow = posIdentificationTable.Rows.AddTableRow()

				Dim j As Integer = 0
				Do While j < tableData.GetLength(1)
					Dim cell As TableCell = row.Cells.AddTableCell()
					cell.Blocks.AddParagraph().Inlines.AddRun(tableData(i, j))
					cell.PreferredWidth = New TableWidthUnit(200)
					j += 1
				Loop
				i += 1
			Loop

'			#End Region

'			#Region "Item 2"

			Dim posDescriptionTitle As Paragraph = section.Blocks.AddParagraph()
			Dim posDescriptionItem = posDescriptionTitle.Inlines.AddRun("Position description")

			posDescriptionItem.FontWeight = FontWeights.Bold
			posDescriptionTitle.ListId = list.Id
			posDescriptionTitle.ListLevel = 1

			Dim posDescriptionText As Paragraph = section.Blocks.AddParagraph()
			Dim posDescriptionTextPart1 = posDescriptionText.Inlines.AddRun(desripionPart1)

			editor.MoveToInlineEnd(posDescriptionTextPart1)
			editor.InsertHyperlink("Sitefinity CMS", "http://www.sitefinity.com/", False, "Sitefinity official site")

			posDescriptionText.Inlines.AddRun(desripionPart2)
			posDescriptionText.ListId = list.Id
			posDescriptionText.ListLevel = 3

'			#End Region

'			#Region "Item 3"

			Dim competenciesRequiredText As Paragraph = section.Blocks.AddParagraph()
			Dim competenciesRequiredItem As Run = competenciesRequiredText.Inlines.AddRun("Competencies required")
			competenciesRequiredItem.FontWeight = FontWeights.Bold
			competenciesRequiredText.ListId = list.Id
			competenciesRequiredText.ListLevel = 2

			i = 0
			Do While i < competencies.Length
				Dim itemText As Paragraph = section.Blocks.AddParagraph()
				itemText.Inlines.AddRun(competencies(i))
				itemText.ListId = list.Id
				itemText.ListLevel = 4
				i += 1
			Loop

'			#End Region

'			#Region "Export "
			Using output As Stream = New FileStream("..\..\output.docx", FileMode.Create)
				Dim provider As DocxFormatProvider = New DocxFormatProvider()
				provider.Export(document, output)
			End Using

'			#End Region

			Process.Start("..\..\output.docx")
			radLabel1.Text = "File saved to: " & Path.GetFullPath("..\..\output.docx")
		End Sub
		#Region "data"
		Private desripionPart1 As String = "Telerik is currently seeking a detail oriented Technical Support Officer to join our "
		Private desripionPart2 As String = " team in Sofia, Bulgaria. The Technical Support Officer will communicate directly with customers as well as serve as a technical resource for members of the sales team by addressing client’s complex technical inquiries." & ControlChars.CrLf & " Relying on your background with ASP.NET / Web technologies and past experiences in client facing roles, your main duty will be to provide timely support to customers and members of the sales team over the phone, our online ticketing system, or email. You will need to analyze, track and resolve customer’s technical problems in a considerate and professional manner, and communicate closely with the appropriate development team. " & ControlChars.CrLf & "The ideal candidate will be able to quickly solve problems that involve a broad range of technical skills with an emphasis on the ASP.NET Framework and experience with CMS products such as Telerik’s Sitefinity ASP.NET CMS. You will be dealing mainly with developers and should be speaking with them on highly technical topics." & ControlChars.CrLf & ""
		Private competencies As String() = New String() { "Technical background in ASP.NET Microsoft platform (WebForms and MVC)", "Programming experience with LINQ, C#, and JavaScript", "Experience with HTML and CSS", "Experience with Networks, Hosting environments, IIS", "Experience with Microsoft SQL Server 2008/2012 is a plus", "Experience with ORM Framework is a plus", "Previous professional experience on a technical support related position", "Bachelor's degree in Computer Science or relevant field", "Exceptional problem-solving skills", "Exceptional ability to learn new skills", "Excellent communication skills: listening, written and verbal", "Strong work ethics and time management skills" }

		Private tableData As String(,) = New String(, ) { { "Title", "Technical Support Officer" }, { "Functional area", "Sitefinity CMS" }, { "Reports to", "Sitefinity Team Leader" }, { "Employment status", "Full-time job" } }
		#End Region
	End Class
End Namespace