示例#1
0
    private string GenerateResCode()
    {
        string text   = string.Empty;
        string typeId = base.Request["parentId"];

        if (!string.IsNullOrEmpty(typeId))
        {
            ResResourceTypeService resResourceTypeService = new ResResourceTypeService();
            ResResourceService     resResourceService     = new ResResourceService();
            ResResourceType        byId = resResourceTypeService.GetById(typeId);
            text = byId.ResourceTypeCode;
            int num = (
                from r in resResourceService
                where r.ResourceType == typeId
                select r).Count <ResResource>();
            text += (num + 1).ToString().PadLeft(5, '0');
            if (resResourceService.IsExists(text))
            {
                text += "01";
            }
            return(text);
        }
        else
        {
            return("");
        }
    }
示例#2
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();
        }