IDB0130MF.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  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. #include "ITS_OPLibF.h"
  9. #pragma hdrstop
  10. #include "IDB0130MF.h"
  11. //---------------------------------------------------------------------------
  12. #pragma package(smart_init)
  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 "cxLabel"
  32. #pragma link "cxLookAndFeelPainters"
  33. #pragma link "cxLookAndFeels"
  34. #pragma link "cxStyles"
  35. #pragma link "cxTextEdit"
  36. #pragma link "dxSkinBlack"
  37. #pragma link "dxSkinBlue"
  38. #pragma link "dxSkinsCore"
  39. #pragma link "dxSkinscxPCPainter"
  40. #pragma link "dxSkinMcSkin"
  41. #pragma resource "*.dfm"
  42. TIDB0130M *IDB0130M = NULL;
  43. //---------------------------------------------------------------------------
  44. __fastcall TIDB0130M::TIDB0130M(TComponent* Owner)
  45. : TForm(Owner)
  46. {
  47. LangTrans->Translate(this, ITSDb_GetConnection());
  48. ITSSkin_Load(this);
  49. CMM_LoadForm(g_sFormsDir, this);
  50. FTitle = Caption;//"운영자그룹 메뉴관리";
  51. FDbUpdate = false;
  52. }
  53. //---------------------------------------------------------------------------
  54. void __fastcall TIDB0130M::CommClose()
  55. {
  56. try
  57. {
  58. CMM_SaveForm(g_sFormsDir, this);
  59. }
  60. catch(...)
  61. {
  62. }
  63. }
  64. //---------------------------------------------------------------------------
  65. void __fastcall TIDB0130M::FormShow(TObject *Sender)
  66. {
  67. Refresh();
  68. FormInit();
  69. TmrShow->Enabled = true;
  70. }
  71. //---------------------------------------------------------------------------
  72. void __fastcall TIDB0130M::FormInit()
  73. {
  74. m_pGDC = TvList->DataController;
  75. TvList->OptionsView->NoDataToDisplayInfoText = FrmLang->lblNoInfo->Caption;//"<현재 등록된 운영자그룹 메뉴 정보가 없습니다>";
  76. InitColumnProperties();
  77. }
  78. //---------------------------------------------------------------------------
  79. void __fastcall TIDB0130M::InitColumnProperties()
  80. {
  81. FInitCombo1 = "";
  82. FInitCombo2 = "";
  83. try
  84. {
  85. try
  86. {
  87. //메뉴권한
  88. TcxComboBoxProperties *pcxColumn12 = (TcxComboBoxProperties *)Column12->Properties;
  89. pcxColumn12->Items->Clear();
  90. FInitCombo1 = lblY->Caption;//"[Y] 권한있음";
  91. pcxColumn12->Items->Add(lblY->Caption);//"[Y] 권한있음");
  92. pcxColumn12->Items->Add(lblN->Caption);//"[N] 권한없음");
  93. }
  94. catch(EDatabaseError &E)
  95. {
  96. throw Exception(String(E.ClassName()) + E.Message);
  97. }
  98. catch(Exception &exception)
  99. {
  100. throw Exception(String(exception.ClassName()) + exception.Message);
  101. }
  102. catch(...)
  103. {
  104. throw Exception(FrmLang->lblDbErr->Caption);//"알수없는 DB 오류가 발생하였습니다.");
  105. }
  106. }
  107. __finally
  108. {
  109. }
  110. }
  111. //---------------------------------------------------------------------------
  112. void __fastcall TIDB0130M::TmrShowTimer(TObject *Sender)
  113. {
  114. TmrShow->Enabled = false;
  115. BtnSearchClick((TObject*)BtnSearch);
  116. }
  117. //---------------------------------------------------------------------------
  118. void __fastcall TIDB0130M::BtnSearchClick(TObject *Sender)
  119. {
  120. Application->ProcessMessages();
  121. TSqlCursor sqlCrs((TControl*)BtnSearch);
  122. RefreshData();
  123. CxList->SetFocus();
  124. }
  125. //---------------------------------------------------------------------------
  126. void __fastcall TIDB0130M::RefreshData()
  127. {
  128. SelListData();
  129. }
  130. //---------------------------------------------------------------------------
  131. void __fastcall TIDB0130M::SelListData()
  132. {
  133. FUpdate = false;
  134. CMM_ClearGridTableView(TvList);
  135. String sQry;
  136. TADOQuery *pADO = NULL;
  137. try
  138. {
  139. TvList->BeginUpdate();
  140. try
  141. {
  142. pADO = new TADOQuery(NULL);
  143. pADO->Close();
  144. pADO->Connection = ITSDb_GetConnection();
  145. #if 0
  146. sQry = "SELECT X.GROP_ID, X.GROP_NM, X.OPERSYST_MENU_ID, X.ATHR_YN, \r\n"
  147. " Y.GROP_MENU_NAME, Y.MENU_NAME \r\n"
  148. " FROM (SELECT A.GROP_ID, B.GROP_NM, A.OPERSYST_MENU_ID, A.ATHR_YN \r\n"
  149. " FROM TB_USER_GROP_MENU_ATHR A, \r\n"
  150. // " TB_USER_GROP_INFR B \r\n"
  151. " TB_USERGROP_INFR B \r\n"
  152. " WHERE A.GROP_ID = B.GROP_ID \r\n"
  153. " AND B.DEL_YN = 'N' ) X, \r\n"
  154. " (SELECT B.GROP_MENU_NAME, A.OPERSYST_MENU_ID, A.MENU_NAME \r\n"
  155. " FROM TB_OPERSYST_MENU A, \r\n"
  156. " (SELECT OPERSYST_MENU_ID AS OPER_SYST_ID, \r\n"
  157. " MENU_NAME AS GROP_MENU_NAME \r\n"
  158. " FROM TB_OPERSYST_MENU \r\n"
  159. " WHERE MENU_LEVL = 1 \r\n"
  160. " AND DEL_YN = 'N') B \r\n"
  161. " WHERE A.OPER_SYST_ID = B.OPER_SYST_ID \r\n"
  162. " AND A.MENU_LEVL = 2 \r\n"
  163. " AND A.DEL_YN = 'N' ) Y \r\n"
  164. " WHERE X.OPERSYST_MENU_ID = Y.OPERSYST_MENU_ID \r\n"
  165. " ORDER BY X.GROP_ID, Y.GROP_MENU_NAME, Y.MENU_NAME \r\n";
  166. #else
  167. sQry = "SELECT X.GROP_ID, X.GROP_NM, Y.OPERSYST_MENU_ID, \r\n"
  168. " NVL((SELECT ATHR_YN \r\n"
  169. " FROM TB_GROP_MENU_ATHR \r\n"
  170. " WHERE GROP_ID = X.GROP_ID \r\n"
  171. " AND OPERSYST_MENU_ID = Y.OPERSYST_MENU_ID), 'Y') AS ATHR_YN, \r\n"
  172. " Y.GROP_MENU_NAME, Y.MENU_NAME \r\n"
  173. // " FROM TB_USER_GROP_INFR X, \r\n"
  174. " FROM TB_USERGROP_INFR X, \r\n"
  175. " (SELECT B.GROP_MENU_NAME, A.OPERSYST_MENU_ID, A.MENU_NAME \r\n"
  176. " FROM TB_OPERSYST_MENU A, \r\n"
  177. " (SELECT OPERSYST_MENU_ID AS OPER_SYST_ID, \r\n"
  178. " MENU_NAME AS GROP_MENU_NAME \r\n"
  179. " FROM TB_OPERSYST_MENU \r\n"
  180. " WHERE MENU_LEVL = 1 \r\n"
  181. " AND DEL_YN = 'N') B \r\n"
  182. " WHERE A.OPER_SYST_ID = B.OPER_SYST_ID \r\n"
  183. " AND A.MENU_LEVL = 2 \r\n"
  184. " AND A.DEL_YN = 'N' ) Y \r\n";
  185. #endif
  186. pADO->SQL->Clear();
  187. pADO->SQL->Text = sQry;
  188. pADO->Prepared = true;
  189. pADO->Open();
  190. int nRow;
  191. for( ; !pADO->Eof; pADO->Next())
  192. {
  193. nRow = m_pGDC->AppendRecord();
  194. m_pGDC->Values[nRow][Column00->Index] = "-";
  195. m_pGDC->Values[nRow][Column01->Index] = pADO->FieldByName("GROP_ID")->AsString;
  196. m_pGDC->Values[nRow][Column02->Index] = pADO->FieldByName("GROP_NM")->AsString;
  197. m_pGDC->Values[nRow][Column03->Index] = pADO->FieldByName("GROP_MENU_NAME")->AsString;
  198. m_pGDC->Values[nRow][Column04->Index] = pADO->FieldByName("OPERSYST_MENU_ID")->AsString;
  199. m_pGDC->Values[nRow][Column05->Index] = pADO->FieldByName("MENU_NAME")->AsString;
  200. m_pGDC->Values[nRow][Column14->Index] = pADO->FieldByName("ATHR_YN")->AsString;
  201. String sATHR_YN = pADO->FieldByName("ATHR_YN")->AsString; //권한
  202. if (sATHR_YN == "Y")
  203. m_pGDC->Values[nRow][Column12->Index] = lblY->Caption;//"[Y] 권한있음";
  204. else
  205. m_pGDC->Values[nRow][Column12->Index] = lblN->Caption;//"[N] 권한없음";
  206. }
  207. }
  208. catch(EDatabaseError &E)
  209. {
  210. ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
  211. DBERRORMSG(Caption, String(E.ClassName()), E.Message, sQry);
  212. throw Exception(String(E.ClassName()) + E.Message);
  213. }
  214. catch(Exception &e)
  215. {
  216. ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
  217. DBERRORMSG(Caption, String(e.ClassName()), e.Message, sQry);
  218. throw Exception(String(e.ClassName()) + e.Message);
  219. }
  220. }
  221. __finally
  222. {
  223. if (pADO)
  224. {
  225. pADO->Close();
  226. delete pADO;
  227. }
  228. LblRecords->Caption = "("+FormatFloat("##,##0", m_pGDC->FilteredRecordCount) +"/"+FormatFloat("##,##0", m_pGDC->RecordCount) + ")";
  229. TvList->EndUpdate();
  230. TvList->DataController->GotoFirst();
  231. TvList->DataController->FocusedRecordIndex = 0;
  232. //CxList->SetFocus();
  233. }
  234. }
  235. //---------------------------------------------------------------------------
  236. void __fastcall TIDB0130M::BtnCloseClick(TObject *Sender)
  237. {
  238. Close();
  239. }
  240. //---------------------------------------------------------------------------
  241. void __fastcall TIDB0130M::BtnExlSaveClick(TObject *Sender)
  242. {
  243. TcxGrid *pGrid = CxList;
  244. TcxGridTableView *pView = TvList;
  245. String sTitle= Caption;//"운영자그룹 메뉴";
  246. CMM_ExportToExcelFile(sTitle, pGrid, pView, this);
  247. }
  248. //---------------------------------------------------------------------------
  249. void __fastcall TIDB0130M::FormClose(TObject *Sender, TCloseAction &Action)
  250. {
  251. CommClose();
  252. IDB0130M = NULL;
  253. Action = caFree;
  254. }
  255. //---------------------------------------------------------------------------
  256. void __fastcall TIDB0130M::BtnEditClick(TObject *Sender)
  257. {
  258. TListFocus tvFocus(TvList);
  259. if (BtnEdit->Caption == FrmLang->lblCancel->Caption)//"취소")
  260. {
  261. CxList->SetFocus();
  262. Application->ProcessMessages();
  263. SaveData();
  264. }
  265. FrmLang->ITSSkin_ButtonClick(BtnSearch, BtnEdit, BtnInsert, BtnDelete, BtnApply);
  266. ChangeEditMode(BtnEdit->Down);
  267. RefreshData();
  268. }
  269. //---------------------------------------------------------------------------
  270. void __fastcall TIDB0130M::ChangeEditMode(bool AEdit)
  271. {
  272. bool bEditing = AEdit;
  273. try
  274. {
  275. TvList->BeginUpdate();
  276. Column00->Visible = bEditing;
  277. Column12->Options->Editing = bEditing;
  278. }
  279. __finally
  280. {
  281. TvList->EndUpdate();
  282. if (bEditing)
  283. {
  284. BtnEdit->Caption = FrmLang->lblCancel->Caption;//"취소";
  285. BtnEdit->Hint = FrmLang->lblCancel->Hint;//데이터 편집 취소";
  286. }
  287. else
  288. {
  289. BtnEdit->Caption = FrmLang->lblEdit->Caption;//"편집";
  290. BtnEdit->Hint = FrmLang->lblEdit->Hint;//데이터 편집";
  291. }
  292. }
  293. }
  294. //---------------------------------------------------------------------------
  295. void __fastcall TIDB0130M::TvListColumnPropertiesValidate(TObject *Sender, Variant &DisplayValue, TCaption &ErrorText, bool &Error)
  296. {
  297. if (TvList->Controller->FocusedRow->IsFilterRow) return;
  298. int nRow = m_pGDC->FocusedRecordIndex;
  299. if (nRow < 0) return;
  300. String ATHR_YN_ORG = VarToStr(m_pGDC->Values[nRow][Column14->Index]);
  301. String ATHR_YN = VarToStr(m_pGDC->Values[nRow][Column12->Index]);
  302. TcxGridColumn *pColumn = TvList->Controller->FocusedColumn;
  303. if (pColumn == Column12) ATHR_YN = DisplayValue;
  304. ATHR_YN = ITSUtil_GetCode(ATHR_YN);
  305. if (ATHR_YN_ORG != ATHR_YN )
  306. {
  307. m_pGDC->Values[nRow][Column00->Index] = FrmLang->lblModify->Caption;//"수정";
  308. }
  309. else
  310. {
  311. TvList->DataController->Values[nRow][Column00->Index] = "-";
  312. }
  313. }
  314. //---------------------------------------------------------------------------
  315. void __fastcall TIDB0130M::BtnBestFitClick(TObject *Sender)
  316. {
  317. try
  318. {
  319. TvList->BeginUpdate();
  320. TvList->ApplyBestFit(NULL, false, false);
  321. }
  322. __finally
  323. {
  324. TvList->EndUpdate();
  325. }
  326. }
  327. //---------------------------------------------------------------------------
  328. void __fastcall TIDB0130M::ChkAutoWidthPropertiesChange(TObject *Sender)
  329. {
  330. try
  331. {
  332. TvList->BeginUpdate();
  333. TvList->OptionsView->ColumnAutoWidth = ChkAutoWidth->Checked;
  334. BtnBestFit->Visible = !ChkAutoWidth->Checked;
  335. }
  336. __finally
  337. {
  338. TvList->EndUpdate();
  339. }
  340. }
  341. //---------------------------------------------------------------------------
  342. void __fastcall TIDB0130M::MnuDeleteCancelClick(TObject *Sender)
  343. {
  344. //
  345. }
  346. //---------------------------------------------------------------------------
  347. void __fastcall TIDB0130M::BtnApplyClick(TObject *Sender)
  348. {
  349. FUpdate = true;
  350. BtnEdit->Down = false;
  351. BtnEdit->Click();
  352. }
  353. //---------------------------------------------------------------------------
  354. bool __fastcall TIDB0130M::IsUpdate()
  355. {
  356. try
  357. {
  358. TcxGridDataController *pGDC = TvList->DataController;
  359. TvList->BeginUpdate();
  360. for(int ii = 0; ii < pGDC->RecordCount; ii++)
  361. {
  362. String sEdit = VarToStr(pGDC->Values[ii][Column00->Index]);
  363. if (sEdit != "-") return true;
  364. }
  365. }
  366. __finally
  367. {
  368. TvList->EndUpdate();
  369. }
  370. return false;
  371. }
  372. //---------------------------------------------------------------------------
  373. void __fastcall TIDB0130M::SaveData()
  374. {
  375. if (!IsUpdate()) return;
  376. if (!FUpdate)
  377. {
  378. if (Application->MessageBox(FrmLang->lblEidtConfirm->Caption.c_str(),//L"변경된 정보가 있습니다.\r\n변경된 정보를 저장 하시겠습니까?",
  379. FTitle.c_str(), MB_YESNO|MB_ICONQUESTION|MB_APPLMODAL) != IDYES) return;
  380. }
  381. TADOQuery *pADOU = NULL;
  382. String sQryU;
  383. try
  384. {
  385. sQryU= "MERGE INTO TB_GROP_MENU_ATHR L \r\n"
  386. "USING (SELECT :p01 AS GROP_ID, \r\n"
  387. " :p02 AS OPERSYST_MENU_ID, \r\n"
  388. " :p03 AS ATHR_YN \r\n"
  389. " FROM DUAL \r\n"
  390. " ) M \r\n"
  391. "ON (L.GROP_ID = M.GROP_ID AND L.OPERSYST_MENU_ID = M.OPERSYST_MENU_ID) \r\n"
  392. "WHEN MATCHED THEN \r\n"
  393. " UPDATE SET L.ATHR_YN = M.ATHR_YN \r\n"
  394. "WHEN NOT MATCHED THEN \r\n"
  395. " INSERT (L.GROP_ID, L.OPERSYST_MENU_ID, L.ATHR_YN) \r\n"
  396. " VALUES (M.GROP_ID, M.OPERSYST_MENU_ID, M.ATHR_YN) \r\n";
  397. int nRow;
  398. TvList->BeginUpdate();
  399. try
  400. {
  401. pADOU = new TADOQuery(NULL);
  402. pADOU->Close();
  403. pADOU->Connection = ITSDb_GetConnection();
  404. ITSDb_SQLText(pADOU, sQryU);
  405. ITSDb_GetConnection()->BeginTrans();
  406. try
  407. {
  408. TcxGridDataController *pGDC = TvList->DataController;
  409. for(int ii = 0; ii < pGDC->RecordCount; ii++)
  410. {
  411. String sEdit = VarToStr(pGDC->Values[ii][Column00->Index]);
  412. if (sEdit == "-") continue;
  413. String GROP_ID = VarToStr(pGDC->Values[ii][Column01->Index]);
  414. String OPERSYST_MENU_ID = VarToStr(pGDC->Values[ii][Column04->Index]);
  415. String ATHR_YN = VarToStr(pGDC->Values[ii][Column12->Index]);
  416. ATHR_YN = ITSUtil_GetCode(ATHR_YN);
  417. ITSDb_SQLBind(pADOU, "p01", GROP_ID);
  418. ITSDb_SQLBind(pADOU, "p02", OPERSYST_MENU_ID);
  419. ITSDb_SQLBind(pADOU, "p03", ATHR_YN);
  420. #if 0
  421. ITSDb_SQLBind(pADOU, "p04", g_pLOGIN->sUserId);
  422. #endif
  423. ITSDb_SQLExec(pADOU);
  424. pGDC->Values[ii][Column14->Index] = ATHR_YN;
  425. }
  426. }
  427. catch(...)
  428. {
  429. }
  430. ITSDb_GetConnection()->CommitTrans();
  431. Application->MessageBox(FrmLang->lblDbSave->Caption.c_str(),//L"운영자그룹 메뉴권한 정보를 저장 하였습니다.",
  432. FTitle.c_str(), MB_OK|MB_ICONINFORMATION|MB_APPLMODAL);
  433. FDbUpdate = true;
  434. }
  435. catch(EDatabaseError &E)
  436. {
  437. ITSDb_GetConnection()->RollbackTrans();
  438. ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
  439. DBERRORMSG(Caption, String(E.ClassName()), E.Message, sQryU);
  440. throw Exception(String(E.ClassName()) + E.Message);
  441. }
  442. catch(Exception &e)
  443. {
  444. ITSDb_GetConnection()->RollbackTrans();
  445. ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
  446. DBERRORMSG(Caption, String(e.ClassName()), e.Message, sQryU);
  447. throw Exception(String(e.ClassName()) + e.Message);
  448. }
  449. }
  450. __finally
  451. {
  452. if (pADOU)
  453. {
  454. pADOU->Close();
  455. delete pADOU;
  456. }
  457. TvList->EndUpdate();
  458. }
  459. }
  460. //---------------------------------------------------------------------------
  461. void __fastcall TIDB0130M::FormCloseQuery(TObject *Sender, bool &CanClose)
  462. {
  463. SaveData();
  464. }
  465. //---------------------------------------------------------------------------
  466. void __fastcall TIDB0130M::TvListDataControllerFilterChanged(TObject *Sender)
  467. {
  468. CMM_SetFilterLike(TvList);
  469. LblRecords->Caption = "("+FormatFloat("##,##0", m_pGDC->FilteredRecordCount) +"/"+FormatFloat("##,##0", m_pGDC->RecordCount) + ")";
  470. }
  471. //---------------------------------------------------------------------------
  472. void __fastcall TIDB0130M::TvListCustomDrawCell(TcxCustomGridTableView *Sender, TcxCanvas *ACanvas, TcxGridTableDataCellViewInfo *AViewInfo,
  473. bool &ADone)
  474. {
  475. if (AViewInfo)
  476. {
  477. String sType = AViewInfo->GridRecord->DisplayTexts[Column00->Index];
  478. if (sType == FrmLang->lblModify->Caption)//"수정")
  479. {
  480. ACanvas->Brush->Color = clOlive;
  481. }
  482. else if (sType == FrmLang->lblDelete->Caption)//"삭제")
  483. {
  484. ACanvas->Brush->Color = clRed;
  485. }
  486. else if (sType == FrmLang->lblNew->Caption)//"신규")
  487. {
  488. ACanvas->Brush->Color = clLime;
  489. if (AViewInfo->Focused) ACanvas->Font->Color = clBlack;
  490. }
  491. else
  492. {
  493. String sAuth = AViewInfo->GridRecord->DisplayTexts[Column12->Index];
  494. if (sAuth.Pos("N"))
  495. {
  496. ACanvas->Brush->Color = clPurple;
  497. }
  498. }
  499. }
  500. }
  501. //---------------------------------------------------------------------------