using BLL; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Linq; namespace FineUIPro.Web.JDGL.WBSCompleteAndReal { public partial class WBSCompleteAudit : 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) { this.txtMonths.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now); GetNoApproveIds(); InitTreeMenu(); } else { if (GetRequestEventArgument() == "UPDATE_SUMMARY") { // 页面要求重新计算合计行的值 OutputSummaryData(); } } } private void GetNoApproveIds() { List parentUnitWorkIds = new List(); List wbsSetIds = new List(); noApproveInstallationIds.Clear(); noApproveCnProfessionIds.Clear(); noApproveUnitProjectIds.Clear(); noApproveWbsSetIds.Clear(); } #endregion #region 计算合计 不用了 /// /// 计算合计 /// private void OutputSummaryData() { if (this.Grid1.Rows.Count > 0) { decimal totalCompleteValueSum = 0, totalRateSum = 0, totalRateSumAll = 0, totalRealValueSum = 0, totalCompleteValueSumAll = 0, weightsMoneySum = Funs.GetNewDecimalOrZero(this.Grid1.Rows[0].Values[29].ToString()); for (int i = 0; i < this.Grid1.Rows.Count; i++) { if (i > 0) { decimal weightsMoney = Funs.GetNewDecimalOrZero(this.Grid1.Rows[i].Values[29].ToString()); //总计划费用 decimal totalComplete = Funs.GetNewDecimalOrZero(this.Grid1.Rows[i].Values[30].ToString()); //累计完成值 decimal lastMoney = weightsMoney - totalComplete; //剩余未完成值 if (Funs.GetNewDecimalOrZero(this.Grid1.Rows[i].Values[14].ToString()) > lastMoney && lastMoney > 0) { this.Grid1.Rows[i].Values[14] = lastMoney; this.Grid1.Rows[i].Values[15] = decimal.Round(lastMoney / weightsMoney * 100, 2); } totalCompleteValueSum += Funs.GetNewDecimalOrZero(this.Grid1.Rows[i].Values[14].ToString()); if (string.IsNullOrEmpty(this.Grid1.Rows[i].Values[19].ToString())) { totalRealValueSum += Funs.GetNewDecimalOrZero(this.Grid1.Rows[i].Values[14].ToString()); } else { totalRealValueSum += Funs.GetNewDecimalOrZero(this.Grid1.Rows[i].Values[19].ToString()); } } string id = this.Grid1.Rows[i].Values[32].ToString(); if (id.Length > 10) { decimal totalCompleteValue = 0, totalRate = 0, totalRealValue = 0; if (!string.IsNullOrEmpty(this.Grid1.Rows[i].Values[14].ToString()) && !string.IsNullOrEmpty(this.Grid1.Rows[i].Values[29].ToString())) { decimal completeValue = Funs.GetNewDecimalOrZero(this.Grid1.Rows[i].Values[14].ToString()); decimal weightsMoney = Funs.GetNewDecimalOrZero(this.Grid1.Rows[i].Values[29].ToString()); if (!string.IsNullOrEmpty(this.Grid1.Rows[i].Values[16].ToString())) { totalCompleteValue = Funs.GetNewDecimalOrZero(this.Grid1.Rows[i].Values[30].ToString()) + completeValue; totalRate = decimal.Round(totalCompleteValue / weightsMoney * 100, 2); this.Grid1.Rows[i].Values[16] = totalCompleteValue; this.Grid1.Rows[i].Values[17] = totalRate; this.Grid1.Rows[i].Values[22] = totalCompleteValue - Funs.GetNewDecimalOrZero(this.Grid1.Rows[i].Values[11].ToString()); if (weightsMoney == totalCompleteValue) { this.Grid1.Rows[i].Values[17] = 100; } } if (string.IsNullOrEmpty(this.Grid1.Rows[i].Values[19].ToString())) //实耗值没有时,默认完成值为实耗值 { this.Grid1.Rows[i].Values[19] = completeValue; totalRealValue = Funs.GetNewDecimalOrZero(this.Grid1.Rows[i].Values[31].ToString()) + completeValue; this.Grid1.Rows[i].Values[20] = totalRealValue; this.Grid1.Rows[i].Values[23] = totalCompleteValue - totalRealValue; } } if (!string.IsNullOrEmpty(this.Grid1.Rows[i].Values[19].ToString())) { decimal realValue = Funs.GetNewDecimalOrZero(this.Grid1.Rows[i].Values[19].ToString()); this.Grid1.Rows[i].Values[19] = realValue; totalRealValue = Funs.GetNewDecimalOrZero(this.Grid1.Rows[i].Values[31].ToString()) + realValue; if (!string.IsNullOrEmpty(this.Grid1.Rows[i].Values[16].ToString())) { totalCompleteValue = Funs.GetNewDecimalOrZero(this.Grid1.Rows[i].Values[16].ToString()); } this.Grid1.Rows[i].Values[20] = totalRealValue; this.Grid1.Rows[i].Values[23] = totalCompleteValue - totalRealValue; } } } totalRateSum = decimal.Round(totalCompleteValueSum / weightsMoneySum * 100, 2); this.Grid1.Rows[0].Values[14] = totalCompleteValueSum; this.Grid1.Rows[0].Values[15] = totalRateSum; totalCompleteValueSumAll = Funs.GetNewDecimalOrZero(this.Grid1.Rows[0].Values[30].ToString()) + totalCompleteValueSum; totalRateSumAll = decimal.Round(totalCompleteValueSumAll / weightsMoneySum * 100, 2); this.Grid1.Rows[0].Values[16] = totalCompleteValueSumAll; this.Grid1.Rows[0].Values[17] = totalRateSumAll; this.Grid1.Rows[0].Values[19] = totalRealValueSum; this.Grid1.Rows[0].Values[20] = Funs.GetNewDecimalOrZero(this.Grid1.Rows[0].Values[31].ToString()) + totalRealValueSum; this.Grid1.Rows[0].Values[22] = totalCompleteValueSumAll - Funs.GetNewDecimalOrZero(this.Grid1.Rows[0].Values[11].ToString()); this.Grid1.Rows[0].Values[23] = totalCompleteValueSumAll - (Funs.GetNewDecimalOrZero(this.Grid1.Rows[0].Values[31].ToString()) + totalRealValueSum); } } #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); e.Node.Expanded = true; } } } 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) { BindGrid(); } #endregion #region 保存方法 /// /// 保存方法 /// /// /// private void SaveData(string message) { if (this.Grid1.Rows.Count == 0) { Alert.ShowInTop("请先选择一条记录!", MessageBoxIcon.Warning); return; } JArray mergedData = Grid1.GetMergedData(); int i = 0; foreach (JObject mergedRow in mergedData) { if (i > 0) { JObject values = mergedRow.Value("values"); string type = this.trWBS.SelectedNode.CommandName; if (type == "wbsSet") { var oldDetail = BLL.WbsDetailService.GetWbsDetailByWbsDetailId(this.Grid1.Rows[i].Values[27].ToString()); decimal oldEngineeringQuantity = oldDetail.EngineeringQuantity ?? 0; decimal oldCompleteValue = oldDetail.CompleteValue ?? 0; decimal oldRealValue = oldDetail.RealValue ?? 0; Model.WbsDetail detail = BLL.WbsDetailService.GetWbsDetailByWbsDetailId(this.Grid1.Rows[i].Values[27].ToString()); Model.Wbs_WbsSet wbsSet = BLL.WbsSetService.GetWbsSetByWbsSetId(detail.ToWbs); if (message == "submit") { if (detail.IsCompleteApprove == null) { detail.IsCompleteApprove = true; } } if (!string.IsNullOrEmpty(values.Value("EngineerQuantity"))) { detail.EngineeringQuantity = Convert.ToDecimal(values.Value("EngineerQuantity")); } else { detail.EngineeringQuantity = 0; } if (!string.IsNullOrEmpty(values.Value("CompleteValue"))) { detail.CompleteValue = Convert.ToDecimal(values.Value("CompleteValue")); detail.CompleteValueRate = decimal.Round(Convert.ToDecimal(detail.CompleteValue) / Convert.ToDecimal(wbsSet.WeightsMoney) * 100, 2); } else { detail.CompleteValue = 0; detail.CompleteValueRate = 0; } if (!string.IsNullOrEmpty(values.Value("RealValue"))) { detail.RealValue = Convert.ToDecimal(values.Value("RealValue")); detail.RealValueRate = decimal.Round(Convert.ToDecimal(detail.RealValue) / Convert.ToDecimal(wbsSet.WeightsMoney) * 100, 2); } else { detail.RealValue = 0; detail.RealValueRate = 0; } BLL.WbsDetailService.UpdateWbsDetail(detail); //循环保存所有上级分部分项对应记录 UpdateWbsParentDetail(Convert.ToDateTime(detail.Months), detail.CompleteValue, oldCompleteValue, detail.RealValue, oldRealValue, wbsSet.SuperWbsSetId, detail.EngineeringQuantity, oldEngineeringQuantity); Model.Wbs_UnitProject unitProject = BLL.UnitProjectService.GetUnitProjectByUnitProjectId(wbsSet.UnitProjectId); Model.WbsDetail detailUnitProject = BLL.WbsDetailService.GetWbsDetailByWbsFlagYearMonth(wbsSet.UnitProjectId, 3, Convert.ToDateTime(detail.Months)); if (unitProject != null) { if (detailUnitProject != null) { if (detailUnitProject.CompleteValue != null) { detailUnitProject.CompleteValue += ((detail.CompleteValue ?? 0) - oldCompleteValue); } else { detailUnitProject.CompleteValue = detail.CompleteValue ?? 0; } detailUnitProject.CompleteValueRate = decimal.Round(Convert.ToDecimal(detailUnitProject.CompleteValue) / Convert.ToDecimal(unitProject.WeightsMoney) * 100, 2); if (detailUnitProject.RealValue != null) { detailUnitProject.RealValue += ((detail.RealValue ?? 0) - oldRealValue); } else { detailUnitProject.RealValue = detail.RealValue ?? 0; } detailUnitProject.IsCompleteApprove = true; detailUnitProject.RealValueRate = decimal.Round(Convert.ToDecimal(detailUnitProject.RealValue) / Convert.ToDecimal(unitProject.WeightsMoney) * 100, 2); BLL.WbsDetailService.UpdateWbsDetail(detailUnitProject); } if (unitProject.SuperUnitProjectId != null) //存在单位工程 { Model.Wbs_UnitProject parentUnitProject = BLL.UnitProjectService.GetUnitProjectByUnitProjectId(unitProject.SuperUnitProjectId); Model.WbsDetail detailParentUnitProject = BLL.WbsDetailService.GetWbsDetailByWbsFlagYearMonth(parentUnitProject.UnitProjectId, 3, Convert.ToDateTime(detail.Months)); if (detailParentUnitProject != null) { if (detailParentUnitProject.CompleteValue != null) { detailParentUnitProject.CompleteValue += ((detail.CompleteValue ?? 0) - oldCompleteValue); } else { detailParentUnitProject.CompleteValue = detail.CompleteValue ?? 0; } detailParentUnitProject.CompleteValueRate = decimal.Round(Convert.ToDecimal(detailParentUnitProject.CompleteValue) / Convert.ToDecimal(parentUnitProject.WeightsMoney) * 100, 2); if (detailParentUnitProject.RealValue != null) { detailParentUnitProject.RealValue += ((detail.RealValue ?? 0) - oldRealValue); } else { detailParentUnitProject.RealValue = detail.RealValue ?? 0; } detailParentUnitProject.IsCompleteApprove = true; detailParentUnitProject.RealValueRate = decimal.Round(Convert.ToDecimal(detailParentUnitProject.RealValue) / Convert.ToDecimal(parentUnitProject.WeightsMoney) * 100, 2); BLL.WbsDetailService.UpdateWbsDetail(detailParentUnitProject); } } } //保存对应专业 Model.WBS_CnProfession cnProfession = BLL.CnProfessionService.GetCnProfessionByCnProfessionId(wbsSet.CnProfessionId); if (cnProfession != null) { Model.WbsDetail detailCnProfession = BLL.WbsDetailService.GetWbsDetailByWbsFlagYearMonth(cnProfession.CnProfessionId, 2, Convert.ToDateTime(detail.Months)); if (detailCnProfession != null) { if (detailCnProfession.CompleteValue != null) { detailCnProfession.CompleteValue += ((detail.CompleteValue ?? 0) - oldCompleteValue); } else { detailCnProfession.CompleteValue = detail.CompleteValue ?? 0; } detailCnProfession.CompleteValueRate = decimal.Round(Convert.ToDecimal(detailCnProfession.CompleteValue) / Convert.ToDecimal(cnProfession.WeightsMoney) * 100, 2); if (detailCnProfession.RealValue != null) { detailCnProfession.RealValue += ((detail.RealValue ?? 0) - oldRealValue); } else { detailCnProfession.RealValue = detail.RealValue ?? 0; } detailCnProfession.IsCompleteApprove = true; detailCnProfession.RealValueRate = decimal.Round(Convert.ToDecimal(detailCnProfession.RealValue) / Convert.ToDecimal(cnProfession.WeightsMoney) * 100, 2); BLL.WbsDetailService.UpdateWbsDetail(detailCnProfession); } //保存对应装置 Model.Project_Installation installation = BLL.Project_InstallationService.GetInstallationByInstallationId(cnProfession.InstallationId); if (installation != null) { Model.WbsDetail detailInstallation = BLL.WbsDetailService.GetWbsDetailByWbsFlagYearMonth(installation.InstallationId, 1, Convert.ToDateTime(detail.Months)); if (detailInstallation != null) { if (detailInstallation.CompleteValue != null) { detailInstallation.CompleteValue += ((detail.CompleteValue ?? 0) - oldCompleteValue); } else { detailInstallation.CompleteValue = detail.CompleteValue ?? 0; } detailInstallation.CompleteValueRate = decimal.Round(Convert.ToDecimal(detailInstallation.CompleteValue) / Convert.ToDecimal(installation.WeightsMoney) * 100, 2); if (detailInstallation.RealValue != null) { detailInstallation.RealValue += ((detail.RealValue ?? 0) - oldRealValue); } else { detailInstallation.RealValue = detail.RealValue ?? 0; } detailInstallation.IsCompleteApprove = true; detailInstallation.RealValueRate = decimal.Round(Convert.ToDecimal(detailInstallation.RealValue) / Convert.ToDecimal(installation.WeightsMoney) * 100, 2); BLL.WbsDetailService.UpdateWbsDetail(detailInstallation); if (installation.SuperInstallationId != "0") //一般装置 { //主项 Model.Project_Installation pInstallation = BLL.Project_InstallationService.GetInstallationByInstallationId(installation.SuperInstallationId); Model.WbsDetail pDetailInstallation = BLL.WbsDetailService.GetWbsDetailByWbsFlagYearMonth(installation.SuperInstallationId, 1, Convert.ToDateTime(detail.Months)); if (pDetailInstallation.CompleteValue != null) { pDetailInstallation.CompleteValue += ((detail.CompleteValue ?? 0) - oldCompleteValue); } else { pDetailInstallation.CompleteValue = detail.CompleteValue ?? 0; } pDetailInstallation.CompleteValueRate = decimal.Round(Convert.ToDecimal(pDetailInstallation.CompleteValue) / Convert.ToDecimal(installation.WeightsMoney) * 100, 2); if (pDetailInstallation.RealValue != null) { pDetailInstallation.RealValue += ((detail.RealValue ?? 0) - oldRealValue); } else { pDetailInstallation.RealValue = detail.RealValue ?? 0; } pDetailInstallation.IsCompleteApprove = true; pDetailInstallation.RealValueRate = decimal.Round(Convert.ToDecimal(pDetailInstallation.RealValue) / Convert.ToDecimal(installation.WeightsMoney) * 100, 2); BLL.WbsDetailService.UpdateWbsDetail(pDetailInstallation); //装置 Model.WbsDetail ppDetailInstallation = BLL.WbsDetailService.GetWbsDetailByWbsFlagYearMonth(pInstallation.SuperInstallationId, 1, Convert.ToDateTime(detail.Months)); if (ppDetailInstallation.CompleteValue != null) { ppDetailInstallation.CompleteValue += ((detail.CompleteValue ?? 0) - oldCompleteValue); } else { ppDetailInstallation.CompleteValue = detail.CompleteValue ?? 0; } ppDetailInstallation.CompleteValueRate = decimal.Round(Convert.ToDecimal(ppDetailInstallation.CompleteValue) / Convert.ToDecimal(installation.WeightsMoney) * 100, 2); if (ppDetailInstallation.RealValue != null) { ppDetailInstallation.RealValue += ((detail.RealValue ?? 0) - oldRealValue); } else { ppDetailInstallation.RealValue = detail.RealValue ?? 0; } ppDetailInstallation.IsCompleteApprove = true; ppDetailInstallation.RealValueRate = decimal.Round(Convert.ToDecimal(ppDetailInstallation.RealValue) / Convert.ToDecimal(installation.WeightsMoney) * 100, 2); BLL.WbsDetailService.UpdateWbsDetail(ppDetailInstallation); } } } } else //总图 { Model.Project_Installation installation = BLL.Project_InstallationService.GetInstallationByInstallationId(wbsSet.InstallationId); if (installation != null) { Model.WbsDetail detailInstallation = BLL.WbsDetailService.GetWbsDetailByWbsFlagYearMonth(installation.InstallationId, 1, Convert.ToDateTime(detail.Months)); if (detailInstallation != null) { if (detailInstallation.CompleteValue != null) { detailInstallation.CompleteValue += ((detail.CompleteValue ?? 0) - oldCompleteValue); } else { detailInstallation.CompleteValue = detail.CompleteValue ?? 0; } detailInstallation.CompleteValueRate = decimal.Round(Convert.ToDecimal(detailInstallation.CompleteValue) / Convert.ToDecimal(installation.WeightsMoney) * 100, 2); if (detailInstallation.RealValue != null) { detailInstallation.RealValue += ((detail.RealValue ?? 0) - oldRealValue); } else { detailInstallation.RealValue = detail.RealValue ?? 0; } detailInstallation.IsCompleteApprove = true; detailInstallation.RealValueRate = decimal.Round(Convert.ToDecimal(detailInstallation.RealValue) / Convert.ToDecimal(installation.WeightsMoney) * 100, 2); BLL.WbsDetailService.UpdateWbsDetail(detailInstallation); } } } } else if (type == "childUnitProject") { var oldDetail = BLL.WbsDetailService.GetWbsDetailByWbsDetailId(this.Grid1.Rows[i].Values[27].ToString()); decimal oldEngineeringQuantity = oldDetail.EngineeringQuantity ?? 0; decimal oldCompleteValue = oldDetail.CompleteValue ?? 0; decimal oldRealValue = oldDetail.RealValue ?? 0; var childWbsSets = BLL.WbsSetService.GetApproveWbsSetsBySuperWbsSetId(this.trWBS.SelectedNodeID); if (childWbsSets.Count == 0) //当前为末级 { Model.WbsDetail detail = BLL.WbsDetailService.GetWbsDetailByWbsDetailId(this.Grid1.Rows[i].Values[27].ToString()); Model.Wbs_WbsSet wbsSet = BLL.WbsSetService.GetWbsSetByWbsSetId(detail.ToWbs); if (message == "submit") { if (detail.IsCompleteApprove == null) { detail.IsCompleteApprove = true; } else { Alert.ShowInTop(wbsSet.WbsSetName + "的当月完成值已审批完成!", MessageBoxIcon.Warning); return; } } if (!string.IsNullOrEmpty(values.Value("EngineerQuantity"))) { detail.EngineeringQuantity = Convert.ToDecimal(values.Value("EngineerQuantity")); } else { detail.EngineeringQuantity = 0; } if (!string.IsNullOrEmpty(values.Value("CompleteValue"))) { detail.CompleteValue = Convert.ToDecimal(values.Value("CompleteValue")); detail.CompleteValueRate = decimal.Round(Convert.ToDecimal(detail.CompleteValue) / Convert.ToDecimal(wbsSet.WeightsMoney) * 100, 2); } else { detail.CompleteValue = 0; detail.CompleteValueRate = 0; } if (!string.IsNullOrEmpty(values.Value("RealValue"))) { detail.RealValue = Convert.ToDecimal(values.Value("RealValue")); detail.RealValueRate = decimal.Round(Convert.ToDecimal(detail.RealValue) / Convert.ToDecimal(wbsSet.WeightsMoney) * 100, 2); } else { detail.RealValue = 0; detail.RealValueRate = 0; } BLL.WbsDetailService.UpdateWbsDetail(detail); //循环保存所有上级分部分项对应记录 UpdateWbsParentDetail(Convert.ToDateTime(detail.Months), detail.CompleteValue, oldCompleteValue, detail.RealValue, oldRealValue, this.trWBS.SelectedNode.ParentNode.NodeID, detail.EngineeringQuantity, oldEngineeringQuantity); Model.Wbs_UnitProject unitProject = BLL.UnitProjectService.GetUnitProjectByUnitProjectId(wbsSet.UnitProjectId); Model.WbsDetail detailUnitProject = BLL.WbsDetailService.GetWbsDetailByWbsFlagYearMonth(wbsSet.UnitProjectId, 3, Convert.ToDateTime(detail.Months)); if (unitProject != null) { if (detailUnitProject != null) { if (detailUnitProject.CompleteValue != null) { detailUnitProject.CompleteValue += ((detail.CompleteValue ?? 0) - oldCompleteValue); } else { detailUnitProject.CompleteValue = detail.CompleteValue ?? 0; } detailUnitProject.CompleteValueRate = decimal.Round(Convert.ToDecimal(detailUnitProject.CompleteValue) / Convert.ToDecimal(unitProject.WeightsMoney) * 100, 2); if (detailUnitProject.RealValue != null) { detailUnitProject.RealValue += ((detail.RealValue ?? 0) - oldRealValue); } else { detailUnitProject.RealValue = detail.RealValue ?? 0; } if (unitProject.EngineerQuantity != null && unitProject.EngineerQuantity > 0) { if (detailUnitProject.EngineeringQuantity != null) { detailUnitProject.EngineeringQuantity += detail.EngineeringQuantity - oldEngineeringQuantity; } else { detailUnitProject.EngineeringQuantity = detail.EngineeringQuantity ?? 0; } } detailUnitProject.IsCompleteApprove = true; detailUnitProject.RealValueRate = decimal.Round(Convert.ToDecimal(detailUnitProject.RealValue) / Convert.ToDecimal(unitProject.WeightsMoney) * 100, 2); BLL.WbsDetailService.UpdateWbsDetail(detailUnitProject); } if (unitProject.SuperUnitProjectId != null) //存在单位工程 { Model.Wbs_UnitProject parentUnitProject = BLL.UnitProjectService.GetUnitProjectByUnitProjectId(unitProject.SuperUnitProjectId); Model.WbsDetail detailParentUnitProject = BLL.WbsDetailService.GetWbsDetailByWbsFlagYearMonth(parentUnitProject.UnitProjectId, 3, Convert.ToDateTime(detail.Months)); if (detailParentUnitProject != null) { if (detailParentUnitProject.CompleteValue != null) { detailParentUnitProject.CompleteValue += ((detail.CompleteValue ?? 0) - oldCompleteValue); } else { detailParentUnitProject.CompleteValue = detail.CompleteValue ?? 0; } detailParentUnitProject.CompleteValueRate = decimal.Round(Convert.ToDecimal(detailParentUnitProject.CompleteValue) / Convert.ToDecimal(parentUnitProject.WeightsMoney) * 100, 2); if (detailParentUnitProject.RealValue != null) { detailParentUnitProject.RealValue += ((detail.RealValue ?? 0) - oldRealValue); } else { detailParentUnitProject.RealValue = detail.RealValue ?? 0; } detailParentUnitProject.IsCompleteApprove = true; detailParentUnitProject.RealValueRate = decimal.Round(Convert.ToDecimal(detailParentUnitProject.RealValue) / Convert.ToDecimal(parentUnitProject.WeightsMoney) * 100, 2); BLL.WbsDetailService.UpdateWbsDetail(detailParentUnitProject); } } } //保存对应专业 Model.WBS_CnProfession cnProfession = BLL.CnProfessionService.GetCnProfessionByCnProfessionId(wbsSet.CnProfessionId); if (cnProfession != null) { Model.WbsDetail detailCnProfession = BLL.WbsDetailService.GetWbsDetailByWbsFlagYearMonth(cnProfession.CnProfessionId, 2, Convert.ToDateTime(detail.Months)); if (detailCnProfession != null) { if (detailCnProfession.CompleteValue != null) { detailCnProfession.CompleteValue += ((detail.CompleteValue ?? 0) - oldCompleteValue); } else { detailCnProfession.CompleteValue = detail.CompleteValue ?? 0; } detailCnProfession.CompleteValueRate = decimal.Round(Convert.ToDecimal(detailCnProfession.CompleteValue) / Convert.ToDecimal(cnProfession.WeightsMoney) * 100, 2); if (detailCnProfession.RealValue != null) { detailCnProfession.RealValue += ((detail.RealValue ?? 0) - oldRealValue); } else { detailCnProfession.RealValue = detail.RealValue ?? 0; } detailCnProfession.IsCompleteApprove = true; detailCnProfession.RealValueRate = decimal.Round(Convert.ToDecimal(detailCnProfession.RealValue) / Convert.ToDecimal(cnProfession.WeightsMoney) * 100, 2); BLL.WbsDetailService.UpdateWbsDetail(detailCnProfession); } //保存对应装置 Model.Project_Installation installation = BLL.Project_InstallationService.GetInstallationByInstallationId(cnProfession.InstallationId); if (installation != null) { Model.WbsDetail detailInstallation = BLL.WbsDetailService.GetWbsDetailByWbsFlagYearMonth(installation.InstallationId, 1, Convert.ToDateTime(detail.Months)); if (detailInstallation != null) { if (detailInstallation.CompleteValue != null) { detailInstallation.CompleteValue += ((detail.CompleteValue ?? 0) - oldCompleteValue); } else { detailInstallation.CompleteValue = detail.CompleteValue ?? 0; } detailInstallation.CompleteValueRate = decimal.Round(Convert.ToDecimal(detailInstallation.CompleteValue) / Convert.ToDecimal(installation.WeightsMoney) * 100, 2); if (detailInstallation.RealValue != null) { detailInstallation.RealValue += ((detail.RealValue ?? 0) - oldRealValue); } else { detailInstallation.RealValue = detail.RealValue ?? 0; } detailInstallation.IsCompleteApprove = true; detailInstallation.RealValueRate = decimal.Round(Convert.ToDecimal(detailInstallation.RealValue) / Convert.ToDecimal(installation.WeightsMoney) * 100, 2); BLL.WbsDetailService.UpdateWbsDetail(detailInstallation); if (installation.SuperInstallationId != "0") //一般装置 { //主项 Model.Project_Installation pInstallation = BLL.Project_InstallationService.GetInstallationByInstallationId(installation.SuperInstallationId); Model.WbsDetail pDetailInstallation = BLL.WbsDetailService.GetWbsDetailByWbsFlagYearMonth(installation.SuperInstallationId, 1, Convert.ToDateTime(detail.Months)); if (pDetailInstallation.CompleteValue != null) { pDetailInstallation.CompleteValue += ((detail.CompleteValue ?? 0) - oldCompleteValue); } else { pDetailInstallation.CompleteValue = detail.CompleteValue ?? 0; } pDetailInstallation.CompleteValueRate = decimal.Round(Convert.ToDecimal(pDetailInstallation.CompleteValue) / Convert.ToDecimal(installation.WeightsMoney) * 100, 2); if (pDetailInstallation.RealValue != null) { pDetailInstallation.RealValue += ((detail.RealValue ?? 0) - oldRealValue); } else { pDetailInstallation.RealValue = detail.RealValue ?? 0; } pDetailInstallation.IsCompleteApprove = true; pDetailInstallation.RealValueRate = decimal.Round(Convert.ToDecimal(pDetailInstallation.RealValue) / Convert.ToDecimal(installation.WeightsMoney) * 100, 2); BLL.WbsDetailService.UpdateWbsDetail(pDetailInstallation); //装置 Model.WbsDetail ppDetailInstallation = BLL.WbsDetailService.GetWbsDetailByWbsFlagYearMonth(pInstallation.SuperInstallationId, 1, Convert.ToDateTime(detail.Months)); if (ppDetailInstallation.CompleteValue != null) { ppDetailInstallation.CompleteValue += ((detail.CompleteValue ?? 0) - oldCompleteValue); } else { ppDetailInstallation.CompleteValue = detail.CompleteValue ?? 0; } ppDetailInstallation.CompleteValueRate = decimal.Round(Convert.ToDecimal(ppDetailInstallation.CompleteValue) / Convert.ToDecimal(installation.WeightsMoney) * 100, 2); if (ppDetailInstallation.RealValue != null) { ppDetailInstallation.RealValue += ((detail.RealValue ?? 0) - oldRealValue); } else { ppDetailInstallation.RealValue = detail.RealValue ?? 0; } ppDetailInstallation.IsCompleteApprove = true; ppDetailInstallation.RealValueRate = decimal.Round(Convert.ToDecimal(ppDetailInstallation.RealValue) / Convert.ToDecimal(installation.WeightsMoney) * 100, 2); BLL.WbsDetailService.UpdateWbsDetail(ppDetailInstallation); } } } } } } } i++; } //BLL.Sys_LogService.AddLog(BLL.Const.System_9, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "审核完成值/实耗值"); if (message == "success") { ShowNotify("保存成功!", MessageBoxIcon.Success); } else if (message == "submit") { ShowNotify("保存成功!", MessageBoxIcon.Success); } } #endregion #region 更新分部分项 /// /// 更新分部分项 /// /// /// /// /// private void UpdateWbsParentDetail(DateTime months, decimal? completeValue, decimal oldCompleteValue, decimal? realValue, decimal oldRealValue, string parentId, decimal? engineeringQuantity, decimal oldEngineeringQuantity) { 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) //父节点不是分部节点 { if (detail1.CompleteValue != null) { detail1.CompleteValue += ((completeValue ?? 0) - oldCompleteValue); } else { detail1.CompleteValue = completeValue ?? 0; } if (detail1.RealValue != null) { detail1.RealValue += ((realValue ?? 0) - oldRealValue); } else { detail1.RealValue = realValue ?? 0; } if (parentWbsSet1.EngineerQuantity != null && parentWbsSet1.EngineerQuantity > 0) { if (detail1.EngineeringQuantity != null) { detail1.EngineeringQuantity += ((engineeringQuantity ?? 0) - oldEngineeringQuantity); } else { detail1.EngineeringQuantity = engineeringQuantity ?? 0; } } detail1.IsCompleteApprove = true; detail1.CompleteValueRate = decimal.Round(Convert.ToDecimal(detail1.CompleteValue) / Convert.ToDecimal(parentWbsSet1.WeightsMoney) * 100, 2); BLL.WbsDetailService.UpdateWbsDetail(detail1); UpdateWbsParentDetail(months, completeValue, oldCompleteValue, realValue, oldRealValue, parentWbsSet1.SuperWbsSetId, engineeringQuantity, oldEngineeringQuantity); } else { if (detail1.CompleteValue != null) { detail1.CompleteValue += ((completeValue ?? 0) - oldCompleteValue); } else { detail1.CompleteValue = completeValue ?? 0; } if (detail1.RealValue != null) { detail1.RealValue += ((realValue ?? 0) - oldRealValue); } else { detail1.RealValue = realValue ?? 0; } if (parentWbsSet1.EngineerQuantity != null && parentWbsSet1.EngineerQuantity > 0) { if (detail1.EngineeringQuantity != null) { detail1.EngineeringQuantity += ((engineeringQuantity ?? 0) - oldEngineeringQuantity); } else { detail1.EngineeringQuantity = engineeringQuantity ?? 0; } } detail1.IsCompleteApprove = true; detail1.CompleteValueRate = decimal.Round(Convert.ToDecimal(detail1.CompleteValue) / 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("submit"); } else { Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); return; } } /// /// 保存 /// /// /// protected void btnSave1_Click(object sender, EventArgs e) { if (this.Grid1.Rows.Count > 0) { SaveData("success"); } else { Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); return; } } #endregion #region 绑定数据Grid1 /// /// 绑定数据Grid1 /// /// /// 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() { if (!string.IsNullOrEmpty(this.txtMonths.Text.Trim())) { var wbsDetails = from x in Funs.DB.WbsDetail select x; Model.Project_Sys_Set completeAndRealSet = BLL.Project_SysSetService.GetSysSetBySetId("22", this.CurrUser.LoginProjectId); DateTime date = DateTime.Now.Date; DateTime nowMonth = Convert.ToDateTime(date.Year + "-" + date.Month + "-01"); DateTime minDate, maxDate; if (completeAndRealSet != null) { minDate = nowMonth.AddMonths(-Convert.ToInt32(completeAndRealSet.SetValue)); } else { minDate = nowMonth; } maxDate = nowMonth.AddMonths(1).AddDays(-1); DateTime month = Convert.ToDateTime(this.txtMonths.Text.Trim() + "-01"); this.btnSave1.Hidden = true; List items = new List(); bool showSave = false; 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) //当前为末级 { string column0 = string.Empty; if (wbsSet.Flag == 1) { column0 = "分部工程"; } else if (wbsSet.Flag == 2) { column0 = "子分部工程"; } else if (wbsSet.Flag == 3) { column0 = "分项工程"; } else if (wbsSet.Flag == 4) { column0 = "子分项工程"; } this.Grid1.Columns[0].HeaderText = column0; this.Grid1.Columns[1].HeaderText = string.Empty; RenderField columnCompleteValue = Grid1.FindColumn("CompleteValue") as RenderField; RenderField columnCompleteValueRate = Grid1.FindColumn("CompleteValueRate") as RenderField; RenderField columnRealValue = Grid1.FindColumn("RealValue") as RenderField; columnCompleteValue.EnableColumnEdit = true; columnCompleteValueRate.EnableColumnEdit = true; columnRealValue.EnableColumnEdit = true; Model.WbsDetail detail = BLL.WbsDetailService.GetWbsDetailByWbsFlagYearMonth(wbsSet.WbsSetId, 4, month); if (detail != null) { List totalDetails = BLL.WbsDetailService.GetTotalWbsDetailsByYearMonth(wbsSet.WbsSetId, 4, month); Model.WBSSetItem item = new Model.WBSSetItem(); item.Id = wbsSet.WbsSetId; item.WbsDetailId = detail.WbsDetailId; item.EngineerQuantity = detail.EngineeringQuantity; item.Code = wbsSet.WbsSetCode; item.Name = wbsSet.WbsSetName; item.Weights = wbsSet.Weights; item.WeightsMoney = wbsSet.WeightsMoney; item.WeightsMoneyStr = decimal.Round(Convert.ToDecimal(item.WeightsMoney), 2).ToString(); if (detail.CompleteValue != null) { item.CompleteValue = decimal.Round(Convert.ToDecimal(detail.CompleteValue), 2); item.CompleteValueRate = decimal.Round(Convert.ToDecimal(detail.CompleteValue) / Convert.ToDecimal(item.WeightsMoney) * 100, 2); } item.CompleteValueTotal = decimal.Round(Convert.ToDecimal(totalDetails.Sum(x => x.CompleteValue ?? 0)), 2); item.CompleteValueTotalPart = item.CompleteValueTotal - (detail.CompleteValue ?? 0); if (item.WeightsMoney > 0) { item.CompleteValueRateTotal = decimal.Round(Convert.ToDecimal(item.CompleteValueTotal) / Convert.ToDecimal(item.WeightsMoney) * 100, 2); } if (detail.RealValue != null) { item.RealValue = decimal.Round(Convert.ToDecimal(detail.RealValue), 2); } item.RealValueTotal = decimal.Round(Convert.ToDecimal(totalDetails.Sum(x => x.RealValue ?? 0)), 2); item.RealValueTotalPart = item.RealValueTotal - (detail.RealValue ?? 0); item.StartDate = wbsSet.StartDate; item.EndDate = wbsSet.EndDate; item.PlanValue = decimal.Round(Convert.ToDecimal(detail.PlanValue ?? 0), 2); item.PlanValueTotal = decimal.Round(Convert.ToDecimal(totalDetails.Sum(x => x.PlanValue ?? 0)), 2); if (item.WeightsMoney > 0) { item.PlanValueRateTotal = decimal.Round(Convert.ToDecimal(item.PlanValueTotal) / Convert.ToDecimal(item.WeightsMoney) * 100, 2); } item.SVValue = item.CompleteValueTotal - item.PlanValueTotal; item.CVValue = item.CompleteValueTotal - item.RealValueTotal; items.Add(item); } } else //当前不为末级 { string column0 = string.Empty; if (wbsSet.Flag == 1) { column0 = "分部工程"; } else if (wbsSet.Flag == 2) { column0 = "子分部工程"; } else if (wbsSet.Flag == 3) { column0 = "分项工程"; } this.Grid1.Columns[0].HeaderText = column0; string column1 = string.Empty; if (childWbsSets[0].Flag == 2) { column1 = "子分部工程"; } else if (childWbsSets[0].Flag == 3) { column1 = "分项工程"; } else if (childWbsSets[0].Flag == 4) { column1 = "子分项工程"; } this.Grid1.Columns[1].HeaderText = column1; if (month >= minDate && month <= maxDate) { if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.WBSCompleteAuditMenuId, Const.BtnSave)) { showSave = true; } } Model.WbsDetail detail = BLL.WbsDetailService.GetWbsDetailByWbsFlagYearMonth(wbsSet.WbsSetId, 4, month); if (detail != null) { List totalDetails = BLL.WbsDetailService.GetTotalWbsDetailsByYearMonth(wbsSet.WbsSetId, 4, month); Model.WBSSetItem item = new Model.WBSSetItem(); item.Id = wbsSet.WbsSetId; item.EngineerQuantity = detail.EngineeringQuantity; item.WbsDetailId = detail.WbsDetailId; item.Code = wbsSet.WbsSetCode; item.Name = wbsSet.WbsSetName; item.Weights = wbsSet.Weights; item.WeightsMoney = wbsSet.WeightsMoney; item.WeightsMoneyStr = decimal.Round(Convert.ToDecimal(item.WeightsMoney), 2).ToString(); item.BudgetUnitPrice = wbsSet.BudgetUnitPrice; item.CostUnivalent = wbsSet.CostUnivalent; if (detail.CompleteValue != null) { item.CompleteValue = decimal.Round(Convert.ToDecimal(detail.CompleteValue), 2); item.CompleteValueRate = decimal.Round(Convert.ToDecimal(detail.CompleteValue) / Convert.ToDecimal(item.WeightsMoney) * 100, 2); } item.CompleteValueTotal = decimal.Round(Convert.ToDecimal(totalDetails.Sum(x => x.CompleteValue ?? 0)), 2); item.CompleteValueTotalPart = item.CompleteValueTotal - (detail.CompleteValue ?? 0); if (item.WeightsMoney > 0) { item.CompleteValueRateTotal = decimal.Round(Convert.ToDecimal(item.CompleteValueTotal) / Convert.ToDecimal(item.WeightsMoney) * 100, 2); } if (detail.RealValue != null) { item.RealValue = decimal.Round(Convert.ToDecimal(detail.RealValue), 2); } item.RealValueTotal = decimal.Round(Convert.ToDecimal(totalDetails.Sum(x => x.RealValue ?? 0)), 2); item.RealValueTotalPart = item.RealValueTotal - (detail.RealValue ?? 0); item.StartDate = wbsSet.StartDate; item.EndDate = wbsSet.EndDate; item.PlanValue = decimal.Round(Convert.ToDecimal(detail.PlanValue ?? 0), 2); item.PlanValueTotal = decimal.Round(Convert.ToDecimal(totalDetails.Sum(x => x.PlanValue ?? 0)), 2); if (item.WeightsMoney > 0) { item.PlanValueRateTotal = decimal.Round(Convert.ToDecimal(item.PlanValueTotal) / Convert.ToDecimal(item.WeightsMoney) * 100, 2); } item.SVValue = item.CompleteValueTotal - item.PlanValueTotal; item.CVValue = item.CompleteValueTotal - item.RealValueTotal; items.Add(item); foreach (var childWbsSet in childWbsSets) { Model.WbsDetail childDetail = BLL.WbsDetailService.GetWbsDetailByWbsFlagYearMonth(childWbsSet.WbsSetId, 4, month); if (childDetail != null) { List totalChildDetails = BLL.WbsDetailService.GetTotalWbsDetailsByYearMonth(childWbsSet.WbsSetId, 4, month); Model.WBSSetItem childItem = new Model.WBSSetItem(); childItem.Id = childWbsSet.WbsSetId; childItem.EngineerQuantity = childDetail.EngineeringQuantity; childItem.WbsDetailId = childDetail.WbsDetailId; childItem.ChildCode = childWbsSet.WbsSetCode; childItem.ChildName = childWbsSet.WbsSetName; childItem.BudgetUnitPrice = wbsSet.BudgetUnitPrice; childItem.CostUnivalent = wbsSet.CostUnivalent; childItem.Weights = childWbsSet.Weights; childItem.WeightsMoney = childWbsSet.WeightsMoney; childItem.WeightsMoneyStr = decimal.Round(Convert.ToDecimal(childItem.WeightsMoney), 2).ToString(); if (childDetail.CompleteValue != null) { childItem.CompleteValue = decimal.Round(Convert.ToDecimal(childDetail.CompleteValue), 2); childItem.CompleteValueRate = decimal.Round(Convert.ToDecimal(childDetail.CompleteValue) / Convert.ToDecimal(childItem.WeightsMoney) * 100, 2); } childItem.CompleteValueTotal = decimal.Round(Convert.ToDecimal(totalChildDetails.Sum(x => x.CompleteValue ?? 0)), 2); childItem.CompleteValueTotalPart = childItem.CompleteValueTotal - (childDetail.CompleteValue ?? 0); if (childItem.WeightsMoney > 0) { childItem.CompleteValueRateTotal = decimal.Round(Convert.ToDecimal(childItem.CompleteValueTotal) / Convert.ToDecimal(childItem.WeightsMoney) * 100, 2); } if (childDetail.RealValue != null) { childItem.RealValue = decimal.Round(Convert.ToDecimal(childDetail.RealValue), 2); } childItem.RealValueTotal = decimal.Round(Convert.ToDecimal(totalChildDetails.Sum(x => x.RealValue ?? 0)), 2); childItem.RealValueTotalPart = childItem.RealValueTotal - (childDetail.RealValue ?? 0); childItem.StartDate = childWbsSet.StartDate; childItem.EndDate = childWbsSet.EndDate; childItem.PlanValue = decimal.Round(Convert.ToDecimal(childDetail.PlanValue ?? 0), 2); childItem.PlanValueTotal = decimal.Round(Convert.ToDecimal(totalChildDetails.Sum(x => x.PlanValue ?? 0)), 2); if (childItem.WeightsMoney > 0) { childItem.PlanValueRateTotal = decimal.Round(Convert.ToDecimal(childItem.PlanValueTotal) / Convert.ToDecimal(childItem.WeightsMoney) * 100, 2); } childItem.SVValue = childItem.CompleteValueTotal - childItem.PlanValueTotal; childItem.CVValue = childItem.CompleteValueTotal - childItem.RealValueTotal; items.Add(childItem); } } } } } } #endregion #region 子单位工程 else if (this.trWBS.SelectedNode.CommandName == "childUnitProject") { this.Grid1.Columns[0].HeaderText = "子单位工程"; this.Grid1.Columns[1].HeaderText = "分部工程"; Model.Wbs_UnitProject unitProject = BLL.UnitProjectService.GetUnitProjectByUnitProjectId(this.trWBS.SelectedNode.NodeID); if (unitProject.EngineerQuantity != null && unitProject.EngineerQuantity > 0) //已设置工作量 { this.btnSave1.Hidden = false; } Model.WbsDetail detail = BLL.WbsDetailService.GetWbsDetailByWbsFlagYearMonth(unitProject.UnitProjectId, 3, month); if (detail != null) { List totalDetails = BLL.WbsDetailService.GetTotalWbsDetailsByYearMonth(unitProject.UnitProjectId, 3, month); Model.WBSSetItem item = new Model.WBSSetItem(); item.Id = unitProject.UnitProjectId; item.WbsDetailId = detail.WbsDetailId; item.EngineerQuantity = detail.EngineeringQuantity; item.Code = unitProject.UnitProjectCode; item.Name = unitProject.UnitProjectName; item.Weights = unitProject.Weights; item.WeightsMoney = unitProject.WeightsMoney; item.WeightsMoneyStr = decimal.Round(Convert.ToDecimal(item.WeightsMoney), 2).ToString(); if (detail.CompleteValue != null) { item.CompleteValue = decimal.Round(Convert.ToDecimal(detail.CompleteValue), 2); item.CompleteValueRate = decimal.Round(Convert.ToDecimal(detail.CompleteValue) / Convert.ToDecimal(item.WeightsMoney) * 100, 2); } item.CompleteValueTotal = decimal.Round(Convert.ToDecimal(totalDetails.Sum(x => x.CompleteValue ?? 0)), 2); if (item.WeightsMoney > 0) { item.CompleteValueRateTotal = decimal.Round(Convert.ToDecimal(item.CompleteValueTotal) / Convert.ToDecimal(item.WeightsMoney) * 100, 2); } if (detail.RealValue != null) { item.RealValue = decimal.Round(Convert.ToDecimal(detail.RealValue), 2); } item.RealValueTotal = decimal.Round(Convert.ToDecimal(totalDetails.Sum(x => x.RealValue ?? 0)), 2); item.StartDate = unitProject.StartDate; item.EndDate = unitProject.EndDate; item.PlanValue = decimal.Round(Convert.ToDecimal(detail.PlanValue ?? 0), 2); item.PlanValueTotal = decimal.Round(Convert.ToDecimal(totalDetails.Sum(x => x.PlanValue ?? 0)), 2); if (item.WeightsMoney > 0) { item.PlanValueRateTotal = decimal.Round(Convert.ToDecimal(item.PlanValueTotal) / Convert.ToDecimal(item.WeightsMoney) * 100, 2); } item.SVValue = item.CompleteValueTotal - item.PlanValueTotal; item.CVValue = item.CompleteValueTotal - item.RealValueTotal; items.Add(item); var childWbsSets = from x in Funs.DB.Wbs_WbsSet where x.SuperWbsSetId == null && x.UnitProjectId == this.trWBS.SelectedNode.NodeID && x.IsApprove == true orderby x.WbsSetCode select x; foreach (var childWbsSet in childWbsSets) { Model.WbsDetail childDetail = BLL.WbsDetailService.GetWbsDetailByWbsFlagYearMonth(childWbsSet.WbsSetId, 4, month); if (childDetail != null) { List totalChildDetails = BLL.WbsDetailService.GetTotalWbsDetailsByYearMonth(childWbsSet.WbsSetId, 4, month); Model.WBSSetItem childItem = new Model.WBSSetItem(); childItem.Id = childWbsSet.WbsSetId; childItem.EngineerQuantity = childDetail.EngineeringQuantity; childItem.WbsDetailId = childDetail.WbsDetailId; childItem.ChildCode = childWbsSet.WbsSetCode; childItem.ChildName = childWbsSet.WbsSetName; childItem.BudgetUnitPrice = unitProject.BudgetUnitPrice; childItem.CostUnivalent = unitProject.CostUnivalent; childItem.Weights = childWbsSet.Weights; childItem.WeightsMoney = childWbsSet.WeightsMoney; childItem.WeightsMoneyStr = decimal.Round(Convert.ToDecimal(childItem.WeightsMoney), 2).ToString(); if (childDetail.CompleteValue != null) { childItem.CompleteValue = decimal.Round(Convert.ToDecimal(childDetail.CompleteValue), 2); childItem.CompleteValueRate = decimal.Round(Convert.ToDecimal(childDetail.CompleteValue) / Convert.ToDecimal(childItem.WeightsMoney) * 100, 2); } childItem.CompleteValueTotal = decimal.Round(Convert.ToDecimal(totalChildDetails.Sum(x => x.CompleteValue ?? 0)), 2); if (childItem.WeightsMoney > 0) { childItem.CompleteValueRateTotal = decimal.Round(Convert.ToDecimal(childItem.CompleteValueTotal) / Convert.ToDecimal(childItem.WeightsMoney) * 100, 2); } if (childDetail.RealValue != null) { childItem.RealValue = decimal.Round(Convert.ToDecimal(childDetail.RealValue), 2); } childItem.RealValueTotal = decimal.Round(Convert.ToDecimal(totalChildDetails.Sum(x => x.RealValue ?? 0)), 2); childItem.StartDate = childWbsSet.StartDate; childItem.EndDate = childWbsSet.EndDate; childItem.PlanValue = decimal.Round(Convert.ToDecimal(childDetail.PlanValue ?? 0), 2); childItem.PlanValueTotal = decimal.Round(Convert.ToDecimal(totalChildDetails.Sum(x => x.PlanValue ?? 0)), 2); if (childItem.WeightsMoney > 0) { childItem.PlanValueRateTotal = decimal.Round(Convert.ToDecimal(childItem.PlanValueTotal) / Convert.ToDecimal(childItem.WeightsMoney) * 100, 2); } childItem.SVValue = childItem.CompleteValueTotal - childItem.PlanValueTotal; childItem.CVValue = childItem.CompleteValueTotal - childItem.RealValueTotal; items.Add(childItem); } } } } #endregion #region 单位工程 else if (this.trWBS.SelectedNode.CommandName == "unitProject") { this.Grid1.Columns[0].HeaderText = "单位工程"; Model.Wbs_UnitProject unitProject = BLL.UnitProjectService.GetUnitProjectByUnitProjectId(this.trWBS.SelectedNode.NodeID); Model.WbsDetail detail = BLL.WbsDetailService.GetWbsDetailByWbsFlagYearMonth(unitProject.UnitProjectId, 3, month); if (detail != null) { List totalDetails = BLL.WbsDetailService.GetTotalWbsDetailsByYearMonth(unitProject.UnitProjectId, 3, month); Model.WBSSetItem item = new Model.WBSSetItem(); item.Id = unitProject.UnitProjectId; item.WbsDetailId = detail.WbsDetailId; item.Code = unitProject.UnitProjectCode; item.Name = unitProject.UnitProjectName; item.Weights = unitProject.Weights; item.WeightsMoney = unitProject.WeightsMoney; item.WeightsMoneyStr = decimal.Round(Convert.ToDecimal(item.WeightsMoney), 2).ToString(); if (detail.CompleteValue != null) { item.CompleteValue = decimal.Round(Convert.ToDecimal(detail.CompleteValue), 2); item.CompleteValueRate = decimal.Round(Convert.ToDecimal(detail.CompleteValue) / Convert.ToDecimal(item.WeightsMoney) * 100, 2); } item.CompleteValueTotal = decimal.Round(Convert.ToDecimal(totalDetails.Sum(x => x.CompleteValue ?? 0)), 2); if (item.WeightsMoney > 0) { item.CompleteValueRateTotal = decimal.Round(Convert.ToDecimal(item.CompleteValueTotal) / Convert.ToDecimal(item.WeightsMoney) * 100, 2); } if (detail.RealValue != null) { item.RealValue = decimal.Round(Convert.ToDecimal(detail.RealValue), 2); } item.RealValueTotal = decimal.Round(Convert.ToDecimal(totalDetails.Sum(x => x.RealValue ?? 0)), 2); item.StartDate = unitProject.StartDate; item.EndDate = unitProject.EndDate; item.PlanValue = decimal.Round(Convert.ToDecimal(detail.PlanValue ?? 0), 2); item.PlanValueTotal = decimal.Round(Convert.ToDecimal(totalDetails.Sum(x => x.PlanValue ?? 0)), 2); if (item.WeightsMoney > 0) { item.PlanValueRateTotal = decimal.Round(Convert.ToDecimal(item.PlanValueTotal) / Convert.ToDecimal(item.WeightsMoney) * 100, 2); } item.SVValue = item.CompleteValueTotal - item.PlanValueTotal; item.CVValue = item.CompleteValueTotal - item.RealValueTotal; items.Add(item); } if (unitProject.UnitProjectName == "质量行为") { if (month >= minDate && month <= maxDate) { if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.WBSCompleteAuditMenuId, Const.BtnSave)) { this.btnSave1.Hidden = false; } } var childWbsSets = from x in Funs.DB.Wbs_WbsSet where x.SuperWbsSetId == null && x.UnitProjectId == this.trWBS.SelectedNode.NodeID && x.IsApprove == true orderby x.SortIndex, x.WbsSetCode select x; RenderField columnCompleteValue = Grid1.FindColumn("CompleteValue") as RenderField; RenderField columnCompleteValueRate = Grid1.FindColumn("CompleteValueRate") as RenderField; RenderField columnRealValue = Grid1.FindColumn("RealValue") as RenderField; columnCompleteValue.EnableColumnEdit = true; columnCompleteValueRate.EnableColumnEdit = true; columnRealValue.EnableColumnEdit = true; foreach (var childWbsSet in childWbsSets) { Model.WbsDetail childDetail = BLL.WbsDetailService.GetWbsDetailByWbsFlagYearMonth(childWbsSet.WbsSetId, 4, month); if (childDetail != null) { List totalChildDetails = BLL.WbsDetailService.GetTotalWbsDetailsByYearMonth(childWbsSet.WbsSetId, 4, month); Model.WBSSetItem item = new Model.WBSSetItem(); item.Id = childWbsSet.WbsSetId; item.WbsDetailId = childDetail.WbsDetailId; item.Code = childWbsSet.WbsSetCode; item.Name = childWbsSet.WbsSetName; item.Weights = childWbsSet.Weights; item.WeightsMoney = childWbsSet.WeightsMoney; item.WeightsMoneyStr = decimal.Round(Convert.ToDecimal(item.WeightsMoney), 2).ToString(); if (childDetail.CompleteValue != null) { item.CompleteValue = decimal.Round(Convert.ToDecimal(childDetail.CompleteValue), 2); item.CompleteValueRate = decimal.Round(Convert.ToDecimal(childDetail.CompleteValue) / Convert.ToDecimal(item.WeightsMoney) * 100, 2); } item.CompleteValueTotal = decimal.Round(Convert.ToDecimal(totalChildDetails.Sum(x => x.CompleteValue ?? 0)), 2); item.CompleteValueTotalPart = item.CompleteValueTotal - (childDetail.CompleteValue ?? 0); if (item.WeightsMoney > 0) { item.CompleteValueRateTotal = decimal.Round(Convert.ToDecimal(item.CompleteValueTotal) / Convert.ToDecimal(item.WeightsMoney) * 100, 2); } if (childDetail.RealValue != null) { item.RealValue = decimal.Round(Convert.ToDecimal(childDetail.RealValue), 2); } item.RealValueTotal = decimal.Round(Convert.ToDecimal(totalChildDetails.Sum(x => x.RealValue ?? 0)), 2); item.RealValueTotalPart = item.RealValueTotal - (childDetail.RealValue ?? 0); item.StartDate = childWbsSet.StartDate; item.EndDate = childWbsSet.EndDate; item.PlanValue = decimal.Round(Convert.ToDecimal(childDetail.PlanValue ?? 0), 2); item.PlanValueTotal = decimal.Round(Convert.ToDecimal(totalChildDetails.Sum(x => x.PlanValue ?? 0)), 2); if (item.WeightsMoney > 0) { item.PlanValueRateTotal = decimal.Round(Convert.ToDecimal(item.PlanValueTotal) / Convert.ToDecimal(item.WeightsMoney) * 100, 2); } item.SVValue = item.CompleteValueTotal - item.PlanValueTotal; item.CVValue = item.CompleteValueTotal - item.RealValueTotal; items.Add(item); } } } else { var childUnitProjects = from x in Funs.DB.Wbs_UnitProject where x.SuperUnitProjectId == this.trWBS.SelectedNode.NodeID && x.IsApprove == true orderby x.UnitProjectCode select x; if (childUnitProjects.Count() > 0) //存在子单位工程 { this.Grid1.Columns[1].HeaderText = "子单位工程"; foreach (var childUnitProject in childUnitProjects) { Model.WbsDetail childDetail = BLL.WbsDetailService.GetWbsDetailByWbsFlagYearMonth(childUnitProject.UnitProjectId, 3, month); if (childDetail != null) { List totalChildDetails = BLL.WbsDetailService.GetTotalWbsDetailsByYearMonth(childUnitProject.UnitProjectId, 3, month); Model.WBSSetItem childItem = new Model.WBSSetItem(); childItem.Id = childUnitProject.UnitProjectId; childItem.WbsDetailId = childDetail.WbsDetailId; childItem.ChildCode = childUnitProject.UnitProjectCode; childItem.ChildName = childUnitProject.UnitProjectName; childItem.Weights = childUnitProject.Weights; childItem.WeightsMoney = childUnitProject.WeightsMoney; childItem.WeightsMoneyStr = decimal.Round(Convert.ToDecimal(childItem.WeightsMoney), 2).ToString(); if (childDetail.CompleteValue != null) { childItem.CompleteValue = decimal.Round(Convert.ToDecimal(childDetail.CompleteValue), 2); childItem.CompleteValueRate = decimal.Round(Convert.ToDecimal(childDetail.CompleteValue) / Convert.ToDecimal(childItem.WeightsMoney) * 100, 2); } childItem.CompleteValueTotal = decimal.Round(Convert.ToDecimal(totalChildDetails.Sum(x => x.CompleteValue ?? 0)), 2); if (childItem.WeightsMoney > 0) { childItem.CompleteValueRateTotal = decimal.Round(Convert.ToDecimal(childItem.CompleteValueTotal) / Convert.ToDecimal(childItem.WeightsMoney) * 100, 2); } if (childDetail.RealValue != null) { childItem.RealValue = decimal.Round(Convert.ToDecimal(childDetail.RealValue), 2); } childItem.RealValueTotal = decimal.Round(Convert.ToDecimal(totalChildDetails.Sum(x => x.RealValue ?? 0)), 2); childItem.StartDate = childUnitProject.StartDate; childItem.EndDate = childUnitProject.EndDate; childItem.PlanValue = decimal.Round(Convert.ToDecimal(childDetail.PlanValue ?? 0), 2); childItem.PlanValueTotal = decimal.Round(Convert.ToDecimal(totalChildDetails.Sum(x => x.PlanValue ?? 0)), 2); if (childItem.WeightsMoney > 0) { childItem.PlanValueRateTotal = decimal.Round(Convert.ToDecimal(childItem.PlanValueTotal) / Convert.ToDecimal(childItem.WeightsMoney) * 100, 2); } childItem.SVValue = childItem.CompleteValueTotal - childItem.PlanValueTotal; childItem.CVValue = childItem.CompleteValueTotal - childItem.RealValueTotal; items.Add(childItem); } } } else //不存在子单位工程 { this.Grid1.Columns[1].HeaderText = "分部工程"; var childWbsSets = from x in Funs.DB.Wbs_WbsSet where x.SuperWbsSetId == null && x.UnitProjectId == this.trWBS.SelectedNode.NodeID && x.IsApprove == true orderby x.WbsSetCode select x; foreach (var childWbsSet in childWbsSets) { Model.WbsDetail childDetail = BLL.WbsDetailService.GetWbsDetailByWbsFlagYearMonth(childWbsSet.WbsSetId, 4, month); if (childDetail != null) { List totalChildDetails = BLL.WbsDetailService.GetTotalWbsDetailsByYearMonth(childWbsSet.WbsSetId, 4, month); Model.WBSSetItem childItem = new Model.WBSSetItem(); childItem.Id = childWbsSet.WbsSetId; childItem.WbsDetailId = childDetail.WbsDetailId; childItem.ChildCode = childWbsSet.WbsSetCode; childItem.ChildName = childWbsSet.WbsSetName; childItem.Weights = childWbsSet.Weights; childItem.WeightsMoney = childWbsSet.WeightsMoney; childItem.WeightsMoneyStr = decimal.Round(Convert.ToDecimal(childItem.WeightsMoney), 2).ToString(); if (childDetail.CompleteValue != null) { childItem.CompleteValue = decimal.Round(Convert.ToDecimal(childDetail.CompleteValue), 2); childItem.CompleteValueRate = decimal.Round(Convert.ToDecimal(childDetail.CompleteValue) / Convert.ToDecimal(childItem.WeightsMoney) * 100, 2); } childItem.CompleteValueTotal = decimal.Round(Convert.ToDecimal(totalChildDetails.Sum(x => x.CompleteValue ?? 0)), 2); if (childItem.WeightsMoney > 0) { childItem.CompleteValueRateTotal = decimal.Round(Convert.ToDecimal(childItem.CompleteValueTotal) / Convert.ToDecimal(childItem.WeightsMoney) * 100, 2); } if (childDetail.RealValue != null) { childItem.RealValue = decimal.Round(Convert.ToDecimal(childDetail.RealValue), 2); } childItem.RealValueTotal = decimal.Round(Convert.ToDecimal(totalChildDetails.Sum(x => x.RealValue ?? 0)), 2); childItem.StartDate = childWbsSet.StartDate; childItem.EndDate = childWbsSet.EndDate; childItem.PlanValue = decimal.Round(Convert.ToDecimal(childDetail.PlanValue ?? 0), 2); childItem.PlanValueTotal = decimal.Round(Convert.ToDecimal(totalChildDetails.Sum(x => x.PlanValue ?? 0)), 2); if (childItem.WeightsMoney > 0) { childItem.PlanValueRateTotal = decimal.Round(Convert.ToDecimal(childItem.PlanValueTotal) / Convert.ToDecimal(childItem.WeightsMoney) * 100, 2); } childItem.SVValue = childItem.CompleteValueTotal - childItem.PlanValueTotal; childItem.CVValue = childItem.CompleteValueTotal - childItem.RealValueTotal; items.Add(childItem); } } } } } #endregion #region 专业 else if (this.trWBS.SelectedNode.CommandName == "cnProfession") { this.Grid1.Columns[0].HeaderText = "专业"; this.Grid1.Columns[1].HeaderText = "单位工程"; Model.WBS_CnProfession cnProfession = BLL.CnProfessionService.GetCnProfessionByCnProfessionId(this.trWBS.SelectedNode.NodeID); Model.WbsDetail detail = BLL.WbsDetailService.GetWbsDetailByWbsFlagYearMonth(cnProfession.CnProfessionId, 2, month); if (detail != null) { List totalDetails = BLL.WbsDetailService.GetTotalWbsDetailsByYearMonth(cnProfession.CnProfessionId, 2, month); Model.WBSSetItem item = new Model.WBSSetItem(); item.Id = cnProfession.CnProfessionId; item.WbsDetailId = detail.WbsDetailId; item.Code = cnProfession.CnProfessionCode; item.Name = cnProfession.CnProfessionName; item.Weights = cnProfession.Weights; item.WeightsMoney = cnProfession.WeightsMoney; item.WeightsMoneyStr = decimal.Round(Convert.ToDecimal(item.WeightsMoney), 2).ToString(); if (detail.CompleteValue != null) { item.CompleteValue = decimal.Round(Convert.ToDecimal(detail.CompleteValue), 2); item.CompleteValueRate = decimal.Round(Convert.ToDecimal(detail.CompleteValue) / Convert.ToDecimal(item.WeightsMoney) * 100, 2); } item.CompleteValueTotal = decimal.Round(Convert.ToDecimal(totalDetails.Sum(x => x.CompleteValue ?? 0)), 2); if (item.WeightsMoney > 0) { item.CompleteValueRateTotal = decimal.Round(Convert.ToDecimal(item.CompleteValueTotal) / Convert.ToDecimal(item.WeightsMoney) * 100, 2); } if (detail.RealValue != null) { item.RealValue = decimal.Round(Convert.ToDecimal(detail.RealValue), 2); } item.RealValueTotal = decimal.Round(Convert.ToDecimal(totalDetails.Sum(x => x.RealValue ?? 0)), 2); item.StartDate = cnProfession.StartDate; item.EndDate = cnProfession.EndDate; item.PlanValue = decimal.Round(Convert.ToDecimal(detail.PlanValue ?? 0), 2); item.PlanValueTotal = decimal.Round(Convert.ToDecimal(totalDetails.Sum(x => x.PlanValue ?? 0)), 2); if (item.WeightsMoney > 0) { item.PlanValueRateTotal = decimal.Round(Convert.ToDecimal(item.PlanValueTotal) / Convert.ToDecimal(item.WeightsMoney) * 100, 2); } item.SVValue = item.CompleteValueTotal - item.PlanValueTotal; item.CVValue = item.CompleteValueTotal - item.RealValueTotal; items.Add(item); var childUnitProjects = from x in Funs.DB.Wbs_UnitProject where x.CnProfessionId == this.trWBS.SelectedNodeID && x.SuperUnitProjectId == null && x.IsApprove == true orderby x.UnitProjectCode select x; foreach (var childUnitProject in childUnitProjects) { Model.WbsDetail childDetail = BLL.WbsDetailService.GetWbsDetailByWbsFlagYearMonth(childUnitProject.UnitProjectId, 3, month); if (childDetail != null) { List totalChildDetails = BLL.WbsDetailService.GetTotalWbsDetailsByYearMonth(childUnitProject.UnitProjectId, 3, month); Model.WBSSetItem childItem = new Model.WBSSetItem(); childItem.Id = childUnitProject.UnitProjectId; childItem.WbsDetailId = childDetail.WbsDetailId; childItem.ChildCode = childUnitProject.UnitProjectCode; childItem.ChildName = childUnitProject.UnitProjectName; childItem.Weights = childUnitProject.Weights; childItem.WeightsMoney = childUnitProject.WeightsMoney; childItem.WeightsMoneyStr = decimal.Round(Convert.ToDecimal(childItem.WeightsMoney), 2).ToString(); if (childDetail.CompleteValue != null) { childItem.CompleteValue = decimal.Round(Convert.ToDecimal(childDetail.CompleteValue), 2); childItem.CompleteValueRate = decimal.Round(Convert.ToDecimal(childDetail.CompleteValue) / Convert.ToDecimal(childItem.WeightsMoney) * 100, 2); } childItem.CompleteValueTotal = decimal.Round(Convert.ToDecimal(totalChildDetails.Sum(x => x.CompleteValue ?? 0)), 2); if (childItem.WeightsMoney > 0) { childItem.CompleteValueRateTotal = decimal.Round(Convert.ToDecimal(childItem.CompleteValueTotal) / Convert.ToDecimal(childItem.WeightsMoney) * 100, 2); } if (childDetail.RealValue != null) { childItem.RealValue = decimal.Round(Convert.ToDecimal(childDetail.RealValue), 2); } childItem.RealValueTotal = decimal.Round(Convert.ToDecimal(totalChildDetails.Sum(x => x.RealValue ?? 0)), 2); childItem.StartDate = childUnitProject.StartDate; childItem.EndDate = childUnitProject.EndDate; childItem.PlanValue = decimal.Round(Convert.ToDecimal(childDetail.PlanValue ?? 0), 2); childItem.PlanValueTotal = decimal.Round(Convert.ToDecimal(totalChildDetails.Sum(x => x.PlanValue ?? 0)), 2); if (childItem.WeightsMoney > 0) { childItem.PlanValueRateTotal = decimal.Round(Convert.ToDecimal(childItem.PlanValueTotal) / Convert.ToDecimal(childItem.WeightsMoney) * 100, 2); } childItem.SVValue = childItem.CompleteValueTotal - childItem.PlanValueTotal; childItem.CVValue = childItem.CompleteValueTotal - childItem.RealValueTotal; items.Add(childItem); } } } } #endregion #region 装置 else if (this.trWBS.SelectedNode.CommandName == "installation") { this.Grid1.Columns[0].HeaderText = "装置"; this.Grid1.Columns[1].HeaderText = "专业"; Model.Project_Installation installation = BLL.Project_InstallationService.GetInstallationByInstallationId(this.trWBS.SelectedNode.NodeID); Model.WbsDetail detail = BLL.WbsDetailService.GetWbsDetailByWbsFlagYearMonth(installation.InstallationId, 1, month); if (detail != null) { List totalDetails = BLL.WbsDetailService.GetTotalWbsDetailsByYearMonth(installation.InstallationId, 1, month); Model.WBSSetItem item = new Model.WBSSetItem(); item.Id = installation.InstallationId; item.WbsDetailId = detail.WbsDetailId; item.Code = installation.InstallationCode; item.Name = installation.InstallationName; item.Weights = installation.Weights; item.WeightsMoney = installation.WeightsMoney; item.WeightsMoneyStr = decimal.Round(Convert.ToDecimal(item.WeightsMoney), 2).ToString(); if (detail.CompleteValue != null) { item.CompleteValue = decimal.Round(Convert.ToDecimal(detail.CompleteValue), 2); item.CompleteValueRate = decimal.Round(Convert.ToDecimal(detail.CompleteValue) / Convert.ToDecimal(item.WeightsMoney) * 100, 2); } item.CompleteValueTotal = decimal.Round(Convert.ToDecimal(totalDetails.Sum(x => x.CompleteValue ?? 0)), 2); if (item.WeightsMoney > 0) { item.CompleteValueRateTotal = decimal.Round(Convert.ToDecimal(item.CompleteValueTotal) / Convert.ToDecimal(item.WeightsMoney) * 100, 2); } if (detail.RealValue != null) { item.RealValue = decimal.Round(Convert.ToDecimal(detail.RealValue), 2); } item.RealValueTotal = decimal.Round(Convert.ToDecimal(totalDetails.Sum(x => x.RealValue ?? 0)), 2); item.StartDate = installation.StartDate; item.EndDate = installation.EndDate; item.PlanValue = decimal.Round(Convert.ToDecimal(detail.PlanValue ?? 0), 2); item.PlanValueTotal = decimal.Round(Convert.ToDecimal(totalDetails.Sum(x => x.PlanValue ?? 0)), 2); if (item.WeightsMoney > 0) { item.PlanValueRateTotal = decimal.Round(Convert.ToDecimal(item.PlanValueTotal) / Convert.ToDecimal(item.WeightsMoney) * 100, 2); } item.SVValue = item.CompleteValueTotal - item.PlanValueTotal; item.CVValue = item.CompleteValueTotal - item.RealValueTotal; items.Add(item); if (installation.SuperInstallationId != "0") //工序或主项 { var cnProfessions = from x in Funs.DB.WBS_CnProfession where x.InstallationId == this.trWBS.SelectedNodeID orderby x.OldId select x; if (cnProfessions.Count() > 0) //工序 { foreach (var cnProfession in cnProfessions) { #region 计划日期已结束但尚未完成的项增加当月记录 var wbsSets = from x in Funs.DB.Wbs_WbsSet where x.CnProfessionId == cnProfession.CnProfessionId && x.IsApprove == true select x; //末级节点计划日期已结束但尚未完成的项集合 List addDetailWbsSets = new List(); foreach (var wbsSet in wbsSets) { if (BLL.WbsSetService.GetApproveWbsSetsBySuperWbsSetId(wbsSet.WbsSetId).Count == 0) //末级节点 { var details = from x in wbsDetails where x.ToWbs == wbsSet.WbsSetId && x.IsCompleteApprove == null orderby x.Months descending select x; if (details.Count() == 0) //所有月份记录都已审核 { //累计完成值 var completeValueList = from x in wbsDetails where x.ToWbs == wbsSet.WbsSetId select x.CompleteValue; decimal totalCompleteValue = 0; foreach (var completeValue in completeValueList) { totalCompleteValue += completeValue ?? 0; } if (totalCompleteValue < wbsSet.WeightsMoney) //累计完成值小于总计划值 { addDetailWbsSets.Add(wbsSet); } } } } foreach (var addDetailWbsSet in addDetailWbsSets) { Model.WbsDetail newWbsDetail = new Model.WbsDetail(); newWbsDetail.WbsDetailId = SQLHelper.GetNewID(typeof(Model.WbsDetail)); newWbsDetail.ToWbs = addDetailWbsSet.WbsSetId; newWbsDetail.ToFlag = 4; newWbsDetail.Way = addDetailWbsSet.Way; newWbsDetail.Months = month; newWbsDetail.PlanValue = 0; newWbsDetail.PlanValueRate = 0; newWbsDetail.CompleteValue = 0; newWbsDetail.CompleteValueRate = 0; newWbsDetail.RealValue = 0; newWbsDetail.RealValueRate = 0; if (BLL.WbsDetailService.GetWbsDetailByWbsFlagYearMonth(addDetailWbsSet.WbsSetId, 4, month) == null) { BLL.WbsDetailService.AddWbsDetail(newWbsDetail); //循环保存所有上级分部分项对应记录 AddWbsParentDetail(month, 0, addDetailWbsSet.SuperWbsSetId, 0, 0); //保存对应单位工程及子单位工程 Model.Wbs_UnitProject unitProject = BLL.UnitProjectService.GetUnitProjectByUnitProjectId(addDetailWbsSet.UnitProjectId); Model.WbsDetail detailUnitProject = BLL.WbsDetailService.GetWbsDetailByWbsFlagYearMonth(addDetailWbsSet.UnitProjectId, 3, month); if (unitProject != null) { if (detailUnitProject == null) { Model.WbsDetail newDetailUnitProject = new Model.WbsDetail(); newDetailUnitProject.WbsDetailId = SQLHelper.GetNewID(typeof(Model.WbsDetail)); newDetailUnitProject.ToWbs = addDetailWbsSet.UnitProjectId; newDetailUnitProject.ToFlag = 3; //单位工程 newDetailUnitProject.Way = "A"; newDetailUnitProject.Months = month; newDetailUnitProject.PlanValue = 0; newDetailUnitProject.PlanValueRate = 0; BLL.WbsDetailService.AddWbsDetail(newDetailUnitProject); } else { detailUnitProject.PlanValue += 0; detailUnitProject.PlanValueRate = 0; BLL.WbsDetailService.UpdateWbsDetail(detailUnitProject); } if (unitProject.SuperUnitProjectId != null) //存在单位工程 { Model.Wbs_UnitProject parentUnitProject = BLL.UnitProjectService.GetUnitProjectByUnitProjectId(unitProject.SuperUnitProjectId); Model.WbsDetail detailParentUnitProject = BLL.WbsDetailService.GetWbsDetailByWbsFlagYearMonth(parentUnitProject.UnitProjectId, 3, month); if (detailParentUnitProject == null) { Model.WbsDetail newDetailParentUnitProject = new Model.WbsDetail(); newDetailParentUnitProject.WbsDetailId = SQLHelper.GetNewID(typeof(Model.WbsDetail)); newDetailParentUnitProject.ToWbs = parentUnitProject.UnitProjectId; newDetailParentUnitProject.ToFlag = 3; //单位工程 newDetailParentUnitProject.Way = "A"; newDetailParentUnitProject.Months = month; newDetailParentUnitProject.PlanValue = 0; newDetailParentUnitProject.PlanValueRate = 0; BLL.WbsDetailService.AddWbsDetail(newDetailParentUnitProject); } else { detailParentUnitProject.PlanValue += 0; detailParentUnitProject.PlanValueRate = 0; BLL.WbsDetailService.UpdateWbsDetail(detailParentUnitProject); } } } //保存对应专业 if (cnProfession != null) { Model.WbsDetail detailCnProfession = BLL.WbsDetailService.GetWbsDetailByWbsFlagYearMonth(cnProfession.CnProfessionId, 2, month); if (detailCnProfession == null) { Model.WbsDetail newDetailCnProfession = new Model.WbsDetail(); newDetailCnProfession.WbsDetailId = SQLHelper.GetNewID(typeof(Model.WbsDetail)); newDetailCnProfession.ToWbs = cnProfession.CnProfessionId; newDetailCnProfession.ToFlag = 2; //专业 newDetailCnProfession.Way = "A"; newDetailCnProfession.Months = month; newDetailCnProfession.PlanValue = 0; newDetailCnProfession.PlanValueRate = 0; BLL.WbsDetailService.AddWbsDetail(newDetailCnProfession); } else { detailCnProfession.PlanValue += 0; detailCnProfession.PlanValueRate = 0; BLL.WbsDetailService.UpdateWbsDetail(detailCnProfession); } //保存对应装置 if (installation != null) { Model.WbsDetail detailInstallation = BLL.WbsDetailService.GetWbsDetailByWbsFlagYearMonth(installation.InstallationId, 1, month); if (detailInstallation == null) { Model.WbsDetail newDetailInstallation = new Model.WbsDetail(); newDetailInstallation.WbsDetailId = SQLHelper.GetNewID(typeof(Model.WbsDetail)); newDetailInstallation.ToWbs = installation.InstallationId; newDetailInstallation.ToFlag = 1; //装置 newDetailInstallation.Way = "A"; newDetailInstallation.Months = month; newDetailInstallation.PlanValue = 0; newDetailInstallation.PlanValueRate = 0; BLL.WbsDetailService.AddWbsDetail(newDetailInstallation); } else { detailInstallation.PlanValue += 0; detailInstallation.PlanValueRate = 0; BLL.WbsDetailService.UpdateWbsDetail(detailInstallation); } } } } } #endregion Model.WbsDetail childDetail = BLL.WbsDetailService.GetWbsDetailByWbsFlagYearMonth(cnProfession.CnProfessionId, 2, month); if (childDetail != null) { List totalChildDetails = BLL.WbsDetailService.GetTotalWbsDetailsByYearMonth(cnProfession.CnProfessionId, 2, month); Model.WBSSetItem childItem = new Model.WBSSetItem(); childItem.Id = cnProfession.CnProfessionId; childItem.WbsDetailId = childDetail.WbsDetailId; childItem.ChildCode = cnProfession.CnProfessionCode; childItem.ChildName = cnProfession.CnProfessionName; childItem.Weights = cnProfession.Weights; childItem.WeightsMoney = cnProfession.WeightsMoney; childItem.WeightsMoneyStr = decimal.Round(Convert.ToDecimal(childItem.WeightsMoney), 2).ToString(); if (childDetail.CompleteValue != null) { childItem.CompleteValue = decimal.Round(Convert.ToDecimal(childDetail.CompleteValue), 2); childItem.CompleteValueRate = decimal.Round(Convert.ToDecimal(childDetail.CompleteValue) / Convert.ToDecimal(childItem.WeightsMoney) * 100, 2); } childItem.CompleteValueTotal = decimal.Round(Convert.ToDecimal(totalChildDetails.Sum(x => x.CompleteValue ?? 0)), 2); if (childItem.WeightsMoney > 0) { childItem.CompleteValueRateTotal = decimal.Round(Convert.ToDecimal(childItem.CompleteValueTotal) / Convert.ToDecimal(childItem.WeightsMoney) * 100, 2); } if (childDetail.RealValue != null) { childItem.RealValue = decimal.Round(Convert.ToDecimal(childDetail.RealValue), 2); } childItem.RealValueTotal = decimal.Round(Convert.ToDecimal(totalChildDetails.Sum(x => x.RealValue ?? 0)), 2); childItem.StartDate = cnProfession.StartDate; childItem.EndDate = cnProfession.EndDate; childItem.PlanValue = decimal.Round(Convert.ToDecimal(childDetail.PlanValue ?? 0), 2); childItem.PlanValueTotal = decimal.Round(Convert.ToDecimal(totalChildDetails.Sum(x => x.PlanValue ?? 0)), 2); if (childItem.WeightsMoney > 0) { childItem.PlanValueRateTotal = decimal.Round(Convert.ToDecimal(childItem.PlanValueTotal) / Convert.ToDecimal(childItem.WeightsMoney) * 100, 2); } childItem.SVValue = childItem.CompleteValueTotal - childItem.PlanValueTotal; childItem.CVValue = childItem.CompleteValueTotal - childItem.RealValueTotal; items.Add(childItem); } } } else { var installation2s = from x in Funs.DB.Project_Installation where x.SuperInstallationId == this.trWBS.SelectedNodeID orderby x.InstallationCode select x; foreach (var installation2 in installation2s) { Model.WbsDetail childDetail = BLL.WbsDetailService.GetWbsDetailByWbsFlagYearMonth(installation2.InstallationId, 1, month); if (childDetail != null) { List totalChildDetails = BLL.WbsDetailService.GetTotalWbsDetailsByYearMonth(installation2.InstallationId, 1, month); Model.WBSSetItem childItem = new Model.WBSSetItem(); childItem.Id = installation2.InstallationId; childItem.WbsDetailId = childDetail.WbsDetailId; childItem.ChildCode = installation2.InstallationCode; childItem.ChildName = installation2.InstallationName; childItem.Weights = installation2.Weights; childItem.WeightsMoney = installation2.WeightsMoney; childItem.WeightsMoneyStr = decimal.Round(Convert.ToDecimal(childItem.WeightsMoney), 2).ToString(); if (childDetail.CompleteValue != null) { childItem.CompleteValue = decimal.Round(Convert.ToDecimal(childDetail.CompleteValue), 2); childItem.CompleteValueRate = decimal.Round(Convert.ToDecimal(childDetail.CompleteValue) / Convert.ToDecimal(childItem.WeightsMoney) * 100, 2); } childItem.CompleteValueTotal = decimal.Round(Convert.ToDecimal(totalChildDetails.Sum(x => x.CompleteValue ?? 0)), 2); if (childItem.WeightsMoney > 0) { childItem.CompleteValueRateTotal = decimal.Round(Convert.ToDecimal(childItem.CompleteValueTotal) / Convert.ToDecimal(childItem.WeightsMoney) * 100, 2); } if (childDetail.RealValue != null) { childItem.RealValue = decimal.Round(Convert.ToDecimal(childDetail.RealValue), 2); } childItem.RealValueTotal = decimal.Round(Convert.ToDecimal(totalChildDetails.Sum(x => x.RealValue ?? 0)), 2); childItem.StartDate = installation2.StartDate; childItem.EndDate = installation2.EndDate; childItem.PlanValue = decimal.Round(Convert.ToDecimal(childDetail.PlanValue ?? 0), 2); childItem.PlanValueTotal = decimal.Round(Convert.ToDecimal(totalChildDetails.Sum(x => x.PlanValue ?? 0)), 2); if (childItem.WeightsMoney > 0) { childItem.PlanValueRateTotal = decimal.Round(Convert.ToDecimal(childItem.PlanValueTotal) / Convert.ToDecimal(childItem.WeightsMoney) * 100, 2); } childItem.SVValue = childItem.CompleteValueTotal - childItem.PlanValueTotal; childItem.CVValue = childItem.CompleteValueTotal - childItem.RealValueTotal; items.Add(childItem); } } } } else { var installation1s = from x in Funs.DB.Project_Installation where x.SuperInstallationId == this.trWBS.SelectedNodeID orderby x.InstallationCode select x; if (installation1s.Count() > 0) //普通装置 { foreach (var installation1 in installation1s) { Model.WbsDetail childDetail = BLL.WbsDetailService.GetWbsDetailByWbsFlagYearMonth(installation1.InstallationId, 1, month); if (childDetail != null) { List totalChildDetails = BLL.WbsDetailService.GetTotalWbsDetailsByYearMonth(installation1.InstallationId, 1, month); Model.WBSSetItem childItem = new Model.WBSSetItem(); childItem.Id = installation1.InstallationId; childItem.WbsDetailId = childDetail.WbsDetailId; childItem.ChildCode = installation1.InstallationCode; childItem.ChildName = installation1.InstallationName; childItem.Weights = installation1.Weights; childItem.WeightsMoney = installation1.WeightsMoney; childItem.WeightsMoneyStr = decimal.Round(Convert.ToDecimal(childItem.WeightsMoney), 2).ToString(); if (childDetail.CompleteValue != null) { childItem.CompleteValue = decimal.Round(Convert.ToDecimal(childDetail.CompleteValue), 2); childItem.CompleteValueRate = decimal.Round(Convert.ToDecimal(childDetail.CompleteValue) / Convert.ToDecimal(childItem.WeightsMoney) * 100, 2); } childItem.CompleteValueTotal = decimal.Round(Convert.ToDecimal(totalChildDetails.Sum(x => x.CompleteValue ?? 0)), 2); if (childItem.WeightsMoney > 0) { childItem.CompleteValueRateTotal = decimal.Round(Convert.ToDecimal(childItem.CompleteValueTotal) / Convert.ToDecimal(childItem.WeightsMoney) * 100, 2); } if (childDetail.RealValue != null) { childItem.RealValue = decimal.Round(Convert.ToDecimal(childDetail.RealValue), 2); } childItem.RealValueTotal = decimal.Round(Convert.ToDecimal(totalChildDetails.Sum(x => x.RealValue ?? 0)), 2); childItem.StartDate = installation1.StartDate; childItem.EndDate = installation1.EndDate; childItem.PlanValue = decimal.Round(Convert.ToDecimal(childDetail.PlanValue ?? 0), 2); childItem.PlanValueTotal = decimal.Round(Convert.ToDecimal(totalChildDetails.Sum(x => x.PlanValue ?? 0)), 2); if (childItem.WeightsMoney > 0) { childItem.PlanValueRateTotal = decimal.Round(Convert.ToDecimal(childItem.PlanValueTotal) / Convert.ToDecimal(childItem.WeightsMoney) * 100, 2); } childItem.SVValue = childItem.CompleteValueTotal - childItem.PlanValueTotal; childItem.CVValue = childItem.CompleteValueTotal - childItem.RealValueTotal; items.Add(childItem); } } } else //总图 { var unitProjects = from x in Funs.DB.Wbs_UnitProject where x.InstallationId == this.trWBS.SelectedNodeID orderby x.UnitProjectCode select x; foreach (var unitProject in unitProjects) { Model.WbsDetail childDetail = BLL.WbsDetailService.GetWbsDetailByWbsFlagYearMonth(unitProject.UnitProjectId, 3, month); if (childDetail != null) { List totalChildDetails = BLL.WbsDetailService.GetTotalWbsDetailsByYearMonth(unitProject.UnitProjectId, 3, month); Model.WBSSetItem childItem = new Model.WBSSetItem(); childItem.Id = unitProject.UnitProjectId; childItem.WbsDetailId = childDetail.WbsDetailId; childItem.ChildCode = unitProject.UnitProjectCode; childItem.ChildName = unitProject.UnitProjectName; childItem.Weights = unitProject.Weights; childItem.WeightsMoney = unitProject.WeightsMoney; childItem.WeightsMoneyStr = decimal.Round(Convert.ToDecimal(childItem.WeightsMoney), 2).ToString(); if (childDetail.CompleteValue != null) { childItem.CompleteValue = decimal.Round(Convert.ToDecimal(childDetail.CompleteValue), 2); childItem.CompleteValueRate = decimal.Round(Convert.ToDecimal(childDetail.CompleteValue) / Convert.ToDecimal(childItem.WeightsMoney) * 100, 2); } childItem.CompleteValueTotal = decimal.Round(Convert.ToDecimal(totalChildDetails.Sum(x => x.CompleteValue ?? 0)), 2); if (childItem.WeightsMoney > 0) { childItem.CompleteValueRateTotal = decimal.Round(Convert.ToDecimal(childItem.CompleteValueTotal) / Convert.ToDecimal(childItem.WeightsMoney) * 100, 2); } if (childDetail.RealValue != null) { childItem.RealValue = decimal.Round(Convert.ToDecimal(childDetail.RealValue), 2); } childItem.RealValueTotal = decimal.Round(Convert.ToDecimal(totalChildDetails.Sum(x => x.RealValue ?? 0)), 2); childItem.StartDate = unitProject.StartDate; childItem.EndDate = unitProject.EndDate; childItem.PlanValue = decimal.Round(Convert.ToDecimal(childDetail.PlanValue ?? 0), 2); childItem.PlanValueTotal = decimal.Round(Convert.ToDecimal(totalChildDetails.Sum(x => x.PlanValue ?? 0)), 2); if (childItem.WeightsMoney > 0) { childItem.PlanValueRateTotal = decimal.Round(Convert.ToDecimal(childItem.PlanValueTotal) / Convert.ToDecimal(childItem.WeightsMoney) * 100, 2); } childItem.SVValue = childItem.CompleteValueTotal - childItem.PlanValueTotal; childItem.CVValue = childItem.CompleteValueTotal - childItem.RealValueTotal; items.Add(childItem); } } } } } } #endregion this.Grid1.DataSource = items; this.Grid1.DataBind(); if (this.trWBS.SelectedNode.CommandName == "wbsSet") { int notEndLevel = 0; //子级集合中的末级数量 for (int i = 1; i < this.Grid1.Rows.Count; i++) { string wbsDetailId = this.Grid1.Rows[i].DataKeys[0].ToString(); Model.WbsDetail wbsDetail = BLL.WbsDetailService.GetWbsDetailByWbsDetailId(wbsDetailId); if (wbsDetail != null) { List childWbsSets = BLL.WbsSetService.GetApproveWbsSetsBySuperWbsSetId(wbsDetail.ToWbs); if (childWbsSets.Count > 0) { Grid1.Rows[i].CellCssClasses[14] = "f-grid-cell-uneditable"; Grid1.Rows[i].CellCssClasses[15] = "f-grid-cell-uneditable"; Grid1.Rows[i].CellCssClasses[19] = "f-grid-cell-uneditable"; notEndLevel++; } } } if (notEndLevel == (this.Grid1.Rows.Count - 1)) //所有grid子集项均为含有末级的项 { showSave = false; } if (showSave) { this.btnSave1.Hidden = false; } } for (int i = 1; i < this.Grid1.Rows.Count; i++) { if ((Funs.GetNewDecimalOrZero(Grid1.Rows[i].Values[30].ToString()) + Funs.GetNewDecimalOrZero(Grid1.Rows[i].Values[14].ToString())) < Funs.GetNewDecimalOrZero(Grid1.Rows[i].Values[29].ToString()) && Convert.ToDateTime(Grid1.Rows[i].Values[26].ToString()) < month) //计划已结束但尚未完成的项红色提醒 { Grid1.Rows[i].RowCssClass = "red"; } if (Convert.ToDateTime(Grid1.Rows[i].Values[25].ToString()) >= month.AddMonths(1)) //计划尚未开始的项底色为灰 { Grid1.Rows[i].RowCssClass = "hui"; } if ((Funs.GetNewDecimalOrZero(Grid1.Rows[i].Values[30].ToString()) + Funs.GetNewDecimalOrZero(Grid1.Rows[i].Values[14].ToString())) == Funs.GetNewDecimalOrZero(Grid1.Rows[i].Values[29].ToString())) ////之前累计完成值+当月值等于总计划费用的项绿色提醒 { Grid1.Rows[i].RowCssClass = "green"; } } for (int i = 0; i < this.Grid1.Rows.Count; i++) { if (i == 0) { Grid1.Rows[i].CellCssClasses[12] = "f-grid-cell-uneditable"; } Grid1.Rows[i].CellCssClasses[14] = "f-grid-cell-uneditable"; Grid1.Rows[i].CellCssClasses[15] = "f-grid-cell-uneditable"; Grid1.Rows[i].CellCssClasses[19] = "f-grid-cell-uneditable"; } } } else { Alert.ShowInTop("请选择月份!", MessageBoxIcon.Warning); return; } } #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 月份选择事件 /// /// 月份选择事件 /// /// /// protected void txtMonths_TextChanged(object sender, EventArgs e) { GetNoApproveIds(); InitTreeMenu(); BindGrid(); } #endregion #region 修正完成值 protected void btnMenuCorrect_Click(object sender, EventArgs e) { if (this.trWBS.SelectedNode.CommandName == "unitProject") { Model.Wbs_UnitProject unitProject = BLL.UnitProjectService.GetUnitProjectByUnitProjectId(this.trWBS.SelectedNodeID); var wbsSets = from x in Funs.DB.Wbs_WbsSet where x.SuperWbsSetId == null && x.UnitProjectId == this.trWBS.SelectedNodeID select x; foreach (var wbsSet in wbsSets) { } } else { Alert.ShowInTop("请选择单位工程进行操作!", MessageBoxIcon.Warning); return; } } #endregion } }