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

1,水力模型水质模拟

parent 6f8296c6
...@@ -49,7 +49,7 @@ ...@@ -49,7 +49,7 @@
<ConfigurationType>DynamicLibrary</ConfigurationType> <ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset> <PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>false</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet> <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
...@@ -142,13 +142,14 @@ copy epanet2.h $(OutDir)..\include /y</Command> ...@@ -142,13 +142,14 @@ copy epanet2.h $(OutDir)..\include /y</Command>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions> <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<Optimization>Disabled</Optimization> <Optimization>MaxSpeed</Optimization>
<WholeProgramOptimization>true</WholeProgramOptimization>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding> <EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>false</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories> <AdditionalLibraryDirectories>
</AdditionalLibraryDirectories> </AdditionalLibraryDirectories>
<ImportLibrary>$(OutDir)..\lib\$(TargetName).lib</ImportLibrary> <ImportLibrary>$(OutDir)..\lib\$(TargetName).lib</ImportLibrary>
......
...@@ -21,17 +21,17 @@ int main(int argc, char* argv[]) ...@@ -21,17 +21,17 @@ int main(int argc, char* argv[])
const char netName[128] = "水力模型管网"; const char netName[128] = "水力模型管网";
strcpy_s(net, "水力模型管网"); strcpy_s(net, "水力模型管网");
strcpy_s(flag, "HDY"); strcpy_s(flag, "QUALITY");
//bool msg = simulation(findUri, net, flag); bool msg = simulation(findUri, net, flag);
// std::cout << msg << std::endl; std::cout << msg << std::endl;
getchar();
const char* date = "2020-06-19"; /* const char* date = "2020-06-19";
char* dates = const_cast<char*>(date); char* dates = const_cast<char*>(date);
const char* interval = "0"; const char* interval = "0";
char* intervals = const_cast<char*>(interval); char* intervals = const_cast<char*>(interval);
getDataByInterval(findUri, dates, intervals); getDataByInterval(findUri, dates, intervals);*/
// std::cout << flag << std::endl; // std::cout << flag << std::endl;
return 0; return 0;
......
...@@ -12,7 +12,7 @@ void CivNode::addItem(NodeTable table) ...@@ -12,7 +12,7 @@ void CivNode::addItem(NodeTable table)
void CivNode::addItems(std::list<NodeTable> tables) void CivNode::addItems(std::list<NodeTable> tables)
{ {
//mTables.merge(tables); // mTables.merge(tables);
} }
void CivPipe::addItem(PipesTable table) void CivPipe::addItem(PipesTable table)
......
...@@ -10,6 +10,10 @@ class CivTank; ...@@ -10,6 +10,10 @@ class CivTank;
class CivValve; class CivValve;
class CivPumps; class CivPumps;
class CivEmitters; class CivEmitters;
class CivCoordinates;
class CivMixing;
class CivLabels;
class CivTags;
/** /**
管网基本组件 管网基本组件
......
...@@ -386,37 +386,37 @@ void CivInpBuilder::builder(StrQuote table, CivInp& inp) ...@@ -386,37 +386,37 @@ void CivInpBuilder::builder(StrQuote table, CivInp& inp)
} }
} }
void CivInpBuilder::builderNode() void CivInpBuilder::buildNode()
{ {
mDbConn->getComponets(PIPENODE);
} }
void CivInpBuilder::builderPipe() void CivInpBuilder::buildPipe()
{ {
} }
void CivInpBuilder::builderTank() void CivInpBuilder::buildTank()
{ {
} }
void CivInpBuilder::builderVavle() void CivInpBuilder::buildVavle()
{ {
} }
void CivInpBuilder::builderPump() void CivInpBuilder::buildPump()
{ {
} }
void CivInpBuilder::builderReservoir() void CivInpBuilder::buildReservoir()
{ {
} }
void CivInpBuilder::builderEmitter() void CivInpBuilder::buildEmitter()
{ {
} }
...@@ -425,3 +425,79 @@ CivNewInp* CivInpBuilder::getNewInp() ...@@ -425,3 +425,79 @@ CivNewInp* CivInpBuilder::getNewInp()
{ {
} }
void CivInpBuilder::buildPatterns()
{
}
void CivInpBuilder::buildParamter()
{
}
void CivInpBuilder::buildCoordnates()
{
}
void CivInpBuilder::buildVertices()
{
}
void CivInpBuilder::buildLabels()
{
}
void CivInpBuilder::buildTags()
{
}
void CivInpBuilder::buildBackDrop()
{
}
void CivInpBuilder::buildQuality()
{
}
void CivInpBuilder::buildSources()
{
}
void CivInpBuilder::buildMixing()
{
}
void CivInpBuilder::buildCurves()
{
}
void CivInpBuilder::buildStatus()
{
}
void CivInpBuilder::buildControls()
{
}
void CivInpBuilder::buildRules()
{
}
void CivInpBuilder::buildDemands()
{
}
\ No newline at end of file
...@@ -10,13 +10,29 @@ ...@@ -10,13 +10,29 @@
class CivBuilder class CivBuilder
{ {
public: public:
virtual void builderNode() = 0; virtual void buildNode() = 0;
virtual void builderPipe() = 0; virtual void buildPipe() = 0;
virtual void builderTank() = 0; virtual void buildTank() = 0;
virtual void builderVavle() = 0; virtual void buildVavle() = 0;
virtual void builderPump() = 0; virtual void buildPump() = 0;
virtual void builderReservoir() = 0; virtual void buildReservoir() = 0;
virtual void builderEmitter() = 0; virtual void buildEmitter() = 0;
virtual void buildPatterns() = 0;
virtual void buildParamter() = 0;
virtual void buildCoordnates() = 0;
virtual void buildVertices() = 0;
virtual void buildLabels() = 0;
virtual void buildTags() = 0;
virtual void buildBackDrop() = 0;
virtual void buildQuality() = 0;
virtual void buildSources() = 0;
virtual void buildMixing() = 0;
virtual void buildCurves() = 0;
virtual void buildStatus() = 0;
virtual void buildControls() = 0;
virtual void buildRules() = 0;
virtual void buildDemands() = 0;
virtual CivNewInp* getNewInp() = 0; virtual CivNewInp* getNewInp() = 0;
}; };
...@@ -46,13 +62,28 @@ public: ...@@ -46,13 +62,28 @@ public:
*/ */
void builder(StrQuote table, CivInp& inp); void builder(StrQuote table, CivInp& inp);
virtual void builderNode(); virtual void buildNode();
virtual void builderPipe(); virtual void buildPipe();
virtual void builderTank() ; virtual void buildTank();
virtual void builderVavle(); virtual void buildVavle();
virtual void builderPump(); virtual void buildPump();
virtual void builderReservoir() ; virtual void buildReservoir();
virtual void builderEmitter(); virtual void buildEmitter();
virtual void buildPatterns();
virtual void buildParamter();
virtual void buildCoordnates();
virtual void buildVertices();
virtual void buildLabels();
virtual void buildTags();
virtual void buildBackDrop();
virtual void buildQuality();
virtual void buildSources();
virtual void buildMixing();
virtual void buildCurves();
virtual void buildStatus();
virtual void buildControls();
virtual void buildRules();
virtual void buildDemands();
virtual CivNewInp* getNewInp(); virtual CivNewInp* getNewInp();
private: private:
......
...@@ -98,53 +98,51 @@ bool CivHydrCalc::qualitySimulation(char* inpFile, char* rptFile, char* binOutFi ...@@ -98,53 +98,51 @@ bool CivHydrCalc::qualitySimulation(char* inpFile, char* rptFile, char* binOutFi
if (!exportInp(inpFile)) if (!exportInp(inpFile))
return false; return false;
short hydCode = 1;
// 运行水质运算需要先进行水力运算,没有直接采用ENSolveH 是为了考虑减压阀的压力曲线设置
long t(0), tstep(0); long t(0), tstep(0);
int iTime(0); int iTime(0);
int errcode = 0; int errcode = 0;
errcode = ENopen(inpFile, rptFile, binOutFile); errcode = ENopen(inpFile, rptFile, binOutFile);
if (errcode > 0) if (errcode > 0)
{ {
ENclose(); ENclose();
return false; return false;
} }
if (ENopenH() > 0) errcode = ENopenH();
if (errcode > 0)
{ {
ENclose(); ENclose();
return false; return false;
} }
if (ENinitH(0) > 0)
// 根据类型 更改值
errcode = ENinitH(EN_SAVE);
if (errcode > 0)
{ {
ENcloseH();
ENclose(); ENclose();
return false; return false;
} }
float dHStep;
ENGetVal(4, &dHStep);
bool isFirst = true; bool isFirst = true;
// 计算
do do
{ {
int nLinkCount; int nLinkCount;
ENgetcount(EN_LINKCOUNT, &nLinkCount); ENgetcount(EN_LINKCOUNT, &nLinkCount);
/*for (int i = 1; i <= nLinkCount; i++)
{
int linkType;
char id[128] = "";
ENgetlinktype(i, &linkType);
ENgetlinkid(i, id);
}*/
if (ENrunH(&t) > 100) // errcode > 100 是错误 errcode = ENrunH(&t); // errcode > 100 是错误
if (errcode > 100)
{ {
ENopenQ();
ENclose(); ENclose();
return false; return false;
} }
ENnextH(&tstep);
if (isFirst) if (isFirst)
{ {
mDbConn->deleteByDate(NODERESULTTABLE, "日期", CurrentDate); mDbConn->deleteByDate(NODERESULTTABLE, "日期", CurrentDate);
...@@ -154,18 +152,14 @@ bool CivHydrCalc::qualitySimulation(char* inpFile, char* rptFile, char* binOutFi ...@@ -154,18 +152,14 @@ bool CivHydrCalc::qualitySimulation(char* inpFile, char* rptFile, char* binOutFi
// 获取当前节点和管段数据 // 获取当前节点和管段数据
getNodeResult(iTime); getNodeResult(iTime);
getLinkResult(iTime); getLinkResult(iTime);
ENnextH(&tstep);
iTime++; iTime++;
} while (tstep > 0);
// 更新管网数据库数据 } while (tstep > 0);
(void)mDbConn->updateNodeByInterval(CurrentDate, "0");
(void)mDbConn->updateLinkByInterval(CurrentDate, "0");
ENcloseH(); ENcloseH();
// 运行水质运算需要先进行水力运算
errcode = 0;
// 进行水质分析 // 进行水质分析
ENopenQ(); ENopenQ();
ENinitQ(1); ENinitQ(1);
...@@ -173,8 +167,6 @@ bool CivHydrCalc::qualitySimulation(char* inpFile, char* rptFile, char* binOutFi ...@@ -173,8 +167,6 @@ bool CivHydrCalc::qualitySimulation(char* inpFile, char* rptFile, char* binOutFi
t = 0; t = 0;
tstep = 0; tstep = 0;
iTime = 0; iTime = 0;
errcode = 0;
do do
{ {
errcode = ENrunQ(&t); // errcode > 100 是错误 errcode = ENrunQ(&t); // errcode > 100 是错误
...@@ -185,7 +177,9 @@ bool CivHydrCalc::qualitySimulation(char* inpFile, char* rptFile, char* binOutFi ...@@ -185,7 +177,9 @@ bool CivHydrCalc::qualitySimulation(char* inpFile, char* rptFile, char* binOutFi
return false; return false;
} }
// 存储水质计算结果 // 获取水质模拟结果
getNodeQuality(iTime);
getLinkQuality(iTime);
ENstepQ(&tstep); ENstepQ(&tstep);
...@@ -196,6 +190,16 @@ bool CivHydrCalc::qualitySimulation(char* inpFile, char* rptFile, char* binOutFi ...@@ -196,6 +190,16 @@ bool CivHydrCalc::qualitySimulation(char* inpFile, char* rptFile, char* binOutFi
ENcloseQ(); ENcloseQ();
ENclose(); ENclose();
// 更新数据
if (mResultCache.updateToDb(mDbConn))
return false;
// 更新管网数据库数据
(void)mDbConn->updateNodeByInterval(CurrentDate, "0");
(void)mDbConn->updateLinkByInterval(CurrentDate, "0");
return true; return true;
} }
...@@ -577,7 +581,6 @@ void CivHydrCalc::getNodeResult(short time) ...@@ -577,7 +581,6 @@ void CivHydrCalc::getNodeResult(short time)
int nNodeCount; int nNodeCount;
ENgetcount(EN_NODECOUNT, &nNodeCount); ENgetcount(EN_NODECOUNT, &nNodeCount);
NodeResultItems nodeItems;
for (int i = 1; i <= nNodeCount; i++) for (int i = 1; i <= nNodeCount; i++)
{ {
NodeResultItem nodeItem; NodeResultItem nodeItem;
...@@ -599,14 +602,14 @@ void CivHydrCalc::getNodeResult(short time) ...@@ -599,14 +602,14 @@ void CivHydrCalc::getNodeResult(short time)
ENgetnodevalue(i, EN_MAXVOLUME, &nodeItem.dTankMaxVolume); ENgetnodevalue(i, EN_MAXVOLUME, &nodeItem.dTankMaxVolume);
// 液位高度 // 液位高度
ENgetnodevalue(i, EN_TANKLEVEL, &nodeItem.dTankLevel); ENgetnodevalue(i, EN_TANKLEVEL, &nodeItem.dTankLevel);
// 水质 //// 水质
ENgetnodevalue(i, EN_QUALITY, &nodeItem.dQuality); //ENgetnodevalue(i, EN_QUALITY, &nodeItem.dQuality);
nodeItem.dInterval = time; nodeItem.dInterval = time;
nodeItems.push_back(nodeItem); // 放到缓存类中
mResultCache.addNodeItems(nodeItem);
} }
mDbConn->updateNode(nodeItems);
} }
void CivHydrCalc::getLinkResult(short time) void CivHydrCalc::getLinkResult(short time)
...@@ -614,7 +617,6 @@ void CivHydrCalc::getLinkResult(short time) ...@@ -614,7 +617,6 @@ void CivHydrCalc::getLinkResult(short time)
int nLinkCount; int nLinkCount;
ENgetcount(EN_LINKCOUNT, &nLinkCount); ENgetcount(EN_LINKCOUNT, &nLinkCount);
LinkResultItems linkItems;
for (int i = 1; i <= nLinkCount; i++) for (int i = 1; i <= nLinkCount; i++)
{ {
LinkResultItem linkItem; LinkResultItem linkItem;
...@@ -651,8 +653,7 @@ void CivHydrCalc::getLinkResult(short time) ...@@ -651,8 +653,7 @@ void CivHydrCalc::getLinkResult(short time)
ENgetnodevalue(node1, EN_HEAD, &linkItem.dFromNodHeadloss); ENgetnodevalue(node1, EN_HEAD, &linkItem.dFromNodHeadloss);
// 本点水头 // 本点水头
ENgetnodevalue(node2, EN_HEAD, &linkItem.dToNodHeadloss); ENgetnodevalue(node2, EN_HEAD, &linkItem.dToNodHeadloss);
// 水质
ENgetlinkvalue(i, EN_LINKQUAL, &linkItem.dQuality);
// 局部水头损失 // 局部水头损失
float fCoeff; float fCoeff;
ENgetlinkvalue(i, EN_MINORLOSS, &fCoeff); ENgetlinkvalue(i, EN_MINORLOSS, &fCoeff);
...@@ -671,8 +672,56 @@ void CivHydrCalc::getLinkResult(short time) ...@@ -671,8 +672,56 @@ void CivHydrCalc::getLinkResult(short time)
strcpy_s(linkItem.szStatus, "开启"); strcpy_s(linkItem.szStatus, "开启");
linkItem.dInterval = time; linkItem.dInterval = time;
// 放到缓存类中
mResultCache.addLinkItems(linkItem);
}
}
void CivHydrCalc::getNodeQuality(short time)
{
int nNodeCount;
ENgetcount(EN_NODECOUNT, &nNodeCount);
for (int i = 1; i <= nNodeCount; i++)
{
char No[35];
// 编号
ENgetnodeid(i, No);
float* quality = (float*)malloc(sizeof(float));
// 水质
ENgetnodevalue(i, EN_QUALITY, quality);
mResultCache.addNodeQuality(*quality, time, No);
free(quality);
}
}
void CivHydrCalc::getLinkQuality(short time)
{
int nLinkCount;
ENgetcount(EN_LINKCOUNT, &nLinkCount);
for (int i = 1; i <= nLinkCount; i++)
{
int* typeCode = (int*)malloc(sizeof(int));
ENgetlinktype(i, typeCode);
if (*typeCode != EN_PIPE)
{
free(typeCode);
continue;
}
free(typeCode);
char lnkNo[35];
// 编号
ENgetlinkid(i, lnkNo);
float* quality =(float*) malloc(sizeof(float));
// 水质
ENgetlinkvalue(i, EN_LINKQUAL, quality);
linkItems.push_back(linkItem); mResultCache.addLinkQuality(*quality, time, lnkNo);
free(quality);
} }
mDbConn->updateLink(linkItems);
} }
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include<string> #include<string>
#include<set> #include<set>
#include "CivInp.h" #include "CivInp.h"
#include "CivSimulResultCache.h"
class CivDbConnection; class CivDbConnection;
...@@ -58,9 +59,23 @@ private: ...@@ -58,9 +59,23 @@ private:
*/ */
void getLinkResult(short time); void getLinkResult(short time);
/*
*@brief 获取节点的水质计算结果
*@time: 时间
*/
void getNodeQuality(short time);
/*
*@brief 获取管线水值计算结果
*@time: 时间
*/
void getLinkQuality(short time);
private: private:
CivDbConnection* mDbConn; CivDbConnection* mDbConn;
std::string mNetname; std::string mNetname;
CivSimulResultCache mResultCache; // 存储模拟结果缓存类
}; };
...@@ -4,13 +4,13 @@ ...@@ -4,13 +4,13 @@
bool DLLEXPORT simulation(char* uri, char* netName, char* flag) bool DLLEXPORT simulation(char* uri, char* netName, char* flag)
{ {
char fileName[20]; char fileName[256];
char rptR[20]; char rptR[256];
char outBinFile[20]; char outBinFile[256];
strcpy_s(fileName, "test.inp"); strcpy_s(fileName, "E:\\work\\workspace\\hydraulicModelCode\\hydraulicModel\\funcDemo\\test.inp");
strcpy_s(rptR, "test.rpt"); strcpy_s(rptR, "E:\\work\\workspace\\hydraulicModelCode\\hydraulicModel\\funcDemo\\test.rpt");
strcpy_s(outBinFile, "test.bin"); strcpy_s(outBinFile, "E:\\work\\workspace\\hydraulicModelCode\\hydraulicModel\\funcDemo\\test.bin");
CivHydrCalc* calc = new CivHydrCalc(uri, netName); CivHydrCalc* calc = new CivHydrCalc(uri, netName);
......
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
void CivInpDirector::create(CivBuilder* builder) void CivInpDirector::create(CivBuilder* builder)
{ {
builder->builderNode(); builder->buildNode();
builder->builderPipe(); builder->buildPipe();
builder->builderTank(); builder->buildTank();
builder->builderReservoir(); builder->buildReservoir();
builder->builderPump(); builder->buildPump();
builder->builderVavle(); builder->buildVavle();
builder->builderEmitter(); builder->buildEmitter();
} }
\ No newline at end of file
...@@ -9,5 +9,7 @@ class CivInpDirector ...@@ -9,5 +9,7 @@ class CivInpDirector
public: public:
void create(CivBuilder* builder); void create(CivBuilder* builder);
}; };
#endif // !CIVINPDIRECTOR_H #endif // !CIVINPDIRECTOR_H
#include "CivSimulResultCache.h"
void CivSimulResultCache::addNodeQuality(float quality, int interval, Str sNo)
{
if (mNodeItemsMap.find(interval) == mNodeItemsMap.end())
return;
auto nodeMap = mNodeItemsMap.find(interval)->second;
if (nodeMap.find(sNo) == nodeMap.end())
return;
mNodeItemsMap[interval][sNo].dQuality = quality;
}
void CivSimulResultCache::addLinkQuality(float quality, int interval, Str sNo)
{
if (mLinkItemsMap.find(interval) == mLinkItemsMap.end())
return;
auto linkMap = mLinkItemsMap.find(interval)->second;
if (linkMap.find(sNo) == linkMap.end())
return;
mLinkItemsMap[interval][sNo].dQuality = quality;
}
void CivSimulResultCache::addNodeItems(const NodeResultItem& nodeItem)
{
mNodeItemsMap[nodeItem.dInterval][nodeItem.szNo] = nodeItem;
}
void CivSimulResultCache::addLinkItems(const LinkResultItem& linkItem)
{
mLinkItemsMap[linkItem.dInterval][linkItem.szNo] = linkItem;
}
bool CivSimulResultCache::updateToDb(CivDbConnection* dbConn)
{
if (dbConn == nullptr)
return false;
for (auto iter = mNodeItemsMap.begin(); iter != mNodeItemsMap.end(); iter++)
{
NodeResultItems nodeItems = iter->second;
dbConn->updateNode(nodeItems);
}
for (auto iter = mLinkItemsMap.begin(); iter != mLinkItemsMap.end(); iter++)
{
LinkResultItems nodeItems = iter->second;
dbConn->updateLink(nodeItems);
}
clear();
return true;
}
void CivSimulResultCache::clear()
{
mLinkItemsMap.clear();
mNodeItemsMap.clear();
}
#ifndef CIVSIMULRESULTCACHE_H
#define CIVSIMULRESULTCACHE_H
#include <map>
#include "CivDbConn.h"
#include "CivDbConnection.h"
#include "CivTypes.h"
/**
模拟结果缓存类
*/
class CivSimulResultCache
{
public:
/**
*@brief 缓存节点水质
*@quality:存储的值
*@interval:模拟第几次
*@sNo:本点号
*/
void addNodeQuality(float quality, int interval, Str sNo);
/**
*@brief 缓存管线水质
*@quality:存储的值
*@interval:模拟第几次
*@sNo:管线编号
*/
void addLinkQuality(float quality, int interval, Str sNo);
/**
*@brief 缓存节点水力模拟情况
*@nodeItem:节点水力结果值
*/
void addNodeItems(const NodeResultItem& nodeItem);
/**
*@brief 缓存管线水力模拟情况
*@linkItem:管线模拟结果
*/
void addLinkItems(const LinkResultItem& linkItem);
/**
*@brief 释放缓存的结果值
*/
void clear();
/**
*@brief 缓存数据更新到数据库
*@dbConn:数据库连接对象
*/
bool updateToDb(CivDbConnection* dbConn);
private:
std::map<int, NodeResultItems> mNodeItemsMap; // 模拟
std::map<int, LinkResultItems> mLinkItemsMap; // 计算的
};
#endif // !CIVSIMULRESULTCACHE_H
...@@ -160,6 +160,7 @@ ...@@ -160,6 +160,7 @@
<ClCompile Include="CivBuilder.cpp" /> <ClCompile Include="CivBuilder.cpp" />
<ClCompile Include="CivInpDirector.cpp" /> <ClCompile Include="CivInpDirector.cpp" />
<ClCompile Include="CivNewInp.cpp" /> <ClCompile Include="CivNewInp.cpp" />
<ClCompile Include="CivSimulResultCache.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="CivAssembly.h" /> <ClInclude Include="CivAssembly.h" />
...@@ -169,6 +170,7 @@ ...@@ -169,6 +170,7 @@
<ClInclude Include="CivBuilder.h" /> <ClInclude Include="CivBuilder.h" />
<ClInclude Include="CivInpDirector.h" /> <ClInclude Include="CivInpDirector.h" />
<ClInclude Include="CivNewInp.h" /> <ClInclude Include="CivNewInp.h" />
<ClInclude Include="CivSimulResultCache.h" />
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
......
...@@ -39,6 +39,9 @@ ...@@ -39,6 +39,9 @@
<ClCompile Include="CivNewInp.cpp"> <ClCompile Include="CivNewInp.cpp">
<Filter>源文件</Filter> <Filter>源文件</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="CivSimulResultCache.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="CivHydrCalc.h"> <ClInclude Include="CivHydrCalc.h">
...@@ -62,5 +65,8 @@ ...@@ -62,5 +65,8 @@
<ClInclude Include="CivInpDirector.h"> <ClInclude Include="CivInpDirector.h">
<Filter>头文件</Filter> <Filter>头文件</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="CivSimulResultCache.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>
\ No newline at end of file
...@@ -178,36 +178,36 @@ bool CivDbConn::updateNode(const NodeResultItems& nodeItems) ...@@ -178,36 +178,36 @@ bool CivDbConn::updateNode(const NodeResultItems& nodeItems)
os.clear(); os.clear();
os.str(""); os.str("");
// 2, 参数值 //// 2, 参数值
size_t total = nodeItems.size(); //size_t total = nodeItems.size();
for (int i = 0; i < total; i++) //for (int i = 0; i < total; i++)
{ //{
NodeResultItem item = nodeItems[i]; // NodeResultItem item = nodeItems[i];
os << "('" << item.szNo << "',"; // os << "('" << item.szNo << "',";
os << item.dDemand << ","; // os << item.dDemand << ",";
os << item.dHead << ","; // os << item.dHead << ",";
os << item.dElevation << ","; // os << item.dElevation << ",";
os << item.dPressure << ","; // os << item.dPressure << ",";
os << item.dTankLevel << ","; // os << item.dTankLevel << ",";
os << item.dTankMaxVolume << ","; // os << item.dTankMaxVolume << ",";
os << item.dTankVolume << ","; // os << item.dTankVolume << ",";
os << "'" << CurrentDate << "',"; // os << "'" << CurrentDate << "',";
os << item.dInterval << ","; // os << item.dInterval << ",";
os << "'" << CurrentTime << "'"; // os << "'" << CurrentTime << "'";
if (i == (total - 1)) // if (i == (total - 1))
{ // {
os << ")"; // os << ")";
} // }
else // else
{ // {
os << "),"; // os << "),";
} // }
} //}
std::string sql = TransUTFCoding(preSql) + os.str(); //std::string sql = TransUTFCoding(preSql) + os.str();
os.clear(); //os.clear();
os.str(""); //os.str("");
if (!execSql(sql)) //if (!execSql(sql))
return false; // return false;
} }
return true; return true;
...@@ -218,69 +218,69 @@ bool CivDbConn::updateLink(const LinkResultItems& lineItems) ...@@ -218,69 +218,69 @@ bool CivDbConn::updateLink(const LinkResultItems& lineItems)
if (!isValid()) if (!isValid())
return false; return false;
std::stringstream os; //std::stringstream os;
LinkFiledName filedNames; //LinkFiledName filedNames;
std::string currData = CurrentDate; //std::string currData = CurrentDate;
if (createTable(PIPERESULTTABLE, "public", CivTableTemp::PIPE_TABLE)) //if (createTable(PIPERESULTTABLE, "public", CivTableTemp::PIPE_TABLE))
{ //{
os << "INSERT INTO public." << PIPERESULTTABLE << "( "; // os << "INSERT INTO public." << PIPERESULTTABLE << "( ";
os << filedNames.szNo << ","; // os << filedNames.szNo << ",";
os << filedNames.dFlow << ","; // os << filedNames.dFlow << ",";
os << filedNames.nFlowDirect << ","; // os << filedNames.nFlowDirect << ",";
os << filedNames.dVelocity << ","; // os << filedNames.dVelocity << ",";
os << filedNames.dHeadloss << ","; // os << filedNames.dHeadloss << ",";
os << filedNames.dUnitHeadloss << ","; // os << filedNames.dUnitHeadloss << ",";
os << filedNames.dFromNodHeadloss << ","; // os << filedNames.dFromNodHeadloss << ",";
os << filedNames.dToNodHeadloss << ","; // os << filedNames.dToNodHeadloss << ",";
os << filedNames.dLocalHeadloss << ","; // os << filedNames.dLocalHeadloss << ",";
os << filedNames.dFrictionHeadloss << ","; // os << filedNames.dFrictionHeadloss << ",";
os << filedNames.szStatus << ","; // os << filedNames.szStatus << ",";
os << filedNames.dDate << ","; // os << filedNames.dDate << ",";
os << filedNames.dInterval << ","; // os << filedNames.dInterval << ",";
os << filedNames.dModifyTime; // os << filedNames.dModifyTime;
os << ") VALUES"; // os << ") VALUES";
std::string preSql = os.str(); // std::string preSql = os.str();
os.clear(); // os.clear();
os.str(""); // os.str("");
// 2, 参数值 // // 2, 参数值
size_t total = lineItems.size(); // size_t total = lineItems.size();
for (int i = 0; i < total; i++) // for (int i = 0; i < total; i++)
{ // {
LinkResultItem item = lineItems[i]; // LinkResultItem item = lineItems[i];
os << "('" << item.szNo << "'" << ","; // os << "('" << item.szNo << "'" << ",";
os << item.dFlow << ","; // os << item.dFlow << ",";
os << item.nFlowDirect << ","; // os << item.nFlowDirect << ",";
os << item.dVelocity << ","; // os << item.dVelocity << ",";
os << item.dHeadloss << ","; // os << item.dHeadloss << ",";
os << item.dUnitHeadloss << ","; // os << item.dUnitHeadloss << ",";
os << item.dFromNodHeadloss << ","; // os << item.dFromNodHeadloss << ",";
os << item.dToNodHeadloss << ","; // os << item.dToNodHeadloss << ",";
os << item.dLocalHeadloss << ","; // os << item.dLocalHeadloss << ",";
os << item.dFrictionHeadloss << ","; // os << item.dFrictionHeadloss << ",";
os << "'" << TransUTFCoding(item.szStatus) << "'" << ","; // os << "'" << TransUTFCoding(item.szStatus) << "'" << ",";
os << "'" << CurrentDate << "',"; // os << "'" << CurrentDate << "',";
os << item.dInterval << ","; // os << item.dInterval << ",";
os << "'" << CurrentTime << "'"; // os << "'" << CurrentTime << "'";
if (i == (total - 1)) // if (i == (total - 1))
os << ")"; // os << ")";
else // else
os << "),"; // os << "),";
} // }
std::string utf8Sql = TransUTFCoding(preSql); // std::string utf8Sql = TransUTFCoding(preSql);
std::string sql = utf8Sql + os.str(); // std::string sql = utf8Sql + os.str();
os.clear(); // os.clear();
os.str(""); // os.str("");
if (!execSql(sql)) // if (!execSql(sql))
return false; // return false;
} //}
return true; return true;
} }
......
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
#include "CivTypes.h" #include "CivTypes.h"
#include "CivTableTemp.h" #include "CivTableTemp.h"
#define DBEXPORT __declspec(dllexport)
/** /**
数据库连接接口 数据库连接接口
*/ */
class CivDbConn class DBEXPORT CivDbConn
{ {
public: public:
CivDbConn(); CivDbConn();
......
...@@ -122,6 +122,7 @@ bool CivDbConnection::updateNode(const NodeResultItems& nodeItems) ...@@ -122,6 +122,7 @@ bool CivDbConnection::updateNode(const NodeResultItems& nodeItems)
os<< filedNames.dTankVolume<<","; os<< filedNames.dTankVolume<<",";
os << filedNames.dDate << ","; os << filedNames.dDate << ",";
os << filedNames.dInterval<<","; os << filedNames.dInterval<<",";
os << filedNames.dQuality<< ",";
os << filedNames.dModifyTime; os << filedNames.dModifyTime;
os<< ") VALUES"; os<< ") VALUES";
...@@ -131,10 +132,9 @@ bool CivDbConnection::updateNode(const NodeResultItems& nodeItems) ...@@ -131,10 +132,9 @@ bool CivDbConnection::updateNode(const NodeResultItems& nodeItems)
os.str(""); os.str("");
// 2, 参数值 // 2, 参数值
size_t total = nodeItems.size(); for(auto iter= nodeItems.begin();iter!=nodeItems.end();iter++)
for (int i = 0; i < total; i++)
{ {
NodeResultItem item = nodeItems[i]; NodeResultItem item = iter->second;
os << "('" << item.szNo << "',"; os << "('" << item.szNo << "',";
os << item.dDemand << ","; os << item.dDemand << ",";
os << item.dHead << ","; os << item.dHead << ",";
...@@ -145,8 +145,12 @@ bool CivDbConnection::updateNode(const NodeResultItems& nodeItems) ...@@ -145,8 +145,12 @@ bool CivDbConnection::updateNode(const NodeResultItems& nodeItems)
os << item.dTankVolume << ","; os << item.dTankVolume << ",";
os <<"'"<< CurrentDate <<"',"; os <<"'"<< CurrentDate <<"',";
os << item.dInterval<<","; os << item.dInterval<<",";
os << item.dQuality<< ",";
os << "'"<< CurrentTime <<"'"; os << "'"<< CurrentTime <<"'";
if (i == (total - 1))
auto subiter = iter;
++subiter;
if (subiter == nodeItems.end())
{ {
os << ")"; os << ")";
} }
...@@ -190,6 +194,7 @@ bool CivDbConnection::updateLink(const LinkResultItems& lineItems) ...@@ -190,6 +194,7 @@ bool CivDbConnection::updateLink(const LinkResultItems& lineItems)
os << filedNames.szStatus << ","; os << filedNames.szStatus << ",";
os << filedNames.dDate << ","; os << filedNames.dDate << ",";
os << filedNames.dInterval<<","; os << filedNames.dInterval<<",";
os << filedNames.dQuality << ",";
os << filedNames.dModifyTime; os << filedNames.dModifyTime;
os<< ") VALUES"; os<< ") VALUES";
...@@ -197,13 +202,10 @@ bool CivDbConnection::updateLink(const LinkResultItems& lineItems) ...@@ -197,13 +202,10 @@ bool CivDbConnection::updateLink(const LinkResultItems& lineItems)
os.clear(); os.clear();
os.str(""); os.str("");
// 2, 参数值 // 2, 参数值
size_t total = lineItems.size(); for(auto iter = lineItems.begin();iter!=lineItems.end();iter++)
for (int i = 0; i < total; i++)
{ {
LinkResultItem item = lineItems[i]; LinkResultItem item =iter->second;
os<<"('" <<item.szNo<<"'"<< ","; os<<"('" <<item.szNo<<"'"<< ",";
os<< item.dFlow<< ","; os<< item.dFlow<< ",";
os<< item.nFlowDirect<<","; os<< item.nFlowDirect<<",";
...@@ -217,8 +219,12 @@ bool CivDbConnection::updateLink(const LinkResultItems& lineItems) ...@@ -217,8 +219,12 @@ bool CivDbConnection::updateLink(const LinkResultItems& lineItems)
os<< "'"<<TransUTFCoding(item.szStatus)<<"'"<<","; os<< "'"<<TransUTFCoding(item.szStatus)<<"'"<<",";
os <<"'"<< CurrentDate << "',"; os <<"'"<< CurrentDate << "',";
os<< item.dInterval<<","; os<< item.dInterval<<",";
os << item.dQuality << ",";
os <<"'" << CurrentTime <<"'"; os <<"'" << CurrentTime <<"'";
if (i == (total - 1))
auto subIte = iter;
++subIte;
if (subIte == lineItems.end())
os << ")"; os << ")";
else else
os << "),"; os << "),";
......
...@@ -55,6 +55,15 @@ public: ...@@ -55,6 +55,15 @@ public:
bool updateNodeByInterval(StrQuote currDate, StrQuote interval); bool updateNodeByInterval(StrQuote currDate, StrQuote interval);
bool updateLinkByInterval(StrQuote currDate, StrQuote interval); bool updateLinkByInterval(StrQuote currDate, StrQuote interval);
/**
*@brief 刷新模拟的水质字段值
*@quality: 水质
*@currDate: 模拟的日期
*@StrQuote: 模拟的次数
*/
bool updateNodeQuality(const NodeResultItems& nodeItems);
bool updatePipeQuality(const LinkResultItems& lineItems);
/** /**
*@brief 更新点表数据 *@brief 更新点表数据
*@nodeItems:需要更新的值 *@nodeItems:需要更新的值
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include "CivDbConn.h" #include "CivDbConn.h"
#include <libpq-fe.h> #include <libpq-fe.h>
#define DBEXPORT __declspec(dllexport)
/** /**
postgress 数据库 postgress 数据库
*/ */
......
...@@ -171,7 +171,6 @@ struct CurvesFields { ...@@ -171,7 +171,6 @@ struct CurvesFields {
}; };
// 参数选项表 // 参数选项表
struct ParameterFileds { struct ParameterFileds {
Str name = "参数名"; Str name = "参数名";
Str val = "参数值"; Str val = "参数值";
...@@ -274,8 +273,8 @@ struct LinkResultItem ...@@ -274,8 +273,8 @@ struct LinkResultItem
int dInterval; // 时段 int dInterval; // 时段
}; };
#define NodeResultItems std::vector<NodeResultItem> #define NodeResultItems std::map<Str, NodeResultItem>
#define LinkResultItems std::vector<LinkResultItem> #define LinkResultItems std::map<Str, LinkResultItem>
#endif // !CIVTYPES_H #endif // !CIVTYPES_H
......
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