Skip to content
This repository has been archived by the owner on Feb 3, 2024. It is now read-only.

Commit

Permalink
fix database bug;
Browse files Browse the repository at this point in the history
  • Loading branch information
B1ackSand committed Oct 4, 2023
1 parent c2cf2fa commit 085d52d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 50 deletions.
46 changes: 18 additions & 28 deletions LiaoTian_Cup/Helper/DbHelper.cs
Original file line number Diff line number Diff line change
@@ -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<string> GetColumnData(string tableName, List<string> 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<string[]> GetListData(string tableName,int columnCount, List<string[]> 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];
Expand All @@ -51,12 +46,7 @@ public static List<string[]> GetListData(string tableName,int columnCount, List<
list.Add(rowStrings);
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}

Conn.Close();
connection.Close();
return list;
}
}
4 changes: 0 additions & 4 deletions LiaoTian_Cup/Helper/LogHelper.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
36 changes: 19 additions & 17 deletions LiaoTian_Cup/LiaoTian_Cup.csproj
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<PublishSingleFile>true</PublishSingleFile>
<SelfContained>false</SelfContained>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<UseWPF>true</UseWPF>
<ApplicationIcon>Resources\Logo\icon.ico</ApplicationIcon>
<Version>0.2.3</Version>
<Authors>B1ackSand</Authors>
<ApplicationManifest>app.manifest</ApplicationManifest>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PlatformTarget>x64</PlatformTarget>
<SelfContained>false</SelfContained>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<UseWPF>true</UseWPF>
<ApplicationIcon>Resources\Logo\icon.ico</ApplicationIcon>
<Version>0.2.3</Version>
<Authors>B1ackSand</Authors>
<ApplicationManifest>app.manifest</ApplicationManifest>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PlatformTarget>x64</PlatformTarget>
<DebugType>embedded</DebugType>
</PropertyGroup>

<ItemGroup>
Expand Down Expand Up @@ -188,16 +189,17 @@
</ItemGroup>

<ItemGroup>
<None Include="..\README.md">
<Content Include="..\README.md">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<Content Include="Resources\database.db">
<EmbeddedResource Include="Resources\database.db">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</EmbeddedResource>
<Resource Include="Resources\factor\力量退变.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
Expand Down Expand Up @@ -248,7 +250,7 @@
<ItemGroup>
<PackageReference Include="DeepCloner" Version="0.10.4" />
<PackageReference Include="log4net" Version="2.0.15" />
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.118" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="7.0.11" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion LiaoTian_Cup/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Windows;
using System.Reflection;
using System.Windows;
using LiaoTian_Cup.Helper;

namespace LiaoTian_Cup
Expand Down

0 comments on commit 085d52d

Please sign in to comment.