挪動查詢至SQLSearch
This commit is contained in:
parent
6e8b2a36db
commit
8d66c5e408
@ -1,3 +1,8 @@
|
|||||||
|
using DBObj;
|
||||||
|
using MySqlConnector;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace DualScreenDemo
|
namespace DualScreenDemo
|
||||||
{
|
{
|
||||||
public partial class PrimaryForm
|
public partial class PrimaryForm
|
||||||
@ -42,6 +47,8 @@ namespace DualScreenDemo
|
|||||||
private Button keYuButton;
|
private Button keYuButton;
|
||||||
private Bitmap keYuNormalBackground;
|
private Bitmap keYuNormalBackground;
|
||||||
private Bitmap keYuActiveBackground;
|
private Bitmap keYuActiveBackground;
|
||||||
|
|
||||||
|
// 語別查詢 query LIMIT 100 可更改
|
||||||
|
|
||||||
private void LanguageSongSelectionButton_Click(object sender, EventArgs e)
|
private void LanguageSongSelectionButton_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
@ -66,9 +73,8 @@ namespace DualScreenDemo
|
|||||||
hanYuButton.BackgroundImage = hanYuNormalBackground;
|
hanYuButton.BackgroundImage = hanYuNormalBackground;
|
||||||
keYuButton.BackgroundImage = keYuNormalBackground;
|
keYuButton.BackgroundImage = keYuNormalBackground;
|
||||||
|
|
||||||
guoYuSongs = allSongs.Where(song => song.Category == "國語")
|
string query = $"SELECT * FROM SongLibrary WHERE `語別` = '國語' ORDER BY `點播次數` DESC LIMIT 100;";
|
||||||
.OrderByDescending(song => song.Plays)
|
var guoYuSongs = SearchSongs_Mysql(query);
|
||||||
.ToList();
|
|
||||||
currentPage = 0;
|
currentPage = 0;
|
||||||
currentSongList = guoYuSongs;
|
currentSongList = guoYuSongs;
|
||||||
totalPages = (int)Math.Ceiling((double)guoYuSongs.Count / itemsPerPage);
|
totalPages = (int)Math.Ceiling((double)guoYuSongs.Count / itemsPerPage);
|
||||||
@ -115,11 +121,11 @@ namespace DualScreenDemo
|
|||||||
|
|
||||||
|
|
||||||
activeButton.BackgroundImage = activeBackground;
|
activeButton.BackgroundImage = activeBackground;
|
||||||
|
string query = $"SELECT * FROM SongLibrary WHERE `語別` = '{category}' ORDER BY `點播次數` DESC LIMIT 100;";
|
||||||
|
var selectedSongs = SearchSongs_Mysql(query);
|
||||||
var selectedSongs = allSongs.Where(song => song.Category == category)
|
/*var selectedSongs = allSongs.Where(song => song.Category == category)
|
||||||
.OrderByDescending(song => song.Plays)
|
.OrderByDescending(song => song.Plays)
|
||||||
.ToList();
|
.ToList();*/
|
||||||
currentPage = 0;
|
currentPage = 0;
|
||||||
currentSongList = selectedSongs;
|
currentSongList = selectedSongs;
|
||||||
totalPages = (int)Math.Ceiling((double)selectedSongs.Count / itemsPerPage);
|
totalPages = (int)Math.Ceiling((double)selectedSongs.Count / itemsPerPage);
|
||||||
|
87
PrimaryFormParts/PrimaryForm.SQLSearch.cs
Normal file
87
PrimaryFormParts/PrimaryForm.SQLSearch.cs
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
using MySqlConnector;
|
||||||
|
using DBObj;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.IO;
|
||||||
|
namespace DualScreenDemo{
|
||||||
|
public partial class PrimaryForm
|
||||||
|
{
|
||||||
|
public List<SongData> SearchSongs_Mysql(string query)
|
||||||
|
{
|
||||||
|
List<SongData> searchResults = new List<SongData>();
|
||||||
|
Console.WriteLine(query);
|
||||||
|
string connectionString = "Server=192.168.22.170;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))
|
||||||
|
{
|
||||||
|
|
||||||
|
using (var reader = command.ExecuteReader())
|
||||||
|
{
|
||||||
|
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 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,
|
||||||
|
songFilePathHost1, songFilePathHost2,
|
||||||
|
phoneticNotation, pinyinNotation,
|
||||||
|
artistAPhonetic, artistBPhonetic,
|
||||||
|
artistASimplified, artistBSimplified,
|
||||||
|
songSimplified, songGenre,
|
||||||
|
artistAPinyin, artistBPinyin,
|
||||||
|
humanVoice
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
connection.Close();
|
||||||
|
Console.WriteLine("MyDB 連線已關閉!");
|
||||||
|
}
|
||||||
|
|
||||||
|
return searchResults;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -3489,7 +3489,7 @@ public class MultiPagePanel : Panel
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string filePath = Path.Combine(Application.StartupPath, "ButtonImages", imageName);
|
string filePath = Path.Combine(Application.StartupPath, "themes", "superstar", "ButtonImages", imageName);
|
||||||
if (File.Exists(filePath))
|
if (File.Exists(filePath))
|
||||||
{
|
{
|
||||||
return Image.FromFile(filePath);
|
return Image.FromFile(filePath);
|
||||||
|
@ -143,82 +143,5 @@ namespace DualScreenDemo
|
|||||||
1214, 544, 209, 58, ref numberSearchSongNormalBackground, ref numberSearchSongActiveBackground,
|
1214, 544, 209, 58, ref numberSearchSongNormalBackground, ref numberSearchSongActiveBackground,
|
||||||
normalStateImageSongQuery, mouseDownImageSongQuery, SongIDSearchSongsButton_Click);
|
normalStateImageSongQuery, mouseDownImageSongQuery, SongIDSearchSongsButton_Click);
|
||||||
}
|
}
|
||||||
public List<SongData> SearchSongs_Mysql(string query)
|
|
||||||
{
|
|
||||||
List<SongData> searchResults = new List<SongData>();
|
|
||||||
Console.WriteLine(query);
|
|
||||||
string connectionString = "Server=192.168.22.170;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))
|
|
||||||
{
|
|
||||||
|
|
||||||
using (var reader = command.ExecuteReader())
|
|
||||||
{
|
|
||||||
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 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,
|
|
||||||
songFilePathHost1, songFilePathHost2,
|
|
||||||
phoneticNotation, pinyinNotation,
|
|
||||||
artistAPhonetic, artistBPhonetic,
|
|
||||||
artistASimplified, artistBSimplified,
|
|
||||||
songSimplified, songGenre,
|
|
||||||
artistAPinyin, artistBPinyin,
|
|
||||||
humanVoice
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
connection.Close();
|
|
||||||
Console.WriteLine("MyDB 連線已關閉!");
|
|
||||||
}
|
|
||||||
|
|
||||||
return searchResults;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user