stdafx.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // stdafx.cpp : 只包括标准包含文件的源文件
  2. // SmartEvaluationLogic.pch 将作为预编译头
  3. // stdafx.obj 将包含预编译类型信息
  4. #include "stdafx.h"
  5. #include "basic_struct.h"
  6. void GetCurrentModuleDir( CString& modulDir )
  7. {
  8. CString path;
  9. GetModuleFileName(NULL,path.GetBufferSetLength(MAX_PATH+1),MAX_PATH);
  10. path.ReleaseBuffer();
  11. int pos = path.ReverseFind('\\');
  12. modulDir = path.Left(pos);
  13. }
  14. CString GetTimeString()
  15. {
  16. CString time_string;
  17. SYSTEMTIME systime;
  18. GetLocalTime(&systime);
  19. time_string.Format(_T("%4d%02d%02d%02d%02d%02d%03d"),systime.wYear,
  20. systime.wMonth,
  21. systime.wDay,
  22. systime.wHour,
  23. systime.wMinute,
  24. systime.wSecond,
  25. systime.wMilliseconds);
  26. return time_string;
  27. }
  28. void split( const std::string& s, const std::string& delim,std::vector< std::string >* ret )
  29. {
  30. size_t last = 0;
  31. size_t index=s.find_first_of(delim,last);
  32. while (index!=std::string::npos)
  33. {
  34. ret->push_back(s.substr(last,index-last));
  35. last=index+1;
  36. index=s.find_first_of(delim,last);
  37. }
  38. if (index-last>0)
  39. {
  40. ret->push_back(s.substr(last,index-last));
  41. }
  42. }
  43. void updatefile(CppSQLite3DB* bantch_db,long student_paper_id,const std::string & norimg_dir,const std::string & excimg_dir){
  44. char sql5[512];
  45. sprintf_s(sql5,"select * from student_paper sp where sp.student_paper_id =%d",student_paper_id);
  46. CppSQLite3Query query_s =bantch_db->execQuery(sql5);
  47. if(!query_s.eof()){
  48. long paper_state=query_s.getInt64Field("paper_state");
  49. const char * student_code=query_s.getStringField("student_code");
  50. sprintf_s(sql5,"select * from page p where p.student_paper_id =%d",student_paper_id);
  51. CppSQLite3Query query_p =bantch_db->execQuery(sql5);
  52. CppSQLite3Statement stmt = bantch_db->compileStatement("update page set img_path =:img_path where page_id =:page_id");
  53. while(!query_p.eof()){
  54. std::string img_path=query_p.getStringField("img_path");
  55. int page_id=query_p.getIntField("page_id");
  56. int phy_number=atoi(query_p.getStringField("phy_number"));
  57. int page_index=query_p.getIntField("page_index");
  58. int index_dirspeator=img_path.find_last_of('\\');
  59. int index_dot=img_path.find_last_of('.');
  60. std::string dir = img_path.substr(0,index_dirspeator);
  61. std::string filename =img_path.substr(index_dirspeator,img_path.length()-index_dirspeator);
  62. std::string extname =index_dot>index_dirspeator?img_path.substr(index_dot,img_path.length()-index_dot):".jpg";
  63. std::string dir_new=(paper_state&(MEX_YICHANG))?excimg_dir:norimg_dir;
  64. char filename_new[512];
  65. if(paper_state&(MEX_YICHANG)){
  66. sprintf_s(filename_new, "%06d%s",phy_number,extname.c_str());
  67. }else{
  68. sprintf_s(filename_new, "%s_%01d_%06d%s",student_code,page_index,phy_number,extname.c_str());
  69. }
  70. std::string img_path_new =dir_new+"\\"+filename_new;
  71. if(dir!=dir_new){
  72. MoveFile(CString(img_path.c_str()),CString(img_path_new.c_str()));
  73. stmt.bind(":img_path",img_path_new.c_str());
  74. stmt.bind(":page_id",page_id);
  75. stmt.execDML();
  76. }else if(filename != filename_new){
  77. rename(img_path.c_str(),img_path_new.c_str());
  78. stmt.bind(":img_path",img_path_new.c_str());
  79. stmt.bind(":page_id",page_id);
  80. stmt.execDML();
  81. }
  82. query_p.nextRow();
  83. }
  84. }
  85. }
  86. void setRunUploadFlag(CString str)
  87. {
  88. TCHAR FilePath[MAX_PATH];
  89. GetModuleFileName(NULL, FilePath, MAX_PATH);
  90. (_tcsrchr(FilePath, '\\'))[0] = 0;
  91. (_tcsrchr(FilePath, '\\'))[1] = 0;
  92. lstrcat(FilePath, _T("config.ini"));
  93. //MessageBox(NULL, FilePath,str , MB_OK);
  94. WritePrivateProfileString(L"THIRD", L"uploadflag", str, FilePath);
  95. }
  96. void setRunFlag(CString str)
  97. {
  98. TCHAR FilePath[MAX_PATH];
  99. GetModuleFileName(NULL, FilePath, MAX_PATH);
  100. (_tcsrchr(FilePath, '\\'))[0] = 0;
  101. (_tcsrchr(FilePath, '\\'))[1] = 0;
  102. lstrcat(FilePath, _T("config.ini"));
  103. //MessageBox(NULL, FilePath,str , MB_OK);
  104. WritePrivateProfileString(L"THIRD", L"flag", str, FilePath);
  105. }
  106. CString getRunFlag()
  107. {
  108. TCHAR FilePath[MAX_PATH];
  109. GetModuleFileName(NULL, FilePath, MAX_PATH);
  110. (_tcsrchr(FilePath, '\\'))[0] = 0;
  111. (_tcsrchr(FilePath, '\\'))[1] = 0;
  112. lstrcat(FilePath, _T("config.ini"));
  113. TCHAR wcharFlag[10];
  114. GetPrivateProfileString(L"THIRD", L"flag", L"0", wcharFlag, 10, FilePath);
  115. CString temp;
  116. temp = wcharFlag;
  117. return temp;
  118. }