using BLL; using Microsoft.Office.Interop.Word; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; namespace FineUIPro.Web.HJGL.WeldingManage { public partial class WeldingConDate : PageBase { public int pageSize = PipelineService.pageSize; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BLL.UnitService.InitUnitByProjectIdUnitTypeDropDownList(drpUnit, this.CurrUser.LoginProjectId, Const.ProjectUnitType_2, true); this.InitTreeMenu(); } } #region 加载树装置-单位-工作区 /// /// 加载树 /// private void InitTreeMenu() { this.tvControlItem.Nodes.Clear(); TreeNode rootNode1 = new TreeNode(); rootNode1.NodeID = "1"; rootNode1.Text = "建筑工程"; rootNode1.CommandName = "建筑工程"; rootNode1.Selectable = false; this.tvControlItem.Nodes.Add(rootNode1); TreeNode rootNode2 = new TreeNode(); rootNode2.NodeID = "2"; rootNode2.Text = "安装工程"; rootNode2.CommandName = "安装工程"; rootNode2.Expanded = true; this.tvControlItem.Nodes.Add(rootNode2); var pUnits = (from x in Funs.DB.Project_ProjectUnit where x.ProjectId == this.CurrUser.LoginProjectId select x).ToList(); // 获取当前用户所在单位 var currUnit = pUnits.FirstOrDefault(x => x.UnitId == this.CurrUser.UnitId); var unitWorkList = (from x in Funs.DB.WBS_UnitWork where x.ProjectId == this.CurrUser.LoginProjectId && x.SuperUnitWork == null && x.UnitId != null && x.ProjectType != null select x).ToList(); List unitWork1 = null; List unitWork2 = null; // 当前为施工单位,只能操作本单位的数据 if (currUnit != null && currUnit.UnitType == Const.ProjectUnitType_2) { unitWork1 = (from x in unitWorkList where x.UnitId == this.CurrUser.UnitId && x.ProjectType == "1" select x).ToList(); unitWork2 = (from x in unitWorkList where x.UnitId == this.CurrUser.UnitId && x.ProjectType == "2" select x).ToList(); } else { unitWork1 = (from x in unitWorkList where x.ProjectType == "1" select x).ToList(); unitWork2 = (from x in unitWorkList where x.ProjectType == "2" select x).ToList(); } if (unitWork1.Count() > 0) { foreach (var q in unitWork1) { int a = 0; if (ckNOEdit.Checked) { string strSql = "SELECT distinct PipelineCode FROM View_HJGL_WeldJoint WHERE IsTwoJoint IS NULL AND UnitWorkId =@UnitWorkId AND WPQId IS NULL"; List listStr = new List(); listStr.Add(new SqlParameter("@UnitWorkId", q.UnitWorkId)); SqlParameter[] parameter = listStr.ToArray(); System.Data.DataTable dt = SQLHelper.GetDataTableRunText(strSql, parameter); a = dt.Rows.Count; } else { a = (from x in Funs.DB.HJGL_Pipeline where x.ProjectId == this.CurrUser.LoginProjectId && x.UnitWorkId == q.UnitWorkId select x).Count(); } var u = BLL.UnitService.GetUnitByUnitId(q.UnitId); TreeNode tn1 = new TreeNode(); tn1.NodeID = q.UnitWorkId; tn1.Text = q.UnitWorkName + "【" + a.ToString() + "】" + "管线"; tn1.ToolTip = "施工单位:" + u.UnitName; tn1.CommandName = 1 + "|" + Funs.GetEndPageNumber(a, pageSize); tn1.EnableExpandEvent = true; tn1.EnableClickEvent = true; rootNode1.Nodes.Add(tn1); if (a > 0) { // BindNodes(tn1); TreeNode newNode = new TreeNode(); newNode.Text = "加载管线..."; newNode.NodeID = "加载管线..."; tn1.Nodes.Add(newNode); } } } if (unitWork2.Count() > 0) { foreach (var q in unitWork2) { int a = 0; if (ckNOEdit.Checked) { string strSql = "SELECT distinct PipelineCode FROM View_HJGL_WeldJoint WHERE IsTwoJoint IS NULL AND UnitWorkId =@UnitWorkId AND WPQId IS NULL"; List listStr = new List(); listStr.Add(new SqlParameter("@UnitWorkId", q.UnitWorkId)); SqlParameter[] parameter = listStr.ToArray(); System.Data.DataTable dt = SQLHelper.GetDataTableRunText(strSql, parameter); a = dt.Rows.Count; } else { a = (from x in Funs.DB.HJGL_Pipeline where x.ProjectId == this.CurrUser.LoginProjectId && x.UnitWorkId == q.UnitWorkId && x.PipelineCode.Contains(this.txtPipelineCode.Text.Trim()) select x).Count(); } var u = BLL.UnitService.GetUnitByUnitId(q.UnitId); TreeNode tn2 = new TreeNode(); tn2.NodeID = q.UnitWorkId; tn2.Text = q.UnitWorkName + "【" + a.ToString() + "】" + "管线"; //if (q.UnitWorkId == this.hdUnitWorkId.Text) //{ // tn2.Expanded = true; //} tn2.ToolTip = "施工单位:" + u.UnitName; tn2.CommandName = 1 + "|" + Funs.GetEndPageNumber(a, pageSize); tn2.EnableExpandEvent = true; tn2.EnableClickEvent = true; rootNode2.Nodes.Add(tn2); if (a > 0) { // BindNodes(tn2); TreeNode newNode = new TreeNode(); newNode.Text = "加载管线..."; newNode.NodeID = "加载管线..."; tn2.Nodes.Add(newNode); } } } } protected void tvControlItem_TreeNodeExpanded(object sender, TreeNodeEventArgs e) { if (e.Node.Nodes[0].NodeID == "加载管线...") { e.Node.Nodes.Clear(); BindNodes(e.Node); } } private void BindNodes(TreeNode node) { BLL.PipelineService.BindTreeNodes(node, ckNOEdit.Checked, this.txtPipelineCode.Text.Trim(), this.CurrUser.LoginProjectId, pageSize); } #endregion protected void btnTreeFind_Click(object sender, EventArgs e) { this.InitTreeMenu(); } #region 点击TreeView /// /// 点击TreeView /// /// /// protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e) { if (e.CommandName == "加载") { string CommandName = e.Node.ParentNode.CommandName; e.Node.ParentNode.CommandName = (int.Parse(CommandName.Split('|')[0]) + 1) + "|" + int.Parse(CommandName.Split('|')[1]); TreeNode treeNode = e.Node.ParentNode; treeNode.Nodes.Remove(e.Node); BindNodes(e.Node.ParentNode); } else { if (!string.IsNullOrEmpty(this.tvControlItem.SelectedNodeID)) { if (tvControlItem.SelectedNode.CommandName == "管线") { Model.HJGL_Pipeline pipeline = BLL.PipelineService.GetPipelineByPipelineId(this.tvControlItem.SelectedNodeID); this.hdUnitWorkId.Text = string.Empty; if (pipeline != null) { this.hdUnitWorkId.Text = this.tvControlItem.SelectedNode.ParentNode.NodeID; this.BindGrid(); } } else if (tvControlItem.SelectedNode.CommandName.Split('|').Count() == 2) { this.hdUnitWorkId.Text = this.tvControlItem.SelectedNode.NodeID; this.BindGrid(); } } } } #endregion #region 数据绑定 private void BindGrid() { string strSql = @"SELECT WeldJointId,WeldJointCode,PipelineId,PipelineCode,JointAttribute, IsWelding,IsHotProessStr,Material1Code,Material2Code,WeldTypeCode, Specification,HeartNo1,HeartNo2,Size,Dia,DNDia,Thickness,GrooveTypeCode, WeldingMethodCode,WeldingWireCode,WeldingRodCode,WeldingDate,WeldingDailyCode, BackingWelderCode,CoverWelderCode,MediumCode ,PreTemperature,JointArea,WPQCode,Remark FROM View_HJGL_WeldJoint WHERE IsTwoJoint IS NULL "; List listStr = new List { }; if (tvControlItem.SelectedNode.CommandName == "管线") { strSql += " AND PipelineId =@PipelineId"; listStr.Add(new SqlParameter("@PipelineId", tvControlItem.SelectedNodeID)); } else if (tvControlItem.SelectedNode.CommandName.Split('|').Count() == 2) { strSql += " AND UnitWorkId =@UnitWorkId"; listStr.Add(new SqlParameter("@UnitWorkId", tvControlItem.SelectedNodeID)); } if (!string.IsNullOrEmpty(this.txtWeldJointCode.Text.Trim())) { strSql += " AND WeldJointCode LIKE @WeldJointCode"; listStr.Add(new SqlParameter("@WeldJointCode", "%" + this.txtWeldJointCode.Text.Trim() + "%")); } if (rbInput.SelectedValue != "0") { if (rbInput.SelectedValue == "1") // 示录入 { strSql += " AND WPQId IS NULL"; } else { strSql += " AND WPQId IS NOT NULL"; } } SqlParameter[] parameter = listStr.ToArray(); System.Data.DataTable dt = SQLHelper.GetDataTableRunText(strSql, parameter); // 2.获取当前分页数据 Grid1.RecordCount = dt.Rows.Count; var table = this.GetPagedDataTable(Grid1, dt); Grid1.DataSource = table; Grid1.DataBind(); } #endregion protected void Grid1_RowDataBound(object sender, GridRowEventArgs e) { // DataRowView row = e.DataItem as DataRowView; string jotid = Grid1.DataKeys[e.RowIndex][0].ToString(); var jot = Funs.DB.HJGL_WeldJoint.FirstOrDefault(x => x.WeldJointId == jotid); if (jot != null && !string.IsNullOrEmpty(jot.MatchableWPQ)) { int wpqNum = jot.MatchableWPQ.Split(',').Count(); if (wpqNum > 1) { e.RowCssClass = "color1"; } } } #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 protected void TextBox_TextChanged(object sender, EventArgs e) { this.BindGrid(); } #endregion #region 焊口信息 维护事件 /// /// Grid双击事件 /// /// /// protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e) { if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.PersonId, BLL.Const.HJGL_WeldJointMenuId, BLL.Const.BtnModify)) { if (BLL.WeldTaskService.GetWeldTaskByWeldJointId(Grid1.SelectedRowID) != null) //已下任务单,不可修改数据 { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("WeldJointView.aspx?WeldJointId={0}&flag=2", Grid1.SelectedRowID, "编辑 - "))); } else { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("WeldJointEdit.aspx?WeldJointId={0}&flag=2", Grid1.SelectedRowID, "编辑 - "))); } } else { ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); } } /// /// 自动录入 /// /// /// protected void btnAutoInput_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(tvControlItem.SelectedNodeID)) { var jotList = from x in Funs.DB.HJGL_WeldJoint where x.PipelineId == tvControlItem.SelectedNodeID && x.WPQId == null select x; if (jotList.Count() > 0) { foreach (var jot in jotList) { List wpqList =BLL.WPQListServiceService.GetMatchWPQ(jot,this.CurrUser.LoginProjectId, drpUnit.SelectedValue); if (wpqList != null) { Model.HJGL_WeldJoint newJot = new Model.HJGL_WeldJoint(); Model.WPQ_WPQList wps = BLL.WPQListServiceService.GetWPQById(wpqList.First().WPQId); newJot.WPQId = wps.WPQId; newJot.WeldJointId = jot.WeldJointId; newJot.WeldingRod = wps.WeldingRod; newJot.WeldingWire = wps.WeldingWire; newJot.WeldingMethodId = wps.WeldingMethodId; newJot.GrooveTypeId = wps.GrooveType; newJot.PreTemperature = wps.PreTemperature; newJot.IsHotProess = wps.IsHotProess; newJot.MatchableWPQ = string.Join(",", wpqList.Select(x => x.WPQCode)); BLL.WeldJointService.UpdateConWeldJoint(newJot); } } } BindGrid(); ShowNotify("该管线焊口已完成自动录入!", MessageBoxIcon.Success); } } protected void btnEdit_Click(object sender, EventArgs e) { if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.PersonId, BLL.Const.HJGL_WeldJointMenuId, BLL.Const.BtnModify)) { if (BLL.WeldTaskService.GetWeldTaskByWeldJointId(Grid1.SelectedRowID) != null) //已下任务单,不可修改数据 { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("WeldJointView.aspx?WeldJointId={0}&flag=2", Grid1.SelectedRowID, "编辑 - "))); } else { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("WeldJointEdit.aspx?WeldJointId={0}&flag=2", Grid1.SelectedRowID, "编辑 - "))); } } else { ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); } } /// /// 焊口信息编辑 /// /// /// protected void btnMenuEdit_Click(object sender, EventArgs e) { if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.PersonId, BLL.Const.HJGL_WeldJointMenuId, BLL.Const.BtnModify)) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请至少选择一条记录", MessageBoxIcon.Warning); return; } if (BLL.WeldTaskService.GetWeldTaskByWeldJointId(Grid1.SelectedRowID) != null) //已下任务单,不可修改数据 { Alert.ShowInTop("该焊口已生成焊接任务单,不能编辑!", MessageBoxIcon.Warning); return; } PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("WeldJointEdit.aspx?WeldJointId={0}&flag=2", Grid1.SelectedRowID, "维护 - "))); } else { ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); } } protected void btnView_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请至少选择一条记录", MessageBoxIcon.Warning); return; } PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("WeldJointView.aspx?WeldJointId={0}&flag=2", Grid1.SelectedRowID, "维护 - "))); } #endregion protected void Window1_Close(object sender, WindowCloseEventArgs e) { this.BindGrid(); } } }