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 加载树装置-单位-工作区
///
/// 加载树
///
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 绑定树节点
///
/// 绑定树节点
///
///
private void BindNodes(TreeNode node, List pInstallation, List pWorkArea, List pUnits)
{
if (node==null)
{
List 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 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
///
/// 点击TreeView
///
///
///
protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e)
{
this.BindGrid();
}
#endregion
#region 数据绑定
///
/// 数据绑定
///
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 listStr = new List();
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 计算合计
///
/// 计算合计
///
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 页索引改变事件
///
/// 页索引改变事件
///
///
///
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 查询
///
/// 下拉框选择事件
///
///
///
protected void btnSearch_Click(object sender, EventArgs e)
{
BindGrid();
}
protected void btnTreeSearch_Click(object sender, EventArgs e)
{
this.InitTreeMenu();
}
#endregion
#region 管线信息 维护事件
///
/// Grid双击事件
///
///
///
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);
}
}
///
/// 增加管线信息
///
///
///
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);
}
}
///
/// 管线信息编辑
///
///
///
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);
}
}
///
/// 删除按钮
///
///
///
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 关闭弹出窗口及刷新页面
///
/// 关闭弹出窗口
///
///
///
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
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.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 选择要显示列
///
/// 选择显示列
///
///
///
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 显示的列
///
/// 显示的列
///
///
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 columns = column.Split(',').ToList();
foreach (var item in columns)
{
this.Grid1.Columns[Convert.ToInt32(item)].Hidden = false;
}
}
}
#endregion
}
}