Files
envi-code/SourceCode/Code2026/PipelineCmd/SysLayerCfg/THVacCfgDataBase.cpp
T
2026-09-28 15:28:50 +08:00

330 lines
7.7 KiB
C++

#include "..\stdafx.h"
#include "EarThwormDef.h"
#include "THVacCfgDataBase.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
#define SYSTEM_KEY -2 // 所属系统
THVacCfgDataBase::THVacCfgDataBase()
{
}
THVacCfgDataBase::~THVacCfgDataBase()
{
}
AcDbObjectId THVacCfgDataBase::GetLayId(LPCTSTR pszTab, LPCTSTR pszLayKey, LPCTSTR pszSysName)
{
if (NULL == pszTab || NULL == pszLayKey || NULL == pszSysName)
return FALSE;
// 遍历数据库表,获取对应的图层名
CString strLayName = _T("");
if (!GetLayName(pszTab, pszLayKey, pszSysName, strLayName))
return FALSE;
// 根据图层名获取图层Id, 图层不存在,则创建新的图层
// 获得图层
AcDbObjectId idLayer = AcDbObjectId::kNull;
AcDbLayerTable* pLayerTab = NULL;
AcDbDatabase* pDb = acdbHostApplicationServices()->workingDatabase();
if(Acad::eOk == pDb->getLayerTable(pLayerTab, AcDb::kForWrite))
{
if(pLayerTab->has(strLayName))
{
// 图层已经存在
pLayerTab->getAt(strLayName, idLayer);
pLayerTab->close();
return idLayer;
}
else
{
// 创建图层
// 创建新的层表记录
AcDbLayerTableRecord* pLayerTabRec = NULL;
pLayerTabRec = new AcDbLayerTableRecord();
if(NULL == pLayerTabRec)
{
DELETE_PTR(pLayerTabRec);
pLayerTab->close();
return FALSE;
}
pLayerTabRec->setName(strLayName);
// 将新建的层表记录添加到层表中
if(Acad::eOk != pLayerTab->add(idLayer, pLayerTabRec))
{
pLayerTabRec->close();
pLayerTab->close();
return FALSE;
}
// 设置图层的颜色
AcCmColor color;
color.setColorIndex(3);
pLayerTabRec->setColor(color);
// 关闭图层和图层记录
pLayerTabRec->close();
pLayerTab->close();
return idLayer;
}
}
return FALSE;
}
BOOL THVacCfgDataBase::GetLayName(LPCTSTR pszTab, LPCTSTR pszLayKey, LPCTSTR pszSysName, CString& strLayName)
{
if (NULL == pszTab || NULL == pszLayKey || NULL == pszSysName)
return FALSE;
CString strLayKey, strSys, strTemp;
strTemp = pszLayKey;
strLayKey.Format(_T("\'%s\'"), strTemp);
strTemp = pszSysName;
strSys.Format(_T("\'%s\'"), strTemp);
CString strSQL;
strTemp = pszTab;
strSQL.Format(_T("Select [LAYNAME] From [%s] Where [LAYKEY]='%s' And [SYSTEM]='%s'"), strTemp, strLayKey, strLayName);
int iFlag = GetSelData(strSQL, strLayName);
BOOL bValue = iFlag == 1 ? TRUE : FALSE;
return bValue;
}
// 获取系统设置的模板
int THVacCfgDataBase::GetSystemModel(LPCTSTR pszTabName, CUIIValueTable &vSelTab)
{
return 1;
}
BOOL THVacCfgDataBase::SelectTableFromDMB(LPCTSTR pszSysName, LPCTSTR pszTab, CUIIValueTable& vSelTable)
{
if (NULL == pszSysName || NULL == pszTab)
return FALSE;
// 确保数据库是打开的
if (!IsDatabaseOpen())
return FALSE;
// 写入查询SQL语句 (从表中查询指定系统名称的记录)
CString strSQL, strSys, strTab;
strSys = pszSysName;
strTab = pszTab;
strSQL.Format(_T("Select * From [%s] Where [SYSTEM]='%s'"), strTab, strSys);
if (0 == strSys.CompareNoCase( _T("")))
{
strSQL.Format(_T("Select * From [%s] Where [SYSTEM] is null"), strTab);
}
int iFlag = GetSelData(strSQL, vSelTable);
BOOL bValue = iFlag > 0 ? TRUE : FALSE;
return bValue;
}
// 获取指定行记录
BOOL THVacCfgDataBase::SelRowFromDB(LPCTSTR pszTab, LPCTSTR pszLayKey, LPCTSTR pszSysName, CMapStringToString& strMap)
{
if (NULL == pszTab || NULL == pszLayKey || NULL == pszSysName)
return FALSE;
// 获取表的字段
Ttable tField;
//GetTableStructInfoEx(BLOWPIPE_SETTING, tField);
CUIIValueTable table;
CString sSQL;
sSQL = _T("select from Wpipecfg limit 0,1");
GetSelData(sSQL, table);
CStringArray arField;
table.GetLableRecord(arField);
for (int j = 0; j < arField.GetSize(); j++)
{
CUIITableField strufield;
strufield.m_sFieldName = arField.GetAt(j);
tField.Add(strufield);
}
// 遍历字段,获取每个字段的值
CString strSQL, strField, strKey, strValue;
for (int i = 0; i < tField.GetSize(); i++)
{
strField = tField.GetAt(i).m_sFieldName;
strSQL.Format(_T("Select [%s] Form %s Where [SYSTEM]='%s' And [LAYKEY]='%s'"), strField, pszTab, pszSysName, pszLayKey);
GetSelData(strSQL, strValue);
if (1 == GetSelData(strSQL, strValue))
strMap.SetAt(strField, strValue);
else
strMap.SetAt(strField, _T(""));
}
return TRUE;
}
// 获取指定列的不为空的值
BOOL THVacCfgDataBase::SelColFromDB(LPCTSTR pszTab, LPCTSTR pszColKey, CStringArray& arSysTem)
{
if (NULL == pszTab || NULL == pszColKey)
return FALSE;
// 确保表有效
if (!IsTableValue(pszTab))
return FALSE;
CString strSQL;
CString strSys = _T("SYSTEM");
strSQL.Format(_T("Select [%s] From %s where [%s]<>'' ORDER BY [ID] ASC"), pszColKey, pszTab, pszColKey);
int iFlag = GetSelData(strSQL, arSysTem);
BOOL bValue = iFlag > 0 ? TRUE : FALSE;
return bValue;
}
// 查询线型表中线型的信息
int THVacCfgDataBase::SelLineFromDB(LPCTSTR pszTab, CUIIValueTable& vSelTab)
{
if (NULL == pszTab)
return -1;
// 获取表字段
Ttable arField;
//GetTableStructInfoEx(pszTab, arField);
CUIIValueTable table;
CString sSQL;
sSQL.Format(_T("select * from %s limit 0,1"), pszTab);
GetSelData(sSQL, table);
CStringArray arFieldName;
table.GetLableRecord(arFieldName);
for (int j = 0; j < arFieldName.GetSize(); j++)
{
CUIITableField strufield;
strufield.m_sFieldName = arFieldName.GetAt(j);
arField.Add(strufield);
}
// 设置SQL语句 查询这个行的信息
CString strSQL, strSet, strName, strKey;
for (int i = 0; i < arField.GetSize(); i++)
{
strName = arField.GetAt(i).m_sFieldName;
strSet.Format(_T("[%s]"), strName);
if (0 == strKey.CompareNoCase(_T("")))
strKey = strSet;
else
strKey += _T(",") + strSet;
}
strSQL.Format(_T("Select %s From %s"), strKey, pszTab);
int iLen = GetSelData(strSQL, vSelTab);
return iLen;
}
BOOL THVacCfgDataBase::IsTableValue(LPCTSTR pszTable)
{
if (NULL == pszTable)
return FALSE;
// 判断数据库是否打开
if (!IsDatabaseOpen())
return FALSE;
// 遍历数据库中的表,判断指定表是否存在
CStringArray arTabName;
GetDbTableNameArray(arTabName);
CString strName;
for (int i = 0; i < arTabName.GetSize(); i++)
{
strName = arTabName.GetAt(i);
if (0 == strName.CompareNoCase(pszTable))
return TRUE;
}
return FALSE;
}
BOOL THVacCfgDataBase::IsRowExistInDB(LPCTSTR pszLayKey, LPCTSTR pszSystem, LPCTSTR pszTab)
{
CString strSQL, strKey = _T("LAYKEY"), strValue;
strSQL.Format(_T("Select distinct [%s] From %s where [LAYKEY] = '%s' And [SYSTEM] = '%s'"),
strKey, pszTab, pszLayKey, pszSystem);
if (GetSelData(strSQL, strValue) > 0)
return TRUE;
return FALSE;
}
BOOL THVacCfgDataBase::IsTextExist(LPCTSTR pszDbKey, LPCTSTR pszCurText, LPCTSTR pszTab)
{
// 确保数据库有效且被打开
if (!IsTableValue(pszTab) || NULL == pszDbKey|| NULL == pszCurText)
return FALSE;
// 获取表的结构
Ttable tField;
//GetTableStructInfoEx(pszTab, tField);
CUIIValueTable table;
CString sSQL;
sSQL.Format(_T("select * from %s limit 0,1"), pszTab);
GetSelData(sSQL, table);
CStringArray arFieldName;
table.GetLableRecord(arFieldName);
for (int j = 0; j < arFieldName.GetSize(); j++)
{
CUIITableField strufield;
strufield.m_sFieldName = arFieldName.GetAt(j);
tField.Add(strufield);
}
// 遍历数据库,判断是否存在指定值
BOOL bHas = FALSE;
CString strSQL, strValue;
CString strTemp = pszCurText;
strValue.Format(_T("\'%s\'"), strTemp);
strSQL.Format(_T("Select [%s] From %s where [%s] = %s"), pszDbKey, pszTab, pszDbKey, strValue);
if (GetSelData(strSQL, strValue) > 0)
bHas |= TRUE;
return bHas;
}
// 判断MDB数据库是裎�?不包含模板)
BOOL THVacCfgDataBase::IsDBNull(LPCTSTR pszTab)
{
if (NULL == pszTab)
return FALSE;
// 确保数据库中的表有效
BOOL bNULL = FALSE;
if (!IsTableValue(pszTab))
return bNULL;
// 写入查询SQL语句
CString strSQL, strTemp;
strTemp = pszTab;
strSQL.Format(_T("Select distinct [SYSTEM] From %s Where [SYSTEM]<>'' "), strTemp);
if (IsSelEmpty(strSQL))
bNULL = TRUE;
return bNULL;
}