Bessere eingabe
This commit is contained in:
parent
11c226bfcd
commit
e76ec822db
@ -69,35 +69,45 @@ namespace Matomat
|
|||||||
}
|
}
|
||||||
catch (ArgumentException)
|
catch (ArgumentException)
|
||||||
{
|
{
|
||||||
Factory.getLCD().print("Bitte den Usernamen [255] eingeben:");
|
string username;
|
||||||
string username = Console.ReadLine();
|
try
|
||||||
Factory.getLCD().print("Username:\n" + username);
|
{
|
||||||
System.Threading.Thread.Sleep(4500);
|
username = Factory.getInput().getKeyboardInput("Bitte den Namen [255] eingeben:");
|
||||||
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Factory.getLCD().print("Bitte Kürzel [8] eingeben:");
|
string kurzel;
|
||||||
string kurzel = Console.ReadLine();
|
try
|
||||||
Factory.getLCD().print("Kürzel:\n" + kurzel);
|
{
|
||||||
System.Threading.Thread.Sleep(4500);
|
kurzel = Factory.getInput().getKeyboardInput("Bitte Kürzel [8] eingeben:");
|
||||||
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Factory.getLCD().print("Bitte E-Mail [255] eingeben:");
|
string email;
|
||||||
string email = Console.ReadLine();
|
try
|
||||||
Factory.getLCD().print("E-Mail:\n" + email);
|
{
|
||||||
System.Threading.Thread.Sleep(4500);
|
email = Factory.getInput().getKeyboardInput("Bitte E-Mail [255] eingeben:");
|
||||||
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Factory.getLCD().print("Bitte Admin [1|0] eingeben:");
|
|
||||||
bool isadmin;
|
bool isadmin;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
isadmin = bool.Parse(Console.ReadLine());
|
isadmin = bool.Parse(Factory.getInput().getKeyboardInput("Bitte Admin [true|false] eingeben:"));
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
Factory.getLCD().print("Fehler bei der Eingabe\ndes Adminflags ABBRUCH!", 5, LCDDisplay.Status.Error);
|
|
||||||
System.Threading.Thread.Sleep(4500);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Factory.getLCD().print("Admin:\n" + isadmin);
|
|
||||||
System.Threading.Thread.Sleep(4500);
|
|
||||||
|
|
||||||
User.Add(target.id, username, isadmin, kurzel, email);
|
User.Add(target.id, username, isadmin, kurzel, email);
|
||||||
|
|
||||||
@ -177,40 +187,35 @@ namespace Matomat
|
|||||||
}
|
}
|
||||||
catch (ArgumentException)
|
catch (ArgumentException)
|
||||||
{
|
{
|
||||||
Factory.getLCD().print("Bitte den Produktnamen [255] eingeben:");
|
string name;
|
||||||
string name = Console.ReadLine();
|
try
|
||||||
Factory.getLCD().print("Produktname:\n" + name);
|
{
|
||||||
System.Threading.Thread.Sleep(4500);
|
name = Factory.getInput().getKeyboardInput("Bitte den Produktnamen [255] eingeben:");
|
||||||
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Factory.getLCD().print("Bitte Preis [Cent] eingeben:");
|
|
||||||
int preis;
|
int preis;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
preis = int.Parse(Console.ReadLine());
|
preis = int.Parse(Factory.getInput().getKeyboardInput("Bitte Preis [Cent] eingeben:"));
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
Factory.getLCD().print("Fehler bei der Eingabe des Preises\nABBRUCH!", 5, LCDDisplay.Status.Error);
|
|
||||||
System.Threading.Thread.Sleep(4500);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Factory.getLCD().print("Preis:\n" + preis + " €Cent");
|
|
||||||
System.Threading.Thread.Sleep(4500);
|
|
||||||
|
|
||||||
Factory.getLCD().print("Bitte Koffeingehalt [mg] eingeben:");
|
|
||||||
int coffeine;
|
int coffeine;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
coffeine = int.Parse(Console.ReadLine());
|
coffeine = int.Parse(Factory.getInput().getKeyboardInput("Bitte Koffeingehalt [mg] eingeben:"));
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
Factory.getLCD().print("Fehler bei der Eingabe\ndes Koffeingehaltes ABBRUCH!", 5, LCDDisplay.Status.Error);
|
|
||||||
System.Threading.Thread.Sleep(4500);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Factory.getLCD().print("Koffeingehalt:\n" + coffeine + " mg");
|
|
||||||
System.Threading.Thread.Sleep(4500);
|
|
||||||
|
|
||||||
Product.Add(target.id, name, preis, coffeine);
|
Product.Add(target.id, name, preis, coffeine);
|
||||||
|
|
||||||
|
49
Matomat/Input/KeyboardReader.cs
Normal file
49
Matomat/Input/KeyboardReader.cs
Normal 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 "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -135,6 +135,12 @@ namespace Matomat.Input
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string getKeyboardInput(string text)
|
||||||
|
{
|
||||||
|
KeyboardReader r = new KeyboardReader();
|
||||||
|
return r.getCodeID(text);
|
||||||
|
}
|
||||||
|
|
||||||
public void RequestStop()
|
public void RequestStop()
|
||||||
{
|
{
|
||||||
this.cardrunning = false;
|
this.cardrunning = false;
|
||||||
|
@ -68,6 +68,7 @@
|
|||||||
<Compile Include="Database\DBDriverMysqli.cs" />
|
<Compile Include="Database\DBDriverMysqli.cs" />
|
||||||
<Compile Include="Helper\Factory.cs" />
|
<Compile Include="Helper\Factory.cs" />
|
||||||
<Compile Include="Helper\Types.cs" />
|
<Compile Include="Helper\Types.cs" />
|
||||||
|
<Compile Include="Input\KeyboardReader.cs" />
|
||||||
<Compile Include="Input\TInput.cs" />
|
<Compile Include="Input\TInput.cs" />
|
||||||
<Compile Include="Controller\Instruction.cs" />
|
<Compile Include="Controller\Instruction.cs" />
|
||||||
<Compile Include="Model\History.cs" />
|
<Compile Include="Model\History.cs" />
|
||||||
|
@ -30,8 +30,7 @@ namespace Matomat
|
|||||||
|
|
||||||
private static void test()
|
private static void test()
|
||||||
{
|
{
|
||||||
User u = new User(2855543482);
|
Console.WriteLine(Factory.getInput().getKeyboardInput("Bitte den Namen [255] eingeben"));
|
||||||
Instruction.InsShowStats(u, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#region MainThread
|
#region MainThread
|
||||||
|
Loading…
Reference in New Issue
Block a user