2025-06-04 22:46:21 +08:00
using BLL ;
2025-06-09 17:20:34 +08:00
using FineUIPro.Web.ProjectData ;
2025-06-04 22:46:21 +08:00
using MiniExcelLibs ;
using Model ;
using Newtonsoft.Json.Linq ;
2025-06-09 17:20:34 +08:00
using NPOI.SS.Formula.Functions ;
2025-06-04 22:46:21 +08:00
using System ;
using System.Collections.Generic ;
using System.Data ;
using System.Data.SqlClient ;
using System.Data.SqlTypes ;
using System.Drawing ;
using System.IO ;
using System.Linq ;
using System.Runtime.InteropServices ;
2025-06-09 17:20:34 +08:00
using System.Security.Cryptography ;
2025-06-04 22:46:21 +08:00
using System.Web ;
using System.Web.WebSockets ;
namespace FineUIPro.Web.HJGL.PreDesign
{
public partial class ProductionSchedulingPlan : PageBase
{
public int pageSize = 20 ;
public static DataTable GridDataTable = new DataTable ( ) ;
protected void Page_Load ( object sender , EventArgs e )
{
if ( ! IsPostBack )
{
this . ddlPageSize . SelectedValue = this . Grid1 . PageSize . ToString ( ) ;
this . InitTreeMenu ( ) ; //加载树
}
}
#region 加 载 树 装 置 - 单 位 - 工 作 区
/// <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 ( ) ;
//}
if ( unitWork1 . Count ( ) > 0 )
{
foreach ( var q in unitWork1 )
{
2025-06-09 17:20:34 +08:00
int a = ( from x in Funs . DB . HJGL_Pipeline where x . ProjectId = = this . CurrUser . LoginProjectId & & x . UnitWorkId = = q . UnitWorkId & & x . PipeArea = = "1" select x . FlowingSection ) . Distinct ( ) . Count ( ) ;
2025-06-04 22:46:21 +08:00
var unitNamesUnitIds = BLL . UnitService . getUnitNamesUnitIds ( q . UnitId ) ;
TreeNode tn1 = new TreeNode ( ) ;
tn1 . NodeID = q . UnitWorkId ;
//tn1.Text = q.UnitWorkName + "【" + a.ToString() + "】" + "管线";
tn1 . Text = q . UnitWorkName ;
tn1 . ToolTip = "施工单位:" + unitNamesUnitIds ;
tn1 . CommandName = 1 + "|" + Funs . GetEndPageNumber ( a , pageSize ) ;
tn1 . EnableClickEvent = true ;
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 (a > 0)
//{
// BindNodes(tn1);
//}
}
}
if ( unitWork2 . Count ( ) > 0 )
{
foreach ( var q in unitWork2 )
{
2025-06-09 17:20:34 +08:00
int a = ( from x in Funs . DB . HJGL_Pipeline where x . ProjectId = = this . CurrUser . LoginProjectId & & x . UnitWorkId = = q . UnitWorkId & & x . PipeArea = = "1" select x . FlowingSection ) . Distinct ( ) . Count ( ) ;
2025-06-04 22:46:21 +08:00
var unitNamesUnitIds = BLL . UnitService . getUnitNamesUnitIds ( q . UnitId ) ;
TreeNode tn2 = new TreeNode ( ) ;
tn2 . NodeID = q . UnitWorkId ;
//tn2.Text = q.UnitWorkName + "【" + a.ToString() + "】" + "管线";
tn2 . Text = q . UnitWorkName ;
if ( q . UnitWorkId = = this . hdUnitWorkId . Text )
{
tn2 . Expanded = true ;
}
tn2 . ToolTip = "施工单位:" + unitNamesUnitIds ;
tn2 . CommandName = 1 + "|" + Funs . GetEndPageNumber ( a , pageSize ) ;
tn2 . EnableClickEvent = true ;
tn2 . EnableExpandEvent = true ;
rootNode2 . Nodes . Add ( tn2 ) ;
if ( a > 0 )
{
// BindNodes(tn1);
TreeNode newNode = new TreeNode ( ) ;
newNode . Text = "加载流水段..." ;
newNode . NodeID = "加载流水段..." ;
tn2 . Nodes . Add ( newNode ) ;
}
//if (a > 0)
//{
// BindNodes(tn2);
//}
}
}
}
private void BindNodes ( TreeNode node )
{
List < string > flowingSection = new List < string > ( ) ;
//List<Model.HJGL_Pipeline> pipeline = new List<Model.HJGL_Pipeline>();
2025-06-09 17:20:34 +08:00
var list = ( from x in Funs . DB . HJGL_Pipeline where x . ProjectId = = this . CurrUser . LoginProjectId & & x . PipeArea = = "1" & & x . UnitWorkId = = node . NodeID select x . FlowingSection ) . ToList ( ) ;
2025-06-04 22:46:21 +08:00
flowingSection = list . Where ( x = > ! string . IsNullOrWhiteSpace ( x ) = = true ) . Distinct ( ) . OrderBy ( x = > x ) . ToList ( ) ;
//int pageindex = int.Parse(node.CommandName.Split('|')[0]);
//int pageCount = int.Parse(node.CommandName.Split('|')[1]);
//if (pageindex <= pageCount)
//{
// flowingSection = flowingSection.Skip(pageSize * (pageindex - 1)).Take(pageSize).ToList();
foreach ( var item in flowingSection )
{
//var comCount = (from x in Funs.DB.HJGL_Pipeline_Component where x.PipelineId == item.PipelineId select x).Count();
TreeNode newNode = new TreeNode ( ) ;
//newNode.Text = item.PipelineCode + "【" + comCount.ToString() + " " + "组件" + "】";
newNode . Text = item ;
newNode . ToolTip = "流水段" ;
newNode . CommandName = "流水段" ;
newNode . NodeID = SQLHelper . GetNewID ( ) ;
newNode . EnableClickEvent = true ;
node . Nodes . Add ( newNode ) ;
}
// if (pageindex < pageCount)
// {
// TreeNode newNode = new TreeNode();
// newNode.Text = "加载";
// newNode.NodeID = "加载";
// //newNode.NodeID = SQLHelper.GetNewID();
// newNode.CommandName = "加载";
// newNode.Icon = Icon.ArrowDown;
// newNode.EnableClickEvent = true;
// node.Nodes.Add(newNode);
// }
//}
}
#endregion
protected void tvControlItem_TreeNodeExpanded ( object sender , TreeNodeEventArgs e )
{
if ( e . Node . Nodes [ 0 ] . NodeID = = "加载流水段..." )
{
e . Node . Nodes . Clear ( ) ;
BindNodes ( e . Node ) ;
}
}
#region 点 击 TreeView
/// <summary>
/// 点击TreeView
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void tvControlItem_NodeCommand ( object sender , TreeCommandEventArgs e )
{
2025-06-09 17:20:34 +08:00
//if (e.CommandName == "流水段")
//{
// Model.HJGL_Pipeline pipeline = BLL.PipelineService.GetPipelineByFlowingSection(this.tvControlItem.SelectedNode.Text);
// this.hdUnitWorkId.Text = string.Empty;
// if (pipeline != null)
// {
// this.hdUnitWorkId.Text = this.tvControlItem.SelectedNode.ParentNode.NodeID;
// SaveProductionSchedulingPlan();
// }
//}
2025-06-04 22:46:21 +08:00
this . BindGrid ( ) ;
}
/// <summary>
/// 保存数据
/// </summary>
/// <exception cref="NotImplementedException"></exception>
private void SaveProductionSchedulingPlan ( )
{
if ( ! string . IsNullOrEmpty ( this . tvControlItem . SelectedNodeID ) )
{
2025-09-24 15:27:48 +08:00
string projectId = this . CurrUser . LoginProjectId ;
2025-06-09 17:20:34 +08:00
if ( tvControlItem . SelectedNode . CommandName = = "流水段" )
{
List < SqlParameter > listStr = new List < SqlParameter > ( ) ;
2025-09-24 15:27:48 +08:00
listStr . Add ( new SqlParameter ( "@projectId" , projectId ) ) ;
2025-06-09 17:20:34 +08:00
if ( ! string . IsNullOrEmpty ( this . tvControlItem . SelectedNode . ParentNode . NodeID ) )
{
listStr . Add ( new SqlParameter ( "@unitWorkId" , this . tvControlItem . SelectedNode . ParentNode . NodeID ) ) ;
}
else
{
listStr . Add ( new SqlParameter ( "@unitWorkId" , null ) ) ;
}
if ( ! string . IsNullOrEmpty ( this . tvControlItem . SelectedNode . Text ) )
{
listStr . Add ( new SqlParameter ( "@flowingSection" , this . tvControlItem . SelectedNode . Text ) ) ;
}
else
{
listStr . Add ( new SqlParameter ( "@flowingSection" , null ) ) ;
}
if ( ! string . IsNullOrEmpty ( this . txtSize . Text . Trim ( ) ) )
{
listStr . Add ( new SqlParameter ( "@caliber" , this . txtSize . Text . Trim ( ) ) ) ;
}
SqlParameter [ ] parameter = listStr . ToArray ( ) ;
DataTable tb = SQLHelper . GetDataTableRunProc ( "Sp_ProductionSchedulingPlanStatistics" , parameter ) ;
2025-07-23 13:27:58 +08:00
//删除原有数据
2025-09-24 15:27:48 +08:00
BLL . ProductionSchedulingPlanService . DeleteProductionSchedulingPlanByUnitWorkIdAndFlowNum ( projectId , this . tvControlItem . SelectedNode . ParentNode . Text , this . tvControlItem . SelectedNode . Text ) ;
2025-06-09 17:20:34 +08:00
for ( int i = 0 ; i < tb . Rows . Count ; i + + )
{
2025-08-04 10:44:32 +08:00
string unitWorkId = tb . Rows [ i ] [ "UnitWorkId" ] . ToString ( ) ; //单位工程
string flowingSection = tb . Rows [ i ] [ "FlowingSection" ] . ToString ( ) ; //流水号
string steelType = tb . Rows [ i ] [ "SteelType" ] . ToString ( ) ; //材质Value
string material = tb . Rows [ i ] [ "Material" ] . ToString ( ) ; //材质Text
string caliber = tb . Rows [ i ] [ "Caliber" ] . ToString ( ) ; //寸径
2025-09-24 15:27:48 +08:00
var plan = BLL . ProductionSchedulingPlanService . GetProductionSchedulingPlan ( projectId , flowingSection , unitWorkId , material , caliber ) ;
2025-06-09 17:20:34 +08:00
if ( plan = = null )
{
Model . HJGL_ProductionSchedulingPlan newPlan = new HJGL_ProductionSchedulingPlan ( ) ;
newPlan . ProductionSchedulingPlanId = SQLHelper . GetNewID ( typeof ( Model . HJGL_ProductionSchedulingPlan ) ) ;
2025-09-24 15:27:48 +08:00
newPlan . ProjectId = projectId ;
2025-08-04 10:44:32 +08:00
newPlan . PipelineId = unitWorkId ;
newPlan . FlowNum = flowingSection ;
2025-06-09 17:20:34 +08:00
newPlan . MainItemName = tb . Rows [ i ] [ "UnitWorkName" ] . ToString ( ) ;
2025-08-04 10:44:32 +08:00
newPlan . Material = material ;
newPlan . Caliber = caliber ;
2025-09-24 15:27:48 +08:00
newPlan . Dain = BLL . WeldJointService . GetSizeSum ( projectId , unitWorkId , flowingSection , steelType , caliber , "1" ) ; //达因数
var dyne = BLL . WeldJointService . GetSizeSumByUnitWorkIdAndFlowingSectionAndMaterial ( projectId , unitWorkId , flowingSection , steelType ) ; //总达因(按材质)
if ( dyne ! = null )
{
newPlan . TotalDyne = dyne ;
}
else
{
newPlan . TotalDyne = 0 ;
}
newPlan . PriorityTotalDyne = BLL . WeldJointService . GetSizeSumByUnitWorkIdAndFlowingSection ( projectId , unitWorkId , flowingSection , "1" ) ; //总达因
//当日已完成量
var currentDay = BLL . WeldJointService . GetCurrentDaySizeSum ( projectId , unitWorkId , flowingSection , steelType , caliber ) ;
if ( currentDay ! = null )
{
newPlan . OnDayCompleteDyne = currentDay ;
}
else
{
newPlan . OnDayCompleteDyne = 0 ;
}
newPlan . CompletedCount = BLL . WeldJointService . GetSizeSum ( projectId , unitWorkId , flowingSection , steelType , caliber , "2" ) ; //累计已完成量
2025-08-04 10:44:32 +08:00
if ( newPlan . Dain > 0 )
{
2025-09-24 15:27:48 +08:00
newPlan . CompletedRate = ( newPlan . CompletedCount / newPlan . Dain ) * 100 ; //已完成百分比
2025-08-04 10:44:32 +08:00
}
else
{
newPlan . CompletedRate = 0 ;
}
2025-09-24 15:27:48 +08:00
if ( newPlan . PriorityTotalDyne > 0 )
2025-08-04 10:44:32 +08:00
{
2025-09-24 15:27:48 +08:00
decimal? completeDinSum = BLL . WeldJointService . GetSizeSumByUnitWorkIdAndFlowingSection ( projectId , unitWorkId , flowingSection , "2" ) ; //完成总达因
newPlan . TotalCompletedRate = ( completeDinSum / newPlan . PriorityTotalDyne ) * 100 ; //已完成百分比汇总
2025-08-04 10:44:32 +08:00
}
else
{
newPlan . TotalCompletedRate = 0 ;
}
2025-06-09 17:20:34 +08:00
BLL . ProductionSchedulingPlanService . AddProductionSchedulingPlan ( newPlan ) ;
}
}
}
else if ( tvControlItem . SelectedNode . CommandName . Split ( '|' ) . Length = = 2 ) //单位工程
{
List < SqlParameter > listStr = new List < SqlParameter > ( ) ;
2025-09-24 15:27:48 +08:00
listStr . Add ( new SqlParameter ( "@projectId" , projectId ) ) ;
2025-06-09 17:20:34 +08:00
if ( ! string . IsNullOrEmpty ( this . tvControlItem . SelectedNode . NodeID ) )
{
listStr . Add ( new SqlParameter ( "@unitWorkId" , this . tvControlItem . SelectedNode . NodeID ) ) ;
}
else
{
listStr . Add ( new SqlParameter ( "@unitWorkId" , null ) ) ;
}
if ( ! string . IsNullOrEmpty ( this . txtSize . Text . Trim ( ) ) )
{
listStr . Add ( new SqlParameter ( "@caliber" , this . txtSize . Text . Trim ( ) ) ) ;
}
SqlParameter [ ] parameter = listStr . ToArray ( ) ;
DataTable tb = SQLHelper . GetDataTableRunProc ( "Sp_ProductionSchedulingPlanStatistics" , parameter ) ;
2025-07-23 13:27:58 +08:00
//删除原有数据
2025-09-24 15:27:48 +08:00
BLL . ProductionSchedulingPlanService . DeleteProductionSchedulingPlanByUnitWork ( projectId , this . tvControlItem . SelectedNode . Text ) ;
2025-06-09 17:20:34 +08:00
for ( int i = 0 ; i < tb . Rows . Count ; i + + )
{
2025-08-04 10:44:32 +08:00
string unitWorkId = tb . Rows [ i ] [ "UnitWorkId" ] . ToString ( ) ; //单位工程
string flowingSection = tb . Rows [ i ] [ "FlowingSection" ] . ToString ( ) ; //流水号
string steelType = tb . Rows [ i ] [ "SteelType" ] . ToString ( ) ; //材质Value
string material = tb . Rows [ i ] [ "Material" ] . ToString ( ) ; //材质Text
string caliber = tb . Rows [ i ] [ "Caliber" ] . ToString ( ) ; //寸径
2025-09-24 15:27:48 +08:00
var plan = BLL . ProductionSchedulingPlanService . GetProductionSchedulingPlan ( projectId , flowingSection , unitWorkId , material , caliber ) ;
2025-06-09 17:20:34 +08:00
if ( plan = = null )
{
Model . HJGL_ProductionSchedulingPlan newPlan = new HJGL_ProductionSchedulingPlan ( ) ;
newPlan . ProductionSchedulingPlanId = SQLHelper . GetNewID ( typeof ( Model . HJGL_ProductionSchedulingPlan ) ) ;
2025-09-24 15:27:48 +08:00
newPlan . ProjectId = projectId ;
2025-08-04 10:44:32 +08:00
newPlan . PipelineId = unitWorkId ;
newPlan . FlowNum = flowingSection ;
2025-06-09 17:20:34 +08:00
newPlan . MainItemName = tb . Rows [ i ] [ "UnitWorkName" ] . ToString ( ) ;
2025-08-04 10:44:32 +08:00
newPlan . Material = material ;
newPlan . Caliber = caliber ;
2025-09-24 15:27:48 +08:00
newPlan . Dain = BLL . WeldJointService . GetSizeSum ( projectId , unitWorkId , flowingSection , steelType , caliber , "1" ) ; //达因数
var dyne = BLL . WeldJointService . GetSizeSumByUnitWorkIdAndFlowingSectionAndMaterial ( projectId , unitWorkId , flowingSection , steelType ) ; //总达因(按材质)
if ( dyne ! = null )
{
newPlan . TotalDyne = dyne ;
}
else
{
newPlan . TotalDyne = 0 ;
}
newPlan . PriorityTotalDyne = BLL . WeldJointService . GetSizeSumByUnitWorkIdAndFlowingSection ( projectId , unitWorkId , flowingSection , "1" ) ; //总达因
//当日已完成量
var currentDay = BLL . WeldJointService . GetCurrentDaySizeSum ( projectId , unitWorkId , flowingSection , steelType , caliber ) ;
if ( currentDay ! = null )
{
newPlan . OnDayCompleteDyne = currentDay ;
}
else
{
newPlan . OnDayCompleteDyne = 0 ;
}
newPlan . CompletedCount = BLL . WeldJointService . GetSizeSum ( projectId , unitWorkId , flowingSection , steelType , caliber , "2" ) ; //累计已完成量
2025-08-04 10:44:32 +08:00
if ( newPlan . Dain > 0 )
{
2025-09-24 15:27:48 +08:00
newPlan . CompletedRate = ( newPlan . CompletedCount / newPlan . Dain ) * 100 ; //已完成百分比
2025-08-04 10:44:32 +08:00
}
else
{
newPlan . CompletedRate = 0 ;
}
2025-09-24 15:27:48 +08:00
if ( newPlan . PriorityTotalDyne > 0 )
2025-08-04 10:44:32 +08:00
{
2025-09-24 15:27:48 +08:00
decimal? completeDinSum = BLL . WeldJointService . GetSizeSumByUnitWorkIdAndFlowingSection ( projectId , unitWorkId , flowingSection , "2" ) ; //完成总达因
newPlan . TotalCompletedRate = ( completeDinSum / newPlan . PriorityTotalDyne ) * 100 ; //已完成百分比汇总
2025-08-04 10:44:32 +08:00
}
else
{
newPlan . TotalCompletedRate = 0 ;
}
2025-06-09 17:20:34 +08:00
BLL . ProductionSchedulingPlanService . AddProductionSchedulingPlan ( newPlan ) ;
}
}
}
2025-07-23 13:27:58 +08:00
//else if (this.tvControlItem.SelectedNodeID == "1" || this.tvControlItem.SelectedNodeID == "2")
//{
// List<SqlParameter> listStr = new List<SqlParameter>();
// listStr.Add(new SqlParameter("@projectId", this.CurrUser.LoginProjectId));
// if (!string.IsNullOrEmpty(this.hdUnitWorkId.Text))
// {
// listStr.Add(new SqlParameter("@unitWorkId", this.hdUnitWorkId.Text));
// }
// else
// {
// listStr.Add(new SqlParameter("@unitWorkId", null));
// }
// if (!string.IsNullOrEmpty(this.txtSize.Text.Trim()))
// {
// listStr.Add(new SqlParameter("@caliber", this.txtSize.Text.Trim()));
// }
// SqlParameter[] parameter = listStr.ToArray();
// DataTable tb = SQLHelper.GetDataTableRunProc("Sp_ProductionSchedulingPlanStatistics", parameter);
// for (int i = 0; i < tb.Rows.Count; i++)
// {
// if (!string.IsNullOrEmpty(tb.Rows[i]["FlowingSection"].ToString()))
// {
// var plan = BLL.ProductionSchedulingPlanService.GetProductionSchedulingPlan(this.CurrUser.LoginProjectId, tb.Rows[i]["FlowingSection"].ToString(), tb.Rows[i]["UnitWorkId"].ToString(), tb.Rows[i]["Material"].ToString(), tb.Rows[i]["Caliber"].ToString());
// if (plan == null)
// {
// Model.HJGL_ProductionSchedulingPlan newPlan = new HJGL_ProductionSchedulingPlan();
// newPlan.ProductionSchedulingPlanId = SQLHelper.GetNewID(typeof(Model.HJGL_ProductionSchedulingPlan));
// newPlan.ProjectId = this.CurrUser.LoginProjectId;
// newPlan.PipelineId = tb.Rows[i]["UnitWorkId"].ToString();//装置ID
// newPlan.FlowNum = tb.Rows[i]["FlowingSection"].ToString();
// newPlan.MainItemName = tb.Rows[i]["UnitWorkName"].ToString();
// newPlan.Material = tb.Rows[i]["Material"].ToString();
// newPlan.Caliber = tb.Rows[i]["Caliber"].ToString();
// newPlan.Dain = Funs.GetNewDecimalOrZero(tb.Rows[i]["Dia"].ToString());
// newPlan.TotalDyne = Funs.GetNewDecimalOrZero(tb.Rows[i]["TotalDia"].ToString());
// newPlan.CompletedCount = Funs.GetNewIntOrZero(tb.Rows[i]["cTotalCount"].ToString());
// newPlan.CompletedRate = Funs.GetNewDecimalOrZero(tb.Rows[i]["rate"].ToString());
// newPlan.TotalCompletedRate = Funs.GetNewDecimalOrZero(tb.Rows[i]["Srate"].ToString());
// BLL.ProductionSchedulingPlanService.AddProductionSchedulingPlan(newPlan);
// }
// }
// }
//}
2025-06-04 22:46:21 +08:00
}
}
#endregion
#region 数 据 绑 定
/// <summary>
/// 数据绑定
/// </summary>
private void BindGrid ( )
{
if ( tvControlItem . SelectedNode = = null ) return ;
string strSql = @ "SELECT p.ProductionSchedulingPlanId,
p . ProjectId ,
p . PipelineId ,
p . FlowNum ,
p . MainItemName ,
p . Material ,
p . Caliber ,
p . Dain ,
p . TotalDyne ,
p . TotalPriority ,
p . PriorityTotalDyne ,
p . PlanStartDate ,
p . PlanEndDate ,
p . Days ,
2025-06-09 17:20:34 +08:00
p . AvgDailyWorkload ,
w . ProjectType ,
p . CompletedCount ,
p . CompletedRate ,
2025-08-04 10:44:32 +08:00
p . TotalCompletedRate ,
p . OnDayCompleteDyne ,
p . NextDayCompleteDyne
2025-06-04 22:46:21 +08:00
FROM HJGL_ProductionSchedulingPlan p
2025-06-09 17:20:34 +08:00
left join WBS_UnitWork w on w . UnitWorkId = p . PipelineId
2025-06-04 22:46:21 +08:00
WHERE 1 = 1 ";
List < SqlParameter > listStr = new List < SqlParameter > ( ) ;
if ( tvControlItem . SelectedNode . CommandName . Split ( '|' ) . Length = = 2 )
{
2025-06-09 17:20:34 +08:00
strSql + = " and p.PipelineId =@UnitWorkId" ;
listStr . Add ( new SqlParameter ( "@UnitWorkId" , this . tvControlItem . SelectedNode . NodeID ) ) ;
2025-06-04 22:46:21 +08:00
}
else if ( tvControlItem . SelectedNode . CommandName = = "流水段" )
{
2025-06-09 17:20:34 +08:00
strSql + = "and p.PipelineId =@UnitWorkId and p.FlowNum = @FlowNum " ;
listStr . Add ( new SqlParameter ( "@UnitWorkId" , this . tvControlItem . SelectedNode . ParentNode . NodeID ) ) ;
2025-06-04 22:46:21 +08:00
listStr . Add ( new SqlParameter ( "@FlowNum" , this . tvControlItem . SelectedNode . Text ) ) ;
2025-06-09 17:20:34 +08:00
}
else if ( tvControlItem . SelectedNodeID = = "1" )
{
strSql + = "and w.ProjectType ='1' " ;
}
else if ( tvControlItem . SelectedNodeID = = "2" )
{
strSql + = "and w.ProjectType ='2' " ;
2025-06-04 22:46:21 +08:00
}
SqlParameter [ ] parameter = listStr . ToArray ( ) ;
DataTable tb = SQLHelper . GetDataTableRunText ( strSql , parameter ) ;
GridDataTable = tb ;
// 2.获取当前分页数据
Grid1 . RecordCount = tb . Rows . Count ;
var table = this . GetPagedDataTable ( Grid1 , tb ) ;
Grid1 . DataSource = table ;
Grid1 . DataBind ( ) ;
}
#endregion
#region 分 页 排 序
#region 页 索 引 改 变 事 件
/// <summary>
/// 页索引改变事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_PageIndexChange ( object sender , GridPageEventArgs e )
{
BindGrid ( ) ;
}
#endregion
#region 排 序
/// <summary>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort ( object sender , GridSortEventArgs e )
{
BindGrid ( ) ;
}
#endregion
#region 分 页 选 择 下 拉 改 变 事 件
/// <summary>
/// 分页选择下拉改变事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ddlPageSize_SelectedIndexChanged ( object sender , EventArgs e )
{
Grid1 . PageSize = Convert . ToInt32 ( ddlPageSize . SelectedValue ) ;
BindGrid ( ) ;
}
#endregion
#endregion
#region 维 护 事 件
2025-06-09 17:20:34 +08:00
//protected void btnSearch_Click(object sender, EventArgs e)
//{
// BindGrid();
//}
2025-06-04 22:46:21 +08:00
#endregion
#region 关 闭 弹 出 窗 口 及 刷 新 页 面
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
2025-06-09 17:20:34 +08:00
//protected void TextBox_TextChanged(object sender, EventArgs e)
//{
// this.BindGrid();
//}
//protected void btnTreeFind_Click(object sender, EventArgs e)
//{
// this.InitTreeMenu();
//}
2025-06-04 22:46:21 +08:00
#endregion
#region 保 存
/// <summary>
/// 保存
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click ( object sender , EventArgs e )
{
if ( this . Grid1 . Rows . Count > 0 )
{
foreach ( JObject mergedRow in Grid1 . GetMergedData ( ) )
{
JObject values = mergedRow . Value < JObject > ( "values" ) ;
int i = mergedRow . Value < int > ( "index" ) ;
string rowId = Grid1 . Rows [ i ] . RowID ;
var newPlan = BLL . ProductionSchedulingPlanService . GetProductionSchedulingPlanById ( rowId ) ;
if ( newPlan ! = null )
{
newPlan . TotalPriority = values . Value < string > ( "TotalPriority" ) ;
newPlan . PriorityTotalDyne = Funs . GetNewDecimal ( values . Value < string > ( "PriorityTotalDyne" ) ) ;
newPlan . PlanStartDate = Funs . GetNewDateTime ( values . Value < string > ( "PlanStartDate" ) ) ;
newPlan . PlanEndDate = Funs . GetNewDateTime ( values . Value < string > ( "PlanEndDate" ) ) ;
newPlan . Days = Funs . GetNewInt ( values . Value < string > ( "Days" ) ) ;
newPlan . AvgDailyWorkload = Funs . GetNewDecimal ( values . Value < string > ( "AvgDailyWorkload" ) ) ;
2025-08-04 10:44:32 +08:00
newPlan . OnDayCompleteDyne = Funs . GetNewDecimal ( values . Value < string > ( "OnDayCompleteDyne" ) ) ;
newPlan . NextDayCompleteDyne = Funs . GetNewDecimal ( values . Value < string > ( "NextDayCompleteDyne" ) ) ;
newPlan . CompletedCount = Funs . GetNewInt ( values . Value < string > ( "CompletedCount" ) ) ;
newPlan . CompletedRate = Funs . GetNewDecimal ( values . Value < string > ( "CompletedRate" ) ) ;
newPlan . TotalCompletedRate = Funs . GetNewDecimal ( values . Value < string > ( "TotalCompletedRate" ) ) ;
2025-06-04 22:46:21 +08:00
BLL . ProductionSchedulingPlanService . UpdateProductionSchedulingPlan ( newPlan ) ;
}
}
ShowNotify ( "保存成功!" , MessageBoxIcon . Success ) ;
BindGrid ( ) ;
}
}
#endregion
#region 导 出
protected void btnOut_Click ( object sender , EventArgs e )
{
string rootPath = Server . MapPath ( "~/" ) ;
string initTemplatePath = Const . HJGL_ProductionSchedulingPlanPath ;
string uploadfilepath = string . Empty ;
string newUrl = string . Empty ;
uploadfilepath = rootPath + initTemplatePath ;
var lists = ( from x in Funs . DB . HJGL_ProductionSchedulingPlan
where x . ProjectId = = this . CurrUser . LoginProjectId
select x ) ;
if ( tvControlItem . SelectedNode . CommandName . Split ( '|' ) . Length = = 2 )
{
lists = lists . Where ( x = > x . MainItemName = = this . tvControlItem . SelectedNode . Text ) ;
}
else if ( tvControlItem . SelectedNode . CommandName = = "流水段" )
{
2025-08-04 10:44:32 +08:00
lists = lists . Where ( x = > x . MainItemName = = this . tvControlItem . SelectedNode . ParentNode . Text & & x . FlowNum = = this . tvControlItem . SelectedNode . Text ) ;
2025-06-04 22:46:21 +08:00
}
2025-08-04 10:44:32 +08:00
lists = lists . OrderBy ( x = > x . Caliber ) . OrderBy ( x = > x . Material ) . OrderBy ( x = > x . FlowNum ) . OrderBy ( x = > x . MainItemName ) ;
2025-06-04 22:46:21 +08:00
if ( lists ! = null )
{
2025-07-23 13:27:58 +08:00
newUrl = uploadfilepath . Replace ( "排产计划导出模板" , "排产计划-" + this . tvControlItem . SelectedNode . Text + "-" + DateTime . Now . ToString ( "yyyyMMdd" ) ) ;
2025-06-04 22:46:21 +08:00
if ( File . Exists ( newUrl ) )
{
File . Delete ( newUrl ) ;
}
File . Copy ( uploadfilepath , newUrl ) ;
// 第一步:读取文件流
NPOI . SS . UserModel . IWorkbook workbook ;
using ( FileStream stream = new FileStream ( newUrl , FileMode . Open , FileAccess . Read ) )
{
workbook = new NPOI . XSSF . UserModel . XSSFWorkbook ( stream ) ;
//workbook = new NPOI.HSSF.UserModel.HSSFWorkbook(stream);
}
// 创建单元格样式
NPOI . SS . UserModel . ICellStyle cellStyle = workbook . CreateCellStyle ( ) ;
cellStyle . BorderTop = NPOI . SS . UserModel . BorderStyle . Thin ;
cellStyle . BorderRight = NPOI . SS . UserModel . BorderStyle . Thin ;
cellStyle . BorderBottom = NPOI . SS . UserModel . BorderStyle . Thin ;
cellStyle . BorderLeft = NPOI . SS . UserModel . BorderStyle . Thin ;
cellStyle . Alignment = NPOI . SS . UserModel . HorizontalAlignment . Center ;
cellStyle . VerticalAlignment = NPOI . SS . UserModel . VerticalAlignment . Center ;
cellStyle . WrapText = true ; //自动换行
2025-09-19 14:47:27 +08:00
NPOI . SS . UserModel . ICellStyle style11 = workbook . CreateCellStyle ( ) ;
style11 . DataFormat = NPOI . HSSF . UserModel . HSSFDataFormat . GetBuiltinFormat ( "0.00" ) ; //数字格式
style11 . BorderTop = NPOI . SS . UserModel . BorderStyle . Thin ;
style11 . BorderRight = NPOI . SS . UserModel . BorderStyle . Thin ;
style11 . BorderBottom = NPOI . SS . UserModel . BorderStyle . Thin ;
style11 . BorderLeft = NPOI . SS . UserModel . BorderStyle . Thin ;
style11 . Alignment = NPOI . SS . UserModel . HorizontalAlignment . Right ;
style11 . VerticalAlignment = NPOI . SS . UserModel . VerticalAlignment . Center ;
style11 . WrapText = true ; //自动换行
2025-06-04 22:46:21 +08:00
var font = workbook . CreateFont ( ) ;
font . FontHeightInPoints = 11 ;
cellStyle . SetFont ( font ) ;
2025-09-24 15:27:48 +08:00
2025-06-04 22:46:21 +08:00
// 第二步:创建新数据行
NPOI . SS . UserModel . ISheet sheet = workbook . GetSheetAt ( 0 ) ;
NPOI . SS . UserModel . IRow row = sheet . GetRow ( 0 ) ;
NPOI . SS . UserModel . ICell cell ;
int i = 1 ;
foreach ( var item in lists )
{
// 第二步:创建新数据行
row = sheet . CreateRow ( i ) ;
// 添加数据
cell = row . CreateCell ( 0 ) ;
cell . CellStyle = cellStyle ;
cell . SetCellValue ( item . FlowNum ) ; //流水段号
cell = row . CreateCell ( 1 ) ;
cell . CellStyle = cellStyle ;
cell . SetCellValue ( item . MainItemName ) ; //主项名称
cell = row . CreateCell ( 2 ) ;
cell . CellStyle = cellStyle ;
cell . SetCellValue ( item . Material ) ; //材质
cell = row . CreateCell ( 3 ) ;
cell . CellStyle = cellStyle ;
cell . SetCellValue ( item . Caliber ) ; //口径
cell = row . CreateCell ( 4 ) ;
2025-09-19 14:47:27 +08:00
//cell.CellStyle = cellStyle;
cell . SetCellValue ( item . Dain . HasValue ? Convert . ToDouble ( item . Dain ) : 0 ) ; //达因数
cell . CellStyle = style11 ;
2025-06-04 22:46:21 +08:00
cell = row . CreateCell ( 5 ) ;
2025-09-19 14:47:27 +08:00
//cell.CellStyle = cellStyle;
cell . SetCellValue ( item . TotalDyne . HasValue ? Convert . ToDouble ( item . TotalDyne ) : 0 ) ; //总达因数
cell . CellStyle = style11 ;
2025-06-04 22:46:21 +08:00
cell = row . CreateCell ( 6 ) ;
cell . CellStyle = cellStyle ;
cell . SetCellValue ( item . TotalPriority ) ; //总优先级
cell = row . CreateCell ( 7 ) ;
2025-09-19 14:47:27 +08:00
//cell.CellStyle = cellStyle;
cell . SetCellValue ( item . PriorityTotalDyne . HasValue ? Convert . ToDouble ( item . PriorityTotalDyne ) : 0 ) ; //优先级总达因
cell . CellStyle = style11 ;
2025-06-04 22:46:21 +08:00
cell = row . CreateCell ( 8 ) ;
cell . CellStyle = cellStyle ;
cell . SetCellValue ( item . PlanStartDate . HasValue ? string . Format ( "{0:yyyy-MM-dd}" , item . PlanStartDate ) : "" ) ; //计划开始时间
cell = row . CreateCell ( 9 ) ;
cell . CellStyle = cellStyle ;
cell . SetCellValue ( item . PlanEndDate . HasValue ? string . Format ( "{0:yyyy-MM-dd}" , item . PlanEndDate ) : "" ) ; //计划结束时间
cell = row . CreateCell ( 10 ) ;
cell . CellStyle = cellStyle ;
2025-06-09 17:20:34 +08:00
cell . SetCellValue ( item . Days . HasValue ? item . Days . ToString ( ) : "" ) ; //天数
2025-06-04 22:46:21 +08:00
cell = row . CreateCell ( 11 ) ;
2025-09-19 14:47:27 +08:00
//cell.CellStyle = cellStyle;
cell . SetCellValue ( item . AvgDailyWorkload . HasValue ? Convert . ToDouble ( item . AvgDailyWorkload . ToString ( ) ) : 0 ) ; //平均每天工作量
cell . CellStyle = style11 ;
2025-06-09 17:20:34 +08:00
cell = row . CreateCell ( 12 ) ;
2025-09-19 14:47:27 +08:00
//cell.CellStyle = cellStyle;
cell . SetCellValue ( item . OnDayCompleteDyne . HasValue ? Convert . ToDouble ( item . OnDayCompleteDyne . ToString ( ) ) : 0 ) ; //当日已完成量
cell . CellStyle = style11 ;
2025-08-04 10:44:32 +08:00
2025-06-09 17:20:34 +08:00
cell = row . CreateCell ( 13 ) ;
2025-09-19 14:47:27 +08:00
//cell.CellStyle = cellStyle;
cell . SetCellValue ( item . NextDayCompleteDyne . HasValue ? Convert . ToDouble ( item . NextDayCompleteDyne . ToString ( ) ) : 0 ) ; //次日应完成量
cell . CellStyle = style11 ;
2025-06-09 17:20:34 +08:00
cell = row . CreateCell ( 14 ) ;
2025-09-19 14:47:27 +08:00
//cell.CellStyle = cellStyle;
cell . SetCellValue ( item . CompletedCount . HasValue ? Convert . ToDouble ( item . CompletedCount . ToString ( ) ) : 0 ) ; //累计已完成量
cell . CellStyle = style11 ;
2025-08-04 10:44:32 +08:00
cell = row . CreateCell ( 15 ) ;
cell . CellStyle = cellStyle ;
cell . SetCellValue ( item . CompletedRate . HasValue ? item . CompletedRate . ToString ( ) : "" ) ; //已完成百分比
cell = row . CreateCell ( 16 ) ;
cell . CellStyle = cellStyle ;
2025-06-09 17:20:34 +08:00
cell . SetCellValue ( item . TotalCompletedRate . HasValue ? item . TotalCompletedRate . ToString ( ) : "" ) ; //已完成百分比汇总
2025-06-04 22:46:21 +08:00
i + + ;
}
// 第三步:写入文件流
using ( FileStream stream = new FileStream ( newUrl , FileMode . Create , FileAccess . Write ) )
{
workbook . Write ( stream ) ;
workbook . Close ( ) ;
}
string fileName = Path . GetFileName ( newUrl ) ;
FileInfo info = new FileInfo ( newUrl ) ;
long fileSize = info . Length ;
Response . Clear ( ) ;
Response . ContentType = "application/x-zip-compressed" ;
Response . AddHeader ( "Content-Disposition" , "attachment;filename=" + System . Web . HttpUtility . UrlEncode ( fileName , System . Text . Encoding . UTF8 ) ) ;
Response . AddHeader ( "Content-Length" , fileSize . ToString ( ) ) ;
Response . TransmitFile ( newUrl , 0 , fileSize ) ;
Response . Flush ( ) ;
Response . Close ( ) ;
File . Delete ( newUrl ) ;
}
else
{
Alert . ShowInTop ( "当前无记录,无法导出!" , MessageBoxIcon . Warning ) ;
}
}
#endregion
2025-06-09 17:20:34 +08:00
#region 统 计
/// <summary>
/// 统计
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnStatics_Click ( object sender , EventArgs e )
{
if ( ! string . IsNullOrEmpty ( this . txtSize . Text . Trim ( ) ) )
{
//单位工程
if ( tvControlItem . SelectedNode . CommandName . Split ( '|' ) . Length = = 2 )
{
///根据流水段获取管线信息
Model . HJGL_Pipeline pipeline = BLL . PipelineService . GetPipelineByUnitWorkId ( this . tvControlItem . SelectedNode . NodeID ) ;
this . hdUnitWorkId . Text = string . Empty ;
if ( pipeline ! = null )
{
this . hdUnitWorkId . Text = this . tvControlItem . SelectedNode . NodeID ;
SaveProductionSchedulingPlan ( ) ;
}
}
else if ( tvControlItem . SelectedNode . CommandName = = "流水段" )
{
///根据流水段获取管线信息
Model . HJGL_Pipeline pipeline = BLL . PipelineService . GetPipelineByFlowingSection ( this . tvControlItem . SelectedNode . Text ) ;
this . hdUnitWorkId . Text = string . Empty ;
if ( pipeline ! = null )
{
this . hdUnitWorkId . Text = this . tvControlItem . SelectedNode . ParentNode . NodeID ;
SaveProductionSchedulingPlan ( ) ;
}
}
2025-07-23 13:27:58 +08:00
else //建筑工程/安装工程
2025-06-09 17:20:34 +08:00
{
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 > unitWorks = null ;
//List<Model.WBS_UnitWork> unitWork2 = null;
/ /
if ( this . tvControlItem . SelectedNodeID = = "1" )
{
unitWorks = ( from x in unitWorkList where x . ProjectType = = "1" select x ) . ToList ( ) ;
}
else if ( this . tvControlItem . SelectedNodeID = = "2" )
{
unitWorks = ( from x in unitWorkList where x . ProjectType = = "2" select x ) . ToList ( ) ;
}
foreach ( var item in unitWorks )
{
Model . HJGL_Pipeline pipeline = BLL . PipelineService . GetPipelineByUnitWorkId ( item . UnitWorkId ) ;
this . hdUnitWorkId . Text = string . Empty ;
if ( pipeline ! = null )
{
this . hdUnitWorkId . Text = item . UnitWorkId ;
SaveProductionSchedulingPlan ( ) ;
}
}
}
this . BindGrid ( ) ;
}
else
{
Alert . ShowInTop ( "请输入口径!" , MessageBoxIcon . Warning ) ;
return ;
}
}
#endregion
#region 右 键 删 除
/// <summary>
/// 删除
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuDelete_Click ( object sender , EventArgs e )
{
if ( Grid1 . SelectedRowIndexArray . Length > 0 )
{
foreach ( int rowIndex in Grid1 . SelectedRowIndexArray )
{
string rowID = Grid1 . DataKeys [ rowIndex ] [ 0 ] . ToString ( ) ;
var model = BLL . ProductionSchedulingPlanService . GetProductionSchedulingPlanById ( rowID ) ;
if ( model ! = null )
{
BLL . ProductionSchedulingPlanService . DeleteProductionSchedulingPlanById ( rowID ) ;
}
}
BindGrid ( ) ;
ShowNotify ( "删除数据成功!" , MessageBoxIcon . Success ) ;
}
}
#endregion
2025-09-24 15:27:48 +08:00
#region Grid行绑定事件
/// <summary>
/// 次日应完成量高于平均每日应完成工作量发出预警,预警要统一着色显示红色
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_RowDataBound ( object sender , GridRowEventArgs e )
{
DataRowView row = e . DataItem as DataRowView ;
double avgDailyWorkload = 0 ;
double nextDayCompleteDyne = 0 ;
if ( row [ "AvgDailyWorkload" ] ! = null & & ! string . IsNullOrEmpty ( row [ "AvgDailyWorkload" ] . ToString ( ) ) )
{
avgDailyWorkload = Convert . ToDouble ( row [ "AvgDailyWorkload" ] ) ;
}
if ( row [ "NextDayCompleteDyne" ] ! = null & & ! string . IsNullOrEmpty ( row [ "NextDayCompleteDyne" ] . ToString ( ) ) )
{
nextDayCompleteDyne = Convert . ToDouble ( row [ "NextDayCompleteDyne" ] ) ;
}
if ( avgDailyWorkload < nextDayCompleteDyne )
{
e . RowCssClass = "color1" ;
}
}
#endregion
2025-06-04 22:46:21 +08:00
}
}