SGGL_SHJ/SGGL/FineUIPro.Web/CLGL/OutPlanMasterSelect.aspx.cs

364 lines
13 KiB
C#
Raw Normal View History

2024-09-24 20:38:50 +08:00
using BLL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace FineUIPro.Web.CLGL
{
public partial class OutPlanMasterSelect : PageBase
{
#region
2024-09-25 15:13:49 +08:00
2024-09-24 20:38:50 +08:00
/// <summary>
/// 单位工程主键
/// </summary>
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<HJGL_Pipeline> Tree_hJGL_Pipelines;
public int pageSize = PipelineService.pageSize;
#endregion
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
2024-09-25 15:13:49 +08:00
UnitWorkId=Request.QueryString["UnitWorkId"];
Id = Request.QueryString["Id"];
2024-09-24 20:38:50 +08:00
this.InitTreeMenu();//加载树
2024-09-25 15:13:49 +08:00
InitDropList();
2024-09-24 20:38:50 +08:00
}
}
#endregion
#region
/// <summary>
/// 加载树
/// </summary>
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();
2024-09-27 18:17:21 +08:00
2024-09-24 20:38:50 +08:00
//bool istrue = BLL.HJGL_MaterialService.isInStockByPipeline(item.PipelineId, this.CurrUser.LoginProjectId);
//if (istrue)
//{
// newNode.CssClass = "tn-color-green";
//}
2024-09-27 18:17:21 +08:00
newNode.Text = item.PipelineCode;
2024-09-24 20:38:50 +08:00
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
/// <summary>
/// 点击TreeView
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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
/// <summary>
/// 数据绑定
/// </summary>
private void BindGrid()
{
2024-09-25 15:13:49 +08:00
// 确保 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
2024-09-25 15:13:49 +08:00
&& y.UnitWorkId == this.UnitWorkId
&& y.PipelineId == this.tvControlItem.SelectedNodeID
&& (x.PrefabricatedComponents==null||x.PrefabricatedComponents=="")
2024-09-25 15:13:49 +08:00
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
2025-02-18 17:38:49 +08:00
&& (x.PrefabricatedComponents == null || x.PrefabricatedComponents == "")
2024-09-25 15:13:49 +08:00
select x).ToList();
2024-09-24 20:38:50 +08:00
2024-09-25 15:13:49 +08:00
// 优化 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();
2024-09-24 20:38:50 +08:00
2024-09-25 15:13:49 +08:00
2024-09-25 15:13:49 +08:00
Grid1.RecordCount = tb.Count;
Grid1.DataSource = tb;
Grid1.DataBind();
2024-09-24 20:38:50 +08:00
}
2024-09-25 15:13:49 +08:00
2024-09-24 20:38:50 +08:00
private void InitDropList()
{
2024-09-25 15:13:49 +08:00
var pipeline = (from x in Funs.DB.HJGL_Pipeline
2024-09-24 20:38:50 +08:00
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();
2024-09-25 15:13:49 +08:00
Funs.FineUIPleaseSelect(drpFlowingSection);
2024-09-24 20:38:50 +08:00
}
#endregion
#region 线
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnQuery_Click(object sender, EventArgs e)
{
this.InitTreeMenu();
this.BindGrid();
}
#endregion
#region
/// <summary>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort(object sender, GridSortEventArgs e)
{
this.BindGrid();
}
#endregion
#region
/// <summary>
/// 提交按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnAccept_Click(object sender, EventArgs e)
{
2024-09-25 15:13:49 +08:00
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
2024-09-24 20:38:50 +08:00
}
protected void btnSave_Click(object sender, EventArgs e)
{
2024-09-25 15:13:49 +08:00
Save();
BindGrid();
2024-09-24 20:38:50 +08:00
}
2024-09-25 15:13:49 +08:00
private void Save()
2024-09-24 20:38:50 +08:00
{
2024-09-25 15:13:49 +08:00
var List_Id = Grid1.SelectedRowIDArray;
if (List_Id != null)
2024-09-24 20:38:50 +08:00
{
2024-09-25 15:13:49 +08:00
foreach (var id in List_Id)
2024-09-24 20:38:50 +08:00
{
2024-09-25 15:13:49 +08:00
var hJGL_PipeLineMat = BLL.PipelineMatService.GetPipeLineMat(id);
if (hJGL_PipeLineMat != null)
2024-09-24 20:38:50 +08:00
{
2024-09-25 15:13:49 +08:00
var model = new Model.Tw_InOutPlanDetail_Relation()
2024-09-24 20:38:50 +08:00
{
2024-09-25 15:13:49 +08:00
Id = SQLHelper.GetNewID(),
PipelineId = hJGL_PipeLineMat.PipelineId,
MaterialCode = hJGL_PipeLineMat.MaterialCode,
Number = hJGL_PipeLineMat.Number,
PrefabricatedComponents = hJGL_PipeLineMat.PrefabricatedComponents,
InOutPlanMasterId = Id,
};
TwInoutplandetailRelationService.Add(model);
2024-09-24 20:38:50 +08:00
}
}
2024-09-25 15:13:49 +08:00
}
TwInOutplandetailService.GenInOutPlanDetailByInoutPlanMasterId(Id);
2024-09-24 20:38:50 +08:00
}
2024-09-25 15:13:49 +08:00
#endregion
2024-09-24 20:38:50 +08:00
}
}