Database
This commit is contained in:
parent
a70d76c731
commit
9bfb6285aa
@ -13,28 +13,31 @@ namespace Matomat
|
||||
private Exception err;
|
||||
private bool data_b;
|
||||
private MySqlDataReader data;
|
||||
private long id;
|
||||
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 + ";");
|
||||
this.conn.Open();
|
||||
}
|
||||
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();
|
||||
this.query("SET NAMES 'UTF8'");
|
||||
this.query("SET CHARACTER SET 'UTF8'");
|
||||
return true;
|
||||
}
|
||||
public override void query(string sql)
|
||||
{
|
||||
this.err = null;
|
||||
this.data = null;
|
||||
this.data_b = true;
|
||||
if (sql.ToUpper().Substring(0, 6) == "SELECT")
|
||||
this.select(sql);
|
||||
else if (sql.ToUpper().Substring(0, 6) == "INSERT")
|
||||
@ -53,9 +56,94 @@ namespace Matomat
|
||||
this.err = new Exception("Keine unterstütze MySQL Abfrage '" + sql + "'...");
|
||||
}
|
||||
|
||||
private void set(string sql)
|
||||
{
|
||||
try
|
||||
{
|
||||
MySqlCommand cmd = new MySqlCommand(sql, this.conn);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.err = e;
|
||||
this.data_b = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void create(string sql)
|
||||
{
|
||||
try
|
||||
{
|
||||
MySqlCommand cmd = new MySqlCommand(sql, this.conn);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.err = e;
|
||||
this.data_b = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void truncate(string sql)
|
||||
{
|
||||
try
|
||||
{
|
||||
MySqlCommand cmd = new MySqlCommand(sql, this.conn);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.err = e;
|
||||
this.data_b = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void delete(string sql)
|
||||
{
|
||||
try
|
||||
{
|
||||
MySqlCommand cmd = new MySqlCommand(sql, this.conn);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.err = e;
|
||||
this.data_b = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void update(string sql)
|
||||
{
|
||||
try
|
||||
{
|
||||
MySqlCommand cmd = new MySqlCommand(sql, this.conn);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.err = e;
|
||||
this.data_b = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void insert(string sql)
|
||||
{
|
||||
try
|
||||
{
|
||||
MySqlCommand cmd = new MySqlCommand(sql, this.conn);
|
||||
cmd.ExecuteNonQuery();
|
||||
this.id = cmd.LastInsertedId;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.err = e;
|
||||
this.data_b = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void select(string sql)
|
||||
{
|
||||
this.data_b = true;
|
||||
try
|
||||
{
|
||||
MySqlCommand cmd = new MySqlCommand(sql, this.conn);
|
||||
@ -68,13 +156,13 @@ namespace Matomat
|
||||
this.data = null;
|
||||
}
|
||||
}
|
||||
public override List<object> getResultList()
|
||||
public override List<object[]> getResultList()
|
||||
{
|
||||
if (!data_b || this.data == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
List<object> ret = new List<object>();
|
||||
List<object[]> ret = new List<object[]>();
|
||||
while (this.data.Read())
|
||||
{
|
||||
object[] row = new object[this.data.FieldCount];
|
||||
@ -87,5 +175,41 @@ namespace Matomat
|
||||
this.data.Close();
|
||||
return ret;
|
||||
}
|
||||
public override object[] getResult()
|
||||
{
|
||||
if (!data_b || this.data == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (this.data.HasRows)
|
||||
{
|
||||
this.data.Read();
|
||||
object[] row = new object[this.data.FieldCount];
|
||||
for (int i = 0; i < this.data.FieldCount; i++)
|
||||
{
|
||||
row[i] = this.data[i];
|
||||
}
|
||||
return row;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public override Exception getError()
|
||||
{
|
||||
return this.err;
|
||||
}
|
||||
public override long getID()
|
||||
{
|
||||
return this.id;
|
||||
}
|
||||
public override string quote(string str)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
~DBDriverMysqli()
|
||||
{
|
||||
if (!this.data.IsClosed)
|
||||
this.data.Close();
|
||||
this.conn.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,8 @@ namespace Matomat
|
||||
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());
|
||||
string object_driver = "Matomat.DBDriver" + char.ToUpper(driver[0]) + driver.Substring(1).ToLower();
|
||||
Type t = Type.GetType(object_driver, true);
|
||||
Database db = (Database)t.GetConstructor(Type.EmptyTypes).Invoke(new Object[0]);
|
||||
db.connect(server, dbs, user, pw, port, driver);
|
||||
if (db.getError() != null)
|
||||
@ -39,31 +40,31 @@ namespace Matomat
|
||||
instances.Add(instance);
|
||||
return instance.iDatabase;
|
||||
}
|
||||
public bool connect(string server, string dbs, string user, string pw, int port, string driver)
|
||||
public virtual bool connect(string server, string dbs, string user, string pw, int port, string driver)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public void query(string sql)
|
||||
public virtual void query(string sql)
|
||||
{
|
||||
return;
|
||||
}
|
||||
public object getResult()
|
||||
public virtual object[] getResult()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public List<object> getResultList()
|
||||
public virtual List<object[]> getResultList()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public Exception getError()
|
||||
public virtual Exception getError()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public int getID()
|
||||
public virtual long getID()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
public string quote(string str)
|
||||
public virtual string quote(string str)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
@ -34,6 +34,21 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="mysql.data, Version=6.2.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>.\mysql.data.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="mysql.data.entity, Version=6.2.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>.\mysql.data.entity.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="mysql.visualstudio">
|
||||
<HintPath>.\mysql.visualstudio.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="mysql.web, Version=6.2.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>.\mysql.web.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RfidClass, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>.\RfidClass.dll</HintPath>
|
||||
@ -55,7 +70,6 @@
|
||||
<Compile Include="Factory.cs" />
|
||||
<Compile Include="Helper.cs" />
|
||||
<Compile Include="Input.cs" />
|
||||
<Compile Include="instance.cs" />
|
||||
<Compile Include="LCDDisplay.cs" />
|
||||
<Compile Include="Prod.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
@ -67,16 +81,22 @@
|
||||
<Compile Include="Worker.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="librfid-tool.exe">
|
||||
<Content Include="exe\librfid-tool.exe">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="RfidClass.dll">
|
||||
<Content Include="dll\RfidClass.dll">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="dll\mysql.data.dll" />
|
||||
<Content Include="dll\mysql.data.entity.dll" />
|
||||
<Content Include="dll\mysql.visualstudio.dll" />
|
||||
<Content Include="dll\mysql.web.dll" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<Compile Include="Tables\Tables.Product.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
@ -24,10 +24,24 @@ namespace Matomat
|
||||
|
||||
private void load()
|
||||
{
|
||||
if (true)
|
||||
TProduct t = new Tables().getProdTable(this.prodId);
|
||||
if (t == null)
|
||||
{
|
||||
this.found = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.found = true;
|
||||
if (t.iscommand)
|
||||
{
|
||||
this.type = ProdType.instruction;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.type = ProdType.product;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal bool vaild()
|
||||
{
|
||||
|
88
Matomat/Tables/Tables.Product.cs
Normal file
88
Matomat/Tables/Tables.Product.cs
Normal file
@ -0,0 +1,88 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Matomat
|
||||
{
|
||||
class TProduct : Tables
|
||||
{
|
||||
private int _id;
|
||||
public int id
|
||||
{
|
||||
get
|
||||
{
|
||||
return _id;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_id != value)
|
||||
{
|
||||
_id = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private long _barcode;
|
||||
public long barcode
|
||||
{
|
||||
get
|
||||
{
|
||||
return _barcode;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_barcode != value)
|
||||
{
|
||||
_barcode = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string _name;
|
||||
public string name
|
||||
{
|
||||
get
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_name != value)
|
||||
{
|
||||
_name = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
private int _cost;
|
||||
public int cost
|
||||
{
|
||||
get
|
||||
{
|
||||
return _cost;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_cost != value)
|
||||
{
|
||||
_cost = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
private bool _iscommand;
|
||||
public bool iscommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return _iscommand;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_iscommand != value)
|
||||
{
|
||||
_iscommand = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@ using System.Text;
|
||||
|
||||
namespace Matomat
|
||||
{
|
||||
partial class Tables
|
||||
class Tables
|
||||
{
|
||||
public TUser getUserTable(int id)
|
||||
{
|
||||
@ -13,7 +13,31 @@ namespace Matomat
|
||||
}
|
||||
public TUser getUserTable(long userid)
|
||||
{
|
||||
Database db = Factory.getDBO();
|
||||
db.query("SELECT * FROM `user` WHERE `userid` =" + db.quote(userid.ToString()));
|
||||
object[] row = db.getResult();
|
||||
return new TUser();
|
||||
}
|
||||
public TProduct getProdTable(int id)
|
||||
{
|
||||
return new TProduct();
|
||||
}
|
||||
public TProduct getProdTable(long barcode)
|
||||
{
|
||||
Database db = Factory.getDBO();
|
||||
db.query("SELECT * FROM `product` WHERE `barcode` = " + db.quote(barcode.ToString()));
|
||||
object[] row = db.getResult();
|
||||
if (row == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
TProduct ret = new TProduct();
|
||||
ret.id = (int)row[0];
|
||||
ret.barcode = (long)row[1];
|
||||
ret.name = (string)row[2];
|
||||
ret.cost = (int)row[3];
|
||||
ret.iscommand = (bool)row[4];
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,8 @@ namespace Matomat
|
||||
|
||||
private void load()
|
||||
{
|
||||
TUser u = new Tables().getUserTable(this.userId);
|
||||
|
||||
if (true)
|
||||
this.found = true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user