using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using BLL;
using System.Text;
using NPOI.HSSF.Util;
using NPOI.SS.UserModel;
using NPOI.SS.Util;
using NPOI.XSSF.UserModel;
using System.IO;
using NPOI.OpenXmlFormats.Wordprocessing;
namespace FineUIPro.Web.WeldingProcess.WeldingManage
{
public partial class JointInfo : PageBase
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString();
this.InitTreeMenu();//加载树
//显示列
Model.Sys_UserShowColumns c = BLL.UserShowColumnsService.GetColumnsByUserId(this.CurrUser.UserId, "Joint");
if (c != null)
{
this.GetShowColumn(c.Columns);
}
}
}
protected void drpProjectId_SelectedIndexChanged(object sender, EventArgs e)
{
this.InitTreeMenu();
}
#region 加载树装置-单位-工作区
///
/// 加载树
///
private void InitTreeMenu()
{
this.tvControlItem.Nodes.Clear();
var totalInstallation = from x in Funs.DB.Project_Installation select x;
var totalWorkArea = from x in Funs.DB.Project_WorkArea select x;
var totalUnit = from x in Funs.DB.Project_Unit select x;
var totalPipeline = from x in Funs.DB.Pipeline_Pipeline select x;
////装置
var pInstallation = (from x in totalInstallation where x.ProjectId == this.CurrUser.LoginProjectId select x).ToList();
////区域
var pWorkArea = (from x in totalWorkArea where x.ProjectId == this.CurrUser.LoginProjectId select x).ToList();
////单位
var pUnits = (from x in totalUnit where x.ProjectId == this.CurrUser.LoginProjectId select x).ToList();
var workAreaIdList = (from x in totalPipeline
where x.ProjectId == this.CurrUser.LoginProjectId && x.PipelineCode.Contains(this.txtPipelineCode.Text.Trim())
orderby x.PipelineCode
select x.WorkAreaId).Distinct().ToList();
pWorkArea = pWorkArea.Where(x => workAreaIdList.Contains(x.WorkAreaId)).OrderBy(x => x.WorkAreaCode).ToList();
pInstallation = (from x in pInstallation
join y in pWorkArea on x.InstallationId equals y.InstallationId
select x).Distinct().ToList();
pUnits = (from x in pUnits
join y in pWorkArea on x.UnitId equals y.UnitId
select x).Distinct().ToList();
this.BindNodes(null, pInstallation, pWorkArea, pUnits);
}
#endregion
#region 绑定树节点
#region 绑定树节点
///
/// 绑定树节点
///
///
private void BindNodes(TreeNode node, List pInstallation, List pWorkArea, List pUnits)
{
if (node == null)
{
List installations = pInstallation;
var pUnit = pUnits.FirstOrDefault(x => x.UnitId == this.CurrUser.UnitId);
//if (pUnit != null && !pUnit.UnitType.Contains(Const.UnitType_2) && !pUnit.UnitType.Contains(Const.UnitType_1))
if (pUnit != null && pUnit.UnitType.Contains(Const.UnitType_5))
{
installations = (from x in pInstallation
join y in pWorkArea on x.InstallationId equals y.InstallationId
where y.UnitId == this.CurrUser.UnitId
orderby x.InstallationId
select x).Distinct().ToList();
}
foreach (var q in installations)
{
TreeNode newNode = new TreeNode();
newNode.NodeID = q.InstallationId;
newNode.Text = q.InstallationName;
newNode.ToolTip = Resources.Lan.InstallationName;
newNode.Expanded = true;
this.tvControlItem.Nodes.Add(newNode);
this.BindNodes(newNode, pInstallation, pWorkArea, pUnits);
}
}
else if (node.ToolTip == Resources.Lan.InstallationName)
{
List units = null;
var pUnitDepth = pUnits.FirstOrDefault(x => x.UnitId == this.CurrUser.UnitId);
if (pUnitDepth == null || pUnitDepth.UnitType.Contains(Const.UnitType_2) || pUnitDepth.UnitType.Contains(Const.UnitType_1)
|| pUnitDepth.UnitType == BLL.Const.UnitType_3 || pUnitDepth.UnitType == BLL.Const.UnitType_4)
{
units = (from x in pUnits
join y in pWorkArea on x.UnitId equals y.UnitId
where y.InstallationId == node.NodeID && x.UnitType == Const.UnitType_5
select x).ToList();
}
else
{
units = (from x in pUnits
join y in pWorkArea on x.UnitId equals y.UnitId
where y.InstallationId == node.NodeID && x.UnitType == Const.UnitType_5 && x.UnitId == this.CurrUser.UnitId
select x).ToList();
}
units = units.OrderBy(x => x.InTime).Distinct().ToList();
foreach (var q in units)
{
var unit = BLL.Base_UnitService.GetUnit(q.UnitId);
if (unit != null)
{
TreeNode newNode = new TreeNode();
newNode.Text = unit.UnitName;
newNode.NodeID = q.UnitId + "|" + node.NodeID;
newNode.ToolTip = Resources.Lan.UnitName;
node.Nodes.Add(newNode);
this.BindNodes(newNode, pInstallation, pWorkArea, pUnits);
}
}
}
else if (node.ToolTip == Resources.Lan.UnitName)
{
var workAreas = (from x in pWorkArea
where x.InstallationId == node.ParentNode.NodeID && x.UnitId == node.NodeID.Split('|')[0]
select x);
workAreas = workAreas.OrderByDescending(x => x.WorkAreaCode);
var pipelines = from x in Funs.DB.Pipeline_Pipeline select x;
foreach (var q in workAreas)
{
int a = (from x in pipelines where x.ProjectId == this.CurrUser.LoginProjectId && x.UnitId == node.NodeID.Split('|')[0] && x.WorkAreaId == q.WorkAreaId select x).Count();
TreeNode newNode = new TreeNode();
newNode.Text = q.WorkAreaCode + "【" + a.ToString() + " " + Resources.Lan.Pipeline + "】";
newNode.NodeID = q.WorkAreaId;
newNode.EnableExpandEvent = true;
newNode.ToolTip = Resources.Lan.Area;
node.Nodes.Add(newNode);
this.BindNodes(newNode, pInstallation, pWorkArea, pUnits);
}
}
else if (node.ToolTip == Resources.Lan.Area)
{
TreeNode newNode = new TreeNode();
newNode.Text = Resources.Lan.Pipeline;
newNode.NodeID = Resources.Lan.Pipeline;
node.Nodes.Add(newNode);
}
}
#endregion
#region 树展开事件
///
/// 树展开事件
///
///
///
protected void tvControlItem_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
{
if (e.Node.ToolTip == Resources.Lan.Area)
{
e.Node.Nodes.Clear();
List pipeline = new List();
var pipelines = from x in Funs.DB.Pipeline_Pipeline select x;
pipeline = (from x in pipelines
where x.ProjectId == this.CurrUser.LoginProjectId && x.WorkAreaId == e.Node.NodeID
&& x.PipelineCode.Contains(this.txtPipelineCode.Text.Trim())
orderby x.PipelineCode
select x).ToList();
foreach (var item in pipeline)
{
var jotCount = (from x in Funs.DB.Pipeline_WeldJoint where x.PipelineId == item.PipelineId select x).Count();
TreeNode newNode = new TreeNode();
if (!String.IsNullOrEmpty(item.Sheet))
{
newNode.Text = item.PipelineCode + "(" + item.Sheet + ")";
}
else
{
newNode.Text = item.PipelineCode;
}
newNode.Text += "【" + jotCount.ToString() + " " + Resources.Lan.WeldingJoint + "】";
newNode.ToolTip = Resources.Lan.PipelinePage;
newNode.NodeID = item.PipelineId;
newNode.EnableClickEvent = true;
e.Node.Nodes.Add(newNode);
}
}
}
#endregion
#endregion
#region 点击TreeView
///
/// 点击TreeView
///
///
///
protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e)
{
this.BindGrid();
}
#endregion
#region 数据绑定
///
/// 数据绑定
///
private void BindGrid()
{
string strSql = @"SELECT WeldJointId,ProjectId,PipelineId,WeldJointCode,WPQCode,DetectionType,
convert(int,dbo.Fun_GetParseInt(WeldJointCode)) AS ConvertJointNo,
dbo.Fun_GetParseString(WeldJointCode) AS PreJotNo,Coode1,Coode2,
PipingClassCode,PipeSegment,JointAttribute,PageNum,
ComponentsCode1,ComponentsCode2,Is_hjName,IsHotProessStr,Material1Code,Material2Code,
WeldTypeCode,Specification,HeartNo1,HeartNo2,Size,Dia,Thickness,GrooveTypeCode,
WeldingMethodCode,WeldSilkId,WeldMatCode,WeldingDate,WeldingDailyCode,DoneDin,
BackingWelderCode,CoverWelderCode,SystemNumber,TestPackageNo,Remark,
(CASE WHEN IsCancel=1 THEN '是' ELSE '否' END) AS IsCancel
FROM View_Pipeline_WeldJoint WHERE 1= 1";
List listStr = new List
{
};
strSql += " AND PipelineId =@PipelineId";
listStr.Add(new SqlParameter("@PipelineId", this.tvControlItem.SelectedNodeID));
if (!string.IsNullOrEmpty(this.txtWeldJointCode.Text.Trim()))
{
strSql += " AND WeldJointCode LIKE @WeldJointCode";
listStr.Add(new SqlParameter("@WeldJointCode", "%" + this.txtWeldJointCode.Text.Trim() + "%"));
}
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
// 2.获取当前分页数据
Grid1.RecordCount = tb.Rows.Count;
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 焊口信息 维护事件
///
/// Grid双击事件
///
///
///
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
{
if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.HJGL_JointInfoMenuId, BLL.Const.BtnModify))
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("JointInfoEdit.aspx?WeldJointId={0}", Grid1.SelectedRowID, "编辑 - ")));
}
else
{
ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
}
}
///
/// 增加焊口信息
///
///
///
protected void btnNew_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_JointInfoMenuId, Const.BtnAdd))
{
var pipeline = BLL.Pipeline_PipelineService.GetPipelineByPipelineId(tvControlItem.SelectedNodeID);
if (pipeline != null)
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("JointInfoEdit.aspx?PipelineId={0}", this.tvControlItem.SelectedNodeID, "新增 - ")));
}
else
{
ShowNotify(Resources.Lan.PleaseSelectPipelinetFirst, MessageBoxIcon.Warning);
}
}
else
{
ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
}
}
///
/// 批量增加焊口信息
///
///
///
protected void btnBatchAdd_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_JointInfoMenuId, Const.BtnAdd))
{
var pipeline = BLL.Pipeline_PipelineService.GetPipelineByPipelineId(tvControlItem.SelectedNodeID);
if (pipeline != null)
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("JointInfoBatchEdit.aspx?PipelineId={0}", this.tvControlItem.SelectedNodeID, "新增 - ")));
}
else
{
ShowNotify(Resources.Lan.PleaseSelectPipelinetFirst, MessageBoxIcon.Warning);
}
}
else
{
ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
}
}
protected void btnUpdate_Click(object sender, EventArgs e)
{
var jotList = (from x in Funs.DB.Pipeline_WeldJoint select x).ToList();
foreach (var j in jotList)
{
decimal? size = j.Size;
string ansi = j.ANSISCH;
decimal? dia = j.Dia;
decimal? sch = j.Thickness;
string specification = j.Specification;
if (size != null && !string.IsNullOrEmpty(ansi))
{
var dn = from x in Funs.DB.Base_DNCompare where x.PipeSize == size select x;
if (dn.Count() > 0)
{
if (dn.First().OutSizeDia != null)
{
dia = dn.First().OutSizeDia;
}
if (ansi == "5")
{
if (dn.First().SCH5 != null)
{
sch = dn.First().SCH5;
}
}
if (ansi == "5S")
{
if (dn.First().SCH5S != null)
{
sch = dn.First().SCH5S;
}
}
if (ansi == "10")
{
if (dn.First().SCH10 != null)
{
sch = dn.First().SCH10;
}
}
if (ansi == "10S")
{
if (dn.First().SCH10S != null)
{
sch = dn.First().SCH10S;
}
}
if (ansi == "20")
{
if (dn.First().SCH20 != null)
{
sch = dn.First().SCH20;
}
}
if (ansi == "30")
{
if (dn.First().SCH30 != null)
{
sch = dn.First().SCH30;
}
}
if (ansi == "40")
{
if (dn.First().SCH40 != null)
{
sch = dn.First().SCH40;
}
}
if (ansi == "40S")
{
if (dn.First().SCH40S != null)
{
sch = dn.First().SCH40S;
}
}
if (ansi == "STD")
{
if (dn.First().STD != null)
{
sch = dn.First().STD;
}
}
if (ansi == "60")
{
if (dn.First().SCH60 != null)
{
sch = dn.First().SCH60;
}
}
if (ansi == "80")
{
if (dn.First().SCH80 != null)
{
sch = dn.First().SCH80;
}
}
if (ansi == "80S")
{
if (dn.First().SCH80S != null)
{
sch = dn.First().SCH80S;
}
}
if (ansi == "XS")
{
if (dn.First().XS != null)
{
sch = dn.First().XS;
}
}
if (ansi == "100")
{
if (dn.First().SCH100 != null)
{
sch = dn.First().SCH100;
}
}
if (ansi == "120")
{
if (dn.First().SCH120 != null)
{
sch = dn.First().SCH120;
}
}
if (ansi == "140")
{
if (dn.First().SCH140 != null)
{
sch = dn.First().SCH140;
}
}
if (ansi == "160")
{
if (dn.First().SCH160 != null)
{
sch = dn.First().SCH160;
}
}
if (ansi == "XXS")
{
if (dn.First().XXS != null)
{
sch = dn.First().XXS;
}
}
j.Dia = dia;
j.Thickness = sch;
j.Specification = "Φ" + dia + "×" + sch;
}
}
}
Funs.DB.SubmitChanges();
}
///
/// 焊口信息编辑
///
///
///
protected void btnMenuEdit_Click(object sender, EventArgs e)
{
if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.HJGL_JointInfoMenuId, BLL.Const.BtnModify))
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop(Resources.Lan.SelectLeastOneRecord, MessageBoxIcon.Warning);
return;
}
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("JointInfoEdit.aspx?WeldJointId={0}", Grid1.SelectedRowID, "维护 - ")));
}
else
{
ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
}
}
///
/// 删除按钮
///
///
///
protected void btnMenuDelete_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_JointInfoMenuId, Const.BtnDelete))
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop(Resources.Lan.SelectLeastOneRecord, MessageBoxIcon.Warning);
return;
}
bool isShow = true;
if (Grid1.SelectedRowIndexArray.Length > 1)
{
isShow = false;
}
string rowID = Grid1.DataKeys[Grid1.SelectedRowIndex][0].ToString();
var jot = BLL.Pipeline_WeldJointService.GetWeldJointByWeldJointId(rowID);
var isoInfo = BLL.Pipeline_PipelineService.GetPipelineByPipelineId(jot.PipelineId);
var rate = Funs.DB.Base_DetectionRate.FirstOrDefault(x => x.DetectionRateId == isoInfo.DetectionRateId);
if (judgementDelete(rowID, isShow))
{
BLL.Pipeline_WeldJointService.DeleteWeldJointById(rowID);
BLL.Sys_LogService.AddLog(BLL.Const.System_3, this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_JointInfoMenuId, Const.BtnDelete, rowID);
// 如固定口比例不足,则在固定口中随机补充缺的部分
// 已焊接数
int num = (from x in Funs.DB.Pipeline_WeldJoint
join y in Funs.DB.Base_WeldType on x.WeldTypeId equals y.WeldTypeId
where x.PipelineId == jot.PipelineId && y.Flag == "1"
&& (x.IsCancel == false || x.IsCancel == null)
&& (x.WeldingDailyId != null && x.WeldingDailyId != "")
select x).Count();
// 焊口总数
int totalNum = (from x in Funs.DB.Pipeline_WeldJoint
join y in Funs.DB.Base_WeldType on x.WeldTypeId equals y.WeldTypeId
where x.PipelineId == jot.PipelineId && y.Flag == "1"
&& (x.IsCancel == false || x.IsCancel == null)
select x).Count();
// 说明这条线已焊完,如固定口比例不足,则在固定口中随机补充缺的部分
if (num == totalNum)
{
// 固定口需要点口数
int needPointNum = Convert.ToInt32(Math.Ceiling(((double)(totalNum) * (double)(rate.DetectionRateValue) * 0.5) / 100.0));
// 固定口已点口数
int GdPointNum = (from x in Funs.DB.Pipeline_WeldJoint
join y in Funs.DB.Batch_PointBatchItem on x.WeldJointId equals y.WeldJointId
join z in Funs.DB.Batch_PointBatch on y.PointBatchId equals z.PointBatchId
join n in Funs.DB.Base_DetectionType on z.DetectionTypeId equals n.DetectionTypeId
where x.PipelineId == jot.PipelineId && x.WeldingDailyId != null && (x.IsCancel == false || x.IsCancel == null)
&& y.PointState == "1" && n.SysType == "射线检测" && x.JointAttribute == "固定F"
select y.PointBatchItemId).Count();
if (GdPointNum < needPointNum)
{
int d = needPointNum - GdPointNum;
// 没有点口的固定口
var GdNoPoint = from x in Funs.DB.Batch_PointBatchItem
join y in Funs.DB.Pipeline_WeldJoint on x.WeldJointId equals y.WeldJointId
join z in Funs.DB.Base_WeldType on y.WeldTypeId equals z.WeldTypeId
where y.PipelineId == jot.PipelineId && y.WeldingDailyId != null
&& (y.IsCancel == false || y.IsCancel == null)
&& x.PointState == null && z.Flag == "1" && y.JointAttribute == "固定F"
select x;
int gdMaxValue = GdNoPoint.Count();
if (gdMaxValue > 0)
{
string random = string.Empty;
int[] r = Funs.GetRandomNum(d, 1, gdMaxValue);
var q = from x in r orderby x select x;
foreach (int i in q)
{
if (i <= gdMaxValue)
{
random = random + i.ToString() + ",";
}
}
int j = 1;
foreach (var g in GdNoPoint)
{
if (random.Contains(j.ToString()))
{
BLL.Batch_PointBatchItemService.UpdatePointBatchItem(g.PointBatchItemId, "1", System.DateTime.Now, null);
}
j++;
}
}
}
}
ShowNotify(Resources.Lan.DeletedSuccessfully, MessageBoxIcon.Success);
this.BindGrid();
}
}
else
{
Alert.ShowInTop(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
}
}
protected void btnMenuDeleteAll_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_JointInfoMenuId, Const.BtnDeleteAll))
{
if (Grid1.SelectedRowIndexArray.Length == 1)
{
string rowID = Grid1.DataKeys[Grid1.SelectedRowIndex][0].ToString();
BLL.Batch_NDEItemService.DeleteWeldJointAllInfo(rowID);
ShowNotify(Resources.Lan.DeletedSuccessfully, MessageBoxIcon.Success);
BLL.Sys_LogService.AddLog(BLL.Const.System_3, this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_JointInfoMenuId, Const.BtnDeleteAll, rowID);
this.BindGrid();
}
else
{
Alert.ShowInTop(Resources.Lan.SelectLeastOneRecord, MessageBoxIcon.Warning);
return;
}
}
else
{
Alert.ShowInTop(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
}
}
protected void btnMenuCopy_Click(object sender, EventArgs e)
{
if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.HJGL_JointInfoMenuId, BLL.Const.BtnAdd))
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop(Resources.Lan.SelectLeastOneRecord, MessageBoxIcon.Warning);
return;
}
PageContext.RegisterStartupScript(Window8.GetShowReference(String.Format("JointInfoCopy.aspx?WeldJointId={0}", Grid1.SelectedRowID, "增口复制 - ")));
}
else
{
ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
}
}
#endregion
#region 报表打印
///
/// 报表打印
///
///
///
protected void btnPrint_Click(object sender, EventArgs e)
{
string pipelineId = this.tvControlItem.SelectedNodeID;
var q = BLL.Pipeline_PipelineService.GetPipelineByPipelineId(pipelineId);
if (q != null)
{
string varValue = string.Empty;
var project = BLL.Base_ProjectService.GetProjectByProjectId(this.CurrUser.LoginProjectId);
var ins = BLL.Project_InstallationService.GetProject_InstallationNameByInstallationId(q.InstallationId);
if (project != null)
{
varValue = "工程名称:" + project.ProjectName;
if (ins != null)
{
string insName = "单位工程名称:" + ins.ToString();
varValue = varValue + "|" + insName;
}
}
List listStr = new List();
listStr.Add(new SqlParameter("@IsoIds", pipelineId));
listStr.Add(new SqlParameter("@Flag", "0"));
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = BLL.SQLHelper.GetDataTableRunProc("HJGL_spJointWorkRecordNew", parameter);
string page = Funs.GetPagesCountByPageSize(11, 16, tb.Rows.Count).ToString();
varValue = varValue + "|" + page;
if (!string.IsNullOrEmpty(varValue))
{
varValue = HttpUtility.UrlEncodeUnicode(varValue);
}
if (tb.Rows.Count <= 11)
{
PageContext.RegisterStartupScript(Window6.GetShowReference(String.Format("../../Common/ReportPrint/ExReportPrint.aspx?ispop=1&reportId={0}&replaceParameter={1}&varValue={2}&projectId=0", BLL.Const.WeldingRecordReport1, pipelineId, varValue)));
}
else
{
PageContext.RegisterStartupScript(Window7.GetShowReference(String.Format("../../Common/ReportPrint/ExReportPrint.aspx?ispop=1&reportId={0}&replaceParameter={1}&varValue={2}&projectId=0", BLL.Const.WeldingRecordReport2, pipelineId, varValue)));
PageContext.RegisterStartupScript(Window6.GetShowReference(String.Format("../../Common/ReportPrint/ExReportPrint.aspx?ispop=1&reportId={0}&replaceParameter={1}&varValue={2}&projectId=0", BLL.Const.WeldingRecordReport1, pipelineId, varValue)));
}
}
else
{
ShowNotify(Resources.Lan.PleaseSelectPipeline, MessageBoxIcon.Warning);
return;
}
}
#endregion
#region 关闭弹出窗口及刷新页面
///
/// 关闭弹出窗口
///
///
///
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
this.InitTreeMenu();//加载树
this.BindGrid();
}
protected void Window8_Close(object sender, WindowCloseEventArgs e)
{
this.BindGrid();
}
///
/// 查询
///
///
///
protected void TextBox_TextChanged(object sender, EventArgs e)
{
this.BindGrid();
}
///
/// 查询
///
///
///
protected void Tree_TextChanged(object sender, EventArgs e)
{
this.InitTreeMenu();
this.BindGrid();
}
#endregion
#region 判断是否可删除
///
/// 判断是否可以删除
///
///
private bool judgementDelete(string id, bool isShow)
{
string content = string.Empty;
if (!string.IsNullOrEmpty(BLL.Pipeline_WeldJointService.GetWeldJointByWeldJointId(id).WeldingDailyId))
{
content = "该焊口已焊接,不能删除!";
}
if (BLL.Funs.DB.HotProess_TrustItem.FirstOrDefault(x => x.WeldJointId == id) != null)
{
content = "热处理已经使用了该焊口,不能删除!";
}
//if (BLL.Funs.DB.HJGL_CH_CheckItem.FirstOrDefault(x => x.WeldJointId == id) != null)
//{
// content = "检测单已经使用了该焊口,不能删除!";
//}
if (string.IsNullOrEmpty(content))
{
return true;
}
else
{
if (isShow)
{
Alert.ShowInTop(content, MessageBoxIcon.Error);
}
return false;
}
}
#endregion
#region 导出焊口信息
///
/// 导出焊口信息
///
///
///
protected void btnOut_Click(object sender, EventArgs e)
{
var iso = BLL.Pipeline_PipelineService.GetPipelineByPipelineId(this.tvControlItem.SelectedNodeID);
var workArea = BLL.Project_WorkAreaService.GetProject_WorkAreaByWorkAreaId(this.tvControlItem.SelectedNodeID);
if (iso != null)
{
PageContext.RegisterStartupScript(Window3.GetShowReference(String.Format("JointInfoOut.aspx?PipelineId={0}", this.tvControlItem.SelectedNodeID, "导出 - ")));
}
else if (workArea != null)
{
PageContext.RegisterStartupScript(Window3.GetShowReference(String.Format("JointInfoOut.aspx?WorkAreaId={0}", this.tvControlItem.SelectedNodeID, "导出 - ")));
}
else
{
Alert.ShowInTop(Resources.Lan.PleaseSelectPipelineOrArea, MessageBoxIcon.Warning);
}
}
///
/// 导出焊口初始信息
///
///
///
protected void btnOut2_Click(object sender, EventArgs e)
{
string rootPath = Server.MapPath("~/") + Const.ExcelUrl;
//导出文件
string filePath = rootPath + DateTime.Now.ToString("yyyyMMddhhmmss") + "\\";
if (!Directory.Exists(filePath))
{
Directory.CreateDirectory(filePath);
}
string ReportFileName = filePath + "管道焊接工作记录.xlsx";
string sqlStr = @"SELECT WeldSilkId,PipelineId,WorkAreaId,a.ProjectName,a.WeldJointCode,a.Specification,a.Material1Code,a.WeldingMethodCode,a.WeldingDate,a.WeldSilkCode,a.WeldMatCode,a.BackingWelderCode,a.CoverWelderCode,a.IsHotProess,(case a.IsHotProess when 1 then '是' else '否' end) as IsHotProessName,PrepareTemp,WeldingLocationCode FROM View_Pipeline_WeldJoint as a WHERE 1= 1 AND PipelineId =@PipelineId and Is_hjName='是' ";
List listStr = new List();
listStr.Add(new SqlParameter("@PipelineId", this.tvControlItem.SelectedNodeID));
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(sqlStr, parameter);
var titleQuery = from a in Funs.DB.Pipeline_Pipeline
join b in Funs.DB.Base_Project on a.ProjectId equals b.ProjectId
join c in Funs.DB.Base_Unit on a.UnitId equals c.UnitId
select new { a.PipelineId, a.PipelineCode, b.ProjectName, c.UnitName };
var titleModel = titleQuery.FirstOrDefault();
if (titleModel != null && tb.Rows.Count > 0)
{
int rowIndex = 0;
XSSFWorkbook hssfworkbook = new XSSFWorkbook();
XSSFSheet ws = (XSSFSheet)hssfworkbook.CreateSheet("管道焊接工作记录");
#region 列宽
ws.SetColumnWidth(0, 18 * 256);
ws.SetColumnWidth(1, 13 * 256);
ws.SetColumnWidth(2, 10 * 256);
ws.SetColumnWidth(3, 18 * 256);
ws.SetColumnWidth(4, 13 * 256);
ws.SetColumnWidth(5, 16 * 256);
ws.SetColumnWidth(6, 13 * 256);
ws.SetColumnWidth(7, 13 * 256);
ws.SetColumnWidth(8, 9 * 256);
ws.SetColumnWidth(9, 13 * 256);
ws.SetColumnWidth(10, 13 * 256);
ws.SetColumnWidth(11, 17 * 256);
ws.SetColumnWidth(12, 13 * 256);
#endregion
var style = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Center, 10, true, false);
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 = ExcelCreateRow(ws, hssfworkbook, rowIndex, rowIndex + 5, style, 0, 12, true);
//行0
CellRangeAddress region = new CellRangeAddress(rowIndex, rowIndex + 3, 0, 2);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex).GetCell(0).SetCellValue("SH/T 3503-J415-1");
region = new CellRangeAddress(rowIndex, rowIndex + 3, 3, 9);
ws.AddMergedRegion(region);
string titleStr = i == 1 ? "管道焊接工作记录\r\nPiping Welding Record" : "管道焊接工作记录(续)\r\nPiping Welding Record";
ws.GetRow(rowIndex).GetCell(3).SetCellValue(titleStr);
ws.GetRow(rowIndex).GetCell(3).CellStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Center, 16, true, true);
region = new CellRangeAddress(rowIndex, rowIndex, 10, 12);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex).GetCell(10).SetCellValue($"工程名称:{titleModel.ProjectName}");
ws.GetRow(rowIndex).GetCell(10).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, 10, 12);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 1).GetCell(10).SetCellValue("Project Name:");
ws.GetRow(rowIndex + 1).GetCell(10).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, 10, 12);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 2).GetCell(10).SetCellValue($"单位工程名称:{titleModel.UnitName}");
ws.GetRow(rowIndex + 2).GetCell(10).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, 10, 12);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 3).GetCell(10).SetCellValue("Unit Name:");
ws.GetRow(rowIndex + 3).GetCell(10).CellStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Justify, 10, true, false);
//行4行5
region = new CellRangeAddress(rowIndex + 4, rowIndex + 5, 0, 0);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 4).GetCell(0).SetCellValue("管道编号/单线号\r\nPiping No./Line No");
region = new CellRangeAddress(rowIndex + 4, rowIndex + 5, 1, 2);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 4).GetCell(1).SetCellValue("焊口编号\r\nWeld No.");
region = new CellRangeAddress(rowIndex + 4, rowIndex + 5, 3, 3);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 4).GetCell(3).SetCellValue("焊工代号\r\nWelder's Stamp No.");
region = new CellRangeAddress(rowIndex + 4, rowIndex + 5, 4, 4);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 4).GetCell(4).SetCellValue("规格mm\r\nSpecification\r\nmm");
region = new CellRangeAddress(rowIndex + 4, rowIndex + 5, 5, 5);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 4).GetCell(5).SetCellValue("材质\r\nMaterial");
region = new CellRangeAddress(rowIndex + 4, rowIndex + 5, 6, 6);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 4).GetCell(6).SetCellValue("焊接位置\r\nWelding\r\nPosition");
region = new CellRangeAddress(rowIndex + 4, rowIndex + 5, 7, 8);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 4).GetCell(7).SetCellValue("焊接方法\r\nWelding Process");
region = new CellRangeAddress(rowIndex + 4, rowIndex + 5, 9, 10);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 4).GetCell(9).SetCellValue("焊材牌号\r\nWelding Material Designation");
region = new CellRangeAddress(rowIndex + 4, rowIndex + 5, 11, 11);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 4).GetCell(11).SetCellValue("实际预热温度℃\r\nActual Preheating Temperature ℃");
region = new CellRangeAddress(rowIndex + 4, rowIndex + 5, 12, 12);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 4).GetCell(12).SetCellValue("焊接日期\r\nWelding Date");
#endregion
#region 表格
ws = ExcelCreateRow(ws, hssfworkbook, rowIndex + 6, rowIndex + 21, style, 0, 12);
var dataTit = rowIndex + 6;
var tIndex = 5 + 16;
var dStart = 0;
var dEnd = 0;
if (i == 1)
{
dStart = 0;
dEnd = 16;
}
else
{
dStart = i == 2 ? 16 : ((i - 2) * 16) + 16;
dEnd = ((i - 1) * 16) + 16;
}
//合并单元格
for (int hb = dataTit; hb <= rowIndex + tIndex; hb++)
{
region = new CellRangeAddress(hb, hb, 1, 2);
ws.AddMergedRegion(region);
region = new CellRangeAddress(hb, hb, 7, 8);
ws.AddMergedRegion(region);
region = new CellRangeAddress(hb, hb, 9, 10);
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(titleModel.PipelineCode);
//焊口编号
ws.GetRow(dataIndex).GetCell(1).SetCellValue(tb.Rows[i]["WeldJointCode"].ToString());
//焊工代号
List welderStr = new List();
if (!string.IsNullOrWhiteSpace(tb.Rows[i]["BackingWelderCode"].ToString()))
{
welderStr.Add(tb.Rows[i]["BackingWelderCode"].ToString());
}
if (!string.IsNullOrWhiteSpace(tb.Rows[i]["CoverWelderCode"].ToString()))
{
welderStr.Add(tb.Rows[i]["CoverWelderCode"].ToString());
}
if (welderStr.Count > 0) welderStr = welderStr.GroupBy(x => x).Select(x => x.Key).ToList();
ws.GetRow(dataIndex).GetCell(3).SetCellValue(string.Join("/", welderStr));
//规格mm
ws.GetRow(dataIndex).GetCell(4).SetCellValue(tb.Rows[i]["Specification"].ToString());
//材质
ws.GetRow(dataIndex).GetCell(5).SetCellValue(tb.Rows[i]["Material1Code"].ToString());
//焊接位置
ws.GetRow(dataIndex).GetCell(6).SetCellValue(tb.Rows[i]["WeldingLocationCode"].ToString());
//焊接方法
ws.GetRow(dataIndex).GetCell(7).SetCellValue(tb.Rows[i]["WeldingMethodCode"].ToString());
//焊材牌号
List silkMats = new List();
if (!string.IsNullOrWhiteSpace(tb.Rows[i]["WeldSilkCode"].ToString()))
{
silkMats.Add(tb.Rows[i]["WeldSilkCode"].ToString());
}
if (!string.IsNullOrWhiteSpace(tb.Rows[i]["WeldMatCode"].ToString()))
{
silkMats.Add(tb.Rows[i]["WeldMatCode"].ToString());
}
if (silkMats.Count > 0) silkMats = silkMats.GroupBy(x => x).Select(x => x.Key).ToList();
ws.GetRow(dataIndex).GetCell(9).SetCellValue(string.Join("/", silkMats));
//实际预热温度
ws.GetRow(dataIndex).GetCell(11).SetCellValue(tb.Rows[i]["PrepareTemp"].ToString());
//焊接日期
ws.GetRow(dataIndex).GetCell(12).SetCellValue(tb.Rows[i]["WeldingDate"].ToString());
}
rowIndex += tIndex;
#endregion
#region 尾部
ws = ExcelCreateRow(ws, hssfworkbook, rowIndex + 1, rowIndex + 7, style, 0, 12, false, true);
//合并单元格
for (int hb = rowIndex + 1; hb <= rowIndex + 7; hb++)
{
for (int c = 0; c <= 12; c++)
{
if (hb >= rowIndex + 1 && hb <= rowIndex + 6)
{
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 + 7)
{
ws.GetRow(hb).GetCell(c).CellStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.None, VerticalAlignment.Center, HorizontalAlignment.Left, 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, 12);
ws.AddMergedRegion(region);
}
//行1
ws.GetRow(rowIndex + 1).GetCell(0).SetCellValue("建设/监理单位");
ws.GetRow(rowIndex + 1).GetCell(4).SetCellValue("总承包单位\r\nGeneral Contractor");
ws.GetRow(rowIndex + 1).GetCell(9).SetCellValue("施工单位\r\nConstruction Contractor");
//行2
ws.GetRow(rowIndex + 2).GetCell(0).SetCellValue("专业工程师\r\nDiscipline Engineer:");
ws.GetRow(rowIndex + 2).GetCell(4).SetCellValue("专业工程师\r\nDiscipline Engineer:");
ws.GetRow(rowIndex + 2).GetCell(9).SetCellValue("记录人 :\r\nRecord Prepared by:");
//行3
ws.GetRow(rowIndex + 4).GetCell(9).SetCellValue("质量检查员:\r\nQuality Inspector:");
//行5
ws.GetRow(rowIndex + 6).GetCell(9).SetCellValue("焊接责任工程师:\r\nWelding Engineer:");
//行6
ws.GetRow(rowIndex + 7).GetCell(0).SetCellValue("日期Date: 年 月 日");
ws.GetRow(rowIndex + 7).GetCell(4).SetCellValue("日期Date: 年 月 日");
ws.GetRow(rowIndex + 7).GetCell(9).SetCellValue("日期Date: 年 月 日");
#endregion
ws = ExcelCreateRow(ws, hssfworkbook, rowIndex + 8, rowIndex + 8, style, 0, 12, false, false, true);
rowIndex += 9;
}
ws.SetMargin(MarginType.LeftMargin, 0.3);
ws.SetMargin(MarginType.RightMargin, 0.2);
ws.PrintSetup.Landscape = true;
ws.PrintSetup.Scale = 75;
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("管道焊接工作记录.xlsx"));
// 添加头信息,指定文件大小,让浏览器能够显示下载进度
Response.AddHeader("Content-Length", filet.Length.ToString());
// 指定返回的是一个不能被客户端读取的流,必须被下载
Response.ContentType = "application/ms-excel";
// 把文件流发送到客户端
Response.WriteFile(filet.FullName);
// 停止页面的执行
Response.End();
}
else
{
Alert.ShowInTop("无数据!", MessageBoxIcon.Warning);
}
}
///
/// 导出方法
///
///
///
private string GetGridTableHtml(Grid grid)
{
StringBuilder sb = new StringBuilder();
sb.Append("");
sb.Append("");
sb.Append("");
foreach (GridColumn column in grid.Columns)
{
if (column.HeaderText != Resources.Lan.SerialNumber)
{
sb.AppendFormat("{0} | ", column.HeaderText);
}
}
sb.Append("
");
foreach (GridRow row in grid.Rows)
{
sb.Append("");
foreach (GridColumn column in grid.Columns)
{
string html = row.Values[column.ColumnIndex].ToString();
if (column.ColumnID != "tfNumber")
{
//html = (row.FindControl("lblNumber") as AspNet.Label).Text;
sb.AppendFormat("{0} | ", html);
}
//sb.AppendFormat("{0} | ", html);
}
sb.Append("
");
}
sb.Append("
");
return sb.ToString();
}
#endregion
#region 选择要显示列
///
/// 选择显示列
///
///
///
protected void btnSelectColumn_Click(object sender, EventArgs e)
{
PageContext.RegisterStartupScript(Window4.GetShowReference(String.Format("JointShowColumn.aspx", "显示列 - ")));
}
#endregion
#region 格式化字符串
///
/// 转换探伤类型
///
///
///
protected string ConvertDetectionType(object detectionType)
{
string detectionTypeName = string.Empty;
if (detectionType != null)
{
string[] ndtList = detectionType.ToString().Split('|');
foreach (string r in ndtList)
{
var q = BLL.Base_DetectionTypeService.GetDetectionTypeByDetectionTypeId(r);
if (q != null)
{
detectionTypeName = detectionTypeName + q.DetectionTypeCode + ",";
}
}
}
if (detectionTypeName.Length > 0)
{
detectionTypeName = detectionTypeName.Substring(0, detectionTypeName.Length - 1);
}
return detectionTypeName;
}
protected string ConvertWeldSilkCode(object WeldSilkId)
{
string weldSilkCode = string.Empty;
if (WeldSilkId != null)
{
weldSilkCode = BLL.Pipeline_WeldingDailyService.GetWeldSilkCode(WeldSilkId.ToString());
}
return weldSilkCode;
}
#endregion
#region 显示列
protected void Window4_Close(object sender, WindowCloseEventArgs e)
{
this.BindGrid();
//显示列
Model.Sys_UserShowColumns c = BLL.UserShowColumnsService.GetColumnsByUserId(this.CurrUser.UserId, "Joint");
if (c != null)
{
this.GetShowColumn(c.Columns);
}
}
///
/// 显示的列
///
///
private void GetShowColumn(string column)
{
if (!string.IsNullOrEmpty(column))
{
this.Grid1.Columns[1].Hidden = true;
this.Grid1.Columns[2].Hidden = true;
this.Grid1.Columns[3].Hidden = true;
this.Grid1.Columns[4].Hidden = true;
this.Grid1.Columns[5].Hidden = true;
this.Grid1.Columns[6].Hidden = true;
this.Grid1.Columns[7].Hidden = true;
this.Grid1.Columns[8].Hidden = true;
this.Grid1.Columns[9].Hidden = true;
this.Grid1.Columns[10].Hidden = true;
this.Grid1.Columns[11].Hidden = true;
this.Grid1.Columns[12].Hidden = true;
this.Grid1.Columns[13].Hidden = true;
this.Grid1.Columns[14].Hidden = true;
this.Grid1.Columns[15].Hidden = true;
this.Grid1.Columns[16].Hidden = true;
this.Grid1.Columns[17].Hidden = true;
this.Grid1.Columns[18].Hidden = true;
this.Grid1.Columns[19].Hidden = true;
this.Grid1.Columns[20].Hidden = true;
this.Grid1.Columns[21].Hidden = true;
this.Grid1.Columns[22].Hidden = true;
this.Grid1.Columns[23].Hidden = true;
this.Grid1.Columns[24].Hidden = true;
this.Grid1.Columns[25].Hidden = true;
this.Grid1.Columns[26].Hidden = true;
this.Grid1.Columns[27].Hidden = true;
this.Grid1.Columns[28].Hidden = true;
this.Grid1.Columns[29].Hidden = true;
this.Grid1.Columns[30].Hidden = true;
this.Grid1.Columns[31].Hidden = true;
this.Grid1.Columns[32].Hidden = true;
this.Grid1.Columns[33].Hidden = true;
this.Grid1.Columns[34].Hidden = true;
List columns = column.Split(',').ToList();
foreach (var item in columns)
{
if (!string.IsNullOrEmpty(item))
{
this.Grid1.Columns[Convert.ToInt32(item)].Hidden = false;
}
}
}
}
#endregion
#region 私有方法
///
/// 获取某一列的所有值
///
/// 列数据类型
/// 数据表
/// 列名
///
public static List GetColumnValues(DataTable dtSource, string filedName)
{
return (from r in dtSource.AsEnumerable() select r.Field(filedName)).ToList();
}
///
/// 创建列
///
///
private XSSFSheet ExcelCreateRow(XSSFSheet ws, XSSFWorkbook hssfworkbook, int sRows, int eRows, ICellStyle style, int cStart, int cEnd, bool istitle = false, bool isend = false, bool isnobk = false)
{
for (int i = sRows; i <= eRows; i++)
{
ws.CreateRow(i);
if (istitle)
{
ws.GetRow(i).HeightInPoints =
i <= (sRows + 5) ? 25f :
19.95f;
}
else
{
if (isnobk)
{
ws.GetRow(i).HeightInPoints = 16f;
}
else
{
ws.GetRow(i).HeightInPoints = isend ? 25f : 19.95f;
}
}
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;
}
///
/// 查询指定条数分页
///
///
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
}
}