diff --git a/Matomat/Automat.cs b/Matomat/Automat.cs index 6010d48..122db93 100644 --- a/Matomat/Automat.cs +++ b/Matomat/Automat.cs @@ -32,7 +32,7 @@ namespace Matomat } catch (ArgumentException e) { - Factory.getLCD().print(e.ToString(), 5, LCDDisplay.Status.OK); + Factory.getLCD().print(e.Message, 5, LCDDisplay.Status.OK); System.Threading.Thread.Sleep(4500); return; } @@ -52,7 +52,7 @@ namespace Matomat } catch (ArgumentException e) { - Factory.getLCD().print(e.ToString(), 5, LCDDisplay.Status.OK); + Factory.getLCD().print(e.Message, 5, LCDDisplay.Status.OK); System.Threading.Thread.Sleep(4500); return; } @@ -90,7 +90,7 @@ namespace Matomat } catch (ArgumentException e) { - Factory.getLCD().print(e.ToString(), 5, LCDDisplay.Status.OK); + Factory.getLCD().print(e.Message, 5, LCDDisplay.Status.OK); System.Threading.Thread.Sleep(4500); return; } diff --git a/Matomat/Database/DBDriverMysqli.cs b/Matomat/Database/DBDriverMysqli.cs index 6a4490c..103e1c4 100644 --- a/Matomat/Database/DBDriverMysqli.cs +++ b/Matomat/Database/DBDriverMysqli.cs @@ -34,9 +34,9 @@ namespace Matomat.Database this.err = e; return false; } + this.startPing(); this.query("SET NAMES 'UTF8'"); this.query("SET CHARACTER SET 'UTF8'"); - this.startPing(); return true; } @@ -55,6 +55,11 @@ namespace Matomat.Database } public override void query(string sql) { + this.pingThread.Abort(); + while (this.pingThread.IsAlive) + { + Thread.Sleep(1); + } this.err = null; if (this.data is MySqlDataReader && !this.data.IsClosed) this.data.Close(); @@ -80,6 +85,7 @@ namespace Matomat.Database { Console.WriteLine("SQL: " + sql + ((err != null) ? " Err" + err.Message : "")); } + this.startPing(); } private void set(string sql) diff --git a/Matomat/Database/Query/DatabaseQueryElement.cs b/Matomat/Database/Query/DatabaseQueryElement.cs index bf7499b..32e0425 100644 --- a/Matomat/Database/Query/DatabaseQueryElement.cs +++ b/Matomat/Database/Query/DatabaseQueryElement.cs @@ -51,7 +51,7 @@ namespace Matomat.Database.Query { if (this.name.Substring(this.name.Length - 2) == "()") { - return "\n" + this.name.Substring(this.name.Length - 2) + "(" + String.Join(this.glue, this.elements) + ")"; + return "\n" + this.name.Substring(0, this.name.Length - 2) + "(" + String.Join(this.glue, this.elements) + ")"; } else { diff --git a/Matomat/Database/TDatabase.cs b/Matomat/Database/TDatabase.cs index 3d99f95..c7692d9 100644 --- a/Matomat/Database/TDatabase.cs +++ b/Matomat/Database/TDatabase.cs @@ -114,7 +114,14 @@ namespace Matomat.Database foreach (System.Reflection.PropertyInfo item in p) { fields.Add(this.quoteName(item.Name)); - values.Add(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) @@ -122,8 +129,8 @@ namespace Matomat.Database return true; } - query.columns(String.Join("", fields)); - query.values(String.Join("", values)); + query.columns(String.Join(",", fields)); + query.values(String.Join(",", values)); this.setQuery(query); return true; diff --git a/Matomat/Database/Tables/Table.cs b/Matomat/Database/Tables/Table.cs index 4eaef25..d2a984c 100644 --- a/Matomat/Database/Tables/Table.cs +++ b/Matomat/Database/Tables/Table.cs @@ -14,7 +14,7 @@ namespace Matomat.Database.Tables private TDatabase _db; protected void Constructor(string table, string key, TDatabase db) { - this._tbl = table; + this._tbl = table; this._tbl_key = key; this._db = db; } diff --git a/Matomat/Instruction.cs b/Matomat/Instruction.cs index 22f1a14..77de4a4 100644 --- a/Matomat/Instruction.cs +++ b/Matomat/Instruction.cs @@ -44,7 +44,7 @@ namespace Matomat } catch (ArgumentException e) { - Factory.getLCD().print(e.ToString(), 5, LCDDisplay.Status.OK); + Factory.getLCD().print(e.Message, 5, LCDDisplay.Status.OK); System.Threading.Thread.Sleep(4500); return; } @@ -135,7 +135,7 @@ namespace Matomat } catch (ArgumentException e) { - Factory.getLCD().print(e.ToString(), 5, LCDDisplay.Status.OK); + Factory.getLCD().print(e.Message, 5, LCDDisplay.Status.OK); System.Threading.Thread.Sleep(4500); return; } diff --git a/Matomat/Model/History.cs b/Matomat/Model/History.cs index 7eb5dfa..51d39b3 100644 --- a/Matomat/Model/History.cs +++ b/Matomat/Model/History.cs @@ -73,6 +73,10 @@ namespace Matomat.Model Console.WriteLine(Factory.getDBO().getError()); return 0; } + if ((double)row[0] == 0.0) + { + return 0; + } return (int)((double)row[0]/ double.Parse(((decimal)row[1]).ToString())); } diff --git a/Matomat/Model/User.cs b/Matomat/Model/User.cs index 66c41f5..0acf22b 100644 --- a/Matomat/Model/User.cs +++ b/Matomat/Model/User.cs @@ -26,7 +26,7 @@ namespace Matomat.Model { this.table = new TableUser(); Dictionary load = new Dictionary(); - load.Add("barcode", userid.ToString()); + load.Add("userid", userid.ToString()); this.table.load(load); return (this.table.userid == this.userid); } @@ -63,7 +63,7 @@ namespace Matomat.Model Console.WriteLine(Factory.getDBO().getError()); return 0.0; } - return ((double)row[0])/100; + return (double.Parse(row[0].ToString()))/100; } public bool GetAdmin() @@ -71,9 +71,9 @@ namespace Matomat.Model return this.table.admin; } - public void SetUserKonto(double p) + public void SetUserKonto(double cost) { - p = (int)(p * 100); + int p = (int)(cost * 100); Dictionary k = new Dictionary(); k.Add("credits", this.table.credits + p); this.table.bind(k);