AppGlobalF.cpp 33 KB

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