diff --git a/Matomat/App.config b/Matomat/App.config index 8da3d8e..a25fc87 100644 --- a/Matomat/App.config +++ b/Matomat/App.config @@ -1,8 +1,8 @@ - + - - + + @@ -12,4 +12,4 @@ - \ No newline at end of file + diff --git a/Matomat/Database/TDatabase.cs b/Matomat/Database/TDatabase.cs index c7692d9..126a19a 100644 --- a/Matomat/Database/TDatabase.cs +++ b/Matomat/Database/TDatabase.cs @@ -35,7 +35,18 @@ namespace Matomat.Database if (db.getError() != null) { - throw new Exception("db Fehler:" + db.getError()); + Exception e = db.getError(); + if (e.GetType() == typeof(MySql.Data.MySqlClient.MySqlException)) + { + String mesg = e.Message; + if (mesg.Length > 38) + { + mesg = mesg.Substring(0, 38) + "\n" + mesg.Substring(38); + } + Matomat.Helper.Factory.getLCD().print(mesg, 10, Matomat.Output.LCDDisplay.Status.Error); + System.Threading.Thread.Sleep(10000); + throw new Exception("ENDE"); + } } instances.Add(signature,db); @@ -114,14 +125,14 @@ namespace Matomat.Database foreach (System.Reflection.PropertyInfo item in p) { fields.Add(this.quoteName(item.Name)); - if (item.GetValue(row, null).GetType() == DateTime.Now.GetType()) - { - values.Add(this.quote(((DateTime)item.GetValue(row, null)).ToString("s"))); - } - else - { - values.Add(this.quote(item.GetValue(row, null).ToString())); - } + if (item.GetValue(row, null).GetType() == DateTime.Now.GetType()) + { + values.Add(this.quote(((DateTime)item.GetValue(row, null)).ToString("s"))); + } + else + { + values.Add(this.quote(item.GetValue(row, null).ToString())); + } } if (p.Length == 0) diff --git a/Matomat/Model/History.cs b/Matomat/Model/History.cs index 27cab24..3df3737 100644 --- a/Matomat/Model/History.cs +++ b/Matomat/Model/History.cs @@ -21,7 +21,8 @@ namespace Matomat.Model query.where(Factory.getDBO().quoteName("p.iscommand") + " = " + Factory.getDBO().quote(0.ToString())); query.where(Factory.getDBO().quoteName("h.time") + " >= DATE_SUB(NOW(),INTERVAL 7 DAY)"); query.group(Factory.getDBO().quoteName("h.user")); - query.order(Factory.getDBO().quoteName("num")); + query.order(Factory.getDBO().quoteName("num")+" DESC"); + query.order(Factory.getDBO().quoteName("name")); query.limit(0, limit); Factory.getDBO().setQuery(query); @@ -54,6 +55,10 @@ namespace Matomat.Model Console.WriteLine(Factory.getDBO().getError()); return 0; } + if (row[0].GetType() == System.DBNull.Value.GetType()) + { + return 0; + } return (int)(double)row[0]; } @@ -65,19 +70,38 @@ namespace Matomat.Model query.from(Factory.getDBO().quoteName("history", "h")); query.leftJoin(Factory.getDBO().quoteName("product", "p") + " ON " + Factory.getDBO().quoteName("p.id") + " = " + Factory.getDBO().quoteName("h.prod")); query.where(Factory.getDBO().quoteName("h.time") + " >= DATE_SUB(NOW(),INTERVAL 7 DAY)"); + query.group(Factory.getDBO().quoteName("h.user")); Factory.getDBO().setQuery(query); - object[] row = Factory.getDBO().getResult(); - if (row == null) + List rows = Factory.getDBO().getResultList(); + if (rows == null) { Console.WriteLine(Factory.getDBO().getError()); return 0; } - if ((double)row[0] == 0.0) + if (rows.Count == 0) { return 0; } - return (int)((double)row[0]/ double.Parse(((decimal)row[1]).ToString())); + if (rows[0][0].GetType() == System.DBNull.Value.GetType()) + { + return 0; + } + if ((double)rows[0][0] == 0.0) + { + return 0; + } + double num = 0; + double meng = 0; + foreach (var row in rows) + { + if (int.Parse(row[1].ToString()) != 0) + { + meng += double.Parse(row[0].ToString()); + num++; + } + } + return (int)(meng/num); } public static void Add(int product_id, int user_id) diff --git a/Matomat/Program.cs b/Matomat/Program.cs index 320b78a..596ceca 100644 --- a/Matomat/Program.cs +++ b/Matomat/Program.cs @@ -17,15 +17,14 @@ namespace Matomat public static void Main(string[] args) { - //test(); - InitMainThread(); - Thread t = new Thread(MainThread); - t.Start(); - while (!t.IsAlive) ; - while (t.IsAlive) - { - Thread.Sleep(10); - } + InitMainThread(); + Thread t = new Thread(MainThread); + t.Start(); + while (!t.IsAlive) ; + while (t.IsAlive) + { + Thread.Sleep(10); + } } private static void test() @@ -43,20 +42,33 @@ namespace Matomat private static void MainThread() { - while (!_shouldStop) + try { - Instruction.GetInitStatus(); - InputData input = Factory.getInput().getAnyInput(60); - if (input.type != InputData.types.None) + while (!_shouldStop) { - doJob(input); + 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(); + } + catch (Exception e) + { + Factory.getLCD().print("Der Matomat wurde kritisch beendet.\n" + e.Message); + Console.WriteLine(e.ToString()); + Factory.rmLCD(); + Factory.rmInput(); + Factory.rmDBO(); + Factory.rmConfig(); + Thread.Sleep(10000); } - 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) diff --git a/Matomat/Properties/AssemblyInfo.cs b/Matomat/Properties/AssemblyInfo.cs index dd59582..b7f265c 100644 --- a/Matomat/Properties/AssemblyInfo.cs +++ b/Matomat/Properties/AssemblyInfo.cs @@ -1,16 +1,17 @@ using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using System.Resources; // Allgemeine Informationen über eine Assembly werden über die folgenden // Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, // die mit einer Assembly verknüpft sind. [assembly: AssemblyTitle("Matomat")] -[assembly: AssemblyDescription("")] +[assembly: AssemblyDescription("Der Matomat")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyCompany("BlubbFish")] [assembly: AssemblyProduct("Matomat")] -[assembly: AssemblyCopyright("Copyright © Microsoft 2011")] +[assembly: AssemblyCopyright("Copyright © BlubbFish 2013")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -34,3 +35,4 @@ using System.Runtime.InteropServices; // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: NeutralResourcesLanguageAttribute("de-DE")] diff --git a/Working/Matomat.exe b/Working/Matomat.exe new file mode 100644 index 0000000..18563f5 Binary files /dev/null and b/Working/Matomat.exe differ diff --git a/Working/Matomat.exe.config_MODIFY_ME b/Working/Matomat.exe.config_MODIFY_ME new file mode 100644 index 0000000..a25fc87 --- /dev/null +++ b/Working/Matomat.exe.config_MODIFY_ME @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/Working/RfidClass.dll b/Working/RfidClass.dll new file mode 100644 index 0000000..f1e0da6 Binary files /dev/null and b/Working/RfidClass.dll differ diff --git a/Working/librfid-tool.exe b/Working/librfid-tool.exe new file mode 100644 index 0000000..9becc5c Binary files /dev/null and b/Working/librfid-tool.exe differ diff --git a/Working/mysql.data.dll b/Working/mysql.data.dll new file mode 100644 index 0000000..1254d90 Binary files /dev/null and b/Working/mysql.data.dll differ diff --git a/Working/mysql.data.entity.dll b/Working/mysql.data.entity.dll new file mode 100644 index 0000000..3c7886c Binary files /dev/null and b/Working/mysql.data.entity.dll differ