Habe nun das Fenster "Kürzel" sowie Code Behind fertig und das "PinPanel", ebenfalls mit Code Behind angefertig.

Bitte Kommentare lesen wenn was geändert werden soll oder mich Ansprechen, danke :)
This commit is contained in:
David Oppermann 2025-06-05 11:17:46 +02:00
parent 67bfce265c
commit 8bdf2b334e
4 changed files with 452 additions and 2 deletions

View File

@ -5,8 +5,59 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:StempelClient"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
Title="MainWindow" Height="450" Width="800"
KeyDown="Window_KeyDown">
<Grid Margin="10" Background="LightGray">
<!-- Zwei Zeilen: Die erste für das Textfeld und das Label, die zweite für die Buchstaben-Buttons -->
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!-- Zeile 0: Textfeld und Label "Kürzel" -->
<StackPanel Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,10,0,20">
<Label FontWeight="Bold" FontSize="12" Content="Kürzel" VerticalAlignment="Center" Margin="0,0,10,0" Width="50" Height="30"/>
<TextBox x:Name="KuerzelTextBox" Width="200" Height="25" TextChanged="TextBox_TextChanged" BorderThickness="2" Background="White"/>
</StackPanel>
<!-- Zeile 1: Buttons von A-Z in einem WrapPanel mit fester Breite -->
<WrapPanel x:Name="PinButtonsPanel"
Grid.Row="1"
HorizontalAlignment="Center"
VerticalAlignment="Top"
Margin="50,20,0,0"
Width="170">
<Button Content="A" Width="30" Height="30" Margin="2" Background="White" Click="LetterButton_Click"/>
<Button Content="B" Width="30" Height="30" Margin="2" Background="White" Click="LetterButton_Click"/>
<Button Content="C" Width="30" Height="30" Margin="2" Background="White" Click="LetterButton_Click"/>
<Button Content="D" Width="30" Height="30" Margin="2" Background="White" Click="LetterButton_Click"/>
<Button Content="E" Width="30" Height="30" Margin="2" Background="White" Click="LetterButton_Click"/>
<Button Content="F" Width="30" Height="30" Margin="2" Background="White" Click="LetterButton_Click"/>
<Button Content="G" Width="30" Height="30" Margin="2" Background="White" Click="LetterButton_Click"/>
<Button Content="H" Width="30" Height="30" Margin="2" Background="White" Click="LetterButton_Click"/>
<Button Content="I" Width="30" Height="30" Margin="2" Background="White" Click="LetterButton_Click"/>
<Button Content="J" Width="30" Height="30" Margin="2" Background="White" Click="LetterButton_Click"/>
<Button Content="K" Width="30" Height="30" Margin="2" Background="White" Click="LetterButton_Click"/>
<Button Content="L" Width="30" Height="30" Margin="2" Background="White" Click="LetterButton_Click"/>
<Button Content="M" Width="30" Height="30" Margin="2" Background="White" Click="LetterButton_Click"/>
<Button Content="N" Width="30" Height="30" Margin="2" Background="White" Click="LetterButton_Click"/>
<Button Content="O" Width="30" Height="30" Margin="2" Background="White" Click="LetterButton_Click"/>
<Button Content="P" Width="30" Height="30" Margin="2" Background="White" Click="LetterButton_Click"/>
<Button Content="Q" Width="30" Height="30" Margin="2" Background="White" Click="LetterButton_Click"/>
<Button Content="R" Width="30" Height="30" Margin="2" Background="White" Click="LetterButton_Click"/>
<Button Content="S" Width="30" Height="30" Margin="2" Background="White" Click="LetterButton_Click"/>
<Button Content="T" Width="30" Height="30" Margin="2" Background="White" Click="LetterButton_Click"/>
<Button Content="U" Width="30" Height="30" Margin="2" Background="White" Click="LetterButton_Click"/>
<Button Content="V" Width="30" Height="30" Margin="2" Background="White" Click="LetterButton_Click"/>
<Button Content="W" Width="30" Height="30" Margin="2" Background="White" Click="LetterButton_Click"/>
<Button Content="X" Width="30" Height="30" Margin="2" Background="White" Click="LetterButton_Click"/>
<Button Content="Y" Width="30" Height="30" Margin="2" Background="White" Click="LetterButton_Click"/>
<Button Content="Z" Width="30" Height="30" Margin="2" Background="White" Click="LetterButton_Click"/>
<!-- Neuer Enter-Button -->
<Button x:Name="EnterButton" Content="↵" Width="132" Height="30" Margin="2" Background="LightGreen" Click="EnterButton_Click"/>
</WrapPanel>
</Grid>
</Window>

