This commit is contained in:
BlubbFish 2011-10-27 23:44:44 +00:00
parent 77ec113e0d
commit a70d76c731
14 changed files with 353 additions and 3 deletions

View File

@ -3,5 +3,11 @@
<appSettings> <appSettings>
<add key="com_display" value="COM1" /> <add key="com_display" value="COM1" />
<add key="com_rfid" value="COM2" /> <add key="com_rfid" value="COM2" />
<add key="mysql_server" value="127.0.0.1"/>
<add key="mysql_user" value="root"/>
<add key="mysql_db" value="matomat"/>
<add key="mysql_port" value="3306"/>
<add key="mysql_pw" value=""/>
<add key="mysql_driver" value="mysqli"/>
</appSettings> </appSettings>
</configuration> </configuration>

View File

@ -23,6 +23,7 @@ namespace Matomat
static List<instance> instances; static List<instance> instances;
private AppSettingsReader config; private AppSettingsReader config;
public Config() public Config()
{ {
this.config = new AppSettingsReader(); this.config = new AppSettingsReader();
@ -34,6 +35,12 @@ namespace Matomat
{ {
this.com_display = (string)config.GetValue("com_display", typeof(string)); this.com_display = (string)config.GetValue("com_display", typeof(string));
this.com_rfid = (string)config.GetValue("com_rfid", 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) { } catch (Exception) { }
} }
@ -54,5 +61,17 @@ namespace Matomat
public string com_display { get; set; } public string com_display { get; set; }
public string com_rfid { 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; }
} }
} }

91
Matomat/DBDriverMysqli.cs Normal file
View File

@ -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<object> getResultList()
{
if (!data_b || this.data == null)
{
return null;
}
List<object> ret = new List<object>();
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;
}
}
}

74
Matomat/Database.cs Normal file
View File

@ -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<instance> instances;
internal static Database getInstance(string server, string dbs, string user, string pw, int port, string driver)
{
if (instances == null)
instances = new List<instance>();
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<object> getResultList()
{
return null;
}
public Exception getError()
{
return null;
}
public int getID()
{
return 0;
}
public string quote(string str)
{
return str;
}
~Database()
{
}
}
}

View File

@ -7,9 +7,10 @@ namespace Matomat
{ {
class Factory class Factory
{ {
static LCDDisplay lcd_i = null; private static LCDDisplay lcd_i = null;
static Input inp_i = null; private static Input inp_i = null;
static Config con_i = null; private static Config con_i = null;
private static Database dbo_i;
internal static LCDDisplay getLCDDisplay() internal static LCDDisplay getLCDDisplay()
{ {
if (lcd_i == null) if (lcd_i == null)
@ -44,5 +45,17 @@ namespace Matomat
{ {
return Config.getInstance(file); 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);
}
} }
} }

View File

@ -50,14 +50,19 @@
<Compile Include="Automat.cs" /> <Compile Include="Automat.cs" />
<Compile Include="BarcodeReader.cs" /> <Compile Include="BarcodeReader.cs" />
<Compile Include="Config.cs" /> <Compile Include="Config.cs" />
<Compile Include="Database.cs" />
<Compile Include="DBDriverMysqli.cs" />
<Compile Include="Factory.cs" /> <Compile Include="Factory.cs" />
<Compile Include="Helper.cs" /> <Compile Include="Helper.cs" />
<Compile Include="Input.cs" /> <Compile Include="Input.cs" />
<Compile Include="instance.cs" />
<Compile Include="LCDDisplay.cs" /> <Compile Include="LCDDisplay.cs" />
<Compile Include="Prod.cs" /> <Compile Include="Prod.cs" />
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RFIDReader.cs" /> <Compile Include="RFIDReader.cs" />
<Compile Include="Tables\Tables.cs" />
<Compile Include="Tables\Tables.User.cs" />
<Compile Include="User.cs" /> <Compile Include="User.cs" />
<Compile Include="Worker.cs" /> <Compile Include="Worker.cs" />
</ItemGroup> </ItemGroup>

View File

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

19
Matomat/Tables/Tables.cs Normal file
View File

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

BIN
Matomat/dll/mysql.data.dll Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
Matomat/dll/mysql.web.dll Normal file

Binary file not shown.