diff --git a/Matomat/Controller/Instruction.cs b/Matomat/Controller/Instruction.cs
index 0c65ffa..3d4ebe2 100644
--- a/Matomat/Controller/Instruction.cs
+++ b/Matomat/Controller/Instruction.cs
@@ -69,35 +69,45 @@ namespace Matomat
}
catch (ArgumentException)
{
- Factory.getLCD().print("Bitte den Usernamen [255] eingeben:");
- string username = Console.ReadLine();
- Factory.getLCD().print("Username:\n" + username);
- System.Threading.Thread.Sleep(4500);
+ string username;
+ try
+ {
+ username = Factory.getInput().getKeyboardInput("Bitte den Namen [255] eingeben:");
+ }
+ catch (ArgumentException)
+ {
+ return;
+ }
- Factory.getLCD().print("Bitte Kürzel [8] eingeben:");
- string kurzel = Console.ReadLine();
- Factory.getLCD().print("Kürzel:\n" + kurzel);
- System.Threading.Thread.Sleep(4500);
+ string kurzel;
+ try
+ {
+ kurzel = Factory.getInput().getKeyboardInput("Bitte Kürzel [8] eingeben:");
+ }
+ catch (ArgumentException)
+ {
+ return;
+ }
- Factory.getLCD().print("Bitte E-Mail [255] eingeben:");
- string email = Console.ReadLine();
- Factory.getLCD().print("E-Mail:\n" + email);
- System.Threading.Thread.Sleep(4500);
+ string email;
+ try
+ {
+ email = Factory.getInput().getKeyboardInput("Bitte E-Mail [255] eingeben:");
+ }
+ catch (ArgumentException)
+ {
+ return;
+ }
- Factory.getLCD().print("Bitte Admin [1|0] eingeben:");
bool isadmin;
try
{
- isadmin = bool.Parse(Console.ReadLine());
+ isadmin = bool.Parse(Factory.getInput().getKeyboardInput("Bitte Admin [true|false] eingeben:"));
}
catch (Exception)
{
- Factory.getLCD().print("Fehler bei der Eingabe\ndes Adminflags ABBRUCH!", 5, LCDDisplay.Status.Error);
- System.Threading.Thread.Sleep(4500);
return;
}
- Factory.getLCD().print("Admin:\n" + isadmin);
- System.Threading.Thread.Sleep(4500);
User.Add(target.id, username, isadmin, kurzel, email);
@@ -177,40 +187,35 @@ namespace Matomat
}
catch (ArgumentException)
{
- Factory.getLCD().print("Bitte den Produktnamen [255] eingeben:");
- string name = Console.ReadLine();
- Factory.getLCD().print("Produktname:\n" + name);
- System.Threading.Thread.Sleep(4500);
+ string name;
+ try
+ {
+ name = Factory.getInput().getKeyboardInput("Bitte den Produktnamen [255] eingeben:");
+ }
+ catch (ArgumentException)
+ {
+ return;
+ }
- Factory.getLCD().print("Bitte Preis [Cent] eingeben:");
int preis;
try
{
- preis = int.Parse(Console.ReadLine());
+ preis = int.Parse(Factory.getInput().getKeyboardInput("Bitte Preis [Cent] eingeben:"));
}
catch (Exception)
{
- Factory.getLCD().print("Fehler bei der Eingabe des Preises\nABBRUCH!", 5, LCDDisplay.Status.Error);
- System.Threading.Thread.Sleep(4500);
return;
}
- Factory.getLCD().print("Preis:\n" + preis + " €Cent");
- System.Threading.Thread.Sleep(4500);
- Factory.getLCD().print("Bitte Koffeingehalt [mg] eingeben:");
int coffeine;
try
{
- coffeine = int.Parse(Console.ReadLine());
+ coffeine = int.Parse(Factory.getInput().getKeyboardInput("Bitte Koffeingehalt [mg] eingeben:"));
}
catch (Exception)
{
- Factory.getLCD().print("Fehler bei der Eingabe\ndes Koffeingehaltes ABBRUCH!", 5, LCDDisplay.Status.Error);
- System.Threading.Thread.Sleep(4500);
return;
}
- Factory.getLCD().print("Koffeingehalt:\n" + coffeine + " mg");
- System.Threading.Thread.Sleep(4500);
Product.Add(target.id, name, preis, coffeine);
diff --git a/Matomat/Input/KeyboardReader.cs b/Matomat/Input/KeyboardReader.cs
new file mode 100644
index 0000000..9983475
--- /dev/null
+++ b/Matomat/Input/KeyboardReader.cs
@@ -0,0 +1,49 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Matomat.Helper;
+
+namespace Matomat.Input
+{
+ class KeyboardReader
+ {
+ public string getCodeID(string text)
+ {
+ Factory.getLCD().print(text);
+ string str = "";
+ while (true)
+ {
+ if (Console.KeyAvailable)
+ {
+ ConsoleKeyInfo k = Console.ReadKey(true);
+ if (k.Key == ConsoleKey.Enter)
+ {
+ break;
+ }
+ else if (k.Key == ConsoleKey.Backspace)
+ {
+ if(str.Length > 0)
+ str = str.Substring(0, str.Length - 1);
+ }
+ else if (k.Key == ConsoleKey.Escape)
+ {
+ throw new ArgumentOutOfRangeException("Eingabe abgebrochen");
+ }
+ else
+ {
+ str = str + k.KeyChar.ToString();
+ }
+ Factory.getLCD().print(text + "\n" + str.PadRight(38,' '));
+ }
+ System.Threading.Thread.Sleep(10);
+ }
+ try
+ {
+ return str.Trim();
+ }
+ catch (Exception) { }
+ return "";
+ }
+ }
+}
diff --git a/Matomat/Input/TInput.cs b/Matomat/Input/TInput.cs
index 138cfae..c569e90 100644
--- a/Matomat/Input/TInput.cs
+++ b/Matomat/Input/TInput.cs
@@ -135,6 +135,12 @@ namespace Matomat.Input
return data;
}
+ public string getKeyboardInput(string text)
+ {
+ KeyboardReader r = new KeyboardReader();
+ return r.getCodeID(text);
+ }
+
public void RequestStop()
{
this.cardrunning = false;
diff --git a/Matomat/Matomat.csproj b/Matomat/Matomat.csproj
index a075316..b418683 100644
--- a/Matomat/Matomat.csproj
+++ b/Matomat/Matomat.csproj
@@ -68,6 +68,7 @@
+
diff --git a/Matomat/Program.cs b/Matomat/Program.cs
index 6f32bf6..320b78a 100644
--- a/Matomat/Program.cs
+++ b/Matomat/Program.cs
@@ -30,8 +30,7 @@ namespace Matomat
private static void test()
{
- User u = new User(2855543482);
- Instruction.InsShowStats(u, true);
+ Console.WriteLine(Factory.getInput().getKeyboardInput("Bitte den Namen [255] eingeben"));
}
#region MainThread