MaxEDSRulesDataDB.cpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. #include "stdafx.h"
  2. #include "MaxEDSRulesDataDB.h"
  3. #include "MaxEDSRulesDataTable.h"
  4. namespace OTSClassifyEngine
  5. {
  6. using namespace OTSSQLITE;
  7. CMaxEDSRulesDataDB::CMaxEDSRulesDataDB(CDBStoreBasePtr a_datastore)
  8. {
  9. m_tableInfo.reset(new CMaxEDSRulesDataTable());
  10. myDB = CreateNewSQLiteDB(a_datastore, m_tableInfo);
  11. }
  12. CMaxEDSRulesDataDB::~CMaxEDSRulesDataDB()
  13. {
  14. }
  15. CDBTableBasePtr CMaxEDSRulesDataDB::GetTableInfo()
  16. {
  17. /*if (!m_tableInfo)
  18. {
  19. m_tableInfo.reset(new CSTDDataTable);
  20. }*/
  21. return m_tableInfo;
  22. }
  23. BOOL CMaxEDSRulesDataDB::Init(const BOOL a_bClean /*= FALSE*/)
  24. {
  25. return myDB->Init(a_bClean);
  26. }
  27. BOOL CMaxEDSRulesDataDB::CreateTable(const BOOL a_bForce /*= FALSE*/)
  28. {
  29. return myDB->CreateTable(a_bForce);
  30. }
  31. BOOL CMaxEDSRulesDataDB::DeleteTable()
  32. {
  33. return myDB->DeleteTable();
  34. }
  35. BOOL CMaxEDSRulesDataDB::RemoveAllRows()
  36. {
  37. return myDB->RemoveAllRows();
  38. }
  39. BOOL CMaxEDSRulesDataDB::IsDBExist()
  40. {
  41. return myDB->IsDBExist();
  42. }
  43. OTSSQLITE::CDBStoreBasePtr CMaxEDSRulesDataDB::GetDatastore()
  44. {
  45. return myDB->GetDatastore();
  46. }
  47. OTSSQLITE::CDBQueryBasePtr CMaxEDSRulesDataDB::GetTableQuery(LPCTSTR a_sOrderColumnName /*= nullptr*/)
  48. {
  49. return myDB->GetTableQuery(a_sOrderColumnName);
  50. }
  51. MaxEDSRuleList CMaxEDSRulesDataDB::GetMaxEDSRulesLib(BOOL bForce /*= FALSE*/)
  52. {
  53. ParticleSTDPtr partStd = ParticleSTDPtr(new ParticleSTD());
  54. if (bForce)
  55. {
  56. partStd->MaxEDSRuleListClear();
  57. }
  58. auto query = GetTableQuery("Expression");
  59. ASSERT(query);
  60. auto MaxEDSRuleslist = ReadMaxEDSRulesList(query);
  61. /*partStd->setMaxEDSRuleList(MaxEDSRuleslist);*/
  62. //m_pOretype->SetName(_T(""));
  63. return MaxEDSRuleslist;
  64. }
  65. MaxEDSRuleList CMaxEDSRulesDataDB::ReadMaxEDSRulesList(CDBQueryBasePtr a_query)
  66. {
  67. MaxEDSRuleList listSTDItem;
  68. int nRowId = 0;
  69. int nWrongItems = 0;
  70. while (!a_query->IsEOF())
  71. {
  72. if (!ReadMaxEDSRulesItem(a_query)) //current x-ray point
  73. {
  74. LogErrorTrace(__FILE__, __LINE__, _T("Read xray point failed"));
  75. nWrongItems++;
  76. break;
  77. }
  78. listSTDItem.push_back(m_MaxEdsItem);
  79. a_query->NextRow();
  80. nRowId++;
  81. }
  82. return listSTDItem;
  83. }
  84. BOOL CMaxEDSRulesDataDB::ReadMaxEDSRulesItem(CDBQueryBasePtr a_query)
  85. {
  86. int nCol;
  87. m_MaxEdsItem = MaxEDSRulePtr(new MaxEDSRule());
  88. int nMaxEDSTime;
  89. nCol = (int)CMaxEDSRulesDataTable::ColumnID::N_MaxEDSTime - (int)CMaxEDSRulesDataTable::ColumnID::MIN;
  90. nMaxEDSTime = a_query->GetColIntValue(nCol, -1);
  91. m_MaxEdsItem->m_MaxEDSTime = nMaxEDSTime;
  92. CString sUsingElementList;
  93. nCol = (int)CMaxEDSRulesDataTable::ColumnID::S_UsingElementList - (int)CMaxEDSRulesDataTable::ColumnID::MIN;
  94. sUsingElementList = a_query->GetColStringValue(nCol, _T(""));
  95. std::vector<std::string> eleStrlist;
  96. CElementsList elelist;
  97. xmls::SplitString(sUsingElementList.GetBuffer(), eleStrlist, ",");
  98. for (auto s : eleStrlist)
  99. {
  100. CElementPtr ele = CElementPtr(new CElement(s.c_str()));
  101. elelist.push_back(ele);
  102. }
  103. m_MaxEdsItem->m_elementList = elelist;
  104. CString sUsingImgPropertyList;
  105. nCol = (int)CMaxEDSRulesDataTable::ColumnID::S_UsingImgPropertyList - (int)CMaxEDSRulesDataTable::ColumnID::MIN;
  106. sUsingImgPropertyList = a_query->GetColStringValue(nCol, _T(""));
  107. eleStrlist.clear();
  108. xmls::SplitString(sUsingImgPropertyList.GetBuffer(), eleStrlist, ",");
  109. m_MaxEdsItem->m_ImgPropertyList = eleStrlist;
  110. CString sUsingOtherPropertyList;
  111. nCol = (int)CMaxEDSRulesDataTable::ColumnID::S_UsingOtherPropertyList - (int)CMaxEDSRulesDataTable::ColumnID::MIN;
  112. sUsingOtherPropertyList = a_query->GetColStringValue(nCol, _T(""));
  113. xmls::SplitString(sUsingOtherPropertyList.GetBuffer(), eleStrlist, ",");
  114. m_MaxEdsItem->m_OtherpropertyList = eleStrlist;
  115. CString sExpression;
  116. nCol = (int)CMaxEDSRulesDataTable::ColumnID::S_Expression - (int)CMaxEDSRulesDataTable::ColumnID::MIN;
  117. sExpression = a_query->GetColStringValue(nCol, _T(""));
  118. m_MaxEdsItem->m_expressionStr = sExpression.GetString();
  119. return TRUE;
  120. }
  121. #pragma region ɾ¼õ´úÂë
  122. //MaxEDSRulePtr CMaxEDSRulesDataDB::GetSTDItemById(const long a_nIncAId)
  123. //{
  124. // MaxEDSRulePtr pSTDItem;
  125. // if (!m_listSTDItem.empty())
  126. // {
  127. // for (auto pItem : m_listSTDItem)
  128. // {
  129. // if (pItem->GetSTDId() == (DWORD)a_nIncAId)
  130. // {
  131. // pSTDItem = pItem;
  132. // }
  133. // }
  134. // }
  135. // else
  136. // {
  137. // auto tableQuery = GetQueryById(a_nIncAId);
  138. // ASSERT(tableQuery);
  139. // if (!tableQuery)
  140. // {
  141. // return pSTDItem;
  142. // }
  143. // if (!ReadSTDItem(tableQuery))
  144. // {
  145. // LogErrorTrace(__FILE__, __LINE__, _T("read x-ray failed."));
  146. // return pSTDItem;
  147. // }
  148. // pSTDItem = MaxEDSRulePtr(new MaxEDSRule(*m_pSTDItem.get()));
  149. // }
  150. // return pSTDItem;
  151. //}
  152. //MaxEDSRuleList& CMaxEDSRulesDataDB::GetSTDItemList(const BOOL a_bForce/* = FALSE*/)
  153. //{
  154. // if (a_bForce)
  155. // {
  156. // m_listSTDItem.clear();
  157. // }
  158. // if (m_listSTDItem.size() == 0)
  159. // {
  160. // ReadSTDItemList();
  161. // }
  162. // return m_listSTDItem;
  163. //}
  164. //BOOL CMaxEDSRulesDataDB::ReadSTDItemList()
  165. //{
  166. // auto tableInfoPtr = GetTableInfo();
  167. // ASSERT(tableInfoPtr);
  168. // if (!tableInfoPtr)
  169. // {
  170. // return FALSE;
  171. // }
  172. // auto query = GetTableQuery();
  173. // ASSERT(query);
  174. // if (!query)
  175. // {
  176. // return FALSE;
  177. // }
  178. // m_listSTDItem = ReadSTDItemList(query);
  179. // return TRUE;
  180. //}
  181. //CDBQueryBasePtr CMaxEDSRulesDataDB::GetQueryById(const long a_nIncAId)
  182. //{
  183. // CDBQueryBasePtr query;
  184. // auto datastorePtr = GetDatastore();
  185. // ASSERT(datastorePtr);
  186. // if (!datastorePtr)
  187. // {
  188. // return query;
  189. // }
  190. // auto tableInfoPtr = GetTableInfo();
  191. // ASSERT(tableInfoPtr);
  192. // if (!tableInfoPtr)
  193. // {
  194. // return query;
  195. // }
  196. // CString sIncAIdColumnName = tableInfoPtr->GetColumnName((int)CMaxEDSRulesDataTable::ColumnID::N_STDId - (int)CMaxEDSRulesDataTable::ColumnID::MIN);
  197. // CString sSQLCommand;
  198. // sSQLCommand.Format(_T("SELECT * FROM \'%s\' WHERE %s = %d AND %s = %d;"),
  199. // (LPCTSTR)tableInfoPtr->GetTableName(),
  200. // (LPCTSTR)sIncAIdColumnName,
  201. // a_nIncAId);
  202. // query = datastorePtr->QueryByCommand(sSQLCommand);
  203. // ASSERT(query);
  204. // if (!query || !query->IsValid())
  205. // {
  206. // LogErrorTrace(__FILE__, __LINE__, _T("Invalid quary command (%s)."), (LPCTSTR)sSQLCommand);
  207. // ASSERT(FALSE);
  208. // return (CDBQueryBasePtr());
  209. // }
  210. // // do the table related valid checking
  211. // if (query->GetColCount() != GetTableInfo()->GetColumnCount())
  212. // {
  213. // LogErrorTrace(__FILE__, __LINE__, _T("query col num value is %d, but not %d"), query->GetColCount(), GetTableInfo()->GetColumnCount());
  214. // ASSERT(FALSE);
  215. // return (CDBQueryBasePtr());
  216. // }
  217. // return query;
  218. //}
  219. #pragma endregion
  220. }