BatchManager.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #include "stdafx.h"
  2. #include "BatchManager.h"
  3. #include "Bantch.h"
  4. #include "ServerConfig.h"
  5. #include "TemplateManager.h"
  6. #include "ImgUploadManager.h"
  7. #include "ImgUploader.h"
  8. #include "resource.h"
  9. std::string g_appFilePathName;
  10. CBatchManager::CBatchManager()
  11. :m_bOnlineCard(false)
  12. {
  13. m_nOnlineScanType = -1;
  14. m_nSubjectID = 0;
  15. InitializeCriticalSection(&database_db_lock);
  16. }
  17. CBatchManager::~CBatchManager()
  18. {
  19. DeleteCriticalSection(&database_db_lock);
  20. }
  21. boost::shared_ptr<CBatchManager> CBatchManager::Get()
  22. {
  23. static boost::shared_ptr<CBatchManager> instance(new CBatchManager());
  24. return instance;
  25. }
  26. boost::shared_ptr<CBatch>& CBatchManager::createNewBatch()
  27. {
  28. if (currentBatch.get()){
  29. GiveUpCurrentBatch();
  30. }
  31. currentBatch.reset(new CBatch(m_bOnlineCard, m_nSubjectID, m_nOnlineScanType));
  32. currentBatch->SetDataBaseManager(&database_db_lock, &database_db, 0);
  33. return currentBatch;
  34. }
  35. int CBatchManager::GiveUpCurrentBatch()
  36. {
  37. int ret = 0;
  38. if (currentBatch.get()){
  39. ret=currentBatch->GiveUpCurrentBatch();
  40. }
  41. currentBatch.reset();
  42. return ret;
  43. }
  44. boost::shared_ptr<CBatch>& CBatchManager::GetCurrentBatch()
  45. {
  46. return currentBatch;
  47. }
  48. void CBatchManager::initalize(bool bOnlineCard, int subjectid, int nOnlineScanType)
  49. {
  50. m_bOnlineCard = bOnlineCard;
  51. m_nSubjectID = subjectid;
  52. m_nOnlineScanType = nOnlineScanType;
  53. sqlite3_config(SQLITE_CONFIG_SERIALIZED);
  54. CString path = CServerConfig::app_data_dir + _T("\\index.db3");
  55. if (!PathFileExists(path)){ CTemplateManager::ExtractResourceToFile(_T("database"), IDR_DATABASE_INDEX, path); }
  56. char db_file_name[520];
  57. WideCharToMultiByte(CP_UTF8, 0, path, -1, db_file_name, 520, NULL, NULL);
  58. database_db.open(db_file_name);
  59. database_db.execDML("pragma journal_mode = MEMORY");
  60. CImgUploadManager::GetInstance()->GetImgUploader()->SetDataBaseManager(&database_db_lock, &database_db, 0);
  61. }
  62. int CBatchManager::leaveCurrentBatch()
  63. {
  64. currentBatch->leaveCurrentBatch();
  65. currentBatch.reset();
  66. return 0;
  67. }