3043 lines
		
	
	
		
			250 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			3043 lines
		
	
	
		
			250 KiB
		
	
	
	
		
			C#
		
	
	
	
| using System;
 | |
| using System.Collections.Generic;
 | |
| using System.Data;
 | |
| using System.Linq;
 | |
| 
 | |
| namespace BLL
 | |
| {
 | |
|     public static class WorkloadStatisticsService
 | |
|     {
 | |
|         public static Model.SGGLDB db = Funs.DB;
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 获取模拟树表格
 | |
|         /// </summary> 
 | |
|         /// <returns></returns>
 | |
|         public static DataTable GetTreeDataTable(string projectId, DateTime months, string startDate, string cnProfessionId, string unitProjectCode, string wbsSetCode, string equipmentMaterialType)
 | |
|         {
 | |
|             List<Model.View_WBS_CostControlDetailStatistics> CostControlDetailStatisticsList = new List<Model.View_WBS_CostControlDetailStatistics>();
 | |
|             DataTable table = new DataTable();
 | |
|             table.Columns.Add(new DataColumn("Id", typeof(String)));
 | |
|             table.Columns.Add(new DataColumn("SupId", typeof(String)));
 | |
|             table.Columns.Add(new DataColumn("Name", typeof(String)));
 | |
|             table.Columns.Add(new DataColumn("ProjectId", typeof(String)));
 | |
|             table.Columns.Add(new DataColumn("Unit", typeof(String)));
 | |
|             table.Columns.Add(new DataColumn("TotalNum", typeof(String)));
 | |
|             table.Columns.Add(new DataColumn("RealPrice", typeof(String)));
 | |
|             table.Columns.Add(new DataColumn("PlanNum", typeof(String)));
 | |
|             table.Columns.Add(new DataColumn("ThisNum", typeof(String)));
 | |
|             table.Columns.Add(new DataColumn("PlanPrice", typeof(String)));
 | |
|             table.Columns.Add(new DataColumn("ThisRealCost", typeof(String)));
 | |
|             table.Columns.Add(new DataColumn("ThisPlanValue", typeof(String)));
 | |
|             table.Columns.Add(new DataColumn("ThisPlanCost", typeof(String)));
 | |
|             table.Columns.Add(new DataColumn("TotalPlanNum", typeof(String)));
 | |
|             table.Columns.Add(new DataColumn("TotalThisNum", typeof(String)));
 | |
|             table.Columns.Add(new DataColumn("TotalRealCost", typeof(String)));
 | |
|             table.Columns.Add(new DataColumn("TotalPlanValue", typeof(String)));
 | |
|             table.Columns.Add(new DataColumn("TotalPlanCost", typeof(String)));
 | |
|             Model.SGGLDB db = Funs.DB;
 | |
|             var costControls = from x in db.WBS_CostControl where x.ProjectId == projectId where x.IsSelected == true select x;
 | |
|             var details = from x in db.View_WBS_CostControlDetail where x.ProjectId == projectId select x;
 | |
|             var parentDetails = from x in db.View_WBS_CostControlParentDetail select x;
 | |
|             var wbsSets = from x in db.Wbs_WbsSet where x.ProjectId == projectId select x;
 | |
|             var wbsSetInits = from x in db.WBS_WbsSetInit select x;
 | |
|             var unitProjects = from x in db.Wbs_UnitProject where x.ProjectId == projectId select x;
 | |
|             var unitProjectInits = from x in db.Wbs_UnitProjectInit select x;
 | |
|             var cnProfessions = from x in db.WBS_CnProfession where x.ProjectId == projectId select x;
 | |
|             var cnProfessionInits = from x in db.WBS_CnProfessionInit select x;
 | |
|             var installations = from x in db.Project_Installation where x.ProjectId == projectId select x;
 | |
|             var totalEquipmentMaterialTypes = from x in db.WBS_EquipmentMaterialType
 | |
|                                               join y in db.WBS_EquipmentMaterialBigType
 | |
|                                               on x.EquipmentMaterialBigTypeId equals y.EquipmentMaterialBigTypeId
 | |
|                                               orderby x.EquipmentMaterialTypeCode
 | |
|                                               select new
 | |
|                                               {
 | |
|                                                   x.EquipmentMaterialTypeId,
 | |
|                                                   x.EquipmentMaterialTypeName,
 | |
|                                                   x.EquipmentMaterialBigTypeId,
 | |
|                                                   y.CnProfessionId,
 | |
|                                               };
 | |
|             CostControlDetailStatisticsList = (from x in db.View_WBS_CostControlDetailStatistics where x.ProjectId == projectId select x).Distinct().ToList();
 | |
|             List<Model.View_WBS_CostControlDetailStatistics> newList = new List<Model.View_WBS_CostControlDetailStatistics>();
 | |
|             var installationList = CostControlDetailStatisticsList.Where(x => x.WBSType == "Installation" && x.SupId == "0");
 | |
|             foreach (var item in installationList)
 | |
|             {
 | |
|                 newList.Add(item);
 | |
|                 AddDetail(newList, CostControlDetailStatisticsList, item.Id);
 | |
|             }
 | |
|             DataRow row; DataRow parentRow;
 | |
|             #region  按月统计
 | |
|             if (startDate == BLL.Const._Null)
 | |
|             {
 | |
|                 #region 全部统计
 | |
|                 if (cnProfessionId == BLL.Const._Null)   //全部统计
 | |
|                 {
 | |
|                     if (string.IsNullOrEmpty(equipmentMaterialType))
 | |
|                     {
 | |
|                         foreach (Model.View_WBS_CostControlDetailStatistics item in newList)
 | |
|                         {
 | |
|                             row = table.NewRow();
 | |
|                             row[0] = item.Id;
 | |
|                             row[1] = item.SupId;
 | |
|                             row[2] = item.Name;
 | |
|                             row[3] = item.ProjectId;
 | |
|                             Model.WBS_CostControl costControl = costControls.FirstOrDefault(x => x.CostControlId == item.Id);
 | |
|                             if (costControl != null)
 | |
|                             {
 | |
|                                 Model.View_WBS_CostControlDetail detail = details.FirstOrDefault(x => x.CostControlId == item.Id && x.Months == months);
 | |
|                                 if (detail != null)
 | |
|                                 {
 | |
|                                     row[4] = detail.Unit;//单位
 | |
|                                     row[5] = decimal.Round(Convert.ToDecimal(detail.TotalNum), 2);//合同工作量
 | |
|                                     row[6] = decimal.Round(Convert.ToDecimal(detail.RealPrice), 2);//成本单价
 | |
|                                     row[7] = decimal.Round(Convert.ToDecimal(detail.PlanNum), 2);//本月计划完成量
 | |
|                                     row[8] = decimal.Round(Convert.ToDecimal(detail.ThisNum), 2);//本月完成量
 | |
|                                     row[9] = decimal.Round(Convert.ToDecimal(detail.PlanPrice), 2);//控制预算单价
 | |
|                                     row[10] = decimal.Round(Convert.ToDecimal(detail.ThisRealCost), 2);//本月实际成本
 | |
|                                     row[11] = decimal.Round(Convert.ToDecimal(detail.ThisPlanValue), 2);//本月计划完成预算
 | |
|                                     row[12] = decimal.Round(Convert.ToDecimal(detail.ThisPlanCost), 2);//本月完成预算
 | |
|                                     row[13] = decimal.Round(Convert.ToDecimal(detail.TotalPlanNum), 2);//累计计划完成量
 | |
|                                     row[14] = decimal.Round(Convert.ToDecimal(detail.TotalThisNum), 2);//累计完成量
 | |
|                                     row[15] = decimal.Round(Convert.ToDecimal(detail.TotalRealCost), 2);//累计完成成本
 | |
|                                     row[16] = decimal.Round(Convert.ToDecimal(detail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                     row[17] = decimal.Round(Convert.ToDecimal(detail.TotalPlanCost), 2);//累计完成预算
 | |
|                                 }
 | |
|                                 else
 | |
|                                 {
 | |
|                                     Model.View_WBS_CostControlDetail lastDetail = details.OrderByDescending(x => x.Months).FirstOrDefault(x => x.CostControlId == item.Id);
 | |
|                                     if (lastDetail != null && lastDetail.Months <= months)
 | |
|                                     {
 | |
|                                         row[4] = lastDetail.Unit;//单位
 | |
|                                         row[5] = decimal.Round(Convert.ToDecimal(lastDetail.TotalNum), 2);//合同工作量
 | |
|                                         row[6] = decimal.Round(Convert.ToDecimal(lastDetail.RealPrice), 2);//成本单价
 | |
|                                         row[7] = decimal.Round(Convert.ToDecimal(lastDetail.PlanNum), 2);//本月计划完成量
 | |
|                                         row[8] = decimal.Round(Convert.ToDecimal(lastDetail.ThisNum), 2);//本月完成量
 | |
|                                         row[9] = decimal.Round(Convert.ToDecimal(lastDetail.PlanPrice), 2);//控制预算单价
 | |
|                                         row[13] = decimal.Round(Convert.ToDecimal(lastDetail.TotalPlanNum), 2);//累计计划完成量
 | |
|                                         row[14] = decimal.Round(Convert.ToDecimal(lastDetail.TotalThisNum), 2);//累计完成量
 | |
|                                         row[15] = decimal.Round(Convert.ToDecimal(lastDetail.TotalRealCost), 2);//累计完成成本
 | |
|                                         row[16] = decimal.Round(Convert.ToDecimal(lastDetail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                         row[17] = decimal.Round(Convert.ToDecimal(lastDetail.TotalPlanCost), 2);//累计完成预算
 | |
|                                     }
 | |
|                                 }
 | |
|                             }
 | |
|                             else
 | |
|                             {
 | |
|                                 Model.View_WBS_CostControlParentDetail parentDetail = parentDetails.FirstOrDefault(x => x.ParentId == item.Id && x.Months == months);
 | |
|                                 if (parentDetail != null)
 | |
|                                 {
 | |
|                                     row[10] = decimal.Round(Convert.ToDecimal(parentDetail.ThisRealCost), 2);//本月实际成本
 | |
|                                     row[11] = decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanValue), 2);//本月计划完成预算
 | |
|                                     row[12] = decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanCost), 2);//本月完成预算
 | |
|                                     row[15] = decimal.Round(Convert.ToDecimal(parentDetail.TotalRealCost), 2);//累计完成成本
 | |
|                                     row[16] = decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                     row[17] = decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanCost), 2);//累计完成预算
 | |
|                                 }
 | |
|                                 else
 | |
|                                 {
 | |
|                                     Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).FirstOrDefault(x => x.ParentId == item.Id);
 | |
|                                     if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                     {
 | |
|                                         row[15] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalRealCost), 2);//累计完成成本
 | |
|                                         row[16] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                         row[17] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanCost), 2);//累计完成预算
 | |
|                                     }
 | |
|                                 }
 | |
|                             }
 | |
|                             table.Rows.Add(row);
 | |
|                         }
 | |
|                     }
 | |
|                     else
 | |
|                     {
 | |
|                         var equipmentMaterialTypes = totalEquipmentMaterialTypes.Where(x => x.EquipmentMaterialTypeName.Contains(equipmentMaterialType));
 | |
|                         var equipmentMaterialTypeList = newList.Where(x => x.EquipmentMaterialTypeName.Contains(equipmentMaterialType));
 | |
|                         if (equipmentMaterialTypeList.Count() > 0)
 | |
|                         {
 | |
|                             parentRow = table.NewRow();
 | |
|                             parentRow[0] = equipmentMaterialType;
 | |
|                             parentRow[1] = "0";
 | |
|                             parentRow[2] = equipmentMaterialType;
 | |
|                             parentRow[3] = projectId;
 | |
|                             var costControl = costControls.FirstOrDefault(x => x.CostControlId == equipmentMaterialTypeList.First().Id);
 | |
|                             if (costControl != null)
 | |
|                             {
 | |
|                                 parentRow[4] = costControl.Unit;//单位
 | |
|                             }
 | |
|                             var costControlList = from x in costControls
 | |
|                                                   join y in db.WBS_EquipmentMaterialType
 | |
|                                                   on x.EquipmentMaterialTypeId equals y.EquipmentMaterialTypeId
 | |
|                                                   where y.EquipmentMaterialTypeName.Contains(equipmentMaterialType)
 | |
|                                                   select x;
 | |
|                             var costControlIdList = costControlList.Select(x => x.CostControlId).ToList();
 | |
|                             List<string> ids = new List<string>();
 | |
|                             foreach (var costControlItem in costControlList)   //获取所有关联费控清单的父级节点Id
 | |
|                             {
 | |
|                                 Model.Wbs_WbsSet wbsSet = BLL.WbsSetService.GetWbsSetByWbsSetId(costControlItem.WbsSetId);
 | |
|                                 GetAllWbsIds(ids, costControlItem.WbsSetId);
 | |
|                                 ids.Add(wbsSet.UnitProjectId);
 | |
|                                 ids.Add(wbsSet.CnProfessionId);
 | |
|                                 GetAllInsIds(ids, wbsSet.InstallationId);
 | |
|                             }
 | |
|                             ids.AddRange(costControlIdList);
 | |
|                             var parDetails = details.Where(x => costControlIdList.Contains(x.CostControlId) && x.Months == months);
 | |
|                             parentRow[5] = decimal.Round(costControlList.Sum(x => Convert.ToDecimal(x.TotalNum ?? 0)), 2);//合同工作量
 | |
|                             //parentRow[6] = decimal.Round(Convert.ToDecimal(detail.RealPrice), 2);//成本单价
 | |
|                             parentRow[7] = decimal.Round(parDetails.Sum(x => Convert.ToDecimal(x.PlanNum ?? 0)), 2);//本月计划完成量
 | |
|                             parentRow[8] = decimal.Round(parDetails.Sum(x => Convert.ToDecimal(x.ThisNum ?? 0)), 2);//本月完成量
 | |
|                             //parentRow[9] = decimal.Round(Convert.ToDecimal(detail.PlanPrice), 2);//控制预算单价
 | |
|                             parentRow[10] = decimal.Round(parDetails.Sum(x => Convert.ToDecimal(x.ThisRealCost ?? 0)), 2);//本月实际成本
 | |
|                             parentRow[11] = decimal.Round(parDetails.Sum(x => Convert.ToDecimal(x.ThisPlanValue ?? 0)), 2);//本月计划完成预算
 | |
|                             parentRow[12] = decimal.Round(parDetails.Sum(x => Convert.ToDecimal(x.ThisPlanCost ?? 0)), 2);//本月完成预算
 | |
|                             parentRow[13] = decimal.Round(parDetails.Sum(x => Convert.ToDecimal(x.TotalPlanNum ?? 0)), 2);//累计计划完成量
 | |
|                             parentRow[14] = decimal.Round(parDetails.Sum(x => Convert.ToDecimal(x.TotalThisNum ?? 0)), 2);//累计完成量
 | |
|                             parentRow[15] = decimal.Round(parDetails.Sum(x => Convert.ToDecimal(x.TotalRealCost ?? 0)), 2);//累计完成成本
 | |
|                             parentRow[16] = decimal.Round(parDetails.Sum(x => Convert.ToDecimal(x.TotalPlanValue ?? 0)), 2);//累计计划完成预算
 | |
|                             parentRow[17] = decimal.Round(parDetails.Sum(x => Convert.ToDecimal(x.TotalPlanCost ?? 0)), 2);//累计完成预算
 | |
|                             table.Rows.Add(parentRow);
 | |
|                             foreach (Model.View_WBS_CostControlDetailStatistics item in newList)
 | |
|                             {
 | |
|                                 if (ids.Contains(item.Id))
 | |
|                                 {
 | |
|                                     row = table.NewRow();
 | |
|                                     row[0] = item.Id;
 | |
|                                     row[2] = item.Name;
 | |
|                                     row[3] = item.ProjectId;
 | |
|                                     if (item.WBSType == "Installation")
 | |
|                                     {
 | |
|                                         decimal ind10 = 0, ind11 = 0, ind12 = 0, ind15 = 0, ind16 = 0, ind17 = 0;
 | |
|                                         if (item.SupId == "0")
 | |
|                                         {
 | |
|                                             row[1] = equipmentMaterialType;
 | |
|                                         }
 | |
|                                         else
 | |
|                                         {
 | |
|                                             row[1] = item.SupId;
 | |
|                                         }
 | |
|                                         List<string> cnIds = BLL.CnProfessionService.GetCnProfessionIdsByInstallationIdAndOldId(item.Id, cnProfessionId);
 | |
|                                         foreach (var cnId in cnIds)
 | |
|                                         {
 | |
|                                             Model.View_WBS_CostControlParentDetail parentDetail = parentDetails.FirstOrDefault(x => x.ParentId == cnId && x.Months == months);
 | |
|                                             if (parentDetail != null)
 | |
|                                             {
 | |
|                                                 ind10 += decimal.Round(Convert.ToDecimal(parentDetail.ThisRealCost), 2);
 | |
|                                                 ind11 += decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanValue), 2);
 | |
|                                                 ind12 += decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanCost), 2);
 | |
|                                                 ind15 += decimal.Round(Convert.ToDecimal(parentDetail.TotalRealCost), 2);
 | |
|                                                 ind16 += decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanValue), 2);
 | |
|                                                 ind17 += decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanCost), 2);
 | |
|                                             }
 | |
|                                             else
 | |
|                                             {
 | |
|                                                 Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).FirstOrDefault(x => x.ParentId == cnId);
 | |
|                                                 if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                                 {
 | |
|                                                     ind15 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalRealCost), 2);
 | |
|                                                     ind16 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanValue), 2);
 | |
|                                                     ind17 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanCost), 2);
 | |
|                                                 }
 | |
|                                             }
 | |
|                                         }
 | |
|                                         if (ind10 != 0)
 | |
|                                         {
 | |
|                                             row[10] = decimal.Round(ind10, 2);//本月实际成本
 | |
|                                             row[11] = decimal.Round(ind11, 2);//本月计划完成预算
 | |
|                                             row[12] = decimal.Round(ind12, 2);//本月完成预算
 | |
|                                             row[15] = decimal.Round(ind15, 2);//累计完成成本
 | |
|                                             row[16] = decimal.Round(ind16, 2);//累计计划完成预算
 | |
|                                             row[17] = decimal.Round(ind17, 2);//累计完成预算
 | |
|                                         }
 | |
|                                         else
 | |
|                                         {
 | |
|                                             if (ind15 > 0)
 | |
|                                             {
 | |
|                                                 row[15] = decimal.Round(ind15, 2);//累计完成成本
 | |
|                                             }
 | |
|                                             if (ind16 > 0)
 | |
|                                             {
 | |
|                                                 row[16] = decimal.Round(ind16, 2);//累计计划完成预算
 | |
|                                             }
 | |
|                                             if (ind17 > 0)
 | |
|                                             {
 | |
|                                                 row[17] = decimal.Round(ind17, 2);//累计完成预算
 | |
|                                             }
 | |
|                                         }
 | |
|                                     }
 | |
|                                     else if (item.WBSType == "CnProfession")
 | |
|                                     {
 | |
|                                         row[1] = item.SupId;
 | |
|                                         Model.View_WBS_CostControlParentDetail parentDetail = parentDetails.FirstOrDefault(x => x.ParentId == item.Id && x.Months == months);
 | |
|                                         if (parentDetail != null)
 | |
|                                         {
 | |
|                                             row[10] = decimal.Round(Convert.ToDecimal(parentDetail.ThisRealCost), 2);//本月实际成本
 | |
|                                             row[11] = decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanValue), 2);//本月计划完成预算
 | |
|                                             row[12] = decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanCost), 2);//本月完成预算
 | |
|                                             row[15] = decimal.Round(Convert.ToDecimal(parentDetail.TotalRealCost), 2);//累计完成成本
 | |
|                                             row[16] = decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                             row[17] = decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanCost), 2);//累计完成预算
 | |
|                                         }
 | |
|                                         else
 | |
|                                         {
 | |
|                                             Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).FirstOrDefault(x => x.ParentId == item.Id);
 | |
|                                             if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                             {
 | |
|                                                 row[15] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalRealCost), 2);//累计完成成本
 | |
|                                                 row[16] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                                 row[17] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanCost), 2);//累计完成预算
 | |
|                                             }
 | |
|                                         }
 | |
|                                     }
 | |
|                                     else if (item.WBSType == "UnitProject")
 | |
|                                     {
 | |
|                                         row[1] = item.SupId;
 | |
|                                         Model.View_WBS_CostControlParentDetail parentDetail = parentDetails.FirstOrDefault(x => x.ParentId == item.Id && x.Months == months);
 | |
|                                         if (parentDetail != null)
 | |
|                                         {
 | |
|                                             row[10] = decimal.Round(Convert.ToDecimal(parentDetail.ThisRealCost), 2);//本月实际成本
 | |
|                                             row[11] = decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanValue), 2);//本月计划完成预算
 | |
|                                             row[12] = decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanCost), 2);//本月完成预算
 | |
|                                             row[15] = decimal.Round(Convert.ToDecimal(parentDetail.TotalRealCost), 2);//累计完成成本
 | |
|                                             row[16] = decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                             row[17] = decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanCost), 2);//累计完成预算
 | |
|                                         }
 | |
|                                         else
 | |
|                                         {
 | |
|                                             Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).FirstOrDefault(x => x.ParentId == item.Id);
 | |
|                                             if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                             {
 | |
|                                                 row[15] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalRealCost), 2);//累计完成成本
 | |
|                                                 row[16] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                                 row[17] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanCost), 2);//累计完成预算
 | |
|                                             }
 | |
|                                         }
 | |
|                                     }
 | |
|                                     else if (item.WBSType == "WbsSet")
 | |
|                                     {
 | |
|                                         row[1] = item.SupId;
 | |
|                                         Model.View_WBS_CostControlParentDetail parentDetail = parentDetails.FirstOrDefault(x => x.ParentId == item.Id && x.Months == months);
 | |
|                                         if (parentDetail != null)
 | |
|                                         {
 | |
|                                             row[10] = decimal.Round(Convert.ToDecimal(parentDetail.ThisRealCost), 2);//本月实际成本
 | |
|                                             row[11] = decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanValue), 2);//本月计划完成预算
 | |
|                                             row[12] = decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanCost), 2);//本月完成预算
 | |
|                                             row[15] = decimal.Round(Convert.ToDecimal(parentDetail.TotalRealCost), 2);//累计完成成本
 | |
|                                             row[16] = decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                             row[17] = decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanCost), 2);//累计完成预算
 | |
|                                         }
 | |
|                                         else
 | |
|                                         {
 | |
|                                             Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).FirstOrDefault(x => x.ParentId == item.Id);
 | |
|                                             if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                             {
 | |
|                                                 row[15] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalRealCost), 2);//累计完成成本
 | |
|                                                 row[16] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                                 row[17] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanCost), 2);//累计完成预算
 | |
|                                             }
 | |
|                                         }
 | |
|                                     }
 | |
|                                     else if (item.WBSType == "CostControl")
 | |
|                                     {
 | |
|                                         row[1] = item.SupId;
 | |
|                                         Model.View_WBS_CostControlDetail detail = details.FirstOrDefault(x => x.CostControlId == item.Id && x.Months == months);
 | |
|                                         if (detail != null)
 | |
|                                         {
 | |
|                                             row[4] = detail.Unit;//单位
 | |
|                                             row[5] = decimal.Round(Convert.ToDecimal(detail.TotalNum), 2);//合同工作量
 | |
|                                             row[6] = decimal.Round(Convert.ToDecimal(detail.RealPrice), 2);//成本单价
 | |
|                                             row[7] = decimal.Round(Convert.ToDecimal(detail.PlanNum), 2);//本月计划完成量
 | |
|                                             row[8] = decimal.Round(Convert.ToDecimal(detail.ThisNum), 2);//本月完成量
 | |
|                                             row[9] = decimal.Round(Convert.ToDecimal(detail.PlanPrice), 2);//控制预算单价
 | |
|                                             row[10] = decimal.Round(Convert.ToDecimal(detail.ThisRealCost), 2);//本月实际成本
 | |
|                                             row[11] = decimal.Round(Convert.ToDecimal(detail.ThisPlanValue), 2);//本月计划完成预算
 | |
|                                             row[12] = decimal.Round(Convert.ToDecimal(detail.ThisPlanCost), 2);//本月完成预算
 | |
|                                             row[13] = decimal.Round(Convert.ToDecimal(detail.TotalPlanNum), 2);//累计计划完成量
 | |
|                                             row[14] = decimal.Round(Convert.ToDecimal(detail.TotalThisNum), 2);//累计完成量
 | |
|                                             row[15] = decimal.Round(Convert.ToDecimal(detail.TotalRealCost), 2);//累计完成成本
 | |
|                                             row[16] = decimal.Round(Convert.ToDecimal(detail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                             row[17] = decimal.Round(Convert.ToDecimal(detail.TotalPlanCost), 2);//累计完成预算
 | |
|                                         }
 | |
|                                         else
 | |
|                                         {
 | |
|                                             Model.View_WBS_CostControlDetail lastDetail = details.OrderByDescending(x => x.Months).FirstOrDefault(x => x.CostControlId == item.Id);
 | |
|                                             if (lastDetail != null && lastDetail.Months <= months)
 | |
|                                             {
 | |
|                                                 row[4] = lastDetail.Unit;//单位
 | |
|                                                 row[5] = decimal.Round(Convert.ToDecimal(lastDetail.TotalNum), 2);//合同工作量
 | |
|                                                 row[6] = decimal.Round(Convert.ToDecimal(lastDetail.RealPrice), 2);//成本单价
 | |
|                                                 row[7] = decimal.Round(Convert.ToDecimal(lastDetail.PlanNum), 2);//本月计划完成量
 | |
|                                                 row[8] = decimal.Round(Convert.ToDecimal(lastDetail.ThisNum), 2);//本月完成量
 | |
|                                                 row[9] = decimal.Round(Convert.ToDecimal(lastDetail.PlanPrice), 2);//控制预算单价
 | |
|                                                 row[13] = decimal.Round(Convert.ToDecimal(lastDetail.TotalPlanNum), 2);//累计计划完成量
 | |
|                                                 row[14] = decimal.Round(Convert.ToDecimal(lastDetail.TotalThisNum), 2);//累计完成量
 | |
|                                                 row[15] = decimal.Round(Convert.ToDecimal(lastDetail.TotalRealCost), 2);//累计完成成本
 | |
|                                                 row[16] = decimal.Round(Convert.ToDecimal(lastDetail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                                 row[17] = decimal.Round(Convert.ToDecimal(lastDetail.TotalPlanCost), 2);//累计完成预算
 | |
|                                             }
 | |
|                                         }
 | |
|                                     }
 | |
|                                     table.Rows.Add(row);
 | |
|                                 }
 | |
|                             }
 | |
|                         }
 | |
|                     }
 | |
