using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using BLL;
using Newtonsoft.Json.Linq;
namespace FineUIPro.Web.HJGL.TrustManage
{
public partial class TrustManageItemEdit : PageBase
{
#region 定义项
///
/// 无损委托主键
///
public string CH_TrustID
{
get
{
return (string)ViewState["CH_TrustID"];
}
set
{
ViewState["CH_TrustID"] = value;
}
}
#endregion
#region 加载页面
///
/// 加载页面
///
///
///
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString();
this.CH_TrustID = Request.Params["TrustID"];
if (!string.IsNullOrEmpty(this.CH_TrustID))
{
var trust = BLL.HJGL_TrustManageEditService.GetCH_TrustByID(this.CH_TrustID);
if (trust != null)
{
///检测单位
this.drpCH_CheckUnit.DataTextField = "UnitName";
this.drpCH_CheckUnit.DataValueField = "UnitId";
this.drpCH_CheckUnit.DataSource = BLL.Base_UnitService.GetUnitsByProjectUnitType(trust.ProjectId, BLL.Const.UnitType_8);
this.drpCH_CheckUnit.DataBind();
Funs.FineUIPleaseSelect(this.drpCH_CheckUnit);
}
}
///合格等级
this.drpCH_AcceptGrade.DataTextField = "Text";
this.drpCH_AcceptGrade.DataValueField = "Value";
this.drpCH_AcceptGrade.DataSource = BLL.HJGL_TrustManageEditService.GetAcceptGradeList();
this.drpCH_AcceptGrade.DataBind();
Funs.FineUIPleaseSelect(this.drpCH_AcceptGrade);
///坡口类型
this.drpCH_SlopeType.DataTextField = "JST_Name";
this.drpCH_SlopeType.DataValueField = "JST_ID";
this.drpCH_SlopeType.DataSource = BLL.HJGL_GrooveService.GetSlopeTypeNameList();
this.drpCH_SlopeType.DataBind();
Funs.FineUIPleaseSelect(this.drpCH_SlopeType);
///焊接方法
this.drpCH_WeldMethod.DataTextField = "WME_Name";
this.drpCH_WeldMethod.DataValueField = "WME_ID";
this.drpCH_WeldMethod.DataSource = BLL.HJGL_WeldingMethodService.GetWeldMethodNameList();
this.drpCH_WeldMethod.DataBind();
Funs.FineUIPleaseSelect(this.drpCH_WeldMethod);
///检测标准
this.drpCH_NDTCriteria.DataTextField = "TestStandardCode";
this.drpCH_NDTCriteria.DataValueField = "TestStandardCode";
this.drpCH_NDTCriteria.DataSource = BLL.HJGL_TestStandardService.GetTestStandardNameList();
this.drpCH_NDTCriteria.DataBind();
Funs.FineUIPleaseSelect(this.drpCH_NDTCriteria);
this.PageInfoLoad(); ///加载页面
}
}
#endregion
#region 加载页面输入提交信息
///
/// 加载页面输入提交信息
///
private void PageInfoLoad()
{
var trust = BLL.HJGL_TrustManageEditService.GetCH_TrustByID(this.CH_TrustID);
if (trust != null)
{
var ndtInfo = BLL.HJGL_TestingService.GetTestingByTestingId(trust.CH_NDTMethod);
this.lblCH_TrustCode.Text = trust.CH_TrustCode;
if (!string.IsNullOrEmpty(trust.CH_TrustUnit))
{
var unit = BLL.Base_UnitService.GetUnit(trust.CH_TrustUnit);
if (unit != null)
{
this.hdCH_TrustUnitId.Text = unit.UnitId;
this.lblCH_TrustUnit.Text = unit.UnitName;
}
}
if (!string.IsNullOrEmpty(trust.InstallationId))
{
var installation = BLL.Project_InstallationService.GetInstallationByInstallationId(trust.InstallationId);
if (installation != null)
{
this.hdCH_InstallationId.Text = installation.InstallationId;
this.lblInstallationName.Text = installation.InstallationName;
}
}
this.lblCH_TrustDate.Text = string.Format("{0:yyyy-MM-dd}", trust.CH_TrustDate);
if (!string.IsNullOrEmpty(trust.CH_TrustMan))
{
var user = BLL.Sys_UserService.GetUsersByUserId(trust.CH_TrustMan);
if (user != null)
{
this.lblCH_TrustMan.Text = user.UserName;
}
}
if (!string.IsNullOrEmpty(trust.CH_CheckUnit))
{
this.drpCH_CheckUnit.SelectedValue = trust.CH_CheckUnit;
}
if (!string.IsNullOrEmpty(trust.CH_NDTMethod))
{
var ndtMethod = BLL.HJGL_TestingService.GetTestingByTestingId(trust.CH_NDTMethod);
if (ndtMethod != null)
{
this.lblCH_NDTMethod.Text = ndtMethod.NDT_Name;
}
}
if (!string.IsNullOrEmpty(trust.CH_AcceptGrade))
{
var jot = from x in Funs.DB.HJGL_PW_JointInfo
join y in Funs.DB.HJGL_CH_TrustItem on x.JOT_ID equals y.JOT_ID
where y.CH_TrustID == this.CH_TrustID
select x;
if (jot.Count() > 0)
{
var joty = BLL.HJGL_WeldService.GetJointTypeByID(jot.First().JOTY_ID);
if ((ndtInfo.NDT_Code == "MT" || ndtInfo.NDT_Code == "PT") && joty.JOTY_Group == "1")
{
this.drpCH_AcceptGrade.Text = "Ⅰ";
}
else
{
this.drpCH_AcceptGrade.Text = (from x in Funs.DB.HJGL_PW_JointInfo
join y in Funs.DB.HJGL_CH_TrustItem on x.JOT_ID equals y.JOT_ID
where y.CH_TrustID == this.CH_TrustID
select x.JOT_QualifiedLevel).FirstOrDefault();
}
}
//this.drpCH_AcceptGrade.SelectedValue = trust.CH_AcceptGrade;
}
if (!string.IsNullOrEmpty(trust.CH_NDTCriteria))
{
this.drpCH_NDTCriteria.SelectedValue = trust.CH_NDTCriteria;
}
else
{
this.drpCH_NDTCriteria.SelectedValue = "NB/T 47013-2015";
}
if (!string.IsNullOrEmpty(trust.CH_SlopeType))
{
this.drpCH_SlopeType.SelectedValue = trust.CH_SlopeType;
}
if (!string.IsNullOrEmpty(trust.CH_WeldMethod))
{
this.drpCH_WeldMethod.SelectedValue = trust.CH_WeldMethod;
}
this.txtCH_Remark.Text = trust.CH_Remark;
if (!string.IsNullOrEmpty(trust.BatchId))
{
var batch = BLL.HJGL_BO_BatchService.GetBatchById(trust.BatchId);
if (batch != null)
{
if (!string.IsNullOrEmpty(batch.NDTR_ID))//探伤比例
{
var ndt = BLL.HJGL_DetectionService.GetNDTRateByNDTRID(batch.NDTR_ID);
if (ndt != null)
{
this.lblCH_NDTRate.Text = ndt.NDTR_Name;
}
}
if (!string.IsNullOrEmpty(batch.InstallationId))//装置
{
var installation = BLL.Project_InstallationService.GetInstallationByInstallationId(batch.InstallationId);
if (installation != null)
{
this.hdCH_InstallationId.Text = installation.InstallationId;
this.lblInstallationName.Text = installation.InstallationName;
}
}
}
}
//if (!string.IsNullOrEmpty(trust.ISO_ID))
//{
// var isoInfo = BLL.HJGL_PW_IsoInfoService.GetIsoInfoByIsoInfoId(trust.ISO_ID);
// if (isoInfo!=null)
// {
// this.lblIsoNo.Text = isoInfo.ISO_IsoNo;
// }
// var jointInfo = Funs.DB.HJGL_PW_JointInfo.FirstOrDefault(e=>e.ISO_ID==trust.ISO_ID);
// if (jointInfo != null)
// {
// if (!string.IsNullOrEmpty(jointInfo.JST_ID))
// {
// this.drpCH_SlopeType.SelectedValue = jointInfo.JST_ID;
// }
// if (!string.IsNullOrEmpty(jointInfo.WME_ID))
// {
// this.drpCH_WeldMethod.SelectedValue = jointInfo.WME_ID;
// }
// }
//}
this.BindGrid(); ////初始化页面
}
}
#endregion
#region 数据绑定
///
/// 数据绑定
///
private void BindGrid()
{
string strSql = @"SELECT TrustItem.CH_TrustItemID
,TrustItem.CH_TrustID
,TrustItem.JOT_ID
,TrustItem.CHT_CheckItemId
,TrustItem.CH_CheckMethod
,TrustItem.CH_UnitNo
,TrustItem.CH_CheckResult
,TrustItem.CH_RepairLocation
,(CASE WHEN (TrustItem.CH_Remark IS NULL OR TrustItem.CH_Remark='') AND jotR.JOT_JointNo IS NOT NULL
THEN isoR.ISO_IsoNo+','+jotR.JOT_JointNo+' 返修' ELSE TrustItem.CH_Remark END) AS CH_Remark
,IsoInfo.ISO_IsoNo
,(CASE WHEN batchDetail.PointType=2 THEN JointInfo.JOT_JointNo+'K' ELSE JointInfo.JOT_JointNo END) AS JOT_JointNo
,CAST(JointInfo.JOT_Dia AS Decimal(18,2)) AS JOT_Dia
,JointInfo.JOT_Sch
,JointInfo.WLO_Code
,WeldMethod.WME_Name
,batch.BatchCode
FROM HJGL_CH_TrustItem AS TrustItem
LEFT JOIN HJGL_CH_Trust AS Trust ON Trust.CH_TrustID = TrustItem.CH_TrustID
LEFT JOIN dbo.HJGL_PW_JointInfo AS JointInfo ON JointInfo.JOT_ID = TrustItem.JOT_ID
LEFT JOIN dbo.HJGL_PW_IsoInfo AS IsoInfo ON JointInfo.ISO_ID = IsoInfo.ISO_ID
LEFT JOIN dbo.HJGL_BS_WeldMethod AS WeldMethod ON WeldMethod.WME_ID=JointInfo.WME_ID
LEFT JOIN dbo.HJGL_BO_Batch AS batch ON batch.BatchId=Trust.BatchId
LEFT JOIN dbo.HJGL_BO_BatchDetail AS batchDetail ON batchDetail.BatchDetailId = TrustItem.BatchDetailId
LEFT JOIN dbo.HJGL_CH_RepairItemRecord AS repair ON batchDetail.ToRepairId=repair.RepairItemRecordId
LEFT JOIN dbo.HJGL_PW_JointInfo AS jotR ON jotR.JOT_ID = repair.JOT_ID
LEFT JOIN dbo.HJGL_PW_IsoInfo AS isoR ON isoR.ISO_ID = repair.ISO_ID
WHERE TrustItem.CH_TrustID=@CH_TrustID";
List listStr = new List();
listStr.Add(new SqlParameter("@CH_TrustID", this.CH_TrustID));
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
// 2.获取当前分页数据
//var table = this.GetPagedDataTable(Grid1, tb1);
Grid1.RecordCount = tb.Rows.Count;
tb = GetFilteredTable(Grid1.FilteredData, tb);
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
}
#endregion
#region 分页排序
#region 页索引改变事件
///
/// 页索引改变事件
///
///
///
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
this.BindGrid();
}
#endregion
#region 排序
///
/// 排序
///
///
///
protected void Grid1_Sort(object sender, GridSortEventArgs e)
{
this.BindGrid();
}
#endregion
#region 分页选择下拉改变事件
///
/// 分页选择下拉改变事件
///
///
///
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
//this.CollectGridJointInfo();
this.BindGrid();
//this.ShowGridItem();
}
#endregion
#endregion
#region 无损委托 提交事件
///
/// 编辑无损委托
///
///
///
protected void btnSave_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_TrustManageEditMenuId, Const.BtnSave))
{
var newTrust = BLL.HJGL_TrustManageEditService.GetCH_TrustByID(this.CH_TrustID);
if (this.drpCH_CheckUnit.SelectedValue == BLL.Const._Null)
{
Alert.ShowInTop("请选择检测单位!", MessageBoxIcon.Warning);
return;
}
if (this.drpCH_NDTCriteria.SelectedValue != BLL.Const._Null)
{
newTrust.CH_NDTCriteria = this.drpCH_NDTCriteria.SelectedValue;
}
if (this.drpCH_SlopeType.SelectedValue != BLL.Const._Null)
{
newTrust.CH_SlopeType = this.drpCH_SlopeType.SelectedValue;
}
if (this.drpCH_AcceptGrade.SelectedValue != BLL.Const._Null)
{
newTrust.CH_AcceptGrade = this.drpCH_AcceptGrade.SelectedValue;
}
newTrust.CH_Remark = this.txtCH_Remark.Text.Trim();
if (this.drpCH_WeldMethod.SelectedValue != BLL.Const._Null)
{
newTrust.CH_WeldMethod = this.drpCH_WeldMethod.SelectedValue;
}
if (this.drpCH_CheckUnit.SelectedValue != BLL.Const._Null)
{
newTrust.CH_CheckUnit = this.drpCH_CheckUnit.SelectedValue;
}
newTrust.CH_TrustType = "1";
//this.CollectGridJointInfo();
if (!string.IsNullOrEmpty(this.CH_TrustID))
{
newTrust.CH_TrustID = this.CH_TrustID;
BLL.HJGL_TrustManageEditService.UpdateCH_Trust(newTrust);
//BLL.HJGL_TrustManageEditService.DeleteCH_TrustItemByCH_TrustID(this.CH_TrustID);
BLL.Sys_LogService.AddLog(BLL.Const.System_3, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "修改委托单信息");
JArray mergedData = Grid1.GetMergedData();
if (mergedData.Count > 0)
{
int i = 0;
foreach (JObject mergedRow in mergedData)
{
JObject values = mergedRow.Value("values");
if (!string.IsNullOrEmpty(values.Value("CH_Remark")))
{
string rowID = Grid1.DataKeys[i][0].ToString();
Model.HJGL_CH_TrustItem update = BLL.HJGL_TrustManageEditService.GetCH_TrustItemById(rowID);
update.CH_Remark = values.Value("CH_Remark").ToString();
Funs.DB.SubmitChanges();
}
i++;
}
}
}
//foreach (var item in listSelects)
//{
// List list = Funs.GetStrListByStr(item, '|');
// var newJointInfo = BLL.HJGL_PW_JointInfoService.GetJointInfoByJotID(list[0].ToString());
// if (newJointInfo != null)
// {
// Model.HJGL_CH_TrustItem newitem = new Model.HJGL_CH_TrustItem();
// newitem.CH_TrustID = this.CH_TrustID;
// newitem.JOT_ID = newJointInfo.JOT_ID;
// newitem.CH_Remark = list[1].ToString();
// BLL.HJGL_TrustManageEditService.AddCH_TrustItem(newitem);
// BLL.HJGL_TrustManageEditService.UpdateJOT_TrustFlag(newitem.JOT_ID, "1"); ///更新焊接委托标志
// }
//}
ShowNotify("提交成功!", MessageBoxIcon.Success);
PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
}
else
{
ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
return;
}
}
#endregion
//#region 收集Grid页面信息
/////
///// 收集Grid页面信息
/////
/////
//private void CollectGridJointInfo()
//{
// for (int i = 0; i < Grid1.Rows.Count; i++)
// {
// string rowID = Grid1.DataKeys[i][0].ToString();
// //for (int j = listSelects.Count() - 1; j >= 0; j--)
// //{
// // List list = Funs.GetStrListByStr(listSelects[j], '|');
// // if (list[0].ToString() == rowID)
// // {
// // listSelects.Remove(listSelects[j]);
// // }
// //}
// if (checkField.GetCheckedState(i))
// {
// string item = rowID + "|" + Grid1.Rows[i].Values[8].ToString();
// listSelects.Add(item);
// }
// }
//}
//#endregion
//#region Grid 明细操作事件
/////
///// 全选
/////
/////
/////
//protected void btnAllSelect_Click(object sender, EventArgs e)
//{
// for (int i = 0; i < Grid1.Rows.Count; i++)
// {
// string rowID = Grid1.DataKeys[i][0].ToString();
// var itemList = listSelects.FirstOrDefault(x => x.Contains(rowID));
// if (itemList == null)
// {
// string item = rowID + "|" + Grid1.Rows[i].Values[8].ToString();
// listSelects.Add(item);
// }
// }
// this.ShowGridItem();
//}
/////
///// 全不选
/////
/////
/////
//protected void btnNoSelect_Click(object sender, EventArgs e)
//{
// for (int i = 0; i < Grid1.Rows.Count; i++)
// {
// string rowID = Grid1.DataKeys[i][0].ToString();
// var itemList = listSelects.FirstOrDefault(x => x.Contains(rowID));
// if (itemList != null)
// {
// listSelects.Remove(itemList);
// }
// }
// this.ShowGridItem();
//}
//#endregion
//#region 只显示选中项
/////
///// 只显示选中项
/////
/////
/////
//protected void ckSelect_OnCheckedChanged(object sender, CheckedEventArgs e)
//{
// this.CollectGridJointInfo();
// this.BindGrid();
// this.ShowGridItem();
//}
//#endregion
//#region 合格等级下拉框
/////
///// 合格等级下拉框
/////
/////
/////
//protected void drpCH_AcceptGrade_SelectedIndexChanged(object sender, EventArgs e)
//{
// this.txtCH_NDTCriteria.Text = "JB/T4730-2005";
// if (this.drpCH_AcceptGrade.SelectedValue != BLL.Const._Null)
// {
// txtCH_NDTCriteria.Text = "JB/T4730-2005" + "(" + this.drpCH_AcceptGrade.SelectedItem.Text + ")";
// }
//}
//#endregion
}
}