IDB0080MF.cpp 37 KB

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