CNCEC_SUBQHSE_WUHUAN/SGGL/BLL/JDGL/WBSCompleteAndReal/WBSReportService.cs

382 lines
19 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
namespace BLL
{
public static class WBSReportService
{
/// <summary>
/// 获取模拟树表格
/// </summary>
/// <returns></returns>
public static DataTable GetTreeDataTable(string projectId, int year, int month, string[] installationId, string[] cnProfessionId, int marking2, string rectificationMeasureType)
{
List<Model.View_WBSReport> WBSReportList = new List<Model.View_WBSReport>();
List<Model.View_WBSReport> newInstallationList = new List<Model.View_WBSReport>();
List<Model.View_WBSReport> newCNProfessionList = new List<Model.View_WBSReport>();
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("Weights", typeof(String)));
table.Columns.Add(new DataColumn("WeightsMoneyTotal", typeof(String)));
table.Columns.Add(new DataColumn("CompleteValue", typeof(String)));
table.Columns.Add(new DataColumn("CompleteValueTotal", typeof(String)));
table.Columns.Add(new DataColumn("CompleteValuePercentage", typeof(String)));
table.Columns.Add(new DataColumn("RealValue", typeof(String)));
table.Columns.Add(new DataColumn("RealValueTotal", typeof(String)));
table.Columns.Add(new DataColumn("SVCost", typeof(String)));
table.Columns.Add(new DataColumn("CVCost", typeof(String)));
table.Columns.Add(new DataColumn("StartDate", typeof(String)));
table.Columns.Add(new DataColumn("EndDate", typeof(String)));
table.Columns.Add(new DataColumn("PlanValue", typeof(String)));
table.Columns.Add(new DataColumn("PlanValueTotal", typeof(String)));
table.Columns.Add(new DataColumn("PlanValuePercentage", typeof(String)));
table.Columns.Add(new DataColumn("PlanValueRateTotal", typeof(String)));
table.Columns.Add(new DataColumn("IsLeaf", typeof(String)));
table.Columns.Add(new DataColumn("RectificationMeasureNames", typeof(String)));
//时间筛选
WBSReportList = (from x in Funs.DB.View_WBSReport where x.ProjectId == projectId && x.Months.Value.Year == year && x.Months.Value.Month == month select x).Distinct().ToList();
//单位工程、子单位工程、分部工程、子分部工程、分项工程、子分项工程 筛选
if (marking2 != 0)
{
WBSReportList = (from x in WBSReportList where x.Marking2 <= marking2 select x).Distinct().ToList();
}
#region
if (installationId != null)
{
if (installationId.Length > 0)
{
List<string> allId1 = new List<string>();
List<string> allId2 = new List<string>();
List<string> allId3 = new List<string>();
List<string> allId4 = new List<string>();
List<string> allId5 = new List<string>();
List<string> allId6 = new List<string>();
List<string> allId7 = new List<string>();
foreach (var item in installationId) //在集合中获取Id或SupId是所选中装置Id的记录的Id
{
foreach (Model.View_WBSReport r in WBSReportList)
{
if (item == r.Id || item == r.SupId)
{
if (!allId1.Contains(r.Id))
{
allId1.Add(r.Id);//装置和专业记录的Id
}
}
}
}
foreach (string item in allId1)
{
foreach (Model.View_WBSReport r in WBSReportList)
{
if (item == r.Id || item == r.SupId)
{
if (!allId2.Contains(r.Id))
{
allId2.Add(r.Id);//装置、专业、单位工程所在记录的Id
}
}
}
}
foreach (string item in allId2)
{
foreach (Model.View_WBSReport r in WBSReportList)
{
if (item == r.Id || item == r.SupId)
{
if (!allId3.Contains(r.Id))
{
allId3.Add(r.Id);
}
}
}
}
foreach (string item in allId3)
{
foreach (Model.View_WBSReport r in WBSReportList)
{
if (item == r.Id || item == r.SupId)
{
if (!allId4.Contains(r.Id))
{
allId4.Add(r.Id);
}
}
}
}
foreach (string item in allId4)
{
foreach (Model.View_WBSReport r in WBSReportList)
{
if (item == r.Id || item == r.SupId)
{
if (!allId5.Contains(r.Id))
{
allId5.Add(r.Id);
}
}
}
}
foreach (string item in allId5)
{
foreach (Model.View_WBSReport r in WBSReportList)
{
if (item == r.Id || item == r.SupId)
{
if (!allId6.Contains(r.Id))
{
allId6.Add(r.Id);
}
}
}
}
foreach (string item in allId6)
{
foreach (Model.View_WBSReport r in WBSReportList)
{
if (item == r.Id || item == r.SupId)
{
if (!allId7.Contains(r.Id))
{
allId7.Add(r.Id);
}
}
}
}
foreach (string item in allId7)
{
Model.View_WBSReport report = (from x in WBSReportList where x.Id == item select x).FirstOrDefault();
newInstallationList.Add(report);//根据所选最终Id获取对应记录
}
WBSReportList = newInstallationList;//最终集合
}
}
#endregion
#region
if (cnProfessionId != null)
{
if (cnProfessionId.Length > 0)
{
List<string> allIdA = new List<string>();
List<string> allIdB = new List<string>();
List<string> allIdC = new List<string>();
List<string> allIdD = new List<string>();
List<string> allIdE = new List<string>();
List<string> allIdF = new List<string>();
foreach (string item in cnProfessionId)
{
foreach (Model.View_WBSReport r in WBSReportList)//WBSReportList为以上条件筛选后的集合
{
Model.WBS_CnProfession cnp = (from x in Funs.DB.WBS_CnProfession where x.CnProfessionId == r.Id select x).FirstOrDefault();
if (cnp != null)
{
if (cnp.OldId.ToString() == item)//判断集合中的专业记录是否筛选条件
{
allIdA.Add(r.Id);//所有装置下符合所选专业条件记录的Id
}
}
}
}
foreach (string item in allIdA)
{
foreach (Model.View_WBSReport r in WBSReportList)
{
if (item == r.Id || item == r.SupId)
{
if (!allIdB.Contains(r.Id))
{
allIdB.Add(r.Id);//符合条件的专业Id、和对应专业下单位工程的Id
}
}
}
}
foreach (string item in allIdB)
{
foreach (Model.View_WBSReport r in WBSReportList)
{
if (item == r.Id || item == r.SupId)
{
if (!allIdC.Contains(r.Id))
{
allIdC.Add(r.Id);
}
}
}
}
foreach (string item in allIdC)
{
foreach (Model.View_WBSReport r in WBSReportList)
{
if (item == r.Id || item == r.SupId)
{
if (!allIdD.Contains(r.Id))
{
allIdD.Add(r.Id);
}
}
}
}
foreach (string item in allIdD)
{
foreach (Model.View_WBSReport r in WBSReportList)
{
if (item == r.Id || item == r.SupId)
{
if (!allIdE.Contains(r.Id))
{
allIdE.Add(r.Id);
}
}
}
}
foreach (string item in allIdE)
{
foreach (Model.View_WBSReport r in WBSReportList)
{
if (item == r.Id || item == r.SupId)
{
if (!allIdF.Contains(r.Id))
{
allIdF.Add(r.Id);
}
}
}
}
foreach (string item in allIdF)//allIdF 最终符合条件的记录主键
{
Model.View_WBSReport report = (from x in WBSReportList where x.Id == item select x).FirstOrDefault();
if (report != null)
{
newCNProfessionList.Add(report);//在集合中获取记录
}
}
if (installationId != null)
{
if (installationId.Length > 0)
{
foreach (string item in installationId)
{
Model.View_WBSReport report = (from x in WBSReportList where x.Id == item select x).FirstOrDefault();
if (report != null)
{
newCNProfessionList.Add(report);//当装置空时添加所选装置对应记录
}
}
}
else
{
List<Model.WBS_UnitWork> InstallationList = (from x in Funs.DB.WBS_UnitWork where x.ProjectId == projectId && (x.SuperUnitWork == null || x.SuperUnitWork == "0") select x).ToList();//装置条件为空时获取对应操作表中所有的装置
foreach (Model.WBS_UnitWork item in InstallationList)
{
Model.View_WBSReport InstallationInit = (from x in WBSReportList where x.Id == item.UnitWorkId select x).FirstOrDefault();
if (InstallationInit != null)//判断这些装置是否在筛选集合中,符合的添加
{
newCNProfessionList.Add(InstallationInit);
}
}
}
}
else
{
List<Model.WBS_UnitWork> InstallationList = (from x in Funs.DB.WBS_UnitWork where x.ProjectId==projectId && (x.SuperUnitWork == null || x.SuperUnitWork == "0") select x).ToList();
foreach (Model.WBS_UnitWork item in InstallationList)
{
Model.View_WBSReport InstallationInit = (from x in WBSReportList where x.Id == item.UnitWorkId select x).FirstOrDefault();
if (InstallationInit != null)
{
newCNProfessionList.Add(InstallationInit);
}
}
}
WBSReportList = newCNProfessionList;
}
}
#endregion
DataRow row;
foreach (Model.View_WBSReport item in WBSReportList)
{
row = table.NewRow();
row[0] = item.Id;
row[1] = item.SupId;
row[2] = item.Name;
row[3] = item.Weights;
row[4] = decimal.Round(Convert.ToDecimal(item.WeightsMoney), 2);
row[5] = decimal.Round(Convert.ToDecimal(item.CompleteValue), 2);//完成值
DateTime date = Convert.ToDateTime(year + "-" + month + "-01");
List<Model.WbsDetail> totalDetails = BLL.WbsDetailService.GetTotalWbsDetailsByYearMonth2(item.Id, date);
Decimal CompleteValueTotal = decimal.Round(Convert.ToDecimal(totalDetails.Sum(x => x.CompleteValue ?? 0)), 2);
row[6] = CompleteValueTotal;//完成值累计费用
row[7] = decimal.Round(Convert.ToDecimal(CompleteValueTotal) / Convert.ToDecimal(item.WeightsMoney) * 100, 2);//累计%
row[8] = decimal.Round(Convert.ToDecimal(item.RealValue), 2);//实耗值
Decimal RealValueTotal = decimal.Round(Convert.ToDecimal(totalDetails.Sum(x => x.RealValue ?? 0)), 2);
row[9] = RealValueTotal;//累计实耗
Decimal PlanValueTotal = decimal.Round(Convert.ToDecimal(totalDetails.Sum(x => x.PlanValue ?? 0)), 2);//累计计划
row[10] = CompleteValueTotal - PlanValueTotal;//进度SV费用万元=完成值累计费用-计划值累计费用
row[11] = CompleteValueTotal - RealValueTotal;//费用CV费用万元=完成值累计费用-实耗值累计实耗
row[12] = string.Format("{0:yyyy-MM-dd}", item.StartDate);
row[13] = string.Format("{0:yyyy-MM-dd}", item.EndDate);
row[14] = decimal.Round(Convert.ToDecimal(item.PlanValue), 2);//计划值
row[15] = PlanValueTotal;//累计计划
row[16] = decimal.Round(Convert.ToDecimal(item.PlanValue) / Convert.ToDecimal(item.WeightsMoney) * 100, 2);// //月计划%
row[17] = decimal.Round(Convert.ToDecimal(PlanValueTotal) / Convert.ToDecimal(item.WeightsMoney) * 100, 2);// //累计计划%
int count = (from x in WBSReportList where x.SupId == item.Id select x).Count();
if (count == 0)
{
row[18] = "true"; //末级节点
}
else
{
row[18] = "false"; //非末级节点
}
string str = string.Empty;
Model.WBSRectificationMeasureSet wBSRectificationMeasureSet = BLL.WBSRectificationMeasureSetService.GetWBSRectificationMeasureSetByDateAndToWbs(item.Id, date, rectificationMeasureType);
if (wBSRectificationMeasureSet != null)
{
if (!string.IsNullOrEmpty(wBSRectificationMeasureSet.RectificationMeasureIds))
{
if (rectificationMeasureType == "1")
{
str += "进度纠偏措施:";
}
else
{
str += "费用纠偏措施:";
}
string[] ids = wBSRectificationMeasureSet.RectificationMeasureIds.Split(',');
foreach (var id in ids)
{
Model.JDGL_Base_RectificationMeasure rectificationMeasure = BLL.RectificationMeasureService.GetRectificationMeasureByRectificationMeasureId(id);
if (rectificationMeasure != null)
{
str += rectificationMeasure.RectificationMeasureName + ",";
}
}
}
}
if (!string.IsNullOrEmpty(str))
{
row[19] = str.Substring(0, str.LastIndexOf(",")) + (wBSRectificationMeasureSet.IsComplete == true ? "(措施已落实)" : "(尚在落实中)");
}
table.Rows.Add(row);
}
return table;
}
}
}