123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275 |
- #include "stdafx.h"
- #include "MaxEDSRulesDataDB.h"
- #include "MaxEDSRulesDataTable.h"
- namespace OTSClassifyEngine
- {
- using namespace OTSSQLITE;
- CMaxEDSRulesDataDB::CMaxEDSRulesDataDB(CDBStoreBasePtr a_datastore)
- {
- m_tableInfo.reset(new CMaxEDSRulesDataTable());
- myDB = CreateNewSQLiteDB(a_datastore, m_tableInfo);
- }
- CMaxEDSRulesDataDB::~CMaxEDSRulesDataDB()
- {
- }
- CDBTableBasePtr CMaxEDSRulesDataDB::GetTableInfo()
- {
- /*if (!m_tableInfo)
- {
- m_tableInfo.reset(new CSTDDataTable);
- }*/
- return m_tableInfo;
- }
- BOOL CMaxEDSRulesDataDB::Init(const BOOL a_bClean /*= FALSE*/)
- {
- return myDB->Init(a_bClean);
- }
- BOOL CMaxEDSRulesDataDB::CreateTable(const BOOL a_bForce /*= FALSE*/)
- {
- return myDB->CreateTable(a_bForce);
- }
- BOOL CMaxEDSRulesDataDB::DeleteTable()
- {
- return myDB->DeleteTable();
- }
- BOOL CMaxEDSRulesDataDB::RemoveAllRows()
- {
- return myDB->RemoveAllRows();
- }
- BOOL CMaxEDSRulesDataDB::IsDBExist()
- {
- return myDB->IsDBExist();
- }
- OTSSQLITE::CDBStoreBasePtr CMaxEDSRulesDataDB::GetDatastore()
- {
- return myDB->GetDatastore();
- }
- OTSSQLITE::CDBQueryBasePtr CMaxEDSRulesDataDB::GetTableQuery(LPCTSTR a_sOrderColumnName /*= nullptr*/)
- {
- return myDB->GetTableQuery(a_sOrderColumnName);
- }
-
- MaxEDSRuleList CMaxEDSRulesDataDB::GetMaxEDSRulesLib(BOOL bForce /*= FALSE*/)
- {
- ParticleSTDPtr partStd = ParticleSTDPtr(new ParticleSTD());
- if (bForce)
- {
- partStd->MaxEDSRuleListClear();
- }
- auto query = GetTableQuery("Expression");
- ASSERT(query);
-
- auto MaxEDSRuleslist = ReadMaxEDSRulesList(query);
- /*partStd->setMaxEDSRuleList(MaxEDSRuleslist);*/
- //m_pOretype->SetName(_T(""));
- return MaxEDSRuleslist;
- }
- MaxEDSRuleList CMaxEDSRulesDataDB::ReadMaxEDSRulesList(CDBQueryBasePtr a_query)
- {
- MaxEDSRuleList listSTDItem;
- int nRowId = 0;
- int nWrongItems = 0;
- while (!a_query->IsEOF())
- {
- if (!ReadMaxEDSRulesItem(a_query)) //current x-ray point
- {
- LogErrorTrace(__FILE__, __LINE__, _T("Read xray point failed"));
- nWrongItems++;
- break;
- }
- listSTDItem.push_back(m_MaxEdsItem);
- a_query->NextRow();
- nRowId++;
- }
- return listSTDItem;
- }
- BOOL CMaxEDSRulesDataDB::ReadMaxEDSRulesItem(CDBQueryBasePtr a_query)
- {
- int nCol;
- m_MaxEdsItem = MaxEDSRulePtr(new MaxEDSRule());
- int nMaxEDSTime;
- nCol = (int)CMaxEDSRulesDataTable::ColumnID::N_MaxEDSTime - (int)CMaxEDSRulesDataTable::ColumnID::MIN;
- nMaxEDSTime = a_query->GetColIntValue(nCol, -1);
- m_MaxEdsItem->m_MaxEDSTime = nMaxEDSTime;
- CString sUsingElementList;
- nCol = (int)CMaxEDSRulesDataTable::ColumnID::S_UsingElementList - (int)CMaxEDSRulesDataTable::ColumnID::MIN;
- sUsingElementList = a_query->GetColStringValue(nCol, _T(""));
- std::vector<std::string> eleStrlist;
- CElementsList elelist;
- xmls::SplitString(sUsingElementList.GetBuffer(), eleStrlist, ",");
- for (auto s : eleStrlist)
- {
- CElementPtr ele = CElementPtr(new CElement(s.c_str()));
- elelist.push_back(ele);
- }
- m_MaxEdsItem->m_elementList = elelist;
- CString sUsingImgPropertyList;
- nCol = (int)CMaxEDSRulesDataTable::ColumnID::S_UsingImgPropertyList - (int)CMaxEDSRulesDataTable::ColumnID::MIN;
- sUsingImgPropertyList = a_query->GetColStringValue(nCol, _T(""));
- eleStrlist.clear();
- xmls::SplitString(sUsingImgPropertyList.GetBuffer(), eleStrlist, ",");
- m_MaxEdsItem->m_ImgPropertyList = eleStrlist;
- CString sUsingOtherPropertyList;
- nCol = (int)CMaxEDSRulesDataTable::ColumnID::S_UsingOtherPropertyList - (int)CMaxEDSRulesDataTable::ColumnID::MIN;
- sUsingOtherPropertyList = a_query->GetColStringValue(nCol, _T(""));
- xmls::SplitString(sUsingOtherPropertyList.GetBuffer(), eleStrlist, ",");
- m_MaxEdsItem->m_OtherpropertyList = eleStrlist;
- CString sExpression;
- nCol = (int)CMaxEDSRulesDataTable::ColumnID::S_Expression - (int)CMaxEDSRulesDataTable::ColumnID::MIN;
- sExpression = a_query->GetColStringValue(nCol, _T(""));
- m_MaxEdsItem->m_expressionStr = sExpression.GetString();
- return TRUE;
- }
-
- #pragma region ɾ¼õ´úÂë
- //MaxEDSRulePtr CMaxEDSRulesDataDB::GetSTDItemById(const long a_nIncAId)
- //{
- // MaxEDSRulePtr pSTDItem;
- // if (!m_listSTDItem.empty())
- // {
- // for (auto pItem : m_listSTDItem)
- // {
- // if (pItem->GetSTDId() == (DWORD)a_nIncAId)
- // {
- // pSTDItem = pItem;
- // }
- // }
- // }
- // else
- // {
- // auto tableQuery = GetQueryById(a_nIncAId);
- // ASSERT(tableQuery);
- // if (!tableQuery)
- // {
- // return pSTDItem;
- // }
- // if (!ReadSTDItem(tableQuery))
- // {
- // LogErrorTrace(__FILE__, __LINE__, _T("read x-ray failed."));
- // return pSTDItem;
- // }
- // pSTDItem = MaxEDSRulePtr(new MaxEDSRule(*m_pSTDItem.get()));
- // }
- // return pSTDItem;
- //}
- //MaxEDSRuleList& CMaxEDSRulesDataDB::GetSTDItemList(const BOOL a_bForce/* = FALSE*/)
- //{
- // if (a_bForce)
- // {
- // m_listSTDItem.clear();
- // }
- // if (m_listSTDItem.size() == 0)
- // {
- // ReadSTDItemList();
- // }
- // return m_listSTDItem;
- //}
- //BOOL CMaxEDSRulesDataDB::ReadSTDItemList()
- //{
- // auto tableInfoPtr = GetTableInfo();
- // ASSERT(tableInfoPtr);
- // if (!tableInfoPtr)
- // {
- // return FALSE;
- // }
- // auto query = GetTableQuery();
- // ASSERT(query);
- // if (!query)
- // {
- // return FALSE;
- // }
- // m_listSTDItem = ReadSTDItemList(query);
- // return TRUE;
- //}
- //CDBQueryBasePtr CMaxEDSRulesDataDB::GetQueryById(const long a_nIncAId)
- //{
- // CDBQueryBasePtr query;
- // auto datastorePtr = GetDatastore();
- // ASSERT(datastorePtr);
- // if (!datastorePtr)
- // {
- // return query;
- // }
- // auto tableInfoPtr = GetTableInfo();
- // ASSERT(tableInfoPtr);
- // if (!tableInfoPtr)
- // {
- // return query;
- // }
- // CString sIncAIdColumnName = tableInfoPtr->GetColumnName((int)CMaxEDSRulesDataTable::ColumnID::N_STDId - (int)CMaxEDSRulesDataTable::ColumnID::MIN);
- // CString sSQLCommand;
- // sSQLCommand.Format(_T("SELECT * FROM \'%s\' WHERE %s = %d AND %s = %d;"),
- // (LPCTSTR)tableInfoPtr->GetTableName(),
- // (LPCTSTR)sIncAIdColumnName,
- // a_nIncAId);
- // query = datastorePtr->QueryByCommand(sSQLCommand);
- // ASSERT(query);
- // if (!query || !query->IsValid())
- // {
- // LogErrorTrace(__FILE__, __LINE__, _T("Invalid quary command (%s)."), (LPCTSTR)sSQLCommand);
- // ASSERT(FALSE);
- // return (CDBQueryBasePtr());
- // }
- // // do the table related valid checking
- // if (query->GetColCount() != GetTableInfo()->GetColumnCount())
- // {
- // LogErrorTrace(__FILE__, __LINE__, _T("query col num value is %d, but not %d"), query->GetColCount(), GetTableInfo()->GetColumnCount());
- // ASSERT(FALSE);
- // return (CDBQueryBasePtr());
- // }
- // return query;
- //}
- #pragma endregion
- }
|