Rave Report PDF and Intraweb 联系客服

发布时间 : 星期日 文章Rave Report PDF and Intraweb更新完毕开始阅读

in the Project Manager, select the ServerController, and in

the Object Inspector, toggleIwServerController.AllowSubFolder to True declare a global tCriticalSection variable, initialize it and free it in the Initialization and Finalization section of the Unit: unit u_irp_safe_page; interface // -- ...ooo... implementation uses SyncObjs; {$R *.dfm} var // -- critical section to serialize the .PDF generation g_c_rave_critical_section: TCriticalSection= Nil; // -- ...ooo... initialization TIWForm1.SetAsMainForm; g_c_rave_critical_section:= TCriticalSection.Create; finalization g_c_rave_critical_section.Free; end

drop a tIwButton and create the OnClick event which will generate and display the .PDF report procedure TIWForm1.GenerateAndDisplayClick(Sender: TObject); var l_pdf_file_name: string; l_session_id_segment: String; procedure generate_pdf; var l_c_rave_dataset_connection: TRvDataSetConnection; begin ClientDataSet1.Close; ClientDataSet1.IndexFieldNames:= g_sort_column; ClientDataSet1.Open; RVProject1.ProjectFile:= WebApplication.ApplicationPath+ '..\\_data\\r_employee.rav'; with RvSystem1 do begin DoNativeOutput:= false; RenderObject:= RvRenderPDF1;

OutputFileName:= IWServerController.FilesDir

+ l_session_id_segment+ '\\'+ l_pdf_file_name; end; // with RvSystem1

// -- create the user specific path

ForceDirectories(ExtractFileDir(RvSystem1.OutputFileName)); // -- enter into the critical section g_c_rave_critical_section.Enter;

// -- create a new RvDataSetConnectoin

l_c_rave_dataset_connection:= TRvDataSetConnection.Create(self); try

l_c_rave_dataset_connection.Name:= 'my_rave_dataset_connection';

l_c_rave_dataset_connection.DataSet:= ClientDataset1; l_c_rave_dataset_connection.Name:= 'dataset_connection_'+ l_session_id_segment;

l_c_rave_dataset_connection.DataSet:= ClientDataset1;

RvProject1.ExecuteReport('Report1'); finally

l_c_rave_dataset_connection.Free; g_c_rave_critical_section.leave;

RvSystem1.OutputFileName:= ''; end; // try/finally end; // generate_pdf procedure display_pdf;

var l_pdf_url: String;

l_popup_page_name: string; l_popup_page_options: string; l_popup_parameter: String; begin

l_pdf_url:= WebApplication.AppURLBase+ '/files/'

+ l_session_id_segment+ '/'+ l_pdf_file_name; IwLabel2.Caption:= l_pdf_url;

l_popup_page_name:= 'the_report';

l_popup_page_options:= 'scrollbars=yes,width=500,height=300';

l_popup_parameter:= 'NewWindow(\ + l_pdf_url + '\\+ l_popup_page_name + '\+ l_popup_page_options + '\; AddToInitProc(l_popup_parameter); end; // display_pdf begin // GenerateAndDisplayClick l_session_id_segment:= WebApplication.AppID; l_pdf_file_name:= 'safe_report_' + g_sort_column+ '_'+ l_session_id_segment+ '.pdf'; generate_pdf; display_pdf; end; // GenerateAndDisplayClick

in the Project Manager, create the OnCloseSession event, and erase all PDF's of this session: procedure TIWServerController.IWServerControllerBaseCloseSession( ASession: TIWApplication); const k_path_delimiter= '\\'; var l_output_file_dir: string; l_search_record: TSearchRec; begin l_output_file_dir:= GServerController.FilesDir+ ASession.AppID; // -- CleanUp session's files directory if FindFirst(l_output_file_dir+ k_path_delimiter+ '*.*', faAnyFile, l_search_record)= 0 then begin repeat DeleteFile( l_output_file_dir+ k_path_delimiter+ l_search_record.Name); until FindNext(l_search_record)<> 0; FindClose(l_search_record); end; RemoveDir(l_output_file_dir); end; // IWServerControllerBaseCloseSession compile, run, type F9, click \

the PDF is displayed in a separate page, and, if you look at the FILES/ subfolder, you will see the session folder with the .PDF in it close the Intraweb Server the session folder is removed

We also tried to generate several kinds of reports, by changing some parameters of the tDataSet: the order, filtering rows etc (but NOT the column structure, which is hard coded in the .RAV)

drop a tIwListbox, with the list of some columns, and create the event which will

sort the ClientDataSet1: var g_sort_column: String= ''; procedure TIWForm1.IWListbox1Click(Sender: TObject); begin with IwListBox1 do case ItemIndex of 0 : g_sort_column:= 'EmpNo'; 1 : g_sort_column:= 'LastName'; 2 : g_sort_column:= 'PhoneExt'; else g_sort_column:= ''; end; // case ClientDataSet1.IndexFieldNames:= g_sort_column; end; // IWListbox1Click

run, select a PhoneExt sort, click \

the PDF is displayed sorted in PhoneExt order

you may repeat the operation with an other sort order

Please note that:

IwServerController.AllowSubFolder only exists for Intraweb versions after 5.1 ? the code within the critical section should be kept as short as possible

? there are many possible options for the pop-up page. We could use code like:

?

const k_options= 'toolbar=no,status=no,menubar=yes,scrollbars=yes'