Dynamic report technology (2) in .NET.

zhaozj2021-02-16  47

Ø Using Formula One to implement dynamic reporting technology (2)

4. The read template is stored in the database in the form of binary flow, and F1 provides a WRITETOBLOBEX (), and WRITETOBLOB () method, and the syntax defined in the help document is:

phblob = f1book1.writetoblobex (NRESERVEDBYTES)

Originally, it can be easily written to binary stream, but the syntax defined after converting .NET can be called:

Public Virtual New System.Int32 WriteToblobex (System.Int16 NRESERVEDBYTES)

PHBLOB types become System.Int32 types! So we can only transfer additional methods. First save the current template, also a temporary file

/ / Save the current template to the temporary file

AXF1BOOK1.WRITEEX ("f1Temp.vts", ttf160.f1filetypeconstants.f1fileformulaone6);

Then use the .NET function to convert into a binary stream, then delete the temporary file.

/ / Temporary document binary stream

BYTE [] DATA = FileTobyte ("f1Temp.vts");

/ / Delete temporary files

File.delete ("f1Temp.vts");

// File-> Byte []

Private Byte [] Filetobyte (String FileName)

{

BYTE [] FileData;

Try

{

Using (filestream fs = file.openread (filename))

{

FileData = new byte [fs.length];

fs.read (FileData, 0, (INT) fs.length);

}

}

Catch (Exception E)

{

MessageBox.show ("Generates a binary flow error! Reason:" E.MESSAGE);

Return NULL;

}

Return FileData;

}

After obtaining binary flow, it is judged that this template has been there in the database. If this template has been updated, it will be added.

The new operation code is as follows:

#REGION inserted into the current template to the database

Strsql = "INSERT INTO REPORT_LIST_DATA (NUM, RPT_ID, RPT_NAME, User_Name, RPT_DATE, RPT_DATA)";

STRSQL = "VALUES (@ pkid, @ rptid, @ rptname, @ rptusername, getdate (), @ rptdata)

Sqlcommand command = new sqlcommand (strsql, funclib.aconn);

// Insert parameters

Sqlparameter parampkid = new sqlparameter ("@ pkid", sqldbtype.int);

Parampkid.Value = getpkid ("Report_List_Data", "NUM");

Command.Parameters.Add (parampkid);

Sqlparameter paramrptid = new sqlparameter ("@ rptid", sqldbtype.int);

Paramrptid.value = TPLINFO [1];

Command.Parameters.Add (paraMrptid); SQLParameter Paramrptname = New Sqlparameter ("@ rptname", sqldbtype.nvarchar);

Paramrptname.Value = TPLINFO [0];

Command.Parameters.Add (paraMrptname);

SQLParameter ParamrptUserName = New Sqlparameter ("@ rptusername", sqldbtype.nvarchar);

Paramrptusername.value = "hy";

Command.Parameters.Add (paraMrptusername);

SQLParameter Paramrptdata = New Sqlparameter ("@ rptdata", sqldbtype.image);

PARAMRPTDATA.VALUE = DATA;

Command.Parameters.Add (paraMrptdata);

IF (funclib.aconn.state! = connectionState.open) Funclib.aconn.Open ();

Command.executenonQuery ();

}

Catch (Exception Err)

{

Messagebox.show ("Inserting the current template is unsuccessful! Reason:" Err.Message);

Return;

}

#ndregion

Updating the operation code for the template as follows:

#Region Save the modified template to the database

Try

{

strsql = "Update report_list_data set rpt_data = @rptdata where rpt_id =" TPLINFO [1] "and rpt_name = '" TPLINFO [0] "'";

Sqlcommand command = new sqlcommand (strsql, funclib.aconn);

// Insert parameters

SQLParameter Paramrptdata = New Sqlparameter ("@ rptdata", sqldbtype.image);

PARAMRPTDATA.VALUE = DATA;

Command.Parameters.Add (paraMrptdata);

IF (funclib.aconn.state! = connectionState.open) Funclib.aconn.Open ();

Command.executenonQuery ();

Break;

}

Catch (Exception Err)

{

Messagebox.show ("Save the current template is unsuccessful! Cause:" Err.Message, "Error");

Return;

}

#ndregion

Note: FunClib is an instance of the current connection to obtain the current connection, getPKID ("Report_List_Data", "NUM") function function is the maximum main key value of the specified table name and its primary keypad name.

转载请注明原文地址:https://www.9cbs.com/read-26906.html

New Post(0)