1 |
<%pre> |
2 |
#include <tntdb/connect.h> |
3 |
#include <tntdb/connection.h> |
4 |
#include <tntdb/result.h> |
5 |
#include <tntdb/row.h> |
6 |
|
7 |
#include "common.h" |
8 |
|
9 |
#include <sstream> |
10 |
</%pre> |
11 |
|
12 |
<%config> |
13 |
dburl; |
14 |
</%config> |
15 |
|
16 |
<&header title="Critical systems"> |
17 |
</&header> |
18 |
|
19 |
<h2>Customers and installations</h2> |
20 |
|
21 |
<{ |
22 |
tntdb::Connection conn; |
23 |
|
24 |
conn = tntdb::connect(dburl); //letting exceptions flow up and to tntnet and let it display an error message |
25 |
|
26 |
std::string customer_sql = "SELECT id,name,address,phonenr,contactperson FROM customer ORDER BY name ASC"; |
27 |
|
28 |
tntdb::Result res = conn.select(customer_sql); |
29 |
|
30 |
std::ostream& out = reply.out(); |
31 |
|
32 |
if (res.size() != 0) |
33 |
{ |
34 |
for (tntdb::Result::const_iterator it = res.begin(); it != res.end(); ++it) |
35 |
{ |
36 |
tntdb::Row row = *it; |
37 |
int customerid = row.getInt(0); |
38 |
out << "<table border=1 width='80%' cellspacing=0 align=center><tr><td>"; |
39 |
out << "<b>" << row.getString(1) << "</b><br>\n\n"; |
40 |
|
41 |
|
42 |
out << nl2br(trim(row.getString(2))) << "<br>\n"; |
43 |
|
44 |
out << "<i>Phone:</i> " << row.getString(3) << "<br>\n"; |
45 |
out << "<i>Contact:</i> " << row.getString(4) << "<br>\n"; |
46 |
|
47 |
out << "<br>\n"; |
48 |
|
49 |
|
50 |
std::stringstream sqlstream; |
51 |
sqlstream << "SELECT id, description FROM installation "; |
52 |
sqlstream << "WHERE customerid = " << customerid; |
53 |
|
54 |
tntdb::Result instres = conn.select(sqlstream.str()); |
55 |
|
56 |
if (instres.size() > 0) |
57 |
{ |
58 |
out << "Installations:\n"; |
59 |
out << "<ol style='margin-top:0px;'>\n"; |
60 |
for (tntdb::Result::const_iterator instit = instres.begin(); instit != instres.end(); ++instit) |
61 |
{ |
62 |
tntdb::Row instrow = *instit; |
63 |
out << "<li><a href='installationdetails?id=" << instrow.getString(0) << "'>"; |
64 |
out << instrow.getString(1) << "</a></li>"; |
65 |
} |
66 |
out << "</ol>\n"; |
67 |
} |
68 |
else |
69 |
{ |
70 |
out << "<i>No installations !</i>\n"; |
71 |
} |
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
out << "</td></tr></table><br>\n"; |
78 |
|
79 |
} |
80 |
} |
81 |
else |
82 |
{ |
83 |
out << "<i>No customer records found!</i>"; |
84 |
} |
85 |
|
86 |
}> |
87 |
|
88 |
<&footer> |
89 |
</&footer> |