diff --git a/Matomat/App.config b/Matomat/App.config index f7ae6c7..b6c6250 100644 --- a/Matomat/App.config +++ b/Matomat/App.config @@ -3,5 +3,11 @@ + + + + + + \ No newline at end of file diff --git a/Matomat/Config.cs b/Matomat/Config.cs index 7d53baf..65c35fc 100644 --- a/Matomat/Config.cs +++ b/Matomat/Config.cs @@ -23,6 +23,7 @@ namespace Matomat static List instances; private AppSettingsReader config; + public Config() { this.config = new AppSettingsReader(); @@ -34,6 +35,12 @@ namespace Matomat { this.com_display = (string)config.GetValue("com_display", typeof(string)); this.com_rfid = (string)config.GetValue("com_rfid", typeof(string)); + this.mysql_server = (string)config.GetValue("mysql_server", typeof(string)); + this.mysql_user = (string)config.GetValue("mysql_user", typeof(string)); + this.mysql_db = (string)config.GetValue("mysql_db", typeof(string)); + 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)); } catch (Exception) { } } @@ -54,5 +61,17 @@ namespace Matomat public string com_display { get; set; } public string com_rfid { get; 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; } } } diff --git a/Matomat/DBDriverMysqli.cs b/Matomat/DBDriverMysqli.cs new file mode 100644 index 0000000..bc29b23 --- /dev/null +++ b/Matomat/DBDriverMysqli.cs @@ -0,0 +1,91 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MySql.Data; +using MySql.Data.MySqlClient; + +namespace Matomat +{ + class DBDriverMysqli : Database + { + MySqlConnection conn; + private Exception err; + private bool data_b; + private MySqlDataReader data; + public DBDriverMysqli() + { + + } + public override bool connect(string server, string dbs, string user, string pw, int port, string driver) + { + try + { + this.conn = new MySqlConnection("server=" + server + ";user=" + user + ";database=" + dbs + ";port=" + port + ";password=" + pw + ";"); + } + catch (Exception e) + { + this.err = e; + return false; + } + new MySqlCommand("SET NAMES 'UTF8'", this.conn).ExecuteNonQuery(); + new MySqlCommand("SET CHARACTER SET 'UTF8'", this.conn).ExecuteNonQuery(); + return true; + } + public override void query(string sql) + { + this.err = null; + if (sql.ToUpper().Substring(0, 6) == "SELECT") + this.select(sql); + else if (sql.ToUpper().Substring(0, 6) == "INSERT") + this.insert(sql); + else if (sql.ToUpper().Substring(0, 6) == "UPDATE") + this.update(sql); + else if (sql.ToUpper().Substring(0, 6) == "DELETE") + this.delete(sql); + else if (sql.ToUpper().Substring(0, 8) == "TRUNCATE") + this.truncate(sql); + else if (sql.ToUpper().Substring(0, 6) == "CREATE") + this.create(sql); + else if (sql.ToUpper().Substring(0, 3) == "SET") + this.set(sql); + else + this.err = new Exception("Keine unterstütze MySQL Abfrage '" + sql + "'..."); + } + + private void select(string sql) + { + this.data_b = true; + try + { + MySqlCommand cmd = new MySqlCommand(sql, this.conn); + this.data = cmd.ExecuteReader(); + } + catch (Exception e) + { + this.err = e; + this.data_b = false; + this.data = null; + } + } + public override List getResultList() + { + if (!data_b || this.data == null) + { + return null; + } + List ret = new List(); + while (this.data.Read()) + { + object[] row = new object[this.data.FieldCount]; + for (int i = 0; i < this.data.FieldCount; i++) + { + row[i] = this.data[i]; + } + ret.Add(row); + } + this.data.Close(); + return ret; + } + } +} diff --git a/Matomat/Database.cs b/Matomat/Database.cs new file mode 100644 index 0000000..961bb8f --- /dev/null +++ b/Matomat/Database.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Matomat +{ + 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 instances; + internal static Database getInstance(string server, string dbs, string user, string pw, int port, string driver) + { + if (instances == null) + instances = new List(); + foreach (instance i in instances) + { + if (i.signature == server + dbs + user + pw + port + driver) + return i.iDatabase; + } + Type t = Type.GetType("DBDriver" + char.ToUpper(driver[0]) + driver.Substring(1).ToLower()); + 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 bool connect(string server, string dbs, string user, string pw, int port, string driver) + { + return false; + } + public void query(string sql) + { + return; + } + public object getResult() + { + return null; + } + public List getResultList() + { + return null; + } + public Exception getError() + { + return null; + } + public int getID() + { + return 0; + } + public string quote(string str) + { + return str; + } + ~Database() + { + } + } +} diff --git a/Matomat/Factory.cs b/Matomat/Factory.cs index 034e940..869ed96 100644 --- a/Matomat/Factory.cs +++ b/Matomat/Factory.cs @@ -7,9 +7,10 @@ namespace Matomat { class Factory { - static LCDDisplay lcd_i = null; - static Input inp_i = null; - static Config con_i = null; + private static LCDDisplay lcd_i = null; + private static Input inp_i = null; + private static Config con_i = null; + private static Database dbo_i; internal static LCDDisplay getLCDDisplay() { if (lcd_i == null) @@ -44,5 +45,17 @@ namespace Matomat { 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); + } } } diff --git a/Matomat/Matomat.csproj b/Matomat/Matomat.csproj index ee14549..25cc1c9 100644 --- a/Matomat/Matomat.csproj +++ b/Matomat/Matomat.csproj @@ -50,14 +50,19 @@ + + + + + diff --git a/Matomat/Tables/Tables.User.cs b/Matomat/Tables/Tables.User.cs new file mode 100644 index 0000000..823a1cd --- /dev/null +++ b/Matomat/Tables/Tables.User.cs @@ -0,0 +1,123 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Data; + +namespace Matomat +{ + class TUser : Tables + { + private int _id; + public int id + { + get + { + return _id; + } + set + { + if (_id != value) + { + _id = value; + } + } + } + + private long _userid; + public long userid + { + get + { + return _userid; + } + set + { + if (_userid != value) + { + _userid = value; + } + } + } + + private string _username; + public string username + { + get + { + return _username; + } + set + { + if (_username != value) + { + _username = value; + } + } + } + + private int _credits; + public int credits + { + get + { + return _credits; + } + set + { + if (_credits != value) + { + _credits = value; + } + } + } + + private bool _admin; + public bool admin + { + get + { + return _admin; + } + set + { + if (_admin != value) + { + _admin = value; + } + } + } + + private string _shortname; + public string shortname + { + get + { + return _shortname; + } + set + { + if (_shortname != value) + { + _shortname = value; + } + } + } + + private string _email; + public string email + { + get + { + return _email; + } + set + { + if (_email != value) + { + _email = value; + } + } + } + } +} diff --git a/Matomat/Tables/Tables.cs b/Matomat/Tables/Tables.cs new file mode 100644 index 0000000..4b1a1b5 --- /dev/null +++ b/Matomat/Tables/Tables.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Matomat +{ + partial class Tables + { + public TUser getUserTable(int id) + { + return new TUser(); + } + public TUser getUserTable(long userid) + { + return new TUser(); + } + } +} diff --git a/Matomat/RfidClass.dll b/Matomat/dll/RfidClass.dll similarity index 100% rename from Matomat/RfidClass.dll rename to Matomat/dll/RfidClass.dll diff --git a/Matomat/dll/mysql.data.dll b/Matomat/dll/mysql.data.dll new file mode 100644 index 0000000..1254d90 Binary files /dev/null and b/Matomat/dll/mysql.data.dll differ diff --git a/Matomat/dll/mysql.data.entity.dll b/Matomat/dll/mysql.data.entity.dll new file mode 100644 index 0000000..3c7886c Binary files /dev/null and b/Matomat/dll/mysql.data.entity.dll differ diff --git a/Matomat/dll/mysql.visualstudio.dll b/Matomat/dll/mysql.visualstudio.dll new file mode 100644 index 0000000..191a494 Binary files /dev/null and b/Matomat/dll/mysql.visualstudio.dll differ diff --git a/Matomat/dll/mysql.web.dll b/Matomat/dll/mysql.web.dll new file mode 100644 index 0000000..cb4f8d4 Binary files /dev/null and b/Matomat/dll/mysql.web.dll differ diff --git a/Matomat/librfid-tool.exe b/Matomat/exe/librfid-tool.exe similarity index 100% rename from Matomat/librfid-tool.exe rename to Matomat/exe/librfid-tool.exe