Esempio n. 1
0
        public static List <ConstructResource> GetAll(string consTaskId, List <string> resourceIds)
        {
            List <ConstructResource> list = new List <ConstructResource>();

            using (pm2Entities entities = new pm2Entities())
            {
                using (List <string> .Enumerator enumerator = resourceIds.GetEnumerator())
                {
                    string resourceId;
                    while (enumerator.MoveNext())
                    {
                        resourceId = enumerator.Current;
                        Bud_ConsTaskRes res = (from m in entities.Bud_ConsTaskRes
                                               where (m.Bud_ConsTask.ConsTaskId == consTaskId) && (m.Res_Resource.ResourceId == resourceId)
                                               select m).FirstOrDefault <Bud_ConsTaskRes>();
                        ConstructResource item = null;
                        if (res != null)
                        {
                            item = new ConstructResource {
                                ResourceId = resourceId,
                                Quantity   = res.Quantity,
                                UnitPrice  = res.UnitPrice,
                                ConsTaskId = consTaskId
                            };
                        }
                        else
                        {
                            item = new ConstructResource {
                                ResourceId = resourceId,
                                Quantity   = 0M,
                                UnitPrice  = 0M,
                                ConsTaskId = consTaskId
                            };
                        }
                        list.Add(item);
                    }
                }
            }
            return(list);
        }
Esempio n. 2
0
 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();
         }
     }
 }
Esempio n. 3
0
 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);
                 }
             }
         }
     }
 }
Esempio n. 4
0
        public static List <ConstructResource> GetByConsTask(string consTaskId, string TaskId)
        {
            List <ConstructResource> list = new List <ConstructResource>();

            using (pm2Entities entities = new pm2Entities())
            {
                using (var enumerator = (from m in entities.Bud_ConsTaskRes
                                         where m.Bud_ConsTask.ConsTaskId == consTaskId
                                         select new { ConsTaskResId = m.ConsTaskResId, ResourceId = m.Res_Resource.ResourceId, Quantity = m.Quantity, UnitPrice = m.UnitPrice, AccountingQuantity = m.AccountingQuantity, ResourceTypeId = m.Res_Resource.Res_ResourceType.ResourceTypeId, CBSCode = m.CBSCode }).ToList().GetEnumerator())
                {
                    var bud_consRes;
                    while (enumerator.MoveNext())
                    {
                        bud_consRes = enumerator.Current;
                        ConstructResource item = null;
                        if (bud_consRes != null)
                        {
                            item = new ConstructResource {
                                Id                 = bud_consRes.ConsTaskResId,
                                ResourceId         = bud_consRes.ResourceId,
                                Quantity           = bud_consRes.Quantity,
                                UnitPrice          = bud_consRes.UnitPrice,
                                ConsTaskId         = consTaskId,
                                AccountingQuantity = bud_consRes.AccountingQuantity
                            };
                        }
                        Bud_TaskResource resource3 = (from btr in entities.Bud_TaskResource
                                                      where (btr.Bud_Task.TaskId == TaskId) && (btr.Res_Resource.ResourceId == bud_consRes.ResourceId)
                                                      select btr).FirstOrDefault <Bud_TaskResource>();
                        if (resource3 != null)
                        {
                            item.BudQuantity = Convert.ToDecimal(resource3.ResourceQuantity);
                        }
                        else
                        {
                            item.BudQuantity = 0M;
                        }
                        if (bud_consRes.CBSCode != null)
                        {
                            item.CBScode = bud_consRes.CBSCode;
                        }
                        else
                        {
                            ResType byId = ResType.GetById(cn.justwin.Domain.Resource.GetFirstResourceTypeId(bud_consRes.ResourceTypeId));
                            if (byId != null)
                            {
                                if (!string.IsNullOrEmpty(byId.CBSCode))
                                {
                                    item.CBScode = byId.CBSCode;
                                }
                                else
                                {
                                    item.CBScode = string.Empty;
                                }
                            }
                            else
                            {
                                item.CBScode = string.Empty;
                            }
                        }
                        list.Add(item);
                    }
                }
            }
            return(list);
        }