VdsOprMain.cpp 7.2 KB

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