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