CFG0000MF.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include "ITSSkinF.h"
  4. #//include "ITSUtilF.h"
  5. #include "ITSDbF.h"
  6. //#include "AppGlobalF.h"
  7. #pragma hdrstop
  8. #include "CFG0000MF.h"
  9. //---------------------------------------------------------------------------
  10. #pragma package(smart_init)
  11. #pragma link "cxButtonEdit"
  12. #pragma link "cxButtons"
  13. #pragma link "cxContainer"
  14. #pragma link "cxControls"
  15. #pragma link "cxEdit"
  16. #pragma link "cxGraphics"
  17. #pragma link "cxGroupBox"
  18. #pragma link "cxLookAndFeelPainters"
  19. #pragma link "cxLookAndFeels"
  20. #pragma link "cxMaskEdit"
  21. #pragma link "cxTextEdit"
  22. #pragma link "dxSkinBlack"
  23. #pragma link "dxSkinBlue"
  24. #pragma link "dxSkinCaramel"
  25. #pragma link "dxSkinCoffee"
  26. #pragma link "dxSkinDarkRoom"
  27. #pragma link "dxSkinDarkSide"
  28. #pragma link "dxSkinFoggy"
  29. #pragma link "dxSkinGlassOceans"
  30. #pragma link "dxSkiniMaginary"
  31. #pragma link "dxSkinLilian"
  32. #pragma link "dxSkinLiquidSky"
  33. #pragma link "dxSkinLondonLiquidSky"
  34. #pragma link "dxSkinMcSkin"
  35. #pragma link "dxSkinMoneyTwins"
  36. #pragma link "dxSkinOffice2007Black"
  37. #pragma link "dxSkinOffice2007Blue"
  38. #pragma link "dxSkinOffice2007Green"
  39. #pragma link "dxSkinOffice2007Pink"
  40. #pragma link "dxSkinOffice2007Silver"
  41. #pragma link "dxSkinOffice2010Black"
  42. #pragma link "dxSkinOffice2010Blue"
  43. #pragma link "dxSkinOffice2010Silver"
  44. #pragma link "dxSkinsCore"
  45. #pragma link "dxSkinSeven"
  46. #pragma link "dxSkinSharp"
  47. #pragma link "dxSkinSilver"
  48. #pragma link "dxSkinStardust"
  49. #pragma link "cxCheckBox"
  50. #pragma link "cxSpinEdit"
  51. #pragma link "cxClasses"
  52. #pragma link "cxCustomData"
  53. #pragma link "cxData"
  54. #pragma link "cxDataStorage"
  55. #pragma link "cxDBData"
  56. #pragma link "cxFilter"
  57. #pragma link "cxGrid"
  58. #pragma link "cxGridCustomTableView"
  59. #pragma link "cxGridCustomView"
  60. #pragma link "cxGridDBTableView"
  61. #pragma link "cxGridLevel"
  62. #pragma link "cxGridTableView"
  63. #pragma link "cxStyles"
  64. #pragma link "dxSkinscxPCPainter"
  65. #pragma link "dxSkinsForm"
  66. #pragma resource "*.dfm"
  67. TCFG0000M *CFG0000M = NULL;
  68. typedef struct tag_AppConfig
  69. {
  70. String sConfigFile;
  71. bool bAppClose;
  72. long lMainWinHandle; /* Main Window Handle */
  73. String sTitle;
  74. String sProcessId; /* 프로세스 ID */
  75. String sSkinName;
  76. bool bSaveForm;
  77. bool bLoginPrompt;
  78. String sDefUseId;
  79. int nLogLevel;
  80. AnsiString sLogDay;
  81. bool bDebug;
  82. struct
  83. {
  84. bool Window;
  85. bool Enabled;
  86. int TimeOut;
  87. } Alarm;
  88. struct
  89. {
  90. bool Window;
  91. bool Enabled;
  92. int TimeOut;
  93. } Incident;
  94. struct
  95. {
  96. int AlarmValue;
  97. } Temp;
  98. struct
  99. {
  100. bool Enabled;
  101. int IntervalMin;
  102. bool LogoutExit;
  103. } AutoLogout;
  104. struct
  105. {
  106. TThread *pThread;
  107. DWORD dwThreadId;
  108. unsigned int nHandle;
  109. bool bRunning;
  110. } thr;
  111. struct
  112. {
  113. String sProvider;
  114. String sServerName;
  115. String sUserName;
  116. String sPassword;
  117. bool bSqlLog;
  118. } itsdb;
  119. struct
  120. {
  121. String sMainMap;
  122. String sLinkMap;
  123. } flashmap;
  124. struct
  125. {
  126. String sComModel;
  127. String sDevModel;
  128. } vmscam;
  129. } APP_CONFIG;
  130. /*
  131. * 전자지도 정보를 저장할 구조체
  132. */
  133. typedef struct
  134. {
  135. bool bLoadL0;
  136. bool bLoadL1;
  137. bool bLoadL2;
  138. bool bLoadL3;
  139. double dCenterX;
  140. double dCenterY;
  141. double dLeftTopX;
  142. double dLeftTopY;
  143. double dRightBottomX;
  144. double dRightBottomY;
  145. String sCenterName;
  146. String sMapFileNameL0;
  147. String sMapFileNameL1;
  148. String sMapFileNameL2;
  149. String sMapFileNameL3;
  150. String sIdxMapFileName;
  151. } ST_GISINFO;
  152. APP_CONFIG g_AppCfg;
  153. ST_GISINFO g_GisInfo;
  154. String CenterCd = ""; // 지역센터 코드
  155. String CenterId = ""; // 지역센터 아이디
  156. String CenterName = ""; // 지역센터 명칭
  157. int g_nPid = -1; // Application Process ID
  158. String g_sAppDir = ""; // Application Directory
  159. String g_sAppName= ""; // Program name
  160. String g_sCfgDir = ""; // Config File Directory
  161. String g_sLogDir = ""; // Program Log Directory
  162. String g_sTempDir = ""; // Program Temp Directory
  163. String g_sFormsDir = ""; // Program Forms Directory
  164. //---------------------------------------------------------------------------
  165. bool LoadConfigInfo()
  166. {
  167. String sCfgFile;
  168. TIniFile *pIniFile = NULL;
  169. // g_nPid = GetAppInfo(Application->ExeName, g_sAppDir, g_sProgNm);
  170. g_sAppDir = ExtractFilePath(Application->ExeName);
  171. sCfgFile = g_sAppDir + "\\Cfg\\ITS_OP.ini";
  172. g_AppCfg.AutoLogout.Enabled = false;
  173. g_AppCfg.AutoLogout.IntervalMin = 0;
  174. g_AppCfg.AutoLogout.LogoutExit = false;
  175. g_AppCfg.thr.pThread = NULL;
  176. g_AppCfg.thr.dwThreadId = 0;
  177. g_AppCfg.thr.nHandle = 0;
  178. g_AppCfg.thr.bRunning = false;
  179. g_AppCfg.bAppClose = false;
  180. try
  181. {
  182. String sTmp;
  183. pIniFile = new TIniFile(sCfgFile);
  184. g_AppCfg.sTitle = pIniFile->ReadString("APPLICATION", "TITLE", "광역교통정보 교통관리시스템");
  185. g_AppCfg.sProcessId = pIniFile->ReadString("APPLICATION", "PROCESSID", "999999");
  186. g_AppCfg.sSkinName = pIniFile->ReadString("APPLICATION", "SKINNAME", "Blue");
  187. if (g_AppCfg.sSkinName.IsEmpty()) g_AppCfg.sSkinName = "Blue";
  188. sTmp = pIniFile->ReadString("APPLICATION", "SAVEFORM", "1");
  189. g_AppCfg.bSaveForm = (sTmp == "1") ? true : false;
  190. sTmp = "0";//pIniFile->ReadString("DEFAULT", "LOGINPROMPT", "1");
  191. g_AppCfg.bLoginPrompt = (sTmp == "1") ? true : false;
  192. g_AppCfg.sDefUseId = pIniFile->ReadString("APPLICATION", "LASTUSER", "");
  193. sTmp = pIniFile->ReadString("AUTOLOGOUT", "ENABLED", "0");
  194. g_AppCfg.AutoLogout.Enabled = (sTmp == "1") ? true : false;
  195. sTmp = pIniFile->ReadString("AUTOLOGOUT", "INTERVALMIN", "10");
  196. g_AppCfg.AutoLogout.IntervalMin = sTmp.ToIntDef(0);
  197. if (g_AppCfg.AutoLogout.IntervalMin == 0) g_AppCfg.AutoLogout.IntervalMin = 10;
  198. sTmp = pIniFile->ReadString("AUTOLOGOUT", "LOGOUTEXIT", "0");
  199. g_AppCfg.AutoLogout.LogoutExit = (sTmp == "1") ? true : false;
  200. g_AppCfg.itsdb.bSqlLog = false;
  201. g_AppCfg.itsdb.sProvider = pIniFile->ReadString("ITSDB", "PROVIDER", "OraOLEDB.Oracle.1");
  202. g_AppCfg.itsdb.sServerName = pIniFile->ReadString("ITSDB", "SERVERNAME", "HANTE");
  203. g_AppCfg.itsdb.sUserName = pIniFile->ReadString("ITSDB", "USERNAME", "hnits");
  204. g_AppCfg.itsdb.sPassword = pIniFile->ReadString("ITSDB", "PASSWORD", "hnits");
  205. String sSqlLog = pIniFile->ReadString("ITSDB", "SQLLOG", "0");
  206. if (sSqlLog == "1") g_AppCfg.itsdb.bSqlLog = true;
  207. CenterId = pIniFile->ReadString("CENTER", "CENTERID", "L01");
  208. CenterName = pIniFile->ReadString("CENTER", "CENTERNAME", "중앙센터");
  209. CenterCd = String(StrToInt(CenterId.SubString(2, 2)));
  210. // GIS 설정정보 로딩
  211. String sLeftTopX = pIniFile->ReadString("MAP", "LEFTTOPX", "126.891");
  212. String sLeftTopY = pIniFile->ReadString("MAP", "LEFTTOPY", "037.383");
  213. String sRightBottomX = pIniFile->ReadString("MAP", "RIGHTBOTTOMX", "126.981");
  214. String sRightBottomY = pIniFile->ReadString("MAP", "RIGHTBOTTOMY", "037.318");
  215. String sCenterX = pIniFile->ReadString("MAP", "CENTERX", "126.935");
  216. String sCenterY = pIniFile->ReadString("MAP", "CENTERY", "037.360");
  217. g_GisInfo.dLeftTopX = sLeftTopX.ToDouble();
  218. g_GisInfo.dLeftTopY = sLeftTopY.ToDouble();
  219. g_GisInfo.dRightBottomX = sRightBottomX.ToDouble();
  220. g_GisInfo.dRightBottomY = sRightBottomY.ToDouble();
  221. g_GisInfo.dCenterX = sCenterX.ToDouble();
  222. g_GisInfo.dCenterY = sCenterY.ToDouble();
  223. g_GisInfo.sCenterName = CenterName;
  224. g_GisInfo.sIdxMapFileName = "";
  225. g_GisInfo.sMapFileNameL0 = pIniFile->ReadString("MAP", "MAPFILEL0", "");
  226. g_GisInfo.sMapFileNameL1 = pIniFile->ReadString("MAP", "MAPFILEL1", "");
  227. g_GisInfo.sMapFileNameL2 = pIniFile->ReadString("MAP", "MAPFILEL2", "");
  228. g_GisInfo.sMapFileNameL3 = pIniFile->ReadString("MAP", "MAPFILEL3", "");
  229. g_GisInfo.bLoadL0 = true;
  230. g_GisInfo.bLoadL1 = true;
  231. g_GisInfo.bLoadL2 = true;
  232. g_GisInfo.bLoadL3 = true;
  233. if (g_GisInfo.sMapFileNameL0 == "") g_GisInfo.bLoadL0 = false;
  234. if (g_GisInfo.sMapFileNameL1 == "") g_GisInfo.bLoadL1 = false;
  235. if (g_GisInfo.sMapFileNameL2 == "") g_GisInfo.bLoadL2 = false;
  236. if (g_GisInfo.sMapFileNameL3 == "") g_GisInfo.bLoadL3 = false;
  237. }
  238. __finally
  239. {
  240. if (pIniFile) delete pIniFile;
  241. pIniFile = NULL;
  242. }
  243. return true;
  244. }
  245. //---------------------------------------------------------------------------
  246. __fastcall TCFG0000M::TCFG0000M(TComponent* Owner)
  247. : TForm(Owner)
  248. {
  249. ITSSkin_Initialize(Application);
  250. ITSSkin_Load(this);
  251. FTitle = "환경설정";
  252. Caption = "통합운영단말 " + FTitle;
  253. LblCaption->Caption = FTitle;
  254. }
  255. //---------------------------------------------------------------------------
  256. /*
  257. * 닫기버튼 이나 x버튼 클릭시 공통으로 처리하는 로직이들어간다..
  258. * Form과 DataModule class를 delete시킨다.
  259. * arguments
  260. *
  261. * return
  262. * void
  263. */
  264. void __fastcall TCFG0000M::CommClose()
  265. {
  266. }
  267. //---------------------------------------------------------------------------
  268. /*
  269. * Form이 메모리에서 생성될때 호출되는 생성자 이벤트 핸들러
  270. * arguments
  271. * Sender : event handler 객체
  272. * return
  273. * void
  274. */
  275. void __fastcall TCFG0000M::FormCreate(TObject *Sender)
  276. {
  277. LoadConfigInfo();
  278. }
  279. //---------------------------------------------------------------------------
  280. /*
  281. * Form을 보여줄때 호출되는 event 메서드이다.
  282. * arguments
  283. * Sender : event handler 객체
  284. * return
  285. * void
  286. */
  287. void __fastcall TCFG0000M::FormShow(TObject *Sender)
  288. {
  289. Refresh();
  290. TmrShow->Enabled = true;
  291. }
  292. //---------------------------------------------------------------------------
  293. /*
  294. * Form이 Show되고 난 후 최초 1회 수행되는 타이머 이벤트
  295. * arguments
  296. * Sender : event handler 객체
  297. * return
  298. * void
  299. */
  300. void __fastcall TCFG0000M::TmrShowTimer(TObject *Sender)
  301. {
  302. TmrShow->Enabled = false;
  303. RefreshData();
  304. }
  305. //---------------------------------------------------------------------------
  306. /*
  307. * Refresh Data Event Function
  308. * arguments
  309. *
  310. * return
  311. * void
  312. */
  313. void __fastcall TCFG0000M::RefreshData()
  314. {
  315. // 정보를 읽어와서 표출하자.
  316. EdCenterId->Text = CenterId;
  317. EdCenterName->Text = CenterName;
  318. EdGisFile->Text = g_GisInfo.sMapFileNameL0;
  319. EdDbProvider->Text = g_AppCfg.itsdb.sProvider;
  320. EdDbUser->Text = g_AppCfg.itsdb.sUserName;
  321. EdDbSource->Text = g_AppCfg.itsdb.sServerName;
  322. EdDbPasswd->Text = g_AppCfg.itsdb.sPassword;
  323. EdProcessId->Text = g_AppCfg.sProcessId;
  324. //EdTaskId->Text = "";
  325. //EdNodeId->Text = "";
  326. //EdSequence->Text = "";
  327. ChkSaveForm->Checked = g_AppCfg.bSaveForm;
  328. ChkAutoLogout->Checked = g_AppCfg.AutoLogout.Enabled;
  329. SeInterevalMin->Value = g_AppCfg.AutoLogout.IntervalMin;
  330. }
  331. //---------------------------------------------------------------------------
  332. /*
  333. * Close 버튼 클릭 이벤트 핸들러
  334. * arguments
  335. * Sender : event handler 객체
  336. * return
  337. * void
  338. */
  339. void __fastcall TCFG0000M::BtnCloseClick(TObject *Sender)
  340. {
  341. Close();
  342. }
  343. //---------------------------------------------------------------------------
  344. /*
  345. * Select Button Click Event Handler
  346. * arguments
  347. * Sender : event handler 객체
  348. * return
  349. * void
  350. */
  351. void __fastcall TCFG0000M::BtnSaveClick(TObject *Sender)
  352. {
  353. //bool bSaved = false;
  354. String sMsgString;
  355. String sID, sIPAddress;
  356. int sMsgType = MB_OK|MB_ICONWARNING|MB_APPLMODAL;
  357. sMsgString = "시스템 환경설정 정보를 저장하시겠습니까?";
  358. sMsgType = MB_YESNO|MB_ICONINFORMATION|MB_APPLMODAL;
  359. if (Application->MessageBox(sMsgString.c_str(), FTitle.c_str(), sMsgType)==IDNO)
  360. {
  361. return;
  362. }
  363. String sCenterId = EdCenterId->Text.Trim();
  364. String sCenterName = EdCenterName->Text.Trim();
  365. String sGisFile = EdGisFile->Text.Trim();
  366. String sDbProvider = EdDbProvider->Text.Trim();
  367. String sDbUser = EdDbUser->Text.Trim();
  368. String sDbSource = EdDbSource->Text.Trim();
  369. String sDbPasswd = EdDbPasswd->Text.Trim();
  370. String sProcessId = EdProcessId->Text.Trim();
  371. g_AppCfg.bSaveForm = ChkSaveForm->Checked;
  372. String sSaveForm = g_AppCfg.bSaveForm ? "1" : "0";
  373. //String sTaskId = EdTaskId->Text.Trim();
  374. //String sNodeId = EdNodeId->Text.Trim();
  375. //String sSequence = EdSequence->Text.Trim();
  376. g_AppCfg.AutoLogout.Enabled = ChkAutoLogout->Checked;
  377. g_AppCfg.AutoLogout.IntervalMin = SeInterevalMin->Value;
  378. String sAutoLogout = g_AppCfg.AutoLogout.Enabled ? "1" : "0";
  379. String sInterMin = String(g_AppCfg.AutoLogout.IntervalMin);
  380. try {
  381. SetConfigValue("CENTER", "CENTERID", sCenterId);
  382. SetConfigValue("CENTER", "CENTERNAME", sCenterName);
  383. SetConfigValue("MAP", "MAPFILEL0", sGisFile);
  384. SetConfigValue("ITSDB", "PROVIDER", sDbProvider);
  385. SetConfigValue("ITSDB", "SERVERNAME", sDbSource);
  386. SetConfigValue("ITSDB", "USERNAME", sDbUser);
  387. SetConfigValue("ITSDB", "PASSWORD", sDbPasswd);
  388. SetConfigValue("AUTOLOGOUT", "ENABLED", sAutoLogout);
  389. SetConfigValue("AUTOLOGOUT", "INTERVALMIN", sInterMin);
  390. SetConfigValue("APPLICATION", "PROCESSID", sProcessId);
  391. SetConfigValue("APPLICATION", "SAVEFORM", sSaveForm);
  392. CenterId = sCenterId;
  393. CenterName = sCenterName;
  394. CenterCd = String(StrToInt(CenterId.SubString(2, 2)));
  395. g_AppCfg.itsdb.sProvider = sDbProvider;
  396. g_AppCfg.itsdb.sUserName = sDbUser;
  397. g_AppCfg.itsdb.sServerName = sDbSource;
  398. g_AppCfg.itsdb.sPassword = sDbPasswd;
  399. g_AppCfg.sProcessId = sProcessId;
  400. Application->MessageBox(L"환경설정 정보를 정상적으로 저장하였습니다.\r\다음 프로그램 실행 부터 반영됩니다.",
  401. FTitle.c_str(), MB_OK|MB_ICONINFORMATION|MB_APPLMODAL);
  402. } catch(...) {
  403. }
  404. //Close();
  405. }
  406. //---------------------------------------------------------------------------
  407. void __fastcall TCFG0000M::FormClose(TObject *Sender, TCloseAction &Action)
  408. {
  409. CommClose();
  410. CFG0000M = NULL;
  411. Action = caFree;
  412. }
  413. //---------------------------------------------------------------------------
  414. String __fastcall TCFG0000M::GetConfigValue(String sSection, String sIdent, String sDefVal)
  415. {
  416. String sResult = sDefVal;
  417. TIniFile *pIniFile = NULL;
  418. String sCfgFile = ExtractFilePath(Application->ExeName) + "\\Cfg\\ITS_OP.ini";
  419. try
  420. {
  421. pIniFile = new TIniFile(sCfgFile);
  422. sResult = pIniFile->ReadString(sSection, sIdent, sDefVal);
  423. }
  424. __finally
  425. {
  426. if (pIniFile) delete pIniFile;
  427. pIniFile = NULL;
  428. }
  429. return sResult;
  430. }
  431. //---------------------------------------------------------------------------
  432. void __fastcall TCFG0000M::SetConfigValue(String sSection, String sIdent, String sSetVal)
  433. {
  434. TIniFile *pIniFile = NULL;
  435. String sCfgFile = ExtractFilePath(Application->ExeName) + "\\Cfg\\ITS_OP.ini";
  436. try
  437. {
  438. pIniFile = new TIniFile(sCfgFile);
  439. pIniFile->WriteString(sSection, sIdent, sSetVal);
  440. }
  441. __finally
  442. {
  443. if (pIniFile) delete pIniFile;
  444. pIniFile = NULL;
  445. }
  446. }
  447. //---------------------------------------------------------------------------
  448. void __fastcall TCFG0000M::EdGisFilePropertiesButtonClick(TObject *Sender, int AButtonIndex)
  449. {
  450. try {
  451. OpenDialog1->FileName = EdGisFile->Text.Trim();
  452. OpenDialog1->InitialDir = ExtractFilePath(Application->ExeName) + "\\cfg\\";
  453. OpenDialog1->HistoryList->Clear();
  454. OpenDialog1->Filter = "지도설정파일 (*.DVA)|*.DVA";
  455. //OpenDialog1->Options = dlgOpen->Options << ofFileMustExist;
  456. //OpenDialog1->Options = dlgOpen->Options >> ofAllowMultiSelect;
  457. if (!OpenDialog1->Execute()) return;
  458. EdGisFile->Text = OpenDialog1->FileName;
  459. } catch(...) {}
  460. }
  461. //---------------------------------------------------------------------------
  462. void __fastcall TCFG0000M::BtnDbTestClick(TObject *Sender)
  463. {
  464. String sDbProvider = EdDbProvider->Text.Trim();
  465. String sDbUser = EdDbUser->Text.Trim();
  466. String sDbSource = EdDbSource->Text.Trim();
  467. String sDbPasswd = EdDbPasswd->Text.Trim();
  468. if (!ITSDb_Initialize())
  469. {
  470. Application->MessageBox(L"Database 자원을 시스템으로부터 얻지 못했습니다.",
  471. FTitle.c_str(),
  472. MB_OK|MB_ICONERROR|MB_APPLMODAL);
  473. return;
  474. }
  475. ITSDb_SetInfo(sDbProvider, sDbSource, sDbUser, sDbPasswd);
  476. if (ITSDb_Open())
  477. {
  478. Application->MessageBox(L"Database와 연결 테스트에 성공하였습니다.", FTitle.c_str(), MB_OK|MB_ICONINFORMATION|MB_APPLMODAL);
  479. }
  480. else
  481. {
  482. Application->MessageBox(L"Database와 연결 테스트에 실패하였습니다.", FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
  483. }
  484. ITSDb_Close();
  485. ITSDb_Finalize();
  486. }
  487. //---------------------------------------------------------------------------