Devexpress uses the binary stream storage module to customize report reports.

Source: Internet
Author: User

Recently, the third-party report control (devexpress) was used to load the report designer by reading files (. repx. The implementation method is as follows:

Not SetCopy files to the output directoryThe report module file cannot be loaded.

 1    //  Get datatable data  
2 Createdatatable ();
3 Dataset DS = New Dataset ();
4 DS. Tables. Add (DT );
5 // Load data, custom Report Format
6 Devexpress. xtrareports. UI. xtrareport report = New Devexpress. xtrareports. UI. xtrareport ();
7 Report. loadlayout (application. startuppath + @" \ Reportfile \ reportemplate. repx " );
8 Report. datasource = Ds;
9 Report. showdesignerdialog ();
10 Report. Dispose ();

On the surface, the basic functions are simple, but we should consider how to save them after setting them.

 
1Report. savelayout (application. startuppath +@"\ Reportfile \ reportemplate1.repx");

During the saving process, note that the file name cannot be repeated because the template itself is in use and cannot be overwritten.

Here is the basic function. Let's talk about the problem here.The user saves too many module files, which is inconvenient to use. This will undoubtedly cause the user or server files to constantly increase and carry heavy loads until one day of crash.. It is undoubtedly the best choice to use the template binary stream to complete this function.

Design Concept:

1. Design a table in the database to store files generated using binary bytes. It is best to have two initialization templates and one after the user's design.

 1    Try 
2 {
3 String Filepath = application. startuppath. tostring ();
4 Filestream file = New Filestream (filepath + @" \ Reportfile \ reportemplate. repx " , Filemode. Open, fileaccess. readwrite );
5 Byte [] A = New Byte ;
6 File. Read (, 0 ,( Int ) File. Length );
7 // Here I convert the binary to text display
8 Txtcontent. Text = convert. tobase64string ();
9 }
10 Catch (Exception)
11 {
12 Throw ;
13 }

In this way, you can obtain the binary template data of the initialized template file and save it to the initialized data field. This will not be used in the future.

2. Read Binary data from the report and load it to the template report. As follows:

 1   Using System;
2 Using System. Collections. Generic;
3 Using System. componentmodel;
4 Using System. Data;
5 Using System. drawing;
6 Using System. text;
7 Using System. Windows. forms;
8 Using Devexpress. xtraeditors;
9 Using System. IO;
10 Using System. LINQ;
11 Using Devexpress. xtrareports. UI;
12 Using Devexpress. xtrareports. userdesigner;
13 Using System. Drawing. design;
14 Using System. componentmodel. design;
15 Using Devexpress. xtrareports;

 

 1 Xtrareport R;
2 Private Void Btnread_click ( Object Sender, eventargs E)
3 {
4 R = New Xtrareport ();
5 // Binary stream reading and conversion
6 Byte [] FF = convert. frombase64string (txtcontent. Text. Trim ());
7 System. Io. memorystream MS = New Memorystream (ff );
8 R. loadlayout (MS );
9
10 Xrdesignformex designform = New Xrdesignformex ();
11
12 // Hide the button Section
13 // Designform. designpanel. setcommandvisibility (New reportcommand [] {
14 // Reportcommand. newreport,
15 // Reportcommand. savefileas,
16 // Reportcommand. newreportwizard,
17 // Reportcommand. openfile
18 // }, New devexpress. xtrareports. userdesigner. c commandvisibility. None );
19
20
21
22 // Change status
23 Designform. reportstatechanged + = New Reportstateeventhandler (designform_reportstatechanged );
24 Designform. formclosing + = New Formclosingeventhandler (designform_formclosing );
25 // Load the report.
26 Designform. openreport (R );
27 // Open the designer
28 Designform. showdialog ();
29 Designform. Dispose ();
30 }
31
32 Void Designform_formclosing ( Object Sender, formclosingeventargs E)
33 {
34 // The operations when the designer is disabled are processed here, and data is mainly saved with custom
35
36 System. Io. memorystream MS =New Memorystream ();
37 R. savelayout (MS );
38 Byte [] Fff = Ms. toarray ();
39 Txtcontent. Text = convert. tobase64string (FFF );
40 }
41
42 Void Designform_reportstatechanged ( Object Sender, reportstateeventargs E)
43 {
44 // Set the status to save as long as the report changes.
45 // This avoids the appearance of the default save dialog box.
46 If (E. reportstate = reportstate. Changed)
47 {
48 (Xrdesignformex) sender). designpanel. reportstate = reportstate. Saved;
49 }
50 }

Achieve the aboveCodeYou need to reference devexpress. xtrareports. v11.1.design, devexpress. xtrareports. v11.1.extensions, devexpress. xtrareports. v11.1.

The above code can be used. In the following code, the system. Io. memorystream memory stream is used to obtain the status of the modified binary data template on the report design page.
 

1R =NewXtrareport ();
2//Binary stream reading and conversion
3Byte[] FF = convert. frombase64string (txtcontent. Text. Trim ());
4System. Io. memorystream MS =NewMemorystream (ff );
5R. loadlayout (MS );

The above draft has already come out, and it is very easy to implement the specific database. I won't say much about it.

There is still a small problem in my code. I am also studying how to disable the buttons in the designer by commenting on a section in my code. If you know something, share it with me.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.