mirror of
https://git.battle-of-pip.de/root/vpr-mitarbeiterverwaltung.git
synced 2025-12-13 22:31:38 +01:00
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:
184
StempelClient/PinPanel.xaml.cs
Normal file
184
StempelClient/PinPanel.xaml.cs
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user