PageRenderTime 27ms CodeModel.GetById 14ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 1ms

/Forms/frmOutputLog.vb

#
Visual Basic | 120 lines | 87 code | 27 blank | 6 comment | 0 complexity | 7d33898453334923d3978cb189656dcf MD5 | raw file
  1Imports System.IO
  2Imports System.Text
  3
  4Public Class frmoutputlog
  5    Public output As String = ""
  6    Public FullViewOverride As Boolean = False
  7    Private Sub frmoutputlog_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  8        'Commented out by AnotherPhil as already done [after search for new movies] and if left causes endless processing...
  9        'Try
 10        '    ShowLog() 'call the subroutine to actually show the log when the form is created.
 11        'Catch ex As Exception
 12        '    ExceptionHandler.LogError(ex)
 13        'End Try
 14        If Pref.MultiMonitoEnabled Then
 15            Me.Bounds = Screen.AllScreens(Form1.CurrentScreen).Bounds
 16            Me.Width = 861
 17            Me.Height = 580
 18        End If
 19    End Sub
 20
 21    Public Sub New(ByVal displaystring As String, Optional ByVal forceoverride As Boolean = False, Optional ByVal FullView As Boolean = False)
 22
 23        InitializeComponent()
 24        Try
 25            If forceoverride = False Then
 26                Me.Close()
 27            End If
 28            output = displaystring
 29            FullViewOverride = fullview
 30
 31
 32        Catch ex As Exception
 33            ExceptionHandler.LogError(ex)
 34        End Try
 35    End Sub
 36
 37
 38    Private Sub btn_savelog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_savelog.Click
 39        Try 'this is the save button, it will save the displayed text (full or brief)
 40            Dim strFileName As String
 41
 42            With SaveFileDialog1
 43                .DefaultExt = "txt"
 44                .Filter = "Text Documents (*.txt)|*.txt|All Files(*.*)|*.*"
 45                .FilterIndex = 1
 46                .OverwritePrompt = True
 47                .Title = "Save Scraper Log Dialogue"
 48            End With
 49
 50            If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
 51                Try
 52                    strFileName = SaveFileDialog1.FileName
 53                    Dim file As StreamWriter
 54                    file = New StreamWriter(strFileName, False)
 55                    file.WriteLine(Now())
 56                    file.WriteLine()
 57                    file.Write(TextBox1.Text)
 58                    file.WriteLine()
 59                    file.Close()
 60                    MsgBox(strFileName & " Saved")
 61                Catch ex As Exception
 62                    MsgBox("Error" & vbCrLf & vbCrLf & ex.Message.ToString)
 63                End Try
 64            End If
 65
 66
 67        Catch ex As Exception
 68            ExceptionHandler.LogError(ex)
 69        End Try
 70    End Sub
 71
 72    Private Sub TextBox1_GotFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.GotFocus
 73        Try
 74            TextBox1.Select(TextBox1.Text.Length, 0) 'this removes the whole text being selected when the form is created
 75        Catch ex As Exception
 76            ExceptionHandler.LogError(ex)
 77        End Try
 78    End Sub
 79
 80    Private Sub ComboBoxLogViewType_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBoxLogViewType.SelectedIndexChanged
 81        ShowLog()
 82    End Sub
 83    Private Sub ShowLog()
 84
 85        TextBox1.Text = ""
 86
 87        Pref.logview = ComboBoxLogViewType.SelectedIndex
 88
 89        Dim builder As New StringBuilder
 90
 91        For Each line In output.Split(vbCrLf) 
 92
 93            line = Strings.Replace(line, Chr(10), "")
 94
 95            If IsNothing(line) Then Continue For
 96
 97            If line="!!!" Then
 98                builder.AppendLine
 99
100            ElseIf line.Contains("!!! ") Then 
101                builder.Append(Strings.Right(line, Strings.Len(line) - 4)).AppendLine
102
103            ElseIf (Pref.logview=0 OrElse FullViewOverride) Then          '0 = Full log view -> Append details
104                builder.Append(line).AppendLine
105            End If
106        Next
107
108        TextBox1.Text = builder.ToString
109    End Sub
110
111    Private Sub frmoutputlog_Shown( sender As System.Object,  e As System.EventArgs) Handles MyBase.Shown
112        ComboBoxLogViewType.SelectedIndex = Pref.logview 'set the combobox entry as per the preferences
113    End Sub
114
115    Private Sub frmoutputlog_KeyDown(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown 
116
117        If               e.KeyCode = Keys.Escape Then Me.Close() 
118    End Sub
119
120End Class