SGGL_SHJ/SGGL/FineUIPro.Web/HJGL/TestPackage/TestPackageDatePrint.aspx.cs

81 lines
3.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using BLL;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace FineUIPro.Web.HJGL.TestPackage
{
public partial class TestPackageDatePrint : PageBase
{
/// <summary>
/// 试压包主键
/// </summary>
public string PTP_ID
{
get
{
return (string)ViewState["PTP_ID"];
}
set
{
ViewState["PTP_ID"] = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
PTP_ID = Request.Params["PTP_ID"];
if (!string.IsNullOrEmpty(PTP_ID))
{
BindGrid();
}
}
}
private void BindGrid()
{
var list = BLL.TestPackagePrintService.GetListByPTP_ID(PTP_ID);
//根据 BLL.TestPackagePrintService.TypeIntMap 和 list 进行左连接,确保所有类型都显示,获取对应的 PrintCount没有的类型 PrintCount 为 0
var result = from type in BLL.TestPackagePrintService.TypeIntMap
join item in list on type.Key equals item.TypeInt into gj
from subitem in gj.DefaultIfEmpty()
select new
{
TypeInt = type.Key,
TypeName = type.Value,
PrintCount = subitem != null ? subitem.PrintCount : 0
};
Grid1.DataSource = result;
Grid1.DataBind();
}
protected void btnPrint_Click(object sender, EventArgs e)
{
Model.PTP_TestPackage updateTestPackage = Funs.DB.PTP_TestPackage.FirstOrDefault(x => x.PTP_ID == PTP_ID);
List<Model.FastReportItem> FastReportItemList = new List<Model.FastReportItem>();
foreach (var item in Grid1.SelectedRowIDArray)
{
var fastReportItem = BLL.TestPackagePrintService.GetFastReportItem(updateTestPackage, item, PTP_ID, this.CurrUser.LoginProjectId);
FastReportItemList.Add(fastReportItem);
TestPackagePrintService.AddPrintCountByTypeInt(PTP_ID, int.Parse(item)); //增加打印次数
}
// 在文件名中加入时间戳例如PTP_ID_2025-09-17-14-30-00.pdf
string timeStamp = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss");
string fileName = $"{PTP_ID}_{timeStamp}.pdf";
string filePath = System.IO.Path.Combine(Funs.RootPath, "FileUpload", fileName);
BLL.FastReportService.ExportMergeReport(FastReportItemList, filePath, "1");
FileInfo info = new FileInfo(filePath);
long fileSize = info.Length;
System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.ContentType = "application/x-zip-compressed";
System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode("试压包资料子类.pdf", System.Text.Encoding.UTF8));
System.Web.HttpContext.Current.Response.AddHeader("Content-Length", fileSize.ToString());
System.Web.HttpContext.Current.Response.TransmitFile(filePath, 0, fileSize);
System.Web.HttpContext.Current.Response.Flush();
System.Web.HttpContext.Current.Response.Close();
}
}
}