diff --git a/OverlayFormObj/OverlayForm.cs b/OverlayFormObj/OverlayForm.cs index 0cf8f7d..f3ac602 100644 --- a/OverlayFormObj/OverlayForm.cs +++ b/OverlayFormObj/OverlayForm.cs @@ -1564,6 +1564,12 @@ private void DisplayArtists(List artists, int page)//歌星點進去後 PrimaryForm.PrintPlayingSongList(); stopwatch.Stop(); Console.WriteLine($"[6] 更新下一首與印出列表花費: {stopwatch.ElapsedMilliseconds} ms"); + + // 點播次數+1 + stopwatch.Restart(); + PrimaryForm.Instance.AddSongCount(songData.SongNumber); + stopwatch.Stop(); + Console.WriteLine($"[7] 新增點播次數花費: {stopwatch.ElapsedMilliseconds} ms"); } } catch (Exception ex) diff --git a/PrimaryFormParts/PrimaryForm.SQLSearch.cs b/PrimaryFormParts/PrimaryForm.SQLSearch.cs index 826eedd..462b751 100644 --- a/PrimaryFormParts/PrimaryForm.SQLSearch.cs +++ b/PrimaryFormParts/PrimaryForm.SQLSearch.cs @@ -177,6 +177,33 @@ namespace DualScreenDemo{ File.AppendAllText(logFilePath, data); } + public void AddSongCount(string id){ + string query = $"UPDATE songs SET song_counts = song_counts+1 WHERE id = '{id}';"; + Console.WriteLine(query); + string connectionString = "Server=192.168.11.4;Port=3306;Database=Karaoke-Kingpin;User=Karaoke-Kingpin;Password=ESM7yTPMnavFmbBH;"; + + using (var connection = new MySqlConnection(connectionString)) + { + + connection.Open(); + Console.WriteLine("MyDB 連線成功!"); + + using (var command = new MySqlCommand(query, connection)) + { + int rowsAffected = command.ExecuteNonQuery(); + if (rowsAffected > 0) + { + Console.WriteLine("新增成功!"); + } + else + { + Console.WriteLine("新增失敗(點播次數沒有新增)"); + } + } + connection.Close(); + Console.WriteLine("MyDB 連線已關閉!"); + } + } }