using BLL; using System; using System.Linq; using System.Web.UI.WebControls; namespace FineUIPro.Web.CLGL { public partial class OutPlanMasterSelect : PageBase { #region 定义项 /// /// 单位工程主键 /// public string UnitWorkId { get { return (string)ViewState["UnitWorkId"]; } set { ViewState["UnitWorkId"] = value; } } public string Id { get { return (string)ViewState["Id"]; } set { ViewState["Id"] = value; } } // public List Tree_hJGL_Pipelines; public int pageSize = PipelineService.pageSize; #endregion #region 加载页面 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { UnitWorkId = Request.QueryString["UnitWorkId"]; Id = Request.QueryString["Id"]; this.InitTreeMenu();//加载树 InitDropList(); } } #endregion #region 加载树 /// /// 加载树 /// private void InitTreeMenu() { this.tvControlItem.Nodes.Clear(); int a = (from x in Funs.DB.HJGL_Pipeline where x.ProjectId == this.CurrUser.LoginProjectId && x.UnitWorkId == this.UnitWorkId && x.PipeArea == PipelineService.PipeArea_SHOP && x.PipelineCode.Contains(this.txtPipelineCode.Text.Trim()) select x).Count(); int b = (from x in Funs.DB.HJGL_Pipeline where x.ProjectId == this.CurrUser.LoginProjectId && x.UnitWorkId == this.UnitWorkId && x.PipeArea == PipelineService.PipeArea_FIELD && x.PipelineCode.Contains(this.txtPipelineCode.Text.Trim()) select x).Count(); TreeNode rootNode1 = new TreeNode(); rootNode1.NodeID = BLL.PipelineService.PipeArea_SHOP; rootNode1.Text = "工厂预制"; rootNode1.CommandName = 1 + "|" + Funs.GetEndPageNumber(a, pageSize); //页码|总页 rootNode1.EnableClickEvent = true; rootNode1.EnableExpandEvent = true; this.tvControlItem.Nodes.Add(rootNode1); if (a > 0) { TreeNode newNode = new TreeNode(); newNode.Text = "加载管线..."; newNode.NodeID = "加载管线..."; rootNode1.Nodes.Add(newNode); } TreeNode rootNode2 = new TreeNode(); rootNode2.NodeID = BLL.PipelineService.PipeArea_FIELD; rootNode2.Text = "现场施工"; rootNode2.CommandName = 1 + "|" + Funs.GetEndPageNumber(b, pageSize); rootNode2.EnableClickEvent = true; rootNode2.EnableExpandEvent = true; this.tvControlItem.Nodes.Add(rootNode2); if (b > 0) { TreeNode newNode = new TreeNode(); newNode.Text = "加载管线..."; newNode.NodeID = "加载管线..."; rootNode2.Nodes.Add(newNode); } } void AddTreeNode(string PipeArea, TreeNode node) { var pipeline = (from x in Funs.DB.HJGL_Pipeline where x.ProjectId == this.CurrUser.LoginProjectId && x.UnitWorkId == this.UnitWorkId && x.PipeArea == PipeArea && x.PipelineCode.Contains(this.txtPipelineCode.Text.Trim()) orderby x.PipelineCode select x).ToList(); if (!string.IsNullOrEmpty(drpFlowingSection.SelectedValue) && drpFlowingSection.SelectedValue != Const._Null) { pipeline = pipeline.Where(x => x.FlowingSection == drpFlowingSection.SelectedValue).ToList(); } var joints = (from x in Funs.DB.HJGL_WeldJoint where x.ProjectId == this.CurrUser.LoginProjectId select x).ToList(); int pageindex = int.Parse(node.CommandName.Split('|')[0]); int pageCount = int.Parse(node.CommandName.Split('|')[1]); if (pageindex <= pageCount) { pipeline = pipeline.Skip(pageSize * (pageindex - 1)).Take(pageSize).ToList(); ; foreach (var item in pipeline) { TreeNode newNode = new TreeNode(); //bool istrue = BLL.HJGL_MaterialService.isInStockByPipeline(item.PipelineId, this.CurrUser.LoginProjectId); //if (istrue) //{ // newNode.CssClass = "tn-color-green"; //} newNode.Text = item.PipelineCode; newNode.NodeID = item.PipelineId; newNode.ToolTip = item.PipelineCode; newNode.EnableClickEvent = true; node.Nodes.Add(newNode); } if (pageindex < pageCount) { TreeNode newNode = new TreeNode(); newNode.Text = "加载"; newNode.NodeID = SQLHelper.GetNewID(); newNode.Icon = Icon.ArrowDown; newNode.CommandName = PipeArea; newNode.EnableClickEvent = true; node.Nodes.Add(newNode); } } } protected void tvControlItem_TreeNodeExpanded(object sender, TreeNodeEventArgs e) { if (e.Node.Nodes[0].NodeID == "加载管线...") { e.Node.Nodes.Clear(); if (e.Node.Text == "工厂预制") { AddTreeNode(BLL.PipelineService.PipeArea_SHOP, e.Node); } else if (e.Node.Text == "现场施工") { AddTreeNode(BLL.PipelineService.PipeArea_FIELD, e.Node); } } } #endregion #region 点击TreeView /// /// 点击TreeView /// /// /// protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e) { if (e.Node.Text == "加载") { 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); if (e.Node.CommandName == "1") { AddTreeNode(BLL.PipelineService.PipeArea_SHOP, e.Node.ParentNode); } else if (e.Node.CommandName == "2") { AddTreeNode(BLL.PipelineService.PipeArea_FIELD, e.Node.ParentNode); } } else { this.BindGrid(); } } #endregion #region 数据绑定 /// /// 数据绑定 /// private void BindGrid() { // 确保 SelectedNodeID 不为空 if (this.tvControlItem.SelectedNodeID == null) { return; // 或者显示一个提示 } int Category = (int)TwInOutplanmasterService.GetById(Id).Category; var tb = (from x in Funs.DB.HJGL_PipeLineMat join y in Funs.DB.HJGL_Pipeline on x.PipelineId equals y.PipelineId join z in Funs.DB.Tw_MaterialStock on x.MaterialCode equals z.PipeLineMatCode into zz from z in zz.DefaultIfEmpty() join lib in Funs.DB.HJGL_MaterialCodeLib on x.MaterialCode equals lib.MaterialCode where y.ProjectId == this.CurrUser.LoginProjectId && z.ProjectId == this.CurrUser.LoginProjectId && y.UnitWorkId == this.UnitWorkId && y.PipelineId == this.tvControlItem.SelectedNodeID && (x.PrefabricatedComponents == null || x.PrefabricatedComponents == "") select new { x.PipeLineMatId, x.PipelineId, x.MaterialCode, lib.MaterialName, lib.MaterialSpec, lib.MaterialUnit, PlanNum = x.Number, StockNum = z.StockNum ?? 0, x.IsLooseParts, }).ToList(); if (Category == (int)TwConst.Category.管段) { tb = tb.Where(x => x.MaterialUnit.Contains("米")).ToList(); } else { tb = tb.Where(x => x.MaterialUnit.Contains("个")).ToList(); } var inoutplandetail = (from x in Funs.DB.Tw_InOutPlanDetail_Relation //where x.InOutPlanMasterId == Id && x.PipelineId == this.tvControlItem.SelectedNodeID where x.PipelineId == this.tvControlItem.SelectedNodeID && (x.PrefabricatedComponents == null || x.PrefabricatedComponents == "") select x).ToList(); // 优化 Linq 过滤条件 tb = (from x in tb join y in inoutplandetail on x.MaterialCode equals y.MaterialCode into yy from y in yy.DefaultIfEmpty() where y == null select x).ToList(); Grid1.RecordCount = tb.Count; Grid1.DataSource = tb; Grid1.DataBind(); } private void InitDropList() { var pipeline = (from x in Funs.DB.HJGL_Pipeline where x.ProjectId == this.CurrUser.LoginProjectId && x.UnitWorkId == this.UnitWorkId select x.FlowingSection).Distinct().ToList(); this.drpFlowingSection.DataTextField = "Value"; this.drpFlowingSection.DataValueField = "Value"; this.drpFlowingSection.DataSource = pipeline; this.drpFlowingSection.DataBind(); Funs.FineUIPleaseSelect(drpFlowingSection); } #endregion #region 管线查询 /// /// 查询 /// /// /// protected void btnQuery_Click(object sender, EventArgs e) { this.InitTreeMenu(); this.BindGrid(); } #endregion #region 排序 /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, GridSortEventArgs e) { this.BindGrid(); } #endregion #region 提交按钮 /// /// 提交按钮 /// /// /// protected void btnAccept_Click(object sender, EventArgs e) { PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } protected void btnSave_Click(object sender, EventArgs e) { Save(); BindGrid(); } private void Save() { var List_Id = Grid1.SelectedRowIDArray; if (List_Id != null) { foreach (var id in List_Id) { var hJGL_PipeLineMat = BLL.PipelineMatService.GetPipeLineMat(id); if (hJGL_PipeLineMat != null) { var model = new Model.Tw_InOutPlanDetail_Relation() { Id = SQLHelper.GetNewID(), PipelineId = hJGL_PipeLineMat.PipelineId, MaterialCode = hJGL_PipeLineMat.MaterialCode, Number = hJGL_PipeLineMat.Number, PrefabricatedComponents = hJGL_PipeLineMat.PrefabricatedComponents, InOutPlanMasterId = Id, }; TwInoutplandetailRelationService.Add(model); } } } TwInOutplandetailService.GenInOutPlanDetailByInoutPlanMasterId(Id); } #endregion } }