AppGlobalF.cpp 27 KB

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