/[H9]/trunk/tntnet/dynamic/critical.ecpp
ViewVC logotype

Diff of /trunk/tntnet/dynamic/critical.ecpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 71 by torben, Tue Nov 27 17:08:11 2007 UTC revision 126 by torben, Sun Dec 2 20:26:43 2007 UTC
# Line 3  Line 3 
3  #include <tntdb/connection.h>  #include <tntdb/connection.h>
4  #include <tntdb/result.h>  #include <tntdb/result.h>
5  #include <tntdb/row.h>  #include <tntdb/row.h>
6    
7  </%pre>  </%pre>
8    
9  <%config>  <%config>
# Line 11  dburl; Line 12  dburl;
12    
13  <&header title="Critical systems">  <&header title="Critical systems">
14  </&header>  </&header>
15    <h2>Critical systems</h2>
16    
17  <{  <{
 tntdb::Connection conn;  
18    
19  conn = tntdb::connect(dburl); //letting exceptions flow up and to tntnet and let it display an error message  tntdb::Connection conn = tntdb::connect(dburl);
20    
21    
22    std::string query1;
23    query1 += "SELECT c.name, i.description, i.id ";
24    query1 += "FROM installation i INNER JOIN customer c ";
25    query1 += "ON i.customerid = c.id";
26    
27    
28    tntdb::Result inst_res = conn.select(query1);
29    
30    
31    std::string query2;
32    query2 += "SELECT commerror,temperature,flamedetector,conveyorerror,powerfailure ";
33    query2 += "FROM logtable ";
34    query2 += "INNER JOIN installation ";
35    query2 += "ON logtable.installationnr = installation.id ";
36    query2 += "WHERE installationnr = :v1 ";
37    query2 += "ORDER BY messagenr DESC ";
38    query2 += "LIMIT 1";
39    
40    tntdb::Statement st = conn.prepare(query2);
41    
42    std::ostream& out = reply.out();
43    
44    for (unsigned i=0; i<inst_res.size(); i++)
45    {
46            int id = inst_res[i].getInt(2);
47            st.clear();
48    
49            st.setInt("v1", id);
50            tntdb::Result res = st.select();
51    
52            if (res.size() > 0)
53            {
54                    bool commerror = res[0].getBool(0);
55                    int temperature = res[0].getInt(1);
56                    bool flameDetector = res[0].getBool(2);
57                    bool conveyorError = res[0].getBool(3);
58                    bool powerFailure = res[0].getBool(4);
59    
60                    if (commerror || temperature > 90 || flameDetector == false || conveyorError || powerFailure)
61                    {
62                            out << "<a href='installationdetails?id=" << id << "'><b>" << inst_res[i].getString(0) << "</b> : " << inst_res[i].getString(1) << "<br></a>\n";
63                            out << "<ul>";
64    
65                            if (temperature > 90)
66                                    out << "<li>High temperature</li>\n";
67    
68                            if (commerror)
69                                    out << "<li>Communication error</li>\n";
70    
71                            if (flameDetector == false)
72                                    out << "<li>No flames</li>\n";
73    
74                            if (conveyorError)
75                                    out << "<li>Conveyor error</li>\n";
76    
77                            if (powerFailure)
78                                    out << "<li>Power failure</li>\n";
79    
80                            out << "</ul>\n";
81    
82                            
83                    }
84            }
85    }
86    
87  }>  }>
88    

Legend:
Removed from v.71  
changed lines
  Added in v.126

  ViewVC Help
Powered by ViewVC 1.1.20