CctvOprCtrl.cpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <tchar.h>
  5. #include <cxFormats.hpp>
  6. //---------------------------------------------------------------------------
  7. #include "AppGlobalF.h"
  8. #include "ITSDbF.h"
  9. #include "ITSLangTransF.h"
  10. //---------------------------------------------------------------------------
  11. USEFORM("..\CctvOprMain\PLUGIN\CTV0500M\CTV0500MF.cpp", CTV0500M);
  12. USEFORM("MAIN\FrmCctvCtrlF.cpp", FrmCctvCtrl);
  13. USEFORM("MAIN\FrmResourceF.cpp", FrmLang);
  14. USEFORM("..\CctvOprMain\PLUGIN\00.FRAME\FRAME_CctvStateListF.cpp", FRAMECctvStateList); /* TFrame: File Type */
  15. //---------------------------------------------------------------------------
  16. WINAPI _tWinMain(HINSTANCE, HINSTANCE, LPTSTR, int)
  17. {
  18. int nLoginRes;
  19. DateSeparator = '-';
  20. TimeSeparator = ':';
  21. ShortDateFormat ="yyyy-MM-dd";
  22. ShortTimeFormat = "hh:nn:ss";
  23. LongTimeFormat = "hh:nn:ss";
  24. cxFormatController()->BeginUpdate();
  25. cxFormatController()->UseDelphiDateTimeFormats = true;
  26. cxFormatController()->EndUpdate();
  27. cxFormatController()->GetFormats();
  28. cxFormatController()->NotifyListeners();
  29. String sLoginId = "ADMIN";
  30. bool bLogin = true;
  31. int nArgs = ParamCount();
  32. if (nArgs >= 1)
  33. {
  34. sLoginId = ParamStr(1);
  35. bLogin = false;
  36. }
  37. bLogin = false;
  38. int nRes;
  39. g_nPid = (int)GetCurrentProcessId();
  40. g_sAppDir = ExtractFilePath(Application->ExeName);
  41. g_sAppName = ChangeFileExt(ExtractFileName(Application->ExeName), "");
  42. g_sCfgDir = g_sAppDir + "Cfg\\";
  43. g_sLogDir = g_sAppDir + "Log\\";
  44. g_sTempDir = g_sAppDir + "Temp\\";
  45. g_sFormsDir = g_sCfgDir + "Forms\\";
  46. ForceDirectories(g_sCfgDir.c_str());
  47. ForceDirectories(g_sLogDir.c_str());
  48. ForceDirectories(g_sTempDir.c_str());
  49. ForceDirectories(g_sFormsDir.c_str());
  50. String sTempDir = g_sLogDir + "Db\\";
  51. ForceDirectories(sTempDir.c_str());
  52. String sAppDir = ExtractFilePath(Application->ExeName);
  53. ChDir(sAppDir);
  54. HANDLE hMutex;
  55. try
  56. {
  57. String sLockFile = ChangeFileExt(ExtractFileName(Application->ExeName), ".lock");
  58. String sProgMutexNm = "HANTE_POHANG_" + sLockFile;
  59. if ((hMutex=OpenMutex(MUTEX_ALL_ACCESS, false, sProgMutexNm.c_str()))==NULL)
  60. hMutex = CreateMutex(NULL, true, sProgMutexNm.c_str());
  61. else
  62. {
  63. if (g_AppCfg.sLang == "kr")
  64. {
  65. Application->MessageBox(L"CCTV 제어 프로그램이 이미 실행중입니다.\r\n작업관리자의 프로세스 목록에서 프로그램을 종료후 실행해 주십시오.",
  66. L"프로그램 시작 오류!!!",
  67. MB_OK|MB_ICONERROR);
  68. }
  69. else
  70. {
  71. Application->MessageBox(L"The CCTV Control terminal program is already running.\r\nPlease exit the program from the process list of Task Manager and execute it.",
  72. L"Program Start Error!!!",
  73. MB_OK|MB_ICONERROR);
  74. }
  75. return 0;
  76. }
  77. }
  78. catch (Exception &exception)
  79. {
  80. Application->ShowException(&exception);
  81. return 0;
  82. }
  83. /*
  84. * 시스템 운영환경을 ini 파일에서 읽어 온다.
  85. */
  86. LoadDefaultConfigInfo("ITS_OP");
  87. g_sLangDir = g_sAppDir + "Lang\\";
  88. g_sLangDir = g_sLangDir + g_AppCfg.sLang + "\\";
  89. ForceDirectories(g_sLangDir.c_str());
  90. LangTrans = new TLangTrans("CctvOprCtrl", g_AppCfg.sLang, g_sLangDir, true);
  91. //CommLog = new TCommLog(g_sLogDir, g_sAppName, g_AppCfg.sLogDay);
  92. ITSLog = new TITSLog(g_sLogDir, g_sAppName, g_AppCfg.sLogDay);
  93. ITSLog->FLogCfg = g_LogCfg;
  94. LOGINFO("Program start....");
  95. if (!ITSDb_Initialize())
  96. {
  97. if (g_AppCfg.sLang == "kr")
  98. {
  99. Application->MessageBox(L"Database 자원을 시스템으로부터 얻지 못했습니다.\r\n\r\n프로그램을 종료합니다.",
  100. L"프로그램 시작 오류!!!",
  101. MB_OK|MB_ICONERROR);
  102. }
  103. else
  104. {
  105. Application->MessageBox(L"Database resource could not be obtained from the system.\r\n\r\nExit the program.",
  106. L"Program Start Error!!!",
  107. MB_OK|MB_ICONERROR);
  108. }
  109. goto prog_exit;
  110. }
  111. ITSDb_SetInfo(g_AppCfg.itsdb.sProvider, g_AppCfg.itsdb.sServerName, g_AppCfg.itsdb.sUserName, g_AppCfg.itsdb.sPassword);
  112. g_AppCfg.bLoginPrompt = bLogin;
  113. if (g_AppCfg.bLoginPrompt)
  114. {
  115. /*
  116. * 로그인 처리(라이브러리 로딩 실패시에만 프로그램을 종료하자-일단...)
  117. */
  118. g_AppCfg.sSkinName = "Blue";
  119. #if 0
  120. nLoginRes = UserLogin();
  121. if (nLoginRes <= 0)
  122. {
  123. goto prog_exit;
  124. }
  125. #endif
  126. }
  127. else
  128. {
  129. if (!ITSDb_Open())
  130. {
  131. if (g_AppCfg.sLang == "kr")
  132. {
  133. Application->MessageBox(L"데이터베이스 접속에 실패하였습니다.\r\n\r\n프로그램을 종료합니다.",
  134. L"프로그램 시작 오류!!!",
  135. MB_OK|MB_ICONERROR);
  136. }
  137. else
  138. {
  139. Application->MessageBox(L"Database connection failed.\r\n\r\nExit the program.",
  140. L"Program Start Error!!!",
  141. MB_OK|MB_ICONERROR);
  142. }
  143. goto prog_exit;
  144. }
  145. g_pLOGIN = ITSDb_GetLoginInfo();
  146. g_pLOGIN->bLogin = true;
  147. g_pLOGIN->sUserId = sLoginId;
  148. g_pLOGIN->sUserName = "default";
  149. g_pLOGIN->sUserRightId = "1";
  150. g_pLOGIN->sUserRightName = "";
  151. g_pLOGIN->sConnSystem = "OPR";
  152. g_pLOGIN->sLoginSeq = "0";
  153. g_pLOGIN->sLoginIp = "127.0.0.1";
  154. g_pLOGIN->sLoginTime = Now().FormatString("yyyymmddhhnnss");
  155. }
  156. try
  157. {
  158. ReportMemoryLeaksOnShutdown = true;
  159. Application->Initialize();
  160. Application->MainFormOnTaskBar = true;
  161. Application->Title = g_AppCfg.sTitle;
  162. Application->Title = "CCTV 제어";
  163. Application->CreateForm(__classid(TFrmCctvCtrl), &FrmCctvCtrl);
  164. Application->CreateForm(__classid(TFrmLang), &FrmLang);
  165. Application->Run();
  166. }
  167. catch (Exception &exception)
  168. {
  169. Application->ShowException(&exception);
  170. }
  171. catch (...)
  172. {
  173. try
  174. {
  175. throw Exception("");
  176. }
  177. catch (Exception &exception)
  178. {
  179. Application->ShowException(&exception);
  180. }
  181. }
  182. prog_exit:
  183. try
  184. {
  185. ITSDb_Finalize();
  186. ReleaseMutex(hMutex);
  187. CloseHandle(hMutex);
  188. hMutex = NULL;
  189. LOGINFO("Program end....");
  190. }
  191. catch(...)
  192. {
  193. }
  194. return 0;
  195. }
  196. //---------------------------------------------------------------------------