From 37891877377e624f7138e6c6075bdf6cd8650a0e Mon Sep 17 00:00:00 2001 From: Nexusls Date: Wed, 12 Mar 2025 10:42:44 +0100 Subject: [PATCH] MOD: MainWindow add connection to database (can be decoupled from MW later on) --- PrototypWPFHAG/MainWindow.xaml.cs | 47 +++++++++++++++++++++++++++- PrototypWPFHAG/PrototypWPFHAG.csproj | 4 +-- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/PrototypWPFHAG/MainWindow.xaml.cs b/PrototypWPFHAG/MainWindow.xaml.cs index 565655a..233ae88 100644 --- a/PrototypWPFHAG/MainWindow.xaml.cs +++ b/PrototypWPFHAG/MainWindow.xaml.cs @@ -1,4 +1,5 @@ -using System.Text; +using System.Data; +using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; @@ -9,6 +10,8 @@ using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using MahApps.Metro.Controls; +using Npgsql; +using Npgsql.Replication; namespace PrototypWPFHAG; @@ -20,5 +23,47 @@ public partial class MainWindow : MetroWindow public MainWindow() { InitializeComponent(); + + TestConnection(); + Console.ReadKey(); + } + + private static void TestConnection() + { + using (NpgsqlConnection con = GetConnection()) + { + con.Open(); + if (con.State == ConnectionState.Open) + { + Console.WriteLine("Connected to Server"); + } + } + } + private static NpgsqlConnection GetConnection() + { + return new NpgsqlConnection(@"Server=localhost;Port=5432;User Id=postgres;Password=postgres;Database=postgres;"); + } + + //class Program + //{ + // static void Main(string[] args) + // { + // TestConnection(); + // Console.ReadKey(); + // } + // private static void TestConnection() + // { + // using(NpgsqlConnection con = GetConnection()){ + // con.Open(); + // if (con.State == ConnectionState.Open) { + // Console.WriteLine("Connected to Server"); + // } + // } + // } + // private static NpgsqlConnection GetConnection() + // { + // return new NpgsqlConnection(@"Server=localhost;Port=5432;User Id=postgres;Password=postgres;Database=TestServer;"); + // } + //} } \ No newline at end of file diff --git a/PrototypWPFHAG/PrototypWPFHAG.csproj b/PrototypWPFHAG/PrototypWPFHAG.csproj index b1e5e62..442484f 100644 --- a/PrototypWPFHAG/PrototypWPFHAG.csproj +++ b/PrototypWPFHAG/PrototypWPFHAG.csproj @@ -1,8 +1,8 @@  - WinExe - net8.0-windows + Exe + net9.0-windows enable enable true