mirror of
https://git.battle-of-pip.de/root/vpr-mitarbeiterverwaltung.git
synced 2025-06-21 00:03:18 +02:00
Bitte Kommentare lesen wenn was geändert werden soll oder mich Ansprechen, danke :)
190 lines
6.0 KiB
C#
190 lines
6.0 KiB
C#
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;
|
|
using System.Linq;
|
|
|
|
namespace StempelClient;
|
|
|
|
/// <summary>
|
|
/// Interaction logic for MainWindow.xaml
|
|
/// </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
|
|
} |