using BLL; using Model; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace FineUIPro.Web.TestRun.BeforeTestRun { public partial class SubWorkInspect : PageBase { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.InitTreeMenu();//加载树 } } #region 树绑定 /// /// 加载树 /// private void InitTreeMenu() { this.tvControlItem.Nodes.Clear(); TreeNode rootNode = new TreeNode(); rootNode.Text = "检查表"; rootNode.NodeID = "0"; rootNode.Expanded = true; rootNode.ToolTip = ""; rootNode.EnableClickEvent = true; this.tvControlItem.Nodes.Add(rootNode); var userSubInspects = Funs.DB.PreRun_SubInspectTermItem.Where(x => x.InspectedUser == this.CurrUser.UserId).ToList(); if (userSubInspects.Count == 0) return; var subSystemIds = userSubInspects.ConvertAll(x => x.SubSystemId); var workPackIds = userSubInspects.ConvertAll(x => x.WorkPackId); var list = from a in Funs.DB.PreRun_SysDevice join b in Funs.DB.PreRun_SubSysWorkPackage on a.PreRunId equals b.SubSystemId join c in Funs.DB.PreRun_WorkPackage on b.WorkPackId equals c.WorkPackId where a.ProjectId == this.CurrUser.LoginProjectId && subSystemIds.Contains(a.PreRunId) && workPackIds.Contains(c.WorkPackId) select new { a.PreRunId, a.PreRunCode, a.PreRunName, a.ProjectId, c.WorkPackId, c.WorkPackName }; if (list.Count() > 0) { var selectlist = new List(); var sysPipingData = from proper in Funs.DB.PreRun_PropertySysPiping join selectproper in Funs.DB.PreRun_SubPropertySelect on proper.PropertyId equals selectproper.PropertyId join inspectterm in Funs.DB.PreRun_SubInspectTerm on selectproper.PropertyId equals inspectterm.PropertyTechnologyId where subSystemIds.Contains(selectproper.SubSystemId) select new SelectPropertyTechnology() { Id = proper.PropertyId, Code = $"管道:({proper.PipingCode})", WorkPackId = inspectterm.WorkPackId, SubSystemId = selectproper.SubSystemId }; if (sysPipingData.Count() > 0) { selectlist.AddRange(sysPipingData); } var technologylist = from technology in Funs.DB.PreRun_TechnologySysPiping join selecttechnology in Funs.DB.PreRun_SubTechnologySelect on technology.TechnologyId equals selecttechnology.TechnologyId join inspectterm in Funs.DB.PreRun_SubInspectTerm on selecttechnology.TechnologyId equals inspectterm.PropertyTechnologyId where subSystemIds.Contains(selecttechnology.SubSystemId) select new SelectPropertyTechnology() { Id = technology.TechnologyId, Code = $"设备:({technology.TagNumber})", WorkPackId = inspectterm.WorkPackId, SubSystemId = selecttechnology.SubSystemId }; if (technologylist.Count() > 0) { selectlist.AddRange(technologylist); } var subList = list.GroupBy(x => new { x.PreRunId, x.PreRunCode, x.PreRunName }); foreach (var item in subList) { TreeNode rootUnitNode = new TreeNode();//定义根节点 rootUnitNode.NodeID = item.Key.PreRunId; rootUnitNode.Text = item.Key.PreRunName; rootUnitNode.ToolTip = item.Key.PreRunName; rootUnitNode.CommandName = ""; rootUnitNode.EnableClickEvent = false; rootUnitNode.EnableExpandEvent = false; rootNode.Nodes.Add(rootUnitNode); rootUnitNode.Expanded = true; var worklist = list.Where(a => a.PreRunId == item.Key.PreRunId).GroupBy(x => new { x.WorkPackId, x.WorkPackName }).ToList(); if (worklist.Count > 0) { foreach (var itemWork in worklist) { TreeNode newNode = new TreeNode(); newNode.Text = itemWork.Key.WorkPackName; newNode.NodeID = itemWork.Key.WorkPackId + "|" + item.Key.PreRunId; newNode.ToolTip = itemWork.Key.WorkPackName; newNode.CommandName = ""; newNode.EnableClickEvent = false; newNode.EnableExpandEvent = false; rootUnitNode.Nodes.Add(newNode); newNode.Expanded = true; if (selectlist.Count > 0) { var workselects = selectlist.Where(x => x.SubSystemId == item.Key.PreRunId && x.WorkPackId == itemWork.Key.WorkPackId); foreach (var itemSelect in workselects) { TreeNode newNodeSelect = new TreeNode(); newNodeSelect.Text = itemSelect.Code; newNodeSelect.NodeID = itemWork.Key.WorkPackId + "|" + item.Key.PreRunId + "|" + itemSelect.Id; newNodeSelect.ToolTip = itemSelect.Code; newNodeSelect.CommandName = ""; newNodeSelect.EnableClickEvent = true; newNodeSelect.EnableExpandEvent = true; newNode.Nodes.Add(newNodeSelect); newNodeSelect.Expanded = true; } } } } } } } /// /// 点击TreeView /// protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e) { this.BindGrid(); } #endregion #region 数据绑定 /// /// 绑定数据 /// public void BindGrid() { var workPackId = this.tvControlItem.SelectedNodeID.Split('|').First(); var subSystemId = this.tvControlItem.SelectedNodeID.Split('|')[1]; var propertytechnologyid = this.tvControlItem.SelectedNodeID.Split('|').Last(); //获取子系统 var subSysModel = Funs.DB.PreRun_SysDevice.FirstOrDefault(x => x.PreRunId == subSystemId); var list = Funs.DB.PreRun_SubInspectTermItem.Where(x => x.WorkPackId == workPackId && x.SubSystemId == subSystemId && x.PropertyTechnologyId == propertytechnologyid && x.InspectedUser == this.CurrUser.UserId).OrderBy(x => x.Sort).ToList(); Grid1.DataSource = list; Grid1.DataBind(); } /// /// 排序 /// protected void Grid1_Sort(object sender, GridSortEventArgs e) { Grid1.SortDirection = e.SortDirection; Grid1.SortField = e.SortField; BindGrid(); } #endregion #region 保存 /// /// 保存 /// protected void btnSave_Click(object sender, EventArgs e) { try { JArray mergedData = Grid1.GetMergedData(); foreach (JObject mergedRow in mergedData) { string status = mergedRow.Value("status"); JObject values = mergedRow.Value("values"); int i = mergedRow.Value("index"); var subItemId = this.Grid1.Rows[i].DataKeys[0].ToString(); //获取子系统信息 var model = Funs.DB.PreRun_SubInspectTermItem.FirstOrDefault(x => x.TermItemId == subItemId); if (model != null) { model.InspectionIllustrate = !string.IsNullOrWhiteSpace(values.Value("InspectionIllustrate")) ? values.Value("InspectionIllustrate") : string.Empty; if (!string.IsNullOrWhiteSpace(values.Value("InspectionResults"))) { model.InspectionResults = int.Parse(values.Value("InspectionResults")); } Funs.DB.SubmitChanges(); } } BindGrid(); ShowNotify("保存成功!"); } catch (Exception ex) { ShowNotify(ex.Message, MessageBoxIcon.Error); } } #endregion /// /// 子系统选择的管道/设备 /// public class SelectPropertyTechnology { /// /// 主键 /// public string Id { get; set; } /// /// 编码 /// public string Code { get; set; } /// /// 工作包主键 /// public string WorkPackId { get; set; } /// /// 子系统主键 /// public string SubSystemId { get; set; } } } }