#include "CivHydrFuncInter.h"
#include "CivHydrCalc.h"
#include "CivSysLog.h"

bool DLLEXPORT simulation(char* uri, char* netName, char* flag)
{

    char fileName[256];
    char rptR[256];
    char outBinFile[256];

    strcpy_s(fileName, "test.inp");
    strcpy_s(rptR, "test.rpt");
    strcpy_s(outBinFile, "test.bin");

    CivHydrCalc* calc = new CivHydrCalc(uri, netName);
    CivSysLog::getInstance()->info("开始", "interface", __FUNCTION__);
    bool msg = false;
    if (strcmp(flag,"HDY")==0)
        msg = calc->hydrSimulation( fileName, rptR, outBinFile);
    else if(strcmp(flag, "QUALITY")==0)
        msg = calc->qualitySimulation(fileName, rptR, outBinFile);

    if (msg)
    {
        CivSysLog::getInstance()->info("成功", "interface", __FUNCTION__);
    }       
    else
    {
        CivSysLog::getInstance()->info("失败", "interface", __FUNCTION__);
    }
    delete calc;
    return msg;
}


bool DLLEXPORT hdySimulation(char* uri, char* netName)
{
    return true;
}

//bool DLLEXPORT qualitySimulation(char* uri, char* netName, char* type)
//{
//    return true;
//}

bool DLLEXPORT qualityTrackingSimulation(char* uri, char* netName, char* nodeSn, char* time)
{


    return true;
}

bool DLLEXPORT getDataByInterval(char* uri, char* date, char* interval)
{

    CivHydrCalc* calc = new CivHydrCalc(uri, "");
    char inp[128];
    strcpy(inp, "test.inp");
    bool flag = calc->exportInp(inp);
    std::cout << flag << std::endl;
     //flag = calc->getDataByInterval(date, interval);
    delete calc;
    return flag;
}
#include "CivPgConn.h"
#include "CivHydrSimulation.h"

bool DLLEXPORT hdyrSimulation(char* uri)
{
    // 创建数据库连接
    CivDbConn* pgConn = new CivPgConn(uri);

    // 模拟计算对象
    CivHydrSimulation* mHyDr = new CivHydrSimulation(pgConn);
   
    //开始模拟
    int flag = mHyDr->hdyrSimulation();

    delete mHyDr;
    delete pgConn;
   
    return flag;
}

bool DLLEXPORT qualitySimulation(char* uri)
{
    // 创建数据库连接
    CivDbConn* pgConn = new CivPgConn(uri);

    // 模拟计算对象
    CivHydrSimulation* mHyDr = new CivHydrSimulation();
    mHyDr->registDb(pgConn);

    //开始模拟
    int flag = mHyDr->qualitySimulation();

    delete pgConn;
    delete mHyDr;

    return flag;
}

bool  DLLEXPORT trackingSimulation(char* uri, char* sN, int hours, char* result)
{

    // 创建数据库连接
    CivDbConn* pgConn = new CivPgConn(uri);

    // 模拟计算对象
    CivHydrSimulation* mHyDr = new CivHydrSimulation();
    mHyDr->registDb(pgConn);

    //开始模拟
    bool flag = mHyDr->trackingSimulation(sN, hours);
    if (flag)
    {
        std::string strResult;
        mHyDr->getTrackingResult(hours, strResult);
        result = const_cast<char*>(strResult.c_str());
    }
    std::cout << result << std::endl;
    delete pgConn;
    delete mHyDr;

    return flag;
}