Files
HJGL_DS/HJGL_DS/FineUIPro.Web/HJGL/WeldingManage/JointInfoOut.aspx.cs
T
2026-07-23 15:34:31 +08:00

431 lines
19 KiB
C#

namespace FineUIPro.Web.HJGL.WeldingManage
{
using BLL;
using FastReport.DevComponents.DotNetBar;
using Model;
using NPOI.SS.UserModel;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Text;
using AspNet = System.Web.UI.WebControls;
public partial class JointInfoOut : PageBase
{
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
// 绑定表格
this.BindGrid();
}
}
#endregion
#region
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid()
{
string isoId = Request.Params["ISO_ID"];
if (!string.IsNullOrEmpty(isoId))
{
string strSql = @"SELECT * FROM HJGL_View_JointInfo WHERE ISO_ID='" + isoId + "'";
List<SqlParameter> listStr = new List<SqlParameter>();
//if (!string.IsNullOrEmpty(this.txtCode.Text.Trim()))
//{
// strSql += " AND COM_Code LIKE @COM_Code";
// listStr.Add(new SqlParameter("@COM_Code", "%" + this.txtCode.Text.Trim() + "%"));
//}
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
// 2.获取当前分页数据
//var table = this.GetPagedDataTable(Grid1, tb1);
Grid1.RecordCount = tb.Rows.Count;
//tb = GetFilteredTable(Grid1.FilteredData, tb);
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
}
}
#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_FilterChange(object sender, EventArgs e)
{
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>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnOut_Click(object sender, EventArgs e)
{
Response.ClearContent();
string filename = Funs.GetNewFileName();
Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode("管线焊口信息" + filename, System.Text.Encoding.UTF8) + ".xls");
Response.ContentType = "application/excel";
Response.ContentEncoding = System.Text.Encoding.UTF8;
this.Grid1.PageSize = 100000;
this.BindGrid();
Response.Write(GetGridTableHtml(Grid1));
Response.End();
}
/// <summary>
/// 导出方法
/// </summary>
/// <param name="grid"></param>
/// <returns></returns>
private string GetGridTableHtml(Grid grid)
{
StringBuilder sb = new StringBuilder();
sb.Append("<meta http-equiv=\"content-type\" content=\"application/excel; charset=UTF-8\"/>");
sb.Append("<table cellspacing=\"0\" rules=\"all\" border=\"1\" style=\"border-collapse:collapse;\">");
sb.Append("<tr>");
foreach (GridColumn column in grid.Columns)
{
if (column.HeaderText != "序号")
{
sb.AppendFormat("<td>{0}</td>", column.HeaderText);
}
}
sb.Append("</tr>");
foreach (GridRow row in grid.Rows)
{
sb.Append("<tr>");
foreach (GridColumn column in grid.Columns)
{
string html = row.Values[column.ColumnIndex].ToString();
if (column.ColumnID != "tfNumber")
{
if (column.ColumnID == "BatchCode")
{
sb.AppendFormat("<td style='vnd.ms-excel.numberformat:@;'>{0}</td>", html);
}
else
{
sb.AppendFormat("<td>{0}</td>", html);
}
}
}
sb.Append("</tr>");
}
sb.Append("</table>");
return sb.ToString();
}
#endregion
#region
/// <summary>
/// 按导入模板导出
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnOut2_Click(object sender, EventArgs e)
{
string rootPath = Server.MapPath("~/");
string initTemplatePath = Const.JointInTemplateUrl;
string uploadfilepath = string.Empty;
string newUrl = string.Empty;
uploadfilepath = rootPath + initTemplatePath;
string isoId = Request.QueryString["ISO_ID"] ?? string.Empty;
if (!string.IsNullOrEmpty(isoId))
{
var lists = from x in Funs.DB.HJGL_View_JointInfo
where x.ISO_ID == isoId
select x;
lists = lists.OrderBy(x => x.JOTY_Group).OrderBy(x => x.Sort1).OrderBy(x => x.Sort2).OrderBy(x => x.Sort3).OrderBy(x => x.Sort4).OrderBy(x => x.Sort5);
if (lists != null)
{
newUrl = uploadfilepath.Replace("焊口信息导入模板", "焊口信息");
if (File.Exists(newUrl))
{
File.Delete(newUrl);
}
File.Copy(uploadfilepath, newUrl);
// 第一步:读取文件流
NPOI.SS.UserModel.IWorkbook workbook;
using (FileStream stream = new FileStream(newUrl, FileMode.Open, FileAccess.Read))
{
//workbook = new NPOI.XSSF.UserModel.XSSFWorkbook(stream);
workbook = new NPOI.HSSF.UserModel.HSSFWorkbook(stream);
}
// 创建单元格样式
NPOI.SS.UserModel.ICellStyle cellStyle = workbook.CreateCellStyle();
cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
cellStyle.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
cellStyle.WrapText = true;//自动换行
var font = workbook.CreateFont();
font.FontHeightInPoints = 11;
cellStyle.SetFont(font);
// 第二步:创建新数据行
NPOI.SS.UserModel.ISheet sheet = workbook.GetSheetAt(0);
NPOI.SS.UserModel.IRow row = sheet.GetRow(0);
NPOI.SS.UserModel.ICell cell;
int i = 1;
foreach (var item in lists)
{
// 第二步:创建新数据行
row = sheet.CreateRow(i);
// 添加数据
//施工号
cell = row.CreateCell(0);
cell.CellStyle = cellStyle;
string proCode = string.Empty;
var pro = BLL.Base_ProjectService.GetProjectByProjectId(item.ProjectId);
if (pro != null)
{
proCode = pro.ProjectCode;
}
cell.SetCellValue(proCode);
//管线号
cell = row.CreateCell(1);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.ISO_IsoNo);
//焊口号
cell = row.CreateCell(2);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.JOT_JointNo);
//装置
cell = row.CreateCell(3);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.InstallationName);
//材质一
cell = row.CreateCell(4);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.STE_Name1);
//材质二
cell = row.CreateCell(5);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.STE_Name2);
//焊缝类型
cell = row.CreateCell(6);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.JOTY_Name);
//坡口类型
cell = row.CreateCell(7);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.JST_Name);
//焊口属性
cell = row.CreateCell(8);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.JOT_JointAttribute);
//焊接方法
cell = row.CreateCell(9);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.WME_Name);
//外径
cell = row.CreateCell(10);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.JOT_Dia.HasValue ? item.JOT_Dia.ToString() : "");
//壁厚
cell = row.CreateCell(11);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.JOT_Sch);
//寸径
cell = row.CreateCell(12);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.JOT_Size.HasValue?item.JOT_Size.ToString():"");
//焊接区域
cell = row.CreateCell(13);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.WLO_Code == "F" ? "安装" : "预制");
//组件一
cell = row.CreateCell(14);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.Component1);
//组件二
cell = row.CreateCell(15);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.Component2);
//后热温度
cell = row.CreateCell(16);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.JOT_LastTemp.HasValue ? item.JOT_LastTemp.ToString() : "");
//层间温度
cell = row.CreateCell(17);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.JOT_CellTemp.HasValue ? item.JOT_CellTemp.ToString() : "");
//预热温度
cell = row.CreateCell(18);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.JOT_PrepareTemp.HasValue ? item.JOT_PrepareTemp.ToString() : "");
//焊丝
cell = row.CreateCell(19);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.WeldSilk);
//焊条
cell = row.CreateCell(20);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.WeldMat);
//焊接电流
cell = row.CreateCell(21);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.JOT_Electricity);
//焊接电压
cell = row.CreateCell(22);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.JOT_Voltage);
//是否热处理
cell = row.CreateCell(23);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.IS_Proess == "1" ? "是" : "否");
//热处理类型(是否热处理为‘是’时填写 分别为:预热, 消氢, 后热, 消应力热处理,稳定化处理 填写时请用英文逗号隔开)
cell = row.CreateCell(24);
cell.CellStyle = cellStyle;
string proessTypes = string.Empty;
if (!string.IsNullOrEmpty(item.ProessTypes))
{
foreach (var t in item.ProessTypes.Split('|'))
{
if (t == "1")
{
proessTypes += "预热,";
}
else if (t == "2")
{
proessTypes += "消氢,";
}
else if (t == "3")
{
proessTypes += "后热,";
}
else if (t == "4")
{
proessTypes += "消应力热处理,";
}
else if (t == "5")
{
proessTypes += "稳定化处理,";
}
}
if (!string.IsNullOrEmpty(proessTypes))
{
proessTypes = proessTypes.Substring(0, proessTypes.LastIndexOf(","));
}
}
cell.SetCellValue(proessTypes);
//是否特殊
cell = row.CreateCell(25);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.IsSpecial == true ? "是" : "否");
//探伤比例
cell = row.CreateCell(26);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.NDTR_Name);
//合格等级
cell = row.CreateCell(27);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.JOT_QualifiedLevel);
//硬度合格标准
cell = row.CreateCell(28);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.HardQuaStandard);
//非常焊缝
cell = row.CreateCell(29);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.WeldL.HasValue ? item.WeldL.ToString() : "");
//黄金口(是 / 否)
cell = row.CreateCell(30);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.IsGold == true ? "是" : "否");
//备注
cell = row.CreateCell(31);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.JOT_Remark);
i++;
}
// 第三步:写入文件流
using (FileStream stream = new FileStream(newUrl, FileMode.Create, FileAccess.Write))
{
workbook.Write(stream);
workbook.Close();
}
string fileName = Path.GetFileName(newUrl);
FileInfo info = new FileInfo(newUrl);
long fileSize = info.Length;
Response.Clear();
Response.ContentType = "application/x-zip-compressed";
Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.AddHeader("Content-Length", fileSize.ToString());
Response.TransmitFile(newUrl, 0, fileSize);
Response.Flush();
Response.Close();
File.Delete(newUrl);
}
else
{
Alert.ShowInTop("当前无记录,无法导出!", MessageBoxIcon.Warning);
}
}
}
#endregion
}
}