Basf_TCC7/HJGL/FineUIPro.Web/WeldingProcess/TrustManage/TrustBatchManage.aspx.cs

1615 lines
86 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 System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Web;
using BLL;
using Model;
using NPOI.HSSF.Util;
using NPOI.SS.UserModel;
using NPOI.SS.Util;
using NPOI.XSSF.UserModel;
namespace FineUIPro.Web.WeldingProcess.TrustManage
{
public partial class TrustBatchManage : PageBase
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.txtTrustDateMonth.Text = string.Format("{0:yyyy-MM}", DateTime.Now);
this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString();
BLL.Base_UnitService.InitProjectUnitDropDownList(this.drpNDEUnit, false, this.CurrUser.LoginProjectId, BLL.Const.UnitType_4, Resources.Lan.PleaseSelect);
this.InitTreeMenu();//加载树
}
}
#region -
/// <summary>
/// 加载树
/// </summary>
private void InitTreeMenu()
{
if (!string.IsNullOrEmpty(this.txtTrustDateMonth.Text.Trim()))
{
DateTime startTime = Convert.ToDateTime(this.txtTrustDateMonth.Text.Trim() + "-01");
DateTime endTime = startTime.AddMonths(1);
this.tvControlItem.Nodes.Clear();
List<Model.Base_Unit> units = new List<Model.Base_Unit>();
Model.Project_Unit pUnit = BLL.Project_UnitService.GetProject_UnitByProjectIdUnitId(this.CurrUser.LoginProjectId, this.CurrUser.UnitId);
if (pUnit == null || pUnit.UnitType == BLL.Const.UnitType_1 || pUnit.UnitType == BLL.Const.UnitType_2
|| pUnit.UnitType == BLL.Const.UnitType_3 || pUnit.UnitType == BLL.Const.UnitType_4 || pUnit.UnitType == BLL.Const.UnitType_6)
{
units = (from x in Funs.DB.Base_Unit
join y in Funs.DB.Project_Unit on x.UnitId equals y.UnitId
where y.ProjectId == this.CurrUser.LoginProjectId && y.UnitType.Contains(BLL.Const.UnitType_5)
select x).ToList();
}
else
{
units.Add(BLL.Base_UnitService.GetUnit(this.CurrUser.UnitId));
}
if (units != null)
{
foreach (var unit in units)
{
TreeNode newNode = new TreeNode();//定义根节点
newNode.Text = unit.UnitName;
newNode.NodeID = unit.UnitId;
newNode.Expanded = true;
newNode.ToolTip = "Unit";
this.tvControlItem.Nodes.Add(newNode);
this.BindNodes(newNode);
}
}
else
{
Alert.ShowInTop(Resources.Lan.PleaseAddUnitFirst, MessageBoxIcon.Warning);
}
}
else
{
Alert.ShowInTop(Resources.Lan.PleaseSelectTrustMonth, MessageBoxIcon.Warning);
}
}
#endregion
#region
/// <summary>
/// 绑定树节点
/// </summary>
/// <param name="node"></param>
private void BindNodes(TreeNode node)
{
if (node.ToolTip == "Unit")
{
///装置
var install = (from x in Funs.DB.Project_Installation
join y in Funs.DB.Batch_BatchTrust on x.InstallationId equals y.InstallationId
where y.UnitId == node.NodeID && x.ProjectId == this.CurrUser.LoginProjectId
orderby x.InstallationCode
select x).Distinct();
foreach (var q in install)
{
TreeNode newNode = new TreeNode();
newNode.Text = q.InstallationName;
newNode.NodeID = q.InstallationId.ToString() + "|" + node.NodeID;
newNode.ToolTip = "Installation";
node.Nodes.Add(newNode);
BindNodes(newNode);
}
}
else if (node.ToolTip == "Installation")
{
var ndt = from x in Funs.DB.Base_DetectionType select x;
foreach (var q in ndt)
{
TreeNode newNode = new TreeNode();
newNode.Text = q.DetectionTypeCode;
newNode.NodeID = q.DetectionTypeId + "|" + node.NodeID;
newNode.ToolTip = "DetectionType";
newNode.EnableExpandEvent = true;
node.Nodes.Add(newNode);
BindNodes(newNode);
}
//var types = (from x in Funs.DB.View_Batch_BatchTrust
// join y in Funs.DB.Base_DetectionType
// on x.DetectionTypeId equals y.DetectionTypeId
// where x.TrustDate < Convert.ToDateTime(this.txtTrustDateMonth.Text.Trim() + "-01").AddMonths(1)
// && x.TrustDate >= Convert.ToDateTime(this.txtTrustDateMonth.Text.Trim() + "-01").AddMonths(-1)
// && x.UnitId == node.ParentNode.NodeID && x.ProjectId == this.CurrUser.LoginProjectId
// && x.InstallationId == node.NodeID.Split('|')[0]
// orderby x.DetectionTypeCode
// select y).Distinct();
//foreach (var q in types)
//{
// TreeNode newNode = new TreeNode();
// newNode.Text = q.DetectionTypeCode;
// newNode.NodeID = q.DetectionTypeId + "|" + node.NodeID;
// newNode.ToolTip = "DetectionType";
// newNode.EnableExpandEvent = true;
// node.Nodes.Add(newNode);
// BindNodes(newNode);
//}
}
else if (node.ToolTip == "DetectionType")
{
TreeNode newNode = new TreeNode();
newNode.Text = "加载...";
newNode.NodeID = "加载...";
node.Nodes.Add(newNode);
///单号
// var trusts = from x in Funs.DB.Batch_BatchTrust
// where x.TrustDate < Convert.ToDateTime(this.txtTrustDateMonth.Text.Trim() + "-01").AddMonths(1)
// && x.TrustDate >= Convert.ToDateTime(this.txtTrustDateMonth.Text.Trim() + "-01").AddMonths(-1)
// && x.ProjectId == this.CurrUser.LoginProjectId
// && x.InstallationId.ToString() == node.ParentNode.NodeID.Split('|')[0]
// && x.UnitId == node.ParentNode.ParentNode.NodeID
// && x.DetectionTypeId == node.NodeID.Split('|')[0]
// // orderby x.TrustBatchCode descending
// select x;
// if (txtSearchCode.Text.Trim() != "")
// {
// trusts = from x in trusts where x.TrustBatchCode.Contains(this.txtSearchCode.Text.Trim()) select x;
// }
// if (txtPipeCode.Text.Trim() != "")
// {
// trusts = from x in trusts
// join y in Funs.DB.Pipeline_Pipeline on x.PipelineId equals y.PipelineId
// where y.PipelineCode.Contains(txtPipeCode.Text.Trim())
// select x;
// }
// trusts = trusts.OrderByDescending(x => x.TrustBatchCode);
// foreach (var trust in trusts)
// {
// TreeNode newNode = new TreeNode();
// if (string.Format("{0:yyyy-MM-dd}", trust.TrustDate) == string.Format("{0:yyyy-MM-dd}", System.DateTime.Now))
// {
// newNode.Text = "<font color='#EE0000'>" + trust.TrustBatchCode + "</font>";
// newNode.ToolTip = "当天委托单";
// }
// else
// {
// newNode.Text = trust.TrustBatchCode;
// newNode.ToolTip = "非当天委托单";
// }
// newNode.NodeID = trust.TrustBatchId;
// newNode.EnableClickEvent = true;
// node.Nodes.Add(newNode);
// }
}
}
#endregion
protected void tvControlItem_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
{
if (e.Node.ToolTip == "DetectionType")
{
e.Node.Nodes.Clear();
// 单号
var trusts = from x in Funs.DB.Batch_BatchTrust
where
x.ProjectId == this.CurrUser.LoginProjectId
&& x.InstallationId.ToString() == e.Node.ParentNode.NodeID.Split('|')[0]
&& x.UnitId == e.Node.ParentNode.ParentNode.NodeID
&& x.DetectionTypeId == e.Node.NodeID.Split('|')[0]
// orderby x.TrustBatchCode descending
select x;
if (txtSearchCode.Text.Trim() != "")
{
trusts = from x in trusts where x.TrustBatchCode.Contains(this.txtSearchCode.Text.Trim()) select x;
}
if (txtPipeCode.Text.Trim() != "")
{
trusts = from x in trusts
join y in Funs.DB.Pipeline_Pipeline on x.PipelineId equals y.PipelineId
where y.PipelineCode.Contains(txtPipeCode.Text.Trim())
select x;
}
if (txtSearchCode.Text.Trim() == ""&& txtPipeCode.Text.Trim() == "")
{
trusts = from x in trusts where x.TrustDate < Convert.ToDateTime(this.txtTrustDateMonth.Text.Trim() + "-01").AddMonths(1)
&& x.TrustDate >= Convert.ToDateTime(this.txtTrustDateMonth.Text.Trim() + "-01").AddMonths(-1) select x;
}
trusts = trusts.OrderByDescending(x => x.TrustBatchCode);
foreach (var trust in trusts)
{
TreeNode newNode = new TreeNode();
if (string.Format("{0:yyyy-MM-dd}", trust.TrustDate) == string.Format("{0:yyyy-MM-dd}", System.DateTime.Now))
{
newNode.Text = "<font color='#EE0000'>" + trust.TrustBatchCode + "</font>";
newNode.ToolTip = "当天委托单";
}
else
{
newNode.Text = trust.TrustBatchCode;
newNode.ToolTip = "非当天委托单";
}
newNode.NodeID = trust.TrustBatchId;
newNode.EnableClickEvent = true;
e.Node.Nodes.Add(newNode);
}
}
}
#region TreeView
/// <summary>
/// 点击TreeView
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e)
{
Model.View_Batch_BatchTrust trust = BLL.Batch_BatchTrustService.GetBatchTrustViewById(this.tvControlItem.SelectedNodeID);
if (trust != null)
{
var t = BLL.Batch_BatchTrustService.GetBatchTrustById(trust.TrustBatchId);
if (string.IsNullOrEmpty(trust.SurfaceState) || string.IsNullOrEmpty(trust.DetectionTiming) || string.IsNullOrEmpty(trust.NDEUuit))
{
if (string.IsNullOrEmpty(trust.SurfaceState))
{
t.SurfaceState = "打磨";
}
if (string.IsNullOrEmpty(trust.DetectionTiming))
{
t.DetectionTiming = "焊后";
}
if (string.IsNullOrEmpty(trust.NDEUuit))
{
var u = from x in Funs.DB.Project_Unit where x.ProjectId == CurrUser.LoginProjectId && x.UnitType == Const.UnitType_4 select x;
if (u.Count() == 1)
{
t.NDEUuit = u.First().UnitId;
}
}
Funs.DB.SubmitChanges();
}
lbTrustUnit.Text = trust.TrustUnit;
this.txtTrustBatchCode.Text = trust.TrustBatchCode;
this.txtTrustCode.Text= trust.TrustBatchCode;
//if (trust.TrustDate != null)
//{
// this.txtTrustDate.Text = string.Format("{0:yyyy-MM-dd}", trust.TrustDate);
//}
this.txtDetectionTypeCode.Text = trust.DetectionTypeCode;
drpNDEUnit.SelectedValue = trust.NDEUuit;
txtTrustDate.Text = string.Format("{0:yyyy-MM-dd}", trust.TrustDate);
if (!string.IsNullOrEmpty(trust.SurfaceState))
{
drpSurfaceState.SelectedValue = trust.SurfaceState;
}
if (!string.IsNullOrEmpty(trust.DetectionTiming))
{
drpDetectionTiming.SelectedValue = trust.DetectionTiming;
}
txtTestStandard.Text = trust.TestStandard;
txtTestRate.Text = trust.DetectionRateCode;
txtTechLevel.Text = trust.TechLevel;
txtWeldMothed.Text = trust.WeldingMethodCode;
txtGrooveType.Text = trust.GrooveTypeCode;
txtPipClass.Text = trust.PIPClassCode;
//if (trust.DetectionTypeCode == "RT")
//{
// btnMenuRtReplace.Hidden = false;
//}
//else
//{
// btnMenuRtReplace.Hidden = true;
//}
}
this.BindGrid();
}
#endregion
#region
/// <summary>
/// 数据绑定
/// </summary>
private void BindGrid()
{
if (this.tvControlItem.SelectedNode != null)
{
string strSql = @"SELECT batchItem.TrustBatchItemId, pipe.PipelineCode,jot.Specification,jot.WeldJointCode,
(CASE WHEN CoverWelder.WelderCode IS NOT NULL AND BackingWelder.WelderCode IS NOT NULL
THEN backingWelder.WelderCode + '/' + coverWelder.WelderCode
ELSE (ISNULL(coverWelder.WelderCode,'') + ISNULL(backingWelder.WelderCode,'')) END) AS WelderCode,
(CASE WHEN mat1.MaterialCode IS NOT NULL AND mat2.MaterialCode IS NOT NULL
THEN mat1.MaterialCode + '+' + mat2.MaterialCode
ELSE (ISNULL(mat1.MaterialCode,'') + ISNULL(mat2.MaterialCode,'')) END) AS MaterialCode,
(CASE WHEN BatchTrust.IsWelderFirst=1 THEN '首三口' ELSE '' END) as IsWelderFirst
FROM Batch_BatchTrustItem AS batchItem
LEFT JOIN dbo.Batch_BatchTrust AS BatchTrust ON BatchTrust.TrustBatchId=batchItem.TrustBatchId
LEFT JOIN dbo.Pipeline_WeldJoint jot ON jot.WeldJointId = batchItem.WeldJointId
LEFT JOIN dbo.Pipeline_Pipeline pipe ON pipe.PipelineId = jot.PipelineId
LEFT JOIN dbo.Welder_Welder backingWelder ON backingWelder.WelderId = jot.BackingWelderId
LEFT JOIN dbo.Welder_Welder coverWelder ON coverWelder.WelderId = jot.CoverWelderId
LEFT JOIN Base_Material AS mat1 ON mat1.MaterialId = jot.Material1Id
LEFT JOIN Base_Material AS mat2 ON mat2.MaterialId = jot.Material2Id
LEFT JOIN Batch_PointBatchItem AS PointBatchItem ON PointBatchItem.PointBatchItemId=batchItem.PointBatchItemId
WHERE batchItem.TrustBatchId=@TrustBatchId ";
List<SqlParameter> listStr = new List<SqlParameter>
{
};
listStr.Add(new SqlParameter("@TrustBatchId", this.tvControlItem.SelectedNodeID));
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();
}
}
#endregion
#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.InitTreeMenu();//加载树
this.BindGrid();
}
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void TextBox_TextChanged(object sender, EventArgs e)
{
this.BindGrid();
}
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Tree_TextChanged(object sender, EventArgs e)
{
this.InitTreeMenu();
this.BindGrid();
}
#endregion
protected void btnSave_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_BatchTrustMenuId, Const.BtnSave))
{
if (this.tvControlItem.SelectedNode != null && drpNDEUnit.SelectedValue != null)
{
string trustBatchId = this.tvControlItem.SelectedNodeID;
string ndtUnit = drpNDEUnit.SelectedValue;
string trustCode = txtTrustCode.Text.Trim();
string surfaceState = drpSurfaceState.SelectedValue;
string detectionTiming = drpDetectionTiming.SelectedValue;
DateTime? trustDate= Funs.GetNewDateTime(this.txtTrustDate.Text);
BLL.Batch_BatchTrustService.BatchTrustNDEUnit(trustBatchId, ndtUnit, trustCode, surfaceState, detectionTiming, null, null, trustDate);
txtTrustBatchCode.Text = trustCode;
ShowNotify(Resources.Lan.SaveSuccessfully, MessageBoxIcon.Success);
}
}
else
{
ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
return;
}
}
protected void btnDelete_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_BatchTrustMenuId, Const.BtnDelete))
{
Model.HJGLDB db = Funs.DB;
if (!string.IsNullOrEmpty(this.tvControlItem.SelectedNodeID))
{
string trustBatchId = this.tvControlItem.SelectedNodeID;
var t = from y in db.Batch_BatchTrustItem where y.TrustBatchId == trustBatchId select y;
if (t.Count() > 0)
{
// 修改点口单的IsTrust为False
string topoint = (from x in db.Batch_BatchTrust where x.TrustBatchId == trustBatchId select x.TopointBatch).FirstOrDefault();
if (!String.IsNullOrEmpty(topoint))
{
string[] points = topoint.Split(',');
foreach (string item in points)
{
Model.Batch_PointBatch point = BLL.Batch_PointBatchService.GetPointBatchById(item);
if (point != null)
{
BLL.Batch_PointBatchService.UpdatePointTrustState(item, false);
}
}
}
foreach (var item in t)
{
if (!string.IsNullOrEmpty(item.PointBatchItemId))
{
var pointItem = BLL.Batch_PointBatchItemService.GetPointBatchItemByPointBatchItemId(item.PointBatchItemId);
pointItem.IsBuildTrust = null;
db.SubmitChanges();
}
}
var check = from x in db.Batch_NDE where x.TrustBatchId == trustBatchId select x;
if (check.Count() > 0)
{
var cItem = from x in db.Batch_NDEItem where x.NDEID == check.First().NDEID select x;
if (cItem.Count() > 0)
{
db.Batch_NDEItem.DeleteAllOnSubmit(cItem);
}
db.Batch_NDE.DeleteOnSubmit(check.First());
db.SubmitChanges();
}
db.Batch_BatchTrustItem.DeleteAllOnSubmit(t);
BLL.Batch_BatchTrustService.DeleteBatchTrustById(trustBatchId);
}
else
{
BLL.Batch_BatchTrustService.DeleteBatchTrustById(trustBatchId);
}
BLL.Sys_LogService.AddLog(BLL.Const.System_3, this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_BatchTrustMenuId, Const.BtnDelete, trustBatchId);
ShowNotify(Resources.Lan.DeletedSuccessfully, MessageBoxIcon.Success);
}
}
else
{
ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
return;
}
}
#region
protected void btnMenuCancel_Click(object sender, EventArgs e)
{
if (CurrUser.Account == Const.Gly)
{
string rowId = Grid1.SelectedRowID;
if (!string.IsNullOrEmpty(rowId))
{
var ndtItem = from x in Funs.DB.Batch_NDEItem where x.TrustBatchItemId == rowId select x;
if (ndtItem.Count() == 0)
{
BLL.Batch_BatchTrustItemService.UpdatIsCancelTrust(rowId, true);
ShowNotify(Resources.Lan.SaveSuccessfully, MessageBoxIcon.Success);
BindGrid();
}
else
{
Alert.ShowInTop("此焊口已检测,不能取消委托!", MessageBoxIcon.Warning);
return;
}
}
else
{
Alert.ShowInTop("请选择要取消委托的焊口!", MessageBoxIcon.Warning);
return;
}
}
else
{
ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
return;
}
}
protected void btnMenuReTrust_Click(object sender, EventArgs e)
{
if (CurrUser.Account == Const.Gly)
{
string rowId = Grid1.SelectedRowID;
if (!string.IsNullOrEmpty(rowId))
{
var tItem = BLL.Batch_BatchTrustItemService.GetBatchTrustItemById(rowId);
if (tItem != null && tItem.IsCancelTrust == true)
{
BLL.Batch_BatchTrustItemService.UpdatIsCancelTrust(rowId, null);
ShowNotify(Resources.Lan.SaveSuccessfully, MessageBoxIcon.Success);
BindGrid();
}
else
{
Alert.ShowInTop("此焊口正常委托,不用恢复!", MessageBoxIcon.Warning);
return;
}
}
else
{
Alert.ShowInTop("请选择要恢复委托的焊口!", MessageBoxIcon.Warning);
return;
}
}
else
{
ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
return;
}
}
#endregion
protected void btnMenuRtReplace_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_BatchTrustMenuId, Const.BtnRTTrustReplace))
{
string rowId = Grid1.SelectedRowID;
if (!string.IsNullOrEmpty(rowId))
{
var ndtItem = from x in Funs.DB.Batch_NDEItem where x.TrustBatchItemId == rowId select x;
if (ndtItem.Count() == 0)
{
var tItem = BLL.Batch_BatchTrustItemService.GetBatchTrustItemById(rowId);
var batch = BLL.Batch_BatchTrustService.GetBatchTrustById(tItem.TrustBatchId);
string batchCode = batch.TrustBatchCode;
string str = batchCode.Substring(batchCode.Length - 2);
if (str.Contains("K") || str.Contains("R") || str.Contains("M"))
{
Alert.ShowInTop("焊口为返修、扩透、修磨或异物,不能替换!", MessageBoxIcon.Warning);
return;
}
else
{
PageContext.RegisterStartupScript(Window3.GetShowReference(String.Format("RTTrustReplace.aspx?BatchTrustItemId={0}", rowId, "RT委托替换 - ")));
}
}
else
{
Alert.ShowInTop("此焊口已检测,不能替换!", MessageBoxIcon.Warning);
return;
}
}
else
{
Alert.ShowInTop("请选择要替换的焊口!", MessageBoxIcon.Warning);
return;
}
}
else
{
ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
}
}
protected void btnPrint_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_BatchTrustMenuId, Const.BtnPrint))
{
if (!string.IsNullOrEmpty(this.tvControlItem.SelectedNodeID))
{
string varValue = string.Empty;
string trustBatchId = this.tvControlItem.SelectedNodeID;
var project = BLL.Base_ProjectService.GetProjectByProjectId(this.CurrUser.LoginProjectId);
Model.View_Batch_BatchTrust trust = BLL.Batch_BatchTrustService.GetBatchTrustViewById(trustBatchId);
if (trust != null && project != null)
{
if (project.ProjectArea == "2")
{
varValue = trust.TrustBatchCode + "|" + trust.TrustDate.Value.Date + "|";
varValue = varValue + project.ProjectName + "|" + project.ProjectCode + "|";
varValue = varValue + trust.InstallationName + "|" + trust.InstallationCode;
if (!string.IsNullOrEmpty(varValue))
{
varValue = HttpUtility.UrlEncodeUnicode(varValue);
}
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("../../Common/ReportPrint/ExReportPrint.aspx?ispop=1&reportId={0}&replaceParameter={1}&varValue={2}&projectId=0", BLL.Const.CheckTrustReport, trustBatchId, varValue)));
}
else
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("../../Common/ReportPrint/ExReportPrint.aspx?ispop=1&reportId={0}&replaceParameter={1}&varValue={2}&projectId=0", BLL.Const.CheckTrustReport3, trustBatchId, null)));
}
}
}
}
else
{
ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
return;
}
}
#region
/// <summary>
/// 导入按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnImport_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_CheckManageMenuId, Const.BtnAdd))
{
PageContext.RegisterStartupScript(Window4.GetShowReference(String.Format("TrustBatchIn.aspx", "导入 - ")));
}
else
{
ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
}
}
/// <summary>
/// 关闭导入弹出窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window4_Close(object sender, WindowCloseEventArgs e)
{
InitTreeMenu();
}
#endregion
protected void btnExport_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_BatchTrustMenuId, Const.BtnOut))
{
//PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("TrustBatchOut.aspx", "导出 - ")));
if (string.IsNullOrWhiteSpace(this.tvControlItem.SelectedNodeID))
{
Alert.ShowInTop("请选择委托单!", MessageBoxIcon.Warning);
return;
}
string rootPath = Server.MapPath("~/") + Const.ExcelUrl;
//导出文件
string filePath = rootPath + DateTime.Now.ToString("yyyyMMddhhmmss") + "\\";
if (!Directory.Exists(filePath))
{
Directory.CreateDirectory(filePath);
}
string ReportFileName = filePath + "out1.xlsx";
int rowIndex = 0;
XSSFWorkbook hssfworkbook = new XSSFWorkbook();
XSSFSheet ws = new XSSFSheet();
string trustBatchId = this.tvControlItem.SelectedNodeID;
//头部
var listStr = new List<SqlParameter>();
listStr.Add(new SqlParameter("@TrustBatchId", trustBatchId));
SqlParameter[] parameter = listStr.ToArray();
var tbTitle = SQLHelper.GetDataTableRunProc("sp_TrustReport", parameter);
string detectionTypeCode = tbTitle.Rows[0]["DetectionTypeCode"].ToString();
string trustBatchCode = tbTitle.Rows[0]["TrustBatchCode"].ToString();
DateTime? trustDate = Funs.GetNewDateTime(tbTitle.Rows[0]["TrustDate"].ToString());
//列表
var listTitleStr = new List<SqlParameter>();
listTitleStr.Add(new SqlParameter("@TrustBatchId", trustBatchId));
SqlParameter[] titleparameter = listTitleStr.ToArray();
var tb = SQLHelper.GetDataTableRunProc("TrustItemReport", titleparameter);
var style = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Center, 10, true, false);
var styleButton = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.None, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Center, 10, true, false);
var styleTop = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.None, VerticalAlignment.Center, HorizontalAlignment.Center, 10, true, false);
var styleNone = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.None, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.None, VerticalAlignment.Center, HorizontalAlignment.Center, 10, true, false);
if (detectionTypeCode.Trim() == "PMI")
{
if (hssfworkbook.GetSheet("材料及配件检测委托单") != null)
{
ws = (XSSFSheet)hssfworkbook.GetSheet("材料及配件检测委托单");
}
else
{
rowIndex = 0;
ws = (XSSFSheet)hssfworkbook.CreateSheet("材料及配件检测委托单");
#region
ws.SetColumnWidth(0, 5 * 256);
ws.SetColumnWidth(1, 7 * 256);
ws.SetColumnWidth(2, 5 * 256);
ws.SetColumnWidth(3, 5 * 256);
ws.SetColumnWidth(4, 5 * 256);
ws.SetColumnWidth(5, 5 * 256);
ws.SetColumnWidth(6, 5 * 256);
ws.SetColumnWidth(7, 6 * 256);
ws.SetColumnWidth(8, 6 * 256);
ws.SetColumnWidth(9, 9 * 256);
ws.SetColumnWidth(10, 8 * 256);
ws.SetColumnWidth(11, 8 * 256);
ws.SetColumnWidth(12, 5 * 256);
ws.SetColumnWidth(13, 9 * 256);
ws.SetColumnWidth(14, 4 * 256);
ws.SetColumnWidth(15, 4 * 256);
ws.SetColumnWidth(16, 4 * 256);
ws.SetColumnWidth(17, 5 * 256);
ws.SetColumnWidth(18, 10 * 256);
ws.SetColumnWidth(19, 8 * 256);
ws.SetColumnWidth(20, 8 * 256);
#endregion
}
if (tb.Rows.Count > 0 && tbTitle.Rows.Count > 0)
{
string jlAuditer = tb.Rows[0]["JLAuditID"].ToString();
string glgsAuditer = tb.Rows[0]["GLGSAuditID"].ToString();
var getJLInfo = BLL.Sys_UserService.GetSingtrueImageUrl(jlAuditer);
var getGLGSInfo = BLL.Sys_UserService.GetSingtrueImageUrl(glgsAuditer);
var tbNum = tb.Rows.Count;
var pageNum =
tbNum < 17 ? 1
: Math.Ceiling((float)(tbNum - 16) / 16) + 1;
//循环页
for (int i = 1; i <= pageNum; i++)
{
#region
ws = ClExcelCreateRow(ws, hssfworkbook, rowIndex, rowIndex + 5, style, 0, 20, true);
//行0
CellRangeAddress region = new CellRangeAddress(rowIndex, rowIndex + 3, 0, 4);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex).GetCell(0).SetCellValue(tbTitle.Rows[0]["PipelineCode"].ToString());
region = new CellRangeAddress(rowIndex, rowIndex + 3, 5, 15);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex).GetCell(5).SetCellValue("材料及配件检测委托单");
ws.GetRow(rowIndex).GetCell(5).CellStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Center, 16, true, true);
region = new CellRangeAddress(rowIndex, rowIndex, 16, 20);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex).GetCell(16).SetCellValue(tbTitle.Rows[0]["ProjectName"].ToString());
ws.GetRow(rowIndex).GetCell(16).CellStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Justify, 10, true, false);
//行1
region = new CellRangeAddress(rowIndex + 1, rowIndex + 1, 16, 20);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 1).GetCell(16).SetCellValue("");
ws.GetRow(rowIndex + 1).GetCell(16).CellStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Justify, 9, true, false);
//行2
region = new CellRangeAddress(rowIndex + 2, rowIndex + 2, 16, 20);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 2).GetCell(16).SetCellValue(tbTitle.Rows[0]["InstallationName"].ToString());
ws.GetRow(rowIndex + 2).GetCell(16).CellStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Justify, 10, true, false);
//行3
region = new CellRangeAddress(rowIndex + 3, rowIndex + 3, 16, 20);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 3).GetCell(16).SetCellValue("");
ws.GetRow(rowIndex + 3).GetCell(16).CellStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Justify, 10, true, false);
//行4
region = new CellRangeAddress(rowIndex + 4, rowIndex + 4, 0, 1);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 4).GetCell(0).SetCellValue("检测方法");
region = new CellRangeAddress(rowIndex + 4, rowIndex + 4, 2, 3);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 4).GetCell(2).SetCellValue(tbTitle.Rows[0]["DetectionTypeCode"].ToString());
region = new CellRangeAddress(rowIndex + 4, rowIndex + 4, 4, 6);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 4).GetCell(4).SetCellValue("检测标准");
region = new CellRangeAddress(rowIndex + 4, rowIndex + 4, 7, 9);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 4).GetCell(7).SetCellValue("GB 50184-2011");
//ws.GetRow(rowIndex + 4).GetCell(7).SetCellValue(tbTitle.Rows[0]["ExecStandard"].ToString());
region = new CellRangeAddress(rowIndex + 4, rowIndex + 4, 10, 11);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 4).GetCell(10).SetCellValue("检测比列");
region = new CellRangeAddress(rowIndex + 4, rowIndex + 4, 12, 14);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 4).GetCell(12).SetCellValue(tbTitle.Rows[0]["DetectionRateCode"].ToString());
region = new CellRangeAddress(rowIndex + 4, rowIndex + 4, 15, 17);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 4).GetCell(15).SetCellValue("委托编号");
region = new CellRangeAddress(rowIndex + 4, rowIndex + 4, 18, 20);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 4).GetCell(18).SetCellValue(tbTitle.Rows[0]["TrustBatchCode"].ToString());
//行5
ws.GetRow(rowIndex + 5).GetCell(0).SetCellValue("序号");
region = new CellRangeAddress(rowIndex + 5, rowIndex + 5, 1, 2);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 5).GetCell(1).SetCellValue("检件编号");
region = new CellRangeAddress(rowIndex + 5, rowIndex + 5, 3, 5);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 5).GetCell(3).SetCellValue("检件名称");
region = new CellRangeAddress(rowIndex + 5, rowIndex + 5, 6, 7);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 5).GetCell(6).SetCellValue("质量证明文件编号");
region = new CellRangeAddress(rowIndex + 5, rowIndex + 5, 8, 10);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 5).GetCell(8).SetCellValue("炉/批号");
region = new CellRangeAddress(rowIndex + 5, rowIndex + 5, 11, 12);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 5).GetCell(11).SetCellValue("检件规格");
ws.GetRow(rowIndex + 5).GetCell(13).SetCellValue("检件材质");
region = new CellRangeAddress(rowIndex + 5, rowIndex + 5, 14, 16);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 5).GetCell(14).SetCellValue("热处理状态");
region = new CellRangeAddress(rowIndex + 5, rowIndex + 5, 17, 18);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 5).GetCell(17).SetCellValue("制造/验收标准");
ws.GetRow(rowIndex + 5).GetCell(19).SetCellValue("总数量(道)");
ws.GetRow(rowIndex + 5).GetCell(20).SetCellValue("抽检数量");
#endregion
#region
ws = ClExcelCreateRow(ws, hssfworkbook, rowIndex + 6, rowIndex + 20, style, 0, 20);
var dataTit = rowIndex + 6;
var tIndex = 5 + 15;
var dStart = 0;
var dEnd = 0;
if (i == 1)
{
dStart = 0;
dEnd = 15;
}
else
{
dStart = i == 2 ? 15 : ((i - 2) * 15) + 15;
dEnd = ((i - 1) * 15) + 15;
}
//合并单元格
for (int hb = dataTit; hb <= rowIndex + tIndex; hb++)
{
region = new CellRangeAddress(hb, hb, 1, 2);
ws.AddMergedRegion(region);
region = new CellRangeAddress(hb, hb, 3, 5);
ws.AddMergedRegion(region);
region = new CellRangeAddress(hb, hb, 6, 7);
ws.AddMergedRegion(region);
region = new CellRangeAddress(hb, hb, 8, 10);
ws.AddMergedRegion(region);
region = new CellRangeAddress(hb, hb, 11, 12);
ws.AddMergedRegion(region);
region = new CellRangeAddress(hb, hb, 14, 16);
ws.AddMergedRegion(region);
region = new CellRangeAddress(hb, hb, 17, 18);
ws.AddMergedRegion(region);
}
//获取当前页数据
var pageTb = GetPageToTable(tb, dStart, dEnd);
for (int j = 0; j < pageTb.Rows.Count; j++)
{
int dataIndex = dataTit + j;
//序号
ws.GetRow(dataIndex).GetCell(0).SetCellValue(pageTb.Rows[j]["Number"].ToString());
//检件编号
ws.GetRow(dataIndex).GetCell(1).SetCellValue(pageTb.Rows[j]["PipelineCode"].ToString() + " " + pageTb.Rows[j]["WeldJointCode"].ToString());
//检件名称
ws.GetRow(dataIndex).GetCell(3).SetCellValue("焊缝");
//质量证明文件编号
ws.GetRow(dataIndex).GetCell(6).SetCellValue(tbTitle.Rows[0]["QuaCertFile"].ToString());
//炉/批号
List<string> lpls = new List<string>();
if (!string.IsNullOrWhiteSpace(pageTb.Rows[0]["HeartNo1"].ToString())) lpls.Add(pageTb.Rows[0]["HeartNo1"].ToString());
if (!string.IsNullOrWhiteSpace(pageTb.Rows[0]["HeartNo2"].ToString())) lpls.Add(pageTb.Rows[0]["HeartNo2"].ToString());
if (lpls.Count > 0) lpls = lpls.GroupBy(x => x).Select(x => x.Key).ToList();
ws.GetRow(dataIndex).GetCell(8).SetCellValue(string.Join("/", lpls));
//检件规格
ws.GetRow(dataIndex).GetCell(11).SetCellValue(pageTb.Rows[j]["Specification"].ToString());
//检件材质
ws.GetRow(dataIndex).GetCell(13).SetCellValue(pageTb.Rows[j]["MaterialCode"].ToString());
//热处理状态
ws.GetRow(dataIndex).GetCell(14).SetCellValue(pageTb.Rows[j]["IsHotProessName"].ToString());
//制造/验收标准
ws.GetRow(dataIndex).GetCell(17).SetCellValue(tbTitle.Rows[0]["AcceptStandard"].ToString());
//总数量(道)
ws.GetRow(dataIndex).GetCell(19).SetCellValue("");
//抽检数量
ws.GetRow(dataIndex).GetCell(20).SetCellValue("");
}
rowIndex += tIndex;
#endregion
#region
ws = ClExcelCreateRow(ws, hssfworkbook, rowIndex + 1, rowIndex + 8, style, 0, 20);
//合并单元格
for (int hb = rowIndex + 1; hb <= rowIndex + 8; hb++)
{
for (int c = 0; c <= 20; c++)
{
if (hb >= rowIndex + 2 && hb < rowIndex + 8)
{
ws.GetRow(hb).GetCell(c).CellStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.None, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.None, VerticalAlignment.Center, HorizontalAlignment.Left, 10, true, false);
}
if (hb == rowIndex + 8)
{
ws.GetRow(hb).GetCell(c).CellStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.None, VerticalAlignment.Center, HorizontalAlignment.Right, 10, true, false);
}
}
region = new CellRangeAddress(hb, hb, 0, 3);
ws.AddMergedRegion(region);
region = new CellRangeAddress(hb, hb, 4, 8);
ws.AddMergedRegion(region);
region = new CellRangeAddress(hb, hb, 9, 11);
ws.AddMergedRegion(region);
region = new CellRangeAddress(hb, hb, 12, 17);
ws.AddMergedRegion(region);
region = new CellRangeAddress(hb, hb, 18, 20);
ws.AddMergedRegion(region);
}
//尾部行1
ws.GetRow(rowIndex + 1).GetCell(0).SetCellValue("检测单位");
ws.GetRow(rowIndex + 1).GetCell(4).SetCellValue("监理单位");
ws.GetRow(rowIndex + 1).GetCell(9).SetCellValue("管理公司");
ws.GetRow(rowIndex + 1).GetCell(12).SetCellValue("建设单位");
ws.GetRow(rowIndex + 1).GetCell(18).SetCellValue("检测单位");
//尾部行2
ws.GetRow(rowIndex + 2).GetCell(0).SetCellValue("质量检测员:");
ws.GetRow(rowIndex + 2).GetCell(4).SetCellValue("专业工程师:");
ws.GetRow(rowIndex + 2).GetCell(9).SetCellValue("专业/质量工程师:");
ws.GetRow(rowIndex + 2).GetCell(12).SetCellValue("业主代表:");
ws.GetRow(rowIndex + 2).GetCell(18).SetCellValue("接收人:");
//尾部行4
ws.GetRow(rowIndex + 4).GetCell(0).SetCellValue("专业工程师:");
//尾部行8
ws.GetRow(rowIndex + 8).GetCell(0).SetCellValue("年 月 日");
ws.GetRow(rowIndex + 8).GetCell(4).SetCellValue("年 月 日");
ws.GetRow(rowIndex + 8).GetCell(9).SetCellValue("年 月 日");
ws.GetRow(rowIndex + 8).GetCell(12).SetCellValue("年 月 日");
ws.GetRow(rowIndex + 8).GetCell(18).SetCellValue("年 月 日");
//插入签名图片
if (!string.IsNullOrEmpty(getJLInfo.Item1))
{
InsertImage(hssfworkbook, ws, rowIndex + 4, 2, rowIndex + 4, 4, Server.MapPath(getJLInfo.Item1), 1, 5, 20, 10);
}
if (!string.IsNullOrEmpty(getGLGSInfo.Item1))
{
InsertImage(hssfworkbook, ws, rowIndex + 4, 5, rowIndex + 4, 6, Server.MapPath(getJLInfo.Item1), 1, 5, 20, 10);
}
#endregion
ws = ClExcelCreateRow(ws, hssfworkbook, rowIndex + 9, rowIndex + 9, style, 0, 20, false, true);
rowIndex += 10;
}
}
}
else
{
if (hssfworkbook.GetSheet("无损检测委托单") != null)
{
ws = (XSSFSheet)hssfworkbook.GetSheet("无损检测委托单");
}
else
{
rowIndex = 0;
ws = (XSSFSheet)hssfworkbook.CreateSheet("无损检测委托单");
#region
ws.SetColumnWidth(0, 9 * 256);
ws.SetColumnWidth(1, 6 * 256);
ws.SetColumnWidth(2, 6 * 256);
ws.SetColumnWidth(3, 6 * 256);
ws.SetColumnWidth(4, 6 * 256);
ws.SetColumnWidth(5, 9 * 256);
ws.SetColumnWidth(6, 9 * 256);
ws.SetColumnWidth(7, 5 * 256);
ws.SetColumnWidth(8, 5 * 256);
ws.SetColumnWidth(9, 5 * 256);
ws.SetColumnWidth(10, 8 * 256);
ws.SetColumnWidth(11, 9 * 256);
ws.SetColumnWidth(12, 11 * 256);
#endregion
}
if (tb.Rows.Count > 0 && tbTitle.Rows.Count > 0)
{
string jlAuditer = tb.Rows[0]["JLAuditID"].ToString();
string glgsAuditer = tb.Rows[0]["GLGSAuditID"].ToString();
var getJLInfo = BLL.Sys_UserService.GetSingtrueImageUrl(jlAuditer);
var getGLGSInfo=BLL.Sys_UserService.GetSingtrueImageUrl(glgsAuditer);
var tbNum = tb.Rows.Count;
var pageNum =
tbNum < 15 ? 1
: Math.Ceiling((float)(tbNum - 14) / 14) + 1;
//循环页
for (int i = 1; i <= pageNum; i++)
{
#region
ws = WsExcelCreateRow(ws, hssfworkbook, rowIndex, rowIndex + 12, style, 0, 12, 1);
//行0
CellRangeAddress region = new CellRangeAddress(rowIndex, rowIndex + 3, 0, 2);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex).GetCell(0).SetCellValue("NDE-001");
ws.GetRow(rowIndex).GetCell(0).CellStyle = style;
ws.GetRow(rowIndex).GetCell(1).CellStyle = style;
ws.GetRow(rowIndex).GetCell(2).CellStyle = style;
region = new CellRangeAddress(rowIndex, rowIndex + 3, 3, 9);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex).GetCell(3).SetCellValue("无损检测委托单");
ws.GetRow(rowIndex).GetCell(3).CellStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Center, 16, true, true);
ws.GetRow(rowIndex).GetCell(4).CellStyle = style;
ws.GetRow(rowIndex).GetCell(5).CellStyle = style;
ws.GetRow(rowIndex).GetCell(6).CellStyle = style;
ws.GetRow(rowIndex).GetCell(7).CellStyle = style;
ws.GetRow(rowIndex).GetCell(8).CellStyle = style;
ws.GetRow(rowIndex).GetCell(9).CellStyle = style;
region = new CellRangeAddress(rowIndex, rowIndex, 10, 12);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex).GetCell(10).SetCellValue(tbTitle.Rows[0]["ProjectName"].ToString());
ws.GetRow(rowIndex).GetCell(10).CellStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.None, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Justify, 10.5, true, false);
ws.GetRow(rowIndex).GetCell(11).CellStyle = styleButton;
ws.GetRow(rowIndex).GetCell(12).CellStyle = styleButton;
//行1
region = new CellRangeAddress(rowIndex + 1, rowIndex + 1, 10, 12);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 1).GetCell(10).SetCellValue(tbTitle.Rows[0]["EnProjectName"].ToString());
ws.GetRow(rowIndex + 1).GetCell(10).CellStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.None, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.None, VerticalAlignment.Center, HorizontalAlignment.Justify, 10.5, true, false);
ws.GetRow(rowIndex + 1).GetCell(11).CellStyle = styleNone;
ws.GetRow(rowIndex + 1).GetCell(12).CellStyle = styleNone;
//行2
region = new CellRangeAddress(rowIndex + 2, rowIndex + 2, 10, 12);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 2).GetCell(10).SetCellValue(tbTitle.Rows[0]["WorkAreaName"].ToString());
ws.GetRow(rowIndex + 2).GetCell(10).CellStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.None, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.None, VerticalAlignment.Center, HorizontalAlignment.Justify, 10.5, true, false);
ws.GetRow(rowIndex + 2).GetCell(11).CellStyle = styleNone;
ws.GetRow(rowIndex + 2).GetCell(12).CellStyle = styleNone;
//行3
region = new CellRangeAddress(rowIndex + 3, rowIndex + 3, 10, 12);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 3).GetCell(10).SetCellValue(tbTitle.Rows[0]["EnWorkAreaName"].ToString());
ws.GetRow(rowIndex + 3).GetCell(10).CellStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.None, VerticalAlignment.Center, HorizontalAlignment.Justify, 10.5, true, false);
ws.GetRow(rowIndex + 3).GetCell(11).CellStyle = styleTop;
ws.GetRow(rowIndex + 3).GetCell(12).CellStyle = styleTop;
//行4
ws.GetRow(rowIndex + 4).GetCell(0).SetCellValue("委托单位");
region = new CellRangeAddress(rowIndex + 4, rowIndex + 4, 1, 5);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 4).GetCell(1).SetCellValue(tbTitle.Rows[0]["TrustUnit"].ToString());
region = new CellRangeAddress(rowIndex + 4, rowIndex + 4, 6, 7);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 4).GetCell(6).SetCellValue("委托编号");
region = new CellRangeAddress(rowIndex + 4, rowIndex + 4, 8, 12);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 4).GetCell(8).SetCellValue(tbTitle.Rows[0]["TrustBatchCode"].ToString());
//行5,
ws.GetRow(rowIndex + 5).GetCell(0).SetCellValue("检测单位");
region = new CellRangeAddress(rowIndex + 5, rowIndex + 5, 1, 5);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 5).GetCell(1).SetCellValue(tbTitle.Rows[0]["NDEUnit"].ToString());
region = new CellRangeAddress(rowIndex + 5, rowIndex + 5, 6, 7);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 5).GetCell(6).SetCellValue("检测方法");
region = new CellRangeAddress(rowIndex + 5, rowIndex + 5, 8, 12);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 5).GetCell(8).SetCellValue(detectionTypeCode);
//行6
ws.GetRow(rowIndex + 6).GetCell(0).SetCellValue("检件名称");
region = new CellRangeAddress(rowIndex + 6, rowIndex + 6, 1, 5);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 6).GetCell(1).SetCellValue("管道焊缝");
region = new CellRangeAddress(rowIndex + 6, rowIndex + 6, 6, 7);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 6).GetCell(6).SetCellValue("表面状态");
region = new CellRangeAddress(rowIndex + 6, rowIndex + 6, 8, 12);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 6).GetCell(8).SetCellValue(tbTitle.Rows[0]["SurfaceState"].ToString());
//行7
ws.GetRow(rowIndex + 7).GetCell(0).SetCellValue("检测标准");
region = new CellRangeAddress(rowIndex + 7, rowIndex + 7, 1, 5);
ws.AddMergedRegion(region);
//ws.GetRow(rowIndex + 8).GetCell(1).SetCellValue(tbTitle.Rows[0]["ExecStandard"].ToString());
ws.GetRow(rowIndex + 7).GetCell(1).SetCellValue(tbTitle.Rows[0]["TestStandard"].ToString());
region = new CellRangeAddress(rowIndex + 7, rowIndex + 7, 6, 7);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 7).GetCell(6).SetCellValue("检测比例");
region = new CellRangeAddress(rowIndex + 7, rowIndex + 7, 8, 12);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 7).GetCell(8).SetCellValue(tbTitle.Rows[0]["DetectionRateCode"].ToString());
//行8
ws.GetRow(rowIndex + 8).GetCell(0).SetCellValue("技术等级");
region = new CellRangeAddress(rowIndex + 8, rowIndex + 8, 1, 5);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 8).GetCell(1).SetCellValue(tbTitle.Rows[0]["TechLevel"].ToString());
region = new CellRangeAddress(rowIndex + 8, rowIndex + 8, 6, 7);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 8).GetCell(6).SetCellValue("合格级别");
region = new CellRangeAddress(rowIndex + 8, rowIndex + 8, 8, 12);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 8).GetCell(8).SetCellValue(tbTitle.Rows[0]["QueClass"].ToString());
//行9
ws.GetRow(rowIndex + 9).GetCell(0).SetCellValue("焊接方法");
region = new CellRangeAddress(rowIndex + 9, rowIndex + 9, 1, 5);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 9).GetCell(1).SetCellValue(tbTitle.Rows[0]["WeldingMethodCode"].ToString());
region = new CellRangeAddress(rowIndex + 9, rowIndex + 9, 6, 7);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 9).GetCell(6).SetCellValue("压力管道分级");
region = new CellRangeAddress(rowIndex + 9, rowIndex + 9, 8, 12);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 9).GetCell(8).SetCellValue(tbTitle.Rows[0]["PIPClassCode"].ToString());
//ws.GetRow(rowIndex + 9).GetCell(1).CellStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Justify, 10.5, true, false);
//行10
ws.GetRow(rowIndex + 10).GetCell(0).SetCellValue("坡口形式");
region = new CellRangeAddress(rowIndex + 10, rowIndex + 10, 1, 12);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 10).GetCell(1).SetCellValue(tbTitle.Rows[0]["GrooveTypeCode"].ToString());
ws.GetRow(rowIndex + 10).GetCell(1).CellStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Justify, 10.5, true, false);
//行11
ws.GetRow(rowIndex + 11).GetCell(0).SetCellValue("检测时机");
region = new CellRangeAddress(rowIndex + 11, rowIndex + 11, 1, 12);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 11).GetCell(1).SetCellValue(tbTitle.Rows[0]["DetectionTiming"].ToString());
ws.GetRow(rowIndex + 11).GetCell(1).CellStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Justify, 10.5, true, false);
//行12
region = new CellRangeAddress(rowIndex + 12, rowIndex + 12, 0, 1);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 12).GetCell(0).SetCellValue("检件编号");
region = new CellRangeAddress(rowIndex + 12, rowIndex + 12, 2, 3);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 12).GetCell(2).SetCellValue("焊口号");
region = new CellRangeAddress(rowIndex + 12, rowIndex + 12, 4, 5);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 12).GetCell(4).SetCellValue("焊工代号");
region = new CellRangeAddress(rowIndex + 12, rowIndex + 12, 6, 9);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 12).GetCell(6).SetCellValue("检件材质");
region = new CellRangeAddress(rowIndex + 12, rowIndex + 12, 10, 11);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 12).GetCell(10).SetCellValue("检件规格(mm)");
ws.GetRow(rowIndex + 12).GetCell(12).SetCellValue("备注");
#endregion
#region
ws = WsExcelCreateRow(ws, hssfworkbook, rowIndex + 13, rowIndex + 26, style, 0, 12, 2);
var dataTit = rowIndex + 13;
var tIndex = 12 + 14;
var dStart = 0;
var dEnd = 0;
if (i == 1)
{
dStart = 0;
dEnd = 14;
}
else
{
dStart = i == 2 ? 14 : ((i - 2) * 14) + 14;
dEnd = ((i - 1) * 14) + 14;
}
//合并单元格
for (int hb = dataTit; hb <= rowIndex + tIndex; hb++)
{
region = new CellRangeAddress(hb, hb, 0, 1);
ws.AddMergedRegion(region);
region = new CellRangeAddress(hb, hb, 2, 3);
ws.AddMergedRegion(region);
region = new CellRangeAddress(hb, hb, 4, 5);
ws.AddMergedRegion(region);
region = new CellRangeAddress(hb, hb, 6, 9);
ws.AddMergedRegion(region);
region = new CellRangeAddress(hb, hb, 10, 11);
ws.AddMergedRegion(region);
}
//获取当前页数据
var pageTb = GetPageToTable(tb, dStart, dEnd);
for (int j = 0; j < pageTb.Rows.Count; j++)
{
int dataIndex = dataTit + j;
//检件编号
ws.GetRow(dataIndex).GetCell(0).SetCellValue(pageTb.Rows[j]["PipelineCode"].ToString());
//焊口号
ws.GetRow(dataIndex).GetCell(2).SetCellValue(pageTb.Rows[j]["WeldJointCode"].ToString());
//焊工代号
ws.GetRow(dataIndex).GetCell(4).SetCellValue(pageTb.Rows[j]["WelderCode"].ToString());
//检件材质
ws.GetRow(dataIndex).GetCell(6).SetCellValue(pageTb.Rows[j]["MaterialCode"].ToString());
//检件规格(mm)
ws.GetRow(dataIndex).GetCell(10).SetCellValue(pageTb.Rows[j]["Specification"].ToString());
//备注
ws.GetRow(dataIndex).GetCell(12).SetCellValue(pageTb.Rows[j]["Remark"].ToString());
}
if (dataTit + pageTb.Rows.Count < 26)
{
ws.GetRow(dataTit + pageTb.Rows.Count).GetCell(0).SetCellValue("以下空白");
}
rowIndex += tIndex;
#endregion
#region
string JLAudit = tb.Rows[0]["JLAudit"].ToString();
string GLGSAudit = tb.Rows[0]["GLGSAudit"].ToString();
ws = WsExcelCreateRow(ws, hssfworkbook, rowIndex + 1, rowIndex + 9, style, 0, 12, 3);
//合并单元格
for (int hb = rowIndex + 1; hb <= rowIndex + 9; hb++)
{
for (int c = 0; c <= 12; c++)
{
if (hb >= rowIndex + 2 && hb <= rowIndex + 3)
{
ws.GetRow(hb).GetCell(c).CellStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.None, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.None, VerticalAlignment.Center, HorizontalAlignment.Left, 10.5, true, false);
}
if (hb >= rowIndex + 4 && hb <= rowIndex + 8)
{
ws.GetRow(hb).GetCell(c).CellStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.None, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.None, VerticalAlignment.Center, HorizontalAlignment.Right, 10.5, true, false);
}
if (hb == rowIndex + 9)
{
ws.GetRow(hb).GetCell(c).CellStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.None, VerticalAlignment.Center, HorizontalAlignment.Center, 10.5, true, false);
}
}
region = new CellRangeAddress(hb, hb, 0, 1);
ws.AddMergedRegion(region);
region = new CellRangeAddress(hb, hb, 2, 4);
ws.AddMergedRegion(region);
region = new CellRangeAddress(hb, hb, 5, 6);
ws.AddMergedRegion(region);
region = new CellRangeAddress(hb, hb, 7, 10);
ws.AddMergedRegion(region);
region = new CellRangeAddress(hb, hb, 11, 12);
ws.AddMergedRegion(region);
}
//尾部行1
ws.GetRow(rowIndex + 1).GetCell(0).SetCellValue("施工单位");
ws.GetRow(rowIndex + 1).GetCell(2).SetCellValue("监理单位");
ws.GetRow(rowIndex + 1).GetCell(5).SetCellValue("管理公司");
ws.GetRow(rowIndex + 1).GetCell(7).SetCellValue("建设单位");
ws.GetRow(rowIndex + 1).GetCell(11).SetCellValue("检测单位");
//尾部行2
ws.GetRow(rowIndex + 2).GetCell(0).SetCellValue("");
ws.GetRow(rowIndex + 2).GetCell(2).SetCellValue("");
ws.GetRow(rowIndex + 2).GetCell(5).SetCellValue("");
ws.GetRow(rowIndex + 2).GetCell(7).SetCellValue("");
ws.GetRow(rowIndex + 2).GetCell(11).SetCellValue("");
//尾部行3
ws.GetRow(rowIndex + 3).GetCell(0).SetCellValue("质量检测员:");
ws.GetRow(rowIndex + 3).GetCell(2).SetCellValue("专业工程师:");
ws.GetRow(rowIndex + 3).GetCell(5).SetCellValue("专业/质量工程师:");
ws.GetRow(rowIndex + 3).GetCell(7).SetCellValue("业主代表:");
ws.GetRow(rowIndex + 3).GetCell(11).SetCellValue("接收人:");
// 尾部行4
//插入签名图片
if (!string.IsNullOrEmpty(getJLInfo.Item1))
{
InsertImage(hssfworkbook, ws, rowIndex + 4, 2, rowIndex + 4, 4, Server.MapPath(getJLInfo.Item1), 1, 1, 25,13,10,40);
}
if (!string.IsNullOrEmpty(getGLGSInfo.Item1))
{
InsertImage(hssfworkbook, ws, rowIndex + 4, 5, rowIndex + 4, 6, Server.MapPath(getGLGSInfo.Item1), 1.1, 1, 25, 13,10, 40);
}
ws.GetRow(rowIndex + 4).GetCell(2).SetCellValue(JLAudit);
ws.GetRow(rowIndex + 4).GetCell(5).SetCellValue(GLGSAudit);
//尾部行6
ws.GetRow(rowIndex + 6).GetCell(0).SetCellValue("专业工程师:");
//尾部行8
ws.GetRow(rowIndex + 8).GetCell(0).SetCellValue(" 年 月 日");
if (trustDate != null)
{
string tdate = trustDate.Value.Year + "年" + trustDate.Value.Month + "月" + trustDate.Value.Day + "日";
ws.GetRow(rowIndex + 8).GetCell(2).SetCellValue(tdate);
ws.GetRow(rowIndex + 8).GetCell(5).SetCellValue(tdate);
}
ws.GetRow(rowIndex + 8).GetCell(7).SetCellValue(" 年 月 日");
ws.GetRow(rowIndex + 8).GetCell(11).SetCellValue(" 年 月 日");
//尾部行9
#endregion
ws = WsExcelCreateRow(ws, hssfworkbook, rowIndex + 10, rowIndex + 10, style, 0, 12, 3, true);
rowIndex += 11;
}
}
}
ws.SetMargin(MarginType.LeftMargin, 0.3);
ws.SetMargin(MarginType.RightMargin, 0.2);
ws.SetMargin(MarginType.BottomMargin, 0.4);
if (detectionTypeCode.Trim() == "PMI")
{
ws.PrintSetup.Landscape = true;
}
//ws.PrintSetup.Landscape = true;
ws.PrintSetup.PaperSize = 9;
ws.ForceFormulaRecalculation = true;
using (FileStream filess = System.IO.File.OpenWrite(ReportFileName))
{
hssfworkbook.Write(filess);
}
FileInfo filet = new FileInfo(ReportFileName);
Response.Clear();
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;
// 添加头信息,为"文件下载/另存为"对话框指定默认文件名
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(trustBatchCode+".xlsx"));
// 添加头信息,指定文件大小,让浏览器能够显示下载进度
Response.AddHeader("Content-Length", filet.Length.ToString());
// 指定返回的是一个不能被客户端读取的流,必须被下载
Response.ContentType = "application/ms-excel";
// 把文件流发送到客户端
Response.WriteFile(filet.FullName);
// 停止页面的执行
Response.End();
}
else
{
ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
}
}
#region
private void InsertImage(XSSFWorkbook hssfworkbook, XSSFSheet ws, int row1, int col1, int row2, int col2, string img, double w, double h, int dx1 = 0, int dy1 = 0, int dx2 = 0, int dy2 = 0)
{
int pictureIdx = hssfworkbook.AddPicture(System.IO.File.ReadAllBytes(img), PictureType.PNG);
IDrawing drawing = ws.CreateDrawingPatriarch();
IClientAnchor anchor = new XSSFClientAnchor(dx1 * XSSFShape.EMU_PER_PIXEL, dy1 * XSSFShape.EMU_PER_POINT, dx2 * XSSFShape.EMU_PER_PIXEL, dy2 * XSSFShape.EMU_PER_POINT, col1, row1, col2, row2);
IDrawing patriarch = ws.CreateDrawingPatriarch();
IPicture pict = (XSSFPicture)patriarch.CreatePicture(anchor, pictureIdx);
pict.Resize(w, h);
}
/// <summary>
/// 获取某一列的所有值
/// </summary>
/// <typeparam name="T">列数据类型</typeparam>
/// <param name="dtSource">数据表</param>
/// <param name="filedName">列名</param>
/// <returns></returns>
public static List<T> GetColumnValues<T>(DataTable dtSource, string filedName)
{
return (from r in dtSource.AsEnumerable() select r.Field<T>(filedName)).ToList<T>();
}
/// <summary>
/// 无损检测委托单行和列
/// </summary>
/// <returns></returns>
private XSSFSheet WsExcelCreateRow(XSSFSheet ws, XSSFWorkbook hssfworkbook, int sRows, int eRows, ICellStyle style, int cStart, int cEnd, int excelpart, bool isnobk = false)
{
for (int i = sRows; i <= eRows; i++)
{
ws.CreateRow(i);
if (excelpart==1)
{
ws.GetRow(i).HeightInPoints =
i == sRows ? 27.75f :
i == (sRows + 1) ? 25.5f :
i == (sRows + 2) ? 25.5f :
i == (sRows + 3) ? 25.5f :
i == (sRows + 4) ? 23.25f :
i == (sRows + 5) ? 23.25f :
i == (sRows + 6) ? 23.25f :
i == (sRows + 7) ? 23.25f :
i == (sRows + 8) ? 23.25f :
i == (sRows + 9) ? 23.25f :
i == (sRows + 10) ? 23.25f :
i == (sRows + 11) ? 23.25f :
i == (sRows + 12) ? 23.25f :
17f;
}
else if(excelpart == 2)
{
ws.GetRow(i).HeightInPoints = 25.5f;
}
else
{
ws.GetRow(i).HeightInPoints = 15.5f;
}
for (int j = cStart; j <= cEnd; j++)
{
ws.GetRow(i).CreateCell(j);
if (isnobk)
{
ws.GetRow(i).GetCell(j).CellStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.None, BorderStyle.None, BorderStyle.None, BorderStyle.None, VerticalAlignment.Center, HorizontalAlignment.Center, 10.5, true, false);
}
else
{
ws.GetRow(i).GetCell(j).CellStyle = style;
}
}
}
return ws;
}
/// <summary>
/// 材料及配件检测委托单行和列
/// </summary>
/// <returns></returns>
private XSSFSheet ClExcelCreateRow(XSSFSheet ws, XSSFWorkbook hssfworkbook, int sRows, int eRows, ICellStyle style, int cStart, int cEnd, bool istitle = false, bool isnobk = false)
{
for (int i = sRows; i <= eRows; i++)
{
ws.CreateRow(i);
if (istitle)
{
ws.GetRow(i).HeightInPoints =
i == sRows ? 27.75f :
i == (sRows + 1) ? 25f :
i == (sRows + 2) ? 21.75f :
i == (sRows + 3) ? 21.75f :
i == (sRows + 5) ? 28f :
14.75f;
}
else
{
ws.GetRow(i).HeightInPoints = 14.75f;
}
for (int j = cStart; j <= cEnd; j++)
{
ws.GetRow(i).CreateCell(j);
if (isnobk)
{
ws.GetRow(i).GetCell(j).CellStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.None, BorderStyle.None, BorderStyle.None, BorderStyle.None, VerticalAlignment.Center, HorizontalAlignment.Center, 10, true, false);
}
else
{
ws.GetRow(i).GetCell(j).CellStyle = style;
}
}
}
return ws;
}
/// <summary>
/// 查询指定条数分页
/// </summary>
/// <returns></returns>
public static DataTable GetPageToTable(DataTable dt, int StartNum, int EndNum)
{
//0页代表每页数据直接返回
if (EndNum == 0) return dt;
//数据源为空返回空DataTable
if (dt == null) return new DataTable();
DataTable newdt = dt.Copy();
newdt.Clear();//copy dt的框架
if (StartNum >= dt.Rows.Count)
return newdt;//源数据记录数小于等于要显示的记录直接返回dt
if (EndNum > dt.Rows.Count)
EndNum = dt.Rows.Count;
for (int i = StartNum; i <= EndNum - 1; i++)
{
DataRow newdr = newdt.NewRow();
DataRow dr = dt.Rows[i];
foreach (DataColumn column in dt.Columns)
{
newdr[column.ColumnName] = dr[column.ColumnName];
}
newdt.Rows.Add(newdr);
}
return newdt;
}
#endregion
#region
/// <summary>
/// 判断是否可以删除
/// </summary>
/// <returns></returns>
private bool judgementDelete(string id, bool isShow)
{
string content = string.Empty;
//if (BLL.HJGL_HotProessManageEditService.GetHotProessByJotId(id) > 0)
//{
// content = "热处理已经使用了该焊口,不能删除!";
//}
//if (BLL.Funs.DB.HJGL_CH_TrustItem.FirstOrDefault(x => x.TrustBatchItemId == id) != null)
//{
// content = "无损委托已经使用了该焊口,不能删除!";
//}
//if (BLL.Funs.DB.HJGL_CH_CheckItem.FirstOrDefault(x => x.TrustBatchItemId == id) != null)
//{
// content = "检测单已经使用了该焊口,不能删除!";
//}
if (string.IsNullOrEmpty(content))
{
return true;
}
else
{
if (isShow)
{
Alert.ShowInTop(content, MessageBoxIcon.Error);
}
return false;
}
}
#endregion
}
}