ZHJA_HJGL/HJGL_ZH/FineUIPro.Web/HJGL/WeldingReport/InspectionBatch.aspx.cs

450 lines
20 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.UI;
using System.IO;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using BLL;
namespace FineUIPro.Web.HJGL.WeldingReport
{
public partial class InspectionBatch : PageBase
{
#region
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
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.drpProjectId.SelectedValue = this.CurrUser.LoginProjectId;
ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
// 绑定表格
BindGrid();
}
}
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid()
{
string strSql = @"SELECT batch.BatchId,project.ProjectCode,project.ProjectName,ndtr.NDTR_Name, batch.BatchCloseDate,
batch.BatchStartDate, batch.BatchCode,batch.IsPrint
FROM dbo.HJGL_BO_Batch batch
LEFT JOIN dbo.Base_Project project ON project.ProjectId = batch.ProjectId
LEFT JOIN dbo.HJGL_BS_NDTRate ndtr ON ndtr.NDTR_ID = batch.NDTR_ID
WHERE batch.BatchCloseDate IS NOT NULL";
List<SqlParameter> listStr = new List<SqlParameter>();
if (this.drpProjectId.SelectedValue != null && this.drpProjectId.SelectedValue != "null")
{
strSql += " AND batch.ProjectId = @ProjectId";
listStr.Add(new SqlParameter("@ProjectId", this.drpProjectId.SelectedValue));
}
if (!string.IsNullOrEmpty(this.txtBatch.Text.Trim()))
{
strSql += " AND batch.BatchCode LIKE @BatchCode";
listStr.Add(new SqlParameter("@BatchCode", "%" + this.txtBatch.Text.Trim() + "%"));
}
if (this.rblPrint.SelectedValue == "1")
{
strSql += " AND batch.IsPrint=@IsPrint";
listStr.Add(new SqlParameter("@IsPrint", this.rblPrint.SelectedValue));
}
else
{
strSql += " AND (batch.IsPrint=@IsPrint OR batch.IsPrint IS NULL)";
listStr.Add(new SqlParameter("@IsPrint", this.rblPrint.SelectedValue));
}
strSql += " ORDER BY batch.BatchCode DESC";
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
Grid1.RecordCount = tb.Rows.Count;
//tb = GetFilteredTable(Grid1.FilteredData, tb);
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
//for (int i = 0; i < this.Grid1.Rows.Count; i++)
//{
// string batchId = this.Grid1.Rows[i].DataKeys[0].ToString();
// var batch = BLL.HJGL_BO_BatchService.GetBatchById(batchId);
// if (batch != null)
// {
// if (batch.IsPrint == true)
// {
// System.Web.UI.WebControls.CheckBox cbIsPrint1 = (System.Web.UI.WebControls.CheckBox)(this.Grid1.Rows[i].FindControl("cbIsPrint"));
// cbIsPrint1.Checked = true; //已打印
// }
// }
//}
}
#endregion
#region Grid
/// <summary>
/// Grid双击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("InspectionBatchItem.aspx?BatchId={0}", Grid1.SelectedRowID, "编辑 - ")));
}
#endregion
#region
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Text_TextChanged(object sender, EventArgs e)
{
BindGrid();
}
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void TextBox_TextChanged(object sender, EventArgs e)
{
BindGrid();
}
#endregion
#region
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
BindGrid();
}
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
BindGrid();
}
protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e)
{
Grid1.SortDirection = e.SortDirection;
Grid1.SortField = e.SortField;
BindGrid();
}
#endregion
#region
/// <summary>
/// 关闭弹出窗口刷新Grid
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
BindGrid();
}
#endregion
#region Grid1行点击事件
/// <summary>
/// Grid1行点击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_RowCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName == "print")//打印
{
//string varValue = string.Empty;
//string projectName = "NULL";
//string NDTR_Name = "NULL";
//string standName = "NULL";
//string batchCode=string.Empty;
//string batchId = this.Grid1.SelectedRow.RowID;
//if (!string.IsNullOrEmpty(batchId))
//{
// var batch = BLL.HJGL_BO_BatchService.GetBatchById(batchId);
// if (batch != null)
// {
// batchCode="(批次号:"+batch.BatchCode+")";
// batch.IsPrint = true;
// BLL.HJGL_BO_BatchService.UpdateBatch(batch);//更改已打印状态
// if (!string.IsNullOrEmpty(batch.ProjectId))
// {
// var project = BLL.Base_ProjectService.GetProjectByProjectId(batch.ProjectId);
// if (project != null)
// {
// projectName = project.ProjectName;//工程名称
// }
// }
// if (!string.IsNullOrEmpty(batch.ExecStandardId))
// {
// var stand = BLL.HJGL_ExecStandardService.GetExecStandardById(batch.ExecStandardId);
// if (stand != null)
// {
// standName = stand.ExecStandardName;
// }
// }
// if (!string.IsNullOrEmpty(batch.NDTR_ID))
// {
// var ndtr = BLL.HJGL_DetectionService.GetNDTRateByNDTRID(batch.NDTR_ID);
// if (ndtr != null)
// {
// NDTR_Name = ndtr.NDTR_Name;//检测比例
// }
// }
// }
//}
//List<SqlParameter> listStr = new List<SqlParameter>();
//listStr.Add(new SqlParameter("@BatchId", batchId));
//SqlParameter[] parameter = listStr.ToArray();
//DataTable dt = BLL.SQLHelper.GetDataTableRunProc("dbo.HJGL_rpt_RayCheckConfirm", parameter);
//string totalCounts = string.Empty;
//string chTotalCounts = string.Empty;
//string chFixedJotCounts = string.Empty;
//int totalCount = 0;
//int chTotalCount = 0;
//int chFixedJotCount = 0;
//string realCheckRate = string.Empty;
//for (int i = 0; i < dt.Rows.Count; i++)
//{
// if (dt.Rows[i]["totalCount"] != null)
// {
// totalCount = totalCount + Convert.ToInt32(dt.Rows[i]["totalCount"]);
// }
// if (dt.Rows[i]["CH_TotalCount"] != null)
// {
// chTotalCount = chTotalCount + Convert.ToInt32(dt.Rows[i]["CH_TotalCount"]);
// }
// if (dt.Rows[i]["CH_FixedJotCount"] != null)
// {
// chFixedJotCount = chFixedJotCount + Convert.ToInt32(dt.Rows[i]["CH_FixedJotCount"]);
// }
//}
//if (totalCount != 0)
//{
// realCheckRate = (chTotalCount * 100.0 / totalCount * 1.0).ToString("0.00") + "%";
//}
//totalCounts = totalCount.ToString();
//chTotalCounts = chTotalCount.ToString();
//chFixedJotCounts = chFixedJotCount.ToString();
//varValue = projectName + "|" + standName + "|" + NDTR_Name + "|" + totalCounts + "|" + chTotalCounts + "|" + chFixedJotCounts + "|" + realCheckRate + "|" + batchCode;
//varValue = HttpUtility.UrlEncodeUnicode(varValue);
//PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("../../Common/ReportPrint/ExReportPrint.aspx?ispop=1&reportId={0}&replaceParameter={1}&varValue={2}&projectId=0", BLL.Const.HJGL_RTCheckConfirmReportId, batchId, varValue, "打印 - ")));
string varValue = string.Empty;
string projectName = "NULL";
string NDTR_Name = "NULL";
string standName = "NULL";
string batchCode = string.Empty;
string batchCode2 = string.Empty;
string batchId = this.Grid1.SelectedRow.RowID;
if (!string.IsNullOrEmpty(batchId))
{
var batch = BLL.HJGL_BO_BatchService.GetBatchById(batchId);
if (batch != null)
{
batchCode = "(批次号:" + batch.BatchCode + ")";
batchCode2 = batch.BatchCode;
batch.IsPrint = true;
BLL.HJGL_BO_BatchService.UpdateBatch(batch);//更改已打印状态
if (!string.IsNullOrEmpty(batch.ProjectId))
{
var project = BLL.Base_ProjectService.GetProjectByProjectId(batch.ProjectId);
if (project != null)
{
projectName = project.ProjectName;//工程名称
}
}
if (!string.IsNullOrEmpty(batch.ExecStandardId))
{
var stand = BLL.HJGL_ExecStandardService.GetExecStandardById(batch.ExecStandardId);
if (stand != null)
{
standName = stand.ExecStandardName;
}
}
if (!string.IsNullOrEmpty(batch.NDTR_ID))
{
var ndtr = BLL.HJGL_DetectionService.GetNDTRateByNDTRID(batch.NDTR_ID);
if (ndtr != null)
{
NDTR_Name = ndtr.NDTR_Name;//检测比例
}
}
}
}
List<SqlParameter> listStr = new List<SqlParameter>();
listStr.Add(new SqlParameter("@BatchId", batchId));
SqlParameter[] parameter = listStr.ToArray();
DataTable dt = BLL.SQLHelper.GetDataTableRunProc("dbo.HJGL_rpt_RayCheckConfirmNew", parameter);
string oneTrustCounts = string.Empty;
string oneGTrustCounts = string.Empty;
string chFixedJotCounts = string.Empty;
string jointCounts = string.Empty;
string GjointCounts = string.Empty;
string needCheckCounts = string.Empty;
string totalWeldCounts = string.Empty;
string oneCheckCounts = string.Empty;
string totalCheckCounts = string.Empty;
int oneTrustCount = 0;
int oneGTrustCount = 0;
int chFixedJotCount = 0;
int jointCount = 0;
int GjointCount = 0;
int needCheckCount = 0;
int totalWeldCount = 0;
int totalCheckCount = 0;
string onetrustRate = string.Empty;
string oneGtrustRate = string.Empty;
string totalCheckRate = string.Empty;
for (int i = 0; i < dt.Rows.Count; i++)
{
if (dt.Rows[i]["OneTrustCount"] != null)
{
oneTrustCount = oneTrustCount + Convert.ToInt32(dt.Rows[i]["OneTrustCount"]);
}
if (dt.Rows[i]["totalTrustCount"] != null)
{
totalCheckCount = totalCheckCount + Convert.ToInt32(dt.Rows[i]["totalTrustCount"]);
}
}
totalCheckCounts = totalCheckCount.ToString();
jointCount = BLL.HJGL_BO_BatchDetailService.GetBatchDetailByBatchId(batchId).Count;
jointCounts = jointCount.ToString();
GjointCount = BLL.HJGL_BO_BatchDetailService.GetGBatchDetailByBatchId(batchId).Count;
GjointCounts = GjointCount.ToString();
if (jointCount != 0)
{
onetrustRate = (oneTrustCount * 100.0 / jointCount * 1.0).ToString("0.00") + "%";
}
oneTrustCounts = oneTrustCount.ToString();
oneGTrustCount = (from x in Funs.DB.HJGL_View_RayCheckConfirm
where x.JOT_JointNo.Contains("G") && x.BatchId == batchId && x.PointTypeStr == "1"
select x).Count();
oneGTrustCounts = oneGTrustCount.ToString();
if (GjointCount != 0)
{
oneGtrustRate = (oneGTrustCount * 100.0 / oneTrustCount * 1.0).ToString("0.00") + "%";
}
if (jointCount != 0)
{
totalCheckRate = (totalCheckCount * 100.0 / jointCount * 1.0).ToString("0.00") + "%";
}
chFixedJotCounts = chFixedJotCount.ToString();
needCheckCount = Convert.ToInt32(Math.Ceiling(jointCount * Convert.ToDecimal(NDTR_Name.Replace("%", "")) / 100));
needCheckCounts = needCheckCount.ToString();
totalWeldCount = (from x in Funs.DB.HJGL_BO_BatchDetail
join y in Funs.DB.HJGL_PW_JointInfo
on x.JOT_ID equals y.JOT_ID
where x.BatchId == batchId
select y.JOT_CellWelder + y.JOT_FloorWelder).Distinct().Count();
totalWeldCounts = totalWeldCount.ToString();
varValue = projectName + "|" + standName + "|" + NDTR_Name + "|" + oneTrustCounts + "|" + GjointCounts + "|" + oneGTrustCounts + "|" + onetrustRate + "|" + batchCode + "|" + batchCode2 + "|" + jointCounts + "|" + needCheckCounts + "|" + totalWeldCounts + "|" + oneGtrustRate + "|" + totalCheckCounts + "|" + totalCheckRate;
varValue = HttpUtility.UrlEncodeUnicode(varValue);
PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("../../Common/ReportPrint/ExReportPrint.aspx?ispop=1&reportId={0}&replaceParameter={1}&varValue={2}&projectId=0", BLL.Const.HJGL_RTCheckConfirmNewReportId, batchId, varValue, "打印 - ")));
}
}
#endregion
#region
/// <summary>
/// 打印、未打印筛选
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void rblPrint_SelectedIndexChanged(object sender, EventArgs e)
{
// 绑定表格
BindGrid();
}
#endregion
#region Grid行绑定事件
/// <summary>
/// Grid行绑定事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_RowDataBound(object sender, GridRowEventArgs e)
{
//int Scount = 0;
//int Zcount = 0;
//var inspectionBatchs = from x in Funs.DB.HJGL_View_InspectionBatch where x.BatchId == e.RowID select x;
var passNum = from x in Funs.DB.HJGL_CH_TrustItem
join y in Funs.DB.HJGL_BO_BatchDetail on x.BatchDetailId equals y.BatchDetailId
join z in Funs.DB.HJGL_BO_Batch on y.BatchId equals z.BatchId
where x.States=="2" && z.BatchId== e.RowID
select x;
var noPassNum = from x in Funs.DB.HJGL_CH_TrustItem
join y in Funs.DB.HJGL_BO_BatchDetail on x.BatchDetailId equals y.BatchDetailId
join z in Funs.DB.HJGL_BO_Batch on y.BatchId equals z.BatchId
where (x.States == "1" || x.States == "3"|| x.States == "4") && z.BatchId == e.RowID
select x;
if (passNum.Count() > 0 && noPassNum.Count() == 0)
{
e.RowCssClass = "color1";
}
//foreach (var item in inspectionBatchs)
//{
// if (item.TrustState == "待检测" || item.TrustState == "待重检" || item.TrustState == "待返修")
// {
// Scount++;
// }
// else if (item.TrustState == "检测合格")
// {
// Zcount++;
// }
//}
//if (Scount == 0 && Zcount > 0 && inspectionBatchs.Count() > 0)
//{
// e.RowCssClass = "color1";
//}
}
#endregion
protected void cbIsPrint_OnCheckedChanged(object sender, EventArgs e)
{
System.Web.UI.WebControls.CheckBox cbIsPrint = sender as System.Web.UI.WebControls.CheckBox;
for (int i = 0; i < this.Grid1.Rows.Count; i++)
{
System.Web.UI.WebControls.CheckBox cbIsPrint1 = (System.Web.UI.WebControls.CheckBox)(this.Grid1.Rows[i].FindControl("cbIsPrint"));
if (cbIsPrint1.ClientID == cbIsPrint.ClientID)
{
string batchId = Grid1.DataKeys[i][0].ToString();
var batch = BLL.HJGL_BO_BatchService.GetBatchById(batchId);
if (cbIsPrint.Checked)
{
batch.IsPrint = true;
Funs.DB.SubmitChanges();
}
else
{
batch.IsPrint = null;
Funs.DB.SubmitChanges();
}
}
}
}
}
}