AppGlobalF.cpp 32 KB

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