diff --git a/Matomat/Automat.cs b/Matomat/Automat.cs
deleted file mode 100644
index 122db93..0000000
--- a/Matomat/Automat.cs
+++ /dev/null
@@ -1,114 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using Matomat.Input;
-using Matomat.Output;
-using Matomat.Database.Tables;
-using Matomat.Helper;
-using Matomat.Model;
-
-namespace Matomat
-{
- class Automat
- {
- //private bool shutdown = false;
-
- public delegate void stopEvent(bool stop);
-
- public event stopEvent stopThread;
-
- public Automat() {
-
- }
- internal void doJob(InputData input)
- {
- if (input.type == InputData.types.Card)
- {
- User user;
- try
- {
- user = new User(input.id);
- }
- catch (ArgumentException e)
- {
- Factory.getLCD().print(e.Message, 5, LCDDisplay.Status.OK);
- System.Threading.Thread.Sleep(4500);
- return;
- }
-
- Instruction.showUserInfo(user);
-
- Factory.getLCD().print("Bitte Produkt über den\nBarcodeleser halten");
-
- InputData prodid = Factory.getInput().getProdInput(20);
- if (prodid.type == InputData.types.None)
- return;
-
- Product prod;
- try
- {
- prod = new Product(prodid.id);
- }
- catch (ArgumentException e)
- {
- Factory.getLCD().print(e.Message, 5, LCDDisplay.Status.OK);
- System.Threading.Thread.Sleep(4500);
- return;
- }
-
- Instruction.ShowProdInfo(prod);
-
- if (prod.GetProdType() == Product.ProdType.Product)
- {
- Instruction.sell(prod, user);
- }
- if (prod.GetProdType() == Product.ProdType.Instruction)
- {
- switch (prod.GetName())
- {
- case "exit();": this.stopThread(true); 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;
- }
- }
- }
- else if (input.type == InputData.types.Prod)
- {
- Product prod;
- try
- {
- prod = new Product(input.id);
- }
- catch (ArgumentException e)
- {
- Factory.getLCD().print(e.Message, 5, LCDDisplay.Status.OK);
- System.Threading.Thread.Sleep(4500);
- return;
- }
-
- if (prod.GetProdType() == Product.ProdType.Instruction)
- {
- switch (prod.GetName())
- {
- case "exit();": this.stopThread(true); break;
- case "showStats();": Instruction.InsShowStats(); break;
- default: Instruction.ShowProdInfo(prod); break;
- }
- }
- else
- {
- Instruction.ShowProdInfo(prod);
- }
- }
- }
- }
-}
diff --git a/Matomat/Input/Config.cs b/Matomat/Configuration/Config.cs
similarity index 95%
rename from Matomat/Input/Config.cs
rename to Matomat/Configuration/Config.cs
index 0cac250..819e9a0 100644
--- a/Matomat/Input/Config.cs
+++ b/Matomat/Configuration/Config.cs
@@ -5,7 +5,7 @@ using System.Text;
using System.IO;
using System.Configuration;
-namespace Matomat.Input
+namespace Matomat.Configuration
{
class Config
{
diff --git a/Matomat/Instruction.cs b/Matomat/Controller/Instruction.cs
similarity index 83%
rename from Matomat/Instruction.cs
rename to Matomat/Controller/Instruction.cs
index 77de4a4..a2aaccf 100644
--- a/Matomat/Instruction.cs
+++ b/Matomat/Controller/Instruction.cs
@@ -11,11 +11,6 @@ namespace Matomat
{
class Instruction
{
- public enum Stats
- {
- LastMonth,
- All
- }
public static void InsAufladen(int betrag, User admin)
{
if (!admin.GetAdmin())
@@ -123,7 +118,7 @@ namespace Matomat
System.Threading.Thread.Sleep(4500);
return;
}
- Factory.getLCD().print("Bitte die alte Userkarte auf\nden RFID Leser auflegen.");
+ Factory.getLCD().print("Bitte die zu löschende Userkarte\nauf den RFID Leser auflegen.");
InputData target = Factory.getInput().getCardInput(20);
if (target.type == InputData.types.None)
return;
@@ -135,7 +130,7 @@ namespace Matomat
}
catch (ArgumentException e)
{
- Factory.getLCD().print(e.Message, 5, LCDDisplay.Status.OK);
+ Factory.getLCD().print(e.Message, 5, LCDDisplay.Status.Error);
System.Threading.Thread.Sleep(4500);
return;
}
@@ -162,12 +157,7 @@ namespace Matomat
System.Threading.Thread.Sleep(3500);
}
- internal static void InsShowStats()
- {
- throw new NotImplementedException();
- }
-
- internal static void InsAddProd(User admin)
+ public static void InsAddProd(User admin)
{
if (!admin.GetAdmin())
{
@@ -233,16 +223,6 @@ namespace Matomat
return;
}
- internal static void InsDelProd(User user)
- {
- throw new NotImplementedException();
- }
-
- internal static void InsShowStats(User user, Stats stats)
- {
- throw new NotImplementedException();
- }
-
public static void ShowProdInfo(Product prod)
{
if (prod.GetProdType() == Product.ProdType.Product)
@@ -269,11 +249,61 @@ namespace Matomat
"²²²²²²²²²²²²²²²²²²²²²²²²²²²²" + p[0] +
"² MATOMAT Wilkommen! ²" + p[1] +
"² Frohes genießen der Mate ²" + p[2]);
+ Factory.getLCD().print("µµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµ");
}
public static void showUserInfo(User user)
{
Factory.getLCD().print("User: " + user.GetShortname() + " Betrag: " + user.GetCredits().ToString("N2") + " €\nUserID: " + user.GetUserId() + " Gesamt: " + user.GetUserAll().ToString("N2") + " €", 5);
}
+
+ public static void InsDelProd(User admin)
+ {
+ if (!admin.GetAdmin())
+ {
+ Factory.getLCD().print("Du bist kein Admin,\ndu kannst niemanden Löschen!", 5, LCDDisplay.Status.Error);
+ System.Threading.Thread.Sleep(4500);
+ return;
+ }
+
+ Factory.getLCD().print("Bitte das zu Löschende Produkt\nüber den Barcode-Leser ziehen.");
+ InputData target = Factory.getInput().getProdInput(20);
+ if (target.type == InputData.types.None)
+ return;
+
+ Product prod;
+ try
+ {
+ prod = new Product(target.id);
+ }
+ catch (ArgumentException e)
+ {
+ Factory.getLCD().print(e.Message, 5, LCDDisplay.Status.Error);
+ System.Threading.Thread.Sleep(4500);
+ return;
+ }
+
+ if (prod.GetProdType() == Product.ProdType.Instruction)
+ {
+ Factory.getLCD().print("Sie können keine Instruktion\nlöschen!", 5, LCDDisplay.Status.Error);
+ System.Threading.Thread.Sleep(4500);
+ return;
+ }
+
+ Product.Remove(prod.GetId());
+
+ Factory.getLCD().print("Produkt erfolgreich gelöscht:\n" + prod.GetName(), 3);
+ System.Threading.Thread.Sleep(2500);
+ }
+
+ public static void InsShowStats()
+ {
+ throw new NotImplementedException();
+ }
+
+ public static void InsShowStats(User user, bool lastMonth = true)
+ {
+ throw new NotImplementedException();
+ }
}
}
diff --git a/Matomat/Helper/Factory.cs b/Matomat/Helper/Factory.cs
index b259633..d5e6a4b 100644
--- a/Matomat/Helper/Factory.cs
+++ b/Matomat/Helper/Factory.cs
@@ -5,6 +5,7 @@ using System.Text;
using Matomat.Output;
using Matomat.Input;
using Matomat.Database;
+using Matomat.Configuration;
namespace Matomat.Helper
{
diff --git a/Matomat/Matomat.csproj b/Matomat/Matomat.csproj
index b6871f6..a075316 100644
--- a/Matomat/Matomat.csproj
+++ b/Matomat/Matomat.csproj
@@ -55,7 +55,6 @@
-
@@ -64,13 +63,13 @@
-
+
-
+
@@ -78,7 +77,6 @@
-
diff --git a/Matomat/Model/Product.cs b/Matomat/Model/Product.cs
index 3c6d2e3..2381f54 100644
--- a/Matomat/Model/Product.cs
+++ b/Matomat/Model/Product.cs
@@ -71,5 +71,14 @@ namespace Matomat.Model
p.bind(k);
p.store();
}
+
+ public static void Remove(int id)
+ {
+ TableProduct u = new TableProduct();
+ Dictionary load = new Dictionary();
+ load.Add("id", id.ToString());
+ u.load(load);
+ u.delete();
+ }
}
}
diff --git a/Matomat/Output/LCDDisplay.cs b/Matomat/Output/LCDDisplay.cs
index 6b426c7..2d35640 100644
--- a/Matomat/Output/LCDDisplay.cs
+++ b/Matomat/Output/LCDDisplay.cs
@@ -111,7 +111,7 @@ namespace Matomat.Output
this.beep(750, 500);
}
this.displayClear();
- byte[] btext = text.ToCharArray("ÄÖÜäöüß²€", new byte[] { 0xE1, 0xEF, 0xF5, 0xE1, 0xEF, 0xF5, 0xE2, 0xFF, 0x80});
+ byte[] btext = text.ToCharArray("ÄÖÜäöüß²€µ", new byte[] { 0xE1, 0xEF, 0xF5, 0xE1, 0xEF, 0xF5, 0xE2, 0xFF, 0x80, 0x81 });
byte[] upper;
byte[] lower;
if (text.Length > 80)
@@ -154,10 +154,17 @@ namespace Matomat.Output
private void createChars()
{
this.displayEscCode("GTO0@");
- this.displayEscCode("UDC0GH_H_HG@");
-
+ this.specialChars();
this.displayEscCode("GTO2@");
- this.displayEscCode("UDC0GH_H_HG@");
+ this.specialChars();
+ }
+
+ private void specialChars()
+ {
+ this.displayEscCode("UDC0GH_H_HG@"); //[0, 0x80] Eurosymbol
+ this.displayEscCode("UDC1GGGGGGGG"); //[1, 0x81] Eurosymbol
+ this.displayEscCode("UDC2GH_H_HG@"); //[2] Eurosymbol
+ this.displayEscCode("UDC3GH_H_HG@"); //[3] Eurosymbol
}
private void displayEscCode(string code)
diff --git a/Matomat/Program.cs b/Matomat/Program.cs
index 5214d86..1fe6fe1 100644
--- a/Matomat/Program.cs
+++ b/Matomat/Program.cs
@@ -4,24 +4,149 @@ using System.Linq;
using System.Text;
using System.Threading;
+using Matomat.Helper;
+using Matomat.Input;
+using Matomat.Model;
+using Matomat.Output;
+
namespace Matomat
{
class Program
{
+ private static volatile bool _shouldStop;
+
public static void Main(string[] args)
{
- Worker workerObject = new Worker();
- Thread workerThread = new Thread(workerObject.DoWork);
-
- workerThread.Start();
-
- while (!workerThread.IsAlive) ;
-
- while (workerThread.IsAlive)
+ InitMainThread();
+ Thread t = new Thread(MainThread);
+ t.Start();
+ while (!t.IsAlive) ;
+ while (t.IsAlive)
{
- Thread.Sleep(100);
+ Thread.Sleep(10);
+ }
+ }
+
+ #region MainThread
+ private static void InitMainThread()
+ {
+ Factory.getLCD();
+ Factory.getInput();
+ _shouldStop = false;
+ }
+
+ private static void MainThread()
+ {
+ while (!_shouldStop)
+ {
+ Instruction.GetInitStatus();
+ InputData input = Factory.getInput().getAnyInput(60);
+ if (input.type != InputData.types.None)
+ {
+ doJob(input);
+ }
+ }
+ Factory.getLCD().print("Der Matomat wurde beendet.\nEinen schönen Tag!");
+ Factory.rmLCD();
+ Factory.rmInput();
+ Factory.rmDBO();
+ Factory.rmConfig();
+ }
+
+ private static void RequestStop(bool stop)
+ {
+ _shouldStop = stop;
+ }
+ #endregion
+
+ private static void doJob(InputData input)
+ {
+ if (input.type == InputData.types.Card)
+ {
+ User user;
+ try
+ {
+ user = new User(input.id);
+ }
+ catch (ArgumentException e)
+ {
+ Factory.getLCD().print(e.Message, 5, LCDDisplay.Status.OK);
+ System.Threading.Thread.Sleep(4500);
+ return;
+ }
+
+ Instruction.showUserInfo(user);
+
+ Factory.getLCD().print("Bitte Produkt über den\nBarcodeleser halten");
+
+ InputData prodid = Factory.getInput().getProdInput(20);
+ if (prodid.type == InputData.types.None)
+ return;
+
+ Product prod;
+ try
+ {
+ prod = new Product(prodid.id);
+ }
+ catch (ArgumentException e)
+ {
+ Factory.getLCD().print(e.Message, 5, LCDDisplay.Status.OK);
+ System.Threading.Thread.Sleep(4500);
+ return;
+ }
+
+ Instruction.ShowProdInfo(prod);
+
+ if (prod.GetProdType() == Product.ProdType.Product)
+ {
+ Instruction.sell(prod, user);
+ }
+ if (prod.GetProdType() == Product.ProdType.Instruction)
+ {
+ switch (prod.GetName())
+ {
+ case "exit();": RequestStop(true); 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, true); break;
+ case "showStats(All);": Instruction.InsShowStats(user, false); break;
+ }
+ }
+ }
+ else if (input.type == InputData.types.Prod)
+ {
+ Product prod;
+ try
+ {
+ prod = new Product(input.id);
+ }
+ catch (ArgumentException e)
+ {
+ Factory.getLCD().print(e.Message, 5, LCDDisplay.Status.OK);
+ System.Threading.Thread.Sleep(4500);
+ return;
+ }
+
+ if (prod.GetProdType() == Product.ProdType.Instruction)
+ {
+ switch (prod.GetName())
+ {
+ case "exit();": RequestStop(true); break;
+ case "showStats();": Instruction.InsShowStats(); break;
+ default: Instruction.ShowProdInfo(prod); break;
+ }
+ }
+ else
+ {
+ Instruction.ShowProdInfo(prod);
+ }
}
- //Console.ReadLine();
}
}
}
diff --git a/Matomat/Worker.cs b/Matomat/Worker.cs
deleted file mode 100644
index 384af84..0000000
--- a/Matomat/Worker.cs
+++ /dev/null
@@ -1,46 +0,0 @@
-using System;
-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 Automat automat;
- public Worker()
- {
- automat = new Automat();
- automat.stopThread += new Automat.stopEvent(RequestStop);
- Factory.getLCD();
- Factory.getInput();
- _shouldStop = false;
- }
- public void DoWork()
- {
- while (!_shouldStop)
- {
- Instruction.GetInitStatus();
- InputData input = Factory.getInput().getAnyInput(60);
- if (input.type != InputData.types.None)
- {
- automat.doJob(input);
- }
- }
- Factory.getLCD().print("Der Matomat wurde beendet.\nEinen schönen Tag!");
- Factory.rmLCD();
- Factory.rmInput();
- Factory.rmDBO();
- Factory.rmConfig();
- }
- private void RequestStop(bool stop)
- {
- _shouldStop = stop;
- }
-
- }
-}