FRAME_FailHndlF.cpp 14 KB

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