Beispiel #1
0
 public static void AddResource(List <TaskResource> resList, string prjId, int version)
 {
     using (pm2Entities entities = new pm2Entities())
     {
         DelRes(entities, prjId, version);
         using (List <TaskResource> .Enumerator enumerator = resList.GetEnumerator())
         {
             TaskResource taskResource;
             while (enumerator.MoveNext())
             {
                 taskResource = enumerator.Current;
                 Bud_TaskResource resource = new Bud_TaskResource {
                     TaskResourceId = Guid.NewGuid().ToString(),
                     Bud_Task       = null,
                     Res_Resource   = (from r in entities.Res_Resource
                                       where r.ResourceId == taskResource.Resource.Id
                                       select r).FirstOrDefault <Res_Resource>(),
                     ResourceQuantity = new decimal?(taskResource.Quantity),
                     ResourcePrice    = new decimal?(taskResource.Price),
                     InputUser        = taskResource.InputUser,
                     InputDate        = taskResource.InputDate.Value,
                     PrjGuid          = prjId,
                     Versions         = new int?(version),
                     LossCoefficient  = taskResource.LossCoefficient
                 };
                 entities.AddToBud_TaskResource(resource);
             }
         }
         entities.SaveChanges();
     }
 }
Beispiel #2
0
 public static void AddResource(TaskResource taskResource)
 {
     using (pm2Entities entities = new pm2Entities())
     {
         int?nullable = (from m in entities.Bud_Task
                         where m.PrjId == taskResource.PrjGuid
                         select m.Version).Max <int?>();
         if (!nullable.HasValue)
         {
             nullable = 1;
         }
         Bud_TaskResource resource = new Bud_TaskResource {
             TaskResourceId = taskResource.TaskReourceId,
             Bud_Task       = null,
             Res_Resource   = (from r in entities.Res_Resource
                               where r.ResourceId == taskResource.Resource.Id
                               select r).FirstOrDefault <Res_Resource>(),
             ResourceQuantity = new decimal?(taskResource.Quantity),
             ResourcePrice    = new decimal?(taskResource.Price),
             InputUser        = taskResource.InputUser,
             InputDate        = taskResource.InputDate.Value,
             PrjGuid          = taskResource.PrjGuid,
             Versions         = nullable,
             LossCoefficient  = taskResource.LossCoefficient
         };
         entities.AddToBud_TaskResource(resource);
         entities.SaveChanges();
     }
 }
Beispiel #3
0
 public static void UpdateResQuantity(string taskId, string resId, decimal quantity)
 {
     using (pm2Entities entities = new pm2Entities())
     {
         Bud_TaskResource resource = (from m in entities.Bud_TaskResource
                                      where (m.Res_Resource.ResourceId == resId) && (m.Bud_Task.TaskId == taskId)
                                      select m).FirstOrDefault <Bud_TaskResource>();
         if (resource != null)
         {
             resource.ResourceQuantity = new decimal?(quantity);
             entities.SaveChanges();
         }
     }
 }
Beispiel #4
0
 public static void UpdateResQuantityByPrjId(string prjId, string resId, decimal quantity)
 {
     using (pm2Entities entities = new pm2Entities())
     {
         int?maxVersion = (from m in entities.Bud_Task
                           where m.PrjId == prjId
                           select m.Version).Max <int?>();
         if (!maxVersion.HasValue)
         {
             maxVersion = 1;
         }
         Bud_TaskResource resource = (from m in entities.Bud_TaskResource
                                      where ((m.Res_Resource.ResourceId == resId) && (m.PrjGuid == prjId)) && (m.Versions == maxVersion.Value)
                                      select m).FirstOrDefault <Bud_TaskResource>();
         if (resource != null)
         {
             resource.ResourceQuantity = new decimal?(quantity);
             entities.SaveChanges();
         }
     }
 }
