using BLL; using Model; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.IO; using System.Linq; using AspNet = System.Web.UI.WebControls; namespace FineUIPro.Web.HJGL.PreDesign { public partial class ProductionSchedulingPlan : PageBase { public int pageSize = 20; public static DataTable GridDataTable = new DataTable(); #region 加载页面 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString(); this.InitTreeMenu();//加载树 BindGrid2();//绑定看板数据 } } #endregion #region 加载树装置-单位-工作区 /// /// 加载树 /// 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 unitWork1 = null; List 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" 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" select x.FlowingSection).Distinct().Count(); 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 flowingSection = new List(); //List pipeline = new List(); 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(); 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 #region 树节点展开事件 /// /// 树节点展开事件 /// /// /// protected void tvControlItem_TreeNodeExpanded(object sender, TreeNodeEventArgs e) { if (e.Node.Nodes[0].NodeID == "加载流水段...") { e.Node.Nodes.Clear(); BindNodes(e.Node); } } #endregion #region 点击TreeView /// /// 点击TreeView /// /// /// protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e) { #region 实时统计生产看板数据 string projectId = this.CurrUser.LoginProjectId; string steelType = string.Empty;//材质id //统计生产看板当日已完成量、次日应完成量、累计已完成量、已完成百分比、已完成百分比汇总 if (tvControlItem.SelectedNode.CommandName == "流水段")//点击流水段 { var planLists = BLL.ProductionSchedulingPlanService.GetProductionSchedulingPlanByFlowingSection(projectId, tvControlItem.SelectedNode.Text, tvControlItem.SelectedNode.ParentNode.NodeID); if (planLists.Count > 0) { foreach (var item in planLists) { var plan = BLL.ProductionSchedulingPlanService.GetProductionSchedulingPlanById(item.ProductionSchedulingPlanId); if (plan != null) { if (plan.Material == "碳钢") { steelType = "1"; } else if (plan.Material == "不锈钢") { steelType = "2"; } else if (plan.Material == "铬钼钢") { steelType = "3"; } else if (plan.Material == "低合金钢") { steelType = "4"; } else if (plan.Material == "镍合金钢") { steelType = "5"; } else if (plan.Material == "钛合金钢") { steelType = "6"; } else if (plan.Material == "其他") { steelType = "7"; } //当日已完成量 var currentDay = BLL.WeldJointService.GetCurrentDaySizeSum(projectId, plan.PipelineId, plan.FlowNum, steelType, plan.Caliber); if (currentDay != null) { plan.OnDayCompleteDyne = currentDay; } else { plan.OnDayCompleteDyne = 0; } plan.CompletedCount = BLL.WeldJointService.GetSizeSum(projectId, plan.PipelineId, plan.FlowNum, steelType, plan.Caliber, "2");//累计已完成量 if (plan.Dain > 0) { plan.CompletedRate = (plan.CompletedCount / plan.Dain) * 100;//已完成百分比 } else { plan.CompletedRate = 0; } if (plan.PriorityTotalDyne > 0) { decimal? completeDinSum = BLL.WeldJointService.GetSizeSumByUnitWorkIdAndFlowingSection(projectId, plan.PipelineId, plan.FlowNum, "2");//完成总达因 plan.TotalCompletedRate = (completeDinSum / plan.PriorityTotalDyne) * 100;//已完成百分比汇总 } else { plan.TotalCompletedRate = 0; } BLL.ProductionSchedulingPlanService.UpdateProductionSchedulingPlan(plan); } } } } else if (tvControlItem.SelectedNode.CommandName.Split('|').Length == 2)//点击单位工程 { var planLists = BLL.ProductionSchedulingPlanService.GetProductionSchedulingPlanByUnitWorkId(this.CurrUser.LoginProjectId, tvControlItem.SelectedNode.NodeID); if (planLists.Count > 0) { foreach (var item in planLists) { var plan = BLL.ProductionSchedulingPlanService.GetProductionSchedulingPlanById(item.ProductionSchedulingPlanId); if (plan != null) { if (plan.Material == "碳钢") { steelType = "1"; } else if (plan.Material == "不锈钢") { steelType = "2"; } else if (plan.Material == "铬钼钢") { steelType = "3"; } else if (plan.Material == "低合金钢") { steelType = "4"; } else if (plan.Material == "镍合金钢") { steelType = "5"; } else if (plan.Material == "钛合金钢") { steelType = "6"; } else if (plan.Material == "其他") { steelType = "7"; } //当日已完成量 var currentDay = BLL.WeldJointService.GetCurrentDaySizeSum(projectId, plan.PipelineId, plan.FlowNum, steelType, plan.Caliber); if (currentDay != null) { plan.OnDayCompleteDyne = currentDay; } else { plan.OnDayCompleteDyne = 0; } plan.CompletedCount = BLL.WeldJointService.GetSizeSum(projectId, plan.PipelineId, plan.FlowNum, steelType, plan.Caliber, "2");//累计已完成量 if (plan.Dain > 0) { plan.CompletedRate = (plan.CompletedCount / plan.Dain) * 100;//已完成百分比 } else { plan.CompletedRate = 0; } if (plan.PriorityTotalDyne > 0) { decimal? completeDinSum = BLL.WeldJointService.GetSizeSumByUnitWorkIdAndFlowingSection(projectId, plan.PipelineId, plan.FlowNum, "2");//完成总达因 plan.TotalCompletedRate = (completeDinSum / plan.PriorityTotalDyne) * 100;//已完成百分比汇总 } else { plan.TotalCompletedRate = 0; } BLL.ProductionSchedulingPlanService.UpdateProductionSchedulingPlan(plan); } } } } #endregion this.BindGrid(); } /// /// 保存数据 /// /// private void SaveProductionSchedulingPlan() { if (!string.IsNullOrEmpty(this.tvControlItem.SelectedNodeID)) { string projectId = this.CurrUser.LoginProjectId; if (tvControlItem.SelectedNode.CommandName == "流水段") { List listStr = new List(); listStr.Add(new SqlParameter("@projectId", projectId)); 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); //删除原有数据 BLL.ProductionSchedulingPlanService.DeleteProductionSchedulingPlanByUnitWorkIdAndFlowNum(projectId, this.tvControlItem.SelectedNode.ParentNode.Text, this.tvControlItem.SelectedNode.Text); for (int i = 0; i < tb.Rows.Count; i++) { 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();//寸径 var plan = BLL.ProductionSchedulingPlanService.GetProductionSchedulingPlan(projectId, flowingSection, unitWorkId, material, caliber); if (plan == null) { Model.HJGL_ProductionSchedulingPlan newPlan = new HJGL_ProductionSchedulingPlan(); newPlan.ProductionSchedulingPlanId = SQLHelper.GetNewID(typeof(Model.HJGL_ProductionSchedulingPlan)); newPlan.ProjectId = projectId; newPlan.PipelineId = unitWorkId; newPlan.FlowNum = flowingSection; newPlan.MainItemName = tb.Rows[i]["UnitWorkName"].ToString(); newPlan.Material = material; newPlan.Caliber = caliber; 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");//累计已完成量 if (newPlan.Dain > 0) { newPlan.CompletedRate = (newPlan.CompletedCount / newPlan.Dain) * 100;//已完成百分比 } else { newPlan.CompletedRate = 0; } if (newPlan.PriorityTotalDyne > 0) { decimal? completeDinSum = BLL.WeldJointService.GetSizeSumByUnitWorkIdAndFlowingSection(projectId, unitWorkId, flowingSection, "2");//完成总达因 newPlan.TotalCompletedRate = (completeDinSum / newPlan.PriorityTotalDyne) * 100;//已完成百分比汇总 } else { newPlan.TotalCompletedRate = 0; } BLL.ProductionSchedulingPlanService.AddProductionSchedulingPlan(newPlan); } } } else if (tvControlItem.SelectedNode.CommandName.Split('|').Length == 2)//单位工程 { List listStr = new List(); listStr.Add(new SqlParameter("@projectId", projectId)); 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); //删除原有数据 BLL.ProductionSchedulingPlanService.DeleteProductionSchedulingPlanByUnitWork(projectId, this.tvControlItem.SelectedNode.Text); for (int i = 0; i < tb.Rows.Count; i++) { 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();//寸径 var plan = BLL.ProductionSchedulingPlanService.GetProductionSchedulingPlan(projectId, flowingSection, unitWorkId, material, caliber); if (plan == null) { Model.HJGL_ProductionSchedulingPlan newPlan = new HJGL_ProductionSchedulingPlan(); newPlan.ProductionSchedulingPlanId = SQLHelper.GetNewID(typeof(Model.HJGL_ProductionSchedulingPlan)); newPlan.ProjectId = projectId; newPlan.PipelineId = unitWorkId; newPlan.FlowNum = flowingSection; newPlan.MainItemName = tb.Rows[i]["UnitWorkName"].ToString(); newPlan.Material = material; newPlan.Caliber = caliber; 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");//累计已完成量 if (newPlan.Dain > 0) { newPlan.CompletedRate = (newPlan.CompletedCount / newPlan.Dain) * 100;//已完成百分比 } else { newPlan.CompletedRate = 0; } if (newPlan.PriorityTotalDyne > 0) { decimal? completeDinSum = BLL.WeldJointService.GetSizeSumByUnitWorkIdAndFlowingSection(projectId, unitWorkId, flowingSection, "2");//完成总达因 newPlan.TotalCompletedRate = (completeDinSum / newPlan.PriorityTotalDyne) * 100;//已完成百分比汇总 } else { newPlan.TotalCompletedRate = 0; } BLL.ProductionSchedulingPlanService.AddProductionSchedulingPlan(newPlan); } } } //else if (this.tvControlItem.SelectedNodeID == "1" || this.tvControlItem.SelectedNodeID == "2") //{ // List listStr = new List(); // 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); // } // } // } //} } } #endregion #region 数据绑定 /// /// 数据绑定 /// 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, w.ProjectType, p.CompletedCount, (cast(p.CompletedRate as nvarchar(10))+'%') as CompletedRate, (cast(p.TotalCompletedRate as nvarchar(10))+'%') as TotalCompletedRate, p.OnDayCompleteDyne, p.NextDayCompleteDyne FROM HJGL_ProductionSchedulingPlan p left join WBS_UnitWork w on w.UnitWorkId=p.PipelineId WHERE 1=1 "; List listStr = new List(); if (tvControlItem.SelectedNode.CommandName.Split('|').Length == 2) { strSql += " and p.PipelineId =@UnitWorkId"; listStr.Add(new SqlParameter("@UnitWorkId", this.tvControlItem.SelectedNode.NodeID)); } else if (tvControlItem.SelectedNode.CommandName == "流水段") { strSql += "and p.PipelineId =@UnitWorkId and p.FlowNum = @FlowNum "; listStr.Add(new SqlParameter("@UnitWorkId", this.tvControlItem.SelectedNode.ParentNode.NodeID)); listStr.Add(new SqlParameter("@FlowNum", this.tvControlItem.SelectedNode.Text)); } else if (tvControlItem.SelectedNodeID == "1") { strSql += "and w.ProjectType ='1' "; } else if (tvControlItem.SelectedNodeID == "2") { strSql += "and w.ProjectType ='2' "; } 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 页索引改变事件 /// /// 页索引改变事件 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { BindGrid(); } #endregion #region 排序 /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, GridSortEventArgs e) { BindGrid(); } #endregion #region 分页选择下拉改变事件 /// /// 分页选择下拉改变事件 /// /// /// 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 关闭弹出窗口及刷新页面 /// /// 查询 /// /// /// //protected void TextBox_TextChanged(object sender, EventArgs e) //{ // this.BindGrid(); //} //protected void btnTreeFind_Click(object sender, EventArgs e) //{ // this.InitTreeMenu(); //} #endregion #region 保存 /// /// 保存 /// /// /// protected void btnSave_Click(object sender, EventArgs e) { if (this.Grid1.Rows.Count > 0) { string totalPriority = string.Empty; foreach (JObject mergedRow in Grid1.GetMergedData()) { JObject values = mergedRow.Value("values"); int i = mergedRow.Value("index"); string rowId = Grid1.Rows[i].RowID; var newPlan = BLL.ProductionSchedulingPlanService.GetProductionSchedulingPlanById(rowId); if (newPlan != null) { if (!string.IsNullOrEmpty(totalPriority)) { newPlan.TotalPriority = totalPriority; totalPriority = string.Empty; } else { newPlan.TotalPriority = values.Value("TotalPriority"); totalPriority = newPlan.TotalPriority; } newPlan.PlanStartDate = Funs.GetNewDateTime(values.Value("PlanStartDate")); newPlan.PlanEndDate = Funs.GetNewDateTime(values.Value("PlanEndDate")); newPlan.Days = Funs.GetNewInt(values.Value("Days")); newPlan.AvgDailyWorkload = Funs.GetNewDecimal(values.Value("AvgDailyWorkload")); newPlan.NextDayCompleteDyne = Funs.GetNewDecimal(values.Value("NextDayCompleteDyne")); 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 == "流水段") { lists = lists.Where(x => x.MainItemName == this.tvControlItem.SelectedNode.ParentNode.Text && x.FlowNum == this.tvControlItem.SelectedNode.Text); } lists = lists.OrderBy(x => x.Caliber).OrderBy(x => x.Material).OrderBy(x => x.FlowNum).OrderBy(x => x.MainItemName); if (lists != null) { newUrl = uploadfilepath.Replace("排产计划导出模板", "排产计划-" + this.tvControlItem.SelectedNode.Text + "-" + DateTime.Now.ToString("yyyyMMdd")); 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;//自动换行 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;//自动换行 var font = workbook.CreateFont(); font.FontHeightInPoints = 11; cellStyle.SetFont(font); // 第二步:创建新数据行 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); //cell.CellStyle = cellStyle; cell.SetCellValue(item.Dain.HasValue ? Convert.ToDouble(item.Dain) : 0);//达因数 cell.CellStyle = style11; cell = row.CreateCell(5); //cell.CellStyle = cellStyle; cell.SetCellValue(item.TotalDyne.HasValue ? Convert.ToDouble(item.TotalDyne) : 0);//总达因数 cell.CellStyle = style11; cell = row.CreateCell(6); cell.CellStyle = cellStyle; cell.SetCellValue(item.TotalPriority);//总优先级 cell = row.CreateCell(7); //cell.CellStyle = cellStyle; cell.SetCellValue(item.PriorityTotalDyne.HasValue ? Convert.ToDouble(item.PriorityTotalDyne) : 0);//优先级总达因 cell.CellStyle = style11; 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; cell.SetCellValue(item.Days.HasValue ? item.Days.ToString() : "");//天数 cell = row.CreateCell(11); //cell.CellStyle = cellStyle; cell.SetCellValue(item.AvgDailyWorkload.HasValue ? Convert.ToDouble(item.AvgDailyWorkload.ToString()) : 0);//平均每天工作量 cell.CellStyle = style11; cell = row.CreateCell(12); //cell.CellStyle = cellStyle; cell.SetCellValue(item.OnDayCompleteDyne.HasValue ? Convert.ToDouble(item.OnDayCompleteDyne.ToString()) : 0);//当日已完成量 cell.CellStyle = style11; cell = row.CreateCell(13); //cell.CellStyle = cellStyle; cell.SetCellValue(item.NextDayCompleteDyne.HasValue ? Convert.ToDouble(item.NextDayCompleteDyne.ToString()) : 0);//次日应完成量 cell.CellStyle = style11; cell = row.CreateCell(14); //cell.CellStyle = cellStyle; cell.SetCellValue(item.CompletedCount.HasValue ? Convert.ToDouble(item.CompletedCount.ToString()) : 0);//累计已完成量 cell.CellStyle = style11; cell = row.CreateCell(15); cell.CellStyle = cellStyle; cell.SetCellValue(item.CompletedRate.HasValue ? item.CompletedRate.ToString() : "");//已完成百分比 cell = row.CreateCell(16); cell.CellStyle = cellStyle; cell.SetCellValue(item.TotalCompletedRate.HasValue ? item.TotalCompletedRate.ToString() : "");//已完成百分比汇总 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 #region 统计 /// /// 统计 /// /// /// 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(); } } else //建筑工程/安装工程 { 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 unitWorks = null; //List 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 右键删除 /// /// 删除 /// /// /// 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 #region Grid行绑定事件 /// /// 次日应完成量高于平均每日应完成工作量发出预警,预警要统一着色显示红色 /// /// /// 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 #region 生产看板 protected void ddlPageSize2_SelectedIndexChanged(object sender, EventArgs e) { Grid2.PageSize = Convert.ToInt32(ddlPageSize2.SelectedValue); this.BindGrid2(); } protected void Grid2_Sort(object sender, GridSortEventArgs e) { this.BindGrid2(); } protected void Grid2_PageIndexChange(object sender, GridPageEventArgs e) { this.BindGrid2(); } /// /// 绑定数据 /// private void BindGrid2() { List listStr = new List(); listStr.Add(new SqlParameter("@projectId", this.CurrUser.LoginProjectId)); SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunProc("Sp_HJGL_ProductionPlanStatistics", parameter); this.Grid2.RecordCount = tb.Rows.Count; var table = this.GetPagedDataTable(Grid2, tb); Grid2.DataSource = table; Grid2.DataBind(); } /// /// 当次日应完成量高于平均每日应完成工作量发出预警(标红) /// /// /// protected void Grid2_RowDataBound(object sender, GridRowEventArgs e) { //DataRowView row = e.DataItem as DataRowView; double avgDailyWorkload = 0; double nextDayCompleteDyne = 0; //if (row["AvgDayCompleteDia"] != null && !string.IsNullOrEmpty(row["AvgDayCompleteDia"].ToString())) //{ // avgDailyWorkload = Convert.ToDouble(row["AvgDayCompleteDia"]);//平均每日应完成工作量 //} //if (row["NextDayComplete"] != null && !string.IsNullOrEmpty(row["NextDayComplete"].ToString())) //{ // nextDayCompleteDyne = Convert.ToDouble(row["NextDayComplete"]);//次日应完成量 //} //avgDailyWorkload=(e.RowID["lblAvgDayCompleteDia") as AspNet.Label).Text avgDailyWorkload = Convert.ToDouble((e.Row.FindControl("lblAvgDayCompleteDia") as AspNet.Label).Text);//平均每日应完成工作量 nextDayCompleteDyne = Convert.ToDouble((e.Row.FindControl("lblNextDayComplete") as AspNet.Label).Text); //次日应完成量(平均) if (avgDailyWorkload < nextDayCompleteDyne) { e.RowCssClass = "color1"; } } #endregion #region 格式化字符串 /// /// 获取有效总天数 /// /// /// /// /// public static int getTotalDays(string projectId, string unitWorkId, string flowNum) { var lists = BLL.ProductionSchedulingPlanService.GetProductionSchedulingPlanByFlowingSection(projectId, flowNum, unitWorkId); List<(DateTime, DateTime)> combinedList = new List<(DateTime, DateTime)>(); foreach (var item in lists) { if (item.PlanStartDate.HasValue && item.PlanEndDate.HasValue) { var dateRanges = new List<(DateTime, DateTime)> { (new DateTime(item.PlanStartDate.Value.Year, item.PlanStartDate.Value.Month, item.PlanStartDate.Value.Day), new DateTime(item.PlanEndDate.Value.Year, item.PlanEndDate.Value.Month, item.PlanEndDate.Value.Day)), }; combinedList.AddRange(dateRanges); } } return GetEffectiveDaysLinq(combinedList); } /// /// 获取剩余天数 /// /// /// /// /// public static int getRemainingDays(string projectId, string unitWorkId, string flowNum) { var lists = BLL.ProductionSchedulingPlanService.GetProductionSchedulingPlanByFlowingSection(projectId, flowNum, unitWorkId); List<(DateTime, DateTime)> combinedList = new List<(DateTime, DateTime)>(); foreach (var item in lists) { if (item.PlanStartDate.HasValue && item.PlanEndDate.HasValue) { if (item.PlanEndDate > DateTime.Now) { var dateRanges = new List<(DateTime, DateTime)> { (new DateTime(item.PlanStartDate.Value.Year, item.PlanStartDate.Value.Month, item.PlanStartDate.Value.Day), new DateTime(item.PlanEndDate.Value.Year, item.PlanEndDate.Value.Month, item.PlanEndDate.Value.Day)), }; combinedList.AddRange(dateRanges); } } } return GetEffectiveDaysLinq(combinedList); } /// /// 获取平均每日应完成工作量 /// /// /// /// /// public static double getAvgDayCompleteDia(string projectId, string unitWorkId, string flowNum) { double AvgDayCompleteDia = 0; int totalDays = 0; var lists = BLL.ProductionSchedulingPlanService.GetProductionSchedulingPlanByFlowingSection(projectId, flowNum, unitWorkId); List<(DateTime, DateTime)> combinedList = new List<(DateTime, DateTime)>(); foreach (var item in lists) { if (item.PlanStartDate.HasValue && item.PlanEndDate.HasValue) { var dateRanges = new List<(DateTime, DateTime)> { (new DateTime(item.PlanStartDate.Value.Year, item.PlanStartDate.Value.Month, item.PlanStartDate.Value.Day), new DateTime(item.PlanEndDate.Value.Year, item.PlanEndDate.Value.Month, item.PlanEndDate.Value.Day)), }; combinedList.AddRange(dateRanges); } } totalDays = GetEffectiveDaysLinq(combinedList); ///总达因 decimal? dia = (from x in Funs.DB.HJGL_WeldJoint join y in Funs.DB.HJGL_Pipeline on x.PipelineId equals y.PipelineId where x.ProjectId == projectId && y.UnitWorkId == unitWorkId && y.FlowingSection == flowNum && x.JointAttribute == "预制口" select x.Size).Sum(); if (totalDays > 0) { //平均每日应完成工作量=总达因/有效总天数 AvgDayCompleteDia = Math.Round(Convert.ToDouble(dia / totalDays), 2); } return AvgDayCompleteDia; } /// /// 获取次日应完成量(平均) /// /// /// /// /// public static double getNextDayComplete(string projectId, string unitWorkId, string flowNum) { double nextDayComplete = 0; int remainingDays = 0; var lists = BLL.ProductionSchedulingPlanService.GetProductionSchedulingPlanByFlowingSection(projectId, flowNum, unitWorkId); List<(DateTime, DateTime)> combinedList = new List<(DateTime, DateTime)>(); foreach (var item in lists) { if (item.PlanStartDate.HasValue && item.PlanEndDate.HasValue) { if (item.PlanEndDate > DateTime.Now) { var dateRanges = new List<(DateTime, DateTime)> { (new DateTime(item.PlanStartDate.Value.Year, item.PlanStartDate.Value.Month, item.PlanStartDate.Value.Day), new DateTime(item.PlanEndDate.Value.Year, item.PlanEndDate.Value.Month, item.PlanEndDate.Value.Day)), }; combinedList.AddRange(dateRanges); } } } remainingDays = GetEffectiveDaysLinq(combinedList); ///总达因 decimal? totalDia = (from x in Funs.DB.HJGL_WeldJoint join y in Funs.DB.HJGL_Pipeline on x.PipelineId equals y.PipelineId where x.ProjectId == projectId && y.UnitWorkId == unitWorkId && y.FlowingSection == flowNum && x.JointAttribute == "预制口" select x.Size).Sum(); //完成达因 decimal? completedDia = (from x in Funs.DB.HJGL_WeldJoint join y in Funs.DB.HJGL_Pipeline on x.PipelineId equals y.PipelineId where x.ProjectId == projectId && y.UnitWorkId == unitWorkId && y.FlowingSection == flowNum && x.JointAttribute == "预制口" && x.WeldingDailyId != null && x.WeldingDailyId != "" select x.Size).Sum(); if (remainingDays > 0) { //次日应完成量(平均)=(总达因-完成达因)/剩余天数 nextDayComplete = Math.Round(Convert.ToDouble((totalDia - completedDia) / remainingDays), 2); } return nextDayComplete; } /// /// 生成所有日期并去重 /// /// /// public static int GetEffectiveDaysLinq(List<(DateTime start, DateTime end)> dateRanges) { if (dateRanges == null || !dateRanges.Any()) return 0; // 生成所有日期并去重 var allDates = dateRanges .SelectMany(range => Enumerable.Range(0, (range.end - range.start).Days + 1) .Select(offset => range.start.AddDays(offset).Date)) .Distinct(); return allDates.Count(); } #endregion } }