This commit is contained in:
BlubbFish 2011-11-08 18:18:41 +00:00
parent 9bfb6285aa
commit f46f43dce2
6 changed files with 49 additions and 25 deletions

View File

@ -13,6 +13,10 @@ namespace Matomat
private LCDDisplay lcd; private LCDDisplay lcd;
private Input inp; private Input inp;
public delegate void stopEvent(bool stop);
public event stopEvent stopThread;
public Automat() { public Automat() {
lcd = Factory.getLCDDisplay(); lcd = Factory.getLCDDisplay();
inp = Factory.getInput(); inp = Factory.getInput();
@ -37,6 +41,19 @@ namespace Matomat
{ {
this.sell(prod, user); 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); break;
case "aufladen(20);": this.InsAufladen(20); break;
case "aufladen(5);": this.InsAufladen(5); break;
case "addUser();": this.InsAddUser(); break;
case "delUser();": this.InsDelUser(); break;
case "showStats();": this.InsShowStats(); break;
}
}
} }
@ -56,7 +73,8 @@ namespace Matomat
this.lcd.print("²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²" + this.lcd.print("²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²" +
"² Du hast zu viel Geld auf dem Konto ²" + "² Du hast zu viel Geld auf dem Konto ²" +
"² BITTE bezahlen! | Grenze 20€ ²" + "² BITTE bezahlen! | Grenze 20€ ²" +
"²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²", LCDDisplay.Status.Error, 5); "²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²",
LCDDisplay.Status.Error, 5);
} }
} }
@ -104,17 +122,12 @@ namespace Matomat
return new User(userId); return new User(userId);
} }
internal bool die()
{
return shutdown;
}
internal void GetInitStatus() internal void GetInitStatus()
{ {
lcd.print("²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²abcdef 321" + lcd.print("²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²abcdef 321" +
"² MATOMAT Wilkommen! ²ghijkl 123" + "² MATOMAT Wilkommen! ²ghijkl 123" +
"² Frohes genießen der Mate ²mnopqr 066" + "² Frohes genießen der Mate ²mnopqr 066" +
"²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²stuvwx 001"); "²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²stuvwx 001");
} }
} }
} }

View File

@ -36,6 +36,8 @@ namespace Matomat
public override void query(string sql) public override void query(string sql)
{ {
this.err = null; this.err = null;
if (this.data is MySqlDataReader && !this.data.IsClosed)
this.data.Close();
this.data = null; this.data = null;
this.data_b = true; this.data_b = true;
if (sql.ToUpper().Substring(0, 6) == "SELECT") if (sql.ToUpper().Substring(0, 6) == "SELECT")
@ -191,6 +193,7 @@ namespace Matomat
} }
return row; return row;
} }
this.data.Close();
return null; return null;
} }
public override Exception getError() public override Exception getError()

View File

@ -195,6 +195,8 @@ namespace Matomat
public void RequestStop() public void RequestStop()
{ {
_shouldStop = true; _shouldStop = true;
if (this.serialPort.IsOpen)
this.serialPort.Close();
} }
} }
} }

View File

@ -28,19 +28,19 @@ namespace Matomat
if (t == null) if (t == null)
{ {
this.found = false; this.found = false;
return;
}
this.found = true;
if (t.iscommand)
{
this.type = ProdType.instruction;
} }
else else
{ {
this.found = true; this.type = ProdType.product;
if (t.iscommand)
{
this.type = ProdType.instruction;
}
else
{
this.type = ProdType.product;
}
} }
} }
internal bool vaild() internal bool vaild()

View File

@ -12,7 +12,6 @@ namespace Matomat
public User(long userId) public User(long userId)
{ {
// TODO: Complete member initialization
this.userId = userId; this.userId = userId;
load(); load();
} }
@ -20,9 +19,12 @@ namespace Matomat
private void load() private void load()
{ {
TUser u = new Tables().getUserTable(this.userId); TUser u = new Tables().getUserTable(this.userId);
if (u == null)
if (true) {
this.found = true; this.found = false;
return;
}
this.found = true;
} }
internal bool vaild() internal bool vaild()
@ -31,6 +33,7 @@ namespace Matomat
if (!found) if (!found)
{ {
lcd.print("User wurde nich gefunden",LCDDisplay.Status.Error,5); lcd.print("User wurde nich gefunden",LCDDisplay.Status.Error,5);
System.Threading.Thread.Sleep(4500);
return false; return false;
} }
return true; return true;

View File

@ -18,8 +18,10 @@ namespace Matomat
rfid = new RFIDReader(); rfid = new RFIDReader();
barcode = new BarcodeReader(); barcode = new BarcodeReader();
automat = new Automat(); automat = new Automat();
automat.stopThread += new Automat.stopEvent(RequestStop);
lcd = Factory.getLCDDisplay(); lcd = Factory.getLCDDisplay();
inp = Factory.getInput(); inp = Factory.getInput();
_shouldStop = false;
} }
public void DoWork() public void DoWork()
{ {
@ -29,11 +31,12 @@ namespace Matomat
InputData input = inp.getAnyInput(0); InputData input = inp.getAnyInput(0);
automat.doJob(input); automat.doJob(input);
} }
Console.WriteLine("worker thread: terminating gracefully."); lcd.print("Matomat Beendet!");
lcd.RequestStop();
} }
public void RequestStop() private void RequestStop(bool stop)
{ {
_shouldStop = true; _shouldStop = stop;
} }
} }