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.HJGL.HotProessManage { public partial class HotProessManageItemFind : PageBase { #region 定义项 /// /// 被选择项列表 /// public List SelectedList { get { return (List)ViewState["SelectedList"]; } set { ViewState["SelectedList"] = value; } } /// /// 未被选择项列表 /// public List NoSelectedList { get { return (List)ViewState["NoSelectedList"]; } set { ViewState["NoSelectedList"] = value; } } #endregion #region 加载页面 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.SelectedList = new List(); this.NoSelectedList = new List(); this.InitTreeMenu();//加载树 } else { if (GetRequestEventArgument() == "UPDATE_SUMMARY") { OutputSummaryData(); } } } private void OutputSummaryData() { JArray mergedData = Grid1.GetMergedData(); foreach (JObject mergedRow in mergedData) { JObject values = mergedRow.Value("values"); string hotProessRemark = values.Value("HotProessRemark"); int index = mergedRow.Value("index"); var joint = HJGL_PW_JointInfoService.GetJointInfoByJotID(this.Grid1.Rows[index].DataKeys[0].ToString()); if (joint != null) { joint.HotProessRemark = hotProessRemark; BLL.HJGL_PW_JointInfoService.UpdateHotProessRemark(joint); } } } #endregion #region 加载管线信息 /// /// 加载树 /// private void InitTreeMenu() { this.tvControlItem.Nodes.Clear(); TreeNode rootNode = new TreeNode(); rootNode.Text = "施工号-管线号"; rootNode.NodeID = "0"; rootNode.Expanded = true; this.tvControlItem.Nodes.Add(rootNode); List projects = BLL.Base_ProjectService.GetProjectListByUserId(this.CurrUser.UserId, "1"); List projectIds = projects.Select(x => x.ProjectId).ToList(); var iso = (from x in Funs.DB.HJGL_PW_IsoInfo join y in Funs.DB.HJGL_PW_JointInfo on x.ISO_ID equals y.ISO_ID join z in Funs.DB.HJGL_HotProessItem on y.JOT_ID equals z.JOT_ID where projectIds.Contains(x.ProjectId) && x.ISO_IsoNo.Contains(this.txtIsono.Text.Trim()) select x).Distinct().ToList(); foreach (var item in projects) { TreeNode rootUnitNode = new TreeNode();//定义根节点 rootUnitNode.Text = item.ProjectCode; rootUnitNode.NodeID = item.ProjectId; rootUnitNode.Expanded = false; rootUnitNode.EnableClickEvent = true; rootUnitNode.ToolTip = item.ProjectName; rootUnitNode.CommandName = "项目名称"; rootNode.Nodes.Add(rootUnitNode); var isos = (from x in iso where x.ProjectId == item.ProjectId orderby x.ISO_IsoNo select x).ToList(); this.BindNodes(rootUnitNode, isos); } } /// /// 绑定树节点 /// /// private void BindNodes(TreeNode node, List isos) { foreach (var item in isos) { TreeNode newNode = new TreeNode(); newNode.Text = item.ISO_IsoNo; newNode.NodeID = item.ISO_ID; newNode.ToolTip = item.ISO_IsoNo; newNode.CommandName = "管线号"; newNode.EnableClickEvent = true; node.Nodes.Add(newNode); } } #endregion #region 数据绑定 /// /// 数据绑定 /// private void BindGrid() { string strSql = string.Empty; List listStr = new List(); if (this.tvControlItem.SelectedNode.CommandName == "管线号") { strSql = @"SELECT distinct newid() as New_ID, HotProessItem.JOT_ID,HotProessItem.HotProessTrustId,Joint.HotProessRemark, (CASE WHEN v.RepairMark IS NOT NULL THEN (Joint.JOT_JointNo+v.RepairMark) ELSE Joint.JOT_JointNo END )+isnull((select Top 1 HardRepairMark from dbo.HJGL_CH_HotProessTrustItem a where a.JOT_ID=HotProessItem.JOT_ID and a.HotProessTrustId=HotProessItem.HotProessTrustId and a.ProessTypes=HotProessItem.ProessTypes),'') AS JOT_JointNo,Joint.JOT_JointDesc,(CASE WHEN Steel.STE_Code IS NOT NULL AND Steel2.STE_Code IS NOT NULL and Steel.STE_Code!=Steel2.STE_Code THEN Steel.STE_Code + '/' + Steel2.STE_Code WHEN Steel.STE_Code IS NOT NULL THEN Steel.STE_Code ELSE ISNULL(Steel2.STE_Code,'') END) AS STE_Code,IsoInfo.ISO_IsoNo,Joint.JOT_JointAttribute,InstallationName,TrustItem.TrustDate " + @" FROM HJGL_HotProessItem as HotProessItem" + @" left join dbo.HJGL_PW_JointInfo AS Joint on joint.jot_id=HotProessItem.jot_id " + @" LEFT JOIN dbo.HJGL_PW_IsoInfo AS IsoInfo on IsoInfo.ISO_ID=Joint.ISO_ID" + @" LEFT JOIN dbo.HJGL_BS_Steel AS Steel on Steel.STE_ID=Joint.STE_ID" + @" LEFT JOIN dbo.HJGL_BS_Steel AS Steel2 ON Joint.STE_ID2 = Steel2.STE_ID" + @" LEFT JOIN dbo.HJGL_CH_HotProessTrustItem AS TrustItem on TrustItem.HotProessTrustId=HotProessItem.HotProessTrustId and TrustItem.JOT_ID=HotProessItem.JOT_ID and TrustItem.ProessTypes='4'" + @" LEFT JOIN dbo.Project_Installation AS Installation on Installation.InstallationId=Joint.InstallationId" + @" left join (select record.RepairMark,record.JOT_ID,h.HotProessItemId from dbo.HJGL_CH_HotProessTrustItem AS TrustItem left join dbo.HJGL_CH_RepairItemRecord AS record ON record.RepairItemRecordId=TrustItem.TrustItemID left join dbo.HJGL_HotProessItem h on h.JOT_ID=TrustItem.JOT_ID where h.JOT_ID = TrustItem.JOT_ID and h.HotProessTrustId=TrustItem.HotProessTrustId and h.ProessTypes=TrustItem.ProessTypes) v on v.JOT_ID=HotProessItem.JOT_ID and v.HotProessItemId=HotProessItem.HotProessItemId" + @" WHERE (HotProessItem.RecordChartNo is null or HotProessItem.RecordChartNo='') and Joint.ISO_ID= @IsoId "; listStr.Add(new SqlParameter("@IsoId", this.tvControlItem.SelectedNodeID)); } else if (this.tvControlItem.SelectedNode.CommandName == "项目名称") { strSql = @"SELECT distinct newid() as New_ID, HotProessItem.JOT_ID,HotProessItem.HotProessTrustId,Joint.HotProessRemark, (CASE WHEN v.RepairMark IS NOT NULL THEN (Joint.JOT_JointNo+v.RepairMark) ELSE Joint.JOT_JointNo END )+isnull((select Top 1 HardRepairMark from dbo.HJGL_CH_HotProessTrustItem a where a.JOT_ID=HotProessItem.JOT_ID and a.HotProessTrustId=HotProessItem.HotProessTrustId and a.ProessTypes=HotProessItem.ProessTypes),'') AS JOT_JointNo,Joint.JOT_JointDesc,(CASE WHEN Steel.STE_Code IS NOT NULL AND Steel2.STE_Code IS NOT NULL and Steel.STE_Code!=Steel2.STE_Code THEN Steel.STE_Code + '/' + Steel2.STE_Code WHEN Steel.STE_Code IS NOT NULL THEN Steel.STE_Code ELSE ISNULL(Steel2.STE_Code,'') END) AS STE_Code,IsoInfo.ISO_IsoNo,Joint.JOT_JointAttribute,InstallationName,TrustItem.TrustDate " + @" FROM HJGL_HotProessItem as HotProessItem" + @" left join dbo.HJGL_PW_JointInfo AS Joint on joint.jot_id=HotProessItem.jot_id" + @" LEFT JOIN dbo.HJGL_PW_IsoInfo AS IsoInfo on IsoInfo.ISO_ID=Joint.ISO_ID" + @" LEFT JOIN dbo.HJGL_BS_Steel AS Steel on Steel.STE_ID=Joint.STE_ID" + @" LEFT JOIN dbo.HJGL_BS_Steel AS Steel2 ON Joint.STE_ID2 = Steel2.STE_ID" + @" LEFT JOIN dbo.HJGL_CH_HotProessTrustItem AS TrustItem on TrustItem.HotProessTrustId=HotProessItem.HotProessTrustId and TrustItem.JOT_ID=HotProessItem.JOT_ID and TrustItem.ProessTypes='4'" + @" LEFT JOIN dbo.Project_Installation AS Installation on Installation.InstallationId=Joint.InstallationId" + @" left join (select record.RepairMark,record.JOT_ID,h.HotProessItemId from dbo.HJGL_CH_HotProessTrustItem AS TrustItem left join dbo.HJGL_CH_RepairItemRecord AS record ON record.RepairItemRecordId=TrustItem.TrustItemID left join dbo.HJGL_HotProessItem h on h.JOT_ID=TrustItem.JOT_ID where h.JOT_ID = TrustItem.JOT_ID and h.HotProessTrustId=TrustItem.HotProessTrustId and h.ProessTypes=TrustItem.ProessTypes) v on v.JOT_ID=HotProessItem.JOT_ID and v.HotProessItemId=HotProessItem.HotProessItemId" + @" WHERE (HotProessItem.RecordChartNo is null or HotProessItem.RecordChartNo='') and Joint.ProjectId= @ProjectId "; listStr.Add(new SqlParameter("@ProjectId", this.tvControlItem.SelectedNodeID)); } 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); Grid1.DataSource = table; Grid1.DataBind(); string[] arr = new string[this.Grid1.Rows.Count]; int a = 0; for (int i = 0; i < this.Grid1.Rows.Count; i++) { string rowId = this.Grid1.Rows[i].DataKeys[0].ToString(); if (SelectedList.Contains(rowId)) { arr[a] = rowId; } a++; } Grid1.SelectedRowIDArray = arr; } #endregion #region 管线查询 /// /// 查询 /// /// /// protected void Tree_TextChanged(object sender, EventArgs e) { this.InitTreeMenu(); this.BindGrid(); } #endregion #region 点击TreeView /// /// 点击TreeView /// /// /// protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e) { string[] selectRowId = Grid1.SelectedRowIDArray; for (int i = 0; i < this.Grid1.Rows.Count; i++) { string jot_id = this.Grid1.Rows[i].DataKeys[0].ToString(); string rowId = this.Grid1.Rows[i].DataKeys[1].ToString(); string hotProessTrustId = this.Grid1.Rows[i].Values[7].ToString(); if (selectRowId.Contains(rowId)) { SelectedList.Add(jot_id + "," + hotProessTrustId); } else { NoSelectedList.Add(jot_id + "," + hotProessTrustId); } } this.BindGrid(); } #endregion #region 排序 /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, GridSortEventArgs e) { this.BindGrid(); } #endregion #region 提交按钮 /// /// 提交按钮 /// /// /// protected void btnAccept_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.txtRecordChartNo.Text.Trim())) { ShowNotify("记录曲线图编号不能为空!", MessageBoxIcon.Warning); return; } string recordChartNo = this.txtRecordChartNo.Text.Trim(); string[] selectRowId = Grid1.SelectedRowIDArray; for (int i = 0; i < this.Grid1.Rows.Count; i++) { string jot_id = this.Grid1.Rows[i].DataKeys[0].ToString(); string rowId = this.Grid1.Rows[i].DataKeys[1].ToString(); string hotProessTrustId = this.Grid1.Rows[i].Values[7].ToString(); if (selectRowId.Contains(rowId)) { SelectedList.Add(jot_id + "," + hotProessTrustId); } else { NoSelectedList.Add(jot_id + "," + hotProessTrustId); } } string itemsString = string.Empty; string jotIds = string.Empty; string hotProessTrustIds = string.Empty; var totalItems = from x in Funs.DB.HJGL_HotProessItem select x; Model.SGGLDB db = Funs.DB; foreach (var list in SelectedList.Distinct()) { string item = list.Split(',')[0]; string hotProessTrustId = list.Split(',')[1]; var items = totalItems.Where(x => x.JOT_ID == item && x.HotProessTrustId == hotProessTrustId); foreach (var a in items) { if (a != null) { if (string.IsNullOrEmpty(a.RecordChartNo)) //对于返修口,原口已经有曲线编号,则不更新 { a.RecordChartNo = recordChartNo; db.SubmitChanges(); } } } jotIds += item + ","; hotProessTrustIds += hotProessTrustId + ","; } itemsString = jotIds + "|" + hotProessTrustIds; PageContext.RegisterStartupScript(ActiveWindow.GetWriteBackValueReference(itemsString) + ActiveWindow.GetHidePostBackReference()); } #endregion } }