AppGlobalF.cpp 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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.sApiUrl = pIniFile->ReadString("APPLICATION", "API_URL", "").Trim();
  63. g_AppCfg.bCameraTitle = pIniFile->ReadString("APPLICATION", "CAMERA_TITLE", "1").ToIntDef(0) == 1 ? true : false;
  64. g_AppCfg.sSkinName = pIniFile->ReadString("APPLICATION", "SKINNAME", "Blue");
  65. g_AppCfg.bSaveForm = false;//pIniFile->ReadString("APPLICATION", "SAVEFORM", "1").ToIntDef(1) == 1 ? true : false;
  66. g_AppCfg.bLoginPrompt = false;//pIniFile->ReadString("APPLICATION", "LOGINPROMPT", "1").ToIntDef(1) == 1 ? true : false;
  67. g_AppCfg.bDebug = false;//pIniFile->ReadString("APPLICATION", "DEBUG", "0").ToIntDef(0) == 1 ? true : false;
  68. g_AppCfg.sDefUseId = "";//pIniFile->ReadString("APPLICATION", "LASTUSER", "");
  69. g_AppCfg.sLang = pIniFile->ReadString("APPLICATION", "LANGUAGE", "kr").LowerCase();
  70. if (g_AppCfg.sLang != "en" && g_AppCfg.sLang != "kr") g_AppCfg.sLang = "kr";
  71. g_AppCfg.itsdb.bSqlLog = false;//pIniFile->ReadString("ITSDB", "SQLLOG", "0").ToIntDef(0) == 1 ? true : false;
  72. g_AppCfg.itsdb.sConnectStr = pIniFile->ReadString("ITSDB", "CONNECTSTR", "");
  73. if (g_AppCfg.itsdb.sConnectStr == "")
  74. {
  75. g_AppCfg.itsdb.sProvider = pIniFile->ReadString("ITSDB", "PROVIDER", "OraOLEDB.Oracle.1");
  76. g_AppCfg.itsdb.sServerName = pIniFile->ReadString("ITSDB", "SERVERNAME", "HANTE");
  77. g_AppCfg.itsdb.sUserName = pIniFile->ReadString("ITSDB", "USERNAME", "hnits");
  78. g_AppCfg.itsdb.sPassword = pIniFile->ReadString("ITSDB", "PASSWORD", "hnits");
  79. }
  80. //시설물 온도알람을 사용하지 않는경우 100도가 되기때문에 실제적으로 알람이 발생하지 않는 효과가 있음
  81. //즉, 온도이상알람을 원하는 경우에만 알람값을 설정하여 사용하면 됨
  82. g_AppCfg.Temp.AlarmValue = pIniFile->ReadString("TEMPERATURE", "ALARMVALUE", "100").ToIntDef(100); //45
  83. }
  84. __finally
  85. {
  86. if (pIniFile) delete pIniFile;
  87. pIniFile = NULL;
  88. }
  89. g_AppCfg.sEmptyImg = g_sCfgDir + ChangeFileExt(ExtractFileName(Application->ExeName), ".bmp");
  90. return true;
  91. }
  92. //---------------------------------------------------------------------------
  93. /*
  94. * 환경설정 정보를 저장하는 함수.
  95. * arguments
  96. * String : RegisterKey 또는 파일이름
  97. * return
  98. * bool : 실패하면 false
  99. */
  100. bool WriteConfigInfo(String sCfgFile, String sTitle, String sItem, String sValue)
  101. {
  102. String ConfigFile;
  103. TIniFile *pIniFile = NULL;
  104. ConfigFile = sCfgFile;
  105. try
  106. {
  107. pIniFile = new TIniFile(ConfigFile);
  108. if (pIniFile == NULL)
  109. {
  110. return false;
  111. }
  112. pIniFile->WriteString(sTitle, sItem, sValue);
  113. }
  114. catch(...)
  115. {
  116. }
  117. if (pIniFile)
  118. {
  119. pIniFile->Free();
  120. pIniFile = NULL;
  121. }
  122. return true;
  123. }
  124. //---------------------------------------------------------------------------
  125. /*
  126. * 환경설정 정보를 읽어오는 함수.
  127. * arguments
  128. * String : RegisterKey 또는 파일이름
  129. * return
  130. * bool : 실패하면 false
  131. */
  132. bool ReadConfigInfo(String sCfgFile, String sTitle, String sItem, String &sValue)
  133. {
  134. bool bRes;
  135. String ConfigFile;
  136. TIniFile *pIniFile = NULL;
  137. bRes = false;
  138. ConfigFile = sCfgFile;
  139. try
  140. {
  141. pIniFile = new TIniFile(ConfigFile);
  142. if (pIniFile == NULL)
  143. {
  144. return bRes;
  145. }
  146. sValue = pIniFile->ReadString(sTitle, sItem, "");
  147. if (sValue != "")
  148. {
  149. bRes = true;
  150. }
  151. }
  152. catch(...)
  153. {
  154. }
  155. if (pIniFile)
  156. {
  157. pIniFile->Free();
  158. pIniFile = NULL;
  159. }
  160. return bRes;
  161. }
  162. //---------------------------------------------------------------------------
  163. void ShowErrorMsg(String ATitle, String AErrMsg)
  164. {
  165. Application->NormalizeTopMosts();
  166. Application->MessageBox(AErrMsg.c_str(), ATitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
  167. Application->RestoreTopMosts();
  168. }
  169. //----------------------------------------------------------------------------
  170. ULONG ProcIDFromWnd(HWND hwnd) // 윈도우 핸들로 프로세스 아이디 얻기
  171. {
  172. ULONG idProc;
  173. GetWindowThreadProcessId( hwnd, &idProc );
  174. return idProc;
  175. }
  176. //----------------------------------------------------------------------------
  177. HWND GetWinHandle(ULONG pid) // 프로세스 아이디로 윈도우 핸들 얻기
  178. {
  179. HWND tempHwnd = FindWindow(NULL,NULL); // 최상위 윈도우 핸들 찾기
  180. while( tempHwnd != NULL )
  181. {
  182. if( GetParent(tempHwnd) == NULL ) // 최상위 핸들인지 체크, 버튼 등도 핸들을 가질 수 있으므로 무시하기 위해
  183. if( pid == ProcIDFromWnd(tempHwnd) )
  184. return tempHwnd;
  185. tempHwnd = GetWindow(tempHwnd, GW_HWNDNEXT); // 다음 윈도우 핸들 찾기
  186. }
  187. return NULL;
  188. }
  189. //----------------------------------------------------------------------------
  190. TColor g_DispColor[MAX_DISPCOLOR];
  191. void APP_InitDisplayColor()
  192. {
  193. g_DispColor[ 0] = Graphics::clBlue;
  194. g_DispColor[ 1] = Graphics::clRed;
  195. g_DispColor[ 2] = Graphics::clLime;
  196. g_DispColor[ 3] = Graphics::clMaroon;
  197. g_DispColor[ 4] = Graphics::clGreen;
  198. g_DispColor[ 5] = Graphics::clMenuHighlight;
  199. g_DispColor[ 6] = Graphics::clBackground;
  200. g_DispColor[ 7] = Graphics::clPurple;
  201. g_DispColor[ 8] = Graphics::clTeal;
  202. g_DispColor[ 9] = Graphics::clYellow;
  203. g_DispColor[10] = Graphics::clFuchsia;
  204. g_DispColor[11] = Graphics::clAqua;
  205. g_DispColor[12] = Graphics::clMoneyGreen;
  206. g_DispColor[13] = Graphics::clSkyBlue;
  207. g_DispColor[14] = Graphics::clRed;
  208. g_DispColor[15] = Graphics::clLime;
  209. g_DispColor[16] = Graphics::clYellow;
  210. g_DispColor[17] = Graphics::clBlue;
  211. g_DispColor[18] = Graphics::clFuchsia;
  212. g_DispColor[19] = Graphics::clAqua;
  213. g_DispColor[20] = Graphics::clMoneyGreen;
  214. g_DispColor[21] = Graphics::clActiveCaption;
  215. }
  216. //---------------------------------------------------------------------------
  217. TColor APP_GetDisplayColor(int ASeq)
  218. {
  219. return g_DispColor[ASeq % MAX_DISPCOLOR];
  220. }
  221. //---------------------------------------------------------------------------