VMSM510MF.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include "ITSSkinF.h"
  4. #include "ITSUtilF.h"
  5. #include "AppGlobalF.h"
  6. #pragma hdrstop
  7. #include "VMSM510MF.h"
  8. //---------------------------------------------------------------------------
  9. #pragma package(smart_init)
  10. #pragma link "cxButtons"
  11. #pragma link "cxCalendar"
  12. #pragma link "cxContainer"
  13. #pragma link "cxControls"
  14. #pragma link "cxDropDownEdit"
  15. #pragma link "cxEdit"
  16. #pragma link "cxGraphics"
  17. #pragma link "cxGroupBox"
  18. #pragma link "cxLabel"
  19. #pragma link "cxLookAndFeelPainters"
  20. #pragma link "cxLookAndFeels"
  21. #pragma link "cxMaskEdit"
  22. #pragma link "cxPC"
  23. #pragma link "cxPCdxBarPopupMenu"
  24. #pragma link "cxSpinEdit"
  25. #pragma link "cxSplitter"
  26. #pragma link "cxTextEdit"
  27. #pragma link "cxTimeEdit"
  28. #pragma link "dxSkinBlack"
  29. #pragma link "dxSkinBlue"
  30. #pragma link "dxSkinCaramel"
  31. #pragma link "dxSkinCoffee"
  32. #pragma link "dxSkinDarkRoom"
  33. #pragma link "dxSkinDarkSide"
  34. #pragma link "dxSkinFoggy"
  35. #pragma link "dxSkinGlassOceans"
  36. #pragma link "dxSkiniMaginary"
  37. #pragma link "dxSkinLilian"
  38. #pragma link "dxSkinLiquidSky"
  39. #pragma link "dxSkinLondonLiquidSky"
  40. #pragma link "dxSkinMcSkin"
  41. #pragma link "dxSkinMoneyTwins"
  42. #pragma link "dxSkinOffice2007Black"
  43. #pragma link "dxSkinOffice2007Blue"
  44. #pragma link "dxSkinOffice2007Green"
  45. #pragma link "dxSkinOffice2007Pink"
  46. #pragma link "dxSkinOffice2007Silver"
  47. #pragma link "dxSkinOffice2010Black"
  48. #pragma link "dxSkinOffice2010Blue"
  49. #pragma link "dxSkinOffice2010Silver"
  50. #pragma link "dxSkinsCore"
  51. #pragma link "dxSkinscxPCPainter"
  52. #pragma link "dxSkinSeven"
  53. #pragma link "dxSkinSharp"
  54. #pragma link "dxSkinSilver"
  55. #pragma link "dxSkinStardust"
  56. #pragma link "cxRadioGroup"
  57. #pragma link "cxClasses"
  58. #pragma link "cxCustomData"
  59. #pragma link "cxData"
  60. #pragma link "cxDataStorage"
  61. #pragma link "cxDBData"
  62. #pragma link "cxFilter"
  63. #pragma link "cxGrid"
  64. #pragma link "cxGridCustomTableView"
  65. #pragma link "cxGridCustomView"
  66. #pragma link "cxGridDBTableView"
  67. #pragma link "cxGridLevel"
  68. #pragma link "cxGridTableView"
  69. #pragma link "cxStyles"
  70. #pragma link "cxCheckBox"
  71. #pragma link "cxImage"
  72. #pragma link "cxButtonEdit"
  73. #pragma link "cxBlobEdit"
  74. #pragma link "IdBaseComponent"
  75. #pragma link "IdCoder"
  76. #pragma link "IdCoder3to4"
  77. #pragma link "IdCoderMIME"
  78. #pragma resource "*.dfm"
  79. TVMSM510M *VMSM510M = NULL;
  80. //---------------------------------------------------------------------------
  81. __fastcall TVMSM510M::TVMSM510M(TComponent* Owner)
  82. : TForm(Owner)
  83. {
  84. ITSSkin_Load(this);
  85. CMM_LoadForm(g_sFormsDir, this);
  86. FUpdate= false;
  87. FTitle = Caption;//"VMS 객체이미지 선택";
  88. FListSymb = new TList;
  89. EditMode = false;
  90. m_bSelected = false;
  91. TvList->OptionsView->DataRowHeight = 0;
  92. TvList->OptionsView->CellAutoHeight = true;
  93. TvList->OptionsView->Indicator = true;
  94. TvList->OptionsCustomize->ColumnMoving = false;
  95. TvList->OptionsCustomize->ColumnSorting = false;
  96. TvList->Columns[0]->Width = 50;
  97. TvList->Columns[0]->Options->HorzSizing = false;
  98. }
  99. //---------------------------------------------------------------------------
  100. void __fastcall TVMSM510M::CommClose()
  101. {
  102. try
  103. {
  104. ClearSymbloList();
  105. SAFE_DELETE(FListSymb);
  106. CMM_SaveForm(g_sFormsDir, this);
  107. }
  108. catch(...)
  109. {
  110. }
  111. }
  112. //---------------------------------------------------------------------------
  113. void __fastcall TVMSM510M::FormShow(TObject *Sender)
  114. {
  115. Refresh();
  116. FormInit();
  117. TmrShow->Enabled = true;
  118. }
  119. //---------------------------------------------------------------------------
  120. void __fastcall TVMSM510M::FormInit()
  121. {
  122. EdNmbr->Text = "";
  123. ImgPreView->Picture->Bitmap->FreeImage();
  124. ImgPreView->Picture->Bitmap = NULL;
  125. FNewDb = false;
  126. }
  127. //---------------------------------------------------------------------------
  128. void __fastcall TVMSM510M::TmrShowTimer(TObject *Sender)
  129. {
  130. TmrShow->Enabled = false;
  131. LoadImageSymbol();
  132. }
  133. //---------------------------------------------------------------------------
  134. void __fastcall TVMSM510M::BtnCloseClick(TObject *Sender)
  135. {
  136. Close();
  137. }
  138. //---------------------------------------------------------------------------
  139. void __fastcall TVMSM510M::FormClose(TObject *Sender, TCloseAction &Action)
  140. {
  141. CommClose();
  142. VMSM510M = NULL;
  143. Action = caFree;
  144. }
  145. //---------------------------------------------------------------------------
  146. void __fastcall TVMSM510M::FormCloseQuery(TObject *Sender, bool &CanClose)
  147. {
  148. //
  149. }
  150. //---------------------------------------------------------------------------
  151. void __fastcall TVMSM510M::DisplayInfo()
  152. {
  153. FormInit();
  154. int nRow = TvList->DataController->FocusedRecordIndex;
  155. if( nRow <= -1 )
  156. return;
  157. TcxGridDataController *pDc = TvList->DataController;
  158. nRow = pDc->FocusedRecordIndex;
  159. if (nRow < FListSymb->Count)
  160. {
  161. Graphics::TBitmap *bitmap = (Graphics::TBitmap*)FListSymb->Items[nRow];
  162. ImgPreView->Picture->Bitmap->Assign(bitmap);
  163. }
  164. EdNmbr->Text = VarToStr(pDc->Values[nRow][ColLink1->Index]);
  165. }
  166. //---------------------------------------------------------------------------
  167. void __fastcall TVMSM510M::ClearSymbloList()
  168. {
  169. for(int ii = 0; ii < FListSymb->Count; ii++)
  170. {
  171. Graphics::TBitmap *bitmap = (Graphics::TBitmap *)FListSymb->Items[ii];
  172. delete bitmap;
  173. }
  174. FListSymb->Clear();
  175. }
  176. //---------------------------------------------------------------------------
  177. String __fastcall TVMSM510M::DecodeAndUnCompress(String input)
  178. {
  179. return "";
  180. }
  181. String __fastcall TVMSM510M::BitmapToBase64String(Graphics::TBitmap *AImage)
  182. {
  183. return "";
  184. }
  185. //---------------------------------------------------------------------------
  186. Graphics::TBitmap * __fastcall TVMSM510M::Base64StringToBitmap(String AImageString)
  187. {
  188. TIdDecoderMIME *Decodeur = new TIdDecoderMIME(NULL);
  189. TMemoryStream *TempMem = new TMemoryStream();
  190. Graphics::TBitmap *result = new Graphics::TBitmap();
  191. try {
  192. try {
  193. Decodeur->DecodeBegin(TempMem);
  194. Decodeur->Decode(AImageString);
  195. Decodeur->DecodeEnd();
  196. TempMem->Position = 0;
  197. result->LoadFromStream(TempMem);
  198. }
  199. catch(Exception &e) {
  200. result->Assign(ImgFail->Picture->Bitmap);
  201. }
  202. }
  203. __finally {
  204. if (Decodeur) delete Decodeur;
  205. if (TempMem) delete TempMem;
  206. }
  207. return result;
  208. }
  209. //---------------------------------------------------------------------------
  210. void __fastcall TVMSM510M::LoadImageSymbol()
  211. {
  212. FormInit();
  213. CMM_ClearGridTableView(TvList);
  214. ClearSymbloList();
  215. String vmsTypeCd = "SBT0";
  216. String apiUri = g_AppCfg.sRestApiUri + "/api/vms/manager/symb-sbt0";
  217. TMcJsonItem *ObjList = NULL;
  218. if (FImageType == 0) //이미지 심볼
  219. {
  220. vmsTypeCd = "SBT0";
  221. apiUri = g_AppCfg.sRestApiUri + "/api/vms/manager/symb-sbt0";
  222. }
  223. else
  224. if (FImageType == 1) //소통정보배경이미지
  225. {
  226. vmsTypeCd = "SBT1";
  227. apiUri = g_AppCfg.sRestApiUri + "/api/vms/manager/symb-sbt1";
  228. }
  229. else
  230. if (FImageType == 2) //소통정보이미지
  231. {
  232. vmsTypeCd = "SBT2";
  233. apiUri = g_AppCfg.sRestApiUri + "/api/vms/manager/symb-sbt2";
  234. }
  235. else
  236. if (FImageType == 3) //동영상
  237. {
  238. vmsTypeCd = "SBT3";
  239. apiUri = g_AppCfg.sRestApiUri + "/api/vms/manager/symb-sbt3";
  240. }
  241. else
  242. if (FImageType == 4) //대기환경 이미지
  243. {
  244. vmsTypeCd = "SBT4";
  245. apiUri = g_AppCfg.sRestApiUri + "/api/vms/manager/symb-sbt4";
  246. }
  247. else return;
  248. int nRowHeight = 0;
  249. try
  250. {
  251. int nRow;
  252. TcxDataController *pGDC = TvList->DataController;
  253. TvList->BeginUpdate();
  254. try
  255. {
  256. ObjList = TRestObjectManager::RequestGet(apiUri);
  257. if (ObjList == NULL) {
  258. return;
  259. }
  260. for (int ii = 0; ii < ObjList->Count; ii++) {
  261. nRow = pGDC->AppendRecord();
  262. String imageString = TRestObjectManager::GetValue(ObjList->Items[ii], "imag_data");
  263. Graphics::TBitmap *bitmap = Base64StringToBitmap(imageString);
  264. TStream *pImgStream = new TMemoryStream();
  265. try {
  266. bitmap->SaveToStream(pImgStream);
  267. void *p;
  268. Variant v;
  269. int aBound[]={0, pImgStream->Size - 1};
  270. v = VarArrayCreate(aBound, 1, varByte);
  271. p = VarArrayLock(v);
  272. pImgStream->Position = 0;
  273. pImgStream->Read(p, pImgStream->Size);
  274. VarArrayUnlock(v);
  275. pGDC->Values[nRow][ColLink2->Index] = v;
  276. } catch(Exception &e) {}
  277. SAFE_DELETE(pImgStream);
  278. pGDC->Values[nRow][ColLink1->Index] = TRestObjectManager::GetValue(ObjList->Items[ii], "symb_lib_nmbr");
  279. pGDC->Values[nRow][ColLink3->Index] = TRestObjectManager::GetValue(ObjList->Items[ii], "symb_expl");
  280. pGDC->Values[nRow][ColLink4->Index] = vmsTypeCd;
  281. #if 1
  282. /* 이미지를 가지고 가는 곳에서 이것을 참조하기 때문에 주석으로 막지 말자.... */
  283. //Graphics::TBitmap *bitmap = new Graphics::TBitmap;
  284. //bitmap->LoadFromStream(pADO->CreateBlobStream(pADO->FieldByName("IMAG_DATA"), bmRead));
  285. FListSymb->Add(bitmap);
  286. if (bitmap->Height+2 > nRowHeight) nRowHeight = bitmap->Height+3;
  287. #endif
  288. }
  289. }
  290. catch(EDatabaseError &E)
  291. {
  292. throw Exception(String(E.ClassName()) + E.Message);
  293. }
  294. catch(Exception &e)
  295. {
  296. throw Exception(String(e.ClassName()) + e.Message);
  297. }
  298. }
  299. __finally
  300. {
  301. if (ObjList) delete ObjList;
  302. //TvList->OptionsView->DataRowHeight = nRowHeight;
  303. TvList->EndUpdate();
  304. }
  305. }
  306. //---------------------------------------------------------------------------
  307. void __fastcall TVMSM510M::TvListCellDblClick(TcxCustomGridTableView *Sender, TcxGridTableDataCellViewInfo *ACellViewInfo,
  308. TMouseButton AButton, TShiftState AShift,
  309. bool &AHandled)
  310. {
  311. if (!ACellViewInfo) return;
  312. DisplayInfo();
  313. Sleep(200);
  314. BtnSelImageClick((TObject*)BtnSelImage);
  315. }
  316. //---------------------------------------------------------------------------
  317. void __fastcall TVMSM510M::TvListFocusedRecordChanged(TcxCustomGridTableView *Sender,
  318. TcxCustomGridRecord *APrevFocusedRecord, TcxCustomGridRecord *AFocusedRecord,
  319. bool ANewItemRecordFocusingChanged)
  320. {
  321. if (!AFocusedRecord) return;
  322. DisplayInfo();
  323. }
  324. //---------------------------------------------------------------------------
  325. void __fastcall TVMSM510M::BtnSelImageClick(TObject *Sender)
  326. {
  327. if (EdNmbr->Text == "")
  328. {
  329. Application->MessageBox(lblText1->Caption.c_str(),//L"VMS 객체이미지 선택\r\nVMS 객체이미지를 목록에서 선택하세요.",
  330. FTitle.c_str(),
  331. MB_OK|MB_ICONERROR|MB_APPLMODAL);
  332. return;
  333. }
  334. m_bSelected = true;
  335. Close();
  336. }
  337. //---------------------------------------------------------------------------