Beispiel #5
0
 private static void DeleteResource(List <string> taskResIds, pm2Entities context)
 {
     try
     {
         using (List <string> .Enumerator enumerator = taskResIds.GetEnumerator())
         {
             string taskResId;
             while (enumerator.MoveNext())
             {
                 taskResId = enumerator.Current;
                 Bud_TaskResource entity = context.Bud_TaskResource.FirstOrDefault <Bud_TaskResource>(c => c.TaskResourceId == taskResId);
                 if (entity == null)
                 {
                     throw new Exception("找不到要删除的资源!");
                 }
                 context.DeleteObject(entity);
             }
         }
     }
     catch (Exception)
     {
         throw new Exception("找不到要删除的资源!");
     }
 }
Beispiel #6
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);
        }
Beispiel #7
0
 public static void Delete(ResourceTemp resTemp, string InputUser, string isWBSRelevance)
 {
     using (pm2Entities entities = new pm2Entities())
     {
         if (isWBSRelevance == "1")
         {
             Bud_TaskResource resource = (from tr in entities.Bud_TaskResource
                                          where (tr.Res_Resource.ResourceId == resTemp.ResourceId) && (tr.Bud_Task.TaskId == resTemp.BudTask.Id)
                                          select tr).FirstOrDefault <Bud_TaskResource>();
             if (resource == null)
             {
                 Bud_TaskResource resource2 = new Bud_TaskResource {
                     TaskResourceId = Guid.NewGuid().ToString(),
                     Bud_Task       = (from t in entities.Bud_Task
                                       where t.TaskId == resTemp.BudTask.Id
                                       select t).FirstOrDefault <Bud_Task>(),
                     Res_Resource = (from r in entities.Res_Resource
                                     where r.ResourceId == resTemp.ResourceId
                                     select r).FirstOrDefault <Res_Resource>(),
                     ResourceQuantity = resTemp.Quantity,
                     ResourcePrice    = resTemp.UnitPrice,
                     InputUser        = InputUser,
                     InputDate        = DateTime.Now,
                     PrjGuid          = resTemp.PrjId,
                     Versions         = 1,
                     LossCoefficient  = 1
                 };
                 entities.AddToBud_TaskResource(resource2);
             }
             else
             {
                 resource.ResourceQuantity += resTemp.Quantity;
             }
         }
         else
         {
             Bud_TaskResource resource3 = (from tr in entities.Bud_TaskResource
                                           where (tr.Res_Resource.ResourceId == resTemp.ResourceId) && (tr.PrjGuid == resTemp.PrjId)
                                           select tr).FirstOrDefault <Bud_TaskResource>();
             if (resource3 == null)
             {
                 int?nullable = (from m in entities.Bud_Task
                                 where m.PrjId == resTemp.PrjId
                                 select m.Version).Max <int?>();
                 if (!nullable.HasValue)
                 {
                     nullable = 1;
                 }
                 Bud_TaskResource resource4 = new Bud_TaskResource {
                     TaskResourceId = Guid.NewGuid().ToString(),
                     Bud_Task       = null,
                     Res_Resource   = (from r in entities.Res_Resource
                                       where r.ResourceId == resTemp.ResourceId
                                       select r).FirstOrDefault <Res_Resource>(),
                     ResourceQuantity = resTemp.Quantity,
                     ResourcePrice    = resTemp.UnitPrice,
                     InputUser        = InputUser,
                     InputDate        = DateTime.Now,
                     PrjGuid          = resTemp.PrjId,
                     Versions         = nullable
                 };
                 entities.AddToBud_TaskResource(resource4);
             }
             else
             {
                 resource3.ResourceQuantity += resTemp.Quantity;
             }
         }
         Res_ResourceTemp entity = (from rt in entities.Res_ResourceTemp
                                    where rt.Id == resTemp.Id
                                    select rt).FirstOrDefault <Res_ResourceTemp>();
         entities.DeleteObject(entity);
         entities.SaveChanges();
     }
 }