using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.IO;
//using NPOI.XSSF.UserModel;
using NPOI.HSSF.UserModel;
using BLL;
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);
// 如项目只有一个检测单位则默认
var ndeUnit = from x in Funs.DB.Project_Unit where x.ProjectId == CurrUser.LoginProjectId && x.UnitType.Contains(Const.UnitType_4) select x;
if (ndeUnit.Count() == 1)
{
drpNDEUnit.SelectedValue = ndeUnit.First().UnitId;
}
BindDayByYearMonth(this.txtTrustDateMonth.Text.Trim());
this.InitTreeMenu();//加载树
}
}
#region 加载树项目-月份
///
/// 加载树
///
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();
Model.HJGLDB db = Funs.DB;
var unitList = (from x in db.Project_WorkArea
where x.ProjectId == this.CurrUser.LoginProjectId
select x.UnitId).Distinct();
var units = from x in unitList
join y in db.Base_Unit on x equals y.UnitId
select new { UnitId = x, y.UnitName };
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)
{
}
else
{
units = units.Where(x => x.UnitId == 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, startTime, endTime);
}
}
else
{
Alert.ShowInTop(Resources.Lan.PleaseAddUnitFirst, MessageBoxIcon.Warning);
}
}
else
{
Alert.ShowInTop(Resources.Lan.PleaseSelectTrustMonth, MessageBoxIcon.Warning);
}
}
#endregion
#region 绑定树节点
///
/// 绑定树节点
///
///
private void BindNodes(TreeNode node, DateTime startTime, DateTime endTime)
{
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, startTime, endTime);
}
}
else if (node.ToolTip == "Installation")
{
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.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, startTime, endTime);
}
}
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")
// && x.ProjectId == this.CurrUser.LoginProjectId && x.TrustBatchCode.Contains(this.txtSearchCode.Text.Trim())
// && 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 (drpSelectDay.SelectedValue != Const._Null && !string.IsNullOrEmpty(drpSelectDay.SelectedValue))
//{
// trusts = from x in trusts
// where x.TrustDate >= Convert.ToDateTime(this.txtTrustDateMonth.Text.Trim() + "-" + drpSelectDay.SelectedValue)
// && x.TrustDate < Convert.ToDateTime(this.txtTrustDateMonth.Text.Trim() + "-" + drpSelectDay.SelectedValue).AddDays(1)
// orderby x.TrustBatchCode descending
// select x;
//}
//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 = "" + trust.TrustBatchCode + "";
// 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.TrustDate < Convert.ToDateTime(this.txtTrustDateMonth.Text.Trim() + "-01").AddMonths(1)
&& x.TrustDate >= Convert.ToDateTime(this.txtTrustDateMonth.Text.Trim() + "-01")
&& x.ProjectId == this.CurrUser.LoginProjectId && x.TrustBatchCode.Contains(this.txtSearchCode.Text.Trim())
&& 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 (drpSelectDay.SelectedValue != Const._Null && !string.IsNullOrEmpty(drpSelectDay.SelectedValue))
{
trusts = from x in trusts
where x.TrustDate >= Convert.ToDateTime(this.txtTrustDateMonth.Text.Trim() + "-" + drpSelectDay.SelectedValue)
&& x.TrustDate < Convert.ToDateTime(this.txtTrustDateMonth.Text.Trim() + "-" + drpSelectDay.SelectedValue).AddDays(1)
orderby x.TrustBatchCode descending
select x;
}
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 = "" + trust.TrustBatchCode + "";
newNode.ToolTip = "当天委托单";
}
else
{
newNode.Text = trust.TrustBatchCode;
newNode.ToolTip = "非当天委托单";
}
newNode.NodeID = trust.TrustBatchId;
newNode.EnableClickEvent = true;
e.Node.Nodes.Add(newNode);
}
}
}
private void BindDayByYearMonth(string yearMonth)
{
DateTime beginTime = DateTime.Parse(yearMonth + "-01");//本月初
DateTime endTime = DateTime.Parse(beginTime.AddMonths(1).AddDays(-1).ToShortDateString());//本月最后一天
List dateList = new List();
for (DateTime dt = beginTime; dt <= endTime; dt = dt.AddDays(1))
{
dateList.Add(dt.Day.ToString());
}
drpSelectDay.DataValueField = dateList.ToString();
drpSelectDay.DataTextField = dateList.ToString();
drpSelectDay.DataSource = dateList;
drpSelectDay.DataBind();
Funs.FineUIPleaseSelect(drpSelectDay, Resources.Lan.PleaseSelect);
}
#region 点击TreeView
///
/// 点击TreeView
///
///
///
protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e)
{
Model.View_Batch_BatchTrust trust = BLL.Batch_BatchTrustService.GetBatchTrustViewById(this.tvControlItem.SelectedNodeID);
if (trust != null)
{
string ndtType = trust.DetectionTypeId;
var s = BLL.Project_TestStandardService.GetProjectTestStandard(this.CurrUser.LoginProjectId, ndtType);
if (s != null && !string.IsNullOrEmpty(s.TestStandardNames))
{
var testS = s.TestStandardNames.Split(',');
ListItem[] list = new ListItem[testS.Length];
int i = 0;
foreach (string t in testS)
{
list[i] = new ListItem(t, t);
i++;
}
drpTestStandard.Items.Clear();
drpTestStandard.DataValueField = "Value";
drpTestStandard.DataTextField = "Text";
drpTestStandard.DataSource = list;
drpTestStandard.DataBind();
}
this.txtTrustBatchCode.Text = trust.TrustBatchCode;
if (trust.TrustDate != null)
{
this.txtTrustDate.Text = string.Format("{0:yyyy-MM-dd}", trust.TrustDate);
}
this.txtDetectionTypeCode.Text = trust.DetectionTypeCode;
if (trust.NDEUuit != null)
{
drpNDEUnit.SelectedValue = trust.NDEUuit;
}
else
{
var ndeUnit = from x in Funs.DB.Project_Unit where x.ProjectId == CurrUser.LoginProjectId && x.UnitType.Contains(Const.UnitType_4) select x;
if (ndeUnit.Count() == 1)
{
drpNDEUnit.SelectedValue = ndeUnit.First().UnitId;
BLL.Batch_BatchTrustService.BatchTrustNDEUnit(this.tvControlItem.SelectedNodeID, ndeUnit.First().UnitId);
}
}
if (trust.TestStandard != null)
{
string[] names = trust.TestStandard.Split(',');
drpTestStandard.SelectedValueArray = names;
}
else
{
if (s != null && !string.IsNullOrEmpty(s.TestStandardNames))
{
string[] testS = s.TestStandardNames.Split(',');
if (testS.Length == 1)
{
BLL.Batch_BatchTrustService.BatchTrustTestStandard(this.tvControlItem.SelectedNodeID, testS[0]);
}
}
}
}
this.BindGrid();
}
#endregion
#region 数据绑定
///
/// 数据绑定
///
private void BindGrid()
{
if (this.tvControlItem.SelectedNode != null)
{
string strSql = @"SELECT * FROM dbo.View_Batch_BatchTrustItem d WHERE TrustBatchId=@TrustBatchId ";
List listStr = new List
{
};
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 页索引改变事件
///
/// 页索引改变事件
///
///
///
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
BindGrid();
}
#endregion
#region 排序
///
/// 排序
///
///
///
protected void Grid1_Sort(object sender, GridSortEventArgs e)
{
BindGrid();
}
#endregion
#region 分页选择下拉改变事件
///
/// 分页选择下拉改变事件
///
///
///
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
BindGrid();
}
#endregion
#endregion
#region 关闭弹出窗口及刷新页面
///
/// 关闭弹出窗口
///
///
///
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
this.InitTreeMenu();//加载树
this.BindGrid();
}
protected void Window2_Close(object sender, WindowCloseEventArgs e)
{
this.BindGrid();
}
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_BatchTrustMenuId, Const.BtnCancelTrust))
{
string trustBatchItemId = Grid1.SelectedRowID;
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInParent("请至少选择一条记录!");
return;
}
PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("CancelTrust.aspx?trustBatchItemId={0}", trustBatchItemId, "编辑 - ")));
//var ndeItem = BLL.Batch_NDEItemService.GetNDEItemByTrustItemId(trustBatchItemId);
//if (ndeItem == null)
//{
// PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("CancelTrust.aspx?trustBatchItemId={0}", trustBatchItemId, "编辑 - ")));
//}
//else
//{
// Alert.ShowInParent("已检测,不能取消!");
// return;
//}
}
else
{
ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
return;
}
}
///
/// 查询
///
///
///
protected void TextBox_TextChanged(object sender, EventArgs e)
{
this.BindGrid();
}
///
/// 查询
///
///
///
protected void Tree_TextChanged(object sender, EventArgs e)
{
BindDayByYearMonth(this.txtTrustDateMonth.Text.Trim());
this.InitTreeMenu();
this.BindGrid();
}
protected void drpSelect_OnSelectedIndexChanged(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)
{
string trustBatchId = this.tvControlItem.SelectedNodeID;
if (drpNDEUnit.SelectedValue != null)
{
string ndtUnit = drpNDEUnit.SelectedValue;
BLL.Batch_BatchTrustService.BatchTrustNDEUnit(trustBatchId, ndtUnit);
}
if (drpTestStandard.SelectedValueArray.Length > 0)
{
string testStandard = string.Join(",", drpTestStandard.SelectedValueArray);
BLL.Batch_BatchTrustService.BatchTrustTestStandard(trustBatchId, testStandard);
}
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)
{
bool isAudit = false;
foreach (var n in t)
{
var ndt = BLL.Batch_NDEItemService.GetNDEItemByTrustItemId(n.TrustBatchItemId);
if (ndt != null && ndt.SubmitDate.HasValue)
{
isAudit = true;
break;
}
}
if (!isAudit)
{
// 修改点口单jexl明细的IsBuildTrust为False(null)
foreach (var p in t)
{
Model.Batch_PointBatchItem pitem = db.Batch_PointBatchItem.FirstOrDefault(x => x.PointBatchItemId == p.PointBatchItemId);
if (pitem != null)
{
if (pitem.TrustBatchCode != null && pitem.TrustBatchCode.Length > 2)
{
string r = pitem.TrustBatchCode.Substring(pitem.TrustBatchCode.Length - 2);
if (r.Contains("R"))
{
pitem.IsCheckRepair = true;
}
else
{
pitem.IsCheckRepair = false;
}
}
else
{
pitem.IsCheckRepair = false;
}
pitem.IsBuildTrust = null;
db.SubmitChanges();
}
}
// 修改点口单的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);
}
}
}
var check = from x in db.Batch_NDE where x.TrustBatchId == trustBatchId select x;
if (check.Count() > 0)
{
var ndeItem = from x in db.Batch_NDEItem where x.NDEID == check.First().NDEID select x;
db.Batch_NDEItem.DeleteAllOnSubmit(ndeItem);
db.Batch_NDE.DeleteOnSubmit(check.First());
db.SubmitChanges();
}
db.Batch_BatchTrustItem.DeleteAllOnSubmit(t);
db.SubmitChanges();
BLL.Batch_BatchTrustService.DeleteBatchTrustById(trustBatchId);
ShowNotify(Resources.Lan.DeletedSuccessfully, MessageBoxIcon.Success);
}
else
{
ShowNotify("不能删除,请先取消检测单审核再删除!", MessageBoxIcon.Warning);
return;
}
}
else
{
BLL.Batch_BatchTrustService.DeleteBatchTrustById(trustBatchId);
ShowNotify(Resources.Lan.DeletedSuccessfully, MessageBoxIcon.Success);
}
}
}
else
{
ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
return;
}
}
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 trustBatchId = this.tvControlItem.SelectedNodeID;
Model.View_Batch_BatchTrust trust = BLL.Batch_BatchTrustService.GetBatchTrustViewById(trustBatchId);
if (trust != null)
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("../../Report/ReportPrint.aspx?report=1&trustBatchId={0}&parm={1}", trustBatchId, "编辑 - ")));
}
}
}
else
{
ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
return;
}
}
protected void btnExport_Click(object sender, EventArgs e)
{
string rootPath = Server.MapPath("~/") + Const.ExcelUrl;
//模板文件
string TempletFileName = rootPath + "BatchTrust.xls";
//导出文件
string filePath = rootPath + DateTime.Now.ToString("yyyyMMddhhmmss") + "\\";
if (!Directory.Exists(filePath))
{
Directory.CreateDirectory(filePath);
}
string ReportFileName = filePath + "out.xls";
FileStream file = new FileStream(TempletFileName, FileMode.Open, FileAccess.Read);
HSSFWorkbook hssfworkbook = new HSSFWorkbook(file);
//XSSFWorkbook hssfworkbook = new XSSFWorkbook(file);
#region BatchTrust
HSSFSheet trustSheet = (HSSFSheet)hssfworkbook.GetSheet("Sheet1");
//XSSFFont trustFont = (XSSFFont)hssfworkbook.CreateFont(); //创建字体
//trustFont.FontName = "sans-serif";//字体
//trustFont.FontHeightInPoints = 8; //字体大小
string trustBatchId = this.tvControlItem.SelectedNodeID;
var trust = BLL.Batch_BatchTrustService.GetBatchTrustById(trustBatchId);
var ins = BLL.Project_WorkAreaService.GetProject_WorkAreaByWorkAreaId(trust.WorkAreaId);
string wbs = string.Empty;
if (ins != null)
{
wbs = ins.WorkAreaCode;
}
string trustCode = string.Empty;
string nde = string.Empty;
string trustDate = string.Empty;
string standard = string.Empty;
string isRt = string.Empty;
string ndeUnit = string.Empty;
string projectName = string.Empty;
if (trust != null)
{
trustCode = trust.TrustBatchCode;
trustDate = trust.TrustDate.HasValue ? string.Format("{0:yyyy-MM-dd}", trust.TrustDate) : "";
var n = BLL.Base_DetectionTypeService.GetDetectionTypeByDetectionTypeId(trust.DetectionTypeId);
if (n != null)
{
nde = n.DetectionTypeCode;
if (n.SysType == "光谱检测")
{
standard = "40-010-00-0-0-00-003,ASTM,SH3501,Q/SH 0706-2016";
}
else
{
standard = "NB/T47013-2015, ASME B31.3-2010, SH3517-2013";
}
if (n.SysType == "射线检测")
{
isRt = "AB";
}
}
var project = BLL.Base_ProjectService.GetProjectByProjectId(trust.ProjectId);
if (project != null)
{
var protype = BLL.Base_ProjectTypeService.GetProjectTypeByProjectTypeId(project.ProjectTypeId);
if (protype.ProjectTypeName == "大项目")
{
trustCode = "CTP-" + trustCode;
}
else
{
trustCode = "CTE-" + trustCode;
}
projectName = project.ProjectName;
}
var unit = BLL.Base_UnitService.GetUnit(trust.NDEUuit);
if (unit != null)
{
ndeUnit = unit.UnitCode;
}
if (trustSheet.GetRow(0).GetCell(13) == null)
{
trustSheet.GetRow(0).CreateCell(13);
}
trustSheet.GetRow(0).GetCell(13).SetCellValue(projectName);
if (trustSheet.GetRow(1).GetCell(11) == null)
{
trustSheet.GetRow(1).CreateCell(11);
}
trustSheet.GetRow(1).GetCell(11).SetCellValue(trustCode);
if (trustSheet.GetRow(2).GetCell(8) == null)
{
trustSheet.GetRow(2).CreateCell(8);
}
trustSheet.GetRow(2).GetCell(8).SetCellValue(ndeUnit);
if (trustSheet.GetRow(2).GetCell(14) == null)
{
trustSheet.GetRow(2).CreateCell(14);
}
trustSheet.GetRow(2).GetCell(14).SetCellValue(wbs);
if (trustSheet.GetRow(4).GetCell(3) == null)
{
trustSheet.GetRow(4).CreateCell(3);
}
trustSheet.GetRow(4).GetCell(3).SetCellValue(isRt);
if (trustSheet.GetRow(4).GetCell(8) == null)
{
trustSheet.GetRow(4).CreateCell(8);
}
trustSheet.GetRow(4).GetCell(8).SetCellValue(standard);
if (trustSheet.GetRow(6).GetCell(3) == null)
{
trustSheet.GetRow(6).CreateCell(3);
}
trustSheet.GetRow(6).GetCell(3).SetCellValue(nde);
if (trustSheet.GetRow(6).GetCell(8) == null)
{
trustSheet.GetRow(6).CreateCell(8);
}
trustSheet.GetRow(6).GetCell(8).SetCellValue(trustDate);
}
string strSql = @"SELECT ROW_NUMBER() OVER(ORDER BY PipelineCode,WeldJointCode) AS Number,
TrustBatchItemId, TrustBatchId, InstallationCode, WorkAreaCode,
PipelineCode, WeldJointCode,JointArea, MaterialCode, Size, Thickness,
WeldTypeCode, WelderCode, WeldingMethodCode, DetectionRateCode,
AcceptLevel, Sheet
FROM dbo.View_Batch_BatchTrustItem WHERE TrustBatchId=@TrustBatchId";
List parms = new List();
parms.Add(new SqlParameter("@TrustBatchId", trustBatchId));
SqlParameter[] parameter = parms.ToArray();
DataTable dt = BLL.SQLHelper.GetDataTableRunText(strSql, parameter);
if (dt.Rows.Count > 0)
{
var rowIndex = 9;
foreach (DataRow dr in dt.Rows)
{
if (trustSheet.GetRow(rowIndex) == null) trustSheet.CreateRow(rowIndex);
#region 列赋值
if (trustSheet.GetRow(rowIndex).GetCell(0) == null) trustSheet.GetRow(rowIndex).CreateCell(0);
trustSheet.GetRow(rowIndex).GetCell(0).SetCellValue(dr["Number"].ToString());
//trustSheet.GetRow(rowIndex).GetCell(0).CellStyle.SetFont(trustFont);//将字体绑定到样式
if (trustSheet.GetRow(rowIndex).GetCell(1) == null) trustSheet.GetRow(rowIndex).CreateCell(1);
trustSheet.GetRow(rowIndex).GetCell(1).SetCellValue(dr["InstallationCode"].ToString());
if (trustSheet.GetRow(rowIndex).GetCell(2) == null) trustSheet.GetRow(rowIndex).CreateCell(2);
trustSheet.GetRow(rowIndex).GetCell(2).SetCellValue(dr["PipelineCode"].ToString());
if (trustSheet.GetRow(rowIndex).GetCell(4) == null) trustSheet.GetRow(rowIndex).CreateCell(4);
trustSheet.GetRow(rowIndex).GetCell(4).SetCellValue(dr["WeldJointCode"].ToString());
if (trustSheet.GetRow(rowIndex).GetCell(5) == null) trustSheet.GetRow(rowIndex).CreateCell(5);
trustSheet.GetRow(rowIndex).GetCell(5).SetCellValue(dr["JointArea"].ToString());
if (trustSheet.GetRow(rowIndex).GetCell(6) == null) trustSheet.GetRow(rowIndex).CreateCell(6);
trustSheet.GetRow(rowIndex).GetCell(6).SetCellValue(dr["MaterialCode"].ToString());
if (trustSheet.GetRow(rowIndex).GetCell(7) == null) trustSheet.GetRow(rowIndex).CreateCell(7);
trustSheet.GetRow(rowIndex).GetCell(7).SetCellValue(Convert.ToDouble(dr["Size"]).ToString());
if (trustSheet.GetRow(rowIndex).GetCell(8) == null) trustSheet.GetRow(rowIndex).CreateCell(8);
trustSheet.GetRow(rowIndex).GetCell(8).SetCellValue(Convert.ToDouble(dr["Thickness"]).ToString());
if (trustSheet.GetRow(rowIndex).GetCell(9) == null) trustSheet.GetRow(rowIndex).CreateCell(9);
trustSheet.GetRow(rowIndex).GetCell(9).SetCellValue(dr["WeldTypeCode"].ToString());
if (trustSheet.GetRow(rowIndex).GetCell(10) == null) trustSheet.GetRow(rowIndex).CreateCell(10);
trustSheet.GetRow(rowIndex).GetCell(10).SetCellValue(dr["WelderCode"].ToString());
if (trustSheet.GetRow(rowIndex).GetCell(12) == null) trustSheet.GetRow(rowIndex).CreateCell(12);
trustSheet.GetRow(rowIndex).GetCell(12).SetCellValue(dr["WeldingMethodCode"].ToString());
if (trustSheet.GetRow(rowIndex).GetCell(13) == null) trustSheet.GetRow(rowIndex).CreateCell(13);
trustSheet.GetRow(rowIndex).GetCell(13).SetCellValue(dr["DetectionRateCode"].ToString());
if (trustSheet.GetRow(rowIndex).GetCell(14) == null) trustSheet.GetRow(rowIndex).CreateCell(14);
trustSheet.GetRow(rowIndex).GetCell(14).SetCellValue(dr["AcceptLevel"].ToString());
if (trustSheet.GetRow(rowIndex).GetCell(16) == null) trustSheet.GetRow(rowIndex).CreateCell(16);
trustSheet.GetRow(rowIndex).GetCell(16).SetCellValue(dr["Sheet"].ToString());
#endregion
rowIndex++;
}
}
#endregion
trustSheet.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=" + trustCode + ".xls");
// 添加头信息,指定文件大小,让浏览器能够显示下载进度
Response.AddHeader("Content-Length", filet.Length.ToString());
// 指定返回的是一个不能被客户端读取的流,必须被下载
Response.ContentType = "application/ms-excel";
// 把文件流发送到客户端
Response.WriteFile(filet.FullName);
// 停止页面的执行
Response.End();
}
#region 判断是否可删除
///
/// 判断是否可以删除
///
///
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
}
}