TAS0040MF.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include "ITSSkinF.h"
  4. #include "ITSUtilF.h"
  5. #include "AppGlobalF.h"
  6. #include "CDSRoadF.h"
  7. #include "CDSIfscF.h"
  8. #include "ITSLangTransF.h"
  9. #pragma hdrstop
  10. #include "TAS0040MF.h"
  11. #include "TAS00401F.h"
  12. #include "CDSCodeF.h"
  13. //---------------------------------------------------------------------------
  14. #pragma package(smart_init)
  15. #pragma link "cxButtons"
  16. #pragma link "cxContainer"
  17. #pragma link "cxControls"
  18. #pragma link "cxDropDownEdit"
  19. #pragma link "cxEdit"
  20. #pragma link "cxGraphics"
  21. #pragma link "cxGroupBox"
  22. #pragma link "cxLookAndFeelPainters"
  23. #pragma link "cxLookAndFeels"
  24. #pragma link "cxMaskEdit"
  25. #pragma link "cxPC"
  26. #pragma link "cxPCdxBarPopupMenu"
  27. #pragma link "cxTextEdit"
  28. #pragma link "dxSkinBlack"
  29. #pragma link "dxSkinBlue"
  30. #pragma link "dxSkinsCore"
  31. #pragma link "dxSkinscxPCPainter"
  32. #pragma resource "*.dfm"
  33. TTAS0040M *TAS0040M = NULL;
  34. //---------------------------------------------------------------------------
  35. __fastcall TTAS0040M::TTAS0040M(TComponent* Owner)
  36. : TForm(Owner)
  37. {
  38. LangTrans->Translate(this, ITSDb_GetConnection());
  39. ITSSkin_Load(this);
  40. CMM_LoadForm(g_sFormsDir, this);
  41. FTitle = Caption;//"특수일분석";
  42. m_pFormList = new TList();
  43. TsList01->TabVisible = false;
  44. MyItsAtrdManager = new TItsAtrdManager();
  45. MyItsAtrdManager->LoadFromDb();
  46. }
  47. //---------------------------------------------------------------------------
  48. /*
  49. * 닫기버튼 이나 x버튼 클릭시 공통으로 처리하는 로직이들어간다..
  50. * Form과 DataModule class를 delete시킨다.
  51. * arguments
  52. *
  53. * return
  54. * void
  55. */
  56. void __fastcall TTAS0040M::CommClose()
  57. {
  58. try
  59. {
  60. if (MyHolidayManager)
  61. {
  62. delete MyHolidayManager;
  63. MyHolidayManager = NULL;
  64. }
  65. if (MyItsAtrdManager)
  66. {
  67. delete MyItsAtrdManager;
  68. MyItsAtrdManager = NULL;
  69. }
  70. for (int idx = m_pFormList->Count-1; idx >= 0; idx--)
  71. {
  72. m_pFormList->Delete(idx);
  73. }
  74. delete m_pFormList;
  75. CMM_SaveForm(g_sFormsDir, this);
  76. }
  77. catch(...)
  78. {
  79. }
  80. }
  81. //---------------------------------------------------------------------------
  82. /*
  83. * Form을 보여줄때 호출되는 event 메서드이다.
  84. * arguments
  85. * Sender : event handler 객체
  86. * return
  87. * void
  88. */
  89. void __fastcall TTAS0040M::FormShow(TObject *Sender)
  90. {
  91. Refresh();
  92. FormInit();
  93. TmrShow->Enabled = true;
  94. }
  95. //---------------------------------------------------------------------------
  96. /*
  97. * form 초기화
  98. *
  99. * arguments
  100. *
  101. * return
  102. * void
  103. */
  104. void __fastcall TTAS0040M::FormInit()
  105. {
  106. FAtrdId = "";
  107. if (!MyHolidayManager)
  108. {
  109. MyHolidayManager = new TItsHolidayManager();
  110. }
  111. MyHolidayManager->LoadFromDb();
  112. CbIfsc->Properties->Items->Clear();
  113. CbYear->Properties->Items->Clear();
  114. CbType->Properties->Items->Clear();
  115. CbAtrd->Properties->Items->Clear();
  116. try
  117. {
  118. MyItsAtrdManager->FLists.Lock();
  119. FOR_STL(TItsAtrd*, pObj, MyItsAtrdManager->FLists)
  120. {
  121. if (pObj->DEL_YN == "Y") continue;
  122. String sDir = (pObj->DRCT_CD.Trim() == "0") ? FrmLang->lblUp->Caption : FrmLang->lblDown->Caption;//String("상행") : String("하행");
  123. String sAtr = pObj->ATRD_NM;
  124. CbAtrd->Properties->Items->AddObject(sAtr + " [" + sDir + "]", (TObject*)pObj);
  125. }
  126. }
  127. __finally
  128. {
  129. MyItsAtrdManager->FLists.UnLock();
  130. CbAtrd->ItemIndex = 0;
  131. }
  132. int nMinYear = 2018;
  133. int nMaxYear = Now().FormatString("YYYY").ToIntDef(2018);
  134. for (int ii = nMinYear; ii <= nMaxYear; ii++)
  135. {
  136. String sYear;
  137. sYear.printf(L"%04d", ii);
  138. CbYear->Properties->Items->AddObject(sYear, (TObject*)NULL);
  139. }
  140. CbYear->ItemIndex = 0;
  141. }
  142. //---------------------------------------------------------------------------
  143. /*
  144. * Form이 Show되고 난 후 최초 1회 수행되는 타이머 이벤트
  145. * arguments
  146. * Sender : event handler 객체
  147. * return
  148. * void
  149. */
  150. void __fastcall TTAS0040M::TmrShowTimer(TObject *Sender)
  151. {
  152. TmrShow->Enabled = false;
  153. }
  154. //---------------------------------------------------------------------------
  155. /*
  156. * Refresh Data Event Function
  157. * arguments
  158. *
  159. * return
  160. * void
  161. */
  162. void __fastcall TTAS0040M::RefreshData()
  163. {
  164. // 검색조건에 의한 링크 데이터 조회
  165. try
  166. {
  167. //SelListData();
  168. }
  169. __finally
  170. {
  171. }
  172. }
  173. //---------------------------------------------------------------------------
  174. /*
  175. * Search 버튼 클릭 이벤트 핸들러
  176. * arguments
  177. * Sender : event handler 객체
  178. * return
  179. * void
  180. */
  181. void __fastcall TTAS0040M::BtnSearchClick(TObject *Sender)
  182. {
  183. Application->ProcessMessages();
  184. TSqlCursor sqlCrs((TControl*)BtnSearch);
  185. String sTitle;
  186. TItsAtrd *pAtrd = (TItsAtrd*)CbAtrd->Properties->Items->Objects[CbAtrd->ItemIndex];
  187. if (!pAtrd)
  188. {
  189. Application->MessageBox(FrmLang->lblSelErr->Caption.c_str(),//L"간선도로를 먼저 선택 하세요.",
  190. FTitle.c_str(), MB_OK|MB_ICONWARNING|MB_APPLMODAL);
  191. ActiveControl = CbAtrd;
  192. return;
  193. }
  194. FAtrdId = pAtrd->ATRD_ID;
  195. FAtrdNm = CbAtrd->Text.Trim();
  196. TItsIfsc *pIfsc = (TItsIfsc*)CbIfsc->Properties->Items->Objects[CbIfsc->ItemIndex];
  197. if (!pIfsc)
  198. {
  199. Application->MessageBox(FrmLang->lblSelErr->Caption.c_str(),//L"간선도로 구간을 먼저 선택 하세요.",
  200. FTitle.c_str(), MB_OK|MB_ICONWARNING|MB_APPLMODAL);
  201. ActiveControl = CbIfsc;
  202. return;
  203. }
  204. FLinkId = pIfsc->IFSC_ID;
  205. FLinkNm = pIfsc->STRT_NM + " → " + pIfsc->END_NM;
  206. TItsHoliday *pHoliday = (TItsHoliday*)CbType->Properties->Items->Objects[CbType->ItemIndex];
  207. if (!pHoliday)
  208. {
  209. Application->MessageBox(FrmLang->lblSelErr->Caption.c_str(),//L"특수일을 먼저 선택 하세요.",
  210. FTitle.c_str(), MB_OK|MB_ICONWARNING|MB_APPLMODAL);
  211. ActiveControl = CbType;
  212. return;
  213. }
  214. FQryDay = pHoliday->YMD;
  215. FQryDayNm = pHoliday->LEGL_HLDY_NM;
  216. sTitle.printf(L"%s [%s] ", FLinkNm.c_str(), FQryDayNm.c_str());
  217. try
  218. {
  219. Application->ProcessMessages();
  220. LockWindowUpdate(Handle);
  221. TcxTabSheet *pSheet = CMM_AddTabSheet(PgTab, sTitle);
  222. if (!pSheet) return;
  223. TAS00401 = new TTAS00401(this, Handle, FLinkId, FLinkNm, FQryDay, FPtrnWeek, FQryDayNm);
  224. TAS00401->Parent = pSheet;
  225. TAS00401->Show();
  226. PgTab->ActivePage = pSheet;
  227. pSheet = PgTab->ActivePage;
  228. m_pFormList->Add(TAS00401);
  229. }
  230. __finally
  231. {
  232. LockWindowUpdate(0);
  233. }
  234. }
  235. //---------------------------------------------------------------------------
  236. /*
  237. * Close 버튼 클릭 이벤트 핸들러
  238. * arguments
  239. * Sender : event handler 객체
  240. * return
  241. * void
  242. */
  243. void __fastcall TTAS0040M::BtnCloseClick(TObject *Sender)
  244. {
  245. Close();
  246. }
  247. //---------------------------------------------------------------------------
  248. /*
  249. * 조회결과 폼이 닫힐때 메시지를 받아 처리한다.
  250. * arguments
  251. * Sender : event handler 객체
  252. * return
  253. * void
  254. */
  255. void __fastcall TTAS0040M::OnSubFormClose(TMessage Msg)
  256. {
  257. int nActiveIdx = PgTab->ActivePageIndex;
  258. if (nActiveIdx <= 0) return;
  259. LockWindowUpdate(Handle);
  260. TcxTabSheet *pSheet = PgTab->ActivePage;
  261. if (pSheet)
  262. {
  263. delete pSheet;
  264. }
  265. nActiveIdx--; // 첫번째 탭은 화면에 숨겨져 있다.
  266. m_pFormList->Delete(nActiveIdx);
  267. LockWindowUpdate(0);
  268. }
  269. //---------------------------------------------------------------------------
  270. /*
  271. * Tab Control의 Tab을 더블클릭하여 닫는다.
  272. * arguments
  273. * Sender : event handler 객체
  274. * return
  275. * void
  276. */
  277. void __fastcall TTAS0040M::PgTabDblClick(TObject *Sender)
  278. {
  279. TPoint APoint;
  280. APoint = PgTab->MouseDownPos;
  281. if (PgTab->IndexOfTabAt(APoint.x, APoint.y) != -1)
  282. POST_MSG(Handle, WM_SUBFORM_CLOSE, 0, 0);
  283. }
  284. //---------------------------------------------------------------------------
  285. void __fastcall TTAS0040M::FormClose(TObject *Sender, TCloseAction &Action)
  286. {
  287. CommClose();
  288. TAS0040M = NULL;
  289. Action = caFree;
  290. }
  291. //---------------------------------------------------------------------------
  292. void __fastcall TTAS0040M::CbAtrdPropertiesChange(TObject *Sender)
  293. {
  294. TItsAtrd *pObj = (TItsAtrd*)CbAtrd->Properties->Items->Objects[CbAtrd->ItemIndex];
  295. if (!pObj) return;
  296. FAtrdId = pObj->ATRD_ID;
  297. FAtrdNm = pObj->ATRD_NM;
  298. CbIfsc->Properties->Items->Clear();
  299. FOR_STL(TItsAtrdRoad*, pAtrdRoad, pObj->FSubLists)
  300. {
  301. TItsRoad *pRoad = ItsRoadManager->FLists.Find(pAtrdRoad->ROAD_ID);
  302. if (!pRoad) continue;
  303. std::map<int, String>::iterator itPos;
  304. for(itPos = pRoad->FSubLists.begin(); itPos != pRoad->FSubLists.end(); ++itPos)
  305. {
  306. String sIfscId = itPos->second;
  307. TItsIfsc *pIfsc = ItsIfscManager->FLists.Find(sIfscId);
  308. if (!pIfsc) continue;
  309. CbIfsc->Properties->Items->AddObject(" [" + pIfsc->IFSC_ID + "] " + pIfsc->STRT_NM + " → " + pIfsc->END_NM, (TObject*)pIfsc);
  310. }
  311. }
  312. CbIfsc->ItemIndex = 0;
  313. }
  314. //---------------------------------------------------------------------------
  315. void __fastcall TTAS0040M::CbYearPropertiesChange(TObject *Sender)
  316. {
  317. String sYear = CbYear->Text.Trim();
  318. String sFromDay = sYear + "0101";
  319. String sToDay;
  320. int nSelYear = sYear.ToIntDef(2018);
  321. int nCurYear = Now().FormatString("YYYY").ToIntDef(2018);
  322. if (nSelYear == nCurYear)
  323. {
  324. sToDay = sYear + Now().FormatString("MMDD");
  325. }
  326. else
  327. {
  328. sToDay = sYear + "1231";
  329. }
  330. double nStartYear = sFromDay.ToDouble();
  331. double nEndYear = sToDay.ToDouble();
  332. double nTempYear;
  333. CbType->Properties->Items->Clear();
  334. FOR_STL(TItsHoliday*, pObj, MyHolidayManager->FLists)
  335. {
  336. if (pObj->DEL_YN != "N") continue;
  337. nTempYear = pObj->YMD.ToDouble();
  338. if (nTempYear < nStartYear || nTempYear > nEndYear) continue;
  339. CbType->Properties->Items->AddObject(" [" + pObj->YMD + "] " + pObj->LEGL_HLDY_NM, (TObject*)pObj);
  340. }
  341. CbType->ItemIndex = 0;
  342. }
  343. //---------------------------------------------------------------------------
  344. void __fastcall TTAS0040M::PgTabCanCloseEx(TObject *Sender, int ATabIndex, bool &ACanClose)
  345. {
  346. int nActiveIdx = ATabIndex;
  347. if (nActiveIdx <= 0) return;
  348. nActiveIdx--; // 첫번째 탭은 화면에 숨겨져 있다.
  349. m_pFormList->Delete(nActiveIdx);
  350. }
  351. //---------------------------------------------------------------------------