#include "stdafx.h" #include "BatchManager.h" #include "Bantch.h" #include "ServerConfig.h" #include "TemplateManager.h" #include "ImgUploadManager.h" #include "ImgUploader.h" #include "resource.h" std::string g_appFilePathName; CBatchManager::CBatchManager() :m_bOnlineCard(false) { m_nOnlineScanType = -1; m_nSubjectID = 0; InitializeCriticalSection(&database_db_lock); } CBatchManager::~CBatchManager() { DeleteCriticalSection(&database_db_lock); } boost::shared_ptr CBatchManager::Get() { static boost::shared_ptr instance(new CBatchManager()); return instance; } boost::shared_ptr& CBatchManager::createNewBatch() { if (currentBatch.get()){ GiveUpCurrentBatch(); } currentBatch.reset(new CBatch(m_bOnlineCard, m_nSubjectID, m_nOnlineScanType)); currentBatch->SetDataBaseManager(&database_db_lock, &database_db, 0); return currentBatch; } int CBatchManager::GiveUpCurrentBatch() { int ret = 0; if (currentBatch.get()){ ret=currentBatch->GiveUpCurrentBatch(); } currentBatch.reset(); return ret; } boost::shared_ptr& CBatchManager::GetCurrentBatch() { return currentBatch; } void CBatchManager::initalize(bool bOnlineCard, int subjectid, int nOnlineScanType) { m_bOnlineCard = bOnlineCard; m_nSubjectID = subjectid; m_nOnlineScanType = nOnlineScanType; sqlite3_config(SQLITE_CONFIG_SERIALIZED); CString path = CServerConfig::app_data_dir + _T("\\index.db3"); if (!PathFileExists(path)){ CTemplateManager::ExtractResourceToFile(_T("database"), IDR_DATABASE_INDEX, path); } char db_file_name[520]; WideCharToMultiByte(CP_UTF8, 0, path, -1, db_file_name, 520, NULL, NULL); database_db.open(db_file_name); database_db.execDML("pragma journal_mode = MEMORY"); CImgUploadManager::GetInstance()->GetImgUploader()->SetDataBaseManager(&database_db_lock, &database_db, 0); } int CBatchManager::leaveCurrentBatch() { currentBatch->leaveCurrentBatch(); currentBatch.reset(); return 0; }