Add project files.
This commit is contained in:
25
SQLite_test.sln
Normal file
25
SQLite_test.sln
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.13.35919.96 d17.13
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SQLite_test", "SQLite_test\SQLite_test.csproj", "{164810E3-EA38-48C7-834F-3252AC1C9069}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{164810E3-EA38-48C7-834F-3252AC1C9069}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{164810E3-EA38-48C7-834F-3252AC1C9069}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{164810E3-EA38-48C7-834F-3252AC1C9069}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{164810E3-EA38-48C7-834F-3252AC1C9069}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {BA6C2E1F-3F6F-4F8C-81CB-E4DB2F060DE2}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
9
SQLite_test/App.xaml
Normal file
9
SQLite_test/App.xaml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<Application x:Class="SQLite_test.App"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:local="clr-namespace:SQLite_test"
|
||||||
|
StartupUri="MainWindow.xaml">
|
||||||
|
<Application.Resources>
|
||||||
|
|
||||||
|
</Application.Resources>
|
||||||
|
</Application>
|
||||||
14
SQLite_test/App.xaml.cs
Normal file
14
SQLite_test/App.xaml.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
using System.Configuration;
|
||||||
|
using System.Data;
|
||||||
|
using System.Windows;
|
||||||
|
|
||||||
|
namespace SQLite_test
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Interaction logic for App.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class App : Application
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
10
SQLite_test/AssemblyInfo.cs
Normal file
10
SQLite_test/AssemblyInfo.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
using System.Windows;
|
||||||
|
|
||||||
|
[assembly: ThemeInfo(
|
||||||
|
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
|
||||||
|
//(used if a resource is not found in the page,
|
||||||
|
// or application resource dictionaries)
|
||||||
|
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
|
||||||
|
//(used if a resource is not found in the page,
|
||||||
|
// app, or any theme specific resource dictionaries)
|
||||||
|
)]
|
||||||
57
SQLite_test/Classes/Crud.cs
Normal file
57
SQLite_test/Classes/Crud.cs
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data.Entity.Migrations.Model;
|
||||||
|
using System.Data.SQLite;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SQLite_test.Classes
|
||||||
|
{
|
||||||
|
internal class Crud
|
||||||
|
{
|
||||||
|
|
||||||
|
private SQLiteConnection _connection;
|
||||||
|
string connectionString = "Data Source=mydatabase.db;Version=3;";
|
||||||
|
|
||||||
|
|
||||||
|
// Connection to the database would be established here
|
||||||
|
public Crud()
|
||||||
|
{
|
||||||
|
// Initialize database connection or any other setup
|
||||||
|
_connection = new SQLiteConnection(connectionString);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_connection.Open();
|
||||||
|
Debug.WriteLine("Verbinding met de database is geopend!");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Debug.WriteLine($"Fout bij het openen van de database: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void Add()
|
||||||
|
{
|
||||||
|
// implement Add logic here
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void Create()
|
||||||
|
{
|
||||||
|
// Implement create logic here
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void Read()
|
||||||
|
{
|
||||||
|
// Implement read logic here
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void Delete()
|
||||||
|
{
|
||||||
|
// Implement delete logic here
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
36
SQLite_test/Classes/User.cs
Normal file
36
SQLite_test/Classes/User.cs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SQLite_test.Classes
|
||||||
|
{
|
||||||
|
internal class User : Crud
|
||||||
|
{
|
||||||
|
|
||||||
|
// call inherited methods from Crud class
|
||||||
|
public void AddUser()
|
||||||
|
{
|
||||||
|
Add();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CreateUser()
|
||||||
|
{
|
||||||
|
Create();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ReadUser()
|
||||||
|
{
|
||||||
|
Read();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DeleteUser()
|
||||||
|
{
|
||||||
|
Delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
19
SQLite_test/MainWindow.xaml
Normal file
19
SQLite_test/MainWindow.xaml
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<Window x:Class="SQLite_test.MainWindow"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:local="clr-namespace:SQLite_test"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
Title="MainWindow" Height="450" Width="800">
|
||||||
|
<Grid>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="*" />
|
||||||
|
<RowDefinition Height="*" />
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<StackPanel Grid.Row="0">
|
||||||
|
<Button Click="AddRow" Height="100px" Content="Add"/>
|
||||||
|
<Button Click="DeleteRow" Height="100px" Content="Delete"/>
|
||||||
|
</StackPanel>
|
||||||
|
</Grid>
|
||||||
|
</Window>
|
||||||
92
SQLite_test/MainWindow.xaml.cs
Normal file
92
SQLite_test/MainWindow.xaml.cs
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
using System.Data.SQLite;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Text;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Data;
|
||||||
|
using System.Windows.Documents;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
using System.Windows.Navigation;
|
||||||
|
using System.Windows.Shapes;
|
||||||
|
|
||||||
|
namespace SQLite_test
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Interaction logic for MainWindow.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class MainWindow : Window
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
private SQLiteConnection _connection;
|
||||||
|
public MainWindow()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
CreateConnectionToDB();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CreateConnectionToDB()
|
||||||
|
{
|
||||||
|
|
||||||
|
Classes.User user = new Classes.User();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
string connectionString = "Data Source=mydatabase.db;Version=3;";
|
||||||
|
_connection = new SQLiteConnection(connectionString);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_connection.Open();
|
||||||
|
Debug.WriteLine("Verbinding met de database is geopend!");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Debug.WriteLine($"Fout bij het openen van de database: {ex.Message}");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private void AddRow(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
// first create a table in database if not exists
|
||||||
|
CreateConnectionToDB();
|
||||||
|
|
||||||
|
string tablename = "Users";
|
||||||
|
string createTableQuery = ($"CREATE TABLE IF NOT EXISTS {tablename} (Id INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT, Age INT)");
|
||||||
|
using (SQLiteCommand command = new SQLiteCommand(createTableQuery, _connection))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
command.ExecuteNonQuery();
|
||||||
|
Debug.WriteLine("Tabel is aangemaakt of bestaat al.");
|
||||||
|
// Now insert a new row
|
||||||
|
string insertQuery = $"INSERT INTO {tablename} (Name, Age) VALUES (@Name, @Age)";
|
||||||
|
using (SQLiteCommand insertCommand = new SQLiteCommand(insertQuery, _connection))
|
||||||
|
{
|
||||||
|
insertCommand.Parameters.AddWithValue("@Name", "Nieuwe Naam");
|
||||||
|
insertCommand.Parameters.AddWithValue("@Age", 18);
|
||||||
|
insertCommand.ExecuteNonQuery();
|
||||||
|
Debug.WriteLine("Nieuwe user is toegevoegd.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Debug.WriteLine($"Fout bij het aanmaken van de tabel: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DeleteRow(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
// inputbox
|
||||||
|
string input = Microsoft.VisualBasic.Interaction.InputBox("Voer de ID in van de rij die u wilt verwijderen:", "Rij Verwijderen", "", -1, -1);
|
||||||
|
Debug.WriteLine($"Input: {input}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
15
SQLite_test/SQLite_test.csproj
Normal file
15
SQLite_test/SQLite_test.csproj
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>WinExe</OutputType>
|
||||||
|
<TargetFramework>net8.0-windows</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<UseWPF>true</UseWPF>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="System.Data.SQLite" Version="1.0.119" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
Reference in New Issue
Block a user