Files
SGGL_SHJ/SGGL/FineUIPro.Web/HJGL/WeldingManage/WeldAppearanceCheck.aspx.cs
T
lpf 9bc33c3ab7 feat(hjgl): 支持焊前及外观检查记录导出
按当前筛选条件导出检查记录,便于线下查看和汇总。
2026-11-07 15:22:31 +08:00

241 lines
11 KiB
C#

using BLL;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using MiniExcelLibs;
using System.Web;
namespace FineUIPro.Web.HJGL.WeldingManage
{
public partial class WeldAppearanceCheck : PageBase
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindCheckCodes();
BindGrid();
}
}
private void BindCheckCodes()
{
foreach (string checkCode in WeldAppearanceCheckService.GetCheckCodes(CurrUser.LoginProjectId))
{
ddlCheckCode.Items.Add(new FineUIPro.ListItem(checkCode, checkCode));
}
}
private void BindGrid()
{
var result = GetCurrentPageData();
Grid1.RecordCount = result.Item2;
Grid1.DataSource = result.Item1;
Grid1.DataBind();
}
private Tuple<List<Model.WeldAppearanceCheckItem>, int> GetCurrentPageData()
{
return WeldAppearanceCheckService.GetList(CurrUser.LoginProjectId,
(ddlCheckCode.SelectedValue ?? string.Empty).Trim(),
txtPipelineCode.Text.Trim(), txtWeldJointCode.Text.Trim(), ddlQualified.SelectedValue,
Grid1.PageIndex, Grid1.PageSize);
}
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { Grid1.PageIndex = e.NewPageIndex; BindGrid(); }
protected void btnQuery_Click(object sender, EventArgs e) { Grid1.PageIndex = 0; BindGrid(); }
protected void Window1_Close(object sender, WindowCloseEventArgs e) { BindGrid(); }
/// <summary>
/// 将附件地址转换为列表缩略图。
/// </summary>
/// <param name="photoUrl">以逗号分隔的照片地址。</param>
/// <returns>照片缩略图HTML。</returns>
protected string ConvertImageUrlByImage(object photoUrl)
{
if (photoUrl == null || string.IsNullOrWhiteSpace(photoUrl.ToString()))
{
return string.Empty;
}
string html = "<table cellpadding='5' cellspacing='5' style=\"width: 100%\">";
foreach (string item in photoUrl.ToString().Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries))
{
string imageUrl = "../../" + item.Trim().Replace('\\', '/');
html += "<tr><td align='center'><img class='img' width='100' height='100' src='"
+ HttpUtility.HtmlAttributeEncode(imageUrl) + "' alt='外观检测照片' /></td></tr>";
}
return html + "</table>";
}
protected void btnNew_Click(object sender, EventArgs e)
{
if (HasPower(Const.BtnAdd)) PageContext.RegisterStartupScript(Window1.GetShowReference("WeldAppearanceCheckEdit.aspx"));
}
protected void btnEdit_Click(object sender, EventArgs e) { OpenSelectedRecord(); }
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e) { OpenSelectedRecord(); }
protected void btnDelete_Click(object sender, EventArgs e)
{
if (!EnsureSelected() || !HasPower(Const.BtnDelete)) return;
WeldAppearanceCheckService.Delete(Grid1.SelectedRowID);
BindGrid();
}
protected void btnPrint_Click(object sender, EventArgs e)
{
string checkCode = (ddlCheckCode.SelectedValue ?? string.Empty).Trim();
if (string.IsNullOrEmpty(checkCode))
{
Alert.ShowInTop(BLL.UiText.Message("请选择检测编号!"), MessageBoxIcon.Warning);
return;
}
var printResult = WeldAppearanceCheckService.GetList(CurrUser.LoginProjectId, checkCode,
txtPipelineCode.Text.Trim(), txtWeldJointCode.Text.Trim(), ddlQualified.SelectedValue,
0, int.MaxValue);
List<Model.WeldAppearanceCheckItem> printItems = printResult.Item1;
if (printItems.Count == 0)
{
Alert.ShowInTop(BLL.UiText.Message("当前筛选条件没有可打印的焊口记录!"), MessageBoxIcon.Warning);
return;
}
DataTable reportData = CreateReportData(printItems);
var parameters = new Dictionary<string, string>
{
{ "ProjectName", ProjectService.GetProjectNameByProjectId(CurrUser.LoginProjectId) },
{ "CheckCode", checkCode },
{ "NDTMethod", "RT" },
// 报检数量使用本次实际打印的焊口总数,不包含版式补齐的空行。
{ "InspectionCount", printItems.Count.ToString() },
{ "DetectionRate", string.Empty }
};
FastReportService.ResetData();
FastReportService.AddFastreportTable(reportData);
FastReportService.AddFastreportParameter(parameters);
string rootPath = Server.MapPath("~/");
string initTemplatePath = Const.WeldAppearanceCheckReportTemplateUrl;
if (File.Exists(rootPath + initTemplatePath))
{
PageContext.RegisterStartupScript(Window2.GetShowReference(string.Format(
"~/Controls/Fastreport.aspx?ReportPath={0}", rootPath + initTemplatePath)));
}
else
{
Alert.ShowInTop(BLL.UiText.Message("打印模板不存在!"), MessageBoxIcon.Warning);
}
}
protected void btnOut_Click(object sender, EventArgs e)
{
var items = WeldAppearanceCheckService.GetList(CurrUser.LoginProjectId,
(ddlCheckCode.SelectedValue ?? string.Empty).Trim(), txtPipelineCode.Text.Trim(),
txtWeldJointCode.Text.Trim(), ddlQualified.SelectedValue, 0, int.MaxValue).Item1;
if (items.Count == 0)
{
Alert.ShowInTop(BLL.UiText.Message("无数据,无法导出!"), MessageBoxIcon.Warning);
return;
}
var data = items.Select(x => new
{
检测编号 = x.CheckCode,
管线号 = x.PipelineCode,
焊口号 = x.WeldJointCode,
外观是否合格 = x.QualifiedText,
焊缝余高 = x.WeldReinforcement,
焊缝厚度或焊脚尺寸 = x.WeldHeight,
焊角高度 = x.FilletHeight,
焊缝计算厚度 = x.CalculatedThickness,
电流 = x.WeldingCurrent,
电压 = x.WeldingVoltage,
焊缝宽度 = x.WeldWidth,
表面缺陷 = x.SurfaceDefect,
预热温度 = x.PreheatTemperature,
层间温度 = x.InterpassTemperature,
检测人 = x.CheckPersonName,
检测时间 = x.CheckTime,
照片 = x.AttachUrl,
备注 = x.Remark
}).ToList();
using (var stream = new MemoryStream())
{
MiniExcel.SaveAs(stream, data);
Response.Clear();
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("焊接记录.xlsx", System.Text.Encoding.UTF8));
Response.BinaryWrite(stream.ToArray());
Response.End();
}
}
private static DataTable CreateReportData(List<Model.WeldAppearanceCheckItem> items)
{
var table = new DataTable("Data");
table.Columns.Add("RowNumber", typeof(int));
table.Columns.Add("PipelineCode", typeof(string));
table.Columns.Add("WeldJointCode", typeof(string));
table.Columns.Add("WelderCode", typeof(string));
table.Columns.Add("Specification", typeof(string));
table.Columns.Add("MaterialCode", typeof(string));
table.Columns.Add("WeldingLocation", typeof(string));
table.Columns.Add("WeldingMethodCode", typeof(string));
table.Columns.Add("WeldingMaterial", typeof(string));
table.Columns.Add("ItemCode", typeof(string));
table.Columns.Add("BatchCode", typeof(string));
table.Columns.Add("Remark", typeof(string));
const int regularPageRowCount = 14;
const int lastPageRowCount = 12;
int reportRowCount = items.Count <= lastPageRowCount
? lastPageRowCount
: lastPageRowCount + (int)Math.Ceiling((items.Count - lastPageRowCount)
/ (decimal)regularPageRowCount) * regularPageRowCount;
for (int i = 0; i < reportRowCount; i++)
{
if (i < items.Count)
{
Model.WeldAppearanceCheckItem item = items[i];
// 明细字段严格对应检查表模板;物料代码和炉批号当前业务无来源,保持空白待签填。
table.Rows.Add(i + 1, item.PipelineCode, item.WeldJointCode, item.WelderCode,
item.Specification, item.MaterialCode, item.WeldingLocation, item.WeldingMethodCode,
item.WeldingMaterial, string.Empty, string.Empty, item.Remark);
}
else
{
// 普通页显示14行、末页显示12行,不足部分补空行,使签字区紧跟末页数据区。
table.Rows.Add(i + 1, string.Empty, string.Empty, string.Empty, string.Empty,
string.Empty, string.Empty, string.Empty, string.Empty, string.Empty,
string.Empty, string.Empty);
}
}
return table;
}
private void OpenSelectedRecord()
{
if (!EnsureSelected() || !HasPower(Const.BtnModify)) return;
PageContext.RegisterStartupScript(Window1.GetShowReference("WeldAppearanceCheckEdit.aspx?AppearanceCheckId=" + Grid1.SelectedRowID));
}
private bool EnsureSelected()
{
if (Grid1.SelectedRowIndexArray.Length > 0) return true;
Alert.ShowInTop(BLL.UiText.Message("请选择一条记录!"), MessageBoxIcon.Warning);
return false;
}
private bool HasPower(string button)
{
bool hasPower = CommonService.GetAllButtonPowerList(CurrUser.LoginProjectId, CurrUser.PersonId,
Const.HJGL_WeldAppearanceCheckMenuId, button);
if (!hasPower) Alert.ShowInTop(BLL.UiText.Message("您没有这个权限,请与管理员联系!"), MessageBoxIcon.Warning);
return hasPower;
}
}
}