AppGlobalF.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "AppGlobalF.h"
  5. #include "ITSDbF.h"
  6. #include "CDSCodeF.h"
  7. #include <inifiles.hpp>
  8. //---------------------------------------------------------------------------
  9. #pragma package(smart_init)
  10. //---------------------------------------------------------------------------
  11. String CenterCd = ""; // 지역센터 코드
  12. String CenterId = ""; // 지역센터 아이디
  13. String CenterName = ""; // 지역센터 명칭
  14. int g_nPid = -1; // Application Process ID
  15. String g_sAppDir = ""; // Application Directory
  16. String g_sAppName= ""; // Program name
  17. String g_sCfgDir = ""; // Config File Directory
  18. String g_sLogDir = ""; // Program Log Directory
  19. String g_sTempDir = ""; // Program Temp Directory
  20. String g_sFormsDir = ""; // Program Forms Directory
  21. APP_CONFIG g_AppCfg;
  22. LOG_INFO g_LogCfg;
  23. TITSLog *ITSLog = NULL;
  24. //---------------------------------------------------------------------------
  25. bool LoadDefaultConfigInfo(String ACfgFile/*=""*/)
  26. {
  27. String sCfgFile;
  28. TIniFile *pIniFile = NULL;
  29. String sIniFile = ChangeFileExt(ExtractFileName(Application->ExeName), ".ini");
  30. if (!ACfgFile.IsEmpty())
  31. sIniFile = ACfgFile + ".ini";
  32. sCfgFile = g_sCfgDir + sIniFile;
  33. g_AppCfg.sConfigFile = sCfgFile;
  34. g_AppCfg.AutoLogout.Enabled = false;
  35. g_AppCfg.AutoLogout.IntervalMin = 0;
  36. g_AppCfg.AutoLogout.LogoutExit = false;
  37. g_AppCfg.thr.pThread = NULL;
  38. g_AppCfg.thr.dwThreadId = 0;
  39. g_AppCfg.thr.nHandle = 0;
  40. g_AppCfg.thr.bRunning = false;
  41. g_AppCfg.bAppClose = false;
  42. try
  43. {
  44. String sTmp;
  45. pIniFile = new TIniFile(sCfgFile);
  46. g_AppCfg.sTitle = pIniFile->ReadString("APPLICATION", "TITLE", "광역교통정보 교통관리시스템");
  47. g_AppCfg.sProcessId = pIniFile->ReadString("APPLICATION", "PROCESSID", "999999");
  48. g_AppCfg.sLogDay = pIniFile->ReadString("APPLICATION", "LOGDAY", "");
  49. g_AppCfg.sSkinName = pIniFile->ReadString("APPLICATION", "SKINNAME", "Black");
  50. if (g_AppCfg.sSkinName.IsEmpty()) g_AppCfg.sSkinName = "Blue";
  51. sTmp = pIniFile->ReadString("APPLICATION", "SAVEFORM", "1");
  52. g_AppCfg.bSaveForm = (sTmp == "1") ? true : false;
  53. sTmp = "1";
  54. sTmp = pIniFile->ReadString("APPLICATION", "LOGINPROMPT", "1");
  55. g_AppCfg.bLoginPrompt = (sTmp == "1") ? true : false;
  56. g_AppCfg.sDefUseId = pIniFile->ReadString("APPLICATION", "LASTUSER", "");
  57. g_AppCfg.bDebug = false;
  58. sTmp = pIniFile->ReadString("APPLICATION", "DEBUG", "0");
  59. if (sTmp == "1") g_AppCfg.bDebug = true;
  60. sTmp = pIniFile->ReadString("ALARM", "WINDOW", "1");
  61. g_AppCfg.Alarm.Window = (sTmp == "1") ? true : false;
  62. sTmp = pIniFile->ReadString("ALARM", "ENABLED", "0");
  63. g_AppCfg.Alarm.Enabled = (sTmp == "1") ? true : false;
  64. sTmp = pIniFile->ReadString("ALARM", "TIMEOUT", "10");
  65. g_AppCfg.Alarm.TimeOut = sTmp.ToIntDef(0);
  66. if (g_AppCfg.Alarm.TimeOut == 0) g_AppCfg.Alarm.TimeOut = 10;
  67. if (g_AppCfg.Alarm.TimeOut > 60) g_AppCfg.Alarm.TimeOut = 60;
  68. sTmp = pIniFile->ReadString("TEMPERATURE", "ALARMVALUE", "45");
  69. g_AppCfg.Temp.AlarmValue = sTmp.ToIntDef(0);
  70. sTmp = pIniFile->ReadString("INCIDENT", "WINDOW", "1");
  71. g_AppCfg.Incident.Window = (sTmp == "1") ? true : false;
  72. sTmp = pIniFile->ReadString("INCIDENT", "ENABLED", "0");
  73. g_AppCfg.Incident.Enabled = (sTmp == "1") ? true : false;
  74. sTmp = pIniFile->ReadString("INCIDENT", "TIMEOUT", "30");
  75. g_AppCfg.Incident.TimeOut = sTmp.ToIntDef(0);
  76. if (g_AppCfg.Incident.TimeOut == 0) g_AppCfg.Incident.TimeOut = 30;
  77. if (g_AppCfg.Incident.TimeOut > 300) g_AppCfg.Incident.TimeOut = 60;
  78. sTmp = pIniFile->ReadString("AUTOLOGOUT", "ENABLED", "0");
  79. g_AppCfg.AutoLogout.Enabled = (sTmp == "1") ? true : false;
  80. sTmp = pIniFile->ReadString("AUTOLOGOUT", "INTERVALMIN", "10");
  81. g_AppCfg.AutoLogout.IntervalMin = sTmp.ToIntDef(0);
  82. if (g_AppCfg.AutoLogout.IntervalMin == 0) g_AppCfg.AutoLogout.IntervalMin = 10;
  83. sTmp = pIniFile->ReadString("AUTOLOGOUT", "LOGOUTEXIT", "0");
  84. g_AppCfg.AutoLogout.LogoutExit = (sTmp == "1") ? true : false;
  85. String sSqlLog;
  86. g_AppCfg.itsdb.bSqlLog = false;
  87. g_AppCfg.itsdb.sProvider = pIniFile->ReadString("ITSDB", "PROVIDER", "OraOLEDB.Oracle.1");
  88. g_AppCfg.itsdb.sServerName = pIniFile->ReadString("ITSDB", "SERVERNAME", "HANTE");
  89. g_AppCfg.itsdb.sUserName = pIniFile->ReadString("ITSDB", "USERNAME", "hnits");
  90. g_AppCfg.itsdb.sPassword = pIniFile->ReadString("ITSDB", "PASSWORD", "hnits");
  91. //sSqlLog = pIniFile->ReadString("ITSDB", "SQLLOG", "0");
  92. //if (sSqlLog == "1") g_AppCfg.itsdb.bSqlLog = true;
  93. #if 0
  94. //세종시
  95. g_AppCfg.vmscam.sComModel = pIniFile->ReadString("VMSCAMERA", "COMPANY", "Samsung");
  96. g_AppCfg.vmscam.sDevModel = pIniFile->ReadString("VMSCAMERA", "DEVICE", "Samsung Network Camera/Encoder");
  97. #else
  98. g_AppCfg.vmscam.sComModel = pIniFile->ReadString("VMSCAMERA", "COMPANY", "Samsung");
  99. g_AppCfg.vmscam.sDevModel = pIniFile->ReadString("VMSCAMERA", "DEVICE", "SNP-3371TH");
  100. #endif
  101. CenterId = pIniFile->ReadString("CENTER", "CENTERID", "L01");
  102. CenterName = pIniFile->ReadString("CENTER", "CENTERNAME", "중앙센터");
  103. CenterCd = String(StrToInt(CenterId.SubString(2, 2)));
  104. g_AppCfg.flashmap.sMainMap = pIniFile->ReadString("FLASHMAP", "MAINMAP", "");
  105. g_AppCfg.flashmap.sLinkMap = pIniFile->ReadString("FLASHMAP", "LINKMAP", "");
  106. if (g_AppCfg.flashmap.sMainMap == "" ||
  107. g_AppCfg.flashmap.sLinkMap == "")
  108. {
  109. Application->MessageBox(L"지도 설정 정보를 읽어오는데 실패하였습니다.!!!!!!!!!!",
  110. L"환경설정 정보 로딩 오류!!!",
  111. MB_OK|MB_ICONERROR);
  112. }
  113. g_AppCfg.flashmap.sMainMap = g_sAppDir + g_AppCfg.flashmap.sMainMap;
  114. g_AppCfg.flashmap.sLinkMap = g_sAppDir + g_AppCfg.flashmap.sLinkMap;
  115. }
  116. __finally
  117. {
  118. if (pIniFile) delete pIniFile;
  119. pIniFile = NULL;
  120. WriteConfigInfo(sIniFile, "AUTOLOGOUT", "LOGOUTEXIT", "0");
  121. }
  122. return true;
  123. }
  124. //---------------------------------------------------------------------------
  125. /*
  126. * 환경설정 정보를 저장하는 함수.
  127. * arguments
  128. * String : RegisterKey 또는 파일이름
  129. * return
  130. * bool : 실패하면 false
  131. */
  132. bool WriteConfigInfo(String sCfgFile, String sTitle, String sItem, String sValue)
  133. {
  134. String ConfigFile;
  135. TIniFile *pIniFile = NULL;
  136. ConfigFile = sCfgFile;
  137. try
  138. {
  139. pIniFile = new TIniFile(ConfigFile);
  140. if (pIniFile == NULL)
  141. {
  142. return false;
  143. }
  144. pIniFile->WriteString(sTitle, sItem, sValue);
  145. }
  146. catch(...)
  147. {
  148. }
  149. if (pIniFile)
  150. {
  151. pIniFile->Free();
  152. pIniFile = NULL;
  153. }
  154. return true;
  155. }
  156. //---------------------------------------------------------------------------
  157. /*
  158. * 환경설정 정보를 읽어오는 함수.
  159. * arguments
  160. * String : RegisterKey 또는 파일이름
  161. * return
  162. * bool : 실패하면 false
  163. */
  164. bool ReadConfigInfo(String sCfgFile, String sTitle, String sItem, String &sValue)
  165. {
  166. bool bRes;
  167. String ConfigFile;
  168. TIniFile *pIniFile = NULL;
  169. bRes = false;
  170. ConfigFile = sCfgFile;
  171. try
  172. {
  173. pIniFile = new TIniFile(ConfigFile);
  174. if (pIniFile == NULL)
  175. {
  176. return bRes;
  177. }
  178. sValue = pIniFile->ReadString(sTitle, sItem, "");
  179. if (sValue != "")
  180. {
  181. bRes = true;
  182. }
  183. }
  184. catch(...)
  185. {
  186. }
  187. if (pIniFile)
  188. {
  189. pIniFile->Free();
  190. pIniFile = NULL;
  191. }
  192. return bRes;
  193. }
  194. //---------------------------------------------------------------------------
  195. void ShowErrorMsg(String ATitle, String AErrMsg)
  196. {
  197. Application->NormalizeTopMosts();
  198. Application->MessageBox(AErrMsg.c_str(), ATitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
  199. Application->RestoreTopMosts();
  200. }
  201. //----------------------------------------------------------------------------
  202. String APP_FillCode(TcxComboBox *ACombo, String ACode)
  203. {
  204. String sReturn = "";
  205. ACombo->Properties->Items->Clear();
  206. TItsCode *FCodeRMF = ItsCodeManager->FLists.Find(ACode);
  207. if (FCodeRMF)
  208. {
  209. FOR_STL(TItsSubCode *, pSubCode, FCodeRMF->FSubLists)
  210. {
  211. if (pSubCode->USE_YN == "N") continue;
  212. ACombo->Properties->Items->Add(" [" + pSubCode->CMMN_CD + "] " + pSubCode->CMMN_CD_KOR_NM);
  213. if (sReturn == "")
  214. {
  215. sReturn = " [" + pSubCode->CMMN_CD + "] " + pSubCode->CMMN_CD_KOR_NM;
  216. }
  217. }
  218. }
  219. ACombo->ItemIndex = 0;
  220. return sReturn;
  221. }
  222. //----------------------------------------------------------------------------
  223. String APP_GetCode(TcxComboBox *ACombo)
  224. {
  225. String sReturn = "";
  226. if (ACombo->ItemIndex >= 0)
  227. {
  228. String sDesc = ACombo->Properties->Items->Strings[ACombo->ItemIndex];
  229. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  230. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  231. sReturn = sCode;
  232. }
  233. return sReturn;
  234. }
  235. //----------------------------------------------------------------------------
  236. String APP_GetCodeDesc(TcxComboBox *ACombo, String ACode)
  237. {
  238. String sReturn = "";
  239. for (int ii = 0; ii < ACombo->Properties->Items->Count; ii++)
  240. {
  241. String sDesc = ACombo->Properties->Items->Strings[ii];
  242. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  243. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  244. if (ACode == sCode)
  245. {
  246. sReturn = sDesc;
  247. break;
  248. }
  249. }
  250. return sReturn;
  251. }
  252. //----------------------------------------------------------------------------
  253. String APP_GetCodeName(TcxComboBox *ACombo, String ACode)
  254. {
  255. String sReturn = "";
  256. for (int ii = 0; ii < ACombo->Properties->Items->Count; ii++)
  257. {
  258. String sDesc = ACombo->Properties->Items->Strings[ii];
  259. String sName = sDesc.SubString(sDesc.Pos("]") + 1, sDesc.Length());
  260. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  261. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  262. if (ACode == sCode)
  263. {
  264. sReturn = sName.Trim();
  265. break;
  266. }
  267. }
  268. return sReturn;
  269. }
  270. //----------------------------------------------------------------------------
  271. String APP_GetCodeIdByName(TcxComboBox *ACombo, String AName)
  272. {
  273. String sReturn = "3";
  274. for (int ii = 0; ii < ACombo->Properties->Items->Count; ii++)
  275. {
  276. String sDesc = ACombo->Properties->Items->Strings[ii];
  277. String sName = sDesc.SubString(sDesc.Pos("]") + 1, sDesc.Length());
  278. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  279. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  280. if (sName.Trim() == AName.Trim())
  281. {
  282. sReturn = sCode;
  283. break;
  284. }
  285. }
  286. return sReturn;
  287. }
  288. //----------------------------------------------------------------------------
  289. String APP_GetCodeDefCode(TcxComboBox *ACombo)
  290. {
  291. String sReturn = "";
  292. if (ACombo->Properties->Items->Count > 0)
  293. {
  294. String sDesc = ACombo->Properties->Items->Strings[0];
  295. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  296. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  297. sReturn = sCode;
  298. }
  299. return sReturn;
  300. }
  301. //----------------------------------------------------------------------------
  302. String APP_GetCodeDefDesc(TcxComboBox *ACombo)
  303. {
  304. String sReturn = "";
  305. if (ACombo->Properties->Items->Count > 0)
  306. {
  307. String sDesc = ACombo->Properties->Items->Strings[0];
  308. sReturn = sDesc;
  309. }
  310. return sReturn;
  311. }
  312. //----------------------------------------------------------------------------
  313. int APP_SetCode(TcxComboBox *ACombo, String ACode)
  314. {
  315. int nItemIndex = -1;
  316. for (int ii = 0; ii < ACombo->Properties->Items->Count; ii++)
  317. {
  318. String sDesc = ACombo->Properties->Items->Strings[ii];
  319. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  320. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  321. if (ACode == sCode)
  322. {
  323. nItemIndex = ii;
  324. break;
  325. }
  326. }
  327. ACombo->ItemIndex = nItemIndex;
  328. return nItemIndex;
  329. }
  330. //----------------------------------------------------------------------------
  331. ULONG ProcIDFromWnd(HWND hwnd) // 윈도우 핸들로 프로세스 아이디 얻기
  332. {
  333. ULONG idProc;
  334. GetWindowThreadProcessId( hwnd, &idProc );
  335. return idProc;
  336. }
  337. //----------------------------------------------------------------------------
  338. HWND GetWinHandle(ULONG pid) // 프로세스 아이디로 윈도우 핸들 얻기
  339. {
  340. HWND tempHwnd = FindWindow(NULL,NULL); // 최상위 윈도우 핸들 찾기
  341. while( tempHwnd != NULL )
  342. {
  343. if( GetParent(tempHwnd) == NULL ) // 최상위 핸들인지 체크, 버튼 등도 핸들을 가질 수 있으므로 무시하기 위해
  344. if( pid == ProcIDFromWnd(tempHwnd) )
  345. return tempHwnd;
  346. tempHwnd = GetWindow(tempHwnd, GW_HWNDNEXT); // 다음 윈도우 핸들 찾기
  347. }
  348. return NULL;
  349. }
  350. //----------------------------------------------------------------------------
  351. TColor g_DispColor[MAX_DISPCOLOR];
  352. void APP_InitDisplayColor()
  353. {
  354. g_DispColor[ 0] = Graphics::clBlue;
  355. g_DispColor[ 1] = Graphics::clRed;
  356. g_DispColor[ 2] = Graphics::clLime;
  357. g_DispColor[ 3] = Graphics::clMaroon;
  358. g_DispColor[ 4] = Graphics::clGreen;
  359. g_DispColor[ 5] = Graphics::clMenuHighlight;
  360. g_DispColor[ 6] = Graphics::clBackground;
  361. g_DispColor[ 7] = Graphics::clPurple;
  362. g_DispColor[ 8] = Graphics::clTeal;
  363. g_DispColor[ 9] = Graphics::clYellow;
  364. g_DispColor[10] = Graphics::clFuchsia;
  365. g_DispColor[11] = Graphics::clAqua;
  366. g_DispColor[12] = Graphics::clMoneyGreen;
  367. g_DispColor[13] = Graphics::clSkyBlue;
  368. g_DispColor[14] = Graphics::clRed;
  369. g_DispColor[15] = Graphics::clLime;
  370. g_DispColor[16] = Graphics::clYellow;
  371. g_DispColor[17] = Graphics::clBlue;
  372. g_DispColor[18] = Graphics::clFuchsia;
  373. g_DispColor[19] = Graphics::clAqua;
  374. g_DispColor[20] = Graphics::clMoneyGreen;
  375. g_DispColor[21] = Graphics::clActiveCaption;
  376. }
  377. //---------------------------------------------------------------------------
  378. TColor APP_GetDisplayColor(int ASeq)
  379. {
  380. return g_DispColor[ASeq % MAX_DISPCOLOR];
  381. }
  382. //---------------------------------------------------------------------------