This commit is contained in:
2024-10-22 21:13:56 +08:00
parent cb13fe481d
commit e680580417
25 changed files with 2099 additions and 312 deletions
@@ -0,0 +1,36 @@
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ImportError.aspx.cs" Inherits="FineUIPro.Web.WeldingProcess.PMI.ImportError" %>
<!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>PMI导入错误日志</title>
</head>
<body>
<form id="form1" runat="server">
<f:PageManager ID="PageManager1" AutoSizePanelID="Grid1" runat="server" />
<f:Grid ID="Grid1" ShowBorder="true" ShowHeader="false" Title="试压包导入错误日志" runat="server" EnableCollapse="false"
DataKeyNames="ID" EnableCheckBoxSelect="true" EnableMultiSelect="true" PageSize="100" AllowPaging="true">
<Columns>
<f:RowNumberField />
<f:RenderField ColumnID="batchNo" Width="160px" DataField="BatchNo" HeaderText="批次号" />
<f:RenderField ColumnID="TestPackageNo" MinWidth="80" DataField="TestPackageNo" HeaderText="委托编号" />
<f:RenderField ColumnID="UnitCode" MinWidth="80" DataField="UnitCode" HeaderText="单位代码" />
<f:RenderField ColumnID="InstallCode" MinWidth="80" DataField="InstallCode" HeaderText="装置编号" />
<f:RenderField ColumnID="AreaCode" MinWidth="80" DataField="AreaCode" HeaderText="区域" />
<f:RenderField ColumnID="PiplineCode" MinWidth="160" DataField="PiplineCode" HeaderText="管线号" />
<f:RenderField ColumnID="JointCode" MinWidth="200" DataField="JointCode" HeaderText="焊口编号" />
<f:TemplateField MinWidth="200" HeaderText="错误原因">
<ItemTemplate>
<asp:Label ID="lablRemark" runat="server" Text='<%#Eval("Remark") %>' ForeColor="Red"></asp:Label>
</ItemTemplate>
</f:TemplateField>
<f:RenderField ColumnID="CreatedTime" MinWidth="150" DataField="CreatedTime" HeaderText="导入时间" />
</Columns>
</f:Grid>
</form>
</body>
</html>
@@ -0,0 +1,29 @@
using BLL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace FineUIPro.Web.WeldingProcess.PMI
{
public partial class ImportError : PageBase
{
string batchNo = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
this.batchNo = Request.Params["batchNo"];
if (!IsPostBack)
{
BindGrid();
}
}
void BindGrid()
{
var list = Funs.DB.PMI_ImportErrorLog.Where(t => t.BatchNo == batchNo).OrderBy(t => t.RowId).ToList();
this.Grid1.DataSource = list;
this.Grid1.DataBind();
}
}
}
@@ -0,0 +1,53 @@
//------------------------------------------------------------------------------
// <自动生成>
// 此代码由工具生成。
//
// 对此文件的更改可能导致不正确的行为,如果
// 重新生成代码,则所做更改将丢失。
// </自动生成>
//------------------------------------------------------------------------------
namespace FineUIPro.Web.WeldingProcess.PMI
{
public partial class ImportError
{
/// <summary>
/// form1 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::System.Web.UI.HtmlControls.HtmlForm form1;
/// <summary>
/// PageManager1 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.PageManager PageManager1;
/// <summary>
/// Grid1 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Grid Grid1;
/// <summary>
/// lablRemark 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::System.Web.UI.WebControls.Label lablRemark;
}
}
@@ -38,8 +38,17 @@
<Toolbars>
<f:Toolbar ID="Toolbar2" Position="Top" runat="server" ToolbarAlign="Right">
<Items>
<f:HiddenField ID="hidFileName" runat="server"></f:HiddenField>
<f:HiddenField runat="server" ID="hdPMIDelegationId">
</f:HiddenField>
<f:FileUpload runat="server" ID="fileUpload" EmptyText="请选择要导入的Excel文件"
LabelWidth="50px" LabelAlign="Right" Width="300px">
</f:FileUpload>
<f:Button ID="btnImport" Icon="ApplicationEdit" runat="server" Text="<%$ Resources:Lan,Import %>" ToolTip="<%$ Resources:Lan,Import %>"
AjaxLoadingType="Mask" ShowAjaxLoadingMaskText="true" AjaxLoadingMaskText="正在校验并导入数据,请稍后!" OnClick="btnImport_Click">
</f:Button>
<f:Button ID="btnDownLoad" runat="server" Icon="ApplicationGo" Text="模板下载" ToolTip="模板下载" OnClick="btnDownLoad_Click">
</f:Button>
<f:ToolbarFill ID="ToolbarFill1" runat="server">
</f:ToolbarFill>
<f:Button ID="btnNew" Text="<%$ Resources:Lan,Add %>" ToolTip="<%$ Resources:Lan,Add %>"
@@ -180,7 +189,10 @@
EnableMaximize="true" Target="Parent" EnableResize="true" runat="server" OnClose="Window2_Close"
IsModal="true" Width="1090px" Height="660px">
</f:Window>
<f:Window ID="Window4" Hidden="true" EnableIFrame="true" EnableMaximize="true"
Target="Self" EnableResize="true" runat="server" IsModal="true" Width="1024px"
Height="620px">
</f:Window>
</form>
<script type="text/javascript">
@@ -11,6 +11,7 @@ using NPOI.HSSF.Util;
using NPOI.SS.UserModel;
using NPOI.SS.Util;
using NPOI.XSSF.UserModel;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace FineUIPro.Web.WeldingProcess.PMI
{
@@ -31,6 +32,16 @@ namespace FineUIPro.Web.WeldingProcess.PMI
ViewState["PMIDelegationId"] = value;
}
}
/// <summary>
/// 上传预设的虚拟路径
/// </summary>
private string initPath = Const.ExcelUrl;
/// <summary>
/// 错误集合
/// </summary>
public static string errorInfos = string.Empty;
#endregion
#region
@@ -814,6 +825,399 @@ namespace FineUIPro.Web.WeldingProcess.PMI
Response.End();
}
#region
/// <summary>
/// 模板下载
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnDownLoad_Click(object sender, EventArgs e)
{
string rootPath = Server.MapPath("~/");
string uploadfilepath = rootPath + Const.HJGL_PMITemplateUrl;
string filePath = Const.HJGL_PMITemplateUrl;
string fileName = Path.GetFileName(filePath);
FileInfo info = new FileInfo(uploadfilepath);
long fileSize = info.Length;
Response.ClearContent();
Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.ContentType = "excel/plain";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AddHeader("Content-Length", fileSize.ToString().Trim());
Response.TransmitFile(uploadfilepath, 0, fileSize);
Response.End();
//PageContext.RegisterStartupScript(Confirm.GetShowReference("确定要下载焊工信息导入模板?", String.Empty, MessageBoxIcon.Question, PageManager1.GetCustomEventReference(false, "Confirm_OK"), PageManager1.GetCustomEventReference("Confirm_Cancel")));
}
#endregion
protected void btnImport_Click(object sender, EventArgs e)
{
string message = string.Empty;
errorInfos = string.Empty;
try
{
if (this.fileUpload.HasFile == false)
{
ShowNotify("请选择Excel文件!", MessageBoxIcon.Warning);
return;
}
string IsXls = Path.GetExtension(this.fileUpload.FileName).ToString().Trim().ToLower();
if (IsXls != ".xls" && IsXls != ".xlsx")
{
ShowNotify("只能选择Excel文件!", MessageBoxIcon.Warning);
return;
}
string rootPath = Server.MapPath("~/");
string initFullPath = rootPath + initPath;
if (!Directory.Exists(initFullPath))
{
Directory.CreateDirectory(initFullPath);
}
//指定上传文件名称
this.hidFileName.Text = BLL.Funs.GetNewFileName() + IsXls;
//上传文件路径
string filePath = initFullPath + this.hidFileName.Text;
//文件上传服务器
this.fileUpload.PostedFile.SaveAs(filePath);
//文件上传服务器后的名称
string fileName = rootPath + initPath + this.hidFileName.Text;
//读取Excel
DataSet ds = NPOIHelper.ExcelToDataSet(fileName, out errorInfos, true);
//验证Excel读取是否有误
if (!string.IsNullOrEmpty(errorInfos))
{
ShowNotify(errorInfos, MessageBoxIcon.Warning);
return;
}
if (ds.Tables.Count > 0)
{
//定义错误集合实体类
var data = ValidateFieldsExcelData(ds.Tables[0]);
Funs.DB.PMI_ImportErrorLog.InsertAllOnSubmit(data.Item2);
Funs.DB.SubmitChanges();
//验证错误集合
if (data.Item1)
{
string batchNo = data.Item2.Select(t => t.BatchNo).Distinct().First();
PageContext.RegisterStartupScript(Window4.GetShowReference(String.Format("ImportError.aspx?batchNo={0}", batchNo), "PMI导入错误日志"));
return;
}
//导入数据
List<PMI_Delegation> listPMIData = new List<PMI_Delegation>();
List<Model.PMI_DelegationDetails> listDetailData = new List<PMI_DelegationDetails>();
foreach (var item in data.Item2)
{
if (!listPMIData.Any(t => t.DelegationNo == item.DelegationNo))
{
List<PMI_DelegationDetails> ptpItemListData = new List<PMI_DelegationDetails>();
Model.PMI_Delegation model = new PMI_Delegation();
model.Id = SQLHelper.GetNewID(typeof(PMI_Delegation));
model.DelegationNo = item.DelegationNo;
model.UnitId = item.UnitId;
model.ProjectId = item.ProjectId;
model.InstallationId = item.InstallId;
model.DetectionStandard = "GB 50184-2011";
model.DelegationDate = DateTime.Now;
model.Tabler = this.CurrUser.UserId;
listPMIData.Add(model);
var itemData = data.Item2.Where(t => t.DelegationNo == item.DelegationNo).ToList();
foreach (var item2 in itemData)
{
var model2 = new PMI_DelegationDetails();
model2.PMIId = model.Id;
model2.JointId = item2.WeldJointId;
model2.WorkAreaId = item2.WorkAreaId;
model2.Id = SQLHelper.GetNewID(typeof(PMI_DelegationDetails));
listDetailData.Add(model2);
}
}
}
Funs.DB.PMI_Delegation.InsertAllOnSubmit(listPMIData);
Funs.DB.PMI_DelegationDetails.InsertAllOnSubmit(listDetailData);
//绑定表格
Funs.DB.SubmitChanges();
this.BindGrid();
ShowNotify("导入成功!", MessageBoxIcon.Success);
PageContext.RegisterStartupScript(ActiveWindow.GetWriteBackValueReference(this.PMIDelegationId) + ActiveWindow.GetHidePostBackReference());
}
else
{
ShowAlert("没有数据!", MessageBoxIcon.Warning);
return;
}
}
catch (Exception ex)
{
ShowAlert("'" + ex.Message + "'", MessageBoxIcon.Warning);
}
}
/// <summary>
/// 验证Excle中的数据列是否符合要求
/// </summary>
private (bool, List<PMI_ImportErrorLog>) ValidateFieldsExcelData(DataTable dt)
{
var listData = new List<PMI_ImportErrorLog>();
bool flag = false;
int k = 0;
string batchNo = DateTime.Now.ToString("yyyyMMddHHmmss");
foreach (DataRow dr in dt.Rows)
{
var model = new PMI_ImportErrorLog();
k++;
string delegationNo = dr[0].ToString(); //委托单号
string untiCode = dr[1].ToString(); //单位编号
string installCode = dr[2].ToString(); //装置编号
string areaCode = dr[3].ToString(); //区域编号
string pipelineCode = dr[4].ToString(); //管线编号
string jointCode = dr[5].ToString(); //焊口列表逗号
model.Id = SQLHelper.GetNewID(typeof(PMI_ImportErrorLog));
model.DelegationNo = delegationNo;
model.UnitCode = untiCode;
model.InstallCode = installCode;
model.AreaCode = areaCode;
model.PiplineCode = pipelineCode;
model.JointCode = jointCode;
model.CreatedTime = DateTime.Now;
model.RowId = k;
model.UnitId = string.Empty;
model.InstallId = string.Empty;
model.WorkAreaId = string.Empty;
model.ProjectId = this.CurrUser.LoginProjectId;
model.PipelineId = string.Empty;
model.BatchNo = batchNo;
string errorMsg = string.Empty;
//验证是否为空
if (string.IsNullOrEmpty(delegationNo))
{
errorMsg += "试压包编号未填写 |";
}
if (string.IsNullOrEmpty(untiCode))
{
errorMsg += "试单位编号未填写 | ";
}
if (string.IsNullOrEmpty(installCode))
{
errorMsg += "装置编号未填写 | ";
}
if (string.IsNullOrEmpty(areaCode))
{
errorMsg += "区域编号未填写 | ";
}
if (string.IsNullOrEmpty(pipelineCode))
{
errorMsg += "管线号未填写 | ";
}
if (string.IsNullOrEmpty(jointCode))
{
errorMsg += "是否全部焊口未填写 | ";
}
//检查单位编号是否存在
var unitInfo = Funs.DB.Base_Unit.FirstOrDefault(t => t.UnitCode == model.UnitCode);
if (unitInfo == null)
{
errorMsg += "未知的单位编号 | ";
}
var installInfo = Funs.DB.Project_Installation.FirstOrDefault(t => t.InstallationCode == model.InstallCode);
if (installInfo == null)
{
errorMsg += "未知的装置编号 | ";
}
var areaInfo = Funs.DB.Project_WorkArea.FirstOrDefault(t => t.WorkAreaCode == model.AreaCode);
if (areaInfo == null)
{
errorMsg += "未知的区域编号 | ";
}
var isAnypipeline = Funs.DB.Pipeline_Pipeline.Any(t => t.PipelineCode == model.PiplineCode);
if (!isAnypipeline)
{
errorMsg += "未知的管线号 | ";
}
var isDelegationNo = Funs.DB.PMI_Delegation.Any(t => t.DelegationNo == model.DelegationNo);
if (isDelegationNo)
{
errorMsg += "该委托编号已存在 | ";
}
if (unitInfo != null && installInfo != null && areaInfo != null)
{
model.UnitId = unitInfo.UnitId;
model.WorkAreaId = areaInfo.WorkAreaId;
model.InstallId = installInfo.InstallationId;
var newPipelineInfo = Funs.DB.Pipeline_Pipeline.FirstOrDefault(t => t.UnitId == unitInfo.UnitId &&
t.InstallationId == installInfo.InstallationId && t.WorkAreaId == areaInfo.WorkAreaId &&
t.PipelineCode == model.PiplineCode);
if (newPipelineInfo == null)
{
errorMsg += "当前区域下不存在此管线号 | ";
model.PipelineId = string.Empty;
}
else
{
model.PipelineId = newPipelineInfo.PipelineId;
string pipelineError = CheckPipeline(this.CurrUser.LoginProjectId, unitInfo.UnitId, installInfo.InstallationId, newPipelineInfo.PipelineId);
if (!string.IsNullOrEmpty(pipelineError))
{
errorMsg += pipelineError;
}
else
{
var newWeldJointInfo = Funs.DB.Pipeline_WeldJoint.FirstOrDefault(t => t.PipelineId == newPipelineInfo.PipelineId && t.WeldJointCode == jointCode);
if (newWeldJointInfo == null)
{
errorMsg += "当前管线下不存在此焊口 | ";
model.WeldJointId = string.Empty;
}
else
{
model.WeldJointId = newWeldJointInfo.WeldJointId;
string weldJointError = CheckWeldJoint(newPipelineInfo.PipelineId, model.WeldJointId);
if (!string.IsNullOrEmpty(weldJointError))
{
errorMsg += weldJointError;
model.WeldJointId=string.Empty;
}
}
}
}
}
model.Remark = errorMsg;
if (!string.IsNullOrEmpty(model.Remark))
flag = true;
listData.Add(model);
}
return (flag, listData);
}
public string CheckPipeline(string ProjectId, string UnitId, string installId, string PipelineId)
{
string result = "";
//查询出来未达到PMI检测比例的数据
var pmiNocheckList = Funs.DB.View_PMIDetections
.Where(t => t.ProjectId == ProjectId
&& t.InstallationId == installId
&& t.UnitId == UnitId
&& (t.RateBys <= 2 && t.PMIBySNum <= 2) || (t.RateByf <= 2 && t.PMIByFNum <= 2))
.AsQueryable();
//排除已经委托过的
var listData = (from a in Funs.DB.PMI_Delegation.AsQueryable()
join
b in Funs.DB.PMI_DelegationDetails.AsQueryable() on
a.Id equals b.PMIId
select b.JointId
).Distinct().ToList();
//查询带有PMI处理且已经焊接过的管线数据
var iso = from a in Funs.DB.View_Pipeline_WeldJoint
where a.IsPMI == true && a.ProjectId == ProjectId && a.UnitId == UnitId
&& a.InstallationId == installId && (a.WeldingDailyId != "" && a.WeldingDailyId != null)
select new { a.PipelineId, a.PipelineCode, a.WorkAreaId, a.WeldJointCode, a.WeldJointId }
;
iso = from a in iso
join b in pmiNocheckList on a.PipelineId equals b.PipelineId
select new
{
a.PipelineId,
a.PipelineCode,
a.WorkAreaId,
a.WeldJointCode,
a.WeldJointId
};
if (listData.Count > 0)
{
iso = iso.Where(a => !listData.Contains(a.WeldJointId));
}
iso = iso.Where(a => a.PipelineId.Contains(PipelineId));
var isoList = iso.Select(x => x.PipelineId).Distinct().ToList();
if (isoList.Count ==0)
{
result = "该管线无法进行PMI委托 | ";
}
return result;
}
public string CheckWeldJoint(string PipelineId,string WeldJointId)
{
string result = "";
//未达标的活动S口
var pmiViewJointBy_S = (from a in Funs.DB.View_PMIDetections
join b in Funs.DB.Pipeline_WeldJoint
on a.PipelineId equals b.PipelineId
where b.JointAttribute == "活动S"
&& a.PipelineId == PipelineId
&& (b.WeldingDailyId != null && b.WeldingDailyId != "")
&& (a.RateBys > 2 || a.PMIBySNum > 2)
select b.WeldJointId)
.ToList();
//未达标的固定F口
var pmiViewJointBy_F = (from a in Funs.DB.View_PMIDetections
join b in Funs.DB.Pipeline_WeldJoint
on a.PipelineId equals b.PipelineId
where b.JointAttribute == "固定F"
&& a.PipelineId == PipelineId
&& (b.WeldingDailyId != null && b.WeldingDailyId != "")
&& (a.RateByf > 2 && a.PMIByFNum > 2)
select b.WeldJointId)
.ToList();
//排除已经选择过的焊口
var listData = (from a in Funs.DB.PMI_Delegation.AsQueryable()
join
b in Funs.DB.PMI_DelegationDetails.AsQueryable() on
a.Id equals b.PMIId
select b.JointId
).Distinct().ToList();
var query = Funs.DB.View_Pipeline_WeldJoint.Where(t => t.IsPMI == true
&& (t.WeldingDailyId != null && t.WeldingDailyId != "")
&& t.PipelineId == PipelineId);
if (listData.Count > 0)
{
query = query.Where(t => !listData.Contains(t.WeldJointId));
}
if (pmiViewJointBy_S.Count > 0)
{
query = query.Where(t => t.JointAttribute != "活动S");
}
if (pmiViewJointBy_F.Count > 0)
{
query = query.Where(t => t.JointAttribute != "固定F");
}
query = query.Where(t => t.WeldJointId == WeldJointId);
if (query.Count() == 0)
{
result = "该焊口无法进行PMI委托 | ";
}
return result;
}
#region
/// <summary>
@@ -95,6 +95,15 @@ namespace FineUIPro.Web.WeldingProcess.PMI
/// </remarks>
protected global::FineUIPro.Toolbar Toolbar2;
/// <summary>
/// hidFileName 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.HiddenField hidFileName;
/// <summary>
/// hdPMIDelegationId 控件。
/// </summary>
@@ -104,6 +113,33 @@ namespace FineUIPro.Web.WeldingProcess.PMI
/// </remarks>
protected global::FineUIPro.HiddenField hdPMIDelegationId;
/// <summary>
/// fileUpload 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.FileUpload fileUpload;
/// <summary>
/// btnImport 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Button btnImport;
/// <summary>
/// btnDownLoad 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Button btnDownLoad;
/// <summary>
/// ToolbarFill1 控件。
/// </summary>
@@ -301,5 +337,14 @@ namespace FineUIPro.Web.WeldingProcess.PMI
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Window Window2;
/// <summary>
/// Window4 控件。
/// </summary>
/// <remarks>
/// 自动生成的字段。
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
/// </remarks>
protected global::FineUIPro.Window Window4;
}
}