diff --git a/GBM/Forms/frmMain.vb b/GBM/Forms/frmMain.vb index 099a390..05240a2 100644 --- a/GBM/Forms/frmMain.vb +++ b/GBM/Forms/frmMain.vb @@ -881,7 +881,11 @@ Public Class frmMain Private Sub OpenSessions() Dim frm As New frmSessions PauseScan() - frm.ShowDialog() + If mgrSessions.CountRows > 0 Then + frm.ShowDialog() + Else + mgrCommon.ShowMessage(frmMain_ErrorNoSessions, MsgBoxStyle.Information) + End If ResumeScan() End Sub diff --git a/GBM/Forms/frmSessions.Designer.vb b/GBM/Forms/frmSessions.Designer.vb index 5640618..1cb7e83 100644 --- a/GBM/Forms/frmSessions.Designer.vb +++ b/GBM/Forms/frmSessions.Designer.vb @@ -22,26 +22,33 @@ Partial Class frmSessions 'Do not modify it using the code editor. _ Private Sub InitializeComponent() - Me.lblQuickFilter = New System.Windows.Forms.Label() + Me.lblFilter = New System.Windows.Forms.Label() Me.txtFilter = New System.Windows.Forms.TextBox() Me.dgSessions = New System.Windows.Forms.DataGridView() + Me.dtpStart = New System.Windows.Forms.DateTimePicker() + Me.dtpEnd = New System.Windows.Forms.DateTimePicker() + Me.lblTo = New System.Windows.Forms.Label() + Me.btnReset = New System.Windows.Forms.Button() + Me.btnDelete = New System.Windows.Forms.Button() + Me.btnClose = New System.Windows.Forms.Button() + Me.lblDateRange = New System.Windows.Forms.Label() CType(Me.dgSessions, System.ComponentModel.ISupportInitialize).BeginInit() Me.SuspendLayout() ' - 'lblQuickFilter + 'lblFilter ' - Me.lblQuickFilter.AutoSize = True - Me.lblQuickFilter.Location = New System.Drawing.Point(12, 9) - Me.lblQuickFilter.Name = "lblQuickFilter" - Me.lblQuickFilter.Size = New System.Drawing.Size(63, 13) - Me.lblQuickFilter.TabIndex = 0 - Me.lblQuickFilter.Text = "Game Filter:" + Me.lblFilter.AutoSize = True + Me.lblFilter.Location = New System.Drawing.Point(12, 9) + Me.lblFilter.Name = "lblFilter" + Me.lblFilter.Size = New System.Drawing.Size(63, 13) + Me.lblFilter.TabIndex = 0 + Me.lblFilter.Text = "Game Filter:" ' 'txtFilter ' Me.txtFilter.Location = New System.Drawing.Point(80, 6) Me.txtFilter.Name = "txtFilter" - Me.txtFilter.Size = New System.Drawing.Size(160, 20) + Me.txtFilter.Size = New System.Drawing.Size(190, 20) Me.txtFilter.TabIndex = 1 ' 'dgSessions @@ -58,16 +65,85 @@ Partial Class frmSessions Me.dgSessions.ReadOnly = True Me.dgSessions.RowHeadersVisible = False Me.dgSessions.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect - Me.dgSessions.Size = New System.Drawing.Size(760, 517) - Me.dgSessions.TabIndex = 2 + Me.dgSessions.Size = New System.Drawing.Size(760, 488) + Me.dgSessions.TabIndex = 6 + ' + 'dtpStart + ' + Me.dtpStart.Location = New System.Drawing.Point(384, 6) + Me.dtpStart.Name = "dtpStart" + Me.dtpStart.Size = New System.Drawing.Size(175, 20) + Me.dtpStart.TabIndex = 3 + ' + 'dtpEnd + ' + Me.dtpEnd.Location = New System.Drawing.Point(597, 6) + Me.dtpEnd.Name = "dtpEnd" + Me.dtpEnd.Size = New System.Drawing.Size(175, 20) + Me.dtpEnd.TabIndex = 5 + ' + 'lblTo + ' + Me.lblTo.Location = New System.Drawing.Point(565, 9) + Me.lblTo.Name = "lblTo" + Me.lblTo.Size = New System.Drawing.Size(26, 17) + Me.lblTo.TabIndex = 4 + Me.lblTo.Text = "to" + Me.lblTo.TextAlign = System.Drawing.ContentAlignment.TopCenter + ' + 'btnReset + ' + Me.btnReset.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) + Me.btnReset.Location = New System.Drawing.Point(591, 526) + Me.btnReset.Name = "btnReset" + Me.btnReset.Size = New System.Drawing.Size(100, 23) + Me.btnReset.TabIndex = 2 + Me.btnReset.Text = "&Reset Filters" + Me.btnReset.UseVisualStyleBackColor = True + ' + 'btnDelete + ' + Me.btnDelete.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles) + Me.btnDelete.Location = New System.Drawing.Point(12, 526) + Me.btnDelete.Name = "btnDelete" + Me.btnDelete.Size = New System.Drawing.Size(100, 23) + Me.btnDelete.TabIndex = 7 + Me.btnDelete.Text = "&Delete Session" + Me.btnDelete.UseVisualStyleBackColor = True + ' + 'btnClose + ' + Me.btnClose.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) + Me.btnClose.Location = New System.Drawing.Point(697, 526) + Me.btnClose.Name = "btnClose" + Me.btnClose.Size = New System.Drawing.Size(75, 23) + Me.btnClose.TabIndex = 8 + Me.btnClose.Text = "&Close" + Me.btnClose.UseVisualStyleBackColor = True + ' + 'lblDateRange + ' + Me.lblDateRange.AutoSize = True + Me.lblDateRange.Location = New System.Drawing.Point(310, 9) + Me.lblDateRange.Name = "lblDateRange" + Me.lblDateRange.Size = New System.Drawing.Size(68, 13) + Me.lblDateRange.TabIndex = 9 + Me.lblDateRange.Text = "Date Range:" ' 'frmSessions ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.ClientSize = New System.Drawing.Size(784, 561) + Me.Controls.Add(Me.lblDateRange) + Me.Controls.Add(Me.btnClose) + Me.Controls.Add(Me.btnDelete) + Me.Controls.Add(Me.btnReset) + Me.Controls.Add(Me.lblTo) + Me.Controls.Add(Me.dtpEnd) + Me.Controls.Add(Me.dtpStart) Me.Controls.Add(Me.dgSessions) - Me.Controls.Add(Me.lblQuickFilter) + Me.Controls.Add(Me.lblFilter) Me.Controls.Add(Me.txtFilter) Me.Name = "frmSessions" Me.ShowIcon = False @@ -79,7 +155,14 @@ Partial Class frmSessions End Sub - Friend WithEvents lblQuickFilter As Label + Friend WithEvents lblFilter As Label Friend WithEvents txtFilter As TextBox Friend WithEvents dgSessions As DataGridView + Friend WithEvents dtpStart As DateTimePicker + Friend WithEvents dtpEnd As DateTimePicker + Friend WithEvents lblTo As Label + Friend WithEvents btnReset As Button + Friend WithEvents btnDelete As Button + Friend WithEvents btnClose As Button + Friend WithEvents lblDateRange As Label End Class diff --git a/GBM/Forms/frmSessions.vb b/GBM/Forms/frmSessions.vb index fa8425f..cbc14a2 100644 --- a/GBM/Forms/frmSessions.vb +++ b/GBM/Forms/frmSessions.vb @@ -1,13 +1,19 @@ Imports GBM.My.Resources +Imports System.Globalization Public Class frmSessions + Private bInitFinished As Boolean = False Private WithEvents tmFilterTimer As Timer Private Sub FormatGrid() + dgSessions.Columns.Add("MonitorID", frmSessions_ColumnMonitorID) dgSessions.Columns.Add("Name", frmSessions_ColumnGameName) dgSessions.Columns.Add("Start", frmSessions_ColumnStart) dgSessions.Columns.Add("End", frmSessions_ColumnEnd) + + 'Hide the ID + dgSessions.Columns("MonitorID").Visible = False End Sub Private Sub LoadData() @@ -15,16 +21,16 @@ Public Class frmSessions Dim sFilter As String If txtFilter.Text = String.Empty Then - oData = mgrSessions.GetSessions + oData = mgrSessions.GetSessionRange(dtpStart.Value, dtpEnd.Value) Else sFilter = txtFilter.Text.ToLower - oData = mgrSessions.GetSessionsByGameName(sFilter) + oData = mgrSessions.GetSessionsByGameNameAndRange(sFilter, dtpStart.Value, dtpEnd.Value) End If dgSessions.Rows.Clear() For Each dr As DataRow In oData.Tables(0).Rows - dgSessions.Rows.Add(New Object() {dr("Name"), mgrCommon.UnixToDate(dr("Start")), mgrCommon.UnixToDate(dr("End"))}) + dgSessions.Rows.Add(New Object() {dr("MonitorID"), dr("Name"), mgrCommon.UnixToDate(dr("Start")), mgrCommon.UnixToDate(dr("End"))}) Next dgSessions.AutoResizeColumns() @@ -33,10 +39,79 @@ Public Class frmSessions Private Sub SetForm() Me.Text = frmSessions_Name + 'Init Labels + lblFilter.Text = frmSessions_lblFilter + lblDateRange.Text = frmSessions_lblDateRange + btnDelete.Text = frmSessions_btnDelete + btnReset.Text = frmSessions_btnReset + btnClose.Text = frmSessions_btnClose + 'Init Filter Timer tmFilterTimer = New Timer() tmFilterTimer.Interval = 1000 tmFilterTimer.Enabled = False + + + End Sub + + Private Sub ResetFilterFields() + Dim dtMinDate As DateTime = mgrSessions.GetMinimumDateTime + Dim dtMaxDate As DateTime = mgrSessions.GetMaximumDateTime + Dim sDateTimeFormat = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern & " " & CultureInfo.CurrentCulture.DateTimeFormat.LongTimePattern + + bInitFinished = False + + 'Init Date Fields + dtpStart.Format = DateTimePickerFormat.Custom + dtpEnd.Format = DateTimePickerFormat.Custom + dtpStart.CustomFormat = sDateTimeFormat + dtpEnd.CustomFormat = sDateTimeFormat + dtpStart.MinDate = dtMinDate + dtpStart.MaxDate = dtMaxDate + dtpEnd.MinDate = dtMinDate + dtpEnd.MaxDate = dtMaxDate + dtpStart.Value = dtMinDate + dtpEnd.Value = dtMaxDate + + 'Init Text Filter + txtFilter.Text = String.Empty + + bInitFinished = True + End Sub + + Private Sub Reset() + ResetFilterFields() + LoadData() + End Sub + + Private Sub DeleteSession() + Dim oSession As clsSession + Dim oSessions As New List(Of clsSession) + + For Each dgvRow As DataGridViewRow In dgSessions.SelectedRows + oSession = New clsSession + oSession.MonitorID = dgvRow.Cells(0).Value + oSession.SessionStart = dgvRow.Cells(2).Value + oSession.SessionEnd = dgvRow.Cells(3).Value + oSessions.Add(oSession) + Next + + If oSessions.Count > 0 Then + mgrSessions.DeleteSession(oSessions) + End If + End Sub + + Private Sub frmSession_Load(sender As Object, e As EventArgs) Handles MyBase.Load + SetForm() + ResetFilterFields() + FormatGrid() + LoadData() + End Sub + + Private Sub tmFilterTimer_Tick(sender As Object, ByVal e As EventArgs) Handles tmFilterTimer.Tick + LoadData() + tmFilterTimer.Stop() + tmFilterTimer.Enabled = False End Sub Private Sub txtFilter_TextChanged(sender As Object, e As EventArgs) Handles txtFilter.TextChanged @@ -46,16 +121,28 @@ Public Class frmSessions End If End Sub - Private Sub tmFilterTimer_Tick(sender As Object, ByVal e As EventArgs) Handles tmFilterTimer.Tick - LoadData() - tmFilterTimer.Stop() - tmFilterTimer.Enabled = False + Private Sub dtpStart_ValueChanged(sender As Object, e As EventArgs) Handles dtpStart.ValueChanged + If bInitFinished Then LoadData() End Sub - Private Sub frmSession_Load(sender As Object, e As EventArgs) Handles MyBase.Load - SetForm() - FormatGrid() - LoadData() + Private Sub dtpEnd_ValueChanged(sender As Object, e As EventArgs) Handles dtpEnd.ValueChanged + If bInitFinished Then LoadData() End Sub + Private Sub btnReset_Click(sender As Object, e As EventArgs) Handles btnReset.Click + Reset() + End Sub + + Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click + Me.Close() + End Sub + + Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click + If dgSessions.SelectedRows.Count > 0 Then + If mgrCommon.ShowMessage(frmSessions_ConfirmDelete, MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then + DeleteSession() + Reset() + End If + End If + End Sub End Class \ No newline at end of file diff --git a/GBM/Managers/mgrSQLite.vb b/GBM/Managers/mgrSQLite.vb index d2837c4..795b083 100644 --- a/GBM/Managers/mgrSQLite.vb +++ b/GBM/Managers/mgrSQLite.vb @@ -261,6 +261,27 @@ Public Class mgrSQLite Return oData End Function + Public Function ReadSingleValue(ByVal sSQL As String, ByVal hshParams As Hashtable) As Object + + Dim command As SqliteCommand + Dim oResult As New Object + + Connect() + Command = New SqliteCommand(sSQL, db) + BuildParams(command, hshParams) + + Try + oResult = command.ExecuteScalar() + Catch ex As Exception + mgrCommon.ShowMessage(mgrSQLite_ErrorQueryFailure, New String() {sSQL, ex.Message}, MsgBoxStyle.Information) + Finally + command.Dispose() + Disconnect() + End Try + + Return oResult + End Function + Private Function GetDatabaseVersion() As Integer Dim sSQL As String Dim iVer As Integer diff --git a/GBM/Managers/mgrSessions.vb b/GBM/Managers/mgrSessions.vb index 9eac59e..ab68b43 100644 --- a/GBM/Managers/mgrSessions.vb +++ b/GBM/Managers/mgrSessions.vb @@ -37,21 +37,90 @@ Dim sSQL As String Dim hshParams As New Hashtable - sSQL = "SELECT Name, Start, End FROM sessions NATURAL JOIN monitorlist;" + sSQL = "SELECT sessions.MonitorID, monitorlist.Name, Start, End FROM sessions NATURAL JOIN monitorlist;" Return oDatabase.ReadParamData(sSQL, hshParams) End Function - Public Shared Function GetSessionsByGameName(ByVal sGameName As String, Optional ByVal iSelectDB As mgrSQLite.Database = mgrSQLite.Database.Local) As DataSet + Public Shared Function GetSessionRange(ByVal dtStart As DateTime, ByVal dtEnd As DateTime, Optional ByVal iSelectDB As mgrSQLite.Database = mgrSQLite.Database.Local) As DataSet Dim oDatabase As New mgrSQLite(iSelectDB) Dim sSQL As String Dim hshParams As New Hashtable - sSQL = "SELECT Name, Start, End FROM sessions NATURAL JOIN monitorlist WHERE monitorlist.Name LIKE @Name;" + sSQL = "SELECT sessions.MonitorID, monitorlist.Name, Start, End FROM sessions NATURAL JOIN monitorlist WHERE Start >= @Start AND End <= @End;" - hshParams.Add("Name", "%" & sGameName & "%") + hshParams.Add("Start", mgrCommon.DateToUnix(dtStart)) + hshParams.Add("End", mgrCommon.DateToUnix(dtEnd)) Return oDatabase.ReadParamData(sSQL, hshParams) End Function + Public Shared Function GetSessionsByGameNameAndRange(ByVal sGameName As String, ByVal dtStart As DateTime, ByVal dtEnd As DateTime, Optional ByVal iSelectDB As mgrSQLite.Database = mgrSQLite.Database.Local) As DataSet + Dim oDatabase As New mgrSQLite(iSelectDB) + Dim sSQL As String + Dim hshParams As New Hashtable + + sSQL = "SELECT sessions.MonitorID, monitorlist.Name, Start, End FROM sessions NATURAL JOIN monitorlist WHERE monitorlist.Name LIKE @Name AND (Start >= @Start AND End <= @End);" + + hshParams.Add("Name", "%" & sGameName & "%") + hshParams.Add("Start", mgrCommon.DateToUnix(dtStart)) + hshParams.Add("End", mgrCommon.DateToUnix(dtEnd)) + + Return oDatabase.ReadParamData(sSQL, hshParams) + End Function + + Public Shared Sub DeleteSession(ByVal oSessions As List(Of clsSession), Optional ByVal iSelectDB As mgrSQLite.Database = mgrSQLite.Database.Local) + Dim oDatabase As New mgrSQLite(iSelectDB) + Dim sSQL As String + Dim hshParams As Hashtable + Dim oParamList As New List(Of Hashtable) + + sSQL = "DELETE FROM sessions WHERE MonitorID = @MonitorID AND Start = @Start;" + + For Each oSession As clsSession In oSessions + hshParams = New Hashtable + hshParams.Add("MonitorID", oSession.MonitorID) + hshParams.Add("Start", mgrCommon.DateToUnix(oSession.SessionStart)) + oParamList.Add(hshParams) + Next + + oDatabase.RunMassParamQuery(sSQL, oParamList) + End Sub + + Public Shared Function GetMinimumDateTime(Optional ByVal iSelectDB As mgrSQLite.Database = mgrSQLite.Database.Local) As DateTime + Dim oDatabase As New mgrSQLite(iSelectDB) + Dim sSQL As String + Dim hshParams As New Hashtable + Dim iUnixDate As Int64 + + sSQL = "SELECT Start FROM sessions ORDER BY Start ASC LIMIT 1" + + iUnixDate = CInt(oDatabase.ReadSingleValue(sSQL, hshParams)) + Return mgrCommon.UnixToDate(iUnixDate) + End Function + + Public Shared Function GetMaximumDateTime(Optional ByVal iSelectDB As mgrSQLite.Database = mgrSQLite.Database.Local) As DateTime + Dim oDatabase As New mgrSQLite(iSelectDB) + Dim sSQL As String + Dim hshParams As New Hashtable + Dim iUnixDate As Int64 + + sSQL = "SELECT End FROM sessions ORDER BY Start DESC LIMIT 1" + + iUnixDate = CInt(oDatabase.ReadSingleValue(sSQL, hshParams)) + Return mgrCommon.UnixToDate(iUnixDate) + End Function + + Public Shared Function CountRows(Optional ByVal iSelectDB As mgrSQLite.Database = mgrSQLite.Database.Local) As Integer + Dim oDatabase As New mgrSQLite(iSelectDB) + Dim sSQL As String + Dim hshParams As New Hashtable + Dim iRowCount As Integer + + sSQL = "SELECT COUNT(MonitorID) FROM sessions;" + + iRowCount = CInt(oDatabase.ReadSingleValue(sSQL, hshParams)) + + Return iRowCount + End Function End Class \ No newline at end of file diff --git a/GBM/My Project/Resources.Designer.vb b/GBM/My Project/Resources.Designer.vb index 090a8d6..a7a69e7 100644 --- a/GBM/My Project/Resources.Designer.vb +++ b/GBM/My Project/Resources.Designer.vb @@ -2949,6 +2949,15 @@ Namespace My.Resources End Get End Property + ''' + ''' Looks up a localized string similar to There is currently no session data to display.. + ''' + Friend ReadOnly Property frmMain_ErrorNoSessions() As String + Get + Return ResourceManager.GetString("frmMain_ErrorNoSessions", resourceCulture) + End Get + End Property + ''' ''' Looks up a localized string similar to [PARAM] uses a relative path and has never been detected on this computer.. ''' @@ -3606,6 +3615,33 @@ Namespace My.Resources End Get End Property + ''' + ''' Looks up a localized string similar to &Close. + ''' + Friend ReadOnly Property frmSessions_btnClose() As String + Get + Return ResourceManager.GetString("frmSessions_btnClose", resourceCulture) + End Get + End Property + + ''' + ''' Looks up a localized string similar to &Delete Session. + ''' + Friend ReadOnly Property frmSessions_btnDelete() As String + Get + Return ResourceManager.GetString("frmSessions_btnDelete", resourceCulture) + End Get + End Property + + ''' + ''' Looks up a localized string similar to &Reset Filters. + ''' + Friend ReadOnly Property frmSessions_btnReset() As String + Get + Return ResourceManager.GetString("frmSessions_btnReset", resourceCulture) + End Get + End Property + ''' ''' Looks up a localized string similar to End. ''' @@ -3624,6 +3660,15 @@ Namespace My.Resources End Get End Property + ''' + ''' Looks up a localized string similar to MonitorID. + ''' + Friend ReadOnly Property frmSessions_ColumnMonitorID() As String + Get + Return ResourceManager.GetString("frmSessions_ColumnMonitorID", resourceCulture) + End Get + End Property + ''' ''' Looks up a localized string similar to Start. ''' @@ -3633,6 +3678,33 @@ Namespace My.Resources End Get End Property + ''' + ''' Looks up a localized string similar to Are you sure you want to delete the selected session(s)? This cannot be undone.. + ''' + Friend ReadOnly Property frmSessions_ConfirmDelete() As String + Get + Return ResourceManager.GetString("frmSessions_ConfirmDelete", resourceCulture) + End Get + End Property + + ''' + ''' Looks up a localized string similar to Date Range:. + ''' + Friend ReadOnly Property frmSessions_lblDateRange() As String + Get + Return ResourceManager.GetString("frmSessions_lblDateRange", resourceCulture) + End Get + End Property + + ''' + ''' Looks up a localized string similar to Game Filter:. + ''' + Friend ReadOnly Property frmSessions_lblFilter() As String + Get + Return ResourceManager.GetString("frmSessions_lblFilter", resourceCulture) + End Get + End Property + ''' ''' Looks up a localized string similar to Session Viewer. ''' diff --git a/GBM/My Project/Resources.resx b/GBM/My Project/Resources.resx index 8f06d19..61695a2 100644 --- a/GBM/My Project/Resources.resx +++ b/GBM/My Project/Resources.resx @@ -1915,4 +1915,28 @@ Session Viewer + + There is currently no session data to display. + + + &Close + + + &Delete Session + + + &Reset Filters + + + MonitorID + + + Are you sure you want to delete the selected session(s)? This cannot be undone. + + + Date Range: + + + Game Filter: + \ No newline at end of file