AppGlobalF.cpp 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913
  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. #if 0
  138. //세종시
  139. g_AppCfg.vmscam.sComModel = pIniFile->ReadString("VMSCAMERA", "COMPANY", "Samsung");
  140. g_AppCfg.vmscam.sDevModel = pIniFile->ReadString("VMSCAMERA", "DEVICE", "Samsung Network Camera/Encoder");
  141. #else
  142. g_AppCfg.vmscam.sComModel = pIniFile->ReadString("VMSCAMERA", "COMPANY", "Samsung");
  143. g_AppCfg.vmscam.sDevModel = pIniFile->ReadString("VMSCAMERA", "DEVICE", "SNP-3371TH");
  144. #endif
  145. CenterId = pIniFile->ReadString("CENTER", "CENTERID", "L01");
  146. CenterName = pIniFile->ReadString("CENTER", "CENTERNAME", "PASIG City");
  147. CenterCd = String(StrToInt(CenterId.SubString(2, 2)));
  148. #if 0
  149. g_AppCfg.flashmap.sMainMap = pIniFile->ReadString("FLASHMAP", "MAINMAP", "");
  150. g_AppCfg.flashmap.sLinkMap = pIniFile->ReadString("FLASHMAP", "LINKMAP", "");
  151. if (g_AppCfg.flashmap.sMainMap == "" ||
  152. g_AppCfg.flashmap.sLinkMap == "")
  153. {
  154. Application->MessageBox(L"지도 설정 정보를 읽어오는데 실패하였습니다.!!!!!!!!!!",
  155. L"환경설정 정보 로딩 오류!!!",
  156. MB_OK|MB_ICONERROR);
  157. }
  158. g_AppCfg.flashmap.sMainMap = g_sAppDir + g_AppCfg.flashmap.sMainMap;
  159. g_AppCfg.flashmap.sLinkMap = g_sAppDir + g_AppCfg.flashmap.sLinkMap;
  160. #endif
  161. }
  162. __finally
  163. {
  164. if (pIniFile) delete pIniFile;
  165. pIniFile = NULL;
  166. WriteConfigInfo(sIniFile, "AUTOLOGOUT", "LOGOUTEXIT", "0");
  167. }
  168. return true;
  169. }
  170. //---------------------------------------------------------------------------
  171. bool CMM_InsertLoginHist(PLOGININFO pLogin, bool ALogin)
  172. {
  173. String sQry;
  174. bool bResult= false;
  175. TADOQuery *adoQry = NULL;
  176. if (!pLogin) return false;
  177. if (ALogin)
  178. {
  179. sQry = "INSERT INTO TB_USERCNNC_HS ( \r\n"
  180. " LOGIN_HMS, \r\n"
  181. " USER_ID, \r\n"
  182. " LOGOUT_HMS \r\n"
  183. " ) \r\n"
  184. "VALUES ( \r\n"
  185. " :p01, \r\n"
  186. " :p02, \r\n"
  187. " NULL \r\n"
  188. " ) \r\n";
  189. }
  190. else
  191. {
  192. sQry = "UPDATE TB_USERCNNC_HS SET \r\n"
  193. " LOGOUT_HMS = TO_CHAR(SYSDATE, 'YYYYMMDDHH24MISS') \r\n"
  194. " WHERE LOGIN_HMS = :p01 \r\n"
  195. " AND USER_ID = :p02 \r\n";
  196. }
  197. try
  198. {
  199. try
  200. {
  201. adoQry = new TADOQuery(NULL);
  202. adoQry->Connection = ITSDb_GetConnection();
  203. ITSDb_GetConnection()->BeginTrans();
  204. adoQry->Close();
  205. adoQry->SQL->Text = sQry;
  206. adoQry->Parameters->ParamByName("p01")->Value = pLogin->sLoginTime;
  207. adoQry->Parameters->ParamByName("p02")->Value = pLogin->sUserId;
  208. int nRowCnt = adoQry->ExecSQL();
  209. ITSDb_GetConnection()->CommitTrans();
  210. bResult = nRowCnt > 1 ? true : false;
  211. }
  212. catch (Exception &exception)
  213. {
  214. ITSDb_GetConnection()->RollbackTrans();
  215. throw Exception(String(exception.ClassName()) + exception.Message);
  216. }
  217. catch (...)
  218. {
  219. ITSDb_GetConnection()->RollbackTrans();
  220. }
  221. }
  222. __finally
  223. {
  224. if (adoQry)
  225. {
  226. adoQry->Close();
  227. delete adoQry;
  228. }
  229. }
  230. return bResult;
  231. }
  232. //---------------------------------------------------------------------------
  233. bool ITSLoginProc(String sConnSystem, String sDefUser, TComponent *Owner)
  234. {
  235. bool bResult= false;
  236. PLOGININFO pLogin = ITSDb_GetLoginInfo();
  237. if (NULL == pLogin) return bResult;
  238. FRMLogin = new TFRMLogin(Owner);
  239. if (FRMLogin)
  240. {
  241. FRMLogin->EdUserID->Text = sDefUser;
  242. FRMLogin->ShowModal();
  243. pLogin->bLogin = FRMLogin->m_bLogin;
  244. if (pLogin->bLogin)
  245. {
  246. pLogin->sUserId = FRMLogin->m_sUserID;
  247. pLogin->sUserName = FRMLogin->m_sUserName;
  248. pLogin->sUserRightId = FRMLogin->m_sUserRightID;
  249. pLogin->sUserRightName = FRMLogin->m_sUserRightName;
  250. pLogin->sConnSystem = sConnSystem;
  251. pLogin->sLoginIp = FRMLogin->GetLocalIp();
  252. pLogin->sLoginTime = FRMLogin->m_sLoginTime;
  253. }
  254. else
  255. {
  256. pLogin->sUserId = "default";
  257. pLogin->sUserName = "default";
  258. pLogin->sUserRightId = "1";
  259. pLogin->sUserRightName = "";
  260. pLogin->sConnSystem = "OPR";
  261. pLogin->sLoginSeq = "0";
  262. pLogin->sLoginIp = "127.0.0.1";
  263. pLogin->sLoginTime = Now().FormatString("yyyymmddhhnnss");
  264. }
  265. delete FRMLogin;
  266. FRMLogin = NULL;
  267. bResult = pLogin->bLogin;
  268. }
  269. else
  270. {
  271. bResult = false;
  272. }
  273. if (bResult) CMM_InsertLoginHist(pLogin, true);
  274. return bResult;
  275. }
  276. //---------------------------------------------------------------------------
  277. void ITSLogoutProc()
  278. {
  279. PLOGININFO pLogin = ITSDb_GetLoginInfo();
  280. if (pLogin)
  281. {
  282. if (pLogin->bLogin) CMM_InsertLoginHist(pLogin, false);
  283. pLogin->bLogin = false;
  284. }
  285. }
  286. //---------------------------------------------------------------------------
  287. int UserLogin()
  288. {
  289. if (ITSLoginProc("OPR", g_AppCfg.sDefUseId, Application))
  290. {
  291. g_pLOGIN = ITSDb_GetLoginInfo();
  292. if (g_pLOGIN) WriteConfigInfo(g_AppCfg.sConfigFile, "APPLICATION", "LASTUSER", g_pLOGIN->sUserId);
  293. }
  294. return g_pLOGIN == NULL ? 0 : 1;
  295. }
  296. //---------------------------------------------------------------------------
  297. int UserLogout()
  298. {
  299. if (g_pLOGIN)
  300. WriteConfigInfo(g_AppCfg.sConfigFile, "APPLICATION", "LASTUSER", g_pLOGIN->sUserId);
  301. if (g_AppCfg.AutoLogout.LogoutExit)
  302. WriteConfigInfo(g_AppCfg.sConfigFile, "AUTOLOGOUT", "LOGOUTEXIT", "1");
  303. else
  304. WriteConfigInfo(g_AppCfg.sConfigFile, "AUTOLOGOUT", "LOGOUTEXIT", "0");
  305. ITSLogoutProc();
  306. g_pLOGIN = NULL;
  307. return 0;
  308. }
  309. //---------------------------------------------------------------------------
  310. /*
  311. * 환경설정 정보를 저장하는 함수.
  312. * arguments
  313. * String : RegisterKey 또는 파일이름
  314. * return
  315. * bool : 실패하면 false
  316. */
  317. bool WriteConfigInfo(String sCfgFile, String sTitle, String sItem, String sValue)
  318. {
  319. String ConfigFile;
  320. TIniFile *pIniFile = NULL;
  321. ConfigFile = sCfgFile;
  322. try
  323. {
  324. pIniFile = new TIniFile(ConfigFile);
  325. if (pIniFile == NULL)
  326. {
  327. return false;
  328. }
  329. pIniFile->WriteString(sTitle, sItem, sValue);
  330. }
  331. catch(...)
  332. {
  333. }
  334. if (pIniFile)
  335. {
  336. pIniFile->Free();
  337. pIniFile = NULL;
  338. }
  339. return true;
  340. }
  341. //---------------------------------------------------------------------------
  342. /*
  343. * 환경설정 정보를 읽어오는 함수.
  344. * arguments
  345. * String : RegisterKey 또는 파일이름
  346. * return
  347. * bool : 실패하면 false
  348. */
  349. bool ReadConfigInfo(String sCfgFile, String sTitle, String sItem, String &sValue)
  350. {
  351. bool bRes;
  352. String ConfigFile;
  353. TIniFile *pIniFile = NULL;
  354. bRes = false;
  355. ConfigFile = sCfgFile;
  356. try
  357. {
  358. pIniFile = new TIniFile(ConfigFile);
  359. if (pIniFile == NULL)
  360. {
  361. return bRes;
  362. }
  363. sValue = pIniFile->ReadString(sTitle, sItem, "");
  364. if (sValue != "")
  365. {
  366. bRes = true;
  367. }
  368. }
  369. catch(...)
  370. {
  371. }
  372. if (pIniFile)
  373. {
  374. pIniFile->Free();
  375. pIniFile = NULL;
  376. }
  377. return bRes;
  378. }
  379. //---------------------------------------------------------------------------
  380. void ShowErrorMsg(String ATitle, String AErrMsg)
  381. {
  382. Application->NormalizeTopMosts();
  383. Application->MessageBox(AErrMsg.c_str(), ATitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
  384. Application->RestoreTopMosts();
  385. }
  386. //----------------------------------------------------------------------------
  387. String APP_FillCode(TcxComboBox *ACombo, String ACode)
  388. {
  389. String sReturn = "";
  390. ACombo->Properties->Items->Clear();
  391. TItsCode *FCodeRMF = ItsCodeManager->FLists.Find(ACode);
  392. if (FCodeRMF)
  393. {
  394. FOR_STL(TItsSubCode *, pSubCode, FCodeRMF->FSubLists)
  395. {
  396. if (pSubCode->USE_YN == "N") continue;
  397. ACombo->Properties->Items->Add(" [" + pSubCode->CMMN_CD + "] " + pSubCode->CMMN_CD_KOR_NM);
  398. if (sReturn == "")
  399. {
  400. sReturn = " [" + pSubCode->CMMN_CD + "] " + pSubCode->CMMN_CD_KOR_NM;
  401. }
  402. }
  403. }
  404. ACombo->ItemIndex = 0;
  405. return sReturn;
  406. }
  407. //----------------------------------------------------------------------------
  408. String APP_GetCode(TcxComboBox *ACombo)
  409. {
  410. String sReturn = "";
  411. if (ACombo->ItemIndex >= 0)
  412. {
  413. String sDesc = ACombo->Properties->Items->Strings[ACombo->ItemIndex];
  414. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  415. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  416. sReturn = sCode;
  417. }
  418. return sReturn;
  419. }
  420. //----------------------------------------------------------------------------
  421. String APP_GetCodeDesc(TcxComboBox *ACombo, String ACode)
  422. {
  423. String sReturn = "";
  424. for (int ii = 0; ii < ACombo->Properties->Items->Count; ii++)
  425. {
  426. String sDesc = ACombo->Properties->Items->Strings[ii];
  427. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  428. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  429. if (ACode == sCode)
  430. {
  431. sReturn = sDesc;
  432. break;
  433. }
  434. }
  435. return sReturn;
  436. }
  437. //----------------------------------------------------------------------------
  438. String APP_GetCodeName(TcxComboBox *ACombo, String ACode)
  439. {
  440. String sReturn = "";
  441. for (int ii = 0; ii < ACombo->Properties->Items->Count; ii++)
  442. {
  443. String sDesc = ACombo->Properties->Items->Strings[ii];
  444. String sName = sDesc.SubString(sDesc.Pos("]") + 1, sDesc.Length());
  445. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  446. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  447. if (ACode == sCode)
  448. {
  449. sReturn = sName.Trim();
  450. break;
  451. }
  452. }
  453. return sReturn;
  454. }
  455. //----------------------------------------------------------------------------
  456. String APP_GetCodeIdByName(TcxComboBox *ACombo, String AName)
  457. {
  458. String sReturn = "3";
  459. for (int ii = 0; ii < ACombo->Properties->Items->Count; ii++)
  460. {
  461. String sDesc = ACombo->Properties->Items->Strings[ii];
  462. String sName = sDesc.SubString(sDesc.Pos("]") + 1, sDesc.Length());
  463. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  464. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  465. if (sName.Trim() == AName.Trim())
  466. {
  467. sReturn = sCode;
  468. break;
  469. }
  470. }
  471. return sReturn;
  472. }
  473. //----------------------------------------------------------------------------
  474. String APP_GetCodeDefCode(TcxComboBox *ACombo)
  475. {
  476. String sReturn = "";
  477. if (ACombo->Properties->Items->Count > 0)
  478. {
  479. String sDesc = ACombo->Properties->Items->Strings[0];
  480. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  481. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  482. sReturn = sCode;
  483. }
  484. return sReturn;
  485. }
  486. //----------------------------------------------------------------------------
  487. String APP_GetCodeDefDesc(TcxComboBox *ACombo)
  488. {
  489. String sReturn = "";
  490. if (ACombo->Properties->Items->Count > 0)
  491. {
  492. String sDesc = ACombo->Properties->Items->Strings[0];
  493. sReturn = sDesc;
  494. }
  495. return sReturn;
  496. }
  497. //----------------------------------------------------------------------------
  498. int APP_SetCode(TcxComboBox *ACombo, String ACode)
  499. {
  500. int nItemIndex = -1;
  501. for (int ii = 0; ii < ACombo->Properties->Items->Count; ii++)
  502. {
  503. String sDesc = ACombo->Properties->Items->Strings[ii];
  504. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  505. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  506. if (ACode == sCode)
  507. {
  508. nItemIndex = ii;
  509. break;
  510. }
  511. }
  512. ACombo->ItemIndex = nItemIndex;
  513. return nItemIndex;
  514. }
  515. //----------------------------------------------------------------------------
  516. ULONG ProcIDFromWnd(HWND hwnd) // 윈도우 핸들로 프로세스 아이디 얻기
  517. {
  518. ULONG idProc;
  519. GetWindowThreadProcessId( hwnd, &idProc );
  520. return idProc;
  521. }
  522. //----------------------------------------------------------------------------
  523. HWND GetWinHandle(ULONG pid) // 프로세스 아이디로 윈도우 핸들 얻기
  524. {
  525. HWND tempHwnd = FindWindow(NULL,NULL); // 최상위 윈도우 핸들 찾기
  526. while( tempHwnd != NULL )
  527. {
  528. if( GetParent(tempHwnd) == NULL ) // 최상위 핸들인지 체크, 버튼 등도 핸들을 가질 수 있으므로 무시하기 위해
  529. if( pid == ProcIDFromWnd(tempHwnd) )
  530. return tempHwnd;
  531. tempHwnd = GetWindow(tempHwnd, GW_HWNDNEXT); // 다음 윈도우 핸들 찾기
  532. }
  533. return NULL;
  534. }
  535. //----------------------------------------------------------------------------
  536. String ITSUtil_FormatStr(String AStrDateTime, String AFormat)
  537. {
  538. #define SYEAR "-"
  539. #define STIME ":"
  540. #define SPACE " "
  541. String sDateTime = "";
  542. String sInData = AnsiString(AStrDateTime);
  543. //ShowMessage("IN: " + AStrDateTime + " " + sInData + " " + AFormat);
  544. if (sInData.IsEmpty())
  545. return sInData;
  546. //sDateTime = sInData;
  547. try
  548. {
  549. if (AFormat == STR_DATETIME)
  550. {
  551. if (sInData.Length() < 14) return sInData;
  552. sDateTime = sInData.SubString( 1, 4) + SYEAR +
  553. sInData.SubString( 5, 2) + SYEAR +
  554. sInData.SubString( 7, 2) + SPACE +
  555. sInData.SubString( 9, 2) + STIME +
  556. sInData.SubString(11, 2) + STIME +
  557. sInData.SubString(13, 2);
  558. }
  559. else
  560. if (AFormat == STR_HHNN)
  561. {
  562. if (sInData.Length() < 12) return sInData;
  563. sDateTime = sInData.SubString( 1, 4) + SYEAR +
  564. sInData.SubString( 5, 2) + SYEAR +
  565. sInData.SubString( 7, 2) + SPACE +
  566. sInData.SubString( 9, 2) + STIME +
  567. sInData.SubString(11, 2);
  568. }
  569. else
  570. if (AFormat == STR_DATEHOUR)
  571. {
  572. if (sInData.Length() < 10) return sInData;
  573. sDateTime = sInData.SubString( 1, 4) + SYEAR +
  574. sInData.SubString( 5, 2) + SYEAR +
  575. sInData.SubString( 7, 2) + SPACE +
  576. sInData.SubString( 9, 2);
  577. }
  578. else
  579. if (AFormat == STR_DATE)
  580. {
  581. if (sInData.Length() < 8) return sInData;
  582. sDateTime = sInData.SubString( 1, 4) + SYEAR +
  583. sInData.SubString( 5, 2) + SYEAR +
  584. sInData.SubString( 7, 2);
  585. }
  586. else
  587. if (AFormat == STR_MM)
  588. {
  589. if (sInData.Length() < 6) return sInData;
  590. sDateTime = sInData.SubString( 1, 4) + SYEAR +
  591. sInData.SubString( 5, 2);
  592. }
  593. else
  594. {
  595. sDateTime = sInData;
  596. }
  597. }
  598. catch(...)
  599. {
  600. }
  601. //ShowMessage("OUT: " + sDateTime);
  602. return sDateTime;
  603. }
  604. //---------------------------------------------------------------------------
  605. TColor g_DispColor[MAX_DISPCOLOR];
  606. void APP_InitDisplayColor()
  607. {
  608. g_DispColor[ 0] = Graphics::clBlue;
  609. g_DispColor[ 1] = Graphics::clRed;
  610. g_DispColor[ 2] = Graphics::clLime;
  611. g_DispColor[ 3] = Graphics::clMaroon;
  612. g_DispColor[ 4] = Graphics::clGreen;
  613. g_DispColor[ 5] = Graphics::clMenuHighlight;
  614. g_DispColor[ 6] = Graphics::clBackground;
  615. g_DispColor[ 7] = Graphics::clPurple;
  616. g_DispColor[ 8] = Graphics::clTeal;
  617. g_DispColor[ 9] = Graphics::clYellow;
  618. g_DispColor[10] = Graphics::clFuchsia;
  619. g_DispColor[11] = Graphics::clAqua;
  620. g_DispColor[12] = Graphics::clMoneyGreen;
  621. g_DispColor[13] = Graphics::clSkyBlue;
  622. g_DispColor[14] = Graphics::clRed;
  623. g_DispColor[15] = Graphics::clLime;
  624. g_DispColor[16] = Graphics::clYellow;
  625. g_DispColor[17] = Graphics::clBlue;
  626. g_DispColor[18] = Graphics::clFuchsia;
  627. g_DispColor[19] = Graphics::clAqua;
  628. g_DispColor[20] = Graphics::clMoneyGreen;
  629. g_DispColor[21] = Graphics::clActiveCaption;
  630. }
  631. //---------------------------------------------------------------------------
  632. TColor APP_GetDisplayColor(int ASeq)
  633. {
  634. return g_DispColor[ASeq % MAX_DISPCOLOR];
  635. }
  636. //---------------------------------------------------------------------------
  637. void APP_DelVmsSizeCombo(TcxComboBox *cboBox)
  638. {
  639. TStrings *pStrItems;
  640. TVmsSizeType *Ov;
  641. pStrItems = ((TcxComboBox *)cboBox)->Properties->Items;
  642. for (int ii = pStrItems->Count-1; ii >= 0; ii--)
  643. {
  644. Ov = (TVmsSizeType *)pStrItems->Objects[ii];
  645. if (Ov != NULL)
  646. {
  647. delete Ov;
  648. Ov = NULL;
  649. }
  650. }
  651. }
  652. //---------------------------------------------------------------------------
  653. void APP_FillVmsSizeType(TcxComboBox *cboBox, String AType, bool bAddAll/*=false*/)
  654. {
  655. String sQry;
  656. TStrings *pStrItems;
  657. TADOQuery *pADO = NULL;
  658. APP_DelVmsSizeCombo(cboBox);
  659. pStrItems = ((TcxComboBox *)cboBox)->Properties->Items;
  660. ((TcxComboBox *)cboBox)->Properties->Items->Clear();
  661. sQry = "SELECT CMMN_CD, \r\n"
  662. " CMMN_CD_KOR_NM, \r\n"
  663. " NVL(ATRB1, '320') AS FORMW, \r\n"
  664. " NVL(ATRB2, '64') AS FORMH \r\n"
  665. " FROM TB_CMMN_CD \r\n"
  666. " WHERE CMMN_CLSF_CD = 'VMP' \r\n"
  667. " AND USE_YN = 'Y' \r\n"
  668. " AND CMMN_CD IN (SELECT DISTINCT VMS_TYPE_CD \r\n"
  669. " FROM TB_VMS_CTLR) \r\n"
  670. //" WHERE VMS_USAG_TYPE_CD = :p01) \r\n"
  671. " ORDER BY CMMN_CD DESC \r\n";
  672. try
  673. {
  674. try
  675. {
  676. pADO = new TADOQuery(NULL);
  677. pADO->Close();
  678. pADO->Connection = ITSDb_GetConnection();
  679. ITSDb_SQLText(pADO, sQry);
  680. //ITSDb_SQLBind(pADO, "p01", AType);
  681. ITSDb_SQLOpen(pADO);
  682. for( ; !pADO->Eof; pADO->Next())
  683. {
  684. String sTypeCd = pADO->FieldByName("CMMN_CD")->AsString;
  685. String sTypeNm = pADO->FieldByName("CMMN_CD_KOR_NM")->AsString;
  686. String sWidth = pADO->FieldByName("FORMW")->AsString;
  687. String sHeight = pADO->FieldByName("FORMH")->AsString;
  688. int nW = sWidth.ToIntDef(384);
  689. int nH = sHeight.ToIntDef(64);
  690. pStrItems->AddObject(" [" + sTypeCd + "] " + sTypeNm + " (" + String(nW) + "x" + String(nH) + ")", new TVmsSizeType(sTypeCd, sTypeNm, nW, nH) );
  691. }
  692. if (bAddAll)
  693. {
  694. String sAllName = "전체";
  695. pStrItems->AddObject(" [ALL] 전체" , new TVmsSizeType("ALL", sAllName, 384, 64));
  696. }
  697. cboBox->ItemIndex = 0;
  698. }
  699. catch(EDatabaseError &E)
  700. {
  701. DBERRORMSG("APP_FillVmsSizeType", String(E.ClassName()), E.Message, sQry);
  702. throw Exception(String(E.ClassName()) + E.Message);
  703. }
  704. catch(Exception &exception)
  705. {
  706. DBERRORMSG("APP_FillVmsSizeType", String(exception.ClassName()), exception.Message, sQry);
  707. throw Exception(String(exception.ClassName()) + exception.Message);
  708. }
  709. }
  710. __finally
  711. {
  712. if (pADO)
  713. {
  714. pADO->Close();
  715. delete pADO;
  716. }
  717. }
  718. }
  719. //---------------------------------------------------------------------------
  720. TVmsSizeType* APP_GetVmsSizeTypeObject(TcxComboBox *cboBox)
  721. {
  722. TStrings *pStrItems;
  723. TVmsSizeType *Ov = NULL;
  724. int nItemIndex;
  725. pStrItems = ((TcxComboBox *)cboBox)->Properties->Items;
  726. nItemIndex= ((TcxComboBox *)cboBox)->ItemIndex;
  727. if (nItemIndex < 0)
  728. {
  729. return Ov;
  730. }
  731. Ov = (TVmsSizeType *)pStrItems->Objects[nItemIndex];
  732. if (Ov == NULL)
  733. {
  734. Ov = NULL;
  735. }
  736. return Ov;
  737. }
  738. //---------------------------------------------------------------------------
  739. void APP_ImageClear(TCanvas *c, int offX, int offY, int w, int h, TColor color)
  740. {
  741. try
  742. {
  743. c->Pen->Color = clWhite;
  744. c->Pen->Width = 0;
  745. c->Pen->Style = psClear;
  746. c->Brush->Style = bsSolid;
  747. c->Brush->Color = color;
  748. c->Rectangle(offX, offY, w+offX+2, h+offY+2);
  749. }
  750. catch(...)
  751. {
  752. }
  753. }
  754. //---------------------------------------------------------------------------
  755. #include <DateUtils.hpp>
  756. TDateTime APP_StrToDateTime(String AStrDateTime)
  757. {
  758. TDateTime dtReturnValue = NULL;
  759. if (AStrDateTime.IsEmpty()) return dtReturnValue;
  760. if (AStrDateTime.Length() != 14) return dtReturnValue;
  761. AnsiString sDateTime = AnsiString(AStrDateTime);
  762. try
  763. {
  764. #if 0
  765. sDateTime.printf(L"%s-%s-%s %s:%s:%s",
  766. AStrDateTime.SubString( 1, 4).c_str(),
  767. AStrDateTime.SubString( 5, 2).c_str(),
  768. AStrDateTime.SubString( 7, 2).c_str(),
  769. AStrDateTime.SubString( 9, 2).c_str(),
  770. AStrDateTime.SubString(11, 2).c_str(),
  771. AStrDateTime.SubString(13, 2).c_str());
  772. dtReturnValue = StrToDateTime(sDateTime);
  773. #endif
  774. // swscanf(sRgb.c_str(), L"%d,%d,%d", &r, &g, &b);
  775. int year, month, day, hour, minute, second;
  776. sscanf(sDateTime.c_str(), "%4d%2d%2d%2d%2d%2d", &year, &month, &day, &hour, &minute, &second);
  777. dtReturnValue = EncodeDateTime(year, month, day, hour, minute, second, 0);
  778. }
  779. catch(...)
  780. {
  781. }
  782. return dtReturnValue;
  783. }
  784. //---------------------------------------------------------------------------