feat(hjgl): 支持组件焊口导入和优先匹配

组件与焊口关系需要参与材料匹配、任务生成和出库明细计算。
新增组件焊口导入入口,并允许在材料匹配时手动指定优先组件,
确保按组件范围生成任务单和领料数据。
This commit is contained in:
2026-05-27 12:01:30 +08:00
parent 883493e02e
commit 49d59df7df
13 changed files with 841 additions and 47 deletions
@@ -88,6 +88,8 @@
</f:Button>
<f:Button ID="btnImportQRCode" Text="导入二维码信息" ToolTip="导入二维码信息" Icon="PackageIn" runat="server" OnClick="btnImportQRCode_Click">
</f:Button>
<f:Button ID="btnImportComponentJoint" Text="导入组件焊口信息" ToolTip="导入组件焊口信息" Icon="PackageIn" runat="server" OnClick="btnImportComponentJoint_Click">
</f:Button>
<f:Button ID="btnBatchAdd" Text="批量增加" Icon="TableAdd" Hidden="true"
runat="server" OnClick="btnBatchAdd_Click">
</f:Button>
@@ -653,6 +653,12 @@ if (!string.IsNullOrEmpty(drpFlowingSection.SelectedValue) && drpFlowingSection.
{
PageContext.RegisterStartupScript(Window3.GetShowReference(String.Format("PrePipelineQRCodeIn.aspx?", "导入 - ")));
}
protected void btnImportComponentJoint_Click(object sender, EventArgs e)
{
PageContext.RegisterStartupScript(Window3.GetShowReference(String.Format("PrePipelineComponentJointIn.aspx?", "导入 - ")));
}
protected void btnSinglePreview_Click(object sender, EventArgs e)
{
@@ -239,6 +239,15 @@ namespace FineUIPro.Web.HJGL.PreDesign
/// </remarks>
protected global::FineUIPro.Button btnImportQRCode;
/// <summary>
/// btnImportComponentJoint 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Button btnImportComponentJoint;
/// <summary>
/// btnBatchAdd 控件。
/// </summary>
@@ -0,0 +1,89 @@
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PrePipelineComponentJointIn.aspx.cs" Inherits="FineUIPro.Web.HJGL.PreDesign.PrePipelineComponentJointIn" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<form id="form1" runat="server">
<f:PageManager ID="PageManager1" AutoSizePanelID="SimpleForm1" runat="server" />
<f:Form ID="SimpleForm1" ShowBorder="false" ShowHeader="false" AutoScroll="true"
BodyPadding="10px" runat="server" RedStarPosition="BeforeText" LabelAlign="Right">
<Toolbars>
<f:Toolbar ID="Toolbar2" Position="Top" ToolbarAlign="Right" runat="server">
<Items>
<f:HiddenField ID="hdFileName" runat="server">
</f:HiddenField>
<f:Button ID="btnDownLoad" runat="server" Icon="ApplicationGo" ToolTip="下载模板" Text="下载模板" OnClick="btnDownLoad_Click" EnablePostBack="true" EnableAjax="false">
</f:Button>
<f:ToolbarFill runat="server"></f:ToolbarFill>
<f:Button ID="btnAudit" Icon="ApplicationEdit" runat="server" ToolTip="审核" Text="审核" ValidateForms="SimpleForm1"
OnClick="btnAudit_Click">
</f:Button>
<f:Button ID="btnImport" Icon="ApplicationGet" runat="server" ToolTip="导入" Text="导入" ValidateForms="SimpleForm1"
OnClick="btnImport_Click">
</f:Button>
<f:Button ID="btnSave" Icon="SystemSave" runat="server" ToolTip="提交" Text="提交" ValidateForms="SimpleForm1"
OnClick="btnSave_Click">
</f:Button>
</Items>
</f:Toolbar>
</Toolbars>
<Rows>
<f:FormRow>
<Items>
<f:FileUpload runat="server" ID="fuAttachUrl" EmptyText="选择要导入的文件" Label="选择要导入的文件"
LabelWidth="150px">
</f:FileUpload>
</Items>
</f:FormRow>
<f:FormRow>
<Items>
<f:Grid ID="Grid1" ShowBorder="true" ShowHeader="false" Title="组件焊口信息"
EnableCollapse="true" runat="server" BoxFlex="1" DataKeyNames="WeldJointId" AllowCellEditing="true"
AllowColumnLocking="true" EnableColumnLines="true" ClicksToEdit="2" DataIDField="WeldJointId"
AllowSorting="true" SortField="PipelineCode" SortDirection="ASC"
AllowPaging="true" IsDatabasePaging="true" PageSize="15"
EnableTextSelection="True">
<Columns>
<f:RowNumberField EnablePagingNumber="true" HeaderText="序号"
Width="60px" HeaderTextAlign="Center" TextAlign="Center" />
<f:RenderField Width="180px" ColumnID="PipelineCode" DataField="PipelineCode" SortField="PipelineCode"
FieldType="String" HeaderText="管线号" HeaderTextAlign="Center"
TextAlign="Left">
</f:RenderField>
<f:RenderField Width="200px" ColumnID="PipelineComponentCode" DataField="PipelineComponentCode" SortField="PipelineComponentCode"
FieldType="String" HeaderText="预制组件" HeaderTextAlign="Center"
TextAlign="Left">
</f:RenderField>
<f:RenderField Width="200px" ColumnID="WeldJointCode" DataField="WeldJointCode" SortField="WeldJointCode"
FieldType="String" HeaderText="焊口号" HeaderTextAlign="Center"
TextAlign="Left">
</f:RenderField>
</Columns>
<PageItems>
<f:ToolbarSeparator ID="ToolbarSeparator1" runat="server">
</f:ToolbarSeparator>
<f:ToolbarText ID="ToolbarText1" runat="server" Text="每页记录数:">
</f:ToolbarText>
<f:DropDownList runat="server" ID="ddlPageSize" Width="80px" AutoPostBack="true"
OnSelectedIndexChanged="ddlPageSize_SelectedIndexChanged">
<f:ListItem Text="10" Value="10" />
<f:ListItem Text="15" Value="15" />
<f:ListItem Text="20" Value="20" />
<f:ListItem Text="25" Value="25" />
<f:ListItem Text="所有行" Value="10000" />
</f:DropDownList>
</PageItems>
</f:Grid>
</Items>
</f:FormRow>
</Rows>
</f:Form>
</form>
</body>
</html>
@@ -0,0 +1,336 @@
using BLL;
using MiniExcelLibs;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
namespace FineUIPro.Web.HJGL.PreDesign
{
public partial class PrePipelineComponentJointIn : PageBase
{
private string initPath = Const.ExcelUrl;
public static List<ComponentJointImportItem> ComponentJointList = new List<ComponentJointImportItem>();
public static string errorInfos = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.hdFileName.Text = string.Empty;
if (ComponentJointList != null)
{
ComponentJointList.Clear();
}
errorInfos = string.Empty;
}
}
protected void btnAudit_Click(object sender, EventArgs e)
{
try
{
if (this.fuAttachUrl.HasFile == false)
{
ShowNotify("请您选择Excel文件!", MessageBoxIcon.Warning);
return;
}
string isXls = Path.GetExtension(this.fuAttachUrl.FileName).ToString().Trim().ToLower();
if (isXls != ".xlsx")
{
ShowNotify("只可以选择Excel文件!", MessageBoxIcon.Warning);
return;
}
ComponentJointList.Clear();
errorInfos = string.Empty;
string rootPath = Server.MapPath("~/");
string initFullPath = rootPath + initPath;
if (!Directory.Exists(initFullPath))
{
Directory.CreateDirectory(initFullPath);
}
this.hdFileName.Text = BLL.Funs.GetNewFileName() + isXls;
string filePath = initFullPath + this.hdFileName.Text;
this.fuAttachUrl.PostedFile.SaveAs(filePath);
ImportXlsToData(filePath);
}
catch (Exception ex)
{
Alert alert = new Alert
{
Message = "'" + ex.Message + "'",
Target = Target.Self
};
alert.Show();
}
}
private void ImportXlsToData(string fileName)
{
var rows = MiniExcel.QueryAsDataTable(fileName, useHeaderRow: true);
Model.ResponeData responeData = AddDatasetToSQL(rows, 3);
if (responeData.code == 1)
{
ShowNotify("审核完成,请点击导入!", MessageBoxIcon.Success);
}
else
{
Alert alert = new Alert
{
Message = responeData.message,
Target = Target.Self
};
alert.Show();
}
}
private Model.ResponeData AddDatasetToSQL(DataTable pds, int cols)
{
Model.ResponeData responeData = new Model.ResponeData();
List<string> result = new List<string>();
if (pds == null)
{
responeData.code = 0;
responeData.message = "导入数据为空!";
return responeData;
}
int ic = pds.Columns.Count;
int ir = pds.Rows.Count;
if (ic < cols || !pds.Columns.Contains("管线号") || !pds.Columns.Contains("预制组件") || !pds.Columns.Contains("焊口号"))
{
responeData.code = 0;
responeData.message = "导入Excel格式错误!模板列必须包含:管线号、预制组件、焊口号";
return responeData;
}
if (ir == 0)
{
responeData.code = 0;
responeData.message = "导入数据为空!";
return responeData;
}
var getPipeline = from x in Funs.DB.HJGL_Pipeline where x.ProjectId == this.CurrUser.LoginProjectId select x;
List<ComponentJointImportItem> importItems = new List<ComponentJointImportItem>();
for (int i = 0; i < ir; i++)
{
string pipelineCode = GetCellValue(pds.Rows[i], "管线号");
string pipelineComponentCode = GetCellValue(pds.Rows[i], "预制组件");
string weldJointCode = GetCellValue(pds.Rows[i], "焊口号");
if (string.IsNullOrEmpty(pipelineCode) && string.IsNullOrEmpty(pipelineComponentCode) && string.IsNullOrEmpty(weldJointCode))
{
continue;
}
if (string.IsNullOrEmpty(pipelineCode))
{
result.Add("第" + (i + 2).ToString() + "行,管线号,此项为必填项!");
continue;
}
if (string.IsNullOrEmpty(pipelineComponentCode))
{
result.Add("第" + (i + 2).ToString() + "行,预制组件,此项为必填项!");
continue;
}
if (string.IsNullOrEmpty(weldJointCode))
{
result.Add("第" + (i + 2).ToString() + "行,焊口号,此项为必填项!");
continue;
}
var pipeline = getPipeline.FirstOrDefault(x => x.PipelineCode == pipelineCode);
if (pipeline == null)
{
result.Add("第" + (i + 2).ToString() + "行,不存在此管线号-" + pipelineCode);
continue;
}
var pipelineComponent = HJGL_PipelineComponentService.GetPipelineComponentByCodeandpipelineId(pipelineComponentCode, pipeline.PipelineId);
if (pipelineComponent == null)
{
result.Add("第" + (i + 2).ToString() + "行,不存在此预制组件-" + pipelineComponentCode);
continue;
}
var weldJoint = WeldJointService.GetWeldJointsByWeldJointCode(pipeline.PipelineId, weldJointCode);
if (weldJoint == null)
{
result.Add("第" + (i + 2).ToString() + "行,不存在此焊口号-" + weldJointCode);
continue;
}
importItems.Add(new ComponentJointImportItem
{
PipelineId = pipeline.PipelineId,
PipelineCode = pipeline.PipelineCode,
PipelineComponentId = pipelineComponent.PipelineComponentId,
PipelineComponentCode = pipelineComponent.PipelineComponentCode,
WeldJointId = weldJoint.WeldJointId,
WeldJointCode = weldJoint.WeldJointCode
});
}
var conflictWeldJoints = importItems
.GroupBy(x => x.WeldJointId)
.Where(x => x.Select(y => y.PipelineComponentId).Distinct().Count() > 1)
.Select(x => x.First().PipelineCode + "-" + x.First().WeldJointCode)
.ToList();
if (conflictWeldJoints.Count > 0)
{
result.Add("同一焊口不能导入到多个组件:" + string.Join("、", conflictWeldJoints));
}
if (result.Count > 0)
{
ComponentJointList.Clear();
errorInfos = string.Join("|", result.Distinct());
responeData.code = 0;
responeData.message = errorInfos;
return responeData;
}
ComponentJointList = importItems
.GroupBy(x => new { x.PipelineComponentId, x.WeldJointId })
.Select(x => x.First())
.ToList();
errorInfos = string.Empty;
responeData.code = ComponentJointList.Count > 0 ? 1 : 0;
responeData.message = ComponentJointList.Count > 0 ? string.Empty : "导入数据为空!";
return responeData;
}
protected void btnImport_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(errorInfos))
{
if (!string.IsNullOrEmpty(this.hdFileName.Text))
{
if (ComponentJointList.Count > 0)
{
this.Grid1.Hidden = false;
this.Grid1.DataIDField = "WeldJointId";
this.Grid1.DataSource = ComponentJointList;
this.Grid1.DataBind();
Grid1.RecordCount = ComponentJointList.Count;
}
}
else
{
ShowNotify("请先审核要导入的文件!", MessageBoxIcon.Warning);
}
}
else
{
ShowNotify("请先将错误数据修正,再重新导入提交!", MessageBoxIcon.Warning);
}
}
protected void btnSave_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(errorInfos))
{
ShowNotify("请先将错误数据修正,再重新导入提交!", MessageBoxIcon.Warning);
return;
}
if (ComponentJointList.Count > 0)
{
foreach (var item in ComponentJointList)
{
var componentJoint = BLL.HJGL_PipelineComponentjointService.GetHJGL_Pipeline_ComponentJointByWeldJointId(item.WeldJointId);
if (componentJoint != null)
{
componentJoint.PipelineComponentCode = item.PipelineComponentCode;
componentJoint.PipelineComponentId = item.PipelineComponentId;
componentJoint.WeldJointCode = item.WeldJointCode;
componentJoint.WeldJointId = item.WeldJointId;
HJGL_PipelineComponentjointService.UpdateHJGL_Pipeline_ComponentJoint(componentJoint);
}
else
{
Model.HJGL_Pipeline_ComponentJoint newComponentJoint = new Model.HJGL_Pipeline_ComponentJoint();
newComponentJoint.Id = SQLHelper.GetNewID();
newComponentJoint.PipelineComponentCode = item.PipelineComponentCode;
newComponentJoint.PipelineComponentId = item.PipelineComponentId;
newComponentJoint.WeldJointCode = item.WeldJointCode;
newComponentJoint.WeldJointId = item.WeldJointId;
newComponentJoint.State = 0;
HJGL_PipelineComponentjointService.AddHJGL_Pipeline_ComponentJoint(newComponentJoint);
}
}
}
string rootPath = Server.MapPath("~/");
string filePath = rootPath + initPath + this.hdFileName.Text;
if (filePath != string.Empty && System.IO.File.Exists(filePath))
{
System.IO.File.Delete(filePath);
}
ShowNotify("导入成功!", MessageBoxIcon.Success);
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
protected void btnDownLoad_Click(object sender, EventArgs e)
{
string rootPath = Server.MapPath("~/");
string tempDirectory = rootPath + @"File\Excel\Temp\";
if (!Directory.Exists(tempDirectory))
{
Directory.CreateDirectory(tempDirectory);
}
string tempPath = tempDirectory + "组件焊口信息导入模板" + string.Format("{0:yyyyMMddHHmmss}", DateTime.Now) + ".xlsx";
DataTable template = new DataTable();
template.Columns.Add("管线号");
template.Columns.Add("预制组件");
template.Columns.Add("焊口号");
MiniExcel.SaveAs(tempPath, template);
FileInfo info = new FileInfo(tempPath);
long fileSize = info.Length;
Response.ClearContent();
Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode("组件焊口信息导入模板.xlsx", System.Text.Encoding.UTF8));
Response.ContentType = "excel/plain";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AddHeader("Content-Length", fileSize.ToString().Trim());
Response.TransmitFile(tempPath, 0, fileSize);
Response.Flush();
Response.Close();
File.Delete(tempPath);
}
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
this.Grid1.DataSource = ComponentJointList;
this.Grid1.DataBind();
Grid1.RecordCount = ComponentJointList.Count;
}
private string GetCellValue(DataRow row, string columnName)
{
return Convert.ToString(row[columnName]).Replace("\n", "").Replace(" ", "").Replace("\t", "").Replace("\r", "").Trim();
}
public class ComponentJointImportItem
{
public string PipelineId { get; set; }
public string PipelineCode { get; set; }
public string PipelineComponentId { get; set; }
public string PipelineComponentCode { get; set; }
public string WeldJointId { get; set; }
public string WeldJointCode { get; set; }
}
}
}
@@ -0,0 +1,143 @@
//------------------------------------------------------------------------------
// <自动生成>
// 此代码由工具生成。
//
// 对此文件的更改可能导致不正确的行为,如果
// 重新生成代码,则所做更改将丢失。
// </自动生成>
//------------------------------------------------------------------------------
namespace FineUIPro.Web.HJGL.PreDesign
{
public partial class PrePipelineComponentJointIn
{
/// <summary>
/// form1 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::System.Web.UI.HtmlControls.HtmlForm form1;
/// <summary>
/// PageManager1 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.PageManager PageManager1;
/// <summary>
/// SimpleForm1 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Form SimpleForm1;
/// <summary>
/// Toolbar2 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Toolbar Toolbar2;
/// <summary>
/// hdFileName 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.HiddenField hdFileName;
/// <summary>
/// btnDownLoad 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Button btnDownLoad;
/// <summary>
/// btnAudit 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Button btnAudit;
/// <summary>
/// btnImport 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Button btnImport;
/// <summary>
/// btnSave 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Button btnSave;
/// <summary>
/// fuAttachUrl 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.FileUpload fuAttachUrl;
/// <summary>
/// Grid1 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Grid Grid1;
/// <summary>
/// ToolbarSeparator1 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.ToolbarSeparator ToolbarSeparator1;
/// <summary>
/// ToolbarText1 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.ToolbarText ToolbarText1;
/// <summary>
/// ddlPageSize 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.DropDownList ddlPageSize;
}
}