IFM0050MF.cpp 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include "ITSSkinF.h"
  4. #include "ITSUtilF.h"
  5. #include "ITSDbF.h"
  6. #include "AppGlobalF.h"
  7. #include "ITS_OPLibF.h"
  8. #pragma hdrstop
  9. #include "IFM0050MF.h"
  10. //---------------------------------------------------------------------------
  11. #pragma package(smart_init)
  12. #pragma link "FRAME_FailHndlF"
  13. #pragma link "cxButtons"
  14. #pragma link "cxCalc"
  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 "cxDropDownEdit"
  23. #pragma link "cxEdit"
  24. #pragma link "cxFilter"
  25. #pragma link "cxGraphics"
  26. #pragma link "cxGrid"
  27. #pragma link "cxGridCustomTableView"
  28. #pragma link "cxGridCustomView"
  29. #pragma link "cxGridLevel"
  30. #pragma link "cxGridTableView"
  31. #pragma link "cxGroupBox"
  32. #pragma link "cxLookAndFeelPainters"
  33. #pragma link "cxLookAndFeels"
  34. #pragma link "cxMaskEdit"
  35. #pragma link "cxPC"
  36. #pragma link "cxPCdxBarPopupMenu"
  37. #pragma link "cxStyles"
  38. #pragma link "cxTextEdit"
  39. #pragma link "dxSkinBlack"
  40. #pragma link "dxSkinBlue"
  41. #pragma link "dxSkinsCore"
  42. #pragma link "dxSkinscxPCPainter"
  43. #pragma link "dxSkinMcSkin"
  44. #pragma resource "*.dfm"
  45. TIFM0050M *IFM0050M = NULL;
  46. //---------------------------------------------------------------------------
  47. __fastcall TIFM0050M::TIFM0050M(TComponent* Owner)
  48. : TForm(Owner)
  49. {
  50. ITSSkin_Load(this);
  51. CMM_LoadForm(g_sFormsDir, this);
  52. m_enJob1 = enJobNone;
  53. m_enJob2 = enJobNone;
  54. }
  55. //---------------------------------------------------------------------------
  56. void __fastcall TIFM0050M::CommClose()
  57. {
  58. try
  59. {
  60. CMM_SaveForm(g_sFormsDir, this);
  61. }
  62. catch(...)
  63. {
  64. }
  65. }
  66. //---------------------------------------------------------------------------
  67. void __fastcall TIFM0050M::FormShow(TObject *Sender)
  68. {
  69. Refresh();
  70. FormInit();
  71. TmrShow->Enabled = true;
  72. }
  73. //---------------------------------------------------------------------------
  74. void __fastcall TIFM0050M::FormInit()
  75. {
  76. m_pGDC1 = TvList1->DataController;
  77. m_pGDC2 = TvList2->DataController;
  78. TvList1->OptionsView->NoDataToDisplayInfoText = FrmLang->lblNoInfo->Caption;//"<장애 장비 유형 정보가 없습니다>";
  79. TvList2->OptionsView->NoDataToDisplayInfoText = FrmLang->lblNoInfo->Caption;//"<세부코드 정보가 없습니다>";
  80. EdId1->Enabled = false;
  81. EdId2->Enabled = false;
  82. FormClear1();
  83. FormClear2();
  84. ChangeButtonType1(1);
  85. ChangeButtonType2(1);
  86. }
  87. //---------------------------------------------------------------------------
  88. void __fastcall TIFM0050M::TmrShowTimer(TObject *Sender)
  89. {
  90. TmrShow->Enabled = false;
  91. BtnSearchClick((TObject*)BtnSearch);
  92. }
  93. //---------------------------------------------------------------------------
  94. void __fastcall TIFM0050M::BtnSearchClick(TObject *Sender)
  95. {
  96. Application->ProcessMessages();
  97. TSqlCursor sqlCrs((TControl*)BtnSearch);
  98. FormClear1();
  99. FormClear2();
  100. RefreshData();
  101. CxList1->SetFocus();
  102. ChangeButtonType1(1);
  103. ChangeButtonType2(1);
  104. }
  105. //---------------------------------------------------------------------------
  106. void __fastcall TIFM0050M::RefreshData()
  107. {
  108. SelListData1();
  109. }
  110. //---------------------------------------------------------------------------
  111. void __fastcall TIFM0050M::FormClear1()
  112. {
  113. m_enJob1 = enJobNone;
  114. EdId1->Clear();
  115. EdMsgCd->Clear();
  116. EdKName1->Clear();
  117. EdEName1->Clear();
  118. EdRemark1->Clear();
  119. EdSysCd->Clear();
  120. CbUseYn1->ItemIndex = 0;
  121. EdCmmnClsfCd->Clear();
  122. EdCmmnClsfCdNm->Clear();
  123. FCode = NULL;
  124. }
  125. //---------------------------------------------------------------------------
  126. void __fastcall TIFM0050M::FormClear2()
  127. {
  128. m_enJob2 = enJobNone;
  129. EdId2->Clear();
  130. EdCdAbbr->Clear();
  131. EdKName2->Clear();
  132. EdEName2->Clear();
  133. EdRemark2->Clear();
  134. EdAtrb1->Clear();
  135. EdAtrb2->Clear();
  136. CbUseYn2->ItemIndex = 0;
  137. FSubCode = NULL;
  138. }
  139. //---------------------------------------------------------------------------
  140. void __fastcall TIFM0050M::ChangeButtonType1(int nBtnType)
  141. {
  142. if (nBtnType == 1)
  143. {
  144. BtnSave1->Visible = false;
  145. BtnCancel1->Visible = false;
  146. BtnInsert1->Visible = true;
  147. if (TvList1->ViewData->RecordCount > 0)
  148. {
  149. BtnEdit1->Visible = true;
  150. BtnDelete1->Visible = true;
  151. }
  152. else
  153. {
  154. BtnEdit1->Visible = false;
  155. BtnDelete1->Visible = false;
  156. }
  157. BtnSearch->Enabled = true;
  158. CxList1->Enabled = true;
  159. cxGroupBox1->Enabled = false;
  160. }
  161. else
  162. {
  163. BtnSave1->Visible = true;
  164. BtnCancel1->Visible = true;
  165. BtnInsert1->Visible = false;
  166. BtnEdit1->Visible = false;
  167. BtnDelete1->Visible = false;
  168. BtnSearch->Enabled = false;
  169. CxList1->Enabled = false;
  170. cxGroupBox1->Enabled = true;
  171. }
  172. }
  173. //---------------------------------------------------------------------------
  174. void __fastcall TIFM0050M::ChangeButtonType2(int nBtnType)
  175. {
  176. if (nBtnType == 1)
  177. {
  178. BtnSave2->Visible = false;
  179. BtnCancel2->Visible = false;
  180. BtnInsert2->Visible = true;
  181. if (TvList2->ViewData->RecordCount > 0)
  182. {
  183. BtnEdit2->Visible = true;
  184. BtnDelete2->Visible = true;
  185. }
  186. else
  187. {
  188. BtnEdit2->Visible = false;
  189. BtnDelete2->Visible = false;
  190. }
  191. CxList2->Enabled = true;
  192. cxGroupBox2->Enabled = false;
  193. }
  194. else
  195. {
  196. BtnSave2->Visible = true;
  197. BtnCancel2->Visible = true;
  198. BtnInsert2->Visible = false;
  199. BtnEdit2->Visible = false;
  200. BtnDelete2->Visible = false;
  201. CxList2->Enabled = false;
  202. CxList2->Enabled = false;
  203. cxGroupBox2->Enabled = true;
  204. }
  205. }
  206. //---------------------------------------------------------------------------
  207. void __fastcall TIFM0050M::SelListData1()
  208. {
  209. CMM_ClearGridTableView(TvList1);
  210. CMM_ClearGridTableView(TvList2);
  211. int nRow = 0;
  212. try
  213. {
  214. TvList1->BeginUpdate();
  215. FOR_STL(TItsCode *, pCode, ItsCodeManager->FLists)
  216. {
  217. nRow = m_pGDC1->AppendRecord();
  218. m_pGDC1->Values[nRow][MColumn01->Index] = "-"; //편집모드
  219. m_pGDC1->Values[nRow][MColumn02->Index] = pCode->CMMN_CLSF_CD; //공통 분류 코드
  220. m_pGDC1->Values[nRow][MColumn03->Index] = pCode->MSG_TYPE_CD; //메시지 유형 코드
  221. m_pGDC1->Values[nRow][MColumn04->Index] = pCode->CMMN_CLSF_KOR_NM; //공통 분류 한글 명
  222. m_pGDC1->Values[nRow][MColumn05->Index] = pCode->CMMN_CLSF_ENGL_NM; //공통 분류 영문 명
  223. m_pGDC1->Values[nRow][MColumn06->Index] = pCode->USE_SYST_CD; //사용 시스템 코드
  224. m_pGDC1->Values[nRow][MColumn07->Index] = pCode->RMRK; //비고
  225. m_pGDC1->Values[nRow][MColumn08->Index] = pCode->USE_YN; //사용 여부
  226. m_pGDC1->Values[nRow][MColumn98->Index] = (int)pCode;
  227. }
  228. }
  229. __finally
  230. {
  231. TvList1->EndUpdate();
  232. TvList1->DataController->GotoFirst();
  233. TvList1->DataController->FocusedRecordIndex = 0;
  234. }
  235. }
  236. //---------------------------------------------------------------------------
  237. void __fastcall TIFM0050M::SelListData2()
  238. {
  239. CMM_ClearGridTableView(TvList2);
  240. if (TvList1->ViewData->RecordCount <= 0) return;
  241. int nIndex = m_pGDC1->FocusedRecordIndex;
  242. if (nIndex < 0) return;
  243. int nMemPtr = m_pGDC1->Values[nIndex][MColumn98->Index];
  244. if (nMemPtr == 0) return;
  245. TItsCode *pCode = (TItsCode *)nMemPtr;
  246. int nRow = 0;
  247. try
  248. {
  249. TvList2->BeginUpdate();
  250. FOR_STL(TItsSubCode *, pSubCode, pCode->FSubLists)
  251. {
  252. nRow = m_pGDC2->AppendRecord();
  253. m_pGDC2->Values[nRow][SColumn01->Index] = "-"; //편집모드
  254. m_pGDC2->Values[nRow][SColumn02->Index] = pSubCode->CMMN_CD;
  255. m_pGDC2->Values[nRow][SColumn03->Index] = pSubCode->CMMN_CD_KOR_NM;
  256. m_pGDC2->Values[nRow][SColumn04->Index] = pSubCode->CMMN_CD_ENGL_NM;
  257. m_pGDC2->Values[nRow][SColumn05->Index] = pSubCode->CMMN_CD_ABBR;
  258. m_pGDC2->Values[nRow][SColumn06->Index] = pSubCode->RMRK;
  259. m_pGDC2->Values[nRow][SColumn07->Index] = pSubCode->ATRB1;
  260. m_pGDC2->Values[nRow][SColumn08->Index] = pSubCode->ATRB2;
  261. m_pGDC2->Values[nRow][SColumn09->Index] = pSubCode->USE_YN;
  262. m_pGDC2->Values[nRow][SColumn98->Index] = (int)pSubCode;
  263. }
  264. }
  265. __finally
  266. {
  267. TvList2->EndUpdate();
  268. TvList2->DataController->GotoFirst();
  269. TvList2->DataController->FocusedRecordIndex = 0;
  270. }
  271. }
  272. //---------------------------------------------------------------------------
  273. void __fastcall TIFM0050M::BtnCloseClick(TObject *Sender)
  274. {
  275. Close();
  276. }
  277. //---------------------------------------------------------------------------
  278. void __fastcall TIFM0050M::BtnSaveClick(TObject *Sender)
  279. {
  280. bool bMemDel = true;
  281. String sMsgTitle, sMsgString;
  282. TcxButton *pBtn = (TcxButton*)Sender;
  283. if (pBtn->Tag == 0)
  284. {
  285. TItsCode *pCode = new TItsCode();
  286. try
  287. {
  288. pCode->CMMN_CLSF_CD = EdId1->Text.Trim();
  289. pCode->MSG_TYPE_CD = EdMsgCd->Text.Trim();
  290. pCode->CMMN_CLSF_KOR_NM = EdKName1->Text.Trim();
  291. pCode->CMMN_CLSF_ENGL_NM = EdEName1->Text.Trim();
  292. pCode->USE_SYST_CD = EdSysCd->Text.Trim();
  293. pCode->RMRK = EdRemark1->Text.Trim();
  294. pCode->USE_YN = (CbUseYn1->ItemIndex == 0) ? "Y" : "N";
  295. if (m_enJob1 == enJobSave) sMsgTitle = "대표코드 정보 등록";
  296. sMsgTitle = "대표코드 정보 수정";
  297. if (MergeCmmnClsfCd(pCode))
  298. {
  299. if (m_enJob1 == enJobSave)
  300. {
  301. ItsCodeManager->FLists.Push(pCode->CMMN_CLSF_CD, pCode);
  302. pCode->Completed = true;
  303. bMemDel = false;
  304. }
  305. else
  306. {
  307. //FCode->CMMN_CLSF_CD = EdId1->Text.Trim();
  308. FCode->MSG_TYPE_CD = EdMsgCd->Text.Trim();
  309. FCode->CMMN_CLSF_KOR_NM = EdKName1->Text.Trim();
  310. FCode->CMMN_CLSF_ENGL_NM = EdEName1->Text.Trim();
  311. FCode->USE_SYST_CD = EdSysCd->Text.Trim();
  312. FCode->RMRK = EdRemark1->Text.Trim();
  313. FCode->USE_YN = (CbUseYn1->ItemIndex == 0) ? "Y" : "N";
  314. }
  315. RefreshData();
  316. CMM_SetGridFocusRow(CxList1, TvList1, pCode->CMMN_CLSF_CD, MColumn02->Index);
  317. DisplayListData1();
  318. ChangeButtonType1(1);
  319. Application->MessageBox(String(sMsgTitle + " 하였습니다.").c_str(), sMsgTitle.c_str(), MB_OK|MB_ICONINFORMATION|MB_APPLMODAL);
  320. }
  321. }
  322. __finally
  323. {
  324. if (bMemDel)
  325. {
  326. if (pCode) delete pCode;
  327. }
  328. }
  329. }
  330. else
  331. if (pBtn->Tag == 1)
  332. {
  333. TItsSubCode *pSubCode = new TItsSubCode();
  334. try
  335. {
  336. pSubCode->CMMN_CD = EdId2->Text.Trim();
  337. pSubCode->CMMN_CLSF_CD = FCode->CMMN_CLSF_CD;
  338. pSubCode->CMMN_CD_KOR_NM = EdKName2->Text.Trim();
  339. pSubCode->CMMN_CD_ENGL_NM = EdEName2->Text.Trim();
  340. pSubCode->CMMN_CD_ABBR = EdCdAbbr->Text.Trim();
  341. pSubCode->RMRK = EdRemark2->Text.Trim();
  342. pSubCode->ATRB1 = EdAtrb1->Text.Trim();
  343. pSubCode->ATRB2 = EdAtrb2->Text.Trim();
  344. pSubCode->USE_YN = (CbUseYn2->ItemIndex == 0) ? "Y" : "N";
  345. if (m_enJob2 == enJobSave) sMsgTitle = "세부코드 정보 등록";
  346. else sMsgTitle = "세부코드 정보 수정";
  347. if (MergeCmmnCd(pSubCode))
  348. {
  349. if (m_enJob2 == enJobSave)
  350. {
  351. FCode->FSubLists.Push(pSubCode->CMMN_CD, pSubCode);
  352. pSubCode->Completed = true;
  353. bMemDel = false;
  354. }
  355. else
  356. {
  357. //FSubCode->CMMN_CD = EdId2->Text.Trim();
  358. //FSubCode->CMMN_CLSF_CD = FCode->CMMN_CLSF_CD;
  359. FSubCode->CMMN_CD_KOR_NM = EdKName2->Text.Trim();
  360. FSubCode->CMMN_CD_ENGL_NM = EdEName2->Text.Trim();
  361. FSubCode->CMMN_CD_ABBR = EdCdAbbr->Text.Trim();
  362. FSubCode->RMRK = EdRemark2->Text.Trim();
  363. FSubCode->ATRB1 = EdAtrb1->Text.Trim();
  364. FSubCode->ATRB2 = EdAtrb2->Text.Trim();
  365. FSubCode->USE_YN = (CbUseYn2->ItemIndex == 0) ? "Y" : "N";
  366. }
  367. SelListData2();
  368. CMM_SetGridFocusRow(CxList2, TvList2, pSubCode->CMMN_CD, SColumn02->Index);
  369. DisplayListData2();
  370. ChangeButtonType2(1);
  371. Application->MessageBox(String(sMsgTitle + " 하였습니다.").c_str(), sMsgTitle.c_str(), MB_OK|MB_ICONINFORMATION|MB_APPLMODAL);
  372. }
  373. }
  374. __finally
  375. {
  376. if (bMemDel)
  377. {
  378. if (pSubCode) delete pSubCode;
  379. }
  380. }
  381. }
  382. }
  383. //---------------------------------------------------------------------------
  384. bool __fastcall TIFM0050M::MergeCmmnClsfCd(TItsCode *pCode)
  385. {
  386. bool bResult = false;
  387. String sQry;
  388. TADOQuery *pADO = NULL;
  389. sQry = "MERGE INTO TB_CMMN_CLSF_CD L \r\n"
  390. "USING (SELECT :p01 AS CMMN_CLSF_CD, \r\n"
  391. " :p02 AS MSG_TYPE_CD, \r\n"
  392. " :p03 AS CMMN_CLSF_KOR_NM, \r\n"
  393. " :p04 AS CMMN_CLSF_ENGL_NM, \r\n"
  394. " :p05 AS USE_SYST_CD, \r\n"
  395. " :p06 AS RMRK, \r\n"
  396. " :p07 AS USE_YN \r\n"
  397. " FROM DUAL \r\n"
  398. " ) M \r\n"
  399. "ON (L.CMMN_CLSF_CD = M.CMMN_CLSF_CD) \r\n"
  400. "WHEN MATCHED THEN \r\n"
  401. " UPDATE SET L.MSG_TYPE_CD = M.MSG_TYPE_CD, \r\n"
  402. " L.CMMN_CLSF_KOR_NM = M.CMMN_CLSF_KOR_NM, \r\n"
  403. " L.CMMN_CLSF_ENGL_NM = M.CMMN_CLSF_ENGL_NM, \r\n"
  404. " L.USE_SYST_CD = M.USE_SYST_CD, \r\n"
  405. " L.RMRK = M.RMRK, \r\n"
  406. " L.USE_YN = M.USE_YN \r\n"
  407. "WHEN NOT MATCHED THEN \r\n"
  408. " INSERT (L.CMMN_CLSF_CD, \r\n"
  409. " L.MSG_TYPE_CD, \r\n"
  410. " L.CMMN_CLSF_KOR_NM, \r\n"
  411. " L.CMMN_CLSF_ENGL_NM, \r\n"
  412. " L.USE_SYST_CD, \r\n"
  413. " L.RMRK, \r\n"
  414. " L.USE_YN) \r\n"
  415. " VALUES (M.CMMN_CLSF_CD, \r\n"
  416. " M.MSG_TYPE_CD, \r\n"
  417. " M.CMMN_CLSF_KOR_NM, \r\n"
  418. " M.CMMN_CLSF_ENGL_NM, \r\n"
  419. " M.USE_SYST_CD, \r\n"
  420. " M.RMRK, \r\n"
  421. " M.USE_YN) \r\n";
  422. try
  423. {
  424. try
  425. {
  426. pADO = new TADOQuery(NULL);
  427. pADO->Close();
  428. pADO->Connection = ITSDb_GetConnection();
  429. ITSDb_SQLText(pADO, sQry);
  430. ITSDb_SQLBind(pADO, "p01", pCode->CMMN_CLSF_CD);
  431. ITSDb_SQLBind(pADO, "p02", pCode->MSG_TYPE_CD);
  432. ITSDb_SQLBind(pADO, "p03", pCode->CMMN_CLSF_KOR_NM);
  433. ITSDb_SQLBind(pADO, "p04", pCode->CMMN_CLSF_ENGL_NM);
  434. ITSDb_SQLBind(pADO, "p05", pCode->USE_SYST_CD);
  435. ITSDb_SQLBind(pADO, "p06", pCode->RMRK);
  436. ITSDb_SQLBind(pADO, "p07", pCode->USE_YN);
  437. ITSDb_GetConnection()->BeginTrans();
  438. ITSDb_SQLExec(pADO);
  439. ITSDb_GetConnection()->CommitTrans();
  440. bResult = true;
  441. }
  442. catch(EDatabaseError &E)
  443. {
  444. ITSDb_GetConnection()->RollbackTrans();
  445. ShowMessage(String(E.ClassName()) + E.Message);
  446. }
  447. catch(Exception &exception)
  448. {
  449. ITSDb_GetConnection()->RollbackTrans();
  450. ShowMessage(String(exception.ClassName()) + exception.Message);
  451. }
  452. catch(...)
  453. {
  454. ITSDb_GetConnection()->RollbackTrans();
  455. ShowMessage(FrmLang->lblDbErr->Caption);//"데이터 저장 중에 알수없는 DB 오류가 발생하였습니다.");
  456. }
  457. }
  458. __finally
  459. {
  460. if (pADO)
  461. {
  462. pADO->Close();
  463. delete pADO;
  464. }
  465. }
  466. return bResult;
  467. }
  468. //---------------------------------------------------------------------------
  469. bool __fastcall TIFM0050M::MergeCmmnCd(TItsSubCode *pSubCode)
  470. {
  471. bool bResult = false;
  472. String sQry;
  473. TADOQuery *pADO = NULL;
  474. sQry = "MERGE INTO TB_CMMN_CD L \r\n"
  475. "USING (SELECT :p01 AS CMMN_CD, \r\n"
  476. " :p02 AS CMMN_CLSF_CD, \r\n"
  477. " :p03 AS CMMN_CD_KOR_NM, \r\n"
  478. " :p04 AS CMMN_CD_ENGL_NM, \r\n"
  479. " :p05 AS CMMN_CD_ABBR, \r\n"
  480. " :p06 AS RMRK, \r\n"
  481. " :p07 AS ATRB1, \r\n"
  482. " :p08 AS ATRB2, \r\n"
  483. " :p09 AS USE_YN \r\n"
  484. " FROM DUAL \r\n"
  485. " ) M \r\n"
  486. "ON ( L.CMMN_CD = M.CMMN_CD \r\n"
  487. " AND L.CMMN_CLSF_CD = M.CMMN_CLSF_CD) \r\n"
  488. "WHEN MATCHED THEN \r\n"
  489. " UPDATE SET L.CMMN_CD_KOR_NM = M.CMMN_CD_KOR_NM, \r\n"
  490. " L.CMMN_CD_ENGL_NM = M.CMMN_CD_ENGL_NM, \r\n"
  491. " L.CMMN_CD_ABBR = M.CMMN_CD_ABBR, \r\n"
  492. " L.RMRK = M.RMRK, \r\n"
  493. " L.ATRB1 = M.ATRB1, \r\n"
  494. " L.ATRB2 = M.ATRB2, \r\n"
  495. " L.USE_YN = M.USE_YN \r\n"
  496. "WHEN NOT MATCHED THEN \r\n"
  497. " INSERT (L.CMMN_CD, \r\n"
  498. " L.CMMN_CLSF_CD, \r\n"
  499. " L.CMMN_CD_KOR_NM, \r\n"
  500. " L.CMMN_CD_ENGL_NM, \r\n"
  501. " L.CMMN_CD_ABBR, \r\n"
  502. " L.RMRK, \r\n"
  503. " L.ATRB1, \r\n"
  504. " L.ATRB2, \r\n"
  505. " L.USE_YN) \r\n"
  506. " VALUES (M.CMMN_CD, \r\n"
  507. " M.CMMN_CLSF_CD, \r\n"
  508. " M.CMMN_CD_KOR_NM, \r\n"
  509. " M.CMMN_CD_ENGL_NM, \r\n"
  510. " M.CMMN_CD_ABBR, \r\n"
  511. " M.RMRK, \r\n"
  512. " M.ATRB1, \r\n"
  513. " M.ATRB2, \r\n"
  514. " M.USE_YN) \r\n";
  515. try
  516. {
  517. try
  518. {
  519. pADO = new TADOQuery(NULL);
  520. pADO->Close();
  521. pADO->Connection = ITSDb_GetConnection();
  522. ITSDb_SQLText(pADO, sQry);
  523. ITSDb_SQLBind(pADO, "p01", pSubCode->CMMN_CD);
  524. ITSDb_SQLBind(pADO, "p02", pSubCode->CMMN_CLSF_CD);
  525. ITSDb_SQLBind(pADO, "p03", pSubCode->CMMN_CD_KOR_NM);
  526. ITSDb_SQLBind(pADO, "p04", pSubCode->CMMN_CD_ENGL_NM);
  527. ITSDb_SQLBind(pADO, "p05", pSubCode->CMMN_CD_ABBR);
  528. ITSDb_SQLBind(pADO, "p06", pSubCode->RMRK);
  529. ITSDb_SQLBind(pADO, "p07", pSubCode->ATRB1);
  530. ITSDb_SQLBind(pADO, "p08", pSubCode->ATRB2);
  531. ITSDb_SQLBind(pADO, "p09", pSubCode->USE_YN);
  532. ITSDb_GetConnection()->BeginTrans();
  533. ITSDb_SQLExec(pADO);
  534. ITSDb_GetConnection()->CommitTrans();
  535. bResult = true;
  536. }
  537. catch(EDatabaseError &E)
  538. {
  539. ITSDb_GetConnection()->RollbackTrans();
  540. ShowMessage(String(E.ClassName()) + E.Message);
  541. }
  542. catch(Exception &exception)
  543. {
  544. ITSDb_GetConnection()->RollbackTrans();
  545. ShowMessage(String(exception.ClassName()) + exception.Message);
  546. }
  547. catch(...)
  548. {
  549. ITSDb_GetConnection()->RollbackTrans();
  550. ShowMessage(FrmLang->lblDbErr->Caption);//"데이터 저장 중에 알수없는 DB 오류가 발생하였습니다.");
  551. }
  552. }
  553. __finally
  554. {
  555. if (pADO)
  556. {
  557. pADO->Close();
  558. delete pADO;
  559. }
  560. }
  561. return bResult;
  562. }
  563. //---------------------------------------------------------------------------
  564. void __fastcall TIFM0050M::BtnCancelClick(TObject *Sender)
  565. {
  566. TcxButton *pBtn = (TcxButton*)Sender;
  567. if (pBtn->Tag == 0)
  568. {
  569. ChangeButtonType1(1);
  570. m_enJob1 = enJobNone;
  571. DisplayListData1();
  572. }
  573. else
  574. if (pBtn->Tag == 1)
  575. {
  576. ChangeButtonType2(1);
  577. m_enJob2 = enJobNone;
  578. DisplayListData2();
  579. }
  580. }
  581. //---------------------------------------------------------------------------
  582. void __fastcall TIFM0050M::BtnInsertClick(TObject *Sender)
  583. {
  584. String sErrMsg = "";
  585. String sId = "";
  586. TcxButton *pBtn = (TcxButton*)Sender;
  587. if (pBtn->Tag == 0)
  588. {
  589. sId = InputBox("대표코드", "새로운 대표코드를 입력하세요.\r\n입력후에는 수정이 불가능합니다.", "최대5자리");
  590. sId.Trim();
  591. if (sId.IsEmpty() || AnsiString(sId).Length() > 5 || sId == "최대5자리")
  592. {
  593. Application->MessageBox(L"5자리를 초과하였거나 값이 없습니다.", L"대표코드 추가 오류", MB_OK|MB_ICONERROR|MB_APPLMODAL);
  594. return;
  595. }
  596. TItsCode *pCode = ItsCodeManager->FLists.Find(sId);
  597. if (pCode)
  598. {
  599. sErrMsg = "[" + sId + "] 코드는 이미 사용 중인 코드입니다.\r\n다른 코드를 입력하세요.";
  600. Application->MessageBox(sErrMsg.c_str(), L"대표코드 추가 오류", MB_OK|MB_ICONERROR|MB_APPLMODAL);
  601. return;
  602. }
  603. ChangeButtonType1(2);
  604. FormClear1();
  605. FormClear2();
  606. EdId1->Text = sId;
  607. m_enJob1 = enJobSave;
  608. }
  609. else
  610. if (pBtn->Tag == 1)
  611. {
  612. if (m_pGDC1->FocusedRecordIndex < 0)
  613. {
  614. Application->MessageBox(L"대표코드를 선택후 사용해주십시오.", L"세부코드 추가 오류", MB_OK|MB_ICONERROR|MB_APPLMODAL);
  615. return;
  616. }
  617. if (!FCode)
  618. {
  619. Application->MessageBox(L"대표코드를 선택후 사용해주십시오.", L"세부코드 추가 오류", MB_OK|MB_ICONERROR|MB_APPLMODAL);
  620. return;
  621. }
  622. sId = InputBox("세부코드", "새로운 세부코드를 입력하세요.\r\n입력후에는 수정이 불가능합니다.", "최대7자리");
  623. sId.Trim();
  624. if (sId.IsEmpty() || AnsiString(sId).Length() > 5 || sId == "최대7자리")
  625. {
  626. Application->MessageBox(L"7자리를 초과하였거나 값이 없습니다.", L"세부코드 추가 오류", MB_OK|MB_ICONERROR|MB_APPLMODAL);
  627. return;
  628. }
  629. TItsSubCode *pSubCode = FCode->FSubLists.Find(sId);
  630. if (pSubCode)
  631. {
  632. sErrMsg = "[" + sId + "] 코드는 이미 사용 중인 코드입니다.\r\n다른 코드를 입력하세요.";
  633. Application->MessageBox(sErrMsg.c_str(), L"세부코드 추가 오류", MB_OK|MB_ICONERROR|MB_APPLMODAL);
  634. return;
  635. }
  636. ChangeButtonType2(2);
  637. FormClear2();
  638. EdId2->Text = sId;
  639. m_enJob2 = enJobSave;
  640. }
  641. }
  642. //---------------------------------------------------------------------------
  643. void __fastcall TIFM0050M::BtnEditClick(TObject *Sender)
  644. {
  645. TcxButton *pBtn = (TcxButton*)Sender;
  646. if (pBtn->Tag == 0)
  647. {
  648. ChangeButtonType1(2);
  649. m_enJob1 = enJobEdit;
  650. }
  651. else
  652. if (pBtn->Tag == 1)
  653. {
  654. ChangeButtonType2(2);
  655. m_enJob2 = enJobEdit;
  656. }
  657. }
  658. //---------------------------------------------------------------------------
  659. void __fastcall TIFM0050M::BtnDeleteClick(TObject *Sender)
  660. {
  661. TcxButton *pBtn = (TcxButton*)Sender;
  662. if (pBtn->Tag == 0)
  663. {
  664. DeleteData1();
  665. }
  666. else
  667. if (pBtn->Tag == 1)
  668. {
  669. DeleteData2();
  670. }
  671. }
  672. //---------------------------------------------------------------------------
  673. void __fastcall TIFM0050M::DeleteData1()
  674. {
  675. TADOQuery *pADO = NULL;
  676. String sQry;
  677. String sMsgString;
  678. if (TvList1->ViewData->RecordCount <= 0) return;
  679. if (TvList1->DataController->FocusedRecordIndex < 0) return;
  680. if (!FCode)
  681. {
  682. return;
  683. }
  684. sMsgString = "대표코드 정보를 삭제 하시겠습니까?\r\n세부코드 정보도 함께 삭제 됩니다." ;
  685. if (Application->MessageBox(sMsgString.c_str(), L"코드 정보 삭제", MB_YESNO|MB_ICONQUESTION|MB_APPLMODAL) != IDYES) return;
  686. String sCode = FCode->CMMN_CLSF_CD;
  687. try
  688. {
  689. try
  690. {
  691. pADO = new TADOQuery(NULL);
  692. pADO->Close();
  693. pADO->Connection = ITSDb_GetConnection();
  694. ITSDb_GetConnection()->BeginTrans();
  695. // 세부코드 삭제
  696. sQry = "DELETE FROM TB_CMMN_CD \r\n"
  697. " WHERE CMMN_CLSF_CD = :p01 \r\n";
  698. ITSDb_SQLText(pADO, sQry);
  699. ITSDb_SQLBind(pADO, "p01", sCode);
  700. ITSDb_SQLExec(pADO);
  701. // 대분류 코드 삭제
  702. sQry = "DELETE FROM TB_CMMN_CLSF_CD \r\n"
  703. " WHERE CMMN_CLSF_CD = :p01 \r\n";
  704. ITSDb_SQLText(pADO, sQry);
  705. ITSDb_SQLBind(pADO, "p01", sCode);
  706. ITSDb_SQLExec(pADO);
  707. ITSDb_GetConnection()->CommitTrans();
  708. ItsCodeManager->FLists.Remove(sCode);
  709. Application->MessageBox(L"대표코드와 세부코드 정보를 삭제하였습니다.", L"코드 정보 삭제", MB_OK|MB_ICONINFORMATION|MB_APPLMODAL);
  710. }
  711. catch(EDatabaseError &E)
  712. {
  713. ITSDb_GetConnection()->RollbackTrans();
  714. ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
  715. DBERRORMSG(Caption, String(E.ClassName()), E.Message, sQry);
  716. throw Exception(String(E.ClassName()) + E.Message);
  717. }
  718. catch(Exception &e)
  719. {
  720. ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
  721. DBERRORMSG(Caption, String(e.ClassName()), e.Message, sQry);
  722. throw Exception(String(e.ClassName()) + e.Message);
  723. }
  724. }
  725. __finally
  726. {
  727. if (pADO)
  728. {
  729. pADO->Close();
  730. delete pADO;
  731. }
  732. }
  733. BtnSearchClick(NULL);
  734. }
  735. //---------------------------------------------------------------------------
  736. void __fastcall TIFM0050M::DeleteData2()
  737. {
  738. TADOQuery *pADO = NULL;
  739. String sQry;
  740. String sMsgString;
  741. if (TvList2->ViewData->RecordCount <= 0) return;
  742. if (TvList2->DataController->FocusedRecordIndex < 0) return;
  743. if (!FCode || !FSubCode)
  744. {
  745. return;
  746. }
  747. sMsgString = "세부코드 정보를 삭제 하시겠습니까?" ;
  748. if (Application->MessageBox(sMsgString.c_str(), L"세부코드 정보 삭제", MB_YESNO|MB_ICONQUESTION|MB_APPLMODAL) != IDYES) return;
  749. String sSubCode = FSubCode->CMMN_CD;
  750. String sCode = FSubCode->CMMN_CLSF_CD;
  751. try
  752. {
  753. try
  754. {
  755. pADO = new TADOQuery(NULL);
  756. pADO->Close();
  757. pADO->Connection = ITSDb_GetConnection();
  758. // 세부코드 삭제
  759. sQry = "DELETE FROM TB_CMMN_CD \r\n"
  760. " WHERE CMMN_CD = :p01 \r\n"
  761. " AND CMMN_CLSF_CD = :p02 \r\n";
  762. ITSDb_SQLText(pADO, sQry);
  763. ITSDb_SQLBind(pADO, "p01", sSubCode);
  764. ITSDb_SQLBind(pADO, "p02", sCode);
  765. ITSDb_SQLExec(pADO);
  766. ITSDb_GetConnection()->CommitTrans();
  767. ITSDb_GetConnection()->BeginTrans();
  768. FCode->FSubLists.Remove(sSubCode);
  769. Application->MessageBox(L"세부코드 정보를 삭제하였습니다.", L"세부코드 정보 삭제", MB_OK|MB_ICONINFORMATION|MB_APPLMODAL);
  770. }
  771. catch(EDatabaseError &E)
  772. {
  773. ITSDb_GetConnection()->RollbackTrans();
  774. ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
  775. DBERRORMSG(Caption, String(E.ClassName()), E.Message, sQry);
  776. throw Exception(String(E.ClassName()) + E.Message);
  777. }
  778. catch(Exception &e)
  779. {
  780. ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
  781. DBERRORMSG(Caption, String(e.ClassName()), e.Message, sQry);
  782. throw Exception(String(e.ClassName()) + e.Message);
  783. }
  784. }
  785. __finally
  786. {
  787. if (pADO)
  788. {
  789. pADO->Close();
  790. delete pADO;
  791. }
  792. }
  793. SelListData2();
  794. DisplayListData2();
  795. ChangeButtonType2(1);
  796. }
  797. //---------------------------------------------------------------------------
  798. void __fastcall TIFM0050M::TvList1FocusedRecordChanged(TcxCustomGridTableView *Sender, TcxCustomGridRecord *APrevFocusedRecord,
  799. TcxCustomGridRecord *AFocusedRecord, bool ANewItemRecordFocusingChanged)
  800. {
  801. DisplayListData1();
  802. SelListData2();
  803. ChangeButtonType2(1);
  804. }
  805. //---------------------------------------------------------------------------
  806. void __fastcall TIFM0050M::TvList2FocusedRecordChanged(TcxCustomGridTableView *Sender, TcxCustomGridRecord *APrevFocusedRecord,
  807. TcxCustomGridRecord *AFocusedRecord, bool ANewItemRecordFocusingChanged)
  808. {
  809. DisplayListData2();
  810. }
  811. //---------------------------------------------------------------------------
  812. void __fastcall TIFM0050M::DisplayListData1()
  813. {
  814. int ii;
  815. FormClear1();
  816. if (TvList1->ViewData->RecordCount <= 0) return;
  817. int nIndex = m_pGDC1->FocusedRecordIndex;
  818. if (nIndex < 0) return;
  819. int nMemPtr = m_pGDC1->Values[nIndex][MColumn98->Index];
  820. if (nMemPtr == 0) return;
  821. FCode = (TItsCode *)nMemPtr;
  822. try
  823. {
  824. EdId1->Text = FCode->CMMN_CLSF_CD;
  825. EdMsgCd->Text = FCode->MSG_TYPE_CD;
  826. EdKName1->Text = FCode->CMMN_CLSF_KOR_NM;
  827. EdEName1->Text = FCode->CMMN_CLSF_ENGL_NM;
  828. EdRemark1->Text = FCode->RMRK;
  829. EdSysCd->Text = FCode->USE_SYST_CD;
  830. CbUseYn1->ItemIndex = FCode->USE_YN == "Y" ? 0 : 1;
  831. EdCmmnClsfCd->Text = FCode->CMMN_CLSF_CD;
  832. EdCmmnClsfCdNm->Text= FCode->CMMN_CLSF_KOR_NM;
  833. }
  834. catch(Exception &e)
  835. {
  836. Application->MessageBox((e.Message + " - " +__FILE__+ " - " +__LINE__).c_str(), Caption.c_str(), MB_OK);
  837. }
  838. }
  839. //---------------------------------------------------------------------------
  840. void __fastcall TIFM0050M::DisplayListData2()
  841. {
  842. FormClear2();
  843. if (TvList2->ViewData->RecordCount <= 0) return;
  844. int nIndex = m_pGDC2->FocusedRecordIndex;
  845. if (nIndex < 0) return;
  846. int nMemPtr = m_pGDC2->Values[nIndex][SColumn98->Index];
  847. if (nMemPtr == 0) return;
  848. FSubCode = (TItsSubCode *)nMemPtr;
  849. try
  850. {
  851. EdId2->Text = FSubCode->CMMN_CD;
  852. EdCdAbbr->Text = FSubCode->CMMN_CD_ABBR;
  853. EdKName2->Text = FSubCode->CMMN_CD_KOR_NM;
  854. EdEName2->Text = FSubCode->CMMN_CD_ENGL_NM;
  855. EdRemark2->Text = FSubCode->RMRK;
  856. EdAtrb1->Text = FSubCode->ATRB1;
  857. EdAtrb2->Text = FSubCode->ATRB2;
  858. CbUseYn2->ItemIndex = FSubCode->USE_YN == "Y" ? 0 : 1;
  859. }
  860. catch(Exception &e)
  861. {
  862. Application->MessageBox((e.Message + " - " +__FILE__+ " - " +__LINE__).c_str(), Caption.c_str(), MB_OK);
  863. }
  864. }
  865. //---------------------------------------------------------------------------
  866. void __fastcall TIFM0050M::FormClose(TObject *Sender, TCloseAction &Action)
  867. {
  868. CommClose();
  869. IFM0050M = NULL;
  870. Action = caFree;
  871. }
  872. //---------------------------------------------------------------------------