AppGlobalF.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  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. #if 0
  105. g_AppCfg.flashmap.sMainMap = pIniFile->ReadString("FLASHMAP", "MAINMAP", "");
  106. g_AppCfg.flashmap.sLinkMap = pIniFile->ReadString("FLASHMAP", "LINKMAP", "");
  107. if (g_AppCfg.flashmap.sMainMap == "" ||
  108. g_AppCfg.flashmap.sLinkMap == "")
  109. {
  110. Application->MessageBox(L"지도 설정 정보를 읽어오는데 실패하였습니다.!!!!!!!!!!",
  111. L"환경설정 정보 로딩 오류!!!",
  112. MB_OK|MB_ICONERROR);
  113. }
  114. g_AppCfg.flashmap.sMainMap = g_sAppDir + g_AppCfg.flashmap.sMainMap;
  115. g_AppCfg.flashmap.sLinkMap = g_sAppDir + g_AppCfg.flashmap.sLinkMap;
  116. #endif
  117. }
  118. __finally
  119. {
  120. if (pIniFile) delete pIniFile;
  121. pIniFile = NULL;
  122. WriteConfigInfo(sIniFile, "AUTOLOGOUT", "LOGOUTEXIT", "0");
  123. }
  124. return true;
  125. }
  126. //---------------------------------------------------------------------------
  127. /*
  128. * 환경설정 정보를 저장하는 함수.
  129. * arguments
  130. * String : RegisterKey 또는 파일이름
  131. * return
  132. * bool : 실패하면 false
  133. */
  134. bool WriteConfigInfo(String sCfgFile, String sTitle, String sItem, String sValue)
  135. {
  136. String ConfigFile;
  137. TIniFile *pIniFile = NULL;
  138. ConfigFile = sCfgFile;
  139. try
  140. {
  141. pIniFile = new TIniFile(ConfigFile);
  142. if (pIniFile == NULL)
  143. {
  144. return false;
  145. }
  146. pIniFile->WriteString(sTitle, sItem, sValue);
  147. }
  148. catch(...)
  149. {
  150. }
  151. if (pIniFile)
  152. {
  153. pIniFile->Free();
  154. pIniFile = NULL;
  155. }
  156. return true;
  157. }
  158. //---------------------------------------------------------------------------
  159. /*
  160. * 환경설정 정보를 읽어오는 함수.
  161. * arguments
  162. * String : RegisterKey 또는 파일이름
  163. * return
  164. * bool : 실패하면 false
  165. */
  166. bool ReadConfigInfo(String sCfgFile, String sTitle, String sItem, String &sValue)
  167. {
  168. bool bRes;
  169. String ConfigFile;
  170. TIniFile *pIniFile = NULL;
  171. bRes = false;
  172. ConfigFile = sCfgFile;
  173. try
  174. {
  175. pIniFile = new TIniFile(ConfigFile);
  176. if (pIniFile == NULL)
  177. {
  178. return bRes;
  179. }
  180. sValue = pIniFile->ReadString(sTitle, sItem, "");
  181. if (sValue != "")
  182. {
  183. bRes = true;
  184. }
  185. }
  186. catch(...)
  187. {
  188. }
  189. if (pIniFile)
  190. {
  191. pIniFile->Free();
  192. pIniFile = NULL;
  193. }
  194. return bRes;
  195. }
  196. //---------------------------------------------------------------------------
  197. void ShowErrorMsg(String ATitle, String AErrMsg)
  198. {
  199. Application->NormalizeTopMosts();
  200. Application->MessageBox(AErrMsg.c_str(), ATitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
  201. Application->RestoreTopMosts();
  202. }
  203. //----------------------------------------------------------------------------
  204. String APP_FillCode(TcxComboBox *ACombo, String ACode)
  205. {
  206. String sReturn = "";
  207. ACombo->Properties->Items->Clear();
  208. TItsCode *FCodeRMF = ItsCodeManager->FLists.Find(ACode);
  209. if (FCodeRMF)
  210. {
  211. FOR_STL(TItsSubCode *, pSubCode, FCodeRMF->FSubLists)
  212. {
  213. if (pSubCode->USE_YN == "N") continue;
  214. ACombo->Properties->Items->Add(" [" + pSubCode->CMMN_CD + "] " + pSubCode->CMMN_CD_KOR_NM);
  215. if (sReturn == "")
  216. {
  217. sReturn = " [" + pSubCode->CMMN_CD + "] " + pSubCode->CMMN_CD_KOR_NM;
  218. }
  219. }
  220. }
  221. ACombo->ItemIndex = 0;
  222. return sReturn;
  223. }
  224. //----------------------------------------------------------------------------
  225. String APP_GetCode(TcxComboBox *ACombo)
  226. {
  227. String sReturn = "";
  228. if (ACombo->ItemIndex >= 0)
  229. {
  230. String sDesc = ACombo->Properties->Items->Strings[ACombo->ItemIndex];
  231. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  232. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  233. sReturn = sCode;
  234. }
  235. return sReturn;
  236. }
  237. //----------------------------------------------------------------------------
  238. String APP_GetCodeDesc(TcxComboBox *ACombo, String ACode)
  239. {
  240. String sReturn = "";
  241. for (int ii = 0; ii < ACombo->Properties->Items->Count; ii++)
  242. {
  243. String sDesc = ACombo->Properties->Items->Strings[ii];
  244. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  245. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  246. if (ACode == sCode)
  247. {
  248. sReturn = sDesc;
  249. break;
  250. }
  251. }
  252. return sReturn;
  253. }
  254. //----------------------------------------------------------------------------
  255. String APP_GetCodeName(TcxComboBox *ACombo, String ACode)
  256. {
  257. String sReturn = "";
  258. for (int ii = 0; ii < ACombo->Properties->Items->Count; ii++)
  259. {
  260. String sDesc = ACombo->Properties->Items->Strings[ii];
  261. String sName = sDesc.SubString(sDesc.Pos("]") + 1, sDesc.Length());
  262. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  263. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  264. if (ACode == sCode)
  265. {
  266. sReturn = sName.Trim();
  267. break;
  268. }
  269. }
  270. return sReturn;
  271. }
  272. //----------------------------------------------------------------------------
  273. String APP_GetCodeIdByName(TcxComboBox *ACombo, String AName)
  274. {
  275. String sReturn = "3";
  276. for (int ii = 0; ii < ACombo->Properties->Items->Count; ii++)
  277. {
  278. String sDesc = ACombo->Properties->Items->Strings[ii];
  279. String sName = sDesc.SubString(sDesc.Pos("]") + 1, sDesc.Length());
  280. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  281. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  282. if (sName.Trim() == AName.Trim())
  283. {
  284. sReturn = sCode;
  285. break;
  286. }
  287. }
  288. return sReturn;
  289. }
  290. //----------------------------------------------------------------------------
  291. String APP_GetCodeDefCode(TcxComboBox *ACombo)
  292. {
  293. String sReturn = "";
  294. if (ACombo->Properties->Items->Count > 0)
  295. {
  296. String sDesc = ACombo->Properties->Items->Strings[0];
  297. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  298. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  299. sReturn = sCode;
  300. }
  301. return sReturn;
  302. }
  303. //----------------------------------------------------------------------------
  304. String APP_GetCodeDefDesc(TcxComboBox *ACombo)
  305. {
  306. String sReturn = "";
  307. if (ACombo->Properties->Items->Count > 0)
  308. {
  309. String sDesc = ACombo->Properties->Items->Strings[0];
  310. sReturn = sDesc;
  311. }
  312. return sReturn;
  313. }
  314. //----------------------------------------------------------------------------
  315. int APP_SetCode(TcxComboBox *ACombo, String ACode)
  316. {
  317. int nItemIndex = -1;
  318. for (int ii = 0; ii < ACombo->Properties->Items->Count; ii++)
  319. {
  320. String sDesc = ACombo->Properties->Items->Strings[ii];
  321. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  322. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  323. if (ACode == sCode)
  324. {
  325. nItemIndex = ii;
  326. break;
  327. }
  328. }
  329. ACombo->ItemIndex = nItemIndex;
  330. return nItemIndex;
  331. }
  332. //----------------------------------------------------------------------------
  333. ULONG ProcIDFromWnd(HWND hwnd) // 윈도우 핸들로 프로세스 아이디 얻기
  334. {
  335. ULONG idProc;
  336. GetWindowThreadProcessId( hwnd, &idProc );
  337. return idProc;
  338. }
  339. //----------------------------------------------------------------------------
  340. HWND GetWinHandle(ULONG pid) // 프로세스 아이디로 윈도우 핸들 얻기
  341. {
  342. HWND tempHwnd = FindWindow(NULL,NULL); // 최상위 윈도우 핸들 찾기
  343. while( tempHwnd != NULL )
  344. {
  345. if( GetParent(tempHwnd) == NULL ) // 최상위 핸들인지 체크, 버튼 등도 핸들을 가질 수 있으므로 무시하기 위해
  346. if( pid == ProcIDFromWnd(tempHwnd) )
  347. return tempHwnd;
  348. tempHwnd = GetWindow(tempHwnd, GW_HWNDNEXT); // 다음 윈도우 핸들 찾기
  349. }
  350. return NULL;
  351. }
  352. //----------------------------------------------------------------------------
  353. TColor g_DispColor[MAX_DISPCOLOR];
  354. void APP_InitDisplayColor()
  355. {
  356. g_DispColor[ 0] = Graphics::clBlue;
  357. g_DispColor[ 1] = Graphics::clRed;
  358. g_DispColor[ 2] = Graphics::clLime;
  359. g_DispColor[ 3] = Graphics::clMaroon;
  360. g_DispColor[ 4] = Graphics::clGreen;
  361. g_DispColor[ 5] = Graphics::clMenuHighlight;
  362. g_DispColor[ 6] = Graphics::clBackground;
  363. g_DispColor[ 7] = Graphics::clPurple;
  364. g_DispColor[ 8] = Graphics::clTeal;
  365. g_DispColor[ 9] = Graphics::clYellow;
  366. g_DispColor[10] = Graphics::clFuchsia;
  367. g_DispColor[11] = Graphics::clAqua;
  368. g_DispColor[12] = Graphics::clMoneyGreen;
  369. g_DispColor[13] = Graphics::clSkyBlue;
  370. g_DispColor[14] = Graphics::clRed;
  371. g_DispColor[15] = Graphics::clLime;
  372. g_DispColor[16] = Graphics::clYellow;
  373. g_DispColor[17] = Graphics::clBlue;
  374. g_DispColor[18] = Graphics::clFuchsia;
  375. g_DispColor[19] = Graphics::clAqua;
  376. g_DispColor[20] = Graphics::clMoneyGreen;
  377. g_DispColor[21] = Graphics::clActiveCaption;
  378. }
  379. //---------------------------------------------------------------------------
  380. TColor APP_GetDisplayColor(int ASeq)
  381. {
  382. return g_DispColor[ASeq % MAX_DISPCOLOR];
  383. }
  384. //---------------------------------------------------------------------------