|
|
#include "zxLogInstance.h"
|
|
|
#include "iDataIoUtilsEx.h"
|
|
|
#include "ZxDataProject.h"
|
|
|
#include "ZxDataWell.h"
|
|
|
#include "nmDataDemo.h"
|
|
|
#include "nmDataUtils.h"
|
|
|
|
|
|
#include <QDebug>
|
|
|
#include <QFile>
|
|
|
#include <QTextStream>
|
|
|
|
|
|
nmDataUtils::nmDataUtils() {
|
|
|
}
|
|
|
|
|
|
nmDataUtils::~nmDataUtils() {
|
|
|
|
|
|
}
|
|
|
|
|
|
bool nmDataUtils::extendChildrenOfProj(ZxDataProject* pDataProj)
|
|
|
{
|
|
|
Q_ASSERT (nullptr != pDataProj);
|
|
|
|
|
|
/* 如下代码只是参照,请根据具体需求咨询框架负责人员后进行处理
|
|
|
|
|
|
pDataObj->clearChildren(iDataModelType::sTypePvtInfo);
|
|
|
|
|
|
// load Anal PVTs
|
|
|
QString sSql = "Select PvtID, PvtName, JobID from V_PVT_INFO";
|
|
|
sSql += QString(" order by PvtID");
|
|
|
VVecVariant vvec;
|
|
|
QString sLog = "";
|
|
|
if (_load(sSql, vvec, sLog, false, true))
|
|
|
{
|
|
|
for (int i = 0; i < vvec.count(); i++)
|
|
|
{
|
|
|
ZxDataPvtInfo* p = new ZxDataPvtInfo();
|
|
|
Q_ASSERT (nullptr != p);
|
|
|
p->setCode(vvec.at(i).at(0).toString());
|
|
|
p->setName(vvec.at(i).at(1).toString());
|
|
|
p->setAnalID(vvec.at(i).at(2).toString());
|
|
|
p->createChildren();
|
|
|
appendChild(p);
|
|
|
p->setLoaded(false);
|
|
|
}
|
|
|
}
|
|
|
else if (!sLog.isEmpty())
|
|
|
{
|
|
|
zxLogRunW(QObject::tr("Failed to load PVTInfo with \r\n '%1'").arg(sLog));
|
|
|
return false;
|
|
|
}//*/
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
bool nmDataUtils::extendChildrenOfWell(ZxDataWell* pDataWell)
|
|
|
{
|
|
|
Q_ASSERT (nullptr != pDataWell);
|
|
|
|
|
|
// 此处仅仅以获取样表举例 Alias="n数值样例数据表" Name="N_DATA_DEMO"
|
|
|
QString sWellCode = pDataWell->getCode();
|
|
|
QString sSql = "Select distinct ID from N_DATA_DEMO";
|
|
|
sSql += QString(" where WellCode = '%1'").arg(sWellCode);
|
|
|
sSql += QString(" order by ID");
|
|
|
VVecVariant vvec;
|
|
|
QString sLog = "";
|
|
|
if (pDataWell->loadData(sSql, vvec, sLog, false))
|
|
|
{
|
|
|
for (int i = 0; i < vvec.count(); i++)
|
|
|
{
|
|
|
nmDataDemo* p = new nmDataDemo();
|
|
|
Q_ASSERT (nullptr != p);
|
|
|
p->setCode(vvec.at(i).at(0).toString());
|
|
|
p->setWellCode(sWellCode);
|
|
|
pDataWell->appendChild(p);
|
|
|
}
|
|
|
}
|
|
|
else if (!sLog.isEmpty())
|
|
|
{
|
|
|
zxLogRunW(QObject::tr("Failed to load nmDataDemo with \r\n '%1'").arg(sLog));
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
bool nmDataUtils::deleteChildrenOfWell(ZxDataWell* pDataWell) {
|
|
|
Q_ASSERT(nullptr != pDataWell);
|
|
|
|
|
|
QString sWellCode = pDataWell->getCode();
|
|
|
// 涉及到哪些表(此处只是举例,需要根据表格结构进行处理)
|
|
|
QStringList listTables;
|
|
|
listTables << "N_DATA_DEMO";
|
|
|
//listTables << "N_DATA_DEMO"; 其它
|
|
|
|
|
|
QStringList listSqls;
|
|
|
listSqls.clear();
|
|
|
for (int i = 0; i < listTables.count(); i++)
|
|
|
{
|
|
|
listSqls << QString("delete from %1 where WellCode='%2'").arg(listTables[i]).arg(sWellCode);
|
|
|
}
|
|
|
|
|
|
bool bResult = true;
|
|
|
foreach (QString s, listSqls)
|
|
|
{
|
|
|
iDataIoUtilsEx o;
|
|
|
bool b = o.execSqlOnly(s);
|
|
|
if (!b)
|
|
|
{
|
|
|
zxLogRunW(o.getLastError());
|
|
|
}
|
|
|
bResult &= b;
|
|
|
}
|
|
|
|
|
|
// TODO 说明
|
|
|
// 理论上,此处还应该把子数据对象,从pDataWell中Remove,但是
|
|
|
// 考虑到这是删除井,在主程序中,会统一把pDataWell所有子数据对象删除,所以此处无需额外处理
|
|
|
|
|
|
return bResult;
|
|
|
}
|
|
|
|
|
|
QStringList nmDataUtils::readNmDataFile(const QString &filePath) {
|
|
|
QStringList content;
|
|
|
// 打开文件
|
|
|
QFile file(filePath);
|
|
|
|
|
|
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
|
qDebug() << "Failed to open file:" << filePath;
|
|
|
return content;
|
|
|
}
|
|
|
|
|
|
// 使用QTextStream读取文件
|
|
|
QTextStream in(&file);
|
|
|
|
|
|
while(!in.atEnd()) {
|
|
|
// 读取一行
|
|
|
QString line = in.readLine();
|
|
|
// 将行内容放入QStringList
|
|
|
content.append(line);
|
|
|
}
|
|
|
|
|
|
// 关闭文件
|
|
|
file.close();
|
|
|
|
|
|
return content;
|
|
|
}
|
|
|
|