587 lines
33 KiB
C#
587 lines
33 KiB
C#
using BLL;
|
||
using Model;
|
||
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;
|
||
|
||
namespace FineUIPro.Web.YLRQ.EntrustedManagement
|
||
{
|
||
public partial class InspectionCommissionPrint : PageBase
|
||
{
|
||
protected void Page_Load(object sender, EventArgs e)
|
||
{
|
||
if (!IsPostBack)
|
||
{
|
||
BridProjectGrid();
|
||
BindGrid();
|
||
}
|
||
}
|
||
|
||
#region 绑定数据
|
||
|
||
/// <summary>
|
||
/// 绑定项目
|
||
/// </summary>
|
||
public void BridProjectGrid()
|
||
{
|
||
GridProject.DataSource = BLL.Base_ProjectService.GetYlrqProjectListByUserId(this.CurrUser.UserId, "2");
|
||
GridProject.DataBind();
|
||
drpProject.Value = this.CurrUser.LoginProjectId;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 绑定数据
|
||
/// </summary>
|
||
public void BindGrid()
|
||
{
|
||
if (string.IsNullOrEmpty(drpProject.Value))
|
||
{
|
||
Grid1.DataSource = null;
|
||
Grid1.DataBind();
|
||
return;
|
||
}
|
||
|
||
string strSql = @"select a.Id,a.EntrustCode,f.ProjectCode,a.EntrustData,g.Ndt_NdtCode,g.Ndt_NdtrRate,g.Ndt_Level,d.WME_Code,e.JST_Name,g.ndt_TestStandardCode,b.ProjectCode from PV_EntrustRecord as a inner join PV_ManagementMethod as s on s.EntrustId=a.Id left join Base_Project as b on b.ProjectId=a.ProjectId left join HJGL_BS_WeldMethod as d on d.WME_ID=a.WmeId left join HJGL_BS_SlopeType as e on e.JST_ID=a.GrooveType left join Base_Project as f on f.ProjectId=a.ProjectId left join PV_TestMethod as g on g.Ndt_Id=a.NdtId where a.ProjectId=@ProjectId group by a.Id,a.EntrustCode,f.ProjectCode,a.EntrustData,g.Ndt_NdtCode,g.Ndt_NdtrRate,g.Ndt_Level,d.WME_Code,e.JST_Name,g.ndt_TestStandardCode,b.ProjectCode";
|
||
List<SqlParameter> listStr = new List<SqlParameter>();
|
||
listStr.Add(new SqlParameter("@ProjectId", drpProject.Value));
|
||
if (!string.IsNullOrWhiteSpace(txtEntrustCode.Text))
|
||
{
|
||
strSql += " and a.EntrustCode like '%" + txtEntrustCode.Text + "%' ";
|
||
}
|
||
|
||
SqlParameter[] parameter = listStr.ToArray();
|
||
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
|
||
// 2.获取当前分页数据
|
||
Grid1.RecordCount = tb.Rows.Count;
|
||
var table = this.GetPagedDataTable(Grid1, tb);
|
||
Grid1.DataSource = table;
|
||
Grid1.DataBind();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 绑定数据
|
||
/// </summary>
|
||
public void BindGrid1(string entrustId)
|
||
{
|
||
string strSql = @"select a.WeldingId,a.ProjectId,a.WeldingCode,d.STE_Code as STE_Code1,a.TextureMaterial1,e.STE_Code as STE_Code2,a.TextureMaterial2,a.WeldLength,f.JST_Name,a.GrooveType,a.Thickness,a.HeatTreatmentType,a.CreateId,a.CreateTime,a.SortField,c.UserName from PV_WeldInformation as a inner join Base_Project as b on a.ProjectId=b.ProjectId inner join PV_ManagementMethod as m on m.WeldingId=a.WeldingId left join Sys_User as c on c.UserId=a.CreateId left join HJGL_BS_Steel as d on d.STE_ID=a.TextureMaterial1 left join HJGL_BS_Steel as e on e.STE_ID=a.TextureMaterial2 left join HJGL_BS_SlopeType as f on f.JST_ID=a.GrooveType where 1=1 and m.EntrustId=@EntrustId group by a.WeldingId,a.ProjectId,a.WeldingCode,d.STE_Code,a.TextureMaterial1,e.STE_Code,a.TextureMaterial2,a.WeldLength,f.JST_Name,a.GrooveType,a.Thickness,a.HeatTreatmentType,a.CreateId,a.CreateTime,a.SortField,c.UserName ";
|
||
List<SqlParameter> listStr = new List<SqlParameter>();
|
||
listStr.Add(new SqlParameter("@EntrustId", entrustId));
|
||
SqlParameter[] parameter = listStr.ToArray();
|
||
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
|
||
// 2.获取当前分页数据
|
||
Grid2.RecordCount = tb.Rows.Count;
|
||
var table = this.GetPagedDataTable(Grid2, tb);
|
||
Grid2.DataSource = table;
|
||
Grid2.DataBind();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 施工号下拉框
|
||
/// </summary>
|
||
protected void drpProject_TextChanged(object sender, EventArgs e)
|
||
{
|
||
BindGrid();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 委托单号查询
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void txtEntrustCode_TextChanged(object sender, EventArgs e)
|
||
{
|
||
BindGrid();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 热处理类型名称
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
protected string ConvertProessTypes(object ProessTypes)
|
||
{
|
||
string proessTypes = string.Empty;
|
||
if (ProessTypes != null)
|
||
{
|
||
proessTypes = BLL.HJGL_PW_JointInfoService.ConvertProessTypes(ProessTypes.ToString());
|
||
}
|
||
|
||
return proessTypes;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 行点击加载
|
||
/// </summary>
|
||
protected void Grid1_RowClick(object sender, GridRowClickEventArgs e)
|
||
{
|
||
var entrustId = Grid1.DataKeys[e.RowIndex][1].ToString();
|
||
if (!string.IsNullOrEmpty(entrustId))
|
||
{
|
||
BindGrid1(entrustId);
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 分页排序
|
||
|
||
/// <summary>
|
||
/// 页索引改变事件
|
||
/// </summary>
|
||
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
|
||
{
|
||
BindGrid();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 排序
|
||
/// </summary>
|
||
protected void Grid1_Sort(object sender, GridSortEventArgs e)
|
||
{
|
||
BindGrid();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 分页选择下拉改变事件
|
||
/// </summary>
|
||
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
|
||
{
|
||
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
|
||
BindGrid();
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 导出
|
||
|
||
/// <summary>
|
||
/// 导出
|
||
/// </summary>
|
||
protected void btnExport_Click(object sender, EventArgs e)
|
||
{
|
||
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.PV_InspectionCommissionPrint, Const.BtnEntrustPrint))
|
||
{
|
||
if (Grid1.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 (Grid1.Rows.Count > 0)
|
||
{
|
||
int rowIndex = 0;
|
||
XSSFWorkbook hssfworkbook = new XSSFWorkbook();
|
||
XSSFSheet ws = (XSSFSheet)hssfworkbook.CreateSheet("设备及构件焊缝检测委托单");
|
||
|
||
#region 列宽
|
||
|
||
ws.SetColumnWidth(0, (11 * 256));
|
||
ws.SetColumnWidth(1, 4 * 256);
|
||
ws.SetColumnWidth(2, (12 * 256) + 89);
|
||
ws.SetColumnWidth(3, (11 * 256) + 141);
|
||
ws.SetColumnWidth(4, (15 * 256) + 103);
|
||
ws.SetColumnWidth(5, (12 * 256) + 41);
|
||
ws.SetColumnWidth(6, (19 * 256));
|
||
|
||
#endregion
|
||
|
||
for (int gi = 0; gi < Grid1.Rows.Count; gi++)
|
||
{
|
||
if (Grid1.SelectedRowIndexArray.Contains(gi))
|
||
{
|
||
var entrustId = this.Grid1.Rows[gi].DataKeys[1].ToString();
|
||
//修改数据
|
||
PV_EntrustRecord entrustModel = Funs.DB.PV_EntrustRecord.FirstOrDefault(p => p.Id == entrustId);
|
||
if (entrustModel != null)
|
||
{
|
||
entrustModel.IsPrint = 1;
|
||
entrustModel.PrintTime = DateTime.Now.Date;
|
||
entrustModel.PrinterId = this.CurrUser.UserId;
|
||
Funs.DB.SubmitChanges();
|
||
}
|
||
//列头数据
|
||
var titleSql = "select a.Id,a.ProjectId,i.ProjectName,a.EntrustCode,a.EntrustData,b.Ndt_NdtCode,b.Ndt_NdtName,b.Ndt_NdtrRate,b.Ndt_Level,c.WME_Code,d.JST_Code,e.TestStandardCode,e.TestStandardName,g.DetectionTime,h.WeldingCode,i.EquipmentName,i.TagNum from PV_EntrustRecord as a left join PV_TestMethod as b on a.NdtId=b.Ndt_Id left join HJGL_BS_WeldMethod as c on c.WME_ID=a.WmeId left join HJGL_BS_SlopeType as d on d.JST_ID=a.GrooveType left join HJGL_BS_TestStandard as e on e.TestStandardId=a.TestStandardId inner join PV_ManagementMethod as f on f.EntrustId=a.Id left join PV_DetectionTime as g on g.Id=f.DetectionTimeId left join PV_WeldInformation as h on h.WeldingId=f.WeldingId left join Base_Project as i on i.ProjectId=h.ProjectId where 1=1 and a.Id=@Id";
|
||
var titleStr = new List<SqlParameter>();
|
||
titleStr.Add(new SqlParameter("@Id", entrustId));
|
||
SqlParameter[] parameter = titleStr.ToArray();
|
||
var titleTb = SQLHelper.GetSqlDataReaderToDataTable(titleSql, parameter);
|
||
|
||
//列表
|
||
var listSql = "SELECT ROW_NUMBER() OVER(ORDER BY b.WeldingCode) as Number,a.MethodId,a.EntrustId,a.EntrustCode,b.WeldingCode,(select a.pkidStr from(SELECT STUFF((SELECT ',' + convert(VARCHAR, WED_Code) FROM(select Welder.WED_Code from HJGL_BS_Welder as Welder where Welder.WED_ID in (select Id from StrToTable(b.BackingWelderId)))t FOR XML PATH('')), 1, 1, '') AS pkidStr) a)+',' + (select a.pkidStr from(SELECT STUFF((SELECT ',' + convert(VARCHAR, WED_Code) FROM(select Welder.WED_Code from HJGL_BS_Welder as Welder where Welder.WED_ID in (select Id from StrToTable(b.CoverWelderId)))t FOR XML PATH('')), 1, 1, '') AS pkidStr) a) as WelderCode,(CASE WHEN Steel.STE_Code IS NOT NULL AND Steel2.STE_Code IS NOT NULL and Steel.STE_Code != Steel2.STE_Code THEN Steel.STE_Code + '/' + Steel2.STE_Code WHEN Steel.STE_Code IS NOT NULL THEN Steel.STE_Code ELSE ISNULL(Steel2.STE_Code, '') END) AS STE_Code, a.Remarks,b.JointDesc FROM PV_ManagementMethod AS a LEFT JOIN dbo.PV_WeldInformation AS b ON a.WeldingId = b.WeldingId LEFT JOIN dbo.HJGL_BS_Steel AS Steel ON Steel.STE_ID = b.TextureMaterial1 LEFT JOIN dbo.HJGL_BS_Steel AS Steel2 ON Steel2.STE_ID = b.TextureMaterial2 where 1=1 and a.EntrustId=@EntrustId";
|
||
|
||
var listStr = new List<SqlParameter>();
|
||
listStr.Add(new SqlParameter("@EntrustId", entrustId));
|
||
parameter = listStr.ToArray();
|
||
var tb = SQLHelper.GetSqlDataReaderToDataTable(listSql, parameter);
|
||
if (tb.Rows.Count > 0 && entrustModel != null)
|
||
{
|
||
var projectId = titleTb.Rows[0]["ProjectId"].ToString();
|
||
var jcUnit = Funs.DB.View_Common_Project_UnitList.FirstOrDefault(p => p.ProjectId == projectId && p.UnitType.Contains(BLL.Const.UnitType_8));
|
||
|
||
var titIsXu = tb.Rows.Count > 18 ? Math.Ceiling((float)(tb.Rows.Count + 10) / 28) * 28 : 28;
|
||
|
||
//公共样式
|
||
ICellStyle style = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Center, 10.5, true);
|
||
//有边框文字居左
|
||
ICellStyle leftstyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Left, 10.5, true);
|
||
//底部双底虚线
|
||
ICellStyle doubleLinestyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.Double, 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.5, true);
|
||
//无边框文字靠右
|
||
ICellStyle rightNoneStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.None, BorderStyle.None, BorderStyle.None, BorderStyle.None, VerticalAlignment.Center, HorizontalAlignment.Right, 10.5, true);
|
||
//头部样式
|
||
ICellStyle titleStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Center, 16, true, true, "宋体");
|
||
ws = ExcelCreateRow(ws, hssfworkbook, rowIndex, int.Parse((rowIndex + titIsXu).ToString()), style, 0, 6);
|
||
|
||
#region 头部
|
||
|
||
//行1
|
||
CellRangeAddress region = new CellRangeAddress(rowIndex, rowIndex + 2, 0, 1);
|
||
ws.AddMergedRegion(region);
|
||
ws.GetRow(rowIndex).GetCell(0).SetCellValue("SH/T 3543—G339");
|
||
|
||
region = new CellRangeAddress(rowIndex, rowIndex + 2, 2, 4);
|
||
ws.AddMergedRegion(region);
|
||
ws.GetRow(rowIndex).GetCell(2).SetCellValue("设备及构件焊缝检测委托单");
|
||
ws.GetRow(rowIndex).GetCell(2).CellStyle = titleStyle;
|
||
|
||
region = new CellRangeAddress(rowIndex, rowIndex, 5, 6);
|
||
ws.AddMergedRegion(region);
|
||
ws.GetRow(rowIndex).GetCell(5).SetCellValue("工程名称:" + titleTb.Rows[0]["ProjectName"].ToString());
|
||
region = new CellRangeAddress(rowIndex + 1, rowIndex + 2, 5, 6);
|
||
ws.AddMergedRegion(region);
|
||
ws.GetRow(rowIndex + 1).GetCell(5).SetCellValue("单位工程名称:容器");
|
||
|
||
//行2
|
||
region = new CellRangeAddress(rowIndex + 3, rowIndex + 3, 0, 1);
|
||
ws.AddMergedRegion(region);
|
||
ws.GetRow(rowIndex + 3).GetCell(0).SetCellValue("检测单位");
|
||
ws.GetRow(rowIndex + 3).GetCell(0).CellStyle = style;
|
||
|
||
var jcUnitName = string.Empty;
|
||
if (jcUnit != null)
|
||
{
|
||
jcUnitName = jcUnit.UnitName;
|
||
}
|
||
ws.GetRow(rowIndex + 3).GetCell(2).SetCellValue(jcUnitName);
|
||
ws.GetRow(rowIndex + 3).GetCell(2).CellStyle = style;
|
||
|
||
ws.GetRow(rowIndex + 3).GetCell(3).SetCellValue("接收人");
|
||
ws.GetRow(rowIndex + 3).GetCell(3).CellStyle = style;
|
||
|
||
ws.GetRow(rowIndex + 3).GetCell(4).SetCellValue("");
|
||
ws.GetRow(rowIndex + 3).GetCell(4).CellStyle = style;
|
||
|
||
ws.GetRow(rowIndex + 3).GetCell(5).SetCellValue("委托单编号");
|
||
ws.GetRow(rowIndex + 3).GetCell(5).CellStyle = style;
|
||
|
||
ws.GetRow(rowIndex + 3).GetCell(6).SetCellValue(titleTb.Rows[0]["EntrustCode"].ToString());
|
||
ws.GetRow(rowIndex + 3).GetCell(6).CellStyle = style;
|
||
|
||
//行3
|
||
region = new CellRangeAddress(rowIndex + 4, rowIndex + 4, 0, 1);
|
||
ws.AddMergedRegion(region);
|
||
ws.GetRow(rowIndex + 4).GetCell(0).SetCellValue("检件编号");
|
||
ws.GetRow(rowIndex + 4).GetCell(0).CellStyle = style;
|
||
|
||
ws.GetRow(rowIndex + 4).GetCell(2).SetCellValue(titleTb.Rows[0]["TagNum"].ToString());
|
||
ws.GetRow(rowIndex + 4).GetCell(2).CellStyle = style;
|
||
|
||
ws.GetRow(rowIndex + 4).GetCell(3).SetCellValue("检测时机");
|
||
ws.GetRow(rowIndex + 4).GetCell(3).CellStyle = style;
|
||
|
||
ws.GetRow(rowIndex + 4).GetCell(4).SetCellValue(titleTb.Rows[0]["DetectionTime"].ToString());
|
||
ws.GetRow(rowIndex + 4).GetCell(4).CellStyle = style;
|
||
|
||
ws.GetRow(rowIndex + 4).GetCell(5).SetCellValue("检测标准");
|
||
ws.GetRow(rowIndex + 4).GetCell(5).CellStyle = style;
|
||
|
||
ws.GetRow(rowIndex + 4).GetCell(6).SetCellValue(titleTb.Rows[0]["TestStandardCode"].ToString());
|
||
ws.GetRow(rowIndex + 4).GetCell(6).CellStyle = style;
|
||
|
||
//行4
|
||
region = new CellRangeAddress(rowIndex + 5, rowIndex + 5, 0, 1);
|
||
ws.AddMergedRegion(region);
|
||
ws.GetRow(rowIndex + 5).GetCell(0).SetCellValue("检件名称");
|
||
ws.GetRow(rowIndex + 5).GetCell(0).CellStyle = style;
|
||
|
||
ws.GetRow(rowIndex + 5).GetCell(2).SetCellValue(titleTb.Rows[0]["EquipmentName"].ToString());
|
||
ws.GetRow(rowIndex + 5).GetCell(2).CellStyle = style;
|
||
|
||
ws.GetRow(rowIndex + 5).GetCell(3).SetCellValue("焊接方法");
|
||
ws.GetRow(rowIndex + 5).GetCell(3).CellStyle = style;
|
||
|
||
ws.GetRow(rowIndex + 5).GetCell(4).SetCellValue(titleTb.Rows[0]["WME_Code"].ToString());
|
||
ws.GetRow(rowIndex + 5).GetCell(4).CellStyle = style;
|
||
|
||
ws.GetRow(rowIndex + 5).GetCell(5).SetCellValue("合格级别");
|
||
ws.GetRow(rowIndex + 5).GetCell(5).CellStyle = style;
|
||
|
||
ws.GetRow(rowIndex + 5).GetCell(6).SetCellValue(titleTb.Rows[0]["Ndt_Level"].ToString());
|
||
ws.GetRow(rowIndex + 5).GetCell(6).CellStyle = style;
|
||
|
||
//行5
|
||
region = new CellRangeAddress(rowIndex + 6, rowIndex + 6, 0, 1);
|
||
ws.AddMergedRegion(region);
|
||
ws.GetRow(rowIndex + 6).GetCell(0).SetCellValue("检测方法");
|
||
ws.GetRow(rowIndex + 6).GetCell(0).CellStyle = style;
|
||
|
||
ws.GetRow(rowIndex + 6).GetCell(2).SetCellValue(titleTb.Rows[0]["Ndt_NdtCode"].ToString());
|
||
ws.GetRow(rowIndex + 6).GetCell(2).CellStyle = style;
|
||
|
||
ws.GetRow(rowIndex + 6).GetCell(3).SetCellValue("坡口形式");
|
||
ws.GetRow(rowIndex + 6).GetCell(3).CellStyle = style;
|
||
|
||
ws.GetRow(rowIndex + 6).GetCell(4).SetCellValue(titleTb.Rows[0]["JST_Code"].ToString());
|
||
ws.GetRow(rowIndex + 6).GetCell(4).CellStyle = style;
|
||
|
||
ws.GetRow(rowIndex + 6).GetCell(5).SetCellValue("检测比例");
|
||
ws.GetRow(rowIndex + 6).GetCell(5).CellStyle = style;
|
||
|
||
ws.GetRow(rowIndex + 6).GetCell(6).SetCellValue(titleTb.Rows[0]["Ndt_NdtrRate"].ToString() + "%");
|
||
ws.GetRow(rowIndex + 6).GetCell(6).CellStyle = style;
|
||
#endregion
|
||
|
||
#region 表格
|
||
var dataTit = rowIndex + 7;
|
||
//合并单元格
|
||
for (int hb = dataTit; hb <= rowIndex + titIsXu; hb++)
|
||
{
|
||
region = new CellRangeAddress(hb, hb, 0, 1);
|
||
ws.AddMergedRegion(region);
|
||
}
|
||
|
||
//列头
|
||
ws.GetRow(dataTit).GetCell(0).SetCellValue("检测批号");
|
||
ws.GetRow(dataTit).GetCell(2).SetCellValue("焊缝编号");
|
||
ws.GetRow(dataTit).GetCell(3).SetCellValue("焊工号");
|
||
ws.GetRow(dataTit).GetCell(4).SetCellValue("焊缝规格");
|
||
ws.GetRow(dataTit).GetCell(5).SetCellValue("检件材质");
|
||
ws.GetRow(dataTit).GetCell(6).SetCellValue("备注");
|
||
|
||
//数据
|
||
for (int j = 0; j < tb.Rows.Count; j++)
|
||
{
|
||
int dataIndex = dataTit + j + 1;
|
||
ws.GetRow(dataIndex).GetCell(0).SetCellValue(tb.Rows[j]["EntrustCode"].ToString().Replace("-", "/"));
|
||
ws.GetRow(dataIndex).GetCell(2).SetCellValue(tb.Rows[j]["WeldingCode"].ToString());
|
||
var welderCodes = string.Empty;
|
||
if (tb.Rows[j]["WelderCode"] != null)
|
||
{
|
||
var codes = tb.Rows[j]["WelderCode"].ToString().Split(',').Distinct();
|
||
welderCodes = string.Join("/", codes);
|
||
}
|
||
ws.GetRow(dataIndex).GetCell(3).SetCellValue(welderCodes);
|
||
ws.GetRow(dataIndex).GetCell(4).SetCellValue(tb.Rows[j]["JointDesc"].ToString());
|
||
ws.GetRow(dataIndex).GetCell(5).SetCellValue(tb.Rows[j]["STE_Code"].ToString());
|
||
ws.GetRow(dataIndex).GetCell(6).SetCellValue(tb.Rows[j]["Remarks"].ToString());
|
||
}
|
||
#endregion
|
||
|
||
#region 尾部
|
||
var tEnd = int.Parse((rowIndex + titIsXu + 1).ToString());
|
||
//尾部页码
|
||
ws.CreateRow(tEnd);
|
||
ws.GetRow(tEnd).HeightInPoints = 21.8f;
|
||
ws.CreateRow(tEnd + 1);
|
||
ws.GetRow(tEnd + 1).HeightInPoints = 21.8f;
|
||
ws.CreateRow(tEnd + 2);
|
||
ws.GetRow(tEnd + 1).HeightInPoints = 21.8f;
|
||
ws.CreateRow(tEnd + 3);
|
||
ws.GetRow(tEnd + 1).HeightInPoints = 21.8f;
|
||
//上无边框
|
||
ICellStyle topTailStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.None, VerticalAlignment.Center, HorizontalAlignment.Center, 10.5, true, false);
|
||
//下无边框
|
||
ICellStyle bottTailStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.None, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Left, 10.5, true, false);
|
||
//左下无边框
|
||
ICellStyle leftBottTailStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.None, BorderStyle.None, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Left, 10.5, true, false);
|
||
//右下无边框
|
||
ICellStyle rightBottTailStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.None, BorderStyle.Thin, BorderStyle.None, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Left, 10.5, true, false);
|
||
//左上无边框
|
||
ICellStyle leftTopTailStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.None, BorderStyle.Thin, BorderStyle.None, VerticalAlignment.Center, HorizontalAlignment.Left, 10.5, true, false);
|
||
//右上无边框
|
||
ICellStyle rightTopTailStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.None, BorderStyle.None, VerticalAlignment.Center, HorizontalAlignment.Left, 10.5, true, false);
|
||
|
||
//生成列
|
||
for (int eIndex = 0; eIndex <= 6; eIndex++)
|
||
{
|
||
ws.GetRow(tEnd).CreateCell(eIndex);
|
||
ws.GetRow(tEnd + 1).CreateCell(eIndex);
|
||
ws.GetRow(tEnd + 2).CreateCell(eIndex);
|
||
ws.GetRow(tEnd + 3).CreateCell(eIndex);
|
||
}
|
||
//尾部行1
|
||
region = new CellRangeAddress(tEnd, tEnd, 0, 3);
|
||
ws.AddMergedRegion(region);
|
||
region = new CellRangeAddress(tEnd, tEnd, 4, 6);
|
||
ws.AddMergedRegion(region);
|
||
|
||
ws.GetRow(tEnd).GetCell(0).CellStyle =
|
||
ws.GetRow(tEnd).GetCell(1).CellStyle =
|
||
ws.GetRow(tEnd).GetCell(2).CellStyle =
|
||
ws.GetRow(tEnd).GetCell(3).CellStyle =
|
||
ws.GetRow(tEnd).GetCell(4).CellStyle =
|
||
ws.GetRow(tEnd).GetCell(5).CellStyle =
|
||
ws.GetRow(tEnd).GetCell(6).CellStyle = bottTailStyle;
|
||
ws.GetRow(tEnd).GetCell(0).SetCellValue("委托单位:");
|
||
ws.GetRow(tEnd).GetCell(4).SetCellValue("委托人:");
|
||
//尾部行2
|
||
region = new CellRangeAddress(tEnd + 1, tEnd + 1, 0, 3);
|
||
ws.AddMergedRegion(region);
|
||
region = new CellRangeAddress(tEnd + 1, tEnd + 1, 4, 6);
|
||
ws.AddMergedRegion(region);
|
||
ws.GetRow(tEnd + 1).GetCell(0).CellStyle =
|
||
ws.GetRow(tEnd + 1).GetCell(1).CellStyle =
|
||
ws.GetRow(tEnd + 1).GetCell(2).CellStyle =
|
||
ws.GetRow(tEnd + 1).GetCell(3).CellStyle =
|
||
ws.GetRow(tEnd + 1).GetCell(4).CellStyle =
|
||
ws.GetRow(tEnd + 1).GetCell(5).CellStyle =
|
||
ws.GetRow(tEnd + 1).GetCell(6).CellStyle = topTailStyle;
|
||
ws.GetRow(tEnd + 1).GetCell(4).SetCellValue("日期: 年 月 日");
|
||
|
||
#endregion
|
||
|
||
rowIndex += int.Parse((titIsXu + 2).ToString());
|
||
}
|
||
}
|
||
}
|
||
|
||
//ws.SetMargin(MarginType.LeftMargin, 0.7);
|
||
//ws.SetMargin(MarginType.RightMargin, 0.5);
|
||
//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();
|
||
}
|
||
}
|
||
else
|
||
{
|
||
ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
|
||
}
|
||
}
|
||
|
||
#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 = 21.8f;
|
||
for (int j = cStart; j <= cEnd; j++)
|
||
{
|
||
ws.GetRow(i).CreateCell(j);
|
||
ws.GetRow(i).GetCell(j).CellStyle = style;
|
||
}
|
||
}
|
||
return ws;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 创建头部
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
private XSSFSheet ExcelCreateRowTitle(XSSFSheet ws, XSSFWorkbook hssfworkbook, int sRows, int eRows, ICellStyle style, int cStart, int cEnd)
|
||
{
|
||
for (int i = sRows; i <= eRows; i++)
|
||
{
|
||
ws.CreateRow(i);
|
||
ws.GetRow(i).HeightInPoints =
|
||
i == sRows ? 34.5f :
|
||
i == (sRows + 1) ? 23.3f :
|
||
i == (sRows + 2) ? 21.8f :
|
||
i == (sRows + 3) ? 12f :
|
||
i == (sRows + 4) ? 24f :
|
||
i == (sRows + 5) ? 22.5f :
|
||
i == (sRows + 6) ? 22.5f :
|
||
i == (sRows + 7) ? 24f :
|
||
i == (sRows + 8) ? 20.3f :
|
||
21.8f;
|
||
for (int j = cStart; j <= cEnd; j++)
|
||
{
|
||
ws.GetRow(i).CreateCell(j);
|
||
ws.GetRow(i).GetCell(j).CellStyle = 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
|
||
|
||
}
|
||
} |