ZHJA_HJGL/HJGL_ZH/FineUIPro.Web/HJGL/CheckManage/CheckReportExport.aspx.cs

317 lines
15 KiB
C#
Raw Normal View History

2024-05-08 17:17:11 +08:00
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
/// <summary>
/// 加载树
/// </summary>
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<Model.Base_Project> 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
/// <summary>
/// 点击TreeView
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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<SqlParameter> listStr = new List<SqlParameter>();
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
/// <summary>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort(object sender, GridSortEventArgs e)
{
Grid1.SortDirection = e.SortDirection;
Grid1.SortField = e.SortField;
BindGrid();
}
#endregion
#region
/// <summary>
/// 页索引改变事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
Grid1.PageIndex = e.NewPageIndex;
BindGrid();
}
#endregion
#region
/// <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();
}
#endregion
#region
/// <summary>
/// 项目下拉选择事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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
/// <summary>
/// 统计
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnFind_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)
{
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();
}
/// <summary>
/// 导出方法
/// </summary>
/// <param name="grid"></param>
/// <returns></returns>
private string GetGridTableHtml(Grid grid)
{
StringBuilder sb = new StringBuilder();
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>");
this.Grid1.PageSize = 10000;
BindGrid();
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 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
}
}