xinjiang/SGGL/FineUIPro.Web/HJGL/WeldingReport/NDTTotalReport.aspx.cs

560 lines
25 KiB
C#

using BLL;
using FineUIPro.Web.Controls;
using Model;
using NPOI.SS.UserModel;
using NPOI.SS.Util;
using NPOI.XSSF.UserModel;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Text;
using AspNet = System.Web.UI.WebControls;
namespace FineUIPro.Web.HJGL.WeldingReport
{
public partial class NDTTotalReport : PageBase
{
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGrid();
}
}
private void BindGrid()
{
string strSql1 = @"select unit.UnitId+ workarea.WorkAreaId id,unit.UnitId,unit.UnitCode,unit.UnitName,install.InstallationName, workarea.WorkAreaCode ,workarea.WorkAreaId from Base_Unit unit left join Project_ProjectUnit projectUnit on unit.UnitId = projectUnit.UnitId
left join ProjectData_WorkArea workarea on workarea.UnitId= unit.UnitId and workarea.ProjectId = projectUnit.ProjectId
left join Project_Installation install on install.InstallationId = workarea.InstallationId and install.ProjectId=projectUnit.ProjectId
where workarea.WorkAreaId is not null and projectUnit.UnitType not in ('7','6','3') and projectUnit.ProjectId = @ProjectId";
SqlParameter[] parameter1 = new SqlParameter[] {
new SqlParameter("@ProjectId",this.CurrUser.LoginProjectId)};
DataTable tb1 = SQLHelper.GetDataTableRunText(strSql1, parameter1);
string strSql2 = @"select iso.WorkAreaId,iso.UnitId,DetectionType.DetectionTypeCode,count(distinct jot.JOT_ID) as num
from CH_Trust trust left join CH_TrustItem trustItem on trust.CH_TrustID = trustItem.CH_TrustID
left join PW_JointInfo jot on jot.JOT_ID = trustItem.JOT_ID
left join PW_IsoInfo iso on iso.ISO_ID=jot.ISO_ID
left join Base_DetectionType DetectionType on trust.CH_NDTMethod = DetectionType.DetectionTypeId
where jot.ProjectId=@ProjectId and CH_AuditMan is null
group by iso.WorkAreaId,iso.UnitId,DetectionType.DetectionTypeCode";
SqlParameter[] parameter2 = new SqlParameter[] {
new SqlParameter("@ProjectId",this.CurrUser.LoginProjectId)};
DataTable tb2 = SQLHelper.GetDataTableRunText(strSql2, parameter2);
string strSql3 = @"select iso.WorkAreaId,iso.UnitId,DetectionType.DetectionTypeCode,count(distinct jot.JOT_ID) as num
from CH_Trust trust left join CH_TrustItem trustItem on trust.CH_TrustID = trustItem.CH_TrustID
left join PW_JointInfo jot on jot.JOT_ID = trustItem.JOT_ID
left join PW_IsoInfo iso on iso.ISO_ID=jot.ISO_ID
left join Base_DetectionType DetectionType on trust.CH_NDTMethod = DetectionType.DetectionTypeId
where jot.ProjectId=@ProjectId and CH_AuditMan is not null
group by iso.WorkAreaId,iso.UnitId,DetectionType.DetectionTypeCode";
SqlParameter[] parameter3 = new SqlParameter[] {
new SqlParameter("@ProjectId",this.CurrUser.LoginProjectId)};
DataTable tb3 = SQLHelper.GetDataTableRunText(strSql3, parameter3);
string strSql4 = @"select iso.WorkAreaId,iso.UnitId,DetectionType.DetectionTypeCode,count(distinct jot.JOT_ID) as num
from CH_Check chcheck left join CH_CheckItem checkitem on chcheck.CHT_CheckID = checkitem.CHT_CheckID
left join CH_Trust trust on trust.CH_TrustID = chcheck.CH_TrustID
left join PW_JointInfo jot on jot.JOT_ID = checkitem.JOT_ID
left join PW_IsoInfo iso on iso.ISO_ID=jot.ISO_ID
left join Base_DetectionType DetectionType on trust.CH_NDTMethod = DetectionType.DetectionTypeId
where jot.ProjectId=@ProjectId and CHT_AuditMan is null
group by iso.WorkAreaId,iso.UnitId,DetectionType.DetectionTypeCode";
SqlParameter[] parameter4 = new SqlParameter[] {
new SqlParameter("@ProjectId",this.CurrUser.LoginProjectId)};
DataTable tb4 = SQLHelper.GetDataTableRunText(strSql4, parameter4);
string strSql5 = @"select iso.WorkAreaId,iso.UnitId,DetectionType.DetectionTypeCode,count(distinct jot.JOT_ID) as num
from CH_Check chcheck left join CH_CheckItem checkitem on chcheck.CHT_CheckID = checkitem.CHT_CheckID
left join CH_Trust trust on trust.CH_TrustID = chcheck.CH_TrustID
left join PW_JointInfo jot on jot.JOT_ID = checkitem.JOT_ID
left join PW_IsoInfo iso on iso.ISO_ID=jot.ISO_ID
left join Base_DetectionType DetectionType on trust.CH_NDTMethod = DetectionType.DetectionTypeId
where jot.ProjectId=@ProjectId and CHT_AuditMan is not null
group by iso.WorkAreaId,iso.UnitId,DetectionType.DetectionTypeCode";
SqlParameter[] parameter5 = new SqlParameter[] {
new SqlParameter("@ProjectId",this.CurrUser.LoginProjectId)};
DataTable tb5 = SQLHelper.GetDataTableRunText(strSql5, parameter5);
if (tb1 != null )
{
tb1.Columns.Add("t1y");
tb1.Columns.Add("t2y");
tb1.Columns.Add("t3y");
tb1.Columns.Add("t4y");
tb1.Columns.Add("t5y");
tb1.Columns.Add("t6y");
tb1.Columns.Add("t1n");
tb1.Columns.Add("t2n");
tb1.Columns.Add("t3n");
tb1.Columns.Add("t4n");
tb1.Columns.Add("t5n");
tb1.Columns.Add("t6n");
tb1.Columns.Add("c1y");
tb1.Columns.Add("c2y");
tb1.Columns.Add("c3y");
tb1.Columns.Add("c4y");
tb1.Columns.Add("c5y");
tb1.Columns.Add("c6y");
tb1.Columns.Add("c1n");
tb1.Columns.Add("c2n");
tb1.Columns.Add("c3n");
tb1.Columns.Add("c4n");
tb1.Columns.Add("c5n");
tb1.Columns.Add("c6n");
for (int i = 0; i < tb1.Rows.Count; i++)
{
int t1y = 0;
int t2y = 0;
int t3y = 0;
int t4y = 0;
int t5y = 0;
int t6y = 0;
int t1n = 0;
int t2n = 0;
int t3n = 0;
int t4n = 0;
int t5n = 0;
int t6n = 0;
int c1y = 0;
int c2y = 0;
int c3y = 0;
int c4y = 0;
int c5y = 0;
int c6y = 0;
int c1n = 0;
int c2n = 0;
int c3n = 0;
int c4n = 0;
int c5n = 0;
int c6n = 0;
for (int j = 0; j < tb2.Rows.Count; j++)
{
if (tb1.Rows[i]["WorkAreaId"].ToString() == tb2.Rows[j]["WorkAreaId"].ToString() && tb1.Rows[i]["UnitId"].ToString() == tb2.Rows[j]["UnitId"].ToString())
{
switch (tb2.Rows[j]["DetectionTypeCode"].ToString())
{
case "RT\\UT":
case "RT": t1y+=int.Parse(tb2.Rows[j]["num"].ToString()); break;
case "PT": t2y += int.Parse(tb2.Rows[j]["num"].ToString()); break;
case "MT": t3y += int.Parse(tb2.Rows[j]["num"].ToString()); break;
case "UT": t4y += int.Parse(tb2.Rows[j]["num"].ToString()); break;
case "TOFD\\UT\\MT":
case "TOFD\\MT":
case "3D-TFM":
case "TOFD": t5y += int.Parse(tb2.Rows[j]["num"].ToString()); break;
case "PA": t6y += int.Parse(tb2.Rows[j]["num"].ToString()); break;
}
}
}
for (int j = 0; j < tb3.Rows.Count; j++)
{
if (tb1.Rows[i]["WorkAreaId"].ToString() == tb3.Rows[j]["WorkAreaId"].ToString() && tb1.Rows[i]["UnitId"].ToString() == tb3.Rows[j]["UnitId"].ToString())
{
switch (tb3.Rows[j]["DetectionTypeCode"].ToString())
{
case "RT\\UT":
case "RT": t1n += int.Parse(tb3.Rows[j]["num"].ToString()); break;
case "PT": t2n += int.Parse(tb3.Rows[j]["num"].ToString()); break;
case "MT": t3n += int.Parse(tb3.Rows[j]["num"].ToString()); break;
case "UT": t4n += int.Parse(tb3.Rows[j]["num"].ToString()); break;
case "TOFD\\UT\\MT":
case "TOFD\\MT":
case "3D-TFM":
case "TOFD": t5n += int.Parse(tb3.Rows[j]["num"].ToString()); break;
case "PA": t6n += int.Parse(tb3.Rows[j]["num"].ToString()); break;
}
}
}
for (int j = 0; j < tb4.Rows.Count; j++)
{
if (tb1.Rows[i]["WorkAreaId"].ToString() == tb4.Rows[j]["WorkAreaId"].ToString() && tb1.Rows[i]["UnitId"].ToString() == tb4.Rows[j]["UnitId"].ToString())
{
switch (tb4.Rows[j]["DetectionTypeCode"].ToString())
{
case "RT\\UT":
case "RT": c1y += int.Parse(tb4.Rows[j]["num"].ToString()); break;
case "PT": c2y += int.Parse(tb4.Rows[j]["num"].ToString()); break;
case "MT": c3y += int.Parse(tb4.Rows[j]["num"].ToString()); break;
case "UT": c4y += int.Parse(tb4.Rows[j]["num"].ToString()); break;
case "TOFD\\UT\\MT":
case "TOFD\\MT":
case "3D-TFM":
case "TOFD": c5y += int.Parse(tb4.Rows[j]["num"].ToString()); break;
case "PA": c6y += int.Parse(tb4.Rows[j]["num"].ToString()); break;
}
}
}
for (int j = 0; j < tb5.Rows.Count; j++)
{
if (tb1.Rows[i]["WorkAreaId"].ToString() == tb5.Rows[j]["WorkAreaId"].ToString() && tb1.Rows[i]["UnitId"].ToString() == tb5.Rows[j]["UnitId"].ToString())
{
switch (tb5.Rows[j]["DetectionTypeCode"].ToString())
{
case "RT\\UT":
case "RT": c1n += int.Parse(tb5.Rows[j]["num"].ToString()); break;
case "PT": c2n += int.Parse(tb5.Rows[j]["num"].ToString()); break;
case "MT": c3n += int.Parse(tb5.Rows[j]["num"].ToString()); break;
case "UT": c4n += int.Parse(tb5.Rows[j]["num"].ToString()); break;
case "TOFD\\UT\\MT":
case "TOFD\\MT":
case "3D-TFM":
case "TOFD": c5n += int.Parse(tb5.Rows[j]["num"].ToString()); break;
case "PA": c6n += int.Parse(tb5.Rows[j]["num"].ToString()); break;
}
}
}
tb1.Rows[i]["t1y"] = t1y;
tb1.Rows[i]["t2y"] = t2y;
tb1.Rows[i]["t3y"] = t3y;
tb1.Rows[i]["t4y"] = t4y;
tb1.Rows[i]["t5y"] = t5y;
tb1.Rows[i]["t6y"] = t6y;
tb1.Rows[i]["t1n"] = t1n;
tb1.Rows[i]["t2n"] = t2n;
tb1.Rows[i]["t3n"] = t3n;
tb1.Rows[i]["t4n"] = t4n;
tb1.Rows[i]["t5n"] = t5n;
tb1.Rows[i]["t6n"] = t6n;
tb1.Rows[i]["c1y"] = c1y;
tb1.Rows[i]["c2y"] = c2y;
tb1.Rows[i]["c3y"] = c3y;
tb1.Rows[i]["c4y"] = c4y;
tb1.Rows[i]["c5y"] = c5y;
tb1.Rows[i]["c6y"] = c6y;
tb1.Rows[i]["c1n"] = c1n;
tb1.Rows[i]["c2n"] = c2n;
tb1.Rows[i]["c3n"] = c3n;
tb1.Rows[i]["c4n"] = c4n;
tb1.Rows[i]["c5n"] = c5n;
tb1.Rows[i]["c6n"] = c6n;
}
}
this.Grid1.DataSource = tb1;
this.Grid1.DataBind();
}
#endregion
protected void Grid1_RowCommand(object sender, GridCommandEventArgs e)
{
object[] keys = Grid1.DataKeys[e.RowIndex];
string fileId = string.Empty;
if (keys == null)
{
return;
}
else
{
fileId = keys[0].ToString();
}
if (e.CommandName == "print")
{
var projectName = ProjectService.GetProjectNameByProjectId(CurrUser.LoginProjectId);
string dateStr = Grid1.Rows[e.RowIndex].Values[2].ToString();
Dictionary<string, string> keyValuePairs = new Dictionary<string, string>();
keyValuePairs.Add("projectName", projectName);
keyValuePairs.Add("dateStr", dateStr);
List<Base_Unit> units = UnitService.GetUnitByProjectIdUnitTypeList(this.CurrUser.LoginProjectId, Const.ProjectUnitType_5);
string unitName = "";
foreach (Base_Unit unit in units)
{
unitName += unit.UnitName + ",";
}
keyValuePairs.Add("unitName", unitName);
BLL.Common.FastReportService.ResetData();
BLL.Common.FastReportService.AddFastreportParameter(keyValuePairs);
var dates = dateStr.Split('至');
DateTime begin = DateTime.Parse(dates[0]);
DateTime end = DateTime.Parse(dates[1]);
string strSql1 = @"select unit.UnitId,unit.UnitName,workArea.WorkAreaName,workArea.WorkAreaCode,curr.curr_pass_film,curr.curr_total_film,recurr.recurr_pass_film,recurr.recurr_total_film, 0.0 curr_pass_rate,0.0 recurr_pass_rate
from Base_Unit unit right join
ProjectData_WorkArea workArea on workArea.UnitId=unit.UnitId
left join
( SELECT WorkAreaId,IsoInfo.UnitId,COUNT(*) AS curr_check_count_total
, SUM(cht_totalfilm) AS curr_total_film
, SUM(cht_passfilm) AS curr_pass_film
FROM CH_Check Checks
LEFT JOIN CH_CheckItem ON ch_checkitem.CHT_CheckID = Checks.CHT_CheckID
LEFT JOIN PW_JointInfo as JointInfo ON JointInfo.JOT_ID = ch_checkitem.JOT_ID
LEFT JOIN PW_IsoInfo as IsoInfo ON IsoInfo.ISO_ID = JointInfo.ISO_ID
where JointInfo.ProjectId=@ProjectId and (cht_checkdate >= @date1 OR @date1 IS NULL) and(cht_checkdate <= @date2 OR @date2 IS NULL)
group by WorkAreaId,IsoInfo.UnitId) as curr on unit.UnitId= curr.UnitId and workArea.WorkAreaId=curr.WorkAreaId
left join
( SELECT WorkAreaId,IsoInfo.UnitId,COUNT(*) AS recurr_check_count_total
, SUM(cht_totalfilm) AS recurr_total_film
, SUM(cht_passfilm) AS recurr_pass_film
FROM CH_Check Checks
LEFT JOIN CH_CheckItem ON ch_checkitem.CHT_CheckID = Checks.CHT_CheckID
LEFT JOIN PW_JointInfo as JointInfo ON JointInfo.JOT_ID = ch_checkitem.JOT_ID
LEFT JOIN PW_IsoInfo as IsoInfo ON IsoInfo.ISO_ID = JointInfo.ISO_ID
LEFT JOIN CH_Trust trust on trust.CH_TrustID = Checks.CH_TrustID
where JointInfo.ProjectId=@ProjectId and trust.CH_TrustType='2' and (cht_checkdate >= @date1 OR @date1 IS NULL) and(cht_checkdate <= @date2 OR @date2 IS NULL)
group by WorkAreaId,IsoInfo.UnitId) as recurr on unit.UnitId= recurr.UnitId and workArea.WorkAreaId=recurr.WorkAreaId
where workArea.ProjectId=@ProjectId ";
List<SqlParameter> listpar = new List<SqlParameter>
{
new SqlParameter("@projectId", this.CurrUser.LoginProjectId)
};
listpar.Add(new SqlParameter("@date1", begin.ToString("yyyy-MM-dd")));
listpar.Add(new SqlParameter("@date2", end.ToString("yyyy-MM-dd")));
SqlParameter[] parameter5 = listpar.ToArray();
DataTable dt = SQLHelper.GetDataTableRunText(strSql1, parameter5);
if (dt != null)
{
dt.TableName = "Table1";
foreach (DataRow row in dt.Rows)
{
try
{
row["curr_pass_rate"] =1.0 * int.Parse(row["curr_pass_film"].ToString()) / int.Parse(row["curr_total_film"].ToString());
}
catch (Exception e1)
{ }
try
{
row["recurr_pass_rate"] = 1.0 * int.Parse(row["recurr_pass_film"].ToString()) / int.Parse(row["recurr_total_film"].ToString());
}
catch (Exception e2)
{ }
}
}
BLL.Common.FastReportService.AddFastreportTable(dt);
string initTemplatePath = "";
string rootPath = Server.MapPath("~/");
initTemplatePath = "File\\Fastreport\\无损检测周报.frx";
if (File.Exists(rootPath + initTemplatePath))
{
PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("../TrustManage/Fastreport.aspx?ReportPath={0}", rootPath + initTemplatePath)));
}
}
}
#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("无损检测汇总" + 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();
MultiHeaderTable mht = new MultiHeaderTable();
mht.ResolveMultiHeaderTable(Grid1.Columns);
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;\">");
foreach (List<object[]> rows in mht.MultiTable)
{
sb.Append("<tr>");
foreach (object[] cell in rows)
{
int rowspan = Convert.ToInt32(cell[0]);
int colspan = Convert.ToInt32(cell[1]);
GridColumn column = cell[2] as GridColumn;
sb.AppendFormat("<th{0}{1}{2}>{3}</th>",
rowspan != 1 ? " rowspan=\"" + rowspan + "\"" : "",
colspan != 1 ? " colspan=\"" + colspan + "\"" : "",
colspan != 1 ? " style=\"text-align:center;\"" : "",
column.HeaderText);
}
sb.Append("</tr>");
}
int j = 0;
foreach (GridRow row in grid.Rows)
{
sb.Append("<tr>");
int i = 0;
foreach (GridColumn column in mht.Columns)
{
string html = row.Values[column.ColumnIndex].ToString();
if (column.ColumnID == "tfNumber")
{
html = (row.FindControl("labNumber1") as AspNet.Label).Text;
}
sb.AppendFormat("<td >{0}</td>", html);
i++;
}
j++;
sb.Append("</tr>");
}
var sumary = grid.SummaryData;
if (sumary != null)
{
sb.Append("<tr>");
foreach (GridColumn column in grid.Columns)
{
try
{
if (column is GroupField)
{
if (((GroupField)column).Columns != null)
{
foreach (var item in ((GroupField)column).Columns)
{
if (!column.Hidden)
{
if (sumary.ContainsKey(item.ColumnID))
{
sb.AppendFormat("<td style=\"text-align:center;vnd.ms-excel.numberformat:@\" >{0}</td>", sumary.GetValue(item.ColumnID).ToString());
}
else
{
sb.AppendFormat("<td style=\"text-align:center;vnd.ms-excel.numberformat:@\" >{0}</td>", "");
}
}
}
}
}
else if (column is RenderField)
{
if (!column.Hidden)
{
if (sumary.ContainsKey(column.ColumnID))
{
sb.AppendFormat("<td style=\"text-align:center;vnd.ms-excel.numberformat:@\" >{0}</td>", sumary.GetValue(column.ColumnID).ToString());
}
else
{
sb.AppendFormat("<td style=\"text-align:center;vnd.ms-excel.numberformat:@\" >{0}</td>", "");
}
}
}
else
{
if (!column.Hidden)
{
sb.AppendFormat("<td style=\"text-align:center;vnd.ms-excel.numberformat:@\" >{0}</td>", "");
}
}
}
catch (Exception e)
{
sb.AppendFormat("<td style=\"text-align:center;vnd.ms-excel.numberformat:@\" >{0}</td>", "");
}
}
sb.Append("</tr>");
}
sb.Append("</table>");
return sb.ToString();
}
#endregion
protected void BtnAnalyse_Click(object sender, EventArgs e)
{
BindGrid();
}
}
}