song class 修改

This commit is contained in:
jasonchenwork 2025-04-21 11:33:31 +08:00
parent db9ab8231f
commit b5f46e2f27
7 changed files with 79 additions and 143 deletions

View File

@ -25,30 +25,45 @@ namespace DBObj
public string ArtistBPinyin { get; set; }
public int HumanVoice { get; set; }
/*
public SongData(string songNumber, string category, string song, double plays, string artistA, string artistB, string artistACategory, string artistBCategory, DateTime addedTime, string songFilePathHost1, string songFilePathHost2, string phoneticNotation, string pinyinNotation, string artistAPhonetic, string artistBPhonetic, string artistASimplified, string artistBSimplified, string songSimplified, string songGenre, string artistAPinyin, string artistBPinyin, int humanVoice)
{
SongNumber = songNumber;
Category = category;
// Category = category;
Song = song;
Plays = plays;
// Plays = plays;
ArtistA = artistA;
ArtistB = artistB;
ArtistACategory = artistACategory;
ArtistBCategory = artistBCategory;
AddedTime = addedTime;
//ArtistACategory = artistACategory;
//ArtistBCategory = artistBCategory;
//AddedTime = addedTime;
SongFilePathHost1 = songFilePathHost1;
SongFilePathHost2 = songFilePathHost2;
//PhoneticNotation = phoneticNotation;
//PinyinNotation = pinyinNotation;
//ArtistAPhonetic = artistAPhonetic;
//ArtistBPhonetic = artistBPhonetic;
ArtistASimplified = artistASimplified;
ArtistBSimplified = artistBSimplified;
SongSimplified = songSimplified;
//SongGenre = songGenre;
//ArtistAPinyin = artistAPinyin;
//ArtistBPinyin = artistBPinyin;
HumanVoice = humanVoice;
}
*/
public SongData(string songNumber, string song, string artistA, string artistB, string songFilePathHost1, string songFilePathHost2, string artistASimplified, string artistBSimplified, string songSimplified, int humanVoice)
{
SongNumber = songNumber;
Song = song;
ArtistA = artistA;
ArtistB = artistB;
SongFilePathHost1 = songFilePathHost1;
SongFilePathHost2 = songFilePathHost2;
PhoneticNotation = phoneticNotation;
PinyinNotation = pinyinNotation;
ArtistAPhonetic = artistAPhonetic;
ArtistBPhonetic = artistBPhonetic;
ArtistASimplified = artistASimplified;
ArtistBSimplified = artistBSimplified;
SongSimplified = songSimplified;
SongGenre = songGenre;
ArtistAPinyin = artistAPinyin;
ArtistBPinyin = artistBPinyin;
HumanVoice = humanVoice;
}

View File

@ -110,55 +110,6 @@ namespace DBObj
return AllSongs.Where(song => song.ArtistA == artistName || song.ArtistB == artistName).ToList();
}
public bool CheckIfPhoneNumberExists(string phoneNumber)
{
string databaseFileName = "KSongDatabase.db";
string databasePath = Path.Combine(Application.StartupPath, "db", databaseFileName);
string connectionString = String.Format("Data Source={0};Version=3;", databasePath);
using (var connection = new SQLiteConnection(connectionString))
{
try
{
connection.Open();
string sql = "SELECT COUNT(1) FROM FavoriteSongs WHERE PhoneNumber = @PhoneNumber";
using (var command = new SQLiteCommand(sql, connection))
{
command.Parameters.AddWithValue("@PhoneNumber", phoneNumber);
int count = Convert.ToInt32(command.ExecuteScalar());
return count > 0;
}
}
catch (Exception ex)
{
Console.WriteLine("Failed to check phone number in SQLite database: " + ex.Message);
return false;
}
finally
{
connection.Close();
}
}
}
public void UserLogin(string phoneNumber)
{
IsUserLoggedIn = true;
UserPhoneNumber = phoneNumber;
LoadFavoriteSongs();
Console.WriteLine(String.Format("UserLoggedIn: {0}, PhoneNumber: {1}", IsUserLoggedIn, UserPhoneNumber));
}
public void UserLogout()
{
IsUserLoggedIn = false;
UserPhoneNumber = null;
FavoriteSongs.Clear();
}
public void InitializeDatabase()
{
string databaseFileName = "KSongDatabase.db";
@ -229,6 +180,7 @@ namespace DBObj
}
}
/*
private void LoadSongs()
{
string databaseFileName = "KSongDatabase.db";
@ -298,7 +250,7 @@ namespace DBObj
}
}
}
public void LoadFavoriteSongs()
{
if (!IsUserLoggedIn || string.IsNullOrEmpty(UserPhoneNumber))
@ -400,7 +352,7 @@ namespace DBObj
}
}
}
*/
public void AddToFavorite(string songNumber)
{
if (!IsUserLoggedIn || string.IsNullOrEmpty(UserPhoneNumber))
@ -555,6 +507,7 @@ namespace DBObj
else
return new List<SongData>();
}
/*
public List<SongData> GetFavoriteSongsByPhoneNumber()
{
List<SongData> favoriteSongs = new List<SongData>();
@ -654,5 +607,6 @@ namespace DBObj
return favoriteSongs;
}
*/
}
}

