using BLL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web.UI.WebControls;
namespace FineUIPro.Web.HJGL.WeldingManage
{
public partial class PipelineManage : PageBase
{
public string treeNodeId
{
get
{
return (string)ViewState["treeNodeId"];
}
set
{
ViewState["treeNodeId"] = value;
}
}
public string unitId
{
get
{
return (string)ViewState["unitId"];
}
set
{
ViewState["unitId"] = value;
}
}
#region 加载
///
/// 加载页面
///
///
///
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Funs.DropDownPageSize(this.ddlPageSize);
BLL.Base_TestMediumService.InitMediumDropDownList(this.drpSer, true);//介质
BLL.Base_DetectionTypeService.InitDetectionTypeDropDownList(this.drpNDT, true);//探伤类型
BLL.Base_MaterialService.InitMaterialDropDownList(this.drpSteId, true, this.CurrUser.LoginProjectId);//材质
ListItem[] lis = new ListItem[3];
lis[0] = new ListItem("- 请选择 -", "");
lis[1] = new ListItem("是", "1");
lis[2] = new ListItem("否", "0");
this.drpIsStanded.DataValueField = "Value";
this.drpIsStanded.DataTextField = "Text";
this.drpIsStanded.DataSource = lis;
this.drpIsStanded.DataBind();
this.drpIsStanded.SelectedIndex = 0;
this.InitTreeMenu();//加载树
//显示列
Model.Sys_UserShowColumns c = BLL.UserShowColumnsService.GetColumnsByUserId(this.CurrUser.UserId, "Iso");
if (c != null)
{
this.GetShowColumn(c.Columns);
}
}
}
#endregion
#region 加载树装置-单位-工作区
///
/// 加载树
///
private void InitTreeMenu()
{
this.tvControlItem.Nodes.Clear();
TreeNode rootNode = new TreeNode();
rootNode.Text = "装置-单位-工作区";
rootNode.NodeID = "0";
rootNode.Expanded = true;
this.tvControlItem.Nodes.Add(rootNode);
////装置
var pInstallation = (from x in Funs.DB.Project_Installation where x.ProjectId == this.CurrUser.LoginProjectId select x).ToList();
////区域
var pWorkArea = (from x in Funs.DB.ProjectData_WorkArea where x.ProjectId == this.CurrUser.LoginProjectId select x).ToList();
////单位
var pUnits = (from x in Funs.DB.Project_ProjectUnit where x.ProjectId == this.CurrUser.LoginProjectId select x).ToList();
if (!string.IsNullOrEmpty(this.txtWorkArea.Text))
{
pWorkArea = pWorkArea.Where(x => x.WorkAreaCode.Contains(this.txtWorkArea.Text.Trim())).OrderBy(x => x.WorkAreaCode).ToList();
pInstallation = (from x in pInstallation
join y in pWorkArea on x.InstallationId equals y.InstallationId
select x).Distinct().ToList();
pUnits = (from x in pUnits
join y in pWorkArea on x.UnitId equals y.UnitId
select x).Distinct().ToList();
}
this.BindNodes(rootNode, pInstallation, pWorkArea, pUnits);
}
#endregion
#region 绑定树节点
///
/// 绑定树节点
///
///
private void BindNodes(TreeNode node, List pInstallation, List pWorkArea, List pUnits)
{
if (string.IsNullOrEmpty(node.ToolTip))
{
List installations = pInstallation;
var pUnit = pUnits.FirstOrDefault(x => x.UnitId == this.CurrUser.UnitId);
if (pUnit != null && pUnit.UnitType != Const.ProjectUnitType_1 && pUnit.UnitType != Const.ProjectUnitType_5)
{
installations = (from x in pInstallation
join y in pWorkArea on x.InstallationId equals y.InstallationId
where y.UnitId == this.CurrUser.UnitId
orderby x.InstallationId
select x).Distinct().ToList();
}
foreach (var q in installations)
{
TreeNode newNode = new TreeNode();
newNode.NodeID = q.InstallationId;
newNode.Text = q.InstallationName;
newNode.ToolTip = "装置";
newNode.Expanded = true;
node.Nodes.Add(newNode);
this.BindNodes(newNode, pInstallation, pWorkArea, pUnits);
}
}
else if (node.ToolTip == "装置")
{
List units = null;
var pUnitDepth = pUnits.FirstOrDefault(x => x.UnitId == this.CurrUser.UnitId);
if (pUnitDepth == null || pUnitDepth.UnitType == Const.ProjectUnitType_1 || pUnitDepth.UnitType == Const.ProjectUnitType_5)
{
units = (from x in pUnits
join y in pWorkArea on x.UnitId equals y.UnitId
where y.InstallationId == node.NodeID && x.UnitType == Const.ProjectUnitType_2
select x).ToList();
}
else
{
units = (from x in pUnits
join y in pWorkArea on x.UnitId equals y.UnitId
where y.InstallationId == node.NodeID && x.UnitType == Const.ProjectUnitType_2 && x.UnitId == this.CurrUser.UnitId
select x).ToList();
}
units = units.OrderBy(x => x.InTime).Distinct().ToList();
foreach (var q in units)
{
var unit = BLL.UnitService.GetUnitByUnitId(q.UnitId);
if (unit != null)
{
TreeNode newNode = new TreeNode();
newNode.Text = unit.UnitName;
newNode.NodeID = q.UnitId + "|" + node.NodeID;
newNode.ToolTip = "单位";
node.Nodes.Add(newNode);
this.BindNodes(newNode, pInstallation, pWorkArea, pUnits);
}
}
}
else if (node.ToolTip == "单位")
{
var workAreas = (from x in pWorkArea
where x.InstallationId == node.ParentNode.NodeID && x.UnitId == node.NodeID.Split('|')[0]
select x);
workAreas = workAreas.OrderByDescending(x => x.WorkAreaCode);
foreach (var q in workAreas)
{
int a = (from x in BLL.Funs.DB.PW_IsoInfo where x.ProjectId == this.CurrUser.LoginProjectId && x.UnitId == node.NodeID.Split('|')[0] && x.WorkAreaId == q.WorkAreaId select x).Count();
TreeNode newNode = new TreeNode();
newNode.Text = q.WorkAreaCode + "【" + a.ToString() + "】管线";
newNode.NodeID = q.WorkAreaId;
newNode.EnableClickEvent = true;
newNode.ToolTip = "区域";
node.Nodes.Add(newNode);
}
}
}
#endregion
#region 点击TreeView
///
/// 点击TreeView
///
///
///
protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e)
{
this.unitId = e.Node.ParentNode.NodeID.Split('|')[0];
treeNodeId = e.NodeID;
this.BindGrid();
}
#endregion
#region 数据绑定
///
/// 数据绑定
///
private void BindGrid()
{
var getData = PipelineService.getListData(this.CurrUser.LoginProjectId, treeNodeId, unitId, this.drpIsStanded.SelectedValue, this.txtIsoNo.Text.Trim()
, this.drpSer.SelectedValue, this.drpNDT.SelectedValue, this.txtIso_IsoNumber.Text.Trim(), this.drpSteId.SelectedValue
, this.txtISO_Specification.Text.Trim(), Grid1);
Grid1.RecordCount = PipelineService.count;
Grid1.DataSource = getData;
Grid1.DataBind();
}
#endregion
#region 计算合计
///
/// 计算合计
///
//private void OutputSummaryData(DataTable tb)
//{
// decimal count2 = 0;//总达因数
// int count3 = 0;//总焊口数
// for (int i = 0; i < tb.Rows.Count; i++)
// {
// count2 += Funs.GetNewDecimalOrZero(tb.Rows[i]["ISO_TotalDin"].ToString());
// count3 += Funs.GetNewIntOrZero(tb.Rows[i]["ISO_JointQty"].ToString());
// }
// JObject summary = new JObject();
// summary.Add("ISO_IsoNo", "合计:");
// summary.Add("ISO_TotalDin", count2);
// summary.Add("ISO_JointQty", count3);
// Grid1.SummaryData = summary;
//}
#endregion
#region 分页排序
#region 页索引改变事件
///
/// 页索引改变事件
///
///
///
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
Grid1.PageIndex = e.NewPageIndex;
BindGrid();
}
#endregion
#region 排序
///
/// 排序
///
///
///
protected void Grid1_Sort(object sender, GridSortEventArgs e)
{
Grid1.SortDirection = e.SortDirection;
Grid1.SortField = e.SortField;
BindGrid();
}
#endregion
#region 分页选择下拉改变事件
///
/// 分页选择下拉改变事件
///
///
///
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
BindGrid();
}
#endregion
#endregion
#region 管线信息 维护事件
///
/// Grid双击事件
///
///
///
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
{
if (GetButtonPower(Const.BtnModify))
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PipelineManageEdit.aspx?ISO_ID={0}", Grid1.SelectedRowID, "编辑 - ")));
}
else
{
ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
}
}
protected void btnSearch_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(treeNodeId))
{
BindGrid();
}
}
///
/// 增加管线信息
///
///
///
protected void btnNew_Click(object sender, EventArgs e)
{
if (GetButtonPower(Const.BtnAdd))
{
var workArea = BLL.WorkAreaService.getWorkAreaByWorkAreaId(tvControlItem.SelectedNodeID);
if (workArea != null)
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PipelineManageEdit.aspx?workAreaId={0}", this.tvControlItem.SelectedNodeID, "新增 - ")));
}
else
{
ShowNotify("请先选择区域!", MessageBoxIcon.Warning);
}
}
else
{
ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
}
}
///
/// 管线信息编辑
///
///
///
protected void btnMenuEdit_Click(object sender, EventArgs e)
{
if (GetButtonPower(Const.BtnModify))
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning);
return;
}
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PipelineManageEdit.aspx?ISO_ID={0}", Grid1.SelectedRowID, "维护 - ")));
}
else
{
ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
}
}
///
/// 删除按钮
///
///
///
protected void btnMenuDelete_Click(object sender, EventArgs e)
{
if (GetButtonPower(Const.BtnDelete))
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning);
return;
}
bool isShow = true;
string isoRes = string.Empty;
if (Grid1.SelectedRowIndexArray.Length > 1)
{
isShow = false;
}
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
{
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
if (judgementDelete(rowID, isShow))
{
Model.PW_IsoInfo q = BLL.PW_IsoInfoService.GetIsoInfoByIsoInfoId(rowID);
if (q != null)
{
if (!BLL.PW_JointInfoService.IsExistJointInfoWeld(rowID))
{
BLL.PW_JointInfoService.DeleteJointInfoByIsoId(rowID);
//var tP_IsoList = (from x in BLL.Funs.DB.TP_IsoList where x.ISO_ID == q.ISO_ID select x).FirstOrDefault();
//if (tP_IsoList != null)
//{
// BLL.Funs.DB.TP_IsoList.DeleteOnSubmit(tP_IsoList);
// BLL.Funs.DB.SubmitChanges();
//}
BLL.PW_IsoInfoService.DeleteIsoInfo(rowID);
}
else
{
if (string.IsNullOrEmpty(isoRes))
{
isoRes = q.ISO_IsoNo;
}
else
{
isoRes += "," + q.ISO_IsoNo;
}
}
}
}
}
if (!string.IsNullOrEmpty(isoRes))
{
Alert.ShowInTop("管线" + isoRes + "存在焊口的焊接信息!", MessageBoxIcon.Warning);
}
else
{
ShowNotify("删除成功!", MessageBoxIcon.Success);
}
this.BindGrid();
}
else
{
ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
}
}
#endregion
#region 关闭弹出窗口及刷新页面
///
/// 关闭弹出窗口
///
///
///
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
this.BindGrid();
}
///
/// 查询
///
///
///
protected void TextBox_TextChanged(object sender, EventArgs e)
{
this.BindGrid();
}
///
/// 查询
///
///
///
protected void Tree_TextChanged(object sender, EventArgs e)
{
this.InitTreeMenu();
this.BindGrid();
}
#endregion
#region 判断是否可删除
///
/// 判断是否可以删除
///
///
private bool judgementDelete(string id, bool isShow)
{
string content = string.Empty;
//string jotInfo = string.Empty;
//var q = from x in Funs.DB.HJGL_PW_JointInfo where x.ISO_ID == id && x.DReportID != null select x;
//if (q.Count() > 0)
//{
// foreach (var item in q)
// {
// jotInfo += "焊口号:" + item.JOT_JointNo;
// var dr = Funs.DB.HJGL_BO_WeldReportMain.FirstOrDefault(x => x.DReportID == item.DReportID);
// if (dr != null)
// {
// jotInfo += ";焊接日报号:" + dr.JOT_DailyReportNo;
// }
// }
// content = "该管线已焊焊口!" + jotInfo;
//}
//if (BLL.HJGL_AItemEndCheckService.IsExistAItemEndCheck(id))
//{
// content = "A项尾工已经使用了该管线,不能删除!";
//}
//if (BLL.HJGL_BItemEndCheckService.IsExistBItemEndCheck(id))
//{
// content = "B项尾工已经使用了该管线,不能删除!";
//}
if (string.IsNullOrEmpty(content))
{
return true;
}
else
{
if (isShow)
{
Alert.ShowInTop(content, MessageBoxIcon.Error);
}
return false;
}
}
#endregion
#region 选择要显示列
///
/// 选择显示列
///
///
///
protected void btnSelectColumn_Click(object sender, EventArgs e)
{
PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("PipelineShowColumn.aspx", "显示列 - ")));
}
///
/// 关闭显示列弹出窗口
///
///
///
protected void Window2_Close(object sender, WindowCloseEventArgs e)
{
this.BindGrid();
//显示列
Model.Sys_UserShowColumns c = BLL.UserShowColumnsService.GetColumnsByUserId(this.CurrUser.UserId, "Iso");
if (c != null)
{
this.GetShowColumn(c.Columns);
}
}
#endregion
#region 显示的列
///
/// 显示的列
///
///
private void GetShowColumn(string column)
{
if (!string.IsNullOrEmpty(column))
{
this.Grid1.Columns[1].Hidden = true;
this.Grid1.Columns[2].Hidden = true;
this.Grid1.Columns[3].Hidden = true;
this.Grid1.Columns[4].Hidden = true;
this.Grid1.Columns[5].Hidden = true;
this.Grid1.Columns[6].Hidden = true;
this.Grid1.Columns[7].Hidden = true;
this.Grid1.Columns[8].Hidden = true;
this.Grid1.Columns[9].Hidden = true;
this.Grid1.Columns[10].Hidden = true;
this.Grid1.Columns[11].Hidden = true;
this.Grid1.Columns[12].Hidden = true;
this.Grid1.Columns[13].Hidden = true;
this.Grid1.Columns[14].Hidden = true;
this.Grid1.Columns[15].Hidden = true;
this.Grid1.Columns[16].Hidden = true;
this.Grid1.Columns[17].Hidden = true;
this.Grid1.Columns[18].Hidden = true;
this.Grid1.Columns[19].Hidden = true;
this.Grid1.Columns[20].Hidden = true;
this.Grid1.Columns[21].Hidden = true;
this.Grid1.Columns[22].Hidden = true;
this.Grid1.Columns[23].Hidden = true;
this.Grid1.Columns[24].Hidden = true;
this.Grid1.Columns[25].Hidden = true;
this.Grid1.Columns[26].Hidden = true;
this.Grid1.Columns[27].Hidden = true;
this.Grid1.Columns[28].Hidden = true;
this.Grid1.Columns[29].Hidden = true;
this.Grid1.Columns[30].Hidden = true;
this.Grid1.Columns[31].Hidden = true;
this.Grid1.Columns[32].Hidden = true;
this.Grid1.Columns[33].Hidden = true;
this.Grid1.Columns[34].Hidden = true;
this.Grid1.Columns[35].Hidden = true;
this.Grid1.Columns[36].Hidden = true;
this.Grid1.Columns[37].Hidden = true;
this.Grid1.Columns[38].Hidden = true;
this.Grid1.Columns[39].Hidden = true;
this.Grid1.Columns[40].Hidden = true;
List columns = column.Split(',').ToList();
foreach (var item in columns)
{
this.Grid1.Columns[Convert.ToInt32(item)].Hidden = false;
}
}
}
#endregion
#region 格式化字符串
///
/// 获取总达因数
///
///
///
public static string ConvertTotalDin(object isoId)
{
if (isoId != null)
{
var sizeSum = (from x in Funs.DB.PW_JointInfo where x.ISO_ID == isoId.ToString() select x.JOT_Size).Sum();
if (sizeSum != null)
{
return sizeSum.ToString();
}
}
return null;
}
///
/// 获取总焊口数
///
///
///
public static string ConvertJointQty(object isoId)
{
if (isoId != null)
{
var jotCount = (from x in Funs.DB.PW_JointInfo where x.ISO_ID == isoId.ToString() select x).Count();
if (jotCount != null)
{
return jotCount.ToString();
}
}
return null;
}
///
/// 根据管线主键获取试压包编号
///
///
///
public static string ConvertTestPackageNo(object iso_id)
{
if (iso_id != null)
{
//var testPackage = (from x in Funs.DB.TP_TestPackage
// join y in Funs.DB.TP_IsoList on x.PTP_ID equals y.PTP_ID
// join z in Funs.DB.PW_IsoInfo on y.ISO_ID equals z.ISO_ID
// where z.ISO_ID == iso_id.ToString()
// select x.PTP_TestPackageCode).FirstOrDefault();
//return testPackage;
return null;
}
return null;
}
#endregion
#region 获取按钮权限
///
/// 获取按钮权限
///
///
///
private bool GetButtonPower(string button)
{
return BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.HJGL_PipelineManageMenuId, button);
}
#endregion
#region 批量生成二维码
///
/// 批量生成二维码
///
///
///
protected void btnQR_Click(object sender, EventArgs e)
{
var getJointInfos = from x in Funs.DB.PW_JointInfo
where x.ProjectId == this.CurrUser.LoginProjectId && x.QRCodeAttachUrl == null
select x;
int num = 0;
if (getJointInfos.Count() > 0)
{
foreach (var item in getJointInfos)
{
string url = CreateQRCodeService.CreateCode_Simple("WeldedJoint$" + item.JOT_ID);
if (!string.IsNullOrEmpty(url))
{
item.QRCodeAttachUrl = url;
Funs.DB.SubmitChanges();
num++;
}
}
}
ShowNotify("操作完成,新生成二维码" + num.ToString() + "条", MessageBoxIcon.Success);
}
#endregion
#region 导出焊口二维码
///
/// 导出焊口二维码
///
///
///
protected void btnPrint_Click(object sender, EventArgs e)
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning);
return;
}
string iso_Id = Grid1.SelectedRowID;
var getJots = Funs.DB.PW_JointInfo.Where(x => x.ISO_ID == iso_Id).Select(x => x.JOT_ID);
if (getJots.Count() > 0)
{
string pList = string.Empty;
foreach (var id in getJots)
{
if (string.IsNullOrEmpty(pList))
{
pList = id;
}
else
{
pList += "," + id;
}
}
if (!string.IsNullOrEmpty(pList))
{
PrinterDocService.PrinterDocMethod(BLL.Const.HJGL_PipelineMenuId, pList, "管线焊口二维码");
}
else
{
Alert.ShowInParent("请选择要导出的管线!");
return;
}
}
}
#endregion
protected void betDel_Click(object sender, EventArgs e)
{
if (GetButtonPower(Const.BtnDelete))
{
var getMess = PipelineService.DelAllPopeline(this.CurrUser.LoginProjectId, treeNodeId, unitId, this.drpIsStanded.SelectedValue, this.txtIsoNo.Text.Trim()
, this.drpSer.SelectedValue, this.drpNDT.SelectedValue, this.txtIso_IsoNumber.Text.Trim(), this.drpSteId.SelectedValue
, this.txtISO_Specification.Text.Trim());
if (getMess != null)
{
if (getMess.code == 1)
{
this.InitTreeMenu();//加载树
this.BindGrid();//加载树
ShowNotify(getMess.message, MessageBoxIcon.Success);
}
else
{
Alert.ShowInTop(getMess.message, MessageBoxIcon.Success);
}
}
}
else
{
ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
}
}
}
}