20250702 修改委托单

This commit is contained in:
2025-07-02 09:54:42 +08:00
parent 03b816fd2c
commit 980648fa6e
2 changed files with 484 additions and 158 deletions
@@ -1,6 +1,7 @@
using BLL; using BLL;
using MiniExcelLibs; using MiniExcelLibs;
using Model; using Model;
using NPOI.SS.Util;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data; using System.Data;
@@ -141,19 +142,6 @@ namespace FineUIPro.Web.HJGL.NDT
{ {
if (e.EventArgument == "Confirm_OK") if (e.EventArgument == "Confirm_OK")
{ {
//string rootPath = Server.MapPath("~/");
//string uploadfilepath = rootPath + Const.NDTBatchTemplateUrl;
//string filePath = Const.NDTBatchTemplateUrl;
//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();
string rootPath = Server.MapPath("~/"); string rootPath = Server.MapPath("~/");
string initTemplatePath = Const.NDTBatchTemplateUrl; string initTemplatePath = Const.NDTBatchTemplateUrl;
string uploadfilepath = string.Empty; string uploadfilepath = string.Empty;
@@ -177,8 +165,8 @@ namespace FineUIPro.Web.HJGL.NDT
NPOI.SS.UserModel.IWorkbook workbook; NPOI.SS.UserModel.IWorkbook workbook;
using (FileStream stream = new FileStream(newUrl, FileMode.Open, FileAccess.Read)) using (FileStream stream = new FileStream(newUrl, FileMode.Open, FileAccess.Read))
{ {
workbook = new NPOI.XSSF.UserModel.XSSFWorkbook(stream); workbook = new NPOI.XSSF.UserModel.XSSFWorkbook(stream);//.xlsx
//workbook = new NPOI.HSSF.UserModel.HSSFWorkbook(stream); //workbook = new NPOI.HSSF.UserModel.HSSFWorkbook(stream);//.xls
} }
// 创建单元格样式 // 创建单元格样式
NPOI.SS.UserModel.ICellStyle cellStyle = workbook.CreateCellStyle(); NPOI.SS.UserModel.ICellStyle cellStyle = workbook.CreateCellStyle();
@@ -193,12 +181,29 @@ namespace FineUIPro.Web.HJGL.NDT
font.FontHeightInPoints = 10; font.FontHeightInPoints = 10;
cellStyle.SetFont(font); cellStyle.SetFont(font);
// 第二步:创建新数据行 //尾部样式
NPOI.SS.UserModel.ICellStyle bottomStyle = workbook.CreateCellStyle();
bottomStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
bottomStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
bottomStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
bottomStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
bottomStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
bottomStyle.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Top;
bottomStyle.WrapText = true;//自动换行
var bottomfont = workbook.CreateFont();
bottomfont.FontHeightInPoints = 10;
bottomStyle.SetFont(bottomfont);
//第二步:创建新数据行
NPOI.SS.UserModel.ISheet sheet = workbook.GetSheetAt(0); NPOI.SS.UserModel.ISheet sheet = workbook.GetSheetAt(0);
NPOI.SS.UserModel.IRow row = sheet.GetRow(0); NPOI.SS.UserModel.IRow row = sheet.GetRow(0);
NPOI.SS.UserModel.ICell cell; NPOI.SS.UserModel.ICell cell;
// 添加数据 //设置生成下拉框的行和列
SetCellDropdownList(sheet, 6, 6, new List<string>() { "合格", "不合格" }.ToArray());//是否合格
SetCellDropdownList(sheet, 7, 7, new List<string>() { "", "Ⅱ", "Ⅲ", "Ⅳ", "" }.ToArray());//评定级别
//添加数据
cell = row.CreateCell(7); cell = row.CreateCell(7);
cell.CellStyle = cellStyle; cell.CellStyle = cellStyle;
cell.SetCellValue(batchTrust.ProjectName);//工程名称 cell.SetCellValue(batchTrust.ProjectName);//工程名称
@@ -250,8 +255,10 @@ namespace FineUIPro.Web.HJGL.NDT
cell.CellStyle = cellStyle; cell.CellStyle = cellStyle;
cell.SetCellValue(batchTrust.DetectionRateValue + "%");//检测比例 cell.SetCellValue(batchTrust.DetectionRateValue + "%");//检测比例
int i = 9; int i = 9;
//未满11行,填充空白行到11行;超过11行按实际行填充
if (batchTrustItemLists.Count() < 11)
{
foreach (var item in batchTrustItemLists) foreach (var item in batchTrustItemLists)
{ {
// 第二步:创建新数据行 // 第二步:创建新数据行
@@ -302,6 +309,292 @@ namespace FineUIPro.Web.HJGL.NDT
cell.SetCellValue("");//备注 cell.SetCellValue("");//备注
i++; i++;
} }
for (int j = 0; j < 11 - batchTrustItemLists.Count(); j++)
{
// 第二步:创建新数据行
row = sheet.CreateRow(i);
// 添加数据
cell = row.CreateCell(0);
cell.CellStyle = cellStyle;
cell.SetCellValue((i - 8).ToString());//序号
cell = row.CreateCell(1);
cell.CellStyle = cellStyle;
cell.SetCellValue("");//管线号
cell = row.CreateCell(2);
cell.CellStyle = cellStyle;
cell.SetCellValue("");//焊口号
cell = row.CreateCell(3);
cell.CellStyle = cellStyle;
cell.SetCellValue("");//焊工号
cell = row.CreateCell(4);
cell.CellStyle = cellStyle;
cell.SetCellValue("");//检测总数
cell = row.CreateCell(5);
cell.CellStyle = cellStyle;
cell.SetCellValue("");//合格数
cell = row.CreateCell(6);
cell.CellStyle = cellStyle;
cell.SetCellValue("");//是否合格
cell = row.CreateCell(7);
cell.CellStyle = cellStyle;
cell.SetCellValue("");//评定级别
cell = row.CreateCell(8);
cell.CellStyle = cellStyle;
cell.SetCellValue("");//缺陷
cell = row.CreateCell(9);
cell.CellStyle = cellStyle;
cell.SetCellValue("");//返修位置
cell = row.CreateCell(10);
cell.CellStyle = cellStyle;
cell.SetCellValue("");//备注
i++;
}
//尾部 签字盖章
// 创建新数据行
row = sheet.CreateRow(20);
row.HeightInPoints = 43;
CellRangeAddress region = new CellRangeAddress(20, 20, 0, 1);
sheet.AddMergedRegion(region);
cell = row.CreateCell(0);
cell.SetCellValue("委托方单位:");
cell.CellStyle = bottomStyle;
cell = row.CreateCell(1);
cell.CellStyle = bottomStyle;
region = new CellRangeAddress(20, 20, 2, 3);
sheet.AddMergedRegion(region);
cell = row.CreateCell(2);
cell.SetCellValue("评片人:");
cell.CellStyle = bottomStyle;
cell = row.CreateCell(3);
cell.CellStyle = bottomStyle;
region = new CellRangeAddress(20, 20, 4, 6);
sheet.AddMergedRegion(region);
cell = row.CreateCell(4);
cell.SetCellValue("检测方单位:");
cell.CellStyle = bottomStyle;
cell = row.CreateCell(5);
cell.CellStyle = bottomStyle;
cell = row.CreateCell(6);
cell.CellStyle = bottomStyle;
region = new CellRangeAddress(20, 20, 7, 10);
sheet.AddMergedRegion(region);
cell = row.CreateCell(7);
cell.SetCellValue("监理单位:");
cell.CellStyle = bottomStyle;
cell = row.CreateCell(8);
cell.CellStyle = bottomStyle;
cell = row.CreateCell(9);
cell.CellStyle = bottomStyle;
cell = row.CreateCell(10);
cell.CellStyle = bottomStyle;
row = sheet.CreateRow(21);
row.HeightInPoints = 43;
region = new CellRangeAddress(21, 21, 0, 1);
sheet.AddMergedRegion(region);
cell = row.CreateCell(0);
cell.SetCellValue("日期:");
cell.CellStyle = bottomStyle;
cell = row.CreateCell(1);
cell.CellStyle = bottomStyle;
region = new CellRangeAddress(21, 21, 2, 3);
sheet.AddMergedRegion(region);
cell = row.CreateCell(2);
cell.SetCellValue("日期:");
cell.CellStyle = bottomStyle;
cell = row.CreateCell(3);
cell.CellStyle = bottomStyle;
region = new CellRangeAddress(21, 21, 4, 6);
sheet.AddMergedRegion(region);
cell = row.CreateCell(4);
cell.SetCellValue("日期:");
cell.CellStyle = bottomStyle;
cell = row.CreateCell(5);
cell.CellStyle = bottomStyle;
cell = row.CreateCell(6);
cell.CellStyle = bottomStyle;
region = new CellRangeAddress(21, 21, 7, 10);
sheet.AddMergedRegion(region);
cell = row.CreateCell(7);
cell.SetCellValue("日期:");
cell.CellStyle = bottomStyle;
cell = row.CreateCell(8);
cell.CellStyle = bottomStyle;
cell = row.CreateCell(9);
cell.CellStyle = bottomStyle;
cell = row.CreateCell(10);
cell.CellStyle = bottomStyle;
}
else
{
foreach (var item in batchTrustItemLists)
{
// 第二步:创建新数据行
row = sheet.CreateRow(i);
// 添加数据
cell = row.CreateCell(0);
cell.CellStyle = cellStyle;
cell.SetCellValue((i - 8).ToString());//序号
cell = row.CreateCell(1);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.PipelineCode.ToString());//管线号
cell = row.CreateCell(2);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.WeldJointCode);//焊口号
cell = row.CreateCell(3);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.WelderCode);//焊工号
cell = row.CreateCell(4);
cell.CellStyle = cellStyle;
cell.SetCellValue("");//检测总数
cell = row.CreateCell(5);
cell.CellStyle = cellStyle;
cell.SetCellValue("");//合格数
cell = row.CreateCell(6);
cell.CellStyle = cellStyle;
cell.SetCellValue("");//是否合格
cell = row.CreateCell(7);
cell.CellStyle = cellStyle;
cell.SetCellValue("");//评定级别
cell = row.CreateCell(8);
cell.CellStyle = cellStyle;
cell.SetCellValue("");//缺陷
cell = row.CreateCell(9);
cell.CellStyle = cellStyle;
cell.SetCellValue("");//返修位置
cell = row.CreateCell(10);
cell.CellStyle = cellStyle;
cell.SetCellValue("");//备注
i++;
}
//尾部 签字盖章
// 创建新数据行
row = sheet.CreateRow(i);
row.HeightInPoints = 43;
CellRangeAddress region = new CellRangeAddress(i, i, 0, 1);
sheet.AddMergedRegion(region);
cell = row.CreateCell(0);
cell.SetCellValue("委托方单位:");
cell.CellStyle = bottomStyle;
cell = row.CreateCell(1);
cell.CellStyle = bottomStyle;
region = new CellRangeAddress(i, i, 2, 3);
sheet.AddMergedRegion(region);
cell = row.CreateCell(2);
cell.SetCellValue("评片人:");
cell.CellStyle = bottomStyle;
cell = row.CreateCell(3);
cell.CellStyle = bottomStyle;
region = new CellRangeAddress(i, i, 4, 6);
sheet.AddMergedRegion(region);
cell = row.CreateCell(4);
cell.SetCellValue("检测方单位:");
cell.CellStyle = bottomStyle;
cell = row.CreateCell(5);
cell.CellStyle = bottomStyle;
cell = row.CreateCell(6);
cell.CellStyle = bottomStyle;
region = new CellRangeAddress(i, i, 7, 10);
sheet.AddMergedRegion(region);
cell = row.CreateCell(7);
cell.SetCellValue("监理单位:");
cell.CellStyle = bottomStyle;
cell = row.CreateCell(8);
cell.CellStyle = bottomStyle;
cell = row.CreateCell(9);
cell.CellStyle = bottomStyle;
cell = row.CreateCell(10);
cell.CellStyle = bottomStyle;
row = sheet.CreateRow(i + 1);
row.HeightInPoints = 43;
region = new CellRangeAddress(i + 1, i + 1, 0, 1);
sheet.AddMergedRegion(region);
cell = row.CreateCell(0);
cell.SetCellValue("日期:");
cell.CellStyle = bottomStyle;
cell = row.CreateCell(1);
cell.CellStyle = bottomStyle;
region = new CellRangeAddress(i + 1, i + 1, 2, 3);
sheet.AddMergedRegion(region);
cell = row.CreateCell(2);
cell.SetCellValue("日期:");
cell.CellStyle = bottomStyle;
cell = row.CreateCell(3);
cell.CellStyle = bottomStyle;
region = new CellRangeAddress(i + 1, i + 1, 4, 6);
sheet.AddMergedRegion(region);
cell = row.CreateCell(4);
cell.SetCellValue("日期:");
cell.CellStyle = bottomStyle;
cell = row.CreateCell(5);
cell.CellStyle = bottomStyle;
cell = row.CreateCell(6);
cell.CellStyle = bottomStyle;
region = new CellRangeAddress(i + 1, i + 1, 7, 10);
sheet.AddMergedRegion(region);
cell = row.CreateCell(7);
cell.SetCellValue("日期:");
cell.CellStyle = bottomStyle;
cell = row.CreateCell(8);
cell.CellStyle = bottomStyle;
cell = row.CreateCell(9);
cell.CellStyle = bottomStyle;
cell = row.CreateCell(10);
cell.CellStyle = bottomStyle;
}
// 第三步:写入文件流 // 第三步:写入文件流
using (FileStream stream = new FileStream(newUrl, FileMode.Create, FileAccess.Write)) using (FileStream stream = new FileStream(newUrl, FileMode.Create, FileAccess.Write))
{ {
@@ -322,7 +615,37 @@ namespace FineUIPro.Web.HJGL.NDT
} }
} }
} }
/// <summary>
/// 设置单元格下拉框约束
/// </summary>
/// <param name="sheet"></param>
/// <param name="firstcol"></param>
/// <param name="lastcol"></param>
/// <param name="vals"></param>
public static void SetCellDropdownList(NPOI.SS.UserModel.ISheet sheet, int firstcol, int lastcol, string[] vals)
{
//设置生成下拉框的行和列
var cellRegions = new CellRangeAddressList(1, 65535, firstcol, lastcol);
NPOI.SS.UserModel.IDataValidation validation = null;
if (sheet.GetType().Name.Contains("XSSF")) // .xlsx
{
NPOI.XSSF.UserModel.XSSFDataValidationHelper helper = new NPOI.XSSF.UserModel.XSSFDataValidationHelper((NPOI.XSSF.UserModel.XSSFSheet)sheet);//获得一个数据验证Helper
//IDataValidation
validation = helper.CreateValidation(
helper.CreateExplicitListConstraint(vals), cellRegions);//创建约束
}
else // HSSF .xls
{
//設置 下拉框內容
NPOI.HSSF.UserModel.DVConstraint constraint = NPOI.HSSF.UserModel.DVConstraint.CreateExplicitListConstraint(vals);
validation = new NPOI.HSSF.UserModel.HSSFDataValidation(cellRegions, constraint);
}
sheet.AddValidationData(validation);
}
#endregion #endregion
#region Dataset的数据导入数据库 #region Dataset的数据导入数据库
/// <summary> /// <summary>
/// 将Dataset的数据导入数据库 /// 将Dataset的数据导入数据库
@@ -341,7 +664,7 @@ namespace FineUIPro.Web.HJGL.NDT
responeData.message = "导入Excel格式错误!Excel只有" + count.ToString().Trim() + "列"; responeData.message = "导入Excel格式错误!Excel只有" + count.ToString().Trim() + "列";
return responeData; return responeData;
} }
if (pds.Count > 0 && pds != null) if (pds.Count-2 > 0 && pds != null)
{ {
string NDEId = string.Empty; string NDEId = string.Empty;
//string unitworkId = string.Empty; //string unitworkId = string.Empty;
@@ -415,7 +738,9 @@ namespace FineUIPro.Web.HJGL.NDT
ndes.Add(nde); ndes.Add(nde);
} }
for (int i = 9; i < pds.Count; i++) for (int i = 9; i < pds.Count - 2; i++)
{
if (!string.IsNullOrEmpty(pds[i].B.ToString()) && !string.IsNullOrEmpty(pds[i].C.ToString()))
{ {
HJGL_Batch_NDEItem item = new HJGL_Batch_NDEItem(); HJGL_Batch_NDEItem item = new HJGL_Batch_NDEItem();
item.NDEItemID = SQLHelper.GetNewID(typeof(Model.HJGL_Batch_NDEItem)); item.NDEItemID = SQLHelper.GetNewID(typeof(Model.HJGL_Batch_NDEItem));
@@ -541,17 +866,10 @@ namespace FineUIPro.Web.HJGL.NDT
{ {
result.Add("管线[" + pds[i].B.ToString() + "]焊口[" + pds[i].C.ToString() + "]" + "不存在该委托单中"); result.Add("管线[" + pds[i].B.ToString() + "]焊口[" + pds[i].C.ToString() + "]" + "不存在该委托单中");
} }
//var model = ndeItems.Where(x => x.TrustBatchItemId == item.TrustBatchItemId);
//if (model.Count() == 0)
//{
item.SubmitDate = DateTime.Now; item.SubmitDate = DateTime.Now;
ndeItems.Add(item); ndeItems.Add(item);
//}
// }
} }
#region }
#endregion
} }
} }
else else
@@ -1057,7 +1057,15 @@ namespace FineUIPro.Web.HJGL.PointTrust
{ {
if (pointBatchItem.IsBuildTrust != null) if (pointBatchItem.IsBuildTrust != null)
{ {
pointBatchItem.IsBuildTrust = null; pointBatchItem.IsBuildTrust = null;//是否委托
pointBatchItem.PointState = null;//点口类型
pointBatchItem.PointDate = null;//点口时间
db.SubmitChanges();
}
var pointBatch = BLL.PointBatchService.GetPointBatchById(pointBatchItem.PointBatchId);
if (pointBatch!=null)
{
pointBatch.IsClosed = null;
db.SubmitChanges(); db.SubmitChanges();
} }
} }