AppGlobalF.cpp 29 KB

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