132 lines
5.5 KiB
VB.net
132 lines
5.5 KiB
VB.net
Imports System.Data.Common
|
|
Imports System.Data.SQLite
|
|
Imports DevExpress.Text
|
|
|
|
Public Class SongRepository
|
|
|
|
|
|
Friend Shared Async Function GetSongs() As Task(Of List(Of Song))
|
|
Dim con = DB.getConnection
|
|
Dim cmd As New SQLiteCommand(Nothing, con)
|
|
Dim reader As DbDataReader
|
|
Await con.OpenAsync
|
|
Dim result As New List(Of Song)
|
|
cmd.CommandText = "SELECT * FROM t_songs"
|
|
reader = Await cmd.ExecuteReaderAsync
|
|
result.Clear()
|
|
Dim s As Song
|
|
Do While Await reader.ReadAsync
|
|
s = New Song
|
|
s.ID = CInt(reader("S_ID"))
|
|
s.RootDir = CStr(reader("S_Path"))
|
|
s.SubDirectory = CStr(reader("S_Subpath"))
|
|
s.Artist = TryCast(reader("S_Info_Artist"), String)
|
|
s.Title = TryCast(reader("S_Info_Title"), String)
|
|
s.Year = CInt(reader("S_Info_Year"))
|
|
s.Language = TryCast(reader("S_Info_Language"), String)
|
|
s.Genre = TryCast(reader("S_Info_Genre"), String)
|
|
s.Previewstart = CDec(reader("S_Info_Previewstart"))
|
|
s.BPM = CInt(reader("S_Info_BPM"))
|
|
s.GAP = CInt(reader("S_Info_GAP"))
|
|
s.IsFavorite = CBool(reader("S_Favorite"))
|
|
s.InfoFile = TryCast(reader("S_File_Info"), String)
|
|
s.Songfilename = TryCast(reader("S_File_Song"), String)
|
|
s.CoverFilename = TryCast(reader("S_File_Cover"), String)
|
|
s.VideoFilename = TryCast(reader("S_File_Video"), String)
|
|
s.SongInfos = Newtonsoft.Json.JsonConvert.DeserializeObject(Of Dictionary(Of String, String))(TryCast(reader("S_Info_Additional"), String))
|
|
result.Add(s)
|
|
'ToDo:Songinfos laden (oder erst beim Anklicken des Liedes)
|
|
Loop
|
|
Return result
|
|
End Function
|
|
|
|
Friend Shared Async Sub DeleteAllSongs()
|
|
Dim con = DB.getConnection
|
|
Dim cmd As New SQLiteCommand(Nothing, con)
|
|
Await con.OpenAsync()
|
|
cmd.CommandText = "DELETE FROM t_songs"
|
|
Await cmd.ExecuteNonQueryAsync()
|
|
con.Close()
|
|
End Sub
|
|
|
|
Friend Shared Async Sub SaveSongs(songs As List(Of Song))
|
|
Dim con = DB.getConnection
|
|
Dim cmd As New SQLiteCommand(Nothing, con)
|
|
With cmd.Parameters
|
|
.Add("@path", DbType.String)
|
|
.Add("@subpath", DbType.String)
|
|
.Add("@artist", DbType.String)
|
|
.Add("@title", DbType.String)
|
|
.Add("@year", DbType.Int32)
|
|
.Add("@language", DbType.String)
|
|
.Add("@genre", DbType.String)
|
|
.Add("@previewstart", DbType.Double)
|
|
.Add("@bpm", DbType.Int32)
|
|
.Add("@gap", DbType.Int32)
|
|
.Add("@additional", DbType.String)
|
|
.Add("@favorite", DbType.Boolean)
|
|
.Add("@fileinfo", DbType.String)
|
|
.Add("@filesong", DbType.String)
|
|
.Add("@filecover", DbType.String)
|
|
.Add("@filevideo", DbType.String)
|
|
End With
|
|
Await con.OpenAsync()
|
|
|
|
cmd.CommandText = "INSERT INTO t_songs (
|
|
S_Path,
|
|
S_Subpath,
|
|
S_Info_Artist,
|
|
S_Info_Title,
|
|
S_Info_Year,
|
|
S_Info_Language,
|
|
S_Info_Genre,
|
|
S_Info_Previewstart,
|
|
S_Info_BPM,
|
|
S_Info_GAP,
|
|
S_Info_Additional,
|
|
S_Favorite,
|
|
S_File_Info,
|
|
S_File_Song,
|
|
S_File_Cover,
|
|
S_File_Video
|
|
) VALUES (
|
|
@path,
|
|
@subpath,
|
|
@artist,
|
|
@title,
|
|
@year,
|
|
@language,
|
|
@genre,
|
|
@previewstart,
|
|
@bpm,
|
|
@gap,
|
|
@additional,
|
|
@favorite,
|
|
@fileinfo,
|
|
@filesong,
|
|
@filecover,
|
|
@filevideo
|
|
)"
|
|
For Each s As Song In songs
|
|
cmd.Parameters("@path").Value = s.RootDir
|
|
cmd.Parameters("@subpath").Value = s.SubDirectory
|
|
cmd.Parameters("@artist").Value = s.Artist
|
|
cmd.Parameters("@title").Value = s.Title
|
|
cmd.Parameters("@year").Value = s.Year
|
|
cmd.Parameters("@language").Value = s.Language
|
|
cmd.Parameters("@genre").Value = s.Genre
|
|
cmd.Parameters("@previewstart").Value = s.Previewstart
|
|
cmd.Parameters("@bpm").Value = s.BPM
|
|
cmd.Parameters("@gap").Value = s.GAP
|
|
cmd.Parameters("@additional").Value = Newtonsoft.Json.JsonConvert.SerializeObject(s.SongInfos)
|
|
cmd.Parameters("@favorite").Value = s.IsFavorite
|
|
cmd.Parameters("@fileinfo").Value = s.InfoFile
|
|
cmd.Parameters("@filesong").Value = s.Songfilename
|
|
cmd.Parameters("@filecover").Value = s.CoverFilename
|
|
cmd.Parameters("@filevideo").Value = s.VideoFilename
|
|
Await cmd.ExecuteNonQueryAsync()
|
|
Next
|
|
con.Close()
|
|
End Sub
|
|
End Class
|