SGGL_SHJ/SGGL/BLL/PHTGL/ContractCompile/PhtglContracttrackService .cs

1342 lines
82 KiB
C#
Raw Normal View History

2023-08-25 23:55:32 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
2023-10-07 15:27:02 +08:00
using System.Data;
2023-08-25 23:55:32 +08:00
using System.Linq;
using EmitMapper;
using FineUIPro;
using MiniExcelLibs;
using MiniExcelLibs.Attributes;
using Model;
2023-08-31 11:02:23 +08:00
using WIA;
2023-08-25 23:55:32 +08:00
namespace BLL
{
2023-08-31 11:02:23 +08:00
public static class PhtglContractTrackService
2023-08-25 23:55:32 +08:00
{
#region
/// <summary>
/// 记录数
/// </summary>
public static int Count { get; set; }
public static List<PHTGL_ContractTrack> GetPHTGL_ContractTrackByModle(PHTGL_ContractTrack table)
{
var q = from x in Funs.DB.PHTGL_ContractTrack
where
(string.IsNullOrEmpty(table.Id) || x.Id.Contains(table.Id)) &&
(string.IsNullOrEmpty(table.ContractNum) || x.ContractNum.Contains(table.ContractNum)) &&
(string.IsNullOrEmpty(table.MainItemCode) || x.MainItemCode.Contains(table.MainItemCode)) &&
(string.IsNullOrEmpty(table.MainItemName) || x.MainItemName.Contains(table.MainItemName)) &&
(string.IsNullOrEmpty(table.MajorName) || x.MajorName.Contains(table.MajorName)) &&
(string.IsNullOrEmpty(table.MajorCode) || x.MajorCode.Contains(table.MajorCode)) &&
(string.IsNullOrEmpty(table.SubProject) || x.SubProject.Contains(table.SubProject)) &&
(string.IsNullOrEmpty(table.SubItemProject) ||
x.SubItemProject.Contains(table.SubItemProject)) &&
(string.IsNullOrEmpty(table.ProjectCode) || x.ProjectCode.Contains(table.ProjectCode)) &&
(string.IsNullOrEmpty(table.ProjectName) || x.ProjectName.Contains(table.ProjectName)) &&
(string.IsNullOrEmpty(table.ProjectDescription) ||
x.ProjectDescription.Contains(table.ProjectDescription)) &&
(string.IsNullOrEmpty(table.UnitOfMeasurement) ||
x.UnitOfMeasurement.Contains(table.UnitOfMeasurement)) &&
(string.IsNullOrEmpty(table.Quantity) || x.Quantity.Contains(table.Quantity)) &&
(string.IsNullOrEmpty(table.TotalCostFixedComprehensiveUnitPrice) ||
x.TotalCostFixedComprehensiveUnitPrice.Contains(table.TotalCostFixedComprehensiveUnitPrice)) &&
(string.IsNullOrEmpty(table.MainMaterialCost) ||
x.MainMaterialCost.Contains(table.MainMaterialCost)) &&
(string.IsNullOrEmpty(table.TotalPrice) || x.TotalPrice.Contains(table.TotalPrice)) &&
(string.IsNullOrEmpty(table.CalculationRule) ||
x.CalculationRule.Contains(table.CalculationRule)) &&
(string.IsNullOrEmpty(table.WorkContent) || x.WorkContent.Contains(table.WorkContent)) &&
(string.IsNullOrEmpty(table.Remarks) || x.Remarks.Contains(table.Remarks)) &&
(string.IsNullOrEmpty(table.ConstructionSubcontractor) ||
x.ConstructionSubcontractor.Contains(table.ConstructionSubcontractor)) &&
(string.IsNullOrEmpty(table.ContractWeight) ||
x.ContractWeight.Contains(table.ContractWeight)) &&
(string.IsNullOrEmpty(table.MaterialSupplier) ||
x.MaterialSupplier.Contains(table.MaterialSupplier)) &&
(string.IsNullOrEmpty(table.EstimatedQuantity) ||
x.EstimatedQuantity.Contains(table.EstimatedQuantity)) &&
(string.IsNullOrEmpty(table.SettledQuantity) ||
x.SettledQuantity.Contains(table.SettledQuantity)) &&
(string.IsNullOrEmpty(table.ContractId) ||
2023-10-25 23:30:52 +08:00
table.ContractId.Split(',').Contains(x.ContractId))&&
(string.IsNullOrEmpty(table.ProjectId) ||
x.ProjectId.Contains(table.ProjectId))
2023-10-25 09:16:31 +08:00
2023-08-25 23:55:32 +08:00
select x
;
2023-10-24 17:25:06 +08:00
var model = q.ToList().OrderBy(x => x.SerialNumber, new CustomComparer()).ToList();
2023-10-25 09:16:31 +08:00
return model;
2023-08-25 23:55:32 +08:00
}
/// <summary>
/// 获取分页列表
/// </summary>
/// <param name="table"></param>
/// <param name="grid1"></param>
/// <returns></returns>
public static IEnumerable GetListData(PHTGL_ContractTrack table, Grid grid1)
{
var q = GetPHTGL_ContractTrackByModle(table);
Count = q.Count();
if (Count == 0) return null;
q = q.Skip(grid1.PageSize * grid1.PageIndex).Take(grid1.PageSize).ToList();
// q = SortConditionHelper.SortingAndPaging(q, Grid1.SortField, Grid1.SortDirection, Grid1.PageIndex, Grid1.PageSize);
return from x in q
2023-10-07 15:27:02 +08:00
select new
{
x.Id,
x.ContractNum,
x.MainItemCode,
x.MainItemName,
x.MajorName,
x.MajorCode,
x.SubProject,
x.SubItemProject,
x.ProjectCode,
x.ProjectName,
x.ProjectDescription,
x.UnitOfMeasurement,
x.Quantity,
x.TotalCostFixedComprehensiveUnitPrice,
x.MainMaterialCost,
x.TotalPrice,
x.CalculationRule,
x.WorkContent,
x.Remarks,
x.ConstructionSubcontractor,
x.ContractWeight,
x.MaterialSupplier,
x.IsWithinGeneralContractScope,
x.EstimatedQuantity,
x.EstimatedAmount,
x.SettledQuantity,
x.SettledAmount,
x.ContractId
};
2023-08-25 23:55:32 +08:00
}
#endregion
public static PHTGL_ContractTrack GetPHTGL_ContractTrackById(string id)
{
return Funs.DB.PHTGL_ContractTrack.FirstOrDefault(x => x.Id == id);
}
public static void AddPHTGL_ContractTrack(PHTGL_ContractTrack newtable)
{
var table = new PHTGL_ContractTrack
{
Id = newtable.Id,
ContractNum = newtable.ContractNum,
MainItemCode = newtable.MainItemCode,
MainItemName = newtable.MainItemName,
MajorName = newtable.MajorName,
MajorCode = newtable.MajorCode,
SubProject = newtable.SubProject,
SubItemProject = newtable.SubItemProject,
ProjectCode = newtable.ProjectCode,
ProjectName = newtable.ProjectName,
ProjectDescription = newtable.ProjectDescription,
UnitOfMeasurement = newtable.UnitOfMeasurement,
Quantity = newtable.Quantity,
TotalCostFixedComprehensiveUnitPrice = newtable.TotalCostFixedComprehensiveUnitPrice,
MainMaterialCost = newtable.MainMaterialCost,
TotalPrice = newtable.TotalPrice,
CalculationRule = newtable.CalculationRule,
WorkContent = newtable.WorkContent,
Remarks = newtable.Remarks,
ConstructionSubcontractor = newtable.ConstructionSubcontractor,
ContractWeight = newtable.ContractWeight,
MaterialSupplier = newtable.MaterialSupplier,
IsWithinGeneralContractScope = newtable.IsWithinGeneralContractScope,
EstimatedQuantity = newtable.EstimatedQuantity,
EstimatedAmount = newtable.EstimatedAmount,
SettledQuantity = newtable.SettledQuantity,
SettledAmount = newtable.SettledAmount,
ContractId = newtable.ContractId,
ProjectId = newtable.ProjectId,
2023-10-24 17:25:06 +08:00
SerialNumber = newtable.SerialNumber
2023-08-25 23:55:32 +08:00
};
Funs.DB.PHTGL_ContractTrack.InsertOnSubmit(table);
Funs.DB.SubmitChanges();
2023-08-31 11:02:23 +08:00
PhtglContracttrackprogressService.CreateTemplateByContractTrackId(newtable.Id);
2023-08-25 23:55:32 +08:00
}
public static void UpdatePHTGL_ContractTrack(PHTGL_ContractTrack newtable)
{
var table = Funs.DB.PHTGL_ContractTrack.FirstOrDefault(x => x.Id == newtable.Id);
if (table != null)
{
table.Id = newtable.Id;
table.ContractNum = newtable.ContractNum;
table.MainItemCode = newtable.MainItemCode;
table.MainItemName = newtable.MainItemName;
table.MajorName = newtable.MajorName;
table.MajorCode = newtable.MajorCode;
table.SubProject = newtable.SubProject;
table.SubItemProject = newtable.SubItemProject;
table.ProjectCode = newtable.ProjectCode;
table.ProjectName = newtable.ProjectName;
table.ProjectDescription = newtable.ProjectDescription;
table.UnitOfMeasurement = newtable.UnitOfMeasurement;
table.Quantity = newtable.Quantity;
table.TotalCostFixedComprehensiveUnitPrice = newtable.TotalCostFixedComprehensiveUnitPrice;
table.MainMaterialCost = newtable.MainMaterialCost;
table.TotalPrice = newtable.TotalPrice;
table.CalculationRule = newtable.CalculationRule;
table.WorkContent = newtable.WorkContent;
table.Remarks = newtable.Remarks;
table.ConstructionSubcontractor = newtable.ConstructionSubcontractor;
table.ContractWeight = newtable.ContractWeight;
table.MaterialSupplier = newtable.MaterialSupplier;
table.IsWithinGeneralContractScope = newtable.IsWithinGeneralContractScope;
table.EstimatedQuantity = newtable.EstimatedQuantity;
table.EstimatedAmount = newtable.EstimatedAmount;
table.SettledQuantity = newtable.SettledQuantity;
table.SettledAmount = newtable.SettledAmount;
2023-10-07 15:27:02 +08:00
table.ContractId = newtable.ContractId;
table.ProjectId = newtable.ProjectId;
2023-10-25 09:16:31 +08:00
table.SerialNumber = newtable.SerialNumber;
2023-08-25 23:55:32 +08:00
Funs.DB.SubmitChanges();
}
}
public static void DeletePHTGL_ContractTrackById(string id)
{
2023-10-24 17:25:06 +08:00
PhtglContracttrackprogressService.DeleteModleByContractTrackId(id);
PhtglContracttrackmatchwbsService.DeleteModelByContractTrackId(id);
ConstructionLogWorkEfficiencyService.DeleteConstructionLogWorkEfficiencysByContractTrackId(id);
2023-08-25 23:55:32 +08:00
var table = Funs.DB.PHTGL_ContractTrack.FirstOrDefault(x => x.Id == id);
if (table != null)
{
Funs.DB.PHTGL_ContractTrack.DeleteOnSubmit(table);
Funs.DB.SubmitChanges();
}
2023-10-25 09:16:31 +08:00
2023-08-25 23:55:32 +08:00
}
2023-10-24 14:23:46 +08:00
/// <summary>
/// 重新校验合同权重
/// </summary>
/// <param name="contractid"></param>
/// <param name="projectid"></param>
2023-10-24 17:29:27 +08:00
public static void CheckContractWeightByContractId(string contractid, string projectid)
2023-10-24 14:23:46 +08:00
{
Model.PHTGL_ContractTrack table = new Model.PHTGL_ContractTrack();
table.ProjectId = projectid;
table.ContractId = contractid;
2023-10-24 17:29:27 +08:00
var list = GetPHTGL_ContractTrackByModle(table);
2023-10-24 14:23:46 +08:00
foreach (var item in list)
{
2023-10-24 17:29:27 +08:00
item.ContractWeight = GetContractWeightById(item.Id);
2023-10-24 14:23:46 +08:00
UpdatePHTGL_ContractTrack(item);
2023-10-24 17:29:27 +08:00
2023-10-24 14:23:46 +08:00
}
}
/// <summary>
/// 获取清单的合同权重
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
2023-10-24 17:29:27 +08:00
public static string GetContractWeightById(string id)
2023-10-24 14:23:46 +08:00
{
string ContractWeight = "0";
var model = GetPHTGL_ContractTrackById(id);
if (model != null)
{
if (GetSumSettledAmountByContractId(model.ContractId, model.ProjectId) == 0) return ContractWeight;
var result =
(model.SettledAmount / GetSumSettledAmountByContractId(model.ContractId, model.ProjectId)) * 100;
ContractWeight = string.Format("{0:F}", result);
}
return ContractWeight;
}
/// <summary>
/// 根据合同id 获取合同预算金额
/// </summary>
public static decimal GetSumSettledAmountByContractId(string contractid, string projectid)
{
2023-10-24 17:29:27 +08:00
decimal SumSettledAmount = 0;
2023-10-24 14:23:46 +08:00
SumSettledAmount =
(from x in Funs.DB.PHTGL_ContractTrack
2023-10-24 17:29:27 +08:00
where x.ProjectId == projectid && x.ContractId == contractid
select x.SettledAmount ?? 0).ToList().Sum();
2023-10-24 14:23:46 +08:00
return SumSettledAmount;
}
2023-10-25 23:30:52 +08:00
/// <summary>
/// 根据主键获取工程量偏差
/// </summary>
/// <returns></returns>
public static decimal GetQuantityOffset(object id)
{
decimal result = 0;
var model = GetPHTGL_ContractTrackById(id.ToString());
if (model != null)
{
result = Funs.GetNewDecimalOrZero(model.EstimatedQuantity) -
Funs.GetNewDecimalOrZero(model.SettledQuantity);
}
return result;
}
/// <summary>
/// 根据主键获取费用偏差
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public static decimal GetAmountOffset(object id)
{
decimal result = 0;
var model = GetPHTGL_ContractTrackById(id.ToString());
if (model != null)
{
result =(model.EstimatedAmount??0 )- ( model.SettledAmount??0);
}
return result;
}
2023-08-25 23:55:32 +08:00
public static ResponeData ImportData(string path, string contractid, string projectid)
{
var responeData = new ResponeData();
List<PHTGL_ContractTrackDtoIn> rows;
try
{
rows = MiniExcel.Query<PHTGL_ContractTrackDtoIn>(path).ToList();
}
catch (Exception e)
{
responeData.code = 0;
responeData.message = "模板错误";
return responeData;
}
var mapper =
ObjectMapperManager.DefaultInstance.GetMapper<List<PHTGL_ContractTrackDtoIn>, List<PHTGL_ContractTrack>>();
var modeList = mapper.Map(rows);
if (modeList.Count == 0)
{
responeData.code = 0;
responeData.message = "没有数据";
return responeData;
}
foreach (var item in modeList)
{
item.ContractId = contractid;
item.ProjectId = projectid;
2023-10-24 17:25:06 +08:00
if (string.IsNullOrEmpty(item.ProjectCode)) continue;
2023-08-25 23:55:32 +08:00
var phtglContractTrack = new PHTGL_ContractTrack
{
2023-10-25 09:16:31 +08:00
MainItemCode = item.MainItemCode,
2023-08-25 23:55:32 +08:00
ProjectCode = item.ProjectCode,
ContractId = contractid,
ProjectId = projectid,
};
var resultModel = GetPHTGL_ContractTrackByModle(phtglContractTrack);
2023-10-07 15:27:02 +08:00
item.ContractNum = ContractService.GetContractById(contractid)?.ContractNum;
2023-10-24 17:29:27 +08:00
if (!string.IsNullOrEmpty(item.ProjectCode) && !item.ProjectCode.Contains("-"))
2023-10-24 14:23:46 +08:00
{
item.ProjectCode = item.MainItemCode + "-" + item.ProjectCode;
}
2023-08-25 23:55:32 +08:00
if (resultModel.Any())
{
item.Id = resultModel[0].Id;
UpdatePHTGL_ContractTrack(item);
}
else
{
item.Id = SQLHelper.GetNewID();
AddPHTGL_ContractTrack(item);
}
2023-08-31 11:02:23 +08:00
PhtglContracttrackprogressService.CreateTemplateByContractTrackId(item.Id);
2023-08-25 23:55:32 +08:00
}
return responeData;
}
2023-10-07 15:27:02 +08:00
/// <summary>
/// 获取模拟树表格
/// </summary>
/// <returns></returns>
public static DataTable GetAllTreeDataTable(string projectId, string IsOut, List<string> contractNoList, List<string> professionalList, List<string> workPostIds, List<string> machineIds, string constructionLogId)
{
using (var db = new Model.SGGLDB(Funs.ConnString))
{
2023-10-24 17:29:27 +08:00
var pros = BLL.PHTGL_QuantityService.GetMajorItems2();
2023-10-07 15:27:02 +08:00
List<string> proNames = new List<string>();
foreach (var item in professionalList)
{
var pro = pros.FirstOrDefault(x => x.Text == item);
if (pro != null)
{
proNames.Add(pro.Value);
}
}
IQueryable<Model.PHTGL_ContractTrack> getContractTracks = from x in db.PHTGL_ContractTrack
where x.ProjectId == projectId && contractNoList.Contains(x.ContractId) && proNames.Contains(x.MajorName)
orderby x.ProjectCode, x.ProjectName
select x;
IQueryable<Model.ZHGL_ConstructionLogWorkEfficiency> workEfficiencys = from x in db.ZHGL_ConstructionLogWorkEfficiency
where x.ConstructionLogId == constructionLogId
select x;
var unitWorks = (from x in getContractTracks
2023-10-24 17:29:27 +08:00
select new { MainItemCode = x.MainItemCode, MainItemName = x.MainItemName }).Distinct().OrderBy(x => x.MainItemCode).ToList();
2023-10-07 15:27:02 +08:00
DataTable table = new DataTable();
table.Columns.Add(new DataColumn("Id", typeof(String)));
table.Columns.Add(new DataColumn("Code", typeof(String)));
2023-10-24 17:29:27 +08:00
table.Columns.Add(new DataColumn("MainItemCode", typeof(String)));
table.Columns.Add(new DataColumn("MainItemName", typeof(String)));
table.Columns.Add(new DataColumn("MajorCode", typeof(String)));
table.Columns.Add(new DataColumn("MajorName", typeof(String)));
2023-10-07 15:27:02 +08:00
table.Columns.Add(new DataColumn("ProjectCode", typeof(String)));
table.Columns.Add(new DataColumn("ProjectName", typeof(String)));
table.Columns.Add(new DataColumn("UnitOfMeasurement", typeof(String)));
table.Columns.Add(new DataColumn("PhysicalCompletionQuantity", typeof(String)));
table.Columns.Add(new DataColumn("MaterialConsumption", typeof(String)));
table.Columns.Add(new DataColumn("ShowId", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours0", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency0", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours1", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency1", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours2", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency2", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours3", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency3", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours4", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency4", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours5", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency5", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours6", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency6", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours7", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency7", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours8", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency8", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours9", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency9", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours10", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency10", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours11", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency11", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours12", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency12", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours13", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency13", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours14", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency14", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours15", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency15", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours16", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency16", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours17", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency17", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours18", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency18", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours19", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency19", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours0", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency0", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours1", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency1", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours2", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency2", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours3", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency3", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours4", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency4", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours5", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency5", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours6", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency6", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours7", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency7", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours8", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency8", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours9", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency9", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours10", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency10", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours11", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency11", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours12", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency12", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours13", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency13", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours14", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency14", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours15", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency15", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours16", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency16", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours17", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency17", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours18", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency18", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours19", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency19", typeof(String)));
DataRow row;
int a = 1;
foreach (var unitWork in unitWorks)
{
row = table.NewRow();
row[0] = unitWork.MainItemCode;
row[1] = a;
2023-10-24 17:29:27 +08:00
row[2] = unitWork.MainItemCode;
2023-10-07 15:27:02 +08:00
row[3] = unitWork.MainItemName;
table.Rows.Add(row);
int b = 1;
foreach (var proName in proNames)
{
row = table.NewRow();
row[0] = unitWork.MainItemCode + b.ToString();
row[1] = a + "." + b;
row[2] = string.Empty;
2023-10-24 17:29:27 +08:00
row[3] = string.Empty;
var pro = pros.FirstOrDefault(x => x.Value == proName);
if (pro != null)
{
row[4] = pro.Text;
}
row[5] = proName;
2023-10-07 15:27:02 +08:00
table.Rows.Add(row);
2023-10-24 17:29:27 +08:00
var subProjects = (from x in getContractTracks
where x.MainItemCode == unitWork.MainItemCode && x.MajorName == proName && x.SubProject != null
select x.SubProject).Distinct().ToList();
if (subProjects.Count == 0) //未填分部工程
2023-10-07 15:27:02 +08:00
{
2023-10-24 17:29:27 +08:00
int c = 1;
2023-10-25 09:16:31 +08:00
var contractTracks = getContractTracks.Where(x => x.MainItemCode == unitWork.MainItemCode && x.MajorName == proName).OrderBy(x => x.SerialNumber);
2023-10-24 17:29:27 +08:00
foreach (Model.PHTGL_ContractTrack item in contractTracks)
2023-10-07 15:27:02 +08:00
{
2023-10-24 17:29:27 +08:00
row = table.NewRow();
row[0] = item.Id;
row[1] = a + "." + b + "." + c;
row[6] = item.ProjectCode;
row[7] = item.ProjectName;
row[8] = item.UnitOfMeasurement;
row[11] = item.Id;
if (workEfficiencys.Count() > 0)
2023-10-07 15:27:02 +08:00
{
2023-10-24 17:29:27 +08:00
var we = workEfficiencys.FirstOrDefault(x => x.ContractTrackId == item.Id);
if (we != null)
2023-10-07 15:27:02 +08:00
{
2023-10-24 17:29:27 +08:00
row[9] = we.PhysicalCompletionQuantity;
row[10] = we.MaterialConsumption;
}
for (int i = 0; i < workPostIds.Count; i++)
{
var workEfficiency = workEfficiencys.FirstOrDefault(x => x.Type == "Person" && x.TypeId == workPostIds[i] && x.ContractTrackId == item.Id);
if (workEfficiency != null)
2023-10-07 15:27:02 +08:00
{
2023-10-24 17:29:27 +08:00
if (workEfficiency.ConsumeHours != null)
{
row[12 + i * 2] = decimal.Round(Convert.ToDecimal(workEfficiency.ConsumeHours), 2);
if (we.PhysicalCompletionQuantity != null && we.PhysicalCompletionQuantity > 0)
{
row[13 + i * 2] = decimal.Round(Convert.ToDecimal(we.PhysicalCompletionQuantity / workEfficiency.ConsumeHours), 2);
}
}
}
}
for (int i = 0; i < machineIds.Count; i++)
{
var workEfficiency = workEfficiencys.FirstOrDefault(x => x.Type == "Machine" && x.TypeId == machineIds[i] && x.ContractTrackId == item.Id);
if (workEfficiency != null)
{
if (workEfficiency.ConsumeHours != null)
2023-10-07 15:27:02 +08:00
{
2023-10-24 17:29:27 +08:00
row[52 + i * 2] = decimal.Round(Convert.ToDecimal(workEfficiency.ConsumeHours), 2);
if (we.PhysicalCompletionQuantity != null && we.PhysicalCompletionQuantity > 0)
{
row[53 + i * 2] = decimal.Round(Convert.ToDecimal(we.PhysicalCompletionQuantity / workEfficiency.ConsumeHours), 2);
}
2023-10-07 15:27:02 +08:00
}
}
}
}
2023-10-24 17:29:27 +08:00
table.Rows.Add(row);
c++;
}
}
else //存在分部工程
{
int c = 1;
foreach (var subProject in subProjects)
{
row = table.NewRow();
row[0] = unitWork.MainItemCode + b.ToString() + c.ToString();
row[1] = a + "." + b + "." + c;
row[7] = subProject;
table.Rows.Add(row);
int d = 1;
2023-10-25 09:16:31 +08:00
var contractTracks = getContractTracks.Where(x => x.MainItemCode == unitWork.MainItemCode && x.MajorName == proName && x.SubProject == subProject).OrderBy(x => x.SerialNumber);
2023-10-24 17:29:27 +08:00
foreach (Model.PHTGL_ContractTrack item in contractTracks)
2023-10-07 15:27:02 +08:00
{
2023-10-24 17:29:27 +08:00
row = table.NewRow();
row[0] = item.Id;
row[1] = a + "." + b + "." + c + "." + d;
row[6] = item.ProjectCode;
row[7] = item.ProjectName;
row[8] = item.UnitOfMeasurement;
row[11] = item.Id;
if (workEfficiencys.Count() > 0)
2023-10-07 15:27:02 +08:00
{
2023-10-24 17:29:27 +08:00
var we = workEfficiencys.FirstOrDefault(x => x.ContractTrackId == item.Id);
if (we != null)
2023-10-07 15:27:02 +08:00
{
2023-10-24 17:29:27 +08:00
row[9] = we.PhysicalCompletionQuantity;
row[10] = we.MaterialConsumption;
}
for (int i = 0; i < workPostIds.Count; i++)
{
var workEfficiency = workEfficiencys.FirstOrDefault(x => x.Type == "Person" && x.TypeId == workPostIds[i] && x.ContractTrackId == item.Id);
if (workEfficiency != null)
2023-10-07 15:27:02 +08:00
{
2023-10-24 17:29:27 +08:00
if (workEfficiency.ConsumeHours != null)
{
row[12 + i * 2] = decimal.Round(Convert.ToDecimal(workEfficiency.ConsumeHours), 2);
if (we.PhysicalCompletionQuantity != null && we.PhysicalCompletionQuantity > 0)
{
row[13 + i * 2] = decimal.Round(Convert.ToDecimal(we.PhysicalCompletionQuantity / workEfficiency.ConsumeHours), 2);
}
}
}
}
for (int i = 0; i < machineIds.Count; i++)
{
var workEfficiency = workEfficiencys.FirstOrDefault(x => x.Type == "Machine" && x.TypeId == machineIds[i] && x.ContractTrackId == item.Id);
if (workEfficiency != null)
{
if (workEfficiency.ConsumeHours != null)
{
row[52 + i * 2] = decimal.Round(Convert.ToDecimal(workEfficiency.ConsumeHours), 2);
if (we.PhysicalCompletionQuantity != null && we.PhysicalCompletionQuantity > 0)
{
row[53 + i * 2] = decimal.Round(Convert.ToDecimal(we.PhysicalCompletionQuantity / workEfficiency.ConsumeHours), 2);
}
}
2023-10-07 15:27:02 +08:00
}
}
}
2023-10-24 17:29:27 +08:00
table.Rows.Add(row);
d++;
2023-10-07 15:27:02 +08:00
}
2023-10-24 17:29:27 +08:00
c++;
2023-10-07 15:27:02 +08:00
}
}
b++;
}
a++;
}
return table;
}
}
2023-10-11 10:19:12 +08:00
/// <summary>
/// 获取模拟树表格
/// </summary>
/// <returns></returns>
public static DataTable GetProjectAllTreeDataTable(string projectId, string IsOut, List<string> contractNoList, List<string> professionalList, List<string> workPostIds, List<string> machineIds, string compileDate)
{
using (var db = new Model.SGGLDB(Funs.ConnString))
{
2023-10-24 17:29:27 +08:00
var pros = BLL.PHTGL_QuantityService.GetMajorItems2();
2023-10-11 10:19:12 +08:00
List<string> proNames = new List<string>();
foreach (var item in professionalList)
{
var pro = pros.FirstOrDefault(x => x.Text == item);
if (pro != null)
{
proNames.Add(pro.Value);
}
}
2023-10-18 09:40:57 +08:00
proNames = proNames.Distinct().ToList();
2023-10-11 10:19:12 +08:00
IQueryable<Model.PHTGL_ContractTrack> getContractTracks = from x in db.PHTGL_ContractTrack
where x.ProjectId == projectId && contractNoList.Contains(x.ContractId) && proNames.Contains(x.MajorName)
orderby x.ProjectCode, x.ProjectName
select x;
DateTime date = Funs.GetNewDateTimeOrNow(compileDate);
var personLogIds = (from x in db.ZHGL_ConstructionLog
where x.ProjectId == projectId && x.CompileDate == date
orderby x.CompileDate descending
select x.ConstructionLogId).ToList();
IQueryable<Model.ZHGL_ConstructionLogWorkEfficiency> workEfficiencys = from x in db.ZHGL_ConstructionLogWorkEfficiency
where personLogIds.Contains(x.ConstructionLogId)
select x;
var unitWorks = (from x in getContractTracks
2023-10-25 09:16:31 +08:00
select new { MainItemCode = x.MainItemCode, MainItemName = x.MainItemName }).Distinct().OrderBy(x => x.MainItemCode).ToList();
2023-10-11 10:19:12 +08:00
DataTable table = new DataTable();
table.Columns.Add(new DataColumn("Id", typeof(String)));
table.Columns.Add(new DataColumn("Code", typeof(String)));
2023-10-25 09:16:31 +08:00
table.Columns.Add(new DataColumn("MainItemCode", typeof(String)));
table.Columns.Add(new DataColumn("MainItemName", typeof(String)));
table.Columns.Add(new DataColumn("MajorCode", typeof(String)));
table.Columns.Add(new DataColumn("MajorName", typeof(String)));
2023-10-11 10:19:12 +08:00
table.Columns.Add(new DataColumn("ProjectCode", typeof(String)));
table.Columns.Add(new DataColumn("ProjectName", typeof(String)));
table.Columns.Add(new DataColumn("UnitOfMeasurement", typeof(String)));
table.Columns.Add(new DataColumn("PhysicalCompletionQuantity", typeof(String)));
table.Columns.Add(new DataColumn("MaterialConsumption", typeof(String)));
table.Columns.Add(new DataColumn("ShowId", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours0", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency0", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours1", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency1", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours2", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency2", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours3", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency3", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours4", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency4", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours5", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency5", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours6", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency6", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours7", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency7", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours8", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency8", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours9", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency9", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours10", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency10", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours11", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency11", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours12", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency12", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours13", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency13", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours14", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency14", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours15", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency15", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours16", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency16", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours17", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency17", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours18", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency18", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours19", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency19", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours0", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency0", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours1", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency1", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours2", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency2", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours3", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency3", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours4", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency4", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours5", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency5", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours6", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency6", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours7", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency7", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours8", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency8", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours9", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency9", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours10", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency10", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours11", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency11", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours12", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency12", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours13", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency13", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours14", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency14", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours15", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency15", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours16", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency16", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours17", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency17", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours18", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency18", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours19", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency19", typeof(String)));
DataRow row;
int a = 1;
foreach (var unitWork in unitWorks)
{
row = table.NewRow();
row[0] = unitWork.MainItemCode;
row[1] = a;
2023-10-25 09:16:31 +08:00
row[2] = unitWork.MainItemCode;
2023-10-11 10:19:12 +08:00
row[3] = unitWork.MainItemName;
table.Rows.Add(row);
int b = 1;
foreach (var proName in proNames)
{
row = table.NewRow();
row[0] = unitWork.MainItemCode + b.ToString();
row[1] = a + "." + b;
row[2] = string.Empty;
2023-10-25 09:16:31 +08:00
row[3] = string.Empty;
var pro = pros.FirstOrDefault(x => x.Value == proName);
if (pro != null)
{
row[4] = pro.Text;
}
row[5] = proName;
2023-10-11 10:19:12 +08:00
table.Rows.Add(row);
2023-10-25 09:16:31 +08:00
var subProjects = (from x in getContractTracks
where x.MainItemCode == unitWork.MainItemCode && x.MajorName == proName && x.SubProject != null
select x.SubProject).Distinct().ToList();
if (subProjects.Count == 0) //未填分部工程
2023-10-11 10:19:12 +08:00
{
2023-10-25 09:16:31 +08:00
int c = 1;
var contractTracks = getContractTracks.Where(x => x.MainItemCode == unitWork.MainItemCode && x.MajorName == proName).OrderBy(x => x.SerialNumber);
foreach (Model.PHTGL_ContractTrack item in contractTracks)
2023-10-11 10:19:12 +08:00
{
2023-10-25 09:16:31 +08:00
row = table.NewRow();
row[0] = item.Id;
row[1] = a + "." + b + "." + c;
row[6] = item.ProjectCode;
row[7] = item.ProjectName;
row[8] = item.UnitOfMeasurement;
row[11] = item.Id;
if (workEfficiencys.Count() > 0)
2023-10-11 10:19:12 +08:00
{
2023-10-25 09:16:31 +08:00
var we = workEfficiencys.FirstOrDefault(x => x.ContractTrackId == item.Id);
if (we != null)
{
row[9] = we.PhysicalCompletionQuantity;
row[10] = we.MaterialConsumption;
}
for (int i = 0; i < workPostIds.Count; i++)
2023-10-11 10:19:12 +08:00
{
2023-10-25 09:16:31 +08:00
var workEfficiencyList = workEfficiencys.Where(x => x.Type == "Person" && x.TypeId == workPostIds[i] && x.ContractTrackId == item.Id);
if (workEfficiencyList.Count() > 0)
2023-10-11 10:19:12 +08:00
{
2023-10-25 09:16:31 +08:00
decimal d = 0;
foreach (var workEfficiency in workEfficiencyList)
2023-10-11 10:19:12 +08:00
{
2023-10-25 09:16:31 +08:00
if (workEfficiency.ConsumeHours != null)
{
d += decimal.Round(Convert.ToDecimal(workEfficiency.ConsumeHours), 2);
}
}
if (d > 0)
{
row[12 + i * 2] = decimal.Round(d, 2);
if (we.PhysicalCompletionQuantity != null && we.PhysicalCompletionQuantity > 0)
{
row[13 + i * 2] = decimal.Round(Convert.ToDecimal(we.PhysicalCompletionQuantity / d), 2);
}
2023-10-11 10:19:12 +08:00
}
}
2023-10-25 09:16:31 +08:00
}
for (int i = 0; i < machineIds.Count; i++)
{
var workEfficiencyList = workEfficiencys.Where(x => x.Type == "Machine" && x.TypeId == machineIds[i] && x.ContractTrackId == item.Id);
if (workEfficiencyList.Count() > 0)
2023-10-11 10:19:12 +08:00
{
2023-10-25 09:16:31 +08:00
decimal d = 0;
foreach (var workEfficiency in workEfficiencyList)
{
if (workEfficiency.ConsumeHours != null)
{
d += decimal.Round(Convert.ToDecimal(workEfficiency.ConsumeHours), 2);
}
}
if (d > 0)
2023-10-11 10:19:12 +08:00
{
2023-10-25 09:16:31 +08:00
row[52 + i * 2] = decimal.Round(d, 2);
if (we.PhysicalCompletionQuantity != null && we.PhysicalCompletionQuantity > 0)
{
row[53 + i * 2] = decimal.Round(Convert.ToDecimal(we.PhysicalCompletionQuantity / d), 2);
}
2023-10-11 10:19:12 +08:00
}
}
}
}
2023-10-25 09:16:31 +08:00
table.Rows.Add(row);
c++;
}
}
else //存在分部工程
{
int c = 1;
foreach (var subProject in subProjects)
{
row = table.NewRow();
row[0] = unitWork.MainItemCode + b.ToString() + c.ToString();
row[1] = a + "." + b + "." + c;
row[7] = subProject;
table.Rows.Add(row);
int f = 1;
var contractTracks = getContractTracks.Where(x => x.MainItemCode == unitWork.MainItemCode && x.MajorName == proName && x.SubProject == subProject).OrderBy(x => x.SerialNumber);
foreach (Model.PHTGL_ContractTrack item in contractTracks)
2023-10-11 10:19:12 +08:00
{
2023-10-25 09:16:31 +08:00
row = table.NewRow();
row[0] = item.Id;
row[1] = a + "." + b + "." + c + "." + f;
row[6] = item.ProjectCode;
row[7] = item.ProjectName;
row[8] = item.UnitOfMeasurement;
row[11] = item.Id;
if (workEfficiencys.Count() > 0)
2023-10-11 10:19:12 +08:00
{
2023-10-25 09:16:31 +08:00
var we = workEfficiencys.FirstOrDefault(x => x.ContractTrackId == item.Id);
if (we != null)
2023-10-11 10:19:12 +08:00
{
2023-10-25 09:16:31 +08:00
row[9] = we.PhysicalCompletionQuantity;
row[10] = we.MaterialConsumption;
}
for (int i = 0; i < workPostIds.Count; i++)
{
var workEfficiencyList = workEfficiencys.Where(x => x.Type == "Person" && x.TypeId == workPostIds[i] && x.ContractTrackId == item.Id);
if (workEfficiencyList.Count() > 0)
2023-10-11 10:19:12 +08:00
{
2023-10-25 09:16:31 +08:00
decimal d = 0;
foreach (var workEfficiency in workEfficiencyList)
{
if (workEfficiency.ConsumeHours != null)
{
d += decimal.Round(Convert.ToDecimal(workEfficiency.ConsumeHours), 2);
}
}
if (d > 0)
{
row[12 + i * 2] = decimal.Round(d, 2);
if (we.PhysicalCompletionQuantity != null && we.PhysicalCompletionQuantity > 0)
{
row[13 + i * 2] = decimal.Round(Convert.ToDecimal(we.PhysicalCompletionQuantity / d), 2);
}
}
2023-10-11 10:19:12 +08:00
}
}
2023-10-25 09:16:31 +08:00
for (int i = 0; i < machineIds.Count; i++)
2023-10-11 10:19:12 +08:00
{
2023-10-25 09:16:31 +08:00
var workEfficiencyList = workEfficiencys.Where(x => x.Type == "Machine" && x.TypeId == machineIds[i] && x.ContractTrackId == item.Id);
if (workEfficiencyList.Count() > 0)
2023-10-11 10:19:12 +08:00
{
2023-10-25 09:16:31 +08:00
decimal d = 0;
foreach (var workEfficiency in workEfficiencyList)
{
if (workEfficiency.ConsumeHours != null)
{
d += decimal.Round(Convert.ToDecimal(workEfficiency.ConsumeHours), 2);
}
}
if (d > 0)
{
row[52 + i * 2] = decimal.Round(d, 2);
if (we.PhysicalCompletionQuantity != null && we.PhysicalCompletionQuantity > 0)
{
row[53 + i * 2] = decimal.Round(Convert.ToDecimal(we.PhysicalCompletionQuantity / d), 2);
}
}
2023-10-11 10:19:12 +08:00
}
}
}
2023-10-25 09:16:31 +08:00
table.Rows.Add(row);
f++;
2023-10-11 10:19:12 +08:00
}
2023-10-25 09:16:31 +08:00
c++;
2023-10-11 10:19:12 +08:00
}
}
b++;
}
a++;
}
return table;
}
}
2023-10-18 09:40:57 +08:00
/// <summary>
/// 获取模拟树表格
/// </summary>
/// <returns></returns>
public static DataTable GetMonthProjectAllTreeDataTable(string projectId, string IsOut, List<string> contractNoList, List<string> professionalList, List<string> workPostIds, List<string> machineIds, DateTime startDate, DateTime endDate)
{
using (var db = new Model.SGGLDB(Funs.ConnString))
{
2023-10-24 17:29:27 +08:00
var pros = BLL.PHTGL_QuantityService.GetMajorItems2();
2023-10-18 09:40:57 +08:00
List<string> proNames = new List<string>();
foreach (var item in professionalList)
{
var pro = pros.FirstOrDefault(x => x.Text == item);
if (pro != null)
{
proNames.Add(pro.Value);
}
}
proNames = proNames.Distinct().ToList();
IQueryable<Model.PHTGL_ContractTrack> getContractTracks = from x in db.PHTGL_ContractTrack
where x.ProjectId == projectId && contractNoList.Contains(x.ContractId) && proNames.Contains(x.MajorName)
orderby x.ProjectCode, x.ProjectName
select x;
var personLogIds = (from x in db.ZHGL_ConstructionLog
where x.ProjectId == projectId && x.CompileDate >= startDate && x.CompileDate < endDate
orderby x.CompileDate descending
select x.ConstructionLogId).ToList();
IQueryable<Model.ZHGL_ConstructionLogWorkEfficiency> workEfficiencys = from x in db.ZHGL_ConstructionLogWorkEfficiency
where personLogIds.Contains(x.ConstructionLogId)
select x;
var unitWorks = (from x in getContractTracks
2023-10-25 14:07:29 +08:00
select new { MainItemCode = x.MainItemCode, MainItemName = x.MainItemName }).Distinct().OrderBy(x => x.MainItemCode).ToList();
2023-10-18 09:40:57 +08:00
DataTable table = new DataTable();
table.Columns.Add(new DataColumn("Id", typeof(String)));
table.Columns.Add(new DataColumn("Code", typeof(String)));
2023-10-25 14:07:29 +08:00
table.Columns.Add(new DataColumn("MainItemCode", typeof(String)));
table.Columns.Add(new DataColumn("MainItemName", typeof(String)));
table.Columns.Add(new DataColumn("MajorCode", typeof(String)));
table.Columns.Add(new DataColumn("MajorName", typeof(String)));
2023-10-18 09:40:57 +08:00
table.Columns.Add(new DataColumn("ProjectCode", typeof(String)));
table.Columns.Add(new DataColumn("ProjectName", typeof(String)));
table.Columns.Add(new DataColumn("UnitOfMeasurement", typeof(String)));
table.Columns.Add(new DataColumn("PhysicalCompletionQuantity", typeof(String)));
table.Columns.Add(new DataColumn("MaterialConsumption", typeof(String)));
table.Columns.Add(new DataColumn("ShowId", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours0", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency0", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours1", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency1", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours2", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency2", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours3", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency3", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours4", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency4", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours5", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency5", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours6", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency6", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours7", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency7", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours8", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency8", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours9", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency9", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours10", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency10", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours11", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency11", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours12", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency12", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours13", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency13", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours14", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency14", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours15", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency15", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours16", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency16", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours17", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency17", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours18", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency18", typeof(String)));
table.Columns.Add(new DataColumn("PersonConsumeHours19", typeof(String)));
table.Columns.Add(new DataColumn("PersonWorkEfficiency19", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours0", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency0", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours1", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency1", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours2", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency2", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours3", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency3", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours4", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency4", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours5", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency5", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours6", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency6", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours7", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency7", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours8", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency8", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours9", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency9", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours10", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency10", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours11", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency11", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours12", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency12", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours13", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency13", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours14", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency14", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours15", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency15", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours16", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency16", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours17", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency17", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours18", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency18", typeof(String)));
table.Columns.Add(new DataColumn("MachineConsumeHours19", typeof(String)));
table.Columns.Add(new DataColumn("MachineWorkEfficiency19", typeof(String)));
DataRow row;
int a = 1;
foreach (var unitWork in unitWorks)
{
row = table.NewRow();
row[0] = unitWork.MainItemCode;
row[1] = a;
2023-10-25 14:07:29 +08:00
row[2] = unitWork.MainItemCode;
2023-10-18 09:40:57 +08:00
row[3] = unitWork.MainItemName;
table.Rows.Add(row);
int b = 1;
foreach (var proName in proNames)
{
row = table.NewRow();
row[0] = unitWork.MainItemCode + b.ToString();
row[1] = a + "." + b;
row[2] = string.Empty;
2023-10-25 14:07:29 +08:00
row[3] = string.Empty;
var pro = pros.FirstOrDefault(x => x.Value == proName);
if (pro != null)
{
row[4] = pro.Text;
}
row[5] = proName;
2023-10-18 09:40:57 +08:00
table.Rows.Add(row);
2023-10-25 14:07:29 +08:00
var subProjects = (from x in getContractTracks
where x.MainItemCode == unitWork.MainItemCode && x.MajorName == proName && x.SubProject != null
select x.SubProject).Distinct().ToList();
if (subProjects.Count == 0) //未填分部工程
2023-10-18 09:40:57 +08:00
{
2023-10-25 14:07:29 +08:00
int c = 1;
var contractTracks = getContractTracks.Where(x => x.MainItemCode == unitWork.MainItemCode && x.MajorName == proName).OrderBy(x => x.SerialNumber);
foreach (Model.PHTGL_ContractTrack item in contractTracks)
2023-10-18 09:40:57 +08:00
{
2023-10-25 14:07:29 +08:00
row = table.NewRow();
row[0] = item.Id;
row[1] = a + "." + b + "." + c;
row[6] = item.ProjectCode;
row[7] = item.ProjectName;
row[8] = item.UnitOfMeasurement;
row[11] = item.Id;
if (workEfficiencys.Count() > 0)
2023-10-18 09:40:57 +08:00
{
2023-10-25 14:07:29 +08:00
var we = (from x in workEfficiencys
where x.ContractTrackId == item.Id
select new { x.ConstructionLogId, x.ContractTrackId, x.PhysicalCompletionQuantity, x.MaterialConsumption }).Distinct().ToList();
decimal physicalCompletionQuantity = 0, materialConsumption = 0;
if (we.Count() > 0)
2023-10-20 14:34:35 +08:00
{
2023-10-25 14:23:55 +08:00
physicalCompletionQuantity = we.Sum(x => x.PhysicalCompletionQuantity ?? 0);
materialConsumption = we.Sum(x => x.MaterialConsumption ?? 0);
2023-10-25 14:07:29 +08:00
row[9] = physicalCompletionQuantity;
row[10] = materialConsumption;
2023-10-20 14:34:35 +08:00
}
2023-10-25 14:07:29 +08:00
for (int i = 0; i < workPostIds.Count; i++)
2023-10-18 09:40:57 +08:00
{
2023-10-25 15:08:52 +08:00
var workEfficiencyList = workEfficiencys.Where(x => x.Type == "Person" && x.TypeId == workPostIds[i] && x.ContractTrackId == item.Id && x.ConsumeHours != null);
2023-10-25 14:07:29 +08:00
if (workEfficiencyList.Count() > 0)
2023-10-18 09:40:57 +08:00
{
2023-10-25 14:07:29 +08:00
decimal d = 0;
2023-10-25 15:08:52 +08:00
d = workEfficiencyList.Sum(x => x.ConsumeHours ?? 0);
2023-10-25 14:07:29 +08:00
if (d > 0)
{
row[12 + i * 2] = decimal.Round(d, 2);
if (physicalCompletionQuantity > 0)
{
row[13 + i * 2] = decimal.Round(Convert.ToDecimal(physicalCompletionQuantity / d), 2);
}
2023-10-18 09:40:57 +08:00
}
}
2023-10-25 14:07:29 +08:00
}
for (int i = 0; i < machineIds.Count; i++)
{
2023-10-25 15:08:52 +08:00
var workEfficiencyList = workEfficiencys.Where(x => x.Type == "Machine" && x.TypeId == machineIds[i] && x.ContractTrackId == item.Id && x.ConsumeHours != null);
2023-10-25 14:07:29 +08:00
if (workEfficiencyList.Count() > 0)
2023-10-18 09:40:57 +08:00
{
2023-10-25 14:07:29 +08:00
decimal d = 0;
2023-10-25 15:08:52 +08:00
d = workEfficiencyList.Sum(x => x.ConsumeHours ?? 0);
2023-10-25 14:07:29 +08:00
if (d > 0)
2023-10-18 09:40:57 +08:00
{
2023-10-25 14:07:29 +08:00
row[52 + i * 2] = decimal.Round(d, 2);
if (physicalCompletionQuantity > 0)
{
row[53 + i * 2] = decimal.Round(Convert.ToDecimal(physicalCompletionQuantity / d), 2);
}
2023-10-18 09:40:57 +08:00
}
}
}
}
2023-10-25 14:07:29 +08:00
table.Rows.Add(row);
c++;
}
}
else //存在分部工程
{
int c = 1;
foreach (var subProject in subProjects)
{
row = table.NewRow();
row[0] = unitWork.MainItemCode + b.ToString() + c.ToString();
row[1] = a + "." + b + "." + c;
row[7] = subProject;
table.Rows.Add(row);
int f = 1;
var contractTracks = getContractTracks.Where(x => x.MainItemCode == unitWork.MainItemCode && x.MajorName == proName && x.SubProject == subProject).OrderBy(x => x.SerialNumber);
foreach (Model.PHTGL_ContractTrack item in contractTracks)
2023-10-18 09:40:57 +08:00
{
2023-10-25 14:07:29 +08:00
row = table.NewRow();
row[0] = item.Id;
row[1] = a + "." + b + "." + c + "." + f;
row[6] = item.ProjectCode;
row[7] = item.ProjectName;
row[8] = item.UnitOfMeasurement;
row[11] = item.Id;
if (workEfficiencys.Count() > 0)
2023-10-18 09:40:57 +08:00
{
2023-10-25 14:07:29 +08:00
var we = (from x in workEfficiencys
where x.ContractTrackId == item.Id
select new { x.ConstructionLogId, x.ContractTrackId, x.PhysicalCompletionQuantity, x.MaterialConsumption }).Distinct().ToList();
decimal physicalCompletionQuantity = 0, materialConsumption = 0;
if (we.Count() > 0)
2023-10-18 09:40:57 +08:00
{
2023-10-25 14:23:55 +08:00
physicalCompletionQuantity = we.Sum(x => x.PhysicalCompletionQuantity ?? 0);
materialConsumption = we.Sum(x => x.MaterialConsumption ?? 0);
2023-10-25 14:07:29 +08:00
row[9] = physicalCompletionQuantity;
row[10] = materialConsumption;
}
for (int i = 0; i < workPostIds.Count; i++)
{
2023-10-25 15:08:52 +08:00
var workEfficiencyList = workEfficiencys.Where(x => x.Type == "Person" && x.TypeId == workPostIds[i] && x.ContractTrackId == item.Id && x.ConsumeHours != null);
2023-10-25 14:07:29 +08:00
if (workEfficiencyList.Count() > 0)
{
decimal d = 0;
2023-10-25 15:08:52 +08:00
d = workEfficiencyList.Sum(x => x.ConsumeHours ?? 0);
2023-10-25 14:07:29 +08:00
if (d > 0)
{
row[12 + i * 2] = decimal.Round(d, 2);
if (physicalCompletionQuantity > 0)
{
row[13 + i * 2] = decimal.Round(Convert.ToDecimal(physicalCompletionQuantity / d), 2);
}
}
2023-10-18 09:40:57 +08:00
}
}
2023-10-25 14:07:29 +08:00
for (int i = 0; i < machineIds.Count; i++)
2023-10-18 09:40:57 +08:00
{
2023-10-25 15:08:52 +08:00
var workEfficiencyList = workEfficiencys.Where(x => x.Type == "Machine" && x.TypeId == machineIds[i] && x.ContractTrackId == item.Id && x.ConsumeHours != null);
2023-10-25 14:07:29 +08:00
if (workEfficiencyList.Count() > 0)
2023-10-18 09:40:57 +08:00
{
2023-10-25 14:07:29 +08:00
decimal d = 0;
2023-10-25 15:08:52 +08:00
d = workEfficiencyList.Sum(x => x.ConsumeHours ?? 0);
2023-10-25 14:07:29 +08:00
if (d > 0)
{
row[52 + i * 2] = decimal.Round(d, 2);
if (physicalCompletionQuantity > 0)
{
row[53 + i * 2] = decimal.Round(Convert.ToDecimal(physicalCompletionQuantity / d), 2);
}
}
2023-10-18 09:40:57 +08:00
}
}
}
2023-10-25 14:07:29 +08:00
table.Rows.Add(row);
f++;
2023-10-18 09:40:57 +08:00
}
2023-10-25 14:07:29 +08:00
c++;
2023-10-18 09:40:57 +08:00
}
}
b++;
}
a++;
}
return table;
}
}
2023-08-25 23:55:32 +08:00
}
public class PHTGL_ContractTrackDtoIn
{
2023-10-24 17:25:06 +08:00
/// <summary>
/// 序号
/// </summary>
[ExcelColumnIndex("A")] public string SerialNumber { get; set; }
2023-08-25 23:55:32 +08:00
/// <summary>
/// 主项号
/// </summary>
[ExcelColumnIndex("B")] public string MainItemCode { get; set; }
/// <summary>
/// 主项名称
/// </summary>
[ExcelColumnIndex("C")] public string MainItemName { get; set; }
/// <summary>
/// 专业代码
/// </summary>
[ExcelColumnIndex("D")] public string MajorCode { get; set; }
/// <summary>
/// 专业工程名称
/// </summary>
[ExcelColumnIndex("E")] public string MajorName { get; set; }
/// <summary>
2023-10-24 17:25:06 +08:00
/// 分部工程
/// </summary>
[ExcelColumnIndex("F")] public string SubProject { get; set; }
/// <summary>
/// 分项工程
/// </summary>
[ExcelColumnIndex("G")] public string SubItemProject { get; set; }
/// <summary>
2023-08-25 23:55:32 +08:00
/// 项目编码
/// </summary>
2023-10-24 17:25:06 +08:00
[ExcelColumnIndex("H")] public string ProjectCode { get; set; }
2023-08-25 23:55:32 +08:00
/// <summary>
/// 项目名称
/// </summary>
2023-10-24 17:25:06 +08:00
[ExcelColumnIndex("I")] public string ProjectName { get; set; }
2023-08-25 23:55:32 +08:00
/// <summary>
/// 项目特征描述
/// </summary>
2023-10-24 17:25:06 +08:00
[ExcelColumnIndex("J")] public string ProjectDescription { get; set; }
2023-08-25 23:55:32 +08:00
/// <summary>
/// 计量单位
/// </summary>
2023-10-24 17:25:06 +08:00
[ExcelColumnIndex("K")] public string UnitOfMeasurement { get; set; }
2023-08-25 23:55:32 +08:00
/// <summary>
/// 工程量
/// </summary>
2023-10-24 17:25:06 +08:00
[ExcelColumnIndex("L")] public string Quantity { get; set; }
2023-08-25 23:55:32 +08:00
/// <summary>
/// 全费用固定综合单价
/// </summary>
2023-10-24 17:25:06 +08:00
[ExcelColumnIndex("M")] public string TotalCostFixedComprehensiveUnitPrice { get; set; }
2023-08-25 23:55:32 +08:00
/// <summary>
/// 其中:主材费
/// </summary>
2023-10-24 17:25:06 +08:00
[ExcelColumnIndex("N")] public string MainMaterialCost { get; set; }
2023-08-25 23:55:32 +08:00
/// <summary>
/// 合价/元
/// </summary>
2023-10-24 17:25:06 +08:00
[ExcelColumnIndex("O")] public string TotalPrice { get; set; }
2023-08-25 23:55:32 +08:00
/// <summary>
/// 计算规则
/// </summary>
2023-10-24 17:25:06 +08:00
[ExcelColumnIndex("P")] public string CalculationRule { get; set; }
2023-08-25 23:55:32 +08:00
/// <summary>
/// 工作内容
/// </summary>
2023-10-24 17:25:06 +08:00
[ExcelColumnIndex("Q")] public string WorkContent { get; set; }
2023-08-25 23:55:32 +08:00
/// <summary>
/// 备注
/// </summary>
2023-10-24 17:25:06 +08:00
[ExcelColumnIndex("R")] public string Remarks { get; set; }
2023-08-25 23:55:32 +08:00
}
}