using BLL;
using FineUIPro.Web.HJGL.CheckManage;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace FineUIPro.Web.YLRQ.TestDataManagement
{
public partial class PTReportEdit : PageBase
{
#region 定义项
///
/// 主键
///
private string TestingReportPrintId
{
get
{
return (string)ViewState["TestingReportPrintId"];
}
set
{
ViewState["TestingReportPrintId"] = value;
}
}
///
/// 检测报告Id
///
private string ReportPrintId
{
get
{
return (string)ViewState["ReportPrintId"];
}
set
{
ViewState["ReportPrintId"] = value;
}
}
///
/// 规格
///
private string Specifications
{
get
{
return (string)ViewState["Specifications"];
}
set
{
ViewState["Specifications"] = value;
}
}
///
/// 检测类型主键
///
private string NDT_ID
{
get
{
return (string)ViewState["NDT_ID"];
}
set
{
ViewState["NDT_ID"] = value;
}
}
///
/// 委托单
///
private string EntrustId
{
get
{
return (string)ViewState["EntrustId"];
}
set
{
ViewState["EntrustId"] = value;
}
}
///
/// 焊缝主键
///
private string WeldingId
{
get
{
return (string)ViewState["WeldingId"];
}
set
{
ViewState["WeldingId"] = value;
}
}
#endregion
#region 加载
///
/// 加载页面
///
///
///
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
#region 加载下拉选择项
//检测时机
this.drpTestingTime.DataValueField = "ConstValue";
this.drpTestingTime.DataTextField = "ConstText";
this.drpTestingTime.DataSource = BLL.ConstValue.drpConstItemList(BLL.ConstValue.Group_TestingTime);
this.drpTestingTime.DataBind();
Funs.FineUIPleaseSelect(this.drpTestingTime);
//热处理状态
this.drpHotProessState.DataValueField = "ConstValue";
this.drpHotProessState.DataTextField = "ConstText";
this.drpHotProessState.DataSource = BLL.ConstValue.drpConstItemList(BLL.ConstValue.Group_HotProessState);
this.drpHotProessState.DataBind();
Funs.FineUIPleaseSelect(this.drpHotProessState);
#endregion
this.ReportPrintId = HttpUtility.UrlDecode(Request.Params["reportPrintId"]);
if (!string.IsNullOrEmpty(this.ReportPrintId))
{
WeldingId = ReportPrintId.Split('|')[0];
Specifications = ReportPrintId.Split('|')[1];
NDT_ID = ReportPrintId.Split('|')[2];
EntrustId = ReportPrintId.Split('|')[3];
string WeldingCode = ReportPrintId.Split('|')[4];
var trust = Funs.DB.PV_EntrustRecord.FirstOrDefault(p => p.Id == EntrustId);
var pro = Funs.DB.Base_Project.FirstOrDefault(s => s.ProjectId == trust.ProjectId);
var weld = Funs.DB.PV_WeldInformation.FirstOrDefault(p => p.WeldingId == WeldingId);
this.txtCH_TrustUnit.Text = "舟山分公司";
this.txtContractUnit.Text = "镇海石化建安工程有限公司";
if (weld != null)
{
this.txtWeldingCode.Text = weld.WeldingCode;
this.txtIso_No.Text = weld.WeldingCode;//焊缝名称(添加的时候没有用到此字段,暂时赋这个值)
var ste = Funs.DB.HJGL_BS_Steel.FirstOrDefault(s => s.STE_ID == weld.TextureMaterial1);
if (ste != null)
{
this.txtSteelCode.Text = ste.STE_Code;
}
var ndt = Funs.DB.PV_TestMethod.FirstOrDefault(p => p.Ndt_Id == this.NDT_ID);
if (ndt != null)
{
this.txtNDTR_Name.Text = ndt.Ndt_NdtName;
this.txtCH_NDTCriteria.Text = ndt.Ndt_TestStandardCode;
this.txtCH_AcceptGrade.Text = ndt.Ndt_Level;
}
var wme = Funs.DB.HJGL_BS_WeldMethod.FirstOrDefault(p => p.WME_ID == Request.Params["WME_ID"]);
if (wme != null)
{
this.txtWME_Name.Text = wme.WME_Name;
}
}
this.txtTestMethod.Text = "ⅡC-d";//检测方法
this.txtSpecifications.Text = Specifications;//检件规格
this.drpHotProessState.Text = "消应力";//热处理状态
this.txtPenetrantGrade.Text = "DPT-5A";//渗透剂牌号
this.txtCleaningGrade.Text = "DPT-5A";//清洗剂牌号
this.txtImagingGrade.Text = "DPT-5A";//显像剂牌号
this.txtImposingMethod.Text = "喷洒";//施加方法
this.txtObservationMethod.Text = "目视";//观察方法
this.txtSensitivityTestBlock.Text = "C级";//检测灵敏度
this.txtTestBlock.Text = "B型";//检测试块
this.txtSurfaceState.Text = "机械打磨";//表面状态
this.drpTestingTime.Text = "焊后";
this.txtOsmoticTemperature.Text = " ℃";
this.txtPermeationTime.Text = " min";
this.txtImagingTime.Text = " min";
var ptReport = Funs.DB.PV_CH_TestingReportPrint.FirstOrDefault(s => s.Specifications == Specifications && s.NdtId == NDT_ID && s.EntrustId == EntrustId && s.STE_ID == Request.Params["STE_ID"] && s.STE_ID2 == Request.Params["STE_ID2"] && s.WME_ID == Request.Params["WME_ID"]);
if (ptReport != null)
{
this.txtContractUnit.Text = ptReport.ContractUnitId;
this.TestingReportPrintId = ptReport.TestingReportPrintId;
if (!string.IsNullOrEmpty(ptReport.ReportCode) && ptReport.ReportCode.Length > 3)
{
this.txtPTReportCode.Text = ptReport.ReportCode.Substring(3);//报告编号
}
else
{
this.txtPTReportCode.Text = ptReport.ReportCode;
}
this.hdReportCode.Text = ptReport.ReportCode;
this.txtSurfaceState.Text = ptReport.PT_SurfaceState;//表面状态
this.txtPenetrantGrade.Text = ptReport.PT_PenetrantGrade;//渗透剂牌号
this.txtCleaningGrade.Text = ptReport.PT_CleaningGrade;//清洗剂牌号
this.txtImagingGrade.Text = ptReport.PT_ImagingGrade;//显像剂牌号
this.txtOsmoticTemperature.Text = ptReport.PT_OsmoticTemperature;//渗透温度
this.txtImposingMethod.Text = ptReport.PT_ImposingMethod;//施加方法
this.txtObservationMethod.Text = ptReport.PT_ObservationMethod;//观察方法
this.txtSensitivityTestBlock.Text = ptReport.PT_SensitivityTestBlock;//灵敏度试块
this.txtPermeationTime.Text = ptReport.PT_PermeationTime;//渗透时间
this.txtImagingTime.Text = ptReport.PT_ImagingTime;//显像时间
this.drpTestingTime.Text = ptReport.TestingTime;
this.txtPrinter.Text = ptReport.Printer;//打印人
this.txtPrintTime.Text = string.Format("{0:yyyy-MM-dd}", ptReport.PrintTime);//打印时间
if (!string.IsNullOrEmpty(this.txtPrinter.Text.Trim()) && !string.IsNullOrEmpty(this.txtPrintTime.Text.Trim()))
{
this.cbIsPrint.Checked = true;
}
this.drpHotProessState.Text = ptReport.HotProessState;
}
else
{
this.hdReportCode.Text = BLL.SQLHelper.RunProcNewIdByProjectId("SpGetNewCodeByProjectId3", "PV_CH_TestingReportPrint", "ReportCode", pro.ProjectId, "PT-" + pro.TestEngineeringCode + "-");
this.txtPTReportCode.Text = this.hdReportCode.Text.Substring(3);
this.txtContractUnit.Text = "镇海石化建安工程有限公司";
}
BindGrid();
}
}
}
#endregion
#region 提交
///
/// 提交按钮
///
///
///
protected void btnSave_Click(object sender, EventArgs e)
{
var p = Funs.DB.PV_EntrustRecord.FirstOrDefault(s => s.Id == EntrustId);
Model.PV_CH_TestingReportPrint newPTReport = new Model.PV_CH_TestingReportPrint();
newPTReport.WeldingId = this.WeldingId;
if (!string.IsNullOrEmpty(this.TestingReportPrintId))
{
newPTReport = Funs.DB.PV_CH_TestingReportPrint.FirstOrDefault(s => s.TestingReportPrintId == this.TestingReportPrintId);
}
if (p != null)
{
newPTReport.ProjectId = p.ProjectId;
}
newPTReport.Specifications = this.Specifications;
newPTReport.JotyName = this.txtIso_No.Text;
newPTReport.NdtId = this.NDT_ID;
newPTReport.EntrustId = this.EntrustId;
newPTReport.ReportCode = this.hdReportCode.Text.Trim();
newPTReport.ContractUnitId = this.txtContractUnit.Text.Trim();
newPTReport.PT_SurfaceState = this.txtSurfaceState.Text.Trim();
newPTReport.PT_PenetrantGrade = this.txtPenetrantGrade.Text.Trim();
newPTReport.PT_CleaningGrade = this.txtCleaningGrade.Text.Trim();
newPTReport.PT_ImagingGrade = this.txtImagingGrade.Text.Trim();
newPTReport.PT_OsmoticTemperature = this.txtOsmoticTemperature.Text.Trim();
newPTReport.PT_ImposingMethod = this.txtImposingMethod.Text.Trim();
newPTReport.PT_ObservationMethod = this.txtObservationMethod.Text.Trim();
newPTReport.PT_SensitivityTestBlock = this.txtSensitivityTestBlock.Text.Trim();
newPTReport.TestBlock = this.txtTestBlock.Text.Trim();
newPTReport.PT_PermeationTime = this.txtPermeationTime.Text.Trim();
newPTReport.PT_ImagingTime = this.txtImagingTime.Text.Trim();
newPTReport.Printer = this.txtPrinter.Text.Trim();
newPTReport.PrintTime = Funs.GetNewDateTime(this.txtPrintTime.Text.Trim());
if (this.drpTestingTime.SelectedValue != BLL.Const._Null)
{
if (!string.IsNullOrEmpty(this.drpTestingTime.Text.Trim()))
{
newPTReport.TestingTime = this.drpTestingTime.Text.Trim();
}
else
{
newPTReport.TestingTime = this.drpTestingTime.SelectedValue;
}
}
if (this.drpHotProessState.SelectedValue != BLL.Const._Null)
{
if (!string.IsNullOrEmpty(this.drpHotProessState.Text.Trim()))
{
newPTReport.HotProessState = this.drpHotProessState.Text.Trim();
}
else
{
newPTReport.HotProessState = this.drpHotProessState.SelectedValue;
}
}
newPTReport.STE_ID = Request.Params["STE_ID"];
newPTReport.STE_ID2 = Request.Params["STE_ID2"];
newPTReport.WME_ID = Request.Params["WME_ID"];
if (string.IsNullOrEmpty(this.TestingReportPrintId))
{
newPTReport.Type = "PT";
this.TestingReportPrintId = SQLHelper.GetNewID(typeof(Model.PV_CH_TestingReportPrint));
newPTReport.TestingReportPrintId = this.TestingReportPrintId;
Funs.DB.PV_CH_TestingReportPrint.InsertOnSubmit(newPTReport);
}
Funs.DB.SubmitChanges();
ShowNotify("提交成功!", MessageBoxIcon.Success);
PageContext.RegisterStartupScript(ActiveWindow.GetHideReference());
}
#endregion
#region 绑定数据
///
/// 绑定数据
///
private void BindGrid()
{
string strSql = @"SELECT QualityRating.QualityRatingId,
QualityRating.MethodId,
QualityRating.WeldingId,
test.Ndt_NdtCode,
JointInfo.JointDesc,
JointInfo.WeldingCode,
QualityRating.FilmNum,
(select a.pkidStr from (SELECT STUFF(( SELECT ',' +convert(VARCHAR, WED_Code) FROM (select Welder.WED_Code from HJGL_BS_Welder as Welder where Welder.WED_ID in (select Id from StrToTable(JointInfo.BackingWelderId)))t FOR XML PATH('')), 1, 1, '') AS pkidStr) a)+','+(select a.pkidStr from (SELECT STUFF(( SELECT ',' +convert(VARCHAR, WED_Code) FROM (select Welder.WED_Code from HJGL_BS_Welder as Welder where Welder.WED_ID in (select Id from StrToTable(JointInfo.CoverWelderId)))t FOR XML PATH('')), 1, 1, '') AS pkidStr) a) as WED_Code,
QualityRating.DefectNature,
QualityRating.DefectSize,
QualityRating.DefectResult,
QualityRating.Remark
FROM dbo.PV_BO_QualityRating AS QualityRating
left join PV_ManagementMethod as record on record.MethodId=QualityRating.MethodId
LEFT JOIN dbo.PV_EntrustRecord trust ON trust.Id = record.EntrustId
LEFT JOIN DBO.PV_WeldInformation AS JointInfo ON JointInfo.WeldingId=QualityRating.WeldingId
left join PV_TestMethod as test on test.Ndt_Id=trust.NdtId
WHERE QualityRating.WeldingId=@WeldingId
AND JointInfo.JointDesc=@JointDesc
AND JointInfo.TextureMaterial1=@STE_ID AND (JointInfo.TextureMaterial2=@STE_ID2 or @STE_ID2='')
AND JointInfo.WmeId=@WME_ID
AND trust.NdtId = @NDT
AND trust.Id=@EntrustId";
List listStr = new List();
listStr.Add(new SqlParameter("@WeldingId", this.WeldingId));
listStr.Add(new SqlParameter("@JointDesc", this.Specifications));
listStr.Add(new SqlParameter("@STE_ID", Request.Params["STE_ID"]));
listStr.Add(new SqlParameter("@STE_ID2", Request.Params["STE_ID2"]));
listStr.Add(new SqlParameter("@WME_ID", Request.Params["WME_ID"]));
listStr.Add(new SqlParameter("@NDT", this.NDT_ID));
listStr.Add(new SqlParameter("@EntrustId", this.EntrustId));
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();
}
#endregion
#region 分页排序
///
/// 页索引改变事件
///
///
///
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
BindGrid();
}
///
/// 排序
///
///
///
protected void Grid1_Sort(object sender, GridSortEventArgs e)
{
BindGrid();
}
///
/// 分页选择下拉改变事件
///
///
///
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
BindGrid();
}
#endregion
#region 是否打印点击事件
///
/// 是否打印点击事件
///
///
///
protected void cbIsPrint_CheckedChanged(object sender, CheckedEventArgs e)
{
if (this.cbIsPrint.Checked == false)
{
this.txtPrinter.Text = string.Empty;
this.txtPrintTime.Text = string.Empty;
}
}
#endregion
}
}