diff --git a/PrototypWPFHAG/MainWindow.xaml b/PrototypWPFHAG/MainWindow.xaml
index 6a87c50..0deb55e 100644
--- a/PrototypWPFHAG/MainWindow.xaml
+++ b/PrototypWPFHAG/MainWindow.xaml
@@ -12,21 +12,41 @@
TitleCharacterCasing="Normal"
WindowTitleBrush="Firebrick"
Icon="pack://application:,,,/Images/databaseicon.png"
- ResizeMode="CanResizeWithGrip">
+ ResizeMode="CanResizeWithGrip"
+ Loaded="Window_Loaded">
-
-
+
+
+
-
-
-
+
+
+
+
+<<<<<<< HEAD
+=======
+
+
+
+
+
+
+
+
+
+
+>>>>>>> 1195250b98172d34b8c49b85a81c21d1f26cdbac
-
\ No newline at end of file
+
diff --git a/PrototypWPFHAG/MainWindow.xaml.cs b/PrototypWPFHAG/MainWindow.xaml.cs
index 9528ac4..40695ef 100644
--- a/PrototypWPFHAG/MainWindow.xaml.cs
+++ b/PrototypWPFHAG/MainWindow.xaml.cs
@@ -25,46 +25,116 @@ public partial class MainWindow : MetroWindow
public MainWindow()
{
InitializeComponent();
+<<<<<<< HEAD
//TestConnection();
//Console.ReadKey();
}
private static void TestConnection()
+=======
+ }
+
+ private void Window_Loaded(object sender, RoutedEventArgs e)
+ {
+ UsernameTextBox.Focus(); // Focus first TextBox on start
+ }
+
+ private static NpgsqlConnection GetConnection()
+ {
+ return new NpgsqlConnection("Server=localhost;Port=5432;User Id=postgres;Password=postgres;Database=postgres;");
+ }
+
+ private string ValidateUser(string username, string password)
+>>>>>>> 1195250b98172d34b8c49b85a81c21d1f26cdbac
{
using (NpgsqlConnection con = GetConnection())
{
con.Open();
- if (con.State == ConnectionState.Open)
+
+ // Check for correct UserName
+ string userQuery = "SELECT COUNT(*) FROM \"User\" WHERE \"UserName\" = @username";
+ using (NpgsqlCommand userCmd = new NpgsqlCommand(userQuery, con))
{
- Console.WriteLine("Connected to Server");
+ userCmd.Parameters.AddWithValue("@username", username);
+ int userExists = Convert.ToInt32(userCmd.ExecuteScalar());
+
+ if (userExists == 0)
+ {
+ return "Dieser Benutzername existiert nicht";
+ }
+ }
+
+ // Check for correct Password
+ string pwQuery = "SELECT COUNT(*) FROM \"User\" WHERE \"UserName\" = @username AND \"Password\" = @password";
+ using (NpgsqlCommand pwCmd = new NpgsqlCommand(pwQuery, con))
+ {
+ pwCmd.Parameters.AddWithValue("@username", username);
+ pwCmd.Parameters.AddWithValue("@password", password);
+ int correctPassword = Convert.ToInt32(pwCmd.ExecuteScalar());
+
+ if (correctPassword == 0)
+ {
+ return "Falsches Password!";
+ }
}
}
+<<<<<<< HEAD
}
private static NpgsqlConnection GetConnection()
{
return new NpgsqlConnection(@"Server=localhost;Port=7854;User Id=postgres;Database=postgres;");
+=======
+
+ return "Erfolgreich";
+>>>>>>> 1195250b98172d34b8c49b85a81c21d1f26cdbac
}
- //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;");
- // }
- //}
+ private void ShowPasswordButton_PreviewMouseDown(object sender, RoutedEventArgs e)
+ {
+ PasswordVisibleTextBox.Text = PasswordTextBox.Password; // Write password in the visible box
+ PasswordVisibleTextBox.Visibility = Visibility.Visible;
+ PasswordTextBox.Visibility = Visibility.Collapsed;
+ }
+
+ private void ShowPasswordButton_Click(object sender, RoutedEventArgs e)
+ {
+ if (PasswordTextBox.Visibility == Visibility.Visible)
+ {
+ // Show password
+ PasswordVisibleTextBox.Text = PasswordTextBox.Password;
+ PasswordVisibleTextBox.Visibility = Visibility.Visible;
+ PasswordTextBox.Visibility = Visibility.Collapsed;
+ }
+ else
+ {
+ // Hide password
+ PasswordTextBox.Visibility = Visibility.Visible;
+ PasswordVisibleTextBox.Visibility = Visibility.Collapsed;
+ }
+ }
+
+ // Syncs password with visible TextBox
+ private void PasswordTextBox_PasswordChanged(object sender, RoutedEventArgs e)
+ {
+ PasswordVisibleTextBox.Text = PasswordTextBox.Password;
+ }
+
+ private void loginButton_Click(object sender, RoutedEventArgs e)
+ {
+ string username = UsernameTextBox.Text;
+ string password = PasswordTextBox.Password;
+ string result = ValidateUser(username, password);
+
+ if (result == "Erfolgreich")
+ {
+ SearchWindow searchWindow = new();
+ searchWindow.Show(); // Open new window
+ this.Close(); // Close this window
+ }
+ else
+ {
+ MessageBox.Show(result, "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
+ }
+ }
}
\ No newline at end of file
diff --git a/PrototypWPFHAG/PrototypWPFHAG.csproj b/PrototypWPFHAG/PrototypWPFHAG.csproj
index ac26644..0445611 100644
--- a/PrototypWPFHAG/PrototypWPFHAG.csproj
+++ b/PrototypWPFHAG/PrototypWPFHAG.csproj
@@ -4,7 +4,7 @@
WinExe
- Exe
+ WinExe
net9.0-windows
enable
diff --git a/PrototypWPFHAG/SuchenFenster.xaml b/PrototypWPFHAG/SearchWindow.xaml
similarity index 74%
rename from PrototypWPFHAG/SuchenFenster.xaml
rename to PrototypWPFHAG/SearchWindow.xaml
index 0106553..72ac88d 100644
--- a/PrototypWPFHAG/SuchenFenster.xaml
+++ b/PrototypWPFHAG/SearchWindow.xaml
@@ -1,7 +1,8 @@
-
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:local="clr-namespace:PrototypWPFHAG"
+ Title="Such Fenster" Height="600" Width="800">
@@ -40,6 +41,7 @@
+
@@ -47,19 +49,19 @@
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
diff --git a/PrototypWPFHAG/SearchWindow.xaml.cs b/PrototypWPFHAG/SearchWindow.xaml.cs
new file mode 100644
index 0000000..ed81b01
--- /dev/null
+++ b/PrototypWPFHAG/SearchWindow.xaml.cs
@@ -0,0 +1,34 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+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.Shapes;
+
+namespace PrototypWPFHAG
+{
+ ///
+ /// Interaktionslogik für SearchWindow.xaml
+ ///
+ public partial class SearchWindow : Window
+ {
+ public SearchWindow()
+ {
+ InitializeComponent();
+ }
+
+ private void BackToLogIn_Click(object sender, RoutedEventArgs e)
+ {
+ MainWindow loginWindow = new();
+ loginWindow.Show(); // Open new window
+ this.Close(); // Close this window
+ }
+ }
+}
diff --git a/PrototypWPFHAG/SuchenFenster.xaml.cs b/PrototypWPFHAG/SuchenFenster.xaml.cs
deleted file mode 100644
index 5f28270..0000000
--- a/PrototypWPFHAG/SuchenFenster.xaml.cs
+++ /dev/null
@@ -1 +0,0 @@
-
\ No newline at end of file