AppGlobalF.cpp 32 KB

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