Mal wieder weiter gemacht

This commit is contained in:
BlubbFish 2013-06-29 20:49:49 +00:00
parent cdec43f718
commit eb7db63bb3
21 changed files with 477 additions and 354 deletions

View File

@ -1,13 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="com_display" value="COM1" />
<add key="com_rfid" value="COM2" />
<add key="com_display" value="COM17" />
<add key="com_rfid" value="COM19" />
<add key="mysql_server" value="127.0.0.1"/>
<add key="mysql_user" value="root"/>
<add key="mysql_db" value="matomat"/>
<add key="mysql_port" value="3306"/>
<add key="mysql_pw" value=""/>
<add key="mysql_pw" value="mafia"/>
<add key="mysql_driver" value="mysqli"/>
<add key="debug" value="false"/>
</appSettings>
</configuration>

View File

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

View File

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

View File

@ -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())+"'");

View File

@ -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<instance> instances;
internal static Database getInstance(string server, string dbs, string user, string pw, int port, string driver)
{
if (instances == null)
instances = new List<instance>();
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<object[]> getResultList();
public abstract Exception getError();
public abstract long getID();
public abstract string quote(string str);
public abstract void RequestStop();
}
}

View File

@ -5,10 +5,11 @@ using System.Text;
using MySql.Data;
using MySql.Data.MySqlClient;
using System.Threading;
using Matomat.Helper;
namespace Matomat
namespace Matomat.Database
{
class DBDriverMysqli : Database
class DBDriverMysqli : TDatabase
{
MySqlConnection conn;
private Exception err;
@ -73,6 +74,10 @@ namespace Matomat
this.set(sql);
else
this.err = new Exception("Keine unterstütze MySQL Abfrage '" + sql + "'...");
if (Factory.getConfig().debug)
{
Console.WriteLine("SQL: " + sql + ((err != null) ? " Err" + err.Message : ""));
}
}
private void set(string sql)

View File

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Matomat.Database
{
abstract class TDatabase
{
private static Dictionary<string,TDatabase> instances = new Dictionary<string, TDatabase>();
internal static TDatabase getInstance(string server, string dbs, string user, string pw, int port, string driver)
{
string signature = server + dbs + user + pw + port + driver;
if (instances.Keys.Contains(signature))
{
return instances[signature];
}
string object_driver = "Matomat.Database.DBDriver" + char.ToUpper(driver[0]) + driver.Substring(1).ToLower();
Type t = null;
try
{
t = Type.GetType(object_driver, true);
}
catch (TypeLoadException)
{
throw new Exception("DB Treiber nicht gefunden: " + object_driver);
}
TDatabase db = (TDatabase)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());
}
instances.Add(signature,db);
return db;
}
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<object[]> getResultList();
public abstract Exception getError();
public abstract long getID();
public abstract string quote(string str);
public abstract void RequestStop();
}
}

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Data;
namespace Matomat
namespace Matomat.Database.Tables
{
class TBest : Tables
{

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Matomat
namespace Matomat.Database.Tables
{
class TProduct : Tables
{

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Data;
namespace Matomat
namespace Matomat.Database.Tables
{
class TUser : Tables
{

View File

@ -2,8 +2,10 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Matomat.Database;
using Matomat.Helper;
namespace Matomat
namespace Matomat.Database.Tables
{
class Tables
{
@ -13,7 +15,7 @@ namespace Matomat
}
public TUser getUserTable(long userid)
{
Database db = Factory.getDBO();
TDatabase db = Factory.getDBO();
db.query("SELECT `id`, `userid`, `username`, `credits`, `admin`, `shortname`, `email` FROM `user` WHERE `userid` =" + db.quote(userid.ToString()));
object[] row = db.getResult();
if (row == null)
@ -28,7 +30,7 @@ namespace Matomat
}
public TProduct getProdTable(long barcode)
{
Database db = Factory.getDBO();
TDatabase db = Factory.getDBO();
db.query("SELECT * FROM `product` WHERE `barcode` = " + db.quote(barcode.ToString()));
object[] row = db.getResult();
if (row == null)
@ -40,7 +42,7 @@ namespace Matomat
internal List<TBest> getBestlist()
{
Database db = Factory.getDBO();
TDatabase db = Factory.getDBO();
db.query("SELECT COUNT(*) AS `num`,`u`.`shortname` AS `name` "+
"FROM `history` AS `h` "+
"LEFT JOIN `product` AS `p` ON `p`.`id` = `h`.`prod` "+
@ -61,17 +63,23 @@ namespace Matomat
internal TBest getUserMax(int p)
{
Database db = Factory.getDBO();
db.query("SELECT SUM(`p`.`cost`) AS `num`,`u`.`shortname` AS `name` "+
TDatabase db = Factory.getDBO();
string sql = "SELECT SUM(`p`.`cost`) AS `num`,`u`.`shortname` AS `name` "+
"FROM `history` AS `h` "+
"LEFT JOIN `product` AS `p` ON `p`.`id` = `h`.`prod` "+
"LEFT JOIN `user` AS `u` ON `u`.`id` = `h`.`user` "+
"WHERE `p`.`iscommand` = 0 AND `h`.`user` = " + db.quote(p.ToString()));
"RIGHT JOIN `user` AS `u` ON `u`.`id` = `h`.`user` "+
"WHERE `p`.`iscommand` = 0 AND `h`.`user` = " + db.quote(p.ToString());
db.query(sql);
object[] row = db.getResult();
if (row == null)
{
return null;
}
if (row[0] == System.DBNull.Value)
{
return new TBest(Decimal.ToInt64(0), (string)row[1]);
}
return new TBest(Decimal.ToInt64((decimal)row[0]), (string)row[1]);
}
}

View File

@ -2,72 +2,26 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Matomat.Output;
using Matomat.Input;
using Matomat.Database;
namespace Matomat
namespace Matomat.Helper
{
class Factory
{
private static LCDDisplay lcd_i = null;
private static Input inp_i = null;
private static TInput inp_i = null;
private static Config con_i = null;
private static Database dbo_i;
internal static LCDDisplay getLCDDisplay()
private static TDatabase dbo_i;
public static LCDDisplay getLCD()
{
if (lcd_i == null)
lcd_i = Factory._createLCDDisplay();
return lcd_i;
}
private static LCDDisplay _createLCDDisplay()
{
return LCDDisplay.getInstance(Factory.getConfig().com_display);
}
internal static Input getInput()
{
if (inp_i == null)
inp_i = Factory._createInput();
return inp_i;
}
private static Input _createInput()
{
return Input.getInstance();
}
internal static Config getConfig()
{
if (con_i == null)
con_i = Factory._createConfig("App.config");
return con_i;
}
private static Config _createConfig(string file)
{
return Config.getInstance(file);
}
internal static Database getDBO()
{
if (dbo_i == null)
dbo_i = Factory._createDBO();
return dbo_i;
}
private static Database _createDBO()
{
Config c = Factory.getConfig();
return Database.getInstance(c.mysql_server, c.mysql_db, c.mysql_user, c.mysql_pw, c.mysql_port, c.mysql_driver);
}
internal static void rmDBO()
{
if (dbo_i != null)
{
dbo_i.RequestStop();
dbo_i = null;
}
}
internal static void rmLCDDisplay()
public static void rmLCD()
{
if (lcd_i != null)
{
@ -75,5 +29,67 @@ namespace Matomat
lcd_i = null;
}
}
private static LCDDisplay _createLCDDisplay()
{
return LCDDisplay.getInstance(Factory.getConfig().com_display);
}
public static TInput getInput()
{
if (inp_i == null)
inp_i = Factory._createInput();
return inp_i;
}
private static TInput _createInput()
{
return TInput.getInstance(Factory.getConfig().com_rfid);
}
public static void rmInput()
{
if (inp_i != null)
{
inp_i.RequestStop();
inp_i = null;
}
}
public static Config getConfig()
{
if (con_i == null)
con_i = Factory._createConfig("App.config");
return con_i;
}
private static Config _createConfig(string file)
{
return Config.getInstance(file);
}
public static void rmConfig()
{
if (con_i != null)
{
con_i.RequestStop();
con_i = null;
}
}
public static TDatabase getDBO()
{
if (dbo_i == null)
dbo_i = Factory._createDBO();
return dbo_i;
}
private static TDatabase _createDBO()
{
Config c = Factory.getConfig();
return TDatabase.getInstance(c.mysql_server, c.mysql_db, c.mysql_user, c.mysql_pw, c.mysql_port, c.mysql_driver);
}
public static void rmDBO()
{
if (dbo_i != null)
{
dbo_i.RequestStop();
dbo_i = null;
}
}
}
}

View File

@ -7,12 +7,8 @@ using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
namespace Matomat
namespace Matomat.Helper
{
class Helper
{
}
public static class String
{
public static byte[] ToCharArray(this string str, string search, byte[] replace)

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.IO;
namespace Matomat
namespace Matomat.Input
{
class BarcodeReader
{

View File

@ -5,26 +5,14 @@ using System.Text;
using System.IO;
using System.Configuration;
namespace Matomat
namespace Matomat.Input
{
class Config
{
private class instance
{
public Config config;
public string signature;
public instance(Config config, string signature)
{
this.config = config;
this.signature = signature;
}
}
static List<instance> instances;
private static Dictionary<string,Config> instances = new Dictionary<string,Config>();
private AppSettingsReader config;
public Config()
private Config()
{
this.config = new AppSettingsReader();
loadFile();
@ -41,37 +29,34 @@ namespace Matomat
this.mysql_port = (int)config.GetValue("mysql_port", typeof(int));
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));
}
catch (Exception) { }
}
internal static Config getInstance(string file)
{
if (instances == null)
instances = new List<instance>();
foreach (instance i in instances)
if (instances.Keys.Contains(file))
{
if (i.signature == file)
return i.config;
return instances[file];
}
instance instance = new instance(new Config(), file);
instances.Add(instance);
return instance.config;
instances.Add(file,new Config());
return instances[file];
}
public string com_display { get; set; }
public string com_rfid { get; set; }
public string com_display { get; private set; }
public string com_rfid { get; private set; }
public string mysql_server { get; private set; }
public string mysql_user { get; private set; }
public string mysql_db { get; private set; }
public int mysql_port { get; private set; }
public string mysql_pw { get; private set; }
public string mysql_driver { get; private set; }
public bool debug { get; private set; }
public string mysql_server { get; set; }
public string mysql_user { get; set; }
public string mysql_db { get; set; }
public int mysql_port { get; set; }
public string mysql_pw { get; set; }
public string mysql_driver { get; set; }
public void RequestStop()
{
}
}
}

View File

@ -4,14 +4,14 @@ using System.Linq;
using System.Text;
using RfidClass;
namespace Matomat
namespace Matomat.Input
{
class RFIDReader
{
private RFIDReaderClass r;
public RFIDReader()
public RFIDReader(string comport)
{
r = new RFIDReaderClass(Factory.getConfig().com_rfid);
r = new RFIDReaderClass(comport);
}
internal long getCardID()
{

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading;
namespace Matomat
namespace Matomat.Input
{
class InputData
{
@ -22,33 +22,22 @@ namespace Matomat
public types type { get; set; }
public long id { get; set; }
}
class Input
class TInput
{
private class instance
{
public Input input;
public double signature;
public instance(Input input, double signature)
{
this.input = input;
this.signature = signature;
}
}
static List<instance> instances;
private static Dictionary<string,TInput> instances = new Dictionary<string,TInput>();
private InputData data;
private RFIDReader rfid;
private BarcodeReader code;
public Input()
private bool cardrunning = true;
private bool coderunning = true;
private TInput(string comport)
{
rfid = new RFIDReader();
rfid = new RFIDReader(comport);
code = new BarcodeReader();
}
private void doWorkCard()
{
while (true)
while (this.cardrunning)
{
Thread.Sleep(1);
long id = rfid.getCardID();
@ -62,7 +51,7 @@ namespace Matomat
}
private void doWorkCode()
{
while (true)
while (this.coderunning)
{
Thread.Sleep(1);
long id = code.getCodeID();
@ -73,11 +62,13 @@ namespace Matomat
}
}
}
internal InputData getAnyInput(int timeout)
public InputData getAnyInput(int timeout)
{
if (timeout == 0)
timeout = Int32.MaxValue;
data = new InputData();
this.cardrunning = true;
this.coderunning = true;
Thread wtCard = new Thread(this.doWorkCard);
Thread wtCode = new Thread(this.doWorkCode);
wtCard.Start();
@ -96,11 +87,12 @@ namespace Matomat
return data;
}
internal InputData getProdInput(int timeout)
public InputData getProdInput(int timeout)
{
if (timeout == 0)
timeout = Int32.MaxValue;
data = new InputData();
this.coderunning = true;
Thread wtCode = new Thread(this.doWorkCode);
wtCode.Start();
while (!wtCode.IsAlive) ;
@ -114,26 +106,22 @@ namespace Matomat
return data;
}
internal static Input getInstance()
public static TInput getInstance(string comport)
{
if (instances == null)
instances = new List<instance>();
double signature = 1.0;
foreach (instance i in instances)
if (instances.Keys.Contains(comport))
{
if (i.signature == signature)
return i.input;
return instances[comport];
}
instance instance = new instance(new Input(), signature);
instances.Add(instance);
return instance.input;
instances.Add(comport,new TInput(comport));
return instances[comport];
}
internal InputData getCardInput(int timeout)
public InputData getCardInput(int timeout)
{
if (timeout == 0)
timeout = Int32.MaxValue;
data = new InputData();
this.cardrunning = true;
Thread wtCard = new Thread(this.doWorkCard);
wtCard.Start();
while (!wtCard.IsAlive) ;
@ -146,5 +134,11 @@ namespace Matomat
rfid.Abort();
return data;
}
public void RequestStop()
{
this.cardrunning = false;
this.coderunning = false;
}
}
}

View File

@ -34,8 +34,14 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="MySql.Data, Version=6.2.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL" />
<Reference Include="MySql.Data.Entity, Version=6.2.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL" />
<Reference Include="mysql.data, Version=6.3.7.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>dll\mysql.data.dll</HintPath>
</Reference>
<Reference Include="mysql.data.entity, Version=6.3.7.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>dll\mysql.data.entity.dll</HintPath>
</Reference>
<Reference Include="RfidClass, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>.\RfidClass.dll</HintPath>
@ -50,22 +56,22 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Automat.cs" />
<Compile Include="BarcodeReader.cs" />
<Compile Include="Config.cs" />
<Compile Include="Database.cs" />
<Compile Include="DBDriverMysqli.cs" />
<Compile Include="Factory.cs" />
<Compile Include="Helper.cs" />
<Compile Include="Input.cs" />
<Compile Include="LCDDisplay.cs" />
<Compile Include="Prod.cs" />
<Compile Include="Input\BarcodeReader.cs" />
<Compile Include="Input\Config.cs" />
<Compile Include="Database\TDatabase.cs" />
<Compile Include="Database\DBDriverMysqli.cs" />
<Compile Include="Helper\Factory.cs" />
<Compile Include="Helper\Types.cs" />
<Compile Include="Input\TInput.cs" />
<Compile Include="Output\LCDDisplay.cs" />
<Compile Include="Data\EAN13.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RFIDReader.cs" />
<Compile Include="Tables\Tables.Best.cs" />
<Compile Include="Tables\Tables.cs" />
<Compile Include="Tables\Tables.User.cs" />
<Compile Include="User.cs" />
<Compile Include="Input\RFIDReader.cs" />
<Compile Include="Database\Tables\Tables.Best.cs" />
<Compile Include="Database\Tables\Tables.cs" />
<Compile Include="Database\Tables\Tables.User.cs" />
<Compile Include="Data\RfidCode.cs" />
<Compile Include="Worker.cs" />
</ItemGroup>
<ItemGroup>
@ -82,7 +88,7 @@
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<Compile Include="Tables\Tables.Product.cs" />
<Compile Include="Database\Tables\Tables.Product.cs" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

View File

@ -4,23 +4,13 @@ using System.Linq;
using System.Text;
using System.Threading;
using System.IO.Ports;
using Matomat.Helper;
namespace Matomat
namespace Matomat.Output
{
class LCDDisplay
{
private class instance
{
public LCDDisplay lCDDisplay;
public string signature;
public instance(LCDDisplay lCDDisplay, string signature)
{
this.lCDDisplay = lCDDisplay;
this.signature = signature;
}
}
private class Message
{
public string text;
@ -45,14 +35,14 @@ namespace Matomat
this.duration = duration;
}
}
static List<instance> instances;
private static Dictionary<string,LCDDisplay> instances = new Dictionary<string,LCDDisplay>();
private Queue<Message> messages;
private Queue<Beeb> beeb;
private volatile bool _shouldStop;
private SerialPort serialPort;
private bool disable = false;
public LCDDisplay(string port)
private LCDDisplay(string port)
{
this.serialPort = new SerialPort(port, 19200, Parity.None, 8, StopBits.One);
try
@ -120,7 +110,6 @@ namespace Matomat
this.beep(37, 100);
this.beep(750, 500);
}
Console.WriteLine(text);
this.displayClear();
byte[] btext = text.ToCharArray("ÄÖÜäöüß²€", new byte[] { 0xE1, 0xEF, 0xF5, 0xE1, 0xEF, 0xF5, 0xE2, 0xFF, 0x80});
byte[] upper;
@ -139,6 +128,10 @@ namespace Matomat
this.displayCode(upper);
this.displayEscCode("GTO2@");
this.displayCode(lower);
text = text.PadRight(160, ' ');
text = text.Substring(0, 40) + "\n" + text.Substring(40, 40) + "\n" + text.Substring(80, 40) + "\n" + text.Substring(120, 40);
Console.WriteLine(text);
}
private void displayClear()
@ -182,44 +175,105 @@ namespace Matomat
Warn,
Error
}
internal void print(string text)
#region printb Display method for two lines (Border)
/// <summary>
/// Displays a two line string on the display
/// </summary>
/// <param name="text">Text to display. Break with \n, max length 38 chars each line</param>
public void printb(string text)
{
this.printb(text, Status.OK, 0);
}
/// <summary>
/// Displays a two line string on the display with the minimum duration of the time
/// </summary>
/// <param name="text">Text to display. Break with \n, max length 38 chars each line</param>
/// <param name="time">Minimum duration of displaying the text</param>
public void printb(string text, int time)
{
this.printb(text, Status.OK, time);
}
/// <summary>
/// Displays a two line string on the display with beebcodes when Status is not OK
/// </summary>
/// <param name="text">Text to display. Break with \n, max length 38 chars each line</param>
/// <param name="status">Status code for that Item</param>
public void printb(string text, Status status)
{
this.printb(text, status, 0);
}
/// <summary>
/// Displays a two line string on the display with the minimum duration of the time and beebcodes when Status is not OK
/// </summary>
/// <param name="text">Text to display. Break with \n, max length 38 chars each line</param>
/// <param name="status">Status code for that Item</param>
/// <param name="time">Minimum duration of displaying the text</param>
public void printb(string text, Status status, int time)
{
string[] lines = text.Split('\n');
string line1 = "";
string line2 = "";
if (lines.Length == 1)
{
line1 = lines[0];
}
else
{
line1 = lines[0];
line2 = lines[1];
}
if(line1.Length > 38)
line1 = line1.Substring(0, 38);
double ll1 = ((38D - line1.Length) / 2);
line1 = line1.PadLeft((int)Math.Floor(ll1) + line1.Length, ' ');
line1 = line1.PadRight((int)Math.Ceiling(ll1) + line1.Length, ' ');
if (line2.Length > 38)
line2 = line2.Substring(0, 38);
double ll2 = ((38D - line2.Length) / 2);
line2 = line2.PadLeft((int)Math.Floor(ll2) + line2.Length, ' ');
line2 = line2.PadRight((int)Math.Ceiling(ll2) + line2.Length, ' ');
this.print("²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²" +
"²" + line1 + "²" +
"²" + line2 + "²" +
"²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²", status, time);
}
#endregion
#region print Display method for the whole display
public void print(string text)
{
this.anzeige(text, Status.OK, 0);
}
public void print(string text, int time)
{
this.anzeige(text, Status.OK, time);
}
public void print(string text, Status status)
{
this.anzeige(text, status, 0);
}
public void print(string text, Status status, int time)
{
this.anzeige(text, status, time);
}
#endregion
private void anzeige(string text, Status status, int time)
{
Message m = new Message(text, status, time);
messages.Enqueue(m);
}
internal void print(string text, int time)
public static LCDDisplay getInstance(string port)
{
this.anzeige(text, Status.OK, time);
}
internal void print(string text, Status status)
{
this.anzeige(text, status, 0);
}
internal void print(string text, Status status, int time)
{
this.anzeige(text, status, time);
}
internal static LCDDisplay getInstance(string port)
{
if (instances == null)
instances = new List<instance>();
foreach (instance i in instances)
if (instances.Keys.Contains(port))
{
if (i.signature == port)
return i.lCDDisplay;
return instances[port];
}
instance instance = new instance(new LCDDisplay(port), port);
instances.Add(instance);
return instance.lCDDisplay;
instances.Add(port,new LCDDisplay(port));
return instances[port];
}
public void RequestStop()
{

View File

@ -8,7 +8,7 @@ namespace Matomat
{
class Program
{
static void Main(string[] args)
public static void Main(string[] args)
{
Worker workerObject = new Worker();
Thread workerThread = new Thread(workerObject.DoWork);

View File

@ -2,24 +2,23 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Matomat.Input;
using Matomat.Output;
using Matomat.Helper;
namespace Matomat
{
class Worker
{
private volatile bool _shouldStop;
private RFIDReader rfid;
private BarcodeReader barcode;
private Automat automat;
private LCDDisplay lcd;
private Input inp;
private TInput inp;
public Worker()
{
rfid = new RFIDReader();
barcode = new BarcodeReader();
automat = new Automat();
automat.stopThread += new Automat.stopEvent(RequestStop);
lcd = Factory.getLCDDisplay();
lcd = Factory.getLCD();
inp = Factory.getInput();
_shouldStop = false;
}
@ -31,12 +30,11 @@ namespace Matomat
InputData input = inp.getAnyInput(0);
automat.doJob(input);
}
this.lcd.print("²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²" +
"² Der Matomat wurde beendet. ²" +
"² Einen schönen Tag! ²" +
"²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²");
Factory.rmLCDDisplay();
Factory.getLCD().printb("Der Matomat wurde beendet.\nEinen schönen Tag!");
Factory.rmLCD();
Factory.rmInput();
Factory.rmDBO();
Factory.rmConfig();
}
private void RequestStop(bool stop)
{