/Source Code/PowerSong/Reporting/frmReporting.vb
Visual Basic | 126 lines | 79 code | 34 blank | 13 comment | 0 complexity | 302a83b0f667f8743aba64a6cbadc97a MD5 | raw file
- Imports System.IO
-
- Public Class frmReporting
-
- Public Sub New()
-
- InitializeComponent()
-
- Dim Time As Date = Now
- Time = New Date(Time.Year, Time.Month, Time.Day, 0, 0, 0)
- dtStartDate.Value = Time.AddMonths(-1)
- dtEndDate.Value = Time
-
- If Database.Settings.EnableLogging = False Then
- lblStatus.Change(NoticeLabel.IconType.Warning, "Song usage is currently not being recorded.")
- MsgBox("Song usage is currently not being recorded, therefore any reports generated will be inaccurate. To report on future song usage, please enable logging via the PowerSong Configuration dialog box, accessible via the Tools menu of the main form.", MsgBoxStyle.Exclamation)
- End If
-
- End Sub
-
- Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
-
- ' Hide everything to begin with
- txtLog.Visible = False
- lvReport.Clear()
- lvReport.Visible = False
-
- ' Check what type of report to run
- If optRawData.Checked Then
-
- ' Run a raw report
- Dim Task As New RawReportTask(dtStartDate.Value, dtEndDate.Value)
- Dim Form As New ProgressForm(Task, "Running the report...")
- Form.ShowDialog()
-
- ' Show results if the task was not cancelled
- If Not Task.CancelRequested Then
- txtLog.Text = Task.ReportContents
- txtLog.Visible = True
- End If
-
- ElseIf optSongUsage.Checked Then
-
- ' Run a song usage report
- Dim Task As New SongUsageReportTask(dtStartDate.Value, dtEndDate.Value)
- Dim Form As New ProgressForm(Task, "Running the report...")
- Form.ShowDialog()
-
- ' Show results if the task was not cancelled
- If Not Task.CancelRequested Then
-
- ' Configure the list view
- lvReport.Columns.Add("Song Title", 500)
- lvReport.Columns.Add("Times Played", 100)
-
- ' Populate the results
- For Each Entry As KeyValuePair(Of String, Integer) In Task.ReportContents
- Dim Item As ListViewItem = lvReport.Items.Add(Entry.Key)
- Item.SubItems.Add(Entry.Value.ToString)
- Next
- lvReport.Visible = True
-
- End If
-
- End If
-
- End Sub
-
- Private Sub btnSelectFileName_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelectFileName.Click
-
- dlgSave.FileName = txtFileName.Text
- If dlgSave.ShowDialog = Windows.Forms.DialogResult.OK Then
- txtFileName.Text = dlgSave.FileName
- End If
-
- End Sub
-
- Private Sub btnExport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExport.Click
-
- If lvReport.Visible Then
-
- Dim File As StreamWriter = Nothing
- Try
-
- ' Ensure a file name has been specified
- If txtFileName.Text.Trim = "" Then
- MsgBox("Please enter a file name first.", MsgBoxStyle.Exclamation)
- Exit Sub
- End If
-
- ' Create the file
- File = New StreamWriter(New FileStream(txtFileName.Text, FileMode.Create))
-
- ' Export the columns
- Dim FirstLine As String = String.Empty
- For Each Column As ColumnHeader In lvReport.Columns
- If FirstLine <> "" Then FirstLine += ","
- FirstLine += """" + Column.Text.Replace("""", "'") + """"
- Next
- File.WriteLine(FirstLine)
-
- ' Export the data
- For Each Row As ListViewItem In lvReport.Items
- Dim Line As String = """" + Row.Text.Replace("""", "'") + """"
- For SubItemIndex As Integer = 1 To Row.SubItems.Count - 1
- Line += ",""" + Row.SubItems(SubItemIndex).Text.Replace("""", "'") + """"
- Next
- File.WriteLine(Line)
- Next
-
- ' Done
- MsgBox("The data has been exported.", MsgBoxStyle.Information)
-
- Catch ex As Exception
- MsgBox("Export failed:" + Environment.NewLine + ex.Message, MsgBoxStyle.Critical)
- Finally
- If File IsNot Nothing Then File.Close()
- End Try
-
- Else
- MsgBox("It is not possible to export the type of data that you are looking at.", MsgBoxStyle.Information)
- End If
-
- End Sub
-
- End Class