WCAMH101F.cpp 10.0 KB

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