diff --git a/Matomat/App.config b/Matomat/App.config
index b6c6250..60aa43a 100644
--- a/Matomat/App.config
+++ b/Matomat/App.config
@@ -1,13 +1,14 @@
-
-
+
+
-
+
+
\ No newline at end of file
diff --git a/Matomat/Automat.cs b/Matomat/Automat.cs
index 3923a5e..bfae845 100644
--- a/Matomat/Automat.cs
+++ b/Matomat/Automat.cs
@@ -2,6 +2,11 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
+using Matomat.Input;
+using Matomat.Output;
+using Matomat.Data;
+using Matomat.Database.Tables;
+using Matomat.Helper;
namespace Matomat
{
@@ -18,37 +23,31 @@ namespace Matomat
}
internal void doJob(InputData input)
{
- LCDDisplay lcd = Factory.getLCDDisplay();
- Input inp = Factory.getInput();
-
if (input.type == InputData.types.Card)
{
- User user = new User(input.id);
+ RfidCode user = new RfidCode(input.id);
if (!user.vaild())
return;
this.showUserInfo(user);
- lcd.print("²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²" +
- "² Bitte Produkt über den ²" +
- "² Barcodeleser halten ²" +
- "²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²");
+ Factory.getLCD().printb("Bitte Produkt über den\nBarcodeleser halten");
- InputData prodid = inp.getProdInput(20);
+ InputData prodid = Factory.getInput().getProdInput(20);
if (prodid.type == InputData.types.None)
return;
- Prod prod = new Prod(prodid.id);
+ EAN13 prod = new EAN13(prodid.id);
if(!prod.vaild())
return;
this.showProdInfo(prod);
- if (prod.GetProdType() == Prod.ProdType.product)
+ if (prod.GetProdType() == EAN13.ProdType.product)
{
this.sell(prod, user);
}
- if (prod.GetProdType() == Prod.ProdType.instruction)
+ if (prod.GetProdType() == EAN13.ProdType.instruction)
{
switch (prod.GetFunctName())
{
@@ -56,15 +55,15 @@ namespace Matomat
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(); break;
- case "delUser();": this.InsDelUser(); break;
+ case "addUser();": this.InsAddUser(user); break;
+ /*case "delUser();": this.InsDelUser(); break;
case "showStats();": this.InsShowStats(); break;*/
}
}
}
else if (input.type == InputData.types.Prod)
{
- Prod prod = new Prod(input.id);
+ EAN13 prod = new EAN13(input.id);
if (!prod.vaild())
return;
@@ -78,103 +77,137 @@ namespace Matomat
}
}
- private void InsAufladen(int betrag, User admin)
+ private void InsAddUser(RfidCode admin)
{
- LCDDisplay lcd = Factory.getLCDDisplay();
- Input inp = Factory.getInput();
if (!admin.IsAdmin())
{
- lcd.print("²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²" +
- "² Du bist kein Admin, ²" +
- "² du kannst nichts Aufladen! ²" +
- "²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²",
- LCDDisplay.Status.Error, 5);
+ Factory.getLCD().printb("Du bist kein Admin,\ndu kannst nichts Aufladen!", LCDDisplay.Status.Error, 5);
System.Threading.Thread.Sleep(4500);
return;
}
- lcd.print("²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²" +
- "² Bitte die Zielkarte auf den ²" +
- "² RFID Leser auflegen ²" +
- "²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²");
- InputData target = inp.getCardInput(20);
+
+ 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;
- User user = new User(target.id);
+ 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;
-
- lcd.print("²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²" +
- "² Betrag von User " + user.GetUserName().PadRight(8, ' ') + " ²" +
- "² um "+betrag.ToString().PadLeft(2, ' ')+" € verringert ²" +
- "²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²");
+
+ Factory.getLCD().printb("Betrag von User " + user.GetUserName() + "\num " + betrag + " € verringert");
user.SetUserKonto(user.GetUserKonto()-betrag);
System.Threading.Thread.Sleep(2000);
}
- private void sell(Prod prod, User user)
+ private void sell(EAN13 prod, RfidCode user)
{
- LCDDisplay lcd = Factory.getLCDDisplay();
if (user.GetUserKonto() > 19)
{
- lcd.print("²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²" +
- "² Du hast zu viel Geld auf dem Konto ²" +
- "² BITTE bezahlen! | Grenze 20€ ²" +
- "²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²",
- LCDDisplay.Status.Error, 5);
+ 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(Prod prod)
+ private void showProdInfo(EAN13 prod)
{
- LCDDisplay lcd = Factory.getLCDDisplay();
- if (prod.GetProdType() == Prod.ProdType.product)
+ if (prod.GetProdType() == EAN13.ProdType.product)
{
long id = prod.GetProdId();
double price = prod.GetProdPrice();
string name = prod.GetProdName();
- lcd.print("²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²" +
- "² Produkt: " + name.PadRight(27, ' ') + " ²" +
- "² Preis: " + price.ToString(2).PadLeft(6, ' ') + "€ EAN13: " + id.ToString().PadRight(14, ' ') + " ²" +
- "²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²", 2);
+ Factory.getLCD().printb("Produkt: " + name + "\nPreis: " + price + "€ EAN13: " + id, 2);
}
- if (prod.GetProdType() == Prod.ProdType.instruction)
+ if (prod.GetProdType() == EAN13.ProdType.instruction)
{
string name = prod.GetFunctName();
- lcd.print("²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²" +
- "² Instruktion: " + name.PadRight(23, ' ') + " ²" +
- "² AdminCard + Instruction + TargetCard ²" +
- "²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²", 2);
+ Factory.getLCD().printb("Instruktion: " + name + "\nAdminCard + Instruction + TargetCard", 2);
}
}
- private void showUserInfo(User user)
+ private void showUserInfo(RfidCode user)
{
- LCDDisplay lcd = Factory.getLCDDisplay();
-
string name = user.GetUserName();
int konto = user.GetUserKonto();
long id = user.GetUserId();
long all = user.GetUserAll();
- lcd.print("²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²" +
- "² User: " + name.PadRight(8, ' ') + " Betrag: " + (konto.ToString() + " €").PadRight(7, ' ') + " ²" +
- "² UserID: " + id.ToString().PadRight(12, ' ') + " Gesamt: " + (all.ToString() + " €").PadRight(7, ' ') + " ²" +
- "²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²", 5);
+ Factory.getLCD().printb("User: " + name + " Betrag: " + konto + " €\nUserID: " + id + " Gesamt: " + all + " €", 5);
}
internal void GetInitStatus()
{
- LCDDisplay lcd = Factory.getLCDDisplay();
List l = new Tables().getBestlist();
string[] p = new string[4];
for (int i = 0; i < 4; i++)
{
- p[i] = (l.Count >= i + 1) ? l.ElementAt(i).name.PadRight(6, ' ').Substring(0, 6) + " " + (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') : " ";
}
- lcd.print("²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²" + p[0] +
- "² MATOMAT Wilkommen! ²" + p[1] +
- "² Frohes genießen der Mate ²" + p[2] +
- "²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²" + p[3]);
+ Factory.getLCD().print("²²²²²²²²²²²²²²²²²²²²²²²²²²²²" + p[0] +
+ "² MATOMAT Wilkommen! ²" + p[1] +
+ "² Frohes genießen der Mate ²" + p[2] +
+ "²²²²²²²²²²²²²²²²²²²²²²²²²²²²" + p[3]);
}
}
}
diff --git a/Matomat/Prod.cs b/Matomat/Data/EAN13.cs
similarity index 74%
rename from Matomat/Prod.cs
rename to Matomat/Data/EAN13.cs
index 27f20fd..14fa7f5 100644
--- a/Matomat/Prod.cs
+++ b/Matomat/Data/EAN13.cs
@@ -2,10 +2,13 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
+using Matomat.Output;
+using Matomat.Database.Tables;
+using Matomat.Helper;
-namespace Matomat
+namespace Matomat.Data
{
- class Prod
+ class EAN13
{
private long prodId;
private bool found;
@@ -13,13 +16,14 @@ namespace Matomat
private int price;
private string name;
private string function;
+ private int id;
public enum ProdType
{
product,
instruction
}
- public Prod(long prodId)
+ public EAN13(long prodId)
{
this.prodId = prodId;
this.load();
@@ -46,18 +50,19 @@ namespace Matomat
this.name = t.name;
}
this.price = t.cost;
-
+ this.id = t.id;
}
internal bool vaild()
{
- LCDDisplay lcd = Factory.getLCDDisplay();
+ LCDDisplay lcd = Factory.getLCD();
if (!found)
{
- lcd.print("²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²"+
+ 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);
+ "²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²", LCDDisplay.Status.Error, 5);*/
System.Threading.Thread.Sleep(4500);
return false;
}
@@ -88,5 +93,10 @@ namespace Matomat
{
return this.function;
}
+
+ public int GetDbId()
+ {
+ return this.id;
+ }
}
}
diff --git a/Matomat/User.cs b/Matomat/Data/RfidCode.cs
similarity index 68%
rename from Matomat/User.cs
rename to Matomat/Data/RfidCode.cs
index b5ff018..3d3b8ac 100644
--- a/Matomat/User.cs
+++ b/Matomat/Data/RfidCode.cs
@@ -2,10 +2,14 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
+using Matomat.Output;
+using Matomat.Database;
+using Matomat.Database.Tables;
+using Matomat.Helper;
-namespace Matomat
+namespace Matomat.Data
{
- class User
+ class RfidCode
{
private long userId;
private bool found;
@@ -16,7 +20,7 @@ namespace Matomat
private bool admin;
private int id;
- public User(long userId)
+ public RfidCode(long userId)
{
this.userId = userId;
load();
@@ -39,15 +43,24 @@ namespace Matomat
this.id = u.id;
}
- internal bool vaild()
+ public bool vaild(bool silent)
{
- LCDDisplay lcd = Factory.getLCDDisplay();
+ if (silent)
+ {
+ return found;
+ }
+ else
+ {
+ return vaild();
+ }
+ }
+
+ public bool vaild()
+ {
+ LCDDisplay lcd = Factory.getLCD();
if (!found)
{
- lcd.print("²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²" +
- "² User wurde nicht gefunden ²" +
- "² UserID: " + (this.GetUserId().ToString() + " unbekannt").PadRight(28, ' ') + " ²" +
- "²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²", LCDDisplay.Status.Error, 5);
+ lcd.printb("User wurde nicht gefunden\nUserID:" + this.GetUserId().ToString() + " unbekannt", LCDDisplay.Status.Error, 5);
System.Threading.Thread.Sleep(4500);
return false;
}
@@ -70,6 +83,11 @@ namespace Matomat
return this.userId;
}
+ public int GetDbId()
+ {
+ return this.id;
+ }
+
internal long GetUserAll()
{
return this.all;
@@ -82,7 +100,7 @@ namespace Matomat
internal void SetUserKonto(int p)
{
- Database db = Factory.getDBO();
+ TDatabase db = Factory.getDBO();
this.credits = p;
db.query("UPDATE `user` SET `credits` = '" + db.quote(p.ToString())+"' WHERE "+
"`id` = '"+db.quote(this.id.ToString())+"'");
diff --git a/Matomat/Database.cs b/Matomat/Database.cs
deleted file mode 100644
index 009176b..0000000
--- a/Matomat/Database.cs
+++ /dev/null
@@ -1,52 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace Matomat
-{
- abstract class Database
- {
- private class instance
- {
- public string signature;
- public Database iDatabase;
-
- public instance(Database db, string p)
- {
- this.iDatabase = db;
- this.signature = p;
- }
- }
- private static List instances;
- internal static Database getInstance(string server, string dbs, string user, string pw, int port, string driver)
- {
- if (instances == null)
- instances = new List();
- foreach (instance i in instances)
- {
- if (i.signature == server + dbs + user + pw + port + driver)
- return i.iDatabase;
- }
- string object_driver = "Matomat.DBDriver" + char.ToUpper(driver[0]) + driver.Substring(1).ToLower();
- Type t = Type.GetType(object_driver, true);
- Database db = (Database)t.GetConstructor(Type.EmptyTypes).Invoke(new Object[0]);
- db.connect(server, dbs, user, pw, port, driver);
- if (db.getError() != null)
- {
- throw new Exception("db Fehler:" + db.getError());
- }
- instance instance = new instance(db, server + dbs + user + pw + port + driver);
- instances.Add(instance);
- return instance.iDatabase;
- }
- public abstract bool connect(string server, string dbs, string user, string pw, int port, string driver);
- public abstract void query(string sql);
- public abstract object[] getResult();
- public abstract List