diff --git a/Matomat/App.config b/Matomat/App.config index 07c746f..8da3d8e 100644 --- a/Matomat/App.config +++ b/Matomat/App.config @@ -1,8 +1,8 @@  - - + + diff --git a/Matomat/Automat.cs b/Matomat/Automat.cs index 1e5b292..989f499 100644 --- a/Matomat/Automat.cs +++ b/Matomat/Automat.cs @@ -12,7 +12,7 @@ namespace Matomat { class Automat { - private bool shutdown = false; + //private bool shutdown = false; public delegate void stopEvent(bool stop); @@ -73,7 +73,7 @@ namespace Matomat if (prod.GetProdType() == EAN13.ProdType.instruction) { - switch (prod.GetFunctName().ToLower()) + switch (prod.GetFunctName()) { case "exit();": this.stopThread(true); break; case "showStats();": Instruction.InsShowStats(); break; @@ -94,7 +94,7 @@ namespace Matomat long id = prod.GetProdId(); double price = prod.GetProdPrice(); string name = prod.GetProdName(); - Factory.getLCD().printb("Produkt: " + name + "\nPreis: " + price + "€ EAN13: " + id, 2); + Factory.getLCD().printb("Produkt: " + name + "\nPreis: " + price.ToString("N2") + "€ EAN13: " + id, 2); } if (prod.GetProdType() == EAN13.ProdType.instruction) { @@ -106,10 +106,10 @@ namespace Matomat private void showUserInfo(RfidCode user) { string name = user.GetUserName(); - int konto = user.GetUserKonto(); + double konto = user.GetUserKonto(); long id = user.GetUserId(); - long all = user.GetUserAll(); - Factory.getLCD().printb("User: " + name + " Betrag: " + konto + " €\nUserID: " + id + " Gesamt: " + all + " €", 5); + double all = user.GetUserAll(); + Factory.getLCD().printb("User: " + name + " Betrag: " + konto.ToString("N2") + " €\nUserID: " + id + " Gesamt: " + all.ToString("N2") + " €", 5); } internal void GetInitStatus() diff --git a/Matomat/Data/EAN13.cs b/Matomat/Data/EAN13.cs index 6e74dde..204755c 100644 --- a/Matomat/Data/EAN13.cs +++ b/Matomat/Data/EAN13.cs @@ -76,7 +76,7 @@ namespace Matomat.Data internal double GetProdPrice() { - return this.price; + return ((double)this.price)/100; } internal string GetProdName() @@ -93,5 +93,17 @@ namespace Matomat.Data { return this.id; } + + public bool vaild(bool silent) + { + if (silent) + { + return found; + } + else + { + return vaild(); + } + } } } diff --git a/Matomat/Data/RfidCode.cs b/Matomat/Data/RfidCode.cs index 3d3b8ac..3a14bf2 100644 --- a/Matomat/Data/RfidCode.cs +++ b/Matomat/Data/RfidCode.cs @@ -14,7 +14,7 @@ namespace Matomat.Data private long userId; private bool found; private string username; - private string shrotname; + private string shortname; private int credits; private long all; private bool admin; @@ -36,7 +36,7 @@ namespace Matomat.Data } TBest b = new Tables().getUserMax(u.id); this.found = true; - this.shrotname = u.shortname; + this.shortname = u.shortname; this.credits = u.credits; this.all = b.num; this.admin = u.admin; @@ -70,12 +70,12 @@ namespace Matomat.Data internal string GetUserName() { - return this.shrotname; + return this.shortname; } - internal int GetUserKonto() + internal double GetUserKonto() { - return this.credits; + return ((double)this.credits) / 100; } internal long GetUserId() @@ -88,9 +88,9 @@ namespace Matomat.Data return this.id; } - internal long GetUserAll() + internal double GetUserAll() { - return this.all; + return ((double)this.all) / 100; } internal bool IsAdmin() @@ -98,8 +98,9 @@ namespace Matomat.Data return this.admin; } - internal void SetUserKonto(int p) + internal void SetUserKonto(double cost) { + int p = (int)(cost * 100); TDatabase db = Factory.getDBO(); this.credits = p; db.query("UPDATE `user` SET `credits` = '" + db.quote(p.ToString())+"' WHERE "+ diff --git a/Matomat/Input/RFIDReader.cs b/Matomat/Input/RFIDReader.cs index 0fd9cd0..21367ab 100644 --- a/Matomat/Input/RFIDReader.cs +++ b/Matomat/Input/RFIDReader.cs @@ -20,7 +20,7 @@ namespace Matomat.Input return r.readKey(); //return 388914410; } - catch (Exception)// e) + catch (Exception) //e) { //Console.WriteLine(e); } diff --git a/Matomat/Instruction.cs b/Matomat/Instruction.cs index 0bbc642..93ff622 100644 --- a/Matomat/Instruction.cs +++ b/Matomat/Instruction.cs @@ -124,7 +124,7 @@ namespace Matomat public static void sell(EAN13 prod, RfidCode user) { - if (Factory.getConfig().sell && user.GetUserKonto() > 19) + if (Factory.getConfig().sell && user.GetUserKonto() > 1900) { Factory.getLCD().printb("Du hast zu viel Geld auf dem Konto\nBITTE bezahlen! | Grenze 20€", LCDDisplay.Status.Error, 5); return; @@ -135,7 +135,7 @@ namespace Matomat "NOW())"); if (Factory.getConfig().sell) { - Factory.getDBO().query("UPDATE `user` SET `credits` = `credits`+1 WHERE `user`.`id` = '" + + Factory.getDBO().query("UPDATE `user` SET `credits` = `credits`+" + Factory.getDBO().quote((prod.GetProdPrice() * 100).ToString("N0")) + " WHERE `user`.`id` = '" + Factory.getDBO().quote(user.GetDbId().ToString()) + "'"); } Factory.getLCD().printb("Guten Durst mit der\n" + prod.GetProdName() + "!", 4); @@ -147,9 +147,52 @@ namespace Matomat throw new NotImplementedException(); } - internal static void InsAddProd(RfidCode user) + internal static void InsAddProd(RfidCode admin) { - throw new NotImplementedException(); + if (!admin.IsAdmin()) + { + Factory.getLCD().printb("Du bist kein Admin,\ndu kannst nichts Hinzufügen!", LCDDisplay.Status.Error, 5); + System.Threading.Thread.Sleep(4500); + return; + } + + Factory.getLCD().printb("Bitte das neue Produkt\nüber den Barcodeleser ziehen."); + InputData target = Factory.getInput().getProdInput(20); + if (target.type == InputData.types.None) + return; + + EAN13 code = new EAN13(target.id); + if (code.vaild(true)) + { + Factory.getLCD().printb("Dieser Produkt ist schon\nRegistriert", LCDDisplay.Status.Warn, 5); + System.Threading.Thread.Sleep(4500); + return; + } + + Factory.getLCD().printb("Bitte den Produktnamen [255] eingeben:"); + string name = Console.ReadLine(); + Factory.getLCD().printb("Produktname:\n" + name); + System.Threading.Thread.Sleep(4500); + + Factory.getLCD().printb("Bitte Preis [Cent] eingeben:"); + string preis = Console.ReadLine(); + Factory.getLCD().printb("Preis:\n" + preis + " €Cent"); + System.Threading.Thread.Sleep(4500); + + Factory.getLCD().printb("Bitte Koffeingehalt [mg] eingeben:"); + string coffeine = Console.ReadLine(); + Factory.getLCD().printb("Koffeingehalt:\n" + coffeine + " mg"); + System.Threading.Thread.Sleep(4500); + + string sql = "INSERT INTO `product` (`barcode`,`name`,`cost`,`caffeine`) VALUES (" + + "'" + Factory.getDBO().quote(target.id.ToString()) + "'," + + "'" + Factory.getDBO().quote(name) + "'," + + "'" + Factory.getDBO().quote(preis) + "'," + + "'" + Factory.getDBO().quote(coffeine) + "')"; + Factory.getDBO().query(sql); + + Factory.getLCD().printb("Neues Produkt eingefügt:\n" + name); + System.Threading.Thread.Sleep(4500); } internal static void InsDelProd(RfidCode user) diff --git a/Matomat/Matomat.csproj b/Matomat/Matomat.csproj index fc1c9bc..7eb412a 100644 --- a/Matomat/Matomat.csproj +++ b/Matomat/Matomat.csproj @@ -77,10 +77,10 @@ - PreserveNewest + Always - PreserveNewest + Always