IDB0130MF.cpp 20 KB

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