160 lines
5.2 KiB
C#
160 lines
5.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
|
|
using Matomat.Helper;
|
|
using Matomat.Input;
|
|
using Matomat.Model;
|
|
using Matomat.Output;
|
|
|
|
namespace Matomat
|
|
{
|
|
class Program
|
|
{
|
|
private static volatile bool _shouldStop;
|
|
|
|
public static void Main(string[] args)
|
|
{
|
|
test();
|
|
InitMainThread();
|
|
Thread t = new Thread(MainThread);
|
|
t.Start();
|
|
while (!t.IsAlive) ;
|
|
while (t.IsAlive)
|
|
{
|
|
Thread.Sleep(10);
|
|
}
|
|
}
|
|
|
|
private static void test()
|
|
{
|
|
User u = new User(2855543482);
|
|
Instruction.InsShowStats(u, true);
|
|
}
|
|
|
|
#region MainThread
|
|
private static void InitMainThread()
|
|
{
|
|
Factory.getLCD();
|
|
Factory.getInput();
|
|
_shouldStop = false;
|
|
}
|
|
|
|
private static void MainThread()
|
|
{
|
|
while (!_shouldStop)
|
|
{
|
|
Instruction.GetInitStatus();
|
|
InputData input = Factory.getInput().getAnyInput(60);
|
|
if (input.type != InputData.types.None)
|
|
{
|
|
doJob(input);
|
|
}
|
|
}
|
|
Factory.getLCD().print("Der Matomat wurde beendet.\nEinen schönen Tag!");
|
|
Factory.rmLCD();
|
|
Factory.rmInput();
|
|
Factory.rmDBO();
|
|
Factory.rmConfig();
|
|
}
|
|
|
|
private static void RequestStop(bool stop)
|
|
{
|
|
_shouldStop = stop;
|
|
}
|
|
#endregion
|
|
|
|
private static void doJob(InputData input)
|
|
{
|
|
if (input.type == InputData.types.Card)
|
|
{
|
|
User user;
|
|
try
|
|
{
|
|
user = new User(input.id);
|
|
}
|
|
catch (ArgumentException e)
|
|
{
|
|
Factory.getLCD().print(e.Message, 5, LCDDisplay.Status.OK);
|
|
System.Threading.Thread.Sleep(4500);
|
|
return;
|
|
}
|
|
|
|
Instruction.showUserInfo(user);
|
|
|
|
Factory.getLCD().print("Bitte Produkt über den\nBarcodeleser halten");
|
|
|
|
InputData prodid = Factory.getInput().getProdInput(20);
|
|
if (prodid.type == InputData.types.None)
|
|
return;
|
|
|
|
Product prod;
|
|
try
|
|
{
|
|
prod = new Product(prodid.id);
|
|
}
|
|
catch (ArgumentException e)
|
|
{
|
|
Factory.getLCD().print(e.Message, 5, LCDDisplay.Status.OK);
|
|
System.Threading.Thread.Sleep(4500);
|
|
return;
|
|
}
|
|
|
|
Instruction.ShowProdInfo(prod);
|
|
|
|
if (prod.GetProdType() == Product.ProdType.Product)
|
|
{
|
|
Instruction.sell(prod, user);
|
|
}
|
|
if (prod.GetProdType() == Product.ProdType.Instruction)
|
|
{
|
|
switch (prod.GetName())
|
|
{
|
|
case "exit();": RequestStop(true); break;
|
|
case "aufladen(10);": Instruction.InsAufladen(10, user); break;
|
|
case "aufladen(20);": Instruction.InsAufladen(20, user); break;
|
|
case "aufladen(5);": Instruction.InsAufladen(5, user); break;
|
|
case "addUser();": Instruction.InsAddUser(user); break;
|
|
case "delUser();": Instruction.InsDelUser(user); break;
|
|
case "showStats();": Instruction.InsShowStats(); break;
|
|
case "addProd();": Instruction.InsAddProd(user); break;
|
|
case "delProd();": Instruction.InsDelProd(user); break;
|
|
case "showStats(Month);": Instruction.InsShowStats(user, true); break;
|
|
case "showStats(All);": Instruction.InsShowStats(user, false); break;
|
|
}
|
|
}
|
|
}
|
|
else if (input.type == InputData.types.Prod)
|
|
{
|
|
Product prod;
|
|
try
|
|
{
|
|
prod = new Product(input.id);
|
|
}
|
|
catch (ArgumentException e)
|
|
{
|
|
Factory.getLCD().print(e.Message, 5, LCDDisplay.Status.OK);
|
|
System.Threading.Thread.Sleep(4500);
|
|
return;
|
|
}
|
|
|
|
if (prod.GetProdType() == Product.ProdType.Instruction)
|
|
{
|
|
switch (prod.GetName())
|
|
{
|
|
case "exit();": RequestStop(true); break;
|
|
case "showStats();": Instruction.InsShowStats(); break;
|
|
default: Instruction.ShowProdInfo(prod); break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Instruction.ShowProdInfo(prod);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|