|                 }
 | |
|                 #endregion
 | |
|                 else
 | |
|                 {
 | |
|                     decimal d10 = 0, d11 = 0, d12 = 0, d15 = 0, d16 = 0, d17 = 0;
 | |
|                     #region  按专业
 | |
|                     if (unitProjectCode == BLL.Const._Null)
 | |
|                     {
 | |
|                         if (cnProfessionId != Const.ACCNProfessionalId.ToString() && cnProfessionId != Const.GECNProfessionalId.ToString() && cnProfessionId != Const.UPCNProfessionalId.ToString() && cnProfessionId != Const.TFCNProfessionalId.ToString() && cnProfessionId != Const.GLCNProfessionalId.ToString())
 | |
|                         {
 | |
|                             newList = (from x in newList where (x.WBSType == "Installation" && !x.Name.Contains("防腐绝热") && !x.Name.Contains("地勘") && !x.Name.Contains("全厂地下主管网") && !x.Name.Contains("临时设施") && !x.Name.Contains("总图")) || (x.WBSType != "Installation" && x.OldCnProfessionId.ToString() == cnProfessionId) select x).ToList();
 | |
|                             var cn = cnProfessionInits.FirstOrDefault(x => x.CnProfessionId.ToString() == cnProfessionId);
 | |
|                             parentRow = table.NewRow();
 | |
|                             parentRow[0] = cn.CnProfessionId.ToString();
 | |
|                             parentRow[1] = "0";
 | |
|                             parentRow[2] = cn.CnProfessionName;
 | |
|                             parentRow[3] = projectId;
 | |
|                             var cnList = newList.Where(x => x.WBSType == "CnProfession");
 | |
|                             foreach (Model.View_WBS_CostControlDetailStatistics item in cnList)
 | |
|                             {
 | |
|                                 Model.View_WBS_CostControlParentDetail parentDetail = parentDetails.FirstOrDefault(x => x.ParentId == item.Id && x.Months == months);
 | |
|                                 if (parentDetail != null)
 | |
|                                 {
 | |
|                                     d10 += decimal.Round(Convert.ToDecimal(parentDetail.ThisRealCost), 2);
 | |
|                                     d11 += decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanValue), 2);
 | |
|                                     d12 += decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanCost), 2);
 | |
|                                     d15 += decimal.Round(Convert.ToDecimal(parentDetail.TotalRealCost), 2);
 | |
|                                     d16 += decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanValue), 2);
 | |
|                                     d17 += decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanCost), 2);
 | |
|                                 }
 | |
|                                 else
 | |
|                                 {
 | |
|                                     Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).FirstOrDefault(x => x.ParentId == item.Id);
 | |
|                                     if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                     {
 | |
|                                         d15 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalRealCost), 2);
 | |
|                                         d16 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanValue), 2);
 | |
|                                         d17 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanCost), 2);
 | |
|                                     }
 | |
|                                 }
 | |
|                             }
 | |
|                             if (d10 != 0)
 | |
|                             {
 | |
|                                 parentRow[10] = decimal.Round(d10, 2);//本月实际成本
 | |
|                                 parentRow[11] = decimal.Round(d11, 2);//本月计划完成预算
 | |
|                                 parentRow[12] = decimal.Round(d12, 2);//本月完成预算
 | |
|                                 parentRow[15] = decimal.Round(d15, 2);//累计完成成本
 | |
|                                 parentRow[16] = decimal.Round(d16, 2);//累计计划完成预算
 | |
|                                 parentRow[17] = decimal.Round(d17, 2);//累计完成预算
 | |
|                             }
 | |
|                             else
 | |
|                             {
 | |
|                                 parentRow[15] = decimal.Round(d15, 2);//累计完成成本
 | |
|                                 parentRow[16] = decimal.Round(d16, 2);//累计计划完成预算
 | |
|                                 parentRow[17] = decimal.Round(d17, 2);//累计完成预算
 | |
|                             }
 | |
|                             table.Rows.Add(parentRow);
 | |
|                             foreach (Model.View_WBS_CostControlDetailStatistics item in newList)
 | |
|                             {
 | |
|                                 row = table.NewRow();
 | |
|                                 row[0] = item.Id;
 | |
|                                 row[2] = item.Name;
 | |
|                                 row[3] = item.ProjectId;
 | |
|                                 if (item.WBSType == "Installation")
 | |
|                                 {
 | |
|                                     decimal ind10 = 0, ind11 = 0, ind12 = 0, ind15 = 0, ind16 = 0, ind17 = 0;
 | |
|                                     if (item.SupId == "0")
 | |
|                                     {
 | |
|                                         row[1] = cn.CnProfessionId.ToString();
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         row[1] = item.SupId;
 | |
|                                     }
 | |
|                                     List<string> cnIds = BLL.CnProfessionService.GetCnProfessionIdsByInstallationIdAndOldId(item.Id, cnProfessionId);
 | |
|                                     foreach (var cnId in cnIds)
 | |
|                                     {
 | |
|                                         Model.View_WBS_CostControlParentDetail parentDetail = parentDetails.FirstOrDefault(x => x.ParentId == cnId && x.Months == months);
 | |
|                                         if (parentDetail != null)
 | |
|                                         {
 | |
|                                             ind10 += decimal.Round(Convert.ToDecimal(parentDetail.ThisRealCost), 2);
 | |
|                                             ind11 += decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanValue), 2);
 | |
|                                             ind12 += decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanCost), 2);
 | |
|                                             ind15 += decimal.Round(Convert.ToDecimal(parentDetail.TotalRealCost), 2);
 | |
|                                             ind16 += decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanValue), 2);
 | |
|                                             ind17 += decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanCost), 2);
 | |
|                                         }
 | |
|                                         else
 | |
|                                         {
 | |
|                                             Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).FirstOrDefault(x => x.ParentId == cnId);
 | |
|                                             if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                             {
 | |
|                                                 ind15 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalRealCost), 2);
 | |
|                                                 ind16 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanValue), 2);
 | |
|                                                 ind17 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanCost), 2);
 | |
|                                             }
 | |
|                                         }
 | |
|                                     }
 | |
|                                     if (ind10 != 0)
 | |
|                                     {
 | |
|                                         row[10] = decimal.Round(ind10, 2);//本月实际成本
 | |
|                                         row[11] = decimal.Round(ind11, 2);//本月计划完成预算
 | |
|                                         row[12] = decimal.Round(ind12, 2);//本月完成预算
 | |
|                                         row[15] = decimal.Round(ind15, 2);//累计完成成本
 | |
|                                         row[16] = decimal.Round(ind16, 2);//累计计划完成预算
 | |
|                                         row[17] = decimal.Round(ind17, 2);//累计完成预算
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         if (ind15 > 0)
 | |
|                                         {
 | |
|                                             row[15] = decimal.Round(ind15, 2);//累计完成成本
 | |
|                                         }
 | |
|                                         if (ind16 > 0)
 | |
|                                         {
 | |
|                                             row[16] = decimal.Round(ind16, 2);//累计计划完成预算
 | |
|                                         }
 | |
|                                         if (ind17 > 0)
 | |
|                                         {
 | |
|                                             row[17] = decimal.Round(ind17, 2);//累计完成预算
 | |
|                                         }
 | |
|                                     }
 | |
|                                 }
 | |
|                                 else if (item.WBSType == "CnProfession")
 | |
|                                 {
 | |
|                                     row[1] = item.SupId;
 | |
|                                     Model.View_WBS_CostControlParentDetail parentDetail = parentDetails.FirstOrDefault(x => x.ParentId == item.Id && x.Months == months);
 | |
|                                     if (parentDetail != null)
 | |
|                                     {
 | |
|                                         row[10] = decimal.Round(Convert.ToDecimal(parentDetail.ThisRealCost), 2);//本月实际成本
 | |
|                                         row[11] = decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanValue), 2);//本月计划完成预算
 | |
|                                         row[12] = decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanCost), 2);//本月完成预算
 | |
|                                         row[15] = decimal.Round(Convert.ToDecimal(parentDetail.TotalRealCost), 2);//累计完成成本
 | |
|                                         row[16] = decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                         row[17] = decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanCost), 2);//累计完成预算
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).FirstOrDefault(x => x.ParentId == item.Id);
 | |
|                                         if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                         {
 | |
|                                             row[15] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalRealCost), 2);//累计完成成本
 | |
|                                             row[16] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                             row[17] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanCost), 2);//累计完成预算
 | |
|                                         }
 | |
|                                     }
 | |
|                                 }
 | |
|                                 else if (item.WBSType == "UnitProject")
 | |
|                                 {
 | |
|                                     row[1] = item.SupId;
 | |
|                                     Model.View_WBS_CostControlParentDetail parentDetail = parentDetails.FirstOrDefault(x => x.ParentId == item.Id && x.Months == months);
 | |
|                                     if (parentDetail != null)
 | |
|                                     {
 | |
|                                         row[10] = decimal.Round(Convert.ToDecimal(parentDetail.ThisRealCost), 2);//本月实际成本
 | |
|                                         row[11] = decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanValue), 2);//本月计划完成预算
 | |
|                                         row[12] = decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanCost), 2);//本月完成预算
 | |
|                                         row[15] = decimal.Round(Convert.ToDecimal(parentDetail.TotalRealCost), 2);//累计完成成本
 | |
|                                         row[16] = decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                         row[17] = decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanCost), 2);//累计完成预算
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).FirstOrDefault(x => x.ParentId == item.Id);
 | |
|                                         if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                         {
 | |
|                                             row[15] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalRealCost), 2);//累计完成成本
 | |
|                                             row[16] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                             row[17] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanCost), 2);//累计完成预算
 | |
|                                         }
 | |
|                                     }
 | |
|                                 }
 | |
|                                 else if (item.WBSType == "WbsSet")
 | |
|                                 {
 | |
|                                     row[1] = item.SupId;
 | |
|                                     Model.View_WBS_CostControlParentDetail parentDetail = parentDetails.FirstOrDefault(x => x.ParentId == item.Id && x.Months == months);
 | |
|                                     if (parentDetail != null)
 | |
|                                     {
 | |
|                                         row[10] = decimal.Round(Convert.ToDecimal(parentDetail.ThisRealCost), 2);//本月实际成本
 | |
|                                         row[11] = decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanValue), 2);//本月计划完成预算
 | |
|                                         row[12] = decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanCost), 2);//本月完成预算
 | |
|                                         row[15] = decimal.Round(Convert.ToDecimal(parentDetail.TotalRealCost), 2);//累计完成成本
 | |
|                                         row[16] = decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                         row[17] = decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanCost), 2);//累计完成预算
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).FirstOrDefault(x => x.ParentId == item.Id);
 | |
|                                         if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                         {
 | |
|                                             row[15] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalRealCost), 2);//累计完成成本
 | |
|                                             row[16] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                             row[17] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanCost), 2);//累计完成预算
 | |
|                                         }
 | |
|                                     }
 | |
|                                 }
 | |
|                                 else if (item.WBSType == "CostControl")
 | |
|                                 {
 | |
|                                     row[1] = item.SupId;
 | |
|                                     Model.View_WBS_CostControlDetail detail = details.FirstOrDefault(x => x.CostControlId == item.Id && x.Months == months);
 | |
|                                     if (detail != null)
 | |
|                                     {
 | |
|                                         row[4] = detail.Unit;//单位
 | |
|                                         row[5] = decimal.Round(Convert.ToDecimal(detail.TotalNum), 2);//合同工作量
 | |
|                                         row[6] = decimal.Round(Convert.ToDecimal(detail.RealPrice), 2);//成本单价
 | |
|                                         row[7] = decimal.Round(Convert.ToDecimal(detail.PlanNum), 2);//本月计划完成量
 | |
|                                         row[8] = decimal.Round(Convert.ToDecimal(detail.ThisNum), 2);//本月完成量
 | |
|                                         row[9] = decimal.Round(Convert.ToDecimal(detail.PlanPrice), 2);//控制预算单价
 | |
|                                         row[10] = decimal.Round(Convert.ToDecimal(detail.ThisRealCost), 2);//本月实际成本
 | |
|                                         row[11] = decimal.Round(Convert.ToDecimal(detail.ThisPlanValue), 2);//本月计划完成预算
 | |
|                                         row[12] = decimal.Round(Convert.ToDecimal(detail.ThisPlanCost), 2);//本月完成预算
 | |
|                                         row[13] = decimal.Round(Convert.ToDecimal(detail.TotalPlanNum), 2);//累计计划完成量
 | |
|                                         row[14] = decimal.Round(Convert.ToDecimal(detail.TotalThisNum), 2);//累计完成量
 | |
|                                         row[15] = decimal.Round(Convert.ToDecimal(detail.TotalRealCost), 2);//累计完成成本
 | |
|                                         row[16] = decimal.Round(Convert.ToDecimal(detail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                         row[17] = decimal.Round(Convert.ToDecimal(detail.TotalPlanCost), 2);//累计完成预算
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         Model.View_WBS_CostControlDetail lastDetail = details.OrderByDescending(x => x.Months).FirstOrDefault(x => x.CostControlId == item.Id);
 | |
|                                         if (lastDetail != null && lastDetail.Months <= months)
 | |
|                                         {
 | |
|                                             row[4] = lastDetail.Unit;//单位
 | |
|                                             row[5] = decimal.Round(Convert.ToDecimal(lastDetail.TotalNum), 2);//合同工作量
 | |
|                                             row[6] = decimal.Round(Convert.ToDecimal(lastDetail.RealPrice), 2);//成本单价
 | |
|                                             row[7] = decimal.Round(Convert.ToDecimal(lastDetail.PlanNum), 2);//本月计划完成量
 | |
|                                             row[8] = decimal.Round(Convert.ToDecimal(lastDetail.ThisNum), 2);//本月完成量
 | |
|                                             row[9] = decimal.Round(Convert.ToDecimal(lastDetail.PlanPrice), 2);//控制预算单价
 | |
|                                             row[13] = decimal.Round(Convert.ToDecimal(lastDetail.TotalPlanNum), 2);//累计计划完成量
 | |
|                                             row[14] = decimal.Round(Convert.ToDecimal(lastDetail.TotalThisNum), 2);//累计完成量
 | |
|                                             row[15] = decimal.Round(Convert.ToDecimal(lastDetail.TotalRealCost), 2);//累计完成成本
 | |
|                                             row[16] = decimal.Round(Convert.ToDecimal(lastDetail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                             row[17] = decimal.Round(Convert.ToDecimal(lastDetail.TotalPlanCost), 2);//累计完成预算
 | |
|                                         }
 | |
|                                     }
 | |
|                                 }
 | |
|                                 table.Rows.Add(row);
 | |
|                             }
 | |
|                         }
 | |
|                         else
 | |
|                         {
 | |
|                             Model.WBS_CnProfessionInit cnInit = BLL.CnProfessionInitService.GetCnProfessionInitByCnProfessionId(cnProfessionId);
 | |
|                             newList = (from x in newList where (x.WBSType == "Installation" && x.Name.Contains(cnInit.CnProfessionName.Substring(0, 2))) || (x.WBSType != "Installation" && x.OldCnProfessionId.ToString() == cnProfessionId) select x).ToList();
 | |
|                             var cn = newList.FirstOrDefault(x => x.Name.Contains(cnInit.CnProfessionName.Substring(0, 2)) && x.WBSType == "Installation");
 | |
|                             parentRow = table.NewRow();
 | |
|                             parentRow[0] = cn.Id;
 | |
|                             parentRow[1] = "0";
 | |
|                             parentRow[2] = cn.Name;
 | |
|                             parentRow[3] = projectId;
 | |
|                             Model.View_WBS_CostControlParentDetail pparentDetail = parentDetails.FirstOrDefault(x => x.ParentId == cn.Id && x.Months == months);
 | |
|                             if (pparentDetail != null)
 | |
|                             {
 | |
|                                 d10 += decimal.Round(Convert.ToDecimal(pparentDetail.ThisRealCost), 2);
 | |
|                                 d11 += decimal.Round(Convert.ToDecimal(pparentDetail.ThisPlanValue), 2);
 | |
|                                 d12 += decimal.Round(Convert.ToDecimal(pparentDetail.ThisPlanCost), 2);
 | |
|                                 d15 += decimal.Round(Convert.ToDecimal(pparentDetail.TotalRealCost), 2);
 | |
|                                 d16 += decimal.Round(Convert.ToDecimal(pparentDetail.TotalPlanValue), 2);
 | |
|                                 d17 += decimal.Round(Convert.ToDecimal(pparentDetail.TotalPlanCost), 2);
 | |
|                             }
 | |
|                             else
 | |
|                             {
 | |
|                                 Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).FirstOrDefault(x => x.ParentId == cn.Id);
 | |
|                                 if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                 {
 | |
|                                     d15 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalRealCost), 2);
 | |
|                                     d16 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanValue), 2);
 | |
|                                     d17 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanCost), 2);
 | |
|                                 }
 | |
|                             }
 | |
|                             if (d10 != 0)
 | |
|                             {
 | |
|                                 parentRow[10] = decimal.Round(d10, 2);//本月实际成本
 | |
|                                 parentRow[11] = decimal.Round(d11, 2);//本月计划完成预算
 | |
|                                 parentRow[12] = decimal.Round(d12, 2);//本月完成预算
 | |
|                                 parentRow[15] = decimal.Round(d15, 2);//累计完成成本
 | |
|                                 parentRow[16] = decimal.Round(d16, 2);//累计计划完成预算
 | |
|                                 parentRow[17] = decimal.Round(d17, 2);//累计完成预算
 | |
|                             }
 | |
|                             else
 | |
|                             {
 | |
|                                 parentRow[15] = decimal.Round(d15, 2);//累计完成成本
 | |
|                                 parentRow[16] = decimal.Round(d16, 2);//累计计划完成预算
 | |
|                                 parentRow[17] = decimal.Round(d17, 2);//累计完成预算
 | |
|                             }
 | |
|                             table.Rows.Add(parentRow);
 | |
|                             foreach (Model.View_WBS_CostControlDetailStatistics item in newList)
 | |
|                             {
 | |
|                                 row = table.NewRow();
 | |
|                                 row[0] = item.Id;
 | |
|                                 row[2] = item.Name;
 | |
|                                 row[3] = item.ProjectId;
 | |
|                                 if (item.WBSType == "UnitProject")
 | |
|                                 {
 | |
|                                     row[1] = item.SupId;
 | |
|                                     Model.View_WBS_CostControlParentDetail parentDetail = parentDetails.FirstOrDefault(x => x.ParentId == item.Id && x.Months == months);
 | |
|                                     if (parentDetail != null)
 | |
|                                     {
 | |
|                                         row[10] = decimal.Round(Convert.ToDecimal(parentDetail.ThisRealCost), 2);//本月实际成本
 | |
|                                         row[11] = decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanValue), 2);//本月计划完成预算
 | |
|                                         row[12] = decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanCost), 2);//本月完成预算
 | |
|                                         row[15] = decimal.Round(Convert.ToDecimal(parentDetail.TotalRealCost), 2);//累计完成成本
 | |
|                                         row[16] = decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                         row[17] = decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanCost), 2);//累计完成预算
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).FirstOrDefault(x => x.ParentId == item.Id);
 | |
|                                         if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                         {
 | |
|                                             row[15] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalRealCost), 2);//累计完成成本
 | |
|                                             row[16] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                             row[17] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanCost), 2);//累计完成预算
 | |
|                                         }
 | |
|                                     }
 | |
|                                 }
 | |
|                                 else if (item.WBSType == "WbsSet")
 | |
|                                 {
 | |
|                                     row[1] = item.SupId;
 | |
|                                     Model.View_WBS_CostControlParentDetail parentDetail = parentDetails.FirstOrDefault(x => x.ParentId == item.Id && x.Months == months);
 | |
|                                     if (parentDetail != null)
 | |
|                                     {
 | |
|                                         row[10] = decimal.Round(Convert.ToDecimal(parentDetail.ThisRealCost), 2);//本月实际成本
 | |
|                                         row[11] = decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanValue), 2);//本月计划完成预算
 | |
|                                         row[12] = decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanCost), 2);//本月完成预算
 | |
|                                         row[15] = decimal.Round(Convert.ToDecimal(parentDetail.TotalRealCost), 2);//累计完成成本
 | |
|                                         row[16] = decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                         row[17] = decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanCost), 2);//累计完成预算
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).FirstOrDefault(x => x.ParentId == item.Id);
 | |
|                                         if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                         {
 | |
|                                             row[15] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalRealCost), 2);//累计完成成本
 | |
|                                             row[16] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                             row[17] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanCost), 2);//累计完成预算
 | |
|                                         }
 | |
|                                     }
 | |
|                                 }
 | |
|                                 else if (item.WBSType == "CostControl")
 | |
