diff --git a/Vocaluxe/Base/CDataBase.cs b/Vocaluxe/Base/CDataBase.cs index 89b32fb4..3c2867a2 100644 --- a/Vocaluxe/Base/CDataBase.cs +++ b/Vocaluxe/Base/CDataBase.cs @@ -326,14 +326,16 @@ namespace Vocaluxe.Base reader.Dispose(); return id; } + if (reader != null) reader.Close(); - command.CommandText = "INSERT INTO Songs (Title, Artist, NumPlayed) " + - "VALUES (@title, @artist, @numplayed)"; + command.CommandText = "INSERT INTO Songs (Title, Artist, NumPlayedm DateAdded) " + + "VALUES (@title, @artist, @numplayed, @dateadded)"; command.Parameters.Add("@title", DbType.String, 0).Value = title; command.Parameters.Add("@artist", DbType.String, 0).Value = artist; command.Parameters.Add("@numplayed", DbType.Int32, 0).Value = defNumPlayed; + command.Parameters.Add("@dateadded", System.Data.DbType.Int64, 0).Value = DateTime.Now.Ticks; command.ExecuteNonQuery(); command.CommandText = "SELECT id FROM Songs WHERE [Title] = @title AND [Artist] = @artist"; @@ -353,11 +355,12 @@ namespace Vocaluxe.Base return -1; } - private static bool _GetDataBaseSongInfos(int songID, out string artist, out string title, out int numPlayed, string filePath) + private static bool _GetDataBaseSongInfos(int songID, out string artist, out string title, out int numPlayed, out string dateAdded, string filePath) { artist = String.Empty; title = String.Empty; numPlayed = 0; + dateAdded = String.Empty; using (SQLiteConnection connection = new SQLiteConnection()) { @@ -374,7 +377,7 @@ namespace Vocaluxe.Base using (SQLiteCommand command = new SQLiteCommand(connection)) { - command.CommandText = "SELECT Artist, Title, NumPlayed FROM Songs WHERE [id] = @id"; + command.CommandText = "SELECT Artist, Title, NumPlayed, DateAdded FROM Songs WHERE [id] = @id"; command.Parameters.Add("@id", DbType.String, 0).Value = songID; SQLiteDataReader reader; @@ -393,6 +396,7 @@ namespace Vocaluxe.Base artist = reader.GetString(0); title = reader.GetString(1); numPlayed = reader.GetInt32(2); + dateAdded = reader.GetInt64(3).ToString("dd/MM/yyyy"); reader.Dispose(); return true; } @@ -555,6 +559,7 @@ namespace Vocaluxe.Base _CreateHighscoreDBV1(filePath); _ConvertFrom110(filePath); _UpdateDatabase(1, connection); + _UpdateDatabase(2, connection); } else if (version == 0 && scoresTableExists) { @@ -562,6 +567,7 @@ namespace Vocaluxe.Base _CreateHighscoreDBV1(filePath); _ConvertFrom101(filePath); _UpdateDatabase(1, connection); + _UpdateDatabase(2, connection); } else _CreateHighscoreDB(filePath); @@ -575,6 +581,7 @@ namespace Vocaluxe.Base _CreateHighscoreDBV1(filePath); _ConvertFrom110(filePath); _UpdateDatabase(1, connection); + _UpdateDatabase(2, connection); } else if (version == 0 && scoresTableExists) { @@ -582,6 +589,7 @@ namespace Vocaluxe.Base _CreateHighscoreDBV1(filePath); _ConvertFrom101(filePath); _UpdateDatabase(1, connection); + _UpdateDatabase(2, connection); } else _CreateHighscoreDB(filePath); @@ -882,8 +890,16 @@ namespace Vocaluxe.Base private static bool _UpdateDatabase(int currentVersion, SQLiteConnection connection) { bool updated = true; + if (currentVersion < 2) + { updated &= _ConvertV1toV2(connection); + } + if (currentVersion < 3) + { + updated &= _ConvertV2toV3(connection); + } + return updated; } @@ -904,6 +920,25 @@ namespace Vocaluxe.Base return true; } + private static bool _ConvertV2toV3(SQLiteConnection connection) + { + SQLiteCommand command; + + command = new SQLiteCommand(connection); + + command.CommandText = "ALTER TABLE Songs ADD DateAdded BIGINT"; + command.ExecuteNonQuery(); + command.CommandText = "UPDATE Songs SET [DateAdded] = @DateAdded"; + command.Parameters.Add("@DateAdded",System.Data.DbType.Int64, 0).Value = DateTime.Now.Ticks; + command.ExecuteNonQuery(); + command.CommandText = "UPDATE Version SET [Value] = @version"; + command.Parameters.Add("@version", System.Data.DbType.Int32, 0).Value = 3; + command.ExecuteNonQuery(); + command.Dispose(); + + return true; + } + private static bool _ImportData(string sourceDBPath) { #region open db @@ -948,9 +983,9 @@ namespace Vocaluxe.Base int shortsong = source.GetInt32(7); int diff = source.GetInt32(8); - string artist, title; + string artist, title, dateadded; int numplayed; - if (_GetDataBaseSongInfos(songid, out artist, out title, out numplayed, sourceDBPath)) + if (_GetDataBaseSongInfos(songid, out artist, out title, out numplayed, out dateadded, sourceDBPath)) AddScore(player, score, linenr, date, medley, duet, shortsong, diff, artist, title, numplayed, _HighscoreFilePath); } #endregion import table scores diff --git a/Vocaluxe/Base/CSettings.cs b/Vocaluxe/Base/CSettings.cs index eeaffaef..71cfd196 100644 --- a/Vocaluxe/Base/CSettings.cs +++ b/Vocaluxe/Base/CSettings.cs @@ -55,7 +55,7 @@ namespace Vocaluxe.Base public const ERevision VersionRevision = ERevision.Beta; - public const int DatabaseHighscoreVersion = 2; + public const int DatabaseHighscoreVersion = 3; public const int DatabaseCoverVersion = 1; public const int DatabaseCreditsRessourcesVersion = 1; @@ -224,4 +224,4 @@ namespace Vocaluxe.Base Directory.CreateDirectory(path); } } -} \ No newline at end of file +} diff --git a/VocaluxeLib/Songs/CSong.cs b/VocaluxeLib/Songs/CSong.cs index d78614d6..9af33523 100644 --- a/VocaluxeLib/Songs/CSong.cs +++ b/VocaluxeLib/Songs/CSong.cs @@ -147,6 +147,8 @@ namespace VocaluxeLib.Songs public readonly List Language = new List(); + public string DateAdded = ""; + // Notes public readonly CNotes Notes = new CNotes(); @@ -240,6 +242,8 @@ namespace VocaluxeLib.Songs foreach (string value in song.Language) Language.Add(value); + DateAdded = song.DateAdded; + Notes = new CNotes(song.Notes); }