AppGlobalF.cpp 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "AppGlobalF.h"
  5. #include "ITSDbF.h"
  6. #include <inifiles.hpp>
  7. //---------------------------------------------------------------------------
  8. #pragma package(smart_init)
  9. //---------------------------------------------------------------------------
  10. String CenterCd = ""; // 지역센터 코드
  11. String CenterId = ""; // 지역센터 아이디
  12. String CenterName = ""; // 지역센터 명칭
  13. int g_nPid = -1; // Application Process ID
  14. String g_sAppDir = ""; // Application Directory
  15. String g_sAppName= ""; // Program name
  16. String g_sCfgDir = ""; // Config File Directory
  17. String g_sLogDir = ""; // Program Log Directory
  18. String g_sTempDir = ""; // Program Temp Directory
  19. String g_sFormsDir = ""; // Program Forms Directory
  20. String g_sLangDir = "";
  21. APP_CONFIG g_AppCfg;
  22. LOG_INFO g_LogCfg;
  23. TITSLog *ITSLog = NULL;
  24. //---------------------------------------------------------------------------
  25. void LoadIcon(TIniFile* AIniFile, String ASection, String AItem, String& AValue)
  26. {
  27. try
  28. {
  29. AValue = AIniFile->ReadString(ASection, AItem, "");
  30. if (AValue != "")
  31. {
  32. AValue = g_sAppDir + "Image\\" + AValue;
  33. if (!FileExists(AValue)) AValue = "";
  34. }
  35. }
  36. catch(Exception &e)
  37. {
  38. }
  39. }
  40. //---------------------------------------------------------------------------
  41. bool LoadDefaultConfigInfo(String ACfgFile/*=""*/)
  42. {
  43. String sCfgFile;
  44. TIniFile *pIniFile = NULL;
  45. String sIniFile = ChangeFileExt(ExtractFileName(Application->ExeName), ".ini");
  46. if (!ACfgFile.IsEmpty())
  47. sIniFile = ACfgFile + ".ini";
  48. sCfgFile = g_sCfgDir + sIniFile;
  49. g_AppCfg.sConfigFile = sCfgFile;
  50. g_AppCfg.thr.pThread = NULL;
  51. g_AppCfg.thr.dwThreadId = 0;
  52. g_AppCfg.thr.nHandle = 0;
  53. g_AppCfg.thr.bRunning = false;
  54. g_AppCfg.bAppClose = false;
  55. pIniFile = new TIniFile(sCfgFile);
  56. try
  57. {
  58. g_AppCfg.sTitle = pIniFile->ReadString("APPLICATION", "TITLE", "교통정보시스템 통합 운영단말");
  59. g_AppCfg.sProcessId = pIniFile->ReadString("APPLICATION", "PROCESSID", "OPER01");
  60. g_AppCfg.sLogDay = pIniFile->ReadString("APPLICATION", "LOGDAY", "");
  61. g_AppCfg.sAppPath = pIniFile->ReadString("APPLICATION", "APP_PATH", "");
  62. g_AppCfg.sSkinName = pIniFile->ReadString("APPLICATION", "SKINNAME", "Blue");
  63. g_AppCfg.bSaveForm = pIniFile->ReadString("APPLICATION", "SAVEFORM", "1").ToIntDef(1) == 1 ? true : false;
  64. g_AppCfg.bLoginPrompt = pIniFile->ReadString("APPLICATION", "LOGINPROMPT", "1").ToIntDef(1) == 1 ? true : false;
  65. g_AppCfg.bDebug = pIniFile->ReadString("APPLICATION", "DEBUG", "0").ToIntDef(0) == 1 ? true : false;
  66. g_AppCfg.sDefUseId = pIniFile->ReadString("APPLICATION", "LASTUSER", "");
  67. g_AppCfg.sLang = pIniFile->ReadString("APPLICATION", "LANGUAGE", "kr").LowerCase();
  68. if (g_AppCfg.sLang != "en" && g_AppCfg.sLang != "kr") g_AppCfg.sLang = "kr";
  69. g_AppCfg.itsdb.bSqlLog = pIniFile->ReadString("ITSDB", "SQLLOG", "0").ToIntDef(0) == 1 ? true : false;
  70. g_AppCfg.itsdb.sConnectStr = pIniFile->ReadString("ITSDB", "CONNECTSTR", "");
  71. if (g_AppCfg.itsdb.sConnectStr == "")
  72. {
  73. g_AppCfg.itsdb.sProvider = pIniFile->ReadString("ITSDB", "PROVIDER", "OraOLEDB.Oracle.1");
  74. g_AppCfg.itsdb.sServerName = pIniFile->ReadString("ITSDB", "SERVERNAME", "HANTE");
  75. g_AppCfg.itsdb.sUserName = pIniFile->ReadString("ITSDB", "USERNAME", "hnits");
  76. g_AppCfg.itsdb.sPassword = pIniFile->ReadString("ITSDB", "PASSWORD", "hnits");
  77. }
  78. //시설물 온도알람을 사용하지 않는경우 100도가 되기때문에 실제적으로 알람이 발생하지 않는 효과가 있음
  79. //즉, 온도이상알람을 원하는 경우에만 알람값을 설정하여 사용하면 됨
  80. g_AppCfg.Temp.AlarmValue = pIniFile->ReadString("TEMPERATURE", "ALARMVALUE", "100").ToIntDef(100); //45
  81. //영상미표출시 대체이미지
  82. LoadIcon(pIniFile, "CCTV", "CAMERA_EMPTY", g_AppCfg.sEmptyImg);
  83. }
  84. __finally
  85. {
  86. if (pIniFile) delete pIniFile;
  87. pIniFile = NULL;
  88. }
  89. return true;
  90. }
  91. //---------------------------------------------------------------------------
  92. /*
  93. * 환경설정 정보를 저장하는 함수.
  94. * arguments
  95. * String : RegisterKey 또는 파일이름
  96. * return
  97. * bool : 실패하면 false
  98. */
  99. bool WriteConfigInfo(String sCfgFile, String sTitle, String sItem, String sValue)
  100. {
  101. String ConfigFile;
  102. TIniFile *pIniFile = NULL;
  103. ConfigFile = sCfgFile;
  104. try
  105. {
  106. pIniFile = new TIniFile(ConfigFile);
  107. if (pIniFile == NULL)
  108. {
  109. return false;
  110. }
  111. pIniFile->WriteString(sTitle, sItem, sValue);
  112. }
  113. catch(...)
  114. {
  115. }
  116. if (pIniFile)
  117. {
  118. pIniFile->Free();
  119. pIniFile = NULL;
  120. }
  121. return true;
  122. }
  123. //---------------------------------------------------------------------------
  124. /*
  125. * 환경설정 정보를 읽어오는 함수.
  126. * arguments
  127. * String : RegisterKey 또는 파일이름
  128. * return
  129. * bool : 실패하면 false
  130. */
  131. bool ReadConfigInfo(String sCfgFile, String sTitle, String sItem, String &sValue)
  132. {
  133. bool bRes;
  134. String ConfigFile;
  135. TIniFile *pIniFile = NULL;
  136. bRes = false;
  137. ConfigFile = sCfgFile;
  138. try
  139. {
  140. pIniFile = new TIniFile(ConfigFile);
  141. if (pIniFile == NULL)
  142. {
  143. return bRes;
  144. }
  145. sValue = pIniFile->ReadString(sTitle, sItem, "");
  146. if (sValue != "")
  147. {
  148. bRes = true;
  149. }
  150. }
  151. catch(...)
  152. {
  153. }
  154. if (pIniFile)
  155. {
  156. pIniFile->Free();
  157. pIniFile = NULL;
  158. }
  159. return bRes;
  160. }
  161. //---------------------------------------------------------------------------
  162. void ShowErrorMsg(String ATitle, String AErrMsg)
  163. {
  164. Application->NormalizeTopMosts();
  165. Application->MessageBox(AErrMsg.c_str(), ATitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
  166. Application->RestoreTopMosts();
  167. }
  168. //----------------------------------------------------------------------------
  169. ULONG ProcIDFromWnd(HWND hwnd) // 윈도우 핸들로 프로세스 아이디 얻기
  170. {
  171. ULONG idProc;
  172. GetWindowThreadProcessId( hwnd, &idProc );
  173. return idProc;
  174. }
  175. //----------------------------------------------------------------------------
  176. HWND GetWinHandle(ULONG pid) // 프로세스 아이디로 윈도우 핸들 얻기
  177. {
  178. HWND tempHwnd = FindWindow(NULL,NULL); // 최상위 윈도우 핸들 찾기
  179. while( tempHwnd != NULL )
  180. {
  181. if( GetParent(tempHwnd) == NULL ) // 최상위 핸들인지 체크, 버튼 등도 핸들을 가질 수 있으므로 무시하기 위해
  182. if( pid == ProcIDFromWnd(tempHwnd) )
  183. return tempHwnd;
  184. tempHwnd = GetWindow(tempHwnd, GW_HWNDNEXT); // 다음 윈도우 핸들 찾기
  185. }
  186. return NULL;
  187. }
  188. //----------------------------------------------------------------------------
  189. TColor g_DispColor[MAX_DISPCOLOR];
  190. void APP_InitDisplayColor()
  191. {
  192. g_DispColor[ 0] = Graphics::clBlue;
  193. g_DispColor[ 1] = Graphics::clRed;
  194. g_DispColor[ 2] = Graphics::clLime;
  195. g_DispColor[ 3] = Graphics::clMaroon;
  196. g_DispColor[ 4] = Graphics::clGreen;
  197. g_DispColor[ 5] = Graphics::clMenuHighlight;
  198. g_DispColor[ 6] = Graphics::clBackground;
  199. g_DispColor[ 7] = Graphics::clPurple;
  200. g_DispColor[ 8] = Graphics::clTeal;
  201. g_DispColor[ 9] = Graphics::clYellow;
  202. g_DispColor[10] = Graphics::clFuchsia;
  203. g_DispColor[11] = Graphics::clAqua;
  204. g_DispColor[12] = Graphics::clMoneyGreen;
  205. g_DispColor[13] = Graphics::clSkyBlue;
  206. g_DispColor[14] = Graphics::clRed;
  207. g_DispColor[15] = Graphics::clLime;
  208. g_DispColor[16] = Graphics::clYellow;
  209. g_DispColor[17] = Graphics::clBlue;
  210. g_DispColor[18] = Graphics::clFuchsia;
  211. g_DispColor[19] = Graphics::clAqua;
  212. g_DispColor[20] = Graphics::clMoneyGreen;
  213. g_DispColor[21] = Graphics::clActiveCaption;
  214. }
  215. //---------------------------------------------------------------------------
  216. TColor APP_GetDisplayColor(int ASeq)
  217. {
  218. return g_DispColor[ASeq % MAX_DISPCOLOR];
  219. }
  220. //---------------------------------------------------------------------------