#include "limitupstocksmanager.h"
#include "db/xsqlexcute.h"
#include "db/xwholestocks.h"
#include "db/xwholestockindexs.h"
#include "db/xhighstocks.h"
#include "db/xhighstockindexs.h"
#include <QtDebug>
#include <QFileDialog>
#include "excel/xexcel.h"
#include "xexceltomysq.h"
#include "excel/stocksdecoder.h"
#include "db/stockssqlmanager.h"
#include "db/stockbasissqlmanager.h"
#include "excel/limitupstockdecoder.h"
#include "db/limitupstocksqlmanager.h"

LimitUpStocksManager::LimitUpStocksManager()
{

}

void LimitUpStocksManager::doExcute()
{
    decodeToMysql();
}

void LimitUpStocksManager::decodeToMysql()
{
    qDebug() << "LimitUpStocksManager decodeToMysql";
    XExcel excel;
    excel.openExcelCom();
    QList<QList<QVariant> > excelDatas = excel.readExcel(getDecodeFile());
    excel.closeExcelCom();

    QString cdate = getDataDate();
    //测试stocks
    LimitUpStockDecoder* decoder = new LimitUpStockDecoder;
    decoder->decode(excelDatas);
    QList<_limitUpStocksInfo> d = decoder->data;
    if(!d.isEmpty())
    {
        //插入到数据库
        LimitUpStockSqlManager* lusm = new LimitUpStockSqlManager;
        XSqlExcute* sqlIns = new XSqlExcute;
        sqlIns->openMysql("192.168.0.201","nstocks","admin","1qazse42W3","LimitUpStockSqlManager");
        sqlIns->transaction("LimitUpStockSqlManager");
        int count = d.count();
        for(int i = 0 ; i < count ; i++)
        {
            QString sql = lusm->toInsertSql(d[i]);
            qDebug() << sql;
            sqlIns->query(sql,"LimitUpStockSqlManager");
        }
        sqlIns->commit("LimitUpStockSqlManager");
        sqlIns->closeMysql();
        sqlIns->deleteLater();
    }
}

void LimitUpStocksManager::getDataFromMysql()
{

}
