diff --git a/ClickSequenceState.cs b/ClickSequenceState.cs deleted file mode 100644 index 212e055..0000000 --- a/ClickSequenceState.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace DualScreenDemo -{ - - public enum ClickSequenceState - { - Initial, - FirstClicked, - SecondClicked, - ThirdClicked, - Completed - } -} \ No newline at end of file diff --git a/CommandHandler.cs b/CommandHandler.cs index b379258..ec67db5 100644 --- a/CommandHandler.cs +++ b/CommandHandler.cs @@ -540,8 +540,9 @@ namespace DualScreenDemo ClearDisplay(); // 設定歌曲總數為已播放歌曲的數量 - List historySongs = SongList.GetHistory(); - OverlayForm.MainForm.totalSongs = historySongs.Count; + List history= SongList.GetHistory(); + List historySongs = new List(); + OverlayForm.MainForm.totalSongs = SongList.GetHistory().Count; // 若無任何播放紀錄,直接顯示訊息並返回,不執行後續動作 if (OverlayForm.MainForm.totalSongs == 0) @@ -558,6 +559,9 @@ namespace DualScreenDemo int endIndex = Math.Min(startIndex + OverlayForm.MainForm.songsPerPage, OverlayForm.MainForm.totalSongs); // 準備要傳給 UpdateHistoryLabel 的兩個清單:歌曲資料與播放狀態 + for (int i = startIndex; i < endIndex; i++) { + historySongs.Add(history[i]); + } // 錨點 遙控器 diff --git a/DBObj/MyDB.cs b/DBObj/MyDB.cs new file mode 100644 index 0000000..f0d442e --- /dev/null +++ b/DBObj/MyDB.cs @@ -0,0 +1,59 @@ +using System; +using System.Data; +using MySqlConnector; + +namespace DBObj +{ + public class MyDB : IDisposable + { + private readonly string connectionString = Utils.Env.GetDBConnection(); + private MySqlConnection conn; + + public MyDB() + { + conn = new MySqlConnection(connectionString); + conn.Open(); + Console.WriteLine("MyDB 連線成功!"); + } + + public void Dispose() + { + if (conn != null) + { + conn.Close(); + Console.WriteLine("MyDB 連線已關閉!"); + } + } + + // SELECT 方法 + public DataTable Select(string query, MySqlParameter[] parameters) + { + using (var cmd = new MySqlCommand(query, conn)) + { + if (parameters != null) + { + cmd.Parameters.AddRange(parameters); + } + using (var adapter = new MySqlDataAdapter(cmd)) + { + DataTable result = new DataTable(); + adapter.Fill(result); + return result; + } + } + } + + // INSERT / UPDATE / DELETE 方法 + public int ExecuteNonQuery(string query, MySqlParameter[] parameters) + { + using (var cmd = new MySqlCommand(query, conn)) + { + if (parameters != null) + { + cmd.Parameters.AddRange(parameters); + } + return cmd.ExecuteNonQuery(); + } + } + } +} diff --git a/DBObj/SongListManager.cs b/DBObj/SongListManager.cs index e7f97c1..50a9e97 100644 --- a/DBObj/SongListManager.cs +++ b/DBObj/SongListManager.cs @@ -1,9 +1,11 @@ +using System.Data; using DualScreenDemo; namespace DBObj { public class SongListManager { - public List FavoriteSongs { get; private set; } + private MyDB db = new MyDB(); + public List FavoriteSongs { get; private set; } //public bool IsUserLoggedIn { get; set; } //public string UserPhoneNumber { get; set; } public SongListManager() @@ -76,6 +78,32 @@ namespace DBObj var searchResults =PrimaryForm.Instance.SearchSongs_Mysql(query); return searchResults.FirstOrDefault(); } + private List select_Mysql(string query) + { + List searchResults = new List(); + Console.WriteLine(query); + using (db) + { + DataTable result = db.Select(query, null); + foreach (DataRow row in result.Rows) + { + searchResults.Add(new SongData( + row["song_id"].ToString(), + row["song_name"].ToString(), + row["artistA"].ToString(), + row["artistB"].ToString(), + row["song_filename"].ToString(), + row["artistA_simplified"].ToString(), + row["artistB_simplified"].ToString(), + row["song_simplified"].ToString(), + Convert.ToInt32(row["vocal"]) + )); + } + Console.WriteLine($"查詢到 {searchResults.Count} 筆資料。"); + } + + return searchResults; + } } } \ No newline at end of file diff --git a/DualScreenDemo.Shared.cs b/DualScreenDemo.Shared.cs deleted file mode 100644 index 5c3810d..0000000 --- a/DualScreenDemo.Shared.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace DualScreenDemo.Shared -{ - public class VideoStatus - { - public bool IsGraphOk { get; set; } - public string LastError { get; set; } - public double PositionSeconds { get; set; } - public string PlayState { get; set; } - } -} diff --git a/FilterEnumerator.cs b/FilterEnumerator.cs deleted file mode 100644 index 8ab416f..0000000 --- a/FilterEnumerator.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System.Runtime.InteropServices; -using System.Runtime.InteropServices.ComTypes; -using DirectShowLib; - -namespace DualScreenDemo -{ - public class FilterEnumerator - { - private static readonly Guid IID_IPropertyBag = new Guid("55272A00-42CB-11CE-8135-00AA004BB851"); - - public void EnumerateFilters() - { - ICreateDevEnum createDevEnum = (ICreateDevEnum)new CreateDevEnum(); - IEnumMoniker enumMoniker; - int hr = createDevEnum.CreateClassEnumerator(FilterCategory.LegacyAmFilterCategory, out enumMoniker, 0); - if (hr != 0 || enumMoniker == null) - { - Console.WriteLine("No filters found."); - return; - } - - IMoniker[] monikers = new IMoniker[1]; - IntPtr fetched = Marshal.AllocHGlobal(sizeof(int)); - while (enumMoniker.Next(1, monikers, fetched) == 0) - { - int fetchedCount = Marshal.ReadInt32(fetched); - if (fetchedCount > 0) - { - object objPropBag; - Guid tempGuid = IID_IPropertyBag; - monikers[0].BindToStorage(null, null, ref tempGuid, out objPropBag); - IPropertyBag propBag = objPropBag as IPropertyBag; - - object filterName = null; - if (propBag != null) - { - propBag.Read("FriendlyName", out filterName, null); - } - - if (filterName != null) - { - Console.WriteLine("Filter: " + filterName.ToString()); - } - - Marshal.ReleaseComObject(monikers[0]); - } - } - Marshal.ReleaseComObject(enumMoniker); - Marshal.FreeHGlobal(fetched); - } - } -} \ No newline at end of file diff --git a/FormatTypes.cs b/FormatTypes.cs deleted file mode 100644 index 99202c0..0000000 --- a/FormatTypes.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace DualScreenDemo -{ - public static class FormatTypes - { - public static readonly Guid VideoInfo = new Guid("05589F80-C356-11CE-BF01-00AA0055595A"); - public static readonly Guid WaveEx = new Guid("05589f81-c356-11ce-bf01-00aa0055595a"); - } -} \ No newline at end of file diff --git a/MediaSubTypes.cs b/MediaSubTypes.cs deleted file mode 100644 index 8e1944a..0000000 --- a/MediaSubTypes.cs +++ /dev/null @@ -1,5 +0,0 @@ -public static class MediaSubTypes -{ - public static readonly Guid YUY2 = new Guid("32595559-0000-0010-8000-00AA00389B71"); - public static readonly Guid IEEE_FLOAT = new Guid("00000003-0000-0010-8000-00AA00389B71"); -} \ No newline at end of file diff --git a/MediaTypes.cs b/MediaTypes.cs deleted file mode 100644 index 767b478..0000000 --- a/MediaTypes.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace DualScreenDemo -{ - public static class MediaTypes - { - public static readonly Guid Video = new Guid("73646976-0000-0010-8000-00AA00389B71"); - public static readonly Guid Audio = new Guid("73647561-0000-0010-8000-00AA00389B71"); - } -} \ No newline at end of file diff --git a/OverlayFormObj/OverlayForm.Labels.cs b/OverlayFormObj/OverlayForm.Labels.cs index 582403f..b14e314 100644 --- a/OverlayFormObj/OverlayForm.Labels.cs +++ b/OverlayFormObj/OverlayForm.Labels.cs @@ -7,7 +7,7 @@ namespace OverlayFormObj public partial class OverlayForm { public Label displayLabel; - public Label songDisplayLabel; + //public Label songDisplayLabel; private List