1195 lines
55 KiB
C#
1195 lines
55 KiB
C#
using BLL;
|
||
using MiniExcelLibs;
|
||
using Model;
|
||
using NPOI.SS.Util;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data;
|
||
using System.Data.SqlClient;
|
||
using System.IO;
|
||
using System.Linq;
|
||
|
||
namespace FineUIPro.Web.HJGL.NDT
|
||
{
|
||
public partial class NDTBatchImport : PageBase
|
||
{
|
||
#region 定义项
|
||
/// <summary>
|
||
/// 委托单主键
|
||
/// </summary>
|
||
public string TrustBatchId
|
||
{
|
||
get
|
||
{
|
||
return (string)ViewState["TrustBatchId"];
|
||
}
|
||
set
|
||
{
|
||
ViewState["TrustBatchId"] = value;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 上传预设的虚拟路径
|
||
/// </summary>
|
||
private string initPath = Const.ExcelUrl;//"File\\Excel\\DataIn\\";
|
||
|
||
/// <summary>
|
||
/// 错误集合
|
||
/// </summary>
|
||
public static string errorInfos = string.Empty;
|
||
/// <summary>
|
||
/// 导入数据分类(NDTBatch)
|
||
/// </summary>
|
||
public static string DataClassification = "NDTBatch";
|
||
|
||
public static List<HJGL_Batch_NDE> ndes = new List<HJGL_Batch_NDE>();
|
||
public static List<HJGL_Batch_NDEItem> ndeItems = new List<HJGL_Batch_NDEItem>();
|
||
|
||
public enum ButtonState { Check = 0, Import = 1, Save = 2 }
|
||
|
||
public static int State;
|
||
#endregion
|
||
|
||
#region 加载
|
||
/// <summary>
|
||
/// 加载页面
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void Page_Load(object sender, EventArgs e)
|
||
{
|
||
if (!IsPostBack)
|
||
{
|
||
TrustBatchId = Request.Params["trustBatchId"];
|
||
this.hdFileName.Text = string.Empty;
|
||
errorInfos = string.Empty;
|
||
State = (int)ButtonState.Check;
|
||
if (ndeItems != null)
|
||
{
|
||
ndeItems.Clear();
|
||
}
|
||
//lbVersion.Text = BLL.HJGL_DesignBasisDataImportService.GetNowVersionByUnitWorkId(Request.Params["UnitWorkId"], DataClassification).ToString();
|
||
BindGrid2();
|
||
}
|
||
}
|
||
#endregion
|
||
void BindGrid2()
|
||
{
|
||
string strSql = @" select Import.DesignBasisDataImportId
|
||
,Import.ProjectId
|
||
,Import.UnitWorkId
|
||
,(Case Import.ImportType when '0' then '补充导入'
|
||
when '1' then '更新导入' end) as ImportType
|
||
,Import.FileName
|
||
,Import.FilePath
|
||
,Import.DataClassification
|
||
,Import.FileType
|
||
,Import.FileSize
|
||
,Import.FileId
|
||
,Import.Version
|
||
,Import.Remark
|
||
,Import.CreateMan
|
||
,Import.CreateDate
|
||
, Users.PersonName
|
||
from HJGL_DesignBasisDataImport as Import
|
||
left join Person_Persons as Users on Users.PersonId=Import.CreateMan
|
||
where Import.UnitWorkId=@UnitWorkId and Import.ProjectId=@ProjectId and Import.DataClassification=@DataClassification
|
||
order by Import.CreateDate";
|
||
List<SqlParameter> listStr = new List<SqlParameter>();
|
||
listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
|
||
if (!string.IsNullOrEmpty(this.TrustBatchId))
|
||
{
|
||
var trustBatch = BLL.Batch_BatchTrustService.GetBatchTrustById(this.TrustBatchId);
|
||
if (trustBatch != null)
|
||
{
|
||
if (!string.IsNullOrEmpty(trustBatch.UnitWorkId))
|
||
{
|
||
listStr.Add(new SqlParameter("@UnitWorkId", trustBatch.UnitWorkId));
|
||
}
|
||
}
|
||
}
|
||
listStr.Add(new SqlParameter("@DataClassification", DataClassification));
|
||
SqlParameter[] parameter = listStr.ToArray();
|
||
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
|
||
|
||
// 2.获取当前分页数据
|
||
//var table = this.GetPagedDataTable(Grid1, tb1);
|
||
Grid2.RecordCount = tb.Rows.Count;
|
||
//tb = GetFilteredTable(Grid2.FilteredData, tb);
|
||
var table = this.GetPagedDataTable(Grid2, tb);
|
||
Grid2.DataSource = table;
|
||
Grid2.DataBind();
|
||
}
|
||
|
||
#region 模板下载
|
||
/// <summary>
|
||
/// 模板下载
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnDownLoad_Click(object sender, EventArgs e)
|
||
{
|
||
PageContext.RegisterStartupScript(Confirm.GetShowReference("确定要下载模板吗?", String.Empty, MessageBoxIcon.Question, PageManager1.GetCustomEventReference(false, "Confirm_OK"), PageManager1.GetCustomEventReference("Confirm_Cancel")));
|
||
}
|
||
|
||
/// <summary>
|
||
/// 下载导入模板
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void PageManager1_CustomEvent(object sender, CustomEventArgs e)
|
||
{
|
||
if (e.EventArgument == "Confirm_OK")
|
||
{
|
||
string rootPath = Server.MapPath("~/");
|
||
string initTemplatePath = Const.NDTBatchTemplateUrl;
|
||
string uploadfilepath = string.Empty;
|
||
string newUrl = string.Empty;
|
||
uploadfilepath = rootPath + initTemplatePath;
|
||
|
||
var batchTrust = (from x in Funs.DB.View_Batch_BatchTrust where x.TrustBatchId == TrustBatchId select x).FirstOrDefault();
|
||
|
||
var batchTrustItemLists = (from x in Funs.DB.View_Batch_BatchTrustItem
|
||
where x.TrustBatchId == TrustBatchId
|
||
select x);
|
||
if (batchTrustItemLists != null)
|
||
{
|
||
newUrl = uploadfilepath.Replace("管道焊口检测结果通知单导入模板", "管道焊口检测结果通知单(" + DateTime.Now.ToString("yyyyMMdd") + ")");
|
||
if (File.Exists(newUrl))
|
||
{
|
||
File.Delete(newUrl);
|
||
}
|
||
File.Copy(uploadfilepath, newUrl);
|
||
// 第一步:读取文件流
|
||
NPOI.SS.UserModel.IWorkbook workbook;
|
||
using (FileStream stream = new FileStream(newUrl, FileMode.Open, FileAccess.Read))
|
||
{
|
||
workbook = new NPOI.XSSF.UserModel.XSSFWorkbook(stream);//.xlsx
|
||
//workbook = new NPOI.HSSF.UserModel.HSSFWorkbook(stream);//.xls
|
||
}
|
||
// 创建单元格样式
|
||
NPOI.SS.UserModel.ICellStyle cellStyle = workbook.CreateCellStyle();
|
||
cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
|
||
cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
|
||
cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
|
||
cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
|
||
cellStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
|
||
cellStyle.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
|
||
cellStyle.WrapText = true;//自动换行
|
||
var font = workbook.CreateFont();
|
||
font.FontHeightInPoints = 10;
|
||
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.IRow row = sheet.GetRow(0);
|
||
NPOI.SS.UserModel.ICell cell;
|
||
|
||
//设置生成下拉框的行和列
|
||
SetCellDropdownList(sheet, 6, 6, new List<string>() { "合格", "不合格" }.ToArray());//是否合格
|
||
SetCellDropdownList(sheet, 7, 7, new List<string>() { "Ⅰ", "Ⅱ", "Ⅲ", "Ⅳ", "Ⅴ" }.ToArray());//评定级别
|
||
var defects = from x in Funs.DB.Base_Defect select x.DefectName;//缺陷
|
||
SetCellDropdownList(sheet, 8, 8, new List<string>() { string.Join(",", defects.ToList()) }.ToArray());
|
||
|
||
//添加数据
|
||
cell = row.CreateCell(7);
|
||
cell.CellStyle = cellStyle;
|
||
cell.SetCellValue(batchTrust.ProjectName);//工程名称
|
||
|
||
NPOI.SS.UserModel.IRow row1 = sheet.GetRow(1);
|
||
cell = row1.CreateCell(7);
|
||
cell.CellStyle = cellStyle;
|
||
cell.SetCellValue(batchTrust.UnitWorkName);// 单位工程名称
|
||
|
||
NPOI.SS.UserModel.IRow row2 = sheet.GetRow(2);
|
||
cell = row2.CreateCell(3);
|
||
cell.CellStyle = cellStyle;
|
||
cell.SetCellValue(batchTrust.UnitName);//委托单位
|
||
|
||
cell = row2.CreateCell(7);
|
||
cell.CellStyle = cellStyle;
|
||
cell.SetCellValue(batchTrust.TrustBatchCode);//委托单号
|
||
|
||
NPOI.SS.UserModel.IRow row3 = sheet.GetRow(3);
|
||
cell = row3.CreateCell(3);
|
||
cell.CellStyle = cellStyle;
|
||
cell.SetCellValue("焊后");//检测时机
|
||
|
||
cell = row3.CreateCell(7);
|
||
cell.CellStyle = cellStyle;
|
||
cell.SetCellValue("NB/T47013.2-2015");//检测标准
|
||
|
||
NPOI.SS.UserModel.IRow row4 = sheet.GetRow(4);
|
||
cell = row4.CreateCell(3);
|
||
cell.CellStyle = cellStyle;
|
||
if (!string.IsNullOrEmpty(batchTrustItemLists.FirstOrDefault().WeldingMethodCode))
|
||
{
|
||
cell.SetCellValue(batchTrustItemLists.FirstOrDefault().WeldingMethodCode);//焊接方法
|
||
}
|
||
|
||
NPOI.SS.UserModel.IRow row5 = sheet.GetRow(5);
|
||
cell = row5.CreateCell(1);
|
||
cell.CellStyle = cellStyle;
|
||
cell.SetCellValue(batchTrust.DetectionTypeCode);//检测方法
|
||
|
||
cell = row5.CreateCell(3);
|
||
cell.CellStyle = cellStyle;
|
||
if (!string.IsNullOrEmpty(batchTrustItemLists.FirstOrDefault().GrooveTypeCode))
|
||
{
|
||
cell.SetCellValue(batchTrustItemLists.FirstOrDefault().GrooveTypeCode);//坡口形式
|
||
}
|
||
|
||
cell = row5.CreateCell(7);
|
||
cell.CellStyle = cellStyle;
|
||
cell.SetCellValue(batchTrust.DetectionRateValue + "%");//检测比例
|
||
|
||
int i = 9;
|
||
//未满11行,填充空白行到11行;超过11行按实际行填充
|
||
if (batchTrustItemLists.Count() < 11)
|
||
{
|
||
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++;
|
||
}
|
||
|
||
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))
|
||
{
|
||
workbook.Write(stream);
|
||
workbook.Close();
|
||
}
|
||
string fileName = Path.GetFileName(newUrl);
|
||
FileInfo info = new FileInfo(newUrl);
|
||
long fileSize = info.Length;
|
||
Response.Clear();
|
||
Response.ContentType = "application/x-zip-compressed";
|
||
Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
|
||
Response.AddHeader("Content-Length", fileSize.ToString());
|
||
Response.TransmitFile(newUrl, 0, fileSize);
|
||
Response.Flush();
|
||
Response.Close();
|
||
File.Delete(newUrl);
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <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
|
||
|
||
#region 将Dataset的数据导入数据库
|
||
/// <summary>
|
||
/// 将Dataset的数据导入数据库
|
||
/// </summary>
|
||
/// <param name="pds">数据集</param>
|
||
/// <param name="Cols">数据集行数</param>
|
||
/// <returns></returns>
|
||
private Model.ResponeData AddDatasetToSQL(List<dynamic> pds, int count)
|
||
{
|
||
Model.ResponeData responeData = new Model.ResponeData();
|
||
List<string> result = new List<string>();
|
||
|
||
if (count < 9)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "导入Excel格式错误!Excel只有" + count.ToString().Trim() + "列";
|
||
return responeData;
|
||
}
|
||
if (pds.Count - 2 > 0 && pds != null)
|
||
{
|
||
string NDEId = string.Empty;
|
||
//string unitworkId = string.Empty;
|
||
//unitworkId = Request.Params["UnitWorkId"];
|
||
//var batchTrusts = from x in Funs.DB.View_Batch_BatchTrust where x.ProjectId == this.CurrUser.LoginProjectId && x.UnitWorkId == unitworkId select x;
|
||
//var batchTrustItemLists = from x in Funs.DB.View_Batch_BatchTrustItem where x.ProjectId == this.CurrUser.LoginProjectId && x.UnitWorkId == Request.Params["UnitWorkId"] select x;
|
||
var defects = from x in Funs.DB.Base_Defect select x;//缺陷
|
||
var checkUnits = from x in Funs.DB.Base_Unit
|
||
join y in Funs.DB.Project_ProjectUnit on x.UnitId equals y.UnitId
|
||
where y.ProjectId == this.CurrUser.LoginProjectId
|
||
&& y.UnitType == BLL.Const.ProjectUnitType_5
|
||
select x;//检测单位
|
||
|
||
//var trustUnits = from x in Funs.DB.Base_Unit
|
||
// join y in Funs.DB.Project_ProjectUnit on x.UnitId equals y.UnitId
|
||
// where y.ProjectId == this.CurrUser.LoginProjectId
|
||
// && y.UnitType == BLL.Const.ProjectUnitType_2
|
||
// select x;//委托单位
|
||
|
||
//string trustBatchId = batchTrustItemLists.FirstOrDefault().TrustBatchId;
|
||
var batchNDE = from x in Funs.DB.HJGL_Batch_NDE where x.TrustBatchId == this.TrustBatchId select x;
|
||
if (batchNDE.Count() == 0)
|
||
{
|
||
var batchTrust = BLL.Batch_BatchTrustService.GetBatchTrustViewById(this.TrustBatchId);
|
||
if (batchTrust != null)
|
||
{
|
||
HJGL_Batch_NDE nde = new HJGL_Batch_NDE();
|
||
nde.NDEID = SQLHelper.GetNewID(typeof(Model.HJGL_Batch_NDE));
|
||
NDEId = nde.NDEID;
|
||
nde.TrustBatchId = this.TrustBatchId;
|
||
nde.ProjectId = this.CurrUser.LoginProjectId;
|
||
nde.UnitId = batchTrust.UnitId;
|
||
nde.UnitWorkId = batchTrust.UnitWorkId;
|
||
|
||
if (pds[2].B != null && !string.IsNullOrEmpty(pds[2].B.ToString()))
|
||
{
|
||
string checkUnitName = pds[2].B.ToString();
|
||
var checkUnit = checkUnits.FirstOrDefault(x => x.UnitName == checkUnitName);
|
||
if (checkUnit == null)
|
||
{
|
||
result.Add("检测单位[" + checkUnitName + "]不存在");
|
||
}
|
||
else
|
||
{
|
||
nde.NDEUnit = checkUnit.UnitId;
|
||
}
|
||
}
|
||
if (pds[3].B == null || string.IsNullOrEmpty(pds[3].B.ToString()))
|
||
{
|
||
result.Add("[检测批号]不能为空</br>");
|
||
}
|
||
else
|
||
{
|
||
nde.NDECode = pds[3].B.ToString();
|
||
}
|
||
if (!string.IsNullOrEmpty(pds[6].C.ToString()) && pds[6].C != null)
|
||
{
|
||
try
|
||
{
|
||
nde.NDEDate = Funs.GetNewDateTime(pds[6].C.ToString());
|
||
if (nde.NDEDate == null)
|
||
{
|
||
result.Add("检测日期[" + pds[6].C.ToString() + "]格式错误");
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
result.Add("检测日期[" + pds[6].C.ToString() + "]格式错误");
|
||
}
|
||
}
|
||
ndes.Add(nde);
|
||
}
|
||
|
||
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();
|
||
item.NDEItemID = SQLHelper.GetNewID(typeof(Model.HJGL_Batch_NDEItem));
|
||
item.NDEID = NDEId;
|
||
var batchTrustItems = BLL.Batch_BatchTrustItemService.GetViewBatchTrustItem(this.TrustBatchId);
|
||
if (batchTrustItems != null)
|
||
{
|
||
var trustItem = batchTrustItems.FirstOrDefault(x => x.PipelineCode == pds[i].B.ToString() && x.WeldJointCode == pds[i].C.ToString());
|
||
if (trustItem != null)
|
||
{
|
||
item.TrustBatchItemId = trustItem.TrustBatchItemId;
|
||
item.DetectionTypeId = trustItem.DetectionTypeId;
|
||
|
||
//检测总数
|
||
if (pds[i].E != null && !string.IsNullOrEmpty(pds[i].E.ToString()))
|
||
{
|
||
try
|
||
{
|
||
item.TotalFilm = Funs.GetNewInt(pds[i].E.ToString());
|
||
if (item.TotalFilm == null)
|
||
{
|
||
result.Add("检测总数[" + pds[i].E.ToString() + "]格式错误");
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
result.Add("检测总数[" + pds[i].E.ToString() + "]格式错误");
|
||
}
|
||
}
|
||
//合格数
|
||
if (pds[i].F != null && !string.IsNullOrEmpty(pds[i].F.ToString()))
|
||
{
|
||
try
|
||
{
|
||
item.PassFilm = Funs.GetNewInt(pds[i].F.ToString());
|
||
if (item.PassFilm == null)
|
||
{
|
||
result.Add("合格数[" + pds[i].F.ToString() + "]格式错误");
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
result.Add("合格数[" + pds[i].F.ToString() + "]格式错误");
|
||
}
|
||
}
|
||
//是否合格
|
||
if (pds[i].G != null && !string.IsNullOrEmpty(pds[i].G.ToString()))
|
||
{
|
||
if (pds[i].G.ToString() == "合格" || pds[i].G.ToString() == "不合格")
|
||
{
|
||
item.CheckResult = pds[i].G.ToString() == "合格" ? "1" : "2";
|
||
}
|
||
else
|
||
{
|
||
result.Add("是否合格[" + pds[i].G.ToString() + "]格式错误");
|
||
}
|
||
}
|
||
//评定级别
|
||
if (pds[i].H != null && !string.IsNullOrEmpty(pds[i].H.ToString()))
|
||
{
|
||
string gudgeGrade = pds[i].H.ToString();
|
||
if (gudgeGrade != "Ⅰ" && gudgeGrade != "Ⅱ" && gudgeGrade != "Ⅲ" && gudgeGrade != "Ⅳ" && gudgeGrade != "Ⅴ")
|
||
{
|
||
result.Add("评定级别" + gudgeGrade + "错误");
|
||
}
|
||
else
|
||
{
|
||
item.JudgeGrade = gudgeGrade;
|
||
}
|
||
}
|
||
//缺陷
|
||
if (pds[i].I != null && !string.IsNullOrEmpty(pds[i].I.ToString()))
|
||
{
|
||
string checkDefects = pds[i].I.ToString();
|
||
string defectIds = string.Empty;
|
||
string[] lists = checkDefects.Split(',');
|
||
foreach (var j in lists)
|
||
{
|
||
var u = defects.Where(x => x.DefectName == j.Trim()).FirstOrDefault();
|
||
if (u == null)
|
||
{
|
||
result.Add("缺陷" + j.Trim() + "不存在");
|
||
}
|
||
else
|
||
{
|
||
var q = BLL.Base_DefectService.GetDefectByDefectName(u.DefectName);
|
||
defectIds += q.DefectId + ",";
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(defectIds))
|
||
{
|
||
defectIds = defectIds.Substring(0, defectIds.LastIndexOf(","));
|
||
item.CheckDefects = defectIds;
|
||
}
|
||
}
|
||
//返修位置
|
||
if (pds[i].J != null && !string.IsNullOrEmpty(pds[i].J.ToString()))
|
||
{
|
||
item.RepairLocation = pds[i].J.ToString();
|
||
}
|
||
if (pds[i].K != null && !string.IsNullOrEmpty(pds[i].K.ToString()))
|
||
{
|
||
item.Remark = pds[i].K.ToString();
|
||
}
|
||
//报告日期
|
||
if (pds[6].H != null && !string.IsNullOrEmpty(pds[6].H.ToString()))
|
||
{
|
||
try
|
||
{
|
||
item.ReportDate = Funs.GetNewDateTime(pds[6].H.ToString());
|
||
if (item.ReportDate == null)
|
||
{
|
||
result.Add("报告日期" + pds[6].H.ToString() + "格式错误");
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
result.Add("报告日期" + pds[6].H.ToString() + "格式错误");
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
result.Add("管线[" + pds[i].B.ToString() + "]焊口[" + pds[i].C.ToString() + "]" + "不存在该委托单中");
|
||
}
|
||
item.SubmitDate = DateTime.Now;
|
||
ndeItems.Add(item);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
result.Add("该委托单已检测");
|
||
}
|
||
|
||
if (result.Count > 0)
|
||
{
|
||
ndeItems.Clear();
|
||
errorInfos = string.Join("|", result.Distinct());
|
||
responeData.code = 0;
|
||
responeData.message = errorInfos;
|
||
}
|
||
else
|
||
{
|
||
errorInfos = string.Empty;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = "导入数据为空!";
|
||
}
|
||
return responeData;
|
||
}
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// 审核
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnAudit_Click(object sender, EventArgs e)
|
||
{
|
||
string message = string.Empty;
|
||
|
||
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;
|
||
}
|
||
|
||
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);
|
||
//文件上传服务器后的名称
|
||
string fileName = rootPath + initPath + this.hdFileName.Text;
|
||
//读取Excel
|
||
var ds = MiniExcel.Query(fileName).ToList();
|
||
var columns = MiniExcel.GetColumns(fileName);
|
||
var cnt = columns.Count;
|
||
var reposedata = AddDatasetToSQL(ds, cnt);
|
||
if (reposedata.code == 1)
|
||
{
|
||
State = (int)ButtonState.Import;
|
||
ShowNotify("审核完成请点击导入");
|
||
}
|
||
else
|
||
{
|
||
Alert alert = new Alert
|
||
{
|
||
Message = reposedata.message,
|
||
Target = Target.Self
|
||
};
|
||
alert.Show();
|
||
}
|
||
}
|
||
#region 导入
|
||
/// <summary>
|
||
/// 导入
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnImport_Click(object sender, EventArgs e)
|
||
{
|
||
if (State == (int)ButtonState.Check)
|
||
{
|
||
ShowNotify("请先审核");
|
||
return;
|
||
|
||
}
|
||
if (string.IsNullOrEmpty(errorInfos))
|
||
{
|
||
if (!string.IsNullOrEmpty(this.hdFileName.Text))
|
||
{
|
||
if (ndeItems.Count > 0)
|
||
{
|
||
//this.Grid1.Hidden = false;
|
||
this.Grid1.DataSource = ndeItems;
|
||
this.Grid1.DataBind();
|
||
Grid1.RecordCount = ndeItems.Count;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
ShowNotify("请先审核要导入的文件!", MessageBoxIcon.Warning);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
ShowNotify("请先将错误数据修正,再重新导入提交!", MessageBoxIcon.Warning);
|
||
}
|
||
State = (int)ButtonState.Save;
|
||
ShowNotify("数据导入成功!", MessageBoxIcon.Success);
|
||
}
|
||
#endregion
|
||
/// <summary>
|
||
/// 提交
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnSave_Click(object sender, EventArgs e)
|
||
{
|
||
if (State != (int)ButtonState.Save)
|
||
{
|
||
ShowNotify("请先审核/导入");
|
||
return;
|
||
}
|
||
if (string.IsNullOrEmpty(errorInfos))
|
||
{
|
||
string rootPath = Server.MapPath("~/");
|
||
string oldefilePath = rootPath + initPath + this.hdFileName.Text;
|
||
//string unitworkId = Request.Params["UnitWorkId"];
|
||
string filePath = rootPath + Const.DesignBasisDataImportPath + this.hdFileName.Text;
|
||
if (oldefilePath != string.Empty && System.IO.File.Exists(oldefilePath))
|
||
{
|
||
if (!Directory.Exists(rootPath + Const.DesignBasisDataImportPath))
|
||
{
|
||
Directory.CreateDirectory(rootPath + Const.DesignBasisDataImportPath);
|
||
}
|
||
File.Move(oldefilePath, filePath);
|
||
}
|
||
string FileName = this.fuAttachUrl.FileName;
|
||
|
||
|
||
//if (DrpType.SelectedValue == "1")//更新导入
|
||
//{
|
||
// //BLL.Batch_NDEService.DeleteNDEByUnitWorkId(unitworkId);//删除
|
||
// AddNDE(ndes);
|
||
// AddNDEItem(ndeItems);
|
||
|
||
// //Model.HJGL_DesignBasisDataImport hJGL_DesignBasisDataImport = new Model.HJGL_DesignBasisDataImport();
|
||
// //hJGL_DesignBasisDataImport.DesignBasisDataImportId = SQLHelper.GetNewID();
|
||
// //hJGL_DesignBasisDataImport.ProjectId = this.CurrUser.LoginProjectId;
|
||
// //hJGL_DesignBasisDataImport.UnitWorkId = unitworkId;
|
||
// //hJGL_DesignBasisDataImport.ImportType = "1";
|
||
// //hJGL_DesignBasisDataImport.DataClassification = DataClassification;
|
||
// //hJGL_DesignBasisDataImport.FileName = FileName;
|
||
// //hJGL_DesignBasisDataImport.FilePath = filePath.Replace(rootPath, "");
|
||
// //hJGL_DesignBasisDataImport.FileType = BLL.HJGL_DesignBasisDataImportService.GetFileType(FileName);
|
||
// //hJGL_DesignBasisDataImport.Version = BLL.HJGL_DesignBasisDataImportService.GetNewVersionByUnitWorkId(unitworkId, DataClassification);
|
||
// //hJGL_DesignBasisDataImport.Remark = txtRemark.Text;
|
||
// //hJGL_DesignBasisDataImport.CreateMan = this.CurrUser.PersonId;
|
||
// //hJGL_DesignBasisDataImport.CreateDate = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");
|
||
// //BLL.HJGL_DesignBasisDataImportService.AddHJGL_DesignBasisDataImport(hJGL_DesignBasisDataImport);
|
||
|
||
// //BLL.HJGL_DesignBasisDataImportVerSionLogService.UpdateVersion(this.CurrUser.LoginProjectId, unitworkId, (decimal)hJGL_DesignBasisDataImport.Version, DataClassification);
|
||
//}
|
||
//else //补充导入
|
||
//{
|
||
AddNDE(ndes);
|
||
AddNDEItem(ndeItems);
|
||
|
||
//Model.HJGL_DesignBasisDataImport hJGL_DesignBasisDataImport = new Model.HJGL_DesignBasisDataImport();
|
||
//hJGL_DesignBasisDataImport.DesignBasisDataImportId = SQLHelper.GetNewID();
|
||
//hJGL_DesignBasisDataImport.ProjectId = this.CurrUser.LoginProjectId;
|
||
//hJGL_DesignBasisDataImport.UnitWorkId = unitworkId;
|
||
//hJGL_DesignBasisDataImport.ImportType = "0";
|
||
//hJGL_DesignBasisDataImport.DataClassification = DataClassification;
|
||
//hJGL_DesignBasisDataImport.FileName = FileName;
|
||
//hJGL_DesignBasisDataImport.FilePath = filePath.Replace(rootPath, ""); ;
|
||
//hJGL_DesignBasisDataImport.FileType = BLL.HJGL_DesignBasisDataImportService.GetFileType(FileName);
|
||
//hJGL_DesignBasisDataImport.Version = BLL.HJGL_DesignBasisDataImportService.GetNowVersionByUnitWorkId(unitworkId, DataClassification);
|
||
//hJGL_DesignBasisDataImport.Remark = txtRemark.Text;
|
||
//hJGL_DesignBasisDataImport.CreateMan = this.CurrUser.PersonId;
|
||
//hJGL_DesignBasisDataImport.CreateDate = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");
|
||
//BLL.HJGL_DesignBasisDataImportService.AddHJGL_DesignBasisDataImport(hJGL_DesignBasisDataImport);
|
||
|
||
//BLL.HJGL_DesignBasisDataImportVerSionLogService.UpdateVersion(this.CurrUser.LoginProjectId, unitworkId, (decimal)hJGL_DesignBasisDataImport.Version, DataClassification);
|
||
//}
|
||
ShowNotify("导入成功!", MessageBoxIcon.Success);
|
||
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
|
||
}
|
||
else
|
||
{
|
||
ShowNotify("请先将错误数据修正,再重新导入提交!", MessageBoxIcon.Warning);
|
||
}
|
||
}
|
||
|
||
public void AddNDE(List<HJGL_Batch_NDE> ndeList)
|
||
{
|
||
foreach (var item in ndeList)
|
||
{
|
||
var nde = from x in Funs.DB.HJGL_Batch_NDE where x.NDEID == item.NDEID select x;
|
||
if (nde.Count() == 0 || nde == null)
|
||
{
|
||
//item.NDEID = SQLHelper.GetNewID(typeof(Model.HJGL_Batch_NDE));
|
||
item.NDEID = item.NDEID;
|
||
BLL.Batch_NDEService.AddNDE(item);
|
||
|
||
//更新委托中的检测状态
|
||
var trustBatch = BLL.Batch_BatchTrustService.GetBatchTrustById(item.TrustBatchId);
|
||
if (trustBatch != null)
|
||
{
|
||
trustBatch.IsCheck = true;
|
||
BLL.Batch_BatchTrustService.UpdatTrustBatchtState(item.TrustBatchId, trustBatch.IsCheck);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
item.NDEID = item.NDEID;
|
||
BLL.Batch_NDEService.UpdateNDE(item);
|
||
}
|
||
}
|
||
}
|
||
|
||
public void AddNDEItem(List<HJGL_Batch_NDEItem> itemList)
|
||
{
|
||
foreach (var item in itemList)
|
||
{
|
||
//var ndeItem = from x in Funs.DB.HJGL_Batch_NDEItem where x.TrustBatchItemId==item.TrustBatchItemId select x;
|
||
//if (ndeItem.Count() == 0 || ndeItem == null)
|
||
//{
|
||
//item.NDEItemID = SQLHelper.GetNewID(typeof(Model.HJGL_Batch_NDEItem));
|
||
BLL.Batch_NDEItemService.AddNDEItem(item);
|
||
//}
|
||
//else
|
||
//{
|
||
// item.NDEItemID = ndeItem.First().NDEItemID;
|
||
// BLL.Batch_NDEItemService.UpdateNDEItem(item);
|
||
//}
|
||
}
|
||
}
|
||
|
||
#region 格式化字符串
|
||
protected string ConvertPipeLineCode(object trustBatchItemId)
|
||
{
|
||
string pipelineCode = string.Empty;
|
||
if (trustBatchItemId != null)
|
||
{
|
||
var trustBatchItem = (from x in Funs.DB.View_Batch_BatchTrustItem where x.TrustBatchItemId == trustBatchItemId.ToString() select x).FirstOrDefault();
|
||
if (trustBatchItem != null)
|
||
{
|
||
pipelineCode = trustBatchItem.PipelineCode;
|
||
}
|
||
}
|
||
return pipelineCode;
|
||
}
|
||
|
||
protected string ConvertWeldjointNo(object trustBatchItemId)
|
||
{
|
||
string weldJointCode = string.Empty;
|
||
if (trustBatchItemId != null)
|
||
{
|
||
var trustBatchItem = (from x in Funs.DB.View_Batch_BatchTrustItem where x.TrustBatchItemId == trustBatchItemId.ToString() select x).FirstOrDefault();
|
||
if (trustBatchItem != null)
|
||
{
|
||
weldJointCode = trustBatchItem.WeldJointCode;
|
||
}
|
||
}
|
||
return weldJointCode;
|
||
}
|
||
|
||
protected string ConvertWelderCode(object trustBatchItemId)
|
||
{
|
||
string welderCode = string.Empty;
|
||
if (trustBatchItemId != null)
|
||
{
|
||
var trustBatchItem = (from x in Funs.DB.View_Batch_BatchTrustItem where x.TrustBatchItemId == trustBatchItemId.ToString() select x).FirstOrDefault();
|
||
if (trustBatchItem != null)
|
||
{
|
||
welderCode = trustBatchItem.WelderCode;
|
||
}
|
||
}
|
||
return welderCode;
|
||
}
|
||
protected string ConvertCheckResult(object CheckResult)
|
||
{
|
||
string result = string.Empty;
|
||
if (CheckResult != null)
|
||
{
|
||
if (CheckResult.ToString() == "1")
|
||
{
|
||
result = "合格";
|
||
}
|
||
else
|
||
{
|
||
result = "不合格";
|
||
}
|
||
}
|
||
return result;
|
||
}
|
||
|
||
protected string ConvertCheckDefects(object CheckDefects)
|
||
{
|
||
string str = string.Empty;
|
||
if (CheckDefects != null)
|
||
{
|
||
str = BLL.Base_DefectService.GetDefectNameStrByDefectIdStr(CheckDefects.ToString());
|
||
}
|
||
return str;
|
||
}
|
||
#endregion
|
||
}
|
||
} |