IFM0050MF.cpp 33 KB

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