AppGlobalF.cpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "AppGlobalF.h"
  5. #include "ITSDbF.h"
  6. #include "ITSUtilF.h"
  7. #include "CDSCodeF.h"
  8. #include <inifiles.hpp>
  9. //---------------------------------------------------------------------------
  10. #pragma package(smart_init)
  11. //---------------------------------------------------------------------------
  12. int g_nPid = -1; // Application Process ID
  13. String g_sAppDir = ""; // Application Directory
  14. String g_sAppName= ""; // Program name
  15. String g_sCfgDir = ""; // Config File Directory
  16. String g_sLogDir = ""; // Program Log Directory
  17. String g_sTempDir = ""; // Program Temp Directory
  18. String g_sFormsDir = ""; // Program Forms Directory
  19. String g_sBlackBox = "";
  20. String g_sLangDir = "";
  21. String g_sImageDir = "";
  22. String g_sVideoDir = "";
  23. String g_sMapDir = "";
  24. APP_CONFIG g_AppCfg;
  25. LOG_INFO g_LogCfg;
  26. TITSLog *ITSLog = NULL;
  27. String g_sLang = "kr";
  28. String g_IniFileDir = "";
  29. String g_IniFileName = "Option";
  30. bool g_bControlAuth = true;
  31. //---------------------------------------------------------------------------
  32. bool CheckApplicationParam() {
  33. int nArgs = ParamCount();
  34. if (nArgs < 2) {
  35. return false;
  36. }
  37. g_AppCfg.MAGIC_ID = ParamStr(1);
  38. if (g_AppCfg.MAGIC_ID.UpperCase() != "ICAIR") {
  39. return false;
  40. }
  41. g_AppCfg.OPER_ID = ParamStr(2);
  42. g_AppCfg.OPER_ID = g_AppCfg.OPER_ID.SubString(1, 10);
  43. g_AppCfg.PRCS_ID = DEFAULT_PRCS_ID;
  44. g_AppCfg.PARAM1 = "";
  45. g_AppCfg.PARAM2 = "";
  46. g_AppCfg.PARAM3 = "";
  47. g_AppCfg.PARAM4 = "";
  48. if (nArgs >= 3) {
  49. g_AppCfg.PRCS_ID = ParamStr(3);
  50. }
  51. if (nArgs >= 4) {
  52. g_AppCfg.PARAM1 = ParamStr(4);
  53. }
  54. if (nArgs >= 5) {
  55. g_AppCfg.PARAM2 = ParamStr(5);
  56. }
  57. if (nArgs >= 6) {
  58. g_AppCfg.PARAM3 = ParamStr(6);
  59. }
  60. if (nArgs >= 7) {
  61. g_AppCfg.PARAM4 = ParamStr(7);
  62. }
  63. return true;
  64. }
  65. //---------------------------------------------------------------------------
  66. void ActiveProgram(String AClassName, String ATitle) {
  67. //String AClassName = "TFrmVmsFormEdit";
  68. //String ATitle = g_AppCfg.sTitle + " - Active";
  69. HWND hExeForm = FindWindow(AClassName.c_str(), ATitle.c_str());
  70. if (hExeForm)
  71. {
  72. bool bResult = SetWindowPos(hExeForm, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
  73. if (bResult) {
  74. bResult = ShowWindow(hExeForm, SW_RESTORE);
  75. SetForegroundWindow(hExeForm);
  76. }
  77. }
  78. }
  79. //---------------------------------------------------------------------------
  80. bool ApplicationSingleRun(String AClassName, String ATitle) {
  81. HANDLE hMutex;
  82. try
  83. {
  84. String sLockFile = ChangeFileExt(ExtractFileName(Application->ExeName), ".lock");
  85. String sProgMutexNm = "ICAIR_" + sLockFile;
  86. if ((hMutex=OpenMutex(MUTEX_ALL_ACCESS, false, sProgMutexNm.c_str()))==NULL)
  87. hMutex = CreateMutex(NULL, true, sProgMutexNm.c_str());
  88. else
  89. {
  90. ActiveProgram(AClassName, ATitle);
  91. return false;
  92. }
  93. }
  94. catch (Exception &exception)
  95. {
  96. Application->ShowException(&exception);
  97. return false;
  98. }
  99. return true;
  100. }
  101. //---------------------------------------------------------------------------
  102. void LoadIcon(TIniFile* AIniFile, String ASection, String AItem, String& AValue)
  103. {
  104. try
  105. {
  106. AValue = AIniFile->ReadString(ASection, AItem, "");
  107. if (AValue != "")
  108. {
  109. AValue = g_sAppDir + "Image\\" + AValue;
  110. if (!FileExists(AValue)) AValue = "";
  111. }
  112. }
  113. catch(Exception &e)
  114. {
  115. }
  116. }
  117. //---------------------------------------------------------------------------
  118. #include <windows.h>
  119. #include <shlwapi.h>
  120. #pragma comment (lib, "shlwapi.lib")
  121. bool IsDirectoryExists(LPCTSTR path)
  122. {
  123. return PathFileExists(path);
  124. #if 0
  125. struct _stat buffer;
  126. int iRetTemp = 0;
  127. memset((void*)&buffer, 0, sizeof(buffer));
  128. iRetTemp = _stat(path, &buffer);
  129. if (iRetTemp == 0)
  130. {
  131. if (buffer.st_mode & _S_IFDIR)
  132. {
  133. return true;
  134. }
  135. }
  136. return false;
  137. #endif
  138. }
  139. //---------------------------------------------------------------------------
  140. bool LoadDefaultConfigInfo(String ACfgFile/*=""*/)
  141. {
  142. String sCfgFile;
  143. TIniFile *pIniFile = NULL;
  144. String sIniFile = ACfgFile + ".ini";
  145. sCfgFile = g_sCfgDir + sIniFile;
  146. g_AppCfg.sConfigFile = sCfgFile;
  147. pIniFile = new TIniFile(sCfgFile);
  148. try
  149. {
  150. g_AppCfg.sLang = "kr";
  151. g_sLang = g_AppCfg.sLang;
  152. g_AppCfg.sLogDay = pIniFile->ReadString("VMS", "LOGDAY", "");
  153. g_AppCfg.sSkinName = pIniFile->ReadString("VMS", "SKINNAME", "Silver");
  154. g_AppCfg.bSaveForm = pIniFile->ReadString("VMS", "SAVEFORM", "0").ToIntDef(1) == 1 ? true : false;
  155. g_AppCfg.isDispOfflineMsg = pIniFile->ReadString("VMS", "DISPOFFLINEMSG", "1").ToIntDef(1) == 1 ? true : false;
  156. g_AppCfg.itsdb.bSqlLog = pIniFile->ReadString("DB", "SQLLOG", "0").ToIntDef(0) == 1 ? true : false;
  157. g_AppCfg.itsdb.sConnectStr = pIniFile->ReadString("DB", "CONNECTSTR", "");
  158. if (g_AppCfg.itsdb.sConnectStr == "")
  159. {
  160. g_AppCfg.itsdb.sProvider = pIniFile->ReadString("DB", "PROVIDER", "OraOLEDB.Oracle.1");
  161. //g_AppCfg.itsdb.sProvider = pIniFile->ReadString("DB", "PROVIDER", "MSDAORA.1");
  162. g_AppCfg.itsdb.sServerName = pIniFile->ReadString("DB", "NAME", "ORCL");
  163. g_AppCfg.itsdb.sUserName = pIniFile->ReadString("DB", "USER", "ICAIR");
  164. g_AppCfg.itsdb.sPassword = pIniFile->ReadString("DB", "PASS", "ICAIR");
  165. }
  166. //VMS FTP
  167. g_AppCfg.vmsFtp.SERVER = pIniFile->ReadString("VMS_FTP", "SERVER", "");
  168. g_AppCfg.vmsFtp.PORT = pIniFile->ReadString("VMS_FTP", "PORT", "3600").ToIntDef(21);
  169. g_AppCfg.vmsFtp.USER = pIniFile->ReadString("VMS_FTP", "USER", "icair_vms");
  170. g_AppCfg.vmsFtp.PSWD = pIniFile->ReadString("VMS_FTP", "PSWD", "icair_vms");
  171. g_AppCfg.vmsFtp.PASSIVE = pIniFile->ReadString("VMS_FTP", "PASSIVE", "1").ToIntDef(0) == 0 ? false : true;
  172. //cmraViewerResetMin
  173. g_AppCfg.cmraViewerResetMin = pIniFile->ReadString("CMRA_VIEWER", "RESET_TIMER_MIN", "30").ToIntDef(30);
  174. if (g_AppCfg.cmraViewerResetMin <= 0) g_AppCfg.cmraViewerResetMin = 0;
  175. if (g_AppCfg.cmraViewerResetMin > 0 && g_AppCfg.cmraViewerResetMin < 5) g_AppCfg.cmraViewerResetMin = 5;
  176. if (g_AppCfg.cmraViewerResetMin > 120) g_AppCfg.cmraViewerResetMin = 120;
  177. //cmraViewerDelaySec
  178. g_AppCfg.cmraViewerDelaySec = pIniFile->ReadString("CMRA_VIEWER", "DELAY_TIMER_SEC", "10").ToIntDef(10);
  179. if (g_AppCfg.cmraViewerDelaySec <= 0) g_AppCfg.cmraViewerDelaySec = 0;
  180. if (g_AppCfg.cmraViewerDelaySec > 0 && g_AppCfg.cmraViewerDelaySec < 5) g_AppCfg.cmraViewerDelaySec = 5;
  181. if (g_AppCfg.cmraViewerDelaySec > 120) g_AppCfg.cmraViewerDelaySec = 120;
  182. }
  183. __finally
  184. {
  185. if (pIniFile) delete pIniFile;
  186. pIniFile = NULL;
  187. //WriteConfigInfo(g_AppCfg.sConfigFile, "AUTOLOGOUT", "LOGOUTEXIT", "0");
  188. }
  189. return true;
  190. }
  191. //---------------------------------------------------------------------------
  192. /*
  193. * 환경설정 정보를 저장하는 함수.
  194. * arguments
  195. * String : RegisterKey 또는 파일이름
  196. * return
  197. * bool : 실패하면 false
  198. */
  199. bool WriteConfigInfo(String sCfgFile, String sTitle, String sItem, String sValue)
  200. {
  201. String ConfigFile;
  202. TIniFile *pIniFile = NULL;
  203. ConfigFile = sCfgFile;
  204. try
  205. {
  206. pIniFile = new TIniFile(ConfigFile);
  207. if (pIniFile == NULL)
  208. {
  209. return false;
  210. }
  211. pIniFile->WriteString(sTitle, sItem, sValue);
  212. }
  213. catch(...)
  214. {
  215. }
  216. if (pIniFile)
  217. {
  218. pIniFile->Free();
  219. pIniFile = NULL;
  220. }
  221. return true;
  222. }
  223. //---------------------------------------------------------------------------
  224. /*
  225. * 환경설정 정보를 읽어오는 함수.
  226. * arguments
  227. * String : RegisterKey 또는 파일이름
  228. * return
  229. * bool : 실패하면 false
  230. */
  231. bool ReadConfigInfo(String sCfgFile, String sTitle, String sItem, String &sValue)
  232. {
  233. bool bRes;
  234. String ConfigFile;
  235. TIniFile *pIniFile = NULL;
  236. bRes = false;
  237. ConfigFile = sCfgFile;
  238. try
  239. {
  240. pIniFile = new TIniFile(ConfigFile);
  241. if (pIniFile == NULL)
  242. {
  243. return bRes;
  244. }
  245. sValue = pIniFile->ReadString(sTitle, sItem, "");
  246. if (sValue != "")
  247. {
  248. bRes = true;
  249. }
  250. }
  251. catch(...)
  252. {
  253. }
  254. if (pIniFile)
  255. {
  256. pIniFile->Free();
  257. pIniFile = NULL;
  258. }
  259. return bRes;
  260. }
  261. //---------------------------------------------------------------------------
  262. void ShowErrorMsg(String ATitle, String AErrMsg)
  263. {
  264. Application->NormalizeTopMosts();
  265. Application->MessageBox(AErrMsg.c_str(), ATitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
  266. Application->RestoreTopMosts();
  267. }
  268. //----------------------------------------------------------------------------
  269. String APP_FillCode(TcxComboBox *ACombo, String ACode)
  270. {
  271. String sReturn = "";
  272. if (SysCodeManager == NULL) {
  273. SysCodeManager = new TSysCodeManager();
  274. SysCodeManager->LoadFromDb();
  275. }
  276. TNotifyEvent evt = ACombo->Properties->OnChange;
  277. ACombo->Properties->OnChange = NULL;
  278. ACombo->Properties->Items->Clear();
  279. TSysClssCode *pSysClssCd = SysCodeManager->FLists.Find(ACode);
  280. if (pSysClssCd) {
  281. FOR_STL(TSysCode *, pSubCode, pSysClssCd->FLists)
  282. {
  283. if (pSubCode->USE_YN == "N") continue;
  284. ACombo->Properties->Items->Add(" [" + pSubCode->CODE_NO + "] " + pSubCode->CD_NM);
  285. if (sReturn == "") {
  286. sReturn = " [" + pSubCode->CODE_NO + "] " + pSubCode->CD_NM;
  287. }
  288. }
  289. }
  290. ACombo->ItemIndex = 0;
  291. ACombo->Properties->OnChange = evt;
  292. return sReturn;
  293. }
  294. //----------------------------------------------------------------------------
  295. String APP_GetCode(TcxComboBox *ACombo)
  296. {
  297. String sReturn = "";
  298. if (ACombo->ItemIndex >= 0)
  299. {
  300. String sDesc = ACombo->Properties->Items->Strings[ACombo->ItemIndex];
  301. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  302. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  303. sReturn = sCode;
  304. }
  305. return sReturn;
  306. }
  307. //----------------------------------------------------------------------------
  308. String APP_GetCodeDesc(TcxComboBox *ACombo, String ACode)
  309. {
  310. String sReturn = "";
  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. sReturn = sDesc;
  319. break;
  320. }
  321. }
  322. return sReturn;
  323. }
  324. //----------------------------------------------------------------------------
  325. String APP_GetCodeName(TcxComboBox *ACombo)
  326. {
  327. String sReturn = "";
  328. if (ACombo->ItemIndex >= 0)
  329. {
  330. String sDesc = ACombo->Properties->Items->Strings[ACombo->ItemIndex];
  331. String sName = sDesc.SubString(sDesc.Pos("]") + 1, sDesc.Length());
  332. sReturn = sName.Trim();
  333. }
  334. return sReturn;
  335. }
  336. //----------------------------------------------------------------------------
  337. String APP_GetCodeName(TcxComboBox *ACombo, String ACode)
  338. {
  339. String sReturn = "";
  340. for (int ii = 0; ii < ACombo->Properties->Items->Count; ii++)
  341. {
  342. String sDesc = ACombo->Properties->Items->Strings[ii];
  343. String sName = sDesc.SubString(sDesc.Pos("]") + 1, sDesc.Length());
  344. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  345. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  346. if (ACode == sCode)
  347. {
  348. sReturn = sName.Trim();
  349. break;
  350. }
  351. }
  352. return sReturn;
  353. }
  354. //----------------------------------------------------------------------------
  355. String APP_GetCodeIdByName(TcxComboBox *ACombo, String AName)
  356. {
  357. String sReturn = "3";
  358. for (int ii = 0; ii < ACombo->Properties->Items->Count; ii++)
  359. {
  360. String sDesc = ACombo->Properties->Items->Strings[ii];
  361. String sName = sDesc.SubString(sDesc.Pos("]") + 1, sDesc.Length());
  362. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  363. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  364. if (sName.Trim() == AName.Trim())
  365. {
  366. sReturn = sCode;
  367. break;
  368. }
  369. }
  370. return sReturn;
  371. }
  372. //----------------------------------------------------------------------------
  373. String APP_GetCodeDefCode(TcxComboBox *ACombo)
  374. {
  375. String sReturn = "";
  376. if (ACombo->Properties->Items->Count > 0)
  377. {
  378. String sDesc = ACombo->Properties->Items->Strings[0];
  379. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  380. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  381. sReturn = sCode;
  382. }
  383. return sReturn;
  384. }
  385. //----------------------------------------------------------------------------
  386. String APP_GetCodeDefDesc(TcxComboBox *ACombo)
  387. {
  388. String sReturn = "";
  389. if (ACombo->Properties->Items->Count > 0)
  390. {
  391. String sDesc = ACombo->Properties->Items->Strings[0];
  392. sReturn = sDesc;
  393. }
  394. return sReturn;
  395. }
  396. //----------------------------------------------------------------------------
  397. int APP_SetCode(TcxComboBox *ACombo, String ACode)
  398. {
  399. int nItemIndex = -1;
  400. for (int ii = 0; ii < ACombo->Properties->Items->Count; ii++)
  401. {
  402. String sDesc = ACombo->Properties->Items->Strings[ii];
  403. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  404. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  405. if (ACode == sCode)
  406. {
  407. nItemIndex = ii;
  408. break;
  409. }
  410. }
  411. ACombo->ItemIndex = nItemIndex;
  412. return nItemIndex;
  413. }
  414. //----------------------------------------------------------------------------
  415. ULONG ProcIDFromWnd(HWND hwnd) // 윈도우 핸들로 프로세스 아이디 얻기
  416. {
  417. ULONG idProc;
  418. GetWindowThreadProcessId( hwnd, &idProc );
  419. return idProc;
  420. }
  421. //----------------------------------------------------------------------------
  422. HWND GetWinHandle(ULONG pid) // 프로세스 아이디로 윈도우 핸들 얻기
  423. {
  424. HWND tempHwnd = FindWindow(NULL,NULL); // 최상위 윈도우 핸들 찾기
  425. while( tempHwnd != NULL )
  426. {
  427. if( GetParent(tempHwnd) == NULL ) // 최상위 핸들인지 체크, 버튼 등도 핸들을 가질 수 있으므로 무시하기 위해
  428. if( pid == ProcIDFromWnd(tempHwnd) )
  429. return tempHwnd;
  430. tempHwnd = GetWindow(tempHwnd, GW_HWNDNEXT); // 다음 윈도우 핸들 찾기
  431. }
  432. return NULL;
  433. }
  434. //----------------------------------------------------------------------------
  435. TColor g_DispColor[MAX_DISPCOLOR];
  436. void APP_InitDisplayColor()
  437. {
  438. #if 0
  439. g_DispColor[ 0] = Graphics::clBlue;
  440. g_DispColor[ 1] = Graphics::clRed;
  441. g_DispColor[ 2] = Graphics::clLime;
  442. g_DispColor[ 3] = Graphics::clMaroon;
  443. g_DispColor[ 4] = Graphics::clGreen;
  444. g_DispColor[ 5] = Graphics::clMenuHighlight;
  445. g_DispColor[ 6] = Graphics::clBackground;
  446. g_DispColor[ 7] = Graphics::clPurple;
  447. g_DispColor[ 8] = Graphics::clTeal;
  448. g_DispColor[ 9] = Graphics::clYellow;
  449. g_DispColor[10] = Graphics::clFuchsia;
  450. g_DispColor[11] = Graphics::clAqua;
  451. g_DispColor[12] = Graphics::clMoneyGreen;
  452. g_DispColor[13] = Graphics::clSkyBlue;
  453. g_DispColor[14] = Graphics::clRed;
  454. g_DispColor[15] = Graphics::clLime;
  455. g_DispColor[16] = Graphics::clYellow;
  456. g_DispColor[17] = Graphics::clBlue;
  457. g_DispColor[18] = Graphics::clFuchsia;
  458. g_DispColor[19] = Graphics::clAqua;
  459. g_DispColor[20] = Graphics::clMoneyGreen;
  460. g_DispColor[21] = Graphics::clActiveCaption;
  461. #else
  462. g_DispColor[ 0] = Graphics::clLime;
  463. g_DispColor[ 1] = (TColor)RGB(0xFF, 0x00, 0x00);
  464. g_DispColor[ 2] = (TColor)RGB(0x00, 0x00, 0xFF);
  465. g_DispColor[ 3] = (TColor)RGB(0xFF, 0x82, 0x00);
  466. g_DispColor[ 4] = (TColor)RGB(0x94, 0x00, 0xD3);
  467. g_DispColor[ 5] = Graphics::clPurple;//(TColor)RGB(0x00, 0x00, 0x00);
  468. g_DispColor[ 6] = (TColor)RGB(0x82, 0x82, 0x82);
  469. g_DispColor[ 7] = (TColor)RGB(0x1E, 0x90, 0xFF);
  470. g_DispColor[ 8] = (TColor)RGB(0xB9, 0x06, 0x2F);
  471. g_DispColor[ 9] = (TColor)RGB(0x8c, 0x00, 0x8c);
  472. g_DispColor[10] = (TColor)RGB(0xFF, 0x82, 0x00);
  473. g_DispColor[11] = (TColor)RGB(0x94, 0x00, 0xD3);
  474. g_DispColor[12] = (TColor)RGB(0xB0, 0xC4, 0xDE);
  475. g_DispColor[13] = (TColor)RGB(0x00, 0xBF, 0xFF);
  476. g_DispColor[14] = (TColor)RGB(0x87, 0xCE, 0xEB);
  477. g_DispColor[15] = (TColor)RGB(0x87, 0xCE, 0xFA);
  478. g_DispColor[16] = (TColor)RGB(0xAD, 0xD8, 0xE6);
  479. g_DispColor[17] = (TColor)RGB(0xB0, 0xE0, 0xE6);
  480. g_DispColor[18] = (TColor)RGB(0xE6, 0xE6, 0xFA);
  481. g_DispColor[19] = (TColor)RGB(0xF0, 0xF8, 0xFF);
  482. #endif
  483. }
  484. //---------------------------------------------------------------------------
  485. TColor APP_GetDisplayColor(int ASeq)
  486. {
  487. return g_DispColor[ASeq % MAX_DISPCOLOR];
  488. }
  489. //---------------------------------------------------------------------------
  490. void APP_DelVmsSizeCombo(TcxComboBox *cboBox)
  491. {
  492. TStrings *pStrItems;
  493. TVmsSizeType *Ov;
  494. pStrItems = ((TcxComboBox *)cboBox)->Properties->Items;
  495. for (int ii = pStrItems->Count-1; ii >= 0; ii--)
  496. {
  497. Ov = (TVmsSizeType *)pStrItems->Objects[ii];
  498. if (Ov != NULL)
  499. {
  500. delete Ov;
  501. Ov = NULL;
  502. }
  503. }
  504. }
  505. //---------------------------------------------------------------------------
  506. void APP_FillVmsSizeType(TcxComboBox *cboBox, bool bAddAll/*=false*/)
  507. {
  508. String sQry;
  509. TStrings *pStrItems;
  510. TADOQuery *pADO = NULL;
  511. if (!VmsTypeManager)
  512. {
  513. VmsTypeManager = new TVmsTypeManager();
  514. VmsTypeManager->LoadFromDb();
  515. }
  516. TNotifyEvent evt = cboBox->Properties->OnChange;
  517. cboBox->Properties->OnChange = NULL;
  518. APP_DelVmsSizeCombo(cboBox);
  519. pStrItems = ((TcxComboBox *)cboBox)->Properties->Items;
  520. ((TcxComboBox *)cboBox)->Properties->Items->Clear();
  521. FOR_STL(TVmsType*, pObj, VmsTypeManager->FSortLists)
  522. {
  523. String sTypeCd = pObj->VMS_MODL_KIND;
  524. String sTypeNm = pObj->VMS_MODL_KIND_NM;
  525. int nW = pObj->VMS_WDTH;
  526. int nH = pObj->VMS_HGHT;
  527. int nR = pObj->VMS_MODL_ROW;
  528. int nC = pObj->VMS_MODL_COL;
  529. if (pObj->USE_LCS == "Y") {
  530. pStrItems->AddObject(" [" + sTypeCd + "] " + sTypeNm + " (" + String(nW) + "*" + String(nH) + ") - LCS " + String(pObj->LCS_LANE_CNT) + " 차로", new TVmsSizeType(sTypeCd, sTypeNm, nW, nH, nR, nC, true, pObj->LCS_LANE_CNT) );
  531. }
  532. else {
  533. pStrItems->AddObject(" [" + sTypeCd + "] " + sTypeNm + " (" + String(nW) + "*" + String(nH) + ")", new TVmsSizeType(sTypeCd, sTypeNm, nW, nH, nR, nC, false, 0) );
  534. }
  535. }
  536. if (bAddAll)
  537. {
  538. String sAllName = "전체";
  539. pStrItems->AddObject(" [ALL] 전체" , new TVmsSizeType("ALL", sAllName, 384, 64, 2, 12, false, 0));
  540. }
  541. cboBox->ItemIndex = 0;
  542. cboBox->Properties->OnChange = evt;
  543. }
  544. //---------------------------------------------------------------------------
  545. void APP_FillLcsSizeType(TcxComboBox *cboBox, bool bAddAll/*=false*/)
  546. {
  547. String sQry;
  548. TStrings *pStrItems;
  549. TADOQuery *pADO = NULL;
  550. if (!VmsTypeManager)
  551. {
  552. VmsTypeManager = new TVmsTypeManager();
  553. VmsTypeManager->LoadFromDb();
  554. }
  555. TNotifyEvent evt = cboBox->Properties->OnChange;
  556. cboBox->Properties->OnChange = NULL;
  557. APP_DelVmsSizeCombo(cboBox);
  558. pStrItems = ((TcxComboBox *)cboBox)->Properties->Items;
  559. ((TcxComboBox *)cboBox)->Properties->Items->Clear();
  560. FOR_STL(TVmsType*, pObj, VmsTypeManager->FLists)
  561. {
  562. String sTypeCd = pObj->VMS_MODL_KIND;
  563. String sTypeNm = pObj->VMS_MODL_KIND_NM;
  564. int nW = pObj->VMS_WDTH;
  565. int nH = pObj->VMS_HGHT;
  566. int nR = pObj->VMS_MODL_ROW;
  567. int nC = pObj->VMS_MODL_COL;
  568. if (pObj->USE_LCS == "Y") {
  569. pStrItems->AddObject(" [" + sTypeCd + "] " + sTypeNm + " (" + String(nW) + "*" + String(nH) + ") - LCS " + String(pObj->LCS_LANE_CNT) + " 차로", new TVmsSizeType(sTypeCd, sTypeNm, nW, nH, nR, nC, true, pObj->LCS_LANE_CNT) );
  570. }
  571. }
  572. if (bAddAll)
  573. {
  574. String sAllName = "전체";
  575. pStrItems->AddObject(" [ALL] 전체" , new TVmsSizeType("ALL", sAllName, 384, 64, 2, 12, false, 0));
  576. }
  577. cboBox->ItemIndex = 0;
  578. cboBox->Properties->OnChange = evt;
  579. }
  580. //---------------------------------------------------------------------------
  581. TVmsSizeType* APP_GetVmsSizeTypeObject(TcxComboBox *cboBox)
  582. {
  583. TStrings *pStrItems;
  584. TVmsSizeType *Ov = NULL;
  585. int nItemIndex;
  586. pStrItems = ((TcxComboBox *)cboBox)->Properties->Items;
  587. nItemIndex= ((TcxComboBox *)cboBox)->ItemIndex;
  588. if (nItemIndex < 0)
  589. {
  590. return Ov;
  591. }
  592. Ov = (TVmsSizeType *)pStrItems->Objects[nItemIndex];
  593. if (Ov == NULL)
  594. {
  595. Ov = NULL;
  596. }
  597. return Ov;
  598. }
  599. //---------------------------------------------------------------------------
  600. void APP_ImageClear(TCanvas *c, int offX, int offY, int w, int h, TColor color)
  601. {
  602. try
  603. {
  604. c->Pen->Color = clWhite;
  605. c->Pen->Width = 0;
  606. c->Pen->Style = psClear;
  607. c->Brush->Style = bsSolid;
  608. c->Brush->Color = color;
  609. c->Rectangle(offX, offY, w+offX+2, h+offY+2);
  610. }
  611. catch(...)
  612. {
  613. }
  614. }
  615. //---------------------------------------------------------------------------
  616. #include <DateUtils.hpp>
  617. TDateTime APP_StrToDateTime(String AStrDateTime)
  618. {
  619. TDateTime dtReturnValue = NULL;
  620. if (AStrDateTime.IsEmpty()) return dtReturnValue;
  621. if (AStrDateTime.Length() != 14) return dtReturnValue;
  622. AnsiString sDateTime = AnsiString(AStrDateTime);
  623. try
  624. {
  625. #if 0
  626. sDateTime.printf(L"%s-%s-%s %s:%s:%s",
  627. AStrDateTime.SubString( 1, 4).c_str(),
  628. AStrDateTime.SubString( 5, 2).c_str(),
  629. AStrDateTime.SubString( 7, 2).c_str(),
  630. AStrDateTime.SubString( 9, 2).c_str(),
  631. AStrDateTime.SubString(11, 2).c_str(),
  632. AStrDateTime.SubString(13, 2).c_str());
  633. dtReturnValue = StrToDateTime(sDateTime);
  634. #endif
  635. // swscanf(sRgb.c_str(), L"%d,%d,%d", &r, &g, &b);
  636. int year, month, day, hour, minute, second;
  637. sscanf(sDateTime.c_str(), "%4d%2d%2d%2d%2d%2d", &year, &month, &day, &hour, &minute, &second);
  638. dtReturnValue = EncodeDateTime(year, month, day, hour, minute, second, 0);
  639. }
  640. catch(...)
  641. {
  642. }
  643. return dtReturnValue;
  644. }
  645. //---------------------------------------------------------------------------
  646. #include <jpeg.hpp>
  647. bool APP_CheckBmpFile(String AInFileName, String &AOutFileName)
  648. {
  649. String sFilePath = ExtractFilePath(AInFileName);
  650. String sFileName = ExtractFileName(AInFileName);
  651. String sFileExt = ExtractFileExt(AInFileName);
  652. AOutFileName = AInFileName;
  653. if (sFileExt.UpperCase() == ".BMP")
  654. {
  655. return true;
  656. }
  657. AOutFileName = AInFileName + ".bmp";
  658. TImage *Image1 = new TImage(NULL);
  659. TMemoryStream *pImgStream = new TMemoryStream();
  660. try
  661. {
  662. try
  663. {
  664. pImgStream->LoadFromFile(AInFileName);
  665. sFileExt = sFileExt.UpperCase();
  666. if (sFileExt == ".PNG")
  667. {
  668. TdxPNGImage *img = new TdxPNGImage;
  669. img->LoadFromStream(pImgStream);
  670. Image1->Picture->Bitmap->Assign(img);
  671. Image1->Picture->Bitmap->PixelFormat = pf24bit;
  672. Image1->Picture->Bitmap->SaveToFile(AOutFileName);
  673. SAFE_DELETE(img);
  674. return true;
  675. }
  676. else
  677. if (sFileExt == ".JPG" || sFileExt == ".JPEG")
  678. {
  679. TJPEGImage *img = new TJPEGImage();
  680. img->LoadFromStream(pImgStream);
  681. Image1->Picture->Bitmap->Assign(img);
  682. Image1->Picture->Bitmap->PixelFormat = pf24bit;
  683. Image1->Picture->Bitmap->SaveToFile(AOutFileName);
  684. SAFE_DELETE(img);
  685. return true;
  686. }
  687. }
  688. catch(Exception &e)
  689. {
  690. }
  691. }
  692. __finally
  693. {
  694. SAFE_DELETE(pImgStream);
  695. SAFE_DELETE(Image1);
  696. }
  697. return false;
  698. }
  699. //---------------------------------------------------------------------------
  700. String DbPictTypeToReal(String APictType)
  701. {
  702. if (APictType == "B") return "bmp";
  703. if (APictType == "G") return "gif";
  704. if (APictType == "A") return "gif";
  705. if (APictType == "J") return "jpg";
  706. if (APictType == "P") return "png";
  707. if (APictType == "I") return "ico";
  708. return "bmp";
  709. }
  710. //---------------------------------------------------------------------------
  711. String RealPictTypeToDb(String APictType)
  712. {
  713. if (APictType == "B") return "bmp";
  714. //if (APictType == "gif") return "G";
  715. if (APictType == "gif") return "A";
  716. if (APictType == "jpg") return "J";
  717. if (APictType == "jpeg")return "J";
  718. if (APictType == "png") return "P";
  719. if (APictType == "ico") return "I";
  720. return "B";
  721. }
  722. //---------------------------------------------------------------------------
  723. String DbMovieTypeToReal(String APictType)
  724. {
  725. if (APictType == "AV") return "avi";
  726. if (APictType == "MP") return "mpeg";
  727. if (APictType == "MK") return "mkv";
  728. if (APictType == "M4") return "mp4";
  729. return "avi";
  730. }
  731. //---------------------------------------------------------------------------
  732. String RealMovieTypeToDb(String APictType)
  733. {
  734. if (APictType == "avi") return "AV";
  735. if (APictType == "mpge") return "MP";
  736. if (APictType == "mkv") return "MK";
  737. if (APictType == "mp4") return "M4";
  738. return "AV";
  739. }
  740. //---------------------------------------------------------------------------