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_pw" value="mafia"/>
<add key="mysql_driver" value="mysqli"/> <add key="mysql_driver" value="mysqli"/>
<add key="debug" value="false"/> <add key="debug" value="false"/>
<add key="sell" value="true"/>
</appSettings> </appSettings>
</configuration> </configuration>

View File

@ -45,19 +45,23 @@ namespace Matomat
if (prod.GetProdType() == EAN13.ProdType.product) if (prod.GetProdType() == EAN13.ProdType.product)
{ {
this.sell(prod, user); Instruction.sell(prod, user);
} }
if (prod.GetProdType() == EAN13.ProdType.instruction) if (prod.GetProdType() == EAN13.ProdType.instruction)
{ {
switch (prod.GetFunctName()) switch (prod.GetFunctName())
{ {
case "exit();": this.stopThread(true); break; case "exit();": this.stopThread(true); break;
case "aufladen(10);": this.InsAufladen(10, user); break; case "aufladen(10);": Instruction.InsAufladen(10, user); break;
case "aufladen(20);": this.InsAufladen(20, user); break; case "aufladen(20);": Instruction.InsAufladen(20, user); break;
case "aufladen(5);": this.InsAufladen(5, user); break; case "aufladen(5);": Instruction.InsAufladen(5, user); break;
case "addUser();": this.InsAddUser(user); break; case "addUser();": Instruction.InsAddUser(user); break;
/*case "delUser();": this.InsDelUser(); break; case "delUser();": Instruction.InsDelUser(user); break;
case "showStats();": this.InsShowStats(); 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()) if (!prod.vaild())
return; return;
if (prod.GetFunctName().ToLower() == "exit();") if (prod.GetProdType() == EAN13.ProdType.instruction)
{ {
this.stopThread(true); switch (prod.GetFunctName().ToLower())
return; {
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) private void showProdInfo(EAN13 prod)
{ {
if (prod.GetProdType() == EAN13.ProdType.product) if (prod.GetProdType() == EAN13.ProdType.product)
@ -199,15 +115,17 @@ namespace Matomat
internal void GetInitStatus() internal void GetInitStatus()
{ {
List<TBest> l = new Tables().getBestlist(); List<TBest> l = new Tables().getBestlist();
string[] p = new string[4]; string[] p = new string[3];
for (int i = 0; i < 4; i++) 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') : " "; 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;
"² MATOMAT Wilkommen! ²" + p[1] + int avg = 234;
"² Frohes genießen der Mate ²" + p[2] + Factory.getLCD().print("Koffein im Umlauf: "+ k.ToString().PadLeft(4,' ') + " mg ("+ avg.ToString().PadLeft(4,' ')+" mg/Per)"+
"²²²²²²²²²²²²²²²²²²²²²²²²²²²²" + p[3]); "²²²²²²²²²²²²²²²²²²²²²²²²²²²²" + p[0] +
"² MATOMAT Wilkommen! ²" + p[1] +
"² Frohes genießen der Mate ²" + p[2]);
} }
} }
} }

View File

@ -55,14 +55,9 @@ namespace Matomat.Data
internal bool vaild() internal bool vaild()
{ {
LCDDisplay lcd = Factory.getLCD();
if (!found) if (!found)
{ {
lcd.printb("Produkt wurde nich gefunden\nEAN13: " + this.GetProdId().ToString() + " unbekannt", LCDDisplay.Status.Error, 5); Factory.getLCD().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);*/
System.Threading.Thread.Sleep(4500); System.Threading.Thread.Sleep(4500);
return false; return false;
} }

View File

@ -7,93 +7,96 @@ namespace Matomat.Database.Tables
{ {
class TProduct : Tables class TProduct : Tables
{ {
public TProduct() 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._id = id;
this._barcode = barcode; this._barcode = barcode;
this._name = name; this._name = name;
this._cost = cost; this._cost = cost;
this._iscommand = iscommand; this._iscommand = iscommand;
} this._caffeine = caffeine;
private int _id; }
public int id private int _id;
{ public int id
get {
{ get
return _id; {
} return _id;
set }
{ set
if (_id != value) {
{ if (_id != value)
_id = value; {
} _id = value;
} }
} }
}
private long _barcode; private long _barcode;
public long barcode public long barcode
{ {
get get
{ {
return _barcode; return _barcode;
} }
set set
{ {
if (_barcode != value) if (_barcode != value)
{ {
_barcode = value; _barcode = value;
} }
} }
} }
private string _name; private string _name;
public string name public string name
{ {
get get
{ {
return _name; return _name;
} }
set set
{ {
if (_name != value) if (_name != value)
{ {
_name = value; _name = value;
} }
} }
} }
private int _cost; private int _cost;
public int cost public int cost
{ {
get get
{ {
return _cost; return _cost;
} }
set set
{ {
if (_cost != value) if (_cost != value)
{ {
_cost = value; _cost = value;
} }
} }
} }
private bool _iscommand; private bool _iscommand;
public bool iscommand public bool iscommand
{ {
get get
{ {
return _iscommand; return _iscommand;
} }
set set
{ {
if (_iscommand != value) if (_iscommand != value)
{ {
_iscommand = value; _iscommand = value;
} }
} }
} }
public int _caffeine { get; private set; }
} }
} }

View File

@ -31,13 +31,13 @@ namespace Matomat.Database.Tables
public TProduct getProdTable(long barcode) public TProduct getProdTable(long barcode)
{ {
TDatabase db = Factory.getDBO(); 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(); object[] row = db.getResult();
if (row == null) if (row == null)
{ {
return 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() 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_pw = (string)config.GetValue("mysql_pw", typeof(string));
this.mysql_driver = (string)config.GetValue("mysql_driver", typeof(string)); this.mysql_driver = (string)config.GetValue("mysql_driver", typeof(string));
this.debug = (bool)config.GetValue("debug", typeof(bool)); this.debug = (bool)config.GetValue("debug", typeof(bool));
this.sell = (bool)config.GetValue("sell", typeof(bool));
} }
catch (Exception) { } catch (Exception) { }
} }
@ -53,6 +54,7 @@ namespace Matomat.Input
public string mysql_pw { get; private set; } public string mysql_pw { get; private set; }
public string mysql_driver { get; private set; } public string mysql_driver { get; private set; }
public bool debug { get; private set; } public bool debug { get; private set; }
public bool sell { get; private set; }
public void RequestStop() 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\Factory.cs" />
<Compile Include="Helper\Types.cs" /> <Compile Include="Helper\Types.cs" />
<Compile Include="Input\TInput.cs" /> <Compile Include="Input\TInput.cs" />
<Compile Include="Instruction.cs" />
<Compile Include="Output\LCDDisplay.cs" /> <Compile Include="Output\LCDDisplay.cs" />
<Compile Include="Data\EAN13.cs" /> <Compile Include="Data\EAN13.cs" />
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />

View File

@ -27,8 +27,11 @@ namespace Matomat
while (!_shouldStop) while (!_shouldStop)
{ {
automat.GetInitStatus(); automat.GetInitStatus();
InputData input = inp.getAnyInput(0); InputData input = inp.getAnyInput(60);
automat.doJob(input); if (input.type != InputData.types.None)
{
automat.doJob(input);
}
} }
Factory.getLCD().printb("Der Matomat wurde beendet.\nEinen schönen Tag!"); Factory.getLCD().printb("Der Matomat wurde beendet.\nEinen schönen Tag!");
Factory.rmLCD(); Factory.rmLCD();