FRAME_FailHndlF.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include "ITSSkinF.h"
  4. #include "ITSUtilF.h"
  5. #include "FrmResourceF.h"
  6. #include "ITSDbF.h"
  7. #include "AppGlobalF.h"
  8. #include "ITSLangTransF.h"
  9. #include "ITS_OPLibF.h"
  10. #pragma hdrstop
  11. #include "FRAME_FailHndlF.h"
  12. //---------------------------------------------------------------------------
  13. #pragma package(smart_init)
  14. #pragma link "cxButtons"
  15. #pragma link "cxCalc"
  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 "cxGroupBox"
  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 resource "*.dfm"
  41. //TFRAMEFailHndl *FRAMEFailHndl;
  42. //---------------------------------------------------------------------------
  43. __fastcall TFRAMEFailHndl::TFRAMEFailHndl(TComponent* Owner)
  44. : TFrame(Owner)
  45. {
  46. ITSSkin_Load((TForm*)this);
  47. FCode = new TFacilityCodeManager();
  48. //FCode->LoadHndlTypeDb();
  49. TvList1->OptionsView->NoDataToDisplayInfoText = FrmLang->lblNoInfo->Caption;//"<장애 장비 유형 정보가 없습니다>";
  50. m_pGDC1 = TvList1->DataController;
  51. EdId1->Enabled = false;
  52. FormClear1();
  53. SelListData1();
  54. ChangeButtonType1(1);
  55. //BtnSearchClick((TObject*)BtnSearch);
  56. }
  57. //---------------------------------------------------------------------------
  58. void __fastcall TFRAMEFailHndl::FormClear1()
  59. {
  60. m_enJob1 = enJobNone;
  61. EdId1->Clear();
  62. EdKName1->Clear();
  63. }
  64. //---------------------------------------------------------------------------
  65. void __fastcall TFRAMEFailHndl::ChangeButtonType1(int nBtnType)
  66. {
  67. if (nBtnType == 1)
  68. {
  69. BtnSave1->Visible = false;
  70. BtnCancel1->Visible = false;
  71. BtnInsert1->Visible = true;
  72. //if (TvList1->ViewData->RecordCount > 0)
  73. if (TvList1->ViewData->RecordCount >= 0)
  74. {
  75. BtnEdit1->Visible = true;
  76. BtnDelete1->Visible = true;
  77. }
  78. else
  79. {
  80. BtnEdit1->Visible = false;
  81. BtnDelete1->Visible = false;
  82. }
  83. BtnSearch->Enabled = true;
  84. CxList1->Enabled = true;
  85. cxGroupBox1->Enabled = false;
  86. }
  87. else
  88. {
  89. BtnSave1->Visible = true;
  90. BtnCancel1->Visible = true;
  91. BtnInsert1->Visible = false;
  92. BtnEdit1->Visible = false;
  93. BtnDelete1->Visible = false;
  94. BtnSearch->Enabled = false;
  95. CxList1->Enabled = false;
  96. cxGroupBox1->Enabled = true;
  97. }
  98. }
  99. //---------------------------------------------------------------------------
  100. void __fastcall TFRAMEFailHndl::SelListData1()
  101. {
  102. FCode->LoadHndlTypeDb();
  103. CMM_ClearGridTableView(TvList1);
  104. int nRow = 0;
  105. try
  106. {
  107. TvList1->BeginUpdate();
  108. FOR_STL(TFacilityHndlType *, pCode, FCode->FHndlLists)
  109. {
  110. nRow = m_pGDC1->AppendRecord();
  111. m_pGDC1->Values[nRow][MColumn01->Index] = "-";
  112. m_pGDC1->Values[nRow][MColumn02->Index] = pCode->FAIL_HNDL_CD;
  113. m_pGDC1->Values[nRow][MColumn03->Index] = pCode->FAIL_HNDL_CD_NM;
  114. m_pGDC1->Values[nRow][MColumn98->Index] = (int)pCode;
  115. }
  116. }
  117. __finally
  118. {
  119. TvList1->EndUpdate();
  120. TvList1->DataController->GotoFirst();
  121. TvList1->DataController->FocusedRecordIndex = 0;
  122. }
  123. }
  124. //---------------------------------------------------------------------------
  125. void __fastcall TFRAMEFailHndl::OnCloseQuery(bool &CanClose)
  126. {
  127. //SaveData();
  128. try {
  129. if (FCode) delete FCode;
  130. FCode = NULL;
  131. } catch(...) {}
  132. }
  133. //---------------------------------------------------------------------------
  134. void __fastcall TFRAMEFailHndl::DisplayListData1()
  135. {
  136. int ii;
  137. FormClear1();
  138. if (TvList1->ViewData->RecordCount <= 0) return;
  139. int nIndex = m_pGDC1->FocusedRecordIndex;
  140. if (nIndex < 0) return;
  141. int nMemPtr = m_pGDC1->Values[nIndex][MColumn98->Index];
  142. if (nMemPtr == 0) return;
  143. TFacilityHndlType *pCode = (TFacilityHndlType *)nMemPtr;
  144. try
  145. {
  146. EdId1->Text = pCode->FAIL_HNDL_CD;
  147. EdKName1->Text = pCode->FAIL_HNDL_CD_NM;
  148. }
  149. catch(Exception &e)
  150. {
  151. Application->MessageBox((e.Message + " - " +__FILE__+ " - " +__LINE__).c_str(), Caption.c_str(), MB_OK);
  152. }
  153. }
  154. //---------------------------------------------------------------------------
  155. void __fastcall TFRAMEFailHndl::TvList1FocusedRecordChanged(TcxCustomGridTableView *Sender,
  156. TcxCustomGridRecord *APrevFocusedRecord, TcxCustomGridRecord *AFocusedRecord,
  157. bool ANewItemRecordFocusingChanged)
  158. {
  159. DisplayListData1();
  160. //SelListData2();
  161. //ChangeButtonType2(1);
  162. }
  163. //---------------------------------------------------------------------------
  164. void __fastcall TFRAMEFailHndl::BtnCancel1Click(TObject *Sender)
  165. {
  166. TcxButton *pBtn = (TcxButton*)Sender;
  167. if (pBtn->Tag == 0)
  168. {
  169. ChangeButtonType1(1);
  170. m_enJob1 = enJobNone;
  171. DisplayListData1();
  172. }
  173. }
  174. //---------------------------------------------------------------------------
  175. void __fastcall TFRAMEFailHndl::BtnInsert1Click(TObject *Sender)
  176. {
  177. String sErrMsg = "";
  178. String sId = "";
  179. TcxButton *pBtn = (TcxButton*)Sender;
  180. if (pBtn->Tag == 0)
  181. {
  182. sId = InputBox("장애 처리 코드", "새로운 장애 처리 코드를 입력하세요.\r\n입력후에는 수정이 불가능합니다.", "최대7자리");
  183. sId.Trim();
  184. if (sId.IsEmpty() || AnsiString(sId).Length() > 5 || sId == "최대7자리")
  185. {
  186. Application->MessageBox(L"7자리를 초과하였거나 값이 없습니다.", L"장애 처리 코드 추가 오류", MB_OK|MB_ICONERROR|MB_APPLMODAL);
  187. return;
  188. }
  189. TFacilityHndlType *pCode = FCode->FHndlLists.Find(sId);
  190. if (pCode)
  191. {
  192. sErrMsg = "[" + sId + "] 코드는 이미 사용 중인 코드입니다.\r\n다른 코드를 입력하세요.";
  193. Application->MessageBox(sErrMsg.c_str(), L"장애 처리 코드 추가 오류", MB_OK|MB_ICONERROR|MB_APPLMODAL);
  194. return;
  195. }
  196. ChangeButtonType1(2);
  197. FormClear1();
  198. EdId1->Text = sId;
  199. m_enJob1 = enJobSave;
  200. }
  201. }
  202. //---------------------------------------------------------------------------
  203. void __fastcall TFRAMEFailHndl::BtnEdit1Click(TObject *Sender)
  204. {
  205. TcxButton *pBtn = (TcxButton*)Sender;
  206. if (pBtn->Tag == 0)
  207. {
  208. ChangeButtonType1(2);
  209. m_enJob1 = enJobEdit;
  210. }
  211. }
  212. //---------------------------------------------------------------------------
  213. void __fastcall TFRAMEFailHndl::BtnDelete1Click(TObject *Sender)
  214. {
  215. TcxButton *pBtn = (TcxButton*)Sender;
  216. if (pBtn->Tag == 0)
  217. {
  218. DeleteData1();
  219. }
  220. }
  221. //---------------------------------------------------------------------------
  222. void __fastcall TFRAMEFailHndl::DeleteData1()
  223. {
  224. TADOQuery *pADO = NULL;
  225. String sQry;
  226. String sMsgString;
  227. if (TvList1->ViewData->RecordCount <= 0) return;
  228. if (TvList1->DataController->FocusedRecordIndex < 0) return;
  229. if (!FCode)
  230. {
  231. return;
  232. }
  233. sMsgString = "장애 처리 코드 정보를 삭제 하시겠습니까?" ;
  234. if (Application->MessageBox(sMsgString.c_str(), L"코드 정보 삭제", MB_YESNO|MB_ICONQUESTION|MB_APPLMODAL) != IDYES) return;
  235. String sCode = EdId1->Text;
  236. try
  237. {
  238. try
  239. {
  240. pADO = new TADOQuery(NULL);
  241. pADO->Close();
  242. pADO->Connection = ITSDb_GetConnection();
  243. ITSDb_GetConnection()->BeginTrans();
  244. // 코드 삭제
  245. sQry = "DELETE FROM TB_FAIL_HNDL_TYPE \r\n"
  246. " WHERE FAIL_HNDL_CD = :p01 \r\n";
  247. ITSDb_SQLText(pADO, sQry);
  248. ITSDb_SQLBind(pADO, "p01", sCode);
  249. ITSDb_SQLExec(pADO);
  250. ITSDb_SQLExec(pADO);
  251. ITSDb_GetConnection()->CommitTrans();
  252. ItsCodeManager->FLists.Remove(sCode);
  253. Application->MessageBox(L"장애 처리 코드 정보를 삭제하였습니다.", L"코드 정보 삭제", MB_OK|MB_ICONINFORMATION|MB_APPLMODAL);
  254. }
  255. catch(EDatabaseError &E)
  256. {
  257. ITSDb_GetConnection()->RollbackTrans();
  258. ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
  259. DBERRORMSG(Caption, String(E.ClassName()), E.Message, sQry);
  260. throw Exception(String(E.ClassName()) + E.Message);
  261. }
  262. catch(Exception &e)
  263. {
  264. ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
  265. DBERRORMSG(Caption, String(e.ClassName()), e.Message, sQry);
  266. throw Exception(String(e.ClassName()) + e.Message);
  267. }
  268. }
  269. __finally
  270. {
  271. if (pADO)
  272. {
  273. pADO->Close();
  274. delete pADO;
  275. }
  276. }
  277. BtnSearchClick(NULL);
  278. }
  279. //---------------------------------------------------------------------------
  280. void __fastcall TFRAMEFailHndl::BtnSearchClick(TObject *Sender)
  281. {
  282. Application->ProcessMessages();
  283. TSqlCursor sqlCrs((TControl*)BtnSearch);
  284. FormClear1();
  285. RefreshData();
  286. CxList1->SetFocus();
  287. ChangeButtonType1(1);
  288. }
  289. //---------------------------------------------------------------------------
  290. void __fastcall TFRAMEFailHndl::RefreshData()
  291. {
  292. SelListData1();
  293. }
  294. //---------------------------------------------------------------------------
  295. void __fastcall TFRAMEFailHndl::BtnSave1Click(TObject *Sender)
  296. {
  297. bool bMemDel = true;
  298. String sMsgTitle, sMsgString;
  299. TcxButton *pBtn = (TcxButton*)Sender;
  300. if (pBtn->Tag == 0)
  301. {
  302. TFacilityHndlType *pCode = new TFacilityHndlType();
  303. try
  304. {
  305. pCode->FAIL_HNDL_CD = EdId1->Text.Trim();
  306. pCode->FAIL_HNDL_CD_NM = EdKName1->Text.Trim();
  307. if (m_enJob1 == enJobSave) sMsgTitle = "장애 처리 코드 정보 등록";
  308. sMsgTitle = "장애 처리 코드 정보 수정";
  309. if (MergeMainCode(pCode))
  310. {
  311. if (m_enJob1 == enJobSave)
  312. {
  313. FCode->FHndlLists.Push(pCode->FAIL_HNDL_CD, pCode);
  314. pCode->Completed = true;
  315. bMemDel = false;
  316. }
  317. else
  318. {
  319. #if 0
  320. FCode->FMSG_TYPE_CD = EdMsgCd->Text.Trim();
  321. FCode->FCMMN_CLSF_KOR_NM = EdKName1->Text.Trim();
  322. FCode->FCMMN_CLSF_ENGL_NM = EdEName1->Text.Trim();
  323. FCode->FUSE_SYST_CD = EdSysCd->Text.Trim();
  324. FCode->FRMRK = EdRemark1->Text.Trim();
  325. FCode->FUSE_YN = (CbUseYn1->ItemIndex == 0) ? "Y" : "N";
  326. #endif
  327. }
  328. RefreshData();
  329. CMM_SetGridFocusRow(CxList1, TvList1, pCode->FAIL_HNDL_CD, MColumn02->Index);
  330. DisplayListData1();
  331. ChangeButtonType1(1);
  332. Application->MessageBox(String(sMsgTitle + " 하였습니다.").c_str(), sMsgTitle.c_str(), MB_OK|MB_ICONINFORMATION|MB_APPLMODAL);
  333. }
  334. }
  335. __finally
  336. {
  337. if (bMemDel)
  338. {
  339. if (pCode) delete pCode;
  340. }
  341. }
  342. }
  343. }
  344. //---------------------------------------------------------------------------
  345. bool __fastcall TFRAMEFailHndl::MergeMainCode(TFacilityHndlType *ACode)
  346. {
  347. bool bResult = false;
  348. String sQry;
  349. TADOQuery *pADO = NULL;
  350. sQry = "MERGE INTO TB_FAIL_HNDL_TYPE L \r\n"
  351. "USING (SELECT :p01 AS FAIL_HNDL_CD, \r\n"
  352. " :p02 AS FAIL_HNDL_CD_NM \r\n"
  353. " FROM DUAL \r\n"
  354. " ) M \r\n"
  355. "ON (L.FAIL_HNDL_CD = M.FAIL_HNDL_CD) \r\n"
  356. "WHEN MATCHED THEN \r\n"
  357. " UPDATE SET L.FAIL_HNDL_CD_NM = M.FAIL_HNDL_CD_NM \r\n"
  358. "WHEN NOT MATCHED THEN \r\n"
  359. " INSERT (L.FAIL_HNDL_CD, \r\n"
  360. " L.FAIL_HNDL_CD_NM) \r\n"
  361. " VALUES (M.FAIL_HNDL_CD, \r\n"
  362. " M.FAIL_HNDL_CD_NM) \r\n";
  363. try
  364. {
  365. try
  366. {
  367. pADO = new TADOQuery(NULL);
  368. pADO->Close();
  369. pADO->Connection = ITSDb_GetConnection();
  370. ITSDb_SQLText(pADO, sQry);
  371. ITSDb_SQLBind(pADO, "p01", ACode->FAIL_HNDL_CD);
  372. ITSDb_SQLBind(pADO, "p02", ACode->FAIL_HNDL_CD_NM);
  373. ITSDb_GetConnection()->BeginTrans();
  374. ITSDb_SQLExec(pADO);
  375. ITSDb_GetConnection()->CommitTrans();
  376. bResult = true;
  377. }
  378. catch(EDatabaseError &E)
  379. {
  380. ITSDb_GetConnection()->RollbackTrans();
  381. ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
  382. DBERRORMSG(Caption, String(E.ClassName()), E.Message, sQry);
  383. throw Exception(String(E.ClassName()) + E.Message);
  384. }
  385. catch(Exception &e)
  386. {
  387. ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
  388. DBERRORMSG(Caption, String(e.ClassName()), e.Message, sQry);
  389. throw Exception(String(e.ClassName()) + e.Message);
  390. }
  391. }
  392. __finally
  393. {
  394. if (pADO)
  395. {
  396. pADO->Close();
  397. delete pADO;
  398. }
  399. }
  400. return bResult;
  401. }
  402. //---------------------------------------------------------------------------