This commit is contained in:
BlubbFish 2013-07-08 21:34:13 +00:00
parent eb7db63bb3
commit 1bf6fe008f
9 changed files with 296 additions and 208 deletions

View File

@ -10,5 +10,6 @@
<add key="mysql_pw" value="mafia"/>
<add key="mysql_driver" value="mysqli"/>
<add key="debug" value="false"/>
<add key="sell" value="true"/>
</appSettings>
</configuration>

View File

@ -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,108 +71,20 @@ 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);
}
}
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)
@ -199,15 +115,17 @@ namespace Matomat
internal void GetInitStatus()
{
List<TBest> 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] +
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] +
"²²²²²²²²²²²²²²²²²²²²²²²²²²²²" + p[3]);
"² Frohes genießen der Mate ²" + p[2]);
}
}
}

View File

@ -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;
}

View File

@ -10,13 +10,14 @@ namespace Matomat.Database.Tables
public TProduct()
{
}
public TProduct(int id, long barcode, string name, int cost, bool iscommand)
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
@ -95,5 +96,7 @@ namespace Matomat.Database.Tables
}
}
}
public int _caffeine { get; private set; }
}
}

View File

@ -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<TBest> getBestlist()

View File

@ -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()
{

165
Matomat/Instruction.cs Normal file
View File

@ -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();
}
}
}

View File

@ -63,6 +63,7 @@
<Compile Include="Helper\Factory.cs" />
<Compile Include="Helper\Types.cs" />
<Compile Include="Input\TInput.cs" />
<Compile Include="Instruction.cs" />
<Compile Include="Output\LCDDisplay.cs" />
<Compile Include="Data\EAN13.cs" />
<Compile Include="Program.cs" />

View File

@ -27,9 +27,12 @@ namespace Matomat
while (!_shouldStop)
{
automat.GetInitStatus();
InputData input = inp.getAnyInput(0);
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();
Factory.rmInput();