AppGlobalF.cpp 28 KB

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