|                                 {
 | |
|                                     row[1] = item.SupId;
 | |
|                                     Model.View_WBS_CostControlDetail detail = details.FirstOrDefault(x => x.CostControlId == item.Id && x.Months == months);
 | |
|                                     if (detail != null)
 | |
|                                     {
 | |
|                                         row[4] = detail.Unit;//单位
 | |
|                                         row[5] = decimal.Round(Convert.ToDecimal(detail.TotalNum), 2);//合同工作量
 | |
|                                         row[6] = decimal.Round(Convert.ToDecimal(detail.RealPrice), 2);//成本单价
 | |
|                                         row[7] = decimal.Round(Convert.ToDecimal(detail.PlanNum), 2);//本月计划完成量
 | |
|                                         row[8] = decimal.Round(Convert.ToDecimal(detail.ThisNum), 2);//本月完成量
 | |
|                                         row[9] = decimal.Round(Convert.ToDecimal(detail.PlanPrice), 2);//控制预算单价
 | |
|                                         row[10] = decimal.Round(Convert.ToDecimal(detail.ThisRealCost), 2);//本月实际成本
 | |
|                                         row[11] = decimal.Round(Convert.ToDecimal(detail.ThisPlanValue), 2);//本月计划完成预算
 | |
|                                         row[12] = decimal.Round(Convert.ToDecimal(detail.ThisPlanCost), 2);//本月完成预算
 | |
|                                         row[13] = decimal.Round(Convert.ToDecimal(detail.TotalPlanNum), 2);//累计计划完成量
 | |
|                                         row[14] = decimal.Round(Convert.ToDecimal(detail.TotalThisNum), 2);//累计完成量
 | |
|                                         row[15] = decimal.Round(Convert.ToDecimal(detail.TotalRealCost), 2);//累计完成成本
 | |
|                                         row[16] = decimal.Round(Convert.ToDecimal(detail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                         row[17] = decimal.Round(Convert.ToDecimal(detail.TotalPlanCost), 2);//累计完成预算
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         Model.View_WBS_CostControlDetail lastDetail = details.OrderByDescending(x => x.Months).FirstOrDefault(x => x.CostControlId == item.Id);
 | |
|                                         if (lastDetail != null && lastDetail.Months <= months)
 | |
|                                         {
 | |
|                                             row[4] = lastDetail.Unit;//单位
 | |
|                                             row[5] = decimal.Round(Convert.ToDecimal(lastDetail.TotalNum), 2);//合同工作量
 | |
|                                             row[6] = decimal.Round(Convert.ToDecimal(lastDetail.RealPrice), 2);//成本单价
 | |
|                                             row[7] = decimal.Round(Convert.ToDecimal(lastDetail.PlanNum), 2);//本月计划完成量
 | |
|                                             row[8] = decimal.Round(Convert.ToDecimal(lastDetail.ThisNum), 2);//本月完成量
 | |
|                                             row[9] = decimal.Round(Convert.ToDecimal(lastDetail.PlanPrice), 2);//控制预算单价
 | |
|                                             row[13] = decimal.Round(Convert.ToDecimal(lastDetail.TotalPlanNum), 2);//累计计划完成量
 | |
|                                             row[14] = decimal.Round(Convert.ToDecimal(lastDetail.TotalThisNum), 2);//累计完成量
 | |
|                                             row[15] = decimal.Round(Convert.ToDecimal(lastDetail.TotalRealCost), 2);//累计完成成本
 | |
|                                             row[16] = decimal.Round(Convert.ToDecimal(lastDetail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                             row[17] = decimal.Round(Convert.ToDecimal(lastDetail.TotalPlanCost), 2);//累计完成预算
 | |
|                                         }
 | |
|                                     }
 | |
|                                 }
 | |
|                                 table.Rows.Add(row);
 | |
|                             }
 | |
|                         }
 | |
|                     }
 | |
|                     #endregion
 | |
|                     #region   按分部工程
 | |
|                     else if (wbsSetCode == BLL.Const._Null)
 | |
|                     {
 | |
|                         if (cnProfessionId != Const.ACCNProfessionalId.ToString() && cnProfessionId != Const.GECNProfessionalId.ToString() && cnProfessionId != Const.UPCNProfessionalId.ToString() && cnProfessionId != Const.TFCNProfessionalId.ToString() && cnProfessionId != Const.GLCNProfessionalId.ToString())
 | |
|                         {
 | |
|                             newList = (from x in newList where (x.WBSType == "Installation" && !x.Name.Contains("防腐绝热") && !x.Name.Contains("地勘") && !x.Name.Contains("全厂地下主管网") && !x.Name.Contains("临时设施") && !x.Name.Contains("总图")) || (x.WBSType == "CnProfession" && x.OldCnProfessionId.ToString() == cnProfessionId) || (x.WBSType != "Installation" && x.WBSType != "CnProfession" && x.OldCnProfessionId.ToString() == cnProfessionId && x.OldUnitProjectCode == unitProjectCode) select x).ToList();
 | |
|                             var up = unitProjectInits.FirstOrDefault(x => x.UnitProjectCode == unitProjectCode);
 | |
|                             parentRow = table.NewRow();
 | |
|                             parentRow[0] = up.UnitProjectCode;
 | |
|                             parentRow[1] = "0";
 | |
|                             parentRow[2] = up.UnitProjectName;
 | |
|                             parentRow[3] = projectId;
 | |
|                             foreach (Model.View_WBS_CostControlDetailStatistics item in newList)
 | |
|                             {
 | |
|                                 row = table.NewRow();
 | |
|                                 row[0] = item.Id;
 | |
|                                 row[2] = item.Name;
 | |
|                                 row[3] = item.ProjectId;
 | |
|                                 if (item.WBSType == "Installation")
 | |
|                                 {
 | |
|                                     decimal ind10 = 0, ind11 = 0, ind12 = 0, ind15 = 0, ind16 = 0, ind17 = 0;
 | |
|                                     if (item.SupId == "0")
 | |
|                                     {
 | |
|                                         row[1] = up.UnitProjectCode;
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         row[1] = item.SupId;
 | |
|                                     }
 | |
|                                     List<string> unitProjectIds = BLL.UnitProjectService.GetUnitProjectIdByInstallationIdAndCNCodeAndUnitProjectCode(item.Id, cnProfessionId, unitProjectCode);
 | |
|                                     foreach (var upId in unitProjectIds)
 | |
|                                     {
 | |
|                                         Model.View_WBS_CostControlParentDetail parentDetail = parentDetails.FirstOrDefault(x => x.ParentId == upId && x.Months == months);
 | |
|                                         if (parentDetail != null)
 | |
|                                         {
 | |
|                                             ind10 += decimal.Round(Convert.ToDecimal(parentDetail.ThisRealCost), 2);
 | |
|                                             ind11 += decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanValue), 2);
 | |
|                                             ind12 += decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanCost), 2);
 | |
|                                             ind15 += decimal.Round(Convert.ToDecimal(parentDetail.TotalRealCost), 2);
 | |
|                                             ind16 += decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanValue), 2);
 | |
|                                             ind17 += decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanCost), 2);
 | |
|                                         }
 | |
|                                         else
 | |
|                                         {
 | |
|                                             Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).FirstOrDefault(x => x.ParentId == upId);
 | |
|                                             if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                             {
 | |
|                                                 ind15 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalRealCost), 2);
 | |
|                                                 ind16 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanValue), 2);
 | |
|                                                 ind17 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanCost), 2);
 | |
|                                             }
 | |
|                                         }
 | |
|                                     }
 | |
|                                     if (ind10 != 0)
 | |
|                                     {
 | |
|                                         row[10] = decimal.Round(ind10, 2);//本月实际成本
 | |
|                                         row[11] = decimal.Round(ind11, 2);//本月计划完成预算
 | |
|                                         row[12] = decimal.Round(ind12, 2);//本月完成预算
 | |
|                                         row[15] = decimal.Round(ind15, 2);//累计完成成本
 | |
|                                         row[16] = decimal.Round(ind16, 2);//累计计划完成预算
 | |
|                                         row[17] = decimal.Round(ind17, 2);//累计完成预算
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         if (ind15 > 0)
 | |
|                                         {
 | |
|                                             row[15] = decimal.Round(ind15, 2);//累计完成成本
 | |
|                                         }
 | |
|                                         if (ind16 > 0)
 | |
|                                         {
 | |
|                                             row[16] = decimal.Round(ind16, 2);//累计计划完成预算
 | |
|                                         }
 | |
|                                         if (ind17 > 0)
 | |
|                                         {
 | |
|                                             row[17] = decimal.Round(ind17, 2);//累计完成预算
 | |
|                                         }
 | |
|                                     }
 | |
|                                 }
 | |
|                                 else if (item.WBSType == "CnProfession")
 | |
|                                 {
 | |
|                                     decimal cnd10 = 0, cnd11 = 0, cnd12 = 0, cnd15 = 0, cnd16 = 0, cnd17 = 0;
 | |
|                                     row[1] = item.SupId;
 | |
|                                     List<string> unitProjectIds = BLL.UnitProjectService.GetUnitProjectIdByCnProfessionIdAndUnitProjectCode(item.Id, unitProjectCode);
 | |
|                                     foreach (var upId in unitProjectIds)
 | |
|                                     {
 | |
|                                         Model.View_WBS_CostControlParentDetail parentDetail = parentDetails.FirstOrDefault(x => x.ParentId == upId && x.Months == months);
 | |
|                                         if (parentDetail != null)
 | |
|                                         {
 | |
|                                             cnd10 += decimal.Round(Convert.ToDecimal(parentDetail.ThisRealCost), 2);
 | |
|                                             cnd11 += decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanValue), 2);
 | |
|                                             cnd12 += decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanCost), 2);
 | |
|                                             cnd15 += decimal.Round(Convert.ToDecimal(parentDetail.TotalRealCost), 2);
 | |
|                                             cnd16 += decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanValue), 2);
 | |
|                                             cnd17 += decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanCost), 2);
 | |
|                                         }
 | |
|                                         else
 | |
|                                         {
 | |
|                                             Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).FirstOrDefault(x => x.ParentId == upId);
 | |
|                                             if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                             {
 | |
|                                                 cnd15 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalRealCost), 2);
 | |
|                                                 cnd16 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanValue), 2);
 | |
|                                                 cnd17 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanCost), 2);
 | |
|                                             }
 | |
|                                         }
 | |
|                                     }
 | |
|                                     if (cnd10 != 0)
 | |
|                                     {
 | |
|                                         row[10] = decimal.Round(cnd10, 2);//本月实际成本
 | |
|                                         row[11] = decimal.Round(cnd11, 2);//本月计划完成预算
 | |
|                                         row[12] = decimal.Round(cnd12, 2);//本月完成预算
 | |
|                                         row[15] = decimal.Round(cnd15, 2);//累计完成成本
 | |
|                                         row[16] = decimal.Round(cnd16, 2);//累计计划完成预算
 | |
|                                         row[17] = decimal.Round(cnd17, 2);//累计完成预算
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         if (cnd15 > 0)
 | |
|                                         {
 | |
|                                             row[15] = decimal.Round(cnd15, 2);//累计完成成本
 | |
|                                         }
 | |
|                                         if (cnd16 > 0)
 | |
|                                         {
 | |
|                                             row[16] = decimal.Round(cnd16, 2);//累计计划完成预算
 | |
|                                         }
 | |
|                                         if (cnd17 > 0)
 | |
|                                         {
 | |
|                                             row[17] = decimal.Round(cnd17, 2);//累计完成预算
 | |
|                                         }
 | |
|                                     }
 | |
|                                 }
 | |
|                                 else if (item.WBSType == "UnitProject")
 | |
|                                 {
 | |
|                                     row[1] = item.SupId;
 | |
|                                     Model.View_WBS_CostControlParentDetail parentDetail = parentDetails.FirstOrDefault(x => x.ParentId == item.Id && x.Months == months);
 | |
|                                     if (parentDetail != null)
 | |
|                                     {
 | |
|                                         row[10] = decimal.Round(Convert.ToDecimal(parentDetail.ThisRealCost), 2);//本月实际成本
 | |
|                                         row[11] = decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanValue), 2);//本月计划完成预算
 | |
|                                         row[12] = decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanCost), 2);//本月完成预算
 | |
|                                         row[15] = decimal.Round(Convert.ToDecimal(parentDetail.TotalRealCost), 2);//累计完成成本
 | |
|                                         row[16] = decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                         row[17] = decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanCost), 2);//累计完成预算
 | |
|                                         d10 += decimal.Round(Convert.ToDecimal(parentDetail.ThisRealCost), 2);
 | |
|                                         d11 += decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanValue), 2);
 | |
|                                         d12 += decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanCost), 2);
 | |
|                                         d15 += decimal.Round(Convert.ToDecimal(parentDetail.TotalRealCost), 2);
 | |
|                                         d16 += decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanValue), 2);
 | |
|                                         d17 += decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanCost), 2);
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).FirstOrDefault(x => x.ParentId == item.Id);
 | |
|                                         if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                         {
 | |
|                                             row[15] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalRealCost), 2);//累计完成成本
 | |
|                                             row[16] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                             row[17] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanCost), 2);//累计完成预算
 | |
|                                             d15 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalRealCost), 2);
 | |
|                                             d16 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanValue), 2);
 | |
|                                             d17 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanCost), 2);
 | |
|                                         }
 | |
|                                     }
 | |
|                                 }
 | |
|                                 else if (item.WBSType == "WbsSet")
 | |
|                                 {
 | |
|                                     row[1] = item.SupId;
 | |
|                                     Model.View_WBS_CostControlParentDetail parentDetail = parentDetails.FirstOrDefault(x => x.ParentId == item.Id && x.Months == months);
 | |
|                                     if (parentDetail != null)
 | |
|                                     {
 | |
|                                         row[10] = decimal.Round(Convert.ToDecimal(parentDetail.ThisRealCost), 2);//本月实际成本
 | |
|                                         row[11] = decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanValue), 2);//本月计划完成预算
 | |
|                                         row[12] = decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanCost), 2);//本月完成预算
 | |
|                                         row[15] = decimal.Round(Convert.ToDecimal(parentDetail.TotalRealCost), 2);//累计完成成本
 | |
|                                         row[16] = decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                         row[17] = decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanCost), 2);//累计完成预算
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).FirstOrDefault(x => x.ParentId == item.Id);
 | |
|                                         if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                         {
 | |
|                                             row[15] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalRealCost), 2);//累计完成成本
 | |
|                                             row[16] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                             row[17] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanCost), 2);//累计完成预算
 | |
|                                         }
 | |
|                                     }
 | |
|                                 }
 | |
|                                 else if (item.WBSType == "CostControl")
 | |
|                                 {
 | |
|                                     row[1] = item.SupId;
 | |
|                                     Model.View_WBS_CostControlDetail detail = details.FirstOrDefault(x => x.CostControlId == item.Id && x.Months == months);
 | |
|                                     if (detail != null)
 | |
|                                     {
 | |
|                                         row[4] = detail.Unit;//单位
 | |
|                                         row[5] = decimal.Round(Convert.ToDecimal(detail.TotalNum), 2);//合同工作量
 | |
|                                         row[6] = decimal.Round(Convert.ToDecimal(detail.RealPrice), 2);//成本单价
 | |
|                                         row[7] = decimal.Round(Convert.ToDecimal(detail.PlanNum), 2);//本月计划完成量
 | |
|                                         row[8] = decimal.Round(Convert.ToDecimal(detail.ThisNum), 2);//本月完成量
 | |
|                                         row[9] = decimal.Round(Convert.ToDecimal(detail.PlanPrice), 2);//控制预算单价
 | |
|                                         row[10] = decimal.Round(Convert.ToDecimal(detail.ThisRealCost), 2);//本月实际成本
 | |
|                                         row[11] = decimal.Round(Convert.ToDecimal(detail.ThisPlanValue), 2);//本月计划完成预算
 | |
|                                         row[12] = decimal.Round(Convert.ToDecimal(detail.ThisPlanCost), 2);//本月完成预算
 | |
|                                         row[13] = decimal.Round(Convert.ToDecimal(detail.TotalPlanNum), 2);//累计计划完成量
 | |
|                                         row[14] = decimal.Round(Convert.ToDecimal(detail.TotalThisNum), 2);//累计完成量
 | |
|                                         row[15] = decimal.Round(Convert.ToDecimal(detail.TotalRealCost), 2);//累计完成成本
 | |
|                                         row[16] = decimal.Round(Convert.ToDecimal(detail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                         row[17] = decimal.Round(Convert.ToDecimal(detail.TotalPlanCost), 2);//累计完成预算
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         Model.View_WBS_CostControlDetail lastDetail = details.OrderByDescending(x => x.Months).FirstOrDefault(x => x.CostControlId == item.Id);
 | |
|                                         if (lastDetail != null && lastDetail.Months <= months)
 | |
|                                         {
 | |
|                                             row[4] = lastDetail.Unit;//单位
 | |
|                                             row[5] = decimal.Round(Convert.ToDecimal(lastDetail.TotalNum), 2);//合同工作量
 | |
|                                             row[6] = decimal.Round(Convert.ToDecimal(lastDetail.RealPrice), 2);//成本单价
 | |
|                                             row[7] = decimal.Round(Convert.ToDecimal(lastDetail.PlanNum), 2);//本月计划完成量
 | |
|                                             row[8] = decimal.Round(Convert.ToDecimal(lastDetail.ThisNum), 2);//本月完成量
 | |
|                                             row[9] = decimal.Round(Convert.ToDecimal(lastDetail.PlanPrice), 2);//控制预算单价
 | |
|                                             row[13] = decimal.Round(Convert.ToDecimal(lastDetail.TotalPlanNum), 2);//累计计划完成量
 | |
|                                             row[14] = decimal.Round(Convert.ToDecimal(lastDetail.TotalThisNum), 2);//累计完成量
 | |
|                                             row[15] = decimal.Round(Convert.ToDecimal(lastDetail.TotalRealCost), 2);//累计完成成本
 | |
|                                             row[16] = decimal.Round(Convert.ToDecimal(lastDetail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                             row[17] = decimal.Round(Convert.ToDecimal(lastDetail.TotalPlanCost), 2);//累计完成预算
 | |
|                                         }
 | |
|                                     }
 | |
|                                 }
 | |
|                                 table.Rows.Add(row);
 | |
|                             }
 | |
|                             if (d10 != 0)
 | |
|                             {
 | |
|                                 parentRow[10] = decimal.Round(d10, 2);//本月实际成本
 | |
|                                 parentRow[11] = decimal.Round(d11, 2);//本月计划完成预算
 | |
|                                 parentRow[12] = decimal.Round(d12, 2);//本月完成预算
 | |
|                                 parentRow[15] = decimal.Round(d15, 2);//累计完成成本
 | |
|                                 parentRow[16] = decimal.Round(d16, 2);//累计计划完成预算
 | |
|                                 parentRow[17] = decimal.Round(d17, 2);//累计完成预算
 | |
|                             }
 | |
|                             else
 | |
|                             {
 | |
|                                 parentRow[15] = decimal.Round(d15, 2);//累计完成成本
 | |
|                                 parentRow[16] = decimal.Round(d16, 2);//累计计划完成预算
 | |
|                                 parentRow[17] = decimal.Round(d17, 2);//累计完成预算
 | |
|                             }
 | |
|                             table.Rows.Add(parentRow);
 | |
|                         }
 | |
|                         else
 | |
|                         {
 | |
|                             newList = (from x in newList where x.WBSType != "Installation" && x.WBSType != "CnProfession" && x.OldCnProfessionId.ToString() == cnProfessionId && x.OldUnitProjectCode == unitProjectCode select x).ToList();
 | |
|                             var up = newList.FirstOrDefault(x => x.WBSType == "UnitProject" && x.OldUnitProjectCode == unitProjectCode);
 | |
|                             parentRow = table.NewRow();
 | |
|                             if (up != null)
 | |
|                             {
 | |
|                                 parentRow[0] = up.Id;
 | |
|                                 parentRow[1] = "0";
 | |
|                                 parentRow[2] = up.Name;
 | |
|                                 parentRow[3] = projectId;
 | |
|                                 Model.View_WBS_CostControlParentDetail pparentDetail = parentDetails.FirstOrDefault(x => x.ParentId == up.Id && x.Months == months);
 | |
|                                 if (pparentDetail != null)
 | |
|                                 {
 | |
|                                     d10 += decimal.Round(Convert.ToDecimal(pparentDetail.ThisRealCost), 2);
 | |
|                                     d11 += decimal.Round(Convert.ToDecimal(pparentDetail.ThisPlanValue), 2);
 | |
|                                     d12 += decimal.Round(Convert.ToDecimal(pparentDetail.ThisPlanCost), 2);
 | |
|                                     d15 += decimal.Round(Convert.ToDecimal(pparentDetail.TotalRealCost), 2);
 | |
|                                     d16 += decimal.Round(Convert.ToDecimal(pparentDetail.TotalPlanValue), 2);
 | |
|                                     d17 += decimal.Round(Convert.ToDecimal(pparentDetail.TotalPlanCost), 2);
 | |
|                                 }
 | |
|                                 else
 | |
|                                 {
 | |
|                                     Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).FirstOrDefault(x => x.ParentId == up.Id);
 | |
|                                     if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                     {
 | |
|                                         d15 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalRealCost), 2);
 | |
|                                         d16 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanValue), 2);
 | |
|                                         d17 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanCost), 2);
 | |
|                                     }
 | |
|                                 }
 | |
|                                 foreach (Model.View_WBS_CostControlDetailStatistics item in newList)
 | |
|                                 {
 | |
|                                     row = table.NewRow();
 | |
|                                     row[0] = item.Id;
 | |
|                                     row[2] = item.Name;
 | |
|                                     row[3] = item.ProjectId;
 | |
|                                     if (item.WBSType == "WbsSet")
 | |
|                                     {
 | |
|                                         row[1] = item.SupId;
 | |
|                                         Model.View_WBS_CostControlParentDetail parentDetail = parentDetails.FirstOrDefault(x => x.ParentId == item.Id && x.Months == months);
 | |
|                                         if (parentDetail != null)
 | |
|                                         {
 | |
|                                             row[10] = decimal.Round(Convert.ToDecimal(parentDetail.ThisRealCost), 2);//本月实际成本
 | |
|                                             row[11] = decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanValue), 2);//本月计划完成预算
 | |
|                                             row[12] = decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanCost), 2);//本月完成预算
 | |
|                                             row[15] = decimal.Round(Convert.ToDecimal(parentDetail.TotalRealCost), 2);//累计完成成本
 | |
|                                             row[16] = decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                             row[17] = decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanCost), 2);//累计完成预算
 | |
|                                         }
 | |
|                                         else
 | |
|                                         {
 | |
|                                             Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).FirstOrDefault(x => x.ParentId == item.Id);
 | |
|                                             if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                             {
 | |
|                                                 row[15] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalRealCost), 2);//累计完成成本
 | |
|                                                 row[16] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                                 row[17] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanCost), 2);//累计完成预算
 | |
|                                             }
 | |
|                                         }
 | |
|                                     }
 | |
|                                     else if (item.WBSType == "CostControl")
 | |
|                                     {
 | |
|                                         row[1] = item.SupId;
 | |
|                                         Model.View_WBS_CostControlDetail detail = details.FirstOrDefault(x => x.CostControlId == item.Id && x.Months == months);
 | |
|                                         if (detail != null)
 | |
|                                         {
 | |
|                                             row[4] = detail.Unit;//单位
 | |
|                                             row[5] = decimal.Round(Convert.ToDecimal(detail.TotalNum), 2);//合同工作量
 | |
|                                             row[6] = decimal.Round(Convert.ToDecimal(detail.RealPrice), 2);//成本单价
 | |
|                                             row[7] = decimal.Round(Convert.ToDecimal(detail.PlanNum), 2);//本月计划完成量
 | |
|                                             row[8] = decimal.Round(Convert.ToDecimal(detail.ThisNum), 2);//本月完成量
 | |
|                                             row[9] = decimal.Round(Convert.ToDecimal(detail.PlanPrice), 2);//控制预算单价
 | |
|                                             row[10] = decimal.Round(Convert.ToDecimal(detail.ThisRealCost), 2);//本月实际成本
 | |
|                                             row[11] = decimal.Round(Convert.ToDecimal(detail.ThisPlanValue), 2);//本月计划完成预算
 | |
|                                             row[12] = decimal.Round(Convert.ToDecimal(detail.ThisPlanCost), 2);//本月完成预算
 | |
|                                             row[13] = decimal.Round(Convert.ToDecimal(detail.TotalPlanNum), 2);//累计计划完成量
 | |
|                                             row[14] = decimal.Round(Convert.ToDecimal(detail.TotalThisNum), 2);//累计完成量
 | |
|                                             row[15] = decimal.Round(Convert.ToDecimal(detail.TotalRealCost), 2);//累计完成成本
 | |
|                                             row[16] = decimal.Round(Convert.ToDecimal(detail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                             row[17] = decimal.Round(Convert.ToDecimal(detail.TotalPlanCost), 2);//累计完成预算
 | |
|                                         }
 | |
|                                         else
 | |
|                                         {
 | |
|                                             Model.View_WBS_CostControlDetail lastDetail = details.OrderByDescending(x => x.Months).FirstOrDefault(x => x.CostControlId == item.Id);
 | |
|                                             if (lastDetail != null && lastDetail.Months <= months)
 | |
|                                             {
 | |
|                                                 row[4] = lastDetail.Unit;//单位
 | |
|                                                 row[5] = decimal.Round(Convert.ToDecimal(lastDetail.TotalNum), 2);//合同工作量
 | |
|                                                 row[6] = decimal.Round(Convert.ToDecimal(lastDetail.RealPrice), 2);//成本单价
 | |
|                                                 row[7] = decimal.Round(Convert.ToDecimal(lastDetail.PlanNum), 2);//本月计划完成量
 | |
|                                                 row[8] = decimal.Round(Convert.ToDecimal(lastDetail.ThisNum), 2);//本月完成量
 | |
|                                                 row[9] = decimal.Round(Convert.ToDecimal(lastDetail.PlanPrice), 2);//控制预算单价
 | |
|                                                 row[13] = decimal.Round(Convert.ToDecimal(lastDetail.TotalPlanNum), 2);//累计计划完成量
 | |
|                                                 row[14] = decimal.Round(Convert.ToDecimal(lastDetail.TotalThisNum), 2);//累计完成量
 | |
|                                                 row[15] = decimal.Round(Convert.ToDecimal(lastDetail.TotalRealCost), 2);//累计完成成本
 | |
|                                                 row[16] = decimal.Round(Convert.ToDecimal(lastDetail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                                 row[17] = decimal.Round(Convert.ToDecimal(lastDetail.TotalPlanCost), 2);//累计完成预算
 | |
|                                             }
 | |
|                                         }
 | |
|                                     }
 | |
|                                     table.Rows.Add(row);
 | |
|                                 }
 | |
|                                 if (d10 != 0)
 | |
|                                 {
 | |
|                                     parentRow[10] = decimal.Round(d10, 2);//本月实际成本
 | |
|                                     parentRow[11] = decimal.Round(d11, 2);//本月计划完成预算
 | |
|                                     parentRow[12] = decimal.Round(d12, 2);//本月完成预算
 | |
|                                     parentRow[15] = decimal.Round(d15, 2);//累计完成成本
 | |
|                                     parentRow[16] = decimal.Round(d16, 2);//累计计划完成预算
 | |
|                                     parentRow[17] = decimal.Round(d17, 2);//累计完成预算
 | |
|                                 }
 | |
|                                 else
 | |
|                                 {
 | |
|                                     parentRow[15] = decimal.Round(d15, 2);//累计完成成本
 | |
|                                     parentRow[16] = decimal.Round(d16, 2);//累计计划完成预算
 | |
|                                     parentRow[17] = decimal.Round(d17, 2);//累计完成预算
 | |
|                                 }
 | |
|                                 table.Rows.Add(parentRow);
 | |
|                             }
 | |
|                         }
 | |
|                     }
 | |
|                     #endregion
 | |
|                     #region  按工作包
 | |
|                     else
 | |
