CCAMH101F.cpp 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include "ITSSkinF.h"
  4. #include "ITSUtilF.h"
  5. #include "ITSDbF.h"
  6. #include "AppGlobalF.h"
  7. #include "WindowMsgF.h"
  8. #include "ITSLangTransF.h"
  9. #pragma hdrstop
  10. #include "CCAMH101F.h"
  11. //---------------------------------------------------------------------------
  12. #pragma package(smart_init)
  13. #pragma link "cxButtons"
  14. #pragma link "cxCheckBox"
  15. #pragma link "cxClasses"
  16. #pragma link "cxContainer"
  17. #pragma link "cxControls"
  18. #pragma link "cxCustomData"
  19. #pragma link "cxData"
  20. #pragma link "cxDataStorage"
  21. #pragma link "cxEdit"
  22. #pragma link "cxFilter"
  23. #pragma link "cxGraphics"
  24. #pragma link "cxGrid"
  25. #pragma link "cxGridCustomTableView"
  26. #pragma link "cxGridCustomView"
  27. #pragma link "cxGridLevel"
  28. #pragma link "cxGridTableView"
  29. #pragma link "cxLabel"
  30. #pragma link "cxLookAndFeelPainters"
  31. #pragma link "cxLookAndFeels"
  32. #pragma link "cxStyles"
  33. #pragma link "cxTextEdit"
  34. #pragma link "dxSkinBlack"
  35. #pragma link "dxSkinBlue"
  36. #pragma link "dxSkinsCore"
  37. #pragma link "dxSkinscxPCPainter"
  38. #pragma resource "*.dfm"
  39. TCCAMH101 *CCAMH101 = NULL;
  40. //---------------------------------------------------------------------------
  41. __fastcall TCCAMH101::TCCAMH101(TComponent* Owner, HWND hHandle, String sFrom, String sTo, String sIdList)
  42. : TForm(Owner)
  43. {
  44. LangTrans->Translate(this, ITSDb_GetConnection());
  45. ITSSkin_Load(this);
  46. CMM_LoadForm(g_sFormsDir, this);
  47. FParent = hHandle;
  48. FStDateTime = sFrom;
  49. FEdDateTime = sTo;
  50. FIdList = sIdList;
  51. }
  52. //---------------------------------------------------------------------------
  53. __fastcall TCCAMH101::~TCCAMH101(void)
  54. {
  55. }
  56. //--------------------------------------------------------------------------
  57. void __fastcall TCCAMH101::FormInit()
  58. {
  59. ADOQry->Connection = ITSDb_GetConnection();
  60. m_pGDC = TvList->DataController;
  61. TvList->OptionsView->NoDataToDisplayInfoText = FrmLang->lblNoInfo->Caption;//"<VDS-제어기 상태 이력 정보>";
  62. //TvList->ViewInfo->GroupByBoxViewInfo->Text = "그룹핑할 필드의 헤더를 이곳으로 드래그 하세요";
  63. LblSearch->Caption = FrmLang->lblQryCond->Caption + FStDateTime.SubString(1, 12) + " ~ " + FEdDateTime.SubString(1, 12);
  64. }
  65. //---------------------------------------------------------------------------
  66. void __fastcall TCCAMH101::FormShow(TObject *Sender)
  67. {
  68. FormInit();
  69. Refresh();
  70. TmrShow->Enabled = true;
  71. }
  72. //---------------------------------------------------------------------------
  73. void __fastcall TCCAMH101::CommClose()
  74. {
  75. CMM_SaveForm(g_sFormsDir, this);
  76. //CCAMH101 = NULL;
  77. }
  78. //---------------------------------------------------------------------------
  79. void __fastcall TCCAMH101::TmrShowTimer(TObject *Sender)
  80. {
  81. TmrShow->Enabled = false;
  82. Application->ProcessMessages();
  83. SelHistory();
  84. }
  85. //---------------------------------------------------------------------------
  86. void __fastcall TCCAMH101::ChkExpandClick(TObject *Sender)
  87. {
  88. CMM_ExpandCollapseChk(TvList, ChkExpand->Checked);
  89. }
  90. //---------------------------------------------------------------------------
  91. void __fastcall TCCAMH101::SelHistory()
  92. {
  93. TSqlCursor sqlCrs;
  94. String sQry;
  95. TADOQuery *pADO = ADOQry;
  96. sQry = "SELECT A.*, B.CCAM_CTLR_ID, B.CCAM_NM \r\n"
  97. " FROM TB_CCAM_CTLR_STTS_HS A, TB_CCAM_CTLR B \r\n"
  98. " WHERE A.CRTN_DT BETWEEN :p01 AND :p02 \r\n"
  99. " AND B.CCAM_CTLR_NMBR IN(" + FIdList + ") \r\n"
  100. " AND A.CCAM_CTLR_NMBR = B.CCAM_CTLR_NMBR \r\n"
  101. " ORDER BY A.CCAM_CTLR_NMBR, A.CRTN_DT \r\n";
  102. try
  103. {
  104. ITSDb_SQLText(pADO, sQry);
  105. ITSDb_SQLBind(pADO, "p01", FStDateTime);
  106. ITSDb_SQLBind(pADO, "p02", FEdDateTime);
  107. ITSDb_SQLOpen(pADO);
  108. DspHistory();
  109. }
  110. catch(EDatabaseError &E)
  111. {
  112. ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
  113. DBERRORMSG(Caption, String(E.ClassName()), E.Message, sQry);
  114. throw Exception(String(E.ClassName()) + E.Message);
  115. }
  116. catch(Exception &e)
  117. {
  118. ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
  119. DBERRORMSG(Caption, String(e.ClassName()), e.Message, sQry);
  120. throw Exception(String(e.ClassName()) + e.Message);
  121. }
  122. }
  123. //---------------------------------------------------------------------------
  124. void __fastcall TCCAMH101::DspHistory()
  125. {
  126. TADOQuery *pADO = ADOQry;
  127. try
  128. {
  129. TcxGridChartSeries *pChart = NULL;
  130. CMM_ClearGridTableView(TvList);
  131. int nRow = 0;
  132. int nDataCnt = 0;
  133. try {
  134. TvList->BeginUpdate();
  135. nDataCnt = pADO->RecordCount;
  136. m_pGDC->RecordCount = nDataCnt;
  137. for( ; !pADO->Eof; pADO->Next(), nRow++)
  138. {
  139. m_pGDC->Values[nRow][Column00->Index] = pADO->FieldByName("CCAM_CTLR_NMBR")->AsString;
  140. m_pGDC->Values[nRow][Column11->Index] = pADO->FieldByName("CCAM_CTLR_ID")->AsString;
  141. m_pGDC->Values[nRow][Column09->Index] = pADO->FieldByName("CCAM_NM")->AsString;
  142. String sDbDate = pADO->FieldByName("CRTN_DT")->AsString;
  143. m_pGDC->Values[nRow][Column01->Index] = ITSUtil_FormatStr(sDbDate, STR_DATETIME);
  144. String CMNC_STTS_CD = pADO->FieldByName("CMNC_STTS_CD")->AsString;
  145. if (CMNC_STTS_CD == "CMS0") m_pGDC->Values[nRow][Column02->Index] = FrmLang->lblComm0->Caption;
  146. else
  147. if (CMNC_STTS_CD == "CMS1") m_pGDC->Values[nRow][Column02->Index] = FrmLang->lblComm1->Caption;
  148. else m_pGDC->Values[nRow][Column02->Index] = FrmLang->lblUnknown->Caption;
  149. }
  150. }
  151. __finally
  152. {
  153. if (pADO)
  154. {
  155. pADO->Close();
  156. }
  157. TvList->EndUpdate();
  158. //CxList->SetFocus();
  159. LblRecords->Caption = FormatFloat("##,##0", m_pGDC->RecordCount) + FrmLang->lblEA->Caption;//" 건";
  160. String sEnd = FrmLang->lblQrySel->Caption + " [" + LblRecords->Caption + "]";//"데이터 " + LblRecords->Caption + " 이 조회 되었습니다.";
  161. Application->MessageBox(sEnd.c_str(),
  162. FrmLang->lblQryEnd->Caption.c_str(),//L"데이터 조회 완료",
  163. MB_OK|MB_ICONINFORMATION|MB_APPLMODAL);
  164. }
  165. }
  166. catch(EDatabaseError &E)
  167. {
  168. ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
  169. DBERRORMSG(Caption, String(E.ClassName()), E.Message, pADO->SQL->Text);
  170. throw Exception(String(E.ClassName()) + E.Message);
  171. }
  172. catch(Exception &e)
  173. {
  174. ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
  175. DBERRORMSG(Caption, String(e.ClassName()), e.Message, pADO->SQL->Text);
  176. throw Exception(String(e.ClassName()) + e.Message);
  177. }
  178. }
  179. //---------------------------------------------------------------------------
  180. void __fastcall TCCAMH101::OnMessage(TMessage &Msg)
  181. {
  182. switch (Msg.Msg)
  183. {
  184. case WM_PARAM_DATABASE:
  185. if (WP_DB_SELECT_OK == Msg.WParam)
  186. {
  187. //ShowMessage("Select Ok");
  188. }
  189. break;
  190. }
  191. }
  192. //---------------------------------------------------------------------------
  193. void __fastcall TCCAMH101::BtnExlSaveClick(TObject *Sender)
  194. {
  195. TcxGrid *pGrid = CxList;
  196. TcxGridTableView *pView = TvList;
  197. String sTitle= Caption;//"VDS-제어기 상태이력";
  198. CMM_ExportToExcelFile(sTitle, pGrid, pView, this);
  199. }
  200. //---------------------------------------------------------------------------
  201. void __fastcall TCCAMH101::FormClose(TObject *Sender, TCloseAction &Action)
  202. {
  203. POST_MSG(FParent, WM_SUBFORM_CLOSE, 0, 0);
  204. CommClose();
  205. //CCAMH101 = NULL;
  206. }
  207. //---------------------------------------------------------------------------
  208. void __fastcall TCCAMH101::Column02CustomDrawCell(TcxCustomGridTableView *Sender, TcxCanvas *ACanvas, TcxGridTableDataCellViewInfo *AViewInfo,
  209. bool &ADone)
  210. {
  211. TColor tColor = ACanvas->Brush->Color;
  212. TColor tFont = clBlack;
  213. try
  214. {
  215. if (!VarIsNull(AViewInfo->Value))
  216. {
  217. String sTmp = AViewInfo->Value;
  218. if (sTmp == FrmLang->lblComm0->Caption)
  219. {
  220. tColor = clLime;
  221. }
  222. else
  223. if (sTmp == FrmLang->lblComm1->Caption)
  224. {
  225. tColor = clRed;
  226. }
  227. else
  228. {
  229. tColor = clSilver;
  230. }
  231. }
  232. ACanvas->Font->Color = tFont;
  233. ACanvas->SetBrushColor(tColor);
  234. }
  235. catch(...)
  236. {
  237. }
  238. }
  239. //---------------------------------------------------------------------------