Exemplo n.º 1
0
bool CSVWholeview::enumMonitors(const string &szDeviceID, const string &szDeviceName, WTableCell *pTableCell)
{
    map<int, base_param, less<int> > sortList;
    map<int, base_param, less<int> >::iterator lsItem;

    OBJECT objDevice = GetEntity(szDeviceID,  m_szIDCUser, m_szIDCPwd);
    if(objDevice != INVALID_VALUE)
    {
        list<string> lsMonitorID;
        list<string>::iterator lstItem;
        if (GetSubMonitorsIDByEntity(objDevice, lsMonitorID))
        {
            base_param monitor;
            string szMonitorId("");
            OBJECT objMonitor = INVALID_VALUE;
            MAPNODE node = INVALID_VALUE;

            string szName(""), szIndex("");

            int nIndex = 0;
            for(lstItem = lsMonitorID.begin(); lstItem != lsMonitorID.end(); lstItem ++)
            {
                szMonitorId = (*lstItem).c_str();
                objMonitor = GetMonitor(szMonitorId, m_szIDCUser, m_szIDCPwd);
                if(objMonitor != INVALID_VALUE)
                {
                    node = GetMonitorMainAttribNode(objMonitor);
                    if(node != INVALID_VALUE)
                    {
                        FindNodeValue(node, "sv_name", szName);
                        FindNodeValue(node, "sv_index", szIndex);
                        if(szIndex.empty())
                            nIndex = FindIndexByID(szMonitorId);
                        else
                            nIndex = atoi(szIndex.c_str());
                        monitor.szIndex = szMonitorId;
                        monitor.szName = szName;

                        lsItem = sortList.find(nIndex);
                        while(lsItem != sortList.end())
                        {
                            nIndex ++;//= nMax;
                            lsItem = sortList.find(nIndex);
                        }
                        sortList[nIndex] = monitor;
                    }
                    CloseMonitor(objMonitor);
                }
            }
        }
        CloseEntity(objDevice);
    }
    string szShowText(""), szContent("");
    int nState = dyn_normal;
    bool bShowDevice = false;

    for(lsItem = sortList.begin(); lsItem != sortList.end(); lsItem ++)
    {
        // get monitor's current state
        nState = getMonitorState(lsItem->second.szIndex, szShowText);
        WImage *pMonitor = NULL;
        if(m_nShowType == -1 || m_nShowType == nState || 
            (m_nShowType == dyn_normal && nState == dyn_no_data) ||
            (m_nShowType == dyn_error && nState == dyn_bad))
        {
            bShowDevice = true;
            pMonitor = new WImage("/Images/state_green.gif", pTableCell);
        }
        if(pMonitor)
        {   
            // change show image by state
            switch(nState)
            {
            case dyn_no_data:
                pMonitor->setImageRef("/Images/state_grey.gif");
                break;
            case dyn_normal:
                pMonitor->setImageRef("/Images/state_green.gif");
                break;
            case dyn_warnning:
                pMonitor->setImageRef("/Images/state_yellow.gif");
                break;
            case dyn_error:
            case dyn_bad:
                pMonitor->setImageRef("/Images/state_red.gif");
                break;
            case dyn_disable:
                pMonitor->setImageRef("/Images/state_stop.gif");
                break;
            }

            // monitor's style && onclick event
            szContent = "style='cursor:pointer;' onclick = 'window.open(\"SimpleReport.exe?id=" + lsItem->second.szIndex + "\");'";
            sprintf(pMonitor->contextmenu_, szContent.c_str());
            pMonitor->setToolTip(szDeviceName + ":" + lsItem->second.szName + "\r\n" + szShowText);
        }
    }
    return bShowDevice;
}