日期:2014-05-20 浏览次数:20856 次
//载入报表参数
private void ReportInput()
{
DataTable dt = new DataTable();
if ((CheckShop.Checked == true) && (DDLShop.SelectedValue != ""))
{
string shop = DDLShop.SelectedItem.Value.ToString().Trim();
string text = DDLCX.SelectedItem.Value.ToString().Trim();
string value = string.Empty;
if (text == "null")
{
value = null;
}
else
{
value = DDLCon.SelectedItem.Value.ToString().Replace(" 0:00:00", "");
}
dt = service.yyhz(jbtj, "tbl_jiebantongji", "shop_no", shop, text, value);
}
else
{
dt = service.yyhz(jbtj, "tbl_jiebantongji");
}
string reportPath = Server.MapPath("~/Reports/jiebantongji.rpt");
report.Load(reportPath);
report.SetDatabaseLogon("sa", "");
report.SetDataSource(dt);
}
/// <summary>
/// 报表导出功能实现
/// </summary>
protected void btnSave_Click(object sender, EventArgs e)
{
ReportInput();
//导出类型
string contenttype = string.Empty;
//导出的文件类型
string fileType = DDLSaveType.SelectedValue;
//导出的文件路径
string ExportPath;
//导出的文件名称
string FileName;
ExportPath = Request.PhysicalApplicationPath + "报表/" + ReportName.AddDate() + "/";
if (!Directory.Exists(ExportPath))
{
System.IO.Directory.CreateDirectory(Request.PhysicalApplicationPath + "报表/" + ReportName.AddDate() + "/");
}
FileName = "结班统计报表" + ReportName.AddDate();
//FileName = Request.MapPath(".")+"\\报表\\" + ReportName.AddDate() + "\\" + FileName + "." + fileType;
DiskFileDestinationOptions diskFile = new DiskFileDestinationOptions();
//diskFile.DiskFileName = FileName;
//导出为磁盘文件
ExportOptions options = report.ExportOptions;
options.ExportDestinationOptions = diskFile;
options.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
switch (DDLSaveType.SelectedItem.Value)
{
case "pdf":
contenttype = "application/pdf";
options.ExportFormatType = ExportFormatType.PortableDocFormat;
break;
case "doc":
Response.ContentType = "application/ms-word";
options.ExportFormatType = ExportFormatType.WordForWindows;
break;
case "xls":
contenttype = "application/ms-excel";
options.ExportFormatType = ExportFormatType.Excel;
break;
default:
contenttype = "application/ms-excel";
options.ExportFormatType = ExportFormatType.Excel;
break;
}
FileName = FileName + "." + DDLSaveType.SelectedItem.Value;
diskFile.DiskFileName = ExportPath + FileName;
//导出操作
report.Export();
if (MessageBox.Show(null, "数据已保存到服务器,是否下载到本地?", "信息提示:", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1,MessageBoxOptions.ServiceNotification) == DialogResult.Yes)
{
Response.Redirect("DownloadFile.aspx?FileName=" + diskFile.DiskFileName);
}
ReportLoad();
ScriptManager.RegisterClientScriptBlock(UpdatePanel1, this.GetType(), null, "alert('报表已保存到服务器!')", true);
}
------解决方案--------------------