Exemplo n.º 1
0
        public static IList <TaskResource> GetResourcesByTempItemId(string tempId)
        {
            List <TaskResource> list = new List <TaskResource>();

            using (pm2Entities entities = new pm2Entities())
            {
                var list2 = (from m in entities.Bud_TemplateResource
                             where m.Bud_TemplateItem.TemplateItemId == tempId
                             select new { ResourceQuantity = m.ResourceQuantity, ResourcePrice = m.ResourcePrice, ResourceId = m.Res_Resource.ResourceId }).ToList();
                if (list2.Count <= 0)
                {
                    return(list);
                }
                foreach (var type in list2)
                {
                    TaskResource item          = new TaskResource();
                    decimal?     resourcePrice = type.ResourcePrice;
                    item.Price = resourcePrice.HasValue ? resourcePrice.GetValueOrDefault() : 0M;
                    decimal?resourceQuantity = type.ResourceQuantity;
                    item.Quantity = resourceQuantity.HasValue ? resourceQuantity.GetValueOrDefault() : 0M;
                    item.Resource = Resource.GetById(type.ResourceId);
                    list.Add(item);
                }
            }
            return(list);
        }
Exemplo n.º 2
0
        private void AddTaskResource(string resCode, string resName, decimal price, decimal quanity, string taskId, List <string> errors)
        {
            Resource byId = Resource.GetById(Resource.GetResourceId(resCode));

            if (byId != null)
            {
                TaskResource taskResource = new TaskResource {
                    Resource  = byId,
                    InputUser = this.inputUser,
                    InputDate = new DateTime?(DateTime.Now),
                    Price     = price,
                    Quantity  = quanity
                };
                BudTask.AddResource(taskId, taskResource);
            }
            else
            {
                string item = "资源编号:" + resCode + " 在资源库不存在,已添加到资源映射!";
                if (!errors.Contains(item))
                {
                    errors.Add(item);
                    ResourceTemp.Add(ResourceTemp.Create(string.Empty, taskId, resCode, resName, new decimal?(price), new decimal?(quanity), new decimal?(price * quanity), this.prjId));
                }
            }
        }
