/[H8]/trunk/h8server/MySQLLayer.cpp
ViewVC logotype

Contents of /trunk/h8server/MySQLLayer.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 100 - (show annotations) (download)
Fri May 25 08:34:08 2007 UTC (16 years, 11 months ago) by kevin
File size: 3417 byte(s)
added test program and fixed some log problems
1
2 #include "StdAfx.h"
3 #include ".\MySQLLayer.h"
4
5
6 MySQLLayer::MySQLLayer(ConfigFile &config)
7 {
8 CString dsn;
9 dsn.Format("ODBC;Description=asd;DRIVER=MySQL ODBC 3.51 Driver;SERVER=%s;user=%s;password=%s", config.host, config.username, config.password);
10 db.OpenEx(dsn, CDatabase::noOdbcDialog);
11
12 CString sql;
13 sql.Format("USE %s", config.database);
14 db.ExecuteSQL(sql);
15 }
16
17 MySQLLayer::~MySQLLayer(void)
18 {
19 db.Close();
20 }
21
22 translog MySQLLayer::Transaktionslog(CString TerminalID, CString logID)
23 {
24 CString SQL, ID, lid;
25 translog tl;
26 TerminalID.Replace("'","\"");
27
28 SQL.Format((CString)"INSERT INTO Transaktionslog VALUES('',NOW(),'%s')",TerminalID);
29 db.ExecuteSQL(SQL);
30 SQL.Format("SELECT LAST_INSERT_ID() FROM Transaktionslog");
31 CRecordset rs(&db);
32 rs.Open(AFX_DB_USE_DEFAULT_TYPE, SQL);
33 if (!rs.IsEOF() )
34 {
35 rs.GetFieldValue((short)0,ID);
36
37 tl.logID = ID;
38
39 rs.Close();
40
41 }
42 return tl;
43 }
44 log MySQLLayer::TransaktionsEnhed(CString transaktion, CString price,CString barcode,CString quantity)
45 {
46 //lalala
47 CString SQL;
48 log l;
49 transaktion.Replace("'","\"");
50 price.Replace("'","\"");
51 barcode.Replace("'","\"");
52 quantity.Replace("'","\"");
53
54 SQL.Format((CString)"INSERT INTO TransaktionsEnhed VALUES('','%s','%s','%s','%s')", transaktion, price, barcode, quantity);
55 db.ExecuteSQL(SQL);
56 int pris, sum, antal, nysum;
57 sum = atoi(l.sum);
58 pris = atoi(price);
59 antal = atoi(quantity);
60 nysum = sum+(pris*antal);
61 l.sum.Format("%d",nysum);
62 return l;
63 }
64
65 Equipment MySQLLayer::GetEquipment(CString wantBarcode, CString wantdescription, CString wantprice)
66 {
67
68 CString barcode,description,price;
69
70 CString SQL;
71
72 wantBarcode.Replace("'","\"");
73
74 Equipment e;
75
76 SQL.Format((CString)"SELECT Stregkode,Beskrivelse,Pris FROM VareInfo " +
77 "Where (Stregkode = '%s')", wantBarcode);
78 CRecordset rs(&db);
79 rs.Open(AFX_DB_USE_DEFAULT_TYPE, SQL);
80 if (!rs.IsEOF() )
81 {
82 rs.GetFieldValue((short)0,barcode);
83 rs.GetFieldValue(1,description);
84 rs.GetFieldValue(2,price);
85
86 e.barcode = barcode;
87 e.description = description;
88 e.price = price;
89
90 rs.Close();
91
92 }
93 return e;
94 }
95
96 bool MySQLLayer::Deletelastentry(CString ID, CString barcode)
97 {
98 CString SQL;
99 ID.Replace("'","\"");
100 barcode.Replace("'","\"");
101 SQL.Format("DELETE FROM TransaktionsEnhed WHERE Transaktion = '%s' AND Stregkode = '%s'", ID, barcode);
102 db.ExecuteSQL(SQL);
103 return true;
104 }
105
106 bool MySQLLayer::Deletesession(CString ID)
107 {
108 CString SQL;
109 ID.Replace("'","\"");
110 SQL.Format("DELETE FROM TransaktionsEnhed WHERE Transaktion = '%s'", ID);
111 db.ExecuteSQL(SQL);
112 SQL.Format("DELETE FROM Transaktionslog WHERE ID = '%s'", ID);
113 db.ExecuteSQL(SQL);
114 return true;
115 }
116
117 /*
118 bool MySQLLayer::DeleteEquipment(Equipment DelEquip)
119 {
120 CString SQL;
121 DelEquip.barcode.Replace("'","\"");
122 SQL.Format("DELETE FROM Udstyr WHERE Stregkode = '%s'", DelEquip.barcode);
123 db.ExecuteSQL(SQL);
124 return true;
125 }
126
127
128 // Developed by Torben H. Nielsen
129 void MySQLLayer::FillEquipmentVector(vector<Equipment> &buffer, CRecordset &rs)
130 {
131 CString barcode,description,price;
132 if (rs.GetRecordCount()>0) {
133 rs.MoveFirst();
134 while (!rs.IsEOF() ) {
135 Equipment eq;
136 rs.GetFieldValue((short)0, eq.barcode);
137 rs.GetFieldValue(1, eq.description);
138 rs.GetFieldValue(2, eq.price);
139
140 buffer.push_back(eq);
141
142 rs.MoveNext();
143 }
144 }
145 }
146 */

  ViewVC Help
Powered by ViewVC 1.1.20