diff --git a/Matomat/Automat.cs b/Matomat/Automat.cs index 8f3ce65..5353f2d 100644 --- a/Matomat/Automat.cs +++ b/Matomat/Automat.cs @@ -13,6 +13,10 @@ namespace Matomat private LCDDisplay lcd; private Input inp; + public delegate void stopEvent(bool stop); + + public event stopEvent stopThread; + public Automat() { lcd = Factory.getLCDDisplay(); inp = Factory.getInput(); @@ -37,6 +41,19 @@ namespace Matomat { 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("²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²" + "² Du hast zu viel Geld auf dem Konto ²" + "² BITTE bezahlen! | Grenze 20€ ²" + - "²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²", LCDDisplay.Status.Error, 5); + "²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²", + LCDDisplay.Status.Error, 5); } } @@ -104,17 +122,12 @@ namespace Matomat return new User(userId); } - internal bool die() - { - return shutdown; - } - internal void GetInitStatus() { lcd.print("²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²abcdef 321" + - "² MATOMAT Wilkommen! ²ghijkl 123" + - "² Frohes genießen der Mate ²mnopqr 066" + - "²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²stuvwx 001"); + "² MATOMAT Wilkommen! ²ghijkl 123" + + "² Frohes genießen der Mate ²mnopqr 066" + + "²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²stuvwx 001"); } } } diff --git a/Matomat/DBDriverMysqli.cs b/Matomat/DBDriverMysqli.cs index 1c3e550..a25c3f9 100644 --- a/Matomat/DBDriverMysqli.cs +++ b/Matomat/DBDriverMysqli.cs @@ -36,6 +36,8 @@ namespace Matomat public override void query(string sql) { this.err = null; + if (this.data is MySqlDataReader && !this.data.IsClosed) + this.data.Close(); this.data = null; this.data_b = true; if (sql.ToUpper().Substring(0, 6) == "SELECT") @@ -191,6 +193,7 @@ namespace Matomat } return row; } + this.data.Close(); return null; } public override Exception getError() diff --git a/Matomat/LCDDisplay.cs b/Matomat/LCDDisplay.cs index 89b82bf..9c28f77 100644 --- a/Matomat/LCDDisplay.cs +++ b/Matomat/LCDDisplay.cs @@ -195,6 +195,8 @@ namespace Matomat public void RequestStop() { _shouldStop = true; + if (this.serialPort.IsOpen) + this.serialPort.Close(); } } } diff --git a/Matomat/Prod.cs b/Matomat/Prod.cs index aec9081..1610cee 100644 --- a/Matomat/Prod.cs +++ b/Matomat/Prod.cs @@ -28,19 +28,19 @@ namespace Matomat if (t == null) { this.found = false; + return; + } + + this.found = true; + if (t.iscommand) + { + this.type = ProdType.instruction; } else { - this.found = true; - if (t.iscommand) - { - this.type = ProdType.instruction; - } - else - { - this.type = ProdType.product; - } + this.type = ProdType.product; } + } internal bool vaild() diff --git a/Matomat/User.cs b/Matomat/User.cs index 0520a2f..bcb207f 100644 --- a/Matomat/User.cs +++ b/Matomat/User.cs @@ -12,7 +12,6 @@ namespace Matomat public User(long userId) { - // TODO: Complete member initialization this.userId = userId; load(); } @@ -20,9 +19,12 @@ namespace Matomat private void load() { TUser u = new Tables().getUserTable(this.userId); - - if (true) - this.found = true; + if (u == null) + { + this.found = false; + return; + } + this.found = true; } internal bool vaild() @@ -31,6 +33,7 @@ namespace Matomat if (!found) { lcd.print("User wurde nich gefunden",LCDDisplay.Status.Error,5); + System.Threading.Thread.Sleep(4500); return false; } return true; diff --git a/Matomat/Worker.cs b/Matomat/Worker.cs index 4e56c98..09fcf7e 100644 --- a/Matomat/Worker.cs +++ b/Matomat/Worker.cs @@ -18,8 +18,10 @@ namespace Matomat rfid = new RFIDReader(); barcode = new BarcodeReader(); automat = new Automat(); + automat.stopThread += new Automat.stopEvent(RequestStop); lcd = Factory.getLCDDisplay(); inp = Factory.getInput(); + _shouldStop = false; } public void DoWork() { @@ -29,11 +31,12 @@ namespace Matomat InputData input = inp.getAnyInput(0); 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; } }