AppGlobalF.cpp 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046
  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 "CDSVmsObjTypeF.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. //---------------------------------------------------------------------------
  37. void LoadIcon(TIniFile* AIniFile, String ASection, String AItem, String& AValue)
  38. {
  39. try
  40. {
  41. AValue = AIniFile->ReadString(ASection, AItem, "");
  42. if (AValue != "")
  43. {
  44. AValue = g_sAppDir + "Image\\" + AValue;
  45. if (!FileExists(AValue)) AValue = "";
  46. }
  47. }
  48. catch(Exception &e)
  49. {
  50. }
  51. }
  52. //---------------------------------------------------------------------------
  53. #include <windows.h>
  54. #include <shlwapi.h>
  55. #pragma comment (lib, "shlwapi.lib")
  56. bool IsDirectoryExists(LPCTSTR path)
  57. {
  58. return PathFileExists(path);
  59. #if 0
  60. struct _stat buffer;
  61. int iRetTemp = 0;
  62. memset((void*)&buffer, 0, sizeof(buffer));
  63. iRetTemp = _stat(path, &buffer);
  64. if (iRetTemp == 0)
  65. {
  66. if (buffer.st_mode & _S_IFDIR)
  67. {
  68. return true;
  69. }
  70. }
  71. return false;
  72. #endif
  73. }
  74. //---------------------------------------------------------------------------
  75. bool LoadDefaultConfigInfo(String ACfgFile/*=""*/)
  76. {
  77. String sCfgFile;
  78. TIniFile *pIniFile = NULL;
  79. String sIniFile = ChangeFileExt(ExtractFileName(Application->ExeName), ".ini");
  80. if (!ACfgFile.IsEmpty())
  81. sIniFile = ACfgFile + ".ini";
  82. sCfgFile = g_sCfgDir + sIniFile;
  83. g_AppCfg.sConfigFile = sCfgFile;
  84. g_AppCfg.AutoLogout.Enabled = false;
  85. g_AppCfg.AutoLogout.IntervalMin = 0;
  86. g_AppCfg.AutoLogout.LogoutExit = false;
  87. g_AppCfg.thr.pThread = NULL;
  88. g_AppCfg.thr.dwThreadId = 0;
  89. g_AppCfg.thr.nHandle = 0;
  90. g_AppCfg.thr.bRunning = false;
  91. g_AppCfg.bAppClose = false;
  92. try
  93. {
  94. String sTmp;
  95. pIniFile = new TIniFile(sCfgFile);
  96. g_AppCfg.sTitle = pIniFile->ReadString("APPLICATION", "TITLE", "광역교통정보 교통관리시스템");
  97. g_AppCfg.sProcessId = pIniFile->ReadString("APPLICATION", "PROCESSID", "999999");
  98. g_AppCfg.sLogDay = pIniFile->ReadString("APPLICATION", "LOGDAY", "");
  99. g_AppCfg.sAppPath = pIniFile->ReadString("APPLICATION", "APP_PATH", "");
  100. g_AppCfg.sSkinName = pIniFile->ReadString("APPLICATION", "SKINNAME", "Black");
  101. if (g_AppCfg.sSkinName.IsEmpty()) g_AppCfg.sSkinName = "Blue";
  102. sTmp = pIniFile->ReadString("APPLICATION", "SAVEFORM", "1");
  103. g_AppCfg.bSaveForm = (sTmp == "1") ? true : false;
  104. sTmp = "1";
  105. sTmp = pIniFile->ReadString("APPLICATION", "LOGINPROMPT", "1");
  106. g_AppCfg.bLoginPrompt = (sTmp == "1") ? true : false;
  107. g_AppCfg.sDefUseId = pIniFile->ReadString("APPLICATION", "LASTUSER", "");
  108. g_AppCfg.sLang = pIniFile->ReadString("APPLICATION", "LANGUAGE", "kr");
  109. g_AppCfg.sLang = g_AppCfg.sLang.LowerCase();
  110. if (g_AppCfg.sLang != "en" && g_AppCfg.sLang != "kr")
  111. g_AppCfg.sLang = "kr";
  112. g_AppCfg.bDebug = false;
  113. sTmp = pIniFile->ReadString("APPLICATION", "DEBUG", "0");
  114. if (sTmp == "1") g_AppCfg.bDebug = true;
  115. g_AppCfg.bTermChildProg = true;
  116. sTmp = pIniFile->ReadString("APPLICATION", "TERMCHILD", "1");
  117. if (sTmp == "0") g_AppCfg.bTermChildProg = false;
  118. g_AppCfg.bOnlyOneScreen = true;
  119. sTmp = pIniFile->ReadString("APPLICATION", "ONESCREEN", "1");
  120. if (sTmp == "0") g_AppCfg.bOnlyOneScreen = false;
  121. sTmp = pIniFile->ReadString("ALARM", "WINDOW", "1");
  122. g_AppCfg.Alarm.Window = (sTmp == "1") ? true : false;
  123. sTmp = pIniFile->ReadString("ALARM", "ENABLED", "0");
  124. g_AppCfg.Alarm.Enabled = (sTmp == "1") ? true : false;
  125. sTmp = pIniFile->ReadString("ALARM", "TIMEOUT", "10");
  126. g_AppCfg.Alarm.TimeOut = sTmp.ToIntDef(0);
  127. if (g_AppCfg.Alarm.TimeOut == 0) g_AppCfg.Alarm.TimeOut = 10;
  128. if (g_AppCfg.Alarm.TimeOut > 60) g_AppCfg.Alarm.TimeOut = 60;
  129. sTmp = pIniFile->ReadString("TEMPERATURE", "ALARMVALUE", "45");
  130. g_AppCfg.Temp.AlarmValue = sTmp.ToIntDef(0);
  131. sTmp = pIniFile->ReadString("INCIDENT", "WINDOW", "1");
  132. g_AppCfg.Incident.Window = (sTmp == "1") ? true : false;
  133. sTmp = pIniFile->ReadString("INCIDENT", "ENABLED", "0");
  134. g_AppCfg.Incident.Enabled = (sTmp == "1") ? true : false;
  135. sTmp = pIniFile->ReadString("INCIDENT", "TIMEOUT", "30");
  136. g_AppCfg.Incident.TimeOut = sTmp.ToIntDef(0);
  137. if (g_AppCfg.Incident.TimeOut == 0) g_AppCfg.Incident.TimeOut = 30;
  138. if (g_AppCfg.Incident.TimeOut > 300) g_AppCfg.Incident.TimeOut = 60;
  139. sTmp = pIniFile->ReadString("AUTOLOGOUT", "ENABLED", "0");
  140. g_AppCfg.AutoLogout.Enabled = (sTmp == "1") ? true : false;
  141. sTmp = pIniFile->ReadString("AUTOLOGOUT", "INTERVALMIN", "10");
  142. g_AppCfg.AutoLogout.IntervalMin = sTmp.ToIntDef(0);
  143. if (g_AppCfg.AutoLogout.IntervalMin == 0) g_AppCfg.AutoLogout.IntervalMin = 10;
  144. sTmp = pIniFile->ReadString("AUTOLOGOUT", "LOGOUTEXIT", "0");
  145. g_AppCfg.AutoLogout.LogoutExit = (sTmp == "1") ? true : false;
  146. String sSqlLog;
  147. g_AppCfg.itsdb.bSqlLog = false;
  148. g_AppCfg.itsdb.sConnectStr = "";
  149. g_AppCfg.itsdb.sConnectStr = pIniFile->ReadString("ITSDB", "CONNECTSTR", "");
  150. if (g_AppCfg.itsdb.sConnectStr == "")
  151. {
  152. g_AppCfg.itsdb.sProvider = pIniFile->ReadString("ITSDB", "PROVIDER", "OraOLEDB.Oracle.1");
  153. g_AppCfg.itsdb.sServerName = pIniFile->ReadString("ITSDB", "SERVERNAME", "HANTE");
  154. g_AppCfg.itsdb.sUserName = pIniFile->ReadString("ITSDB", "USERNAME", "hnits");
  155. g_AppCfg.itsdb.sPassword = pIniFile->ReadString("ITSDB", "PASSWORD", "hnits");
  156. }
  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. sQry = "INSERT INTO TB_USER_CNNC_HS ( \r\n"
  230. " LOGIN_HMS, \r\n"
  231. " USER_ID, \r\n"
  232. " LOGOUT_HMS \r\n"
  233. " ) \r\n"
  234. "VALUES ( \r\n"
  235. " :p01, \r\n"
  236. " :p02, \r\n"
  237. " NULL \r\n"
  238. " ) \r\n";
  239. }
  240. else
  241. {
  242. sQry = "UPDATE TB_USER_CNNC_HS SET \r\n"
  243. " LOGOUT_HMS = TO_CHAR(SYSDATE, 'YYYYMMDDHH24MISS') \r\n"
  244. " WHERE LOGIN_HMS = :p01 \r\n"
  245. " AND USER_ID = :p02 \r\n";
  246. }
  247. try
  248. {
  249. try
  250. {
  251. adoQry = new TADOQuery(NULL);
  252. adoQry->Connection = ITSDb_GetConnection();
  253. ITSDb_GetConnection()->BeginTrans();
  254. adoQry->Close();
  255. adoQry->SQL->Text = sQry;
  256. adoQry->Parameters->ParamByName("p01")->Value = pLogin->sLoginTime;
  257. adoQry->Parameters->ParamByName("p02")->Value = pLogin->sUserId;
  258. int nRowCnt = adoQry->ExecSQL();
  259. ITSDb_GetConnection()->CommitTrans();
  260. bResult = nRowCnt > 1 ? true : false;
  261. }
  262. catch (Exception &exception)
  263. {
  264. ITSDb_GetConnection()->RollbackTrans();
  265. throw Exception(String(exception.ClassName()) + exception.Message);
  266. }
  267. catch (...)
  268. {
  269. ITSDb_GetConnection()->RollbackTrans();
  270. }
  271. }
  272. __finally
  273. {
  274. if (adoQry)
  275. {
  276. adoQry->Close();
  277. delete adoQry;
  278. }
  279. }
  280. return bResult;
  281. }
  282. //---------------------------------------------------------------------------
  283. bool ITSLoginProc(String sConnSystem, String sDefUser, TComponent *Owner)
  284. {
  285. bool bResult= false;
  286. PLOGININFO pLogin = ITSDb_GetLoginInfo();
  287. if (NULL == pLogin) return bResult;
  288. FRMLogin = new TFRMLogin(Owner);
  289. if (FRMLogin)
  290. {
  291. FRMLogin->EdUserID->Text = sDefUser;
  292. FRMLogin->ShowModal();
  293. pLogin->bLogin = FRMLogin->m_bLogin;
  294. if (pLogin->bLogin)
  295. {
  296. pLogin->sUserId = FRMLogin->m_sUserID;
  297. pLogin->sUserName = FRMLogin->m_sUserName;
  298. pLogin->sUserRightId = FRMLogin->m_sUserRightID;
  299. pLogin->sUserRightName = FRMLogin->m_sUserRightName;
  300. pLogin->sConnSystem = sConnSystem;
  301. pLogin->sLoginIp = FRMLogin->GetLocalIp();
  302. pLogin->sLoginTime = FRMLogin->m_sLoginTime;
  303. }
  304. else
  305. {
  306. pLogin->sUserId = "default";
  307. pLogin->sUserName = "default";
  308. pLogin->sUserRightId = "1";
  309. pLogin->sUserRightName = "";
  310. pLogin->sConnSystem = "OPR";
  311. pLogin->sLoginSeq = "0";
  312. pLogin->sLoginIp = "127.0.0.1";
  313. pLogin->sLoginTime = Now().FormatString("yyyymmddhhnnss");
  314. }
  315. delete FRMLogin;
  316. FRMLogin = NULL;
  317. bResult = pLogin->bLogin;
  318. }
  319. else
  320. {
  321. bResult = false;
  322. }
  323. if (bResult) CMM_InsertLoginHist(pLogin, true);
  324. return bResult;
  325. }
  326. //---------------------------------------------------------------------------
  327. void ITSLogoutProc()
  328. {
  329. if (ITSDb_IsOpen() == false) return;
  330. PLOGININFO pLogin = ITSDb_GetLoginInfo();
  331. if (pLogin)
  332. {
  333. if (pLogin->bLogin) CMM_InsertLoginHist(pLogin, false);
  334. pLogin->bLogin = false;
  335. }
  336. }
  337. //---------------------------------------------------------------------------
  338. int UserLogin()
  339. {
  340. if (ITSLoginProc("OPR", g_AppCfg.sDefUseId, Application))
  341. {
  342. g_pLOGIN = ITSDb_GetLoginInfo();
  343. if (g_pLOGIN) WriteConfigInfo(g_AppCfg.sConfigFile, "APPLICATION", "LASTUSER", g_pLOGIN->sUserId);
  344. }
  345. return g_pLOGIN == NULL ? 0 : 1;
  346. }
  347. //---------------------------------------------------------------------------
  348. int UserLogout()
  349. {
  350. if (g_pLOGIN)
  351. WriteConfigInfo(g_AppCfg.sConfigFile, "APPLICATION", "LASTUSER", g_pLOGIN->sUserId);
  352. if (g_AppCfg.AutoLogout.LogoutExit)
  353. WriteConfigInfo(g_AppCfg.sConfigFile, "AUTOLOGOUT", "LOGOUTEXIT", "1");
  354. else
  355. WriteConfigInfo(g_AppCfg.sConfigFile, "AUTOLOGOUT", "LOGOUTEXIT", "0");
  356. ITSLogoutProc();
  357. g_pLOGIN = NULL;
  358. return 0;
  359. }
  360. //---------------------------------------------------------------------------
  361. /*
  362. * 환경설정 정보를 저장하는 함수.
  363. * arguments
  364. * String : RegisterKey 또는 파일이름
  365. * return
  366. * bool : 실패하면 false
  367. */
  368. bool WriteConfigInfo(String sCfgFile, String sTitle, String sItem, String sValue)
  369. {
  370. String ConfigFile;
  371. TIniFile *pIniFile = NULL;
  372. ConfigFile = sCfgFile;
  373. try
  374. {
  375. pIniFile = new TIniFile(ConfigFile);
  376. if (pIniFile == NULL)
  377. {
  378. return false;
  379. }
  380. pIniFile->WriteString(sTitle, sItem, sValue);
  381. }
  382. catch(...)
  383. {
  384. }
  385. if (pIniFile)
  386. {
  387. pIniFile->Free();
  388. pIniFile = NULL;
  389. }
  390. return true;
  391. }
  392. //---------------------------------------------------------------------------
  393. /*
  394. * 환경설정 정보를 읽어오는 함수.
  395. * arguments
  396. * String : RegisterKey 또는 파일이름
  397. * return
  398. * bool : 실패하면 false
  399. */
  400. bool ReadConfigInfo(String sCfgFile, String sTitle, String sItem, String &sValue)
  401. {
  402. bool bRes;
  403. String ConfigFile;
  404. TIniFile *pIniFile = NULL;
  405. bRes = false;
  406. ConfigFile = sCfgFile;
  407. try
  408. {
  409. pIniFile = new TIniFile(ConfigFile);
  410. if (pIniFile == NULL)
  411. {
  412. return bRes;
  413. }
  414. sValue = pIniFile->ReadString(sTitle, sItem, "");
  415. if (sValue != "")
  416. {
  417. bRes = true;
  418. }
  419. }
  420. catch(...)
  421. {
  422. }
  423. if (pIniFile)
  424. {
  425. pIniFile->Free();
  426. pIniFile = NULL;
  427. }
  428. return bRes;
  429. }
  430. //---------------------------------------------------------------------------
  431. void ShowErrorMsg(String ATitle, String AErrMsg)
  432. {
  433. Application->NormalizeTopMosts();
  434. Application->MessageBox(AErrMsg.c_str(), ATitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
  435. Application->RestoreTopMosts();
  436. }
  437. //----------------------------------------------------------------------------
  438. String APP_FillCode(TcxComboBox *ACombo, String ACode)
  439. {
  440. String sReturn = "";
  441. ACombo->Properties->Items->Clear();
  442. TItsCode *FCodeRMF = ItsCodeManager->FLists.Find(ACode);
  443. if (FCodeRMF)
  444. {
  445. FOR_STL(TItsSubCode *, pSubCode, FCodeRMF->FSubLists)
  446. {
  447. if (pSubCode->USE_YN == "N") continue;
  448. ACombo->Properties->Items->Add(" [" + pSubCode->CMMN_CD + "] " + pSubCode->CMMN_CD_KOR_NM);
  449. if (sReturn == "")
  450. {
  451. sReturn = " [" + pSubCode->CMMN_CD + "] " + pSubCode->CMMN_CD_KOR_NM;
  452. }
  453. }
  454. }
  455. ACombo->ItemIndex = 0;
  456. return sReturn;
  457. }
  458. //----------------------------------------------------------------------------
  459. String APP_GetCode(TcxComboBox *ACombo)
  460. {
  461. String sReturn = "";
  462. if (ACombo->ItemIndex >= 0)
  463. {
  464. String sDesc = ACombo->Properties->Items->Strings[ACombo->ItemIndex];
  465. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  466. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  467. sReturn = sCode;
  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_GetCodeDesc(TcxComboBox *ACombo, String ACode)
  509. {
  510. String sReturn = "";
  511. for (int ii = 0; ii < ACombo->Properties->Items->Count; ii++)
  512. {
  513. String sDesc = ACombo->Properties->Items->Strings[ii];
  514. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  515. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  516. if (ACode == sCode)
  517. {
  518. sReturn = sDesc;
  519. break;
  520. }
  521. }
  522. return sReturn;
  523. }
  524. //----------------------------------------------------------------------------
  525. String APP_GetCodeDefCode(TcxComboBox *ACombo)
  526. {
  527. String sReturn = "";
  528. if (ACombo->Properties->Items->Count > 0)
  529. {
  530. String sDesc = ACombo->Properties->Items->Strings[0];
  531. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  532. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  533. sReturn = sCode;
  534. }
  535. return sReturn;
  536. }
  537. //----------------------------------------------------------------------------
  538. String APP_GetCodeDefDesc(TcxComboBox *ACombo)
  539. {
  540. String sReturn = "";
  541. if (ACombo->Properties->Items->Count > 0)
  542. {
  543. String sDesc = ACombo->Properties->Items->Strings[0];
  544. sReturn = sDesc;
  545. }
  546. return sReturn;
  547. }
  548. //----------------------------------------------------------------------------
  549. int APP_SetCode(TcxComboBox *ACombo, String ACode)
  550. {
  551. int nItemIndex = -1;
  552. for (int ii = 0; ii < ACombo->Properties->Items->Count; ii++)
  553. {
  554. String sDesc = ACombo->Properties->Items->Strings[ii];
  555. String sCode = sDesc.SubString(sDesc.Pos("[") + 1,
  556. sDesc.Pos("]") - (sDesc.Pos("[") + 1));
  557. if (ACode == sCode)
  558. {
  559. nItemIndex = ii;
  560. break;
  561. }
  562. }
  563. ACombo->ItemIndex = nItemIndex;
  564. return nItemIndex;
  565. }
  566. //----------------------------------------------------------------------------
  567. ULONG ProcIDFromWnd(HWND hwnd) // 윈도우 핸들로 프로세스 아이디 얻기
  568. {
  569. ULONG idProc;
  570. GetWindowThreadProcessId( hwnd, &idProc );
  571. return idProc;
  572. }
  573. //----------------------------------------------------------------------------
  574. HWND GetWinHandle(ULONG pid) // 프로세스 아이디로 윈도우 핸들 얻기
  575. {
  576. HWND tempHwnd = FindWindow(NULL,NULL); // 최상위 윈도우 핸들 찾기
  577. while( tempHwnd != NULL )
  578. {
  579. if( GetParent(tempHwnd) == NULL ) // 최상위 핸들인지 체크, 버튼 등도 핸들을 가질 수 있으므로 무시하기 위해
  580. if( pid == ProcIDFromWnd(tempHwnd) )
  581. return tempHwnd;
  582. tempHwnd = GetWindow(tempHwnd, GW_HWNDNEXT); // 다음 윈도우 핸들 찾기
  583. }
  584. return NULL;
  585. }
  586. String ITSUtil_FormatStr(String AStrDateTime, String AFormat)
  587. {
  588. #define SYEAR "-"
  589. #define STIME ":"
  590. #define SPACE " "
  591. String sDateTime = "";
  592. String sInData = AStrDateTime;//AnsiString(AStrDateTime);
  593. String sFormat = AFormat;
  594. if (sInData.IsEmpty())
  595. return sInData;
  596. try
  597. {
  598. if (sFormat == STR_DATETIME)
  599. {
  600. if (sInData.Length() < 14) return sInData;
  601. sDateTime = sInData.SubString( 1, 4) + SYEAR +
  602. sInData.SubString( 5, 2) + SYEAR +
  603. sInData.SubString( 7, 2) + SPACE +
  604. sInData.SubString( 9, 2) + STIME +
  605. sInData.SubString(11, 2) + STIME +
  606. sInData.SubString(13, 2);
  607. }
  608. else
  609. if (sFormat == STR_HHNN)
  610. {
  611. if (sInData.Length() < 12) return sInData;
  612. sDateTime = sInData.SubString( 1, 4) + SYEAR +
  613. sInData.SubString( 5, 2) + SYEAR +
  614. sInData.SubString( 7, 2) + SPACE +
  615. sInData.SubString( 9, 2) + STIME +
  616. sInData.SubString(11, 2);
  617. }
  618. else
  619. if (sFormat == STR_DATEHOUR)
  620. {
  621. if (sInData.Length() < 10) return sInData;
  622. sDateTime = sInData.SubString( 1, 4) + SYEAR +
  623. sInData.SubString( 5, 2) + SYEAR +
  624. sInData.SubString( 7, 2) + SPACE +
  625. sInData.SubString( 9, 2);
  626. }
  627. else
  628. if (sFormat == STR_DATE)
  629. {
  630. if (sInData.Length() < 8) return sInData;
  631. sDateTime = sInData.SubString( 1, 4) + SYEAR +
  632. sInData.SubString( 5, 2) + SYEAR +
  633. sInData.SubString( 7, 2);
  634. }
  635. else
  636. if (sFormat == STR_MM)
  637. {
  638. if (sInData.Length() < 6) return sInData;
  639. sDateTime = sInData.SubString( 1, 4) + SYEAR +
  640. sInData.SubString( 5, 2);
  641. }
  642. else
  643. {
  644. sDateTime = sInData;
  645. }
  646. }
  647. catch(Exception &E)
  648. {
  649. throw Exception(String(E.ClassName()) + E.Message);
  650. }
  651. return sDateTime;
  652. }
  653. //---------------------------------------------------------------------------
  654. TColor g_DispColor[MAX_DISPCOLOR];
  655. void APP_InitDisplayColor()
  656. {
  657. #if 0
  658. g_DispColor[ 0] = Graphics::clBlue;
  659. g_DispColor[ 1] = Graphics::clRed;
  660. g_DispColor[ 2] = Graphics::clLime;
  661. g_DispColor[ 3] = Graphics::clMaroon;
  662. g_DispColor[ 4] = Graphics::clGreen;
  663. g_DispColor[ 5] = Graphics::clMenuHighlight;
  664. g_DispColor[ 6] = Graphics::clBackground;
  665. g_DispColor[ 7] = Graphics::clPurple;
  666. g_DispColor[ 8] = Graphics::clTeal;
  667. g_DispColor[ 9] = Graphics::clYellow;
  668. g_DispColor[10] = Graphics::clFuchsia;
  669. g_DispColor[11] = Graphics::clAqua;
  670. g_DispColor[12] = Graphics::clMoneyGreen;
  671. g_DispColor[13] = Graphics::clSkyBlue;
  672. g_DispColor[14] = Graphics::clRed;
  673. g_DispColor[15] = Graphics::clLime;
  674. g_DispColor[16] = Graphics::clYellow;
  675. g_DispColor[17] = Graphics::clBlue;
  676. g_DispColor[18] = Graphics::clFuchsia;
  677. g_DispColor[19] = Graphics::clAqua;
  678. g_DispColor[20] = Graphics::clMoneyGreen;
  679. g_DispColor[21] = Graphics::clActiveCaption;
  680. #else
  681. g_DispColor[ 0] = Graphics::clLime;
  682. g_DispColor[ 1] = (TColor)RGB(0xFF, 0x00, 0x00);
  683. g_DispColor[ 2] = (TColor)RGB(0x00, 0x00, 0xFF);
  684. g_DispColor[ 3] = (TColor)RGB(0xFF, 0x82, 0x00);
  685. g_DispColor[ 4] = (TColor)RGB(0x94, 0x00, 0xD3);
  686. g_DispColor[ 5] = (TColor)RGB(0x00, 0x00, 0x00);
  687. g_DispColor[ 6] = (TColor)RGB(0x82, 0x82, 0x82);
  688. g_DispColor[ 7] = (TColor)RGB(0x1E, 0x90, 0xFF);
  689. g_DispColor[ 8] = (TColor)RGB(0xB9, 0x06, 0x2F);
  690. g_DispColor[ 9] = (TColor)RGB(0x8c, 0x00, 0x8c);
  691. g_DispColor[10] = (TColor)RGB(0xFF, 0x82, 0x00);
  692. g_DispColor[11] = (TColor)RGB(0x94, 0x00, 0xD3);
  693. g_DispColor[12] = (TColor)RGB(0xB0, 0xC4, 0xDE);
  694. g_DispColor[13] = (TColor)RGB(0x00, 0xBF, 0xFF);
  695. g_DispColor[14] = (TColor)RGB(0x87, 0xCE, 0xEB);
  696. g_DispColor[15] = (TColor)RGB(0x87, 0xCE, 0xFA);
  697. g_DispColor[16] = (TColor)RGB(0xAD, 0xD8, 0xE6);
  698. g_DispColor[17] = (TColor)RGB(0xB0, 0xE0, 0xE6);
  699. g_DispColor[18] = (TColor)RGB(0xE6, 0xE6, 0xFA);
  700. g_DispColor[19] = (TColor)RGB(0xF0, 0xF8, 0xFF);
  701. #endif
  702. }
  703. //---------------------------------------------------------------------------
  704. TColor APP_GetDisplayColor(int ASeq)
  705. {
  706. return g_DispColor[ASeq % MAX_DISPCOLOR];
  707. }
  708. //---------------------------------------------------------------------------
  709. void APP_DelVmsSizeCombo(TcxComboBox *cboBox)
  710. {
  711. TStrings *pStrItems;
  712. TVmsSizeType *Ov;
  713. pStrItems = ((TcxComboBox *)cboBox)->Properties->Items;
  714. for (int ii = pStrItems->Count-1; ii >= 0; ii--)
  715. {
  716. Ov = (TVmsSizeType *)pStrItems->Objects[ii];
  717. if (Ov != NULL)
  718. {
  719. delete Ov;
  720. Ov = NULL;
  721. }
  722. }
  723. }
  724. //---------------------------------------------------------------------------
  725. void APP_FillVmsSizeType(TcxComboBox *cboBox, bool bAddAll/*=false*/)
  726. {
  727. String sQry;
  728. TStrings *pStrItems;
  729. TADOQuery *pADO = NULL;
  730. APP_DelVmsSizeCombo(cboBox);
  731. pStrItems = ((TcxComboBox *)cboBox)->Properties->Items;
  732. ((TcxComboBox *)cboBox)->Properties->Items->Clear();
  733. FOR_STL(TVmsType*, pObj, VmsTypeManager->FLists)
  734. {
  735. String sTypeCd = pObj->VMS_TYPE_CD;
  736. String sTypeNm = pObj->VMS_TYPE_NM;
  737. int nW = pObj->VMS_WDTH;
  738. int nH = pObj->VMS_HGHT;
  739. pStrItems->AddObject(" [" + sTypeCd + "] " + sTypeNm + " (" + String(nW) + "x" + String(nH) + ")", new TVmsSizeType(sTypeCd, sTypeNm, nW, nH) );
  740. }
  741. if (bAddAll)
  742. {
  743. String sAllName = "전체";
  744. pStrItems->AddObject(" [ALL] 전체" , new TVmsSizeType("ALL", sAllName, 384, 64));
  745. }
  746. cboBox->ItemIndex = 0;
  747. }
  748. //---------------------------------------------------------------------------
  749. TVmsSizeType* APP_GetVmsSizeTypeObject(TcxComboBox *cboBox)
  750. {
  751. TStrings *pStrItems;
  752. TVmsSizeType *Ov = NULL;
  753. int nItemIndex;
  754. pStrItems = ((TcxComboBox *)cboBox)->Properties->Items;
  755. nItemIndex= ((TcxComboBox *)cboBox)->ItemIndex;
  756. if (nItemIndex < 0)
  757. {
  758. return Ov;
  759. }
  760. Ov = (TVmsSizeType *)pStrItems->Objects[nItemIndex];
  761. if (Ov == NULL)
  762. {
  763. Ov = NULL;
  764. }
  765. return Ov;
  766. }
  767. //---------------------------------------------------------------------------
  768. void APP_ImageClear(TCanvas *c, int offX, int offY, int w, int h, TColor color)
  769. {
  770. try
  771. {
  772. c->Pen->Color = clWhite;
  773. c->Pen->Width = 0;
  774. c->Pen->Style = psClear;
  775. c->Brush->Style = bsSolid;
  776. c->Brush->Color = color;
  777. c->Rectangle(offX, offY, w+offX+2, h+offY+2);
  778. }
  779. catch(...)
  780. {
  781. }
  782. }
  783. //---------------------------------------------------------------------------
  784. #include <DateUtils.hpp>
  785. TDateTime APP_StrToDateTime(String AStrDateTime)
  786. {
  787. TDateTime dtReturnValue = NULL;
  788. if (AStrDateTime.IsEmpty()) return dtReturnValue;
  789. if (AStrDateTime.Length() != 14) return dtReturnValue;
  790. AnsiString sDateTime = AnsiString(AStrDateTime);
  791. try
  792. {
  793. #if 0
  794. sDateTime.printf(L"%s-%s-%s %s:%s:%s",
  795. AStrDateTime.SubString( 1, 4).c_str(),
  796. AStrDateTime.SubString( 5, 2).c_str(),
  797. AStrDateTime.SubString( 7, 2).c_str(),
  798. AStrDateTime.SubString( 9, 2).c_str(),
  799. AStrDateTime.SubString(11, 2).c_str(),
  800. AStrDateTime.SubString(13, 2).c_str());
  801. dtReturnValue = StrToDateTime(sDateTime);
  802. #endif
  803. // swscanf(sRgb.c_str(), L"%d,%d,%d", &r, &g, &b);
  804. int year, month, day, hour, minute, second;
  805. sscanf(sDateTime.c_str(), "%4d%2d%2d%2d%2d%2d", &year, &month, &day, &hour, &minute, &second);
  806. dtReturnValue = EncodeDateTime(year, month, day, hour, minute, second, 0);
  807. }
  808. catch(...)
  809. {
  810. }
  811. return dtReturnValue;
  812. }
  813. //---------------------------------------------------------------------------
  814. void APP_SetSummaryItemKind(TcxSummaryEventArguments &Arguments,
  815. TcxSummaryEventOutArguments &OutArguments,
  816. int pKind,
  817. bool pCaptionDisplay,
  818. bool pPointDisplay)
  819. {
  820. #if 0
  821. String sAvgCaption, sSumCaption, sMinCaption, sMaxCaption, sCntCaption;
  822. sAvgCaption = "";
  823. sMinCaption = "";
  824. sMaxCaption = "";
  825. //sCntCaption = "";
  826. sSumCaption = "";
  827. if (pCaptionDisplay)
  828. {
  829. sAvgCaption = "";//"평균: ";
  830. sMinCaption = "최소: ";
  831. sMaxCaption = "최대: ";
  832. if (pKind == 1)
  833. {
  834. sSumCaption = "소계: ";
  835. }
  836. else
  837. {
  838. sSumCaption = "합계: ";
  839. }
  840. }
  841. //sCntCaption = " 건";
  842. #endif
  843. #if 0
  844. if (VarIsNull(OutArguments.Value))
  845. {
  846. OutArguments.Done = true;
  847. return;
  848. }
  849. #endif
  850. #if 0
  851. if (Arguments.SummaryItem->Kind == skSum)
  852. {
  853. if (!VarIsNull(OutArguments.Value))
  854. {
  855. if (!VarSameValue(OutArguments.Value, Variant(0)))
  856. {
  857. OutArguments.CountValue++;
  858. OutArguments.SummaryValue += OutArguments.Value;
  859. OutArguments.Done = true;
  860. }
  861. else
  862. {
  863. //OutArguments.CountValue--;
  864. OutArguments.Done = true;
  865. }
  866. }
  867. else
  868. {
  869. //OutArguments.CountValue--;
  870. OutArguments.Done = true;
  871. }
  872. }
  873. else
  874. #endif
  875. if (Arguments.SummaryItem->Kind == skAverage)
  876. {
  877. if (!VarIsNull(OutArguments.Value))
  878. {
  879. if (!VarSameValue(OutArguments.Value, Variant(0)))
  880. {
  881. OutArguments.CountValue++;
  882. //OutArguments.Value = Variant(0);
  883. OutArguments.SummaryValue += OutArguments.Value;
  884. OutArguments.Done = true;
  885. }
  886. else
  887. {
  888. //OutArguments.CountValue--;
  889. OutArguments.Done = true;
  890. }
  891. }
  892. else
  893. {
  894. //OutArguments.CountValue--;
  895. OutArguments.Done = true;
  896. }
  897. #if 0
  898. if (pPointDisplay)
  899. Arguments.SummaryItem->Format = sAvgCaption + "#,##0.0";
  900. else
  901. Arguments.SummaryItem->Format = sAvgCaption + "#,##0";
  902. #endif
  903. }
  904. #if 0
  905. else if (Arguments.SummaryItem->Kind == skSum)
  906. Arguments.SummaryItem->Format = sSumCaption + "#,##0.##";
  907. else if (Arguments.SummaryItem->Kind == skMin)
  908. Arguments.SummaryItem->Format = sMinCaption + "#,##0.##";
  909. else if (Arguments.SummaryItem->Kind == skMax)
  910. Arguments.SummaryItem->Format = sMaxCaption + "#,##0.##";
  911. else if (Arguments.SummaryItem->Kind == skCount)
  912. Arguments.SummaryItem->Format = "#,##0" + sCntCaption;
  913. #endif
  914. }
  915. //---------------------------------------------------------------------------