AppGlobalF.cpp 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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.AutoLogout.Enabled = false;
  51. g_AppCfg.AutoLogout.IntervalMin = 0;
  52. g_AppCfg.AutoLogout.LogoutExit = false;
  53. g_AppCfg.thr.pThread = NULL;
  54. g_AppCfg.thr.dwThreadId = 0;
  55. g_AppCfg.thr.nHandle = 0;
  56. g_AppCfg.thr.bRunning = false;
  57. g_AppCfg.bAppClose = false;
  58. try
  59. {
  60. String sTmp;
  61. pIniFile = new TIniFile(sCfgFile);
  62. g_AppCfg.sTitle = pIniFile->ReadString("APPLICATION", "TITLE", "광역교통정보 교통관리시스템");
  63. g_AppCfg.sProcessId = pIniFile->ReadString("APPLICATION", "PROCESSID", "999999");
  64. g_AppCfg.sLogDay = pIniFile->ReadString("APPLICATION", "LOGDAY", "");
  65. g_AppCfg.sAppPath = pIniFile->ReadString("APPLICATION", "APP_PATH", "");
  66. g_AppCfg.sSkinName = pIniFile->ReadString("APPLICATION", "SKINNAME", "Black");
  67. if (g_AppCfg.sSkinName.IsEmpty()) g_AppCfg.sSkinName = "Blue";
  68. sTmp = pIniFile->ReadString("APPLICATION", "SAVEFORM", "1");
  69. g_AppCfg.bSaveForm = (sTmp == "1") ? true : false;
  70. sTmp = "1";
  71. sTmp = pIniFile->ReadString("APPLICATION", "LOGINPROMPT", "1");
  72. g_AppCfg.bLoginPrompt = (sTmp == "1") ? true : false;
  73. g_AppCfg.sDefUseId = pIniFile->ReadString("APPLICATION", "LASTUSER", "");
  74. g_AppCfg.sLang = pIniFile->ReadString("APPLICATION", "LANGUAGE", "kr");
  75. g_AppCfg.sLang = g_AppCfg.sLang.LowerCase();
  76. if (g_AppCfg.sLang != "en" && g_AppCfg.sLang != "kr")
  77. g_AppCfg.sLang = "kr";
  78. g_AppCfg.bDebug = false;
  79. sTmp = pIniFile->ReadString("APPLICATION", "DEBUG", "0");
  80. if (sTmp == "1") g_AppCfg.bDebug = true;
  81. String sSqlLog;
  82. g_AppCfg.itsdb.bSqlLog = false;
  83. g_AppCfg.itsdb.sProvider = pIniFile->ReadString("ITSDB", "PROVIDER", "OraOLEDB.Oracle.1");
  84. g_AppCfg.itsdb.sServerName = pIniFile->ReadString("ITSDB", "SERVERNAME", "HANTE");
  85. g_AppCfg.itsdb.sUserName = pIniFile->ReadString("ITSDB", "USERNAME", "hnits");
  86. g_AppCfg.itsdb.sPassword = pIniFile->ReadString("ITSDB", "PASSWORD", "hnits");
  87. //sSqlLog = pIniFile->ReadString("ITSDB", "SQLLOG", "0");
  88. //if (sSqlLog == "1") g_AppCfg.itsdb.bSqlLog = true;
  89. LoadIcon(pIniFile, "CCTV", "CAMERA_EMPTY", g_AppCfg.sEmptyImg);
  90. CenterId = pIniFile->ReadString("CENTER", "CENTERID", "L01");
  91. CenterName = pIniFile->ReadString("CENTER", "CENTERNAME", "중앙센터");
  92. CenterCd = String(StrToInt(CenterId.SubString(2, 2)));
  93. }
  94. __finally
  95. {
  96. if (pIniFile) delete pIniFile;
  97. pIniFile = NULL;
  98. }
  99. return true;
  100. }
  101. //---------------------------------------------------------------------------
  102. /*
  103. * 환경설정 정보를 저장하는 함수.
  104. * arguments
  105. * String : RegisterKey 또는 파일이름
  106. * return
  107. * bool : 실패하면 false
  108. */
  109. bool WriteConfigInfo(String sCfgFile, String sTitle, String sItem, String sValue)
  110. {
  111. String ConfigFile;
  112. TIniFile *pIniFile = NULL;
  113. ConfigFile = sCfgFile;
  114. try
  115. {
  116. pIniFile = new TIniFile(ConfigFile);
  117. if (pIniFile == NULL)
  118. {
  119. return false;
  120. }
  121. pIniFile->WriteString(sTitle, sItem, sValue);
  122. }
  123. catch(...)
  124. {
  125. }
  126. if (pIniFile)
  127. {
  128. pIniFile->Free();
  129. pIniFile = NULL;
  130. }
  131. return true;
  132. }
  133. //---------------------------------------------------------------------------
  134. /*
  135. * 환경설정 정보를 읽어오는 함수.
  136. * arguments
  137. * String : RegisterKey 또는 파일이름
  138. * return
  139. * bool : 실패하면 false
  140. */
  141. bool ReadConfigInfo(String sCfgFile, String sTitle, String sItem, String &sValue)
  142. {
  143. bool bRes;
  144. String ConfigFile;
  145. TIniFile *pIniFile = NULL;
  146. bRes = false;
  147. ConfigFile = sCfgFile;
  148. try
  149. {
  150. pIniFile = new TIniFile(ConfigFile);
  151. if (pIniFile == NULL)
  152. {
  153. return bRes;
  154. }
  155. sValue = pIniFile->ReadString(sTitle, sItem, "");
  156. if (sValue != "")
  157. {
  158. bRes = true;
  159. }
  160. }
  161. catch(...)
  162. {
  163. }
  164. if (pIniFile)
  165. {
  166. pIniFile->Free();
  167. pIniFile = NULL;
  168. }
  169. return bRes;
  170. }
  171. //---------------------------------------------------------------------------
  172. void ShowErrorMsg(String ATitle, String AErrMsg)
  173. {
  174. Application->NormalizeTopMosts();
  175. Application->MessageBox(AErrMsg.c_str(), ATitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
  176. Application->RestoreTopMosts();
  177. }
  178. //----------------------------------------------------------------------------
  179. ULONG ProcIDFromWnd(HWND hwnd) // 윈도우 핸들로 프로세스 아이디 얻기
  180. {
  181. ULONG idProc;
  182. GetWindowThreadProcessId( hwnd, &idProc );
  183. return idProc;
  184. }
  185. //----------------------------------------------------------------------------
  186. HWND GetWinHandle(ULONG pid) // 프로세스 아이디로 윈도우 핸들 얻기
  187. {
  188. HWND tempHwnd = FindWindow(NULL,NULL); // 최상위 윈도우 핸들 찾기
  189. while( tempHwnd != NULL )
  190. {
  191. if( GetParent(tempHwnd) == NULL ) // 최상위 핸들인지 체크, 버튼 등도 핸들을 가질 수 있으므로 무시하기 위해
  192. if( pid == ProcIDFromWnd(tempHwnd) )
  193. return tempHwnd;
  194. tempHwnd = GetWindow(tempHwnd, GW_HWNDNEXT); // 다음 윈도우 핸들 찾기
  195. }
  196. return NULL;
  197. }
  198. //----------------------------------------------------------------------------
  199. TColor g_DispColor[MAX_DISPCOLOR];
  200. void APP_InitDisplayColor()
  201. {
  202. g_DispColor[ 0] = Graphics::clBlue;
  203. g_DispColor[ 1] = Graphics::clRed;
  204. g_DispColor[ 2] = Graphics::clLime;
  205. g_DispColor[ 3] = Graphics::clMaroon;
  206. g_DispColor[ 4] = Graphics::clGreen;
  207. g_DispColor[ 5] = Graphics::clMenuHighlight;
  208. g_DispColor[ 6] = Graphics::clBackground;
  209. g_DispColor[ 7] = Graphics::clPurple;
  210. g_DispColor[ 8] = Graphics::clTeal;
  211. g_DispColor[ 9] = Graphics::clYellow;
  212. g_DispColor[10] = Graphics::clFuchsia;
  213. g_DispColor[11] = Graphics::clAqua;
  214. g_DispColor[12] = Graphics::clMoneyGreen;
  215. g_DispColor[13] = Graphics::clSkyBlue;
  216. g_DispColor[14] = Graphics::clRed;
  217. g_DispColor[15] = Graphics::clLime;
  218. g_DispColor[16] = Graphics::clYellow;
  219. g_DispColor[17] = Graphics::clBlue;
  220. g_DispColor[18] = Graphics::clFuchsia;
  221. g_DispColor[19] = Graphics::clAqua;
  222. g_DispColor[20] = Graphics::clMoneyGreen;
  223. g_DispColor[21] = Graphics::clActiveCaption;
  224. }
  225. //---------------------------------------------------------------------------
  226. TColor APP_GetDisplayColor(int ASeq)
  227. {
  228. return g_DispColor[ASeq % MAX_DISPCOLOR];
  229. }
  230. //---------------------------------------------------------------------------