试压包导入

This commit is contained in:
jackchenyang
2024-05-24 21:27:14 +08:00
parent abfad3c2af
commit 3d974eead4
16 changed files with 1034 additions and 929 deletions
@@ -7,6 +7,8 @@ using System.IO;
using System.Web;
using BLL;
using Newtonsoft.Json.Linq;
using Model;
using NPOI.HSSF.EventUserModel;
namespace FineUIPro.Web.WeldingProcess.TestPackageManage
{
@@ -49,10 +51,10 @@ namespace FineUIPro.Web.WeldingProcess.TestPackageManage
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
{
this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString();
this.PTP_ID = string.Empty;
this.txtSearchDate.Text = string.Format("{0:yyyy-MM}", System.DateTime.Now);
this.txtSearchDate.Text = string.Format("{0:yyyy-MM}", System.DateTime.Now);
this.InitTreeMenu();//加载树
}
}
@@ -64,7 +66,7 @@ namespace FineUIPro.Web.WeldingProcess.TestPackageManage
/// </summary>
private void InitTreeMenu()
{
this.tvControlItem.Nodes.Clear();
this.tvControlItem.Nodes.Clear();
TreeNode rootNode = new TreeNode();
rootNode.Text = "单位-装置-月份";
rootNode.NodeID = "0";
@@ -89,7 +91,7 @@ namespace FineUIPro.Web.WeldingProcess.TestPackageManage
List<Model.PTP_TestPackage> testPackageLists = (from x in Funs.DB.PTP_TestPackage
where x.ProjectId == this.CurrUser.LoginProjectId && x.TableDate >= startTime && x.TableDate < endTime
select x).ToList();
select x).ToList();
if (units != null)
{
foreach (var unit in units)
@@ -126,8 +128,10 @@ namespace FineUIPro.Web.WeldingProcess.TestPackageManage
select x.InstallationId).Distinct();
if (installId.Count() > 0)
{
var install = from x in Funs.DB.Project_Installation
where installId.Contains(x.InstallationId) orderby x.InstallationCode select x;
var install = from x in Funs.DB.Project_Installation
where installId.Contains(x.InstallationId)
orderby x.InstallationCode
select x;
foreach (var q in install)
{
TreeNode newNode = new TreeNode();
@@ -142,7 +146,7 @@ namespace FineUIPro.Web.WeldingProcess.TestPackageManage
}
else if (node.ToolTip == "装置")
{
string installationId = Funs.GetStrListByStr(node.NodeID, '|')[0];
string installationId = Funs.GetStrListByStr(node.NodeID, '|')[0];
var pointListMonth = (from x in testPackageUnitList
where x.InstallationId == installationId
select string.Format("{0:yyyy-MM}", x.TableDate)).Distinct();
@@ -177,10 +181,10 @@ namespace FineUIPro.Web.WeldingProcess.TestPackageManage
{
DateTime startTime = Convert.ToDateTime(this.txtSearchDate.Text.Trim() + "-01");
DateTime endTime = startTime.AddMonths(1);
string installationId = Funs.GetStrListByStr(node.ParentNode.NodeID, '|')[0];
string installationId = Funs.GetStrListByStr(node.ParentNode.NodeID, '|')[0];
var dReports = from x in testPackageUnitList
where x.InstallationId == installationId
&& x.TableDate>= startTime && x.TableDate< endTime
&& x.TableDate >= startTime && x.TableDate < endTime
orderby x.TestPackageNo descending
select x;
foreach (var item in dReports)
@@ -516,7 +520,7 @@ namespace FineUIPro.Web.WeldingProcess.TestPackageManage
BLL.Sys_LogService.AddLog(BLL.Const.System_3, this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.TestPackageManageEditMenuId, Const.BtnDelete, this.PTP_ID);
Alert.ShowInTop("删除成功!", MessageBoxIcon.Success);
this.InitTreeMenu();
this.BindGrid();
this.BindGrid();
}
else
{
@@ -545,7 +549,7 @@ namespace FineUIPro.Web.WeldingProcess.TestPackageManage
this.InitTreeMenu();
this.hdPTP_ID.Text = string.Empty;
}
/// <summary>
/// 查询
/// </summary>
@@ -651,7 +655,7 @@ namespace FineUIPro.Web.WeldingProcess.TestPackageManage
}
}
var qq = from x in Funs.DB.View_CheckResultSummary where x.PTP_ID==this.PTP_ID select x;
var qq = from x in Funs.DB.View_CheckResultSummary where x.PTP_ID == this.PTP_ID select x;
// 合格
var rt = qq.Where(x => x.DetectionTypeCode == "RT" && x.CheckResult == "合格");
@@ -661,7 +665,7 @@ namespace FineUIPro.Web.WeldingProcess.TestPackageManage
bRt = rt.Count().ToString() + "/" + rt.Sum(x => x.TotalFilm).ToString();
}
var jpt = qq.Where(x => x.DetectionTypeCode == "PT" && x.CheckResult == "合格" && x.WeldType=="2");
var jpt = qq.Where(x => x.DetectionTypeCode == "PT" && x.CheckResult == "合格" && x.WeldType == "2");
string ptj = "/";
if (jpt.Count() > 0)
{
@@ -719,7 +723,7 @@ namespace FineUIPro.Web.WeldingProcess.TestPackageManage
if (drpPrintTypeList.SelectedValue == "3")
{
Window2.Title = "管道无损检测比例统计表";
varValue = varValue + "|" + "试压包号:"+pip.TestPackageNo.Trim();
varValue = varValue + "|" + "试压包号:" + pip.TestPackageNo.Trim();
if (!string.IsNullOrEmpty(unitName))
{
varValue = varValue + "|" + unitName;
@@ -812,153 +816,58 @@ namespace FineUIPro.Web.WeldingProcess.TestPackageManage
if (ds.Tables.Count > 0)
{
var units = from x in Funs.DB.Base_Unit
join y in Funs.DB.Project_Unit on x.UnitId equals y.UnitId
where y.ProjectId == this.CurrUser.LoginProjectId
select x;//单位
List<Model.PTP_TestPackage> testPackageList = new List<Model.PTP_TestPackage>();
List<Model.PTP_PipelineList> pipelineList = new List<Model.PTP_PipelineList>();
DataTable dt = ds.Tables[0];
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
//定义错误集合实体类
var data = ValidateFieldsExcelData(ds.Tables[0]);
Funs.DB.PTP_TestPackage_ImportErrorLog.InsertAllOnSubmit(data.Item2);
Funs.DB.SubmitChanges();
//验证错误集合
if (data.Item1)
{
var isExitTestPage = from x in Funs.DB.PTP_TestPackage
join y in Funs.DB.Project_Installation on x.InstallationId equals y.InstallationId
join z in Funs.DB.Base_Unit on x.UnitId equals z.UnitId
where x.ProjectId == this.CurrUser.LoginProjectId
&& x.TestPackageNo == ds.Tables[0].Rows[i]["试压包编号"].ToString()
&& y.InstallationCode == ds.Tables[0].Rows[i]["装置编号"].ToString()
&& z.UnitCode == ds.Tables[0].Rows[i]["单位代码"].ToString()
select x;
string error = string.Empty;
#region
if (isExitTestPage.Count() == 0)
{
Model.PTP_PipelineList pipeline = new Model.PTP_PipelineList();
string ptpId = string.Empty;
string installationId = string.Empty;
if (ds.Tables[0].Rows[i]["装置编号"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["装置编号"].ToString()))
{
var ins = Funs.DB.Project_Installation.FirstOrDefault(x => x.ProjectId == CurrUser.LoginProjectId && x.InstallationCode == ds.Tables[0].Rows[i]["装置编号"].ToString());
if (ins == null)
{
error += "装置编号不存在!";
}
else
{
installationId = ins.InstallationId; ;
}
}
else
{
error += "区域编号不能为空!";
}
string unitId = string.Empty;
if (ds.Tables[0].Rows[i]["单位代码"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["单位代码"].ToString()))
{
var unit = units.FirstOrDefault(x => x.UnitCode == ds.Tables[0].Rows[i]["单位代码"].ToString());
if (unit == null)
{
error += "单位代码不存在!";
}
else
{
unitId = unit.UnitId;
}
}
else
{
error += "单位代码不能为空!";
}
string pipelineId = string.Empty;
if (ds.Tables[0].Rows[i]["管线号"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["管线号"].ToString()))
{
var isExitPipeline = Funs.DB.Pipeline_Pipeline.FirstOrDefault(x => x.ProjectId == this.CurrUser.LoginProjectId
&& x.UnitId == unitId
&& x.InstallationId == installationId
&& x.PipelineCode == ds.Tables[0].Rows[i]["管线号"].ToString());
if (isExitPipeline != null)
{
pipeline.PipelineId = isExitPipeline.PipelineId;
}
else
{
error += "管线号不存在!";
}
}
else
{
error += "管线号不能为空!";
}
if (ds.Tables[0].Rows[i]["试压包编号"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["试压包编号"].ToString()))
{
var cc = from x in testPackageList where x.TestPackageNo == ds.Tables[0].Rows[i]["试压包编号"].ToString() select x;
if (cc.Count() == 0)
{
Model.PTP_TestPackage package = new Model.PTP_TestPackage();
ptpId = Funs.GetNewID();
package.PTP_ID = ptpId;
package.ProjectId = CurrUser.LoginProjectId;
package.UnitId = unitId;
package.InstallationId = installationId;
package.TestPackageNo = ds.Tables[0].Rows[i]["试压包编号"].ToString();
package.TableDate = DateTime.Now;
package.Tabler = this.CurrUser.UserId;
testPackageList.Add(package);
pipeline.PT_PipeId = Funs.GetNewID();
pipeline.PTP_ID = ptpId;
}
else
{
pipeline.PT_PipeId = Funs.GetNewID();
pipeline.PTP_ID = cc.First().PTP_ID;
}
}
else
{
error += "试压包编号不能为空!";
}
if (!string.IsNullOrEmpty(error))
{
errorInfos += "第" + (i + 2) + "行:" + error + " </br>";
}
pipelineList.Add(pipeline);
}
#endregion
}
// 数据验证错误,返回
if (!string.IsNullOrEmpty(errorInfos))
{
ShowNotify(errorInfos, MessageBoxIcon.Warning, 30000);
string batchNo = data.Item2.Select(t => t.BatchNo).Distinct().First();
PageContext.RegisterStartupScript(Window4.GetShowReference(String.Format("ImportError.aspx?batchNo={0}", batchNo),"试压包导入错误日志"));
return;
}
else
//导入数据
List<PTP_TestPackage> listPtpPackgeData = new List<PTP_TestPackage>();
List<Model.PTP_PipelineList> listDetailData = new List<PTP_PipelineList>();
foreach (var item in data.Item2)
{
// 不更新,新数据插入
if (testPackageList.Count > 0 && pipelineList.Count() > 0)
if (!listPtpPackgeData.Any(t => t.TestPackageNo == item.TestPackageNo))
{
Funs.DB.PTP_TestPackage.InsertAllOnSubmit(testPackageList);
Funs.DB.PTP_PipelineList.InsertAllOnSubmit(pipelineList);
Funs.DB.SubmitChanges();
List<PTP_PipelineList> ptpItemListData = new List<PTP_PipelineList>();
Model.PTP_TestPackage model = new PTP_TestPackage();
model.PTP_ID = SQLHelper.GetNewID(typeof(PTP_TestPackage));
model.TestPackageNo = item.TestPackageNo;
model.UnitId = item.UnitId;
model.ProjectId = item.ProjectId;
model.InstallationId = item.InstallId;
model.TableDate = DateTime.Now;
model.Tabler = this.CurrUser.UserId;
listPtpPackgeData.Add(model);
var itemData=data.Item2.Where(t=>t.TestPackageNo==item.TestPackageNo).ToList();
foreach (var item2 in itemData)
{
var model2=new PTP_PipelineList();
model2.PTP_ID = model.PTP_ID;
model2.PipelineId = item2.PipelineId;
model2.WorkAreaId = item2.WorkAreaId;
model2.WeldJonintCode = item2.JointCode;
model2.PT_PipeId = SQLHelper.GetNewID(typeof(PTP_PipelineList));
model2.IsAll= item2.IsAll == "是" ? true : false;
listDetailData.Add(model2);
}
}
ShowNotify("试压包信息导入成功!", MessageBoxIcon.Success);
this.BindGrid();
}
}
Funs.DB.PTP_TestPackage.InsertAllOnSubmit(listPtpPackgeData);
Funs.DB.PTP_PipelineList.InsertAllOnSubmit(listDetailData);
//绑定表格
Funs.DB.SubmitChanges();
this.BindGrid();
ShowNotify("导入成功!", MessageBoxIcon.Success);
PageContext.RegisterStartupScript(ActiveWindow.GetWriteBackValueReference(this.PTP_ID)+ ActiveWindow.GetHidePostBackReference());
}
else
{
ShowAlert("没有数据!", MessageBoxIcon.Warning);
@@ -972,5 +881,180 @@ namespace FineUIPro.Web.WeldingProcess.TestPackageManage
}
}
/// <summary>
/// 验证Excle中的数据列是否符合要求
/// </summary>
private (bool, List<PTP_TestPackage_ImportErrorLog>) ValidateFieldsExcelData(DataTable dt)
{
var listData = new List<PTP_TestPackage_ImportErrorLog>();
bool flag = false;
int k = 0;
string batchNo = DateTime.Now.ToString("yyyyMMddHHmmss");
foreach (DataRow dr in dt.Rows)
{
var model = new PTP_TestPackage_ImportErrorLog();
k++;
string testpackNo = dr[0].ToString(); //试压包编号
string untiCode = dr[1].ToString(); //单位编号
string installCode = dr[2].ToString(); //装置编号
string areaCode = dr[3].ToString(); //区域编号
string pipelineCode = dr[4].ToString(); //管线编号
string isALL = dr[5].ToString(); //是否全部焊口
string jointCode = dr[6].ToString(); //焊口列表逗号
model.Id = SQLHelper.GetNewID(typeof(PTP_TestPackage_ImportErrorLog));
model.TestPackageNo = testpackNo;
model.UnitCode = untiCode;
model.InstallCode = installCode;
model.AreaCode = areaCode;
model.PiplineCode = pipelineCode;
model.IsAll = isALL;
model.JointCode = jointCode;
model.CreatedTime = DateTime.Now;
model.RowId = k;
model.BatchNo = batchNo;
string errorMsg = string.Empty;
//验证是否为空
if (string.IsNullOrEmpty(model.TestPackageNo))
{
errorMsg += "试压包编号未填写 |";
}
if (string.IsNullOrEmpty(model.UnitCode))
{
errorMsg += "试单位编号未填写 | ";
}
if (string.IsNullOrEmpty(installCode))
{
errorMsg += "装置编号未填写 | ";
}
if (string.IsNullOrEmpty(areaCode))
{
errorMsg += "区域编号未填写 | ";
}
if (string.IsNullOrEmpty(pipelineCode))
{
errorMsg += "管线号未填写 | ";
}
if (string.IsNullOrEmpty(isALL))
{
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 += "未知的管线号 | ";
}
if (isALL != "是" && isALL != "否")
{
errorMsg += "是否部分焊口值不正确,只能为是或否 | ";
}
if (isALL == "否" && string.IsNullOrEmpty(model.JointCode))
{
errorMsg += "部分焊口请填写焊口编号 | ";
}
var isPackNoAny = Funs.DB.PTP_TestPackage.Any(t => t.TestPackageCode == model.TestPackageNo);
if (isPackNoAny)
{
errorMsg += "该试压包编号已存在 | ";
}
if (unitInfo != null && installInfo != null && areaInfo != null )
{
model.ProjectId=this.CurrUser.LoginProjectId;
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)
{
model.PipelineId =newPipelineInfo.PipelineId;
var ptpDetailList = Funs.DB.PTP_PipelineList
.Where(t => t.PipelineId == newPipelineInfo.PipelineId);
//查询当前的管线是否被使用了
if (isALL == "是")
{
var isAnyPipeline = ptpDetailList.Where(t => t.IsAll == true).Any();
if (isAnyPipeline)
{
errorMsg += "该管线已被使用 | ";
}
var isExcelPipline= listData.Where(t=>t.PipelineId== newPipelineInfo.PipelineId).Any();
if (isExcelPipline)
{
errorMsg += "该管线已被使用 | ";
}
}
//查询当前的焊口是否被使用了
if (isALL == "否")
{
var dict = GetJointCodeDic(newPipelineInfo.PipelineId);
string[] modelCodes = model.JointCode.Split(',');
for (int i = 0; i < modelCodes.Length; i++)
{
if (dict.ContainsKey(modelCodes[i]))
{
errorMsg += $"焊口【{modelCodes[i]}】已被使用 | ";
}
}
int baseCount = BLL.TestPackageManageEditService.countBaseWeldJointCode(newPipelineInfo.PipelineId);
if (dict.Count == baseCount)
{
errorMsg += $"当前管线【{newPipelineInfo.PipelineId}】已被使用 | ";
}
}
}
model.Remark = errorMsg;
}
if(!string.IsNullOrEmpty(model.Remark))
flag = true;
listData.Add(model);
}
return (flag, listData);
}
private Dictionary<string, int> GetJointCodeDic(string piplineId)
{
var dict = new Dictionary<string, int>();
var dataList = Funs.DB.PTP_PipelineList.Where(t => t.PipelineId == piplineId && t.IsAll == false)
.Select(t => t.WeldJonintCode).ToList();
int k = 0;
foreach (var item in dataList)
{
k++;
if (!string.IsNullOrEmpty(item))
{
string[] arr = item.Split(',');
for (int i = 0; i < arr.Length; i++)
{
if (!dict.ContainsKey(arr[i]))
{
dict.Add(arr[i], k);
}
}
}
}
return dict;
}
}
}