/[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 145 by torben, Tue Dec 4 13:29:21 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  reply.setHeader("Refresh", "120");
20    
21    tntdb::Connection conn = tntdb::connect(dburl);
22    
23    
24    std::string query1;
25    query1 += "SELECT c.name, i.description, i.id ";
26    query1 += "FROM installation i INNER JOIN customer c ";
27    query1 += "ON i.customerid = c.id";
28    
29    
30    tntdb::Result inst_res = conn.select(query1);
31    
32    
33    std::string query2;
34    query2 += "SELECT commerror,temperature,flamedetector,conveyorerror,powerfailure ";
35    query2 += "FROM logtable ";
36    query2 += "INNER JOIN installation ";
37    query2 += "ON logtable.installationnr = installation.id ";
38    query2 += "WHERE installationnr = :v1 ";
39    query2 += "ORDER BY messagenr DESC ";
40    query2 += "LIMIT 1";
41    
42    tntdb::Statement st = conn.prepare(query2);
43    
44    std::ostream& out = reply.out();
45    
46    bool hasCritical = false;
47    
48    for (unsigned i=0; i<inst_res.size(); i++)
49    {
50            int id = inst_res[i].getInt(2);
51            st.clear();
52    
53            st.setInt("v1", id);
54            tntdb::Result res = st.select();
55    
56            if (res.size() > 0)
57            {
58                    bool commerror = res[0].getBool(0);
59                    int temperature = res[0].getInt(1);
60                    bool flameDetector = res[0].getBool(2);
61                    bool conveyorError = res[0].getBool(3);
62                    bool powerFailure = res[0].getBool(4);
63    
64                    if (commerror || temperature > 90 || flameDetector == false || conveyorError || powerFailure)
65                    {
66                            out << "<a href='installationdetails?id=" << id << "'><b>" << inst_res[i].getString(0) << "</b> : " << inst_res[i].getString(1) << "<br></a>\n";
67                            out << "<ul>";
68    
69                            if (temperature > 90)
70                                    out << "<li>High temperature</li>\n";
71    
72                            if (commerror)
73                                    out << "<li>Communication error</li>\n";
74    
75                            if (flameDetector == false)
76                                    out << "<li>No flames</li>\n";
77    
78                            if (conveyorError)
79                                    out << "<li>Conveyor error</li>\n";
80    
81                            if (powerFailure)
82                                    out << "<li>Power failure</li>\n";
83    
84                            out << "</ul>\n";
85    
86                            hasCritical = true;
87                    }
88            }
89    }
90    
91    if (hasCritical == false)
92    {
93            out << "<i>No critical installations found</i>\n";
94    }
95    
96  }>  }>
97    

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

  ViewVC Help
Powered by ViewVC 1.1.20