ZHJA_HJGL/HJGL_ZH/FineUIPro.Web/ContinuousPrint/PipingSingleDiagramPrint.as...

867 lines
51 KiB
C#
Raw Normal View History

2024-05-08 17:17:11 +08:00
using BLL;
using NPOI.SS.UserModel;
using NPOI.SS.Util;
using NPOI.XSSF.UserModel;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
namespace FineUIPro.Web.ContinuousPrint
{
public partial class PipingSingleDiagramPrint : PageBase
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGrid();
}
}
#region Grid1
/// <summary>
/// 绑定Grid1
/// </summary>
public void BindGrid()
{
var project = BLL.Base_ProjectService.GetOnProjectListByUserId(this.CurrUser.UserId, "1");
if (!string.IsNullOrEmpty(txtProjectCode.Text))
{
project = project.Where(e => e.ProjectCode.Contains(txtProjectCode.Text.Trim())).ToList();
}
Grid1.RecordCount = project.Count;
var table = this.GetPagedDataTable(Grid1, project);
Grid1.DataSource = table;
Grid1.DataBind();
}
#endregion
#region Grid2
/// <summary>
/// 绑定Grid2
/// </summary>
public void BindGrid1(string ProjectId)
{
string strSql = @"SELECT ProjectId,ISO_ID,STE_ID,SER_ID,SERName,ISO_IsoNo,ISO_TotalDin
,ISO_Insulator,STECode,ISO_Executive,ISO_Specification,ISO_JointQty,IDName
,ISO_DesignPress,ISO_DesignTemperature,ISO_TestPress,ISO_TestTemperature
,ISO_Remark,MaterialStandardId,PressureTestPackageNo,OperatingPressure
,OperatingTemperature,PipeLineClass,PipeLineLength,LeakageTest
,TestCategoryNum,MaterialStandardCode
FROM HJGL_View_IsoInfo WHERE ProjectId= @ProjectId";
List<SqlParameter> listStr = new List<SqlParameter>();
listStr.Add(new SqlParameter("@ProjectId", ProjectId));
SqlParameter[] parameter = listStr.ToArray();
Grid2.DataSource = SQLHelper.GetDataTableRunText(strSql, parameter);
Grid2.DataBind();
Grid2.SelectAllRows();
}
#endregion
#region
/// <summary>
/// 分页
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
Grid1.PageIndex = e.NewPageIndex;
BindGrid();
}
/// <summary>
/// 分页显示条数下拉框
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
BindGrid();
}
/// <summary>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e)
{
Grid1.SortDirection = e.SortDirection;
Grid1.SortField = e.SortField;
BindGrid();
}
#endregion
#region
/// <summary>
/// 选择加载
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_RowClick(object sender, GridRowClickEventArgs e)
{
BindGrid1(this.Grid1.SelectedRowID);
}
#endregion
#region
/// <summary>
/// 关闭窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window1_Close(object sender, EventArgs e)
{
BindGrid();
}
#endregion
#region
/// <summary>
/// 查询
/// </summary>
protected void btnSubmit_Click(object sender, EventArgs e)
{
BindGrid();
}
#endregion
#region 线线
/// <summary>
/// 项目管理管线单线图附页打印
/// </summary>
protected void btnPrint_Click(object sender, EventArgs e)
{
if (Grid2.SelectedRowIndexArray.Length <= 0)
{
Alert.ShowInTop("最少选中一行!", MessageBoxIcon.Warning);
return;
}
string rootPath = Server.MapPath("~/") + Const.ExcelUrl;
//导出文件
string filePath = rootPath + DateTime.Now.ToString("yyyyMMddhhmmss") + "\\";
if (!Directory.Exists(filePath))
{
Directory.CreateDirectory(filePath);
}
string ReportFileName = filePath + "out1.xlsx";
if (Grid2.Rows.Count > 0)
{
int rowIndex = 0;
XSSFWorkbook hssfworkbook = new XSSFWorkbook();
XSSFSheet ws = (XSSFSheet)hssfworkbook.CreateSheet("项目管理管线单线图附页");
#region
ws.SetColumnWidth(0, (10 * 256) + 15);//(9.5)9.55
ws.SetColumnWidth(1, (2 * 256) - 95);//(1.08)1.09
ws.SetColumnWidth(2, (8 * 256) + 50);//(7.58)7.64
ws.SetColumnWidth(3, (8 * 256) + 100);//(7.83)7.82
ws.SetColumnWidth(4, (9 * 256) + 55);//(8.67)8.64
ws.SetColumnWidth(5, (12 * 256) - 15);//(11.33)11.36
ws.SetColumnWidth(6, (12 * 256) - 15);//(11.33)11.36
ws.SetColumnWidth(7, (12 * 256) + 200);//(11.17)11.18
ws.SetColumnWidth(8, (6 * 256) + 100);//(5.83)5.82
ws.SetColumnWidth(9, (3 * 256) - 95);//(2.08)2.09
ws.SetColumnWidth(10, (2 * 256) + 100);//(1.83)1.82
ws.SetColumnWidth(11, (3 * 256) + 55);//(2.67)2.64
ws.SetColumnWidth(12, (3 * 256) + 15);//(2.5)2.55
ws.SetColumnWidth(13, (3 * 256) + 15);//(2.5)2.55
ws.SetColumnWidth(14, (2 * 256) + 55);//(1.67)1.64
#endregion
//图片地址
byte[] bytes = File.ReadAllBytes(Server.MapPath("~/") + "Images\\PrintLog.png");
int pictureIdx = hssfworkbook.AddPicture(bytes, PictureType.JPEG);
for (int gi = 0; gi < Grid2.Rows.Count; gi++)
{
if (Grid2.SelectedRowIndexArray.Contains(gi))
{
System.Web.UI.WebControls.HiddenField hidISO_ID = Grid2.Rows[gi].FindControl("hidISO_ID") as System.Web.UI.WebControls.HiddenField;
#region
var isoId = hidISO_ID.Value;
string v1 = string.Empty;
string v2 = string.Empty;
string v3 = string.Empty;
string v4 = string.Empty;
string v5 = string.Empty;
string v6 = string.Empty;
string v7 = string.Empty;
string v8 = string.Empty;
string v9 = string.Empty;
string v10 = string.Empty;
string v11 = string.Empty;
string v12 = string.Empty;
string v13 = string.Empty;
string v14 = string.Empty;
string v15 = string.Empty;
string v16 = string.Empty;
string ptCount1 = (from x in Funs.DB.HJGL_CH_TrustItem
join y in Funs.DB.HJGL_PW_JointInfo
on x.JOT_ID equals y.JOT_ID
join a in Funs.DB.HJGL_BS_JointType
on y.JOTY_ID equals a.JOTY_ID
join b in Funs.DB.HJGL_CH_Trust
on x.CH_TrustID equals b.CH_TrustID
join c in Funs.DB.HJGL_BS_NDTType
on b.CH_NDTMethod equals c.NDT_ID
where a.JOTY_Group == "2" && y.ISO_ID == isoId && c.NDT_Code == "PT"
select x).Distinct().Count().ToString();
string mtCount1 = (from x in Funs.DB.HJGL_CH_TrustItem
join y in Funs.DB.HJGL_PW_JointInfo
on x.JOT_ID equals y.JOT_ID
join a in Funs.DB.HJGL_BS_JointType
on y.JOTY_ID equals a.JOTY_ID
join b in Funs.DB.HJGL_CH_Trust
on x.CH_TrustID equals b.CH_TrustID
join c in Funs.DB.HJGL_BS_NDTType
on b.CH_NDTMethod equals c.NDT_ID
where a.JOTY_Group == "2" && y.ISO_ID == isoId && c.NDT_Code == "MT"
select x).Distinct().Count().ToString();
if (ptCount1 != "0")
{
v1 = "PT";
v2 = ptCount1;
if (mtCount1 != "0")
{
v3 = "MT";
v4 = mtCount1;
}
}
else
{
if (mtCount1 != "0")
{
v1 = "MT";
v2 = mtCount1;
}
}
string ptCount2 = (from x in Funs.DB.HJGL_CH_TrustItem
join y in Funs.DB.HJGL_PW_JointInfo
on x.JOT_ID equals y.JOT_ID
join a in Funs.DB.HJGL_BS_JointType
on y.JOTY_ID equals a.JOTY_ID
join b in Funs.DB.HJGL_CH_Trust
on x.CH_TrustID equals b.CH_TrustID
join c in Funs.DB.HJGL_BS_NDTType
on b.CH_NDTMethod equals c.NDT_ID
where a.JOTY_Group == "3" && y.ISO_ID == isoId && c.NDT_Code == "PT"
select x).Distinct().Count().ToString();
string mtCount2 = (from x in Funs.DB.HJGL_CH_TrustItem
join y in Funs.DB.HJGL_PW_JointInfo
on x.JOT_ID equals y.JOT_ID
join a in Funs.DB.HJGL_BS_JointType
on y.JOTY_ID equals a.JOTY_ID
join b in Funs.DB.HJGL_CH_Trust
on x.CH_TrustID equals b.CH_TrustID
join c in Funs.DB.HJGL_BS_NDTType
on b.CH_NDTMethod equals c.NDT_ID
where a.JOTY_Group == "3" && y.ISO_ID == isoId && c.NDT_Code == "MT"
select x).Distinct().Count().ToString();
if (ptCount2 != "0")
{
v5 = "PT";
v6 = ptCount2;
if (mtCount1 != "0")
{
v7 = "MT";
v8 = mtCount2;
}
}
else
{
if (mtCount2 != "0")
{
v5 = "MT";
v6 = mtCount2;
}
}
string rtCount3 = (from x in Funs.DB.HJGL_CH_TrustItem
join y in Funs.DB.HJGL_PW_JointInfo
on x.JOT_ID equals y.JOT_ID
join a in Funs.DB.HJGL_BS_JointType
on y.JOTY_ID equals a.JOTY_ID
join b in Funs.DB.HJGL_CH_Trust
on x.CH_TrustID equals b.CH_TrustID
join c in Funs.DB.HJGL_BS_NDTType
on b.CH_NDTMethod equals c.NDT_ID
where a.JOTY_Group == "1" && y.ISO_ID == isoId && c.NDT_Code == "RT"
select x).Distinct().Count().ToString();
string utCount3 = (from x in Funs.DB.HJGL_CH_TrustItem
join y in Funs.DB.HJGL_PW_JointInfo
on x.JOT_ID equals y.JOT_ID
join a in Funs.DB.HJGL_BS_JointType
on y.JOTY_ID equals a.JOTY_ID
join b in Funs.DB.HJGL_CH_Trust
on x.CH_TrustID equals b.CH_TrustID
join c in Funs.DB.HJGL_BS_NDTType
on b.CH_NDTMethod equals c.NDT_ID
where a.JOTY_Group == "1" && y.ISO_ID == isoId && c.NDT_Code == "UT"
select x).Distinct().Count().ToString();
if (rtCount3 != "0")
{
v9 = "RT";
v10 = rtCount3;
if (utCount3 != "0")
{
v11 = "UT";
v12 = utCount3;
}
}
else
{
if (utCount3 != "0")
{
v9 = "UT";
v10 = utCount3;
}
}
string rt4 = "RT";
string rtCount4 = (from x in Funs.DB.HJGL_CH_TrustItem
join y in Funs.DB.HJGL_PW_JointInfo
on x.JOT_ID equals y.JOT_ID
join a in Funs.DB.HJGL_BS_JointType
on y.JOTY_ID equals a.JOTY_ID
join b in Funs.DB.HJGL_CH_Trust
on x.CH_TrustID equals b.CH_TrustID
join c in Funs.DB.HJGL_BS_NDTType
on b.CH_NDTMethod equals c.NDT_ID
where a.JOTY_Group == "1" && y.ISO_ID == isoId && c.NDT_Code == "RT" && y.JOT_JointAttribute == "固定"
select x).Distinct().Count().ToString();
string ut4 = "UT";
string utCount4 = (from x in Funs.DB.HJGL_CH_TrustItem
join y in Funs.DB.HJGL_PW_JointInfo
on x.JOT_ID equals y.JOT_ID
join a in Funs.DB.HJGL_BS_JointType
on y.JOTY_ID equals a.JOTY_ID
join b in Funs.DB.HJGL_CH_Trust
on x.CH_TrustID equals b.CH_TrustID
join c in Funs.DB.HJGL_BS_NDTType
on b.CH_NDTMethod equals c.NDT_ID
where a.JOTY_Group == "1" && y.ISO_ID == isoId && c.NDT_Code == "UT" && y.JOT_JointAttribute == "固定"
select x).Distinct().Count().ToString();
if (rtCount4 != "0")
{
v13 = "RT";
v14 = rtCount4;
if (utCount4 != "0")
{
v15 = "UT";
v16 = utCount4;
}
}
else
{
if (utCount4 != "0")
{
v13 = "UT";
v14 = utCount4;
}
}
#endregion
//列表
var listStr = new List<SqlParameter>();
listStr.Add(new SqlParameter("@iso_id", hidISO_ID.Value));
listStr.Add(new SqlParameter("@Flag", "0"));
SqlParameter[] parameter = listStr.ToArray();
var tb = SQLHelper.GetDataTableRunProc("HJGL_rpt_PipelineAttach", parameter);
//头部
var listTitleStr = new List<SqlParameter>();
listTitleStr.Add(new SqlParameter("@iso_id", hidISO_ID.Value));
SqlParameter[] titleparameter = listTitleStr.ToArray();
var tbTitle = SQLHelper.GetDataTableRunProc("HJGL_rpt_PipelineAttachMain", titleparameter);
if (tb.Rows.Count > 0 && tbTitle.Rows.Count > 0)
{
CellRangeAddress region;
var pageNum =
tb.Rows.Count < 21 ? 1
: (tb.Rows.Count > 21 && tb.Rows.Count < 55) ? 2
: Math.Ceiling((float)(tb.Rows.Count - 55) / 38) + 2;
//公共样式
ICellStyle style = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Center, 10, true);
//无边框文字靠左
ICellStyle leftNoneStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.None, BorderStyle.None, BorderStyle.None, BorderStyle.None, VerticalAlignment.Center, HorizontalAlignment.Left, 10, true);
//无边框文字靠右
ICellStyle rightNoneStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.None, BorderStyle.None, BorderStyle.None, BorderStyle.None, VerticalAlignment.Center, HorizontalAlignment.Right, 10, true);
//头部样式
ICellStyle titleStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Center, 12, true, true, "黑体");
//循环页
for (int i = 1; i <= pageNum; i++)
{
//每页数据开始和结束条数
var dStart = 0;
var dEnd = 0;
//数据开始行和结束行
var tStart = 0;
var tEnd = 0;
#region
//第一页和第二页需要创建头
if (i == 1)
{
//创建头部行和列
ws = ExcelCreateRowTitle(ws, hssfworkbook, rowIndex, rowIndex + 13, style, 0, 14);
//取数据开始和结束条数
dStart = 0;
dEnd = 21;
//数据开始行和结束行
tStart = rowIndex + 14;
tEnd = rowIndex + 34;
#region
//行1
ws.GetRow(rowIndex).GetCell(0).SetCellValue("文件版本:1");
ws.GetRow(rowIndex).GetCell(0).CellStyle = leftNoneStyle;
region = new CellRangeAddress(rowIndex, rowIndex, 8, 14);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex).GetCell(8).SetCellValue("保管期限:5年");
ws.GetRow(rowIndex).GetCell(8).CellStyle = rightNoneStyle;
//行2
region = new CellRangeAddress(rowIndex + 1, rowIndex + 3, 0, 1);
ws.AddMergedRegion(region);
IDrawing patriarch = ws.CreateDrawingPatriarch();
IClientAnchor anchor = patriarch.CreateAnchor(0, 0, 0, 0, 0, rowIndex + 1, 1, rowIndex + 4);
IPicture pict = patriarch.CreatePicture(anchor, pictureIdx);
//pict.Resize();
//行3
region = new CellRangeAddress(rowIndex + 1, rowIndex + 1, 2, 14);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 1).GetCell(2).SetCellValue("中国石油化工股份有限公司镇海炼化分公司管理体系");
region = new CellRangeAddress(rowIndex + 2, rowIndex + 2, 2, 14);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 2).GetCell(2).SetCellValue("项目管理部管道单线图附页");
ws.GetRow(rowIndex + 2).GetCell(2).CellStyle = titleStyle;
//行4
ws.GetRow(rowIndex + 3).GetCell(2).SetCellValue("记录编号");
region = new CellRangeAddress(rowIndex + 3, rowIndex + 3, 3, 5);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 3).GetCell(3).SetCellValue("PMT-T10.326.06.039.2016");
ws.GetRow(rowIndex + 3).GetCell(6).SetCellValue("使用单位");
region = new CellRangeAddress(rowIndex + 3, rowIndex + 3, 7, 14);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 3).GetCell(7).SetCellValue("镇海石化建安工程有限公司");
//行5
ws.GetRow(rowIndex + 4).GetCell(0).SetCellValue("工程名称");
region = new CellRangeAddress(rowIndex + 4, rowIndex + 4, 1, 5);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 4).GetCell(1).SetCellValue(tbTitle.Rows[0]["ProjectName"].ToString());
ws.GetRow(rowIndex + 4).GetCell(6).SetCellValue("管道级别");
region = new CellRangeAddress(rowIndex + 4, rowIndex + 4, 7, 14);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 4).GetCell(7).SetCellValue(tbTitle.Rows[0]["ISC_IsoName"].ToString());
//行6
ws.GetRow(rowIndex + 5).GetCell(0).SetCellValue("单线号");
region = new CellRangeAddress(rowIndex + 5, rowIndex + 5, 1, 3);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 5).GetCell(1).SetCellValue(tbTitle.Rows[0]["ISO_IsoNo"].ToString());
ws.GetRow(rowIndex + 5).GetCell(4).SetCellValue("设计压力");
ws.GetRow(rowIndex + 5).GetCell(5).SetCellValue(tbTitle.Rows[0]["ISO_DesignPress"].ToString());
ws.GetRow(rowIndex + 5).GetCell(6).SetCellValue("管道主规格");
region = new CellRangeAddress(rowIndex + 5, rowIndex + 5, 7, 14);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 5).GetCell(7).SetCellValue(tbTitle.Rows[0]["Specification"].ToString());
//行7
ws.GetRow(rowIndex + 6).GetCell(0).SetCellValue("管道编号");
region = new CellRangeAddress(rowIndex + 6, rowIndex + 6, 1, 3);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 6).GetCell(1).SetCellValue(tbTitle.Rows[0]["ISO_Code"].ToString());
ws.GetRow(rowIndex + 6).GetCell(4).SetCellValue("设计温度");
ws.GetRow(rowIndex + 6).GetCell(5).SetCellValue(tbTitle.Rows[0]["ISO_DesignTemperature"].ToString());
ws.GetRow(rowIndex + 6).GetCell(6).SetCellValue("管道主材质");
region = new CellRangeAddress(rowIndex + 6, rowIndex + 6, 7, 14);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 6).GetCell(7).SetCellValue(tbTitle.Rows[0]["STE_Code"].ToString());
//行8
ws.GetRow(rowIndex + 7).GetCell(0).SetCellValue("检测类别号");
region = new CellRangeAddress(rowIndex + 7, rowIndex + 7, 1, 3);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 7).GetCell(1).SetCellValue(tbTitle.Rows[0]["TestCategoryNum"].ToString());
ws.GetRow(rowIndex + 7).GetCell(4).SetCellValue("验收规范");
ws.GetRow(rowIndex + 7).GetCell(5).SetCellValue(tbTitle.Rows[0]["ExecStandardName"].ToString());
ws.GetRow(rowIndex + 7).GetCell(6).SetCellValue("介质");
region = new CellRangeAddress(rowIndex + 7, rowIndex + 7, 7, 14);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 7).GetCell(7).SetCellValue(tbTitle.Rows[0]["SER_Name"].ToString());
//行9
ws.GetRow(rowIndex + 8).GetCell(0).SetCellValue("焊缝类型");
region = new CellRangeAddress(rowIndex + 8, rowIndex + 8, 1, 3);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 8).GetCell(1).SetCellValue("角焊接头");
region = new CellRangeAddress(rowIndex + 8, rowIndex + 8, 4, 5);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 8).GetCell(4).SetCellValue("支管连接接头");
region = new CellRangeAddress(rowIndex + 8, rowIndex + 8, 6, 7);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 8).GetCell(6).SetCellValue("对焊接头");
region = new CellRangeAddress(rowIndex + 8, rowIndex + 8, 8, 14);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 8).GetCell(8).SetCellValue("其中对焊接头固定口");
//行10
ws.GetRow(rowIndex + 9).GetCell(0).SetCellValue("总焊口数");
region = new CellRangeAddress(rowIndex + 9, rowIndex + 9, 1, 3);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 9).GetCell(1).SetCellValue(tbTitle.Rows[0]["Joty_C_Num"].ToString());
region = new CellRangeAddress(rowIndex + 9, rowIndex + 9, 4, 5);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 9).GetCell(4).SetCellValue(tbTitle.Rows[0]["Joty_D_Num"].ToString());
region = new CellRangeAddress(rowIndex + 9, rowIndex + 9, 6, 7);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 9).GetCell(6).SetCellValue(tbTitle.Rows[0]["Joty_Num"].ToString());
region = new CellRangeAddress(rowIndex + 9, rowIndex + 9, 8, 14);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 9).GetCell(8).SetCellValue(tbTitle.Rows[0]["Joty_G_Num"].ToString());
//行11
ws.GetRow(rowIndex + 10).GetCell(0).SetCellValue("检测比例");
region = new CellRangeAddress(rowIndex + 10, rowIndex + 10, 1, 3);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 10).GetCell(1).SetCellValue(tbTitle.Rows[0]["Joty_C_Rate"].ToString());
region = new CellRangeAddress(rowIndex + 10, rowIndex + 10, 4, 5);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 10).GetCell(4).SetCellValue(tbTitle.Rows[0]["Joty_D_Rate"].ToString());
region = new CellRangeAddress(rowIndex + 10, rowIndex + 10, 6, 7);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 10).GetCell(6).SetCellValue(tbTitle.Rows[0]["JotyRate"].ToString());
region = new CellRangeAddress(rowIndex + 10, rowIndex + 10, 8, 14);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 10).GetCell(8).SetCellValue("40%");
//行12
ws.GetRow(rowIndex + 11).GetCell(0).SetCellValue("检测方法");
region = new CellRangeAddress(rowIndex + 11, rowIndex + 11, 1, 2);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 11).GetCell(1).SetCellValue(v1);
ws.GetRow(rowIndex + 11).GetCell(3).SetCellValue(v3);
ws.GetRow(rowIndex + 11).GetCell(4).SetCellValue(v5);
ws.GetRow(rowIndex + 11).GetCell(5).SetCellValue(v7);
ws.GetRow(rowIndex + 11).GetCell(6).SetCellValue(v9);
ws.GetRow(rowIndex + 11).GetCell(7).SetCellValue(v11);
region = new CellRangeAddress(rowIndex + 11, rowIndex + 11, 8, 9);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 11).GetCell(8).SetCellValue(v13);
region = new CellRangeAddress(rowIndex + 11, rowIndex + 11, 10, 14);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 11).GetCell(10).SetCellValue(v15);
//行13
ws.GetRow(rowIndex + 12).GetCell(0).SetCellValue("实检焊口数");
region = new CellRangeAddress(rowIndex + 12, rowIndex + 12, 1, 2);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 12).GetCell(1).SetCellValue(v2);
ws.GetRow(rowIndex + 12).GetCell(3).SetCellValue(v4);
ws.GetRow(rowIndex + 12).GetCell(4).SetCellValue(v6);
ws.GetRow(rowIndex + 12).GetCell(5).SetCellValue(v8);
ws.GetRow(rowIndex + 12).GetCell(6).SetCellValue(v10);
ws.GetRow(rowIndex + 12).GetCell(7).SetCellValue(v12);
region = new CellRangeAddress(rowIndex + 12, rowIndex + 12, 8, 9);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 12).GetCell(8).SetCellValue(v14);
region = new CellRangeAddress(rowIndex + 12, rowIndex + 12, 10, 14);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 12).GetCell(10).SetCellValue(v16);
//行14
ws.GetRow(rowIndex + 13).GetCell(0).SetCellValue("焊口编号");
region = new CellRangeAddress(rowIndex + 13, rowIndex + 13, 1, 2);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 13).GetCell(1).SetCellValue("焊工号");
ws.GetRow(rowIndex + 13).GetCell(3).SetCellValue("焊接位置");
ws.GetRow(rowIndex + 13).GetCell(4).SetCellValue("焊接时间");
ws.GetRow(rowIndex + 13).GetCell(5).SetCellValue("热处理时间");
ws.GetRow(rowIndex + 13).GetCell(6).SetCellValue("硬度试验时间");
ws.GetRow(rowIndex + 13).GetCell(7).SetCellValue("委托检测时间");
region = new CellRangeAddress(rowIndex + 13, rowIndex + 13, 8, 9);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 13).GetCell(8).SetCellValue("检测结果");
region = new CellRangeAddress(rowIndex + 13, rowIndex + 13, 10, 14);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 13).GetCell(10).SetCellValue("备注");
#endregion
}
else if (i == 2)
{
//创建头部行和列
ws = ExcelCreateRowTitle(ws, hssfworkbook, rowIndex, rowIndex + 5, style, 0, 14, true);
//取数据开始和结束条数
dStart = 21;
dEnd = 52;
//数据开始行和结束行
tStart = rowIndex + 6;
tEnd = rowIndex + 36;
#region ()
//行1
ws.GetRow(rowIndex).GetCell(0).SetCellValue("文件版本:1");
ws.GetRow(rowIndex).GetCell(0).CellStyle = leftNoneStyle;
region = new CellRangeAddress(rowIndex, rowIndex, 8, 14);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex).GetCell(8).SetCellValue("保管期限:5年");
ws.GetRow(rowIndex).GetCell(8).CellStyle = rightNoneStyle;
//行2
region = new CellRangeAddress(rowIndex + 1, rowIndex + 3, 0, 1);
ws.AddMergedRegion(region);
IDrawing patriarch = ws.CreateDrawingPatriarch();
IClientAnchor anchor = patriarch.CreateAnchor(0, 0, 0, 0, 0, rowIndex + 1, 1, rowIndex + 4);
IPicture pict = patriarch.CreatePicture(anchor, pictureIdx);
//pict.Resize();
//行3
region = new CellRangeAddress(rowIndex + 1, rowIndex + 1, 2, 14);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 1).GetCell(2).SetCellValue("中国石油化工股份有限公司镇海炼化分公司管理体系");
region = new CellRangeAddress(rowIndex + 2, rowIndex + 2, 2, 14);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 2).GetCell(2).SetCellValue("管道单线图附页(续)");
ws.GetRow(rowIndex + 2).GetCell(2).CellStyle = titleStyle;
//行4
ws.GetRow(rowIndex + 3).GetCell(2).SetCellValue("记录编号");
region = new CellRangeAddress(rowIndex + 3, rowIndex + 3, 3, 5);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 3).GetCell(3).SetCellValue("PMT-T10.326.06.039.2016");
ws.GetRow(rowIndex + 3).GetCell(6).SetCellValue("使用单位");
region = new CellRangeAddress(rowIndex + 3, rowIndex + 3, 7, 14);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 3).GetCell(7).SetCellValue("镇海石化建安工程有限公司");
//行5
ws.GetRow(rowIndex + 4).GetCell(0).SetCellValue("工程名称");
region = new CellRangeAddress(rowIndex + 4, rowIndex + 4, 1, 5);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 4).GetCell(1).SetCellValue(tbTitle.Rows[0]["ProjectName"].ToString());
ws.GetRow(rowIndex + 4).GetCell(6).SetCellValue("管道级别");
region = new CellRangeAddress(rowIndex + 4, rowIndex + 4, 7, 14);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 4).GetCell(7).SetCellValue(tbTitle.Rows[0]["ISO_IsoNo"].ToString());
//行6
ws.GetRow(rowIndex + 5).GetCell(0).SetCellValue("焊口编号");
region = new CellRangeAddress(rowIndex + 5, rowIndex + 5, 1, 2);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 5).GetCell(1).SetCellValue("焊工号");
ws.GetRow(rowIndex + 5).GetCell(3).SetCellValue("焊接位置");
ws.GetRow(rowIndex + 5).GetCell(4).SetCellValue("焊接时间");
ws.GetRow(rowIndex + 5).GetCell(5).SetCellValue("热处理时间");
ws.GetRow(rowIndex + 5).GetCell(6).SetCellValue("硬度试验时间");
ws.GetRow(rowIndex + 5).GetCell(7).SetCellValue("委托检测时间");
region = new CellRangeAddress(rowIndex + 5, rowIndex + 5, 8, 9);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 5).GetCell(8).SetCellValue("检测结果");
region = new CellRangeAddress(rowIndex + 5, rowIndex + 5, 10, 14);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 5).GetCell(10).SetCellValue("备注");
#endregion
}
else
{
var pNum = (i - 2) * 38;
//取数据开始和结束条数
dStart = 52 + ((i - 3) * 38);
dEnd = 52 + pNum;
//数据开始行和结束行
tStart = rowIndex;
tEnd = rowIndex + 37;
}
#endregion
#region
//创建数据行和列
ws = ExcelCreateRow(ws, hssfworkbook, tStart, tEnd, style, 0, 14);
//获取当前页数据
var pageTb = GetPageToTable(tb, dStart, dEnd);
//遍历数据
for (int j = 0; j < pageTb.Rows.Count; j++)
{
var dataRow = tStart + j;
ws.GetRow(dataRow).GetCell(0).SetCellValue(pageTb.Rows[j]["JOT_JointNo"].ToString());
ws.GetRow(dataRow).GetCell(1).SetCellValue(pageTb.Rows[j]["WED_Code"].ToString());
ws.GetRow(dataRow).GetCell(3).SetCellValue(pageTb.Rows[j]["JOT_Location"].ToString());
ws.GetRow(dataRow).GetCell(4).SetCellValue(pageTb.Rows[j]["JOT_WeldDate"].ToString());
ws.GetRow(dataRow).GetCell(5).SetCellValue(pageTb.Rows[j]["TrustDate"].ToString());
ws.GetRow(dataRow).GetCell(6).SetCellValue(pageTb.Rows[j]["TestDate"].ToString());
ws.GetRow(dataRow).GetCell(7).SetCellValue(pageTb.Rows[j]["CH_TrustDate"].ToString());
ws.GetRow(dataRow).GetCell(8).SetCellValue(pageTb.Rows[j]["IsOK"].ToString());
ws.GetRow(dataRow).GetCell(10).SetCellValue(pageTb.Rows[j]["Remark"].ToString());
}
#endregion
#region
//尾部页码
ws.CreateRow(tEnd + 1);
ws.GetRow(tEnd + 1).HeightInPoints = 16.5f;
//尾部样式
ICellStyle pageStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.None, BorderStyle.None, BorderStyle.None, BorderStyle.None, VerticalAlignment.Center, HorizontalAlignment.Center, 10);
for (int eIndex = 0; eIndex <= 14; eIndex++)
{
ws.GetRow(tEnd + 1).CreateCell(eIndex);
ws.GetRow(tEnd + 1).GetCell(eIndex).CellStyle = pageStyle;
}
ws.GetRow(tEnd + 1).GetCell(9).SetCellValue("第");
ws.GetRow(tEnd + 1).GetCell(10).SetCellValue(i.ToString());
ws.GetRow(tEnd + 1).GetCell(11).SetCellValue("页");
ws.GetRow(tEnd + 1).GetCell(12).SetCellValue("共");
ws.GetRow(tEnd + 1).GetCell(13).SetCellValue(pageNum.ToString());
ws.GetRow(tEnd + 1).GetCell(14).SetCellValue("页");
#endregion
rowIndex = tEnd + 2;
}
}
}
}
ws.SetMargin(MarginType.LeftMargin, 0.2);
ws.SetMargin(MarginType.RightMargin, 0.2);
//ws.SetMargin(MarginType.BottomMargin, 1);
//ws.SetMargin(MarginType.TopMargin, 1);
//ws.SetMargin(MarginType.FooterMargin, 0.5);
//ws.SetMargin(MarginType.HeaderMargin, 0.5);
ws.PrintSetup.Landscape = false;
ws.PrintSetup.PaperSize = 9;
ws.ForceFormulaRecalculation = true;
using (FileStream filess = File.OpenWrite(ReportFileName))
{
hssfworkbook.Write(filess);
}
FileInfo filet = new FileInfo(ReportFileName);
Response.Clear();
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;
// 添加头信息,为"文件下载/另存为"对话框指定默认文件名
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode("项目管理管线单线图附页.xlsx"));
// 添加头信息,指定文件大小,让浏览器能够显示下载进度
Response.AddHeader("Content-Length", filet.Length.ToString());
// 指定返回的是一个不能被客户端读取的流,必须被下载
Response.ContentType = "application/ms-excel";
// 把文件流发送到客户端
Response.WriteFile(filet.FullName);
// 停止页面的执行
Response.End();
}
}
#endregion
#region
/// <summary>
/// 数据行和列
/// </summary>
/// <returns></returns>
private XSSFSheet ExcelCreateRow(XSSFSheet ws, XSSFWorkbook hssfworkbook, int sRows, int eRows, ICellStyle style, int cStart, int cEnd)
{
CellRangeAddress region;
for (int i = sRows; i <= eRows; i++)
{
ws.CreateRow(i);
ws.GetRow(i).HeightInPoints = 18.8f;
for (int j = cStart; j <= cEnd; j++)
{
ws.GetRow(i).CreateCell(j);
ws.GetRow(i).GetCell(j).CellStyle = style;
}
//合并数据
region = new CellRangeAddress(i, i, 1, 2);
ws.AddMergedRegion(region);
region = new CellRangeAddress(i, i, 8, 9);
ws.AddMergedRegion(region);
region = new CellRangeAddress(i, i, 10, 14);
ws.AddMergedRegion(region);
}
return ws;
}
/// <summary>
/// 创建头部
/// </summary>
/// <returns></returns>
private XSSFSheet ExcelCreateRowTitle(XSSFSheet ws, XSSFWorkbook hssfworkbook, int sRows, int eRows, ICellStyle style, int cStart, int cEnd, bool xuTitle = false)
{
var noneStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.None, BorderStyle.None, BorderStyle.None, BorderStyle.None, VerticalAlignment.Center, HorizontalAlignment.Center, 7, true);
for (int i = sRows; i <= eRows; i++)
{
ws.CreateRow(i);
if (xuTitle)
{
ws.GetRow(i).HeightInPoints =
i == sRows ? 16.5f :
i == (sRows + 1) ? 17.3f :
i == (sRows + 2) ? 27.8f :
i == (sRows + 3) ? 20.3f :
i == (sRows + 4) ? 20.3f :
i == (sRows + 5) ? 28.5f :
18.8f;
}
else
{
ws.GetRow(i).HeightInPoints =
i == sRows ? 16.5f :
i == (sRows + 1) ? 18f :
i == (sRows + 2) ? 27.8f :
i == (sRows + 3) ? 20.3f :
i == (sRows + 4) ? 20.3f :
i == (sRows + 5) ? 21.8f :
i == (sRows + 6) ? 28.5f :
i == (sRows + 7) ? 21f :
i == (sRows + 8) ? 24.8f :
i == (sRows + 9) ? 21f :
i == (sRows + 10) ? 21f :
i == (sRows + 11) ? 21.8f :
i == (sRows + 12) ? 21f :
i == (sRows + 13) ? 27f :
18.8f;
}
for (int j = cStart; j <= cEnd; j++)
{
ws.GetRow(i).CreateCell(j);
ws.GetRow(i).GetCell(j).CellStyle = i == sRows ? noneStyle : style;
}
}
return ws;
}
/// <summary>
/// 查询指定条数分页
/// </summary>
/// <returns></returns>
public static DataTable GetPageToTable(DataTable dt, int StartNum, int EndNum)
{
//0页代表每页数据直接返回
if (EndNum == 0) return dt;
//数据源为空返回空DataTable
if (dt == null) return new DataTable();
DataTable newdt = dt.Copy();
newdt.Clear();//copy dt的框架
if (StartNum >= dt.Rows.Count)
return newdt;//源数据记录数小于等于要显示的记录直接返回dt
if (EndNum > dt.Rows.Count)
EndNum = dt.Rows.Count;
for (int i = StartNum; i <= EndNum - 1; i++)
{
DataRow newdr = newdt.NewRow();
DataRow dr = dt.Rows[i];
foreach (DataColumn column in dt.Columns)
{
newdr[column.ColumnName] = dr[column.ColumnName];
}
newdt.Rows.Add(newdr);
}
return newdt;
}
#endregion
}
}