631 lines
		
	
	
		
			30 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			631 lines
		
	
	
		
			30 KiB
		
	
	
	
		
			C#
		
	
	
	
using BLL;
 | 
						||
using NPOI.XSSF.UserModel;
 | 
						||
using NPOI.SS.UserModel;
 | 
						||
 | 
						||
using System;
 | 
						||
using System.Collections.Generic;
 | 
						||
using System.Data;
 | 
						||
using System.Data.SqlClient;
 | 
						||
using System.IO;
 | 
						||
using System.Linq;
 | 
						||
using Newtonsoft.Json.Linq;
 | 
						||
using BorderStyle = NPOI.SS.UserModel.BorderStyle;
 | 
						||
 | 
						||
 | 
						||
 | 
						||
namespace FineUIPro.Web.WeldingProcess.WeldingReport
 | 
						||
{
 | 
						||
    public partial class WeldDailyExport : PageBase
 | 
						||
    {
 | 
						||
        #region 加载
 | 
						||
        /// <summary>
 | 
						||
        /// 加载页面
 | 
						||
        /// </summary>
 | 
						||
        /// <param name="sender"></param>
 | 
						||
        /// <param name="e"></param>
 | 
						||
        protected void Page_Load(object sender, EventArgs e)
 | 
						||
        {
 | 
						||
            if (!IsPostBack)
 | 
						||
            {
 | 
						||
                this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString();
 | 
						||
                BLL.Project_InstallationService.InitInstallationDropDownList(drpInstallation, true, CurrUser.LoginProjectId, Resources.Lan.PleaseSelect);
 | 
						||
                BLL.Base_UnitService.InitProjectUnitDropDownList(this.drpUnit, true, CurrUser.LoginProjectId, Const.UnitType_5, Resources.Lan.PleaseSelect);
 | 
						||
                Funs.FineUIPleaseSelect(drpWorkAreaId, Resources.Lan.PleaseSelect);
 | 
						||
                var teamGroup = BLL.Welder_TeamGroupService.GetAllTeamGroupList(CurrUser.LoginProjectId, "");
 | 
						||
                drpTeamGroup.DataValueField = "Value";
 | 
						||
                drpTeamGroup.DataTextField = "Text";
 | 
						||
                drpTeamGroup.DataSource = teamGroup;
 | 
						||
                drpTeamGroup.DataBind();
 | 
						||
                Funs.FineUIPleaseSelect(drpTeamGroup, "");
 | 
						||
            }
 | 
						||
        }
 | 
						||
 | 
						||
        /// <summary>
 | 
						||
        /// 数据表
 | 
						||
        /// </summary>
 | 
						||
        private DataTable GetDataTable()
 | 
						||
        {
 | 
						||
            string strSql = @"SELECT weldJoint.WeldJointId,weldJoint.ProjectId,ins.InstallationCode,unit.UnitName,pipeline.PipelineCode,
 | 
						||
                                    (CASE WHEN weldJoint.PageNum IS NOT NULL AND weldJoint.PageNum<>'' THEN pipeline.SingleNumber+'-'+weldJoint.PageNum ELSE  pipeline.SingleNumber END) AS SingleNumber,
 | 
						||
                                     pipeline.DrawingsNum,CONVERT(NVARCHAR(10),weldingDaily.WeldingDate,120) AS WeldingDate,rate.DetectionRateCode,weldJoint.WeldJointCode,
 | 
						||
	                                CAST(ISNULL(weldJoint.Size,0) AS REAL) AS Size,(CAST(ISNULL(weldJoint.Thickness,0) AS REAL)) AS Thickness,weldJoint.Specification,
 | 
						||
									 weldType.WeldTypeCode,com1.ComponentsCode AS ComponentsName1,mat1.MaterialCode AS MaterialCode1,weldJoint.HeartNo1,
 | 
						||
									 com2.ComponentsCode AS ComponentsName2,mat2.MaterialCode AS MaterialCode2,weldJoint.HeartNo2, WeldMethod.WeldingMethodName,
 | 
						||
	                                (CASE WHEN weldJoint.CoverWelderId!=weldJoint.BackingWelderId THEN cw.WelderCode+'/'+fw.WelderCode ELSE cw.WelderCode END) AS WelderCode ,
 | 
						||
	                                (CASE WHEN weldJoint.WeldMatId IS NOT NULL AND weldJoint.WeldSilkId IS NOT NULL THEN weldJoint.WeldSilkId+'|'+ weldJoint.WeldMatId
 | 
						||
									      WHEN weldJoint.WeldMatId IS NOT NULL AND weldJoint.WeldSilkId IS NULL THEN weldJoint.WeldMatId
 | 
						||
										  WHEN weldJoint.WeldSilkId IS NOT NULL AND weldJoint.WeldMatId IS NULL THEN weldJoint.WeldSilkId
 | 
						||
										  ELSE '' END) AS WeldMaterial, wl.WeldingLocationCode,weldJoint.Remark
 | 
						||
                               FROM Pipeline_WeldJoint AS weldJoint
 | 
						||
	                           LEFT JOIN Pipeline_Pipeline AS pipeline ON pipeline.PipelineId = weldJoint.PipelineId	
 | 
						||
	                           LEFT JOIN dbo.Project_Installation ins ON ins.InstallationId = pipeline.InstallationId
 | 
						||
							   LEFT JOIN dbo.Base_Unit unit ON unit.UnitId = pipeline.UnitId
 | 
						||
							   LEFT JOIN dbo.Base_Components com1 ON com1.ComponentsId =weldJoint.PipeAssembly1Id
 | 
						||
	                           LEFT JOIN Base_Material AS mat1 ON mat1.MaterialId = weldJoint.Material1Id
 | 
						||
							   LEFT JOIN dbo.Base_WeldingLocation wl ON wl.WeldingLocationId = weldJoint.WeldingLocationId
 | 
						||
							   LEFT JOIN dbo.Base_Components com2 ON com2.ComponentsId =weldJoint.PipeAssembly2Id
 | 
						||
	                           LEFT JOIN Base_Material AS mat2 ON mat2.MaterialId = weldJoint.Material2Id
 | 
						||
	                           LEFT JOIN Base_WeldingMethod AS WeldMethod ON WeldMethod.WeldingMethodId = weldJoint.WeldingMethodId	
 | 
						||
							   LEFT JOIN dbo.Base_WeldType weldType ON weldType.WeldTypeId = weldJoint.WeldTypeId
 | 
						||
	                           LEFT JOIN Pipeline_WeldingDaily AS weldingDaily ON weldingDaily.WeldingDailyId = weldJoint.WeldingDailyId
 | 
						||
	                           left join Welder_Welder AS fw on weldJoint.BackingWelderId = fw.WelderId
 | 
						||
	                           left join Welder_Welder AS cw on weldJoint.CoverWelderId = cw.WelderId
 | 
						||
	                           LEFT JOIN dbo.Base_DetectionRate rate ON rate.DetectionRateId = pipeline.DetectionRateId
 | 
						||
	                           LEFT JOIN dbo.Welder_ProjectWelder pcw ON pcw.WelderId = weldJoint.CoverWelderId AND pcw.ProjectId=weldJoint.ProjectId
 | 
						||
							   LEFT JOIN dbo.Welder_ProjectWelder pfw ON pfw.WelderId = weldJoint.BackingWelderId AND pfw.ProjectId=weldJoint.ProjectId
 | 
						||
                               WHERE weldJoint.WeldingDailyId IS NOT NULL AND weldJoint.ProjectId=@projectId";
 | 
						||
 | 
						||
            List<SqlParameter> listStr = new List<SqlParameter>();
 | 
						||
            listStr.Add(new SqlParameter("@projectId", this.CurrUser.LoginProjectId));
 | 
						||
 | 
						||
            if (drpInstallation.SelectedValue != Const._Null)
 | 
						||
            {
 | 
						||
                strSql += " AND pipeline.InstallationId = @InstallationId";
 | 
						||
                listStr.Add(new SqlParameter("@InstallationId", this.drpInstallation.SelectedValue));
 | 
						||
                //string[] pipeList = drpPipeLine.SelectedValueArray;
 | 
						||
                //string pipeLineIds = string.Join(",", pipeList);
 | 
						||
                //listStr.Add(new SqlParameter("@pipelineIds", pipeLineIds));
 | 
						||
            }
 | 
						||
            //else
 | 
						||
            //{
 | 
						||
            //    listStr.Add(new SqlParameter("@pipelineIds", null));
 | 
						||
            //}
 | 
						||
            if (this.drpWorkAreaId.SelectedValue != Const._Null && this.drpWorkAreaId.SelectedValue != null)
 | 
						||
            {
 | 
						||
                strSql += " AND pipeline.WorkAreaId = @WorkAreaId";
 | 
						||
                listStr.Add(new SqlParameter("@WorkAreaId", drpWorkAreaId.SelectedValue));
 | 
						||
            }
 | 
						||
            if (this.drpUnit.SelectedValue != Const._Null)
 | 
						||
            {
 | 
						||
                strSql += " AND pipeline.UnitId = @UnitId";
 | 
						||
                listStr.Add(new SqlParameter("@UnitId", drpUnit.SelectedValue));
 | 
						||
            }
 | 
						||
            if (this.drpTeamGroup.SelectedValueArray.Length>0)
 | 
						||
            {
 | 
						||
                string[] teamGroupList = drpTeamGroup.SelectedValueArray;
 | 
						||
                string teamGroups = string.Join(",", teamGroupList);
 | 
						||
                strSql += " AND (CHARINDEX(pcw.TeamGroupId,@TeamGroupId)>0 OR CHARINDEX(pfw.TeamGroupId,@TeamGroupId)>0) ";
 | 
						||
                listStr.Add(new SqlParameter("@TeamGroupId", teamGroups));
 | 
						||
            }
 | 
						||
            if (txtStarTime.Text != "")
 | 
						||
            {
 | 
						||
                strSql += " AND weldingDaily.WeldingDate> = @WeldingStartDate";
 | 
						||
                listStr.Add(new SqlParameter("@WeldingStartDate", txtStarTime.Text.Trim()));
 | 
						||
            }
 | 
						||
            if (txtEndTime.Text != "")
 | 
						||
            {
 | 
						||
                strSql += " AND weldingDaily.WeldingDate< = @WeldingEndDate";
 | 
						||
                listStr.Add(new SqlParameter("@WeldingEndDate", txtEndTime.Text.Trim()));
 | 
						||
            }
 | 
						||
 | 
						||
            strSql += " ORDER BY pipeline.PipelineCode,WeldJointCode";
 | 
						||
            SqlParameter[] parameter = listStr.ToArray();
 | 
						||
            DataTable dt = SQLHelper.GetDataTableRunText(strSql, parameter);
 | 
						||
            return dt;
 | 
						||
        }
 | 
						||
 | 
						||
        /// <summary>
 | 
						||
        /// 绑定数据
 | 
						||
        /// </summary>
 | 
						||
        private void BindGrid()
 | 
						||
        {
 | 
						||
            DataTable tb = GetDataTable();
 | 
						||
            this.Grid1.RecordCount = tb.Rows.Count;
 | 
						||
            var table = this.GetPagedDataTable(Grid1, tb);
 | 
						||
            Grid1.DataSource = table;
 | 
						||
            Grid1.DataBind();
 | 
						||
 | 
						||
            if (tb.Rows.Count > 0)
 | 
						||
            {
 | 
						||
                // 合计
 | 
						||
                var distinctPipelineCode = tb.AsEnumerable().GroupBy(row => row.Field<string>("PipelineCode")).Select(group => group.First());
 | 
						||
                var distinctWelder = tb.AsEnumerable().GroupBy(row => row.Field<string>("WelderCode")).Select(group => group.First());
 | 
						||
                decimal sumSize = decimal.Parse(tb.Compute("sum(Size)", "").ToString());
 | 
						||
                string weldingDate = string.Empty;
 | 
						||
                if (txtStarTime.Text == txtEndTime.Text)
 | 
						||
                {
 | 
						||
                    weldingDate = txtStarTime.Text;
 | 
						||
                }
 | 
						||
                else
 | 
						||
                {
 | 
						||
                    weldingDate = txtStarTime.Text + "-" + txtEndTime.Text;
 | 
						||
                }
 | 
						||
                JObject summary = new JObject();
 | 
						||
                summary.Add("tfNumber", "合计");
 | 
						||
                summary.Add("SingleNumber", distinctPipelineCode.Count().ToString());
 | 
						||
                summary.Add("WeldJointCode", tb.Rows.Count);
 | 
						||
                summary.Add("Size", sumSize);
 | 
						||
                summary.Add("WelderCode", distinctWelder.Count().ToString());
 | 
						||
                summary.Add("WeldingDate", weldingDate);
 | 
						||
 | 
						||
                Grid1.SummaryData = summary;
 | 
						||
            }
 | 
						||
        }
 | 
						||
 | 
						||
        protected void drpInstallation_OnSelectedIndexChanged(object sender, EventArgs e)
 | 
						||
        {
 | 
						||
            drpWorkAreaId.Items.Clear();
 | 
						||
            string ins = drpInstallation.SelectedValue;
 | 
						||
            if (!string.IsNullOrEmpty(ins))
 | 
						||
            {
 | 
						||
                BLL.Project_WorkAreaService.InitWorkAreaDropDownList(this.drpWorkAreaId, true, this.CurrUser.LoginProjectId, ins, string.Empty, string.Empty, Resources.Lan.PleaseSelect);//区域
 | 
						||
                //BLL.Pipeline_PipelineService.InitPipelineDropDownList(drpPipeLine, workAreaId);
 | 
						||
            }
 | 
						||
        }
 | 
						||
 | 
						||
        /// <summary>
 | 
						||
        /// 改变索引事件
 | 
						||
        /// </summary>
 | 
						||
        /// <param name="sender"></param>
 | 
						||
        /// <param name="e"></param>
 | 
						||
        protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
 | 
						||
        {
 | 
						||
            BindGrid();
 | 
						||
        }
 | 
						||
 | 
						||
        /// <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();
 | 
						||
        }
 | 
						||
 | 
						||
        /// <summary>
 | 
						||
        /// 排序
 | 
						||
        /// </summary>
 | 
						||
        /// <param name="sender"></param>
 | 
						||
        /// <param name="e"></param>
 | 
						||
        protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e)
 | 
						||
        {
 | 
						||
            this.BindGrid();
 | 
						||
        }
 | 
						||
        #endregion
 | 
						||
 | 
						||
        #region 统计按钮事件
 | 
						||
        /// <summary>
 | 
						||
        /// 统计
 | 
						||
        /// </summary>
 | 
						||
        /// <param name="sender"></param>
 | 
						||
        /// <param name="e"></param>
 | 
						||
        protected void BtnAnalyse_Click(object sender, EventArgs e)
 | 
						||
        {
 | 
						||
            BindGrid();
 | 
						||
        }
 | 
						||
        #endregion
 | 
						||
 | 
						||
        #region 导出按钮
 | 
						||
        /// 导出按钮
 | 
						||
        /// </summary>
 | 
						||
        /// <param name="sender"></param>
 | 
						||
        /// <param name="e"></param>
 | 
						||
        protected void btnOut_Click(object sender, EventArgs e)
 | 
						||
        {
 | 
						||
            string rootPath = Server.MapPath("~/") + Const.ExcelUrl;
 | 
						||
            //模板文件
 | 
						||
            string TempletFileName = rootPath + "WeldDailyExport.xlsx";
 | 
						||
            //导出文件
 | 
						||
            string filePath = rootPath + DateTime.Now.ToString("yyyyMMddhhmmss") + "\\";
 | 
						||
            if (!Directory.Exists(filePath))
 | 
						||
            {
 | 
						||
                Directory.CreateDirectory(filePath);
 | 
						||
            }
 | 
						||
            string ReportFileName = filePath + "out.xlsx";
 | 
						||
 | 
						||
            FileStream file = new FileStream(TempletFileName, FileMode.Open, FileAccess.Read);
 | 
						||
            XSSFWorkbook hssfworkbook = new XSSFWorkbook(file);
 | 
						||
 | 
						||
            hssfworkbook.RemoveAt(0);
 | 
						||
            XSSFSheet ws = (XSSFSheet)hssfworkbook.CreateSheet("Sheet1");
 | 
						||
 | 
						||
            int rowIndex = 0;
 | 
						||
            var style = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.None, BorderStyle.None, BorderStyle.None, BorderStyle.None, VerticalAlignment.Center, NPOI.SS.UserModel.HorizontalAlignment.Center, 20, true, true, "微软雅黑");
 | 
						||
 | 
						||
            #region  头部
 | 
						||
            ws = ExcelCreateRow(ws, hssfworkbook, rowIndex, rowIndex, style, 0, 19, true);
 | 
						||
            ws.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(rowIndex, rowIndex, 0, 19));
 | 
						||
            //设置表头文字
 | 
						||
            ws.GetRow(rowIndex).GetCell(0).SetCellValue("焊接日报表\nWelding Daily Report");
 | 
						||
            var style2 = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, NPOI.SS.UserModel.HorizontalAlignment.Center, 9, true, true, "Arial");
 | 
						||
 | 
						||
            ws = ExcelCreateRow(ws, hssfworkbook, rowIndex + 1, rowIndex + 2, style2, 0, 19, true);
 | 
						||
            //设置表格表头
 | 
						||
            ws.GetRow(rowIndex + 1).GetCell(0).SetCellValue("序号");
 | 
						||
            ws.GetRow(rowIndex + 1).GetCell(1).SetCellValue("管线号-页码");
 | 
						||
            ws.GetRow(rowIndex + 1).GetCell(2).SetCellValue("图纸版本");
 | 
						||
            ws.GetRow(rowIndex + 1).GetCell(3).SetCellValue("焊口号");
 | 
						||
            ws.GetRow(rowIndex + 1).GetCell(4).SetCellValue("焊接形式");
 | 
						||
            ws.GetRow(rowIndex + 1).GetCell(5).SetCellValue("焊接位置");
 | 
						||
            ws.GetRow(rowIndex + 1).GetCell(6).SetCellValue("寸径");
 | 
						||
            ws.GetRow(rowIndex + 1).GetCell(7).SetCellValue("规格");
 | 
						||
            ws.GetRow(rowIndex + 1).GetCell(8).SetCellValue("焊工号");
 | 
						||
            ws.GetRow(rowIndex + 1).GetCell(9).SetCellValue("组对部件1");
 | 
						||
            ws.GetRow(rowIndex + 1).GetCell(10).SetCellValue("组件1材质");
 | 
						||
            ws.GetRow(rowIndex + 1).GetCell(11).SetCellValue("组件1炉批号");
 | 
						||
            ws.GetRow(rowIndex + 1).GetCell(12).SetCellValue("组对部件2");
 | 
						||
            ws.GetRow(rowIndex + 1).GetCell(13).SetCellValue("组件2材质");
 | 
						||
            ws.GetRow(rowIndex + 1).GetCell(14).SetCellValue("组件2炉批号");
 | 
						||
            ws.GetRow(rowIndex + 1).GetCell(15).SetCellValue("焊接方法");
 | 
						||
            ws.GetRow(rowIndex + 1).GetCell(16).SetCellValue("组对");
 | 
						||
            ws.GetRow(rowIndex + 1).GetCell(17).SetCellValue("外观");
 | 
						||
            ws.GetRow(rowIndex + 1).GetCell(18).SetCellValue("焊接日期");
 | 
						||
            ws.GetRow(rowIndex + 1).GetCell(19).SetCellValue("备注");
 | 
						||
 | 
						||
            ws.GetRow(rowIndex + 2).GetCell(0).SetCellValue("S/N");
 | 
						||
            ws.GetRow(rowIndex + 2).GetCell(1).SetCellValue("LineNo.-PageNo.");
 | 
						||
            ws.GetRow(rowIndex + 2).GetCell(2).SetCellValue("Drawing\nRev");
 | 
						||
            ws.GetRow(rowIndex + 2).GetCell(3).SetCellValue("Joint\nNo.");
 | 
						||
            ws.GetRow(rowIndex + 2).GetCell(4).SetCellValue("JointType");
 | 
						||
            ws.GetRow(rowIndex + 2).GetCell(5).SetCellValue("Welding\nLocation");
 | 
						||
            ws.GetRow(rowIndex + 2).GetCell(6).SetCellValue("Inch");
 | 
						||
            ws.GetRow(rowIndex + 2).GetCell(7).SetCellValue("Size");
 | 
						||
            ws.GetRow(rowIndex + 2).GetCell(8).SetCellValue("Welder\nNo.");
 | 
						||
            ws.GetRow(rowIndex + 2).GetCell(9).SetCellValue("Part(1)");
 | 
						||
            ws.GetRow(rowIndex + 2).GetCell(10).SetCellValue("Material(1)");
 | 
						||
            ws.GetRow(rowIndex + 2).GetCell(11).SetCellValue("Heat\nNo.(1)");
 | 
						||
            ws.GetRow(rowIndex + 2).GetCell(12).SetCellValue("Part(2)");
 | 
						||
            ws.GetRow(rowIndex + 2).GetCell(13).SetCellValue("Material(2)");
 | 
						||
            ws.GetRow(rowIndex + 2).GetCell(14).SetCellValue("Heat\nNo.(2)");
 | 
						||
            ws.GetRow(rowIndex + 2).GetCell(15).SetCellValue("Weld\nProcess");
 | 
						||
            ws.GetRow(rowIndex + 2).GetCell(16).SetCellValue("Fit\nUp");
 | 
						||
            ws.GetRow(rowIndex + 2).GetCell(17).SetCellValue("VT");
 | 
						||
            ws.GetRow(rowIndex + 2).GetCell(18).SetCellValue("Welding\nDate");
 | 
						||
            ws.GetRow(rowIndex + 2).GetCell(19).SetCellValue("Remark");
 | 
						||
 | 
						||
            ws.GetRow(rowIndex).Height = 69 * 20;
 | 
						||
            ws.GetRow(rowIndex + 1).Height = 15 * 20;
 | 
						||
            ws.GetRow(rowIndex + 2).Height = 30 * 20;
 | 
						||
 | 
						||
            ws.SetColumnWidth(0, 5 * 256);
 | 
						||
            ws.SetColumnWidth(1, (int)(21.67 * 256));
 | 
						||
            ws.SetColumnWidth(2, (int)(9.78 * 256));
 | 
						||
            ws.SetColumnWidth(3, (int)(5.33 * 256));
 | 
						||
            ws.SetColumnWidth(4, (int)(7.67 * 256));
 | 
						||
            ws.SetColumnWidth(5, (int)(8.33 * 256));
 | 
						||
            ws.SetColumnWidth(6, (int)(7 * 256));
 | 
						||
            ws.SetColumnWidth(7, (int)(10.82 * 256));
 | 
						||
            ws.SetColumnWidth(8, (int)(8.33 * 256));
 | 
						||
            ws.SetColumnWidth(9, (int)(8.40 * 256));
 | 
						||
            ws.SetColumnWidth(10, (int)(15.67 * 256));
 | 
						||
            ws.SetColumnWidth(11, (int)(12 * 256));
 | 
						||
            ws.SetColumnWidth(12, (int)(8.22 * 256));
 | 
						||
            ws.SetColumnWidth(13, (int)(16.33 * 256));
 | 
						||
            ws.SetColumnWidth(14, (int)(11.45 * 256));
 | 
						||
            ws.SetColumnWidth(15, (int)(11.00 * 256));
 | 
						||
            ws.SetColumnWidth(16, (int)(4.00 * 256));
 | 
						||
            ws.SetColumnWidth(17, (int)(4.00 * 256));
 | 
						||
            ws.SetColumnWidth(18, (int)(9.00 * 256));
 | 
						||
            ws.SetColumnWidth(19, (int)(7 * 256));
 | 
						||
            #endregion
 | 
						||
 | 
						||
            const int pageSize = 65;
 | 
						||
            DataTable dt = GetDataTable();
 | 
						||
            var style3 = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, NPOI.SS.UserModel.HorizontalAlignment.Center, 9, false, false, "sans-serif");
 | 
						||
 | 
						||
            ws = ExcelCreateRow(ws, hssfworkbook, rowIndex + 3, dt.Rows.Count+2, style3, 0, 19);
 | 
						||
            for (int i = 0; i < dt.Rows.Count; i++)
 | 
						||
            {
 | 
						||
                int startIndex = (i + 3);
 | 
						||
                ws.GetRow(startIndex).GetCell(0).SetCellValue(i + 1);
 | 
						||
                ws.GetRow(startIndex).GetCell(1).SetCellValue(dt.Rows[i]["SingleNumber"].ToString());
 | 
						||
                ws.GetRow(startIndex).GetCell(2).SetCellValue(dt.Rows[i]["DrawingsNum"].ToString());
 | 
						||
                ws.GetRow(startIndex).GetCell(3).SetCellValue(dt.Rows[i]["WeldJointCode"].ToString());
 | 
						||
                ws.GetRow(startIndex).GetCell(4).SetCellValue(dt.Rows[i]["WeldTypeCode"].ToString());
 | 
						||
                ws.GetRow(startIndex).GetCell(5).SetCellValue(dt.Rows[i]["WeldingLocationCode"].ToString());
 | 
						||
                ws.GetRow(startIndex).GetCell(6).SetCellValue(dt.Rows[i]["Size"].ToString());
 | 
						||
                ws.GetRow(startIndex).GetCell(7).SetCellValue(dt.Rows[i]["Specification"].ToString());
 | 
						||
                ws.GetRow(startIndex).GetCell(8).SetCellValue(dt.Rows[i]["WelderCode"].ToString());
 | 
						||
                ws.GetRow(startIndex).GetCell(9).SetCellValue(dt.Rows[i]["ComponentsName1"].ToString());
 | 
						||
                ws.GetRow(startIndex).GetCell(10).SetCellValue(dt.Rows[i]["MaterialCode1"].ToString());
 | 
						||
                ws.GetRow(startIndex).GetCell(11).SetCellValue(dt.Rows[i]["HeartNo1"].ToString());
 | 
						||
                ws.GetRow(startIndex).GetCell(12).SetCellValue(dt.Rows[i]["ComponentsName2"].ToString());
 | 
						||
                ws.GetRow(startIndex).GetCell(13).SetCellValue(dt.Rows[i]["MaterialCode2"].ToString());
 | 
						||
                ws.GetRow(startIndex).GetCell(14).SetCellValue(dt.Rows[i]["HeartNo2"].ToString());
 | 
						||
                ws.GetRow(startIndex).GetCell(15).SetCellValue(dt.Rows[i]["WeldingMethodName"].ToString());
 | 
						||
                ws.GetRow(startIndex).GetCell(16).SetCellValue("ACC");
 | 
						||
                ws.GetRow(startIndex).GetCell(17).SetCellValue("ACC");
 | 
						||
                ws.GetRow(startIndex).GetCell(18).SetCellValue(dt.Rows[i]["WeldingDate"].ToString());
 | 
						||
                ws.GetRow(startIndex).GetCell(19).SetCellValue(dt.Rows[i]["Remark"].ToString());
 | 
						||
                ws.GetRow(startIndex).Height = 10 * 20;
 | 
						||
                if (startIndex == pageSize)
 | 
						||
                {
 | 
						||
                    ws.SetRowBreak(startIndex);
 | 
						||
                    startIndex += pageSize;
 | 
						||
                }
 | 
						||
            }
 | 
						||
 | 
						||
            if (dt.Rows.Count > 0)
 | 
						||
            {
 | 
						||
                string weldingDate = string.Empty;
 | 
						||
                if (txtStarTime.Text == txtEndTime.Text)
 | 
						||
                {
 | 
						||
                    weldingDate = txtStarTime.Text;
 | 
						||
                }
 | 
						||
                else
 | 
						||
                {
 | 
						||
                    weldingDate = txtStarTime.Text + "-" + txtEndTime.Text;
 | 
						||
                }
 | 
						||
                var style4 = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, NPOI.SS.UserModel.HorizontalAlignment.Center, 9, true,true, "Arial");
 | 
						||
 | 
						||
                ws = ExcelCreateRow(ws, hssfworkbook, dt.Rows.Count + 3, dt.Rows.Count + 3, style4, 0, 19);
 | 
						||
                var distinctPipelineCode = dt.AsEnumerable().GroupBy(row => row.Field<string>("PipelineCode")).Select(group => group.First());
 | 
						||
                var distinctWelder = dt.AsEnumerable().GroupBy(row => row.Field<string>("WelderCode")).Select(group => group.First());
 | 
						||
                decimal sumSize = decimal.Parse(dt.Compute("sum(Size)", "").ToString());
 | 
						||
                
 | 
						||
                ws.GetRow(dt.Rows.Count + 3).GetCell(0).SetCellValue("Total");
 | 
						||
                ws.GetRow(dt.Rows.Count + 3).GetCell(1).SetCellValue($"{distinctPipelineCode.Count().ToString()}");
 | 
						||
                ws.GetRow(dt.Rows.Count + 3).GetCell(3).SetCellValue($"{dt.Rows.Count}");
 | 
						||
                ws.GetRow(dt.Rows.Count + 3).GetCell(6).SetCellValue($"{sumSize}");
 | 
						||
                ws.GetRow(dt.Rows.Count + 3).GetCell(8).SetCellValue($"{distinctWelder.Count().ToString()}");
 | 
						||
                ws.GetRow(dt.Rows.Count + 3).Height = 20 * 20;
 | 
						||
 | 
						||
 | 
						||
 | 
						||
            }
 | 
						||
         
 | 
						||
            #region 页脚部分
 | 
						||
            IFooter footer = ws.Footer;
 | 
						||
            string str = "   CC7:                                                                                                                监理:                                                                                                             Worley:";
 | 
						||
            str += "\n\n第 &P 页,共 &N 页";
 | 
						||
            footer.Center = str;
 | 
						||
 | 
						||
 | 
						||
            #endregion
 | 
						||
 | 
						||
 | 
						||
 | 
						||
            ws.FitToPage = true;
 | 
						||
            ws.PrintSetup.FitWidth = 1;
 | 
						||
            ws.PrintSetup.FitHeight = short.MaxValue;
 | 
						||
 | 
						||
            ws.SetMargin(MarginType.LeftMargin, (double)1.2 / 3);
 | 
						||
            ws.SetMargin(MarginType.RightMargin, (double)0.5 / 3);
 | 
						||
            ws.SetMargin(MarginType.TopMargin, (double)1.8 / 3);
 | 
						||
            ws.SetMargin(MarginType.BottomMargin, (double)2.9 / 3);
 | 
						||
            ws.PrintSetup.Landscape = true;
 | 
						||
            //ws.PrintSetup.Scale = 70;
 | 
						||
            ws.ForceFormulaRecalculation = true;
 | 
						||
         
 | 
						||
            //ws.PrintSetup.FitWidth = 1;
 | 
						||
            //ws.PrintSetup.FitHeight = 0;
 | 
						||
            ws.PrintSetup.PaperSize = (int)PaperSize.A4_Small;
 | 
						||
            ws.RepeatingRows = new NPOI.SS.Util.CellRangeAddress(0,2, 0, 19);
 | 
						||
 | 
						||
            using (FileStream filess = System.IO.File.OpenWrite(ReportFileName))
 | 
						||
            {
 | 
						||
                hssfworkbook.Write(filess);
 | 
						||
            }
 | 
						||
            hssfworkbook.Close();
 | 
						||
            FileInfo filet = new FileInfo(ReportFileName);
 | 
						||
            Response.Clear();
 | 
						||
            Response.Charset = "GB2312";
 | 
						||
            Response.ContentEncoding = System.Text.Encoding.UTF8;
 | 
						||
            // 添加头信息,为"文件下载/另存为"对话框指定默认文件名
 | 
						||
            Response.AddHeader("Content-Disposition", "attachment; filename=焊接日报_" + Server.UrlEncode(DateTime.Now.ToString("yyyyMMddhhmmss") + ".xlsx"));
 | 
						||
            // 添加头信息,指定文件大小,让浏览器能够显示下载进度
 | 
						||
            Response.AddHeader("Content-Length", filet.Length.ToString());
 | 
						||
            // 指定返回的是一个不能被客户端读取的流,必须被下载
 | 
						||
            Response.ContentType = "application/ms-excel";
 | 
						||
            // 把文件流发送到客户端
 | 
						||
            Response.WriteFile(filet.FullName);
 | 
						||
            // 停止页面的执行
 | 
						||
            Response.End();
 | 
						||
        }
 | 
						||
 | 
						||
        #endregion 
 | 
						||
 | 
						||
        #region 格式化字符串
 | 
						||
        /// <summary>
 | 
						||
        /// 是否热处理
 | 
						||
        /// </summary>
 | 
						||
        /// <param name="isHotProess"></param>
 | 
						||
        /// <returns></returns>
 | 
						||
        protected string ConvertIsHotProess(object isHotProess)
 | 
						||
        {
 | 
						||
            if (isHotProess != null)
 | 
						||
            {
 | 
						||
                if (isHotProess.ToString() == "True")
 | 
						||
                {
 | 
						||
                    return Resources.Lan.Yes;
 | 
						||
                }
 | 
						||
                else
 | 
						||
                {
 | 
						||
                    return Resources.Lan.No;
 | 
						||
                }
 | 
						||
            }
 | 
						||
            return null;
 | 
						||
        }
 | 
						||
 | 
						||
        /// <summary>
 | 
						||
        /// 是否点口
 | 
						||
        /// </summary>
 | 
						||
        /// <param name="if_dk"></param>
 | 
						||
        /// <returns></returns>
 | 
						||
        protected string Convertif_dk(object if_dk)
 | 
						||
        {
 | 
						||
            if (if_dk != null)
 | 
						||
            {
 | 
						||
                if (if_dk.ToString() == "1")
 | 
						||
                {
 | 
						||
                    return Resources.Lan.Yes;
 | 
						||
                }
 | 
						||
                else
 | 
						||
                {
 | 
						||
                    return Resources.Lan.No;
 | 
						||
                }
 | 
						||
            }
 | 
						||
            return null;
 | 
						||
        }
 | 
						||
 | 
						||
        protected string ConvertWeldMaterial(object WeldMaterial)
 | 
						||
        {
 | 
						||
            string weldMaterial = string.Empty;
 | 
						||
            string silkName = string.Empty;
 | 
						||
            string fluxName = string.Empty;
 | 
						||
            string matName = string.Empty;
 | 
						||
 | 
						||
            if (WeldMaterial != null)
 | 
						||
            {
 | 
						||
                string[] wmts = WeldMaterial.ToString().Split('|');
 | 
						||
                if (wmts.Count() > 0)
 | 
						||
                {
 | 
						||
                    if (wmts.Count() == 1)
 | 
						||
                    {
 | 
						||
                        string[] silks = wmts[0].Split(',');
 | 
						||
                        if (silks.Count() > 1)  // 焊丝
 | 
						||
                        {
 | 
						||
                            foreach (string s in silks)
 | 
						||
                            {
 | 
						||
                                var silk = BLL.Base_ConsumablesService.GetConsumablesByConsumablesId(s);
 | 
						||
                                if (!string.IsNullOrEmpty(silk.UserFlux))
 | 
						||
                                {
 | 
						||
                                    fluxName = fluxName + silk.UserFlux + "/";
 | 
						||
                                    silkName = silkName + silk.ConsumablesName + "/";
 | 
						||
                                }
 | 
						||
                                else
 | 
						||
                                {
 | 
						||
                                    silkName = silkName + silk.ConsumablesName + "/";
 | 
						||
                                }
 | 
						||
                            }
 | 
						||
 | 
						||
                            if (fluxName.Length > 0)
 | 
						||
                            {
 | 
						||
                                fluxName = fluxName.Substring(0, fluxName.Length - 1);
 | 
						||
                                weldMaterial = silkName + fluxName;
 | 
						||
                            }
 | 
						||
                            else
 | 
						||
                            {
 | 
						||
                                weldMaterial = silkName.Substring(0, silkName.Length - 1);
 | 
						||
                            }
 | 
						||
 | 
						||
 | 
						||
                        }
 | 
						||
                        else
 | 
						||
                        {
 | 
						||
                            var mat = BLL.Base_ConsumablesService.GetConsumablesByConsumablesId(wmts[0]);
 | 
						||
                            weldMaterial = mat.ConsumablesName;
 | 
						||
                        }
 | 
						||
 | 
						||
                    }
 | 
						||
                    else
 | 
						||
                    {
 | 
						||
 | 
						||
                        string[] silks = wmts[0].Split(',');
 | 
						||
                        foreach (string s in silks)
 | 
						||
                        {
 | 
						||
                            var silk = BLL.Base_ConsumablesService.GetConsumablesByConsumablesId(s);
 | 
						||
                            if (!string.IsNullOrEmpty(silk.UserFlux))
 | 
						||
                            {
 | 
						||
                                fluxName = fluxName + silk.UserFlux + "/";
 | 
						||
                                silkName = silkName + silk.ConsumablesName + "/";
 | 
						||
                            }
 | 
						||
                            else
 | 
						||
                            {
 | 
						||
                                silkName = silkName + silk.ConsumablesName + "/";
 | 
						||
                            }
 | 
						||
                        }
 | 
						||
 | 
						||
                        var mat = BLL.Base_ConsumablesService.GetConsumablesByConsumablesId(wmts[1]);
 | 
						||
                        weldMaterial = silkName + mat.ConsumablesName;
 | 
						||
 | 
						||
                        if (fluxName.Length > 0)
 | 
						||
                        {
 | 
						||
                            fluxName = fluxName.Substring(0, fluxName.Length - 1);
 | 
						||
                            weldMaterial = silkName + mat.ConsumablesName + "/" + fluxName;
 | 
						||
                        }
 | 
						||
                    }
 | 
						||
                }
 | 
						||
            }
 | 
						||
            return weldMaterial;
 | 
						||
        }
 | 
						||
 | 
						||
        #endregion
 | 
						||
 | 
						||
        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;
 | 
						||
        }
 | 
						||
 | 
						||
        private XSSFSheet ExcelCreateRow(XSSFSheet ws, XSSFWorkbook hssfworkbook, int sRows, int eRows, ICellStyle style, int cStart, int cEnd, bool istitle = false)
 | 
						||
        {
 | 
						||
            for (int i = sRows; i <= eRows; i++)
 | 
						||
            {
 | 
						||
                ws.CreateRow(i);
 | 
						||
                if (istitle)
 | 
						||
                {
 | 
						||
                    ws.GetRow(i).HeightInPoints =
 | 
						||
                            i == sRows ? 49.75f :
 | 
						||
                            i == (sRows + 1) ? 13.75f :
 | 
						||
                            38f;
 | 
						||
                }
 | 
						||
                else
 | 
						||
                {
 | 
						||
                    ws.GetRow(i).HeightInPoints = 38f;
 | 
						||
                }
 | 
						||
                for (int j = cStart; j <= cEnd; j++)
 | 
						||
                {
 | 
						||
                    ws.GetRow(i).CreateCell(j);
 | 
						||
                    ws.GetRow(i).GetCell(j).CellStyle = style;
 | 
						||
                }
 | 
						||
            }
 | 
						||
            return ws;
 | 
						||
        }
 | 
						||
 | 
						||
        private ICellStyle SetStyle(XSSFWorkbook ws, BorderStyle top, BorderStyle bottom, BorderStyle left, BorderStyle right)
 | 
						||
        {
 | 
						||
            ICellStyle style = ws.CreateCellStyle();
 | 
						||
            style.BorderLeft = left;
 | 
						||
            style.BorderRight = right;
 | 
						||
            style.BorderTop = top;
 | 
						||
            style.BorderBottom = bottom;
 | 
						||
 | 
						||
            return style;
 | 
						||
        }
 | 
						||
    }
 | 
						||
} |