using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Text; using System.Web.UI.WebControls; using System.Data.SqlClient; using BLL; using System.Data; using AspNet = System.Web.UI.WebControls; namespace FineUIPro.Web.HJGL.CheckManage { public partial class CheckReportExport : PageBase { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString(); this.drpWME.DataValueField = "WME_ID"; this.drpWME.DataTextField = "WME_Name"; this.drpWME.DataSource = BLL.HJGL_WeldingMethodService.GetWeldMethodNameList(); this.drpWME.DataBind(); Funs.FineUIPleaseSelect(this.drpWME); this.drpNdt.DataTextField = "NDT_Code"; this.drpNdt.DataValueField = "NDT_ID"; this.drpNdt.DataSource = BLL.HJGL_TestingService.GetNDTTypeNameList(); this.drpNdt.DataBind(); Funs.FineUIPleaseSelect(this.drpNdt); this.drpProjectId.DataTextField = "ProjectCode"; this.drpProjectId.DataValueField = "ProjectId"; this.drpProjectId.DataSource = BLL.Base_ProjectService.GetOnProjectListByUserId(this.CurrUser.UserId, "1"); this.drpProjectId.DataBind(); Funs.FineUIPleaseSelect(this.drpProjectId); this.InitTreeMenu();//加载树 } } #region 加载树 /// /// 加载树 /// private void InitTreeMenu() { this.tvControlItem.Nodes.Clear(); TreeNode rootNode = new TreeNode(); rootNode.Text = "施工号-装置"; rootNode.ToolTip = "项目"; rootNode.NodeID = "0"; rootNode.Expanded = true; this.tvControlItem.Nodes.Add(rootNode); List projects = BLL.Base_ProjectService.GetOnProjectListByUserId(this.CurrUser.UserId, "1"); if (this.drpProjectId.SelectedValue != null && this.drpProjectId.SelectedValue != "null") { projects = projects.Where(x => x.ProjectId == this.drpProjectId.SelectedValue).ToList(); } foreach (var item in projects) { TreeNode rootProjectNode = new TreeNode();//定义根节点 rootProjectNode.Text = item.ProjectCode; rootProjectNode.NodeID = item.ProjectId; rootProjectNode.EnableClickEvent = true; rootProjectNode.ToolTip = item.ProjectName; rootNode.Nodes.Add(rootProjectNode); } } #endregion #region 点击TreeView /// /// 点击TreeView /// /// /// protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e) { BindGrid(); drpIsoNo.Items.Clear(); this.drpIsoNo.DataTextField = "ISO_IsoNo"; this.drpIsoNo.DataValueField = "ISO_ID"; this.drpIsoNo.DataSource = (from x in Funs.DB.HJGL_PW_IsoInfo where x.ProjectId == this.tvControlItem.SelectedNodeID orderby x.ISO_IsoNo select x).ToList(); this.drpIsoNo.DataBind(); Funs.FineUIPleaseSelect(this.drpIsoNo); } #endregion private void BindGrid() { string strSql = @"SELECT QualityRating.QualityRatingId,QualityRating.FilmNum,JointInfo.JOT_JointDesc, JointInfo.Sort1,JointInfo.Sort2,JointInfo.Sort3,JointInfo.Sort4,JointInfo.Sort5, JointInfo.JOT_JointNo+(case batchDetail.PointType when '2' then 'K' else '' end) as JOT_JointNo, (CASE WHEN JointInfo.JOT_CellWelder!=JointInfo.JOT_FloorWelder THEN Welder1.WED_Code+'/'+Welder2.WED_Code ELSE Welder1.WED_Code END) AS WED_Code, dbo.GetDefectNature(QualityRating.QualityRatingId,QualityRating.CH_TrustItemID) as DefectNature, QualityRating.DefectSize,QualityRating.DefectRation, Replace(QualityRating.DefectResult,' ','') AS DefectResult, '/' AS BatchCode, --batch.BatchCode, 检测批号 isoInfo.ISO_IsoNo, Equipment.EquipmentName as Remark, case when ndtType.NDT_Code='MT' then ((case when QualityRating.DefectNature is not null and QualityRating.DefectNature!='' then '性质:'+QualityRating.DefectNature+',' else '' end) +(case when QualityRating.DefectLocation is not null and QualityRating.DefectLocation!='' then '位置:'+QualityRating.DefectLocation+',' else '' end) +(case when QualityRating.DefectSize is not null then '尺寸:'+convert(nvarchar(10),cast(QualityRating.DefectSize as real)) else '' end)) when ndtType.NDT_Code='PT' then ((case when QualityRating.DefectNature is not null and QualityRating.DefectNature!='' then '性质:'+QualityRating.DefectNature+',' else '' end) +(case when QualityRating.DefectLocation is not null and QualityRating.DefectLocation!='' then '位置:'+QualityRating.DefectLocation+',' else '' end) +(case when QualityRating.DefectSize is not null then '尺寸:'+convert(nvarchar(10),cast(QualityRating.DefectSize as real)) else '' end)) when ndtType.NDT_Code='UT' then ((case when QualityRating.PeakAmplitude is not null and QualityRating.PeakAmplitude!='' then '波幅:'+QualityRating.PeakAmplitude+',' else '' end) +(case when QualityRating.DefectLocation is not null and QualityRating.DefectLocation!='' then '位置:'+QualityRating.DefectLocation+',' else '' end) +(case when QualityRating.DepthDefect is not null then '深度:'+convert(nvarchar(10),cast(QualityRating.DepthDefect as real))+',' else '' end) +(case when QualityRating.IndicatingLength is not null then '长度:'+convert(nvarchar(10),cast(QualityRating.IndicatingLength as real)) else '' end)) else '' end AS Defect FROM dbo.HJGL_BO_QualityRating AS QualityRating LEFT JOIN DBO.HJGL_CH_TrustItem AS TrustItem ON TrustItem.CH_TrustItemID = QualityRating.CH_TrustItemID LEFT JOIN HJGL_BS_Equipment AS Equipment ON Equipment.EquipmentId=TrustItem.EquipmentId LEFT JOIN dbo.HJGL_CH_Trust trust ON trust.CH_TrustID = TrustItem.CH_TrustID LEFT JOIN dbo.HJGL_BS_NDTType ndtType on ndtType.NDT_ID=trust.CH_NDTMethod LEFT JOIN dbo.HJGL_BO_BatchDetail batchDetail ON batchDetail.JOT_ID = QualityRating.JOT_ID LEFT JOIN dbo.HJGL_BO_Batch batch ON batch.BatchId=batchDetail.BatchId LEFT JOIN dbo.HJGL_BS_NDTRate rate ON rate.NDTR_ID = batch.NDTR_ID LEFT JOIN DBO.HJGL_PW_JointInfo AS JointInfo ON JointInfo.JOT_ID=QualityRating.JOT_ID LEFT JOIN dbo.HJGL_PW_IsoInfo AS isoInfo ON isoInfo.ISO_ID=JointInfo.ISO_ID LEFT JOIN DBO.HJGL_BS_Welder AS Welder1 ON Welder1.WED_ID = JointInfo.JOT_CellWelder LEFT JOIN DBO.HJGL_BS_Welder AS Welder2 ON Welder2.WED_ID = JointInfo.JOT_FloorWelder WHERE trust.ProjectId=@ProjectId AND (rate.NDTR_Rate=0 OR rate.NDTR_Rate=100 OR batch.IsSpecial=1)"; List listStr = new List(); listStr.Add(new SqlParameter("@ProjectId", this.tvControlItem.SelectedNodeID)); if (this.drpIsoNo.SelectedValue != BLL.Const._Null && drpIsoNo.SelectedValue != null) { strSql += " AND isoInfo.ISO_ID = @IsoNo"; listStr.Add(new SqlParameter("@IsoNo", this.drpIsoNo.SelectedValue.Trim())); } if (this.drpJointDesc.SelectedValue != BLL.Const._Null && drpJointDesc.SelectedValue != null) { strSql += " AND JointInfo.JOT_JointDesc = @JointDesc"; listStr.Add(new SqlParameter("@JointDesc", this.drpJointDesc.SelectedValue.Trim())); } if (this.drpSte.SelectedValue != BLL.Const._Null && drpSte.SelectedValue != null) { strSql += " AND batch.STE_ID = @STE_ID"; listStr.Add(new SqlParameter("@STE_ID", this.drpSte.SelectedValue)); } if (this.drpWME.SelectedValue != BLL.Const._Null) { strSql += " AND JointInfo.WME_ID = @WME_ID"; listStr.Add(new SqlParameter("@WME_ID", this.drpWME.SelectedValue)); } if (this.drpNdt.SelectedValue != BLL.Const._Null) { strSql += " AND trust.CH_NDTMethod = @NDT"; listStr.Add(new SqlParameter("@NDT", this.drpNdt.SelectedValue)); } //strSql += " ORDER BY ReportCode"; SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); Grid1.RecordCount = tb.Rows.Count; var table = this.GetPagedDataTable(Grid1, tb); Grid1.DataSource = table; Grid1.DataBind(); } #region 排序 /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, GridSortEventArgs e) { Grid1.SortDirection = e.SortDirection; Grid1.SortField = e.SortField; BindGrid(); } #endregion #region 页索引改变事件 /// /// 页索引改变事件 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { Grid1.PageIndex = e.NewPageIndex; BindGrid(); } #endregion #region 分页选择下拉改变事件 /// /// 分页选择下拉改变事件 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(); } #endregion #region 项目下拉选择事件 /// /// 项目下拉选择事件 /// /// /// protected void drpProjectId_SelectedIndexChanged(object sender, EventArgs e) { this.InitTreeMenu(); } protected void drpIsoNo_SelectedIndexChanged(object sender, EventArgs e) { this.drpJointDesc.Items.Clear(); this.drpSte.Items.Clear(); if (drpIsoNo.SelectedValue != Const._Null) { this.drpJointDesc.DataTextField = "JOT_JointDesc"; this.drpJointDesc.DataValueField = "JOT_JointDesc"; this.drpJointDesc.DataSource = (from x in Funs.DB.HJGL_PW_JointInfo where x.ISO_ID == drpIsoNo.SelectedValue orderby x.JOT_JointDesc select x.JOT_JointDesc).Distinct(); this.drpJointDesc.DataBind(); Funs.FineUIPleaseSelect(this.drpJointDesc); this.drpSte.DataValueField = "STE_ID"; this.drpSte.DataTextField = "STE_Code"; this.drpSte.DataSource = (from x in Funs.DB.HJGL_PW_JointInfo join y in Funs.DB.HJGL_BS_Steel on x.STE_ID equals y.STE_ID where x.ISO_ID == drpIsoNo.SelectedValue select new { x.STE_ID, y.STE_Code }).Distinct().OrderBy(x => x.STE_Code); this.drpSte.DataBind(); Funs.FineUIPleaseSelect(this.drpSte); } } #endregion #region 查询 /// /// 统计 /// /// /// protected void btnFind_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("0%、100%、特殊口检测导出" + 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(); sb.Append(""); sb.Append(""); sb.Append(""); this.Grid1.PageSize = 10000; BindGrid(); foreach (GridColumn column in grid.Columns) { sb.AppendFormat("", 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("labNumber") as AspNet.Label).Text; } sb.AppendFormat("", html); } sb.Append(""); } sb.Append("
{0}
{0}
"); return sb.ToString(); } #endregion } }