Exemplo n.º 3
0
        public void AddResource(string[] colArray, string inputUser, List <string> errors, string prjId, string isWBSRelevance, char sep)
        {
            IDictionary <string, int> relation = ExcelUtility.GetRelation(colArray);

            this.ParseResourceTable(relation);
            string  name          = string.Empty;
            string  resourceCode  = string.Empty;
            string  brand         = string.Empty;
            string  specification = string.Empty;
            string  modelNumber   = string.Empty;
            string  str6          = string.Empty;
            decimal?unitPrice     = 0M;
            decimal?quanity       = 0M;
            decimal?amount        = 0M;
            string  str7          = string.Empty;
            string  note          = string.Empty;
            string  item          = string.Empty;
            decimal?nullable4     = 0M;
            string  str10         = string.Empty;

            foreach (DataRow row in this.dtResource.Rows)
            {
                Action <object> action2 = null;
                if (this.serialNoIndex != -1)
                {
                    str10 = (row[this.serialNoIndex] == null) ? null : row[this.serialNoIndex].ToString().Trim();
                }
                name = (row[this.nameIndex] == null) ? null : row[this.nameIndex].ToString();
                if ((isWBSRelevance == "1") && (this.taskCodeIndex != -1))
                {
                    str7 = (row[this.taskCodeIndex] == null) ? null : row[this.taskCodeIndex].ToString().Trim();
                }
                if (this.brandIndex != -1)
                {
                    brand = row[this.brandIndex].ToString();
                }
                if (this.specificationIndex != -1)
                {
                    specification = row[this.specificationIndex].ToString().Trim();
                }
                if (this.ModelNumberIndex != -1)
                {
                    modelNumber = row[this.ModelNumberIndex].ToString().Trim();
                }
                if (this.technicalParameterIndex != -1)
                {
                    row[this.technicalParameterIndex].ToString().Trim();
                }
                if ((this.unitIndex != -1) && (row[this.unitIndex].ToString().Trim().Length == 0))
                {
                    str6 = null;
                }
                if (this.unitPriceIndex != -1)
                {
                    try
                    {
                        unitPrice = new decimal?(decimal.Parse(row[this.unitPriceIndex].ToString()));
                    }
                    catch
                    {
                        item = "在您的Excel中:资源名称为" + name + "的资源,单价不是非有效数字,请修改。";
                        errors.Add(item);
                        return;
                    }
                }
                if (this.quantityIndex != -1)
                {
                    try
                    {
                        quanity = new decimal?(decimal.Parse(row[this.quantityIndex].ToString()));
                    }
                    catch
                    {
                        item = "在您的Excel中:资源名称为" + name + "的资源,数量不是有效数字,请修改。";
                        errors.Add(item);
                        return;
                    }
                }
                if (this.noteIndex != -1)
                {
                    note = row[this.noteIndex].ToString().Trim();
                }
                if (this.codeIndex != -1)
                {
                    resourceCode = row[this.codeIndex].ToString();
                }
                if (this.amountIndex != -1)
                {
                    try
                    {
                        amount = new decimal?(decimal.Parse(row[this.amountIndex].ToString()));
                    }
                    catch
                    {
                        item = "在您的Excel中:资源名称为" + name + "的资源,合计金额不是有效数字,请修改。";
                        errors.Add(item);
                        return;
                    }
                }
                if (this.lossCoefficientIndex != -1)
                {
                    try
                    {
                        nullable4 = new decimal?(decimal.Parse(row[this.lossCoefficientIndex].ToString()));
                    }
                    catch
                    {
                        nullable4 = 1;
                    }
                }
                string str11 = new ResResourceService().GetId(name, brand, specification, modelNumber, note, sep);
                if (string.IsNullOrEmpty(str11))
                {
                    item = "在您的Excel中:资源名称" + name + ",在资源库中不存在。";
                    errors.Add(item);
                }
                string taskId = string.Empty;
                if (!string.IsNullOrEmpty(str7))
                {
                    taskId = this.GetRelationTaskId(str7);
                }
                if (!string.IsNullOrEmpty(str10))
                {
                    taskId = this.GetRelationTaskId(str10);
                }
                if (string.IsNullOrEmpty(taskId) && (isWBSRelevance == "1"))
                {
                    item = "在您的Excel中:资源名称" + name + ",关联的分布分项不存在。";
                    errors.Add(item);
                }
                if (cn.justwin.Domain.BudTask.CheckChilds(taskId))
                {
                    item = "在您的Excel中:资源名称" + name + ",不能配置到有子项的分部分项。";
                    errors.Add(item);
                    taskId = string.Empty;
                }
                if (isWBSRelevance == "1")
                {
                    if (!string.IsNullOrEmpty(taskId) && !string.IsNullOrEmpty(str11))
                    {
                        decimal?repeatResQuantity = TaskResource.GetRepeatResQuantity(taskId, str11);
                        if (repeatResQuantity.HasValue)
                        {
                            decimal?nullable7 = quanity;
                            this.MergeResQuantity(taskId, str11, repeatResQuantity.Value, nullable7.HasValue ? nullable7.GetValueOrDefault() : 0M);
                        }
                        else if (cn.justwin.Domain.BudTask.GetById(taskId) != null)
                        {
                            BudTaskResource resource = new BudTaskResource {
                                TaskResourceId   = Guid.NewGuid().ToString(),
                                TaskId           = taskId,
                                ResourceId       = str11,
                                ResourceQuantity = new decimal?(quanity.Value),
                                InputUser        = this.UserCode,
                                InputDate        = DateTime.Now,
                                ResourcePrice    = new decimal?(unitPrice.Value),
                                PrjGuid          = prjId,
                                Versions         = 1,
                                LossCoefficient  = new decimal?(nullable4.Value)
                            };
                            new BudTaskResourceService().Add(resource);
                        }
                        if (action2 == null)
                        {
                            action2 = obj => new BudTaskService().UpdateTotal2(taskId);
                        }
                        Action <object> action = action2;
                        new Task(action, "").Start();
                    }
                    else
                    {
                        ResourceTemp.Add(ResourceTemp.Create(str11, taskId, resourceCode, name, unitPrice, quanity, amount, prjId));
                    }
                }
                else if (!string.IsNullOrEmpty(str11))
                {
                    decimal?resQuantity = TaskResource.GetResQuantity(prjId, str11);
                    if (resQuantity.HasValue)
                    {
                        decimal?nullable8 = quanity;
                        this.MergeResQuantityByPrjId(prjId, str11, resQuantity.Value, nullable8.HasValue ? nullable8.GetValueOrDefault() : 0M);
                    }
                    else
                    {
                        Resource     byId         = Resource.GetById(str11);
                        TaskResource taskResource = new TaskResource {
                            TaskReourceId   = Guid.NewGuid().ToString(),
                            Resource        = byId,
                            PrjGuid         = prjId,
                            Price           = unitPrice.Value,
                            Quantity        = quanity.Value,
                            InputDate       = new DateTime?(DateTime.Now),
                            InputUser       = this.UserCode,
                            LossCoefficient = nullable4
                        };
                        TaskResource.AddResource(taskResource);
                    }
                }
                else
                {
                    ResourceTemp.Add(ResourceTemp.Create(str11, null, resourceCode, name, unitPrice, quanity, amount, prjId));
                }
            }
            BudTaskServices.codeAndTaskId.Clear();
        }
Exemplo n.º 4
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);
                 }
             }
         }
     }
 }