507 lines
20 KiB
C#
507 lines
20 KiB
C#
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.WeldingProcess.WeldingManage
|
||
{
|
||
public partial class PipelineManage : PageBase
|
||
{
|
||
protected void Page_Load(object sender, EventArgs e)
|
||
{
|
||
if (!IsPostBack)
|
||
{
|
||
this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString();
|
||
this.InitTreeMenu();//加载树
|
||
//显示列
|
||
Model.Sys_UserShowColumns c = BLL.UserShowColumnsService.GetColumnsByUserId(this.CurrUser.UserId, "Pipeline");
|
||
if (c != null)
|
||
{
|
||
this.GetShowColumn(c.Columns);
|
||
}
|
||
}
|
||
}
|
||
|
||
protected void drpProjectId_SelectedIndexChanged(object sender, EventArgs e)
|
||
{
|
||
this.InitTreeMenu();
|
||
}
|
||
|
||
#region 加载树装置-单位-工作区
|
||
/// <summary>
|
||
/// 加载树
|
||
/// </summary>
|
||
private void InitTreeMenu()
|
||
{
|
||
this.tvControlItem.Nodes.Clear();
|
||
var totalInstallation = from x in Funs.DB.Project_Installation select x;
|
||
var totalWorkArea = from x in Funs.DB.Project_WorkArea select x;
|
||
var totalUnit = from x in Funs.DB.Project_Unit select x;
|
||
////装置
|
||
var pInstallation = (from x in totalInstallation where x.ProjectId == this.CurrUser.LoginProjectId select x).ToList();
|
||
////区域
|
||
var pWorkArea = (from x in totalWorkArea where x.ProjectId == this.CurrUser.LoginProjectId select x).ToList();
|
||
////单位
|
||
var pUnits = (from x in totalUnit 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(null, pInstallation, pWorkArea, pUnits);
|
||
}
|
||
#endregion
|
||
|
||
#region 绑定树节点
|
||
/// <summary>
|
||
/// 绑定树节点
|
||
/// </summary>
|
||
/// <param name="node"></param>
|
||
private void BindNodes(TreeNode node, List<Model.Project_Installation> pInstallation, List<Model.Project_WorkArea> pWorkArea, List<Model.Project_Unit> pUnits)
|
||
{
|
||
if (node==null)
|
||
{
|
||
List<Model.Project_Installation> installations = pInstallation;
|
||
var pUnit = pUnits.FirstOrDefault(x => x.UnitId == this.CurrUser.UnitId);
|
||
if (pUnit != null && !pUnit.UnitType.Contains(Const.UnitType_2) && !pUnit.UnitType.Contains(Const.UnitType_1))
|
||
{
|
||
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 = Resources.Lan.InstallationName;
|
||
newNode.Expanded = true;
|
||
this.tvControlItem.Nodes.Add(newNode);
|
||
this.BindNodes(newNode, pInstallation, pWorkArea, pUnits);
|
||
}
|
||
}
|
||
else if (node.ToolTip == Resources.Lan.InstallationName)
|
||
{
|
||
List<Model.Project_Unit> units = null;
|
||
var pUnitDepth = pUnits.FirstOrDefault(x => x.UnitId == this.CurrUser.UnitId);
|
||
if (pUnitDepth == null || pUnitDepth.UnitType.Contains(Const.UnitType_2) || pUnitDepth.UnitType.Contains(Const.UnitType_1))
|
||
{
|
||
units = (from x in pUnits
|
||
join y in pWorkArea on x.UnitId equals y.UnitId
|
||
where y.InstallationId == node.NodeID && x.UnitType.Contains(Const.UnitType_5)
|
||
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.Contains(Const.UnitType_5) && x.UnitId == this.CurrUser.UnitId
|
||
select x).ToList();
|
||
}
|
||
|
||
units = units.OrderBy(x => x.InTime).Distinct().ToList();
|
||
foreach (var q in units)
|
||
{
|
||
var unit = BLL.Base_UnitService.GetUnit(q.UnitId);
|
||
if (unit != null)
|
||
{
|
||
TreeNode newNode = new TreeNode();
|
||
newNode.Text = unit.UnitName;
|
||
newNode.NodeID = q.UnitId + "|" + node.NodeID;
|
||
newNode.ToolTip = Resources.Lan.CompanyName;
|
||
node.Nodes.Add(newNode);
|
||
this.BindNodes(newNode, pInstallation, pWorkArea, pUnits);
|
||
}
|
||
}
|
||
}
|
||
else if (node.ToolTip == Resources.Lan.CompanyName)
|
||
{
|
||
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);
|
||
var pipelines = from x in Funs.DB.Pipeline_Pipeline select x;
|
||
foreach (var q in workAreas)
|
||
{
|
||
int a = (from x in pipelines 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() + "】" + Resources.Lan.Pipeline;
|
||
newNode.NodeID = q.WorkAreaId;
|
||
newNode.EnableClickEvent = true;
|
||
newNode.ToolTip = Resources.Lan.Area;
|
||
node.Nodes.Add(newNode);
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 点击TreeView
|
||
/// <summary>
|
||
/// 点击TreeView
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e)
|
||
{
|
||
this.BindGrid();
|
||
}
|
||
#endregion
|
||
|
||
#region 数据绑定
|
||
/// <summary>
|
||
/// 数据绑定
|
||
/// </summary>
|
||
private void BindGrid()
|
||
{
|
||
string strSql = @"SELECT ProjectId,WorkAreaId,PipelineId,PipelineCode,UnitName,MediumCode,PipingClassCode,
|
||
SystemNumber,WorkAreaCode,WorkPackageCode,SingleNumber,SubSystemNumber,Sheet,PipeSegment,
|
||
DrawingsNum,MaterialCode,Specification,DesignTemperature,TestPressure,DesignPressure,
|
||
IfPicklingStr,Remark,TotalDin,JointCount
|
||
FROM View_Pipeline_Pipeline WHERE ProjectId= @ProjectId";
|
||
List<SqlParameter> listStr = new List<SqlParameter>();
|
||
listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
|
||
if (!string.IsNullOrEmpty(this.tvControlItem.SelectedNodeID))
|
||
{
|
||
strSql += " AND WorkAreaId =@WorkAreaId";
|
||
listStr.Add(new SqlParameter("@WorkAreaId", this.tvControlItem.SelectedNodeID));
|
||
}
|
||
if (!string.IsNullOrEmpty(this.txtPipelineCode.Text.Trim()))
|
||
{
|
||
strSql += " AND PipelineCode LIKE @PipelineCode";
|
||
listStr.Add(new SqlParameter("@PipelineCode", "%" + this.txtPipelineCode.Text.Trim() + "%"));
|
||
}
|
||
if (!string.IsNullOrEmpty(this.txtSingleNumber.Text.Trim()))
|
||
{
|
||
strSql += " AND SingleNumber LIKE @SingleNumber";
|
||
listStr.Add(new SqlParameter("@SingleNumber", "%" + this.txtSingleNumber.Text.Trim() + "%"));
|
||
}
|
||
|
||
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);
|
||
this.OutputSummaryData(tb); ///取合计值
|
||
Grid1.DataSource = table;
|
||
Grid1.DataBind();
|
||
}
|
||
#endregion
|
||
|
||
#region 计算合计
|
||
/// <summary>
|
||
/// 计算合计
|
||
/// </summary>
|
||
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]["TotalDin"].ToString());
|
||
count3 += Funs.GetNewIntOrZero(tb.Rows[i]["JointCount"].ToString());
|
||
}
|
||
JObject summary = new JObject();
|
||
summary.Add("PipelineCode", Resources.Lan.Total);
|
||
summary.Add("TotalDin", count2);
|
||
summary.Add("JointCount", count3);
|
||
Grid1.SummaryData = summary;
|
||
}
|
||
#endregion
|
||
|
||
#region 分页排序
|
||
#region 页索引改变事件
|
||
/// <summary>
|
||
/// 页索引改变事件
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
|
||
{
|
||
Grid1.PageIndex = e.NewPageIndex;
|
||
BindGrid();
|
||
}
|
||
#endregion
|
||
|
||
#region 排序
|
||
/// <summary>
|
||
/// 排序
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void Grid1_Sort(object sender, GridSortEventArgs e)
|
||
{
|
||
Grid1.SortDirection = e.SortDirection;
|
||
Grid1.SortField = e.SortField;
|
||
BindGrid();
|
||
}
|
||
#endregion
|
||
|
||
#region 分页选择下拉改变事件
|
||
/// <summary>
|
||
/// 分页选择下拉改变事件
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
|
||
{
|
||
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
|
||
BindGrid();
|
||
}
|
||
#endregion
|
||
#endregion
|
||
|
||
#region 查询
|
||
/// <summary>
|
||
/// 下拉框选择事件
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnSearch_Click(object sender, EventArgs e)
|
||
{
|
||
BindGrid();
|
||
}
|
||
|
||
protected void btnTreeSearch_Click(object sender, EventArgs e)
|
||
{
|
||
this.InitTreeMenu();
|
||
}
|
||
#endregion
|
||
|
||
|
||
#region 管线信息 维护事件
|
||
/// <summary>
|
||
/// Grid双击事件
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
|
||
{
|
||
if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.HJGL_PipelineManageMenuId, BLL.Const.BtnModify))
|
||
{
|
||
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PipelineManageEdit.aspx?PipelineId={0}", Grid1.SelectedRowID, "编辑 - ")));
|
||
}
|
||
else
|
||
{
|
||
ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 增加管线信息
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnNew_Click(object sender, EventArgs e)
|
||
{
|
||
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_PipelineManageMenuId, Const.BtnAdd))
|
||
{
|
||
var workArea = BLL.Project_WorkAreaService.GetProject_WorkAreaByWorkAreaId(tvControlItem.SelectedNodeID);
|
||
if (workArea != null)
|
||
{
|
||
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PipelineManageEdit.aspx?workAreaId={0}", this.tvControlItem.SelectedNodeID, "新增 - ")));
|
||
}
|
||
else
|
||
{
|
||
ShowNotify(Resources.Lan.PleaseSelectAreaFirst, MessageBoxIcon.Warning);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 管线信息编辑
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnMenuEdit_Click(object sender, EventArgs e)
|
||
{
|
||
if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.HJGL_PipelineManageMenuId, BLL.Const.BtnModify))
|
||
{
|
||
if (Grid1.SelectedRowIndexArray.Length == 0)
|
||
{
|
||
Alert.ShowInTop(Resources.Lan.SelectLeastOneRecord, MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PipelineManageEdit.aspx?PipelineId={0}", Grid1.SelectedRowID, "维护 - ")));
|
||
}
|
||
else
|
||
{
|
||
ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 删除按钮
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnMenuDelete_Click(object sender, EventArgs e)
|
||
{
|
||
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_PipelineManageMenuId, Const.BtnDelete))
|
||
{
|
||
if (Grid1.SelectedRowIndexArray.Length == 0)
|
||
{
|
||
Alert.ShowInTop(Resources.Lan.SelectLeastOneRecord, MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
|
||
bool isShow = true;
|
||
if (Grid1.SelectedRowIndexArray.Length > 1)
|
||
{
|
||
isShow = false;
|
||
}
|
||
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
|
||
{
|
||
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
|
||
if (judgementDelete(rowID, isShow))
|
||
{
|
||
BLL.Pipeline_PipelineService.DeletePipeline(rowID);
|
||
BLL.Sys_LogService.AddLog(BLL.Const.System_3, this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_PipelineManageMenuId, Const.BtnDelete, rowID);
|
||
ShowNotify(Resources.Lan.DeletedSuccessfully, MessageBoxIcon.Success);
|
||
}
|
||
}
|
||
|
||
this.BindGrid();
|
||
}
|
||
else
|
||
{
|
||
ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 关闭弹出窗口及刷新页面
|
||
/// <summary>
|
||
/// 关闭弹出窗口
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void Window1_Close(object sender, WindowCloseEventArgs e)
|
||
{
|
||
this.BindGrid();
|
||
}
|
||
#endregion
|
||
|
||
#region 判断是否可删除
|
||
/// <summary>
|
||
/// 判断是否可以删除
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
private bool judgementDelete(string id, bool isShow)
|
||
{
|
||
string content = string.Empty;
|
||
|
||
string jotInfo = string.Empty;
|
||
var q = from x in Funs.DB.Pipeline_WeldJoint where x.PipelineId == id && x.WeldingDailyId != null select x;
|
||
if (q.Count() > 0)
|
||
{
|
||
foreach (var item in q)
|
||
{
|
||
jotInfo += Resources.Lan.WeldingJointNumber + ":" + item.WeldJointCode;
|
||
var dr = Funs.DB.Pipeline_WeldingDaily.FirstOrDefault(x => x.WeldingDailyId == item.WeldingDailyId);
|
||
if (dr != null)
|
||
{
|
||
jotInfo += ";" + Resources.Lan.DailyWeldingReportNumber + ":" + dr.WeldingDailyCode;
|
||
}
|
||
}
|
||
|
||
content = Resources.Lan.WeldingJointOfThePipeline + ":" + jotInfo;
|
||
}
|
||
if (string.IsNullOrEmpty(content))
|
||
{
|
||
return true;
|
||
}
|
||
else
|
||
{
|
||
if (isShow)
|
||
{
|
||
Alert.ShowInTop(content, MessageBoxIcon.Error);
|
||
}
|
||
return false;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 选择要显示列
|
||
/// <summary>
|
||
/// 选择显示列
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnSelectColumn_Click(object sender, EventArgs e)
|
||
{
|
||
PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("PipelineShowColumn.aspx", "显示列 - ")));
|
||
}
|
||
#endregion
|
||
|
||
protected void Window2_Close(object sender, WindowCloseEventArgs e)
|
||
{
|
||
this.BindGrid();
|
||
//显示列
|
||
Model.Sys_UserShowColumns c = BLL.UserShowColumnsService.GetColumnsByUserId(this.CurrUser.UserId, "Pipeline");
|
||
if (c != null)
|
||
{
|
||
this.GetShowColumn(c.Columns);
|
||
}
|
||
}
|
||
|
||
#region 显示的列
|
||
/// <summary>
|
||
/// 显示的列
|
||
/// </summary>
|
||
/// <param name="column"></param>
|
||
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;
|
||
|
||
List<string> columns = column.Split(',').ToList();
|
||
foreach (var item in columns)
|
||
{
|
||
this.Grid1.Columns[Convert.ToInt32(item)].Hidden = false;
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
}
|
||
} |