using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using BLL; using System.Text; namespace FineUIPro.Web.WeldingProcess.WeldingManage { public partial class JointInfo : 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, "Joint"); if (c != null) { this.GetShowColumn(c.Columns); } if (CurrUser.Account == Const.Gly) { btnMenuDelAll.Hidden = false; } else { btnMenuDelAll.Hidden = true; } } } 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 totalPipeline = from x in Funs.DB.Pipeline_Pipeline 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(); var workAreaIdList = (from x in totalPipeline where x.ProjectId == this.CurrUser.LoginProjectId && x.PipelineCode.Contains(this.txtPipelineCode.Text.Trim()) orderby x.PipelineCode select x.WorkAreaId).Distinct().ToList(); pWorkArea = pWorkArea.Where(x => workAreaIdList.Contains(x.WorkAreaId)).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 绑定树节点 #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 == 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 == 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.UnitName; node.Nodes.Add(newNode); this.BindNodes(newNode, pInstallation, pWorkArea, pUnits); } } } else if (node.ToolTip == Resources.Lan.UnitName) { 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.EnableExpandEvent = true; newNode.ToolTip = Resources.Lan.Area; node.Nodes.Add(newNode); this.BindNodes(newNode, pInstallation, pWorkArea, pUnits); } } else if (node.ToolTip == Resources.Lan.Area) { TreeNode newNode = new TreeNode(); newNode.Text = Resources.Lan.Pipeline; newNode.NodeID = Resources.Lan.Pipeline; node.Nodes.Add(newNode); } } #endregion #region 树展开事件 /// /// 树展开事件 /// /// /// protected void tvControlItem_TreeNodeExpanded(object sender, TreeNodeEventArgs e) { if (e.Node.ToolTip == Resources.Lan.Area) { e.Node.Nodes.Clear(); List pipeline = new List(); var pipelines = from x in Funs.DB.Pipeline_Pipeline select x; pipeline = (from x in pipelines where x.ProjectId == this.CurrUser.LoginProjectId && x.WorkAreaId == e.Node.NodeID && x.PipelineCode.Contains(this.txtPipelineCode.Text.Trim()) orderby x.PipelineCode select x).ToList(); foreach (var item in pipeline) { var jotCount = (from x in Funs.DB.Pipeline_WeldJoint where x.PipelineId == item.PipelineId select x).Count(); TreeNode newNode = new TreeNode(); if (!String.IsNullOrEmpty(item.Sheet)) { newNode.Text = item.PipelineCode + "(" + item.Sheet + ")"; } else { newNode.Text = item.PipelineCode; } newNode.Text += "【" + jotCount.ToString() + " " + Resources.Lan.WeldingJoint + "】"; newNode.ToolTip = Resources.Lan.PipelinePage; newNode.NodeID = item.PipelineId; newNode.EnableClickEvent = true; e.Node.Nodes.Add(newNode); } } } #endregion #endregion #region 点击TreeView /// /// 点击TreeView /// /// /// protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e) { this.BindGrid(); } #endregion #region 数据绑定 /// /// 数据绑定 /// private void BindGrid() { string strSql = @"SELECT WeldJointId,ProjectId,PipelineId,WeldJointCode,PipingClassCode,PipeSegment,JointAttribute, ComponentsCode1,ComponentsCode2,Is_hjName,IsHotProessStr,Material1Code,Material2Code, WeldTypeCode,Specification,HeartNo1,HeartNo2,Size,Dia,Thickness,GrooveTypeCode, WeldingMethodCode,WeldSilkCode,WeldMatCode,WeldingDate,WeldingDailyCode,DoneDin, BackingWelderCode,CoverWelderCode,SystemNumber,TestPackageNo,Remark,WeldingLocationCode, (CASE WHEN IsCancel=1 THEN '是' ELSE '否' END) AS IsCancel FROM View_Pipeline_WeldJoint WHERE 1= 1"; List listStr = new List(); strSql += " AND PipelineId =@PipelineId"; listStr.Add(new SqlParameter("@PipelineId", this.tvControlItem.SelectedNodeID)); if (!string.IsNullOrEmpty(this.txtWeldJointCode.Text.Trim())) { strSql += " AND WeldJointCode LIKE @WeldJointCode"; listStr.Add(new SqlParameter("@WeldJointCode", "%" + this.txtWeldJointCode.Text.Trim() + "%")); } SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); // 2.获取当前分页数据 Grid1.RecordCount = tb.Rows.Count; var table = this.GetPagedDataTable(Grid1, tb); Grid1.DataSource = table; Grid1.DataBind(); } #endregion #region 分页排序 #region 页索引改变事件 /// /// 页索引改变事件 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { BindGrid(); } #endregion #region 排序 /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, GridSortEventArgs e) { BindGrid(); } #endregion #region 分页选择下拉改变事件 /// /// 分页选择下拉改变事件 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(); } #endregion #endregion protected void Grid1_RowDataBound(object sender, GridRowEventArgs e) { // e.DataItem -> System.Data.DataRowView or custom class. // e.RowIndex -> Current row index. // e.Values -> Rendered html for each column of this row. DataRowView row = e.DataItem as DataRowView; string IsCancel = row["IsCancel"].ToString(); //BoundField bfEntranceYear = Grid1.FindColumn("bfEntranceYear") as BoundField; if (IsCancel=="是") { e.RowAttributes["data-color"] = "color1"; } } #region 焊口信息 维护事件 /// /// Grid双击事件 /// /// /// protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e) { if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.HJGL_JointInfoMenuId, BLL.Const.BtnModify)) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("JointInfoEdit.aspx?WeldJointId={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_JointInfoMenuId, Const.BtnAdd)) { var pipeline = BLL.Pipeline_PipelineService.GetPipelineByPipelineId(tvControlItem.SelectedNodeID); if (pipeline != null) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("JointInfoEdit.aspx?PipelineId={0}", this.tvControlItem.SelectedNodeID, "新增 - "))); } else { ShowNotify(Resources.Lan.PleaseSelectPipelinetFirst, MessageBoxIcon.Warning); } } else { ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning); } } /// /// 批量增加焊口信息 /// /// /// protected void btnBatchAdd_Click(object sender, EventArgs e) { if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_JointInfoMenuId, Const.BtnAdd)) { var pipeline = BLL.Pipeline_PipelineService.GetPipelineByPipelineId(tvControlItem.SelectedNodeID); if (pipeline != null) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("JointInfoBatchEdit.aspx?PipelineId={0}", this.tvControlItem.SelectedNodeID, "新增 - "))); } else { ShowNotify(Resources.Lan.PleaseSelectPipelinetFirst, 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_JointInfoMenuId, BLL.Const.BtnModify)) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop(Resources.Lan.SelectLeastOneRecord, MessageBoxIcon.Warning); return; } PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("JointInfoEdit.aspx?WeldJointId={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_JointInfoMenuId, 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_WeldJointService.DeleteWeldJointById(rowID); BLL.Sys_LogService.AddLog(BLL.Const.System_3, this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_JointInfoMenuId, Const.BtnDelete, rowID); } } ShowNotify(Resources.Lan.DeletedSuccessfully, MessageBoxIcon.Success); this.BindGrid(); } else { Alert.ShowInTop(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning); } } #endregion protected void btnMenuDelAll_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(Grid1.SelectedRowID)) { Alert.ShowInTop("请选择要删除的记录!", MessageBoxIcon.Warning); return; } string jotId = Grid1.SelectedRowID; // 删除焊口所有业务数据 BLL.Batch_NDEItemService.DeleteAllNDEInfoToWeldJoint(jotId); BLL.Pipeline_WeldJointService.DeleteWeldJointById(jotId); BLL.Sys_LogService.AddLog(BLL.Const.System_3, this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_JointInfoMenuId, Const.BtnDelete, jotId); ShowNotify(Resources.Lan.DeletedSuccessfully, MessageBoxIcon.Success); this.BindGrid(); } #region 报表打印 /// /// 报表打印 /// /// /// protected void btnPrint_Click(object sender, EventArgs e) { string pipelineId = this.tvControlItem.SelectedNodeID; var q = BLL.Pipeline_PipelineService.GetPipelineByPipelineId(pipelineId); if (q != null) { string varValue = string.Empty; var project = BLL.Base_ProjectService.GetProjectByProjectId(this.CurrUser.LoginProjectId); var area = BLL.Project_WorkAreaService.GetProject_WorkAreaByWorkAreaId(q.WorkAreaId); if (area != null) { var ins = BLL.Project_InstallationService.GetProject_InstallationByInstallationId(area.InstallationId); varValue = project.ProjectName + "|" + ins.InstallationName; } if (!string.IsNullOrEmpty(varValue)) { varValue = Microsoft.JScript.GlobalObject.escape(varValue.Replace("/", ",")); } //PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("../../Common/ReportPrint/ExReportPrint.aspx?ispop=1&reportId={0}&replaceParameter={1}&varValue={2}&projectId={3}", BLL.Const.HJGL_JointInfoReportId, pipelineId, varValue, this.CurrUser.LoginProjectId))); } else { ShowNotify(Resources.Lan.PleaseSelectPipeline, MessageBoxIcon.Warning); return; } } #endregion #region 关闭弹出窗口及刷新页面 /// /// 关闭弹出窗口 /// /// /// protected void Window1_Close(object sender, WindowCloseEventArgs e) { this.InitTreeMenu();//加载树 this.BindGrid(); } /// /// 查询 /// /// /// protected void btnSearch_Click(object sender, EventArgs e) { this.BindGrid(); } /// /// 查询 /// /// /// protected void btnTreeSearch_Click(object sender, EventArgs e) { this.InitTreeMenu(); this.BindGrid(); } #endregion #region 判断是否可删除 /// /// 判断是否可以删除 /// /// private bool judgementDelete(string id, bool isShow) { string content = string.Empty; if (!string.IsNullOrEmpty(BLL.Pipeline_WeldJointService.GetWeldJointByWeldJointId(id).WeldingDailyId)) { content = "该焊口已焊接,不能删除!"; } if (BLL.Funs.DB.HotProess_TrustItem.FirstOrDefault(x => x.WeldJointId == id) != null) { content = "热处理已经使用了该焊口,不能删除!"; } //if (BLL.Funs.DB.HJGL_CH_CheckItem.FirstOrDefault(x => x.WeldJointId == id) != null) //{ // content = "检测单已经使用了该焊口,不能删除!"; //} if (string.IsNullOrEmpty(content)) { return true; } else { if (isShow) { Alert.ShowInTop(content, MessageBoxIcon.Error); } return false; } } #endregion #region 导出焊口信息 /// /// 导出焊口信息 /// /// /// protected void btnOut_Click(object sender, EventArgs e) { var iso = BLL.Pipeline_PipelineService.GetPipelineByPipelineId(this.tvControlItem.SelectedNodeID); var workArea = BLL.Project_WorkAreaService.GetProject_WorkAreaByWorkAreaId(this.tvControlItem.SelectedNodeID); if (iso != null) { PageContext.RegisterStartupScript(Window3.GetShowReference(String.Format("JointInfoOut.aspx?PipelineId={0}", this.tvControlItem.SelectedNodeID, "导出 - "))); } else if (workArea != null) { PageContext.RegisterStartupScript(Window3.GetShowReference(String.Format("JointInfoOut.aspx?WorkAreaId={0}", this.tvControlItem.SelectedNodeID, "导出 - "))); } else { Alert.ShowInTop(Resources.Lan.PleaseSelectPipelineOrArea, MessageBoxIcon.Warning); } } /// /// 导出焊口初始信息 /// /// /// protected void btnOut2_Click(object sender, EventArgs e) { var iso = BLL.Pipeline_PipelineService.GetPipelineByPipelineId(this.tvControlItem.SelectedNodeID); if (iso != null) { Response.ClearContent(); string filename = Funs.GetNewFileName(); Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode(Resources.Lan.WeldingJointInfo + filename, System.Text.Encoding.UTF8) + ".xls"); Response.ContentType = "application/excel"; Response.ContentEncoding = System.Text.Encoding.UTF8; this.Grid1.PageSize = 100000; this.BindGrid(); Response.Write(GetGridTableHtml(Grid1)); Response.End(); } else { Alert.ShowInTop(Resources.Lan.PleaseSelectPipelinetFirst, MessageBoxIcon.Warning); } } /// /// 导出方法 /// /// /// private string GetGridTableHtml(Grid grid) { StringBuilder sb = new StringBuilder(); sb.Append(""); sb.Append(""); sb.Append(""); foreach (GridColumn column in grid.Columns) { if (column.HeaderText != Resources.Lan.SerialNumber) { sb.AppendFormat("", column.HeaderText); } } sb.Append(""); foreach (GridRow row in grid.Rows) { sb.Append(""); foreach (GridColumn column in grid.Columns) { string html = row.Values[column.ColumnIndex].ToString(); if (column.ColumnID != "tfNumber") { //html = (row.FindControl("lblNumber") as AspNet.Label).Text; sb.AppendFormat("", html); } //sb.AppendFormat("", html); } sb.Append(""); } sb.Append("
{0}
{0}{0}
"); return sb.ToString(); } #endregion #region 选择要显示列 /// /// 选择显示列 /// /// /// protected void btnSelectColumn_Click(object sender, EventArgs e) { PageContext.RegisterStartupScript(Window4.GetShowReference(String.Format("JointShowColumn.aspx", "显示列 - "))); } #endregion #region 显示列 protected void Window4_Close(object sender, WindowCloseEventArgs e) { this.BindGrid(); //显示列 Model.Sys_UserShowColumns c = BLL.UserShowColumnsService.GetColumnsByUserId(this.CurrUser.UserId, "Joint"); if (c != null) { this.GetShowColumn(c.Columns); } } /// /// 显示的列 /// /// 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; List columns = column.Split(',').ToList(); foreach (var item in columns) { if (!string.IsNullOrEmpty(item)) { this.Grid1.Columns[Convert.ToInt32(item)].Hidden = false; } } } } #endregion } }