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

inp

parent 06584466
...@@ -229,12 +229,12 @@ bool CivHydrCalc::qualitySimulation(char* inpFile, char* rptFile, char* binOutFi ...@@ -229,12 +229,12 @@ bool CivHydrCalc::qualitySimulation(char* inpFile, char* rptFile, char* binOutFi
bool CivHydrCalc::exportInp(char* fileName) bool CivHydrCalc::exportInp(char* fileName)
{ {
//1 ,获取管网组件 ////1 ,获取管网组件
if (!mDbConn) //if (!mDbConn)
return false; // return false;
if (!mDbConn->open()) //if (!mDbConn->open())
return false; // return false;
CivBuilder* builder = new CivInpBuilder(); CivBuilder* builder = new CivInpBuilder();
builder->registDb(mPgConn); builder->registDb(mPgConn);
......
...@@ -4,6 +4,11 @@ ...@@ -4,6 +4,11 @@
bool CivNewInp::writeToFile(char* fileName) bool CivNewInp::writeToFile(char* fileName)
{ {
// 检查是否存在值
std::string res = mTextStream.str();
if (res.empty())
return false;
std::ofstream outFile(fileName); std::ofstream outFile(fileName);
if (!outFile) if (!outFile)
{ {
...@@ -13,7 +18,7 @@ bool CivNewInp::writeToFile(char* fileName) ...@@ -13,7 +18,7 @@ bool CivNewInp::writeToFile(char* fileName)
} }
else else
{ {
outFile <<mTextStream.str(); outFile << res;
outFile.close(); outFile.close();
mTextStream.clear(); mTextStream.clear();
mTextStream.str(""); mTextStream.str("");
...@@ -50,7 +55,11 @@ std::string CivNewInp::currentTime() ...@@ -50,7 +55,11 @@ std::string CivNewInp::currentTime()
void CivNewInp::setNode(const CivNode& node) void CivNewInp::setNode(const CivNode& node)
{ {
auto tables = node.mTables; auto tables = node.mTables;
if (tables.size() <= 0)
return;
writeHead("JUNCTIONS"); writeHead("JUNCTIONS");
for (auto iter = tables.rbegin(); iter != tables.rend(); iter++) for (auto iter = tables.rbegin(); iter != tables.rend(); iter++)
{ {
...@@ -66,6 +75,9 @@ void CivNewInp::setNode(const CivNode& node) ...@@ -66,6 +75,9 @@ void CivNewInp::setNode(const CivNode& node)
void CivNewInp::setPipes(const CivPipe& pipes) void CivNewInp::setPipes(const CivPipe& pipes)
{ {
auto tables = pipes.mTables; auto tables = pipes.mTables;
if (tables.size() <= 0)
return;
writeHead("PIPES"); writeHead("PIPES");
for (auto iter = tables.rbegin(); iter != tables.rend(); iter++) for (auto iter = tables.rbegin(); iter != tables.rend(); iter++)
{ {
......
...@@ -62,6 +62,7 @@ private: ...@@ -62,6 +62,7 @@ private:
void inline writeStringFormat(const std::string& s, const std::string& sep="\t"); void inline writeStringFormat(const std::string& s, const std::string& sep="\t");
void inline writeHead(const std::string& head); void inline writeHead(const std::string& head);
std::string currentTime(); std::string currentTime();
private: private:
std::ostringstream mTextStream; std::ostringstream mTextStream;
}; };
......
...@@ -34,6 +34,8 @@ void CivPgConn::close() ...@@ -34,6 +34,8 @@ void CivPgConn::close()
bool CivPgConn::tableExist(StrQuote tableName) bool CivPgConn::tableExist(StrQuote tableName)
{ {
char sql[256] = "select count(*) from pg_class where relname = '"; char sql[256] = "select count(*) from pg_class where relname = '";
strcat_s(sql, tableName.c_str()); strcat_s(sql, tableName.c_str());
strcat_s(sql, "'"); strcat_s(sql, "'");
...@@ -50,10 +52,10 @@ bool CivPgConn::tableExist(StrQuote tableName) ...@@ -50,10 +52,10 @@ bool CivPgConn::tableExist(StrQuote tableName)
bool CivPgConn::execSql(Str sql) bool CivPgConn::execSql(Str sql)
{ {
if (mConn == nullptr) if (sql.empty())
return false; return false;
if (sql.empty()) if (!open())
return false; return false;
mResult = PQexec(mConn, sql.c_str()); mResult = PQexec(mConn, sql.c_str());
...@@ -100,7 +102,7 @@ bool CivPgConn::getNode(CivNode& node) ...@@ -100,7 +102,7 @@ bool CivPgConn::getNode(CivNode& node)
nodeTable.PatternId = PQgetvalue(mResult, i, 3); nodeTable.PatternId = PQgetvalue(mResult, i, 3);
node.addItem(nodeTable); node.addItem(nodeTable);
} }
PQclear(mResult); PQclear(mResult);
return true; return true;
} }
...@@ -376,7 +378,7 @@ bool CivPgConn::getParameter(std::vector<CivParameter>& params) ...@@ -376,7 +378,7 @@ bool CivPgConn::getParameter(std::vector<CivParameter>& params)
pTable.name = PQgetvalue(mResult, i, 0); pTable.name = PQgetvalue(mResult, i, 0);
pTable.val = PQgetvalue(mResult, i, 1); pTable.val = PQgetvalue(mResult, i, 1);
char* type = PQgetvalue(mResult, i, 1); char* type = PQgetvalue(mResult, i, 2);
tempMap[type].push_back(pTable); 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