using BLL; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Linq; using System.Web.UI.WebControls; namespace FineUIPro.Web.JDGL.WBSPlan { public partial class WBSPlanAudit :PageBase { #region 定义项 private static List noApproveInstallationIds = new List(); private static List noApproveCnProfessionIds = new List(); private static List noApproveUnitProjectIds = new List(); private static List noApproveWbsSetIds = new List(); #endregion #region 页面加载 /// /// 页面加载 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (this.CurrUser.Account == BLL.Const.sysglyId || BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.WBSPlanAuditMenuId, "一键保存")) { this.btnSaveInstrallion.Hidden = false; } InitTreeMenu(); } else { if (GetRequestEventArgument() == "UPDATE_SUMMARY") { // 页面要求重新计算合计行的值 OutputSummaryData(); } } } #endregion #region 计算合计 /// /// 计算合计 /// private void OutputSummaryData() { decimal totalValue = 0, totalRate = 0, moneys = 0; int i = 0; JArray mergedData = Grid1.GetMergedData(); if (mergedData.Count > 0) { JObject firstValues = mergedData[0].Value("values"); if (!string.IsNullOrEmpty(firstValues.Value("WeightsMoney"))) { moneys = Convert.ToDecimal(firstValues.Value("WeightsMoney")); moneys = decimal.Round(moneys, 2); } foreach (JObject mergedRow in mergedData) { JObject values = mergedRow.Value("values"); if (!string.IsNullOrEmpty(values.Value("PlanValue"))) { totalValue += Convert.ToDecimal(values.Value("PlanValue")); } else { totalValue += 0; } if (moneys != 0) { totalRate = decimal.Round(totalValue / moneys * 100, 2); } else { totalRate = 0; } this.Grid1.Rows[i].Values[1] = values.Value("PlanValue"); this.Grid1.Rows[i].Values[2] = totalValue; this.Grid1.Rows[i].Values[3] = totalRate; i++; } JObject summary = new JObject(); summary.Add("YearsMonthsStr", "未分配费用余额:"); summary.Add("PlanValue", moneys - totalValue); Grid1.SummaryData = summary; } } #endregion #region 加载树 /// /// 加载树 /// private void InitTreeMenu() { this.trWBS.Nodes.Clear(); this.trWBS.ShowBorder = false; this.trWBS.ShowHeader = false; this.trWBS.EnableIcons = true; this.trWBS.AutoScroll = true; this.trWBS.EnableSingleClickExpand = true; var installations = from x in Funs.DB.Project_Installation where x.ProjectId == this.CurrUser.LoginProjectId && x.SuperInstallationId == "0" orderby x.InstallationCode select x; foreach (var installation in installations) { TreeNode rootNode = new TreeNode(); if (noApproveInstallationIds.Contains(installation.InstallationId)) { rootNode.Text = "" + installation.InstallationName + ""; } else { rootNode.Text = installation.InstallationName; } rootNode.NodeID = installation.InstallationId; rootNode.CommandName = "installation"; rootNode.CommandArgument = installation.Weights == null ? null : installation.Weights.ToString(); rootNode.ToolTip = installation.InstallationCode; rootNode.EnableExpandEvent = true; rootNode.EnableClickEvent = true; this.trWBS.Nodes.Add(rootNode); TreeNode emptyNode = new TreeNode(); emptyNode.Text = ""; emptyNode.NodeID = ""; rootNode.Nodes.Add(emptyNode); } } #endregion #region 展开树 /// /// 展开树 /// /// /// protected void trWBS_NodeExpand(object sender, TreeNodeEventArgs e) { e.Node.Nodes.Clear(); if (e.Node.CommandName == "installation") //展开装置/单元节点 { var installations = from x in Funs.DB.Project_Installation where x.SuperInstallationId == e.Node.NodeID orderby x.InstallationCode select x; if (installations.Count() > 0) { foreach (var installation in installations) { TreeNode newNode = new TreeNode(); if (noApproveInstallationIds.Contains(installation.InstallationId)) { newNode.Text = "" + installation.InstallationName + ""; } else { newNode.Text = installation.InstallationName; } newNode.NodeID = installation.InstallationId; newNode.CommandName = "installation"; newNode.CommandArgument = installation.Weights == null ? null : installation.Weights.ToString(); newNode.ToolTip = installation.InstallationCode; newNode.EnableExpandEvent = true; newNode.EnableClickEvent = true; e.Node.Nodes.Add(newNode); TreeNode emptyNode = new TreeNode(); emptyNode.Text = ""; emptyNode.NodeID = ""; newNode.Nodes.Add(emptyNode); } } else { var cnProfessions = from x in Funs.DB.WBS_CnProfession where x.InstallationId == e.Node.NodeID orderby x.OldId select x; if (cnProfessions.Count() > 0) //普通装置主项 { foreach (var cnProfession in cnProfessions) { var unitProjects = from x in Funs.DB.Wbs_UnitProject where x.CnProfessionId == cnProfession.CnProfessionId && x.IsApprove == true select x; if (unitProjects.Count() > 0) { TreeNode newNode = new TreeNode(); if (noApproveCnProfessionIds.Contains(cnProfession.CnProfessionId)) { newNode.Text = "" + cnProfession.CnProfessionName + ""; } else { newNode.Text = cnProfession.CnProfessionName; } newNode.NodeID = cnProfession.CnProfessionId; newNode.CommandName = "cnProfession"; newNode.CommandArgument = cnProfession.Weights == null ? null : cnProfession.Weights.ToString(); newNode.ToolTip = cnProfession.CnProfessionCode; newNode.EnableExpandEvent = true; newNode.EnableClickEvent = true; e.Node.Nodes.Add(newNode); TreeNode emptyNode = new TreeNode(); emptyNode.Text = ""; emptyNode.NodeID = ""; newNode.Nodes.Add(emptyNode); } } } else //总图 { var unitProjects = from x in Funs.DB.Wbs_UnitProject where x.InstallationId == e.Node.NodeID && x.SuperUnitProjectId == null orderby x.SortIndex, x.UnitProjectCode select x; foreach (var unitProject in unitProjects) { var wbsSets = from x in Funs.DB.Wbs_WbsSet where x.UnitProjectId == unitProject.UnitProjectId && x.IsApprove == true select x; if (wbsSets.Count() > 0) { TreeNode newNode = new TreeNode(); if (noApproveUnitProjectIds.Contains(unitProject.UnitProjectId)) { newNode.Text = "" + unitProject.UnitProjectName + ""; } else { newNode.Text = unitProject.UnitProjectName; } newNode.NodeID = unitProject.UnitProjectId; newNode.CommandName = "unitProject"; newNode.CommandArgument = unitProject.Weights == null ? null : unitProject.Weights.ToString(); newNode.ToolTip = unitProject.UnitProjectCode; newNode.EnableExpandEvent = true; newNode.EnableClickEvent = true; e.Node.Nodes.Add(newNode); TreeNode emptyNode = new TreeNode(); emptyNode.Text = ""; emptyNode.NodeID = ""; newNode.Nodes.Add(emptyNode); } } } } } else if (e.Node.CommandName == "cnProfession") //展开专业节点 { var unitProjects = from x in Funs.DB.Wbs_UnitProject where x.CnProfessionId == e.Node.NodeID && x.SuperUnitProjectId == null && x.IsApprove == true orderby x.SortIndex, x.UnitProjectCode select x; foreach (var unitProject in unitProjects) { TreeNode newNode = new TreeNode(); if (noApproveUnitProjectIds.Contains(unitProject.UnitProjectId)) { newNode.Text = "" + unitProject.UnitProjectName + ""; } else { newNode.Text = unitProject.UnitProjectName; } newNode.NodeID = unitProject.UnitProjectId; newNode.CommandName = "unitProject"; newNode.CommandArgument = unitProject.Weights == null ? null : unitProject.Weights.ToString(); newNode.ToolTip = unitProject.UnitProjectCode; newNode.EnableExpandEvent = true; newNode.EnableClickEvent = true; e.Node.Nodes.Add(newNode); TreeNode emptyNode = new TreeNode(); emptyNode.Text = ""; emptyNode.NodeID = ""; newNode.Nodes.Add(emptyNode); } } else if (e.Node.CommandName == "unitProject") //展开单位工程节点 { var childUnitProjects = from x in Funs.DB.Wbs_UnitProject where x.SuperUnitProjectId == e.Node.NodeID && x.IsApprove == true orderby x.SortIndex, x.UnitProjectCode select x; if (childUnitProjects.Count() > 0) //存在子单位工程 { foreach (var childUnitProject in childUnitProjects) { TreeNode newNode = new TreeNode(); if (noApproveUnitProjectIds.Contains(childUnitProject.UnitProjectId)) { newNode.Text = "" + childUnitProject.UnitProjectName + ""; } else { newNode.Text = childUnitProject.UnitProjectName; } newNode.NodeID = childUnitProject.UnitProjectId; newNode.CommandName = "childUnitProject"; newNode.CommandArgument = childUnitProject.Weights == null ? null : childUnitProject.Weights.ToString(); newNode.ToolTip = childUnitProject.UnitProjectCode; newNode.EnableExpandEvent = true; newNode.EnableClickEvent = true; e.Node.Nodes.Add(newNode); TreeNode emptyNode = new TreeNode(); emptyNode.Text = ""; emptyNode.NodeID = ""; newNode.Nodes.Add(emptyNode); } } else //不存在子单位工程,加载分部工程 { var wbsSet1s = from x in Funs.DB.Wbs_WbsSet where x.SuperWbsSetId == null && x.UnitProjectId == e.Node.NodeID && x.IsApprove == true && x.NoShow == null orderby x.SortIndex, x.WbsSetCode select x; if (wbsSet1s.Count() > 0) { foreach (var wbsSet1 in wbsSet1s) { TreeNode newNode = new TreeNode(); if (noApproveWbsSetIds.Contains(wbsSet1.WbsSetId)) { newNode.Text = "" + wbsSet1.WbsSetName + ""; } else { newNode.Text = wbsSet1.WbsSetName; } newNode.NodeID = wbsSet1.WbsSetId; newNode.CommandName = "wbsSet"; newNode.CommandArgument = wbsSet1.Weights == null ? null : wbsSet1.Weights.ToString(); newNode.ToolTip = wbsSet1.WbsSetCode; newNode.EnableExpandEvent = true; newNode.EnableClickEvent = true; e.Node.Nodes.Add(newNode); var childWbsSets2 = BLL.WbsSetService.GetApproveWbsSetsBySuperWbsSetId(newNode.NodeID); if (childWbsSets2.Count() > 0) { TreeNode emptyNode = new TreeNode(); emptyNode.Text = ""; emptyNode.NodeID = ""; newNode.Nodes.Add(emptyNode); } } } else //单位工程下直接是分项内容,如质量行为 { var wbsSet3s = from x in Funs.DB.Wbs_WbsSet where x.SuperWbsSetId == null && x.UnitProjectId == e.Node.NodeID && x.IsApprove == true && x.NoShow == null orderby x.SortIndex, x.WbsSetCode select x; if (wbsSet3s.Count() > 0) { foreach (var wbsSet3 in wbsSet3s) { TreeNode newNode = new TreeNode(); if (noApproveWbsSetIds.Contains(wbsSet3.WbsSetId)) { newNode.Text = "" + wbsSet3.WbsSetName + ""; } else { newNode.Text = wbsSet3.WbsSetName; } newNode.NodeID = wbsSet3.WbsSetId; newNode.CommandName = "wbsSet"; newNode.CommandArgument = wbsSet3.Weights == null ? null : wbsSet3.Weights.ToString(); newNode.ToolTip = wbsSet3.WbsSetCode; newNode.EnableExpandEvent = true; newNode.EnableClickEvent = true; e.Node.Nodes.Add(newNode); var childWbsSets2 = BLL.WbsSetService.GetApproveWbsSetsBySuperWbsSetId(newNode.NodeID); if (childWbsSets2.Count() > 0) { TreeNode emptyNode = new TreeNode(); emptyNode.Text = ""; emptyNode.NodeID = ""; newNode.Nodes.Add(emptyNode); } } } } } } else if (e.Node.CommandName == "childUnitProject") //展开子单位工程节点 { var wbsSet1s = from x in Funs.DB.Wbs_WbsSet where x.SuperWbsSetId == null && x.UnitProjectId == e.Node.NodeID && x.IsApprove == true && x.NoShow == null orderby x.SortIndex, x.WbsSetCode select x; foreach (var wbsSet1 in wbsSet1s) { TreeNode newNode = new TreeNode(); if (noApproveWbsSetIds.Contains(wbsSet1.WbsSetId)) { newNode.Text = "" + wbsSet1.WbsSetName + ""; } else { newNode.Text = wbsSet1.WbsSetName; } newNode.NodeID = wbsSet1.WbsSetId; newNode.CommandName = "wbsSet"; newNode.CommandArgument = wbsSet1.Weights == null ? null : wbsSet1.Weights.ToString(); newNode.ToolTip = wbsSet1.WbsSetCode; newNode.EnableExpandEvent = true; newNode.EnableClickEvent = true; e.Node.Nodes.Add(newNode); var childWbsSets2 = BLL.WbsSetService.GetApproveWbsSetsBySuperWbsSetId(newNode.NodeID); if (childWbsSets2.Count() > 0) { TreeNode emptyNode = new TreeNode(); emptyNode.Text = ""; emptyNode.NodeID = ""; newNode.Nodes.Add(emptyNode); } } } else if (e.Node.CommandName == "wbsSet") //展开分部/子分部/分项/子分项工程节点 { var childWbsSets = BLL.WbsSetService.GetApproveWbsSetsBySuperWbsSetId(e.Node.NodeID); foreach (var wbsSet in childWbsSets) { TreeNode newNode = new TreeNode(); if (noApproveWbsSetIds.Contains(wbsSet.WbsSetId)) { newNode.Text = "" + wbsSet.WbsSetName + ""; } else { newNode.Text = wbsSet.WbsSetName; } newNode.NodeID = wbsSet.WbsSetId; newNode.CommandName = "wbsSet"; newNode.CommandArgument = wbsSet.Weights == null ? null : wbsSet.Weights.ToString(); newNode.ToolTip = wbsSet.WbsSetCode; newNode.EnableExpandEvent = true; newNode.EnableClickEvent = true; e.Node.Nodes.Add(newNode); var childWbsSets2 = BLL.WbsSetService.GetApproveWbsSetsBySuperWbsSetId(newNode.NodeID); if (childWbsSets2.Count() > 0) { TreeNode emptyNode = new TreeNode(); emptyNode.Text = ""; emptyNode.NodeID = ""; newNode.Nodes.Add(emptyNode); } } } } #endregion #region Tree点击事件 /// /// Tree点击事件 /// /// /// protected void trWBS_NodeCommand(object sender, TreeCommandEventArgs e) { this.Grid1.Title = string.Empty; string title = string.Empty; string nodeTooltip = string.Empty; string nodeText = string.Empty; TreeNode parent1 = new TreeNode(); if (this.trWBS.SelectedNode != null) { nodeTooltip = this.trWBS.SelectedNode.ToolTip; nodeText = this.trWBS.SelectedNode.Text; parent1 = this.trWBS.SelectedNode.ParentNode; } if (parent1 != null) { TreeNode parent2 = parent1.ParentNode; if (parent2 != null) { TreeNode parent3 = parent2.ParentNode; if (parent3 != null) { TreeNode parent4 = parent3.ParentNode; if (parent4 != null) { TreeNode parent5 = parent4.ParentNode; if (parent5 != null) { TreeNode parent6 = parent5.ParentNode; if (parent6 != null) { title = parent6.ToolTip + "-" + parent5.ToolTip + "-" + nodeTooltip + "/" + parent6.Text + "-" + parent5.Text + "-" + parent4.Text + "-" + parent3.Text + "-" + parent2.Text + "-" + parent1.Text + "-" + nodeText; } else { if (parent5.CommandName == "installation") { title = parent5.ToolTip + "-" + parent4.ToolTip + "-" + nodeTooltip + "/" + parent5.Text + "-" + parent4.Text + "-" + parent3.Text + "-" + parent2.Text + "-" + parent1.Text + "-" + nodeText; } } } else { if (parent4.CommandName == "installation") { title = parent4.ToolTip + "-" + parent3.ToolTip + "-" + nodeTooltip + "/" + parent4.Text + "-" + parent3.Text + "-" + parent2.Text + "-" + parent1.Text + "-" + nodeText; } } } else { if (parent3.CommandName == "installation") { title = parent3.ToolTip + "-" + parent2.ToolTip + "-" + nodeTooltip + "/" + parent3.Text + "-" + parent2.Text + "-" + parent1.Text + "-" + nodeText; } } } else { if (parent2.CommandName == "installation") { title = parent2.ToolTip + "-" + parent1.ToolTip + "-" + nodeTooltip + "/" + parent2.Text + "-" + parent1.Text + "-" + nodeText; } } } else { if (parent1.CommandName == "installation") { title = parent1.ToolTip + "-" + nodeTooltip + "/" + parent1.Text + "-" + nodeText; } } } else { title = nodeTooltip + "/" + nodeText; } this.Grid1.Title = title; BindGrid(); OutputSummaryData(); } #endregion #region 保存方法 /// /// 保存方法 /// /// private void SaveData() { if (this.Grid1.Rows.Count > 0) { if (!string.IsNullOrEmpty(this.Grid1.Rows[0].Values[10].ToString())) { decimal totalValue = 0, totalRate = 0; decimal moneys = Convert.ToDecimal(this.Grid1.Rows[0].Values[10].ToString()); for (int i = 0; i < this.Grid1.Rows.Count; i++) { if (!string.IsNullOrEmpty(this.Grid1.Rows[i].Values[1].ToString())) { decimal rate = 0; totalValue += Convert.ToDecimal(this.Grid1.Rows[i].Values[1].ToString()); if (moneys != 0) { rate = decimal.Round(Convert.ToDecimal(this.Grid1.Rows[i].Values[1].ToString()) / moneys * 100, 2); } totalRate += rate; this.Grid1.Rows[i].Values[2] = totalValue; this.Grid1.Rows[i].Values[3] = totalRate; if (i == this.Grid1.Rows.Count - 1) { if (moneys == totalValue) { this.Grid1.Rows[i].Values[3] = 100; } } } } if (totalValue != moneys) { Alert.ShowInTop("金额分配不符合要求!", MessageBoxIcon.Warning); return; } } if (this.Grid1.Rows[this.Grid1.Rows.Count - 1].Values[3].ToString() != "100") { Alert.ShowInTop("占比值不是100%!", MessageBoxIcon.Warning); return; } } Model.Wbs_WbsSet wbsSet = BLL.WbsSetService.GetWbsSetByWbsSetId(this.trWBS.SelectedNodeID); wbsSet.IsPlanApprove = true; if (string.IsNullOrEmpty(wbsSet.VersionNum)) { wbsSet.VersionNum = "V1.0"; } else { string version = wbsSet.VersionNum.Substring(1, wbsSet.VersionNum.Length - 3); wbsSet.VersionNum = "V" + (Convert.ToInt32(version) + 1) + ".0"; } BLL.WbsSetService.UpdateWbsSet(wbsSet); for (int i = 0; i < this.Grid1.Rows.Count; i++) { string type = this.trWBS.SelectedNode.CommandName; if (type == "wbsSet") { var childWbsSets = BLL.WbsSetService.GetApproveWbsSetsBySuperWbsSetId(this.trWBS.SelectedNodeID); if (childWbsSets.Count == 0) //当前为末级 { Model.WbsDetail detail = new Model.WbsDetail(); detail.WbsDetailId = this.Grid1.Rows[i].Values[4].ToString(); detail.ToWbs = this.Grid1.Rows[i].Values[5].ToString(); detail.ToFlag = Convert.ToInt32(this.Grid1.Rows[i].Values[6].ToString()); detail.Way = this.Grid1.Rows[i].Values[7].ToString(); detail.Months = Convert.ToDateTime(this.Grid1.Rows[i].Values[9].ToString()); if (!string.IsNullOrEmpty(this.Grid1.Rows[i].Values[1].ToString())) { detail.PlanValue = Convert.ToDecimal(this.Grid1.Rows[i].Values[1].ToString()); if (Convert.ToDecimal(this.Grid1.Rows[i].Values[10].ToString()) != 0) { detail.PlanValueRate = decimal.Round(Convert.ToDecimal(detail.PlanValue) / Convert.ToDecimal(this.Grid1.Rows[i].Values[10].ToString()) * 100, 2); } else { detail.PlanValueRate = 0; } } var oldDetail = BLL.WbsDetailService.GetWbsDetailByWbsDetailId(detail.WbsDetailId); if (oldDetail == null) { BLL.WbsDetailService.AddWbsDetail(detail); } else { decimal? oldValue = oldDetail.PlanValue; detail.CompleteValue = oldDetail.CompleteValue; detail.CompleteValueRate = oldDetail.CompleteValueRate; detail.RealValue = oldDetail.RealValue; detail.RealValueRate = oldDetail.RealValueRate; BLL.WbsDetailService.UpdateWbsDetail(detail); } } } } //BLL.Sys_LogService.AddLog(BLL.Const.System_9, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "审核计划值"); ShowNotify("保存成功!", MessageBoxIcon.Success); } #endregion #region 保存方法2(用于展开末级项时的自动保存) /// /// 保存方法2(用于展开末级项时的自动保存) /// /// private void SaveData2() { Model.Wbs_WbsSet wbsSet = BLL.WbsSetService.GetWbsSetByWbsSetId(this.trWBS.SelectedNodeID); for (int i = 0; i < this.Grid1.Rows.Count; i++) { string type = this.trWBS.SelectedNode.CommandName; if (type == "wbsSet") { var childWbsSets = BLL.WbsSetService.GetApproveWbsSetsBySuperWbsSetId(this.trWBS.SelectedNodeID); if (childWbsSets.Count == 0) //当前为末级 { Model.WbsDetail detail = new Model.WbsDetail(); detail.WbsDetailId = this.Grid1.Rows[i].Values[4].ToString(); detail.ToWbs = this.Grid1.Rows[i].Values[5].ToString(); detail.ToFlag = Convert.ToInt32(this.Grid1.Rows[i].Values[6].ToString()); detail.Way = this.Grid1.Rows[i].Values[7].ToString(); detail.Months = Convert.ToDateTime(this.Grid1.Rows[i].Values[9].ToString()); if (!string.IsNullOrEmpty(this.Grid1.Rows[i].Values[1].ToString())) { detail.PlanValue = Convert.ToDecimal(this.Grid1.Rows[i].Values[1].ToString()); if (this.Grid1.Rows[i].Values[10].ToString() != "0") { detail.PlanValueRate = decimal.Round(Convert.ToDecimal(detail.PlanValue) / Convert.ToDecimal(this.Grid1.Rows[i].Values[10].ToString()) * 100, 2); } } var oldDetail = BLL.WbsDetailService.GetWbsDetailByWbsDetailId(detail.WbsDetailId); if (oldDetail == null) { BLL.WbsDetailService.AddWbsDetail(detail); } } } } //BLL.Sys_LogService.AddLog(BLL.Const.System_9, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "审核计划值"); } #endregion #region 增加分部分项 /// /// 增加分部分项 /// /// /// /// /// private void AddWbsParentDetail(DateTime months, decimal? planValue, string parentId, decimal? completeValue, decimal? realValue) { Model.Wbs_WbsSet parentWbsSet1 = BLL.WbsSetService.GetWbsSetByWbsSetId(parentId); if (parentWbsSet1 != null) { if (parentWbsSet1.WeightsMoney != null) { if (parentWbsSet1.SuperWbsSetId != null) //父节点不是分部节点 { Model.WbsDetail detail1 = BLL.WbsDetailService.GetWbsDetailByWbsFlagYearMonth(parentWbsSet1.WbsSetId, 4, months); if (detail1 == null) { Model.WbsDetail newDetail1 = new Model.WbsDetail(); newDetail1.WbsDetailId = SQLHelper.GetNewID(typeof(Model.WbsDetail)); newDetail1.ToWbs = parentWbsSet1.WbsSetId; newDetail1.ToFlag = 4; newDetail1.Way = parentWbsSet1.Way; newDetail1.Months = months; newDetail1.PlanValue = planValue ?? 0; newDetail1.CompleteValue = completeValue ?? 0; newDetail1.RealValue = realValue ?? 0; if (parentWbsSet1.WeightsMoney != null) { newDetail1.PlanValueRate = decimal.Round(Convert.ToDecimal(newDetail1.PlanValue) / Convert.ToDecimal(parentWbsSet1.WeightsMoney) * 100, 2); newDetail1.CompleteValueRate = decimal.Round(Convert.ToDecimal(newDetail1.CompleteValue) / Convert.ToDecimal(parentWbsSet1.WeightsMoney) * 100, 2); newDetail1.RealValueRate = decimal.Round(Convert.ToDecimal(newDetail1.RealValue) / Convert.ToDecimal(parentWbsSet1.WeightsMoney) * 100, 2); } else { newDetail1.PlanValueRate = 0; newDetail1.CompleteValueRate = 0; newDetail1.RealValueRate = 0; } BLL.WbsDetailService.AddWbsDetail(newDetail1); } else { detail1.PlanValue += planValue ?? 0; detail1.CompleteValue += completeValue ?? 0; detail1.RealValue += realValue ?? 0; if (parentWbsSet1.WeightsMoney != null) { detail1.PlanValueRate = decimal.Round(Convert.ToDecimal(detail1.PlanValue) / Convert.ToDecimal(parentWbsSet1.WeightsMoney) * 100, 2); detail1.CompleteValueRate = decimal.Round(Convert.ToDecimal(detail1.CompleteValue) / Convert.ToDecimal(parentWbsSet1.WeightsMoney) * 100, 2); detail1.RealValueRate = decimal.Round(Convert.ToDecimal(detail1.RealValue) / Convert.ToDecimal(parentWbsSet1.WeightsMoney) * 100, 2); } else { detail1.PlanValueRate = 0; detail1.CompleteValueRate = 0; detail1.RealValueRate = 0; } BLL.WbsDetailService.UpdateWbsDetail(detail1); } AddWbsParentDetail(months, planValue, parentWbsSet1.SuperWbsSetId, completeValue, realValue); } else { Model.WbsDetail detail1 = BLL.WbsDetailService.GetWbsDetailByWbsFlagYearMonth(parentWbsSet1.WbsSetId, 4, months); if (detail1 == null) { Model.WbsDetail newDetail1 = new Model.WbsDetail(); newDetail1.WbsDetailId = SQLHelper.GetNewID(typeof(Model.WbsDetail)); newDetail1.ToWbs = parentWbsSet1.WbsSetId; newDetail1.ToFlag = 4; newDetail1.Way = parentWbsSet1.Way; newDetail1.Months = months; newDetail1.PlanValue = planValue; newDetail1.CompleteValue = completeValue ?? 0; newDetail1.RealValue = realValue ?? 0; if (parentWbsSet1.WeightsMoney != null) { newDetail1.PlanValueRate = decimal.Round(Convert.ToDecimal(newDetail1.PlanValue) / Convert.ToDecimal(parentWbsSet1.WeightsMoney) * 100, 2); newDetail1.CompleteValueRate = decimal.Round(Convert.ToDecimal(newDetail1.CompleteValue) / Convert.ToDecimal(parentWbsSet1.WeightsMoney) * 100, 2); newDetail1.RealValueRate = decimal.Round(Convert.ToDecimal(newDetail1.RealValue) / Convert.ToDecimal(parentWbsSet1.WeightsMoney) * 100, 2); } else { newDetail1.PlanValueRate = 0; newDetail1.CompleteValueRate = 0; newDetail1.RealValueRate = 0; } BLL.WbsDetailService.AddWbsDetail(newDetail1); } else { detail1.PlanValue += planValue; detail1.CompleteValue += completeValue ?? 0; detail1.RealValue += realValue ?? 0; if (parentWbsSet1.WeightsMoney != null) { detail1.PlanValueRate = decimal.Round(Convert.ToDecimal(detail1.PlanValue) / Convert.ToDecimal(parentWbsSet1.WeightsMoney) * 100, 2); detail1.CompleteValueRate = decimal.Round(Convert.ToDecimal(detail1.CompleteValue) / Convert.ToDecimal(parentWbsSet1.WeightsMoney) * 100, 2); detail1.RealValueRate = decimal.Round(Convert.ToDecimal(detail1.RealValue) / Convert.ToDecimal(parentWbsSet1.WeightsMoney) * 100, 2); } else { detail1.PlanValueRate = 0; detail1.CompleteValueRate = 0; detail1.RealValueRate = 0; } BLL.WbsDetailService.UpdateWbsDetail(detail1); } } } } } #endregion #region 更新分部分项 /// /// 更新分部分项 /// /// /// /// /// private void UpdateWbsParentDetail(DateTime months, decimal? planValue, decimal? oldPlanValue, string parentId) { Model.Wbs_WbsSet parentWbsSet1 = BLL.WbsSetService.GetWbsSetByWbsSetId(parentId); if (parentWbsSet1 != null) { Model.WbsDetail detail1 = BLL.WbsDetailService.GetWbsDetailByWbsFlagYearMonth(parentWbsSet1.WbsSetId, 4, months); if (detail1 != null) { if (parentWbsSet1.SuperWbsSetId != null) //父节点不是分部节点 { detail1.PlanValue += ((planValue ?? 0) - (oldPlanValue ?? 0)); detail1.PlanValueRate = decimal.Round(Convert.ToDecimal(detail1.PlanValue) / Convert.ToDecimal(parentWbsSet1.WeightsMoney) * 100, 2); BLL.WbsDetailService.UpdateWbsDetail(detail1); UpdateWbsParentDetail(months, planValue, oldPlanValue, parentWbsSet1.SuperWbsSetId); } else { detail1.PlanValue += ((planValue ?? 0) - (oldPlanValue ?? 0)); detail1.PlanValueRate = decimal.Round(Convert.ToDecimal(detail1.PlanValue) / Convert.ToDecimal(parentWbsSet1.WeightsMoney) * 100, 2); BLL.WbsDetailService.UpdateWbsDetail(detail1); } } } } #endregion #region 提交、保存按钮 /// /// 提交 /// /// /// protected void btnSave_Click(object sender, EventArgs e) { if (this.Grid1.Rows.Count > 0) { SaveData(); } else { Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); return; } } #endregion #region 查看之前版本 /// /// 查看之前版本 /// /// /// protected void btnSee_Click(object sender, EventArgs e) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("SeeDetailHistory.aspx?ToWbs={0}", this.trWBS.SelectedNodeID, "编辑 - "))); } #endregion #region 绑定数据 /// /// 绑定数据 /// /// /// protected void Grid1_FilterChange(object sender, EventArgs e) { BindGrid(); } protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { Grid1.PageIndex = e.NewPageIndex; BindGrid(); } /// /// Grid1排序 /// /// /// protected void Grid1_Sort(object sender, GridSortEventArgs e) { Grid1.SortDirection = e.SortDirection; Grid1.SortField = e.SortField; BindGrid(); } /// /// 加载Grid /// private void BindGrid() { this.btnSave.Hidden = true; this.btnSee.Hidden = true; DateTime startDate, endDate, startMonth, endMonth, parentStartDate, parentEndDate, parentStartMonth, parentEndMonth; List items = new List(); List months = new List(); string column0 = string.Empty; decimal totalValue = 0, totalRate = 0; RenderField column = Grid1.FindColumn("PlanValue") as RenderField; column.EnableColumnEdit = false; this.lbIsAudit.Text = string.Empty; if (this.trWBS.SelectedNode != null) { #region 分部分项 if (this.trWBS.SelectedNode.CommandName == "wbsSet") { Model.Wbs_WbsSet wbsSet = BLL.WbsSetService.GetWbsSetByWbsSetId(this.trWBS.SelectedNode.NodeID); if (wbsSet != null) { var childWbsSets = BLL.WbsSetService.GetApproveWbsSetsBySuperWbsSetId(wbsSet.WbsSetId); if (childWbsSets.Count() == 0) //当前为末级 { BLL.WbsSetService.UpdateWbsSetIsPlanApprove(wbsSet, true); this.lbIsAudit.Text = "已审核!"; } startDate = Convert.ToDateTime(wbsSet.StartDate); endDate = Convert.ToDateTime(wbsSet.EndDate); startMonth = Convert.ToDateTime(startDate.Year + "-" + startDate.Month + "-01"); endMonth = Convert.ToDateTime(endDate.Year + "-" + endDate.Month + "-01"); do { months.Add(startMonth); startMonth = startMonth.AddMonths(1); } while (startMonth <= endMonth); column0 = "进度计划开始日期:" + string.Format("{0:yyyy-MM-dd}", startDate) + "
进度计划结束日期:" + string.Format("{0:yyyy-MM-dd}", endDate); this.Grid1.Columns[0].HeaderText = column0; if (childWbsSets.Count == 0) //当前为末级 { //获取父级节点的月份集合 List parentMonths = new List(); //父级节点的月份集合 string parentId = this.trWBS.SelectedNode.ParentNode.NodeID; Model.Wbs_WbsSet parentWbsSet = BLL.WbsSetService.GetWbsSetByWbsSetId(parentId); if (parentWbsSet != null) //父级为分部 { parentStartDate = Convert.ToDateTime(parentWbsSet.StartDate); parentEndDate = Convert.ToDateTime(parentWbsSet.EndDate); parentStartMonth = Convert.ToDateTime(parentStartDate.Year + "-" + parentStartDate.Month + "-01"); parentEndMonth = Convert.ToDateTime(parentEndDate.Year + "-" + parentEndDate.Month + "-01"); do { parentMonths.Add(parentStartMonth); parentStartMonth = parentStartMonth.AddMonths(1); } while (parentStartMonth <= parentEndMonth); } else //父级为质量行为 { Model.Wbs_UnitProject unitProject = BLL.UnitProjectService.GetUnitProjectByUnitProjectId(parentId); if (unitProject != null) { parentStartDate = Convert.ToDateTime(unitProject.StartDate); parentEndDate = Convert.ToDateTime(unitProject.EndDate); parentStartMonth = Convert.ToDateTime(parentStartDate.Year + "-" + parentStartDate.Month + "-01"); parentEndMonth = Convert.ToDateTime(parentEndDate.Year + "-" + parentEndDate.Month + "-01"); do { parentMonths.Add(parentStartMonth); parentStartMonth = parentStartMonth.AddMonths(1); } while (parentStartMonth <= parentEndMonth); } } RenderField columnPlanValue = Grid1.FindColumn("PlanValue") as RenderField; columnPlanValue.EnableColumnEdit = true; if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.WBSPlanAuditMenuId, Const.BtnSave)) { this.btnSave.Hidden = false; this.btnSee.Hidden = false; } if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.WBSPlanAuditMenuId, Const.BtnAuditing)) { this.btnSee.Hidden = false; } for (int i = 0; i < months.Count; i++) { Model.WbsDetail detail = BLL.WbsDetailService.GetWbsDetailByWbsFlagYearMonth(wbsSet.WbsSetId, 4, months[i]); if (detail == null) { Model.WBSDetailItem item = new Model.WBSDetailItem(); item.WbsDetailId = SQLHelper.GetNewID(typeof(Model.WbsDetail)); item.ToWbs = wbsSet.WbsSetId; item.ToFlag = 4; //分部分项 item.Way = wbsSet.Way; item.Months = months[i]; item.YearsMonthsStr = months[i].Year + "年" + months[i].Month + "月"; item.WeightsMoney = wbsSet.WeightsMoney; if (wbsSet.WeightsMoney != null) { decimal moneys = decimal.Round(Convert.ToDecimal(wbsSet.WeightsMoney), 2); if (i == months.Count - 1) { decimal lastPlanValue = decimal.Round(Convert.ToDecimal(wbsSet.WeightsMoney - totalValue), 2); if (lastPlanValue >= 0) { item.PlanValue = lastPlanValue; } } else { item.PlanValue = WbsDetailService.GetMonthPlanValueByMonthCountAndMonthNumAndWeightMonth(months.Count, i + 1, Convert.ToDecimal(wbsSet.WeightsMoney)); } if (wbsSet.WeightsMoney != 0) { item.PlanValueRate = decimal.Round(Convert.ToDecimal(item.PlanValue / wbsSet.WeightsMoney * 100), 2); } else { item.PlanValueRate = 0; } totalValue += item.PlanValue != null ? item.PlanValue.Value : 0; totalRate += item.PlanValueRate != null ? item.PlanValueRate.Value : 0; item.PlanValueTotal = totalValue; item.PlanValueRateTotal = totalRate; if (i == months.Count - 1) { if (wbsSet.WeightsMoney == totalValue) { item.PlanValueRateTotal = 100; } } } items.Add(item); } else { Model.WBSDetailItem item = new Model.WBSDetailItem(); item.WbsDetailId = detail.WbsDetailId; item.ToWbs = detail.ToWbs; item.ToFlag = 4; //分部分项 item.Way = detail.Way; item.Months = months[i]; item.YearsMonthsStr = months[i].Year + "年" + months[i].Month + "月"; item.WeightsMoney = wbsSet.WeightsMoney; if (detail.PlanValue != null) { item.PlanValue = decimal.Round(Convert.ToDecimal(detail.PlanValue), 2); item.PlanValueRate = decimal.Round(Convert.ToDecimal(detail.PlanValueRate), 2); totalValue += decimal.Round(Convert.ToDecimal(item.PlanValue), 2); totalRate += decimal.Round(Convert.ToDecimal(item.PlanValueRate), 2); item.PlanValueTotal = totalValue; item.PlanValueRateTotal = totalRate; if (i == months.Count - 1) { if (wbsSet.WeightsMoney == totalValue) { item.PlanValueRateTotal = 100; } } } items.Add(item); } } for (int i = 0; i < parentMonths.Count; i++) { if (!months.Contains(parentMonths[i])) { Model.WbsDetail detail = (from x in Funs.DB.WbsDetail where x.ToWbs == wbsSet.WbsSetId && x.Months == parentMonths[i] select x).FirstOrDefault(); if (detail == null) { Model.WBSDetailItem item = new Model.WBSDetailItem(); item.WbsDetailId = SQLHelper.GetNewID(typeof(Model.WbsDetail)); item.ToWbs = wbsSet.WbsSetId; item.ToFlag = 4; //分部分项 item.Way = wbsSet.Way; item.Months = parentMonths[i]; item.YearsMonthsStr = parentMonths[i].Year + "年" + parentMonths[i].Month + "月"; item.WeightsMoney = wbsSet.WeightsMoney; item.PlanValue = 0; item.PlanValueRate = 0; items.Add(item); } else { Model.WBSDetailItem item = new Model.WBSDetailItem(); item.WbsDetailId = detail.WbsDetailId; item.ToWbs = wbsSet.WbsSetId; item.ToFlag = 4; //分部分项 item.Way = wbsSet.Way; item.Months = parentMonths[i]; item.YearsMonthsStr = parentMonths[i].Year + "年" + parentMonths[i].Month + "月"; item.WeightsMoney = wbsSet.WeightsMoney; item.PlanValue = detail.PlanValue; item.PlanValueRate = detail.PlanValueRate; items.Add(item); } } } items = items.OrderBy(x => x.Months).ToList(); } else //当前不为末级 { for (int i = 0; i < months.Count; i++) { Model.WbsDetail detail = BLL.WbsDetailService.GetWbsDetailByWbsFlagYearMonth(wbsSet.WbsSetId, 4, months[i]); if (detail != null) { Model.WBSDetailItem item = new Model.WBSDetailItem(); item.WbsDetailId = detail.WbsDetailId; item.ToWbs = detail.ToWbs; item.ToFlag = 4; //分部分项 item.Way = detail.Way; item.Months = months[i]; item.YearsMonthsStr = months[i].Year + "年" + months[i].Month + "月"; item.WeightsMoney = wbsSet.WeightsMoney; if (detail.PlanValue != null) { item.PlanValue = decimal.Round(Convert.ToDecimal(detail.PlanValue), 2); item.PlanValueRate = decimal.Round(Convert.ToDecimal(detail.PlanValueRate), 2); totalValue += decimal.Round(Convert.ToDecimal(item.PlanValue), 2); totalRate += decimal.Round(Convert.ToDecimal(item.PlanValueRate), 2); item.PlanValueTotal = totalValue; item.PlanValueRateTotal = totalRate; if (i == months.Count - 1) { if (wbsSet.WeightsMoney == totalValue) { item.PlanValueRateTotal = 100; } } } items.Add(item); } } } } } #endregion #region 单位工程/子单位工程 else if (this.trWBS.SelectedNode.CommandName == "unitProject" || this.trWBS.SelectedNode.CommandName == "childUnitProject") { Model.Wbs_UnitProject unitProject = BLL.UnitProjectService.GetUnitProjectByUnitProjectId(this.trWBS.SelectedNode.NodeID); if (unitProject != null) { startDate = Convert.ToDateTime(unitProject.StartDate); endDate = Convert.ToDateTime(unitProject.EndDate); startMonth = Convert.ToDateTime(startDate.Year + "-" + startDate.Month + "-01"); endMonth = Convert.ToDateTime(endDate.Year + "-" + endDate.Month + "-01"); do { months.Add(startMonth); startMonth = startMonth.AddMonths(1); } while (startMonth <= endMonth); column0 = "进度计划开始日期:" + string.Format("{0:yyyy-MM-dd}", startDate) + "
进度计划结束日期:" + string.Format("{0:yyyy-MM-dd}", endDate); this.Grid1.Columns[0].HeaderText = column0; for (int i = 0; i < months.Count; i++) { Model.WbsDetail detail = BLL.WbsDetailService.GetWbsDetailByWbsFlagYearMonth(unitProject.UnitProjectId, 3, months[i]); if (detail != null) { Model.WBSDetailItem item = new Model.WBSDetailItem(); item.WbsDetailId = detail.WbsDetailId; item.ToWbs = detail.ToWbs; item.ToFlag = 3; //单位工程/子单位工程 item.Way = detail.Way; item.Months = months[i]; item.YearsMonthsStr = months[i].Year + "年" + months[i].Month + "月"; item.WeightsMoney = unitProject.WeightsMoney; if (detail.PlanValue != null) { item.PlanValue = decimal.Round(Convert.ToDecimal(detail.PlanValue), 2); item.PlanValueRate = decimal.Round(Convert.ToDecimal(detail.PlanValueRate), 2); totalValue += decimal.Round(Convert.ToDecimal(item.PlanValue), 2); totalRate += decimal.Round(Convert.ToDecimal(item.PlanValueRate), 2); item.PlanValueTotal = totalValue; item.PlanValueRateTotal = totalRate; if (i == months.Count - 1) { if (unitProject.WeightsMoney == totalValue) { item.PlanValueRateTotal = 100; } } } items.Add(item); } } } } #endregion #region 专业 else if (this.trWBS.SelectedNode.CommandName == "cnProfession") { Model.WBS_CnProfession cnProfession = BLL.CnProfessionService.GetCnProfessionByCnProfessionId(this.trWBS.SelectedNode.NodeID); if (cnProfession != null) { startDate = Convert.ToDateTime(cnProfession.StartDate); endDate = Convert.ToDateTime(cnProfession.EndDate); startMonth = Convert.ToDateTime(startDate.Year + "-" + startDate.Month + "-01"); endMonth = Convert.ToDateTime(endDate.Year + "-" + endDate.Month + "-01"); do { months.Add(startMonth); startMonth = startMonth.AddMonths(1); } while (startMonth <= endMonth); column0 = "进度计划开始日期:" + string.Format("{0:yyyy-MM-dd}", startDate) + "
进度计划结束日期:" + string.Format("{0:yyyy-MM-dd}", endDate); this.Grid1.Columns[0].HeaderText = column0; for (int i = 0; i < months.Count; i++) { Model.WbsDetail detail = BLL.WbsDetailService.GetWbsDetailByWbsFlagYearMonth(cnProfession.CnProfessionId, 2, months[i]); if (detail != null) { Model.WBSDetailItem item = new Model.WBSDetailItem(); item.WbsDetailId = detail.WbsDetailId; item.ToWbs = detail.ToWbs; item.ToFlag = 2; //专业 item.Way = detail.Way; item.Months = months[i]; item.YearsMonthsStr = months[i].Year + "年" + months[i].Month + "月"; item.WeightsMoney = cnProfession.WeightsMoney; if (detail.PlanValue != null) { item.PlanValue = decimal.Round(Convert.ToDecimal(detail.PlanValue), 2); item.PlanValueRate = decimal.Round(Convert.ToDecimal(detail.PlanValueRate), 2); totalValue += decimal.Round(Convert.ToDecimal(item.PlanValue), 2); totalRate += decimal.Round(Convert.ToDecimal(item.PlanValueRate), 2); item.PlanValueTotal = totalValue; item.PlanValueRateTotal = totalRate; if (i == months.Count - 1) { if (cnProfession.WeightsMoney == totalValue) { item.PlanValueRateTotal = 100; } } } items.Add(item); } } } } #endregion #region 装置 else if (this.trWBS.SelectedNode.CommandName == "installation") { Model.Project_Installation installation = BLL.Project_InstallationService.GetInstallationByInstallationId(this.trWBS.SelectedNode.NodeID); if (installation != null) { startDate = Convert.ToDateTime(installation.StartDate); endDate = Convert.ToDateTime(installation.EndDate); startMonth = Convert.ToDateTime(startDate.Year + "-" + startDate.Month + "-01"); endMonth = Convert.ToDateTime(endDate.Year + "-" + endDate.Month + "-01"); do { months.Add(startMonth); startMonth = startMonth.AddMonths(1); } while (startMonth <= endMonth); column0 = "进度计划开始日期:" + string.Format("{0:yyyy-MM-dd}", startDate) + "
进度计划结束日期:" + string.Format("{0:yyyy-MM-dd}", endDate); this.Grid1.Columns[0].HeaderText = column0; for (int i = 0; i < months.Count; i++) { Model.WbsDetail detail = BLL.WbsDetailService.GetWbsDetailByWbsFlagYearMonth(installation.InstallationId, 1, months[i]); if (detail != null) { Model.WBSDetailItem item = new Model.WBSDetailItem(); item.WbsDetailId = detail.WbsDetailId; item.ToWbs = detail.ToWbs; item.ToFlag = 1; //装置 item.Way = detail.Way; item.Months = months[i]; item.YearsMonthsStr = months[i].Year + "年" + months[i].Month + "月"; item.WeightsMoney = installation.WeightsMoney; if (detail.PlanValue != null) { item.PlanValue = decimal.Round(Convert.ToDecimal(detail.PlanValue), 2); item.PlanValueRate = decimal.Round(Convert.ToDecimal(detail.PlanValueRate), 2); totalValue += decimal.Round(Convert.ToDecimal(item.PlanValue), 2); totalRate += decimal.Round(Convert.ToDecimal(item.PlanValueRate), 2); item.PlanValueTotal = totalValue; item.PlanValueRateTotal = totalRate; if (i == months.Count - 1) { if (installation.WeightsMoney == totalValue) { item.PlanValueRateTotal = 100; } } } items.Add(item); } } } } #endregion this.Grid1.DataSource = items; this.Grid1.DataBind(); if (this.trWBS.SelectedNode.CommandName == "wbsSet") { Model.Wbs_WbsSet wbsSet = BLL.WbsSetService.GetWbsSetByWbsSetId(this.trWBS.SelectedNode.NodeID); if (wbsSet != null) { var childWbsSets = BLL.WbsSetService.GetApproveWbsSetsBySuperWbsSetId(wbsSet.WbsSetId); if (childWbsSets.Count == 0) //当前为末级 { SaveData2(); wbsSet.IsPlanApprove = true; if (string.IsNullOrEmpty(wbsSet.VersionNum)) { wbsSet.VersionNum = "V1.0"; } else { string version = wbsSet.VersionNum.Substring(1, wbsSet.VersionNum.Length - 3); wbsSet.VersionNum = "V" + (Convert.ToInt32(version) + 1) + ".0"; } BLL.WbsSetService.UpdateWbsSet(wbsSet); } } } } } #endregion #region 右键重新合计方法 /// /// 右键修改事件 /// /// /// protected void btnMenuEdit_Click(object sender, EventArgs e) { if (this.trWBS.SelectedNode != null) { MergeNextWbsSet(trWBS.SelectedNodeID, trWBS.SelectedNode.CommandName); Alert.ShowInTop("计划值合计完成!", MessageBoxIcon.Warning); } } private void MergeNextWbsSet(string id, string type) { if (type == "installation") { var q = from x in Funs.DB.WbsDetail join y in Funs.DB.WBS_CnProfession on x.ToWbs equals y.CnProfessionId where y.InstallationId == id group new { x.PlanValue, x.CompleteValue, x.RealValue } by new { x.Months } into g select new { Months = g.Key.Months, PlanValue = g.Sum(x => x.PlanValue ?? 0), CompleteValue = g.Sum(x => x.CompleteValue ?? 0), RealValue = g.Sum(x => x.RealValue ?? 0) }; if (q.Count() > 0) { foreach (var wbsSet in q) { AddWbsSetDetail(id, Convert.ToDateTime(wbsSet.Months), Convert.ToDecimal(wbsSet.PlanValue), Convert.ToDecimal(wbsSet.CompleteValue), Convert.ToDecimal(wbsSet.RealValue), 1); } } } if (type == "cnProfession") { var q = from x in Funs.DB.WbsDetail join y in Funs.DB.Wbs_UnitProject on x.ToWbs equals y.UnitProjectId where y.CnProfessionId == id && y.IsApprove == true group new { x.PlanValue, x.CompleteValue, x.RealValue } by new { x.Months } into g select new { Months = g.Key.Months, PlanValue = g.Sum(x => x.PlanValue ?? 0), CompleteValue = g.Sum(x => x.CompleteValue ?? 0), RealValue = g.Sum(x => x.RealValue ?? 0) }; if (q.Count() > 0) { foreach (var wbsSet in q) { AddWbsSetDetail(id, Convert.ToDateTime(wbsSet.Months), Convert.ToDecimal(wbsSet.PlanValue), Convert.ToDecimal(wbsSet.CompleteValue), Convert.ToDecimal(wbsSet.RealValue), 2); } } } if (type == "unitProject") { var q = from x in Funs.DB.WbsDetail join y in Funs.DB.Wbs_WbsSet on x.ToWbs equals y.WbsSetId where y.UnitProjectId == id && y.SuperWbsSetId == null && y.IsApprove == true group new { x.PlanValue, x.CompleteValue, x.RealValue } by new { x.Months } into g select new { Months = g.Key.Months, PlanValue = g.Sum(x => x.PlanValue ?? 0), CompleteValue = g.Sum(x => x.CompleteValue ?? 0), RealValue = g.Sum(x => x.RealValue ?? 0) }; // 子单位工程 var c = from x in Funs.DB.WbsDetail join y in Funs.DB.Wbs_UnitProject on x.ToWbs equals y.UnitProjectId where y.SuperUnitProjectId == id && y.IsApprove == true group new { x.PlanValue, x.CompleteValue, x.RealValue } by new { y.SuperUnitProjectId, x.Months } into g select new { ToWbs = g.Key.SuperUnitProjectId, Months = g.Key.Months, PlanValue = g.Sum(x => x.PlanValue ?? 0), CompleteValue = g.Sum(x => x.CompleteValue ?? 0), RealValue = g.Sum(x => x.RealValue ?? 0) }; if (q.Count() > 0) { foreach (var wbsSet in q) { AddWbsSetDetail(id, Convert.ToDateTime(wbsSet.Months), Convert.ToDecimal(wbsSet.PlanValue), Convert.ToDecimal(wbsSet.CompleteValue), Convert.ToDecimal(wbsSet.RealValue), 3); } } if (c.Count() > 0) { foreach (var wbsSet in c) { AddWbsSetDetail(id, Convert.ToDateTime(wbsSet.Months), Convert.ToDecimal(wbsSet.PlanValue), Convert.ToDecimal(wbsSet.CompleteValue), Convert.ToDecimal(wbsSet.RealValue), 3); } } } if (type == "childUnitProject") { var q = from x in Funs.DB.WbsDetail join y in Funs.DB.Wbs_WbsSet on x.ToWbs equals y.WbsSetId where y.UnitProjectId == id && y.SuperWbsSetId == null && y.IsApprove == true group new { x.PlanValue, x.CompleteValue, x.RealValue } by new { x.Months } into g select new { Months = g.Key.Months, PlanValue = g.Sum(x => x.PlanValue ?? 0), CompleteValue = g.Sum(x => x.CompleteValue ?? 0), RealValue = g.Sum(x => x.RealValue ?? 0) }; if (q.Count() > 0) { foreach (var wbsSet in q) { AddWbsSetDetail(id, Convert.ToDateTime(wbsSet.Months), Convert.ToDecimal(wbsSet.PlanValue), Convert.ToDecimal(wbsSet.CompleteValue), Convert.ToDecimal(wbsSet.RealValue), 3); } } } if (type == "wbsSet") { var q = from x in Funs.DB.WbsDetail join y in Funs.DB.Wbs_WbsSet on x.ToWbs equals y.WbsSetId where y.SuperWbsSetId == id && y.IsApprove == true group new { x.PlanValue, x.CompleteValue, x.RealValue } by new { x.Months } into g select new { Months = g.Key.Months, PlanValue = g.Sum(x => x.PlanValue ?? 0), CompleteValue = g.Sum(x => x.CompleteValue ?? 0), RealValue = g.Sum(x => x.RealValue ?? 0) }; if (q.Count() > 0) { foreach (var wbsSet in q) { AddWbsSetDetail(id, Convert.ToDateTime(wbsSet.Months), Convert.ToDecimal(wbsSet.PlanValue), Convert.ToDecimal(wbsSet.CompleteValue), Convert.ToDecimal(wbsSet.RealValue), 4); } } } } #endregion #region 判断装置下权重是否都已审核 /// /// 判断装置下权重是否都已审核 /// /// /// private bool IsWeightAudit(string ins) { int num = 0; bool isWeightAudit = true; var cn = from x in Funs.DB.WBS_CnProfession join y in Funs.DB.Wbs_UnitProject on x.CnProfessionId equals y.CnProfessionId where x.InstallationId == ins && y.IsApprove == true && (x.IsWeightsApprove == false || x.IsWeightsApprove == null) select x; num = cn.Count(); var unit = from x in Funs.DB.Wbs_UnitProject join y in Funs.DB.WBS_CnProfession on x.CnProfessionId equals y.CnProfessionId where y.InstallationId == ins && x.IsApprove == true && (x.IsWeightsApprove == false || x.IsWeightsApprove == null) select x; num = num + unit.Count(); var wbs = from x in Funs.DB.Wbs_WbsSet join y in Funs.DB.WBS_CnProfession on x.CnProfessionId equals y.CnProfessionId where y.InstallationId == ins && x.IsApprove == true && (x.IsWeightsApprove == false || x.IsWeightsApprove == null) select x; num = num + wbs.Count(); if (num > 0) { isWeightAudit = false; } return isWeightAudit; } #endregion #region 判断装置下权重是否有负数 /// /// 判断装置下权重是否有负数 /// /// /// private bool IsWeightMinus(string ins) { int num = 0; bool isWeightMinus = false; var cn = from x in Funs.DB.WBS_CnProfession where x.InstallationId == ins && (x.WeightsMoney <= 0 || x.Weights <= 0) select x; num = cn.Count(); var unit = from x in Funs.DB.Wbs_UnitProject join y in Funs.DB.WBS_CnProfession on x.CnProfessionId equals y.CnProfessionId where y.InstallationId == ins && x.IsApprove == true && (x.WeightsMoney <= 0 || x.Weights <= 0) select x; num = num + unit.Count(); var wbs = from x in Funs.DB.Wbs_WbsSet join y in Funs.DB.WBS_CnProfession on x.CnProfessionId equals y.CnProfessionId where y.InstallationId == ins && x.IsApprove == true && (x.WeightsMoney <= 0 || x.Weights <= 0) select x; num = num + wbs.Count(); if (num > 0) { isWeightMinus = true; } return isWeightMinus; } #endregion #region 自动审核设置装置末级分项计划值 /// /// 自动审核设置装置末级分项计划值(按开始结束日期生成末级明细,并根据父级节点增加未包含在子级但包含在父级的月份记录) /// /// /// protected void btnAuditPlan_Click(object sender, EventArgs e) { if (this.trWBS.SelectedNode != null) { if (this.trWBS.SelectedNode.CommandName == "installation") { if (!IsWeightAudit(this.trWBS.SelectedNodeID)) { Alert.ShowInTop("该装置下有未审核的权重设置!", MessageBoxIcon.Warning); return; } if (!IsWeightAudit(this.trWBS.SelectedNodeID)) { Alert.ShowInTop("该装置下有权重设置为0或负数!", MessageBoxIcon.Warning); return; } var cnProfessions = from x in Funs.DB.WBS_CnProfession where x.InstallationId == this.trWBS.SelectedNodeID orderby x.OldId select x; foreach (var cnProfession in cnProfessions) { var wbsSets = from x in Funs.DB.Wbs_WbsSet where x.IsApprove == true && x.CnProfessionId == cnProfession.CnProfessionId select x; foreach (var wbsSet in wbsSets) { DateTime startDate, endDate, startMonth, endMonth, parentStartDate, parentEndDate, parentStartMonth, parentEndMonth; List months = new List(); string column0 = string.Empty; decimal totalValue = 0, totalRate = 0; var childWbsSets = BLL.WbsSetService.GetApproveWbsSetsBySuperWbsSetId(wbsSet.WbsSetId); if (childWbsSets.Count() == 0) //当前为末级 { BLL.WbsSetService.UpdateWbsSetIsPlanApprove(wbsSet, true); startDate = Convert.ToDateTime(wbsSet.StartDate); endDate = Convert.ToDateTime(wbsSet.EndDate); startMonth = Convert.ToDateTime(startDate.Year + "-" + startDate.Month + "-01"); endMonth = Convert.ToDateTime(endDate.Year + "-" + endDate.Month + "-01"); do { months.Add(startMonth); startMonth = startMonth.AddMonths(1); } while (startMonth <= endMonth); //获取父级节点的月份集合 List parentMonths = new List(); //父级节点的月份集合 string parentId = wbsSet.SuperWbsSetId; Model.Wbs_WbsSet parentWbsSet = BLL.WbsSetService.GetWbsSetByWbsSetId(parentId); if (parentWbsSet != null) //父级为分部 { parentStartDate = Convert.ToDateTime(parentWbsSet.StartDate); parentEndDate = Convert.ToDateTime(parentWbsSet.EndDate); parentStartMonth = Convert.ToDateTime(parentStartDate.Year + "-" + parentStartDate.Month + "-01"); parentEndMonth = Convert.ToDateTime(parentEndDate.Year + "-" + parentEndDate.Month + "-01"); do { parentMonths.Add(parentStartMonth); parentStartMonth = parentStartMonth.AddMonths(1); } while (parentStartMonth <= parentEndMonth); } else //父级为质量行为 { Model.Wbs_UnitProject unitProject = BLL.UnitProjectService.GetUnitProjectByUnitProjectId(parentId); if (unitProject != null) { parentStartDate = Convert.ToDateTime(unitProject.StartDate); parentEndDate = Convert.ToDateTime(unitProject.EndDate); parentStartMonth = Convert.ToDateTime(parentStartDate.Year + "-" + parentStartDate.Month + "-01"); parentEndMonth = Convert.ToDateTime(parentEndDate.Year + "-" + parentEndDate.Month + "-01"); do { parentMonths.Add(parentStartMonth); parentStartMonth = parentStartMonth.AddMonths(1); } while (parentStartMonth <= parentEndMonth); } } for (int i = 0; i < months.Count; i++) { Model.WbsDetail detail = BLL.WbsDetailService.GetWbsDetailByWbsFlagYearMonth(wbsSet.WbsSetId, 4, months[i]); if (detail == null) { Model.WbsDetail item = new Model.WbsDetail(); item.WbsDetailId = SQLHelper.GetNewID(typeof(Model.WbsDetail)); item.ToWbs = wbsSet.WbsSetId; item.ToFlag = 4; //分部分项 item.Way = wbsSet.Way; item.Months = months[i]; if (wbsSet.WeightsMoney != null) { if (i == months.Count - 1) { decimal lastPlanValue = decimal.Round(Convert.ToDecimal(wbsSet.WeightsMoney - totalValue), 2); if (lastPlanValue >= 0) { item.PlanValue = lastPlanValue; } } else { item.PlanValue = WbsDetailService.GetMonthPlanValueByMonthCountAndMonthNumAndWeightMonth(months.Count, i + 1, Convert.ToDecimal(wbsSet.WeightsMoney)); } if (wbsSet.WeightsMoney != 0) { item.PlanValueRate = decimal.Round(Convert.ToDecimal(item.PlanValue / wbsSet.WeightsMoney * 100), 2); } else { item.PlanValueRate = 0; } totalValue += item.PlanValue != null ? item.PlanValue.Value : 0; totalRate += item.PlanValueRate != null ? item.PlanValueRate.Value : 0; BLL.WbsDetailService.AddWbsDetail(item); } } } for (int i = 0; i < parentMonths.Count; i++) { if (!months.Contains(parentMonths[i])) { Model.WbsDetail detail = (from x in Funs.DB.WbsDetail where x.ToWbs == wbsSet.WbsSetId && x.Months == parentMonths[i] select x).FirstOrDefault(); if (detail == null) { Model.WbsDetail item = new Model.WbsDetail(); item.WbsDetailId = SQLHelper.GetNewID(typeof(Model.WbsDetail)); item.ToWbs = wbsSet.WbsSetId; item.ToFlag = 4; //分部分项 item.Way = wbsSet.Way; item.Months = parentMonths[i]; item.PlanValue = 0; item.PlanValueRate = 0; BLL.WbsDetailService.AddWbsDetail(item); } } } } } } Alert.ShowInTop("自动分配计划值完成!", MessageBoxIcon.Warning); } else { Alert.ShowInTop("请选择一个装置!", MessageBoxIcon.Warning); return; } } else { Alert.ShowInTop("请选择装置!", MessageBoxIcon.Warning); return; } } #endregion #region 逐级向上合并计划明细 /// /// 逐级向上合并计划明细 /// /// private void MergeWbsSetDetail(string cnProfessionId) { Model.SGGLDB db = Funs.DB; // 分部分项 var wbsSetList4 = from x in db.WbsDetail join y in db.Wbs_WbsSet on x.ToWbs equals y.WbsSetId where y.CnProfessionId == cnProfessionId && y.IsApprove == true && y.SuperWbsSetId != null group new { x.PlanValue, x.CompleteValue, x.RealValue } by new { y.SuperWbsSetId, x.Months } into g select new { ToWbs = g.Key.SuperWbsSetId, Months = g.Key.Months, PlanValue = g.Sum(x => x.PlanValue ?? 0), CompleteValue = g.Sum(x => x.CompleteValue ?? 0), RealValue = g.Sum(x => x.RealValue ?? 0) }; if (wbsSetList4.Count() > 0) { foreach (var wbsSet in wbsSetList4) { AddWbsSetDetail(wbsSet.ToWbs, Convert.ToDateTime(wbsSet.Months), Convert.ToDecimal(wbsSet.PlanValue), Convert.ToDecimal(wbsSet.CompleteValue), Convert.ToDecimal(wbsSet.RealValue), 4); } } // 单位工程及子单位工程 var wbsSetList1 = from x in db.WbsDetail join y in db.Wbs_WbsSet on x.ToWbs equals y.WbsSetId join z in db.Wbs_UnitProject on y.UnitProjectId equals z.UnitProjectId where y.CnProfessionId == cnProfessionId && y.IsApprove == true && z.IsApprove == true && y.SuperWbsSetId == null group new { x.PlanValue, x.CompleteValue, x.RealValue } by new { z.UnitProjectId, x.Months } into g select new { ToWbs = g.Key.UnitProjectId, Months = g.Key.Months, PlanValue = g.Sum(x => x.PlanValue ?? 0), CompleteValue = g.Sum(x => x.CompleteValue ?? 0), RealValue = g.Sum(x => x.RealValue ?? 0) }; if (wbsSetList1.Count() > 0) { foreach (var wbsSet in wbsSetList1) { AddWbsSetDetail(wbsSet.ToWbs, Convert.ToDateTime(wbsSet.Months), Convert.ToDecimal(wbsSet.PlanValue), Convert.ToDecimal(wbsSet.CompleteValue), Convert.ToDecimal(wbsSet.RealValue), 3); } } var wbsSetList0 = from x in db.WbsDetail join y in db.Wbs_UnitProject on x.ToWbs equals y.UnitProjectId where y.CnProfessionId == cnProfessionId && y.IsApprove == true && y.SuperUnitProjectId != null group new { x.PlanValue, x.CompleteValue, x.RealValue } by new { y.SuperUnitProjectId, x.Months } into g select new { ToWbs = g.Key.SuperUnitProjectId, Months = g.Key.Months, PlanValue = g.Sum(x => x.PlanValue ?? 0), CompleteValue = g.Sum(x => x.CompleteValue ?? 0), RealValue = g.Sum(x => x.RealValue ?? 0) }; if (wbsSetList0.Count() > 0) { foreach (var wbsSet in wbsSetList0) { AddWbsSetDetail(wbsSet.ToWbs, Convert.ToDateTime(wbsSet.Months), Convert.ToDecimal(wbsSet.PlanValue), Convert.ToDecimal(wbsSet.CompleteValue), Convert.ToDecimal(wbsSet.RealValue), 3); } } // 专业 var wbsSetList5 = from x in db.WbsDetail join y in db.Wbs_UnitProject on x.ToWbs equals y.UnitProjectId join z in db.WBS_CnProfession on y.CnProfessionId equals z.CnProfessionId where y.CnProfessionId == cnProfessionId && y.IsApprove == true && y.SuperUnitProjectId == null group new { x.PlanValue, x.CompleteValue, x.RealValue } by new { z.CnProfessionId, x.Months } into g select new { ToWbs = g.Key.CnProfessionId, Months = g.Key.Months, PlanValue = g.Sum(x => x.PlanValue ?? 0), CompleteValue = g.Sum(x => x.CompleteValue ?? 0), RealValue = g.Sum(x => x.RealValue ?? 0) }; if (wbsSetList5.Count() > 0) { foreach (var wbsSet in wbsSetList5) { AddWbsSetDetail(wbsSet.ToWbs, Convert.ToDateTime(wbsSet.Months), Convert.ToDecimal(wbsSet.PlanValue), Convert.ToDecimal(wbsSet.CompleteValue), Convert.ToDecimal(wbsSet.RealValue), 2); } } } /// /// 逐级向上合并计划明细 /// /// private void MergeWbsSetDetail2(string unitProjectId) { Model.SGGLDB db = Funs.DB; // 分部分项 var wbsSetList4 = from x in db.WbsDetail join y in db.Wbs_WbsSet on x.ToWbs equals y.WbsSetId where y.UnitProjectId == unitProjectId && y.IsApprove == true && y.SuperWbsSetId != null group new { x.PlanValue, x.CompleteValue, x.RealValue } by new { y.SuperWbsSetId, x.Months } into g select new { ToWbs = g.Key.SuperWbsSetId, Months = g.Key.Months, PlanValue = g.Sum(x => x.PlanValue ?? 0), CompleteValue = g.Sum(x => x.CompleteValue ?? 0), RealValue = g.Sum(x => x.RealValue ?? 0) }; if (wbsSetList4.Count() > 0) { foreach (var wbsSet in wbsSetList4) { AddWbsSetDetail(wbsSet.ToWbs, Convert.ToDateTime(wbsSet.Months), Convert.ToDecimal(wbsSet.PlanValue), Convert.ToDecimal(wbsSet.CompleteValue), Convert.ToDecimal(wbsSet.RealValue), 4); } } // 单位工程及子单位工程 var wbsSetList1 = from x in db.WbsDetail join y in db.Wbs_WbsSet on x.ToWbs equals y.WbsSetId join z in db.Wbs_UnitProject on y.UnitProjectId equals z.UnitProjectId where y.UnitProjectId == unitProjectId && y.IsApprove == true && z.IsApprove == true && y.SuperWbsSetId == null group new { x.PlanValue, x.CompleteValue, x.RealValue } by new { z.UnitProjectId, x.Months } into g select new { ToWbs = g.Key.UnitProjectId, Months = g.Key.Months, PlanValue = g.Sum(x => x.PlanValue ?? 0), CompleteValue = g.Sum(x => x.CompleteValue ?? 0), RealValue = g.Sum(x => x.RealValue ?? 0) }; if (wbsSetList1.Count() > 0) { foreach (var wbsSet in wbsSetList1) { AddWbsSetDetail(wbsSet.ToWbs, Convert.ToDateTime(wbsSet.Months), Convert.ToDecimal(wbsSet.PlanValue), Convert.ToDecimal(wbsSet.CompleteValue), Convert.ToDecimal(wbsSet.RealValue), 3); } } var wbsSetList0 = from x in db.WbsDetail join y in db.Wbs_UnitProject on x.ToWbs equals y.UnitProjectId where y.UnitProjectId == unitProjectId && y.IsApprove == true && y.SuperUnitProjectId != null group new { x.PlanValue, x.CompleteValue, x.RealValue } by new { y.SuperUnitProjectId, x.Months } into g select new { ToWbs = g.Key.SuperUnitProjectId, Months = g.Key.Months, PlanValue = g.Sum(x => x.PlanValue ?? 0), CompleteValue = g.Sum(x => x.CompleteValue ?? 0), RealValue = g.Sum(x => x.RealValue ?? 0) }; if (wbsSetList0.Count() > 0) { foreach (var wbsSet in wbsSetList0) { AddWbsSetDetail(wbsSet.ToWbs, Convert.ToDateTime(wbsSet.Months), Convert.ToDecimal(wbsSet.PlanValue), Convert.ToDecimal(wbsSet.CompleteValue), Convert.ToDecimal(wbsSet.RealValue), 3); } } } private void AddWbsSetDetail(string toWbs, DateTime months, decimal planValue, decimal completeValue, decimal realValue, int toFlag) { Model.SGGLDB db = Funs.DB; decimal? weight = null; if (toFlag == 4) { weight = BLL.WbsSetService.GetWbsSetByWbsSetId(toWbs).WeightsMoney; } if (toFlag == 3) { weight = BLL.UnitProjectService.GetUnitProjectByUnitProjectId(toWbs).WeightsMoney; } if (toFlag == 2) { weight = BLL.CnProfessionService.GetCnProfessionByCnProfessionId(toWbs).WeightsMoney; } if (toFlag == 1) { weight = BLL.Project_InstallationService.GetInstallationByInstallationId(toWbs).WeightsMoney; } if (BLL.WbsDetailService.IsExitWbsDetailByToWbsOrMonth(toWbs, toFlag, months)) { Model.WbsDetail updateDetail = (from x in db.WbsDetail where x.ToWbs == toWbs && x.Months == months && x.ToFlag == toFlag select x).FirstOrDefault(); updateDetail.PlanValue = planValue; updateDetail.CompleteValue = completeValue; updateDetail.RealValue = realValue; if (weight != null && weight != 0) { updateDetail.PlanValueRate = decimal.Round(Convert.ToDecimal(planValue) / Convert.ToDecimal(weight) * 100, 2); updateDetail.CompleteValueRate = decimal.Round(Convert.ToDecimal(completeValue) / Convert.ToDecimal(weight) * 100, 2); updateDetail.RealValueRate = decimal.Round(Convert.ToDecimal(realValue) / Convert.ToDecimal(weight) * 100, 2); } db.SubmitChanges(); } else { Model.WbsDetail newDetail = new Model.WbsDetail(); newDetail.WbsDetailId = SQLHelper.GetNewID(typeof(Model.WbsDetail)); newDetail.ToWbs = toWbs; newDetail.ToFlag = toFlag; newDetail.Way = "A"; newDetail.Months = months; newDetail.PlanValue = planValue; if (weight != null && weight != 0) { newDetail.PlanValueRate = decimal.Round(Convert.ToDecimal(planValue) / Convert.ToDecimal(weight) * 100, 2); } newDetail.CompleteValue = 0; newDetail.RealValue = 0; db.WbsDetail.InsertOnSubmit(newDetail); db.SubmitChanges(); } } #endregion #region 一键保存 /// /// 一键保存 /// /// /// protected void btnSaveInstrallion_Click(object sender, EventArgs e) { if (this.trWBS.SelectedNode != null) { if (this.trWBS.SelectedNode.CommandName == "installation") { string installationId = this.trWBS.SelectedNodeID; Model.Project_Installation installation = BLL.Project_InstallationService.GetInstallationByInstallationId(installationId); if (installation.SuperInstallationId == "0") { //工序 var installation1s = (from x in Funs.DB.Project_Installation where x.ProjectId == this.CurrUser.LoginProjectId && x.SuperInstallationId == installationId select x).ToList(); if (installation1s.Count > 0) //非总图装置 { foreach (var installation1 in installation1s) { //主项 var installation2s = (from x in Funs.DB.Project_Installation where x.ProjectId == this.CurrUser.LoginProjectId && x.SuperInstallationId == installation1.InstallationId select x).ToList(); foreach (var installation2 in installation2s) { //专业 var profession = BLL.CnProfessionService.GetCnProfessionByInstallation(installation2.InstallationId); foreach (var pro in profession) { MergeWbsSetDetail(pro.CnProfessionId); } var insList2 = from x in Funs.DB.WbsDetail join y in Funs.DB.WBS_CnProfession on x.ToWbs equals y.CnProfessionId where y.InstallationId == installation2.InstallationId group new { x.PlanValue, x.CompleteValue, x.RealValue } by new { y.InstallationId, x.Months } into g select new { ToWbs = g.Key.InstallationId, Months = g.Key.Months, PlanValue = g.Sum(x => x.PlanValue ?? 0), CompleteValue = g.Sum(x => x.CompleteValue ?? 0), RealValue = g.Sum(x => x.RealValue ?? 0) }; if (insList2.Count() > 0) { foreach (var ins in insList2) { AddWbsSetDetail(ins.ToWbs, Convert.ToDateTime(ins.Months), Convert.ToDecimal(ins.PlanValue), Convert.ToDecimal(ins.CompleteValue), Convert.ToDecimal(ins.RealValue), 1); } } } var insList1 = from x in Funs.DB.WbsDetail join y in Funs.DB.Project_Installation on x.ToWbs equals y.InstallationId where y.SuperInstallationId == installation1.InstallationId group new { x.PlanValue, x.CompleteValue, x.RealValue } by new { y.SuperInstallationId, x.Months } into g select new { ToWbs = g.Key.SuperInstallationId, Months = g.Key.Months, PlanValue = g.Sum(x => x.PlanValue ?? 0), CompleteValue = g.Sum(x => x.CompleteValue ?? 0), RealValue = g.Sum(x => x.RealValue ?? 0) }; if (insList1.Count() > 0) { foreach (var ins in insList1) { AddWbsSetDetail(ins.ToWbs, Convert.ToDateTime(ins.Months), Convert.ToDecimal(ins.PlanValue), Convert.ToDecimal(ins.CompleteValue), Convert.ToDecimal(ins.RealValue), 1); } } } var insList = from x in Funs.DB.WbsDetail join y in Funs.DB.Project_Installation on x.ToWbs equals y.InstallationId where y.SuperInstallationId == installation.InstallationId group new { x.PlanValue, x.CompleteValue, x.RealValue } by new { y.SuperInstallationId, x.Months } into g select new { ToWbs = g.Key.SuperInstallationId, Months = g.Key.Months, PlanValue = g.Sum(x => x.PlanValue ?? 0), CompleteValue = g.Sum(x => x.CompleteValue ?? 0), RealValue = g.Sum(x => x.RealValue ?? 0) }; if (insList.Count() > 0) { foreach (var ins in insList) { AddWbsSetDetail(ins.ToWbs, Convert.ToDateTime(ins.Months), Convert.ToDecimal(ins.PlanValue), Convert.ToDecimal(ins.CompleteValue), Convert.ToDecimal(ins.RealValue), 1); } } } else { //专业 var profession = BLL.CnProfessionService.GetCnProfessionByInstallation(installation.InstallationId); foreach (var pro in profession) { MergeWbsSetDetail(pro.CnProfessionId); } //单位工程 var unitProjects = BLL.UnitProjectService.GetUnitProjectsByInstallationId(installationId); foreach (var unitProject in unitProjects) { MergeWbsSetDetail2(unitProject.UnitProjectId); } var insList = from x in Funs.DB.WbsDetail join y in Funs.DB.Wbs_UnitProject on x.ToWbs equals y.UnitProjectId where y.InstallationId == installationId group new { x.PlanValue, x.CompleteValue, x.RealValue } by new { y.InstallationId, x.Months } into g select new { ToWbs = g.Key.InstallationId, Months = g.Key.Months, PlanValue = g.Sum(x => x.PlanValue ?? 0), CompleteValue = g.Sum(x => x.CompleteValue ?? 0), RealValue = g.Sum(x => x.RealValue ?? 0) }; if (insList.Count() > 0) { foreach (var ins in insList) { AddWbsSetDetail(ins.ToWbs, Convert.ToDateTime(ins.Months), Convert.ToDecimal(ins.PlanValue), Convert.ToDecimal(ins.CompleteValue), Convert.ToDecimal(ins.RealValue), 1); } } } Alert.ShowInTop("一键保存成功!", MessageBoxIcon.Success); } else { Alert.ShowInTop("请选择一个装置!", MessageBoxIcon.Warning); return; } } else { Alert.ShowInTop("请选择一个装置!", MessageBoxIcon.Warning); return; } } else { Alert.ShowInTop("请选择装置!", MessageBoxIcon.Warning); return; } } #endregion } }