226 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			226 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			C#
		
	
	
	
using System;
 | 
						||
using System.Collections.Generic;
 | 
						||
using AspNet = System.Web.UI.WebControls;
 | 
						||
using System.Data.SqlClient;
 | 
						||
using System.Data;
 | 
						||
using NPOI.HSSF.Util;
 | 
						||
using NPOI.SS.UserModel;
 | 
						||
using NPOI.SS.Util;
 | 
						||
using NPOI.XSSF.UserModel;
 | 
						||
using System.Linq;
 | 
						||
using System.IO;
 | 
						||
using BLL;
 | 
						||
using System.Text;
 | 
						||
 | 
						||
namespace FineUIPro.Web.WeldingProcess.TrustManage
 | 
						||
{
 | 
						||
    public partial class NDECheckWarn : PageBase
 | 
						||
    {
 | 
						||
        protected void Page_Load(object sender, EventArgs e)
 | 
						||
        {
 | 
						||
            if (!IsPostBack)
 | 
						||
            {
 | 
						||
                this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString();
 | 
						||
                BLL.Project_InstallationService.InitInstallationDropDownList(this.drpInstallation, true, this.CurrUser.LoginProjectId, Resources.Lan.PleaseSelect);
 | 
						||
            }
 | 
						||
        }
 | 
						||
        private void BindGrid()
 | 
						||
        {
 | 
						||
            string strSql = @"SELECT BatchTrustItem.TrustBatchItemId, BatchTrust.TrustType,BatchTrust.TrustBatchCode,
 | 
						||
                                     BatchTrust.ProjectId, CONVERT(varchar(10),BatchTrust.TrustDate,120) AS TrustDate,
 | 
						||
                                     BatchTrust.InstallationId,ins.InstallationCode,pipe.PipelineCode,
 | 
						||
                                    (CASE WHEN PointBatchItem.PointState='2' then (CASE WHEN jot.JointAttribute='固定F' AND RIGHT(jot.WeldJointCode,1)<>'G' THEN jot.WeldJointCode+'G' ELSE jot.WeldJointCode END)+'K'
 | 
						||
                                          ELSE (CASE WHEN jot.JointAttribute='固定F' AND RIGHT(jot.WeldJointCode,1)<>'G' THEN jot.WeldJointCode+'G' ELSE jot.WeldJointCode END) END) AS WeldJointCode,
 | 
						||
                                     mat.MaterialCode,jot.JointArea,welder.WelderCode AS WelderCode,weldType.WeldTypeCode,
 | 
						||
                                     convert(float,jot.Dia) AS Dia,convert(float,jot.Size) AS Size,convert(float,jot.Thickness) AS Thickness,
 | 
						||
                                     method.WeldingMethodCode, jot.Specification,cast(rate.DetectionRateValue as varchar(10))+'%' AS DetectionRateCode,
 | 
						||
                                     PointBatchItem.PointDate,(CASE WHEN dtype.SysType !='射线检测' THEN 'Ⅰ' ELSE PointBatchItem.AcceptLevel END) AS AcceptLevel 
 | 
						||
                                FROM Batch_BatchTrustItem AS BatchTrustItem
 | 
						||
                                     LEFT JOIN dbo.Batch_BatchTrust AS BatchTrust ON BatchTrust.TrustBatchId=BatchTrustItem.TrustBatchId
 | 
						||
                                     LEFT JOIN dbo.Base_DetectionType dtype ON dtype.DetectionTypeId = BatchTrust.DetectionTypeId
 | 
						||
                                     LEFT JOIN Batch_PointBatchItem AS PointBatchItem ON PointBatchItem.PointBatchItemId=BatchTrustItem.PointBatchItemId
 | 
						||
                                     LEFT JOIN dbo.Batch_PointBatch point ON point.PointBatchId = PointBatchItem.PointBatchId
 | 
						||
                                     LEFT JOIN dbo.Base_DetectionRate rate ON rate.DetectionRateId = point.DetectionRateId
 | 
						||
                                     LEFT JOIN dbo.Pipeline_WeldJoint jot ON jot.WeldJointId = BatchTrustItem.WeldJointId
 | 
						||
                                     LEFT JOIN dbo.Pipeline_Pipeline pipe ON pipe.PipelineId = jot.PipelineId
 | 
						||
                                     LEFT JOIN dbo.Project_Installation ins ON ins.InstallationId = BatchTrust.InstallationId
 | 
						||
                                     LEFT JOIN dbo.Base_WeldType weldType ON weldType.WeldTypeId = jot.WeldTypeId
 | 
						||
                                     LEFT JOIN dbo.Welder_Welder welder ON welder.WelderId = jot.BackingWelderId
 | 
						||
                                     LEFT JOIN dbo.Base_Material mat ON mat.MaterialId = jot.Material1Id
 | 
						||
                                     LEFT JOIN dbo.Base_WeldingMethod method ON method.WeldingMethodId = jot.WeldingMethodId
 | 
						||
                                     LEFT JOIN dbo.Batch_NDEItem ndeItem ON ndeItem.TrustBatchItemId = BatchTrustItem.TrustBatchItemId
 | 
						||
                               WHERE BatchTrust.ProjectId=@ProjectId AND ndeItem.NDEItemID IS NULL 
 | 
						||
                                     AND (jot.IsCancel IS NULL OR jot.IsCancel=0)
 | 
						||
                                     AND (BatchTrustItem.IsCancelTrust is null OR BatchTrustItem.IsCancelTrust=0) ";
 | 
						||
 | 
						||
            List<SqlParameter> listStr = new List<SqlParameter>();
 | 
						||
 | 
						||
            listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
 | 
						||
            if (drpInstallation.SelectedValue != Const._Null)
 | 
						||
            {
 | 
						||
                strSql += " AND BatchTrust.InstallationId = @InstallationId";
 | 
						||
                listStr.Add(new SqlParameter("@InstallationId", drpInstallation.SelectedValue));
 | 
						||
            }
 | 
						||
            if (!string.IsNullOrEmpty(this.txtTrustBatchCode.Text))
 | 
						||
            {
 | 
						||
                strSql += " AND BatchTrust.TrustBatchCode LIKE @TrustBatchCode";
 | 
						||
                listStr.Add(new SqlParameter("@TrustBatchCode", "%" + this.txtTrustBatchCode.Text.Trim() + "%"));
 | 
						||
            }
 | 
						||
 | 
						||
            if (!string.IsNullOrEmpty(this.txtTrustDate.Text))
 | 
						||
            {
 | 
						||
                strSql += " AND BatchTrust.TrustDate = @TrustDate";
 | 
						||
                listStr.Add(new SqlParameter("@TrustDate", this.txtTrustDate.Text));
 | 
						||
            }
 | 
						||
            if (!string.IsNullOrEmpty(txtPipeLineCode.Text))
 | 
						||
            {
 | 
						||
                strSql += " AND pipe.PipelineCode LIKE @PipelineCode";
 | 
						||
                listStr.Add(new SqlParameter("@PipelineCode", "%" + this.txtPipeLineCode.Text.Trim() + "%"));
 | 
						||
            }
 | 
						||
            if (!string.IsNullOrEmpty(this.txtWeldJointCode.Text))
 | 
						||
            {
 | 
						||
                strSql += " AND jot.WeldJointCode = @WeldJointCode";
 | 
						||
                listStr.Add(new SqlParameter("@WeldJointCode", this.txtWeldJointCode.Text));
 | 
						||
            }
 | 
						||
            if (rbWarn.SelectedValue != "0")
 | 
						||
            {
 | 
						||
                if (rbWarn.SelectedValue == "1")
 | 
						||
                {
 | 
						||
                    strSql += " AND DateDiff (d,BatchTrust.TrustDate,GETDATE()) >=3 AND DateDiff (d,BatchTrust.TrustDate,GETDATE()) <=5 ";
 | 
						||
                }
 | 
						||
                else
 | 
						||
                {
 | 
						||
                    strSql += " AND DateDiff(d, BatchTrust.TrustDate, GETDATE()) > 5 ";
 | 
						||
                }
 | 
						||
            }
 | 
						||
            
 | 
						||
 | 
						||
            SqlParameter[] parameter = listStr.ToArray();
 | 
						||
            DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
 | 
						||
            this.Grid1.RecordCount = tb.Rows.Count;
 | 
						||
            var table = this.GetPagedDataTable(Grid1, tb);
 | 
						||
            Grid1.DataSource = table;
 | 
						||
            Grid1.DataBind();
 | 
						||
        }
 | 
						||
 | 
						||
        protected void Grid1_RowDataBound(object sender, GridRowEventArgs e)
 | 
						||
        {
 | 
						||
            DataRowView row = e.DataItem as DataRowView;
 | 
						||
 | 
						||
            if (row["TrustDate"].ToString() != "")
 | 
						||
            {
 | 
						||
                DateTime trustDate = Convert.ToDateTime(row["TrustDate"]);
 | 
						||
                if (DateTime.Now.AddDays(-6).Date > trustDate.Date)
 | 
						||
                {
 | 
						||
                    e.RowCssClass = "color1";
 | 
						||
                }
 | 
						||
                else if (DateTime.Now.AddDays(-4) >= trustDate.Date && DateTime.Now.AddDays(-6).Date <= trustDate.Date)
 | 
						||
                {
 | 
						||
                    e.RowCssClass = "color2";
 | 
						||
                }
 | 
						||
            }
 | 
						||
           
 | 
						||
        }
 | 
						||
 | 
						||
        /// <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();
 | 
						||
        }
 | 
						||
 | 
						||
        #region 统计按钮事件
 | 
						||
        /// <summary>
 | 
						||
        /// 统计
 | 
						||
        /// </summary>
 | 
						||
        /// <param name="sender"></param>
 | 
						||
        /// <param name="e"></param>
 | 
						||
        protected void BtnAnalyse_Click(object sender, EventArgs e)
 | 
						||
        {
 | 
						||
            BindGrid();
 | 
						||
        }
 | 
						||
        #endregion
 | 
						||
 | 
						||
        #region 导出
 | 
						||
        protected void btnOut_Click(object sender, EventArgs e)
 | 
						||
        {
 | 
						||
            Response.ClearContent();
 | 
						||
            string filename = Funs.GetNewFileName();
 | 
						||
            Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode(Resources.Lan.RequestSheetNumber + filename, System.Text.Encoding.UTF8) + ".xls");
 | 
						||
            Response.ContentType = "application/excel";
 | 
						||
            Response.ContentEncoding = System.Text.Encoding.UTF8;
 | 
						||
            Response.Write(GetGridTableHtml(Grid1));
 | 
						||
            Response.End();
 | 
						||
        }
 | 
						||
 | 
						||
        private string GetGridTableHtml(Grid grid)
 | 
						||
        {
 | 
						||
            StringBuilder sb = new StringBuilder();
 | 
						||
            grid.PageSize = 1000000;
 | 
						||
            BindGrid();
 | 
						||
            sb.Append("<meta http-equiv=\"content-type\" content=\"application/excel; charset=UTF-8\"/>");
 | 
						||
            sb.Append("<table cellspacing=\"0\" rules=\"all\" border=\"1\" style=\"border-collapse:collapse;\">");
 | 
						||
            sb.Append("<tr>");
 | 
						||
            foreach (GridColumn column in grid.Columns)
 | 
						||
            {
 | 
						||
                sb.AppendFormat("<td>{0}</td>", column.HeaderText);
 | 
						||
            }
 | 
						||
            sb.Append("</tr>");
 | 
						||
            foreach (GridRow row in grid.Rows)
 | 
						||
            {
 | 
						||
                sb.Append("<tr>");
 | 
						||
                foreach (GridColumn column in grid.Columns)
 | 
						||
                {
 | 
						||
                    string jot = row.Values[column.ColumnIndex].ToString();
 | 
						||
                    string html = string.Empty;
 | 
						||
                    if (column.ColumnID == "WeldJointCode" && jot.Split('-').Length > 1)
 | 
						||
                    {
 | 
						||
                        html = "'" + row.Values[column.ColumnIndex].ToString();
 | 
						||
                    }
 | 
						||
                    else
 | 
						||
                    {
 | 
						||
                        html = row.Values[column.ColumnIndex].ToString();
 | 
						||
                    }
 | 
						||
 | 
						||
                    if (column.ColumnID == "tfNumber")
 | 
						||
                    {
 | 
						||
                        html = (row.FindControl("labNumber") as AspNet.Label).Text;
 | 
						||
                    }
 | 
						||
                    sb.AppendFormat("<td>{0}</td>", html);
 | 
						||
                }
 | 
						||
 | 
						||
                sb.Append("</tr>");
 | 
						||
            }
 | 
						||
 | 
						||
            sb.Append("</table>");
 | 
						||
 | 
						||
            return sb.ToString();
 | 
						||
        }
 | 
						||
        #endregion
 | 
						||
 | 
						||
    }
 | 
						||
} |