|                     {
 | |
|                         if (cnProfessionId != Const.ACCNProfessionalId.ToString() && cnProfessionId != Const.GECNProfessionalId.ToString() && cnProfessionId != Const.UPCNProfessionalId.ToString() && cnProfessionId != Const.TFCNProfessionalId.ToString() && cnProfessionId != Const.GLCNProfessionalId.ToString())
 | |
|                         {
 | |
|                             newList = (from x in newList where (x.WBSType == "Installation" && !x.Name.Contains("防腐绝热") && !x.Name.Contains("地勘") && !x.Name.Contains("全厂地下主管网") && !x.Name.Contains("临时设施") && !x.Name.Contains("总图")) || (x.WBSType == "CnProfession" && x.OldCnProfessionId.ToString() == cnProfessionId) || (x.WBSType == "UnitProject" && x.OldCnProfessionId.ToString() == cnProfessionId && x.OldUnitProjectCode == unitProjectCode) || (x.WBSType != "Installation" && x.WBSType != "CnProfession" && x.WBSType != "UnitProject" && x.OldCnProfessionId.ToString() == cnProfessionId && x.OldUnitProjectCode == unitProjectCode && x.OldWbsSetCode == wbsSetCode) select x).ToList();
 | |
|                             var wb = wbsSetInits.FirstOrDefault(x => x.WbsSetCode == wbsSetCode);
 | |
|                             parentRow = table.NewRow();
 | |
|                             parentRow[0] = wb.WbsSetCode;
 | |
|                             parentRow[1] = "0";
 | |
|                             parentRow[2] = wb.WbsSetName;
 | |
|                             parentRow[3] = projectId;
 | |
|                             foreach (Model.View_WBS_CostControlDetailStatistics item in newList)
 | |
|                             {
 | |
|                                 row = table.NewRow();
 | |
|                                 row[0] = item.Id;
 | |
|                                 row[2] = item.Name;
 | |
|                                 row[3] = item.ProjectId;
 | |
|                                 if (item.WBSType == "Installation")
 | |
|                                 {
 | |
|                                     decimal ind10 = 0, ind11 = 0, ind12 = 0, ind15 = 0, ind16 = 0, ind17 = 0;
 | |
|                                     if (item.SupId == "0")
 | |
|                                     {
 | |
|                                         row[1] = wb.WbsSetCode;
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         row[1] = item.SupId;
 | |
|                                     }
 | |
|                                     List<string> wbsSetIds = BLL.WbsSetService.GetWbsSetIdByInstallationIdAndCNCodeAndUnitProjectCodeAndWbsSetCode(item.Id, cnProfessionId, unitProjectCode, wbsSetCode);
 | |
|                                     foreach (var upId in wbsSetIds)
 | |
|                                     {
 | |
|                                         Model.View_WBS_CostControlParentDetail parentDetail = parentDetails.FirstOrDefault(x => x.ParentId == upId && x.Months == months);
 | |
|                                         if (parentDetail != null)
 | |
|                                         {
 | |
|                                             ind10 += decimal.Round(Convert.ToDecimal(parentDetail.ThisRealCost), 2);
 | |
|                                             ind11 += decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanValue), 2);
 | |
|                                             ind12 += decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanCost), 2);
 | |
|                                             ind15 += decimal.Round(Convert.ToDecimal(parentDetail.TotalRealCost), 2);
 | |
|                                             ind16 += decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanValue), 2);
 | |
|                                             ind17 += decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanCost), 2);
 | |
|                                         }
 | |
|                                         else
 | |
|                                         {
 | |
|                                             Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).FirstOrDefault(x => x.ParentId == upId);
 | |
|                                             if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                             {
 | |
|                                                 ind15 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalRealCost), 2);
 | |
|                                                 ind16 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanValue), 2);
 | |
|                                                 ind17 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanCost), 2);
 | |
|                                             }
 | |
|                                         }
 | |
|                                     }
 | |
|                                     if (ind10 != 0)
 | |
|                                     {
 | |
|                                         row[10] = decimal.Round(ind10, 2);//本月实际成本
 | |
|                                         row[11] = decimal.Round(ind11, 2);//本月计划完成预算
 | |
|                                         row[12] = decimal.Round(ind12, 2);//本月完成预算
 | |
|                                         row[15] = decimal.Round(ind15, 2);//累计完成成本
 | |
|                                         row[16] = decimal.Round(ind16, 2);//累计计划完成预算
 | |
|                                         row[17] = decimal.Round(ind17, 2);//累计完成预算
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         if (ind15 > 0)
 | |
|                                         {
 | |
|                                             row[15] = decimal.Round(ind15, 2);//累计完成成本
 | |
|                                         }
 | |
|                                         if (ind16 > 0)
 | |
|                                         {
 | |
|                                             row[16] = decimal.Round(ind16, 2);//累计计划完成预算
 | |
|                                         }
 | |
|                                         if (ind17 > 0)
 | |
|                                         {
 | |
|                                             row[17] = decimal.Round(ind17, 2);//累计完成预算
 | |
|                                         }
 | |
|                                     }
 | |
|                                 }
 | |
|                                 else if (item.WBSType == "CnProfession")
 | |
|                                 {
 | |
|                                     decimal cnd10 = 0, cnd11 = 0, cnd12 = 0, cnd15 = 0, cnd16 = 0, cnd17 = 0;
 | |
|                                     row[1] = item.SupId;
 | |
|                                     List<string> wbsSetIds = BLL.WbsSetService.GetWbsSetIdByCnProfessionIdAndUnitProjectCodeAndWbsSetCode(item.Id, unitProjectCode, wbsSetCode);
 | |
|                                     foreach (var upId in wbsSetIds)
 | |
|                                     {
 | |
|                                         Model.View_WBS_CostControlParentDetail parentDetail = parentDetails.FirstOrDefault(x => x.ParentId == upId && x.Months == months);
 | |
|                                         if (parentDetail != null)
 | |
|                                         {
 | |
|                                             cnd10 += decimal.Round(Convert.ToDecimal(parentDetail.ThisRealCost), 2);
 | |
|                                             cnd11 += decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanValue), 2);
 | |
|                                             cnd12 += decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanCost), 2);
 | |
|                                             cnd15 += decimal.Round(Convert.ToDecimal(parentDetail.TotalRealCost), 2);
 | |
|                                             cnd16 += decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanValue), 2);
 | |
|                                             cnd17 += decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanCost), 2);
 | |
|                                         }
 | |
|                                         else
 | |
|                                         {
 | |
|                                             Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).FirstOrDefault(x => x.ParentId == upId);
 | |
|                                             if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                             {
 | |
|                                                 cnd15 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalRealCost), 2);
 | |
|                                                 cnd16 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanValue), 2);
 | |
|                                                 cnd17 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanCost), 2);
 | |
|                                             }
 | |
|                                         }
 | |
|                                     }
 | |
|                                     if (cnd10 != 0)
 | |
|                                     {
 | |
|                                         row[10] = decimal.Round(cnd10, 2);//本月实际成本
 | |
|                                         row[11] = decimal.Round(cnd11, 2);//本月计划完成预算
 | |
|                                         row[12] = decimal.Round(cnd12, 2);//本月完成预算
 | |
|                                         row[15] = decimal.Round(cnd15, 2);//累计完成成本
 | |
|                                         row[16] = decimal.Round(cnd16, 2);//累计计划完成预算
 | |
|                                         row[17] = decimal.Round(cnd17, 2);//累计完成预算
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         if (cnd15 > 0)
 | |
|                                         {
 | |
|                                             row[15] = decimal.Round(cnd15, 2);//累计完成成本
 | |
|                                         }
 | |
|                                         if (cnd16 > 0)
 | |
|                                         {
 | |
|                                             row[16] = decimal.Round(cnd16, 2);//累计计划完成预算
 | |
|                                         }
 | |
|                                         if (cnd17 > 0)
 | |
|                                         {
 | |
|                                             row[17] = decimal.Round(cnd17, 2);//累计完成预算
 | |
|                                         }
 | |
|                                     }
 | |
|                                 }
 | |
|                                 else if (item.WBSType == "UnitProject")
 | |
|                                 {
 | |
|                                     decimal upd10 = 0, upd11 = 0, upd12 = 0, upd15 = 0, upd16 = 0, upd17 = 0;
 | |
|                                     row[1] = item.SupId;
 | |
|                                     List<string> wbsSetIds = BLL.WbsSetService.GetWbsSetIdByUnitProjectIdAndWbsSetCode(item.Id, wbsSetCode);
 | |
|                                     foreach (var upId in wbsSetIds)
 | |
|                                     {
 | |
|                                         Model.View_WBS_CostControlParentDetail parentDetail = parentDetails.FirstOrDefault(x => x.ParentId == upId && x.Months == months);
 | |
|                                         if (parentDetail != null)
 | |
|                                         {
 | |
|                                             upd10 += decimal.Round(Convert.ToDecimal(parentDetail.ThisRealCost), 2);
 | |
|                                             upd11 += decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanValue), 2);
 | |
|                                             upd12 += decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanCost), 2);
 | |
|                                             upd15 += decimal.Round(Convert.ToDecimal(parentDetail.TotalRealCost), 2);
 | |
|                                             upd16 += decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanValue), 2);
 | |
|                                             upd17 += decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanCost), 2);
 | |
|                                         }
 | |
|                                         else
 | |
|                                         {
 | |
|                                             Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).FirstOrDefault(x => x.ParentId == upId);
 | |
|                                             if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                             {
 | |
|                                                 upd15 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalRealCost), 2);
 | |
|                                                 upd16 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanValue), 2);
 | |
|                                                 upd17 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanCost), 2);
 | |
|                                             }
 | |
|                                         }
 | |
|                                     }
 | |
|                                     if (upd10 != 0)
 | |
|                                     {
 | |
|                                         row[10] = decimal.Round(upd10, 2);//本月实际成本
 | |
|                                         row[11] = decimal.Round(upd11, 2);//本月计划完成预算
 | |
|                                         row[12] = decimal.Round(upd12, 2);//本月完成预算
 | |
|                                         row[15] = decimal.Round(upd15, 2);//累计完成成本
 | |
|                                         row[16] = decimal.Round(upd16, 2);//累计计划完成预算
 | |
|                                         row[17] = decimal.Round(upd17, 2);//累计完成预算
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         if (upd15 > 0)
 | |
|                                         {
 | |
|                                             row[15] = decimal.Round(upd15, 2);//累计完成成本
 | |
|                                         }
 | |
|                                         if (upd16 > 0)
 | |
|                                         {
 | |
|                                             row[16] = decimal.Round(upd16, 2);//累计计划完成预算
 | |
|                                         }
 | |
|                                         if (upd17 > 0)
 | |
|                                         {
 | |
|                                             row[17] = decimal.Round(upd17, 2);//累计完成预算
 | |
|                                         }
 | |
|                                     }
 | |
|                                 }
 | |
|                                 else if (item.WBSType == "WbsSet")
 | |
|                                 {
 | |
|                                     row[1] = item.SupId;
 | |
|                                     var wbsSet = wbsSets.FirstOrDefault(x => x.WbsSetId == item.Id);
 | |
|                                     Model.View_WBS_CostControlParentDetail parentDetail = parentDetails.FirstOrDefault(x => x.ParentId == item.Id && x.Months == months);
 | |
|                                     if (parentDetail != null)
 | |
|                                     {
 | |
|                                         row[10] = decimal.Round(Convert.ToDecimal(parentDetail.ThisRealCost), 2);//本月实际成本
 | |
|                                         row[11] = decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanValue), 2);//本月计划完成预算
 | |
|                                         row[12] = decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanCost), 2);//本月完成预算
 | |
|                                         row[15] = decimal.Round(Convert.ToDecimal(parentDetail.TotalRealCost), 2);//累计完成成本
 | |
|                                         row[16] = decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                         row[17] = decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanCost), 2);//累计完成预算
 | |
|                                         if (wbsSet.SuperWbsSetId == null)  //工作包节点,累加数据
 | |
|                                         {
 | |
|                                             d10 += decimal.Round(Convert.ToDecimal(parentDetail.ThisRealCost), 2);
 | |
|                                             d11 += decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanValue), 2);
 | |
|                                             d12 += decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanCost), 2);
 | |
|                                             d15 += decimal.Round(Convert.ToDecimal(parentDetail.TotalRealCost), 2);
 | |
|                                             d16 += decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanValue), 2);
 | |
|                                             d17 += decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanCost), 2);
 | |
|                                         }
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).FirstOrDefault(x => x.ParentId == item.Id);
 | |
|                                         if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                         {
 | |
|                                             row[15] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalRealCost), 2);//累计完成成本
 | |
|                                             row[16] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                             row[17] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanCost), 2);//累计完成预算
 | |
|                                             if (wbsSet.SuperWbsSetId == null)  //工作包节点,累加数据
 | |
|                                             {
 | |
|                                                 d15 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalRealCost), 2);
 | |
|                                                 d16 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanValue), 2);
 | |
|                                                 d17 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanCost), 2);
 | |
|                                             }
 | |
|                                         }
 | |
|                                     }
 | |
|                                 }
 | |
|                                 else if (item.WBSType == "CostControl")
 | |
|                                 {
 | |
|                                     row[1] = item.SupId;
 | |
|                                     Model.View_WBS_CostControlDetail detail = details.FirstOrDefault(x => x.CostControlId == item.Id && x.Months == months);
 | |
|                                     if (detail != null)
 | |
|                                     {
 | |
|                                         row[4] = detail.Unit;//单位
 | |
|                                         row[5] = decimal.Round(Convert.ToDecimal(detail.TotalNum), 2);//合同工作量
 | |
|                                         row[6] = decimal.Round(Convert.ToDecimal(detail.RealPrice), 2);//成本单价
 | |
|                                         row[7] = decimal.Round(Convert.ToDecimal(detail.PlanNum), 2);//本月计划完成量
 | |
|                                         row[8] = decimal.Round(Convert.ToDecimal(detail.ThisNum), 2);//本月完成量
 | |
|                                         row[9] = decimal.Round(Convert.ToDecimal(detail.PlanPrice), 2);//控制预算单价
 | |
|                                         row[10] = decimal.Round(Convert.ToDecimal(detail.ThisRealCost), 2);//本月实际成本
 | |
|                                         row[11] = decimal.Round(Convert.ToDecimal(detail.ThisPlanValue), 2);//本月计划完成预算
 | |
|                                         row[12] = decimal.Round(Convert.ToDecimal(detail.ThisPlanCost), 2);//本月完成预算
 | |
|                                         row[13] = decimal.Round(Convert.ToDecimal(detail.TotalPlanNum), 2);//累计计划完成量
 | |
|                                         row[14] = decimal.Round(Convert.ToDecimal(detail.TotalThisNum), 2);//累计完成量
 | |
|                                         row[15] = decimal.Round(Convert.ToDecimal(detail.TotalRealCost), 2);//累计完成成本
 | |
|                                         row[16] = decimal.Round(Convert.ToDecimal(detail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                         row[17] = decimal.Round(Convert.ToDecimal(detail.TotalPlanCost), 2);//累计完成预算
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         Model.View_WBS_CostControlDetail lastDetail = details.OrderByDescending(x => x.Months).FirstOrDefault(x => x.CostControlId == item.Id);
 | |
|                                         if (lastDetail != null && lastDetail.Months <= months)
 | |
|                                         {
 | |
|                                             row[4] = lastDetail.Unit;//单位
 | |
|                                             row[5] = decimal.Round(Convert.ToDecimal(lastDetail.TotalNum), 2);//合同工作量
 | |
|                                             row[6] = decimal.Round(Convert.ToDecimal(lastDetail.RealPrice), 2);//成本单价
 | |
|                                             row[7] = decimal.Round(Convert.ToDecimal(lastDetail.PlanNum), 2);//本月计划完成量
 | |
|                                             row[8] = decimal.Round(Convert.ToDecimal(lastDetail.ThisNum), 2);//本月完成量
 | |
|                                             row[9] = decimal.Round(Convert.ToDecimal(lastDetail.PlanPrice), 2);//控制预算单价
 | |
|                                             row[13] = decimal.Round(Convert.ToDecimal(lastDetail.TotalPlanNum), 2);//累计计划完成量
 | |
|                                             row[14] = decimal.Round(Convert.ToDecimal(lastDetail.TotalThisNum), 2);//累计完成量
 | |
|                                             row[15] = decimal.Round(Convert.ToDecimal(lastDetail.TotalRealCost), 2);//累计完成成本
 | |
|                                             row[16] = decimal.Round(Convert.ToDecimal(lastDetail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                             row[17] = decimal.Round(Convert.ToDecimal(lastDetail.TotalPlanCost), 2);//累计完成预算
 | |
|                                         }
 | |
|                                     }
 | |
|                                 }
 | |
|                                 table.Rows.Add(row);
 | |
|                             }
 | |
|                             if (d10 != 0)
 | |
|                             {
 | |
|                                 parentRow[10] = decimal.Round(d10, 2);//本月实际成本
 | |
|                                 parentRow[11] = decimal.Round(d11, 2);//本月计划完成预算
 | |
|                                 parentRow[12] = decimal.Round(d12, 2);//本月完成预算
 | |
|                                 parentRow[15] = decimal.Round(d15, 2);//累计完成成本
 | |
|                                 parentRow[16] = decimal.Round(d16, 2);//累计计划完成预算
 | |
|                                 parentRow[17] = decimal.Round(d17, 2);//累计完成预算
 | |
|                             }
 | |
|                             else
 | |
|                             {
 | |
|                                 parentRow[15] = decimal.Round(d15, 2);//累计完成成本
 | |
|                                 parentRow[16] = decimal.Round(d16, 2);//累计计划完成预算
 | |
|                                 parentRow[17] = decimal.Round(d17, 2);//累计完成预算
 | |
|                             }
 | |
|                             table.Rows.Add(parentRow);
 | |
|                         }
 | |
|                         else
 | |
|                         {
 | |
|                             newList = (from x in newList where x.WBSType != "Installation" && x.WBSType != "CnProfession" && x.WBSType != "UnitProject" && x.OldCnProfessionId.ToString() == cnProfessionId && x.OldUnitProjectCode == unitProjectCode && x.OldWbsSetCode == wbsSetCode select x).ToList();
 | |
|                             var wb = newList.FirstOrDefault(x => x.WBSType == "WbsSet" && x.OldWbsSetCode == wbsSetCode);
 | |
|                             parentRow = table.NewRow();
 | |
|                             if (wb != null)
 | |
|                             {
 | |
|                                 parentRow[0] = wb.Id;
 | |
|                                 parentRow[1] = "0";
 | |
|                                 parentRow[2] = wb.Name;
 | |
|                                 parentRow[3] = projectId;
 | |
|                                 Model.View_WBS_CostControlParentDetail pparentDetail = parentDetails.FirstOrDefault(x => x.ParentId == wb.Id && x.Months == months);
 | |
|                                 if (pparentDetail != null)
 | |
|                                 {
 | |
|                                     d10 += decimal.Round(Convert.ToDecimal(pparentDetail.ThisRealCost), 2);
 | |
|                                     d11 += decimal.Round(Convert.ToDecimal(pparentDetail.ThisPlanValue), 2);
 | |
|                                     d12 += decimal.Round(Convert.ToDecimal(pparentDetail.ThisPlanCost), 2);
 | |
|                                     d15 += decimal.Round(Convert.ToDecimal(pparentDetail.TotalRealCost), 2);
 | |
|                                     d16 += decimal.Round(Convert.ToDecimal(pparentDetail.TotalPlanValue), 2);
 | |
|                                     d17 += decimal.Round(Convert.ToDecimal(pparentDetail.TotalPlanCost), 2);
 | |
|                                 }
 | |
|                                 else
 | |
|                                 {
 | |
|                                     Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).FirstOrDefault(x => x.ParentId == wb.Id);
 | |
|                                     if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                     {
 | |
|                                         d15 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalRealCost), 2);
 | |
|                                         d16 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanValue), 2);
 | |
|                                         d17 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanCost), 2);
 | |
|                                     }
 | |
|                                 }
 | |
|                                 foreach (Model.View_WBS_CostControlDetailStatistics item in newList)
 | |
|                                 {
 | |
|                                     row = table.NewRow();
 | |
|                                     row[0] = item.Id;
 | |
|                                     row[2] = item.Name;
 | |
|                                     row[3] = item.ProjectId;
 | |
|                                     if (item.WBSType == "WbsSet")
 | |
|                                     {
 | |
|                                         row[1] = item.SupId;
 | |
|                                         var wbsSet = wbsSets.FirstOrDefault(x => x.WbsSetId == item.Id);
 | |
|                                         Model.View_WBS_CostControlParentDetail parentDetail = parentDetails.FirstOrDefault(x => x.ParentId == item.Id && x.Months == months);
 | |
|                                         if (parentDetail != null)
 | |
|                                         {
 | |
|                                             row[10] = decimal.Round(Convert.ToDecimal(parentDetail.ThisRealCost), 2);//本月实际成本
 | |
|                                             row[11] = decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanValue), 2);//本月计划完成预算
 | |
|                                             row[12] = decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanCost), 2);//本月完成预算
 | |
|                                             row[15] = decimal.Round(Convert.ToDecimal(parentDetail.TotalRealCost), 2);//累计完成成本
 | |
|                                             row[16] = decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                             row[17] = decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanCost), 2);//累计完成预算
 | |
|                                         }
 | |
|                                         else
 | |
|                                         {
 | |
|                                             Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).FirstOrDefault(x => x.ParentId == item.Id);
 | |
|                                             if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                             {
 | |
|                                                 row[15] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalRealCost), 2);//累计完成成本
 | |
|                                                 row[16] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                                 row[17] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanCost), 2);//累计完成预算
 | |
|                                             }
 | |
|                                         }
 | |
|                                     }
 | |
|                                     else if (item.WBSType == "CostControl")
 | |
|                                     {
 | |
|                                         row[1] = item.SupId;
 | |
|                                         Model.View_WBS_CostControlDetail detail = details.FirstOrDefault(x => x.CostControlId == item.Id && x.Months == months);
 | |
|                                         if (detail != null)
 | |
|                                         {
 | |
|                                             row[4] = detail.Unit;//单位
 | |
|                                             row[5] = decimal.Round(Convert.ToDecimal(detail.TotalNum), 2);//合同工作量
 | |
|                                             row[6] = decimal.Round(Convert.ToDecimal(detail.RealPrice), 2);//成本单价
 | |
|                                             row[7] = decimal.Round(Convert.ToDecimal(detail.PlanNum), 2);//本月计划完成量
 | |
|                                             row[8] = decimal.Round(Convert.ToDecimal(detail.ThisNum), 2);//本月完成量
 | |
|                                             row[9] = decimal.Round(Convert.ToDecimal(detail.PlanPrice), 2);//控制预算单价
 | |
|                                             row[10] = decimal.Round(Convert.ToDecimal(detail.ThisRealCost), 2);//本月实际成本
 | |
|                                             row[11] = decimal.Round(Convert.ToDecimal(detail.ThisPlanValue), 2);//本月计划完成预算
 | |
|                                             row[12] = decimal.Round(Convert.ToDecimal(detail.ThisPlanCost), 2);//本月完成预算
 | |
|                                             row[13] = decimal.Round(Convert.ToDecimal(detail.TotalPlanNum), 2);//累计计划完成量
 | |
|                                             row[14] = decimal.Round(Convert.ToDecimal(detail.TotalThisNum), 2);//累计完成量
 | |
|                                             row[15] = decimal.Round(Convert.ToDecimal(detail.TotalRealCost), 2);//累计完成成本
 | |
|                                             row[16] = decimal.Round(Convert.ToDecimal(detail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                             row[17] = decimal.Round(Convert.ToDecimal(detail.TotalPlanCost), 2);//累计完成预算
 | |
|                                         }
 | |
|                                         else
 | |
|                                         {
 | |
|                                             Model.View_WBS_CostControlDetail lastDetail = details.OrderByDescending(x => x.Months).FirstOrDefault(x => x.CostControlId == item.Id);
 | |
|                                             if (lastDetail != null && lastDetail.Months <= months)
 | |
|                                             {
 | |
|                                                 row[4] = lastDetail.Unit;//单位
 | |
|                                                 row[5] = decimal.Round(Convert.ToDecimal(lastDetail.TotalNum), 2);//合同工作量
 | |
|                                                 row[6] = decimal.Round(Convert.ToDecimal(lastDetail.RealPrice), 2);//成本单价
 | |
|                                                 row[7] = decimal.Round(Convert.ToDecimal(lastDetail.PlanNum), 2);//本月计划完成量
 | |
|                                                 row[8] = decimal.Round(Convert.ToDecimal(lastDetail.ThisNum), 2);//本月完成量
 | |
|                                                 row[9] = decimal.Round(Convert.ToDecimal(lastDetail.PlanPrice), 2);//控制预算单价
 | |
|                                                 row[13] = decimal.Round(Convert.ToDecimal(lastDetail.TotalPlanNum), 2);//累计计划完成量
 | |
|                                                 row[14] = decimal.Round(Convert.ToDecimal(lastDetail.TotalThisNum), 2);//累计完成量
 | |
|                                                 row[15] = decimal.Round(Convert.ToDecimal(lastDetail.TotalRealCost), 2);//累计完成成本
 | |
|                                                 row[16] = decimal.Round(Convert.ToDecimal(lastDetail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                                                 row[17] = decimal.Round(Convert.ToDecimal(lastDetail.TotalPlanCost), 2);//累计完成预算
 | |
|                                             }
 | |
|                                         }
 | |
|                                     }
 | |
|                                     table.Rows.Add(row);
 | |
|                                 }
 | |
|                                 if (d10 != 0)
 | |
|                                 {
 | |
|                                     parentRow[10] = decimal.Round(d10, 2);//本月实际成本
 | |
|                                     parentRow[11] = decimal.Round(d11, 2);//本月计划完成预算
 | |
|                                     parentRow[12] = decimal.Round(d12, 2);//本月完成预算
 | |
|                                     parentRow[15] = decimal.Round(d15, 2);//累计完成成本
 | |
|                                     parentRow[16] = decimal.Round(d16, 2);//累计计划完成预算
 | |
|                                     parentRow[17] = decimal.Round(d17, 2);//累计完成预算
 | |
|                                 }
 | |
|                                 else
 | |
|                                 {
 | |
|                                     parentRow[15] = decimal.Round(d15, 2);//累计完成成本
 | |
|                                     parentRow[16] = decimal.Round(d16, 2);//累计计划完成预算
 | |
|                                     parentRow[17] = decimal.Round(d17, 2);//累计完成预算
 | |
|                                 }
 | |
|                                 table.Rows.Add(parentRow);
 | |
|                             }
 | |
|                         }
 | |
|                     }
 | |