View File

@ -8,6 +8,7 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Linq;
namespace StempelClient;
@ -16,8 +17,174 @@ namespace StempelClient;
/// </summary>
public partial class MainWindow : Window
{
#region MitarbeiterArray
private string[] Mitarbeiter = new string[6]
{
"Tim Grafe", "Julian Kotthoff", "Laurenz Appel", "David Oppermann", "Isaiah Trox", "Joline Elizabeth Panagiotaris"
};
private Dictionary<string, string> MitarbeiterMapping;
#endregion
#region Main
public MainWindow()
{
InitializeComponent();
// Verwende das PIN-Array aus der PinPanel-Klasse zum Erstellen des Mappings.
MitarbeiterMapping = Mitarbeiter.Zip(PinPanel.MitarbeiterPin, (name, pin) => new { name, pin })
.ToDictionary(x => x.name, x => x.pin);
// Das Eingabefeld "Kürzel" bleibt zunächst leer.
}
#endregion
#region Kürzel aus Namen generieren
private string AutoFillKuerzel(string fullName)
{
if (string.IsNullOrWhiteSpace(fullName))
return string.Empty;
var parts = fullName.Split(' ', System.StringSplitOptions.RemoveEmptyEntries);
string initials = string.Empty;
if (parts.Length >= 1 && parts[0].Length > 0)
initials += parts[0][0];
if (parts.Length >= 2 && parts[1].Length > 0)
initials += parts[1][0];
if (parts.Length >= 3 && parts[2].Length > 0)
initials += parts[2][0];
return initials.ToUpper();
}
#endregion
#region LetterButtonClickFunction
private async void LetterButton_Click(object sender, RoutedEventArgs e)
{
if (sender is Button btn)
{
if (!btn.Background.Equals(Brushes.Gray))
{
var originalBackground = btn.Background;
btn.Background = Brushes.Gray;
await Task.Delay(50);
btn.Background = originalBackground;
}
string letter = btn.Content.ToString().ToUpper();
if (KuerzelTextBox != null)
{
if (KuerzelTextBox.Text.Length < 3)
{
KuerzelTextBox.Text += letter;
}
else if (letter != "↵")
{
MessageBox.Show("Fehler: Es dürfen nur drei Buchstaben eingegeben werden!", "Eingabefehler", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
}
#endregion
#region EnterButtonFunction
private void EnterButton_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrWhiteSpace(KuerzelTextBox.Text))
{
MessageBox.Show("Fehler: Bitte geben Sie ein Kürzel ein!", "Eingabefehler", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
string eingabe = KuerzelTextBox.Text.ToUpper();
string matchedEmployee = null;
foreach (var mitarbeiter in Mitarbeiter)
{
string kurz = AutoFillKuerzel(mitarbeiter);
if (kurz == eingabe)
{
matchedEmployee = mitarbeiter;
break;
}
}
if (matchedEmployee == null)
{
MessageBox.Show("Fehler: Das eingetippte Kürzel stimmt mit keinem Mitarbeiter überein!", "Eingabefehler", MessageBoxButton.OK, MessageBoxImage.Error);
}
else
{
// Erwartete PIN aus der Mapping holen und in int umwandeln
string expectedPinStr = MitarbeiterMapping[matchedEmployee];
if (!int.TryParse(expectedPinStr, out int expectedPin))
{
MessageBox.Show("Fehler: Die PIN des Mitarbeiters ist ungültig!", "Eingabefehler", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
// Erstelle eine Instanz des PinPanel und weise die erwartete PIN zu
PinPanel pinPage = new PinPanel();
pinPage.ExpectedPin = expectedPin;
NavigationWindow navWindow = new NavigationWindow();
navWindow.Navigate(pinPage);
navWindow.Title = "Pin Eingabe";
navWindow.Show();
this.Close();
}
}
#endregion
#region WindowKeyDownFunction
private void Window_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
EnterButton_Click(EnterButton, new RoutedEventArgs());
return;
}
var keyStr = e.Key.ToString().ToUpper();
if (keyStr.Length == 1 && char.IsLetter(keyStr[0]))
{
foreach (var child in PinButtonsPanel.Children)
{
if (child is Button btn && btn.Content.ToString().ToUpper() == keyStr)
{
LetterButton_Click(btn, new RoutedEventArgs());
break;
}
}
}
if (e.Key == Key.Back)
{
KuerzelTextBox.Clear();
return;
}
if (e.Key == Key.Escape)
{
Application.Current.Shutdown();
return;
}
}
#endregion
#region TextBoxFunction
private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
{
if (sender is TextBox tb)
{
string text = tb.Text.ToUpper();
if (text != tb.Text)
{
tb.Text = text;
tb.CaretIndex = tb.Text.Length;
}
if (text.Length > 3)
{
MessageBox.Show("Fehler: Es dürfen nur drei Buchstaben eingegeben werden!", "Eingabefehler", MessageBoxButton.OK, MessageBoxImage.Error);
tb.Text = text.Substring(0, 3);
tb.CaretIndex = tb.Text.Length;
}
}
}
#endregion
}

View File

@ -0,0 +1,48 @@
<Page x:Class="StempelClient.PinPanel"
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:StempelClient"
mc:Ignorable="d"
Title="PinPanel" Height = "450" Width = "800"
KeyDown="Page_KeyDown"
Loaded="Page_Loaded"
Focusable="True">
<Grid Margin="10" Background="LightGray">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!-- Zeile 0: Label und TextBox für die PIN -->
<StackPanel Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,10,0,20">
<Label FontWeight="Bold" FontSize="14" Content="PIN" VerticalAlignment="Center" Margin="0,0,10,0" Width="50" Height="30"/>
<TextBox x:Name="PinTextBox" Width="200" Height="30" TextChanged="PinTextBox_TextChanged" BorderThickness="2" Background="White"/>
</StackPanel>
<!-- Zeile 1: Nummern-Buttons in einem UniformGrid -->
<UniformGrid Grid.Row="1" Columns="3" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="20">
<!-- Erste Zeile -->
<Button Content="1" Width="50" Height="50" Margin="5" Background="White" Click="PinButton_Click"/>
<Button Content="2" Width="50" Height="50" Margin="5" Background="White" Click="PinButton_Click"/>
<Button Content="3" Width="50" Height="50" Margin="5" Background="White" Click="PinButton_Click"/>
<!-- Zweite Zeile -->
<Button Content="4" Width="50" Height="50" Margin="5" Background="White" Click="PinButton_Click"/>
<Button Content="5" Width="50" Height="50" Margin="5" Background="White" Click="PinButton_Click"/>
<Button Content="6" Width="50" Height="50" Margin="5" Background="White" Click="PinButton_Click"/>
<!-- Dritte Zeile -->
<Button Content="7" Width="50" Height="50" Margin="5" Background="White" Click="PinButton_Click"/>
<Button Content="8" Width="50" Height="50" Margin="5" Background="White" Click="PinButton_Click"/>
<Button Content="9" Width="50" Height="50" Margin="5" Background="White" Click="PinButton_Click"/>
<!-- Vierte Zeile -->
<Button x:Name="PinEnterButton" Content="↵" Width="50" Height="50" Margin="5" Background="LightGreen" Click="PinEnterButton_Click"/>
<Button Content="0" Width="50" Height="50" Margin="5" Background="White" Click="PinButton_Click"/>
<!-- Leerer Platzhalter -->
<Button Content="" Width="50" Height="50" Margin="5" Visibility="Hidden" IsEnabled="False"/>
</UniformGrid>
</Grid>
</Page>

View File

@ -0,0 +1,184 @@
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 StempelClient
{
/// <summary>
/// Interaktionslogik für PinPanel.xaml
/// </summary>
public partial class PinPanel : Page
{
#region InitializeComponent
public PinPanel()
{
InitializeComponent();
}
#endregion
#region Pin-Array
public static readonly string[] MitarbeiterPin = new string[6]
{
"11111", "11111", "11111", "11111", "11111", "11111"
};
#endregion
#region PinExpected
public int ExpectedPin { get; set; }
#endregion
#region Page Loader
private void Page_Loaded(object sender, RoutedEventArgs e)
{
this.Focus(); // Setzt den Fokus auf die Seite, damit Tastatureingaben verarbeitet werden.
}
#endregion
#region DigitButtonClickFunction
private async void PinButton_Click(object sender, RoutedEventArgs e)
{
if (sender is Button btn)
{
if (!btn.Background.Equals(Brushes.Gray))
{
var originalBackground = btn.Background;
btn.Background = Brushes.Gray;
await Task.Delay(50);
btn.Background = originalBackground;
}
string buttonContent = btn.Content.ToString();
if (buttonContent != "↵")
{
if (PinTextBox.Text.Length < 5)
{
PinTextBox.Text += buttonContent;
}
else
{
MessageBox.Show("Fehler: Es dürfen nur 5 Ziffern eingegeben werden!", "Eingabefehler", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
}
#endregion
#region EnterButtonFunction
private void PinEnterButton_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrWhiteSpace(PinTextBox.Text))
{
MessageBox.Show("Fehler: Bitte geben Sie einen PIN ein!", "Eingabefehler", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
if (PinTextBox.Text.Length != 5)
{
MessageBox.Show("Fehler: Der PIN muss 5 Ziffern lang sein!", "Eingabefehler", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
if (int.TryParse(PinTextBox.Text, out int enteredPin))
{
if (enteredPin == ExpectedPin)
{
MessageBox.Show("PIN akzeptiert. Login erfolgreich!", "Erfolg", MessageBoxButton.OK, MessageBoxImage.Information);
// Nächste Logik zur Navigation kann hier hinzugefügt werden.
}
else
{
MessageBox.Show("Fehler: Der eingegebene PIN ist falsch!", "Eingabefehler", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
else
{
MessageBox.Show("Fehler: Ungültige PIN!", "Eingabefehler", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
#endregion
#region TextBoxFunction
private void PinTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
if (sender is TextBox tb)
{
string newText = "";
foreach (char c in tb.Text)
{
if (char.IsDigit(c))
newText += c;
}
if (newText != tb.Text)
{
tb.Text = newText;
tb.CaretIndex = tb.Text.Length;
}
if (tb.Text.Length > 5)
{
MessageBox.Show("Fehler: Es dürfen nur 5 Ziffern eingegeben werden!", "Eingabefehler", MessageBoxButton.OK, MessageBoxImage.Error);
tb.Text = tb.Text.Substring(0, 5);
tb.CaretIndex = tb.Text.Length;
}
}
}
#endregion
#region ProcessNumericInputFunction
private void ProcessNumericInput(Key key)
{
string digit = string.Empty;
if (key >= Key.D0 && key <= Key.D9)
digit = (key - Key.D0).ToString();
else if (key >= Key.NumPad0 && key <= Key.NumPad9)
digit = (key - Key.NumPad0).ToString();
if (!string.IsNullOrEmpty(digit))
{
if (PinTextBox.Text.Length < 5)
{
PinTextBox.Text += digit;
}
else
{
MessageBox.Show("Fehler: Es dürfen nur 5 Ziffern eingegeben werden!", "Eingabefehler", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
#endregion
#region PageKeyDownFunction
private void Page_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
PinEnterButton_Click(PinEnterButton, new RoutedEventArgs());
return;
}
if ((e.Key >= Key.D0 && e.Key <= Key.D9) || (e.Key >= Key.NumPad0 && e.Key <= Key.NumPad9))
{
ProcessNumericInput(e.Key);
return;
}
if (e.Key == Key.Back)
{
PinTextBox.Clear();
return;
}
if (e.Key == Key.Escape)
{
Application.Current.Shutdown();
return;
}
}
#endregion
}
}