AppGlobalF.cpp 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "AppGlobalF.h"
  5. #include "ITSUtilF.h"
  6. #include <inifiles.hpp>
  7. //---------------------------------------------------------------------------
  8. #pragma package(smart_init)
  9. //---------------------------------------------------------------------------
  10. ST_GISINFO g_GisInfo;
  11. ST_SELLINK g_SelLink;
  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_sBlackBox = "";
  23. String g_sLangDir = "";
  24. String g_sImageDir = "";
  25. String g_sVideoDir = "";
  26. String g_sMapDir = "";
  27. APP_CONFIG g_AppCfg;
  28. //LOGININFO *g_pLOGIN = NULL;
  29. LOG_INFO g_LogCfg;
  30. TITSLog *ITSLog = NULL;
  31. TITSLog *FDbLog = NULL;
  32. bool g_bControlAuth = false;
  33. void ActiveProgram()
  34. {
  35. String AClassName = "TFrmVmsFormEdit";
  36. String ATitle = g_AppCfg.sTitle + " - Active";
  37. HWND hExeForm = FindWindow(AClassName.c_str(), ATitle.c_str());
  38. if (hExeForm)
  39. {
  40. LOGINFO("Program exit.... Find Ok... Program already running....");
  41. bool bResult = SetWindowPos(hExeForm, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
  42. if (bResult) {
  43. bResult = ShowWindow(hExeForm, SW_RESTORE);
  44. SetForegroundWindow(hExeForm);
  45. }
  46. }
  47. }
  48. //---------------------------------------------------------------------------
  49. #include <time.h>
  50. bool CheckParamRandKey(String AParam)
  51. {
  52. String appName = "its.vmscontrol://";
  53. if (!AParam.Pos(appName))
  54. {
  55. LOGINFO("Program exit.... Param AppName Error....");
  56. return false;
  57. }
  58. String param = "";
  59. param = StringReplace(AParam, appName, "", TReplaceFlags() << rfReplaceAll);
  60. param = StringReplace(param, "%20", ",", TReplaceFlags() << rfReplaceAll);
  61. String userId = "";
  62. String randKey = "";
  63. String apiUri = "";
  64. String skinName = "";
  65. TStringList *pStringList = new TStringList;
  66. try {
  67. pStringList->Delimiter = ',';
  68. pStringList->StrictDelimiter = true;
  69. pStringList->DelimitedText = param;
  70. if (pStringList->Count < 3) {
  71. LOGINFO("Program exit.... Param Count Error....");
  72. return false;
  73. }
  74. userId = pStringList->Strings[0];
  75. randKey = pStringList->Strings[1];
  76. apiUri = pStringList->Strings[2];
  77. if (pStringList->Count > 3) {
  78. skinName = pStringList->Strings[3];
  79. }
  80. } __finally {
  81. if (pStringList) delete pStringList;
  82. }
  83. if (!apiUri.Pos("http")) {
  84. LOGINFO("Program exit.... Param URI Error....");
  85. return false;
  86. }
  87. g_AppCfg.sUserId = userId;
  88. g_AppCfg.sRestApiUri = apiUri;
  89. if (skinName != "") {
  90. g_AppCfg.sSkinName = skinName;
  91. }
  92. if (randKey.UpperCase() == "VMSCONTROLADMIN")
  93. {
  94. return true;
  95. }
  96. bool result = false;
  97. try {
  98. time_t lCurTm;
  99. time(&lCurTm);
  100. double current = (double)lCurTm;
  101. double paramTime = randKey.ToDouble();
  102. if (paramTime >= current-3 && paramTime <= current+3) {
  103. result = true;
  104. }
  105. }
  106. catch(Exception &e) {
  107. }
  108. LOGINFO("Program exit.... Param RandKey Error....");
  109. return result;
  110. }
  111. //---------------------------------------------------------------------------
  112. //---------------------------------------------------------------------------
  113. void LoadIcon(TIniFile* AIniFile, String ASection, String AItem, String& AValue)
  114. {
  115. try
  116. {
  117. AValue = AIniFile->ReadString(ASection, AItem, "");
  118. if (AValue != "")
  119. {
  120. AValue = g_sAppDir + "Image\\" + AValue;
  121. if (!FileExists(AValue)) AValue = "";
  122. }
  123. }
  124. catch(Exception &e)
  125. {
  126. }
  127. }
  128. //---------------------------------------------------------------------------
  129. #include <windows.h>
  130. #include <shlwapi.h>
  131. #pragma comment (lib, "shlwapi.lib")
  132. bool IsDirectoryExists(LPCTSTR path)
  133. {
  134. return PathFileExists(path);
  135. #if 0
  136. struct _stat buffer;
  137. int iRetTemp = 0;
  138. memset((void*)&buffer, 0, sizeof(buffer));
  139. iRetTemp = _stat(path, &buffer);
  140. if (iRetTemp == 0)
  141. {
  142. if (buffer.st_mode & _S_IFDIR)
  143. {
  144. return true;
  145. }
  146. }
  147. return false;
  148. #endif
  149. }
  150. //---------------------------------------------------------------------------
  151. bool LoadDefaultConfigInfo(String ACfgFile/*=""*/)
  152. {
  153. String sCfgFile;
  154. TIniFile *pIniFile = NULL;
  155. String sIniFile = ChangeFileExt(ExtractFileName(Application->ExeName), ".ini");
  156. if (!ACfgFile.IsEmpty())
  157. sIniFile = ACfgFile + ".ini";
  158. sCfgFile = g_sCfgDir + sIniFile;
  159. g_AppCfg.sConfigFile = sCfgFile;
  160. g_AppCfg.AutoLogout.Enabled = false;
  161. g_AppCfg.AutoLogout.IntervalMin = 0;
  162. g_AppCfg.AutoLogout.LogoutExit = false;
  163. g_AppCfg.thr.pThread = NULL;
  164. g_AppCfg.thr.dwThreadId = 0;
  165. g_AppCfg.thr.nHandle = 0;
  166. g_AppCfg.thr.bRunning = false;
  167. g_AppCfg.bAppClose = false;
  168. try
  169. {
  170. String sTmp;
  171. pIniFile = new TIniFile(sCfgFile);
  172. g_AppCfg.sTitle = pIniFile->ReadString("APPLICATION", "TITLE", "VMS 제어");
  173. g_AppCfg.sProcessId = pIniFile->ReadString("APPLICATION", "PROCESSID", "999999");
  174. g_AppCfg.nVmsServerPort = pIniFile->ReadString("APPLICATION", "VMSSERVERPORT", "6001").ToIntDef(6001);
  175. g_AppCfg.sLogDay = pIniFile->ReadString("APPLICATION", "LOGDAY", "");
  176. g_AppCfg.sAppPath = pIniFile->ReadString("APPLICATION", "APP_PATH", "");
  177. g_AppCfg.sSkinName = pIniFile->ReadString("APPLICATION", "SKINNAME", "Black");
  178. if (g_AppCfg.sSkinName.IsEmpty()) g_AppCfg.sSkinName = "Blue";
  179. sTmp = pIniFile->ReadString("APPLICATION", "SAVEFORM", "1");
  180. g_AppCfg.bSaveForm = (sTmp == "1") ? true : false;
  181. sTmp = "1";
  182. sTmp = pIniFile->ReadString("APPLICATION", "LOGINPROMPT", "1");
  183. g_AppCfg.bLoginPrompt = (sTmp == "1") ? true : false;
  184. g_AppCfg.sDefUseId = pIniFile->ReadString("APPLICATION", "LASTUSER", "");
  185. g_AppCfg.sLang = pIniFile->ReadString("APPLICATION", "LANGUAGE", "kr");
  186. g_AppCfg.sLang = g_AppCfg.sLang.LowerCase();
  187. if (g_AppCfg.sLang != "en" && g_AppCfg.sLang != "kr")
  188. g_AppCfg.sLang = "kr";
  189. g_AppCfg.isDispOfflineMsg = false;
  190. sTmp = pIniFile->ReadString("APPLICATION", "DISPOFFLINEMSG", "0");
  191. if (sTmp == "1") g_AppCfg.isDispOfflineMsg = true;
  192. g_AppCfg.bDebug = false;
  193. sTmp = pIniFile->ReadString("APPLICATION", "DEBUG", "0");
  194. if (sTmp == "1") g_AppCfg.bDebug = true;
  195. g_AppCfg.bTermChildProg = true;
  196. sTmp = pIniFile->ReadString("APPLICATION", "TERMCHILD", "1");
  197. if (sTmp == "0") g_AppCfg.bTermChildProg = false;
  198. g_AppCfg.bOnlyOneScreen = true;
  199. sTmp = pIniFile->ReadString("APPLICATION", "ONESCREEN", "1");
  200. if (sTmp == "0") g_AppCfg.bOnlyOneScreen = false;
  201. sTmp = pIniFile->ReadString("ALARM", "WINDOW", "1");
  202. g_AppCfg.Alarm.Window = (sTmp == "1") ? true : false;
  203. sTmp = pIniFile->ReadString("ALARM", "ENABLED", "0");
  204. g_AppCfg.Alarm.Enabled = (sTmp == "1") ? true : false;
  205. sTmp = pIniFile->ReadString("ALARM", "TIMEOUT", "10");
  206. g_AppCfg.Alarm.TimeOut = sTmp.ToIntDef(0);
  207. if (g_AppCfg.Alarm.TimeOut == 0) g_AppCfg.Alarm.TimeOut = 10;
  208. if (g_AppCfg.Alarm.TimeOut > 60) g_AppCfg.Alarm.TimeOut = 60;
  209. sTmp = pIniFile->ReadString("TEMPERATURE", "ALARMVALUE", "45");
  210. g_AppCfg.Temp.AlarmValue = sTmp.ToIntDef(0);
  211. sTmp = pIniFile->ReadString("INCIDENT", "WINDOW", "1");
  212. g_AppCfg.Incident.Window = (sTmp == "1") ? true : false;
  213. sTmp = pIniFile->ReadString("INCIDENT", "ENABLED", "0");
  214. g_AppCfg.Incident.Enabled = (sTmp == "1") ? true : false;
  215. sTmp = pIniFile->ReadString("INCIDENT", "TIMEOUT", "30");
  216. g_AppCfg.Incident.TimeOut = sTmp.ToIntDef(0);
  217. if (g_AppCfg.Incident.TimeOut == 0) g_AppCfg.Incident.TimeOut = 30;
  218. if (g_AppCfg.Incident.TimeOut > 300) g_AppCfg.Incident.TimeOut = 60;
  219. sTmp = pIniFile->ReadString("AUTOLOGOUT", "ENABLED", "0");
  220. g_AppCfg.AutoLogout.Enabled = (sTmp == "1") ? true : false;
  221. sTmp = pIniFile->ReadString("AUTOLOGOUT", "INTERVALMIN", "10");
  222. g_AppCfg.AutoLogout.IntervalMin = sTmp.ToIntDef(0);
  223. if (g_AppCfg.AutoLogout.IntervalMin == 0) g_AppCfg.AutoLogout.IntervalMin = 10;
  224. sTmp = pIniFile->ReadString("AUTOLOGOUT", "LOGOUTEXIT", "0");
  225. g_AppCfg.AutoLogout.LogoutExit = (sTmp == "1") ? true : false;
  226. String sSqlLog;
  227. g_AppCfg.itsdb.bSqlLog = false;
  228. g_AppCfg.itsdb.sProvider = pIniFile->ReadString("ITSDB", "PROVIDER", "OraOLEDB.Oracle.1");
  229. g_AppCfg.itsdb.sServerName = pIniFile->ReadString("ITSDB", "SERVERNAME", "HANTE");
  230. g_AppCfg.itsdb.sUserName = pIniFile->ReadString("ITSDB", "USERNAME", "hnits");
  231. g_AppCfg.itsdb.sPassword = pIniFile->ReadString("ITSDB", "PASSWORD", "hnits");
  232. //sSqlLog = pIniFile->ReadString("ITSDB", "SQLLOG", "0");
  233. //if (sSqlLog == "1") g_AppCfg.itsdb.bSqlLog = true;
  234. //시설물 아이콘 경로 로딩ㄷ
  235. LoadIcon(pIniFile, "VMS", "ICON_N", g_AppCfg.vms.ICON[icon_n]);
  236. LoadIcon(pIniFile, "VMS", "ICON_E", g_AppCfg.vms.ICON[icon_e]);
  237. LoadIcon(pIniFile, "VMS", "ICON_M", g_AppCfg.vms.ICON[icon_m]);
  238. LoadIcon(pIniFile, "VMS", "ICON_R", g_AppCfg.vms.ICON[icon_r]);
  239. LoadIcon(pIniFile, "VMS", "ICON_S", g_AppCfg.vms.ICON[icon_s]);
  240. LoadIcon(pIniFile, "VDS", "ICON_N", g_AppCfg.vds.ICON[icon_n]);
  241. LoadIcon(pIniFile, "VDS", "ICON_E", g_AppCfg.vds.ICON[icon_e]);
  242. LoadIcon(pIniFile, "VDS", "ICON_M", g_AppCfg.vds.ICON[icon_m]);
  243. LoadIcon(pIniFile, "VDS", "ICON_R", g_AppCfg.vds.ICON[icon_r]);
  244. LoadIcon(pIniFile, "VDS", "ICON_S", g_AppCfg.vds.ICON[icon_s]);
  245. CenterId = pIniFile->ReadString("CENTER", "CENTERID", "L01");
  246. CenterName = pIniFile->ReadString("CENTER", "CENTERNAME", "중앙센터");
  247. CenterCd = CenterId.SubString(2, 2).ToIntDef(0);
  248. // GIS 설정정보 로딩
  249. g_GisInfo.mapType = pIniFile->ReadInteger("MAP", "MAPTYPE", 1);
  250. g_GisInfo.offLineMapPath = pIniFile->ReadString ("MAP", "OFFLINEMAP", "");
  251. //g_GisInfo.onLineMapPath = pIniFile->ReadString ("MAP", "ONLINEMAP", "");
  252. if (g_GisInfo.mapType != 0 && g_GisInfo.mapType != 1) g_GisInfo.mapType = 1; /* 1: Online, 0: Offline */
  253. if (IsDirectoryExists(g_GisInfo.offLineMapPath.c_str()))
  254. {
  255. g_GisInfo.offLineMapPath = g_GisInfo.offLineMapPath+"\\";
  256. g_GisInfo.offLineMapPath = StringReplace(g_GisInfo.offLineMapPath, ":\\", "://", TReplaceFlags() << rfReplaceAll);
  257. g_GisInfo.offLineMapPath = StringReplace(g_GisInfo.offLineMapPath, "\\", "/", TReplaceFlags() << rfReplaceAll);
  258. }
  259. else
  260. {
  261. if (g_GisInfo.offLineMapPath.UpperCase().Pos("HTTP"))
  262. {
  263. g_GisInfo.offLineMapPath = g_GisInfo.offLineMapPath+"/";
  264. }
  265. else
  266. {
  267. g_GisInfo.offLineMapPath = "";
  268. }
  269. }
  270. g_GisInfo.imagePath = g_sMapDir+"images\\";
  271. g_GisInfo.imagePath = StringReplace(g_GisInfo.imagePath, ":\\", "://", TReplaceFlags() << rfReplaceAll);
  272. g_GisInfo.imagePath = StringReplace(g_GisInfo.imagePath, "\\", "/", TReplaceFlags() << rfReplaceAll);
  273. g_GisInfo.sApiKey = pIniFile->ReadString ("MAP", "APIKEY", "");
  274. g_GisInfo.nZoomLevel = pIniFile->ReadInteger("MAP", "INITZOOM", 11);
  275. g_GisInfo.nMinZoom = pIniFile->ReadInteger("MAP", "MINZOOM", 1);
  276. g_GisInfo.nMaxZoom = pIniFile->ReadInteger("MAP", "MAXZOOM", 19);
  277. g_GisInfo.nFacilityZoom = pIniFile->ReadInteger("MAP", "FACILITYZOOM", 14);
  278. g_GisInfo.dCenterX = pIniFile->ReadString ("MAP", "CENTERX", "33.3536449").ToDouble();
  279. g_GisInfo.dCenterY = pIniFile->ReadString ("MAP", "CENTERY", "126.5278103").ToDouble();
  280. //VMS FTP
  281. g_AppCfg.vmsFtp.SERVER = pIniFile->ReadString("VMS_FTP", "SERVER", "");
  282. g_AppCfg.vmsFtp.PORT = pIniFile->ReadString("VMS_FTP", "PORT", "21").ToIntDef(21);
  283. g_AppCfg.vmsFtp.USER = pIniFile->ReadString("VMS_FTP", "USER", "");
  284. g_AppCfg.vmsFtp.PSWD = pIniFile->ReadString("VMS_FTP", "PSWD", "");
  285. g_AppCfg.vmsFtp.PASSIVE = pIniFile->ReadString("VMS_FTP", "PASSIVE", "0").ToIntDef(0) == 0 ? false : true;
  286. }
  287. __finally
  288. {
  289. if (pIniFile) delete pIniFile;
  290. pIniFile = NULL;
  291. //WriteConfigInfo(sCfgFile, "AUTOLOGOUT", "LOGOUTEXIT", "0");
  292. }
  293. return true;
  294. }
  295. //---------------------------------------------------------------------------
  296. /*
  297. * 환경설정 정보를 저장하는 함수.
  298. * arguments
  299. * String : RegisterKey 또는 파일이름
  300. * return
  301. * bool : 실패하면 false
  302. */
  303. bool WriteConfigInfo(String sCfgFile, String sTitle, String sItem, String sValue)
  304. {
  305. String ConfigFile;
  306. TIniFile *pIniFile = NULL;
  307. ConfigFile = sCfgFile;
  308. try
  309. {
  310. pIniFile = new TIniFile(ConfigFile);
  311. if (pIniFile == NULL)
  312. {
  313. return false;
  314. }
  315. pIniFile->WriteString(sTitle, sItem, sValue);
  316. }
  317. catch(...)
  318. {
  319. }
  320. if (pIniFile)
  321. {
  322. pIniFile->Free();
  323. pIniFile = NULL;
  324. }
  325. return true;
  326. }
  327. //---------------------------------------------------------------------------
  328. /*
  329. * 환경설정 정보를 읽어오는 함수.
  330. * arguments
  331. * String : RegisterKey 또는 파일이름
  332. * return
  333. * bool : 실패하면 false
  334. */
  335. bool ReadConfigInfo(String sCfgFile, String sTitle, String sItem, String &sValue)
  336. {
  337. bool bRes;
  338. String ConfigFile;
  339. TIniFile *pIniFile = NULL;
  340. bRes = false;
  341. ConfigFile = sCfgFile;
  342. try
  343. {
  344. pIniFile = new TIniFile(ConfigFile);
  345. if (pIniFile == NULL)
  346. {
  347. return bRes;
  348. }
  349. sValue = pIniFile->ReadString(sTitle, sItem, "");
  350. if (sValue != "")
  351. {
  352. bRes = true;
  353. }
  354. }
  355. catch(...)
  356. {
  357. }
  358. if (pIniFile)
  359. {
  360. pIniFile->Free();
  361. pIniFile = NULL;
  362. }
  363. return bRes;
  364. }
  365. //---------------------------------------------------------------------------
  366. void ShowErrorMsg(String ATitle, String AErrMsg)
  367. {
  368. Application->NormalizeTopMosts();
  369. Application->MessageBox(AErrMsg.c_str(), ATitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
  370. Application->RestoreTopMosts();
  371. }
  372. //----------------------------------------------------------------------------
  373. String APP_FillCode(TcxComboBox *ACombo, String ACode)
  374. {
  375. String sReturn = "";
  376. #if 0
  377. ACombo->Properties->Items->Clear();
  378. TItsCode *FCodeRMF = ItsCodeManager->FLists.Find(ACode);
  379. if (FCodeRMF)
  380. {
  381. FOR_STL(TItsSubCode *, pSubCode, FCodeRMF->FSubLists)
  382. {
  383. if (pSubCode->USE_YN == "N") continue;
  384. ACombo->Properties->Items->Add(" [" + pSubCode->CMMN_CD + "] " + pSubCode->CMMN_CD_KOR_NM);
  385. if (sReturn == "")
  386. {
  387. sReturn = " [" + pSubCode->CMMN_CD + "] " + pSubCode->CMMN_CD_KOR_NM;
  388. }
  389. }
  390. }
  391. ACombo->ItemIndex = 0;
  392. #endif
  393. return sReturn;
  394. }
  395. //----------------------------------------------------------------------------
  396. String APP_GetCode(TcxComboBox *ACombo)
  397. {
  398. String sReturn = "";
  399. if (ACombo->ItemIndex >= 0)
  400. {
  401. String sDesc = ACombo->Properties->Items->Strings[ACombo->ItemIndex];
  402. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  403. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  404. sReturn = sCode;
  405. }
  406. return sReturn;
  407. }
  408. //----------------------------------------------------------------------------
  409. String APP_GetCodeDesc(TcxComboBox *ACombo, String ACode)
  410. {
  411. String sReturn = "";
  412. for (int ii = 0; ii < ACombo->Properties->Items->Count; ii++)
  413. {
  414. String sDesc = ACombo->Properties->Items->Strings[ii];
  415. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  416. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  417. if (ACode == sCode)
  418. {
  419. sReturn = sDesc;
  420. break;
  421. }
  422. }
  423. return sReturn;
  424. }
  425. //----------------------------------------------------------------------------
  426. String APP_GetCodeName(TcxComboBox *ACombo, String ACode)
  427. {
  428. String sReturn = "";
  429. for (int ii = 0; ii < ACombo->Properties->Items->Count; ii++)
  430. {
  431. String sDesc = ACombo->Properties->Items->Strings[ii];
  432. String sName = sDesc.SubString(sDesc.Pos("]") + 1, sDesc.Length());
  433. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  434. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  435. if (ACode == sCode)
  436. {
  437. sReturn = sName.Trim();
  438. break;
  439. }
  440. }
  441. return sReturn;
  442. }
  443. //----------------------------------------------------------------------------
  444. String APP_GetCodeIdByName(TcxComboBox *ACombo, String AName)
  445. {
  446. String sReturn = "3";
  447. for (int ii = 0; ii < ACombo->Properties->Items->Count; ii++)
  448. {
  449. String sDesc = ACombo->Properties->Items->Strings[ii];
  450. String sName = sDesc.SubString(sDesc.Pos("]") + 1, sDesc.Length());
  451. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  452. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  453. if (sName.Trim() == AName.Trim())
  454. {
  455. sReturn = sCode;
  456. break;
  457. }
  458. }
  459. return sReturn;
  460. }
  461. //----------------------------------------------------------------------------
  462. String APP_GetCodeDefCode(TcxComboBox *ACombo)
  463. {
  464. String sReturn = "";
  465. if (ACombo->Properties->Items->Count > 0)
  466. {
  467. String sDesc = ACombo->Properties->Items->Strings[0];
  468. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  469. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  470. sReturn = sCode;
  471. }
  472. return sReturn;
  473. }
  474. //----------------------------------------------------------------------------
  475. String APP_GetCodeDefDesc(TcxComboBox *ACombo)
  476. {
  477. String sReturn = "";
  478. if (ACombo->Properties->Items->Count > 0)
  479. {
  480. String sDesc = ACombo->Properties->Items->Strings[0];
  481. sReturn = sDesc;
  482. }
  483. return sReturn;
  484. }
  485. //----------------------------------------------------------------------------
  486. int APP_SetCode(TcxComboBox *ACombo, String ACode)
  487. {
  488. int nItemIndex = -1;
  489. for (int ii = 0; ii < ACombo->Properties->Items->Count; ii++)
  490. {
  491. String sDesc = ACombo->Properties->Items->Strings[ii];
  492. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  493. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  494. if (ACode == sCode)
  495. {
  496. nItemIndex = ii;
  497. break;
  498. }
  499. }
  500. ACombo->ItemIndex = nItemIndex;
  501. return nItemIndex;
  502. }
  503. //----------------------------------------------------------------------------
  504. ULONG ProcIDFromWnd(HWND hwnd) // 윈도우 핸들로 프로세스 아이디 얻기
  505. {
  506. ULONG idProc;
  507. GetWindowThreadProcessId( hwnd, &idProc );
  508. return idProc;
  509. }
  510. //----------------------------------------------------------------------------
  511. HWND GetWinHandle(ULONG pid) // 프로세스 아이디로 윈도우 핸들 얻기
  512. {
  513. HWND tempHwnd = FindWindow(NULL,NULL); // 최상위 윈도우 핸들 찾기
  514. while( tempHwnd != NULL )
  515. {
  516. if( GetParent(tempHwnd) == NULL ) // 최상위 핸들인지 체크, 버튼 등도 핸들을 가질 수 있으므로 무시하기 위해
  517. if( pid == ProcIDFromWnd(tempHwnd) )
  518. return tempHwnd;
  519. tempHwnd = GetWindow(tempHwnd, GW_HWNDNEXT); // 다음 윈도우 핸들 찾기
  520. }
  521. return NULL;
  522. }
  523. //----------------------------------------------------------------------------
  524. String ITSUtil_FormatStr(String AStrDateTime, String AFormat)
  525. {
  526. #define SYEAR "-"
  527. #define STIME ":"
  528. #define SPACE " "
  529. String sDateTime = "";
  530. String sInData = AnsiString(AStrDateTime);
  531. //ShowMessage("IN: " + AStrDateTime + " " + sInData + " " + AFormat);
  532. if (sInData.IsEmpty())
  533. return sInData;
  534. //sDateTime = sInData;
  535. try
  536. {
  537. if (AFormat == STR_DATETIME)
  538. {
  539. if (sInData.Length() < 14) return sInData;
  540. sDateTime = sInData.SubString( 1, 4) + SYEAR +
  541. sInData.SubString( 5, 2) + SYEAR +
  542. sInData.SubString( 7, 2) + SPACE +
  543. sInData.SubString( 9, 2) + STIME +
  544. sInData.SubString(11, 2) + STIME +
  545. sInData.SubString(13, 2);
  546. }
  547. else
  548. if (AFormat == STR_HHNN)
  549. {
  550. if (sInData.Length() < 12) return sInData;
  551. sDateTime = sInData.SubString( 1, 4) + SYEAR +
  552. sInData.SubString( 5, 2) + SYEAR +
  553. sInData.SubString( 7, 2) + SPACE +
  554. sInData.SubString( 9, 2) + STIME +
  555. sInData.SubString(11, 2);
  556. }
  557. else
  558. if (AFormat == STR_DATEHOUR)
  559. {
  560. if (sInData.Length() < 10) return sInData;
  561. sDateTime = sInData.SubString( 1, 4) + SYEAR +
  562. sInData.SubString( 5, 2) + SYEAR +
  563. sInData.SubString( 7, 2) + SPACE +
  564. sInData.SubString( 9, 2);
  565. }
  566. else
  567. if (AFormat == STR_DATE)
  568. {
  569. if (sInData.Length() < 8) return sInData;
  570. sDateTime = sInData.SubString( 1, 4) + SYEAR +
  571. sInData.SubString( 5, 2) + SYEAR +
  572. sInData.SubString( 7, 2);
  573. }
  574. else
  575. if (AFormat == STR_MM)
  576. {
  577. if (sInData.Length() < 6) return sInData;
  578. sDateTime = sInData.SubString( 1, 4) + SYEAR +
  579. sInData.SubString( 5, 2);
  580. }
  581. else
  582. {
  583. sDateTime = sInData;
  584. }
  585. }
  586. catch(...)
  587. {
  588. }
  589. //ShowMessage("OUT: " + sDateTime);
  590. return sDateTime;
  591. }
  592. //---------------------------------------------------------------------------
  593. TColor g_DispColor[MAX_DISPCOLOR];
  594. void APP_InitDisplayColor()
  595. {
  596. #if 0
  597. g_DispColor[ 0] = Graphics::clBlue;
  598. g_DispColor[ 1] = Graphics::clRed;
  599. g_DispColor[ 2] = Graphics::clLime;
  600. g_DispColor[ 3] = Graphics::clMaroon;
  601. g_DispColor[ 4] = Graphics::clGreen;
  602. g_DispColor[ 5] = Graphics::clMenuHighlight;
  603. g_DispColor[ 6] = Graphics::clBackground;
  604. g_DispColor[ 7] = Graphics::clPurple;
  605. g_DispColor[ 8] = Graphics::clTeal;
  606. g_DispColor[ 9] = Graphics::clYellow;
  607. g_DispColor[10] = Graphics::clFuchsia;
  608. g_DispColor[11] = Graphics::clAqua;
  609. g_DispColor[12] = Graphics::clMoneyGreen;
  610. g_DispColor[13] = Graphics::clSkyBlue;
  611. g_DispColor[14] = Graphics::clRed;
  612. g_DispColor[15] = Graphics::clLime;
  613. g_DispColor[16] = Graphics::clYellow;
  614. g_DispColor[17] = Graphics::clBlue;
  615. g_DispColor[18] = Graphics::clFuchsia;
  616. g_DispColor[19] = Graphics::clAqua;
  617. g_DispColor[20] = Graphics::clMoneyGreen;
  618. g_DispColor[21] = Graphics::clActiveCaption;
  619. #else
  620. g_DispColor[ 0] = Graphics::clLime;
  621. g_DispColor[ 1] = (TColor)RGB(0xFF, 0x00, 0x00);
  622. g_DispColor[ 2] = (TColor)RGB(0x00, 0x00, 0xFF);
  623. g_DispColor[ 3] = (TColor)RGB(0xFF, 0x82, 0x00);
  624. g_DispColor[ 4] = (TColor)RGB(0x94, 0x00, 0xD3);
  625. g_DispColor[ 5] = Graphics::clPurple;//(TColor)RGB(0x00, 0x00, 0x00);
  626. g_DispColor[ 6] = (TColor)RGB(0x82, 0x82, 0x82);
  627. g_DispColor[ 7] = (TColor)RGB(0x1E, 0x90, 0xFF);
  628. g_DispColor[ 8] = (TColor)RGB(0xB9, 0x06, 0x2F);
  629. g_DispColor[ 9] = (TColor)RGB(0x8c, 0x00, 0x8c);
  630. g_DispColor[10] = (TColor)RGB(0xFF, 0x82, 0x00);
  631. g_DispColor[11] = (TColor)RGB(0x94, 0x00, 0xD3);
  632. g_DispColor[12] = (TColor)RGB(0xB0, 0xC4, 0xDE);
  633. g_DispColor[13] = (TColor)RGB(0x00, 0xBF, 0xFF);
  634. g_DispColor[14] = (TColor)RGB(0x87, 0xCE, 0xEB);
  635. g_DispColor[15] = (TColor)RGB(0x87, 0xCE, 0xFA);
  636. g_DispColor[16] = (TColor)RGB(0xAD, 0xD8, 0xE6);
  637. g_DispColor[17] = (TColor)RGB(0xB0, 0xE0, 0xE6);
  638. g_DispColor[18] = (TColor)RGB(0xE6, 0xE6, 0xFA);
  639. g_DispColor[19] = (TColor)RGB(0xF0, 0xF8, 0xFF);
  640. #endif
  641. }
  642. //---------------------------------------------------------------------------
  643. TColor APP_GetDisplayColor(int ASeq)
  644. {
  645. return g_DispColor[ASeq % MAX_DISPCOLOR];
  646. }
  647. //---------------------------------------------------------------------------
  648. void APP_DelVmsSizeCombo(TcxComboBox *cboBox)
  649. {
  650. TStrings *pStrItems;
  651. TVmsSizeType *Ov;
  652. pStrItems = ((TcxComboBox *)cboBox)->Properties->Items;
  653. for (int ii = pStrItems->Count-1; ii >= 0; ii--)
  654. {
  655. Ov = (TVmsSizeType *)pStrItems->Objects[ii];
  656. if (Ov != NULL)
  657. {
  658. delete Ov;
  659. Ov = NULL;
  660. }
  661. }
  662. }
  663. //---------------------------------------------------------------------------
  664. void APP_FillVmsSizeType(TcxComboBox *cboBox, bool bAddAll/*=false*/)
  665. {
  666. #if 0
  667. String sQry;
  668. TStrings *pStrItems;
  669. TADOQuery *pADO = NULL;
  670. APP_DelVmsSizeCombo(cboBox);
  671. pStrItems = ((TcxComboBox *)cboBox)->Properties->Items;
  672. ((TcxComboBox *)cboBox)->Properties->Items->Clear();
  673. FOR_STL(TVmsType*, pObj, VmsTypeManager->FLists)
  674. {
  675. String sTypeCd = pObj->VMS_TYPE_CD;
  676. String sTypeNm = pObj->VMS_TYPE_NM;
  677. int nW = pObj->VMS_WDTH;
  678. int nH = pObj->VMS_HGHT;
  679. int nR = pObj->ROW_NUM;
  680. int nC = pObj->COL_NUM;
  681. pStrItems->AddObject(" [" + sTypeCd + "] " + sTypeNm + " (" + String(nW) + "x" + String(nH) + ")", new TVmsSizeType(sTypeCd, sTypeNm, nW, nH, nR, nC) );
  682. }
  683. if (bAddAll)
  684. {
  685. String sAllName = "전체";
  686. pStrItems->AddObject(" [ALL] 전체" , new TVmsSizeType("ALL", sAllName, 384, 64, 2, 12));
  687. }
  688. cboBox->ItemIndex = 0;
  689. #endif
  690. }
  691. //---------------------------------------------------------------------------
  692. TVmsSizeType* APP_GetVmsSizeTypeObject(TcxComboBox *cboBox)
  693. {
  694. #if 0
  695. TStrings *pStrItems;
  696. TVmsSizeType *Ov = NULL;
  697. int nItemIndex;
  698. pStrItems = ((TcxComboBox *)cboBox)->Properties->Items;
  699. nItemIndex= ((TcxComboBox *)cboBox)->ItemIndex;
  700. if (nItemIndex < 0)
  701. {
  702. return Ov;
  703. }
  704. Ov = (TVmsSizeType *)pStrItems->Objects[nItemIndex];
  705. if (Ov == NULL)
  706. {
  707. Ov = NULL;
  708. }
  709. return Ov;
  710. #endif
  711. return NULL;
  712. }
  713. //---------------------------------------------------------------------------
  714. void APP_ImageClear(TCanvas *c, int offX, int offY, int w, int h, TColor color)
  715. {
  716. try
  717. {
  718. c->Pen->Color = clWhite;
  719. c->Pen->Width = 0;
  720. c->Pen->Style = psClear;
  721. c->Brush->Style = bsSolid;
  722. c->Brush->Color = color;
  723. c->Rectangle(offX, offY, w+offX+2, h+offY+2);
  724. }
  725. catch(...)
  726. {
  727. }
  728. }
  729. //---------------------------------------------------------------------------
  730. #include <DateUtils.hpp>
  731. TDateTime APP_StrToDateTime(String AStrDateTime)
  732. {
  733. TDateTime dtReturnValue = NULL;
  734. if (AStrDateTime.IsEmpty()) return dtReturnValue;
  735. if (AStrDateTime.Length() != 14) return dtReturnValue;
  736. AnsiString sDateTime = AnsiString(AStrDateTime);
  737. try
  738. {
  739. #if 0
  740. sDateTime.printf(L"%s-%s-%s %s:%s:%s",
  741. AStrDateTime.SubString( 1, 4).c_str(),
  742. AStrDateTime.SubString( 5, 2).c_str(),
  743. AStrDateTime.SubString( 7, 2).c_str(),
  744. AStrDateTime.SubString( 9, 2).c_str(),
  745. AStrDateTime.SubString(11, 2).c_str(),
  746. AStrDateTime.SubString(13, 2).c_str());
  747. dtReturnValue = StrToDateTime(sDateTime);
  748. #endif
  749. // swscanf(sRgb.c_str(), L"%d,%d,%d", &r, &g, &b);
  750. int year, month, day, hour, minute, second;
  751. sscanf(sDateTime.c_str(), "%4d%2d%2d%2d%2d%2d", &year, &month, &day, &hour, &minute, &second);
  752. dtReturnValue = EncodeDateTime(year, month, day, hour, minute, second, 0);
  753. }
  754. catch(...)
  755. {
  756. }
  757. return dtReturnValue;
  758. }
  759. //---------------------------------------------------------------------------