Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
hydraulicModel
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
刘乐
hydraulicModel
Commits
7eeb415e
Commit
7eeb415e
authored
Jun 15, 2020
by
刘乐
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1, 模型改进
parent
49d41dc4
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
232 additions
and
248 deletions
+232
-248
CivHydrCalc.cpp
pandaAnalysis/CivHydrCalc.cpp
+10
-12
CivDbConnection.cpp
pandaDbManager/CivDbConnection.cpp
+203
-228
CivDbConnection.h
pandaDbManager/CivDbConnection.h
+14
-5
CivTableTemp.cpp
pandaDbManager/CivTableTemp.cpp
+2
-0
CivTypes.h
pandaDbManager/CivTypes.h
+3
-3
~$水力模型.docx
建模文档/~$水力模型.docx
+0
-0
水力模型.docx
建模文档/水力模型.docx
+0
-0
No files found.
pandaAnalysis/CivHydrCalc.cpp
View file @
7eeb415e
...
...
@@ -48,18 +48,20 @@ bool CivHydrCalc::hydrSimulation(char* fileName, char* rptFile, char* binOutFile
return
false
;
}
float
dHStep
;
ENGetVal
(
4
,
&
dHStep
);
// 计算
do
{
int
nLinkCount
;
ENgetcount
(
EN_LINKCOUNT
,
&
nLinkCount
);
for
(
int
i
=
1
;
i
<=
nLinkCount
;
i
++
)
/*
for (int i = 1; i <= nLinkCount; i++)
{
int linkType;
char id[128] = "";
ENgetlinktype(i, &linkType);
ENgetlinkid(i, id);
}
}
*/
if
(
ENrunH
(
&
t
)
>
100
)
// errcode > 100 是错误
{
...
...
@@ -67,15 +69,13 @@ bool CivHydrCalc::hydrSimulation(char* fileName, char* rptFile, char* binOutFile
return
false
;
}
ENnextH
(
&
tstep
);
iTime
++
;
// 获取当前节点和管段数据
getNodeResult
(
t
);
getLinkResult
(
t
);
getNodeResult
(
iTime
);
getLinkResult
(
iTime
);
iTime
++
;
}
while
(
tstep
>
0
);
// 获取计算结果
return
true
;
}
...
...
@@ -142,8 +142,6 @@ bool CivHydrCalc::exportInp(char* fileName)
void
CivHydrCalc
::
assemble
(
const
std
::
string
&
table
,
CivInp
&
inp
)
{
// 根据组建类型解析字段
if
(
PIPELINE
==
table
)
{
...
...
@@ -307,7 +305,7 @@ void CivHydrCalc::assemble(const std::string& table, CivInp& inp)
// 水池数据
CivItem
tankNode
;
tankNode
.
push_back
(
"P"
+
id
);
tankNode
.
push_back
(
id
);
tankNode
.
push_back
(
node1
);
tankNode
.
push_back
(
node2
);
...
...
@@ -391,7 +389,7 @@ void CivHydrCalc::assemble(const std::string& table, CivInp& inp)
// 阀门数据
CivItem
vavleNode
;
vavleNode
.
push_back
(
"V"
+
id
);
vavleNode
.
push_back
(
id
);
vavleNode
.
push_back
(
node1
);
vavleNode
.
push_back
(
node2
);
vavleNode
.
push_back
(
diametor
);
...
...
pandaDbManager/CivDbConnection.cpp
View file @
7eeb415e
...
...
@@ -2,6 +2,7 @@
#include "CivCommonUtils.h"
#include "CivTableTemp.h"
#include<iostream>
#include <sstream>
#define MAX_BUFFER 16384
...
...
@@ -22,21 +23,14 @@ bool CivDbConnection::tableExist(StrQuote tableName)
strcat_s
(
sql
,
tableName
.
c_str
());
strcat_s
(
sql
,
"'"
);
PGresult
*
result
=
PQexec
(
mConn
,
sql
);
if
(
result
==
NULL
)
if
(
!
execSql
(
sql
))
return
false
;
/* if (PQstatus(mConn) != PGRES_COMMAND_OK)
{
mLastError = PQresultErrorMessage(result);
PQclear(result);
return false;
}*/
char
*
res
=
PQgetvalue
(
result
,
0
,
0
);
char
*
res
=
PQgetvalue
(
mResult
,
0
,
0
);
PQclear
(
mResult
);
int
number
=
atoi
(
res
);
PQclear
(
result
);
bool
flag
=
number
>
0
?
true
:
false
;
return
flag
;
return
number
>
0
?
true
:
false
;
}
bool
CivDbConnection
::
open
()
...
...
@@ -62,7 +56,7 @@ void CivDbConnection::close()
mIsOpen
=
false
;
}
Tables
CivDbConnection
::
getTables
(
StrQuote
netName
,
StrQuote
schema
)
const
Tables
CivDbConnection
::
getTables
(
StrQuote
netName
,
StrQuote
schema
)
{
if
(
!
isValid
())
...
...
@@ -100,72 +94,67 @@ bool CivDbConnection::updateNode(const NodeResultItems& nodeItems)
if
(
createTable
(
"__node_result__"
,
"public"
,
NODE_TABLE
))
{
NodeFieldName
filedNames
;
char
sql
[
MAX_BUFFER
]
=
"INSERT INTO public.__node_result__ ( "
;
st
rcat_s
(
sql
,
filedNames
.
Number
.
c_str
())
;
strcat_s
(
sql
,
","
)
;
strcat_s
(
sql
,
filedNames
.
dDemand
.
c_str
())
;
strcat_s
(
sql
,
","
)
;
strcat_s
(
sql
,
filedNames
.
dFlow
.
c_str
())
;
strcat_s
(
sql
,
","
)
;
strcat_s
(
sql
,
filedNames
.
dHead
.
c_str
())
;
strcat_s
(
sql
,
","
)
;
strcat_s
(
sql
,
filedNames
.
dElevation
.
c_str
())
;
strcat_s
(
sql
,
","
)
;
strcat_s
(
sql
,
filedNames
.
dPressure
.
c_str
())
;
strcat_s
(
sql
,
","
)
;
strcat_s
(
sql
,
filedNames
.
dTankLevel
.
c_str
())
;
strcat_s
(
sql
,
","
)
;
strcat_s
(
sql
,
filedNames
.
dTankMaxVolume
.
c_str
())
;
strcat_s
(
sql
,
","
)
;
strcat_s
(
sql
,
filedNames
.
dTankVolume
.
c_str
())
;
strcat_s
(
sql
,
","
)
;
strcat_s
(
sql
,
filedNames
.
lTime
.
c_str
());
strcat_s
(
sql
,
") VALUES("
);
st
d
::
stringstream
os
;
os
<<
"INSERT INTO public.__node_result__ ( "
;
os
<<
filedNames
.
Number
;
os
<<
","
;
os
<<
filedNames
.
dDemand
;
os
<<
","
;
os
<<
filedNames
.
dHead
;
os
<<
","
;
os
<<
filedNames
.
dElevation
;
os
<<
","
;
os
<<
filedNames
.
dPressure
;
os
<<
","
;
os
<<
filedNames
.
dTankLevel
;
os
<<
","
;
os
<<
filedNames
.
dTankMaxVolume
;
os
<<
","
;
os
<<
filedNames
.
dTankVolume
;
/* os<< ","
;
os<< filedNames.lTime;*/
os
<<
") VALUES"
;
// 2, 参数值
in
t
total
=
nodeItems
.
size
();
size_
t
total
=
nodeItems
.
size
();
for
(
int
i
=
0
;
i
<
total
;
i
++
)
{
NodeResultItem
item
=
nodeItems
[
i
];
strcat_s
(
sql
,
item
.
szNo
);
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
std
::
to_string
(
item
.
dFlow
).
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
std
::
to_string
(
item
.
dHead
).
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
std
::
to_string
(
item
.
dElevation
).
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
std
::
to_string
(
item
.
dPressure
).
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
std
::
to_string
(
item
.
dTankLevel
).
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
std
::
to_string
(
item
.
dTankMaxVolume
).
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
std
::
to_string
(
item
.
dTankVolume
).
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
std
::
to_string
(
item
.
lTime
).
c_str
());
if
(
i
==
(
total
-
1
))
strcat_s
(
sql
,
")"
);
else
strcat_s
(
sql
,
"),"
);
}
std
::
string
sqlStr
(
sql
,
sql
+
strlen
(
sql
));
std
::
string
utf8Str
=
CivCommonUtils
::
string_To_UTF8
(
sqlStr
);
PGresult
*
result
=
PQexec
(
mConn
,
utf8Str
.
c_str
());
if
(
PQstatus
(
mConn
)
!=
PGRES_COMMAND_OK
)
// or conn==NULL
os
<<
"('"
<<
item
.
szNo
<<
"',"
;
os
<<
item
.
dDemand
;
os
<<
","
;
os
<<
item
.
dHead
;
os
<<
","
;
os
<<
item
.
dElevation
;
os
<<
","
;
os
<<
item
.
dPressure
;
os
<<
","
;
os
<<
item
.
dTankLevel
;
os
<<
","
;
os
<<
item
.
dTankMaxVolume
;
os
<<
","
;
os
<<
item
.
dTankVolume
;
/* os << ",";
os << item.lTime; */
if
(
i
==
(
total
-
1
))
{
mLastError
=
PQresultErrorMessage
(
result
);
PQclear
(
result
);
return
false
;
}
os
<<
")"
;
PQclear
(
result
);
}
else
{
os
<<
"),"
;
}
}
std
::
string
sql
=
os
.
str
();
os
.
clear
();
if
(
!
execSql
(
sql
))
return
false
;
}
// 2, 参数值
in
t
total
=
nodeItems
.
size
();
size_
t
total
=
nodeItems
.
size
();
for
(
int
i
=
0
;
i
<
total
;
i
++
)
{
NodeResultItem
item
=
nodeItems
[
i
];
...
...
@@ -192,19 +181,10 @@ bool CivDbConnection::updateNode(const NodeResultItems& nodeItems)
strcat_s
(
sql
,
item
.
szNo
);
strcat_s
(
sql
,
"'"
);
std
::
string
sqlStr
(
sql
,
sql
+
strlen
(
sql
));
std
::
string
utf8Str
=
CivCommonUtils
::
string_To_UTF8
(
sqlStr
);
PGresult
*
result
=
PQexec
(
mConn
,
utf8Str
.
c_str
());
if
(
PQstatus
(
mConn
)
!=
PGRES_COMMAND_OK
)
// or conn==NULL
{
mLastError
=
PQresultErrorMessage
(
result
);
continue
;
if
(
!
execSql
(
sql
))
return
false
;
}
PQclear
(
result
);
}
}
return
true
;
}
...
...
@@ -214,111 +194,96 @@ bool CivDbConnection::updateLink(const LinkResultItems& lineItems)
if
(
!
isValid
())
return
false
;
if
(
createTable
(
"__pipe_result__"
,
"public"
,
NODE_TABLE
))
std
::
stringstream
os
;
if
(
createTable
(
"__pipe_result__"
,
"public"
,
PIPE_TABLE
))
{
LinkFiledName
filedNames
;
char
sql
[
MAX_BUFFER
]
=
"INSERT INTO public.__pipe_result__ ( "
;
strcat_s
(
sql
,
filedNames
.
szNo
.
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
filedNames
.
dFlow
.
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
filedNames
.
nFlowDirect
.
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
filedNames
.
dVelocity
.
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
filedNames
.
dHeadloss
.
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
filedNames
.
dUnitHeadloss
.
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
filedNames
.
dFromNodHeadloss
.
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
filedNames
.
dToNodHeadloss
.
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
filedNames
.
dLocalHeadloss
.
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
filedNames
.
dFrictionHeadloss
.
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
filedNames
.
dLocalHeadloss
.
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
filedNames
.
szStatus
.
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
filedNames
.
lTime
.
c_str
());
strcat_s
(
sql
,
") VALUES("
);
os
<<
"INSERT INTO public.__pipe_result__( "
;
os
<<
filedNames
.
szNo
;
os
<<
","
;
os
<<
filedNames
.
dFlow
;
os
<<
","
;
/* os<< filedNames.nFlowDirect;
os<< ",";*/
os
<<
filedNames
.
dVelocity
;
os
<<
","
;
os
<<
filedNames
.
dHeadloss
;
os
<<
","
;
os
<<
filedNames
.
dUnitHeadloss
;
os
<<
","
;
os
<<
filedNames
.
dFromNodHeadloss
;
os
<<
","
;
os
<<
filedNames
.
dToNodHeadloss
;
os
<<
","
;
os
<<
filedNames
.
dLocalHeadloss
;
os
<<
","
;
os
<<
filedNames
.
dFrictionHeadloss
;
/*os<< ",";
os<< filedNames.szStatus;*/
/*os<< ",";
os<< filedNames.lTime;*/
os
<<
") VALUES"
;
// 2, 参数值
in
t
total
=
lineItems
.
size
();
size_
t
total
=
lineItems
.
size
();
for
(
int
i
=
0
;
i
<
total
;
i
++
)
{
LinkResultItem
item
=
lineItems
[
i
];
strcat_s
(
sql
,
item
.
szNo
);
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
std
::
to_string
(
item
.
dFlow
).
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
std
::
to_string
(
item
.
nFlowDirect
).
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
std
::
to_string
(
item
.
dVelocity
).
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
std
::
to_string
(
item
.
dHeadloss
).
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
std
::
to_string
(
item
.
dUnitHeadloss
).
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
std
::
to_string
(
item
.
dFromNodHeadloss
).
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
std
::
to_string
(
item
.
dToNodHeadloss
).
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
std
::
to_string
(
item
.
dLocalHeadloss
).
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
std
::
to_string
(
item
.
dFrictionHeadloss
).
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
std
::
to_string
(
item
.
dLocalHeadloss
).
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
item
.
szStatus
);
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
std
::
to_string
(
item
.
lTime
).
c_str
());
// 拼接值
strcat_s
(
sql
,
std
::
to_string
(
item
.
dFlow
).
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
std
::
to_string
(
item
.
dVelocity
).
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
std
::
to_string
(
item
.
dUnitHeadloss
).
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
std
::
to_string
(
item
.
dHeadloss
).
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
std
::
to_string
(
item
.
dFrictionHeadloss
).
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
std
::
to_string
(
item
.
dFromNodHeadloss
).
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
std
::
to_string
(
item
.
dToNodHeadloss
).
c_str
());
strcat_s
(
sql
,
","
);
strcat_s
(
sql
,
std
::
to_string
(
item
.
dLocalHeadloss
).
c_str
());
os
<<
"('"
<<
item
.
szNo
<<
"'"
;
os
<<
","
;
os
<<
item
.
dFlow
;
//os<< ",";
/* int direct = item.nFlowDirect;
os<< direct;*/
os
<<
","
;
os
<<
item
.
dVelocity
;
os
<<
","
;
os
<<
item
.
dHeadloss
;
os
<<
","
;
os
<<
item
.
dUnitHeadloss
;
os
<<
","
;
os
<<
item
.
dFromNodHeadloss
;
os
<<
","
;
os
<<
item
.
dToNodHeadloss
;
os
<<
","
;
os
<<
item
.
dLocalHeadloss
;
os
<<
","
;
os
<<
item
.
dFrictionHeadloss
;
/*os<< ",";
os<< "'"<<item.szStatus<<"'";*/
/*os<< ",";
os<< item.lTime;*/
if
(
i
==
(
total
-
1
))
strcat_s
(
sql
,
")"
)
;
os
<<
")"
;
else
strcat_s
(
sql
,
"),"
)
;
os
<<
"),"
;
}
std
::
string
sqlStr
(
sql
,
sql
+
strlen
(
sql
));
std
::
string
utf8Str
=
CivCommonUtils
::
string_To_UTF8
(
sqlStr
);
PGresult
*
result
=
PQexec
(
mConn
,
utf8Str
.
c_str
());
if
(
PQstatus
(
mConn
)
!=
PGRES_COMMAND_OK
)
{
mLastError
=
PQresultErrorMessage
(
result
);
std
::
string
sql
=
os
.
str
();
os
.
clear
();
if
(
!
execSql
(
sql
))
return
false
;
}
PQclear
(
result
);
}
else
{
// 2, 参数值
int
total
=
lineItems
.
size
();
size_t
total
=
lineItems
.
size
();
/*
update
表一
set
表一的字段 = 表2的字段
from
表一,
表二
where
表一.Id = 表二.Id
*/
std
::
string
sql
=
"update public.管段 as tb1 set("
;
for
(
int
i
=
0
;
i
<
total
;
i
++
)
{
LinkResultItem
item
=
lineItems
[
i
];
char
sql
[
512
]
=
"update public."
;
strcat_s
(
sql
,
"管段"
);
strcat_s
(
sql
,
" as tb1 set("
);
char
sql
[
512
]
=
"update public.管段 as tb1 set("
;
strcat_s
(
sql
,
"流量"
);
strcat_s
(
sql
,
",流速"
);
strcat_s
(
sql
,
",单位水头损"
);
...
...
@@ -352,44 +317,37 @@ bool CivDbConnection::updateLink(const LinkResultItems& lineItems)
strcat_s
(
sql
,
item
.
szNo
);
strcat_s
(
sql
,
"'"
);
std
::
string
sqlStr
(
sql
,
sql
+
strlen
(
sql
));
std
::
string
utf8Str
=
CivCommonUtils
::
string_To_UTF8
(
sqlStr
);
PGresult
*
result
=
PQexec
(
mConn
,
utf8Str
.
c_str
());
PQstatus
(
mConn
);
if
(
PQstatus
(
mConn
)
!=
PGRES_COMMAND_OK
)
// or conn==NULL
{
mLastError
=
PQresultErrorMessage
(
result
);
continue
;
}
PQclear
(
result
);
if
(
!
execSql
(
sql
))
return
false
;
}
}
return
true
;
}
Componets
CivDbConnection
::
getComponets
(
StrQuote
tableName
)
const
Componets
CivDbConnection
::
getComponets
(
StrQuote
tableName
)
{
if
(
!
isValid
())
return
Nodes
();
std
::
string
sql
=
"select * from public.
\"
"
+
tableName
+
"
\"
"
;
std
::
string
utf8Str
=
CivCommonUtils
::
string_To_UTF8
(
sql
);
PGresult
*
result
=
PQexec
(
mConn
,
utf8Str
.
c_str
());
if
(
result
==
NULL
)
if
(
!
execSql
(
sql
))
{
return
Nodes
();
}
Componets
nodes
;
// 取数据到容器中
getData
(
r
esult
,
nodes
);
getData
(
mR
esult
,
nodes
);
PQclear
(
result
);
return
nodes
;
}
void
CivDbConnection
::
getData
(
PGresult
*
result
,
Componets
&
comp
)
const
void
CivDbConnection
::
getData
(
PGresult
*
result
,
Componets
&
comp
)
{
if
(
result
==
NULL
)
return
;
int
rows
=
PQntuples
(
result
);
int
columns
=
PQnfields
(
result
);
for
(
int
i
=
0
;
i
<
rows
;
i
++
)
...
...
@@ -407,10 +365,10 @@ void CivDbConnection::getData(PGresult* result, Componets& comp) const
}
comp
.
push_back
(
node
);
}
PQclear
(
result
);
}
Componets
CivDbConnection
::
getNodeByCode
(
StrQuote
table
,
StrQuote
code
)
const
Componets
CivDbConnection
::
getNodeByCode
(
StrQuote
table
,
StrQuote
code
)
{
if
(
!
isValid
())
return
Nodes
();
...
...
@@ -422,22 +380,18 @@ Componets CivDbConnection::getNodeByCode(StrQuote table, StrQuote code) const
strcat_s
(
sql
,
code
.
c_str
());
strcat_s
(
sql
,
"'"
);
std
::
string
utfStr
=
CivCommonUtils
::
string_To_UTF8
(
sql
);
PGresult
*
result
=
PQexec
(
mConn
,
utfStr
.
c_str
());
if
(
result
==
NULL
)
if
(
!
execSql
(
sql
))
{
return
Nodes
();
}
Componets
componets
;
getData
(
result
,
componets
);
PQclear
(
result
);
getData
(
mResult
,
componets
);
return
componets
;
}
Componets
CivDbConnection
::
getLineByCode
(
StrQuote
table
,
StrQuote
code
)
const
Componets
CivDbConnection
::
getLineByCode
(
StrQuote
table
,
StrQuote
code
)
{
if
(
!
isValid
())
return
Nodes
();
...
...
@@ -451,18 +405,15 @@ Componets CivDbConnection::getLineByCode(StrQuote table, StrQuote code) const
strcat_s
(
sql
,
code
.
c_str
());
strcat_s
(
sql
,
"'"
);
std
::
string
utfStr
=
CivCommonUtils
::
string_To_UTF8
(
sql
);
PGresult
*
result
=
PQexec
(
mConn
,
utfStr
.
c_str
());
if
(
result
==
NULL
)
if
(
!
execSql
(
sql
))
{
return
Nodes
();
}
Componets
componets
;
getData
(
r
esult
,
componets
);
getData
(
mR
esult
,
componets
);
PQclear
(
result
);
return
componets
;
}
...
...
@@ -476,16 +427,14 @@ Componets CivDbConnection::getLikelyPipes(StrQuote tableName)
strcat_s
(
sql
,
tableName
.
c_str
());
strcat_s
(
sql
,
"
\"
"
);
std
::
string
utfStr
=
CivCommonUtils
::
string_To_UTF8
(
sql
);
PGresult
*
result
=
PQexec
(
mConn
,
utfStr
.
c_str
());
if
(
result
==
NULL
)
if
(
!
execSql
(
sql
))
{
return
Componets
();
}
Componets
nodes
;
getData
(
r
esult
,
nodes
);
PQclear
(
result
);
getData
(
mR
esult
,
nodes
);
// 查询线表
if
(
nodes
.
size
()
<=
0
)
...
...
@@ -525,15 +474,28 @@ Componets CivDbConnection::getLikelyPipes(StrQuote tableName)
// 根据点数据查询起点和终点,管径
in
t
total
=
nodes
.
size
();
size_
t
total
=
nodes
.
size
();
for
(
int
i
=
0
;
i
<
total
;
i
++
)
{
Componet
componet
=
nodes
[
i
];
nodes
[
i
][
"编号"
]
=
componet
.
find
(
"id"
)
->
second
;
Str
bendianhao
=
componet
.
find
(
"本点号"
)
->
second
;
if
(
bendianhao
.
empty
()
||
bendianhao
==
""
)
{
Str
ID
=
componet
.
find
(
"id"
)
->
second
;
Str
type
=
mValvesMap
.
find
(
tableName
)
->
second
;
Str
newbendian
=
type
+
ID
;
std
::
string
upSql
=
"Update "
+
tableName
+
" Set 本点号 ='"
+
newbendian
+
"' Where id ='"
+
ID
+
"'"
;
execSql
(
upSql
);
nodes
[
i
][
"编号"
]
=
newbendian
;
}
else
{
nodes
[
i
][
"编号"
]
=
bendianhao
;
}
Str
code
=
componet
.
find
(
"code"
)
->
second
;
Componets
lines
=
getLineByCode
(
PIPELINE
,
code
);
in
t
lTotal
=
lines
.
size
();
size_
t
lTotal
=
lines
.
size
();
for
(
int
j
=
0
;
j
<
lTotal
;
j
++
)
{
...
...
@@ -546,7 +508,7 @@ Componets CivDbConnection::getLikelyPipes(StrQuote tableName)
if
(
fromCode
==
code
)
{
in
t
size
=
tables
.
size
();
size_
t
size
=
tables
.
size
();
for
(
int
i
=
0
;
i
<
size
;
i
++
)
{
codeNodes
=
getNodeByCode
(
tables
[
i
],
toCode
);
...
...
@@ -563,7 +525,7 @@ Componets CivDbConnection::getLikelyPipes(StrQuote tableName)
}
else
if
(
toCode
==
code
)
{
in
t
size
=
tables
.
size
();
size_
t
size
=
tables
.
size
();
Str
currTable
;
for
(
int
i
=
0
;
i
<
size
;
i
++
)
{
...
...
@@ -632,7 +594,7 @@ bool CivDbConnection::createTable(StrQuote tableName, StrQuote schema,TableType
return
true
;
CivTableTemp
tableTemp
(
tableName
);
LinkFiledName
pipeFileds
;
switch
(
tableType
)
{
case
NODE_TABLE
:
...
...
@@ -647,40 +609,52 @@ bool CivDbConnection::createTable(StrQuote tableName, StrQuote schema,TableType
tableTemp
.
addProperty
(
"液位高度"
,
CivTableTemp
::
FILED_DOUBLE
);
tableTemp
.
addProperty
(
"水质"
,
CivTableTemp
::
FILED_DOUBLE
);
tableTemp
.
addProperty
(
"时间"
,
CivTableTemp
::
FILED_DATETIME
);
break
;
case
PIPE_TABLE
:
tableTemp
.
addProperty
(
"编号"
,
CivTableTemp
::
FILED_VARCHAR
);
tableTemp
.
addProperty
(
"流量"
,
CivTableTemp
::
FILED_DOUBLE
);
tableTemp
.
addProperty
(
"流向"
,
CivTableTemp
::
FILED_INT
);
tableTemp
.
addProperty
(
"流速"
,
CivTableTemp
::
FILED_DOUBLE
);
tableTemp
.
addProperty
(
"水头损失"
,
CivTableTemp
::
FILED_DOUBLE
);
tableTemp
.
addProperty
(
"单位水头损失"
,
CivTableTemp
::
FILED_DOUBLE
);
tableTemp
.
addProperty
(
"上点水头"
,
CivTableTemp
::
FILED_DOUBLE
);
tableTemp
.
addProperty
(
"本点水头"
,
CivTableTemp
::
FILED_DOUBLE
);
tableTemp
.
addProperty
(
"局部水头损失"
,
CivTableTemp
::
FILED_DOUBLE
);
tableTemp
.
addProperty
(
"摩擦水头损失"
,
CivTableTemp
::
FILED_DOUBLE
);
tableTemp
.
addProperty
(
"状态"
,
CivTableTemp
::
FILED_VARCHAR
);
tableTemp
.
addProperty
(
"水质"
,
CivTableTemp
::
FILED_DOUBLE
);
tableTemp
.
addProperty
(
pipeFileds
.
szNo
,
CivTableTemp
::
FILED_VARCHAR
);
tableTemp
.
addProperty
(
pipeFileds
.
dFlow
,
CivTableTemp
::
FILED_DOUBLE
);
tableTemp
.
addProperty
(
pipeFileds
.
nFlowDirect
,
CivTableTemp
::
FILED_INT
);
tableTemp
.
addProperty
(
pipeFileds
.
dVelocity
,
CivTableTemp
::
FILED_DOUBLE
);
tableTemp
.
addProperty
(
pipeFileds
.
dHeadloss
,
CivTableTemp
::
FILED_DOUBLE
);
tableTemp
.
addProperty
(
pipeFileds
.
dUnitHeadloss
,
CivTableTemp
::
FILED_DOUBLE
);
tableTemp
.
addProperty
(
pipeFileds
.
dFromNodHeadloss
,
CivTableTemp
::
FILED_DOUBLE
);
tableTemp
.
addProperty
(
pipeFileds
.
dToNodHeadloss
,
CivTableTemp
::
FILED_DOUBLE
);
tableTemp
.
addProperty
(
pipeFileds
.
dLocalHeadloss
,
CivTableTemp
::
FILED_DOUBLE
);
tableTemp
.
addProperty
(
pipeFileds
.
dFrictionHeadloss
,
CivTableTemp
::
FILED_DOUBLE
);
tableTemp
.
addProperty
(
pipeFileds
.
szStatus
,
CivTableTemp
::
FILED_VARCHAR
);
tableTemp
.
addProperty
(
"水质"
,
CivTableTemp
::
FILED_DOUBLE
);
tableTemp
.
addProperty
(
"时间"
,
CivTableTemp
::
FILED_DATETIME
);
break
;
default
:
break
;
}
std
::
string
sql
=
tableTemp
.
createSql
();
return
execSql
(
sql
);
}
bool
CivDbConnection
::
execSql
(
std
::
string
sql
)
{
if
(
sql
==
""
||
sql
.
empty
())
return
false
;
std
::
string
sqlStr
=
CivCommonUtils
::
string_To_UTF8
(
sql
);
const
char
*
finalSql
=
sqlStr
.
c_str
();
PGresult
*
result
=
PQexec
(
mConn
,
finalSql
);
if
(
PQstatus
(
mConn
)
!=
PGRES_COMMAND_OK
)
mResult
=
PQexec
(
mConn
,
finalSql
);
if
(
PQstatus
(
mConn
)
==
PGRES_BAD_RESPONSE
)
{
mLastError
=
PQresultErrorMessage
(
result
);
std
::
cout
<<
mLastError
<<
std
::
endl
;
PQclear
(
result
);
mLastError
=
PQresultErrorMessage
(
mResult
);
PQclear
(
mResult
);
return
false
;
}
PQclear
(
r
esult
);
mLastError
=
PQresultErrorMessage
(
mR
esult
);
return
true
;
}
void
CivDbConnection
::
clearResult
()
{
PQclear
(
mResult
);
}
\ No newline at end of file
pandaDbManager/CivDbConnection.h
View file @
7eeb415e
...
...
@@ -30,13 +30,13 @@ public:
*@brief 获取管网的所有表
*@netName: 管网名
*/
Tables
getTables
(
StrQuote
netName
,
StrQuote
schema
=
"public"
)
const
;
Tables
getTables
(
StrQuote
netName
,
StrQuote
schema
=
"public"
);
/**
*@brief 获取管网组件数据:管线,节点,水源等(必须组件)
*@tableName: 组件表
*/
Componets
getComponets
(
StrQuote
tableName
)
const
;
Componets
getComponets
(
StrQuote
tableName
);
/**
*@brief 水泵,阀门 (节点转换为管线)
...
...
@@ -81,19 +81,28 @@ private:
*@table: 线表
*@code:
*/
Componets
getLineByCode
(
StrQuote
table
,
StrQuote
code
)
const
;
Componets
getLineByCode
(
StrQuote
table
,
StrQuote
code
);
Componets
getNodeByCode
(
StrQuote
table
,
StrQuote
code
)
const
;
Componets
getNodeByCode
(
StrQuote
table
,
StrQuote
code
);
/**
*@brief 执行sql语句
*@sql: 需要执行的sql语句
*/
bool
execSql
(
std
::
string
sql
);
void
clearResult
();
/**
*@brief 从查询集取出数据
*@result: 查询结果集
*@comp: 数据容器
*/
void
getData
(
PGresult
*
result
,
Componets
&
comp
)
const
;
void
getData
(
PGresult
*
result
,
Componets
&
comp
);
private
:
PGconn
*
mConn
;
PGresult
*
mResult
;
bool
mIsOpen
=
false
;
char
*
mUri
;
...
...
pandaDbManager/CivTableTemp.cpp
View file @
7eeb415e
#include "CivTableTemp.h"
#include <fstream>
CivTableTemp
::
CivTableTemp
(
std
::
string
tableName
)
:
mTableName
(
tableName
)
...
...
@@ -32,6 +33,7 @@ std::string CivTableTemp::createSql()
if
(
mPropertys
.
size
()
<=
0
)
return
""
;
char
sql
[
512
]
=
"create table "
;
strcat_s
(
sql
,
mTableName
.
c_str
());
strcat_s
(
sql
,
"(id serial primary key"
);
...
...
pandaDbManager/CivTypes.h
View file @
7eeb415e
...
...
@@ -179,11 +179,11 @@ struct LinkFiledName
Str
nFlowDirect
=
"流向"
;
Str
dVelocity
=
"流速"
;
Str
dHeadloss
=
"水头损失"
;
Str
dUnitHeadloss
=
"单位水头损
失
"
;
Str
dUnitHeadloss
=
"单位水头损"
;
Str
dFromNodHeadloss
=
"上点水头"
;
Str
dToNodHeadloss
=
"本点水头"
;
Str
dLocalHeadloss
=
"局部水头损
失
"
;
Str
dFrictionHeadloss
=
"摩擦水头损
失
"
;
Str
dLocalHeadloss
=
"局部水头损"
;
Str
dFrictionHeadloss
=
"摩擦水头损"
;
Str
szStatus
=
"状态"
;
Str
lTime
=
"时间"
;
};
...
...
建模文档/~$水力模型.docx
View file @
7eeb415e
No preview for this file type
建模文档/水力模型.docx
View file @
7eeb415e
No preview for this file type
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment