Add tagging support for games

This commit is contained in:
Michael J. Seiferling
2015-11-13 17:59:27 -06:00
parent 5e5da3c068
commit 5357fb214d
18 changed files with 1452 additions and 27 deletions
+135
View File
@@ -0,0 +1,135 @@
Public Class mgrGameTags
Public Shared Sub DoGameTagAdd(ByVal oGameTag As clsGameTag)
Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local)
Dim sSQL As String
Dim hshParams As New Hashtable
sSQL = "INSERT INTO gametags VALUES (@TagID, @MonitorID)"
hshParams.Add("TagID", oGameTag.TagID)
hshParams.Add("MonitorID", oGameTag.MonitorID)
oDatabase.RunParamQuery(sSQL, hshParams)
End Sub
Public Shared Sub DoGameTagAddBatch(ByVal oGameTags As List(Of clsGameTag))
Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local)
Dim sSQL As String
Dim hshParams As Hashtable
Dim oParamList As New List(Of Hashtable)
sSQL = "INSERT INTO gametags VALUES (@TagID, @MonitorID)"
For Each oGameTag As clsGameTag In oGameTags
hshParams = New Hashtable
hshParams.Add("TagID", oGameTag.TagID)
hshParams.Add("MonitorID", oGameTag.MonitorID)
oParamList.Add(hshParams)
Next
oDatabase.RunMassParamQuery(sSQL, oParamList)
End Sub
Public Shared Sub DoGameTagDelete(ByVal oGameTags As List(Of clsGameTag))
Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local)
Dim sSQL As String
Dim hshParams As Hashtable
Dim oParamList As New List(Of Hashtable)
sSQL = "DELETE FROM gametags "
sSQL &= "WHERE TagID = @TagID AND MonitorID = @MonitorID;"
For Each oGameTag As clsGameTag In oGameTags
hshParams = New Hashtable
hshParams.Add("TagID", oGameTag.TagID)
hshParams.Add("MonitorID", oGameTag.MonitorID)
oParamList.Add(hshParams)
Next
oDatabase.RunMassParamQuery(sSQL, oParamList)
End Sub
Public Shared Sub DoGameTagDeleteByGame(ByVal sMonitorID As String)
Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local)
Dim sSQL As String
Dim hshParams As New Hashtable
sSQL = "DELETE FROM gametags "
sSQL &= "WHERE MonitorID = @ID;"
hshParams.Add("ID", sMonitorID)
oDatabase.RunParamQuery(sSQL, hshParams)
End Sub
Public Shared Sub DoGameTagDeleteByTag(ByVal sTagID As String)
Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local)
Dim sSQL As String
Dim hshParams As New Hashtable
sSQL = "DELETE FROM gametags "
sSQL &= "WHERE TagID = @ID;"
hshParams.Add("ID", sTagID)
oDatabase.RunParamQuery(sSQL, hshParams)
End Sub
Public Shared Function GetTagsByGame(ByVal sMonitorID As String) As Hashtable
Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local)
Dim oData As DataSet
Dim sSQL As String
Dim hshList As New Hashtable
Dim hshParams As New Hashtable
Dim oTag As clsTag
sSQL = "SELECT TagID, tags.Name FROM gametags NATURAL JOIN tags WHERE MonitorID = @ID"
hshParams.Add("ID", sMonitorID)
oData = oDatabase.ReadParamData(sSQL, hshParams)
For Each dr As DataRow In oData.Tables(0).Rows
oTag = New clsTag
oTag.ID = CStr(dr(0))
oTag.Name = CStr(dr(1))
hshList.Add(oTag.Name, oTag)
Next
Return hshList
End Function
Public Shared Function GetTagsByGameMulti(ByVal sMonitorIDs As List(Of String)) As Hashtable
Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local)
Dim oData As DataSet
Dim sSQL As String
Dim hshList As New Hashtable
Dim hshParams As New Hashtable
Dim oTag As clsTag
Dim iCounter As Integer
sSQL = "SELECT DISTINCT TagID, tags.Name FROM gametags NATURAL JOIN tags WHERE MonitorID IN ("
For Each s As String In sMonitorIDs
sSQL &= "@MonitorID" & iCounter & ","
hshParams.Add("MonitorID" & iCounter, s)
iCounter += 1
Next
sSQL = sSQL.TrimEnd(",")
sSQL &= ")"
oData = oDatabase.ReadParamData(sSQL, hshParams)
For Each dr As DataRow In oData.Tables(0).Rows
oTag = New clsTag
oTag.ID = CStr(dr(0))
oTag.Name = CStr(dr(1))
hshList.Add(oTag.Name, oTag)
Next
Return hshList
End Function
End Class
+18 -4
View File
@@ -403,8 +403,10 @@ Public Class mgrMonitorList
Dim sSQL As String
Dim hshParams As New Hashtable
sSQL = "DELETE FROM monitorlist "
sSQL &= "WHERE MonitorID = @MonitorID"
sSQL = "DELETE FROM gametags "
sSQL &= "WHERE MonitorID = @MonitorID;"
sSQL &= "DELETE FROM monitorlist "
sSQL &= "WHERE MonitorID = @MonitorID;"
hshParams.Add("MonitorID", sMonitorID)
@@ -418,7 +420,7 @@ Public Class mgrMonitorList
Dim hshParams As New Hashtable
Dim iCounter As Integer
sSQL = "DELETE FROM monitorlist "
sSQL = "DELETE FROM gametags "
sSQL &= "WHERE MonitorID IN ("
For Each s As String In sMonitorIDs
@@ -428,7 +430,19 @@ Public Class mgrMonitorList
Next
sSQL = sSQL.TrimEnd(",")
sSQL &= ")"
sSQL &= ");"
sSQL &= "DELETE FROM monitorlist "
sSQL &= "WHERE MonitorID IN ("
For Each s As String In sMonitorIDs
sSQL &= "@MonitorID" & iCounter & ","
hshParams.Add("MonitorID" & iCounter, s)
iCounter += 1
Next
sSQL = sSQL.TrimEnd(",")
sSQL &= ");"
oDatabase.RunParamQuery(sSQL, hshParams)
End Sub
+49 -2
View File
@@ -79,6 +79,12 @@ Public Class mgrSQLite
"ProcessPath TEXT, Icon TEXT, Hours REAL, Version TEXT, Company TEXT, Enabled BOOLEAN NOT NULL, MonitorOnly BOOLEAN NOT NULL, " & _
"PRIMARY KEY(Name, Process));"
'Add Tables (Tags)
sSql &= "CREATE TABLE tags (TagID TEXT NOT NULL UNIQUE, Name TEXT NOT NULL PRIMARY KEY); "
'Add Tables (Game Tags)
sSql &= "CREATE TABLE gametags (TagID TEXT NOT NULL, MonitorID TEXT NOT NULL, PRIMARY KEY(TagID, MonitorID)); "
'Add Tables (Variables)
sSql &= "CREATE TABLE variables (VariableID TEXT NOT NULL UNIQUE, Name TEXT NOT NULL PRIMARY KEY, Path TEXT NOT NULL);"
@@ -114,6 +120,12 @@ Public Class mgrSQLite
sSql &= "CREATE TABLE manifest (ManifestID TEXT NOT NULL UNIQUE, Name TEXT NOT NULL PRIMARY KEY, FileName TEXT NOT NULL, RestorePath TEXT NOT NULL, " & _
"AbsolutePath BOOLEAN NOT NULL, DateUpdated TEXT NOT NULL, UpdatedBy TEXT NOT NULL, CheckSum TEXT);"
'Add Tables (Remote Tags)
sSql &= "CREATE TABLE tags (TagID TEXT NOT NULL UNIQUE, Name TEXT NOT NULL PRIMARY KEY); "
'Add Tables (Remote Game Tags)
sSql &= "CREATE TABLE gametags (TagID TEXT NOT NULL, MonitorID TEXT NOT NULL, PRIMARY KEY(TagID, MonitorID)); "
'Set Version
sSql &= "PRAGMA user_version=" & mgrCommon.AppVersion
@@ -182,6 +194,32 @@ Public Class mgrSQLite
Return True
End Function
Public Function RunMassParamQuery(ByVal sSQL As String, ByVal oParamList As List(Of Hashtable)) As Boolean
Dim trans As SQLiteTransaction
Dim command As SQLiteCommand
Connect()
command = New SQLiteCommand(sSQL, db)
trans = db.BeginTransaction()
Try
For Each hshParams In oParamList
BuildParams(command, hshParams)
command.ExecuteNonQuery()
Next
trans.Commit()
Catch e As Exception
trans.Rollback()
MsgBox("An error has occured attempting run the query." & vbCrLf & vbCrLf & sSQL & vbCrLf & vbCrLf & e.Message)
Return False
Finally
command.Dispose()
Disconnect()
End Try
Return True
End Function
Public Function ReadParamData(ByVal sSQL As String, ByVal hshParams As Hashtable) As DataSet
Dim adapter As SQLiteDataAdapter
Dim command As SQLiteCommand
@@ -417,8 +455,13 @@ Public Class mgrSQLite
'Backup DB before starting
BackupDB("v93")
'Add Tags Tables
sSQL = "CREATE TABLE tags (TagID TEXT NOT NULL UNIQUE, Name TEXT NOT NULL PRIMARY KEY); "
sSQL &= "CREATE TABLE gametags (TagID TEXT NOT NULL, MonitorID TEXT NOT NULL, PRIMARY KEY(TagID, MonitorID)); "
'Add new setting
sSQL = "ALTER TABLE settings ADD COLUMN TimeTracking BOOLEAN NOT NULL DEFAULT 1;"
sSQL &= "ALTER TABLE settings ADD COLUMN TimeTracking BOOLEAN NOT NULL DEFAULT 1;"
sSQL &= "PRAGMA user_version=94"
RunParamQuery(sSQL, New Hashtable)
@@ -427,7 +470,11 @@ Public Class mgrSQLite
'Backup DB before starting
BackupDB("v93")
sSQL = "PRAGMA user_version=94"
'Add Tags Tables
sSQL = "CREATE TABLE tags (TagID TEXT NOT NULL UNIQUE, Name TEXT NOT NULL PRIMARY KEY); "
sSQL &= "CREATE TABLE gametags (TagID TEXT NOT NULL, MonitorID TEXT NOT NULL, PRIMARY KEY(TagID, MonitorID)); "
sSQL &= "PRAGMA user_version=94"
RunParamQuery(sSQL, New Hashtable)
End If
+136
View File
@@ -0,0 +1,136 @@
Public Class mgrTags
Public Shared Sub DoTagAdd(ByVal oTag As clsTag)
Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local)
Dim sSQL As String
Dim hshParams As New Hashtable
sSQL = "INSERT INTO tags VALUES (@ID, @Name)"
hshParams.Add("ID", oTag.ID)
hshParams.Add("Name", oTag.Name)
oDatabase.RunParamQuery(sSQL, hshParams)
End Sub
Public Shared Sub DoTagUpdate(ByVal oTag As clsTag)
Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local)
Dim sSQL As String
Dim hshParams As New Hashtable
sSQL = "UPDATE tags SET Name=@Name "
sSQL &= "WHERE TagID = @ID"
hshParams.Add("Name", oTag.Name)
hshParams.Add("ID", oTag.ID)
oDatabase.RunParamQuery(sSQL, hshParams)
End Sub
Public Shared Sub DoTagDelete(ByVal sTagID As String)
Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local)
Dim sSQL As String
Dim hshParams As New Hashtable
sSQL = "DELETE FROM gametags "
sSQL &= "WHERE TagID = @ID;"
sSQL = "DELETE FROM tags "
sSQL &= "WHERE TagID = @ID;"
hshParams.Add("ID", sTagID)
oDatabase.RunParamQuery(sSQL, hshParams)
End Sub
Public Shared Function DoTagGetbyID(ByVal sTagID As String) As clsTag
Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local)
Dim sSQL As String
Dim oData As DataSet
Dim oTag As New clsTag
Dim hshParams As New Hashtable
sSQL = "SELECT * FROM tags "
sSQL &= "WHERE TagID = @ID"
hshParams.Add("ID", sTagID)
oData = oDatabase.ReadParamData(sSQL, hshParams)
For Each dr As DataRow In oData.Tables(0).Rows
oTag = New clsTag
oTag.ID = CStr(dr(0))
oTag.Name = CStr(dr(1))
Next
Return oTag
End Function
Public Shared Function DoTagGetbyName(ByVal sTagName As String) As clsTag
Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local)
Dim sSQL As String
Dim oData As DataSet
Dim oTag As New clsTag
Dim hshParams As New Hashtable
sSQL = "SELECT * FROM tags "
sSQL &= "WHERE Name = @Name"
hshParams.Add("Name", sTagName)
oData = oDatabase.ReadParamData(sSQL, hshParams)
For Each dr As DataRow In oData.Tables(0).Rows
oTag = New clsTag
oTag.ID = CStr(dr(0))
oTag.Name = CStr(dr(1))
Next
Return oTag
End Function
Public Shared Function DoCheckDuplicate(ByVal sTagName As String, Optional ByVal sExcludeID As String = "") As Boolean
Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local)
Dim sSQL As String
Dim oData As DataSet
Dim hshParams As New Hashtable
sSQL = "SELECT * FROM tags "
sSQL &= "WHERE Name = @Name"
hshParams.Add("Name", sTagName)
If sExcludeID <> String.Empty Then
sSQL &= " AND TagID <> @TagID"
hshParams.Add("TagID", sExcludeID)
End If
oData = oDatabase.ReadParamData(sSQL, hshParams)
If oData.Tables(0).Rows.Count > 0 Then
Return True
Else
Return False
End If
End Function
Public Shared Function ReadTags() As Hashtable
Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local)
Dim oData As DataSet
Dim sSQL As String
Dim hshList As New Hashtable
Dim oTag As clsTag
sSQL = "SELECT * from tags"
oData = oDatabase.ReadParamData(sSQL, New Hashtable)
For Each dr As DataRow In oData.Tables(0).Rows
oTag = New clsTag
oTag.ID = CStr(dr(0))
oTag.Name = CStr(dr(1))
hshList.Add(oTag.Name, oTag)
Next
Return hshList
End Function
End Class
+1 -3
View File
@@ -1,6 +1,4 @@
Imports System.IO
Public Class mgrVariables
Public Class mgrVariables
Public Shared Sub DoPathUpdate(ByVal sOld As String, ByVal sNew As String)
Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local)