AppGlobalF.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "AppGlobalF.h"
  5. #include "ITSDbF.h"
  6. #include "ITSUtilF.h"
  7. #include "ITSLogF.h"
  8. #include <inifiles.hpp>
  9. //---------------------------------------------------------------------------
  10. #pragma package(smart_init)
  11. //---------------------------------------------------------------------------
  12. String CenterCd = ""; // 지역센터 코드
  13. String CenterId = ""; // 지역센터 아이디
  14. String CenterName = ""; // 지역센터 명칭
  15. int g_nPid = -1; // Application Process ID
  16. String g_sAppDir = ""; // Application Directory
  17. String g_sAppName= ""; // Program name
  18. String g_sCfgDir = ""; // Config File Directory
  19. String g_sLogDir = ""; // Program Log Directory
  20. String g_sTempDir = ""; // Program Temp Directory
  21. String g_sFormsDir = ""; // Program Forms Directory
  22. String g_sLangDir = "";
  23. APP_CONFIG g_AppCfg;
  24. LOGININFO *g_pLOGIN = NULL;
  25. LOG_INFO g_LogCfg;
  26. TITSLog *ITSLog = NULL;
  27. //---------------------------------------------------------------------------
  28. bool LoadDefaultConfigInfo(String ACfgFile/*=""*/)
  29. {
  30. String sCfgFile;
  31. TIniFile *pIniFile = NULL;
  32. String sIniFile = ChangeFileExt(ExtractFileName(Application->ExeName), ".ini");
  33. if (!ACfgFile.IsEmpty())
  34. sIniFile = ACfgFile + ".ini";
  35. sCfgFile = g_sCfgDir + sIniFile;
  36. g_AppCfg.sConfigFile = sCfgFile;
  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. pIniFile = new TIniFile(sCfgFile);
  43. try
  44. {
  45. g_AppCfg.sTitle = pIniFile->ReadString("APPLICATION", "TITLE", "교통정보시스템 통합 운영단말");
  46. g_AppCfg.sProcessId = pIniFile->ReadString("APPLICATION", "PROCESSID", "OPER01");
  47. g_AppCfg.sLogDay = pIniFile->ReadString("APPLICATION", "LOGDAY", "");
  48. g_AppCfg.sAppPath = pIniFile->ReadString("APPLICATION", "APP_PATH", "");
  49. g_AppCfg.sSkinName = pIniFile->ReadString("APPLICATION", "SKINNAME", "Blue");
  50. g_AppCfg.bSaveForm = pIniFile->ReadString("APPLICATION", "SAVEFORM", "1").ToIntDef(1) == 1 ? true : false;
  51. g_AppCfg.bLoginPrompt = pIniFile->ReadString("APPLICATION", "LOGINPROMPT", "1").ToIntDef(1) == 1 ? true : false;
  52. g_AppCfg.bDebug = pIniFile->ReadString("APPLICATION", "DEBUG", "0").ToIntDef(0) == 1 ? true : false;
  53. g_AppCfg.sDefUseId = pIniFile->ReadString("APPLICATION", "LASTUSER", "");
  54. g_AppCfg.sLang = pIniFile->ReadString("APPLICATION", "LANGUAGE", "kr").LowerCase();
  55. if (g_AppCfg.sLang != "en" && g_AppCfg.sLang != "kr") g_AppCfg.sLang = "kr";
  56. g_AppCfg.itsdb.bSqlLog = pIniFile->ReadString("ITSDB", "SQLLOG", "0").ToIntDef(0) == 1 ? true : false;
  57. g_AppCfg.itsdb.sConnectStr = pIniFile->ReadString("ITSDB", "CONNECTSTR", "");
  58. if (g_AppCfg.itsdb.sConnectStr == "")
  59. {
  60. g_AppCfg.itsdb.sProvider = pIniFile->ReadString("ITSDB", "PROVIDER", "OraOLEDB.Oracle.1");
  61. g_AppCfg.itsdb.sServerName = pIniFile->ReadString("ITSDB", "SERVERNAME", "HANTE");
  62. g_AppCfg.itsdb.sUserName = pIniFile->ReadString("ITSDB", "USERNAME", "hnits");
  63. g_AppCfg.itsdb.sPassword = pIniFile->ReadString("ITSDB", "PASSWORD", "hnits");
  64. }
  65. //시설물 온도알람을 사용하지 않는경우 100도가 되기때문에 실제적으로 알람이 발생하지 않는 효과가 있음
  66. //즉, 온도이상알람을 원하는 경우에만 알람값을 설정하여 사용하면 됨
  67. g_AppCfg.Temp.AlarmValue = pIniFile->ReadString("TEMPERATURE", "ALARMVALUE", "100").ToIntDef(100); //45
  68. }
  69. __finally
  70. {
  71. if (pIniFile) delete pIniFile;
  72. pIniFile = NULL;
  73. }
  74. return true;
  75. }
  76. //---------------------------------------------------------------------------
  77. /*}
  78. //---------------------------------------------------------------------------
  79. bool CMM_InsertLoginHist(PLOGININFO pLogin, bool ALogin)
  80. {
  81. String sQry;
  82. bool bResult= false;
  83. TADOQuery *adoQry = NULL;
  84. if (!pLogin) return false;
  85. if (ALogin)
  86. {
  87. sQry = "INSERT INTO TB_USERCNNC_HS ( \r\n"
  88. " LOGIN_HMS, \r\n"
  89. " USER_ID, \r\n"
  90. " LOGOUT_HMS \r\n"
  91. " ) \r\n"
  92. "VALUES ( \r\n"
  93. " :p01, \r\n"
  94. " :p02, \r\n"
  95. " NULL \r\n"
  96. " ) \r\n";
  97. }
  98. else
  99. {
  100. sQry = "UPDATE TB_USERCNNC_HS SET \r\n"
  101. " LOGOUT_HMS = TO_CHAR(SYSDATE, 'YYYYMMDDHH24MISS') \r\n"
  102. " WHERE LOGIN_HMS = :p01 \r\n"
  103. " AND USER_ID = :p02 \r\n";
  104. }
  105. try
  106. {
  107. try
  108. {
  109. adoQry = new TADOQuery(NULL);
  110. adoQry->Connection = ITSDb_GetConnection();
  111. ITSDb_GetConnection()->BeginTrans();
  112. adoQry->Close();
  113. adoQry->SQL->Text = sQry;
  114. adoQry->Parameters->ParamByName("p01")->Value = pLogin->sLoginTime;
  115. adoQry->Parameters->ParamByName("p02")->Value = pLogin->sUserId;
  116. int nRowCnt = adoQry->ExecSQL();
  117. ITSDb_GetConnection()->CommitTrans();
  118. bResult = nRowCnt > 1 ? true : false;
  119. }
  120. catch (Exception &exception)
  121. {
  122. ITSDb_GetConnection()->RollbackTrans();
  123. throw Exception(String(exception.ClassName()) + exception.Message);
  124. }
  125. catch (...)
  126. {
  127. ITSDb_GetConnection()->RollbackTrans();
  128. }
  129. }
  130. __finally
  131. {
  132. if (adoQry)
  133. {
  134. adoQry->Close();
  135. delete adoQry;
  136. }
  137. }
  138. return bResult;
  139. }
  140. //---------------------------------------------------------------------------
  141. /*
  142. * 환경설정 정보를 저장하는 함수.
  143. * arguments
  144. * String : RegisterKey 또는 파일이름
  145. * return
  146. * bool : 실패하면 false
  147. */
  148. bool WriteConfigInfo(String sCfgFile, String sTitle, String sItem, String sValue)
  149. {
  150. String ConfigFile;
  151. TIniFile *pIniFile = NULL;
  152. ConfigFile = sCfgFile;
  153. try
  154. {
  155. pIniFile = new TIniFile(ConfigFile);
  156. if (pIniFile == NULL)
  157. {
  158. return false;
  159. }
  160. pIniFile->WriteString(sTitle, sItem, sValue);
  161. }
  162. catch(...)
  163. {
  164. }
  165. if (pIniFile)
  166. {
  167. pIniFile->Free();
  168. pIniFile = NULL;
  169. }
  170. return true;
  171. }
  172. //---------------------------------------------------------------------------
  173. /*
  174. * 환경설정 정보를 읽어오는 함수.
  175. * arguments
  176. * String : RegisterKey 또는 파일이름
  177. * return
  178. * bool : 실패하면 false
  179. */
  180. bool ReadConfigInfo(String sCfgFile, String sTitle, String sItem, String &sValue)
  181. {
  182. bool bRes;
  183. String ConfigFile;
  184. TIniFile *pIniFile = NULL;
  185. bRes = false;
  186. ConfigFile = sCfgFile;
  187. try
  188. {
  189. pIniFile = new TIniFile(ConfigFile);
  190. if (pIniFile == NULL)
  191. {
  192. return bRes;
  193. }
  194. sValue = pIniFile->ReadString(sTitle, sItem, "");
  195. if (sValue != "")
  196. {
  197. bRes = true;
  198. }
  199. }
  200. catch(...)
  201. {
  202. }
  203. if (pIniFile)
  204. {
  205. pIniFile->Free();
  206. pIniFile = NULL;
  207. }
  208. return bRes;
  209. }
  210. //---------------------------------------------------------------------------
  211. void ShowErrorMsg(String ATitle, String AErrMsg)
  212. {
  213. Application->NormalizeTopMosts();
  214. Application->MessageBox(AErrMsg.c_str(), ATitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
  215. Application->RestoreTopMosts();
  216. }
  217. //----------------------------------------------------------------------------
  218. String APP_GetCode(TcxComboBox *ACombo)
  219. {
  220. String sReturn = "";
  221. if (ACombo->ItemIndex >= 0)
  222. {
  223. String sDesc = ACombo->Properties->Items->Strings[ACombo->ItemIndex];
  224. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  225. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  226. sReturn = sCode;
  227. }
  228. return sReturn;
  229. }
  230. //----------------------------------------------------------------------------
  231. String APP_GetCodeDesc(TcxComboBox *ACombo, String ACode)
  232. {
  233. String sReturn = "";
  234. for (int ii = 0; ii < ACombo->Properties->Items->Count; ii++)
  235. {
  236. String sDesc = ACombo->Properties->Items->Strings[ii];
  237. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  238. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  239. if (ACode == sCode)
  240. {
  241. sReturn = sDesc;
  242. break;
  243. }
  244. }
  245. return sReturn;
  246. }
  247. //----------------------------------------------------------------------------
  248. String APP_GetCodeName(TcxComboBox *ACombo, String ACode)
  249. {
  250. String sReturn = "";
  251. for (int ii = 0; ii < ACombo->Properties->Items->Count; ii++)
  252. {
  253. String sDesc = ACombo->Properties->Items->Strings[ii];
  254. String sName = sDesc.SubString(sDesc.Pos("]") + 1, sDesc.Length());
  255. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  256. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  257. if (ACode == sCode)
  258. {
  259. sReturn = sName.Trim();
  260. break;
  261. }
  262. }
  263. return sReturn;
  264. }
  265. //----------------------------------------------------------------------------
  266. String APP_GetCodeIdByName(TcxComboBox *ACombo, String AName)
  267. {
  268. String sReturn = "3";
  269. for (int ii = 0; ii < ACombo->Properties->Items->Count; ii++)
  270. {
  271. String sDesc = ACombo->Properties->Items->Strings[ii];
  272. String sName = sDesc.SubString(sDesc.Pos("]") + 1, sDesc.Length());
  273. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  274. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  275. if (sName.Trim() == AName.Trim())
  276. {
  277. sReturn = sCode;
  278. break;
  279. }
  280. }
  281. return sReturn;
  282. }
  283. //----------------------------------------------------------------------------
  284. String APP_GetCodeDefCode(TcxComboBox *ACombo)
  285. {
  286. String sReturn = "";
  287. if (ACombo->Properties->Items->Count > 0)
  288. {
  289. String sDesc = ACombo->Properties->Items->Strings[0];
  290. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  291. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  292. sReturn = sCode;
  293. }
  294. return sReturn;
  295. }
  296. //----------------------------------------------------------------------------
  297. String APP_GetCodeDefDesc(TcxComboBox *ACombo)
  298. {
  299. String sReturn = "";
  300. if (ACombo->Properties->Items->Count > 0)
  301. {
  302. String sDesc = ACombo->Properties->Items->Strings[0];
  303. sReturn = sDesc;
  304. }
  305. return sReturn;
  306. }
  307. //----------------------------------------------------------------------------
  308. int APP_SetCode(TcxComboBox *ACombo, String ACode)
  309. {
  310. int nItemIndex = -1;
  311. for (int ii = 0; ii < ACombo->Properties->Items->Count; ii++)
  312. {
  313. String sDesc = ACombo->Properties->Items->Strings[ii];
  314. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  315. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  316. if (ACode == sCode)
  317. {
  318. nItemIndex = ii;
  319. break;
  320. }
  321. }
  322. ACombo->ItemIndex = nItemIndex;
  323. return nItemIndex;
  324. }
  325. //----------------------------------------------------------------------------
  326. ULONG ProcIDFromWnd(HWND hwnd) // 윈도우 핸들로 프로세스 아이디 얻기
  327. {
  328. ULONG idProc;
  329. GetWindowThreadProcessId( hwnd, &idProc );
  330. return idProc;
  331. }
  332. //----------------------------------------------------------------------------
  333. HWND GetWinHandle(ULONG pid) // 프로세스 아이디로 윈도우 핸들 얻기
  334. {
  335. HWND tempHwnd = FindWindow(NULL,NULL); // 최상위 윈도우 핸들 찾기
  336. while( tempHwnd != NULL )
  337. {
  338. if( GetParent(tempHwnd) == NULL ) // 최상위 핸들인지 체크, 버튼 등도 핸들을 가질 수 있으므로 무시하기 위해
  339. if( pid == ProcIDFromWnd(tempHwnd) )
  340. return tempHwnd;
  341. tempHwnd = GetWindow(tempHwnd, GW_HWNDNEXT); // 다음 윈도우 핸들 찾기
  342. }
  343. return NULL;
  344. }
  345. //----------------------------------------------------------------------------
  346. String ITSUtil_FormatStr(String AStrDateTime, String AFormat)
  347. {
  348. #define SYEAR "-"
  349. #define STIME ":"
  350. #define SPACE " "
  351. String sDateTime = "";
  352. String sInData = AnsiString(AStrDateTime);
  353. //ShowMessage("IN: " + AStrDateTime + " " + sInData + " " + AFormat);
  354. if (sInData.IsEmpty())
  355. return sInData;
  356. //sDateTime = sInData;
  357. try
  358. {
  359. if (AFormat == STR_DATETIME)
  360. {
  361. if (sInData.Length() < 14) return sInData;
  362. sDateTime = sInData.SubString( 1, 4) + SYEAR +
  363. sInData.SubString( 5, 2) + SYEAR +
  364. sInData.SubString( 7, 2) + SPACE +
  365. sInData.SubString( 9, 2) + STIME +
  366. sInData.SubString(11, 2) + STIME +
  367. sInData.SubString(13, 2);
  368. }
  369. else
  370. if (AFormat == STR_HHNN)
  371. {
  372. if (sInData.Length() < 12) return sInData;
  373. sDateTime = sInData.SubString( 1, 4) + SYEAR +
  374. sInData.SubString( 5, 2) + SYEAR +
  375. sInData.SubString( 7, 2) + SPACE +
  376. sInData.SubString( 9, 2) + STIME +
  377. sInData.SubString(11, 2);
  378. }
  379. else
  380. if (AFormat == STR_DATEHOUR)
  381. {
  382. if (sInData.Length() < 10) return sInData;
  383. sDateTime = sInData.SubString( 1, 4) + SYEAR +
  384. sInData.SubString( 5, 2) + SYEAR +
  385. sInData.SubString( 7, 2) + SPACE +
  386. sInData.SubString( 9, 2);
  387. }
  388. else
  389. if (AFormat == STR_DATE)
  390. {
  391. if (sInData.Length() < 8) return sInData;
  392. sDateTime = sInData.SubString( 1, 4) + SYEAR +
  393. sInData.SubString( 5, 2) + SYEAR +
  394. sInData.SubString( 7, 2);
  395. }
  396. else
  397. if (AFormat == STR_MM)
  398. {
  399. if (sInData.Length() < 6) return sInData;
  400. sDateTime = sInData.SubString( 1, 4) + SYEAR +
  401. sInData.SubString( 5, 2);
  402. }
  403. else
  404. {
  405. sDateTime = sInData;
  406. }
  407. }
  408. catch(...)
  409. {
  410. }
  411. //ShowMessage("OUT: " + sDateTime);
  412. return sDateTime;
  413. }
  414. //---------------------------------------------------------------------------
  415. TColor g_DispColor[MAX_DISPCOLOR];
  416. void APP_InitDisplayColor()
  417. {
  418. g_DispColor[ 0] = Graphics::clBlue;
  419. g_DispColor[ 1] = Graphics::clRed;
  420. g_DispColor[ 2] = Graphics::clLime;
  421. g_DispColor[ 3] = Graphics::clMaroon;
  422. g_DispColor[ 4] = Graphics::clGreen;
  423. g_DispColor[ 5] = Graphics::clMenuHighlight;
  424. g_DispColor[ 6] = Graphics::clBackground;
  425. g_DispColor[ 7] = Graphics::clPurple;
  426. g_DispColor[ 8] = Graphics::clTeal;
  427. g_DispColor[ 9] = Graphics::clYellow;
  428. g_DispColor[10] = Graphics::clFuchsia;
  429. g_DispColor[11] = Graphics::clAqua;
  430. g_DispColor[12] = Graphics::clMoneyGreen;
  431. g_DispColor[13] = Graphics::clSkyBlue;
  432. g_DispColor[14] = Graphics::clRed;
  433. g_DispColor[15] = Graphics::clLime;
  434. g_DispColor[16] = Graphics::clYellow;
  435. g_DispColor[17] = Graphics::clBlue;
  436. g_DispColor[18] = Graphics::clFuchsia;
  437. g_DispColor[19] = Graphics::clAqua;
  438. g_DispColor[20] = Graphics::clMoneyGreen;
  439. g_DispColor[21] = Graphics::clActiveCaption;
  440. }
  441. //---------------------------------------------------------------------------
  442. TColor APP_GetDisplayColor(int ASeq)
  443. {
  444. return g_DispColor[ASeq % MAX_DISPCOLOR];
  445. }
  446. //---------------------------------------------------------------------------
  447. void APP_DelVmsSizeCombo(TcxComboBox *cboBox)
  448. {
  449. TStrings *pStrItems;
  450. TVmsSizeType *Ov;
  451. pStrItems = ((TcxComboBox *)cboBox)->Properties->Items;
  452. for (int ii = pStrItems->Count-1; ii >= 0; ii--)
  453. {
  454. Ov = (TVmsSizeType *)pStrItems->Objects[ii];
  455. if (Ov != NULL)
  456. {
  457. delete Ov;
  458. Ov = NULL;
  459. }
  460. }
  461. }
  462. //---------------------------------------------------------------------------
  463. TVmsSizeType* APP_GetVmsSizeTypeObject(TcxComboBox *cboBox)
  464. {
  465. TStrings *pStrItems;
  466. TVmsSizeType *Ov = NULL;
  467. int nItemIndex;
  468. pStrItems = ((TcxComboBox *)cboBox)->Properties->Items;
  469. nItemIndex= ((TcxComboBox *)cboBox)->ItemIndex;
  470. if (nItemIndex < 0)
  471. {
  472. return Ov;
  473. }
  474. Ov = (TVmsSizeType *)pStrItems->Objects[nItemIndex];
  475. if (Ov == NULL)
  476. {
  477. Ov = NULL;
  478. }
  479. return Ov;
  480. }
  481. //---------------------------------------------------------------------------
  482. void APP_ImageClear(TCanvas *c, int offX, int offY, int w, int h, TColor color)
  483. {
  484. try
  485. {
  486. c->Pen->Color = clWhite;
  487. c->Pen->Width = 0;
  488. c->Pen->Style = psClear;
  489. c->Brush->Style = bsSolid;
  490. c->Brush->Color = color;
  491. c->Rectangle(offX, offY, w+offX+2, h+offY+2);
  492. }
  493. catch(...)
  494. {
  495. }
  496. }
  497. //---------------------------------------------------------------------------
  498. #include <DateUtils.hpp>
  499. TDateTime APP_StrToDateTime(String AStrDateTime)
  500. {
  501. TDateTime dtReturnValue = NULL;
  502. if (AStrDateTime.IsEmpty()) return dtReturnValue;
  503. if (AStrDateTime.Length() != 14) return dtReturnValue;
  504. AnsiString sDateTime = AnsiString(AStrDateTime);
  505. try
  506. {
  507. #if 0
  508. sDateTime.printf(L"%s-%s-%s %s:%s:%s",
  509. AStrDateTime.SubString( 1, 4).c_str(),
  510. AStrDateTime.SubString( 5, 2).c_str(),
  511. AStrDateTime.SubString( 7, 2).c_str(),
  512. AStrDateTime.SubString( 9, 2).c_str(),
  513. AStrDateTime.SubString(11, 2).c_str(),
  514. AStrDateTime.SubString(13, 2).c_str());
  515. dtReturnValue = StrToDateTime(sDateTime);
  516. #endif
  517. // swscanf(sRgb.c_str(), L"%d,%d,%d", &r, &g, &b);
  518. int year, month, day, hour, minute, second;
  519. sscanf(sDateTime.c_str(), "%4d%2d%2d%2d%2d%2d", &year, &month, &day, &hour, &minute, &second);
  520. dtReturnValue = EncodeDateTime(year, month, day, hour, minute, second, 0);
  521. }
  522. catch(...)
  523. {
  524. }
  525. return dtReturnValue;
  526. }
  527. //---------------------------------------------------------------------------