Bessere eingabe

This commit is contained in:
BlubbFish 2013-07-14 20:59:37 +00:00
parent 11c226bfcd
commit e76ec822db
5 changed files with 96 additions and 36 deletions

View File

@ -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);

View File

@ -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 "";
}
}
}

View File

@ -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;

View File

@ -68,6 +68,7 @@
<Compile Include="Database\DBDriverMysqli.cs" />
<Compile Include="Helper\Factory.cs" />
<Compile Include="Helper\Types.cs" />
<Compile Include="Input\KeyboardReader.cs" />
<Compile Include="Input\TInput.cs" />
<Compile Include="Controller\Instruction.cs" />
<Compile Include="Model\History.cs" />

View File

@ -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