Imports SautinSoft.HtmlToRtf
Imports System.IO
Public Class frmDetail

    Private Sub tbrSave_Click(sender As System.Object, e As System.EventArgs) Handles tbrSave.Click
        Me.rtbDoc.SaveFile("h:\tssettings\eintrag" + Microsoft.VisualBasic.Right(Me.TreeView2.SelectedNode.Text, 1) + ".rtf")

    End Sub

    Private Sub TreeView2_AfterSelect(sender As System.Object, e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView2.AfterSelect
        Me.rtbDoc.Clear()
        Me.rtbDoc.Visible = True
        Me.Panel1.Visible = False
        Me.rtbDoc.Dock = DockStyle.Fill
        Me.Panel2.Dock = DockStyle.Fill
        Try
            Me.rtbDoc.LoadFile("h:\tssettings\eintrag" + Microsoft.VisualBasic.Right(Me.TreeView2.SelectedNode.Text, 1) + ".rtf")
        Catch
        End Try
    End Sub

    Private Sub ÜbersichtToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles ÜbersichtToolStripMenuItem.Click
        Dim x As New ToolStrip
        x = ToolStrip9
        Me.rtbDoc.Visible = False
        Me.Panel1.Dock = DockStyle.Fill
        Me.Panel1.Visible = True
        Panel1.Controls.Clear()
        Panel1.Controls.Add(x)
        For i = 9 To 1 Step -1
            Try
                Dim rb As New RichTextBox
                rb.LoadFile("h:\tssettings\Eintrag" + Trim(i.ToString) + ".rtf")
                rb.Height = 80
                rb.Dock = DockStyle.Top
                rb.ReadOnly = True
                AddHandler rb.DoubleClick, AddressOf rb_dblClick
                Panel1.Controls.Add(rb)
                Dim l As New Label
            Catch
            End Try

        Next

    End Sub

    Private Sub rb_dblClick(sender As Object, e As System.EventArgs)
        Me.Panel1.Visible = False
        Me.rtbDoc.Visible = True
        Me.rtbDoc.Dock = DockStyle.Fill
        Me.Panel2.Dock = DockStyle.Fill
        Me.TreeView2.SelectedNode = TreeView2.Nodes(0)
    End Sub



    Private Sub frmDetail_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Me.TreeView2.Nodes.Clear()
        For i = 1 To 9
            Me.TreeView2.Nodes.Add("Eintrag" + i.ToString)
        Next
    End Sub

    Private Sub AllesToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles AllesToolStripMenuItem.Click

        'Dim rb As New RichTextBox
        'Dim rb1 As New RichTextBox
        'Me.Panel1.Controls.Clear()

        'For i = 9 To 1 Step -1
        '    Try
        '        rb1.LoadFile("h:\tssettings\Eintrag" + Trim(i.ToString) + ".rtf")
        '        'rb = AppendRTF(rb1, rb1.Rtf)
        '        rb.SelectionStart = 0
        '        rb.SelectionLength = 0
        '        rb1.SelectAll()
        '        rb.Rtf = rb.Rtf + rb1.Rtf
        '        '                rb1.SelectAll()
        '        '               My.Computer.Clipboard.SetText(rb1.SelectedRtf)
        '        '              rb.Rtf += My.Computer.Clipboard.GetText
        '    Catch
        '    End Try

        'Next
        'Me.Panel1.Controls.Add(rb)
        'rb.Dock = DockStyle.Fill
        Dim h As New SautinSoft.HtmlToRtf

        Dim firstRtf As String = ""
        Dim Delimitter As String = ""
        Dim secondRtf As String = ""
        Dim singleRtf As String = ""

        singleRtf = ReadFromFile("h:\tssettings\empty.rtf")
        Delimitter = ReadFromFile("h:\tssettings\delimitter.rtf")
        For i = 1 To 9
            Try
                secondRtf = ReadFromFile("h:\tssettings\Eintrag" + Trim(i.ToString) + ".rtf")
                singleRtf = h.MergeRtfString(singleRtf, secondRtf)
                singleRtf = h.MergeRtfString(singleRtf, Delimitter)
            Catch
            End Try

        Next
        Dim x As New ToolStrip
        x = ToolStrip9
        Me.Panel1.Controls.Clear()
        Panel1.Controls.Add(x)
        Dim rb As New RichTextBox
        rb.Rtf = singleRtf
        Me.Panel1.Controls.Add(rb)
        rb.Dock = DockStyle.Fill
        Me.Panel1.Visible = True
        Me.Panel1.Dock = DockStyle.Fill
        Me.rtbDoc.Visible = False

    End Sub


    Public Function ReadFromFile(ByVal fileName As String) As String

        Dim fileString As String = ""
        Try
            Dim fs As System.IO.FileStream = New FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read)
            Dim b(CInt(Fix(fs.Length)) - 1) As Byte
            If fs.Read(b, 0, CInt(Fix(fs.Length))) > 0 Then
                Dim arCharRes(fs.Length - 1) As Char
                For i As Integer = 0 To fs.Length - 1
                    arCharRes(i) = ChrW(b(i))
                Next i
                fileString = New String(arCharRes)
            End If
            fs.Close()
            Return fileString
        Catch
            Return ""
        End Try
    End Function
    Public Function WriteToFile(ByVal fileName As String, ByVal fileStr As String) As Integer
        Try
            Dim sw As New StreamWriter(fileName, False)
            sw.Write(fileStr)
            sw.Close()
        Catch
            Return 2
        End Try
        Return 0
    End Function


    Private Sub ToolStripButton22_Click(sender As System.Object, e As System.EventArgs) Handles ToolStripButton22.Click
        ÜbersichtToolStripMenuItem_Click(sender, e)
    End Sub

    Private Sub ToolStripButton23_Click(sender As System.Object, e As System.EventArgs) Handles ToolStripButton23.Click
        AllesToolStripMenuItem_Click(sender, e)
    End Sub
End Class