|                     #endregion
 | |
|                 }
 | |
|             }
 | |
|             #endregion
 | |
|             #region 按周统计
 | |
|             else
 | |
|             {
 | |
|                 DateTime start = Convert.ToDateTime(startDate.Split(',')[0]);
 | |
|                 #region 全部统计
 | |
|                 if (cnProfessionId == BLL.Const._Null)   //全部统计
 | |
|                 {
 | |
|                     foreach (Model.View_WBS_CostControlDetailStatistics item in newList)
 | |
|                     {
 | |
|                         row = table.NewRow();
 | |
|                         row[0] = item.Id;
 | |
|                         row[1] = item.SupId;
 | |
|                         row[2] = item.Name;
 | |
|                         row[3] = item.ProjectId;
 | |
|                         Model.WBS_CostControl costControl = costControls.FirstOrDefault(x => x.CostControlId == item.Id);
 | |
|                         if (costControl != null)
 | |
|                         {
 | |
|                             Model.View_WBS_CostControlDetail detail = details.FirstOrDefault(x => x.CostControlId == item.Id && x.Months == months && x.StartDate == start);
 | |
|                             if (detail != null)
 | |
|                             {
 | |
|                                 row[4] = detail.Unit;//单位
 | |
|                                 row[5] = decimal.Round(Convert.ToDecimal(detail.TotalNum), 2);//合同工作量
 | |
|                                 row[6] = decimal.Round(Convert.ToDecimal(detail.RealPrice), 2);//成本单价
 | |
|                                 row[7] = decimal.Round(Convert.ToDecimal(detail.PlanWeekNum), 2);//本周计划完成量
 | |
|                                 row[8] = decimal.Round(Convert.ToDecimal(detail.ThisWeekNum), 2);//本周完成量
 | |
|                                 row[9] = decimal.Round(Convert.ToDecimal(detail.PlanPrice), 2);//控制预算单价
 | |
|                                 row[10] = decimal.Round(Convert.ToDecimal(detail.ThisWeekRealCost), 2);//本周实际成本
 | |
|                                 row[11] = decimal.Round(Convert.ToDecimal(detail.ThisWeekPlanValue), 2);//本周计划完成预算
 | |
|                                 row[12] = decimal.Round(Convert.ToDecimal(detail.ThisWeekPlanCost), 2);//本周完成预算
 | |
|                                 row[13] = decimal.Round(Convert.ToDecimal(detail.TotalWeekPlanNum), 2);//累计计划完成量
 | |
|                                 row[14] = decimal.Round(Convert.ToDecimal(detail.TotalWeekThisNum), 2);//累计完成量
 | |
|                                 row[15] = decimal.Round(Convert.ToDecimal(detail.TotalWeekRealCost), 2);//累计完成成本
 | |
|                                 row[16] = decimal.Round(Convert.ToDecimal(detail.TotalWeekPlanValue), 2);//累计计划完成预算
 | |
|                                 row[17] = decimal.Round(Convert.ToDecimal(detail.TotalWeekPlanCost), 2);//累计完成预算
 | |
|                             }
 | |
|                             else
 | |
|                             {
 | |
|                                 Model.View_WBS_CostControlDetail lastDetail = details.OrderByDescending(x => x.Months).OrderByDescending(x => x.StartDate).FirstOrDefault(x => x.CostControlId == item.Id);
 | |
|                                 if (lastDetail != null && lastDetail.Months <= months)
 | |
|                                 {
 | |
|                                     row[4] = lastDetail.Unit;//单位
 | |
|                                     row[5] = decimal.Round(Convert.ToDecimal(lastDetail.TotalNum), 2);//合同工作量
 | |
|                                     row[6] = decimal.Round(Convert.ToDecimal(lastDetail.RealPrice), 2);//成本单价
 | |
|                                     row[7] = decimal.Round(Convert.ToDecimal(lastDetail.PlanWeekNum), 2);//本周计划完成量
 | |
|                                     row[8] = decimal.Round(Convert.ToDecimal(lastDetail.ThisWeekNum), 2);//本周完成量
 | |
|                                     row[9] = decimal.Round(Convert.ToDecimal(lastDetail.PlanPrice), 2);//控制预算单价
 | |
|                                     row[13] = decimal.Round(Convert.ToDecimal(lastDetail.TotalWeekPlanNum), 2);//累计计划完成量
 | |
|                                     row[14] = decimal.Round(Convert.ToDecimal(lastDetail.TotalWeekThisNum), 2);//累计完成量
 | |
|                                     row[15] = decimal.Round(Convert.ToDecimal(lastDetail.TotalWeekRealCost), 2);//累计完成成本
 | |
|                                     row[16] = decimal.Round(Convert.ToDecimal(lastDetail.TotalWeekPlanValue), 2);//累计计划完成预算
 | |
|                                     row[17] = decimal.Round(Convert.ToDecimal(lastDetail.TotalWeekPlanCost), 2);//累计完成预算
 | |
|                                 }
 | |
|                             }
 | |
|                         }
 | |
|                         else
 | |
|                         {
 | |
|                             Model.View_WBS_CostControlParentDetail parentDetail = parentDetails.FirstOrDefault(x => x.ParentId == item.Id && x.Months == months && x.StartDate == start);
 | |
|                             if (parentDetail != null)
 | |
|                             {
 | |
|                                 row[10] = decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekRealCost), 2);//本周实际成本
 | |
|                                 row[11] = decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekPlanValue), 2);//本周计划完成预算
 | |
|                                 row[12] = decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekPlanCost), 2);//本周完成预算
 | |
|                                 row[15] = decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekRealCost), 2);//累计完成成本
 | |
|                                 row[16] = decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekPlanValue), 2);//累计计划完成预算
 | |
|                                 row[17] = decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekPlanCost), 2);//累计完成预算
 | |
|                             }
 | |
|                             else
 | |
|                             {
 | |
|                                 Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).OrderByDescending(x => x.StartDate).FirstOrDefault(x => x.ParentId == item.Id);
 | |
|                                 if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                 {
 | |
|                                     row[15] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekRealCost), 2);//累计完成成本
 | |
|                                     row[16] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanValue), 2);//累计计划完成预算
 | |
|                                     row[17] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanCost), 2);//累计完成预算
 | |
|                                 }
 | |
|                             }
 | |
|                         }
 | |
|                         table.Rows.Add(row);
 | |
|                     }
 | |
|                 }
 | |
|                 #endregion
 | |
|                 else
 | |
|                 {
 | |
|                     decimal d10 = 0, d11 = 0, d12 = 0, d15 = 0, d16 = 0, d17 = 0;
 | |
|                     #region  按专业
 | |
|                     if (unitProjectCode == BLL.Const._Null)
 | |
|                     {
 | |
|                         if (cnProfessionId != Const.ACCNProfessionalId.ToString() && cnProfessionId != Const.GECNProfessionalId.ToString() && cnProfessionId != Const.UPCNProfessionalId.ToString() && cnProfessionId != Const.TFCNProfessionalId.ToString() && cnProfessionId != Const.GLCNProfessionalId.ToString())
 | |
|                         {
 | |
|                             newList = (from x in newList where (x.WBSType == "Installation" && !x.Name.Contains("防腐绝热") && !x.Name.Contains("地勘") && !x.Name.Contains("全厂地下主管网") && !x.Name.Contains("临时设施") && !x.Name.Contains("总图")) || (x.WBSType != "Installation" && x.OldCnProfessionId.ToString() == cnProfessionId) select x).ToList();
 | |
|                             var cn = cnProfessionInits.FirstOrDefault(x => x.CnProfessionId.ToString() == cnProfessionId);
 | |
|                             parentRow = table.NewRow();
 | |
|                             parentRow[0] = cn.CnProfessionId.ToString();
 | |
|                             parentRow[1] = "0";
 | |
|                             parentRow[2] = cn.CnProfessionName;
 | |
|                             parentRow[3] = projectId;
 | |
|                             var cnList = newList.Where(x => x.WBSType == "CnProfession");
 | |
|                             foreach (Model.View_WBS_CostControlDetailStatistics item in cnList)
 | |
|                             {
 | |
|                                 Model.View_WBS_CostControlParentDetail parentDetail = parentDetails.FirstOrDefault(x => x.ParentId == item.Id && x.Months == months && x.StartDate == start);
 | |
|                                 if (parentDetail != null)
 | |
|                                 {
 | |
|                                     d10 += decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekRealCost), 2);
 | |
|                                     d11 += decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekPlanValue), 2);
 | |
|                                     d12 += decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekPlanCost), 2);
 | |
|                                     d15 += decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekRealCost), 2);
 | |
|                                     d16 += decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekPlanValue), 2);
 | |
|                                     d17 += decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekPlanCost), 2);
 | |
|                                 }
 | |
|                                 else
 | |
|                                 {
 | |
|                                     Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).OrderByDescending(x => x.StartDate).FirstOrDefault(x => x.ParentId == item.Id);
 | |
|                                     if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                     {
 | |
|                                         d15 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekRealCost), 2);
 | |
|                                         d16 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanValue), 2);
 | |
|                                         d17 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanCost), 2);
 | |
|                                     }
 | |
|                                 }
 | |
|                             }
 | |
|                             if (d10 != 0)
 | |
|                             {
 | |
|                                 parentRow[10] = decimal.Round(d10, 2);//本周实际成本
 | |
|                                 parentRow[11] = decimal.Round(d11, 2);//本周计划完成预算
 | |
|                                 parentRow[12] = decimal.Round(d12, 2);//本周完成预算
 | |
|                                 parentRow[15] = decimal.Round(d15, 2);//累计完成成本
 | |
|                                 parentRow[16] = decimal.Round(d16, 2);//累计计划完成预算
 | |
|                                 parentRow[17] = decimal.Round(d17, 2);//累计完成预算
 | |
|                             }
 | |
|                             else
 | |
|                             {
 | |
|                                 parentRow[15] = decimal.Round(d15, 2);//累计完成成本
 | |
|                                 parentRow[16] = decimal.Round(d16, 2);//累计计划完成预算
 | |
|                                 parentRow[17] = decimal.Round(d17, 2);//累计完成预算
 | |
|                             }
 | |
|                             table.Rows.Add(parentRow);
 | |
|                             foreach (Model.View_WBS_CostControlDetailStatistics item in newList)
 | |
|                             {
 | |
|                                 row = table.NewRow();
 | |
|                                 row[0] = item.Id;
 | |
|                                 row[2] = item.Name;
 | |
|                                 row[3] = item.ProjectId;
 | |
|                                 if (item.WBSType == "Installation")
 | |
|                                 {
 | |
|                                     decimal ind10 = 0, ind11 = 0, ind12 = 0, ind15 = 0, ind16 = 0, ind17 = 0;
 | |
|                                     if (item.SupId == "0")
 | |
|                                     {
 | |
|                                         row[1] = cn.CnProfessionId.ToString();
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         row[1] = item.SupId;
 | |
|                                     }
 | |
|                                     List<string> cnIds = BLL.CnProfessionService.GetCnProfessionIdsByInstallationIdAndOldId(item.Id, cnProfessionId);
 | |
|                                     foreach (var cnId in cnIds)
 | |
|                                     {
 | |
|                                         Model.View_WBS_CostControlParentDetail parentDetail = parentDetails.FirstOrDefault(x => x.ParentId == cnId && x.Months == months && x.StartDate == start);
 | |
|                                         if (parentDetail != null)
 | |
|                                         {
 | |
|                                             ind10 += decimal.Round(Convert.ToDecimal(parentDetail.ThisRealCost), 2);
 | |
|                                             ind11 += decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanValue), 2);
 | |
|                                             ind12 += decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanCost), 2);
 | |
|                                             ind15 += decimal.Round(Convert.ToDecimal(parentDetail.TotalRealCost), 2);
 | |
|                                             ind16 += decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanValue), 2);
 | |
|                                             ind17 += decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanCost), 2);
 | |
|                                         }
 | |
|                                         else
 | |
|                                         {
 | |
|                                             Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).OrderByDescending(x => x.StartDate).FirstOrDefault(x => x.ParentId == cnId);
 | |
|                                             if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                             {
 | |
|                                                 ind15 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalRealCost), 2);
 | |
|                                                 ind16 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanValue), 2);
 | |
|                                                 ind17 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanCost), 2);
 | |
|                                             }
 | |
|                                         }
 | |
|                                     }
 | |
|                                     if (ind10 != 0)
 | |
|                                     {
 | |
|                                         row[10] = decimal.Round(ind10, 2);//本月实际成本
 | |
|                                         row[11] = decimal.Round(ind11, 2);//本月计划完成预算
 | |
|                                         row[12] = decimal.Round(ind12, 2);//本月完成预算
 | |
|                                         row[15] = decimal.Round(ind15, 2);//累计完成成本
 | |
|                                         row[16] = decimal.Round(ind16, 2);//累计计划完成预算
 | |
|                                         row[17] = decimal.Round(ind17, 2);//累计完成预算
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         if (ind15 > 0)
 | |
|                                         {
 | |
|                                             row[15] = decimal.Round(ind15, 2);//累计完成成本
 | |
|                                         }
 | |
|                                         if (ind16 > 0)
 | |
|                                         {
 | |
|                                             row[16] = decimal.Round(ind16, 2);//累计计划完成预算
 | |
|                                         }
 | |
|                                         if (ind17 > 0)
 | |
|                                         {
 | |
|                                             row[17] = decimal.Round(ind17, 2);//累计完成预算
 | |
|                                         }
 | |
|                                     }
 | |
|                                 }
 | |
|                                 else if (item.WBSType == "CnProfession")
 | |
|                                 {
 | |
|                                     row[1] = item.SupId;
 | |
|                                     Model.View_WBS_CostControlParentDetail parentDetail = parentDetails.FirstOrDefault(x => x.ParentId == item.Id && x.Months == months && x.StartDate == start);
 | |
|                                     if (parentDetail != null)
 | |
|                                     {
 | |
|                                         row[10] = decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekRealCost), 2);//本周实际成本
 | |
|                                         row[11] = decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekPlanValue), 2);//本周计划完成预算
 | |
|                                         row[12] = decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekPlanCost), 2);//本周完成预算
 | |
|                                         row[15] = decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekRealCost), 2);//累计完成成本
 | |
|                                         row[16] = decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekPlanValue), 2);//累计计划完成预算
 | |
|                                         row[17] = decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekPlanCost), 2);//累计完成预算
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).OrderByDescending(x => x.StartDate).FirstOrDefault(x => x.ParentId == item.Id);
 | |
|                                         if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                         {
 | |
|                                             row[15] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekRealCost), 2);//累计完成成本
 | |
|                                             row[16] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanValue), 2);//累计计划完成预算
 | |
|                                             row[17] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanCost), 2);//累计完成预算
 | |
|                                         }
 | |
|                                     }
 | |
|                                 }
 | |
|                                 else if (item.WBSType == "UnitProject")
 | |
|                                 {
 | |
|                                     row[1] = item.SupId;
 | |
|                                     Model.View_WBS_CostControlParentDetail parentDetail = parentDetails.FirstOrDefault(x => x.ParentId == item.Id && x.Months == months && x.StartDate == start);
 | |
|                                     if (parentDetail != null)
 | |
|                                     {
 | |
|                                         row[10] = decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekRealCost), 2);//本周实际成本
 | |
|                                         row[11] = decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekPlanValue), 2);//本周计划完成预算
 | |
|                                         row[12] = decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekPlanCost), 2);//本周完成预算
 | |
|                                         row[15] = decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekRealCost), 2);//累计完成成本
 | |
|                                         row[16] = decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekPlanValue), 2);//累计计划完成预算
 | |
|                                         row[17] = decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekPlanCost), 2);//累计完成预算
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).OrderByDescending(x => x.StartDate).FirstOrDefault(x => x.ParentId == item.Id);
 | |
|                                         if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                         {
 | |
|                                             row[15] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekRealCost), 2);//累计完成成本
 | |
|                                             row[16] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanValue), 2);//累计计划完成预算
 | |
|                                             row[17] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanCost), 2);//累计完成预算
 | |
|                                         }
 | |
|                                     }
 | |
|                                 }
 | |
|                                 else if (item.WBSType == "WbsSet")
 | |
|                                 {
 | |
|                                     row[1] = item.SupId;
 | |
|                                     Model.View_WBS_CostControlParentDetail parentDetail = parentDetails.FirstOrDefault(x => x.ParentId == item.Id && x.Months == months && x.StartDate == start);
 | |
|                                     if (parentDetail != null)
 | |
|                                     {
 | |
|                                         row[10] = decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekRealCost), 2);//本周实际成本
 | |
|                                         row[11] = decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekPlanValue), 2);//本周计划完成预算
 | |
|                                         row[12] = decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekPlanCost), 2);//本周完成预算
 | |
|                                         row[15] = decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekRealCost), 2);//累计完成成本
 | |
|                                         row[16] = decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekPlanValue), 2);//累计计划完成预算
 | |
|                                         row[17] = decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekPlanCost), 2);//累计完成预算
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).OrderByDescending(x => x.StartDate).FirstOrDefault(x => x.ParentId == item.Id);
 | |
|                                         if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                         {
 | |
|                                             row[15] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekRealCost), 2);//累计完成成本
 | |
|                                             row[16] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanValue), 2);//累计计划完成预算
 | |
|                                             row[17] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanCost), 2);//累计完成预算
 | |
|                                         }
 | |
|                                     }
 | |
|                                 }
 | |
|                                 else if (item.WBSType == "CostControl")
 | |
|                                 {
 | |
|                                     row[1] = item.SupId;
 | |
|                                     Model.View_WBS_CostControlDetail detail = details.FirstOrDefault(x => x.CostControlId == item.Id && x.Months == months && x.StartDate == start);
 | |
|                                     if (detail != null)
 | |
|                                     {
 | |
|                                         row[4] = detail.Unit;//单位
 | |
|                                         row[5] = decimal.Round(Convert.ToDecimal(detail.TotalNum), 2);//合同工作量
 | |
|                                         row[6] = decimal.Round(Convert.ToDecimal(detail.RealPrice), 2);//成本单价
 | |
|                                         row[7] = decimal.Round(Convert.ToDecimal(detail.PlanWeekNum), 2);//本周计划完成量
 | |
|                                         row[8] = decimal.Round(Convert.ToDecimal(detail.ThisWeekNum), 2);//本周完成量
 | |
|                                         row[9] = decimal.Round(Convert.ToDecimal(detail.PlanPrice), 2);//控制预算单价
 | |
|                                         row[10] = decimal.Round(Convert.ToDecimal(detail.ThisWeekRealCost), 2);//本周实际成本
 | |
|                                         row[11] = decimal.Round(Convert.ToDecimal(detail.ThisWeekPlanValue), 2);//本周计划完成预算
 | |
|                                         row[12] = decimal.Round(Convert.ToDecimal(detail.ThisWeekPlanCost), 2);//本周完成预算
 | |
|                                         row[13] = decimal.Round(Convert.ToDecimal(detail.TotalWeekPlanNum), 2);//累计计划完成量
 | |
|                                         row[14] = decimal.Round(Convert.ToDecimal(detail.TotalWeekThisNum), 2);//累计完成量
 | |
|                                         row[15] = decimal.Round(Convert.ToDecimal(detail.TotalWeekRealCost), 2);//累计完成成本
 | |
|                                         row[16] = decimal.Round(Convert.ToDecimal(detail.TotalWeekPlanValue), 2);//累计计划完成预算
 | |
|                                         row[17] = decimal.Round(Convert.ToDecimal(detail.TotalWeekPlanCost), 2);//累计完成预算
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         Model.View_WBS_CostControlDetail lastDetail = details.OrderByDescending(x => x.Months).OrderByDescending(x => x.StartDate).FirstOrDefault(x => x.CostControlId == item.Id);
 | |
|                                         if (lastDetail != null && lastDetail.Months <= months)
 | |
|                                         {
 | |
|                                             row[4] = lastDetail.Unit;//单位
 | |
|                                             row[5] = decimal.Round(Convert.ToDecimal(lastDetail.TotalNum), 2);//合同工作量
 | |
|                                             row[6] = decimal.Round(Convert.ToDecimal(lastDetail.RealPrice), 2);//成本单价
 | |
|                                             row[7] = decimal.Round(Convert.ToDecimal(lastDetail.PlanWeekNum), 2);//本周计划完成量
 | |
|                                             row[8] = decimal.Round(Convert.ToDecimal(lastDetail.ThisWeekNum), 2);//本周完成量
 | |
|                                             row[9] = decimal.Round(Convert.ToDecimal(lastDetail.PlanPrice), 2);//控制预算单价
 | |
|                                             row[13] = decimal.Round(Convert.ToDecimal(lastDetail.TotalWeekPlanNum), 2);//累计计划完成量
 | |
|                                             row[14] = decimal.Round(Convert.ToDecimal(lastDetail.TotalWeekThisNum), 2);//累计完成量
 | |
|                                             row[15] = decimal.Round(Convert.ToDecimal(lastDetail.TotalWeekRealCost), 2);//累计完成成本
 | |
|                                             row[16] = decimal.Round(Convert.ToDecimal(lastDetail.TotalWeekPlanValue), 2);//累计计划完成预算
 | |
|                                             row[17] = decimal.Round(Convert.ToDecimal(lastDetail.TotalWeekPlanCost), 2);//累计完成预算
 | |
|                                         }
 | |
|                                     }
 | |
|                                 }
 | |
|                                 table.Rows.Add(row);
 | |
|                             }
 | |
|                         }
 | |
|                         else
 | |
|                         {
 | |
|                             Model.WBS_CnProfessionInit cnInit = BLL.CnProfessionInitService.GetCnProfessionInitByCnProfessionId(cnProfessionId);
 | |
|                             newList = (from x in newList where (x.WBSType == "Installation" && x.Name == cnInit.CnProfessionName) || (x.WBSType != "Installation" && x.OldCnProfessionId.ToString() == cnProfessionId) select x).ToList();
 | |
|                             var cn = newList.FirstOrDefault(x => x.Name == cnInit.CnProfessionName);
 | |
|                             parentRow = table.NewRow();
 | |
|                             parentRow[0] = cn.Id;
 | |
|                             parentRow[1] = "0";
 | |
|                             parentRow[2] = cn.Name;
 | |
|                             parentRow[3] = projectId;
 | |
|                             Model.View_WBS_CostControlParentDetail pparentDetail = parentDetails.FirstOrDefault(x => x.ParentId == cn.Id && x.Months == months && x.StartDate == start);
 | |
|                             if (pparentDetail != null)
 | |
|                             {
 | |
|                                 d10 += decimal.Round(Convert.ToDecimal(pparentDetail.ThisWeekRealCost), 2);
 | |
|                                 d11 += decimal.Round(Convert.ToDecimal(pparentDetail.ThisWeekPlanValue), 2);
 | |
|                                 d12 += decimal.Round(Convert.ToDecimal(pparentDetail.ThisWeekPlanCost), 2);
 | |
|                                 d15 += decimal.Round(Convert.ToDecimal(pparentDetail.TotalWeekRealCost), 2);
 | |
|                                 d16 += decimal.Round(Convert.ToDecimal(pparentDetail.TotalWeekPlanValue), 2);
 | |
|                                 d17 += decimal.Round(Convert.ToDecimal(pparentDetail.TotalWeekPlanCost), 2);
 | |
|                             }
 | |
|                             else
 | |
|                             {
 | |
|                                 Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).OrderByDescending(x => x.StartDate).FirstOrDefault(x => x.ParentId == cn.Id);
 | |
|                                 if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                 {
 | |
|                                     d15 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekRealCost), 2);
 | |
|                                     d16 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanValue), 2);
 | |
|                                     d17 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanCost), 2);
 | |
|                                 }
 | |
|                             }
 | |
|                             if (d10 != 0)
 | |
