SGGL_SHJ/SGGL/FineUIPro.Web/HJGL/PreDesign/ProductionSchedulingPlan.as...

427 lines
18 KiB
C#

using BLL;
using MiniExcelLibs;
using Model;
using Newtonsoft.Json.Linq;
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;
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();//加载树
//HJGL_PipelineComponentService.InitMainItemDownList(drpState, true);
//HJGL_PipelineComponentService.InitMainItemDownProductionStateList(drpProductionState, true);
//var pipeline = (from x in Funs.DB.HJGL_Pipeline
// where x.ProjectId == this.CurrUser.LoginProjectId
// select x.FlowingSection).Distinct().ToList();
//this.drpFlowingSection.DataTextField = "Value";
//this.drpFlowingSection.DataValueField = "Value";
//this.drpFlowingSection.DataSource = pipeline;
//this.drpFlowingSection.DataBind();
//Funs.FineUIPleaseSelect(drpFlowingSection);
}
}
#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)
{
int a = (from x in Funs.DB.HJGL_Pipeline where x.ProjectId == this.CurrUser.LoginProjectId && x.UnitWorkId == q.UnitWorkId && x.PipeArea == "1" && x.PipelineCode.Contains(txtPipelineCode.Text.Trim()) select x.FlowingSection).Distinct().Count();
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)
{
int a = (from x in Funs.DB.HJGL_Pipeline where x.ProjectId == this.CurrUser.LoginProjectId && x.UnitWorkId == q.UnitWorkId && x.PipeArea == "1" && x.PipelineCode.Contains(txtPipelineCode.Text.Trim()) select x).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.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<Model.HJGL_Pipeline> pipeline = new List<Model.HJGL_Pipeline>();
var pipelines = from x in Funs.DB.HJGL_Pipeline where x.ProjectId == this.CurrUser.LoginProjectId && x.PipeArea == "1" select x;
pipeline = (from x in pipelines
where x.ProjectId == this.CurrUser.LoginProjectId && x.UnitWorkId == node.NodeID && x.PipelineCode.Contains(this.txtPipelineCode.Text.Trim())
orderby x.PipelineCode
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)
{
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.ToolTip = "管线号【组件数】";
newNode.CommandName = "管线";
newNode.NodeID = item.PipelineId;
newNode.EnableClickEvent = true;
node.Nodes.Add(newNode);
}
if (pageindex < pageCount)
{
TreeNode newNode = new TreeNode();
newNode.Text = "加载";
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)
{
if (e.CommandName.Split('|').Length == 2)
{
this.hdUnitWorkId.Text = this.tvControlItem.SelectedNodeID;
}
else if (e.CommandName == "管线")
{
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;
SaveProductionSchedulingPlan();
}
}
else 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);
}
this.BindGrid();
}
/// <summary>
/// 保存数据
/// </summary>
/// <exception cref="NotImplementedException"></exception>
private void SaveProductionSchedulingPlan()
{
if (!string.IsNullOrEmpty(this.tvControlItem.SelectedNodeID))
{
var schedulingPlan = BLL.ProductionSchedulingPlanService.GetProductionSchedulingPlanByPipelineId(this.CurrUser.LoginProjectId, this.tvControlItem.SelectedNodeID);
if (schedulingPlan == null)
{
Model.HJGL_ProductionSchedulingPlan newPlan = new HJGL_ProductionSchedulingPlan();
newPlan.ProductionSchedulingPlanId = SQLHelper.GetNewID(typeof(Model.HJGL_ProductionSchedulingPlan));
newPlan.ProjectId = this.CurrUser.LoginProjectId;
newPlan.PipelineId = this.tvControlItem.SelectedNodeID;
var pipeline = BLL.PipelineService.GetPipelineByPipelineId(this.tvControlItem.SelectedNodeID);
if (pipeline!=null)
{
newPlan.FlowNum = pipeline.FlowingSection;
if (!string.IsNullOrEmpty(pipeline.UnitWorkId))
{
newPlan.MainItemName = BLL.UnitWorkService.getUnitWorkByUnitWorkId(pipeline.UnitWorkId).UnitWorkName;
}
if (!string.IsNullOrEmpty(pipeline.PipingClassId))
{
newPlan.Material = BLL.Base_PipingClassService.GetPipingClassByPipingClassId(pipeline.PipingClassId).SteelType;
}
}
BLL.ProductionSchedulingPlanService.AddProductionSchedulingPlan(newPlan);
}
}
}
#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,
p.AvgDailyWorkload,
pipeline.UnitWorkId
FROM HJGL_ProductionSchedulingPlan p
left join HJGL_Pipeline as pipeline on pipeline.PipelineId = p.PipelineId
WHERE 1=1 ";
List<SqlParameter> listStr = new List<SqlParameter>();
if (tvControlItem.SelectedNode.CommandName.Split('|').Length == 2)
{
strSql += " and pipeline.UnitWorkId =@UnitWorkId";
listStr.Add(new SqlParameter("@UnitWorkId", this.tvControlItem.SelectedNodeID));
}
else if (tvControlItem.SelectedNode.CommandName == "管线")
{
strSql += " and p.PipelineId = @PipelineId ";
listStr.Add(new SqlParameter("@PipelineId", this.tvControlItem.SelectedNodeID));
}
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
protected void btnSearch_Click(object sender, EventArgs e)
{
BindGrid();
}
#endregion
#region
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void TextBox_TextChanged(object sender, EventArgs e)
{
this.BindGrid();
}
protected void btnTreeFind_Click(object sender, EventArgs e)
{
this.InitTreeMenu();
}
#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"));
BLL.ProductionSchedulingPlanService.UpdateProductionSchedulingPlan(newPlan);
}
}
ShowNotify("保存成功!", MessageBoxIcon.Success);
BindGrid();
}
}
#endregion
#region
protected void btnOut_Click(object sender, EventArgs e)
{
}
#endregion
}
}