#include "StdAfx.h" #include ".\MySQLLayer.h" MySQLLayer::MySQLLayer(ConfigFile &config) { CString dsn; dsn.Format("ODBC;Description=asd;DRIVER=MySQL ODBC 3.51 Driver;SERVER=%s;user=%s;password=%s", config.host, config.username, config.password); db.OpenEx(dsn, CDatabase::noOdbcDialog); CString sql; sql.Format("USE %s", config.database); db.ExecuteSQL(sql); } MySQLLayer::~MySQLLayer(void) { db.Close(); } translog MySQLLayer::Transaktionslog(CString TerminalID, CString logID) { CString SQL, ID, lid; translog tl; TerminalID.Replace("'","\""); SQL.Format((CString)"INSERT INTO Transaktionslog VALUES('',NOW(),'%s')",TerminalID); db.ExecuteSQL(SQL); SQL.Format("SELECT LAST_INSERT_ID() FROM Transaktionslog"); CRecordset rs(&db); rs.Open(AFX_DB_USE_DEFAULT_TYPE, SQL); if (!rs.IsEOF() ) { rs.GetFieldValue((short)0,ID); tl.logID = ID; rs.Close(); } return tl; } log MySQLLayer::TransaktionsEnhed(CString transaktion, CString price,CString barcode,CString quantity) { //lalala CString SQL; log l; transaktion.Replace("'","\""); price.Replace("'","\""); barcode.Replace("'","\""); quantity.Replace("'","\""); SQL.Format((CString)"INSERT INTO TransaktionsEnhed VALUES('','%s','%s','%s','%s')", transaktion, price, barcode, quantity); db.ExecuteSQL(SQL); int pris, sum, antal, nysum; sum = atoi(l.sum); pris = atoi(price); antal = atoi(quantity); nysum = sum+(pris*antal); l.sum.Format("%d",nysum); return l; } Equipment MySQLLayer::GetEquipment(CString wantBarcode, CString wantdescription, CString wantprice) { CString barcode,description,price; CString SQL; wantBarcode.Replace("'","\""); Equipment e; SQL.Format((CString)"SELECT Stregkode,Beskrivelse,Pris FROM VareInfo " + "Where (Stregkode = '%s')", wantBarcode); CRecordset rs(&db); rs.Open(AFX_DB_USE_DEFAULT_TYPE, SQL); if (!rs.IsEOF() ) { rs.GetFieldValue((short)0,barcode); rs.GetFieldValue(1,description); rs.GetFieldValue(2,price); e.barcode = barcode; e.description = description; e.price = price; rs.Close(); } return e; } bool MySQLLayer::Deletelastentry(CString ID, CString barcode) { CString SQL; ID.Replace("'","\""); barcode.Replace("'","\""); SQL.Format("DELETE FROM TransaktionsEnhed WHERE Transaktion = '%s' AND Stregkode = '%s'", ID, barcode); db.ExecuteSQL(SQL); return true; } bool MySQLLayer::Deletesession(CString ID) { CString SQL; ID.Replace("'","\""); SQL.Format("DELETE FROM TransaktionsEnhed WHERE Transaktion = '%s'", ID); db.ExecuteSQL(SQL); SQL.Format("DELETE FROM Transaktionslog WHERE ID = '%s'", ID); db.ExecuteSQL(SQL); return true; } /* bool MySQLLayer::DeleteEquipment(Equipment DelEquip) { CString SQL; DelEquip.barcode.Replace("'","\""); SQL.Format("DELETE FROM Udstyr WHERE Stregkode = '%s'", DelEquip.barcode); db.ExecuteSQL(SQL); return true; } // Developed by Torben H. Nielsen void MySQLLayer::FillEquipmentVector(vector &buffer, CRecordset &rs) { CString barcode,description,price; if (rs.GetRecordCount()>0) { rs.MoveFirst(); while (!rs.IsEOF() ) { Equipment eq; rs.GetFieldValue((short)0, eq.barcode); rs.GetFieldValue(1, eq.description); rs.GetFieldValue(2, eq.price); buffer.push_back(eq); rs.MoveNext(); } } } */