View File

@ -1060,7 +1060,7 @@ namespace DualScreenDemo
// 启动服务器的公共方法
private static async Task HandleFavoriteRequest(HttpListenerContext context)
{
try
/* try
{
if (PrimaryForm.isPhoneNumberValid && !string.IsNullOrEmpty(PrimaryForm.phonenumber))
{
@ -1144,10 +1144,11 @@ namespace DualScreenDemo
context.Response.ContentType = "application/json";
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
await SendResponseAsyncs(context, jsonResponse);
}
}*/
}
// 异步响应发送方法
/*
private static async Task SendResponseAsyncs(HttpListenerContext context, string responseContent)
{
try
@ -1162,7 +1163,7 @@ namespace DualScreenDemo
Console.WriteLine("Error sending response: " + ex.Message);
}
}
*/
private static async Task HandleGetRequest(HttpListenerContext context, string baseDirectory, string requestedFile)
{
try

View File

@ -33,51 +33,22 @@ namespace DualScreenDemo{
while (reader.Read())
{
string songNumber = reader["歌曲編號"].ToString();
string category = reader["語別"].ToString();
string song = reader["歌曲名稱"].ToString();
int plays = Convert.ToInt32(reader["點播次數"]);
string artistA = reader["歌星 A"].ToString();
string artistB = reader["歌星 B"].ToString();
string artistACategory = reader["歌星A分類"].ToString();
string artistBCategory = reader["歌星B分類"].ToString();
string dateValue = reader["新增日期"]?.ToString() ?? "";
DateTime addedTime;
try
{
addedTime = DateTime.Parse(dateValue, CultureInfo.InvariantCulture).Date;
}
catch
{
addedTime = DateTime.Today;
}
string basePathHost1 = reader["路徑 1"].ToString();
string basePathHost2 = reader["路徑 2"].ToString();
string fileName = reader["歌曲檔名"].ToString();
string songFilePathHost1 = Path.Combine(basePathHost1, fileName);
string songFilePathHost2 = Path.Combine(basePathHost2, fileName);
string phoneticNotation = reader["歌曲注音"].ToString();
string pinyinNotation = reader["歌曲拼音"].ToString();
string artistAPhonetic = reader["歌星A注音"].ToString();
string artistBPhonetic = reader["歌星B注音"].ToString();
string artistASimplified = reader["歌星A簡體"].ToString();
string songFilePathHost1 = Path.Combine("\\SVR01\\DISK01\\", fileName); // \SVR01\DISK01\
string songFilePathHost2 = Path.Combine("\\SVR01\\DISK01\\", fileName); // \SVR02\DISK01\
string artistASimplified = reader["歌星A簡體"].ToString();
string artistBSimplified = reader["歌星B簡體"].ToString();
string songSimplified = reader["歌名簡體"].ToString();
string songGenre = reader["分類"].ToString();
string artistAPinyin = reader["歌星A拼音"].ToString();
string artistBPinyin = reader["歌星B拼音"].ToString();
int humanVoice = Convert.ToInt32(reader["人聲"]);
searchResults.Add(new SongData(
songNumber, category, song, plays, artistA, artistB,
artistACategory, artistBCategory, addedTime,
songNumber, song, artistA, artistB,
songFilePathHost1, songFilePathHost2,
phoneticNotation, pinyinNotation,
artistAPhonetic, artistBPhonetic,
artistASimplified, artistBSimplified,
songSimplified, songGenre,
artistAPinyin, artistBPinyin,
humanVoice
songSimplified, humanVoice
));
}
}

View File

@ -1589,26 +1589,26 @@ namespace DualScreenDemo
SongData song = new SongData(
songNumber, // songNumber
"", // songNumberB
//"", // songNumberB
songName, // song
0, // songLength
//0, // songLength
"", // artistA
"", // artistB
"", // language
"", // category
DateTime.Now, // dateAdded
//"", // language
//"", // category
//DateTime.Now, // dateAdded
songPath, // songFilePathHost1
"", // songFilePathHost2
"", // songFilePathHost3
"", // songFilePathHost4
"", // songFilePathHost5
"", // songFilePathHost6
"", // songFilePathHost7
"", // songFilePathHost8
"", // songFilePathHost9
"", // songFilePathHost10
"", // humanVoice
"", // songType
//"", // songFilePathHost6
//"", // songFilePathHost7
//"", // songFilePathHost8
//"", // songFilePathHost9
//"", // songFilePathHost10
//"", // humanVoice
//"", // songType
1 // priority
);
publicSongList.Add(song);
@ -1617,26 +1617,26 @@ namespace DualScreenDemo
{
SongData song = new SongData(
"", // songNumber
"", // songNumberB
//"", // songNumberB
"", // song
0, // songLength
//0, // songLength
"", // artistA
"", // artistB
"", // language
"", // category
DateTime.Now, // dateAdded
//"", // language
//"", // category
//DateTime.Now, // dateAdded
songPath, // songFilePathHost1
"", // songFilePathHost2
"", // songFilePathHost3
"", // songFilePathHost4
"", // songFilePathHost5
"", // songFilePathHost6
"", // songFilePathHost7
"", // songFilePathHost8
"", // songFilePathHost9
"", // songFilePathHost10
"", // humanVoice
"", // songType
//"", // songFilePathHost6
//"", // songFilePathHost7
//"", // songFilePathHost8
//"", // songFilePathHost9
//"", // songFilePathHost10
//"", // humanVoice
//"", // songType
1 // priority
);
publicSongList.Add(song);

View File

@ -146,9 +146,9 @@ namespace DualScreenDemo
if (File.Exists(closePath))
{
SongData closeSong = new SongData(
"", "", "結束播放", 0, "", "", "", "",
DateTime.Now, closePath, "", "", "", "",
"", "", "", "", "", "", "", 1
"0", "結束播放", "", "",
closePath, "", "", "", "",
1
);
VideoPlayerForm.publicPlaylist = new List<SongData>();
VideoPlayerForm.playingSongList = new List<SongData>();

View File

@ -570,9 +570,8 @@ namespace DualScreenDemo
if (File.Exists(welcomePath))
{
publicPlaylist.Add(new SongData(
"0", "", "歡迎光臨", 0, "", "", "", "",
DateTime.Now, welcomePath, "", "", "", "",
"", "", "", "", "", "", "", 1
"0", "歡迎光臨", "", "", welcomePath,
"", "", "", "", 1
));
}
@ -583,9 +582,8 @@ namespace DualScreenDemo
if (File.Exists(bgmPath))
{
publicPlaylist.Add(new SongData(
i.ToString(), "", $"背景音樂{i:D2}", 0, "", "", "", "",
DateTime.Now, bgmPath, "", "", "", "",
"", "", "", "", "", "", "", 1
i.ToString(), $"背景音樂{i:D2}",
"", "", bgmPath, "", "", "", "", 1
));
}
}
@ -599,9 +597,9 @@ namespace DualScreenDemo
{
string fileName = Path.GetFileNameWithoutExtension(songPath);
publicPlaylist.Add(new SongData(
"0", "", fileName, 0, "", "", "", "",
DateTime.Now, songPath, "", "", "", "",
"", "", "", "", "", "", "", 1
"0", fileName, "", "",
songPath, "", "", "", "",
1
));
}
}
@ -879,9 +877,7 @@ namespace DualScreenDemo
if (File.Exists(welcomePath))
{
publicPlaylist.Add(new SongData(
"0", "", "歡迎光臨", 0, "", "", "", "",
DateTime.Now, welcomePath, "", "", "", "",
"", "", "", "", "", "", "", 1
"0", "歡迎光臨", "", "", welcomePath, "", "", "", "", 1
));
}
@ -892,9 +888,8 @@ namespace DualScreenDemo
if (File.Exists(bgmPath))
{
publicPlaylist.Add(new SongData(
i.ToString(), "", $"背景音樂{i:D2}", 0, "", "", "", "",
DateTime.Now, bgmPath, "", "", "", "",
"", "", "", "", "", "", "", 1
i.ToString(), $"背景音樂{i:D2}", "", "", bgmPath,
"", "", "", "", 1
));
}
}