diff --git a/Matomat/App.config b/Matomat/App.config index 60aa43a..07c746f 100644 --- a/Matomat/App.config +++ b/Matomat/App.config @@ -10,5 +10,6 @@ + \ No newline at end of file diff --git a/Matomat/Automat.cs b/Matomat/Automat.cs index bfae845..1e5b292 100644 --- a/Matomat/Automat.cs +++ b/Matomat/Automat.cs @@ -45,19 +45,23 @@ namespace Matomat if (prod.GetProdType() == EAN13.ProdType.product) { - this.sell(prod, user); + Instruction.sell(prod, user); } if (prod.GetProdType() == EAN13.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(user); break; - /*case "delUser();": this.InsDelUser(); break; - case "showStats();": this.InsShowStats(); 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,Instruction.Stats.LastMonth); break; + case "showStats(All);": Instruction.InsShowStats(user, Instruction.Stats.All); break; } } } @@ -67,110 +71,22 @@ namespace Matomat if (!prod.vaild()) return; - if (prod.GetFunctName().ToLower() == "exit();") + if (prod.GetProdType() == EAN13.ProdType.instruction) { - this.stopThread(true); - return; + switch (prod.GetFunctName().ToLower()) + { + case "exit();": this.stopThread(true); break; + case "showStats();": Instruction.InsShowStats(); break; + default: this.showProdInfo(prod); break; + } + } + else + { + this.showProdInfo(prod); } - - this.showProdInfo(prod); } } - private void InsAddUser(RfidCode admin) - { - if (!admin.IsAdmin()) - { - Factory.getLCD().printb("Du bist kein Admin,\ndu kannst nichts Aufladen!", LCDDisplay.Status.Error, 5); - System.Threading.Thread.Sleep(4500); - return; - } - - Factory.getLCD().printb("Bitte die neue Userkarte auf\nden RFID Leser auflegen."); - InputData target = Factory.getInput().getCardInput(20); - if (target.type == InputData.types.None) - return; - - RfidCode user = new RfidCode(target.id); - if (user.vaild(true)) - { - Factory.getLCD().printb("Dieser User ist schon\nRegistriert", LCDDisplay.Status.Warn, 5); - System.Threading.Thread.Sleep(4500); - return; - } - - Factory.getLCD().printb("Bitte den Usernamen [255] eingeben:"); - string username = Console.ReadLine(); - Factory.getLCD().printb("Username:\n" + username); - System.Threading.Thread.Sleep(4500); - - Factory.getLCD().printb("Bitte Kürzel [8] eingeben:"); - string kurzel = Console.ReadLine(); - Factory.getLCD().printb("Kürzel:\n" + kurzel); - System.Threading.Thread.Sleep(4500); - - Factory.getLCD().printb("Bitte E-Mail [255] eingeben:"); - string email = Console.ReadLine(); - Factory.getLCD().printb("E-Mail:\n" + email); - System.Threading.Thread.Sleep(4500); - - Factory.getLCD().printb("Bitte Admin [1|0] eingeben:"); - string isadmin = Console.ReadLine(); - Factory.getLCD().printb("Admin:\n" + isadmin); - System.Threading.Thread.Sleep(4500); - - string sql = "INSERT INTO `user` (`userid`,`username`,`admin`,`shortname`,`email`) VALUES (" + - "'" + Factory.getDBO().quote(target.id.ToString()) + "'," + - "'" + Factory.getDBO().quote(username) + "'," + - "'" + Factory.getDBO().quote(isadmin == "1"?"1":"0") + "'," + - "'" + Factory.getDBO().quote(kurzel) + "'," + - "'" + Factory.getDBO().quote(email) + "')"; - Factory.getDBO().query(sql); - - Factory.getLCD().printb("Neuen User eingefügt:\n" + kurzel); - System.Threading.Thread.Sleep(4500); - } - - private void InsAufladen(int betrag, RfidCode admin) - { - if (!admin.IsAdmin()) - { - Factory.getLCD().printb("Du bist kein Admin,\ndu kannst nichts Aufladen!", LCDDisplay.Status.Error, 5); - System.Threading.Thread.Sleep(4500); - return; - } - - Factory.getLCD().printb("Bitte die Zielkarte auf den\nRFID Leser auflegen"); - InputData target = Factory.getInput().getCardInput(20); - if (target.type == InputData.types.None) - return; - - RfidCode user = new RfidCode(target.id); - if (!user.vaild()) - return; - - Factory.getLCD().printb("Betrag von User " + user.GetUserName() + "\num " + betrag + " € verringert"); - user.SetUserKonto(user.GetUserKonto()-betrag); - System.Threading.Thread.Sleep(2000); - } - - private void sell(EAN13 prod, RfidCode user) - { - if (user.GetUserKonto() > 19) - { - Factory.getLCD().printb("Du hast zu viel Geld auf dem Konto\nBITTE bezahlen! | Grenze 20€", LCDDisplay.Status.Error, 5); - return; - } - Factory.getDBO().query("INSERT INTO `history` (`prod`,`user`,`time`) VALUES (" + - "'" + Factory.getDBO().quote(prod.GetDbId().ToString()) + "'," + - "'" + Factory.getDBO().quote(user.GetDbId().ToString()) + "'," + - "NOW())"); - Factory.getDBO().query("UPDATE `user` SET `credits` = `credits`+1 WHERE `user`.`id` = '" + - Factory.getDBO().quote(user.GetDbId().ToString()) + "'"); - Factory.getLCD().printb("Guten Durst mit der\n" + prod.GetProdName() + "!", 4); - System.Threading.Thread.Sleep(3500); - } - private void showProdInfo(EAN13 prod) { if (prod.GetProdType() == EAN13.ProdType.product) @@ -199,15 +115,17 @@ namespace Matomat internal void GetInitStatus() { List l = new Tables().getBestlist(); - string[] p = new string[4]; - for (int i = 0; i < 4; i++) + string[] p = new string[3]; + for (int i = 0; i < 3; i++) { p[i] = (l.Count >= i + 1) ? l.ElementAt(i).name.PadRight(8, ' ').Substring(0, 8) + " " + (l.ElementAt(i).num % 1000).ToString().PadLeft(3, '0') : " "; } - Factory.getLCD().print("²²²²²²²²²²²²²²²²²²²²²²²²²²²²" + p[0] + - "² MATOMAT Wilkommen! ²" + p[1] + - "² Frohes genießen der Mate ²" + p[2] + - "²²²²²²²²²²²²²²²²²²²²²²²²²²²²" + p[3]); + int k = 4232; + int avg = 234; + Factory.getLCD().print("Koffein im Umlauf: "+ k.ToString().PadLeft(4,' ') + " mg ("+ avg.ToString().PadLeft(4,' ')+" mg/Per)"+ + "²²²²²²²²²²²²²²²²²²²²²²²²²²²²" + p[0] + + "² MATOMAT Wilkommen! ²" + p[1] + + "² Frohes genießen der Mate ²" + p[2]); } } } diff --git a/Matomat/Data/EAN13.cs b/Matomat/Data/EAN13.cs index 14fa7f5..6e74dde 100644 --- a/Matomat/Data/EAN13.cs +++ b/Matomat/Data/EAN13.cs @@ -55,14 +55,9 @@ namespace Matomat.Data internal bool vaild() { - LCDDisplay lcd = Factory.getLCD(); if (!found) { - lcd.printb("Produkt wurde nich gefunden\nEAN13: " + this.GetProdId().ToString() + " unbekannt", LCDDisplay.Status.Error, 5); - /*lcd.print("²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²"+ - "² Produkt wurde nich gefunden ²"+ - "² EAN13: "+(this.GetProdId().ToString()+" unbekannt").PadRight(29,' ')+" ²"+ - "²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²", LCDDisplay.Status.Error, 5);*/ + Factory.getLCD().printb("Produkt wurde nich gefunden\nEAN13: " + this.GetProdId().ToString() + " unbekannt", LCDDisplay.Status.Error, 5); System.Threading.Thread.Sleep(4500); return false; } diff --git a/Matomat/Database/Tables/Tables.Product.cs b/Matomat/Database/Tables/Tables.Product.cs index 07bd544..d6674e9 100644 --- a/Matomat/Database/Tables/Tables.Product.cs +++ b/Matomat/Database/Tables/Tables.Product.cs @@ -7,93 +7,96 @@ namespace Matomat.Database.Tables { class TProduct : Tables { - public TProduct() - { - } - public TProduct(int id, long barcode, string name, int cost, bool iscommand) - { - this._id = id; - this._barcode = barcode; - this._name = name; - this._cost = cost; - this._iscommand = iscommand; - } - private int _id; - public int id - { - get - { - return _id; - } - set - { - if (_id != value) - { - _id = value; - } - } - } + public TProduct() + { + } + public TProduct(int id, long barcode, string name, int cost, bool iscommand, int caffeine) + { + this._id = id; + this._barcode = barcode; + this._name = name; + this._cost = cost; + this._iscommand = iscommand; + this._caffeine = caffeine; + } + private int _id; + public int id + { + get + { + return _id; + } + set + { + if (_id != value) + { + _id = value; + } + } + } - private long _barcode; - public long barcode - { - get - { - return _barcode; - } - set - { - if (_barcode != value) - { - _barcode = value; - } - } - } + private long _barcode; + public long barcode + { + get + { + return _barcode; + } + set + { + if (_barcode != value) + { + _barcode = value; + } + } + } - private string _name; - public string name - { - get - { - return _name; - } - set - { - if (_name != value) - { - _name = value; - } - } - } - private int _cost; - public int cost - { - get - { - return _cost; - } - set - { - if (_cost != value) - { - _cost = value; - } - } - } - private bool _iscommand; - public bool iscommand - { - get - { - return _iscommand; - } - set - { - if (_iscommand != value) - { - _iscommand = value; - } - } - } + private string _name; + public string name + { + get + { + return _name; + } + set + { + if (_name != value) + { + _name = value; + } + } + } + private int _cost; + public int cost + { + get + { + return _cost; + } + set + { + if (_cost != value) + { + _cost = value; + } + } + } + private bool _iscommand; + public bool iscommand + { + get + { + return _iscommand; + } + set + { + if (_iscommand != value) + { + _iscommand = value; + } + } + } + + public int _caffeine { get; private set; } } } diff --git a/Matomat/Database/Tables/Tables.cs b/Matomat/Database/Tables/Tables.cs index fbc6a4f..988407e 100644 --- a/Matomat/Database/Tables/Tables.cs +++ b/Matomat/Database/Tables/Tables.cs @@ -31,13 +31,13 @@ namespace Matomat.Database.Tables public TProduct getProdTable(long barcode) { TDatabase db = Factory.getDBO(); - db.query("SELECT * FROM `product` WHERE `barcode` = " + db.quote(barcode.ToString())); + db.query("SELECT `id`, `barcode`,`name`,`cost`,`iscommand`,`caffeine` FROM `product` WHERE `barcode` = " + db.quote(barcode.ToString())); object[] row = db.getResult(); if (row == null) { return null; } - return new TProduct((int)row[0], (long)row[1], (string)row[2], (int)row[3], (bool)row[4]); + return new TProduct((int)row[0], (long)row[1], (string)row[2], (int)row[3], (bool)row[4], (int)row[5]); } internal List getBestlist() diff --git a/Matomat/Input/Config.cs b/Matomat/Input/Config.cs index 7f26cc5..0cac250 100644 --- a/Matomat/Input/Config.cs +++ b/Matomat/Input/Config.cs @@ -30,6 +30,7 @@ namespace Matomat.Input this.mysql_pw = (string)config.GetValue("mysql_pw", typeof(string)); this.mysql_driver = (string)config.GetValue("mysql_driver", typeof(string)); this.debug = (bool)config.GetValue("debug", typeof(bool)); + this.sell = (bool)config.GetValue("sell", typeof(bool)); } catch (Exception) { } } @@ -53,6 +54,7 @@ namespace Matomat.Input public string mysql_pw { get; private set; } public string mysql_driver { get; private set; } public bool debug { get; private set; } + public bool sell { get; private set; } public void RequestStop() { diff --git a/Matomat/Instruction.cs b/Matomat/Instruction.cs new file mode 100644 index 0000000..0bbc642 --- /dev/null +++ b/Matomat/Instruction.cs @@ -0,0 +1,165 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Matomat.Data; +using Matomat.Helper; +using Matomat.Output; +using Matomat.Input; + +namespace Matomat +{ + class Instruction + { + public enum Stats + { + LastMonth, + All + } + public static void InsAufladen(int betrag, RfidCode admin) + { + if (!admin.IsAdmin()) + { + Factory.getLCD().printb("Du bist kein Admin,\ndu kannst nichts Aufladen!", LCDDisplay.Status.Error, 5); + System.Threading.Thread.Sleep(4500); + return; + } + if (!Factory.getConfig().sell) + { + Factory.getLCD().printb("Das Aufladen\nist abgeschaltet!", LCDDisplay.Status.Error, 5); + System.Threading.Thread.Sleep(4500); + return; + } + + Factory.getLCD().printb("Bitte die Zielkarte auf den\nRFID Leser auflegen"); + InputData target = Factory.getInput().getCardInput(20); + if (target.type == InputData.types.None) + return; + + RfidCode user = new RfidCode(target.id); + if (!user.vaild()) + return; + + Factory.getLCD().printb("Betrag von User " + user.GetUserName() + "\num " + betrag + " € verringert"); + user.SetUserKonto(user.GetUserKonto()-betrag); + System.Threading.Thread.Sleep(2000); + } + + public static void InsAddUser(RfidCode admin) + { + if (!admin.IsAdmin()) + { + Factory.getLCD().printb("Du bist kein Admin,\ndu kannst niemanden Hinzufügen!", LCDDisplay.Status.Error, 5); + System.Threading.Thread.Sleep(4500); + return; + } + + Factory.getLCD().printb("Bitte die neue Userkarte auf\nden RFID Leser auflegen."); + InputData target = Factory.getInput().getCardInput(20); + if (target.type == InputData.types.None) + return; + + RfidCode user = new RfidCode(target.id); + if (user.vaild(true)) + { + Factory.getLCD().printb("Dieser User ist schon\nRegistriert", LCDDisplay.Status.Warn, 5); + System.Threading.Thread.Sleep(4500); + return; + } + + Factory.getLCD().printb("Bitte den Usernamen [255] eingeben:"); + string username = Console.ReadLine(); + Factory.getLCD().printb("Username:\n" + username); + System.Threading.Thread.Sleep(4500); + + Factory.getLCD().printb("Bitte Kürzel [8] eingeben:"); + string kurzel = Console.ReadLine(); + Factory.getLCD().printb("Kürzel:\n" + kurzel); + System.Threading.Thread.Sleep(4500); + + Factory.getLCD().printb("Bitte E-Mail [255] eingeben:"); + string email = Console.ReadLine(); + Factory.getLCD().printb("E-Mail:\n" + email); + System.Threading.Thread.Sleep(4500); + + Factory.getLCD().printb("Bitte Admin [1|0] eingeben:"); + string isadmin = Console.ReadLine(); + Factory.getLCD().printb("Admin:\n" + isadmin); + System.Threading.Thread.Sleep(4500); + + string sql = "INSERT INTO `user` (`userid`,`username`,`admin`,`shortname`,`email`) VALUES (" + + "'" + Factory.getDBO().quote(target.id.ToString()) + "'," + + "'" + Factory.getDBO().quote(username) + "'," + + "'" + Factory.getDBO().quote(isadmin == "1" ? "1" : "0") + "'," + + "'" + Factory.getDBO().quote(kurzel) + "'," + + "'" + Factory.getDBO().quote(email) + "')"; + Factory.getDBO().query(sql); + + Factory.getLCD().printb("Neuen User eingefügt:\n" + kurzel); + System.Threading.Thread.Sleep(4500); + } + + public static void InsDelUser(RfidCode admin) + { + if (!admin.IsAdmin()) + { + Factory.getLCD().printb("Du bist kein Admin,\ndu kannst niemanden Löschen!", LCDDisplay.Status.Error, 5); + System.Threading.Thread.Sleep(4500); + return; + } + Factory.getLCD().printb("Bitte die alte Userkarte auf\nden RFID Leser auflegen."); + InputData target = Factory.getInput().getCardInput(20); + if (target.type == InputData.types.None) + return; + + RfidCode user = new RfidCode(target.id); + if (!user.vaild()) + return; + + Factory.getDBO().query("DELETE * FROM `user` WHERE `id`='" + Factory.getDBO().quote(user.GetDbId().ToString()) + "'"); + + Factory.getLCD().printb("User erfolgreich gelöscht:\n" + user.GetUserName(), 3); + System.Threading.Thread.Sleep(2500); + } + + public static void sell(EAN13 prod, RfidCode user) + { + if (Factory.getConfig().sell && user.GetUserKonto() > 19) + { + Factory.getLCD().printb("Du hast zu viel Geld auf dem Konto\nBITTE bezahlen! | Grenze 20€", LCDDisplay.Status.Error, 5); + return; + } + Factory.getDBO().query("INSERT INTO `history` (`prod`,`user`,`time`) VALUES (" + + "'" + Factory.getDBO().quote(prod.GetDbId().ToString()) + "'," + + "'" + Factory.getDBO().quote(user.GetDbId().ToString()) + "'," + + "NOW())"); + if (Factory.getConfig().sell) + { + Factory.getDBO().query("UPDATE `user` SET `credits` = `credits`+1 WHERE `user`.`id` = '" + + Factory.getDBO().quote(user.GetDbId().ToString()) + "'"); + } + Factory.getLCD().printb("Guten Durst mit der\n" + prod.GetProdName() + "!", 4); + System.Threading.Thread.Sleep(3500); + } + + internal static void InsShowStats() + { + throw new NotImplementedException(); + } + + internal static void InsAddProd(RfidCode user) + { + throw new NotImplementedException(); + } + + internal static void InsDelProd(RfidCode user) + { + throw new NotImplementedException(); + } + + internal static void InsShowStats(RfidCode user, Stats stats) + { + throw new NotImplementedException(); + } + } +} diff --git a/Matomat/Matomat.csproj b/Matomat/Matomat.csproj index 2f272be..fc1c9bc 100644 --- a/Matomat/Matomat.csproj +++ b/Matomat/Matomat.csproj @@ -63,6 +63,7 @@ + diff --git a/Matomat/Worker.cs b/Matomat/Worker.cs index 02ae142..a31ea8a 100644 --- a/Matomat/Worker.cs +++ b/Matomat/Worker.cs @@ -27,8 +27,11 @@ namespace Matomat while (!_shouldStop) { automat.GetInitStatus(); - InputData input = inp.getAnyInput(0); - automat.doJob(input); + InputData input = inp.getAnyInput(60); + if (input.type != InputData.types.None) + { + automat.doJob(input); + } } Factory.getLCD().printb("Der Matomat wurde beendet.\nEinen schönen Tag!"); Factory.rmLCD();