Commit 7a7924a1 authored by 刘乐's avatar 刘乐

inp

parent 06584466
......@@ -229,12 +229,12 @@ bool CivHydrCalc::qualitySimulation(char* inpFile, char* rptFile, char* binOutFi
bool CivHydrCalc::exportInp(char* fileName)
{
//1 ,获取管网组件
if (!mDbConn)
return false;
////1 ,获取管网组件
//if (!mDbConn)
// return false;
if (!mDbConn->open())
return false;
//if (!mDbConn->open())
// return false;
CivBuilder* builder = new CivInpBuilder();
builder->registDb(mPgConn);
......
......@@ -4,6 +4,11 @@
bool CivNewInp::writeToFile(char* fileName)
{
// 检查是否存在值
std::string res = mTextStream.str();
if (res.empty())
return false;
std::ofstream outFile(fileName);
if (!outFile)
{
......@@ -13,7 +18,7 @@ bool CivNewInp::writeToFile(char* fileName)
}
else
{
outFile <<mTextStream.str();
outFile << res;
outFile.close();
mTextStream.clear();
mTextStream.str("");
......@@ -50,7 +55,11 @@ std::string CivNewInp::currentTime()
void CivNewInp::setNode(const CivNode& node)
{
auto tables = node.mTables;
if (tables.size() <= 0)
return;
writeHead("JUNCTIONS");
for (auto iter = tables.rbegin(); iter != tables.rend(); iter++)
{
......@@ -66,6 +75,9 @@ void CivNewInp::setNode(const CivNode& node)
void CivNewInp::setPipes(const CivPipe& pipes)
{
auto tables = pipes.mTables;
if (tables.size() <= 0)
return;
writeHead("PIPES");
for (auto iter = tables.rbegin(); iter != tables.rend(); iter++)
{
......
......@@ -62,6 +62,7 @@ private:
void inline writeStringFormat(const std::string& s, const std::string& sep="\t");
void inline writeHead(const std::string& head);
std::string currentTime();
private:
std::ostringstream mTextStream;
};
......
......@@ -34,6 +34,8 @@ void CivPgConn::close()
bool CivPgConn::tableExist(StrQuote tableName)
{
char sql[256] = "select count(*) from pg_class where relname = '";
strcat_s(sql, tableName.c_str());
strcat_s(sql, "'");
......@@ -50,10 +52,10 @@ bool CivPgConn::tableExist(StrQuote tableName)
bool CivPgConn::execSql(Str sql)
{
if (mConn == nullptr)
if (sql.empty())
return false;
if (sql.empty())
if (!open())
return false;
mResult = PQexec(mConn, sql.c_str());
......@@ -100,7 +102,7 @@ bool CivPgConn::getNode(CivNode& node)
nodeTable.PatternId = PQgetvalue(mResult, i, 3);
node.addItem(nodeTable);
}
PQclear(mResult);
PQclear(mResult);
return true;
}
......@@ -376,7 +378,7 @@ bool CivPgConn::getParameter(std::vector<CivParameter>& params)
pTable.name = PQgetvalue(mResult, i, 0);
pTable.val = PQgetvalue(mResult, i, 1);
char* type = PQgetvalue(mResult, i, 1);
char* type = PQgetvalue(mResult, i, 2);
tempMap[type].push_back(pTable);
}
// 遍历临时存储的数据拼接参数对象
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment