AppGlobalF.cpp 18 KB

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