using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using BLL;
namespace FineUIPro.Web.HJGL.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 InstallationId
{
get
{
return (string)ViewState["InstallationId"];
}
set
{
ViewState["InstallationId"] = value;
}
}
///
/// 焊口主键
///
public string Jot_ID
{
get
{
return (string)ViewState["Jot_ID"];
}
set
{
ViewState["Jot_ID"] = 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 weldJoints = from x in Funs.DB.HJGL_PW_JointInfo
where x.DReportID != null
select x; //已经焊接的焊口集合
var hotProessItems = from x in Funs.DB.HJGL_CH_HotProessTrustItem select x; //热处理委托明细集合
var iso = from x in Funs.DB.HJGL_PW_IsoInfo where x.ProjectId == this.ProjectId && x.BSU_ID == this.UnitId select x;
if (!string.IsNullOrEmpty(this.txtIsono.Text))
{
iso = iso.Where(e => e.ISO_IsoNo.Contains(this.txtIsono.Text.Trim()));
}
iso = iso.OrderBy(x => x.ISO_IsoNo);
if (iso.Count() > 0)
{
foreach (var q in iso)
{
var jots = from x in Funs.DB.HJGL_PW_JointInfo where x.ISO_ID == q.ISO_ID && x.IS_Proess == "1" select x;
if (jots.Count() > 0)
{
TreeNode newNode = new TreeNode();
newNode.NodeID = q.ISO_ID;
var isoWeldJoints = weldJoints.Where(x => x.ISO_ID == q.ISO_ID); //该管线已焊接的焊口集合
bool isHotProess = true; //默认已完成热处理委托
foreach (var item in isoWeldJoints)
{
if (!string.IsNullOrEmpty(item.ProessTypes)) //需要热处理
{
string[] strs = item.ProessTypes.Split('|');
if (strs.Contains("3"))
{
var hotProessItem1 = hotProessItems.Where(x => x.JOT_ID == item.JOT_ID && x.ProessTypes == "3");
if (hotProessItem1.Count()==0)
{
isHotProess = false; //未完成热处理委托
break;
}
}
if (strs.Contains("4"))
{
var hotProessItem2 = hotProessItems.Where(x => x.JOT_ID == item.JOT_ID && x.ProessTypes == "4");
if (hotProessItem2.Count() == 0)
{
isHotProess = false; //未完成热处理委托
break;
}
}
if (strs.Contains("5"))
{
var hotProessItem3 = hotProessItems.Where(x => x.JOT_ID == item.JOT_ID && x.ProessTypes == "5");
if (hotProessItem3.Count() == 0)
{
isHotProess = false; //未完成热处理委托
break;
}
}
}
}
if (isHotProess)
{
newNode.Text = q.ISO_IsoNo;
}
else
{
newNode.Text = "" + q.ISO_IsoNo + "";
}
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 = BLL.HJGL_CH_HotProessTrustService.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();
}
string jotIds = Request.Params["jotIds"];
if (!string.IsNullOrEmpty(jotIds))
{
string[] jots = jotIds.Split('|');
foreach (string jotId in jots)
{
Model.HJGL_View_CH_HotProessTrustItem item = toDoMatterList.FirstOrDefault(e => e.JOT_ID == jotId);
if (item != null)
{
toDoMatterList.Remove(item);
}
}
}
DataTable tb = this.LINQToDataTable(toDoMatterList);
// 2.获取当前分页数据
//var table = this.GetPagedDataTable(GridNewDynamic, tb1);
Grid1.RecordCount = tb.Rows.Count;
tb = GetFilteredTable(Grid1.FilteredData, tb);
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
}
#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();
foreach (int i in select)
{
string rowID = Grid1.DataKeys[i][0].ToString();
string hardTestResultId = Grid1.Rows[i].Values[4].ToString();
string hardRepairMark = Grid1.Rows[i].Values[5].ToString();
string ids = rowID;
if (!string.IsNullOrEmpty(hardTestResultId))
{
ids += "," + hardTestResultId;
}
if (!string.IsNullOrEmpty(hardRepairMark))
{
ids += "," + hardRepairMark;
}
if (!ItemsString.Contains(rowID))
{
ItemsString += ids + "|";
}
}
this.BindGrid();
}
#endregion
#region 提交按钮
///
/// 提交按钮
///
///
///
protected void btnAccept_Click(object sender, EventArgs e)
{
string itemsString = "";
//if (Grid1.SelectedRowIndexArray.Length > 0)
//{
// foreach (int rowIndex in Grid1.SelectedRowIndexArray)
// {
// string rowID = Grid1.DataKeys[rowIndex][0].ToString();
// string trustItemID = Grid1.Rows[rowIndex].Values[5].ToString();
// if (!itemsString.Contains(rowID))
// {
// itemsString += rowID + "," + trustItemID + "|";
// }
// }
//}
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();
string jotIds = Request.Params["jotIds"];
if (!string.IsNullOrEmpty(jotIds))
{
string[] jots = jotIds.Split('|');
foreach (string jotId in jots)
{
itemsString += jotId + "|";
}
}
foreach (int i in select)
{
string rowID = Grid1.DataKeys[i][0].ToString();
string hardTestResultId = Grid1.Rows[i].Values[4].ToString();
string hardRepairMark = Grid1.Rows[i].Values[5].ToString();
string ids = rowID;
if (!string.IsNullOrEmpty(hardTestResultId))
{
ids += "," + hardTestResultId;
}
if (!string.IsNullOrEmpty(hardRepairMark))
{
ids += "," + hardRepairMark;
}
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
///
/// 得到焊接日期
///
///
///
protected string ConvertWeldDate(object JOT_ID)
{
string date = string.Empty;
if (JOT_ID != null)
{
var dayReport = (from x in Funs.DB.HJGL_BO_WeldReportMain
join y in Funs.DB.HJGL_PW_JointInfo
on x.DReportID equals y.DReportID
where y.JOT_ID == JOT_ID.ToString()
select x).FirstOrDefault();
if (dayReport != null && dayReport.JOT_WeldDate != null)
{
date = string.Format("{0:yyyy-MM-dd}", dayReport.JOT_WeldDate);
}
}
return date;
}
///
/// 得到委托情况
///
///
///
protected string ConvertHotProessState(object JOT_ID)
{
string state = string.Empty;
if (JOT_ID != null)
{
string jot_id = JOT_ID.ToString();
var list = from x in Funs.DB.HJGL_View_CH_HotProessTrustItem
where x.JOT_ID == jot_id
select x;
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 += BLL.HJGL_CH_HotProessTrustService.GetProessTypesName(item.ProessTypes) + ":" + item.IsOKStr2 + date + ";";
state += BLL.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 ConvertIsRepair(object TrustItemID)
{
string state = string.Empty;
if (TrustItemID != null)
{
string trustItemID = TrustItemID.ToString();
if (!string.IsNullOrEmpty(trustItemID))
{
state = "是";
}
}
return state;
}
#region 格式化字符串
///
/// 得到热处理类型
///
///
///
protected string ConvertProessTypes(object JOT_ID)
{
string proessTypes = string.Empty;
if (JOT_ID != null)
{
Model.HJGL_PW_JointInfo joint = BLL.HJGL_PW_JointInfoService.GetJointInfoByJotID(JOT_ID.ToString());
if (joint != null)
{
if (!string.IsNullOrEmpty(joint.ProessTypes))
{
proessTypes = BLL.HJGL_PW_JointInfoService.ConvertProessTypes(joint.ProessTypes);
}
}
}
return proessTypes;
}
#endregion
}
}