FRAME_FailHndlF.cpp 14 KB

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