|                             {
 | |
|                                 parentRow[10] = decimal.Round(d10, 2);//本周实际成本
 | |
|                                 parentRow[11] = decimal.Round(d11, 2);//本周计划完成预算
 | |
|                                 parentRow[12] = decimal.Round(d12, 2);//本周完成预算
 | |
|                                 parentRow[15] = decimal.Round(d15, 2);//累计完成成本
 | |
|                                 parentRow[16] = decimal.Round(d16, 2);//累计计划完成预算
 | |
|                                 parentRow[17] = decimal.Round(d17, 2);//累计完成预算
 | |
|                             }
 | |
|                             else
 | |
|                             {
 | |
|                                 parentRow[15] = decimal.Round(d15, 2);//累计完成成本
 | |
|                                 parentRow[16] = decimal.Round(d16, 2);//累计计划完成预算
 | |
|                                 parentRow[17] = decimal.Round(d17, 2);//累计完成预算
 | |
|                             }
 | |
|                             table.Rows.Add(parentRow);
 | |
|                             foreach (Model.View_WBS_CostControlDetailStatistics item in newList)
 | |
|                             {
 | |
|                                 row = table.NewRow();
 | |
|                                 row[0] = item.Id;
 | |
|                                 row[2] = item.Name;
 | |
|                                 row[3] = item.ProjectId;
 | |
|                                 if (item.WBSType == "UnitProject")
 | |
|                                 {
 | |
|                                     row[1] = item.SupId;
 | |
|                                     Model.View_WBS_CostControlParentDetail parentDetail = parentDetails.FirstOrDefault(x => x.ParentId == item.Id && x.Months == months && x.StartDate == start);
 | |
|                                     if (parentDetail != null)
 | |
|                                     {
 | |
|                                         row[10] = decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekRealCost), 2);//本周实际成本
 | |
|                                         row[11] = decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekPlanValue), 2);//本周计划完成预算
 | |
|                                         row[12] = decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekPlanCost), 2);//本周完成预算
 | |
|                                         row[15] = decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekRealCost), 2);//累计完成成本
 | |
|                                         row[16] = decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekPlanValue), 2);//累计计划完成预算
 | |
|                                         row[17] = decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekPlanCost), 2);//累计完成预算
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).OrderByDescending(x => x.StartDate).FirstOrDefault(x => x.ParentId == item.Id);
 | |
|                                         if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                         {
 | |
|                                             row[15] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekRealCost), 2);//累计完成成本
 | |
|                                             row[16] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanValue), 2);//累计计划完成预算
 | |
|                                             row[17] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanCost), 2);//累计完成预算
 | |
|                                         }
 | |
|                                     }
 | |
|                                 }
 | |
|                                 else if (item.WBSType == "WbsSet")
 | |
|                                 {
 | |
|                                     row[1] = item.SupId;
 | |
|                                     Model.View_WBS_CostControlParentDetail parentDetail = parentDetails.FirstOrDefault(x => x.ParentId == item.Id && x.Months == months && x.StartDate == start);
 | |
|                                     if (parentDetail != null)
 | |
|                                     {
 | |
|                                         row[10] = decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekRealCost), 2);//本周实际成本
 | |
|                                         row[11] = decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekPlanValue), 2);//本周计划完成预算
 | |
|                                         row[12] = decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekPlanCost), 2);//本周完成预算
 | |
|                                         row[15] = decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekRealCost), 2);//累计完成成本
 | |
|                                         row[16] = decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekPlanValue), 2);//累计计划完成预算
 | |
|                                         row[17] = decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekPlanCost), 2);//累计完成预算
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).OrderByDescending(x => x.StartDate).FirstOrDefault(x => x.ParentId == item.Id);
 | |
|                                         if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                         {
 | |
|                                             row[15] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekRealCost), 2);//累计完成成本
 | |
|                                             row[16] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanValue), 2);//累计计划完成预算
 | |
|                                             row[17] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanCost), 2);//累计完成预算
 | |
|                                         }
 | |
|                                     }
 | |
|                                 }
 | |
|                                 else if (item.WBSType == "CostControl")
 | |
|                                 {
 | |
|                                     row[1] = item.SupId;
 | |
|                                     Model.View_WBS_CostControlDetail detail = details.FirstOrDefault(x => x.CostControlId == item.Id && x.Months == months && x.StartDate == start);
 | |
|                                     if (detail != null)
 | |
|                                     {
 | |
|                                         row[4] = detail.Unit;//单位
 | |
|                                         row[5] = decimal.Round(Convert.ToDecimal(detail.TotalNum), 2);//合同工作量
 | |
|                                         row[6] = decimal.Round(Convert.ToDecimal(detail.RealPrice), 2);//成本单价
 | |
|                                         row[7] = decimal.Round(Convert.ToDecimal(detail.PlanWeekNum), 2);//本周计划完成量
 | |
|                                         row[8] = decimal.Round(Convert.ToDecimal(detail.ThisWeekNum), 2);//本周完成量
 | |
|                                         row[9] = decimal.Round(Convert.ToDecimal(detail.PlanPrice), 2);//控制预算单价
 | |
|                                         row[10] = decimal.Round(Convert.ToDecimal(detail.ThisWeekRealCost), 2);//本周实际成本
 | |
|                                         row[11] = decimal.Round(Convert.ToDecimal(detail.ThisWeekPlanValue), 2);//本周计划完成预算
 | |
|                                         row[12] = decimal.Round(Convert.ToDecimal(detail.ThisWeekPlanCost), 2);//本周完成预算
 | |
|                                         row[13] = decimal.Round(Convert.ToDecimal(detail.TotalWeekPlanNum), 2);//累计计划完成量
 | |
|                                         row[14] = decimal.Round(Convert.ToDecimal(detail.TotalWeekThisNum), 2);//累计完成量
 | |
|                                         row[15] = decimal.Round(Convert.ToDecimal(detail.TotalWeekRealCost), 2);//累计完成成本
 | |
|                                         row[16] = decimal.Round(Convert.ToDecimal(detail.TotalWeekPlanValue), 2);//累计计划完成预算
 | |
|                                         row[17] = decimal.Round(Convert.ToDecimal(detail.TotalWeekPlanCost), 2);//累计完成预算
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         Model.View_WBS_CostControlDetail lastDetail = details.OrderByDescending(x => x.Months).OrderByDescending(x => x.StartDate).FirstOrDefault(x => x.CostControlId == item.Id);
 | |
|                                         if (lastDetail != null && lastDetail.Months <= months)
 | |
|                                         {
 | |
|                                             row[4] = lastDetail.Unit;//单位
 | |
|                                             row[5] = decimal.Round(Convert.ToDecimal(lastDetail.TotalNum), 2);//合同工作量
 | |
|                                             row[6] = decimal.Round(Convert.ToDecimal(lastDetail.RealPrice), 2);//成本单价
 | |
|                                             row[7] = decimal.Round(Convert.ToDecimal(lastDetail.PlanWeekNum), 2);//本周计划完成量
 | |
|                                             row[8] = decimal.Round(Convert.ToDecimal(lastDetail.ThisWeekNum), 2);//本周完成量
 | |
|                                             row[9] = decimal.Round(Convert.ToDecimal(lastDetail.PlanPrice), 2);//控制预算单价
 | |
|                                             row[13] = decimal.Round(Convert.ToDecimal(lastDetail.TotalWeekPlanNum), 2);//累计计划完成量
 | |
|                                             row[14] = decimal.Round(Convert.ToDecimal(lastDetail.TotalWeekThisNum), 2);//累计完成量
 | |
|                                             row[15] = decimal.Round(Convert.ToDecimal(lastDetail.TotalWeekRealCost), 2);//累计完成成本
 | |
|                                             row[16] = decimal.Round(Convert.ToDecimal(lastDetail.TotalWeekPlanValue), 2);//累计计划完成预算
 | |
|                                             row[17] = decimal.Round(Convert.ToDecimal(lastDetail.TotalWeekPlanCost), 2);//累计完成预算
 | |
|                                         }
 | |
|                                     }
 | |
|                                 }
 | |
|                                 table.Rows.Add(row);
 | |
|                             }
 | |
|                         }
 | |
|                     }
 | |
|                     #endregion
 | |
|                     #region   按分部工程
 | |
|                     else if (wbsSetCode == BLL.Const._Null)
 | |
|                     {
 | |
|                         if (cnProfessionId != Const.ACCNProfessionalId.ToString() && cnProfessionId != Const.GECNProfessionalId.ToString() && cnProfessionId != Const.UPCNProfessionalId.ToString() && cnProfessionId != Const.TFCNProfessionalId.ToString() && cnProfessionId != Const.GLCNProfessionalId.ToString())
 | |
|                         {
 | |
|                             newList = (from x in newList where (x.WBSType == "Installation" && !x.Name.Contains("防腐绝热") && !x.Name.Contains("地勘") && !x.Name.Contains("全厂地下主管网") && !x.Name.Contains("临时设施") && !x.Name.Contains("总图")) || (x.WBSType == "CnProfession" && x.OldCnProfessionId.ToString() == cnProfessionId) || (x.WBSType != "Installation" && x.WBSType != "CnProfession" && x.OldCnProfessionId.ToString() == cnProfessionId && x.OldUnitProjectCode == unitProjectCode) select x).ToList();
 | |
|                             var up = unitProjectInits.FirstOrDefault(x => x.UnitProjectCode == unitProjectCode);
 | |
|                             parentRow = table.NewRow();
 | |
|                             parentRow[0] = up.UnitProjectCode;
 | |
|                             parentRow[1] = "0";
 | |
|                             parentRow[2] = up.UnitProjectName;
 | |
|                             parentRow[3] = projectId;
 | |
|                             foreach (Model.View_WBS_CostControlDetailStatistics item in newList)
 | |
|                             {
 | |
|                                 row = table.NewRow();
 | |
|                                 row[0] = item.Id;
 | |
|                                 row[2] = item.Name;
 | |
|                                 row[3] = item.ProjectId;
 | |
|                                 if (item.WBSType == "Installation")
 | |
|                                 {
 | |
|                                     decimal ind10 = 0, ind11 = 0, ind12 = 0, ind15 = 0, ind16 = 0, ind17 = 0;
 | |
|                                     if (item.SupId == "0")
 | |
|                                     {
 | |
|                                         row[1] = up.UnitProjectCode;
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         row[1] = item.SupId;
 | |
|                                     }
 | |
|                                     List<string> unitProjectIds = BLL.UnitProjectService.GetUnitProjectIdByInstallationIdAndCNCodeAndUnitProjectCode(item.Id, cnProfessionId, unitProjectCode);
 | |
|                                     foreach (var upId in unitProjectIds)
 | |
|                                     {
 | |
|                                         Model.View_WBS_CostControlParentDetail parentDetail = parentDetails.FirstOrDefault(x => x.ParentId == upId && x.Months == months && x.StartDate == start);
 | |
|                                         if (parentDetail != null)
 | |
|                                         {
 | |
|                                             ind10 += decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekRealCost), 2);
 | |
|                                             ind11 += decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekPlanValue), 2);
 | |
|                                             ind12 += decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekPlanCost), 2);
 | |
|                                             ind15 += decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekRealCost), 2);
 | |
|                                             ind16 += decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekPlanValue), 2);
 | |
|                                             ind17 += decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekPlanCost), 2);
 | |
|                                         }
 | |
|                                         else
 | |
|                                         {
 | |
|                                             Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).OrderByDescending(x => x.StartDate).FirstOrDefault(x => x.ParentId == upId);
 | |
|                                             if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                             {
 | |
|                                                 ind15 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekRealCost), 2);
 | |
|                                                 ind16 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanValue), 2);
 | |
|                                                 ind17 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanCost), 2);
 | |
|                                             }
 | |
|                                         }
 | |
|                                     }
 | |
|                                     if (ind10 != 0)
 | |
|                                     {
 | |
|                                         row[10] = decimal.Round(ind10, 2);//本周实际成本
 | |
|                                         row[11] = decimal.Round(ind11, 2);//本周计划完成预算
 | |
|                                         row[12] = decimal.Round(ind12, 2);//本周完成预算
 | |
|                                         row[15] = decimal.Round(ind15, 2);//累计完成成本
 | |
|                                         row[16] = decimal.Round(ind16, 2);//累计计划完成预算
 | |
|                                         row[17] = decimal.Round(ind17, 2);//累计完成预算
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         if (ind15 > 0)
 | |
|                                         {
 | |
|                                             row[15] = decimal.Round(ind15, 2);//累计完成成本
 | |
|                                         }
 | |
|                                         if (ind16 > 0)
 | |
|                                         {
 | |
|                                             row[16] = decimal.Round(ind16, 2);//累计计划完成预算
 | |
|                                         }
 | |
|                                         if (ind17 > 0)
 | |
|                                         {
 | |
|                                             row[17] = decimal.Round(ind17, 2);//累计完成预算
 | |
|                                         }
 | |
|                                     }
 | |
|                                 }
 | |
|                                 else if (item.WBSType == "CnProfession")
 | |
|                                 {
 | |
|                                     decimal cnd10 = 0, cnd11 = 0, cnd12 = 0, cnd15 = 0, cnd16 = 0, cnd17 = 0;
 | |
|                                     row[1] = item.SupId;
 | |
|                                     List<string> unitProjectIds = BLL.UnitProjectService.GetUnitProjectIdByCnProfessionIdAndUnitProjectCode(item.Id, unitProjectCode);
 | |
|                                     foreach (var upId in unitProjectIds)
 | |
|                                     {
 | |
|                                         Model.View_WBS_CostControlParentDetail parentDetail = parentDetails.FirstOrDefault(x => x.ParentId == upId && x.Months == months && x.StartDate == start);
 | |
|                                         if (parentDetail != null)
 | |
|                                         {
 | |
|                                             cnd10 += decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekRealCost), 2);
 | |
|                                             cnd11 += decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekPlanValue), 2);
 | |
|                                             cnd12 += decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekPlanCost), 2);
 | |
|                                             cnd15 += decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekRealCost), 2);
 | |
|                                             cnd16 += decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekPlanValue), 2);
 | |
|                                             cnd17 += decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekPlanCost), 2);
 | |
|                                         }
 | |
|                                         else
 | |
|                                         {
 | |
|                                             Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).OrderByDescending(x => x.StartDate).FirstOrDefault(x => x.ParentId == upId);
 | |
|                                             if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                             {
 | |
|                                                 cnd15 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekRealCost), 2);
 | |
|                                                 cnd16 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanValue), 2);
 | |
|                                                 cnd17 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanCost), 2);
 | |
|                                             }
 | |
|                                         }
 | |
|                                     }
 | |
|                                     if (cnd10 != 0)
 | |
|                                     {
 | |
|                                         row[10] = decimal.Round(cnd10, 2);//本周实际成本
 | |
|                                         row[11] = decimal.Round(cnd11, 2);//本周计划完成预算
 | |
|                                         row[12] = decimal.Round(cnd12, 2);//本周完成预算
 | |
|                                         row[15] = decimal.Round(cnd15, 2);//累计完成成本
 | |
|                                         row[16] = decimal.Round(cnd16, 2);//累计计划完成预算
 | |
|                                         row[17] = decimal.Round(cnd17, 2);//累计完成预算
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         if (cnd15 > 0)
 | |
|                                         {
 | |
|                                             row[15] = decimal.Round(cnd15, 2);//累计完成成本
 | |
|                                         }
 | |
|                                         if (cnd16 > 0)
 | |
|                                         {
 | |
|                                             row[16] = decimal.Round(cnd16, 2);//累计计划完成预算
 | |
|                                         }
 | |
|                                         if (cnd17 > 0)
 | |
|                                         {
 | |
|                                             row[17] = decimal.Round(cnd17, 2);//累计完成预算
 | |
|                                         }
 | |
|                                     }
 | |
|                                 }
 | |
|                                 else if (item.WBSType == "UnitProject")
 | |
|                                 {
 | |
|                                     row[1] = item.SupId;
 | |
|                                     Model.View_WBS_CostControlParentDetail parentDetail = parentDetails.FirstOrDefault(x => x.ParentId == item.Id && x.Months == months && x.StartDate == start);
 | |
|                                     if (parentDetail != null)
 | |
|                                     {
 | |
|                                         row[10] = decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekRealCost), 2);//本周实际成本
 | |
|                                         row[11] = decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekPlanValue), 2);//本周计划完成预算
 | |
|                                         row[12] = decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekPlanCost), 2);//本周完成预算
 | |
|                                         row[15] = decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekRealCost), 2);//累计完成成本
 | |
|                                         row[16] = decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekPlanValue), 2);//累计计划完成预算
 | |
|                                         row[17] = decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekPlanCost), 2);//累计完成预算
 | |
|                                         d10 += decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekRealCost), 2);
 | |
|                                         d11 += decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekPlanValue), 2);
 | |
|                                         d12 += decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekPlanCost), 2);
 | |
|                                         d15 += decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekRealCost), 2);
 | |
|                                         d16 += decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekPlanValue), 2);
 | |
|                                         d17 += decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekPlanCost), 2);
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).OrderByDescending(x => x.StartDate).FirstOrDefault(x => x.ParentId == item.Id);
 | |
|                                         if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                         {
 | |
|                                             row[15] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekRealCost), 2);//累计完成成本
 | |
|                                             row[16] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanValue), 2);//累计计划完成预算
 | |
|                                             row[17] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanCost), 2);//累计完成预算
 | |
|                                             d15 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekRealCost), 2);
 | |
|                                             d16 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanValue), 2);
 | |
|                                             d17 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanCost), 2);
 | |
|                                         }
 | |
|                                     }
 | |
|                                 }
 | |
|                                 else if (item.WBSType == "WbsSet")
 | |
|                                 {
 | |
|                                     row[1] = item.SupId;
 | |
|                                     Model.View_WBS_CostControlParentDetail parentDetail = parentDetails.FirstOrDefault(x => x.ParentId == item.Id && x.Months == months && x.StartDate == start);
 | |
|                                     if (parentDetail != null)
 | |
|                                     {
 | |
|                                         row[10] = decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekRealCost), 2);//本周实际成本
 | |
|                                         row[11] = decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekPlanValue), 2);//本周计划完成预算
 | |
|                                         row[12] = decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekPlanCost), 2);//本周完成预算
 | |
|                                         row[15] = decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekRealCost), 2);//累计完成成本
 | |
|                                         row[16] = decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekPlanValue), 2);//累计计划完成预算
 | |
|                                         row[17] = decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekPlanCost), 2);//累计完成预算
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).OrderByDescending(x => x.StartDate).FirstOrDefault(x => x.ParentId == item.Id);
 | |
|                                         if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                         {
 | |
|                                             row[15] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekRealCost), 2);//累计完成成本
 | |
|                                             row[16] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanValue), 2);//累计计划完成预算
 | |
|                                             row[17] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanCost), 2);//累计完成预算
 | |
|                                         }
 | |
|                                     }
 | |
|                                 }
 | |
|                                 else if (item.WBSType == "CostControl")
 | |
|                                 {
 | |
|                                     row[1] = item.SupId;
 | |
|                                     Model.View_WBS_CostControlDetail detail = details.FirstOrDefault(x => x.CostControlId == item.Id && x.Months == months && x.StartDate == start);
 | |
|                                     if (detail != null)
 | |
|                                     {
 | |
|                                         row[4] = detail.Unit;//单位
 | |
|                                         row[5] = decimal.Round(Convert.ToDecimal(detail.TotalNum), 2);//合同工作量
 | |
|                                         row[6] = decimal.Round(Convert.ToDecimal(detail.RealPrice), 2);//成本单价
 | |
|                                         row[7] = decimal.Round(Convert.ToDecimal(detail.PlanWeekNum), 2);//本周计划完成量
 | |
|                                         row[8] = decimal.Round(Convert.ToDecimal(detail.ThisWeekNum), 2);//本周完成量
 | |
|                                         row[9] = decimal.Round(Convert.ToDecimal(detail.PlanPrice), 2);//控制预算单价
 | |
|                                         row[10] = decimal.Round(Convert.ToDecimal(detail.ThisWeekRealCost), 2);//本周实际成本
 | |
|                                         row[11] = decimal.Round(Convert.ToDecimal(detail.ThisWeekPlanValue), 2);//本周计划完成预算
 | |
|                                         row[12] = decimal.Round(Convert.ToDecimal(detail.ThisWeekPlanCost), 2);//本周完成预算
 | |
|                                         row[13] = decimal.Round(Convert.ToDecimal(detail.TotalWeekPlanNum), 2);//累计计划完成量
 | |
|                                         row[14] = decimal.Round(Convert.ToDecimal(detail.TotalWeekThisNum), 2);//累计完成量
 | |
|                                         row[15] = decimal.Round(Convert.ToDecimal(detail.TotalWeekRealCost), 2);//累计完成成本
 | |
|                                         row[16] = decimal.Round(Convert.ToDecimal(detail.TotalWeekPlanValue), 2);//累计计划完成预算
 | |
|                                         row[17] = decimal.Round(Convert.ToDecimal(detail.TotalWeekPlanCost), 2);//累计完成预算
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         Model.View_WBS_CostControlDetail lastDetail = details.OrderByDescending(x => x.Months).OrderByDescending(x => x.StartDate).FirstOrDefault(x => x.CostControlId == item.Id);
 | |
|                                         if (lastDetail != null && lastDetail.Months <= months)
 | |
|                                         {
 | |
|                                             row[4] = lastDetail.Unit;//单位
 | |
|                                             row[5] = decimal.Round(Convert.ToDecimal(lastDetail.TotalNum), 2);//合同工作量
 | |
|                                             row[6] = decimal.Round(Convert.ToDecimal(lastDetail.RealPrice), 2);//成本单价
 | |
|                                             row[7] = decimal.Round(Convert.ToDecimal(lastDetail.PlanWeekNum), 2);//本周计划完成量
 | |
|                                             row[8] = decimal.Round(Convert.ToDecimal(lastDetail.ThisWeekNum), 2);//本周完成量
 | |
|                                             row[9] = decimal.Round(Convert.ToDecimal(lastDetail.PlanPrice), 2);//控制预算单价
 | |
|                                             row[13] = decimal.Round(Convert.ToDecimal(lastDetail.TotalWeekPlanNum), 2);//累计计划完成量
 | |
|                                             row[14] = decimal.Round(Convert.ToDecimal(lastDetail.TotalWeekThisNum), 2);//累计完成量
 | |
|                                             row[15] = decimal.Round(Convert.ToDecimal(lastDetail.TotalWeekRealCost), 2);//累计完成成本
 | |
|                                             row[16] = decimal.Round(Convert.ToDecimal(lastDetail.TotalWeekPlanValue), 2);//累计计划完成预算
 | |
|                                             row[17] = decimal.Round(Convert.ToDecimal(lastDetail.TotalWeekPlanCost), 2);//累计完成预算
 | |
|                                         }
 | |
|                                     }
 | |
|                                 }
 | |
|                                 table.Rows.Add(row);
 | |
|                             }
 | |
|                             if (d10 != 0)
 | |
|                             {
 | |
|                                 parentRow[10] = decimal.Round(d10, 2);//本周实际成本
 | |
|                                 parentRow[11] = decimal.Round(d11, 2);//本周计划完成预算
 | |
|                                 parentRow[12] = decimal.Round(d12, 2);//本周完成预算
 | |
|                                 parentRow[15] = decimal.Round(d15, 2);//累计完成成本
 | |
|                                 parentRow[16] = decimal.Round(d16, 2);//累计计划完成预算
 | |
|                                 parentRow[17] = decimal.Round(d17, 2);//累计完成预算
 | |
|                             }
 | |
|                             else
 | |
|                             {
 | |
|                                 parentRow[15] = decimal.Round(d15, 2);//累计完成成本
 | |
|                                 parentRow[16] = decimal.Round(d16, 2);//累计计划完成预算
 | |
|                                 parentRow[17] = decimal.Round(d17, 2);//累计完成预算
 | |
|                             }
 | |
|                             table.Rows.Add(parentRow);
 | |
|                         }
 | |
|                         else
 | |
|                         {
 | |
|                             newList = (from x in newList where x.WBSType != "Installation" && x.WBSType != "CnProfession" && x.OldCnProfessionId.ToString() == cnProfessionId && x.OldUnitProjectCode == unitProjectCode select x).ToList();
 | |
|                             var up = newList.FirstOrDefault(x => x.WBSType == "UnitProject" && x.OldUnitProjectCode == unitProjectCode);
 | |
|                             parentRow = table.NewRow();
 | |
|                             parentRow[0] = up.Id;
 | |
|                             parentRow[1] = "0";
 | |
|                             parentRow[2] = up.Name;
 | |
|                             parentRow[3] = projectId;
 | |
|                             Model.View_WBS_CostControlParentDetail pparentDetail = parentDetails.FirstOrDefault(x => x.ParentId == up.Id && x.Months == months && x.StartDate == start);
 | |
|                             if (pparentDetail != null)
 | |
|                             {
 | |
|                                 d10 += decimal.Round(Convert.ToDecimal(pparentDetail.ThisWeekRealCost), 2);
 | |
|                                 d11 += decimal.Round(Convert.ToDecimal(pparentDetail.ThisWeekPlanValue), 2);
 | |
|                                 d12 += decimal.Round(Convert.ToDecimal(pparentDetail.ThisWeekPlanCost), 2);
 | |
|                                 d15 += decimal.Round(Convert.ToDecimal(pparentDetail.TotalWeekRealCost), 2);
 | |
|                                 d16 += decimal.Round(Convert.ToDecimal(pparentDetail.TotalWeekPlanValue), 2);
 | |
|                                 d17 += decimal.Round(Convert.ToDecimal(pparentDetail.TotalWeekPlanCost), 2);
 | |
|                             }
 | |
|                             else
 | |
|                             {
 | |
|                                 Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).OrderByDescending(x => x.StartDate).FirstOrDefault(x => x.ParentId == up.Id);
 | |
|                                 if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                 {
 | |
|                                     d15 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekRealCost), 2);
 | |
