CFG0000MF.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include "ITSSkinF.h"
  4. #include "ITSUtilF.h"
  5. #include "ITSDbF.h"
  6. #include "AppGlobalF.h"
  7. #include "ITSLangTransF.h"
  8. #pragma hdrstop
  9. #include "CFG0000MF.h"
  10. //---------------------------------------------------------------------------
  11. #pragma package(smart_init)
  12. #pragma link "cxButtonEdit"
  13. #pragma link "cxButtons"
  14. #pragma link "cxCheckBox"
  15. #pragma link "cxContainer"
  16. #pragma link "cxControls"
  17. #pragma link "cxEdit"
  18. #pragma link "cxGraphics"
  19. #pragma link "cxGroupBox"
  20. #pragma link "cxLookAndFeelPainters"
  21. #pragma link "cxLookAndFeels"
  22. #pragma link "cxMaskEdit"
  23. #pragma link "cxSpinEdit"
  24. #pragma link "cxTextEdit"
  25. #pragma link "dxSkinBlack"
  26. #pragma link "dxSkinBlue"
  27. #pragma link "dxSkinsCore"
  28. #pragma link "cxLabel"
  29. #pragma resource "*.dfm"
  30. TCFG0000M *CFG0000M = NULL;
  31. //---------------------------------------------------------------------------
  32. __fastcall TCFG0000M::TCFG0000M(TComponent* Owner)
  33. : TForm(Owner)
  34. {
  35. LangTrans->Translate(this, ITSDb_GetConnection());
  36. ITSSkin_Load(this);
  37. CMM_LoadForm(g_sFormsDir, this);
  38. GrpMap->Visible = false;
  39. //GrpAlarm->Visible = true;
  40. GrpLogout->Visible = false;
  41. Height = 418;
  42. FTitle = Caption;//"환경설정";
  43. }
  44. //---------------------------------------------------------------------------
  45. /*
  46. * 닫기버튼 이나 x버튼 클릭시 공통으로 처리하는 로직이들어간다..
  47. * Form과 DataModule class를 delete시킨다.
  48. * arguments
  49. *
  50. * return
  51. * void
  52. */
  53. void __fastcall TCFG0000M::CommClose()
  54. {
  55. CMM_SaveForm(g_sFormsDir, this);
  56. }
  57. //---------------------------------------------------------------------------
  58. /*
  59. * Form을 보여줄때 호출되는 event 메서드이다.
  60. * arguments
  61. * Sender : event handler 객체
  62. * return
  63. * void
  64. */
  65. void __fastcall TCFG0000M::FormShow(TObject *Sender)
  66. {
  67. Refresh();
  68. TmrShow->Enabled = true;
  69. }
  70. //---------------------------------------------------------------------------
  71. /*
  72. * Form이 Show되고 난 후 최초 1회 수행되는 타이머 이벤트
  73. * arguments
  74. * Sender : event handler 객체
  75. * return
  76. * void
  77. */
  78. void __fastcall TCFG0000M::TmrShowTimer(TObject *Sender)
  79. {
  80. TmrShow->Enabled = false;
  81. RefreshData();
  82. }
  83. //---------------------------------------------------------------------------
  84. /*
  85. * Refresh Data Event Function
  86. * arguments
  87. *
  88. * return
  89. * void
  90. */
  91. void __fastcall TCFG0000M::RefreshData()
  92. {
  93. // 정보를 읽어와서 표출하자.
  94. #if 0
  95. ST_GISINFO GisInfo;
  96. String sLeftTopX = GetConfigValue("MAP", "LEFTTOPX", "126.891");
  97. String sLeftTopY = GetConfigValue("MAP", "LEFTTOPY", "037.383");
  98. String sRightBottomX = GetConfigValue("MAP", "RIGHTBOTTOMX", "126.981");
  99. String sRightBottomY = GetConfigValue("MAP", "RIGHTBOTTOMY", "037.318");
  100. String sCenterX = GetConfigValue("MAP", "CENTERX", "126.935");
  101. String sCenterY = GetConfigValue("MAP", "CENTERY", "037.360");
  102. GisInfo.dLeftTopX = sLeftTopX.ToDouble();
  103. GisInfo.dLeftTopY = sLeftTopY.ToDouble();
  104. GisInfo.dRightBottomX = sRightBottomX.ToDouble();
  105. GisInfo.dRightBottomY = sRightBottomY.ToDouble();
  106. GisInfo.dCenterX = sCenterX.ToDouble();
  107. GisInfo.dCenterY = sCenterY.ToDouble();
  108. GisInfo.sCenterName = CenterName;
  109. GisInfo.sMapFileNameL0 = GetConfigValue("MAP", "MAPFILEL0", "");
  110. GisInfo.sIdxMapFileName = "";//GetConfigValue("MAP", "INDEXMAPFILE", "");
  111. #endif
  112. EdCenterId->Text = CenterId;
  113. EdCenterName->Text = CenterName;
  114. //EdGisFile->Text = g_GisInfo.sMapFileNameL0;
  115. EdDbProvider->Text = g_AppCfg.itsdb.sProvider;
  116. EdDbUser->Text = g_AppCfg.itsdb.sUserName;
  117. EdDbSource->Text = g_AppCfg.itsdb.sServerName;
  118. EdDbPasswd->Text = g_AppCfg.itsdb.sPassword;
  119. EdProcessId->Text = g_AppCfg.sProcessId;
  120. //EdTaskId->Text = "";
  121. //EdNodeId->Text = "";
  122. //EdSequence->Text = "";
  123. SeTemp->Value = g_AppCfg.Temp.AlarmValue;
  124. ChkAlarm->Checked = g_AppCfg.Alarm.Enabled;
  125. ChkAlarmWindow->Checked = g_AppCfg.Alarm.Window;
  126. SeAlarmTimeOut->Value = g_AppCfg.Alarm.TimeOut;
  127. ChkIncident->Checked = g_AppCfg.Incident.Enabled;
  128. SeIncidentTimeOut->Value = g_AppCfg.Incident.TimeOut;
  129. ChkSaveForm->Checked = g_AppCfg.bSaveForm;
  130. ChkAutoLogout->Checked = g_AppCfg.AutoLogout.Enabled;
  131. SeInterevalMin->Value = g_AppCfg.AutoLogout.IntervalMin;
  132. }
  133. //---------------------------------------------------------------------------
  134. /*
  135. * Search 버튼 클릭 이벤트 핸들러
  136. * arguments
  137. * Sender : event handler 객체
  138. * return
  139. * void
  140. */
  141. /*
  142. * Close 버튼 클릭 이벤트 핸들러
  143. * arguments
  144. * Sender : event handler 객체
  145. * return
  146. * void
  147. */
  148. void __fastcall TCFG0000M::BtnCloseClick(TObject *Sender)
  149. {
  150. Close();
  151. }
  152. //---------------------------------------------------------------------------
  153. /*
  154. * Select Button Click Event Handler
  155. * arguments
  156. * Sender : event handler 객체
  157. * return
  158. * void
  159. */
  160. void __fastcall TCFG0000M::BtnSaveClick(TObject *Sender)
  161. {
  162. //bool bSaved = false;
  163. String sMsgString;
  164. String sID, sIPAddress;
  165. int sMsgType = MB_OK|MB_ICONWARNING|MB_APPLMODAL;
  166. sMsgString = lblQry->Caption;//"시스템 환경설정 정보를 저장하시겠습니까?";
  167. sMsgType = MB_YESNO|MB_ICONINFORMATION|MB_APPLMODAL;
  168. if (Application->MessageBox(sMsgString.c_str(), FTitle.c_str(), sMsgType)==IDNO)
  169. {
  170. return;
  171. }
  172. String sCenterId = EdCenterId->Text.Trim();
  173. String sCenterName = EdCenterName->Text.Trim();
  174. String sGisFile = EdGisFile->Text.Trim();
  175. String sDbProvider = EdDbProvider->Text.Trim();
  176. String sDbUser = EdDbUser->Text.Trim();
  177. String sDbSource = EdDbSource->Text.Trim();
  178. String sDbPasswd = EdDbPasswd->Text.Trim();
  179. String sProcessId = EdProcessId->Text.Trim();
  180. g_AppCfg.bSaveForm = ChkSaveForm->Checked;
  181. String sSaveForm = g_AppCfg.bSaveForm ? "1" : "0";
  182. //String sTaskId = EdTaskId->Text.Trim();
  183. //String sNodeId = EdNodeId->Text.Trim();
  184. //String sSequence = EdSequence->Text.Trim();
  185. g_AppCfg.Temp.AlarmValue = SeTemp->Value;
  186. g_AppCfg.Alarm.Enabled = ChkAlarm->Checked;
  187. g_AppCfg.Alarm.Window = ChkAlarmWindow->Checked;
  188. g_AppCfg.Alarm.TimeOut = SeAlarmTimeOut->Value;
  189. String sAlarm = g_AppCfg.Alarm.Enabled ? "1" : "0";
  190. String sAlarmWindow = g_AppCfg.Alarm.Window ? "1" : "0";
  191. String sAlarmTimeOut = String(g_AppCfg.Alarm.TimeOut);
  192. g_AppCfg.Incident.Enabled = ChkIncident->Checked;
  193. g_AppCfg.Incident.TimeOut = SeIncidentTimeOut->Value;
  194. String sIncident = g_AppCfg.Incident.Enabled ? "1" : "0";
  195. String sIncidentTimeOut = String(g_AppCfg.Incident.TimeOut);
  196. g_AppCfg.AutoLogout.Enabled = ChkAutoLogout->Checked;
  197. g_AppCfg.AutoLogout.IntervalMin = SeInterevalMin->Value;
  198. String sAutoLogout = g_AppCfg.AutoLogout.Enabled ? "1" : "0";
  199. String sInterMin = String(g_AppCfg.AutoLogout.IntervalMin);
  200. try {
  201. SetConfigValue("CENTER", "CENTERID", sCenterId);
  202. SetConfigValue("CENTER", "CENTERNAME", sCenterName);
  203. //SetConfigValue("MAP", "MAPFILEL0", sGisFile);
  204. SetConfigValue("ITSDB", "PROVIDER", sDbProvider);
  205. SetConfigValue("ITSDB", "SERVERNAME", sDbSource);
  206. SetConfigValue("ITSDB", "USERNAME", sDbUser);
  207. SetConfigValue("ITSDB", "PASSWORD", sDbPasswd);
  208. SetConfigValue("TEMPERATURE", "ALARMVALUE", String(g_AppCfg.Temp.AlarmValue));
  209. SetConfigValue("ALARM", "ENABLED", sAlarm);
  210. SetConfigValue("ALARM", "WINDOW", sAlarmWindow);
  211. SetConfigValue("ALARM", "TIMEOUT", sAlarmTimeOut);
  212. SetConfigValue("INCIDENT", "ENABLED", sIncident);
  213. SetConfigValue("INCIDENT", "TIMEOUT", sIncidentTimeOut);
  214. SetConfigValue("AUTOLOGOUT", "ENABLED", sAutoLogout);
  215. SetConfigValue("AUTOLOGOUT", "INTERVALMIN", sInterMin);
  216. SetConfigValue("APPLICATION", "PROCESSID", sProcessId);
  217. SetConfigValue("APPLICATION", "SAVEFORM", sSaveForm);
  218. CenterId = sCenterId;
  219. CenterName = sCenterName;
  220. CenterCd = String(StrToInt(CenterId.SubString(2, 2)));
  221. //g_GisInfo.sMapFileNameL0 = sGisFile;
  222. g_AppCfg.itsdb.sProvider = sDbProvider;
  223. g_AppCfg.itsdb.sUserName = sDbUser;
  224. g_AppCfg.itsdb.sServerName = sDbSource;
  225. g_AppCfg.itsdb.sPassword = sDbPasswd;
  226. g_AppCfg.sProcessId = sProcessId;
  227. Application->MessageBox(lblQryRes->Caption.c_str(),//L"환경설정 정보를 정상적으로 저장하였습니다.\r\일부 환경설정은 다음 프로그램 실행 부터 반영됩니다.",
  228. FTitle.c_str(), MB_OK|MB_ICONINFORMATION|MB_APPLMODAL);
  229. CMM_SetFormPosition(g_AppCfg.bSaveForm);
  230. } catch(...) {
  231. }
  232. //Close();
  233. }
  234. //---------------------------------------------------------------------------
  235. void __fastcall TCFG0000M::FormClose(TObject *Sender, TCloseAction &Action)
  236. {
  237. CommClose();
  238. CFG0000M = NULL;
  239. Action = caFree;
  240. }
  241. //---------------------------------------------------------------------------
  242. String __fastcall TCFG0000M::GetConfigValue(String sSection, String sIdent, String sDefVal)
  243. {
  244. String sResult = sDefVal;
  245. TIniFile *pIniFile = NULL;
  246. String sCfgFile = ExtractFilePath(Application->ExeName) + "\\cfg\\" + FIniFile;
  247. try
  248. {
  249. pIniFile = new TIniFile(sCfgFile);
  250. sResult = pIniFile->ReadString(sSection, sIdent, sDefVal);
  251. }
  252. __finally
  253. {
  254. if (pIniFile) delete pIniFile;
  255. pIniFile = NULL;
  256. }
  257. return sResult;
  258. }
  259. //---------------------------------------------------------------------------
  260. void __fastcall TCFG0000M::SetConfigValue(String sSection, String sIdent, String sSetVal)
  261. {
  262. TIniFile *pIniFile = NULL;
  263. String sCfgFile = ExtractFilePath(Application->ExeName) + "\\cfg\\" + FIniFile;
  264. try
  265. {
  266. pIniFile = new TIniFile(sCfgFile);
  267. pIniFile->WriteString(sSection, sIdent, sSetVal);
  268. }
  269. __finally
  270. {
  271. if (pIniFile) delete pIniFile;
  272. pIniFile = NULL;
  273. }
  274. }
  275. //---------------------------------------------------------------------------
  276. void __fastcall TCFG0000M::EdGisFilePropertiesButtonClick(TObject *Sender, int AButtonIndex)
  277. {
  278. try {
  279. OpenDialog1->FileName = EdGisFile->Text.Trim();
  280. OpenDialog1->InitialDir = ExtractFilePath(Application->ExeName) + "\\cfg\\";
  281. OpenDialog1->HistoryList->Clear();
  282. OpenDialog1->Filter = "지도설정파일 (*.DVA)|*.DVA";
  283. //OpenDialog1->Options = dlgOpen->Options << ofFileMustExist;
  284. //OpenDialog1->Options = dlgOpen->Options >> ofAllowMultiSelect;
  285. if (!OpenDialog1->Execute()) return;
  286. EdGisFile->Text = OpenDialog1->FileName;
  287. } catch(...) {}
  288. }
  289. //---------------------------------------------------------------------------