SGGL_SHJ/SGGL/FineUIPro.Web/HJGL/PreDesign/PackagingManageSelect.aspx.cs

372 lines
15 KiB
C#
Raw Normal View History

2025-05-08 18:38:55 +08:00
using BLL;
using FastReport.DevComponents.DotNetBar;
using FineUIPro.Web.HJGL.WeldingManage;
2025-05-12 19:05:13 +08:00
using Model;
2025-05-08 18:38:55 +08:00
using System;
2025-05-12 19:05:13 +08:00
using System.Collections;
2025-05-08 18:38:55 +08:00
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace FineUIPro.Web.HJGL.PreDesign
{
public partial class PackagingManageSelect : PageBase
{
#region
// public List<HJGL_Pipeline> Tree_hJGL_Pipelines;
public int pageSize = PipelineService.pageSize;
public string PackagingManageId
{
get
{
return (string)ViewState["PackagingManageId"];
}
set
{
ViewState["PackagingManageId"] = value;
}
}
#endregion
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
PackagingManageId = Request.QueryString["PackagingManageId"];
this.InitTreeMenu();//加载树
InitDropList();
}
}
#endregion
#region
private void BindNodes(TreeNode node)
{
BLL.PipelineService.BindTreeNodes(node, this.tvPipeCode.Text.Trim(), txtMaterialCode.Text.Trim(), this.CurrUser.LoginProjectId, pageSize);
}
/// <summary>
/// 加载树
/// </summary>
private void InitTreeMenu()
{
this.tvControlItem.Nodes.Clear();
TreeNode rootNode1 = new TreeNode();
rootNode1.NodeID = "1";
rootNode1.Text = "建筑工程";
rootNode1.CommandName = "建筑工程";
rootNode1.Selectable = false;
this.tvControlItem.Nodes.Add(rootNode1);
TreeNode rootNode2 = new TreeNode();
rootNode2.NodeID = "2";
rootNode2.Text = "安装工程";
rootNode2.CommandName = "安装工程";
rootNode2.Expanded = true;
this.tvControlItem.Nodes.Add(rootNode2);
var pUnits = (from x in Funs.DB.Project_ProjectUnit where x.ProjectId == this.CurrUser.LoginProjectId select x).ToList();
// 获取当前用户所在单位
var currUnit = pUnits.FirstOrDefault(x => x.UnitId == this.CurrUser.UnitId);
var unitWorkList = (from x in Funs.DB.WBS_UnitWork
where x.ProjectId == this.CurrUser.LoginProjectId
&& x.SuperUnitWork == null && x.UnitId != null && x.ProjectType != null
select x).ToList();
List<Model.WBS_UnitWork> unitWork1 = null;
List<Model.WBS_UnitWork> unitWork2 = null;
//// 当前为施工单位,只能操作本单位的数据
//if (currUnit != null && currUnit.UnitType == Const.ProjectUnitType_2)
//{
// unitWork1 = (from x in unitWorkList
// where x.UnitId == this.CurrUser.UnitId && x.ProjectType == "1"
// select x).ToList();
// unitWork2 = (from x in unitWorkList
// where x.UnitId == this.CurrUser.UnitId && x.ProjectType == "2"
// select x).ToList();
//}
//else
//{
unitWork1 = (from x in unitWorkList where x.ProjectType == "1" select x).ToList();
unitWork2 = (from x in unitWorkList where x.ProjectType == "2" select x).ToList();
//}
//var dbpipeLineMat = from x in Funs.DB.HJGL_PipeLineMat select x;
//var DBpipeline = from x in Funs.DB.HJGL_Pipeline where x.ProjectId == this.CurrUser.LoginProjectId select x;
if (unitWork1.Count() > 0)
{
foreach (var q in unitWork1)
{
string strSql = " SELECT DISTINCT [t0].[PipelineId] FROM [dbo].[HJGL_Pipeline] AS [t0]\r\nleft JOIN [dbo].[HJGL_PipeLineMat] AS [t1] ON [t0].[PipelineId] = [t1].[PipelineId]";
strSql += "where [t0].[UnitWorkId] =@UnitWorkId ";
List<SqlParameter> listStr = new List<SqlParameter>();
listStr.Add(new SqlParameter("@UnitWorkId", q.UnitWorkId));
if (!string.IsNullOrEmpty(txtMaterialCode.Text.Trim()))
{
strSql += " and [t1].[MaterialCode] like @MaterialCode";
listStr.Add(new SqlParameter("@MaterialCode", "%" + txtMaterialCode.Text.Trim() + "%"));
}
if (!string.IsNullOrEmpty(tvPipeCode.Text.Trim()))
{
strSql += " and [t0].[PipelineCode] like @PipelineCode";
listStr.Add(new SqlParameter("@PipelineCode", "%" + tvPipeCode.Text.Trim() + "%"));
}
SqlParameter[] parameter = listStr.ToArray();
DataTable dt = SQLHelper.GetDataTableRunText(strSql, parameter);
var a = dt.Rows.Count;
//int a = (from x in DBpipeline
// join y in dbpipeLineMat on x.PipelineId equals y.PipelineId
// where x.PipelineCode.Contains(tvPipeCode.Text.Trim()) && x.UnitWorkId == q.UnitWorkId
// && y.MaterialCode.Contains(txtMaterialCode.Text.Trim())
// select x.PipelineId).Distinct().Count();
var unitNamesUnitIds = BLL.UnitService.getUnitNamesUnitIds(q.UnitId);
TreeNode tn1 = new TreeNode();
tn1.NodeID = q.UnitWorkId;
tn1.Text = q.UnitWorkName + "【" + a.ToString() + "】" + "管线";
tn1.ToolTip = "施工单位:" + unitNamesUnitIds;
tn1.CommandName = 1 + "|" + Funs.GetEndPageNumber(a, pageSize);
tn1.EnableExpandEvent = true;
rootNode1.Nodes.Add(tn1);
if (a > 0)
{
// BindNodes(tn1);
TreeNode newNode = new TreeNode();
newNode.Text = "加载管线...";
newNode.NodeID = "加载管线...";
tn1.Nodes.Add(newNode);
}
}
}
if (unitWork2.Count() > 0)
{
foreach (var q in unitWork2)
{
string strSql = " SELECT DISTINCT [t0].[PipelineId] FROM [dbo].[HJGL_Pipeline] AS [t0]\r\nleft JOIN [dbo].[HJGL_PipeLineMat] AS [t1] ON [t0].[PipelineId] = [t1].[PipelineId]";
strSql += "where [t0].[UnitWorkId] =@UnitWorkId ";
List<SqlParameter> listStr = new List<SqlParameter>();
listStr.Add(new SqlParameter("@UnitWorkId", q.UnitWorkId));
if (!string.IsNullOrEmpty(txtMaterialCode.Text.Trim()))
{
strSql += " and [t1].[MaterialCode] like @MaterialCode";
listStr.Add(new SqlParameter("@MaterialCode", "%" + txtMaterialCode.Text.Trim() + "%"));
}
if (!string.IsNullOrEmpty(tvPipeCode.Text.Trim()))
{
strSql += " and [t0].[PipelineCode] like @PipelineCode";
listStr.Add(new SqlParameter("@PipelineCode", "%" + tvPipeCode.Text.Trim() + "%"));
}
SqlParameter[] parameter = listStr.ToArray();
DataTable dt = SQLHelper.GetDataTableRunText(strSql, parameter);
var a = dt.Rows.Count;
//var b = (from x in Funs.DB.HJGL_Pipeline
// join y in Funs.DB.HJGL_PipeLineMat on x.PipelineId equals y.PipelineId
// where x.ProjectId == this.CurrUser.LoginProjectId && x.UnitWorkId == q.UnitWorkId && y.MaterialCode.Contains(txtMaterialCode.Text.Trim())
// select x).Distinct();
//var b = (from x in DBpipeline
// join y in dbpipeLineMat on x.PipelineId equals y.PipelineId
// where x.PipelineCode.Contains(tvPipeCode.Text.Trim()) && x.UnitWorkId == q.UnitWorkId
// && y.MaterialCode.Contains(txtMaterialCode.Text.Trim())
// select x.PipelineId).Distinct();
//int a = (from x in DBpipeline
// join y in dbpipeLineMat on x.PipelineId equals y.PipelineId
// where x.PipelineCode.Contains(tvPipeCode.Text.Trim()) && x.UnitWorkId == q.UnitWorkId
// && y.MaterialCode.Contains(txtMaterialCode.Text.Trim())
// select x.PipelineId).Distinct().Count();
var unitNamesUnitIds = BLL.UnitService.getUnitNamesUnitIds(q.UnitId);
TreeNode tn2 = new TreeNode();
tn2.NodeID = q.UnitWorkId;
tn2.Text = q.UnitWorkName + "【" + a.ToString() + "】" + "管线";
//if (q.UnitWorkId == this.hdUnitWorkId.Text)
//{
// tn2.Expanded = true;
//}
tn2.ToolTip = "施工单位:" + unitNamesUnitIds;
tn2.CommandName = 1 + "|" + Funs.GetEndPageNumber(a, pageSize);
tn2.EnableExpandEvent = true;
tn2.EnableClickEvent = true;
rootNode2.Nodes.Add(tn2);
if (a > 0)
{
// BindNodes(tn2);
TreeNode newNode = new TreeNode();
newNode.Text = "加载管线...";
newNode.NodeID = "加载管线...";
tn2.Nodes.Add(newNode);
}
}
}
}
#endregion
#region Methods
protected void btnTreeFind_Click(object sender, EventArgs e)
{
this.InitTreeMenu();
//this.BindGrid3(this.tvControlItem.SelectedNodeID);
}
#endregion Methods
#region Methods
protected void tvControlItem_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
{
if (e.Node.Nodes[0].NodeID == "加载管线...")
{
e.Node.Nodes.Clear();
BindNodes(e.Node);
}
}
#endregion Methods
#region TreeView
/// <summary>
/// 点击TreeView
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e)
{
if (e.CommandName == "加载")
{
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);
BindNodes(e.Node.ParentNode);
}
else
{
if (!string.IsNullOrEmpty(this.tvControlItem.SelectedNodeID))
{
Model.HJGL_Pipeline pipeline = BLL.PipelineService.GetPipelineByPipelineId(this.tvControlItem.SelectedNodeID);
this.hdUnitWorkId.Text = string.Empty;
if (pipeline != null)
{
this.hdUnitWorkId.Text = this.tvControlItem.SelectedNode.ParentNode.NodeID;
this.BindGrid(this.tvControlItem.SelectedNodeID, this.hdUnitWorkId.Text);
}
}
}
}
#endregion TreeView
#region
2025-05-12 19:05:13 +08:00
private void BindGrid(string pipelineId, string unitworkid)
2025-05-08 18:38:55 +08:00
{
2025-05-12 19:05:13 +08:00
var Prelist = HJGL_PipelineComponentService.GetPipelinePrefabricatedComponent(unitworkid, pipelineId);
2025-05-08 18:38:55 +08:00
var inoutplandetail = (from x in Funs.DB.HJGL_PackagingManageDetail
2025-05-12 19:05:13 +08:00
where x.PipelineId == pipelineId
&& (x.PipelineComponentId == null || x.PipelineComponentId == "")
select x).ToList();
var queryList = Prelist;
// 优化 Linq 过滤条件,过滤已经进入包装的预制散件
var result = (from x in queryList
join y in inoutplandetail on x.MaterialCode equals y.MaterialCode into yy
from y in yy.DefaultIfEmpty()
where y == null
select x).ToList();
2025-05-08 18:38:55 +08:00
Grid1.DataSource = result;
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
/// <summary>
/// 提交按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnAccept_Click(object sender, EventArgs e)
{
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
protected void btnSave_Click(object sender, EventArgs e)
{
Save();
this.BindGrid(this.tvControlItem.SelectedNodeID, this.hdUnitWorkId.Text);
}
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.HJGL_PackagingManageDetail()
{
Id = SQLHelper.GetNewID(),
PackagingManageId = this.PackagingManageId,
PipelineId = hJGL_PipeLineMat.PipelineId,
MaterialCode = hJGL_PipeLineMat.MaterialCode,
Number = hJGL_PipeLineMat.Number,
CreateTime = DateTime.Now,
CreateUser = this.CurrUser.PersonId,
};
2025-05-12 19:05:13 +08:00
HJGLPackagingmanagedetailService.Add(model);
2025-05-08 18:38:55 +08:00
}
}
}
}
#endregion
}
}