|                                     d16 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanValue), 2);
 | |
|                                     d17 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanCost), 2);
 | |
|                                 }
 | |
|                             }
 | |
|                             foreach (Model.View_WBS_CostControlDetailStatistics item in newList)
 | |
|                             {
 | |
|                                 row = table.NewRow();
 | |
|                                 row[0] = item.Id;
 | |
|                                 row[2] = item.Name;
 | |
|                                 row[3] = item.ProjectId;
 | |
|                                 if (item.WBSType == "WbsSet")
 | |
|                                 {
 | |
|                                     row[1] = item.SupId;
 | |
|                                     Model.View_WBS_CostControlParentDetail parentDetail = parentDetails.FirstOrDefault(x => x.ParentId == item.Id && x.Months == months && x.StartDate == start);
 | |
|                                     if (parentDetail != null)
 | |
|                                     {
 | |
|                                         row[10] = decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekRealCost), 2);//本周实际成本
 | |
|                                         row[11] = decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekPlanValue), 2);//本周计划完成预算
 | |
|                                         row[12] = decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekPlanCost), 2);//本周完成预算
 | |
|                                         row[15] = decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekRealCost), 2);//累计完成成本
 | |
|                                         row[16] = decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekPlanValue), 2);//累计计划完成预算
 | |
|                                         row[17] = decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekPlanCost), 2);//累计完成预算
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).OrderByDescending(x => x.StartDate).FirstOrDefault(x => x.ParentId == item.Id);
 | |
|                                         if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                         {
 | |
|                                             row[15] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekRealCost), 2);//累计完成成本
 | |
|                                             row[16] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanValue), 2);//累计计划完成预算
 | |
|                                             row[17] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanCost), 2);//累计完成预算
 | |
|                                         }
 | |
|                                     }
 | |
|                                 }
 | |
|                                 else if (item.WBSType == "CostControl")
 | |
|                                 {
 | |
|                                     row[1] = item.SupId;
 | |
|                                     Model.View_WBS_CostControlDetail detail = details.FirstOrDefault(x => x.CostControlId == item.Id && x.Months == months && x.StartDate == start);
 | |
|                                     if (detail != null)
 | |
|                                     {
 | |
|                                         row[4] = detail.Unit;//单位
 | |
|                                         row[5] = decimal.Round(Convert.ToDecimal(detail.TotalNum), 2);//合同工作量
 | |
|                                         row[6] = decimal.Round(Convert.ToDecimal(detail.RealPrice), 2);//成本单价
 | |
|                                         row[7] = decimal.Round(Convert.ToDecimal(detail.PlanWeekNum), 2);//本周计划完成量
 | |
|                                         row[8] = decimal.Round(Convert.ToDecimal(detail.ThisWeekNum), 2);//本周完成量
 | |
|                                         row[9] = decimal.Round(Convert.ToDecimal(detail.PlanPrice), 2);//控制预算单价
 | |
|                                         row[10] = decimal.Round(Convert.ToDecimal(detail.ThisWeekRealCost), 2);//本周实际成本
 | |
|                                         row[11] = decimal.Round(Convert.ToDecimal(detail.ThisWeekPlanValue), 2);//本周计划完成预算
 | |
|                                         row[12] = decimal.Round(Convert.ToDecimal(detail.ThisWeekPlanCost), 2);//本周完成预算
 | |
|                                         row[13] = decimal.Round(Convert.ToDecimal(detail.TotalWeekPlanNum), 2);//累计计划完成量
 | |
|                                         row[14] = decimal.Round(Convert.ToDecimal(detail.TotalWeekThisNum), 2);//累计完成量
 | |
|                                         row[15] = decimal.Round(Convert.ToDecimal(detail.TotalWeekRealCost), 2);//累计完成成本
 | |
|                                         row[16] = decimal.Round(Convert.ToDecimal(detail.TotalWeekPlanValue), 2);//累计计划完成预算
 | |
|                                         row[17] = decimal.Round(Convert.ToDecimal(detail.TotalWeekPlanCost), 2);//累计完成预算
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         Model.View_WBS_CostControlDetail lastDetail = details.OrderByDescending(x => x.Months).OrderByDescending(x => x.StartDate).FirstOrDefault(x => x.CostControlId == item.Id);
 | |
|                                         if (lastDetail != null && lastDetail.Months <= months)
 | |
|                                         {
 | |
|                                             row[4] = lastDetail.Unit;//单位
 | |
|                                             row[5] = decimal.Round(Convert.ToDecimal(lastDetail.TotalNum), 2);//合同工作量
 | |
|                                             row[6] = decimal.Round(Convert.ToDecimal(lastDetail.RealPrice), 2);//成本单价
 | |
|                                             row[7] = decimal.Round(Convert.ToDecimal(lastDetail.PlanWeekNum), 2);//本周计划完成量
 | |
|                                             row[8] = decimal.Round(Convert.ToDecimal(lastDetail.ThisWeekNum), 2);//本周完成量
 | |
|                                             row[9] = decimal.Round(Convert.ToDecimal(lastDetail.PlanPrice), 2);//控制预算单价
 | |
|                                             row[13] = decimal.Round(Convert.ToDecimal(lastDetail.TotalWeekPlanNum), 2);//累计计划完成量
 | |
|                                             row[14] = decimal.Round(Convert.ToDecimal(lastDetail.TotalWeekThisNum), 2);//累计完成量
 | |
|                                             row[15] = decimal.Round(Convert.ToDecimal(lastDetail.TotalWeekRealCost), 2);//累计完成成本
 | |
|                                             row[16] = decimal.Round(Convert.ToDecimal(lastDetail.TotalWeekPlanValue), 2);//累计计划完成预算
 | |
|                                             row[17] = decimal.Round(Convert.ToDecimal(lastDetail.TotalWeekPlanCost), 2);//累计完成预算
 | |
|                                         }
 | |
|                                     }
 | |
|                                 }
 | |
|                                 table.Rows.Add(row);
 | |
|                             }
 | |
|                             if (d10 != 0)
 | |
|                             {
 | |
|                                 parentRow[10] = decimal.Round(d10, 2);//本周实际成本
 | |
|                                 parentRow[11] = decimal.Round(d11, 2);//本周计划完成预算
 | |
|                                 parentRow[12] = decimal.Round(d12, 2);//本周完成预算
 | |
|                                 parentRow[15] = decimal.Round(d15, 2);//累计完成成本
 | |
|                                 parentRow[16] = decimal.Round(d16, 2);//累计计划完成预算
 | |
|                                 parentRow[17] = decimal.Round(d17, 2);//累计完成预算
 | |
|                             }
 | |
|                             else
 | |
|                             {
 | |
|                                 parentRow[15] = decimal.Round(d15, 2);//累计完成成本
 | |
|                                 parentRow[16] = decimal.Round(d16, 2);//累计计划完成预算
 | |
|                                 parentRow[17] = decimal.Round(d17, 2);//累计完成预算
 | |
|                             }
 | |
|                             table.Rows.Add(parentRow);
 | |
|                         }
 | |
|                     }
 | |
|                     #endregion
 | |
|                     #region  按工作包
 | |
|                     else
 | |
|                     {
 | |
|                         if (cnProfessionId != Const.ACCNProfessionalId.ToString() && cnProfessionId != Const.GECNProfessionalId.ToString() && cnProfessionId != Const.UPCNProfessionalId.ToString() && cnProfessionId != Const.TFCNProfessionalId.ToString() && cnProfessionId != Const.GLCNProfessionalId.ToString())
 | |
|                         {
 | |
|                             newList = (from x in newList where (x.WBSType == "Installation" && !x.Name.Contains("防腐绝热") && !x.Name.Contains("地勘") && !x.Name.Contains("全厂地下主管网") && !x.Name.Contains("临时设施") && !x.Name.Contains("总图")) || (x.WBSType == "CnProfession" && x.OldCnProfessionId.ToString() == cnProfessionId) || (x.WBSType == "UnitProject" && x.OldCnProfessionId.ToString() == cnProfessionId && x.OldUnitProjectCode == unitProjectCode) || (x.WBSType != "Installation" && x.WBSType != "CnProfession" && x.WBSType != "UnitProject" && x.OldCnProfessionId.ToString() == cnProfessionId && x.OldUnitProjectCode == unitProjectCode && x.OldWbsSetCode == wbsSetCode) select x).ToList();
 | |
|                             var wb = wbsSetInits.FirstOrDefault(x => x.WbsSetCode == wbsSetCode);
 | |
|                             parentRow = table.NewRow();
 | |
|                             parentRow[0] = wb.WbsSetCode;
 | |
|                             parentRow[1] = "0";
 | |
|                             parentRow[2] = wb.WbsSetName;
 | |
|                             parentRow[3] = projectId;
 | |
|                             foreach (Model.View_WBS_CostControlDetailStatistics item in newList)
 | |
|                             {
 | |
|                                 row = table.NewRow();
 | |
|                                 row[0] = item.Id;
 | |
|                                 row[2] = item.Name;
 | |
|                                 row[3] = item.ProjectId;
 | |
|                                 if (item.WBSType == "Installation")
 | |
|                                 {
 | |
|                                     decimal ind10 = 0, ind11 = 0, ind12 = 0, ind15 = 0, ind16 = 0, ind17 = 0;
 | |
|                                     if (item.SupId == "0")
 | |
|                                     {
 | |
|                                         row[1] = wb.WbsSetCode;
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         row[1] = item.SupId;
 | |
|                                     }
 | |
|                                     List<string> wbsSetIds = BLL.WbsSetService.GetWbsSetIdByInstallationIdAndCNCodeAndUnitProjectCodeAndWbsSetCode(item.Id, cnProfessionId, unitProjectCode, wbsSetCode);
 | |
|                                     foreach (var upId in wbsSetIds)
 | |
|                                     {
 | |
|                                         Model.View_WBS_CostControlParentDetail parentDetail = parentDetails.FirstOrDefault(x => x.ParentId == upId && x.Months == months && x.StartDate == start);
 | |
|                                         if (parentDetail != null)
 | |
|                                         {
 | |
|                                             ind10 += decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekRealCost), 2);
 | |
|                                             ind11 += decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekPlanValue), 2);
 | |
|                                             ind12 += decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekPlanCost), 2);
 | |
|                                             ind15 += decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekRealCost), 2);
 | |
|                                             ind16 += decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekPlanValue), 2);
 | |
|                                             ind17 += decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekPlanCost), 2);
 | |
|                                         }
 | |
|                                         else
 | |
|                                         {
 | |
|                                             Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).OrderByDescending(x => x.StartDate).FirstOrDefault(x => x.ParentId == upId);
 | |
|                                             if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                             {
 | |
|                                                 ind15 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekRealCost), 2);
 | |
|                                                 ind16 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanValue), 2);
 | |
|                                                 ind17 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanCost), 2);
 | |
|                                             }
 | |
|                                         }
 | |
|                                     }
 | |
|                                     if (ind10 != 0)
 | |
|                                     {
 | |
|                                         row[10] = decimal.Round(ind10, 2);//本周实际成本
 | |
|                                         row[11] = decimal.Round(ind11, 2);//本周计划完成预算
 | |
|                                         row[12] = decimal.Round(ind12, 2);//本周完成预算
 | |
|                                         row[15] = decimal.Round(ind15, 2);//累计完成成本
 | |
|                                         row[16] = decimal.Round(ind16, 2);//累计计划完成预算
 | |
|                                         row[17] = decimal.Round(ind17, 2);//累计完成预算
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         if (ind15 > 0)
 | |
|                                         {
 | |
|                                             row[15] = decimal.Round(ind15, 2);//累计完成成本
 | |
|                                         }
 | |
|                                         if (ind16 > 0)
 | |
|                                         {
 | |
|                                             row[16] = decimal.Round(ind16, 2);//累计计划完成预算
 | |
|                                         }
 | |
|                                         if (ind17 > 0)
 | |
|                                         {
 | |
|                                             row[17] = decimal.Round(ind17, 2);//累计完成预算
 | |
|                                         }
 | |
|                                     }
 | |
|                                 }
 | |
|                                 else if (item.WBSType == "CnProfession")
 | |
|                                 {
 | |
|                                     decimal cnd10 = 0, cnd11 = 0, cnd12 = 0, cnd15 = 0, cnd16 = 0, cnd17 = 0;
 | |
|                                     row[1] = item.SupId;
 | |
|                                     List<string> wbsSetIds = BLL.WbsSetService.GetWbsSetIdByCnProfessionIdAndUnitProjectCodeAndWbsSetCode(item.Id, unitProjectCode, wbsSetCode);
 | |
|                                     foreach (var upId in wbsSetIds)
 | |
|                                     {
 | |
|                                         Model.View_WBS_CostControlParentDetail parentDetail = parentDetails.FirstOrDefault(x => x.ParentId == upId && x.Months == months && x.StartDate == start);
 | |
|                                         if (parentDetail != null)
 | |
|                                         {
 | |
|                                             cnd10 += decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekRealCost), 2);
 | |
|                                             cnd11 += decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekPlanValue), 2);
 | |
|                                             cnd12 += decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekPlanCost), 2);
 | |
|                                             cnd15 += decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekRealCost), 2);
 | |
|                                             cnd16 += decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekPlanValue), 2);
 | |
|                                             cnd17 += decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekPlanCost), 2);
 | |
|                                         }
 | |
|                                         else
 | |
|                                         {
 | |
|                                             Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).OrderByDescending(x => x.StartDate).FirstOrDefault(x => x.ParentId == upId);
 | |
|                                             if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                             {
 | |
|                                                 cnd15 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekRealCost), 2);
 | |
|                                                 cnd16 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanValue), 2);
 | |
|                                                 cnd17 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanCost), 2);
 | |
|                                             }
 | |
|                                         }
 | |
|                                     }
 | |
|                                     if (cnd10 != 0)
 | |
|                                     {
 | |
|                                         row[10] = decimal.Round(cnd10, 2);//本周实际成本
 | |
|                                         row[11] = decimal.Round(cnd11, 2);//本周计划完成预算
 | |
|                                         row[12] = decimal.Round(cnd12, 2);//本周完成预算
 | |
|                                         row[15] = decimal.Round(cnd15, 2);//累计完成成本
 | |
|                                         row[16] = decimal.Round(cnd16, 2);//累计计划完成预算
 | |
|                                         row[17] = decimal.Round(cnd17, 2);//累计完成预算
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         if (cnd15 > 0)
 | |
|                                         {
 | |
|                                             row[15] = decimal.Round(cnd15, 2);//累计完成成本
 | |
|                                         }
 | |
|                                         if (cnd16 > 0)
 | |
|                                         {
 | |
|                                             row[16] = decimal.Round(cnd16, 2);//累计计划完成预算
 | |
|                                         }
 | |
|                                         if (cnd17 > 0)
 | |
|                                         {
 | |
|                                             row[17] = decimal.Round(cnd17, 2);//累计完成预算
 | |
|                                         }
 | |
|                                     }
 | |
|                                 }
 | |
|                                 else if (item.WBSType == "UnitProject")
 | |
|                                 {
 | |
|                                     decimal upd10 = 0, upd11 = 0, upd12 = 0, upd15 = 0, upd16 = 0, upd17 = 0;
 | |
|                                     row[1] = item.SupId;
 | |
|                                     List<string> wbsSetIds = BLL.WbsSetService.GetWbsSetIdByUnitProjectIdAndWbsSetCode(item.Id, wbsSetCode);
 | |
|                                     foreach (var upId in wbsSetIds)
 | |
|                                     {
 | |
|                                         Model.View_WBS_CostControlParentDetail parentDetail = parentDetails.FirstOrDefault(x => x.ParentId == upId && x.Months == months && x.StartDate == start);
 | |
|                                         if (parentDetail != null)
 | |
|                                         {
 | |
|                                             upd10 += decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekRealCost), 2);
 | |
|                                             upd11 += decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekPlanValue), 2);
 | |
|                                             upd12 += decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekPlanCost), 2);
 | |
|                                             upd15 += decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekRealCost), 2);
 | |
|                                             upd16 += decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekPlanValue), 2);
 | |
|                                             upd17 += decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekPlanCost), 2);
 | |
|                                         }
 | |
|                                         else
 | |
|                                         {
 | |
|                                             Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).OrderByDescending(x => x.StartDate).FirstOrDefault(x => x.ParentId == upId);
 | |
|                                             if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                             {
 | |
|                                                 upd15 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekRealCost), 2);
 | |
|                                                 upd16 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanValue), 2);
 | |
|                                                 upd17 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanCost), 2);
 | |
|                                             }
 | |
|                                         }
 | |
|                                     }
 | |
|                                     if (upd10 != 0)
 | |
|                                     {
 | |
|                                         row[10] = decimal.Round(upd10, 2);//本周实际成本
 | |
|                                         row[11] = decimal.Round(upd11, 2);//本周计划完成预算
 | |
|                                         row[12] = decimal.Round(upd12, 2);//本周完成预算
 | |
|                                         row[15] = decimal.Round(upd15, 2);//累计完成成本
 | |
|                                         row[16] = decimal.Round(upd16, 2);//累计计划完成预算
 | |
|                                         row[17] = decimal.Round(upd17, 2);//累计完成预算
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         if (upd15 > 0)
 | |
|                                         {
 | |
|                                             row[15] = decimal.Round(upd15, 2);//累计完成成本
 | |
|                                         }
 | |
|                                         if (upd16 > 0)
 | |
|                                         {
 | |
|                                             row[16] = decimal.Round(upd16, 2);//累计计划完成预算
 | |
|                                         }
 | |
|                                         if (upd17 > 0)
 | |
|                                         {
 | |
|                                             row[17] = decimal.Round(upd17, 2);//累计完成预算
 | |
|                                         }
 | |
|                                     }
 | |
|                                 }
 | |
|                                 else if (item.WBSType == "WbsSet")
 | |
|                                 {
 | |
|                                     row[1] = item.SupId;
 | |
|                                     var wbsSet = wbsSets.FirstOrDefault(x => x.WbsSetId == item.Id);
 | |
|                                     Model.View_WBS_CostControlParentDetail parentDetail = parentDetails.FirstOrDefault(x => x.ParentId == item.Id && x.Months == months && x.StartDate == start);
 | |
|                                     if (parentDetail != null)
 | |
|                                     {
 | |
|                                         row[10] = decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekRealCost), 2);//本周实际成本
 | |
|                                         row[11] = decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekPlanValue), 2);//本周计划完成预算
 | |
|                                         row[12] = decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekPlanCost), 2);//本周完成预算
 | |
|                                         row[15] = decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekRealCost), 2);//累计完成成本
 | |
|                                         row[16] = decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekPlanValue), 2);//累计计划完成预算
 | |
|                                         row[17] = decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekPlanCost), 2);//累计完成预算
 | |
|                                         if (wbsSet.SuperWbsSetId == null)  //工作包节点,累加数据
 | |
|                                         {
 | |
|                                             d10 += decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekRealCost), 2);
 | |
|                                             d11 += decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekPlanValue), 2);
 | |
|                                             d12 += decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekPlanCost), 2);
 | |
|                                             d15 += decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekRealCost), 2);
 | |
|                                             d16 += decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekPlanValue), 2);
 | |
|                                             d17 += decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekPlanCost), 2);
 | |
|                                         }
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).OrderByDescending(x => x.StartDate).FirstOrDefault(x => x.ParentId == item.Id);
 | |
|                                         if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                         {
 | |
|                                             row[15] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekRealCost), 2);//累计完成成本
 | |
|                                             row[16] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanValue), 2);//累计计划完成预算
 | |
|                                             row[17] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanCost), 2);//累计完成预算
 | |
|                                             if (wbsSet.SuperWbsSetId == null)  //工作包节点,累加数据
 | |
|                                             {
 | |
|                                                 d15 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekRealCost), 2);
 | |
|                                                 d16 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanValue), 2);
 | |
|                                                 d17 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanCost), 2);
 | |
|                                             }
 | |
|                                         }
 | |
|                                     }
 | |
|                                 }
 | |
|                                 else if (item.WBSType == "CostControl")
 | |
|                                 {
 | |
|                                     row[1] = item.SupId;
 | |
|                                     Model.View_WBS_CostControlDetail detail = details.FirstOrDefault(x => x.CostControlId == item.Id && x.Months == months && x.StartDate == start);
 | |
|                                     if (detail != null)
 | |
|                                     {
 | |
|                                         row[4] = detail.Unit;//单位
 | |
|                                         row[5] = decimal.Round(Convert.ToDecimal(detail.TotalNum), 2);//合同工作量
 | |
|                                         row[6] = decimal.Round(Convert.ToDecimal(detail.RealPrice), 2);//成本单价
 | |
|                                         row[7] = decimal.Round(Convert.ToDecimal(detail.PlanWeekNum), 2);//本周计划完成量
 | |
|                                         row[8] = decimal.Round(Convert.ToDecimal(detail.ThisWeekNum), 2);//本周完成量
 | |
|                                         row[9] = decimal.Round(Convert.ToDecimal(detail.PlanPrice), 2);//控制预算单价
 | |
|                                         row[10] = decimal.Round(Convert.ToDecimal(detail.ThisWeekRealCost), 2);//本周实际成本
 | |
|                                         row[11] = decimal.Round(Convert.ToDecimal(detail.ThisWeekPlanValue), 2);//本周计划完成预算
 | |
|                                         row[12] = decimal.Round(Convert.ToDecimal(detail.ThisWeekPlanCost), 2);//本周完成预算
 | |
|                                         row[13] = decimal.Round(Convert.ToDecimal(detail.TotalWeekPlanNum), 2);//累计计划完成量
 | |
|                                         row[14] = decimal.Round(Convert.ToDecimal(detail.TotalWeekThisNum), 2);//累计完成量
 | |
|                                         row[15] = decimal.Round(Convert.ToDecimal(detail.TotalWeekRealCost), 2);//累计完成成本
 | |
|                                         row[16] = decimal.Round(Convert.ToDecimal(detail.TotalWeekPlanValue), 2);//累计计划完成预算
 | |
|                                         row[17] = decimal.Round(Convert.ToDecimal(detail.TotalWeekPlanCost), 2);//累计完成预算
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         Model.View_WBS_CostControlDetail lastDetail = details.OrderByDescending(x => x.Months).OrderByDescending(x => x.StartDate).FirstOrDefault(x => x.CostControlId == item.Id);
 | |
|                                         if (lastDetail != null && lastDetail.Months <= months)
 | |
|                                         {
 | |
|                                             row[4] = lastDetail.Unit;//单位
 | |
|                                             row[5] = decimal.Round(Convert.ToDecimal(lastDetail.TotalNum), 2);//合同工作量
 | |
|                                             row[6] = decimal.Round(Convert.ToDecimal(lastDetail.RealPrice), 2);//成本单价
 | |
|                                             row[7] = decimal.Round(Convert.ToDecimal(lastDetail.PlanWeekNum), 2);//本周计划完成量
 | |
|                                             row[8] = decimal.Round(Convert.ToDecimal(lastDetail.ThisWeekNum), 2);//本周完成量
 | |
|                                             row[9] = decimal.Round(Convert.ToDecimal(lastDetail.PlanPrice), 2);//控制预算单价
 | |
|                                             row[13] = decimal.Round(Convert.ToDecimal(lastDetail.TotalWeekPlanNum), 2);//累计计划完成量
 | |
|                                             row[14] = decimal.Round(Convert.ToDecimal(lastDetail.TotalWeekThisNum), 2);//累计完成量
 | |
|                                             row[15] = decimal.Round(Convert.ToDecimal(lastDetail.TotalWeekRealCost), 2);//累计完成成本
 | |
|                                             row[16] = decimal.Round(Convert.ToDecimal(lastDetail.TotalWeekPlanValue), 2);//累计计划完成预算
 | |
|                                             row[17] = decimal.Round(Convert.ToDecimal(lastDetail.TotalWeekPlanCost), 2);//累计完成预算
 | |
|                                         }
 | |
|                                     }
 | |
|                                 }
 | |
|                                 table.Rows.Add(row);
 | |
|                             }
 | |
|                             if (d10 != 0)
 | |
