Refactoring! New display features

This commit is contained in:
BlubbFish 2013-07-13 21:34:46 +00:00
parent 67c5f65d52
commit a9e76fb3d6
9 changed files with 212 additions and 202 deletions

View File

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

View File

@ -5,7 +5,7 @@ using System.Text;
using System.IO; using System.IO;
using System.Configuration; using System.Configuration;
namespace Matomat.Input namespace Matomat.Configuration
{ {
class Config class Config
{ {

View File

@ -11,11 +11,6 @@ namespace Matomat
{ {
class Instruction class Instruction
{ {
public enum Stats
{
LastMonth,
All
}
public static void InsAufladen(int betrag, User admin) public static void InsAufladen(int betrag, User admin)
{ {
if (!admin.GetAdmin()) if (!admin.GetAdmin())
@ -123,7 +118,7 @@ namespace Matomat
System.Threading.Thread.Sleep(4500); System.Threading.Thread.Sleep(4500);
return; 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); InputData target = Factory.getInput().getCardInput(20);
if (target.type == InputData.types.None) if (target.type == InputData.types.None)
return; return;
@ -135,7 +130,7 @@ namespace Matomat
} }
catch (ArgumentException e) 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); System.Threading.Thread.Sleep(4500);
return; return;
} }
@ -162,12 +157,7 @@ namespace Matomat
System.Threading.Thread.Sleep(3500); System.Threading.Thread.Sleep(3500);
} }
internal static void InsShowStats() public static void InsAddProd(User admin)
{
throw new NotImplementedException();
}
internal static void InsAddProd(User admin)
{ {
if (!admin.GetAdmin()) if (!admin.GetAdmin())
{ {
@ -233,16 +223,6 @@ namespace Matomat
return; 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) public static void ShowProdInfo(Product prod)
{ {
if (prod.GetProdType() == Product.ProdType.Product) if (prod.GetProdType() == Product.ProdType.Product)
@ -269,11 +249,61 @@ namespace Matomat
"²²²²²²²²²²²²²²²²²²²²²²²²²²²²" + p[0] + "²²²²²²²²²²²²²²²²²²²²²²²²²²²²" + p[0] +
"² MATOMAT Wilkommen! ²" + p[1] + "² MATOMAT Wilkommen! ²" + p[1] +
"² Frohes genießen der Mate ²" + p[2]); "² Frohes genießen der Mate ²" + p[2]);
Factory.getLCD().print("µµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµ");
} }
public static void showUserInfo(User user) 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); 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();
}
} }
} }

View File

@ -5,6 +5,7 @@ using System.Text;
using Matomat.Output; using Matomat.Output;
using Matomat.Input; using Matomat.Input;
using Matomat.Database; using Matomat.Database;
using Matomat.Configuration;
namespace Matomat.Helper namespace Matomat.Helper
{ {

View File

@ -55,7 +55,6 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Automat.cs" />
<Compile Include="Database\Query\DatabaseQueryElement.cs" /> <Compile Include="Database\Query\DatabaseQueryElement.cs" />
<Compile Include="Database\Query\DBQuery.cs" /> <Compile Include="Database\Query\DBQuery.cs" />
<Compile Include="Database\Query\DBQueryMysqli.cs" /> <Compile Include="Database\Query\DBQueryMysqli.cs" />
@ -64,13 +63,13 @@
<Compile Include="Database\Tables\TableProduct.cs" /> <Compile Include="Database\Tables\TableProduct.cs" />
<Compile Include="Database\Tables\TableUser.cs" /> <Compile Include="Database\Tables\TableUser.cs" />
<Compile Include="Input\BarcodeReader.cs" /> <Compile Include="Input\BarcodeReader.cs" />
<Compile Include="Input\Config.cs" /> <Compile Include="Configuration\Config.cs" />
<Compile Include="Database\TDatabase.cs" /> <Compile Include="Database\TDatabase.cs" />
<Compile Include="Database\DBDriverMysqli.cs" /> <Compile Include="Database\DBDriverMysqli.cs" />
<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="Controller\Instruction.cs" />
<Compile Include="Model\History.cs" /> <Compile Include="Model\History.cs" />
<Compile Include="Model\Product.cs" /> <Compile Include="Model\Product.cs" />
<Compile Include="Model\User.cs" /> <Compile Include="Model\User.cs" />
@ -78,7 +77,6 @@
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Input\RFIDReader.cs" /> <Compile Include="Input\RFIDReader.cs" />
<Compile Include="Worker.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="exe\librfid-tool.exe"> <Content Include="exe\librfid-tool.exe">

View File

@ -71,5 +71,14 @@ namespace Matomat.Model
p.bind(k); p.bind(k);
p.store(); p.store();
} }
public static void Remove(int id)
{
TableProduct u = new TableProduct();
Dictionary<string, string> load = new Dictionary<string, string>();
load.Add("id", id.ToString());
u.load(load);
u.delete();
}
} }
} }

View File

@ -111,7 +111,7 @@ namespace Matomat.Output
this.beep(750, 500); this.beep(750, 500);
} }
this.displayClear(); 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[] upper;
byte[] lower; byte[] lower;
if (text.Length > 80) if (text.Length > 80)
@ -154,10 +154,17 @@ namespace Matomat.Output
private void createChars() private void createChars()
{ {
this.displayEscCode("GTO0@"); this.displayEscCode("GTO0@");
this.displayEscCode("UDC0GH_H_HG@"); this.specialChars();
this.displayEscCode("GTO2@"); 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) private void displayEscCode(string code)

View File

@ -4,24 +4,149 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using Matomat.Helper;
using Matomat.Input;
using Matomat.Model;
using Matomat.Output;
namespace Matomat namespace Matomat
{ {
class Program class Program
{ {
private static volatile bool _shouldStop;
public static void Main(string[] args) public static void Main(string[] args)
{ {
Worker workerObject = new Worker(); InitMainThread();
Thread workerThread = new Thread(workerObject.DoWork); Thread t = new Thread(MainThread);
t.Start();
workerThread.Start(); while (!t.IsAlive) ;
while (t.IsAlive)
while (!workerThread.IsAlive) ;
while (workerThread.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();
} }
} }
} }

View File

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