Matomat/Matomat/Automat.cs

181 lines
8.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Matomat
{
class Automat
{
private bool shutdown = false;
public delegate void stopEvent(bool stop);
public event stopEvent stopThread;
public Automat() {
}
internal void doJob(InputData input)
{
LCDDisplay lcd = Factory.getLCDDisplay();
Input inp = Factory.getInput();
if (input.type == InputData.types.Card)
{
User user = new User(input.id);
if (!user.vaild())
return;
this.showUserInfo(user);
lcd.print("²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²" +
"² Bitte Produkt über den ²" +
"² Barcodeleser halten ²" +
"²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²");
InputData prodid = inp.getProdInput(20);
if (prodid.type == InputData.types.None)
return;
Prod prod = new Prod(prodid.id);
if(!prod.vaild())
return;
this.showProdInfo(prod);
if (prod.GetProdType() == Prod.ProdType.product)
{
this.sell(prod, user);
}
if (prod.GetProdType() == Prod.ProdType.instruction)
{
switch (prod.GetFunctName())
{
case "exit();": this.stopThread(true); break;
case "aufladen(10);": this.InsAufladen(10, user); break;
case "aufladen(20);": this.InsAufladen(20, user); break;
case "aufladen(5);": this.InsAufladen(5, user); break;
/*case "addUser();": this.InsAddUser(); break;
case "delUser();": this.InsDelUser(); break;
case "showStats();": this.InsShowStats(); break;*/
}
}
}
else if (input.type == InputData.types.Prod)
{
Prod prod = new Prod(input.id);
if (!prod.vaild())
return;
if (prod.GetFunctName().ToLower() == "exit();")
{
this.stopThread(true);
return;
}
this.showProdInfo(prod);
}
}
private void InsAufladen(int betrag, User admin)
{
LCDDisplay lcd = Factory.getLCDDisplay();
Input inp = Factory.getInput();
if (!admin.IsAdmin())
{
lcd.print("²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²" +
"² Du bist kein Admin, ²" +
"² du kannst nichts Aufladen! ²" +
"²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²",
LCDDisplay.Status.Error, 5);
System.Threading.Thread.Sleep(4500);
return;
}
lcd.print("²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²" +
"² Bitte die Zielkarte auf den ²" +
"² RFID Leser auflegen ²" +
"²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²");
InputData target = inp.getCardInput(20);
if (target.type == InputData.types.None)
return;
User user = new User(target.id);
if (!user.vaild())
return;
lcd.print("²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²" +
"² Betrag von User " + user.GetUserName().PadRight(8, ' ') + " ²" +
"² um "+betrag.ToString().PadLeft(2, ' ')+" € verringert ²" +
"²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²");
user.SetUserKonto(user.GetUserKonto()-betrag);
System.Threading.Thread.Sleep(2000);
}
private void sell(Prod prod, User user)
{
LCDDisplay lcd = Factory.getLCDDisplay();
if (user.GetUserKonto() > 19)
{
lcd.print("²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²" +
"² Du hast zu viel Geld auf dem Konto ²" +
"² BITTE bezahlen! | Grenze 20€ ²" +
"²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²",
LCDDisplay.Status.Error, 5);
}
}
private void showProdInfo(Prod prod)
{
LCDDisplay lcd = Factory.getLCDDisplay();
if (prod.GetProdType() == Prod.ProdType.product)
{
long id = prod.GetProdId();
double price = prod.GetProdPrice();
string name = prod.GetProdName();
lcd.print("²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²" +
"² Produkt: " + name.PadRight(27, ' ') + " ²" +
"² Preis: " + price.ToString(2).PadLeft(6, ' ') + "€ EAN13: " + id.ToString().PadRight(14, ' ') + " ²" +
"²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²", 2);
}
if (prod.GetProdType() == Prod.ProdType.instruction)
{
string name = prod.GetFunctName();
lcd.print("²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²" +
"² Instruktion: " + name.PadRight(23, ' ') + " ²" +
"² AdminCard + Instruction + TargetCard ²" +
"²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²", 2);
}
}
private void showUserInfo(User user)
{
LCDDisplay lcd = Factory.getLCDDisplay();
string name = user.GetUserName();
int konto = user.GetUserKonto();
long id = user.GetUserId();
long all = user.GetUserAll();
lcd.print("²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²" +
"² User: " + name.PadRight(8, ' ') + " Betrag: " + (konto.ToString() + " €").PadRight(7, ' ') + " ²" +
"² UserID: " + id.ToString().PadRight(12, ' ') + " Gesamt: " + (all.ToString() + " €").PadRight(7, ' ') + " ²" +
"²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²", 5);
}
internal void GetInitStatus()
{
LCDDisplay lcd = Factory.getLCDDisplay();
List<TBest> l = new Tables().getBestlist();
string[] p = new string[4];
for (int i = 0; i < 4; i++)
{
p[i] = (l.Count >= i + 1) ? l.ElementAt(i).name.PadRight(6, ' ').Substring(0, 6) + " " + (l.ElementAt(i).num % 1000).ToString().PadLeft(3, '0') : " ";
}
lcd.print("²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²" + p[0] +
"² MATOMAT Wilkommen! ²" + p[1] +
"² Frohes genießen der Mate ²" + p[2] +
"²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²" + p[3]);
}
}
}