diff --git a/LiaoTian_Cup/Helper/DbHelper.cs b/LiaoTian_Cup/Helper/DbHelper.cs index ab19911..c88e83e 100644 --- a/LiaoTian_Cup/Helper/DbHelper.cs +++ b/LiaoTian_Cup/Helper/DbHelper.cs @@ -1,46 +1,41 @@ using System; using System.Collections.Generic; -using System.Data.SQLite; +using Microsoft.Data.Sqlite; namespace LiaoTian_Cup.Helper; public class DbHelper { - private const string ConnectionString = @"Data Source=./Resources/database.db;"; - - private static readonly SQLiteConnection Conn = new SQLiteConnection(ConnectionString); - public static List GetColumnData(string tableName, List list) { - Conn.Open(); - try + using var connection = new SqliteConnection("Data Source=./Resources/database.db"); + connection.Open(); + + var command = connection.CreateCommand(); + command.CommandText = $"SELECT * FROM {tableName}"; + + using (var reader = command.ExecuteReader()) { - using SQLiteCommand cmd = new SQLiteCommand(Conn); - cmd.CommandText = $"SELECT * FROM {tableName}"; - using SQLiteDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { - var str = Convert.ToString(reader[0]); - list.Add(str); + list.Add(Convert.ToString(reader[0])); } } - catch (Exception ex) - { - throw new Exception(ex.Message); - } - Conn.Close(); + connection.Close(); return list; } public static List GetListData(string tableName,int columnCount, List list) { - Conn.Open(); - try + using var connection = new SqliteConnection("Data Source=./Resources/database.db"); + connection.Open(); + + var command = connection.CreateCommand(); + command.CommandText = $"SELECT * FROM {tableName}"; + + using (var reader = command.ExecuteReader()) { - using SQLiteCommand cmd = new SQLiteCommand(Conn); - cmd.CommandText = $"SELECT * FROM {tableName}"; - using SQLiteDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { string[] rowStrings = new string[columnCount]; @@ -51,12 +46,7 @@ public static List GetListData(string tableName,int columnCount, List< list.Add(rowStrings); } } - catch (Exception ex) - { - throw new Exception(ex.Message); - } - - Conn.Close(); + connection.Close(); return list; } } \ No newline at end of file diff --git a/LiaoTian_Cup/Helper/LogHelper.cs b/LiaoTian_Cup/Helper/LogHelper.cs index c4e3969..3d27cfb 100644 --- a/LiaoTian_Cup/Helper/LogHelper.cs +++ b/LiaoTian_Cup/Helper/LogHelper.cs @@ -1,10 +1,6 @@ using log4net.Config; using System; -using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace LiaoTian_Cup.Helper { diff --git a/LiaoTian_Cup/LiaoTian_Cup.csproj b/LiaoTian_Cup/LiaoTian_Cup.csproj index dfc3c7f..4837292 100644 --- a/LiaoTian_Cup/LiaoTian_Cup.csproj +++ b/LiaoTian_Cup/LiaoTian_Cup.csproj @@ -1,19 +1,20 @@  - WinExe - net6.0-windows - enable + WinExe + net6.0-windows + enable true - false - win-x64 - true - Resources\Logo\icon.ico - 0.2.3 - B1ackSand - app.manifest - README.md - x64 + false + win-x64 + true + Resources\Logo\icon.ico + 0.2.3 + B1ackSand + app.manifest + README.md + x64 + embedded @@ -188,16 +189,17 @@ - + True \ - + Always + - + Always - + Always @@ -248,7 +250,7 @@ - + diff --git a/LiaoTian_Cup/MainWindow.xaml.cs b/LiaoTian_Cup/MainWindow.xaml.cs index 0607db7..de7d4b6 100644 --- a/LiaoTian_Cup/MainWindow.xaml.cs +++ b/LiaoTian_Cup/MainWindow.xaml.cs @@ -1,4 +1,5 @@ -using System.Windows; +using System.Reflection; +using System.Windows; using LiaoTian_Cup.Helper; namespace LiaoTian_Cup