|                             {
 | |
|                                 parentRow[10] = decimal.Round(d10, 2);//本周实际成本
 | |
|                                 parentRow[11] = decimal.Round(d11, 2);//本周计划完成预算
 | |
|                                 parentRow[12] = decimal.Round(d12, 2);//本周完成预算
 | |
|                                 parentRow[15] = decimal.Round(d15, 2);//累计完成成本
 | |
|                                 parentRow[16] = decimal.Round(d16, 2);//累计计划完成预算
 | |
|                                 parentRow[17] = decimal.Round(d17, 2);//累计完成预算
 | |
|                             }
 | |
|                             else
 | |
|                             {
 | |
|                                 parentRow[15] = decimal.Round(d15, 2);//累计完成成本
 | |
|                                 parentRow[16] = decimal.Round(d16, 2);//累计计划完成预算
 | |
|                                 parentRow[17] = decimal.Round(d17, 2);//累计完成预算
 | |
|                             }
 | |
|                             table.Rows.Add(parentRow);
 | |
|                         }
 | |
|                         else
 | |
|                         {
 | |
|                             newList = (from x in newList where x.WBSType != "Installation" && x.WBSType != "CnProfession" && x.WBSType != "UnitProject" && x.OldCnProfessionId.ToString() == cnProfessionId && x.OldUnitProjectCode == unitProjectCode && x.OldWbsSetCode == wbsSetCode select x).ToList();
 | |
|                             var wb = newList.FirstOrDefault(x => x.WBSType == "WbsSet" && x.OldWbsSetCode == wbsSetCode);
 | |
|                             parentRow = table.NewRow();
 | |
|                             parentRow[0] = wb.Id;
 | |
|                             parentRow[1] = "0";
 | |
|                             parentRow[2] = wb.Name;
 | |
|                             parentRow[3] = projectId;
 | |
|                             Model.View_WBS_CostControlParentDetail pparentDetail = parentDetails.FirstOrDefault(x => x.ParentId == wb.Id && x.Months == months && x.StartDate == start);
 | |
|                             if (pparentDetail != null)
 | |
|                             {
 | |
|                                 d10 += decimal.Round(Convert.ToDecimal(pparentDetail.ThisWeekRealCost), 2);
 | |
|                                 d11 += decimal.Round(Convert.ToDecimal(pparentDetail.ThisWeekPlanValue), 2);
 | |
|                                 d12 += decimal.Round(Convert.ToDecimal(pparentDetail.ThisWeekPlanCost), 2);
 | |
|                                 d15 += decimal.Round(Convert.ToDecimal(pparentDetail.TotalWeekRealCost), 2);
 | |
|                                 d16 += decimal.Round(Convert.ToDecimal(pparentDetail.TotalWeekPlanValue), 2);
 | |
|                                 d17 += decimal.Round(Convert.ToDecimal(pparentDetail.TotalWeekPlanCost), 2);
 | |
|                             }
 | |
|                             else
 | |
|                             {
 | |
|                                 Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).OrderByDescending(x => x.StartDate).FirstOrDefault(x => x.ParentId == wb.Id);
 | |
|                                 if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                 {
 | |
|                                     d15 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekRealCost), 2);
 | |
|                                     d16 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanValue), 2);
 | |
|                                     d17 += decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanCost), 2);
 | |
|                                 }
 | |
|                             }
 | |
|                             foreach (Model.View_WBS_CostControlDetailStatistics item in newList)
 | |
|                             {
 | |
|                                 row = table.NewRow();
 | |
|                                 row[0] = item.Id;
 | |
|                                 row[2] = item.Name;
 | |
|                                 row[3] = item.ProjectId;
 | |
|                                 if (item.WBSType == "WbsSet")
 | |
|                                 {
 | |
|                                     row[1] = item.SupId;
 | |
|                                     var wbsSet = wbsSets.FirstOrDefault(x => x.WbsSetId == item.Id);
 | |
|                                     Model.View_WBS_CostControlParentDetail parentDetail = parentDetails.FirstOrDefault(x => x.ParentId == item.Id && x.Months == months && x.StartDate == start);
 | |
|                                     if (parentDetail != null)
 | |
|                                     {
 | |
|                                         row[10] = decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekRealCost), 2);//本周实际成本
 | |
|                                         row[11] = decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekPlanValue), 2);//本周计划完成预算
 | |
|                                         row[12] = decimal.Round(Convert.ToDecimal(parentDetail.ThisWeekPlanCost), 2);//本周完成预算
 | |
|                                         row[15] = decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekRealCost), 2);//累计完成成本
 | |
|                                         row[16] = decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekPlanValue), 2);//累计计划完成预算
 | |
|                                         row[17] = decimal.Round(Convert.ToDecimal(parentDetail.TotalWeekPlanCost), 2);//累计完成预算
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).OrderByDescending(x => x.StartDate).FirstOrDefault(x => x.ParentId == item.Id);
 | |
|                                         if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                                         {
 | |
|                                             row[15] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekRealCost), 2);//累计完成成本
 | |
|                                             row[16] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanValue), 2);//累计计划完成预算
 | |
|                                             row[17] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalWeekPlanCost), 2);//累计完成预算
 | |
|                                         }
 | |
|                                     }
 | |
|                                 }
 | |
|                                 else if (item.WBSType == "CostControl")
 | |
|                                 {
 | |
|                                     row[1] = item.SupId;
 | |
|                                     Model.View_WBS_CostControlDetail detail = details.FirstOrDefault(x => x.CostControlId == item.Id && x.Months == months && x.StartDate == start);
 | |
|                                     if (detail != null)
 | |
|                                     {
 | |
|                                         row[4] = detail.Unit;//单位
 | |
|                                         row[5] = decimal.Round(Convert.ToDecimal(detail.TotalNum), 2);//合同工作量
 | |
|                                         row[6] = decimal.Round(Convert.ToDecimal(detail.RealPrice), 2);//成本单价
 | |
|                                         row[7] = decimal.Round(Convert.ToDecimal(detail.PlanWeekNum), 2);//本周计划完成量
 | |
|                                         row[8] = decimal.Round(Convert.ToDecimal(detail.ThisWeekNum), 2);//本周完成量
 | |
|                                         row[9] = decimal.Round(Convert.ToDecimal(detail.PlanPrice), 2);//控制预算单价
 | |
|                                         row[10] = decimal.Round(Convert.ToDecimal(detail.ThisWeekRealCost), 2);//本周实际成本
 | |
|                                         row[11] = decimal.Round(Convert.ToDecimal(detail.ThisWeekPlanValue), 2);//本周计划完成预算
 | |
|                                         row[12] = decimal.Round(Convert.ToDecimal(detail.ThisWeekPlanCost), 2);//本周完成预算
 | |
|                                         row[13] = decimal.Round(Convert.ToDecimal(detail.TotalWeekPlanNum), 2);//累计计划完成量
 | |
|                                         row[14] = decimal.Round(Convert.ToDecimal(detail.TotalWeekThisNum), 2);//累计完成量
 | |
|                                         row[15] = decimal.Round(Convert.ToDecimal(detail.TotalWeekRealCost), 2);//累计完成成本
 | |
|                                         row[16] = decimal.Round(Convert.ToDecimal(detail.TotalWeekPlanValue), 2);//累计计划完成预算
 | |
|                                         row[17] = decimal.Round(Convert.ToDecimal(detail.TotalWeekPlanCost), 2);//累计完成预算
 | |
|                                     }
 | |
|                                     else
 | |
|                                     {
 | |
|                                         Model.View_WBS_CostControlDetail lastDetail = details.OrderByDescending(x => x.Months).OrderByDescending(x => x.StartDate).FirstOrDefault(x => x.CostControlId == item.Id);
 | |
|                                         if (lastDetail != null && lastDetail.Months <= months)
 | |
|                                         {
 | |
|                                             row[4] = lastDetail.Unit;//单位
 | |
|                                             row[5] = decimal.Round(Convert.ToDecimal(lastDetail.TotalNum), 2);//合同工作量
 | |
|                                             row[6] = decimal.Round(Convert.ToDecimal(lastDetail.RealPrice), 2);//成本单价
 | |
|                                             row[7] = decimal.Round(Convert.ToDecimal(lastDetail.PlanWeekNum), 2);//本周计划完成量
 | |
|                                             row[8] = decimal.Round(Convert.ToDecimal(lastDetail.ThisWeekNum), 2);//本周完成量
 | |
|                                             row[9] = decimal.Round(Convert.ToDecimal(lastDetail.PlanPrice), 2);//控制预算单价
 | |
|                                             row[13] = decimal.Round(Convert.ToDecimal(lastDetail.TotalWeekPlanNum), 2);//累计计划完成量
 | |
|                                             row[14] = decimal.Round(Convert.ToDecimal(lastDetail.TotalWeekThisNum), 2);//累计完成量
 | |
|                                             row[15] = decimal.Round(Convert.ToDecimal(lastDetail.TotalWeekRealCost), 2);//累计完成成本
 | |
|                                             row[16] = decimal.Round(Convert.ToDecimal(lastDetail.TotalWeekPlanValue), 2);//累计计划完成预算
 | |
|                                             row[17] = decimal.Round(Convert.ToDecimal(lastDetail.TotalWeekPlanCost), 2);//累计完成预算
 | |
|                                         }
 | |
|                                     }
 | |
|                                 }
 | |
|                                 table.Rows.Add(row);
 | |
|                             }
 | |
|                             if (d10 != 0)
 | |
|                             {
 | |
|                                 parentRow[10] = decimal.Round(d10, 2);//本周实际成本
 | |
|                                 parentRow[11] = decimal.Round(d11, 2);//本周计划完成预算
 | |
|                                 parentRow[12] = decimal.Round(d12, 2);//本周完成预算
 | |
|                                 parentRow[15] = decimal.Round(d15, 2);//累计完成成本
 | |
|                                 parentRow[16] = decimal.Round(d16, 2);//累计计划完成预算
 | |
|                                 parentRow[17] = decimal.Round(d17, 2);//累计完成预算
 | |
|                             }
 | |
|                             else
 | |
|                             {
 | |
|                                 parentRow[15] = decimal.Round(d15, 2);//累计完成成本
 | |
|                                 parentRow[16] = decimal.Round(d16, 2);//累计计划完成预算
 | |
|                                 parentRow[17] = decimal.Round(d17, 2);//累计完成预算
 | |
|                             }
 | |
|                             table.Rows.Add(parentRow);
 | |
|                         }
 | |
|                     }
 | |
|                     #endregion
 | |
|                 }
 | |
|             }
 | |
|             #endregion
 | |
|             return table;
 | |
|         }
 | |
| 
 | |
|         private static void GetAllWbsIds(List<string> list, string wbsSetId)
 | |
|         {
 | |
|             Model.Wbs_WbsSet wbsSet = BLL.WbsSetService.GetWbsSetByWbsSetId(wbsSetId);
 | |
|             if (wbsSet != null)
 | |
|             {
 | |
|                 list.Add(wbsSetId);
 | |
|                 GetAllWbsIds(list, wbsSet.SuperWbsSetId);
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         private static void GetAllInsIds(List<string> list, string installationId)
 | |
|         {
 | |
|             Model.Project_Installation installation = BLL.Project_InstallationService.GetInstallationByInstallationId(installationId);
 | |
|             if (installation != null)
 | |
|             {
 | |
|                 list.Add(installationId);
 | |
|                 GetAllInsIds(list, installation.SuperInstallationId);
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         private static void AddDetail(List<Model.View_WBS_CostControlDetailStatistics> newList, List<Model.View_WBS_CostControlDetailStatistics> oldList, string id)
 | |
|         {
 | |
|             var items = oldList.Where(x => x.SupId == id).OrderBy(x => x.Code);
 | |
|             foreach (var item in items)
 | |
|             {
 | |
|                 newList.Add(item);
 | |
|                 AddDetail(newList, oldList, item.Id);
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         private static void AddDetailOut(List<Model.View_WBS_CostControlDetailStatistics> newList, List<Model.View_WBS_CostControlDetailStatistics> oldList, string id, string prefix)
 | |
|         {
 | |
|             var items = oldList.Where(x => x.SupId == id).OrderBy(x => x.Code);
 | |
|             foreach (var item in items)
 | |
|             {
 | |
|                 item.Name = prefix + "...." + item.Name;
 | |
|                 newList.Add(item);
 | |
|                 AddDetailOut(newList, oldList, item.Id, prefix + "....");
 | |
|             }
 | |
|         }
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 获取模拟树表格
 | |
|         /// </summary>
 | |
|         /// <returns></returns>
 | |
|         public static DataTable GetAllTreeDataTable(string projectId, string IsOut, string Id)
 | |
|         {
 | |
|             using (var db = new Model.SGGLDB(Funs.ConnString))
 | |
|             {
 | |
|                 IQueryable<Model.WBS_CostControl> getCostControls = from x in db.WBS_CostControl select x;
 | |
|                 IQueryable<Model.View_WBS_CostControlDetail> getDetails = from x in db.View_WBS_CostControlDetail select x;
 | |
|                 IQueryable<Model.View_WBS_CostControlParentDetail> getParentDetails = from x in db.View_WBS_CostControlParentDetail select x;
 | |
|                 IQueryable<Model.Wbs_WbsSet> getWbsSets = from x in db.Wbs_WbsSet select x;
 | |
|                 IQueryable<Model.WBS_WbsSetInit> getWbsSetInits = from x in db.WBS_WbsSetInit select x;
 | |
|                 IQueryable<Model.Wbs_UnitProject> getUnitProjects = from x in db.Wbs_UnitProject select x;
 | |
|                 IQueryable<Model.Wbs_UnitProjectInit> getUnitProjectInits = from x in db.Wbs_UnitProjectInit select x;
 | |
|                 IQueryable<Model.WBS_CnProfession> getCnProfessions = from x in db.WBS_CnProfession select x;
 | |
|                 IQueryable<Model.WBS_CnProfessionInit> getCnProfessionInits = from x in db.WBS_CnProfessionInit select x;
 | |
|                 IQueryable<Model.Project_Installation> getInstallations = from x in db.Project_Installation select x;
 | |
|                 IQueryable<Model.View_WBS_CostControlDetailStatistics> getCostControlDetailStatisticss = from x in db.View_WBS_CostControlDetailStatistics select x;
 | |
|                 List<Model.View_WBS_CostControlDetailStatistics> CostControlDetailStatisticsList = new List<Model.View_WBS_CostControlDetailStatistics>();
 | |
|                 DataTable table = new DataTable();
 | |
|                 var installation = db.Project_Installation.FirstOrDefault(x => x.SuperInstallationId == "0" && x.ProjectId == projectId);
 | |
|                 if (installation != null)
 | |
|                 {
 | |
|                     DateTime startDate, endDate, startMonth, endMonth;
 | |
|                     List<DateTime> months = new List<DateTime>();
 | |
|                     if (installation.StartDate != null && installation.EndDate != 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);
 | |
|                     }
 | |
| 
 | |
|                     table.Columns.Add(new DataColumn("Id", typeof(String)));
 | |
|                     table.Columns.Add(new DataColumn("SupId", typeof(String)));
 | |
|                     table.Columns.Add(new DataColumn("Name", typeof(String)));
 | |
|                     table.Columns.Add(new DataColumn("ProjectId", typeof(String)));
 | |
|                     table.Columns.Add(new DataColumn("Unit", typeof(String)));
 | |
|                     table.Columns.Add(new DataColumn("TotalNum", typeof(String)));
 | |
|                     table.Columns.Add(new DataColumn("RealPrice", typeof(String)));
 | |
|                     table.Columns.Add(new DataColumn("PlanPrice", typeof(String)));
 | |
|                     table.Columns.Add(new DataColumn("PlanStartDate", typeof(DateTime)));
 | |
|                     table.Columns.Add(new DataColumn("PlanEndDate", typeof(DateTime)));
 | |
|                     table.Columns.Add(new DataColumn("RealStartDate", typeof(DateTime)));
 | |
|                     table.Columns.Add(new DataColumn("RealEndDate", typeof(DateTime)));
 | |
|                     for (int i = 0; i < months.Count; i++)
 | |
|                     {
 | |
|                         table.Columns.Add(new DataColumn("PlanNum" + (i + 1).ToString(), typeof(String)));
 | |
|                         table.Columns.Add(new DataColumn("ThisNum" + (i + 1).ToString(), typeof(String)));
 | |
|                     }
 | |
|                     table.Columns.Add(new DataColumn("ShowId", typeof(String)));
 | |
| 
 | |
|                     var costControls = getCostControls.Where(x => x.ProjectId == projectId);
 | |
|                     var details = getDetails.Where(x => x.ProjectId == projectId);
 | |
|                     var parentDetails = getParentDetails;
 | |
|                     var wbsSets = getWbsSets.Where(x => x.ProjectId == projectId);
 | |
|                     var wbsSetInits = getWbsSetInits;
 | |
| 
 | |
|                     var unitProjects = getUnitProjects.Where(x => x.ProjectId == projectId);
 | |
|                     var unitProjectInits = getUnitProjectInits;
 | |
|                     var cnProfessions = getCnProfessions.Where(x => x.ProjectId == projectId);
 | |
|                     var cnProfessionInits = getCnProfessionInits;
 | |
|                     var installations = getInstallations.Where(x => x.ProjectId == projectId);
 | |
| 
 | |
|                     CostControlDetailStatisticsList = getCostControlDetailStatisticss.Where(x => x.ProjectId == projectId).Distinct().ToList();
 | |
|                     List<Model.View_WBS_CostControlDetailStatistics> newList = new List<Model.View_WBS_CostControlDetailStatistics>();
 | |
|                     if (string.IsNullOrEmpty(Id))  //加载全项目记录
 | |
|                     {
 | |
|                         var installationList = CostControlDetailStatisticsList.Where(x => x.WBSType == "Installation" && x.SupId == "0");
 | |
|                         foreach (var item in installationList)
 | |
|                         {
 | |
|                             newList.Add(item);
 | |
|                             if (string.IsNullOrEmpty(IsOut))
 | |
|                             {
 | |
|                                 AddDetail(newList, CostControlDetailStatisticsList, item.Id);
 | |
|                             }
 | |
|                             else
 | |
|                             {
 | |
|                                 AddDetailOut(newList, CostControlDetailStatisticsList, item.Id, string.Empty);
 | |
|                             }
 | |
|                         }
 | |
|                     }
 | |
|                     else   //加载选择节点及其子级
 | |
|                     {
 | |
|                         var node = CostControlDetailStatisticsList.FirstOrDefault(x => x.Id == Id);
 | |
|                         if (node != null)
 | |
|                         {
 | |
|                             newList.Add(node);
 | |
|                             if (string.IsNullOrEmpty(IsOut))
 | |
|                             {
 | |
|                                 AddDetail(newList, CostControlDetailStatisticsList, node.Id);
 | |
|                             }
 | |
|                             else
 | |
|                             {
 | |
|                                 AddDetailOut(newList, CostControlDetailStatisticsList, node.Id, string.Empty);
 | |
|                             }
 | |
|                         }
 | |
|                     }
 | |
|                     DataRow row;
 | |
|                     foreach (Model.View_WBS_CostControlDetailStatistics item in newList)
 | |
|                     {
 | |
|                         row = table.NewRow();
 | |
|                         row[0] = item.Id;
 | |
|                         row[1] = item.SupId;
 | |
|                         row[2] = item.Name;
 | |
|                         row[3] = item.ProjectId;
 | |
|                         Model.WBS_CostControl costControl = costControls.FirstOrDefault(x => x.CostControlId == item.Id);
 | |
|                         if (costControl != null)
 | |
|                         {
 | |
|                             row[4] = costControl.Unit;//单位
 | |
|                             if (costControl.TotalNum != null)
 | |
|                             {
 | |
|                                 row[5] = decimal.Round(Convert.ToDecimal(costControl.TotalNum), 2);//合同工作量
 | |
|                             }
 | |
|                             if (costControl.RealPrice != null)
 | |
|                             {
 | |
|                                 row[6] = decimal.Round(Convert.ToDecimal(costControl.RealPrice), 2);//成本单价
 | |
|                             }
 | |
|                             if (costControl.PlanPrice != null)
 | |
|                             {
 | |
|                                 row[7] = decimal.Round(Convert.ToDecimal(costControl.PlanPrice), 2);//控制预算单价
 | |
|                             }
 | |
|                             if (costControl.PlanStartDate != null)
 | |
|                             {
 | |
|                                 row[8] = costControl.PlanStartDate;//计划开始时间
 | |
|                             }
 | |
|                             if (costControl.PlanEndDate != null)
 | |
|                             {
 | |
|                                 row[9] = costControl.PlanEndDate;//计划完成时间
 | |
|                             }
 | |
|                             if (costControl.RealStartDate != null)
 | |
|                             {
 | |
|                                 row[10] = costControl.RealStartDate;//实际开始时间
 | |
|                             }
 | |
|                             if (costControl.RealEndDate != null)
 | |
|                             {
 | |
|                                 row[11] = costControl.RealEndDate;//实际完成时间
 | |
|                             }
 | |
|                             var detail = details.Where(x => x.CostControlId == item.Id).ToList();
 | |
|                             foreach (var item1 in detail)
 | |
|                             {
 | |
|                                 var index = months.FindIndex(x => x.Equals(item1.Months));
 | |
|                                 if (item1.PlanNum != 0)
 | |
|                                 {
 | |
|                                     row[12 + index * 2] = decimal.Round(Convert.ToDecimal(item1.PlanNum), 2);
 | |
|                                 }
 | |
|                                 if (item1.ThisNum != 0)
 | |
|                                 {
 | |
|                                     row[13 + index * 2] = decimal.Round(Convert.ToDecimal(item1.ThisNum), 2);
 | |
|                                 }
 | |
| 
 | |
|                             }
 | |
|                             //for (int i = 0; i < months.Count; i++)
 | |
|                             //{
 | |
|                             //    Model.View_WBS_CostControlDetail detail = details.FirstOrDefault(x => x.CostControlId == item.Id && x.Months == months[i]);
 | |
|                             //    if (detail != null)
 | |
|                             //    {
 | |
|                             //        if (detail.PlanNum != 0)
 | |
|                             //        {
 | |
|                             //            row[12 + i * 2] = decimal.Round(Convert.ToDecimal(detail.PlanNum), 2);
 | |
|                             //        }
 | |
|                             //        if (detail.ThisNum != 0)
 | |
|                             //        {
 | |
|                             //            row[13 + i * 2] = decimal.Round(Convert.ToDecimal(detail.ThisNum), 2);
 | |
|                             //        }
 | |
|                             //    }
 | |
|                             //}
 | |
|                             row[14 + (months.Count - 1) * 2] = item.Id;
 | |
|                             //row[10] = decimal.Round(Convert.ToDecimal(detail.ThisRealCost), 2);//本月实际成本
 | |
|                             //row[11] = decimal.Round(Convert.ToDecimal(detail.ThisPlanValue), 2);//本月计划完成预算
 | |
|                             //row[12] = decimal.Round(Convert.ToDecimal(detail.ThisPlanCost), 2);//本月完成预算
 | |
|                             //row[13] = decimal.Round(Convert.ToDecimal(detail.TotalPlanNum), 2);//累计计划完成量
 | |
|                             //row[14] = decimal.Round(Convert.ToDecimal(detail.TotalThisNum), 2);//累计完成量
 | |
|                             //row[15] = decimal.Round(Convert.ToDecimal(detail.TotalRealCost), 2);//累计完成成本
 | |
|                             //row[16] = decimal.Round(Convert.ToDecimal(detail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                             //row[17] = decimal.Round(Convert.ToDecimal(detail.TotalPlanCost), 2);//累计完成预算
 | |
|                         }
 | |
|                         else
 | |
|                         {
 | |
|                             //Model.View_WBS_CostControlParentDetail parentDetail = parentDetails.FirstOrDefault(x => x.ParentId == item.Id && x.Months == months);
 | |
|                             //if (parentDetail != null)
 | |
|                             //{
 | |
|                             //    row[10] = decimal.Round(Convert.ToDecimal(parentDetail.ThisRealCost), 2);//本月实际成本
 | |
|                             //    row[11] = decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanValue), 2);//本月计划完成预算
 | |
|                             //    row[12] = decimal.Round(Convert.ToDecimal(parentDetail.ThisPlanCost), 2);//本月完成预算
 | |
|                             //    row[15] = decimal.Round(Convert.ToDecimal(parentDetail.TotalRealCost), 2);//累计完成成本
 | |
|                             //    row[16] = decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                             //    row[17] = decimal.Round(Convert.ToDecimal(parentDetail.TotalPlanCost), 2);//累计完成预算
 | |
|                             //}
 | |
|                             //else
 | |
|                             //{
 | |
|                             //    Model.View_WBS_CostControlParentDetail parentLastDetail = parentDetails.OrderByDescending(x => x.Months).FirstOrDefault(x => x.ParentId == item.Id);
 | |
|                             //    if (parentLastDetail != null && parentLastDetail.Months <= months)
 | |
|                             //    {
 | |
|                             //        row[15] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalRealCost), 2);//累计完成成本
 | |
|                             //        row[16] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanValue), 2);//累计计划完成预算
 | |
|                             //        row[17] = decimal.Round(Convert.ToDecimal(parentLastDetail.TotalPlanCost), 2);//累计完成预算
 | |
|                             //    }
 | |
|                             //}
 | |
|                         }
 | |
|                         table.Rows.Add(row);
 | |
|                     }
 | |
|                 }
 | |
|                 return table;
 | |
|             }
 | |
|         }
 | |
| 
 | |
|     }
 | |
| }
 |