using BLL; using Model; using NPOI.SS.Formula.Functions; using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace FineUIPro.Web.WeldingProcess.PMI { public partial class PMISelectList : PageBase { string UnitId = string.Empty; string ProjectId = string.Empty; string PMIId = string.Empty; string weldJointIds=string.Empty; string installId=string.Empty; #region 加载页面 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { this.UnitId = Request.Params["unitId"] ?? ""; this.ProjectId = this.CurrUser.LoginProjectId; this.PMIId = Request.Params["PMIId"] ?? ""; this.weldJointIds = Request.Params["weldJointIds"] ?? ""; this.installId = Request.Params["installId"]; if (!IsPostBack) { this.InitTreeMenu();//加载树 this.BindGrid(); } } #endregion #region 加载管线信息 /// /// 加载树 /// private void InitTreeMenu() { this.tvControlItem.Nodes.Clear(); TreeNode rootNode = new TreeNode(); rootNode.Text = Resources.Lan.PipelineCode; rootNode.NodeID = "0"; rootNode.ToolTip = Resources.Lan.SeachTip; rootNode.Expanded = true; this.tvControlItem.Nodes.Add(rootNode); //排除已经委托过的 var listData= (from a in Funs.DB.PMI_Delegation.AsQueryable() join b in Funs.DB.PMI_DelegationDetails.AsQueryable() on a.Id equals b.PMIId select b.JointId ).Distinct().ToList(); //查询带有PMI处理的管线数据 var iso = (from a in Funs.DB.Pipeline_Pipeline join b in Funs.DB.Project_WorkArea on a.WorkAreaId equals b.WorkAreaId join c in Funs.DB.Pipeline_WeldJoint on a.PipelineId equals c.PipelineId where a.ProjectId==this.ProjectId && a.UnitId==this.UnitId && a.InstallationId==this.installId && c.IsPMI==true select new { a.PipelineCode, a.PipelineId, b.WorkAreaId, b.WorkAreaCode, c.WeldJointId, c.WeldJointCode }); if (listData.Count > 0) { iso = iso.Where(e => !listData.Contains(e.WeldJointId)); } if (!string.IsNullOrEmpty(this.txtIsono.Text)) { iso = iso.Where(e => e.PipelineCode.Contains(this.txtIsono.Text.Trim())); } var isoList = iso.Select(x => new { x.PipelineId,x.PipelineCode,x.WorkAreaCode}).OrderBy(x => x.PipelineCode).Distinct().ToList(); if (isoList.Count > 0) { foreach (var q in isoList) { TreeNode newNode = new TreeNode(); newNode.NodeID = q.PipelineId; newNode.Text = q.PipelineCode + "(" + q.WorkAreaCode + ")"; newNode.EnableClickEvent = true; rootNode.Nodes.Add(newNode); } } } #endregion #region 管线查询 /// /// 查询 /// /// /// protected void Tree_TextChanged(object sender, EventArgs e) { this.InitTreeMenu(); } protected void Tree2_TextChanged(object sender, EventArgs e) { this.BindGrid(); } #endregion #region 点击TreeView /// /// 点击TreeView /// /// /// protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e) { this.BindGrid(); } #endregion #region 数据绑定 /// /// 数据绑定 /// private void BindGrid() { var listData = (from a in Funs.DB.PMI_Delegation.AsQueryable() join b in Funs.DB.PMI_DelegationDetails.AsQueryable() on a.Id equals b.PMIId select b.JointId ).Distinct().ToList(); string[] arr = this.weldJointIds.Split('|'); var query = Funs.DB.View_Pipeline_WeldJoint.Where(t => t.IsPMI == true && t.PipelineId == this.tvControlItem.SelectedNodeID); if (arr.Length > 0) { listData.Add(arr[0]); } if (listData.Count > 0) { query = query.Where(t => !listData.Contains(t.WeldJointId)); } if (!string.IsNullOrEmpty(this.txtJointNo.Text)) { query = query.Where(t => t.WeldJointCode == this.txtJointNo.Text); } var data= query.ToList() ; if (!string.IsNullOrEmpty(weldJointIds)) { string[] jots = weldJointIds.Split('|'); data = data.Where(t => !jots.Contains(t.WeldJointId)).ToList(); } data = data.OrderBy(t => t.WeldJointCode).ToList(); Grid1.DataSource = data; Grid1.DataBind(); } #endregion #region 排序 /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, GridSortEventArgs e) { this.BindGrid(); } #endregion #region 提交按钮 /// /// 提交按钮 /// /// /// protected void btnAccept_Click(object sender, EventArgs e) { string itemsString = ""; string[] selectRowId = Grid1.SelectedRowIDArray; int n = 0; int j = 0; int[] selections = new int[selectRowId.Count()]; foreach (GridRow row in Grid1.Rows) { if (selectRowId.Contains(row.DataKeys[0])) { selections[n] = j; n++; } j++; } var select = selections.Distinct(); string jotIds = Request.Params["jotIds"]; if (!string.IsNullOrEmpty(jotIds)) { string[] jots = jotIds.Split('|'); foreach (string jotId in jots) { itemsString += jotId + "|"; } } foreach (int i in select) { string rowID = Grid1.DataKeys[i][0].ToString(); if (!itemsString.Contains(rowID)) { itemsString += rowID + "|"; } } PageContext.RegisterStartupScript(ActiveWindow.GetWriteBackValueReference(itemsString) + ActiveWindow.GetHidePostBackReference()); } #endregion } }