void TImageViewerDemoMainForm::PopulateGallery(bool ASorted) { TMemoryStream *AStream; TdxSmartImage *AImage; Integer AGroupIndex, AFilmID, AActionID, AComedyID, ADramaID; AGroupIndex = 0; //dxGalleryControl->BeginUpdate(); try { dxGalleryControl->Gallery->Groups->Clear(); dxGalleryControl->Gallery->Groups->Add(); if (ASorted) { dxGalleryControl->Gallery->Groups->Add(); dxGalleryControl->Gallery->Groups->Add(); dxGalleryControl->Gallery->Groups->Add(); dxGalleryControl->Gallery->Groups->Groups[0]->Caption = ActionGenre; dxGalleryControl->Gallery->Groups->Groups[1]->Caption = ComedyGenre; dxGalleryControl->Gallery->Groups->Groups[2]->Caption = DramaGenre; dxGalleryControl->Gallery->Groups->Groups[3]->Caption = OtherGenres; } GetGenresIDs(AActionID, AComedyID, ADramaID); cdsFilms->First(); AStream = new TMemoryStream(); try { while (! cdsFilms->Eof) { if (! cdsFilms->Fields->FieldByName("Photo")->IsNull) { AImage = new TdxSmartImage(); try { AStream->Position = 0; TField *AField = cdsFilms->Fields->FieldByName("Photo"); TBlobField *ABlobField = (TBlobField *)AField; ABlobField->SaveToStream(AStream); AStream->Position = 0; AImage->LoadFromStream(AStream); AFilmID = cdsFilms->Fields->FieldByName("ID")->AsInteger; if (ASorted) AGroupIndex = FilmGenreGroup(AFilmID, AActionID, AComedyID, ADramaID); TdxGalleryControlItem *AItem = dxGalleryControl->Gallery->Groups->Groups[AGroupIndex]->Items->Add(); AItem->Glyph->Assign(AImage); AItem->Caption = cdsFilms->Fields->FieldByName("Caption")->AsString; AItem->Tag = AFilmID; } __finally { delete AImage; } } cdsFilms->Next(); } } __finally { delete AStream; } }
//--------------------------------------------------------------------------- //Процедура получения книги из базы void __fastcall TMainForm::GetBook(TObject *Sender){ HWND hWnd; AnsiString filter,path; path=getenv("TEMP"); path+="\\temp.rar"; int bkod=DM->dsTree->FieldByName("KBOOK")->Value; filter.printf("KOD=%d",bkod); DM->dsBook->Filter=filter; DM->dsBook->Filtered=true; TBlobField *bl = (TBlobField *)DM->dsBook->FieldByName("BOOK"); bl->SaveToFile(path); ShellExecute(hWnd, "open",path.c_str(), NULL, NULL, SW_SHOWNORMAL); DM->dsBook->Filtered=false; }
void __fastcall TMainForm::ButtonAddDocClick(TObject *Sender) { if (OraQueryAllJournal->RecordCount == 0) { ShowMessage ("Не выбрана запись !"); return; } Screen->Cursor = crHourGlass; OpenDialogDocs->Filter = "All files (*.*)|*.*||"; if (OpenDialogDocs->Execute()) { for (int i = 0; i < OpenDialogDocs->Files->Count; i++) { OraQueryDocsInsert->SQL->Text = "SELECT DOC_NAME FROM " + m_shema + "." + m_blob_table + " WHERE DOC_NAME = '" + ExtractFileName(OpenDialogDocs->Files->Strings[i].c_str()) + "' AND " + m_blob_foreign_key + " = " + OraQueryAllJournal->Fields->FieldByName(m_primary_key)->AsString; OraQueryDocsInsert->Open(); if (OraQueryDocsInsert->RecordCount) { ShowMessage ("Файл " + ExtractFileName(OpenDialogDocs->Files->Strings[i].c_str()) + " уже существует !"); OraQueryDocsInsert->Close(); continue; } OraQueryDocsInsert->Close(); OraQueryDocsInsert->SQL->Clear(); OraQueryDocsInsert->Open(); OraQueryDocsInsert->Insert(); TFields *fields = OraQueryDocsInsert->Fields; TBlobField *t = (TBlobField*)(fields->FieldByName("DOC_TEXT")); t->LoadFromFile(OpenDialogDocs->Files->Strings[i].c_str()); OraQueryDocsInsert->FieldValues [m_blob_foreign_key] = OraQueryAllJournal->Fields->FieldByName (m_primary_key)->AsString; OraQueryDocsInsert->FieldValues ["DOC_NAME"] = ExtractFileName(OpenDialogDocs->Files->Strings[i].c_str()); OraQueryDocsInsert->Post(); OraQueryDocsInsert->Close(); } } OraQueryDocs->Close(); OraQueryDocs->Open(); Screen->Cursor = crDefault; }
void __fastcall TMainForm::ButtonLoadClick(TObject *Sender) { if (OraQueryAllJournal->RecordCount == 0 || OraQueryDocs->RecordCount == 0) { ShowMessage ("Не выбран файл для загрузки !"); return; } Screen->Cursor = crHourGlass; AnsiString temp_dir; TRegistry * reg = new TRegistry (KEY_READ); try { reg->RootKey = HKEY_LOCAL_MACHINE; reg->OpenKey ("\\SOFTWARE\\Gis center\\Journal", true); temp_dir = reg->ReadString ("TempDir"); } __finally { safe_delete (reg); // delete reg; } if (temp_dir.IsEmpty()) { ShowMessage ("Не задана временная директория для выгрузки файлов !"); Screen->Cursor = crDefault; return; } ProgressForm->Show(); AnsiString fn; TOraQuery * docQuery = new TOraQuery (this); try { docQuery->SQL->Text = "SELECT DOC_NAME, DOC_TEXT FROM " + m_shema + "." + m_blob_table + " WHERE " + m_blob_primary_key + " = " + OraQueryDocs->Fields->FieldByName(m_blob_primary_key)->AsString; docQuery->Open(); docQuery->First(); fn = docQuery->Fields->FieldByName ("DOC_NAME")->AsString; TBlobField * blob = (TBlobField*)(docQuery->Fields->FieldByName("DOC_TEXT")); blob->SaveToFile (temp_dir + "\\" + fn); docQuery->Close(); } __finally { safe_delete (docQuery); //delete docQuery; } m_loading_docs [OraQueryDocs->Fields->FieldByName(m_blob_primary_key)->AsInteger] = temp_dir + "\\" + fn; ButtonSaveDoc->Enabled = true; Files.insert(temp_dir + "\\" + fn); // Проверка ассоциации AnsiString path; reg = new TRegistry (KEY_READ); try { reg->RootKey = HKEY_LOCAL_MACHINE; reg->OpenKey ("\\SOFTWARE\\Gis center\\Journal\\Associations", true); path = reg->ReadString (ExtractFileExt (fn).Delete(1, 1)); reg->CloseKey(); } __finally { safe_delete (reg); //delete reg; } if (!path.IsEmpty()) { STARTUPINFO si = {sizeof (si)}; PROCESS_INFORMATION pi; AnsiString dir = GetCurrentDir(); SetCurrentDir (temp_dir); if (CreateProcess (NULL, ("\"" + path + "\" \"" +fn + "\"").c_str(), 0, 0, FALSE, 0,0,0, &si, &pi)) { CloseHandle (pi.hThread); CloseHandle (pi.hProcess); } SetCurrentDir (dir); } else { ShellExecute(0, "open", AnsiString (temp_dir + "\\" + fn).c_str(), NULL, NULL, SW_SHOWNORMAL); } ProgressForm->Close(); Screen->Cursor = crDefault; }