Merge branch 'main' of https://git.bib.de/PBG2H23ASA/HAG_BIB_Projekt
# Conflicts: # PrototypWPFHAG/MainWindow.xaml # PrototypWPFHAG/MainWindow.xaml.cs
This commit is contained in:
commit
ebea635c53
@ -12,21 +12,41 @@
|
|||||||
TitleCharacterCasing="Normal"
|
TitleCharacterCasing="Normal"
|
||||||
WindowTitleBrush="Firebrick"
|
WindowTitleBrush="Firebrick"
|
||||||
Icon="pack://application:,,,/Images/databaseicon.png"
|
Icon="pack://application:,,,/Images/databaseicon.png"
|
||||||
ResizeMode="CanResizeWithGrip">
|
ResizeMode="CanResizeWithGrip"
|
||||||
|
Loaded="Window_Loaded">
|
||||||
<Grid>
|
<Grid>
|
||||||
<Border BorderBrush="Firebrick" BorderThickness="3" Padding="20">
|
<Border BorderBrush="Firebrick" BorderThickness="3" Padding="20">
|
||||||
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
|
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
|
||||||
<!-- 用户名标签和输入框 -->
|
|
||||||
<TextBlock Text="USERNAME" Margin="0,10,0,0" FontSize="14" FontWeight="Bold" />
|
<!-- Username -->
|
||||||
|
<TextBlock Text="Benutzername" Margin="0,10,0,0" FontSize="14" FontWeight="Bold" />
|
||||||
<TextBox Width="200" Height="30" Margin="0,5,0,0" x:Name="UsernameTextBox" />
|
<TextBox Width="200" Height="30" Margin="0,5,0,0" x:Name="UsernameTextBox" />
|
||||||
|
|
||||||
<!-- 密码标签和输入框 -->
|
<TextBlock Text="Passwort" Margin="0,10,0,0" FontSize="14" FontWeight="Bold" />
|
||||||
<TextBlock Text="PASSWORD" Margin="0,10,0,0" FontSize="14" FontWeight="Bold" />
|
<Grid>
|
||||||
<PasswordBox Width="200" Height="30" Margin="0,5,0,0" x:Name="PasswordTextBox" />
|
<!-- Passwortbox (hidden when Password is visible) -->
|
||||||
|
<PasswordBox Width="170" Height="30" Margin="0,5,34,0" x:Name="PasswordTextBox"
|
||||||
|
PasswordChanged="PasswordTextBox_PasswordChanged"/>
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
<!-- 登录按钮 -->
|
<!-- 登录按钮 -->
|
||||||
<Button Height="30" Width="100" Content="Log in" Margin="0,20,0,0" Click="LoginButton_Click" />
|
<Button Height="30" Width="100" Content="Log in" Margin="0,20,0,0" Click="LoginButton_Click" />
|
||||||
|
=======
|
||||||
|
<!-- Textbox for visible password (hidden at default) -->
|
||||||
|
<TextBox Width="170" Height="30" Margin="0,5,34,0" x:Name="PasswordVisibleTextBox"
|
||||||
|
Visibility="Collapsed" IsReadOnly="True"/>
|
||||||
|
|
||||||
|
<!-- Button with Eye-Icon -->
|
||||||
|
<Button Width="30" Height="30" Margin="175,5,0,0" Content="👁"
|
||||||
|
Click="ShowPasswordButton_Click"/>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- Login Button -->
|
||||||
|
<Button Height="30" Width="100" Content="Zur Suche" Margin="0,20,0,0"
|
||||||
|
Click="loginButton_Click" IsDefault="True" />
|
||||||
|
>>>>>>> 1195250b98172d34b8c49b85a81c21d1f26cdbac
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Border>
|
</Border>
|
||||||
</Grid>
|
</Grid>
|
||||||
</mah:MetroWindow>
|
</mah:MetroWindow>
|
||||||
|
@ -25,46 +25,116 @@ public partial class MainWindow : MetroWindow
|
|||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
<<<<<<< HEAD
|
||||||
//TestConnection();
|
//TestConnection();
|
||||||
//Console.ReadKey();
|
//Console.ReadKey();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void TestConnection()
|
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())
|
using (NpgsqlConnection con = GetConnection())
|
||||||
{
|
{
|
||||||
con.Open();
|
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()
|
private static NpgsqlConnection GetConnection()
|
||||||
{
|
{
|
||||||
return new NpgsqlConnection(@"Server=localhost;Port=7854;User Id=postgres;Database=postgres;");
|
return new NpgsqlConnection(@"Server=localhost;Port=7854;User Id=postgres;Database=postgres;");
|
||||||
|
=======
|
||||||
|
|
||||||
|
return "Erfolgreich";
|
||||||
|
>>>>>>> 1195250b98172d34b8c49b85a81c21d1f26cdbac
|
||||||
}
|
}
|
||||||
|
|
||||||
//class Program
|
private void ShowPasswordButton_PreviewMouseDown(object sender, RoutedEventArgs e)
|
||||||
//{
|
{
|
||||||
// static void Main(string[] args)
|
PasswordVisibleTextBox.Text = PasswordTextBox.Password; // Write password in the visible box
|
||||||
// {
|
PasswordVisibleTextBox.Visibility = Visibility.Visible;
|
||||||
// TestConnection();
|
PasswordTextBox.Visibility = Visibility.Collapsed;
|
||||||
// Console.ReadKey();
|
}
|
||||||
// }
|
|
||||||
// private static void TestConnection()
|
private void ShowPasswordButton_Click(object sender, RoutedEventArgs e)
|
||||||
// {
|
{
|
||||||
// using(NpgsqlConnection con = GetConnection()){
|
if (PasswordTextBox.Visibility == Visibility.Visible)
|
||||||
// con.Open();
|
{
|
||||||
// if (con.State == ConnectionState.Open) {
|
// Show password
|
||||||
// Console.WriteLine("Connected to Server");
|
PasswordVisibleTextBox.Text = PasswordTextBox.Password;
|
||||||
// }
|
PasswordVisibleTextBox.Visibility = Visibility.Visible;
|
||||||
// }
|
PasswordTextBox.Visibility = Visibility.Collapsed;
|
||||||
// }
|
}
|
||||||
// private static NpgsqlConnection GetConnection()
|
else
|
||||||
// {
|
{
|
||||||
// return new NpgsqlConnection(@"Server=localhost;Port=5432;User Id=postgres;Password=postgres;Database=TestServer;");
|
// 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
<OutputType>WinExe</OutputType>
|
<OutputType>WinExe</OutputType>
|
||||||
|
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>WinExe</OutputType>
|
||||||
|
|
||||||
<TargetFramework>net9.0-windows</TargetFramework>
|
<TargetFramework>net9.0-windows</TargetFramework>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
<Window x:Class="SuchenFenster.MainWindow"
|
<Window x:Class="PrototypWPFHAG.SearchWindow"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
Title="Suchen Fenster" Height="600" Width="800">
|
xmlns:local="clr-namespace:PrototypWPFHAG"
|
||||||
|
Title="Such Fenster" Height="600" Width="800">
|
||||||
<Grid>
|
<Grid>
|
||||||
<!-- 左侧垂直布局 -->
|
<!-- 左侧垂直布局 -->
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
@ -40,6 +41,7 @@
|
|||||||
</Border>
|
</Border>
|
||||||
<Button Content="ADD" Width="60" Height="30" Grid.Column="1" Margin="5,0,0,0"/>
|
<Button Content="ADD" Width="60" Height="30" Grid.Column="1" Margin="5,0,0,0"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
<Button Content="Zurück " Margin="5,380" Click="BackToLogIn_Click"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
<!-- 右侧区域 -->
|
<!-- 右侧区域 -->
|
||||||
@ -47,19 +49,19 @@
|
|||||||
<Label Content="Zeugnisse:" HorizontalAlignment="Left" Margin="0,2,0,8"/>
|
<Label Content="Zeugnisse:" HorizontalAlignment="Left" Margin="0,2,0,8"/>
|
||||||
<!-- ListField -->
|
<!-- ListField -->
|
||||||
<ListBox x:Name="ListField" Margin="0,29,0,35" BorderThickness="1" BorderBrush="Black">
|
<ListBox x:Name="ListField" Margin="0,29,0,35" BorderThickness="1" BorderBrush="Black">
|
||||||
<ListBox.ItemTemplate>
|
<ListBox.ItemTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<StackPanel Orientation="Vertical">
|
<StackPanel Orientation="Vertical">
|
||||||
<!-- 内容 -->
|
<!-- 内容 -->
|
||||||
<TextBlock Text="{Binding}" VerticalAlignment="Center" HorizontalAlignment="Stretch" Padding="5"/>
|
<TextBlock Text="{Binding}" VerticalAlignment="Center" HorizontalAlignment="Stretch" Padding="5"/>
|
||||||
<!-- 分隔线 -->
|
<!-- 分隔线 -->
|
||||||
<Border Height="1" Background="Black" Margin="0,2,0,2"/>
|
<Border Height="1" Background="Black" Margin="0,2,0,2"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</ListBox.ItemTemplate>
|
</ListBox.ItemTemplate>
|
||||||
</ListBox>
|
</ListBox>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- 删除按钮 -->
|
<!-- 删除按钮 -->
|
||||||
<Button Content="Löschen" Width="100" Height="30" HorizontalAlignment="Right" VerticalAlignment="Bottom"/>
|
<Button Content="Löschen" Width="100" Height="30" HorizontalAlignment="Right" VerticalAlignment="Bottom"/>
|
||||||
</Grid>
|
</Grid>
|
34
PrototypWPFHAG/SearchWindow.xaml.cs
Normal file
34
PrototypWPFHAG/SearchWindow.xaml.cs
Normal file
@ -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
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Interaktionslogik für SearchWindow.xaml
|
||||||
|
/// </summary>
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1 +0,0 @@
|
|||||||
|
|
Loading…
x
Reference in New Issue
Block a user