#include "scolumn.h"
#include <QFile>

SColumn::SColumn() : m_bUse(false)
{
}

SColumn::~SColumn()
{
}

int SColumn::getColumnIndex(QString _str)
{
    int nIndex = 0;
    foreach(QStringList strList,m_vecColumn)
    {
        if (strList.at(E_DATABASE).trimmed() == _str.trimmed())
            return nIndex;
        if (strList.at(E_NAME).trimmed() == _str.trimmed())
            return nIndex;
        nIndex++;
    }
    return -1;
}


bool SColumn::reload()
{
    m_bUse = false;
    m_vecColumn.clear();
    QFile file("column.txt");
    if (file.open(QIODevice::ReadOnly | QIODevice::Text) == false) return m_bUse;
    {
        while (!file.atEnd())
        {
            QString str = QString(file.readLine());
            if (str.at(0) == QChar('#')) continue;
            if (str.trimmed().isEmpty()) continue;
            m_vecColumn.push_back(str.split(","));
        }
    }
    if (m_vecColumn.size() <= 0) return m_bUse;

    m_nDateColumn = -1;
    foreach(QStringList strList,m_vecColumn)
    {
        if (strList.at(E_DATE).trimmed() == QString("o"))
            break;
        else
            m_nDateColumn++;
    }
    m_nDateColumn++;
    m_bUse = true;
    return m_bUse;
}


