public static List <ConstructTask> GetAll(string reportId, List <string> taskIds) { List <ConstructTask> list = new List <ConstructTask>(); using (pm2Entities entities = new pm2Entities()) { using (List <string> .Enumerator enumerator = taskIds.GetEnumerator()) { string taskId; while (enumerator.MoveNext()) { taskId = enumerator.Current; Bud_ConsTask task = (from m in entities.Bud_ConsTask where (m.Bud_ConsReport.ConsReportId == reportId) && (m.TaskId == taskId) select m).FirstOrDefault <Bud_ConsTask>(); decimal num = 0M; try { num = ((IQueryable <decimal>)(from m in entities.Bud_ConsTask where m.TaskId == taskId select m.CompleteQuantity)).Sum(); } catch { } ConstructTask item = new ConstructTask(); if (task != null) { item.Id = task.ConsTaskId; item.Note = task.Note; item.CompleteQuantity = task.CompleteQuantity; item.WorkContent = task.WorkContent; item.taskId = taskId; item.SurplusQuantity = decimal.Subtract(item.BudTask.Quantity, num); item.reportId = reportId; } else { item.Id = string.Empty; item.Note = string.Empty; item.CompleteQuantity = 0M; item.WorkContent = string.Empty; item.taskId = taskId; item.SurplusQuantity = decimal.Subtract(item.BudTask.Quantity, num); item.reportId = reportId; } list.Add(item); } } } return(list); }
private static void Delete(string id, pm2Entities context) { Bud_ConsTask entity = (from m in context.Bud_ConsTask where m.ConsTaskId == id select m).FirstOrDefault <Bud_ConsTask>(); if (entity == null) { throw new Exception("已删除不存在!"); } context.DeleteObject(entity); context.SaveChanges(); }
public static void Clear(string reportId) { using (pm2Entities entities = new pm2Entities()) { Bud_ConsTask entity = (from m in entities.Bud_ConsTask where m.Bud_ConsReport.ConsReportId == reportId select m).FirstOrDefault <Bud_ConsTask>(); if (entity != null) { entities.DeleteObject(entity); entities.SaveChanges(); } } }
public void Update(ConstructTask consTask) { using (pm2Entities entities = new pm2Entities()) { Bud_ConsTask task = (from m in entities.Bud_ConsTask where m.ConsTaskId == consTask.Id select m).FirstOrDefault <Bud_ConsTask>(); if (task == null) { throw new Exception("此施工报量节点不存在无法完成修改!"); } task.WorkContent = consTask.WorkContent; task.Note = consTask.Note; task.CompleteQuantity = consTask.CompleteQuantity; task.AccountingQuantity = new decimal?(consTask.CompleteQuantity); entities.SaveChanges(); } }
private static List <Bud_ConsTask> GetBud_ConsTask(List <string> idList, pm2Entities contxt) { List <Bud_ConsTask> list = new List <Bud_ConsTask>(); using (List <string> .Enumerator enumerator = idList.GetEnumerator()) { string id; while (enumerator.MoveNext()) { id = enumerator.Current; Bud_ConsTask item = contxt.Bud_ConsTask.FirstOrDefault <Bud_ConsTask>(c => c.ConsTaskId == id); if (item != null) { list.Add(item); } } } return(list); }
private static void Delete(List <string> idList, pm2Entities context) { using (List <string> .Enumerator enumerator = idList.GetEnumerator()) { string id; while (enumerator.MoveNext()) { id = enumerator.Current; Bud_ConsTask entity = (from m in context.Bud_ConsTask where m.ConsTaskId == id select m).FirstOrDefault <Bud_ConsTask>(); if (entity != null) { context.DeleteObject(entity); context.SaveChanges(); } } } }
public static void AuditConsTask(List <ConstructTask> consTaskList) { using (pm2Entities entities = new pm2Entities()) { using (List <ConstructTask> .Enumerator enumerator = consTaskList.GetEnumerator()) { ConstructTask consTask; while (enumerator.MoveNext()) { consTask = enumerator.Current; Bud_ConsTask task = (from ct in entities.Bud_ConsTask where ct.ConsTaskId == consTask.Id select ct).FirstOrDefault <Bud_ConsTask>(); if (task != null) { task.AccountingQuantity = new decimal?(consTask.AccountingQuantity); } } } entities.SaveChanges(); } }
public void Add(ConstructResource consRes) { using (pm2Entities entities = new pm2Entities()) { Res_Resource resource = (from m in entities.Res_Resource where m.ResourceId == consRes.ResourceId select m).FirstOrDefault <Res_Resource>(); Bud_ConsTask task = (from m in entities.Bud_ConsTask where m.ConsTaskId == consRes.ConsTaskId select m).FirstOrDefault <Bud_ConsTask>(); if ((resource != null) && (task != null)) { Bud_ConsTaskRes res = new Bud_ConsTaskRes { ConsTaskResId = consRes.Id, Quantity = consRes.Quantity, Bud_ConsTask = task, Res_Resource = resource, UnitPrice = consRes.UnitPrice }; entities.AddToBud_ConsTaskRes(res); entities.SaveChanges(); } } }
public void Add(ConstructTask consTask, string isWBSRelevance) { using (pm2Entities entities = new pm2Entities()) { (from m in entities.Bud_Task where m.TaskId == consTask.taskId select m).FirstOrDefault <Bud_Task>(); Bud_ConsReport report = (from m in entities.Bud_ConsReport where m.ConsReportId == consTask.reportId select m).FirstOrDefault <Bud_ConsReport>(); Bud_ConsTask task = new Bud_ConsTask { TaskId = consTask.taskId, ConsTaskId = consTask.Id, Note = consTask.Note, Bud_ConsReport = report, CompleteQuantity = consTask.CompleteQuantity, WorkContent = consTask.WorkContent }; entities.AddToBud_ConsTask(task); entities.SaveChanges(); if (isWBSRelevance == "1") { var list = (from m in entities.Bud_TaskResource where m.Bud_Task.TaskId == consTask.taskId select new { resourceId = m.Res_Resource.ResourceId, resourcePrice = m.ResourcePrice, resourceQuantity = m.ResourceQuantity }).ToList(); List <BudModifyTaskRes> first = (from mt in this.budModifyTaskSer join m in this.budModifySer on mt.ModifyId equals m.ModifyId into m join mtr in this.budModifyTaskResSer on mt.ModifyTaskId equals mtr.ModifyTaskId into mtr where (mt.TaskId == consTask.taskId) && (m.Flowstate == 1) select mtr).ToList <BudModifyTaskRes>(); List <BudModifyTaskRes> second = (from mt in this.budModifyTaskSer join m in this.budModifySer on mt.ModifyId equals m.ModifyId into m join mtr in this.budModifyTaskResSer on mt.ModifyTaskId equals mtr.ModifyTaskId into mtr where (mt.ModifyTaskId == consTask.taskId) && (m.Flowstate == 1) select mtr).ToList <BudModifyTaskRes>(); first = first.Union <BudModifyTaskRes>(second).ToList <BudModifyTaskRes>(); using (var enumerator = list.GetEnumerator()) { System.Func <BudModifyTaskRes, bool> predicate = null; var res; while (enumerator.MoveNext()) { res = enumerator.Current; decimal num = 0M; decimal unitPrice = 0M; decimal num3 = 0M; if (res.resourceQuantity.HasValue && res.resourcePrice.HasValue) { num = res.resourceQuantity.Value; num3 = num * res.resourcePrice.Value; } if (predicate == null) { predicate = list => list.ResourceId == res.resourceId; } foreach (BudModifyTaskRes res in first.Where <BudModifyTaskRes>(predicate).ToList <BudModifyTaskRes>()) { if (res != null) { num += res.ResourceQuantity; num3 += res.ResourcePrice * res.ResourceQuantity; first.Remove(res); } } if (num != 0M) { unitPrice = num3 / num; } ConstructResource consRes = ConstructResource.Create(Guid.NewGuid().ToString(), consTask.Id, res.resourceId, 0M, unitPrice); consRes.Add(consRes); } } using (List <string> .Enumerator enumerator3 = this.budModifyTaskResSer.GetModifyTasResIds(first).GetEnumerator()) { System.Func <BudModifyTaskRes, bool> func2 = null; string resId; while (enumerator3.MoveNext()) { resId = enumerator3.Current; decimal num4 = 0M; decimal num5 = 0M; decimal num6 = 0M; if (func2 == null) { func2 = list => list.ResourceId == resId; } foreach (BudModifyTaskRes res2 in first.Where <BudModifyTaskRes>(func2).ToList <BudModifyTaskRes>()) { if (res2 != null) { num4 += res2.ResourceQuantity; num6 += res2.ResourcePrice * res2.ResourceQuantity; first.Remove(res2); } } if (num4 != 0M) { num5 = num6 / num4; } Resource.GetById(resId); ConstructResource resource2 = ConstructResource.Create(Guid.NewGuid().ToString(), consTask.Id, resId, 0M, num5); resource2.Add(resource2); } } } } }