宁虹看板
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

943 lines
37 KiB

using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Web;
namespace NFine.Web
{
public class PrintJson
{
/// <summary>
/// 打印的JSON数据
/// </summary>
private JObject jPrintValue;
/// <summary>
/// 打印的参数,每个数组包括两个值:Key, Value
/// </summary>
private JArray jaryPrintParam;
/// <summary>
/// 打印预览时的按钮是否显示
/// </summary>
private JObject jButtonHide;
/// <summary>
/// 设置页边距
/// </summary>
private JObject jMargin;
/// <summary>
/// 设置数据集的名称
/// </summary>
private JObject jDataSetName;
/// <summary>
/// 打印的单个图片的数组,包含3个元素:报表图片对象名、图片文件名、 图片文件内容
/// </summary>
private JArray jaryPictureSingle;
/// <summary>
/// 打印的数据集中的图片的内容的数组,包含2个元素:图片文件名称、图片文件内容
/// </summary>
private JArray jaryPictureTableValue;
/// <summary>
/// 打印的数据集中的图片的设置的数组,包含3个元素:报表图片对象名、数据集序号、字段名称
/// </summary>
private JArray jaryPictureTableSet;
/// <summary>
/// 打印的数据内容的数组
/// </summary>
private JArray jaryPrintData;
/// <summary>
/// 控件注册的姓名或公司名称
/// </summary>
private string strRegName;
/// <summary>
/// 控件的注册码
/// </summary>
private string strRegValue;
/// <summary>
/// 报表文件名称,包括绝对路径
/// </summary>
private string strReportFileName;
/// <summary>
/// 报表临时文件所在的文件夹,服务器的报表JSON数据将临时存储在此文件夹,此文件夹要求能通过URL访问,控件通过文件名下载报表打印所需要的数据
/// </summary>
private string strReportTempDirectory;
/// <summary>
/// 存储打印控件时初始化时,所传入的Cookie值、回传服务端的URL
/// </summary>
private JObject jCookieUrl;
/// <summary>
/// 打印初始化类
/// </summary>
/// <param name="_strReportTempDirectory">报表临时文件所在的文件夹,服务器的报表JSON数据将临时存储在此文件夹,此文件夹要求能通过URL访问,控件通过文件名下载报表打印所需要的数据</param>
/// <param name="_strReportFileName">报表文件名称,包括绝对路径</param>
public PrintJson(string _strReportTempDirectory, string _strReportFileName)
{
jPrintValue = new JObject();
jaryPrintParam = new JArray();
jButtonHide = new JObject();
jMargin = new JObject();
jDataSetName = new JObject();
jaryPictureSingle = new JArray();
jaryPictureTableValue = new JArray();
jaryPictureTableSet = new JArray();
jaryPrintData = new JArray();
jCookieUrl = new JObject();
this.strReportTempDirectory = _strReportTempDirectory;
if (this.strReportTempDirectory != "")
{
if (strReportTempDirectory.Substring(strReportTempDirectory.Length - 1, 1) != "\\")
{
strReportTempDirectory = strReportTempDirectory + "\\";
}
}
if (!Directory.Exists(strReportTempDirectory))
{
Directory.CreateDirectory(strReportTempDirectory);
}
this.strReportFileName = _strReportFileName;
}
/// <summary>
/// 输入控件注册的信息,检查注册
/// </summary>
/// <param name="_strRegName">控件注册的姓名或公司名称</param>
/// <param name="_strRegValue">控件的注册码</param>
public void CheckRegister(string _strRegName, string _strRegValue)
{
this.strRegName = _strRegName;
this.strRegValue = _strRegValue;
}
/// <summary>
/// 设置控件初始化后,需要上传的Cookie,以及回传的服务器URL
/// 服务端调用控件之前,判断是否有 Cookie(此Cookie为GuId值,保证唯一性,此Cookie的保存时间为10年以上),若有Cookie则在服务端的数据表中查找,判断是否有记录,若有记录,则表示此电脑已经安装过。 若没有记录,或者没有Cookie,则表示未安装过。若没有Cookie则建立一个Cookie。
/// 调用控件时,把此Cookie,还有Cookie回传的服务端的URL传给控件。控件在运行时,把此cookie值回传服务器,服务器把此Cookie写入数据表中,并且更新最后一次回调的时间
/// 浏览器在调用控件之后,可以再启动一个延时(比如延时3秒)函数,以Ajax去访问服务端(参数:Cookie值),服务端去读取数据表的此Cookie的记录,若不存在记录,或最后访问的时间超过了规定时间,则判断为客户机没有安装,提示下载安装。
/// </summary>
/// <param name="strCookie">此Cookie值由服务器生成,最好是GUID,保证唯一性</param>
/// <param name="strServerGetUrl">回传的服务器URL,是Get方式</param>
public void SetCookieAndURL(string strCookie, string strServerGetUrl)
{
if (strCookie != "" && strServerGetUrl.ToLower().Contains("http"))
{
jCookieUrl.Add(new JProperty("Cookie", strCookie));
jCookieUrl.Add(new JProperty("ServerUrl", strServerGetUrl));
}
}
/// <summary>
/// 增加打印的参数
/// </summary>
/// <param name="strKey">参数名</param>
/// <param name="strValue">参数值</param>
public void AddPrintParam(string strKey, string strValue)
{
JObject jParam = new JObject();
jParam.Add(new JProperty("Key", strKey));
jParam.Add(new JProperty("Value", strValue));
jaryPrintParam.Add(jParam);
}
/// <summary>
/// 在线编辑报表时,设置报表的文件名
/// </summary>
/// <param name="strReportFileName"></param>
public void SetReportFileName(string strReportFileName)
{
jPrintValue.Add(new JProperty("ReportFileName", strReportFileName));
}
/// <summary>
/// 在线编辑报表时,设置Web服务器接收保存报表数据的URL
/// 公司版本才有此功能,个人版本无此功能
/// </summary>
/// <param name="strPostUrl"></param>
public void SetPostUrl(string strPostUrl)
{
jPrintValue.Add(new JProperty("PostUrl", strPostUrl));
}
/// <summary>
/// 在报表预览时,点击页面设置按钮,所设置的页面设置信息可通过此URL上传至Web服务器保存
/// </summary>
/// <param name="strPageSetUrl"></param>
public void SetPageSetUrl(string strPageSetUrl)
{
jPrintValue.Add(new JProperty("PageSetUrl", strPageSetUrl));
}
/// <summary>
/// 在报表打印时,在弹出的选择打印机的窗口后点击“确定”按钮时,通过Http的Post方式直接提交到所设置的URL页面,用户可以在URL处理用户已打印的份数
/// </summary>
/// <param name="strPrintUrl"></param>
public void SetPrintUrl(string strPrintUrl)
{
jPrintValue.Add(new JProperty("PrintUrl", strPrintUrl));
}
/// <summary>
/// 指定打印时的打印机名称
/// </summary>
/// <param name="strPrinter"></param>
public void SetPrinter(string strPrinter)
{
jPrintValue.Add(new JProperty("Printer", strPrinter));
}
/// <summary>
/// 报表打印预览窗口隐藏按钮:打印
/// 公司版本才有此功能,个人版本无此功能
/// </summary>
public void IsHideButtonPrint()
{
jButtonHide.Add(new JProperty("pbPrint", false));
}
/// <summary>
/// 报表打印预览窗口隐藏按钮:打开文件
/// 公司版本才有此功能,个人版本无此功能
/// </summary>
public void IsHideButtonLoad()
{
jButtonHide.Add(new JProperty("pbLoad", false));
}
/// <summary>
/// 报表打印预览窗口隐藏按钮:保存
/// 公司版本才有此功能,个人版本无此功能
/// </summary>
public void IsHideButtonSave()
{
jButtonHide.Add(new JProperty("pbSave", false));
}
/// <summary>
/// 报表打印预览窗口隐藏按钮:导出
/// 公司版本才有此功能,个人版本无此功能
/// </summary>
public void IsHideButtonExport()
{
jButtonHide.Add(new JProperty("pbExport", false));
}
/// <summary>
/// 报表打印预览窗口隐藏按钮:放大缩小
/// 公司版本才有此功能,个人版本无此功能
/// </summary>
public void IsHideButtonZoom()
{
jButtonHide.Add(new JProperty("pbZoom", false));
}
/// <summary>
/// 报表打印预览窗口隐藏按钮:查找
/// 公司版本才有此功能,个人版本无此功能
/// </summary>
public void IsHideButtonFind()
{
jButtonHide.Add(new JProperty("pbFind", false));
}
/// <summary>
/// 报表打印预览窗口隐藏按钮:大纲显示
/// 公司版本才有此功能,个人版本无此功能
/// </summary>
public void IsHideButtonOutline()
{
jButtonHide.Add(new JProperty("pbOutline", false));
}
/// <summary>
/// 报表打印预览窗口隐藏按钮:页面设置
/// 公司版本才有此功能,个人版本无此功能
/// </summary>
public void IsHideButtonPageSetup()
{
jButtonHide.Add(new JProperty("pbPageSetup", false));
}
/// <summary>
/// 报表打印预览窗口隐藏按钮:页面导航
/// 公司版本才有此功能,个人版本无此功能
/// </summary>
public void IsHideButtonNavigator()
{
jButtonHide.Add(new JProperty("pbNavigator", false));
}
/// <summary>
/// 报表打印预览窗口隐藏按钮:快速导出
/// 公司版本才有此功能,个人版本无此功能
/// </summary>
public void IsHideButtonExportQuick()
{
jButtonHide.Add(new JProperty("pbExportQuick", false));
}
/// <summary>
/// 设置页面设置的左边距,单位为毫米
/// 公司版本才有此功能,个人版本无此功能
/// </summary>
/// <param name="iMargin"></param>
public void SetLeftMargin(double dbLeftMargin)
{
jMargin.Add(new JProperty("LeftMargin", dbLeftMargin));
}
/// <summary>
/// 设置页面设置的右边距,单位为毫米
/// 公司版本才有此功能,个人版本无此功能
/// </summary>
/// <param name="iMargin"></param>
public void SetRightMargin(int dbRightMargin)
{
jMargin.Add(new JProperty("RightMargin", dbRightMargin));
}
/// <summary>
/// 设置页面设置的上边距,单位为毫米
/// 公司版本才有此功能,个人版本无此功能
/// </summary>
/// <param name="iMargin"></param>
public void SetTopMargin(int dbTopMargin)
{
jMargin.Add(new JProperty("TopMargin", dbTopMargin));
}
/// <summary>
/// 设置页面设置的下边距,单位为毫米
/// 公司版本才有此功能,个人版本无此功能
/// </summary>
/// <param name="iMargin"></param>
public void SetBottomMargin(int dbBottomMargin)
{
jMargin.Add(new JProperty("BottomMargin", dbBottomMargin));
}
/// <summary>
/// 设置数据集1的名称为指定名称(可以是中文)
/// 公司版本才有此功能,个人版本无此功能
/// </summary>
/// <param name="strDataSetName"></param>
public void SetDataSetName1(string strDataSetName)
{
jDataSetName.Add(new JProperty("DataSetName1", strDataSetName));
}
/// <summary>
/// 设置数据集2的名称为指定名称(可以是中文)
/// 公司版本才有此功能,个人版本无此功能
/// </summary>
/// <param name="strDataSetName"></param>
public void SetDataSetName2(string strDataSetName)
{
jDataSetName.Add(new JProperty("DataSetName2", strDataSetName));
}
/// <summary>
/// 设置数据集3的名称为指定名称(可以是中文)
/// 公司版本才有此功能,个人版本无此功能
/// </summary>
/// <param name="strDataSetName"></param>
public void SetDataSetName3(string strDataSetName)
{
jDataSetName.Add(new JProperty("DataSetName3", strDataSetName));
}
/// <summary>
/// 设置数据集4的名称为指定名称(可以是中文)
/// 公司版本才有此功能,个人版本无此功能
/// </summary>
/// <param name="strDataSetName"></param>
public void SetDataSetName4(string strDataSetName)
{
jDataSetName.Add(new JProperty("DataSetName4", strDataSetName));
}
/// <summary>
/// 设置数据集5的名称为指定名称(可以是中文)
/// 公司版本才有此功能,个人版本无此功能
/// </summary>
/// <param name="strDataSetName"></param>
public void SetDataSetName5(string strDataSetName)
{
jDataSetName.Add(new JProperty("DataSetName5", strDataSetName));
}
/// <summary>
/// 设置数据集6的名称为指定名称(可以是中文)
/// 公司版本才有此功能,个人版本无此功能
/// </summary>
/// <param name="strDataSetName"></param>
public void SetDataSetName6(string strDataSetName)
{
jDataSetName.Add(new JProperty("DataSetName6", strDataSetName));
}
/// <summary>
/// 建立数据集的主从关系
/// </summary>
/// <param name="iMasterDataSeq">主数据集序号,通常为1</param>
/// <param name="strFieldName">关联字段名为两个数据集共同的字段名</param>
/// <param name="bIsNumber">关联的字段是否为数值型</param>
public void MasterOptions(int iMasterDataSeq, string strFieldName, bool bIsNumber)
{
JObject jMasterOptions = new JObject();
jMasterOptions.Add(new JProperty("MasterDataSeq", iMasterDataSeq));
jMasterOptions.Add(new JProperty("FieldName", strFieldName));
jMasterOptions.Add(new JProperty("IsNumber", bIsNumber));
jPrintValue.Add("MasterOptions", jMasterOptions);
}
/// <summary>
/// 增加单张图片打印
/// </summary>
/// <param name="strReportObjectName">在报表中的图片对象名称</param>
/// <param name="strPictureFilePath">图片文件的绝对路径,包括最后的\</param>
/// <param name="strPictureFileName">图片文件名称</param>
public void AddPictureSinglePrint(string strReportObjectName, string strPictureFileName, string strPictureFilePath)
{
if (!strPictureFilePath.EndsWith("\\"))
{
strPictureFilePath = strPictureFilePath + "\\";
}
string strFileValue = PrintFunction.FileToString(strPictureFilePath + strPictureFileName);
if (strFileValue != "")
{
JObject jPicture = new JObject();
jPicture.Add(new JProperty("ReportObjectName", strReportObjectName));
jPicture.Add(new JProperty("PictureFileName", strPictureFileName));
jPicture.Add(new JProperty("PictureFileValue", strFileValue));
jaryPictureSingle.Add(jPicture);
}
}
/// <summary>
/// 增加List数据中图片字段所对应的图片打印
/// </summary>
/// <typeparam name="T">List的类名</typeparam>
/// <param name="strReportObjectName">在报表中的图片对象名称</param>
/// <param name="listData">list数据内容</param>
/// <param name="iDataSetIndex">该list中所有数据集的序号,从1开始</param>
/// <param name="strFieldName">图片所在的字段名</param>
/// <param name="strFilePath">图片在服务器上的绝对路径</param>
public void AddPictureIListToPrint<T>(string strReportObjectName, IList<T> listData, int iDataSetIndex, string strFieldName, string strFilePath)
{
//增加图片打印的设置信息
JObject jPictureSet = new JObject();
jPictureSet.Add(new JProperty("ReportObjectName", strReportObjectName));
jPictureSet.Add(new JProperty("DataSetIndex", iDataSetIndex));
jPictureSet.Add(new JProperty("FieldName", strFieldName));
jaryPictureTableSet.Add(jPictureSet);
//利用反射找到图片字段的索引号
Type pDataType = listData[0].GetType();
int iPictureFieldCol = -1;
PropertyInfo[] aryColumnes = pDataType.GetProperties();
for (int iColRecn = 0; iColRecn < aryColumnes.Length; iColRecn++)
{
if (strFieldName.Trim() == aryColumnes[iColRecn].Name.Trim())
{
iPictureFieldCol = iColRecn;
break;
}
}
if (iPictureFieldCol < 0)
{
return;
}
//取各行的图片文件的值,写入JSON数组中
for (int iRowRecn = 0; iRowRecn < listData.Count; iRowRecn++)
{
string strPictureFileName = aryColumnes[iPictureFieldCol].GetValue(listData[iRowRecn], null).ToString();
if (strPictureFileName == "")
{
continue;
}
string strPictureValue = PrintFunction.FileToString(strFilePath + strPictureFileName);
if (strPictureValue != "")
{
JObject jPicture = new JObject();
jPicture.Add(new JProperty("PictureFileName", strPictureFileName));
jPicture.Add(new JProperty("PictureFileValue", strPictureValue));
jaryPictureTableValue.Add(jPicture);
}
}
}
/// <summary>
/// 增加DataTable中图片字段所对应的图片打印
/// </summary>
/// <param name="strReportObjectName">在报表中的图片对象名称</param>
/// <param name="dtTable">Table数据内容</param>
/// <param name="iDataSetIndex">该table中所有数据集的序号,从1开始</param>
/// <param name="strFieldName">图片所在的字段名</param>
/// <param name="strFilePath">图片在服务器上的绝对路径</param>
public void AddPictureTableToPrint(string strReportObjectName, DataTable dtTable, int iDataSetIndex, string strFieldName, string strFilePath)
{
//增加图片打印的设置信息
JObject jPictureSet = new JObject();
jPictureSet.Add(new JProperty("ReportObjectName", strReportObjectName));
jPictureSet.Add(new JProperty("DataSetIndex", iDataSetIndex));
jPictureSet.Add(new JProperty("FieldName", strFieldName));
jaryPictureTableSet.Add(jPictureSet);
//取各行的图片文件的值,写入JSON数组中
if (!strFilePath.EndsWith("\\"))
{
strFilePath = strFilePath + "\\";
}
foreach (DataRow pRow in dtTable.Rows)
{
string strPictureFileName = pRow[strFieldName].ToString().Trim();
if (strPictureFileName == "")
{
continue;
}
string strPictureValue = PrintFunction.FileToString(strFilePath + strPictureFileName);
if (strPictureValue != "")
{
JObject jPicture = new JObject();
jPicture.Add(new JProperty("PictureFileName", strPictureFileName));
jPicture.Add(new JProperty("PictureFileValue", strPictureValue));
jaryPictureTableValue.Add(jPicture);
}
}
}
/// <summary>
/// 增加打印的数据集,数据类型:List
/// </summary>
/// <typeparam name="T">List的类名</typeparam>
/// <param name="listData">list数据内容</param>
public void AddPrintDataIList<T>(IList<T> listData)
{
string strPrintValue = PrintFunction.ListToXml<T>(listData);
if (strPrintValue != "")
{
jaryPrintData.Add(strPrintValue);
}
}
/// <summary>
/// 增加打印的数据集,数据类型:Table
/// </summary>
/// <param name="dtTable">数据内容,此Table需要取得数据结构,即在填充数据集之前,先调用:da.FillSchema(ds, SchemaType.Source);</param>
public void AddPrintDataTable(DataTable dtTable)
{
string strPrintValue = PrintFunction.TableToXml(dtTable);
if (strPrintValue != "")
{
jaryPrintData.Add(strPrintValue);
}
}
/// <summary>
/// 预览报表,在打印之前先调用了 AddPrintDataIList 或 AddPrintDataTable 增加好了数据集
/// </summary>
public string ShowReport()
{
if (jaryPrintData.Count == 0)
{
throw new Exception("没有数据集");
}
jPrintValue.Add(new JProperty("Method", "ShowReport"));
return CallPrint();
}
/// <summary>
/// 预览报表,1个List数据
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="listData"></param>
public string ShowReport<T>(IList<T> listData)
{
AddPrintDataIList<T>(listData);
jPrintValue.Add(new JProperty("Method", "ShowReport"));
return CallPrint();
}
/// <summary>
/// 预览报表:2个List数据
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="S"></typeparam>
/// <param name="listData1"></param>
/// <param name="listData2"></param>
public string ShowReport<T, S>(IList<T> listData1, IList<S> listData2)
{
AddPrintDataIList<T>(listData1);
AddPrintDataIList<S>(listData2);
jPrintValue.Add(new JProperty("Method", "ShowReport"));
return CallPrint();
}
/// <summary>
/// 预览报表:多个Table数据
/// </summary>
/// <param name="dtTable1">此Table需要取得数据结构,即在填充数据集之前,先调用:da.FillSchema(ds, SchemaType.Source);</param>
/// <param name="dtTable2">Table数据,可不填</param>
/// <param name="dtTable3">Table数据,可不填</param>
/// <param name="dtTable4">Table数据,可不填</param>
/// <param name="dtTable5">Table数据,可不填</param>
/// <param name="dtTable6">Table数据,可不填</param>
public string ShowReport(DataTable dtTable1, DataTable dtTable2 = null, DataTable dtTable3 = null, DataTable dtTable4 = null, DataTable dtTable5 = null, DataTable dtTable6 = null)
{
AddPrintDataTable(dtTable1);
if (dtTable2 != null)
{
AddPrintDataTable(dtTable2);
}
if (dtTable3 != null)
{
AddPrintDataTable(dtTable3);
}
if (dtTable4 != null)
{
AddPrintDataTable(dtTable4);
}
if (dtTable5 != null)
{
AddPrintDataTable(dtTable5);
}
if (dtTable6 != null)
{
AddPrintDataTable(dtTable6);
}
jPrintValue.Add(new JProperty("Method", "ShowReport"));
return CallPrint();
}
/// <summary>
/// 打印报表,在打印之前先调用了 AddPrintDataIList 或 AddPrintDataTable 增加好了数据集
/// </summary>
public string PrintReport()
{
if (jaryPrintData.Count == 0)
{
throw new Exception("没有数据集");
}
jPrintValue.Add(new JProperty("Method", "PrintReport"));
return CallPrint();
}
/// <summary>
/// 打印报表,1个List数据
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="listData"></param>
public string PrintReport<T>(IList<T> listData)
{
AddPrintDataIList<T>(listData);
jPrintValue.Add(new JProperty("Method", "PrintReport"));
return CallPrint();
}
/// <summary>
/// 打印报表:2个List数据
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="S"></typeparam>
/// <param name="listData1"></param>
/// <param name="listData2"></param>
public string PrintReport<T, S>(IList<T> listData1, IList<S> listData2)
{
AddPrintDataIList<T>(listData1);
AddPrintDataIList<S>(listData2);
jPrintValue.Add(new JProperty("Method", "PrintReport"));
return CallPrint();
}
/// <summary>
/// 打印报表:多个Table数据
/// </summary>
/// <param name="dtTable1">此Table需要取得数据结构,即在填充数据集之前,先调用:da.FillSchema(ds, SchemaType.Source);</param>
/// <param name="dtTable2">Table数据,可不填</param>
/// <param name="dtTable3">Table数据,可不填</param>
/// <param name="dtTable4">Table数据,可不填</param>
/// <param name="dtTable5">Table数据,可不填</param>
/// <param name="dtTable6">Table数据,可不填</param>
public string PrintReport(DataTable dtTable1, DataTable dtTable2 = null, DataTable dtTable3 = null, DataTable dtTable4 = null, DataTable dtTable5 = null, DataTable dtTable6 = null)
{
AddPrintDataTable(dtTable1);
if (dtTable2 != null)
{
AddPrintDataTable(dtTable2);
}
if (dtTable3 != null)
{
AddPrintDataTable(dtTable3);
}
if (dtTable4 != null)
{
AddPrintDataTable(dtTable4);
}
if (dtTable5 != null)
{
AddPrintDataTable(dtTable5);
}
if (dtTable6 != null)
{
AddPrintDataTable(dtTable6);
}
jPrintValue.Add(new JProperty("Method", "PrintReport"));
return CallPrint();
}
/// <summary>
/// 在线设计报表,在打印之前先调用了 AddPrintDataIList 或 AddPrintDataTable 增加好了数据集
/// </summary>
public string DesignReport()
{
if (jaryPrintData.Count == 0)
{
throw new Exception("没有数据集");
}
jPrintValue.Add(new JProperty("Method", "DesignReport"));
return CallPrint();
}
/// <summary>
/// 在线设计报表,1个List数据
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="listData"></param>
public string DesignReport<T>(IList<T> listData)
{
AddPrintDataIList<T>(listData);
jPrintValue.Add(new JProperty("Method", "DesignReport"));
return CallPrint();
}
/// <summary>
/// 在线设计报表:2个List数据
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="S"></typeparam>
/// <param name="listData1"></param>
/// <param name="listData2"></param>
public string DesignReport<T, S>(IList<T> listData1, IList<S> listData2)
{
AddPrintDataIList<T>(listData1);
AddPrintDataIList<S>(listData2);
jPrintValue.Add(new JProperty("Method", "DesignReport"));
return CallPrint();
}
/// <summary>
/// 在线设计报表:多个Table数据
/// </summary>
/// <param name="dtTable1">此Table需要取得数据结构,即在填充数据集之前,先调用:da.FillSchema(ds, SchemaType.Source);</param>
/// <param name="dtTable2">Table数据,可不填</param>
/// <param name="dtTable3">Table数据,可不填</param>
/// <param name="dtTable4">Table数据,可不填</param>
/// <param name="dtTable5">Table数据,可不填</param>
/// <param name="dtTable6">Table数据,可不填</param>
public string DesignReport(DataTable dtTable1, DataTable dtTable2 = null, DataTable dtTable3 = null, DataTable dtTable4 = null, DataTable dtTable5 = null, DataTable dtTable6 = null)
{
AddPrintDataTable(dtTable1);
if (dtTable2 != null)
{
AddPrintDataTable(dtTable2);
}
if (dtTable3 != null)
{
AddPrintDataTable(dtTable3);
}
if (dtTable4 != null)
{
AddPrintDataTable(dtTable4);
}
if (dtTable5 != null)
{
AddPrintDataTable(dtTable5);
}
if (dtTable6 != null)
{
AddPrintDataTable(dtTable6);
}
jPrintValue.Add(new JProperty("Method", "DesignReport"));
return CallPrint();
}
/// <summary>
/// 导出报表至Pdf文件,在打印之前先调用了 AddPrintDataIList 或 AddPrintDataTable 增加好了数据集
/// 公司版本才有此功能,个人版本无此功能
/// </summary>
/// <param name="strExportPdfFileName">所导出的Pdf文件的绝对路径及文件名;如果为空,则会弹出打开文件的对话框</param>
public string ExportReportPdf(string strExportPdfFileName = "")
{
if (jaryPrintData.Count == 0)
{
throw new Exception("没有数据集");
}
jPrintValue.Add(new JProperty("ExportPdfFileName", strExportPdfFileName));
jPrintValue.Add(new JProperty("Method", "ExportReportPdf"));
return CallPrint();
}
/// <summary>
/// 导出报表至Pdf文件,1个List数据
/// 公司版本才有此功能,个人版本无此功能
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="listData"></param>
/// <param name="strExportPdfFileName">所导出的Pdf文件的绝对路径及文件名;如果为空,则会弹出打开文件的对话框</param>
public string ExportReportPdf<T>(IList<T> listData, string strExportPdfFileName = "")
{
jPrintValue.Add(new JProperty("ExportPdfFileName", strExportPdfFileName));
AddPrintDataIList<T>(listData);
jPrintValue.Add(new JProperty("Method", "ExportReportPdf"));
return CallPrint();
}
/// <summary>
/// 导出报表至Pdf文件:2个List数据
/// 公司版本才有此功能,个人版本无此功能
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="S"></typeparam>
/// <param name="listData1"></param>
/// <param name="listData2"></param>
/// <param name="strExportPdfFileName">所导出的Pdf文件的绝对路径及文件名;如果为空,则会弹出打开文件的对话框</param>
public string ExportReportPdf<T, S>(IList<T> listData1, IList<S> listData2, string strExportPdfFileName = "")
{
jPrintValue.Add(new JProperty("ExportPdfFileName", strExportPdfFileName));
AddPrintDataIList<T>(listData1);
AddPrintDataIList<S>(listData2);
jPrintValue.Add(new JProperty("Method", "ExportReportPdf"));
return CallPrint();
}
/// <summary>
/// 导出报表至Pdf文件:多个Table数据
/// 公司版本才有此功能,个人版本无此功能
/// </summary>
/// <param name="dtTable1">此Table需要取得数据结构,即在填充数据集之前,先调用:da.FillSchema(ds, SchemaType.Source);</param>
/// <param name="dtTable2">Table数据,可不填</param>
/// <param name="dtTable3">Table数据,可不填</param>
/// <param name="dtTable4">Table数据,可不填</param>
/// <param name="dtTable5">Table数据,可不填</param>
/// <param name="dtTable6">Table数据,可不填</param>
/// <param name="strExportPdfFileName">所导出的Pdf文件的绝对路径及文件名;如果为空,则会弹出打开文件的对话框</param>
public string ExportReportPdf(DataTable dtTable1, DataTable dtTable2 = null, DataTable dtTable3 = null, DataTable dtTable4 = null, DataTable dtTable5 = null, DataTable dtTable6 = null, string strExportPdfFileName = "")
{
jPrintValue.Add(new JProperty("ExportPdfFileName", strExportPdfFileName));
AddPrintDataTable(dtTable1);
if (dtTable2 != null)
{
AddPrintDataTable(dtTable2);
}
if (dtTable3 != null)
{
AddPrintDataTable(dtTable3);
}
if (dtTable4 != null)
{
AddPrintDataTable(dtTable4);
}
if (dtTable5 != null)
{
AddPrintDataTable(dtTable5);
}
if (dtTable6 != null)
{
AddPrintDataTable(dtTable6);
}
jPrintValue.Add(new JProperty("Method", "ExportReportPdf"));
return CallPrint();
}
/// <summary>
/// 组织好参数,调用控件进行操作
/// </summary>
/// <param name="strReportFileName">报表文件名,包括绝对路径</param>
private string CallPrint()
{
string strPrintFileName = "";
//取报表文件的内容
string strReportFileValue = PrintFunction.FileToString(this.strReportFileName);
jPrintValue.Add(new JProperty("ReportFileValue", strReportFileValue));
//检查注册信息
JObject jRegInfo = new JObject();
jRegInfo.Add(new JProperty("RegName", this.strRegName));
jRegInfo.Add(new JProperty("RegValue", this.strRegValue));
jPrintValue.Add("RegInfo", jRegInfo);
//报表打印的各参数
jPrintValue.Add("PrintParam", jaryPrintParam);
jPrintValue.Add("ButtonHide", jButtonHide);
jPrintValue.Add("Margin", jMargin);
jPrintValue.Add("DataSetName", jDataSetName);
jPrintValue.Add("PictureSingle", jaryPictureSingle);
jPrintValue.Add("PictureTableValue", jaryPictureTableValue);
jPrintValue.Add("PictureTableSet", jaryPictureTableSet);
jPrintValue.Add("PrintData", jaryPrintData);
jPrintValue.Add("CookieUrl", jCookieUrl);
//把JSON内容写入文件,返回文件名
try
{
string strPrintValue = jPrintValue.ToString(Newtonsoft.Json.Formatting.None);
Random r = new Random();
strPrintFileName = "PrintTemp" + DateTime.Now.ToString("yyyyMMddHHmmss") + r.Next(999999) + ".txt";
string strFileName = this.strReportTempDirectory + strPrintFileName;
if (File.Exists(strFileName))
{
File.Delete(strFileName);
}
FileStream pFileStream = new FileStream(strFileName, System.IO.FileMode.CreateNew);
byte[] byteWrite = Encoding.UTF8.GetBytes(strPrintValue);
pFileStream.Write(byteWrite, 0, byteWrite.Length);
byteWrite = null;
pFileStream.Flush();
pFileStream.Close();
pFileStream.Dispose();
}
catch
{
strPrintFileName = "";
}
return strPrintFileName;
}
}
}