/[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 121 by torben, Fri Nov 30 16:05:11 2007 UTC revision 122 by torben, Sun Dec 2 16:56:14 2007 UTC
# Line 4  Line 4 
4  #include <tntdb/result.h>  #include <tntdb/result.h>
5  #include <tntdb/row.h>  #include <tntdb/row.h>
6    
7  #include <vector>  //#include <vector>
8    #include <sstream>
   
9    
10    /*
11  class CriticalInstallation  class CriticalInstallation
12  {  {
13  public:  public:
# Line 15  public: Line 15  public:
15          CriticalInstallation(int i, std::string m) : id(i), message(m) {}          CriticalInstallation(int i, std::string m) : id(i), message(m) {}
16          int id;          int id;
17          std::string message;          std::string message;
18  };  };*/
19    
20  </%pre>  </%pre>
21    
# Line 30  dburl; Line 30  dburl;
30  <{  <{
31    
32    
33  std::vector<CriticalInstallation> criticals;  //std::vector<CriticalInstallation> criticals;
34    
35  tntdb::Connection conn = tntdb::connect(dburl);  tntdb::Connection conn = tntdb::connect(dburl);
36    
37    /*
38  tntdb::Result res = conn.select("SELECT id FROM installation WHERE commerror = true");  tntdb::Result res = conn.select("SELECT id FROM installation WHERE commerror = true");
39  for (int i=0; i<res.size(); ++i)  for (int i=0; i<res.size(); ++i)
40  {  {
41          criticals.push_back(CriticalInstallation(res[i].getInt(0), std::string("Communication Error")));          criticals.push_back(CriticalInstallation(res[i].getInt(0), std::string("Communication Error")));
42  }  }*/
43    
44    
45    std::string query1;
46    query1 += "SELECT c.name, i.description, i.id ";
47    query1 += "FROM installation i INNER JOIN customer c ";
48    query1 += "ON i.customerid = c.id";
49    
50    
51    tntdb::Result inst_res = conn.select(query1);
52    
53    
54    
55    std::string query2;
56    query2 += "SELECT commerror,temperature,flamedetector,conveyorerror,powerfailure ";
57    query2 += "FROM logtable ";
58    query2 += "INNER JOIN installation ";
59    query2 += "ON logtable.installationnr = installation.id ";
60    query2 += "WHERE installationnr = :v1 ";
61    query2 += "ORDER BY messagenr DESC ";
62    query2 += "LIMIT 1";
63    
64    tntdb::Statement st = conn.prepare(query2);
65    
66    std::ostream& out = reply.out();
67    
68    for (int i=0; i<inst_res.size(); i++)
69    {
70            int id = inst_res[i].getInt(2);
71            st.clear();
72    
73            st.setInt("v1", id);
74            tntdb::Result res = st.select();
75    
76            if (res.size() > 0)
77            {
78                    bool commerror = res[0].getBool(0);
79                    int temperature = res[0].getInt(1);
80                    bool flameDetector = res[0].getBool(2);
81                    bool conveyorError = res[0].getBool(3);
82                    bool powerFailure = res[0].getBool(4);
83    
84                    if (commerror || temperature > 90 || flameDetector == false || conveyorError || powerFailure)
85                    {
86                            out << "<a href='installationdetails?id=" << id << "'><b>" << inst_res[i].getString(0) << "</b> : " << inst_res[i].getString(1) << "<br></a>\n";
87                            out << "<ul>";
88    
89                            if (temperature > 90)
90                                    out << "<li>High temperature</li>\n";
91    
92                            if (commerror)
93                                    out << "<li>Communication error</li>\n";
94    
95                            if (flameDetector == false)
96                                    out << "<li>No flames</li>\n";
97    
98                            if (conveyorError)
99                                    out << "<li>Conveyor error</li>\n";
100    
101                            if (powerFailure)
102                                    out << "<li>Power failure</li>\n";
103    
104                            out << "</ul>\n";
105    
106                            
107                    }
108            }
109    }
110    
111  }>  }>
112    
113  <&footer>  <&footer>

Legend:
Removed from v.121  
changed lines
  Added in v.122

  ViewVC Help
Powered by ViewVC 1.1.20