755 lines
38 KiB
C#
755 lines
38 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
|
|
namespace BLL
|
|
{
|
|
public class WorkPackageService
|
|
{
|
|
/// <summary>
|
|
/// 添加分部分项工程
|
|
/// </summary>
|
|
/// <param name="WorkPackage"></param>
|
|
public static void AddWorkPackage(Model.WBS_WorkPackage WorkPackage)
|
|
{
|
|
Model.SGGLDB db = Funs.DB;
|
|
Model.WBS_WorkPackage newWorkPackage = new Model.WBS_WorkPackage();
|
|
|
|
newWorkPackage.WorkPackageId = WorkPackage.WorkPackageId;
|
|
newWorkPackage.WorkPackageCode = WorkPackage.WorkPackageCode;
|
|
newWorkPackage.UnitWorkId = WorkPackage.UnitWorkId;
|
|
newWorkPackage.SuperWorkPack = WorkPackage.SuperWorkPack;
|
|
newWorkPackage.PackageCode = WorkPackage.PackageCode;
|
|
newWorkPackage.SuperWorkPackageId = WorkPackage.SuperWorkPackageId;
|
|
newWorkPackage.PackageContent = WorkPackage.PackageContent;
|
|
newWorkPackage.ProjectId = WorkPackage.ProjectId;
|
|
newWorkPackage.IsChild = WorkPackage.IsChild;
|
|
newWorkPackage.SortIndex = WorkPackage.SortIndex;
|
|
newWorkPackage.InitWorkPackageCode = WorkPackage.InitWorkPackageCode;
|
|
newWorkPackage.Weights = WorkPackage.Weights;
|
|
newWorkPackage.ProjectType = WorkPackage.ProjectType;
|
|
newWorkPackage.IsApprove = WorkPackage.IsApprove;
|
|
newWorkPackage.Costs = WorkPackage.Costs;
|
|
newWorkPackage.SubItemType = WorkPackage.SubItemType;
|
|
newWorkPackage.PreJobId = WorkPackage.PreJobId;
|
|
newWorkPackage.PlanProjectQuantity = WorkPackage.PlanProjectQuantity;
|
|
newWorkPackage.RealProjectQuantity = WorkPackage.RealProjectQuantity;
|
|
newWorkPackage.PlanStartDate = WorkPackage.PlanStartDate;
|
|
newWorkPackage.PlanEndDate = WorkPackage.PlanEndDate;
|
|
newWorkPackage.RealStartDate = WorkPackage.RealStartDate;
|
|
newWorkPackage.RealEndDate = WorkPackage.RealEndDate;
|
|
newWorkPackage.Unit = WorkPackage.Unit;
|
|
|
|
db.WBS_WorkPackage.InsertOnSubmit(newWorkPackage);
|
|
db.SubmitChanges();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改分部分项工程
|
|
/// </summary>
|
|
/// <param name="WorkPackage"></param>
|
|
public static void UpdateWorkPackage(Model.WBS_WorkPackage WorkPackage)
|
|
{
|
|
Model.SGGLDB db = Funs.DB;
|
|
Model.WBS_WorkPackage newWorkPackage = db.WBS_WorkPackage.First(e => e.WorkPackageId == WorkPackage.WorkPackageId);
|
|
newWorkPackage.WorkPackageCode = WorkPackage.WorkPackageCode;
|
|
newWorkPackage.UnitWorkId = WorkPackage.UnitWorkId;
|
|
newWorkPackage.PackageCode = WorkPackage.PackageCode;
|
|
newWorkPackage.PackageContent = WorkPackage.PackageContent;
|
|
newWorkPackage.ProjectId = WorkPackage.ProjectId;
|
|
newWorkPackage.IsChild = WorkPackage.IsChild;
|
|
newWorkPackage.SortIndex = WorkPackage.SortIndex;
|
|
newWorkPackage.Weights = WorkPackage.Weights;
|
|
newWorkPackage.IsApprove = WorkPackage.IsApprove;
|
|
newWorkPackage.Costs = WorkPackage.Costs;
|
|
newWorkPackage.SubItemType = WorkPackage.SubItemType;
|
|
newWorkPackage.PreJobId = WorkPackage.PreJobId;
|
|
newWorkPackage.PlanProjectQuantity = WorkPackage.PlanProjectQuantity;
|
|
newWorkPackage.RealProjectQuantity = WorkPackage.RealProjectQuantity;
|
|
newWorkPackage.PlanStartDate = WorkPackage.PlanStartDate;
|
|
newWorkPackage.PlanEndDate = WorkPackage.PlanEndDate;
|
|
newWorkPackage.RealStartDate = WorkPackage.RealStartDate;
|
|
newWorkPackage.RealEndDate = WorkPackage.RealEndDate;
|
|
newWorkPackage.Unit = WorkPackage.Unit;
|
|
newWorkPackage.IsMileStone = WorkPackage.IsMileStone;
|
|
newWorkPackage.PlanCost = WorkPackage.PlanCost;
|
|
newWorkPackage.JDWeights = WorkPackage.JDWeights;
|
|
newWorkPackage.PreWorkCode = WorkPackage.PreWorkCode;
|
|
|
|
db.SubmitChanges();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据单位工程id获取一个第一级分部信息
|
|
/// </summary>
|
|
/// <param name="unitWorkId"></param>
|
|
/// <returns></returns>
|
|
public static Model.WBS_WorkPackage GetWorkPackages1ByUnitWorkId(string unitWorkId)
|
|
{
|
|
return Funs.DB.WBS_WorkPackage.FirstOrDefault(x => x.SuperWorkPackageId == null && x.IsApprove == true && x.UnitWorkId == unitWorkId);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据单位工程Id获取第一级所有分部信息
|
|
/// </summary>
|
|
/// <param name="unitWorkId"></param>
|
|
/// <returns></returns>
|
|
public static List<Model.WBS_WorkPackage> GetWorkPackages1sByUnitWorkId(string unitWorkId)
|
|
{
|
|
return (from x in Funs.DB.WBS_WorkPackage where x.SuperWorkPackageId == null && x.UnitWorkId.ToString() == unitWorkId orderby x.WorkPackageCode select x).ToList();
|
|
}
|
|
/// <summary>
|
|
/// 根据单位工程Id获取第一级审批所有分部信息
|
|
/// </summary>
|
|
/// <param name="unitWorkId"></param>
|
|
/// <returns></returns>
|
|
public static List<Model.WBS_WorkPackage> GetApproveWorkPackages1sByUnitWorkId(string unitWorkId)
|
|
{
|
|
return (from x in Funs.DB.WBS_WorkPackage where x.SuperWorkPackageId == null && x.UnitWorkId.ToString() == unitWorkId && x.IsApprove == true orderby x.WorkPackageCode select x).ToList();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据分部分项名称和单位工程id获取项目分部分项内容
|
|
/// </summary>
|
|
/// <param name="workPackageCode"></param>
|
|
/// <param name="projectId"></param>
|
|
/// <returns></returns>
|
|
public static Model.WBS_WorkPackage GetWorkPackageByPackageContent(string packageContent, string unitWorkId)
|
|
{
|
|
return Funs.DB.WBS_WorkPackage.FirstOrDefault(x => x.PackageContent == packageContent && x.UnitWorkId == unitWorkId);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据单位工程Id获取所有分部信息
|
|
/// </summary>
|
|
/// <param name="unitWorkId"></param>
|
|
/// <returns></returns>
|
|
public static List<Model.WBS_WorkPackage> GetAllWorkPackagesByUnitWorkId(string unitWorkId)
|
|
{
|
|
return (from x in Funs.DB.WBS_WorkPackage where x.UnitWorkId.ToString() == unitWorkId orderby x.WorkPackageCode select x).ToList();
|
|
}
|
|
/// <summary>
|
|
/// 根据项目Id获取所有分部信息
|
|
/// </summary>
|
|
/// <param name="unitWorkId"></param>
|
|
/// <returns></returns>
|
|
public static List<Model.WBS_WorkPackage> GetAllWorkPackagesByProjectId(string projectId)
|
|
{
|
|
return (from x in Funs.DB.WBS_WorkPackage where x.ProjectId == projectId orderby x.WorkPackageCode select x).ToList();
|
|
}
|
|
/// <summary>
|
|
/// 根据分部分项Id获取分部分项信息
|
|
/// </summary>
|
|
/// <param name="workPackageId"></param>
|
|
/// <returns></returns>
|
|
public static Model.WBS_WorkPackage GetWorkPackageByWorkPackageId(string workPackageId)
|
|
{
|
|
return Funs.DB.WBS_WorkPackage.FirstOrDefault(x => x.WorkPackageId == workPackageId);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据单位工程Id和初始化编号获取分部分项信息
|
|
/// </summary>
|
|
/// <param name="unitWorkId"></param>
|
|
/// <param name="initWorkPackageCode"></param>
|
|
/// <returns></returns>
|
|
public static Model.WBS_WorkPackage GetWorkPackageByUnitWorkIdAndInitWorkPackageCode(string unitWorkId, string initWorkPackageCode)
|
|
{
|
|
return Funs.DB.WBS_WorkPackage.FirstOrDefault(x => x.UnitWorkId == unitWorkId && x.InitWorkPackageCode == initWorkPackageCode);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据父级Id获取所有分部分项信息
|
|
/// </summary>
|
|
/// <param name="workPackageId"></param>
|
|
/// <returns></returns>
|
|
public static List<Model.WBS_WorkPackage> GetAllWorkPackagesBySuperWorkPackageId(string workPackageId)
|
|
{
|
|
return (from x in Funs.DB.WBS_WorkPackage where x.SuperWorkPackageId == workPackageId orderby x.WorkPackageCode select x).ToList();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据父级Id获取所有审批分部分项信息
|
|
/// </summary>
|
|
/// <param name="workPackageId"></param>
|
|
/// <returns></returns>
|
|
public static List<Model.WBS_WorkPackage> GetAllApproveWorkPackagesBySuperWorkPackageId(string workPackageId)
|
|
{
|
|
return (from x in Funs.DB.WBS_WorkPackage where x.SuperWorkPackageId == workPackageId && x.IsApprove == true orderby x.WorkPackageCode select x).ToList();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据子分部工程Id删除一个子分部工程信息
|
|
/// </summary>
|
|
/// <param name="WorkPackageId"></param>
|
|
public static void DeleteWorkPackage(string WorkPackageId)
|
|
{
|
|
Model.SGGLDB db = Funs.DB;
|
|
Model.WBS_WorkPackage WorkPackage = db.WBS_WorkPackage.First(e => e.WorkPackageId == WorkPackageId);
|
|
db.WBS_WorkPackage.DeleteOnSubmit(WorkPackage);
|
|
db.SubmitChanges();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据分部分项Id删除所有明细信息
|
|
/// </summary>
|
|
/// <param name="ControlItemAndCycleId"></param>
|
|
public static void DeleteAllWorkPackageByUnitWorkId(string unitWorkId)
|
|
{
|
|
Model.SGGLDB db = Funs.DB;
|
|
List<Model.WBS_WorkPackage> q = (from x in db.WBS_WorkPackage where x.UnitWorkId == unitWorkId orderby x.WorkPackageCode select x).ToList();
|
|
db.WBS_WorkPackage.DeleteAllOnSubmit(q);
|
|
db.SubmitChanges();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据初始工作包编码和单位工程获取工作包集合
|
|
/// </summary>
|
|
/// <param name="initWorkPackageCode"></param>
|
|
/// <param name="unitWorkId"></param>
|
|
/// <returns></returns>
|
|
public static List<Model.WBS_WorkPackage> GetWorkPackagesByInitWorkPackageCodeAndUnitWorkId(string initWorkPackageCode, string unitWorkId)
|
|
{
|
|
return (from x in Funs.DB.WBS_WorkPackage where x.InitWorkPackageCode == initWorkPackageCode && x.UnitWorkId.ToString() == unitWorkId orderby x.WorkPackageCode descending select x).ToList();
|
|
}
|
|
/// <summary>
|
|
/// 根据单位工程Id获取所有分部信息
|
|
/// </summary>
|
|
/// <param name="unitWorkId"></param>
|
|
/// <returns></returns>
|
|
public static List<Model.WBS_WorkPackage> GetAllWorkPackagesByUnitWorkIds(string[] unitWorkIds)
|
|
{
|
|
return (from x in Funs.DB.WBS_WorkPackage where unitWorkIds.Contains(x.UnitWorkId) orderby x.WorkPackageCode select x).ToList();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取单位工程分部分项下拉列表
|
|
/// </summary>
|
|
/// <param name="dropName"></param>
|
|
/// <param name="projectId"></param>
|
|
/// <param name="isShowPlease"></param>
|
|
public static void InitWorkPackagesDropDownListByUnitWorkId(FineUIPro.DropDownList dropName, string unitWorkId, bool isShowPlease)
|
|
{
|
|
dropName.DataValueField = "WorkPackageId";
|
|
dropName.DataTextField = "PackageContent";
|
|
dropName.DataSource = GetAllWorkPackagesByUnitWorkId(unitWorkId);
|
|
dropName.DataBind();
|
|
if (isShowPlease)
|
|
{
|
|
Funs.FineUIPleaseSelect(dropName);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取模拟树表格
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static DataTable GetAllTreeDataTable(string projectId, string IsOut, string startTime, string endTime, string isOK)
|
|
{
|
|
using (var db = new Model.SGGLDB(Funs.ConnString))
|
|
{
|
|
IQueryable<Model.WBS_WorkPackage> workPackages = from x in db.WBS_WorkPackage where x.ProjectId == projectId select x;
|
|
IQueryable<Model.WBS_UnitWork> unitWorks = from x in db.WBS_UnitWork where x.ProjectId == projectId select x;
|
|
IQueryable<Model.View_WBS_WorkPackageDetail> getDetails = from x in db.View_WBS_WorkPackageDetail where x.ProjectId == projectId select x;
|
|
List<Model.View_WBS> getWBSs = (from x in db.View_WBS where x.ProjectId == projectId select x).ToList();
|
|
List<Model.View_WBS> WBSList = new List<Model.View_WBS>();
|
|
DateTime startDate, endDate, startMonth, endMonth;
|
|
List<DateTime> months = new List<DateTime>();
|
|
var project = Funs.DB.Base_Project.FirstOrDefault(x => x.ProjectId == projectId);
|
|
if (project.StartDate != null)
|
|
{
|
|
startDate = Convert.ToDateTime(project.StartDate);
|
|
endDate = DateTime.Now;
|
|
if (project.EndDate != null)
|
|
{
|
|
endDate = Convert.ToDateTime(project.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);
|
|
}
|
|
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("WBSType", typeof(String)));
|
|
table.Columns.Add(new DataColumn("ProjectId", typeof(String)));
|
|
table.Columns.Add(new DataColumn("ShowId", typeof(String)));
|
|
table.Columns.Add(new DataColumn("JDWeights", typeof(String)));
|
|
table.Columns.Add(new DataColumn("Unit", typeof(String)));
|
|
table.Columns.Add(new DataColumn("PlanProjectQuantity", typeof(String)));
|
|
table.Columns.Add(new DataColumn("RealProjectQuantity", 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)));
|
|
table.Columns.Add(new DataColumn("IsMileStone", typeof(bool)));
|
|
table.Columns.Add(new DataColumn("PlanCost", typeof(String)));
|
|
table.Columns.Add(new DataColumn("PreWorkCode", typeof(String)));
|
|
table.Columns.Add(new DataColumn("Code", typeof(String)));
|
|
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)));
|
|
}
|
|
if (getWBSs.Count() > 0)
|
|
{
|
|
List<Model.View_WBS> newList = new List<Model.View_WBS>();
|
|
var projectTypes = getWBSs.Where(x => x.WBSType == "ProjectType" && x.SupId == "0");
|
|
int a = 1;
|
|
foreach (var item in projectTypes)
|
|
{
|
|
item.Code = a.ToString();
|
|
newList.Add(item);
|
|
if (string.IsNullOrEmpty(IsOut))
|
|
{
|
|
AddDetail(newList, getWBSs.ToList(), item.Id, a.ToString(), startTime, endTime, isOK);
|
|
}
|
|
else
|
|
{
|
|
AddDetail(newList, getWBSs.ToList(), item.Id, a.ToString(), string.Empty, startTime, endTime, isOK);
|
|
}
|
|
a++;
|
|
}
|
|
DataRow row;
|
|
foreach (Model.View_WBS item in newList)
|
|
{
|
|
row = table.NewRow();
|
|
row[0] = item.Id;
|
|
row[1] = item.SupId;
|
|
row[2] = item.Name;
|
|
row[3] = item.WBSType;
|
|
row[4] = item.ProjectId;
|
|
if (item.WBSType == "WorkPackage")
|
|
{
|
|
var childWorkPackages = from x in workPackages where x.SuperWorkPackageId == item.Id && x.IsApprove == true select x;
|
|
var workPackage = workPackages.FirstOrDefault(x => x.WorkPackageId == item.Id);
|
|
if (workPackage != null)
|
|
{
|
|
if (childWorkPackages.Count() == 0)
|
|
{
|
|
row[5] = item.Id;
|
|
if (workPackage.JDWeights != null)
|
|
{
|
|
row[6] = decimal.Round(Convert.ToDecimal(workPackage.JDWeights), 2);
|
|
}
|
|
row[7] = workPackage.Unit;
|
|
if (workPackage.PlanProjectQuantity != null)
|
|
{
|
|
row[8] = decimal.Round(Convert.ToDecimal(workPackage.PlanProjectQuantity), 2);
|
|
}
|
|
if (workPackage.RealProjectQuantity != null)
|
|
{
|
|
row[9] = decimal.Round(Convert.ToDecimal(workPackage.RealProjectQuantity), 2);
|
|
}
|
|
if (workPackage.PlanStartDate != null)
|
|
{
|
|
row[10] = workPackage.PlanStartDate;
|
|
}
|
|
if (workPackage.PlanEndDate != null)
|
|
{
|
|
row[11] = workPackage.PlanEndDate;
|
|
}
|
|
if (workPackage.RealStartDate != null)
|
|
{
|
|
row[12] = workPackage.RealStartDate;
|
|
}
|
|
if (workPackage.RealEndDate != null)
|
|
{
|
|
row[13] = workPackage.RealEndDate;
|
|
}
|
|
if (workPackage.IsMileStone != null)
|
|
{
|
|
row[14] = workPackage.IsMileStone;
|
|
}
|
|
if (workPackage.PlanCost != null)
|
|
{
|
|
row[15] = decimal.Round(Convert.ToDecimal(workPackage.PlanCost), 2);
|
|
}
|
|
row[16] = workPackage.PreWorkCode;
|
|
var details = getDetails.Where(x => x.WorkPackageId == item.Id).ToList();
|
|
foreach (var item1 in details)
|
|
{
|
|
var index = months.FindIndex(x => x.Equals(item1.Months));
|
|
if (item1.PlanNum != 0)
|
|
{
|
|
row[18 + index * 2] = decimal.Round(Convert.ToDecimal(item1.PlanNum), 2);
|
|
}
|
|
if (item1.ThisNum != 0)
|
|
{
|
|
row[19 + index * 2] = decimal.Round(Convert.ToDecimal(item1.ThisNum), 2);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (workPackage.JDWeights != null)
|
|
{
|
|
row[6] = decimal.Round(Convert.ToDecimal(workPackage.JDWeights), 2);
|
|
}
|
|
if (workPackage.PlanStartDate != null)
|
|
{
|
|
row[10] = workPackage.PlanStartDate;
|
|
}
|
|
if (workPackage.PlanEndDate != null)
|
|
{
|
|
row[11] = workPackage.PlanEndDate;
|
|
}
|
|
if (workPackage.RealStartDate != null)
|
|
{
|
|
row[12] = workPackage.RealStartDate;
|
|
}
|
|
if (workPackage.RealEndDate != null)
|
|
{
|
|
row[13] = workPackage.RealEndDate;
|
|
}
|
|
if (workPackage.PlanCost != null)
|
|
{
|
|
row[15] = decimal.Round(Convert.ToDecimal(workPackage.PlanCost), 2);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else if (item.WBSType == "UnitWork")
|
|
{
|
|
var unitWork = unitWorks.FirstOrDefault(x => x.UnitWorkId == item.Id);
|
|
if (unitWork != null)
|
|
{
|
|
if (unitWork.JDWeights != null)
|
|
{
|
|
row[6] = decimal.Round(Convert.ToDecimal(unitWork.JDWeights), 2);
|
|
}
|
|
if (unitWork.PlanStartDate != null)
|
|
{
|
|
row[10] = unitWork.PlanStartDate;
|
|
}
|
|
if (unitWork.PlanEndDate != null)
|
|
{
|
|
row[11] = unitWork.PlanEndDate;
|
|
}
|
|
if (unitWork.RealStartDate != null)
|
|
{
|
|
row[12] = unitWork.RealStartDate;
|
|
}
|
|
if (unitWork.RealEndDate != null)
|
|
{
|
|
row[13] = unitWork.RealEndDate;
|
|
}
|
|
if (unitWork.PlanCost != null)
|
|
{
|
|
row[15] = decimal.Round(Convert.ToDecimal(unitWork.PlanCost), 2);
|
|
}
|
|
}
|
|
}
|
|
row[17] = item.Code;
|
|
table.Rows.Add(row);
|
|
}
|
|
}
|
|
return table;
|
|
}
|
|
}
|
|
|
|
private static void AddDetail(List<Model.View_WBS> newList, List<Model.View_WBS> oldList, string id, string preCode, string startTime, string endTime, string isOK)
|
|
{
|
|
if (isOK == "0")
|
|
{
|
|
var items = oldList.Where(x => x.SupId == id && (x.PlanStartDate <= Funs.GetNewDateTime(startTime) || string.IsNullOrEmpty(startTime)) && (x.PlanEndDate >= Funs.GetNewDateTime(endTime) || string.IsNullOrEmpty(endTime))).OrderBy(x => x.WBSCode);
|
|
int b = 1;
|
|
foreach (var item in items)
|
|
{
|
|
item.Code = preCode + "." + b.ToString();
|
|
newList.Add(item);
|
|
AddDetail(newList, oldList, item.Id, item.Code, startTime, endTime, isOK);
|
|
b++;
|
|
}
|
|
}
|
|
else if (isOK == "1")
|
|
{
|
|
var items = oldList.Where(x => x.SupId == id && x.RealEndDate != null && (x.PlanStartDate <= Funs.GetNewDateTime(startTime) || string.IsNullOrEmpty(startTime)) && (x.PlanEndDate >= Funs.GetNewDateTime(endTime) || string.IsNullOrEmpty(endTime))).OrderBy(x => x.WBSCode);
|
|
int b = 1;
|
|
foreach (var item in items)
|
|
{
|
|
item.Code = preCode + "." + b.ToString();
|
|
newList.Add(item);
|
|
AddDetail(newList, oldList, item.Id, item.Code, startTime, endTime, isOK);
|
|
b++;
|
|
}
|
|
}
|
|
else if (isOK == "2")
|
|
{
|
|
var items = oldList.Where(x => x.SupId == id && x.RealEndDate == null && (x.PlanStartDate <= Funs.GetNewDateTime(startTime) || string.IsNullOrEmpty(startTime)) && (x.PlanEndDate >= Funs.GetNewDateTime(endTime) || string.IsNullOrEmpty(endTime))).OrderBy(x => x.WBSCode);
|
|
int b = 1;
|
|
foreach (var item in items)
|
|
{
|
|
item.Code = preCode + "." + b.ToString();
|
|
newList.Add(item);
|
|
AddDetail(newList, oldList, item.Id, item.Code, startTime, endTime, isOK);
|
|
b++;
|
|
}
|
|
}
|
|
}
|
|
|
|
private static void AddDetail(List<Model.View_WBS> newList, List<Model.View_WBS> oldList, string id, string preCode, string prefix, string startTime, string endTime, string isOK)
|
|
{
|
|
if (isOK == "0")
|
|
{
|
|
var items = oldList.Where(x => x.SupId == id && (x.PlanStartDate <= Funs.GetNewDateTime(startTime) || string.IsNullOrEmpty(startTime)) && (x.PlanEndDate >= Funs.GetNewDateTime(endTime) || string.IsNullOrEmpty(endTime))).OrderBy(x => x.WBSCode);
|
|
int b = 1;
|
|
foreach (var item in items)
|
|
{
|
|
item.Code = preCode + "." + b.ToString();
|
|
item.Name = prefix + "...." + item.Name;
|
|
newList.Add(item);
|
|
AddDetail(newList, oldList, item.Id, item.Code, prefix + "....", startTime, endTime, isOK);
|
|
b++;
|
|
}
|
|
}
|
|
else if (isOK == "1")
|
|
{
|
|
var items = oldList.Where(x => x.SupId == id && x.RealEndDate != null && (x.PlanStartDate <= Funs.GetNewDateTime(startTime) || string.IsNullOrEmpty(startTime)) && (x.PlanEndDate >= Funs.GetNewDateTime(endTime) || string.IsNullOrEmpty(endTime))).OrderBy(x => x.WBSCode);
|
|
int b = 1;
|
|
foreach (var item in items)
|
|
{
|
|
item.Code = preCode + "." + b.ToString();
|
|
item.Name = prefix + "...." + item.Name;
|
|
newList.Add(item);
|
|
AddDetail(newList, oldList, item.Id, item.Code, prefix + "....", startTime, endTime, isOK);
|
|
b++;
|
|
}
|
|
}
|
|
else if (isOK == "2")
|
|
{
|
|
var items = oldList.Where(x => x.SupId == id && x.RealEndDate == null && (x.PlanStartDate <= Funs.GetNewDateTime(startTime) || string.IsNullOrEmpty(startTime)) && (x.PlanEndDate >= Funs.GetNewDateTime(endTime) || string.IsNullOrEmpty(endTime))).OrderBy(x => x.WBSCode);
|
|
int b = 1;
|
|
foreach (var item in items)
|
|
{
|
|
item.Code = preCode + "." + b.ToString();
|
|
item.Name = prefix + "...." + item.Name;
|
|
newList.Add(item);
|
|
AddDetail(newList, oldList, item.Id, item.Code, prefix + "....", startTime, endTime, isOK);
|
|
b++;
|
|
}
|
|
}
|
|
}
|
|
|
|
#region 更新工作包、工作项
|
|
/// <summary>
|
|
/// 更新月工作包、工作项
|
|
/// </summary>
|
|
/// <param name="years"></param>
|
|
/// <param name="months"></param>
|
|
/// <param name="planValue"></param>
|
|
/// <param name="parentId"></param>
|
|
public static void UpdateWorkPackages(Model.SGGLDB db, Model.WBS_WorkPackage workPackage, DateTime? planStartDate, DateTime? planEndDate, DateTime? realStartDate, DateTime? realEndDate)
|
|
{
|
|
if (workPackage != null)
|
|
{
|
|
Model.WBS_WorkPackage parentWorkPackage = BLL.WorkPackageService.GetWorkPackageByWorkPackageId(workPackage.SuperWorkPackageId);
|
|
if (parentWorkPackage != null)
|
|
{
|
|
if (planStartDate != null)
|
|
{
|
|
if (parentWorkPackage.PlanStartDate == null)
|
|
{
|
|
parentWorkPackage.PlanStartDate = planStartDate;
|
|
}
|
|
else
|
|
{
|
|
if (parentWorkPackage.PlanStartDate > planStartDate)
|
|
{
|
|
parentWorkPackage.PlanStartDate = planStartDate;
|
|
}
|
|
}
|
|
}
|
|
if (planEndDate != null)
|
|
{
|
|
if (parentWorkPackage.PlanEndDate == null)
|
|
{
|
|
parentWorkPackage.PlanEndDate = planEndDate;
|
|
}
|
|
else
|
|
{
|
|
if (parentWorkPackage.PlanEndDate < planEndDate)
|
|
{
|
|
parentWorkPackage.PlanEndDate = planEndDate;
|
|
}
|
|
}
|
|
}
|
|
if (realStartDate != null)
|
|
{
|
|
if (parentWorkPackage.RealStartDate == null)
|
|
{
|
|
parentWorkPackage.RealStartDate = realStartDate;
|
|
}
|
|
else
|
|
{
|
|
if (parentWorkPackage.RealStartDate > realStartDate)
|
|
{
|
|
parentWorkPackage.RealStartDate = realStartDate;
|
|
}
|
|
}
|
|
}
|
|
if (realEndDate != null)
|
|
{
|
|
if (parentWorkPackage.RealEndDate == null)
|
|
{
|
|
parentWorkPackage.RealEndDate = realEndDate;
|
|
}
|
|
else
|
|
{
|
|
if (parentWorkPackage.RealEndDate < realEndDate)
|
|
{
|
|
parentWorkPackage.RealEndDate = realEndDate;
|
|
}
|
|
}
|
|
}
|
|
UpdateWorkPackages(db, parentWorkPackage, planStartDate, planEndDate, realStartDate, realEndDate);
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// 更新分部分项工程实际完成时间
|
|
/// </summary>
|
|
/// <param name="WorkPackage"></param>
|
|
public static void UpdateWorkPackageRealEndDate(string workPackageId)
|
|
{
|
|
using (var db = new Model.SGGLDB(Funs.ConnString))
|
|
{
|
|
var controlItemAndCycles = from x in db.WBS_ControlItemAndCycle where x.WorkPackageId == workPackageId && x.IsApprove == true select x;
|
|
var spotCheckDetails = from x in db.Check_SpotCheckDetail where x.IsOK == true select x;
|
|
bool b = true;
|
|
if (controlItemAndCycles.Count() > 0)
|
|
{
|
|
foreach (var c in controlItemAndCycles)
|
|
{
|
|
if (c.CheckNum != null && c.CheckNum != 0) //检查次数为0表示一直检查
|
|
{
|
|
var okSpotCheckDetails = spotCheckDetails.Where(x => x.ControlItemAndCycleId == c.ControlItemAndCycleId);
|
|
if (okSpotCheckDetails.Count() != c.CheckNum)
|
|
{
|
|
b = false;
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
b = false;
|
|
break;
|
|
}
|
|
}
|
|
if (b)
|
|
{
|
|
var LastEndControlItemAndCycle = controlItemAndCycles.OrderByDescending(x => x.RealEndDate).FirstOrDefault();
|
|
if (LastEndControlItemAndCycle != null)
|
|
{
|
|
var workPackage = db.WBS_WorkPackage.FirstOrDefault(x => x.WorkPackageId == LastEndControlItemAndCycle.WorkPackageId);
|
|
if (workPackage != null)
|
|
{
|
|
workPackage.RealEndDate = LastEndControlItemAndCycle.RealEndDate;
|
|
UpdateWorkPackages(db, workPackage, null, null, null, workPackage.RealEndDate);
|
|
db.SubmitChanges();
|
|
var unitWork = db.WBS_UnitWork.FirstOrDefault(x => x.UnitWorkId == workPackage.UnitWorkId);
|
|
//获取是否存在其他未完成的分部分项
|
|
var notEndOthenWorkPackage = db.WBS_WorkPackage.FirstOrDefault(x => x.UnitWorkId == unitWork.UnitWorkId && x.IsApprove == true && x.RealEndDate == null);
|
|
if (notEndOthenWorkPackage == null)
|
|
{
|
|
if (workPackage.RealEndDate != null)
|
|
{
|
|
if (unitWork.RealEndDate == null)
|
|
{
|
|
unitWork.RealEndDate = workPackage.RealEndDate;
|
|
}
|
|
else
|
|
{
|
|
if (unitWork.RealEndDate < workPackage.RealEndDate)
|
|
{
|
|
unitWork.RealEndDate = workPackage.RealEndDate;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
db.SubmitChanges();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#region 根据工作包ID获取wbs节点及父节点字符串
|
|
/// <summary>
|
|
/// 根据工作包ID获取wbs节点及父节点字符串
|
|
/// </summary>
|
|
/// <param name="controlItemAndCycleId"></param>
|
|
/// <returns></returns>
|
|
public static string getWorkPageIdsByControlItemAndCycle(string workPackageId, string controlItemAndCycleId)
|
|
{
|
|
string returnValues = string.Empty;
|
|
if (!string.IsNullOrEmpty(controlItemAndCycleId))
|
|
{
|
|
var getControlItemAndCycle = Funs.DB.WBS_ControlItemAndCycle.FirstOrDefault(x => x.ControlItemAndCycleId == controlItemAndCycleId);
|
|
if (getControlItemAndCycle != null)
|
|
{
|
|
workPackageId = getControlItemAndCycle.WorkPackageId;
|
|
}
|
|
}
|
|
var getWorkPackage = Funs.DB.WBS_WorkPackage.FirstOrDefault(x => x.WorkPackageId == workPackageId);
|
|
if (getWorkPackage != null)
|
|
{
|
|
if (!string.IsNullOrEmpty(controlItemAndCycleId))
|
|
{
|
|
returnValues = getSelectIds(getWorkPackage.WorkPackageId, getWorkPackage.WorkPackageId + "[" + getWorkPackage.InitWorkPackageCode + "]$" + controlItemAndCycleId);
|
|
}
|
|
else
|
|
{
|
|
returnValues = getSelectIds(getWorkPackage.WorkPackageId, getWorkPackage.WorkPackageId + "[" + getWorkPackage.InitWorkPackageCode + "]");
|
|
}
|
|
}
|
|
|
|
return returnValues;
|
|
}
|
|
|
|
/// <summary>
|
|
/// id
|
|
/// </summary>
|
|
/// <param name="node"></param>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public static string getSelectIds(string workPageId, string returnValues)
|
|
{
|
|
var getWorkPackage = Funs.DB.WBS_WorkPackage.FirstOrDefault(x => x.WorkPackageId == workPageId);
|
|
if (getWorkPackage != null)
|
|
{
|
|
if (!string.IsNullOrEmpty(getWorkPackage.SuperWorkPackageId))
|
|
{
|
|
var getSupWorkPackage = Funs.DB.WBS_WorkPackage.FirstOrDefault(x => x.WorkPackageId == getWorkPackage.SuperWorkPackageId);
|
|
if (getSupWorkPackage != null)
|
|
{
|
|
returnValues = getWorkPackage.SuperWorkPackageId + "[" + getWorkPackage.InitWorkPackageCode + "]" + "|" + returnValues;
|
|
returnValues = getSelectIds(getWorkPackage.SuperWorkPackageId, returnValues);
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
var getUnitWork = Funs.DB.WBS_UnitWork.FirstOrDefault(x => x.UnitWorkId == getWorkPackage.UnitWorkId);
|
|
if (getUnitWork != null)
|
|
{
|
|
returnValues = ("Type" + getUnitWork.ProjectType ?? "1") + "|" + getUnitWork.UnitWorkId + "|" + returnValues;
|
|
}
|
|
}
|
|
}
|
|
|
|
return returnValues;
|
|
}
|
|
#endregion
|
|
}
|
|
}
|