HJGL_DS/HJGL_DS/FineUIPro.Web/HJGL/HotProessManage/HotProessManageEdit.aspx.cs

2069 lines
118 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using BLL;
using Newtonsoft.Json.Linq;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
namespace FineUIPro.Web.HJGL.HotProessManage
{
public partial class HotProessManageEdit : PageBase
{
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString();
this.drpIsoNo.SelectedValue = BLL.Const._Null;
this.drpProjectId.DataTextField = "ProjectCode";
this.drpProjectId.DataValueField = "ProjectId";
this.drpProjectId.DataSource = BLL.Base_ProjectService.GetOnProjectListByUserId(this.CurrUser.UserId, "1");
this.drpProjectId.DataBind();
Funs.FineUIPleaseSelect(this.drpProjectId);
this.drpProjectId.SelectedValue = this.CurrUser.LoginProjectId;
this.InitTreeMenu();//加载树
this.tvControlItem.SelectedNodeID = this.CurrUser.LoginProjectId;
this.drpIsoNo.DataTextField = "ISO_IsoNo";
this.drpIsoNo.DataValueField = "ISO_ID";
this.drpIsoNo.DataSource = from x in Funs.DB.HJGL_PW_IsoInfo where x.ProjectId == this.CurrUser.LoginProjectId select x;
this.drpIsoNo.DataBind();
Funs.FineUIPleaseSelect(this.drpIsoNo);
BindGrid();
this.txtUnit.Text = "管道";
this.txtProessMethod.Text = "电加热";
this.txtProessEquipment.Text = "智能温控仪";
}
}
#endregion
#region
/// <summary>
/// 加载树
/// </summary>
private void InitTreeMenu()
{
this.tvControlItem.Nodes.Clear();
TreeNode rootNode = new TreeNode();
rootNode.Text = "项目";
rootNode.NodeID = "0";
rootNode.Expanded = true;
rootNode.EnableClickEvent = true;
this.tvControlItem.Nodes.Add(rootNode);
List<Model.Base_Project> projects = BLL.Base_ProjectService.GetOnProjectListByUserId(this.CurrUser.UserId, "1");
if (this.drpProjectId.SelectedValueArray.Length > 1 || (this.drpProjectId.SelectedValueArray.Length == 1 && this.drpProjectId.SelectedValue != "null"))
{
projects = projects.Where(x => this.drpProjectId.SelectedValueArray.Contains(x.ProjectId)).ToList();
}
foreach (var item in projects)
{
TreeNode rootUnitNode = new TreeNode();//定义根节点
rootUnitNode.Text = item.ProjectCode;
rootUnitNode.NodeID = item.ProjectId;
rootUnitNode.Expanded = true;
rootUnitNode.ToolTip = item.ProjectName;
rootUnitNode.CommandName = "项目名称";
rootUnitNode.EnableClickEvent = true;
rootNode.Nodes.Add(rootUnitNode);
}
}
#endregion
#region TreeView
/// <summary>
/// 点击TreeView
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e)
{
string projectId = tvControlItem.SelectedNodeID;
this.drpIsoNo.Items.Clear();
this.drpIsoNo.DataSource = from x in Funs.DB.HJGL_PW_IsoInfo where x.ProjectId == projectId select x;
this.drpIsoNo.DataBind();
Funs.FineUIPleaseSelect(this.drpIsoNo);
this.drpIsoNo.SelectedValue = BLL.Const._Null;
this.BindGrid();
}
#endregion
#region
protected void drpProjectId_SelectedIndexChanged(object sender, EventArgs e)
{
this.InitTreeMenu();
}
/// <summary>
/// 数据绑定
/// </summary>
private void BindGrid()
{
this.PageInfoLoad(); ///页面输入提交信息
this.txtHotProessNo.Text = string.Empty;
string strSql = string.Empty;
List<SqlParameter> listStr = new List<SqlParameter>();
string projectIds = BLL.Base_ProjectService.GetStrOnProjectIds(this.CurrUser.UserId, "1");
if (this.tvControlItem.SelectedNode.CommandName == "项目名称")
{
strSql = @"SELECT JointInfo.ProjectId,JointInfo.JOT_ID,Project.ProjectCode,HotProessItem.PrintDate,Sort1,Sort2,Sort3,Sort4,Sort5,
JointInfo.JOT_ID+'1' as JOT_ID1, JointInfo.JOT_ID+'2' as JOT_ID2,JointInfo.JOT_ID+'3' as JOT_ID3,JointInfo.JOT_ID+'4' as JOT_ID4,
(CASE WHEN v.RepairMark IS NOT NULL THEN (JointInfo.JOT_JointNo+v.RepairMark)
ELSE JointInfo.JOT_JointNo END )+isnull((select Top 1 HardRepairMark from dbo.HJGL_CH_HotProessTrustItem a where a.JOT_ID=HotProessItem.JOT_ID and a.HotProessTrustId=HotProessItem.HotProessTrustId and a.ProessTypes=HotProessItem.ProessTypes),'') AS JOT_JointNo,IsoInfo.ISO_IsoNo,IsoInfo.ISO_ID,
(CASE WHEN Steel.STE_Code IS NOT NULL AND Steel2.STE_Code IS NOT NULL and Steel.STE_Code!=Steel2.STE_Code
THEN Steel.STE_Code + '/' + Steel2.STE_Code
WHEN Steel.STE_Code IS NOT NULL THEN Steel.STE_Code
ELSE ISNULL(Steel2.STE_Code,'') END) AS STE_Code,ThermocouplesNum,HeatingRange,InsulationRange,InsulationThickness,HotStartDate,HotEndDate,
HotProessItem.PointCount,HotProessItem.RequiredT,HotProessItem.ActualT,
HotProessItem.RequestTime,HotProessItem.ActualTime,HotProessItem.RecordChartNo,
HotProessItem.HotProessDate,HotProessItem.HotProessTrustId,
(SELECT (case when HotHardCode is null then HardTestReportCode else HotHardCode end) as HardTestReportCode FROM dbo.HJGL_CH_HardTestReport
WHERE HardTestReportId =(SELECT TOP 1 re.HardTestReportId FROM dbo.HJGL_CH_HardTestReportItem item
left join dbo.HJGL_CH_HardTestReport re on item.HardTestReportId=re.HardTestReportId
WHERE item.JOT_ID=HotProessItem.JOT_ID AND item.HotProessTrustId=HotProessItem.HotProessTrustId and (re.FileType='R' or re.FileType is null)))
AS HardnessReportNo,
HotProessItem.HotProessItemId,HotProessItem.SortIndex,HotProessItem.ProessTypes,JointInfo.JOT_JointDesc,isnull(HotProessItem.Remark,'') as Remark
FROM dbo.HJGL_HotProessItem AS HotProessItem
LEFT JOIN dbo.HJGL_PW_JointInfo AS JointInfo ON JointInfo.JOT_ID = HotProessItem.JOT_ID
LEFT JOIN dbo.HJGL_PW_IsoInfo AS IsoInfo ON JointInfo.ISO_ID = IsoInfo.ISO_ID
left join Base_Project as Project on Project.ProjectId = IsoInfo.ProjectId
LEFT JOIN dbo.Project_WorkArea AS WorkArea ON IsoInfo.BAW_ID = WorkArea.WorkAreaId
LEFT JOIN dbo.HJGL_BS_Steel AS Steel ON JointInfo.STE_ID = Steel.STE_ID
LEFT JOIN dbo.HJGL_BS_Steel AS Steel2 ON JointInfo.STE_ID2 = Steel2.STE_ID
left join (select record.RepairMark,record.JOT_ID,h.HotProessItemId from dbo.HJGL_CH_HotProessTrustItem AS TrustItem
left join dbo.HJGL_CH_RepairItemRecord AS record ON record.RepairItemRecordId=TrustItem.TrustItemID
left join dbo.HJGL_HotProessItem h on h.JOT_ID=TrustItem.JOT_ID
where h.JOT_ID = TrustItem.JOT_ID and h.HotProessTrustId=TrustItem.HotProessTrustId and h.ProessTypes=TrustItem.ProessTypes) v
on v.JOT_ID=HotProessItem.JOT_ID and v.HotProessItemId=HotProessItem.HotProessItemId
WHERE JointInfo.ProjectId= @ProjectId ";
listStr.Add(new SqlParameter("@ProjectId", this.tvControlItem.SelectedNodeID));
if (this.drpIsoNo.SelectedValue != BLL.Const._Null)
{
strSql += @" AND IsoInfo.ISO_ID = @ISO_ID";
listStr.Add(new SqlParameter("@ISO_ID", this.drpIsoNo.SelectedValue));
}
if (!string.IsNullOrEmpty(this.txtSearchNo.Text.Trim()))
{
strSql += @" AND HotProessItem.RecordChartNo like @RecordChartNo";
listStr.Add(new SqlParameter("@RecordChartNo", "%" + this.txtSearchNo.Text.Trim() + "%"));
}
if (this.rblIsPrint.SelectedValue == "0")
{
strSql += @" AND HotProessItem.PrintDate is null";
}
else
{
strSql += @" AND HotProessItem.PrintDate is not null";
}
var hotProessItems = from x in Funs.DB.View_HotProessItem where x.ProjectId == this.tvControlItem.SelectedNodeID && x.PrintDate != null && x.IsPrint == null select x;
foreach (var item in hotProessItems)
{
Model.HJGL_HotProessItem hItem = BLL.HJGL_HotProessManageEditService.GetHotProessItemByHotProessItemId(item.HotProessItemId);
if (hItem != null)
{
hItem.IsPrint = true;
Funs.DB.SubmitChanges();
}
}
}
else
{
strSql = @"SELECT JointInfo.ProjectId,JointInfo.JOT_ID,Project.ProjectCode,HotProessItem.PrintDate,Sort1,Sort2,Sort3,Sort4,Sort5,
JointInfo.JOT_ID+'1' as JOT_ID1, JointInfo.JOT_ID+'2' as JOT_ID2,JointInfo.JOT_ID+'3' as JOT_ID3,JointInfo.JOT_ID+'4' as JOT_ID4,
(CASE WHEN v.RepairMark IS NOT NULL THEN (JointInfo.JOT_JointNo+v.RepairMark)
ELSE JointInfo.JOT_JointNo END )+isnull((select Top 1 HardRepairMark from dbo.HJGL_CH_HotProessTrustItem a where a.JOT_ID=HotProessItem.JOT_ID and a.HotProessTrustId=HotProessItem.HotProessTrustId and a.ProessTypes=HotProessItem.ProessTypes),'') AS JOT_JointNo,IsoInfo.ISO_IsoNo,IsoInfo.ISO_ID,
(CASE WHEN Steel.STE_Code IS NOT NULL AND Steel2.STE_Code IS NOT NULL and Steel.STE_Code!=Steel2.STE_Code
THEN Steel.STE_Code + '/' + Steel2.STE_Code
WHEN Steel.STE_Code IS NOT NULL THEN Steel.STE_Code
ELSE ISNULL(Steel2.STE_Code,'') END) AS STE_Code,ThermocouplesNum,HeatingRange,InsulationRange,InsulationThickness,HotStartDate,HotEndDate,
HotProessItem.PointCount,HotProessItem.RequiredT,HotProessItem.ActualT,HotProessItem.RequestTime,
HotProessItem.ActualTime,HotProessItem.RecordChartNo,
HotProessItem.HotProessDate,HotProessItem.HotProessTrustId,HotProessItem.HotProessItemId,HotProessItem.SortIndex,
(SELECT (case when HotHardCode is null then HardTestReportCode else HotHardCode end) as HardTestReportCode FROM dbo.HJGL_CH_HardTestReport
WHERE HardTestReportId =(SELECT TOP 1 re.HardTestReportId FROM dbo.HJGL_CH_HardTestReportItem item
left join dbo.HJGL_CH_HardTestReport re on item.HardTestReportId=re.HardTestReportId
WHERE item.JOT_ID=HotProessItem.JOT_ID AND item.HotProessTrustId=HotProessItem.HotProessTrustId and (re.FileType='R' or re.FileType is null)))
AS HardnessReportNo,
HotProessItem.ProessTypes,JointInfo.JOT_JointDesc,isnull(HotProessItem.Remark,'') as Remark
FROM dbo.HJGL_HotProessItem AS HotProessItem
LEFT JOIN dbo.HJGL_PW_JointInfo AS JointInfo ON JointInfo.JOT_ID = HotProessItem.JOT_ID
LEFT JOIN dbo.HJGL_PW_IsoInfo AS IsoInfo ON JointInfo.ISO_ID = IsoInfo.ISO_ID
left join Base_Project as Project on Project.ProjectId = IsoInfo.ProjectId
LEFT JOIN dbo.Project_WorkArea AS WorkArea ON IsoInfo.BAW_ID = WorkArea.WorkAreaId
LEFT JOIN dbo.HJGL_BS_Steel AS Steel ON JointInfo.STE_ID = Steel.STE_ID
LEFT JOIN dbo.HJGL_BS_Steel AS Steel2 ON JointInfo.STE_ID2 = Steel2.STE_ID
left join (select record.RepairMark,record.JOT_ID,h.HotProessItemId from dbo.HJGL_CH_HotProessTrustItem AS TrustItem
left join dbo.HJGL_CH_RepairItemRecord AS record ON record.RepairItemRecordId=TrustItem.TrustItemID
left join dbo.HJGL_HotProessItem h on h.JOT_ID=TrustItem.JOT_ID
where h.JOT_ID = TrustItem.JOT_ID and h.HotProessTrustId=TrustItem.HotProessTrustId and h.ProessTypes=TrustItem.ProessTypes) v
on v.JOT_ID=HotProessItem.JOT_ID and v.HotProessItemId=HotProessItem.HotProessItemId
WHERE CHARINDEX(JointInfo.ProjectId,@ProjectId)>0 ";
listStr.Add(new SqlParameter("@ProjectId", projectIds));
if (this.drpIsoNo.SelectedValue != BLL.Const._Null)
{
strSql += @" AND IsoInfo.ISO_ID = @ISO_ID";
listStr.Add(new SqlParameter("@ISO_ID", this.drpIsoNo.SelectedValue));
}
if (!string.IsNullOrEmpty(this.txtSearchNo.Text.Trim()))
{
strSql += @" AND HotProessItem.RecordChartNo like @RecordChartNo";
listStr.Add(new SqlParameter("@RecordChartNo", "%" + this.txtSearchNo.Text.Trim() + "%"));
}
if (this.rblIsPrint.SelectedValue == "0")
{
strSql += @" AND HotProessItem.PrintDate is null";
}
else
{
strSql += @" AND HotProessItem.PrintDate is not null";
}
}
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
// 2.获取当前分页数据
//var table = this.GetPagedDataTable(Grid1, tb1);
Grid1.RecordCount = tb.Rows.Count;
tb = GetFilteredTable(Grid1.FilteredData, tb);
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
if (this.drpIsoNo.SelectedValue != BLL.Const._Null)
{
Model.HJGL_PW_IsoInfo iso = BLL.HJGL_PW_IsoInfoService.GetIsoInfoByIsoInfoId(this.drpIsoNo.SelectedValue);
if (iso != null)
{
string projectPrefix = BLL.Base_ProjectService.GetProjectByProjectId(iso.ProjectId).ProjectCode + "-";
string isoPrefix = BLL.Base_ProjectService.GetProjectByProjectId(iso.ProjectId).ProjectCode + "-" + iso.ISO_IsoNo + "-";
var hotProess = (from x in Funs.DB.HJGL_HotProess where x.HotProessNo.Contains(projectPrefix) select x).FirstOrDefault();
if (hotProess == null) //项目还未有打印记录
{
this.txtHotProessNo.Text = isoPrefix + "0001";
}
else
{
var isoHotProess = (from x in Funs.DB.HJGL_HotProess where x.HotProessNo.Contains(isoPrefix) select x).FirstOrDefault();
if (isoHotProess != null) //管线打印记录已存在,则保持原有打印记录编号
{
this.txtHotProessNo.Text = isoHotProess.HotProessNo;
}
else
{
var hotProessNos = (from x in Funs.DB.HJGL_HotProess where x.HotProessNo.Contains(projectPrefix) orderby x.HotProessNo.Substring(x.HotProessNo.Length - 4) descending select x.HotProessNo.Substring(x.HotProessNo.Length - 4)).ToList();
this.txtHotProessNo.Text = isoPrefix + GetNo(Convert.ToInt32(hotProessNos[0]) + 1);
}
}
//this.txtHotProessNo.Text = BLL.SQLHelper.RunProcNewIdByProjectId("SpGetNewCodeByProjectId", "dbo.HJGL_HotProess", "HotProessNo", iso.ProjectId, BLL.Base_ProjectService.GetProjectByProjectId(iso.ProjectId).ProjectCode + "-" + DateTime.Now.Year.ToString());
}
}
var hardTestReportItems = from x in Funs.DB.HJGL_CH_HardTestReportItem select x;
var hardTestReports = from x in Funs.DB.HJGL_CH_HardTestReport select x;
for (int i = 0; i < this.Grid1.Rows.Count; i++)
{
string hotProessItemId = this.Grid1.Rows[i].DataKeys[0].ToString();
Model.HJGL_HotProessItem hotProessItem = BLL.HJGL_HotProessManageEditService.GetHotProessItemByHotProessItemId(hotProessItemId);
if (hotProessItem != null)
{
Model.HJGL_CH_HardTestReport hardTestReport = (from x in hardTestReports
join y in hardTestReportItems
on x.HardTestReportId equals y.HardTestReportId
where y.JOT_ID == hotProessItem.JOT_ID && y.HotProessTrustId == hotProessItem.HotProessTrustId
select x).FirstOrDefault();
if (hardTestReport != null && hardTestReport.IsPrintTrust == true) //硬度委托打印后,不能修改热处理录入数据
{
this.Grid1.Rows[i].CellCssClasses[2] = "color";
}
}
this.Grid1.Rows[i].Values[8] = this.Grid1.Rows[i].Values[8].ToString().Replace("&#177;", "±");
}
}
private string GetNo(int i)
{
if (i < 10)
{
return "000" + i.ToString();
}
else if (i < 100)
{
return "00" + i.ToString();
}
else if (i < 1000)
{
return "0" + i.ToString();
}
else
{
return i.ToString();
}
}
#region
/// <summary>
/// 加载页面输入提交信息
/// </summary>
private void PageInfoLoad()
{
//this.btnPrint.Hidden = false;
this.btnPrintNew.Hidden = false;
this.btnSave.Hidden = false;
this.SimpleForm1.Reset(); ///重置所有字段
}
#endregion
#endregion
/// <summary>
/// 判断是否修改
/// </summary>
/// <returns></returns>
private bool IsEdit()
{
bool isEdit = true;
//var hotHardItem = Funs.DB.HJGL_View_HotHardItem.FirstOrDefault(x => x.HotProessId == this.HotProessId && x.HotHardID != null);
//if (hotHardItem != null)
//{
// isEdit = false;
//}
return isEdit;
}
#region
#region
/// <summary>
/// 页索引改变事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
BindGrid();
}
#endregion
#region
/// <summary>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort(object sender, GridSortEventArgs e)
{
BindGrid();
}
#endregion
#region
/// <summary>
/// 分页选择下拉改变事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
BindGrid();
}
#endregion
#endregion
#region
/// <summary>
/// 关闭弹出窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
this.BindGrid();
}
/// <summary>
/// 关闭弹出窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window3_Close(object sender, WindowCloseEventArgs e)
{
string ids1 = string.Empty;
string ids2 = string.Empty;
if (!string.IsNullOrEmpty(this.hdItemsString.Text.Trim()) && this.hdItemsString.Text.Trim().Contains("|"))
{
ids1 = this.hdItemsString.Text.Trim().Split('|')[0];
ids2 = this.hdItemsString.Text.Trim().Split('|')[1];
}
if (!string.IsNullOrEmpty(ids1) && !string.IsNullOrEmpty(ids2))
{
string strSql = string.Empty;
List<SqlParameter> listStr = new List<SqlParameter>();
strSql = @"SELECT JointInfo.ProjectId,WorkArea.WorkAreaCode,WorkArea.WorkAreaId,JointInfo.JOT_ID,(CASE WHEN v.RepairMark IS NOT NULL THEN (JointInfo.JOT_JointNo+v.RepairMark)
ELSE JointInfo.JOT_JointNo END )+isnull((select Top 1 HardRepairMark from dbo.HJGL_CH_HotProessTrustItem a where a.JOT_ID=HotProessItem.JOT_ID and a.HotProessTrustId=HotProessItem.HotProessTrustId and a.ProessTypes=HotProessItem.ProessTypes),'') AS JOT_JointNo,IsoInfo.ISO_IsoNo,IsoInfo.ISO_ID,Steel.STE_Code,HotProessItem.PointCount,HotProessItem.RequiredT,HotProessItem.ActualT,HotProessItem.RequestTime,HotProessItem.ActualTime,HotProessItem.RecordChartNo,HotProessItem.HardnessReportNo,HotProessItem.HotProessDate,HotProessItem.HotProessTrustId,HotProessItem.HotProessItemId,HotProessItem.SortIndex,HotProessItem.ProessTypes,JointInfo.JOT_JointDesc,HotProessItem.Remark"
+ @" FROM dbo.HJGL_HotProessItem AS HotProessItem "
+ @" LEFT JOIN dbo.HJGL_PW_JointInfo AS JointInfo ON JointInfo.JOT_ID = HotProessItem.JOT_ID"
+ @" LEFT JOIN dbo.HJGL_PW_IsoInfo AS IsoInfo ON JointInfo.ISO_ID = IsoInfo.ISO_ID"
+ @" LEFT JOIN dbo.Project_WorkArea AS WorkArea ON IsoInfo.BAW_ID = WorkArea.WorkAreaId"
+ @" LEFT JOIN dbo.HJGL_BS_Steel AS Steel ON IsoInfo.STE_ID = Steel.STE_ID
left join (select record.RepairMark,record.JOT_ID,h.HotProessItemId from dbo.HJGL_CH_HotProessTrustItem AS TrustItem
left join dbo.HJGL_CH_RepairItemRecord AS record ON record.RepairItemRecordId=TrustItem.TrustItemID
left join dbo.HJGL_HotProessItem h on h.JOT_ID=TrustItem.JOT_ID
where h.JOT_ID = TrustItem.JOT_ID and h.HotProessTrustId=TrustItem.HotProessTrustId and h.ProessTypes=TrustItem.ProessTypes) v
on v.JOT_ID=HotProessItem.JOT_ID and v.HotProessItemId=HotProessItem.HotProessItemId "
+ @"WHERE @Ids1 like '%'+JointInfo.JOT_ID+'%' and @Ids2 like '%'+HotProessItem.HotProessTrustId+'%' order by IsoInfo.ISO_IsoNo,JointInfo.JOT_JointNo";
listStr.Add(new SqlParameter("@Ids1", ids1));
listStr.Add(new SqlParameter("@Ids2", ids2));
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
// 2.获取当前分页数据
//var table = this.GetPagedDataTable(Grid1, tb1);
Grid1.RecordCount = tb.Rows.Count;
tb = GetFilteredTable(Grid1.FilteredData, tb);
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
}
}
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Tree_TextChanged(object sender, EventArgs e)
{
this.InitTreeMenu();
this.BindGrid();
}
#endregion
#region
/// <summary>
/// 热处理表打印
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnPrint_Click(object sender, EventArgs e)
{
if (this.drpIsoNo.SelectedValue != BLL.Const._Null)
{
string varValue = String.Empty;
Model.HJGL_PW_IsoInfo iso = BLL.HJGL_PW_IsoInfoService.GetIsoInfoByIsoInfoId(this.drpIsoNo.SelectedValue);
if (iso != null)
{
Model.HJGL_HotProess hotProess = new Model.HJGL_HotProess();
hotProess.HotProessId = SQLHelper.GetNewID(typeof(Model.HJGL_HotProess));
hotProess.ProjectId = iso.ProjectId;
hotProess.HotProessNo = this.txtHotProessNo.Text.Trim();
hotProess.ProessDate = DateTime.Now;
BLL.HJGL_HotProessManageEditService.AddHotProess(hotProess);
}
string hotProessNo = this.txtHotProessNo.Text.Trim().Replace("/", ",");
string installName = string.Empty;
installName = this.txtUnit.Text.Trim().Replace("/", ",");
string proessMethod = this.txtProessMethod.Text.Trim().Replace("/", ",");
string proessEquipment = this.txtProessEquipment.Text.Trim().Replace("/", ",");
string projectName = string.Empty;
string reportId = string.Empty;
if (this.tvControlItem.SelectedNode != null)
{
Model.Base_Project selectProject = BLL.Base_ProjectService.GetProjectByProjectId(this.tvControlItem.SelectedNodeID);
if (selectProject != null)
{
projectName = selectProject.ProjectName.Replace("/", ",");
}
}
var hotProessItems = from x in Funs.DB.View_HotProessItem where x.RecordChartNo != null && x.RecordChartNo != "" select x;
var items = from x in hotProessItems
where x.ISO_ID == this.drpIsoNo.SelectedValue && x.HotProessItemId != null
select x;
if (this.rblIsPrint.SelectedValue == "0")
{
items = items.Where(x => x.IsPrint == null);
}
else
{
items = items.Where(x => x.IsPrint == true);
}
int count = items.Count(); //Grid行数
if (this.rblIsPrint.SelectedValue == "0")
{
foreach (var item in items)
{
Model.HJGL_HotProessItem hItem = BLL.HJGL_HotProessManageEditService.GetHotProessItemByHotProessItemId(item.HotProessItemId);
if (hItem != null)
{
hItem.PrintDate = DateTime.Now;
Funs.DB.SubmitChanges();
}
}
}
string pageNum = Funs.GetPagesCountByPageSize(12, 20, count).ToString();
varValue = projectName + "|" + installName + "|" + this.drpIsoNo.SelectedText.Replace("/", ",") + "|" + hotProessNo + "|" + proessMethod + "|" + proessEquipment + "|" + pageNum;
varValue = HttpUtility.UrlEncodeUnicode(varValue);
bool isOther = false; //是否存在一个口大于2个测温点的情况
var jotIds = (from x in hotProessItems
where x.ISO_ID == this.drpIsoNo.SelectedValue && x.HotProessItemId != null
select x.JOT_ID).Distinct().ToList(); //所选管线焊口Id集合
//int jointCount = jotIds.Count; //所选管线焊口数
int jointCount = 0; //所选管线焊口数
foreach (var jotId in jotIds)
{
var a = (from x in hotProessItems
where x.JOT_ID == jotId
select x).Count();
if (a > 2) //有焊口大于2个测温点
{
isOther = true;
}
}
this.Grid1.PageSize = 1000;
BindGrid();
List<string> jointNoLists = new List<string>();
for (int i = 0; i < this.Grid1.Rows.Count; i++)
{
System.Web.UI.WebControls.Label lbJOT_JointNo = (System.Web.UI.WebControls.Label)(this.Grid1.Rows[i].FindControl("lbJOT_JointNo"));
if (!string.IsNullOrEmpty(this.Grid1.Rows[i].Values[13].ToString()))
{
jointNoLists.Add(lbJOT_JointNo.Text);
}
//if (lbJOT_JointNo.Text.Contains("R"))
//{
// jointCount++;
//}
}
jointCount = jointNoLists.Distinct().Count();
if (count == jointCount) //全部是一个测温点
{
reportId = Const.HJGL_HotProessReportId1;
}
else if (count == (jointCount * 2) && !isOther) //全部是两个测温点
{
reportId = Const.HJGL_HotProessReportId2;
}
else if (count > jointCount && count < jointCount * 2 && !isOther) //全部由一或两个测温点组成
{
reportId = Const.HJGL_HotProessReportId3;
}
else //存在一个口大于2个测温点的情况
{
reportId = Const.HJGL_HotProessReportId4;
}
if (count <= 12)
{
PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("../../Common/ReportPrint/ExReportPrint.aspx?ispop=1&reportId={0}&replaceParameter={1}&varValue={2}&projectId=0", reportId, this.drpIsoNo.SelectedValue, varValue, "打印 - ")));
}
else
{
PageContext.RegisterStartupScript(Window4.GetShowReference(String.Format("../../Common/ReportPrint/ExReportPrint.aspx?ispop=1&reportId={0}&replaceParameter={1}&varValue={2}&projectId=0", Const.HJGL_HotProessReportTwoId, this.drpIsoNo.SelectedValue, varValue, "打印 - ")));
PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("../../Common/ReportPrint/ExReportPrint.aspx?ispop=1&reportId={0}&replaceParameter={1}&varValue={2}&projectId=0", reportId, this.drpIsoNo.SelectedValue, varValue, "打印 - ")));
}
}
else
{
ShowNotify("请选择管线!", MessageBoxIcon.Warning);
return;
}
}
/// <summary>
/// 打印(新)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnPrintNew_Click(object sender, EventArgs e)
{
if (this.drpIsoNo.SelectedValue != BLL.Const._Null)
{
string varValue = String.Empty;
Model.HJGL_PW_IsoInfo iso = BLL.HJGL_PW_IsoInfoService.GetIsoInfoByIsoInfoId(this.drpIsoNo.SelectedValue);
if (iso != null)
{
Model.HJGL_HotProess hotProess = new Model.HJGL_HotProess();
hotProess.HotProessId = SQLHelper.GetNewID(typeof(Model.HJGL_HotProess));
hotProess.ProjectId = iso.ProjectId;
hotProess.HotProessNo = this.txtHotProessNo.Text.Trim();
hotProess.ProessDate = DateTime.Now;
BLL.HJGL_HotProessManageEditService.AddHotProess(hotProess);
}
string hotProessNo = this.txtHotProessNo.Text.Trim().Replace("/", ",");
//string installName = string.Empty;
//installName = this.txtUnit.Text.Trim().Replace("/", ",");
string proessMethod = this.txtProessMethod.Text.Trim().Replace("/", ",");
string proessEquipment = this.txtProessEquipment.Text.Trim().Replace("/", ",");
string projectName = string.Empty;
//string reportId = string.Empty;
var hotProessItems = from x in Funs.DB.View_HotProessItem where x.RecordChartNo != null && x.RecordChartNo != "" select x;
var items = from x in hotProessItems
where x.ISO_ID == this.drpIsoNo.SelectedValue && x.HotProessItemId != null
select x;
if (this.rblIsPrint.SelectedValue == "0")
{
foreach (var item in items)
{
Model.HJGL_HotProessItem hItem = BLL.HJGL_HotProessManageEditService.GetHotProessItemByHotProessItemId(item.HotProessItemId);
if (hItem != null)
{
hItem.PrintDate = DateTime.Now;
Funs.DB.SubmitChanges();
}
}
}
if (this.tvControlItem.SelectedNode != null)
{
Model.Base_Project selectProject = BLL.Base_ProjectService.GetProjectByProjectId(this.tvControlItem.SelectedNodeID);
if (selectProject != null)
{
projectName = selectProject.ProjectName.Replace("/", ",");
}
}
string initTemplatePath = "";
string rootPath = Server.MapPath("~/");
BLL.Common.FastReportService.ResetData();
//传参
Dictionary<string, string> keyValuePairs = new Dictionary<string, string>();
keyValuePairs.Add("ProjectName", projectName);
//keyValuePairs.Add("InstallationName", installName);
keyValuePairs.Add("HotProessNo", hotProessNo);
keyValuePairs.Add("ProessMethod", proessMethod);
keyValuePairs.Add("ProessEquipment", proessEquipment);
BLL.Common.FastReportService.AddFastreportParameter(keyValuePairs);
List<SqlParameter> listStr = new List<SqlParameter>();
listStr.Add(new SqlParameter("@IsoId", this.drpIsoNo.SelectedValue));
listStr.Add(new SqlParameter("@Flag", "0"));
listStr.Add(new SqlParameter("@IsPrint", this.rblIsPrint.SelectedValue));
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = BLL.SQLHelper.GetDataTableRunProc("HJGL_spHotProessItem", parameter);
DataTable dt = new DataTable();
dt.TableName = "Data";
dt.Columns.Add("ISO_IsoNo");
dt.Columns.Add("JOT_JointNo");
dt.Columns.Add("PointCount");
dt.Columns.Add("RequiredT");
dt.Columns.Add("ActualT");
dt.Columns.Add("RequestTime");
dt.Columns.Add("ActualTime");
dt.Columns.Add("STE_Code");
dt.Columns.Add("JOT_JointDesc");
dt.Columns.Add("HotProessDate");
dt.Columns.Add("RecordChartNo");
dt.Columns.Add("HardnessReportNo");
DataView dv = tb.DefaultView;//获取表视图
dv.Sort = "Number ASC";//按照ID倒序排序
tb = dv.ToTable();//转为表
DataRow[] rows = tb.DefaultView.ToTable().Select();
foreach (var row in rows)
{
var newRows = dt.NewRow();
newRows["ISO_IsoNo"] = row["ISO_IsoNo"].ToString();
newRows["JOT_JointNo"] = row["JOT_JointNo"].ToString();
newRows["PointCount"] = row["PointCount"].ToString();
newRows["RequiredT"] = row["RequiredT"].ToString();
newRows["ActualT"] = row["ActualT"].ToString();
newRows["RequestTime"] = row["RequestTime"].ToString();
newRows["ActualTime"] = row["ActualTime"].ToString();
newRows["STE_Code"] = row["STE_Code"].ToString();
newRows["JOT_JointDesc"] = row["JOT_JointDesc"].ToString();
newRows["HotProessDate"] = string.Format("{0:yyyy-MM-dd}", row["HotProessDate"]);
newRows["RecordChartNo"] = row["RecordChartNo"].ToString();
newRows["HardnessReportNo"] = row["HardnessReportNo"].ToString();
dt.Rows.Add(newRows);
}
BLL.Common.FastReportService.AddFastreportTable(dt);
initTemplatePath = "File\\Fastreport\\管道焊接接头热处理报告.frx";
if (File.Exists(rootPath + initTemplatePath))
{
PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("../../common/ReportPrint/Fastreport.aspx?ReportPath={0}", rootPath + initTemplatePath)));
}
//List<SqlParameter> listStr = new List<SqlParameter>();
//listStr.Add(new SqlParameter("@IsoId", this.drpIsoNo.SelectedValue));
//listStr.Add(new SqlParameter("@Flag", "0"));
//listStr.Add(new SqlParameter("@IsPrint", this.rblIsPrint.SelectedValue));
//SqlParameter[] parameter = listStr.ToArray();
//DataTable tb = BLL.SQLHelper.GetDataTableRunProc("HJGL_spHotProessItem", parameter);
//string page = Funs.GetPagesCountByPageSize(7, 13, tb.Rows.Count).ToString();
//varValue = projectName + "|" + installName + "|" + this.drpIsoNo.SelectedText.Replace("/", ",") + "|" + hotProessNo + "|" + proessMethod + "|" + proessEquipment + "|" + page;
//if (!string.IsNullOrEmpty(varValue))
//{
// varValue = HttpUtility.UrlEncodeUnicode(varValue);
//}
//reportId = Const.HJGL_HotProessReportNewId1;
//if (tb.Rows.Count <= 7)
//{
// PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("../../Common/ReportPrint/ExReportPrint.aspx?ispop=1&reportId={0}&replaceParameter={1}&varValue={2}&projectId=0", reportId, this.drpIsoNo.SelectedValue + "|0|" + this.rblIsPrint.SelectedValue, varValue, "打印 - ")));
//}
//else
//{
// PageContext.RegisterStartupScript(Window4.GetShowReference(String.Format("../../Common/ReportPrint/ExReportPrint.aspx?ispop=1&reportId={0}&replaceParameter={1}&varValue={2}&projectId=0", Const.HJGL_HotProessReportNewId2, this.drpIsoNo.SelectedValue + "|2|" + this.rblIsPrint.SelectedValue, varValue, "打印 - ")));
// PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("../../Common/ReportPrint/ExReportPrint.aspx?ispop=1&reportId={0}&replaceParameter={1}&varValue={2}&projectId=0", reportId, this.drpIsoNo.SelectedValue + "|1|" + this.rblIsPrint.SelectedValue, varValue, "打印 - ")));
//}
}
else
{
ShowNotify("请选择管线!", MessageBoxIcon.Warning);
return;
}
}
#endregion
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void TextBox_TextChanged(object sender, EventArgs e)
{
this.BindGrid();
}
protected void TextBox2_TextChanged(object sender, EventArgs e)
{
this.BindGrid();
}
/// <summary>
/// 得到热处理类型
/// </summary>
/// <param name="bigType"></param>
/// <returns></returns>
protected string ConvertProessTypes(object ProessTypes)
{
string proessTypes = string.Empty;
if (ProessTypes != null)
{
proessTypes = BLL.HJGL_PW_JointInfoService.ConvertProessTypes(ProessTypes.ToString());
}
return proessTypes;
}
/// <summary>
/// 是否生成报告
/// </summary>
/// <param name="bigType"></param>
/// <returns></returns>
protected string ConvertReport(object PrintDate)
{
if (PrintDate != null)
{
if (!string.IsNullOrEmpty(PrintDate.ToString()))
{
return "已生成";
}
}
return "";
}
#region Grid
/// <summary>
/// 右键增加
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnAdd_Click(object sender, EventArgs e)
{
SaveData();
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning);
return;
}
JArray mergedData = Grid1.GetMergedData();
foreach (JObject mergedRow in mergedData)
{
string status = mergedRow.Value<string>("status");
JObject values = mergedRow.Value<JObject>("values");
int rowIndex = mergedRow.Value<int>("index");
string jot_id = values.Value<string>("JOT_ID").ToString();
if (rowIndex == this.Grid1.SelectedRowIndex)
{
Model.HJGL_HotProessItem newHotProessItem = new Model.HJGL_HotProessItem();
newHotProessItem.HotProessItemId = SQLHelper.GetNewID(typeof(Model.HJGL_HotProessItem));
newHotProessItem.JOT_ID = jot_id;
newHotProessItem.RequiredT = values.Value<string>("RequiredT").ToString();
newHotProessItem.ActualT = values.Value<string>("ActualT").ToString();
newHotProessItem.RequestTime = values.Value<string>("RequestTime").ToString();
newHotProessItem.ActualTime = values.Value<string>("ActualTime").ToString();
newHotProessItem.HotProessDate = Funs.GetNewDateTime(values.Value<string>("HotProessDate").ToString());
newHotProessItem.RecordChartNo = values.Value<string>("RecordChartNo").ToString();
newHotProessItem.HotProessTrustId = values.Value<string>("HotProessTrustId").ToString();
newHotProessItem.ProessTypes = values.Value<string>("ProessTypes").ToString();
newHotProessItem.SortIndex = BLL.HJGL_HotProessManageEditService.GetSortIndex(newHotProessItem.HotProessTrustId, jot_id, newHotProessItem.ProessTypes);
newHotProessItem.Remark = values.Value<string>("Remark").ToString();
BLL.HJGL_HotProessManageEditService.AddHotProessItem(newHotProessItem, "", null);
}
}
this.BindGrid();
}
/// <summary>
/// 右键同上
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnCopy_Click(object sender, EventArgs e)
{
SaveData();
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning);
return;
}
//string[] strs = this.Grid1.SelectedCell; //选择的单元格
int rowId = this.Grid1.SelectedRowIndex;
string RequiredT = string.Empty;
string ActualT = string.Empty;
string RequestTime = string.Empty;
string ActualTime = string.Empty;
string HotProessDate = string.Empty;
string RecordChartNo = string.Empty;
string Remark = string.Empty;
JArray mergedData = Grid1.GetMergedData();
if (this.Grid1.SelectedRowIndex > 0)
{
foreach (JObject mergedRow in mergedData)
{
string status = mergedRow.Value<string>("status");
JObject values = mergedRow.Value<JObject>("values");
int rowIndex = mergedRow.Value<int>("index");
if (rowIndex == this.Grid1.SelectedRowIndex - 1) //选择行的上一行
{
RequiredT = values.Value<string>("RequiredT").ToString();
ActualT = values.Value<string>("ActualT").ToString();
RequestTime = values.Value<string>("RequestTime").ToString();
ActualTime = values.Value<string>("ActualTime").ToString();
HotProessDate = values.Value<string>("HotProessDate").ToString();
RecordChartNo = values.Value<string>("RecordChartNo").ToString();
Remark = values.Value<string>("Remark").ToString();
}
if (rowIndex == this.Grid1.SelectedRowIndex)
{
Model.HJGL_HotProessItem newHotProessItem = BLL.HJGL_HotProessManageEditService.GetHotProessItemByHotProessItemId(this.Grid1.Rows[rowIndex].DataKeys[0].ToString());
newHotProessItem.RequiredT = RequiredT;
newHotProessItem.ActualT = ActualT;
newHotProessItem.RequestTime = RequestTime;
newHotProessItem.ActualTime = ActualTime;
newHotProessItem.HotProessDate = Funs.GetNewDateTime(HotProessDate);
newHotProessItem.RecordChartNo = RecordChartNo;
newHotProessItem.Remark = Remark;
Funs.DB.SubmitChanges();
}
}
this.BindGrid();
this.Grid1.SelectedRowIndex = rowId + 1;
}
}
/// <summary>
/// 右键删除
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnDelete_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_HotProessManageEditMenuId, Const.BtnDelete))
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning);
return;
}
var hardTestReportItems = from x in Funs.DB.HJGL_CH_HardTestReportItem select x;
var hardTestReports = from x in Funs.DB.HJGL_CH_HardTestReport select x;
foreach (var item in this.Grid1.SelectedRowIDArray)
{
Model.HJGL_HotProessItem hotProessItem = BLL.HJGL_HotProessManageEditService.GetHotProessItemByHotProessItemId(item);
if (hotProessItem != null)
{
Model.HJGL_CH_HardTestReport hardTestReport = (from x in hardTestReports
join y in hardTestReportItems
on x.HardTestReportId equals y.HardTestReportId
where y.JOT_ID == hotProessItem.JOT_ID && y.HotProessTrustId == hotProessItem.HotProessTrustId
select x).FirstOrDefault();
var hotProessItems = from x in Funs.DB.HJGL_HotProessItem
where x.JOT_ID == hotProessItem.JOT_ID && x.HotProessTrustId == hotProessItem.HotProessTrustId && x.ProessTypes == hotProessItem.ProessTypes
select x;
//if (hardTestReport != null && hardTestReport.IsPrintTrust == true) //硬度委托打印后,不能删除热处理录入数据
//{
// //if (this.CurrUser.UserId == BLL.Const.GlyId) //管理员可以删除数据
// //{
// // BLL.HJGL_HotProessManageEditService.DeleteHotProessItemByHotProessItemId(item);
// //}
// Alert.ShowInTop("硬度委托已打印,不能删除热处理录入数据!", MessageBoxIcon.Warning);
// return;
//}
if (hotProessItems.Count() == 1) //该委托对应的热处理数据只有一条
{
var hotProessTrustItem = (from x in Funs.DB.HJGL_CH_HotProessTrustItem
where x.JOT_ID == hotProessItem.JOT_ID && x.HotProessTrustId == hotProessItem.HotProessTrustId && x.ProessTypes == hotProessItem.ProessTypes
select x).FirstOrDefault();
if (hotProessTrustItem != null) //热处理委托明细信息存在
{
Alert.ShowInTop("热处理委托明细只存在一条热处理录入数据,不能删除!", MessageBoxIcon.Warning);
return;
}
}
else
{
BLL.HJGL_HotProessManageEditService.DeleteHotProessItemByHotProessItemId(item);
}
}
}
this.BindGrid();
}
else
{
ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
}
}
#endregion
#region
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_HotProessManageEditMenuId, Const.BtnSave))
{
//int count = 0;
//for (int i = 0; i < this.Grid1.Rows.Count; i++)
//{
// System.Web.UI.WebControls.CheckBoxList cblProessTypes = (System.Web.UI.WebControls.CheckBoxList)(this.Grid1.Rows[i].FindControl("cblProessTypes"));
// for (int j = 0; j < cblProessTypes.Items.Count; j++)
// {
// if (cblProessTypes.Items[j].Selected)
// {
// count += 1;
// break;
// }
// }
//}
//if (count < this.Grid1.Rows.Count)
//{
// ShowNotify("热处理类型不能为空!", MessageBoxIcon.Warning);
// return;
//}
SaveData();
}
else
{
ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
return;
}
}
#endregion
/// <summary>
/// 提交明细数据方法
/// </summary>
private void SaveData()
{
bool isEmpty = false;//是否为空
string isoidLog = string.Empty; //是否同一管线标记
int i = 0; //检验数量
int flag = 0; //打印标记
string hardTestReportId = string.Empty; //硬度检验报告主键
List<string> hotProessStates = new List<string>(); //热处理状态
string hotProessState = string.Empty;
var results = from x in Funs.DB.HJGL_CH_HotProessResult select x;
var hardTestReportItems = from x in Funs.DB.HJGL_CH_HardTestReportItem select x;
var hardTestReports = from x in Funs.DB.HJGL_CH_HardTestReport select x;
JArray mergedData = Grid1.GetMergedData();
foreach (JObject mergedRow in mergedData)
{
string status = mergedRow.Value<string>("status");
JObject values = mergedRow.Value<JObject>("values");
int rowIndex = mergedRow.Value<int>("index");
string jot_id = values.Value<string>("JOT_ID").ToString();
string iso_No = values.Value<string>("ISO_IsoNo").ToString();
//判断是否可以修改数据
string hotProessItemId = this.Grid1.Rows[rowIndex].DataKeys[0].ToString();
Model.HJGL_HotProessItem newHotProessItem = BLL.HJGL_HotProessManageEditService.GetHotProessItemByHotProessItemId(hotProessItemId);
Model.HJGL_HotProessItem hotProessItem = BLL.HJGL_HotProessManageEditService.GetHotProessItemByHotProessItemId(hotProessItemId);
if (hotProessItem != null)
{
//Model.HJGL_CH_HardTestReport hardTestReport = (from x in hardTestReports
// join y in hardTestReportItems
// on x.HardTestReportId equals y.HardTestReportId
// where y.JOT_ID == hotProessItem.JOT_ID && y.HotProessTrustId == hotProessItem.HotProessTrustId
// select x).FirstOrDefault();
//if (hardTestReport != null && hardTestReport.IsPrintTrust == true) //硬度委托打印后,不能修改热处理录入数据
//{
// if (this.CurrUser.UserId == BLL.Const.GlyId) //管理员可以修改数据
// {
// newHotProessItem.PointCount = Funs.GetNewInt(values.Value<string>("PointCount").ToString());
// newHotProessItem.RequiredT = values.Value<string>("RequiredT").ToString();
// newHotProessItem.ActualT = values.Value<string>("ActualT").ToString();
// newHotProessItem.RequestTime = values.Value<string>("RequestTime").ToString();
// newHotProessItem.ActualTime = values.Value<string>("ActualTime").ToString();
// newHotProessItem.HotProessDate = Funs.GetNewDateTime(values.Value<string>("HotProessDate").ToString());
// newHotProessItem.RecordChartNo = values.Value<string>("RecordChartNo").ToString();
// Funs.DB.SubmitChanges();
// }
//}
//else
//{
if (!string.IsNullOrEmpty(values.Value<string>("PointCount").ToString()))
{
newHotProessItem.PointCount = values.Value<string>("PointCount").ToString();
}
else
{
isEmpty = true;
}
if (!string.IsNullOrEmpty(values.Value<string>("RequiredT").ToString()))
{
newHotProessItem.RequiredT = values.Value<string>("RequiredT").ToString();
}
else
{
isEmpty = true;
}
if (!string.IsNullOrEmpty(values.Value<string>("ActualT").ToString()))
{
newHotProessItem.ActualT = values.Value<string>("ActualT").ToString();
}
else
{
isEmpty = true;
}
if (!string.IsNullOrEmpty(values.Value<string>("RequestTime").ToString()))
{
newHotProessItem.RequestTime = values.Value<string>("RequestTime").ToString();
}
else
{
isEmpty = true;
}
if (!string.IsNullOrEmpty(values.Value<string>("ActualTime").ToString()))
{
newHotProessItem.ActualTime = values.Value<string>("ActualTime").ToString();
}
else
{
isEmpty = true;
}
if (!string.IsNullOrEmpty(values.Value<string>("HotProessDate").ToString()))
{
newHotProessItem.HotProessDate = Funs.GetNewDateTime(values.Value<string>("HotProessDate").ToString());
}
else
{
isEmpty = true;
}
if (!string.IsNullOrEmpty(values.Value<string>("RecordChartNo").ToString()))
{
newHotProessItem.RecordChartNo = values.Value<string>("RecordChartNo").ToString();
}
else
{
isEmpty = true;
}
if (!string.IsNullOrEmpty(values.Value<string>("ThermocouplesNum").ToString()))
{
newHotProessItem.ThermocouplesNum = values.Value<string>("ThermocouplesNum").ToString();
}
else
{
isEmpty = true;
}
if (!string.IsNullOrEmpty(values.Value<string>("HeatingRange").ToString()))
{
newHotProessItem.HeatingRange = values.Value<string>("HeatingRange").ToString();
}
else
{
isEmpty = true;
}
if (!string.IsNullOrEmpty(values.Value<string>("InsulationRange").ToString()))
{
newHotProessItem.InsulationRange = values.Value<string>("InsulationRange").ToString();
}
else
{
isEmpty = true;
}
if (!string.IsNullOrEmpty(values.Value<string>("InsulationThickness").ToString()))
{
newHotProessItem.InsulationThickness = values.Value<string>("InsulationThickness").ToString();
}
else
{
isEmpty = true;
}
if (!string.IsNullOrEmpty(values.Value<string>("HotStartDate").ToString()))
{
newHotProessItem.HotStartDate = Funs.GetNewDateTime(values.Value<string>("HotStartDate").ToString());
}
else
{
isEmpty = true;
}
if (!string.IsNullOrEmpty(values.Value<string>("HotEndDate").ToString()))
{
newHotProessItem.HotEndDate = Funs.GetNewDateTime(values.Value<string>("HotEndDate").ToString());
}
else
{
isEmpty = true;
}
newHotProessItem.Remark = values.Value<string>("Remark").ToString();
if (!isEmpty)
{
Funs.DB.SubmitChanges();
}
else
{
Alert.ShowInTop("测温点编号、热处理温度℃(要求)、热处理温度℃(实际)、恒温时间h要求、恒温时间h实际、热处理日期、记录曲线图编号、热电偶数量、加热范围、保温范围、保温厚度、热处理开始时间、热处理完成时间不能为空", MessageBoxIcon.Warning);
return;
}
//}
}
if (hotProessItem.ProessTypes.Contains("4")) //消应力热处理需要进行硬度委托
{
//生成硬度委托记录
string hotProessTrustId = values.Value<string>("HotProessTrustId").ToString();
Model.HJGL_CH_HotProessResult result = results.FirstOrDefault(x => x.JOT_ID == jot_id && x.ProessTypes == newHotProessItem.ProessTypes && x.HotProessTrustId == hotProessTrustId);
if (result != null && !string.IsNullOrEmpty(newHotProessItem.RecordChartNo))
{
result.IsNeedHardTest = true;
BLL.HJGL_CH_HotProessResultService.UpdateHotProessResult(result);
}
}
//if (hotProessItem.ProessTypes.Contains("4")) //消应力热处理需要进行硬度委托
//{
// //生成硬度委托记录
// string hotProessTrustId = values.Value<string>("HotProessTrustId").ToString();
// Model.HJGL_CH_HotProessResult result = results.FirstOrDefault(x => x.JOT_ID == jot_id && x.ProessTypes == newHotProessItem.ProessTypes && x.HotProessTrustId == hotProessTrustId);
// if (result != null && !string.IsNullOrEmpty(newHotProessItem.RecordChartNo))
// {
// result.IsNeedHardTest = true;
// BLL.HJGL_CH_HotProessResultService.UpdateHotProessResult(result);
// string proessTypes = BLL.HJGL_PW_JointInfoService.ConvertProessTypes(values.Value<string>("ProessTypes").ToString());
// Model.HJGL_CH_HardTestReportItem oldHardTestReportItem = BLL.HJGL_CH_HardTestReportService.GetHardTestReportItemByJotIDAndHotProessTrustId(jot_id, hotProessTrustId);
// if (oldHardTestReportItem == null) //该焊口尚未生成硬度检验报告记录
// {
// Model.HJGL_PW_JointInfo joint = BLL.HJGL_PW_JointInfoService.GetJointInfoByJotID(jot_id);
// Model.HJGL_PW_IsoInfo iso = BLL.HJGL_PW_IsoInfoService.GetIsoInfoByIsoInfoId(joint.ISO_ID);
// if (isoidLog != joint.ISO_ID) //新管线的记录
// {
// flag = 0;
// Model.HJGL_CH_HardTestReport oldHardTestReport = BLL.HJGL_CH_HardTestReportService.GetCH_HardTestReportByID(hardTestReportId);
// if (oldHardTestReport != null) //更新之前硬度检验报告的热处理状态和检验数量
// {
// hotProessStates = hotProessStates.Distinct().ToList();
// foreach (var item in hotProessStates)
// {
// hotProessState = item + ",";
// }
// hotProessState = hotProessState.Substring(0, hotProessState.LastIndexOf(","));
// oldHardTestReport.HotProessState = hotProessState;
// oldHardTestReport.TestCount = i;
// BLL.HJGL_CH_HardTestReportService.UpdateCH_HardTestReport(oldHardTestReport);
// }
// i = 0; //检验数量清零
// i++; //检验数量+1
// hotProessState = string.Empty; //热处理状态字符串清空
// hotProessStates.Clear(); //热处理状态集合清空
// hotProessStates.Add(proessTypes); //热处理状态集合添加元素
// isoidLog = joint.ISO_ID;
// hardTestReportId = SQLHelper.GetNewID(typeof(Model.HJGL_CH_HardTestReport));
// //生成硬度委托及硬度检验报告记录
// Model.HJGL_CH_HardTestReport hardTestReport = new Model.HJGL_CH_HardTestReport();
// hardTestReport.HardTestReportId = hardTestReportId;
// hardTestReport.HotHardCode = BLL.SQLHelper.RunProcNewIdByProjectId("SpGetNewCodeByProjectId", "dbo.HJGL_CH_HardTestReport", "HotHardCode", joint.ProjectId, BLL.Base_ProjectService.GetProjectCode(joint.ProjectId) + "-" + iso.ISO_IsoNo + "-");
// //八硫磺六个项目单独规则生成编号
// if (joint.ProjectId == "fe91191c-230d-4536-b80a-5756db1dc120" || joint.ProjectId == "64dbad31-e022-4933-94aa-b00ecdfa9dbb" || joint.ProjectId == "9ecef5cd-f522-4640-b95d-6462da08e3fb" || joint.ProjectId == "4adcc1af-341d-4006-a1c8-e205b14d4c74" || joint.ProjectId == "7061b8be-95d8-4047-9bf2-774e0f4d3329" || joint.ProjectId == "560239b5-4d83-4d58-b752-1caa3407ec34")
// {
// Model.Base_Project project = BLL.Base_ProjectService.GetProjectByProjectId(joint.ProjectId);
// string projectCode = string.Empty;
// if (project != null)
// {
// projectCode = project.ProjectCode.Substring(project.ProjectCode.Length - 1);
// }
// hardTestReport.HardTestReportCode = "HT2018-1073/" + projectCode + "-" + iso_No + "-YDBG-0001";
// }
// else
// {
// hardTestReport.HardTestReportCode = BLL.HJGL_CH_HardTestReportService.GetHardTestReportCodeByISO_ID(iso.ISO_ID, DateTime.Now);
// }
// hardTestReport.ProjectId = joint.ProjectId;
// hardTestReport.ISO_ID = iso.ISO_ID;
// hardTestReport.TestDate = DateTime.Now;
// hardTestReport.TrustUnitId = iso.BSU_ID;
// hardTestReport.TestStandard = "GB/T17394.1-2014";
// hardTestReport.STE_ID = iso.STE_ID;
// //项目承包单位信息
// hardTestReport.ContractUnit = "浙江鼎盛石化工程有限公司";
// hardTestReport.TestMethod = "里氏硬度";
// BLL.HJGL_CH_HardTestReportService.AddCH_HardTestReport(hardTestReport);
// //回写焊口硬度委托时间
// BLL.HJGL_PW_JointInfoService.WriteBackHardTrustDate(hotProessItem.JOT_ID, hardTestReport.TestDate);
// }
// else
// {
// i++; //检验数量+1
// hotProessStates.Add(proessTypes); //热处理状态集合添加元素
// //回写焊口硬度委托时间
// BLL.HJGL_PW_JointInfoService.WriteBackHardTrustDate(hotProessItem.JOT_ID, DateTime.Now);
// }
// //增加硬度检验报告明细信息
// flag++; //打印标记+1
// Model.HJGL_CH_HardTestReportItem newItem11 = new Model.HJGL_CH_HardTestReportItem();
// newItem11.HardTestReportItemId = SQLHelper.GetNewID(typeof(Model.HJGL_CH_HardTestReportItem));
// newItem11.HardTestReportId = hardTestReportId;
// newItem11.JOT_ID = jot_id;
// newItem11.TestPart = "焊缝";
// newItem11.SortIndex = 1;
// newItem11.Flag = flag;
// newItem11.IsShow = true;
// newItem11.HotProessTrustId = hotProessTrustId;
// BLL.HJGL_CH_HardTestReportService.AddCH_HardTestReportItem(newItem11);
// Model.HJGL_CH_HardTestReportItem newItem12 = new Model.HJGL_CH_HardTestReportItem();
// newItem12.HardTestReportItemId = SQLHelper.GetNewID(typeof(Model.HJGL_CH_HardTestReportItem));
// newItem12.HardTestReportId = hardTestReportId;
// newItem12.JOT_ID = jot_id;
// newItem12.TestPart = "焊缝";
// newItem12.SortIndex = 1;
// newItem12.Flag = flag;
// newItem12.HotProessTrustId = hotProessTrustId;
// BLL.HJGL_CH_HardTestReportService.AddCH_HardTestReportItem(newItem12);
// Model.HJGL_CH_HardTestReportItem newItem13 = new Model.HJGL_CH_HardTestReportItem();
// newItem13.HardTestReportItemId = SQLHelper.GetNewID(typeof(Model.HJGL_CH_HardTestReportItem));
// newItem13.HardTestReportId = hardTestReportId;
// newItem13.JOT_ID = jot_id;
// newItem13.TestPart = "焊缝";
// newItem13.SortIndex = 1;
// newItem13.Flag = flag;
// newItem13.HotProessTrustId = hotProessTrustId;
// if (!string.IsNullOrEmpty(joint.STE_ID2) && joint.STE_ID != joint.STE_ID2) //材质2不为空,且材质1与材质2不同
// {
// newItem13.Remark = BLL.HJGL_MaterialService.GetSteelBySteID(joint.STE_ID).STE_Code;
// }
// BLL.HJGL_CH_HardTestReportService.AddCH_HardTestReportItem(newItem13);
// Model.HJGL_CH_HardTestReportItem newItem21 = new Model.HJGL_CH_HardTestReportItem();
// newItem21.HardTestReportItemId = SQLHelper.GetNewID(typeof(Model.HJGL_CH_HardTestReportItem));
// newItem21.HardTestReportId = hardTestReportId;
// newItem21.JOT_ID = jot_id;
// newItem21.TestPart = "热影响区";
// newItem21.SortIndex = 2;
// newItem21.Flag = flag;
// newItem21.IsShow = true;
// newItem21.HotProessTrustId = hotProessTrustId;
// if (!string.IsNullOrEmpty(joint.STE_ID2) && joint.STE_ID != joint.STE_ID2) //材质2不为空,且材质1与材质2不同
// {
// newItem21.Remark = BLL.HJGL_MaterialService.GetSteelBySteID(joint.STE_ID).STE_Code;
// }
// BLL.HJGL_CH_HardTestReportService.AddCH_HardTestReportItem(newItem21);
// Model.HJGL_CH_HardTestReportItem newItem22 = new Model.HJGL_CH_HardTestReportItem();
// newItem22.HardTestReportItemId = SQLHelper.GetNewID(typeof(Model.HJGL_CH_HardTestReportItem));
// newItem22.HardTestReportId = hardTestReportId;
// newItem22.JOT_ID = jot_id;
// newItem22.TestPart = "热影响区";
// newItem22.SortIndex = 2;
// newItem22.Flag = flag;
// newItem22.HotProessTrustId = hotProessTrustId;
// if (!string.IsNullOrEmpty(joint.STE_ID2) && joint.STE_ID != joint.STE_ID2) //材质2不为空,且材质1与材质2不同
// {
// newItem22.Remark = BLL.HJGL_MaterialService.GetSteelBySteID(joint.STE_ID).STE_Code;
// }
// BLL.HJGL_CH_HardTestReportService.AddCH_HardTestReportItem(newItem22);
// Model.HJGL_CH_HardTestReportItem newItem23 = new Model.HJGL_CH_HardTestReportItem();
// newItem23.HardTestReportItemId = SQLHelper.GetNewID(typeof(Model.HJGL_CH_HardTestReportItem));
// newItem23.HardTestReportId = hardTestReportId;
// newItem23.JOT_ID = jot_id;
// newItem23.TestPart = "热影响区";
// newItem23.SortIndex = 2;
// newItem23.Flag = flag;
// newItem23.HotProessTrustId = hotProessTrustId;
// if (!string.IsNullOrEmpty(joint.STE_ID2) && joint.STE_ID != joint.STE_ID2) //材质2不为空,且材质1与材质2不同
// {
// newItem23.Remark = BLL.HJGL_MaterialService.GetSteelBySteID(joint.STE_ID).STE_Code;
// }
// BLL.HJGL_CH_HardTestReportService.AddCH_HardTestReportItem(newItem23);
// if (!string.IsNullOrEmpty(joint.STE_ID2) && joint.STE_ID != joint.STE_ID2) //材质2不为空,且材质1与材质2不同
// {
// Model.HJGL_CH_HardTestReportItem newItem51 = new Model.HJGL_CH_HardTestReportItem();
// newItem51.HardTestReportItemId = SQLHelper.GetNewID(typeof(Model.HJGL_CH_HardTestReportItem));
// newItem51.HardTestReportId = hardTestReportId;
// newItem51.JOT_ID = jot_id;
// newItem51.TestPart = "热影响区";
// newItem51.SortIndex = 5;
// newItem51.Flag = flag;
// newItem51.IsShow = true;
// newItem51.HotProessTrustId = hotProessTrustId;
// newItem51.Remark = BLL.HJGL_MaterialService.GetSteelBySteID(joint.STE_ID2).STE_Code;
// BLL.HJGL_CH_HardTestReportService.AddCH_HardTestReportItem(newItem51);
// Model.HJGL_CH_HardTestReportItem newItem52 = new Model.HJGL_CH_HardTestReportItem();
// newItem52.HardTestReportItemId = SQLHelper.GetNewID(typeof(Model.HJGL_CH_HardTestReportItem));
// newItem52.HardTestReportId = hardTestReportId;
// newItem52.JOT_ID = jot_id;
// newItem52.TestPart = "热影响区";
// newItem52.SortIndex = 5;
// newItem52.Flag = flag;
// newItem52.HotProessTrustId = hotProessTrustId;
// newItem52.Remark = BLL.HJGL_MaterialService.GetSteelBySteID(joint.STE_ID2).STE_Code;
// BLL.HJGL_CH_HardTestReportService.AddCH_HardTestReportItem(newItem52);
// Model.HJGL_CH_HardTestReportItem newItem53 = new Model.HJGL_CH_HardTestReportItem();
// newItem53.HardTestReportItemId = SQLHelper.GetNewID(typeof(Model.HJGL_CH_HardTestReportItem));
// newItem53.HardTestReportId = hardTestReportId;
// newItem53.JOT_ID = jot_id;
// newItem53.TestPart = "热影响区";
// newItem53.SortIndex = 5;
// newItem53.Flag = flag;
// newItem53.HotProessTrustId = hotProessTrustId;
// newItem53.Remark = BLL.HJGL_MaterialService.GetSteelBySteID(joint.STE_ID2).STE_Code;
// BLL.HJGL_CH_HardTestReportService.AddCH_HardTestReportItem(newItem53);
// }
// if (flag == 3) //逢3重置标识
// {
// flag = 0;
// }
// }
// }
//}
}
//更新之前硬度检验报告的热处理状态和检验数量
//Model.HJGL_CH_HardTestReport oldHardTestReport2 = BLL.HJGL_CH_HardTestReportService.GetCH_HardTestReportByID(hardTestReportId);
//if (oldHardTestReport2 != null)
//{
// hotProessStates = hotProessStates.Distinct().ToList();
// foreach (var item in hotProessStates)
// {
// hotProessState += item + ",";
// }
// hotProessState = hotProessState.Substring(0, hotProessState.LastIndexOf(","));
// oldHardTestReport2.HotProessState = hotProessState;
// oldHardTestReport2.TestCount = i;
// BLL.HJGL_CH_HardTestReportService.UpdateCH_HardTestReport(oldHardTestReport2);
//}
if (!isEmpty)
{
ShowNotify("提交成功!", MessageBoxIcon.Success);
}
}
/// <summary>
/// 批量处理热处理记录号
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ckSelect_Click(object sender, EventArgs e)
{
if (this.tvControlItem.SelectedNode.CommandName == "项目名称")
{
string window = String.Format("HotProessManageItemFind.aspx?ProjectId=" + this.tvControlItem.SelectedNodeID, "编辑 - ");
PageContext.RegisterStartupScript(Window3.GetSaveStateReference(hdItemsString.ClientID) + Window3.GetShowReference(window));
}
else
{
ShowNotify("请选择项目!", MessageBoxIcon.Success);
}
//PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("HotProessManageItemFind.aspx", "编辑 - ")));
}
protected void rblIsPrint_SelectedIndexChanged(object sender, EventArgs e)
{
BindGrid();
}
#region
/// <summary>
/// 导入
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnImport_Click(object sender, EventArgs e)
{
PageContext.RegisterStartupScript(Window5.GetShowReference(String.Format("HotProessManageEditImport.aspx", "导入 - ")));
}
#endregion
#region
protected void btnOut_Click(object sender, EventArgs e)
{
string ids = string.Empty;
if (this.tvControlItem.SelectedNode != null && this.tvControlItem.SelectedNode.CommandName == "项目名称")
{
}
else
{
ShowNotify("请选择要导出的项目!", MessageBoxIcon.Warning);
return;
}
string rootPath = Server.MapPath("~/");
string initTemplatePath = string.Empty;
string uploadfilepath = string.Empty;
string newUrl = string.Empty;
string filePath = string.Empty;
initTemplatePath = Const.HotProessManageOutTemplateUrl;
uploadfilepath = rootPath + initTemplatePath;
newUrl = uploadfilepath.Replace(".xlsx", "(" + BLL.Base_ProjectService.GetProjectCode(this.tvControlItem.SelectedNodeID).Replace("/", "-") + ").xlsx");
if (File.Exists(newUrl))
{
File.Delete(newUrl);
}
File.Copy(uploadfilepath, newUrl);
// 读取模板
IWorkbook workbook;
using (FileStream stream = new FileStream(newUrl, FileMode.Open, FileAccess.Read))
{
workbook = new XSSFWorkbook(stream);
}
// 单元格样式
ICellStyle cellStyle = workbook.CreateCellStyle();
cellStyle.BorderTop = BorderStyle.Thin;
cellStyle.BorderRight = BorderStyle.Thin;
cellStyle.BorderBottom = BorderStyle.Thin;
cellStyle.BorderLeft = BorderStyle.Thin;
cellStyle.Alignment = HorizontalAlignment.Center;
cellStyle.VerticalAlignment = VerticalAlignment.Center;
cellStyle.WrapText = true;
IFont font = workbook.CreateFont();
font.FontHeightInPoints = 10;
cellStyle.SetFont(font);
ISheet sheet = workbook.GetSheetAt(0);
int i = 2;
string strSql = @"SELECT JointInfo.ProjectId,JointInfo.JOT_ID,Project.ProjectCode,HotProessItem.PrintDate,HotProessTrust.HotProessTrustCode,
(select Top 1 TrustDate from dbo.HJGL_CH_HotProessTrustItem a where a.JOT_ID=HotProessItem.JOT_ID and a.HotProessTrustId=HotProessItem.HotProessTrustId) as TrustDate,
JointInfo.JOT_ID+'1' as JOT_ID1, JointInfo.JOT_ID+'2' as JOT_ID2,JointInfo.JOT_ID+'3' as JOT_ID3,JointInfo.JOT_ID+'4' as JOT_ID4,
(CASE WHEN v.RepairMark IS NOT NULL THEN (JointInfo.JOT_JointNo+v.RepairMark)
ELSE JointInfo.JOT_JointNo END )+isnull((select Top 1 HardRepairMark from dbo.HJGL_CH_HotProessTrustItem a where a.JOT_ID=HotProessItem.JOT_ID and a.HotProessTrustId=HotProessItem.HotProessTrustId and a.ProessTypes=HotProessItem.ProessTypes),'') AS JOT_JointNo,IsoInfo.ISO_IsoNo,IsoInfo.ISO_ID,
(CASE WHEN Steel.STE_Code IS NOT NULL AND Steel2.STE_Code IS NOT NULL and Steel.STE_Code!=Steel2.STE_Code
THEN Steel.STE_Code + '/' + Steel2.STE_Code
WHEN Steel.STE_Code IS NOT NULL THEN Steel.STE_Code
ELSE ISNULL(Steel2.STE_Code,'') END) AS STE_Code,ThermocouplesNum,HeatingRange,InsulationRange,InsulationThickness,HotStartDate,HotEndDate,
HotProessItem.PointCount,HotProessItem.RequiredT,HotProessItem.ActualT,
HotProessItem.RequestTime,HotProessItem.ActualTime,HotProessItem.RecordChartNo,
HotProessItem.HotProessDate,HotProessItem.HotProessTrustId,
(SELECT (case when HotHardCode is null then HardTestReportCode else HotHardCode end) as HardTestReportCode FROM dbo.HJGL_CH_HardTestReport
WHERE HardTestReportId =(SELECT TOP 1 re.HardTestReportId FROM dbo.HJGL_CH_HardTestReportItem item
left join dbo.HJGL_CH_HardTestReport re on item.HardTestReportId=re.HardTestReportId
WHERE item.JOT_ID=HotProessItem.JOT_ID AND item.HotProessTrustId=HotProessItem.HotProessTrustId and (re.FileType='R' or re.FileType is null)))
AS HardnessReportNo,
HotProessItem.HotProessItemId,HotProessItem.SortIndex,HotProessItem.ProessTypes,JointInfo.JOT_JointDesc,isnull(HotProessItem.Remark,'') as Remark
FROM dbo.HJGL_HotProessItem AS HotProessItem
LEFT JOIN dbo.HJGL_CH_HotProessTrust AS HotProessTrust ON HotProessTrust.HotProessTrustId = HotProessItem.HotProessTrustId
LEFT JOIN dbo.HJGL_PW_JointInfo AS JointInfo ON JointInfo.JOT_ID = HotProessItem.JOT_ID
LEFT JOIN dbo.HJGL_PW_IsoInfo AS IsoInfo ON JointInfo.ISO_ID = IsoInfo.ISO_ID
left join Base_Project as Project on Project.ProjectId = IsoInfo.ProjectId
LEFT JOIN dbo.Project_WorkArea AS WorkArea ON IsoInfo.BAW_ID = WorkArea.WorkAreaId
LEFT JOIN dbo.HJGL_BS_Steel AS Steel ON JointInfo.STE_ID = Steel.STE_ID
LEFT JOIN dbo.HJGL_BS_Steel AS Steel2 ON JointInfo.STE_ID2 = Steel2.STE_ID
left join (select record.RepairMark,record.JOT_ID,h.HotProessItemId from dbo.HJGL_CH_HotProessTrustItem AS TrustItem
left join dbo.HJGL_CH_RepairItemRecord AS record ON record.RepairItemRecordId=TrustItem.TrustItemID
left join dbo.HJGL_HotProessItem h on h.JOT_ID=TrustItem.JOT_ID
where h.JOT_ID = TrustItem.JOT_ID and h.HotProessTrustId=TrustItem.HotProessTrustId and h.ProessTypes=TrustItem.ProessTypes) v
on v.JOT_ID=HotProessItem.JOT_ID and v.HotProessItemId=HotProessItem.HotProessItemId
WHERE JointInfo.ProjectId= @ProjectId order by ISO_IsoNo,Sort1,Sort2,Sort3,Sort4,Sort5,SortIndex,PointCount ";
List<SqlParameter> listStr = new List<SqlParameter>();
listStr.Add(new SqlParameter("@ProjectId", this.tvControlItem.SelectedNodeID));
DataTable tb = SQLHelper.GetDataTableRunText(strSql, listStr.ToArray());
// 加载附件
Model.SGGLDB db = Funs.DB;
var attachFiles = db.AttachFile.ToList();
// 先遍历一遍,设置列宽 + 行高
Dictionary<string, int> maxHeightDic = new Dictionary<string, int>();
int col13 = 0, col14 = 0, col15 = 0, col16 = 0;
foreach (DataRow row in tb.Rows)
{
string jotId = row["JOT_ID"].ToString();
if (!maxHeightDic.ContainsKey(jotId))
{
int maxH = 0;
CheckAndUpdateImageSize(attachFiles, jotId + "1", ref col13, ref maxH);
CheckAndUpdateImageSize(attachFiles, jotId + "2", ref col14, ref maxH);
CheckAndUpdateImageSize(attachFiles, jotId + "3", ref col15, ref maxH);
CheckAndUpdateImageSize(attachFiles, jotId + "4", ref col16, ref maxH);
maxHeightDic[jotId] = maxH;
}
}
// 设置列宽
if (col13 > 0) sheet.SetColumnWidth(13, col13 * 30);
if (col14 > 0) sheet.SetColumnWidth(14, col14 * 30);
if (col15 > 0) sheet.SetColumnWidth(15, col15 * 30);
if (col16 > 0) sheet.SetColumnWidth(16, col16 * 30);
// 填充数据 + 插入图片
foreach (DataRow row in tb.Rows)
{
string jotId = row["JOT_ID"].ToString();
IRow excelRow = sheet.CreateRow(i);
// 设置行高(根据图片高度自动适应)
if (maxHeightDic.TryGetValue(jotId, out int height) && height > 0)
{
excelRow.Height = (short)(height * 17);
}
else
{
excelRow.Height = 400; // 默认行高,防止图片被截断
}
// 赋值单元格
SetCell(excelRow, 0, cellStyle, (i - 1).ToString());
SetCell(excelRow, 1, cellStyle, row["ISO_IsoNo"].ToString());
SetCell(excelRow, 2, cellStyle, row["JOT_JointNo"].ToString());
SetCell(excelRow, 3, cellStyle, row["JOT_JointDesc"].ToString());
SetCell(excelRow, 4, cellStyle, row["STE_Code"].ToString());
SetCell(excelRow, 5, cellStyle, row["ThermocouplesNum"].ToString());
SetCell(excelRow, 6, cellStyle, row["HeatingRange"].ToString());
SetCell(excelRow, 7, cellStyle, row["InsulationRange"].ToString());
SetCell(excelRow, 8, cellStyle, row["InsulationThickness"].ToString());
SetCell(excelRow, 9, cellStyle, row["HotProessTrustCode"].ToString());
string trustDate = row["TrustDate"] != DBNull.Value ? $"{Convert.ToDateTime(row["TrustDate"]):yyyy-MM-dd}" : "";
SetCell(excelRow, 10, cellStyle, trustDate);
string hotStart = row["HotStartDate"] != DBNull.Value ? $"{Convert.ToDateTime(row["HotStartDate"]):yyyy-MM-dd}" : "";
SetCell(excelRow, 11, cellStyle, hotStart);
string hotEnd = row["HotEndDate"] != DBNull.Value ? $"{Convert.ToDateTime(row["HotEndDate"]):yyyy-MM-dd}" : "";
SetCell(excelRow, 12, cellStyle, hotEnd);
// 图片列(空值)
SetCell(excelRow, 13, cellStyle, "");
SetCell(excelRow, 14, cellStyle, "");
SetCell(excelRow, 15, cellStyle, "");
SetCell(excelRow, 16, cellStyle, "");
SetCell(excelRow, 17, cellStyle, row["Remark"].ToString());
// 插入图片
InsertImageToExcel(sheet, i, 13, attachFiles, jotId + "1");
InsertImageToExcel(sheet, i, 14, attachFiles, jotId + "2");
InsertImageToExcel(sheet, i, 15, attachFiles, jotId + "3");
InsertImageToExcel(sheet, i, 16, attachFiles, jotId + "4");
i++;
}
using (FileStream stream = new FileStream(newUrl, FileMode.Create, FileAccess.Write))
{
workbook.Write(stream);
workbook.Close();
}
string fileName = Path.GetFileName(newUrl);
Response.Clear();
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName, Encoding.UTF8));
Response.TransmitFile(newUrl);
Response.Flush();
Response.Close();
File.Delete(newUrl);
}
/// <summary>
/// 检查图片尺寸(不使用 System.Drawing避免报错
/// </summary>
private void CheckAndUpdateImageSize(List<Model.AttachFile> attachFiles, string keyId, ref int colWidth, ref int maxHeight)
{
try
{
var file = attachFiles.FirstOrDefault(x => x.ToKeyId == keyId);
if (file == null) return;
string path = BLL.Funs.RootPath + file.AttachUrl;
if (!File.Exists(path)) return;
// 不读取图片,直接给固定宽高,避免报错
colWidth = 120;
maxHeight = 120;
}
catch { }
}
/// <summary>
/// 向Excel指定单元格插入单张图片
/// </summary>
private void InsertImageToExcel(ISheet sheet, int row, int col, List<Model.AttachFile> attachFiles, string toKeyId)
{
try
{
var attach = attachFiles.FirstOrDefault(x => x.ToKeyId == toKeyId);
if (attach == null) return;
string filePath = BLL.Funs.RootPath + attach.AttachUrl;
if (!File.Exists(filePath)) return;
byte[] bytes = File.ReadAllBytes(filePath);
TryAddPicture(sheet, row, col, bytes, PictureType.PNG);
}
catch
{
// 图片异常不影响导出
}
}
/// <summary>
/// 快速设置单元格
/// </summary>
private void SetCell(IRow row, int index, ICellStyle style, string value)
{
ICell cell = row.CreateCell(index);
cell.CellStyle = style;
cell.SetCellValue(value);
}
/// 导出按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
// protected void btnOut_Click(object sender, EventArgs e)
// {
// string ids = string.Empty;
// if (this.tvControlItem.SelectedNode != null && this.tvControlItem.SelectedNode.CommandName == "项目名称")
// {
// }
// else
// {
// ShowNotify("请选择要导出的项目!", MessageBoxIcon.Warning);
// return;
// }
// string rootPath = Server.MapPath("~/");
// string initTemplatePath = string.Empty;
// string uploadfilepath = string.Empty;
// string newUrl = string.Empty;
// string filePath = string.Empty;
// initTemplatePath = Const.HotProessManageOutTemplateUrl;
// uploadfilepath = rootPath + initTemplatePath;
// //newUrl = uploadfilepath.Replace(".xlsx", "(" + BLL.Base_ProjectService.GetProjectCode(this.tvControlItem.SelectedNodeID) + "_" + string.Format("{0:yyyy-MM-dd}", DateTime.Now) + ").xlsx");
// newUrl = uploadfilepath.Replace(".xlsx", "(" + BLL.Base_ProjectService.GetProjectCode(this.tvControlItem.SelectedNodeID).Replace("/", "-") + ").xlsx");
// 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);
// }
// string strSql = string.Empty;
// List<SqlParameter> listStr = new List<SqlParameter>();
// Model.SGGLDB db = Funs.DB;
// var attachFiles = from x in db.AttachFile select x;
// // 创建单元格样式
// 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;
// //font.FontHeightInPoints = (short)8.5;字号为小数时要转为short
// cellStyle.SetFont(font);
// // 第二步:创建新数据行
// NPOI.SS.UserModel.ISheet sheet = workbook.GetSheetAt(0);
// int i = 2;
// strSql = @"SELECT JointInfo.ProjectId,JointInfo.JOT_ID,Project.ProjectCode,HotProessItem.PrintDate,HotProessTrust.HotProessTrustCode,(select Top 1 TrustDate from dbo.HJGL_CH_HotProessTrustItem a where a.JOT_ID=HotProessItem.JOT_ID and a.HotProessTrustId=HotProessItem.HotProessTrustId) as TrustDate,
// JointInfo.JOT_ID+'1' as JOT_ID1, JointInfo.JOT_ID+'2' as JOT_ID2,JointInfo.JOT_ID+'3' as JOT_ID3,JointInfo.JOT_ID+'4' as JOT_ID4,
// (CASE WHEN v.RepairMark IS NOT NULL THEN (JointInfo.JOT_JointNo+v.RepairMark)
// ELSE JointInfo.JOT_JointNo END )+isnull((select Top 1 HardRepairMark from dbo.HJGL_CH_HotProessTrustItem a where a.JOT_ID=HotProessItem.JOT_ID and a.HotProessTrustId=HotProessItem.HotProessTrustId and a.ProessTypes=HotProessItem.ProessTypes),'') AS JOT_JointNo,IsoInfo.ISO_IsoNo,IsoInfo.ISO_ID,
// (CASE WHEN Steel.STE_Code IS NOT NULL AND Steel2.STE_Code IS NOT NULL and Steel.STE_Code!=Steel2.STE_Code
// THEN Steel.STE_Code + '/' + Steel2.STE_Code
// WHEN Steel.STE_Code IS NOT NULL THEN Steel.STE_Code
// ELSE ISNULL(Steel2.STE_Code,'') END) AS STE_Code,ThermocouplesNum,HeatingRange,InsulationRange,InsulationThickness,HotStartDate,HotEndDate,
// HotProessItem.PointCount,HotProessItem.RequiredT,HotProessItem.ActualT,
// HotProessItem.RequestTime,HotProessItem.ActualTime,HotProessItem.RecordChartNo,
// HotProessItem.HotProessDate,HotProessItem.HotProessTrustId,
//(SELECT (case when HotHardCode is null then HardTestReportCode else HotHardCode end) as HardTestReportCode FROM dbo.HJGL_CH_HardTestReport
// WHERE HardTestReportId =(SELECT TOP 1 re.HardTestReportId FROM dbo.HJGL_CH_HardTestReportItem item
// left join dbo.HJGL_CH_HardTestReport re on item.HardTestReportId=re.HardTestReportId
// WHERE item.JOT_ID=HotProessItem.JOT_ID AND item.HotProessTrustId=HotProessItem.HotProessTrustId and (re.FileType='R' or re.FileType is null)))
// AS HardnessReportNo,
// HotProessItem.HotProessItemId,HotProessItem.SortIndex,HotProessItem.ProessTypes,JointInfo.JOT_JointDesc,isnull(HotProessItem.Remark,'') as Remark
// FROM dbo.HJGL_HotProessItem AS HotProessItem
// LEFT JOIN dbo.HJGL_CH_HotProessTrust AS HotProessTrust ON HotProessTrust.HotProessTrustId = HotProessItem.HotProessTrustId
// LEFT JOIN dbo.HJGL_PW_JointInfo AS JointInfo ON JointInfo.JOT_ID = HotProessItem.JOT_ID
// LEFT JOIN dbo.HJGL_PW_IsoInfo AS IsoInfo ON JointInfo.ISO_ID = IsoInfo.ISO_ID
// left join Base_Project as Project on Project.ProjectId = IsoInfo.ProjectId
// LEFT JOIN dbo.Project_WorkArea AS WorkArea ON IsoInfo.BAW_ID = WorkArea.WorkAreaId
// LEFT JOIN dbo.HJGL_BS_Steel AS Steel ON JointInfo.STE_ID = Steel.STE_ID
// LEFT JOIN dbo.HJGL_BS_Steel AS Steel2 ON JointInfo.STE_ID2 = Steel2.STE_ID
// left join (select record.RepairMark,record.JOT_ID,h.HotProessItemId from dbo.HJGL_CH_HotProessTrustItem AS TrustItem
// left join dbo.HJGL_CH_RepairItemRecord AS record ON record.RepairItemRecordId=TrustItem.TrustItemID
// left join dbo.HJGL_HotProessItem h on h.JOT_ID=TrustItem.JOT_ID
// where h.JOT_ID = TrustItem.JOT_ID and h.HotProessTrustId=TrustItem.HotProessTrustId and h.ProessTypes=TrustItem.ProessTypes) v
// on v.JOT_ID=HotProessItem.JOT_ID and v.HotProessItemId=HotProessItem.HotProessItemId
// WHERE JointInfo.ProjectId= @ProjectId order by ISO_IsoNo,JOT_JointNo,SortIndex,PointCount ";
// listStr.Add(new SqlParameter("@ProjectId", this.tvControlItem.SelectedNodeID));
// SqlParameter[] parameter = listStr.ToArray();
// DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
// // 第二步:创建新数据行
// NPOI.SS.UserModel.IRow row;
// NPOI.SS.UserModel.ICell cell;
// //List<string> jotIds = new List<string>();
// //int col13 = 0, col14 = 0, col15 = 0, col16 = 0;
// //for (int j = 0; j < tb.Rows.Count; j++)
// //{
// // if (!jotIds.Contains(tb.Rows[j]["JOT_ID"].ToString()))
// // {
// // string jotId = tb.Rows[j]["JOT_ID"].ToString();
// // jotIds.Add(jotId);
// // var attachFile1 = attachFiles.FirstOrDefault(x => x.ToKeyId == (jotId + "1"));
// // var attachFile2 = attachFiles.FirstOrDefault(x => x.ToKeyId == (jotId + "2"));
// // var attachFile3 = attachFiles.FirstOrDefault(x => x.ToKeyId == (jotId + "3"));
// // var attachFile4 = attachFiles.FirstOrDefault(x => x.ToKeyId == (jotId + "4"));
// // if (attachFile1 != null)
// // {
// // string url = BLL.Funs.RootPath + attachFile1.AttachUrl;
// // if (File.Exists(url))
// // {
// // System.Drawing.Image image = System.Drawing.Image.FromFile(url);
// // if (image.Width > col13)
// // {
// // col13 = image.Width;
// // }
// // }
// // }
// // if (attachFile2 != null)
// // {
// // string url = BLL.Funs.RootPath + attachFile2.AttachUrl;
// // if (File.Exists(url))
// // {
// // System.Drawing.Image image = System.Drawing.Image.FromFile(url);
// // if (image.Width > col14)
// // {
// // col14 = image.Width;
// // }
// // }
// // }
// // if (attachFile3 != null)
// // {
// // string url = BLL.Funs.RootPath + attachFile3.AttachUrl;
// // if (File.Exists(url))
// // {
// // System.Drawing.Image image = System.Drawing.Image.FromFile(url);
// // if (image.Width > col15)
// // {
// // col15 = image.Width;
// // }
// // }
// // }
// // if (attachFile4 != null)
// // {
// // string url = BLL.Funs.RootPath + attachFile4.AttachUrl;
// // if (File.Exists(url))
// // {
// // System.Drawing.Image image = System.Drawing.Image.FromFile(url);
// // if (image.Width > col16)
// // {
// // col16 = image.Width;
// // }
// // }
// // }
// // i++;
// // }
// //}
// //if (col13 > 0)
// //{
// // sheet.SetColumnWidth(13, col13 * 37);
// //}
// //if (col14 > 0)
// //{
// // sheet.SetColumnWidth(14, col14 * 37);
// //}
// //if (col15 > 0)
// //{
// // sheet.SetColumnWidth(15, col15 * 37);
// //}
// //if (col16 > 0)
// //{
// // sheet.SetColumnWidth(16, col16 * 37);
// //}
// //i = 2;
// //jotIds.Clear();
// for (int j = 0; j < tb.Rows.Count; j++)
// {
// //if (!jotIds.Contains(tb.Rows[j]["JOT_ID"].ToString()))
// //{
// string jotId = tb.Rows[j]["JOT_ID"].ToString();
// //jotIds.Add(jotId);
// row = sheet.CreateRow(i);
// //var attachFile1 = attachFiles.FirstOrDefault(x => x.ToKeyId == (jotId + "1"));
// //var attachFile2 = attachFiles.FirstOrDefault(x => x.ToKeyId == (jotId + "2"));
// //var attachFile3 = attachFiles.FirstOrDefault(x => x.ToKeyId == (jotId + "3"));
// //var attachFile4 = attachFiles.FirstOrDefault(x => x.ToKeyId == (jotId + "4"));
// //int height = 0;
// //if (attachFile1 != null)
// //{
// // string url = BLL.Funs.RootPath + attachFile1.AttachUrl;
// // if (File.Exists(url))
// // {
// // System.Drawing.Image image = System.Drawing.Image.FromFile(url);
// // if (image.Height > height)
// // {
// // height = image.Height;
// // }
// // }
// //}
// //if (attachFile2 != null)
// //{
// // string url = BLL.Funs.RootPath + attachFile2.AttachUrl;
// // if (File.Exists(url))
// // {
// // System.Drawing.Image image = System.Drawing.Image.FromFile(url);
// // if (image.Height > height)
// // {
// // height = image.Height;
// // }
// // }
// //}
// //if (attachFile3 != null)
// //{
// // string url = BLL.Funs.RootPath + attachFile3.AttachUrl;
// // if (File.Exists(url))
// // {
// // System.Drawing.Image image = System.Drawing.Image.FromFile(url);
// // if (image.Height > height)
// // {
// // height = image.Height;
// // }
// // }
// //}
// //if (attachFile4 != null)
// //{
// // string url = BLL.Funs.RootPath + attachFile4.AttachUrl;
// // if (File.Exists(url))
// // {
// // System.Drawing.Image image = System.Drawing.Image.FromFile(url);
// // if (image.Height > height)
// // {
// // height = image.Height;
// // }
// // }
// //}
// //if (height > 0)
// //{
// // row.Height = (short)(height * 17);
// //}
// // 添加数据
// cell = row.CreateCell(0);
// cell.CellStyle = cellStyle;
// cell.SetCellValue((i - 1).ToString());
// cell = row.CreateCell(1);
// cell.CellStyle = cellStyle;
// cell.SetCellValue(tb.Rows[j]["ISO_IsoNo"].ToString());
// cell = row.CreateCell(2);
// cell.CellStyle = cellStyle;
// cell.SetCellValue(tb.Rows[j]["JOT_JointNo"].ToString());
// cell = row.CreateCell(3);
// cell.CellStyle = cellStyle;
// cell.SetCellValue(tb.Rows[j]["JOT_JointDesc"].ToString());
// cell = row.CreateCell(4);
// cell.CellStyle = cellStyle;
// cell.SetCellValue(tb.Rows[j]["STE_Code"].ToString());
// cell = row.CreateCell(5);
// cell.CellStyle = cellStyle;
// cell.SetCellValue(tb.Rows[j]["ThermocouplesNum"].ToString());
// cell = row.CreateCell(6);
// cell.CellStyle = cellStyle;
// cell.SetCellValue(tb.Rows[j]["HeatingRange"].ToString());
// cell = row.CreateCell(7);
// cell.CellStyle = cellStyle;
// cell.SetCellValue(tb.Rows[j]["InsulationRange"].ToString());
// cell = row.CreateCell(8);
// cell.CellStyle = cellStyle;
// cell.SetCellValue(tb.Rows[j]["InsulationThickness"].ToString());
// cell = row.CreateCell(9);
// cell.CellStyle = cellStyle;
// cell.SetCellValue(tb.Rows[j]["HotProessTrustCode"].ToString());
// cell = row.CreateCell(10);
// cell.CellStyle = cellStyle;
// string trustDate = string.Empty;
// if (tb.Rows[j]["TrustDate"] != DBNull.Value)
// {
// trustDate = string.Format("{0:yyyy-MM-dd}", Convert.ToDateTime(tb.Rows[j]["TrustDate"]));
// }
// cell.SetCellValue(trustDate);
// cell = row.CreateCell(11);
// cell.CellStyle = cellStyle;
// string hotStartDate = string.Empty;
// if (tb.Rows[j]["HotStartDate"] != DBNull.Value)
// {
// hotStartDate = string.Format("{0:yyyy-MM-dd}", Convert.ToDateTime(tb.Rows[j]["HotStartDate"]));
// }
// cell.SetCellValue(hotStartDate);
// cell = row.CreateCell(12);
// cell.CellStyle = cellStyle;
// string hotEndDate = string.Empty;
// if (tb.Rows[j]["HotEndDate"] != DBNull.Value)
// {
// hotEndDate = string.Format("{0:yyyy-MM-dd}", Convert.ToDateTime(tb.Rows[j]["HotEndDate"]));
// }
// cell.SetCellValue(hotEndDate);
// cell = row.CreateCell(13);
// cell.CellStyle = cellStyle;
// cell.SetCellValue(string.Empty);
// cell = row.CreateCell(14);
// cell.CellStyle = cellStyle;
// cell.SetCellValue(string.Empty);
// cell = row.CreateCell(15);
// cell.CellStyle = cellStyle;
// cell.SetCellValue(string.Empty);
// cell = row.CreateCell(16);
// cell.CellStyle = cellStyle;
// cell.SetCellValue(string.Empty);
// cell = row.CreateCell(17);
// cell.CellStyle = cellStyle;
// cell.SetCellValue(tb.Rows[j]["Remark"].ToString());
// //if (attachFile1 != null)
// //{
// // string fp = BLL.Funs.RootPath + attachFile1.AttachUrl;
// // if (File.Exists(fp))
// // {
// // byte[] fileBytes = File.ReadAllBytes(fp);
// // TryAddPicture(sheet, i, 13, fileBytes, PictureType.PNG);
// // }
// //}
// //if (attachFile2 != null)
// //{
// // string fp = BLL.Funs.RootPath + attachFile2.AttachUrl;
// // if (File.Exists(fp))
// // {
// // byte[] fileBytes = File.ReadAllBytes(fp);
// // TryAddPicture(sheet, i, 14, fileBytes, PictureType.PNG);
// // }
// //}
// //if (attachFile3 != null)
// //{
// // string fp = BLL.Funs.RootPath + attachFile3.AttachUrl;
// // if (File.Exists(fp))
// // {
// // byte[] fileBytes = File.ReadAllBytes(fp);
// // TryAddPicture(sheet, i, 15, fileBytes, PictureType.PNG);
// // }
// //}
// //if (attachFile4 != null)
// //{
// // string fp = BLL.Funs.RootPath + attachFile4.AttachUrl;
// // if (File.Exists(fp))
// // {
// // byte[] fileBytes = File.ReadAllBytes(fp);
// // TryAddPicture(sheet, i, 16, fileBytes, PictureType.PNG);
// // }
// //}
// i++;
// //}
// }
// // 第三步:写入文件流
// 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);
// }
//private void TryAddPicture(ISheet sheet, int row, int col, byte[] pictureBytes, PictureType pictureType = PictureType.PNG)
//{
// if (sheet is null)
// {
// throw new ArgumentNullException(nameof(sheet));
// }
// try
// {
// var pictureIndex = sheet.Workbook.AddPicture(pictureBytes, pictureType);
// var clientAnchor = sheet.Workbook.GetCreationHelper().CreateClientAnchor();
// clientAnchor.Row1 = row;
// clientAnchor.Col1 = col;
// var picture = (sheet.DrawingPatriarch ?? sheet.CreateDrawingPatriarch())
// .CreatePicture(clientAnchor, pictureIndex);
// picture.Resize();
// }
// catch (Exception ex)
// {
// }
//}
private void TryAddPicture(ISheet sheet, int row, int col, byte[] pictureBytes, PictureType pictureType = PictureType.PNG)
{
if (sheet == null)
throw new ArgumentNullException(nameof(sheet));
if (pictureBytes == null || pictureBytes.Length == 0)
return;
try
{
int pictureIndex = sheet.Workbook.AddPicture(pictureBytes, pictureType);
IClientAnchor clientAnchor = sheet.Workbook.GetCreationHelper().CreateClientAnchor();
clientAnchor.Row1 = row;
clientAnchor.Col1 = col;
clientAnchor.Row2 = row + 1;
clientAnchor.Col2 = col + 1;
IDrawing drawing = sheet.DrawingPatriarch ?? sheet.CreateDrawingPatriarch();
IPicture picture = drawing.CreatePicture(clientAnchor, pictureIndex);
picture.Resize(0.6); // 缩放
}
catch
{
// 不抛异常,不影响导出
}
}
#endregion
}
}