using BLL;
using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace FineUIPro.Web.YLRQ.HotProessManage
{
public partial class HotProessTrustItemEdit : PageBase
{
#region 定义项
///
/// 项目主键
///
public string ProjectId { get { return (string)ViewState["ProjectId"]; } set { ViewState["ProjectId"] = value; } }
///
/// 单位主键
///
public string UnitId { get { return (string)ViewState["UnitId"]; } set { ViewState["UnitId"] = value; } }
///
/// 热处理委托主键
///
public string HotProessTrustId { get { return (string)ViewState["HotProessTrustId"]; } set { ViewState["HotProessTrustId"] = value; } }
///
/// 选择内容字符串
///
public string ItemsString { get { return (string)ViewState["ItemsString"]; } set { ViewState["ItemsString"] = value; } }
#endregion
#region 加载页面
///
/// 加载页面
///
///
///
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ItemsString = string.Empty;
string strList = Request.Params["strList"];
List list = Funs.GetStrListByStr(strList, '|');
if (list.Count() == 3)
{
this.UnitId = list[0];
this.HotProessTrustId = list[1];
this.ProjectId = list[2];
this.InitTreeMenu();//加载树
}
}
}
#endregion
#region 加载管线信息
///
/// 加载树
///
private void InitTreeMenu()
{
this.tvControlItem.Nodes.Clear();
TreeNode rootNode = new TreeNode();
rootNode.Text = "施工号";
rootNode.NodeID = "0";
rootNode.ToolTip = "绿色表示焊缝编号下有已焊接的焊口未委托热处理";
rootNode.Expanded = true;
this.tvControlItem.Nodes.Add(rootNode);
var hotProessItems = from x in Funs.DB.PV_CH_HotProessTrustItem select x;
var project = Funs.DB.Base_Project.FirstOrDefault(p => p.ProjectId == this.ProjectId);
var jots = Funs.DB.PV_View_HotWeldInformation.Where(p => p.ProjectId == this.ProjectId && p.HeatTreatmentType != null);
if (jots.Count() > 0)
{
TreeNode newNode = new TreeNode();
newNode.NodeID = this.ProjectId;
bool isHotProess = true; //默认已完成热处理委托
foreach (var item in jots)
{
string[] strs = item.HeatTreatmentType.Split('|');
if (strs.Contains("3"))
{
if (hotProessItems.Count(x => x.HotId == item.HotId && x.ProessTypes == "3") == 0)
{
isHotProess = false; //未完成热处理委托
break;
}
}
if (strs.Contains("4"))
{
if (hotProessItems.Count(x => x.HotId == item.HotId && x.ProessTypes == "4") == 0)
{
isHotProess = false; //未完成热处理委托
break;
}
}
if (strs.Contains("5"))
{
if (hotProessItems.Count(x => x.HotId == item.HotId && x.ProessTypes == "5") == 0)
{
isHotProess = false; //未完成热处理委托
break;
}
}
}
if (isHotProess)
{
newNode.Text = project.ProjectCode;
}
else
{
newNode.Text = "" + project.ProjectCode + "";
}
newNode.EnableClickEvent = true;
rootNode.Nodes.Add(newNode);
}
}
#endregion
#region 焊缝编号查询
///
/// 查询
///
///
///
protected void Tree_TextChanged(object sender, EventArgs e)
{
this.InitTreeMenu();
this.BindGrid();
}
#endregion
#region 数据绑定
///
/// 数据绑定
///
private void BindGrid()
{
List toDoMatterList = GetHotProessTrustFind(this.ProjectId, this.HotProessTrustId, this.tvControlItem.SelectedNodeID);
if (rblIsWeld.SelectedValue == "0")
{
toDoMatterList = toDoMatterList.Where(x => x.DReportID == null).ToList();
}
if (rblIsWeld.SelectedValue == "1")
{
toDoMatterList = toDoMatterList.Where(x => x.DReportID != null).ToList();
}
if (this.txtJointNo.Text.Trim() != string.Empty)
{
toDoMatterList = toDoMatterList.Where(x => x.JOT_JointNo.Contains(this.txtJointNo.Text.Trim())).ToList();
}
DataTable tb = this.LINQToDataTable(toDoMatterList);
// 2.获取当前分页数据
Grid1.RecordCount = tb.Rows.Count;
tb = GetFilteredTable(Grid1.FilteredData, tb);
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
}
///
/// 获取未完全热处理焊口信息
///
///
private static List GetHotProessTrustFind(string projectId, string trustId, string weldingId)
{
var weldInfos = Funs.DB.PV_View_HotWeldInformation.Where(p => p.ProjectId == projectId && p.IsHotProessTrust == 0).ToList();
List returnViewMatch = new List();
//热处理明细
var hotProessTrustItems = from x in Funs.DB.PV_CH_HotProessTrustItem join z in Funs.DB.PV_View_HotWeldInformation on x.HotId equals z.HotId where z.ProjectId == projectId select x;
//热处理反馈
var hotProessResult = from x in Funs.DB.PV_CH_HotProessResult join y in Funs.DB.PV_View_HotWeldInformation on x.HotId equals y.HotId select x;
//判断焊缝信息
if (weldInfos.Count > 0)
{
foreach (var item in weldInfos)
{
var jothotProessTrustItems = from x in hotProessTrustItems where x.HotId == item.HotId select x;
bool isShow = false;
//判断是否需要热处理
if (!string.IsNullOrEmpty(item.HeatTreatmentType))
{
if (jothotProessTrustItems.Count() == 0)//未进行过热处理
{
isShow = true;
}
else//已进行过热处理
{
string oldProessTypes = item.HeatTreatmentType.Replace("|", "").Replace("1", "").Replace("2", "");
string proessTypes = string.Empty;
foreach (var jothotProessTrustItem in jothotProessTrustItems)
{
proessTypes += jothotProessTrustItem.ProessTypes;
}
proessTypes = proessTypes.Replace("|", "");
if (oldProessTypes.Length > proessTypes.Length) //未将所有热处理类型委托完
{
isShow = true;
}
}
//添加
if (isShow)
{
var jotInfo = weldInfos.FirstOrDefault(x => x.HotId == item.HotId);
if (jotInfo != null)
{
var date = Funs.DB.PV_BO_WeldReportMain.FirstOrDefault(x => x.DReportID == jotInfo.DReportID);
PV_View_CH_HotProessTrustItem newItem = new PV_View_CH_HotProessTrustItem();
newItem.HotId = jotInfo.HotId;
newItem.JOT_JointNo = jotInfo.JOT_JointNo;
newItem.WeldingId = jotInfo.WeldingId;
newItem.WeldingCode = jotInfo.WeldingCode;
if (date != null && date.ReportDate != null)
{
newItem.ReportDate = date.ReportDate;
newItem.DReportID = date.DReportID;
}
newItem.JointDesc = jotInfo.JointDesc;
newItem.STE_Code = jotInfo.STE_Code;
newItem.RepairFalg = jotInfo.RepairFalg;
newItem.RepairNum = jotInfo.RepairNum.Value;
newItem.AgainId = jotInfo.AgainId;
newItem.TrustType = jotInfo.TrustType;
returnViewMatch.Add(newItem);
}
}
}
}
}
return returnViewMatch;
}
#endregion
#region 点击TreeView
///
/// 点击TreeView
///
///
///
protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e)
{
string[] selectRowId = Grid1.SelectedRowIDArray;
int n = 0;
int j = 0;
int[] selections = new int[selectRowId.Count()];
foreach (GridRow row in Grid1.Rows)
{
if (selectRowId.Contains(row.DataKeys[0]))
{
selections[n] = j;
n++;
}
j++;
}
var select = selections.Distinct();
this.BindGrid();
}
#endregion
#region 提交按钮
///
/// 提交按钮
///
///
///
protected void btnAccept_Click(object sender, EventArgs e)
{
string itemsString = "";
string[] selectRowId = Grid1.SelectedRowIDArray;
int n = 0;
int j = 0;
int[] selections = new int[selectRowId.Count()];
foreach (GridRow row in Grid1.Rows)
{
if (selectRowId.Contains(row.DataKeys[0]))
{
selections[n] = j;
n++;
}
j++;
}
var select = selections.Distinct();
itemsString = Request.Params["hotids"];
foreach (int i in select)
{
string rowID = Grid1.DataKeys[i][0].ToString();
string weldingId = Grid1.DataKeys[i][1].ToString();
string repairNum = Grid1.DataKeys[i][2].ToString();
string ids = rowID + ",";
//if (!string.IsNullOrEmpty(weldingId))
//{
// ids += "," + weldingId;
//}
//if (!string.IsNullOrEmpty(repairNum))
//{
// ids += "," + repairNum;
//}
//在这里添加的都是添加的
itemsString += "|" + ids;
//if (!itemsString.Contains(rowID))
//{
// itemsString += ids + "|";
//}
}
PageContext.RegisterStartupScript(ActiveWindow.GetWriteBackValueReference(itemsString + ItemsString)
+ ActiveWindow.GetHidePostBackReference());
}
#endregion
#region 排序
///
/// 排序
///
///
///
protected void Grid1_Sort(object sender, GridSortEventArgs e)
{
this.BindGrid();
}
#endregion
#region 私有方法
///
/// 得到焊接日期
///
///
///
protected string ConvertWeldDate(object hotids)
{
string date = string.Empty;
if (hotids != null)
{
var id = hotids.ToString();
var dayReport = (from x in Funs.DB.PV_BO_WeldReportMain
join y in Funs.DB.PV_View_HotWeldInformation
on x.DReportID equals y.DReportID
where y.HotId == id
select x).FirstOrDefault();
if (dayReport != null && dayReport.ReportDate != null)
{
date = string.Format("{0:yyyy-MM-dd}", dayReport.ReportDate);
}
}
return date;
}
///
/// 得到委托情况
///
///
///
protected string ConvertHotProessState(object hotId)
{
string state = string.Empty;
if (hotId != null)
{
string hot_id = hotId.ToString();
var list = Funs.DB.PV_View_CH_HotProessTrustItem.Where(p => p.HotId == hot_id);
foreach (var item in list)
{
if (!string.IsNullOrEmpty(item.HotProessTrustId)) //存在委托信息
{
string date = string.Empty;
if (item.TrustDate != null)
{
date = "(" + string.Format("{0:yyyy-MM-dd}", item.TrustDate) + ")";
}
state += HJGL_CH_HotProessTrustService.GetProessTypesName(item.ProessTypes) + ":" + date + ";";
}
}
if (!string.IsNullOrEmpty(state))
{
state = state.Substring(0, state.LastIndexOf(";"));
}
}
return state;
}
///
/// 搜索
///
protected void rblIsWeld_SelectedIndexChanged(object sender, EventArgs e)
{
this.BindGrid();
}
///
/// 得到热处理类型
///
///
protected string ConvertProessTypes(object hotids)
{
string proessTypes = string.Empty;
if (hotids != null)
{
var id = hotids.ToString();
var joint = Funs.DB.PV_View_HotWeldInformation.FirstOrDefault(e => e.HotId == id);
if (joint != null)
{
if (!string.IsNullOrEmpty(joint.HeatTreatmentType))
{
proessTypes = BLL.HJGL_PW_JointInfoService.ConvertProessTypes(joint.HeatTreatmentType);
}
}
}
return proessTypes;
}
#endregion
}
}