Exemplo n.º 1
0
        public void SetResQuantityByConsQuantity(decimal quantity)
        {
            cn.justwin.Domain.BudTask byId = cn.justwin.Domain.BudTask.GetById(this.taskId);
            decimal num = 0M;

            if (byId == null)
            {
                BudModifyTask task2 = this.budModifyTaskSer.GetById(this.taskId);
                if ((task2 != null) && (task2.Quantity != 0M))
                {
                    num = quantity / task2.Quantity;
                }
            }
            else if (byId.Quantity != 0M)
            {
                num = quantity / byId.Quantity;
            }
            using (pm2Entities entities = new pm2Entities())
            {
                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 == this.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 == this.taskId) && (m.Flowstate == 1)
                                                  select mtr).ToList <BudModifyTaskRes>();
                first = first.Union <BudModifyTaskRes>(second).ToList <BudModifyTaskRes>();
                if (byId != null)
                {
                    using (IEnumerator <TaskResource> enumerator = byId.Resources.GetEnumerator())
                    {
                        System.Func <BudModifyTaskRes, bool> predicate = null;
                        TaskResource item;
                        while (enumerator.MoveNext())
                        {
                            item = enumerator.Current;
                            decimal num2 = 0M;
                            num2 = item.Quantity;
                            if (predicate == null)
                            {
                                predicate = list => list.ResourceId == item.Resource.Id;
                            }
                            foreach (BudModifyTaskRes res in first.Where <BudModifyTaskRes>(predicate).ToList <BudModifyTaskRes>())
                            {
                                if (item != null)
                                {
                                    num2 += res.ResourceQuantity;
                                    first.Remove(res);
                                }
                            }
                            for (int i = 0; i < this.ResourceList.Count; i++)
                            {
                                string resourceId = this.resourceList[i].ResourceId;
                                if (resourceId == item.Resource.Id)
                                {
                                    Bud_ConsTaskRes res2 = (from ctr in entities.Bud_ConsTaskRes
                                                            where (ctr.Res_Resource.ResourceId == resourceId) && (ctr.Bud_ConsTask.ConsTaskId == this.Id)
                                                            select ctr).FirstOrDefault <Bud_ConsTaskRes>();
                                    if (res2 != null)
                                    {
                                        if (num > 1M)
                                        {
                                            res2.Quantity           = num2;
                                            res2.AccountingQuantity = new decimal?(num2);
                                        }
                                        else
                                        {
                                            res2.Quantity           = num * num2;
                                            res2.AccountingQuantity = new decimal?(num * num2);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                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;
                        if (func2 == null)
                        {
                            func2 = list => list.ResourceId == resId;
                        }
                        foreach (BudModifyTaskRes res3 in first.Where <BudModifyTaskRes>(func2).ToList <BudModifyTaskRes>())
                        {
                            num4 += res3.ResourceQuantity;
                            first.Remove(res3);
                        }
                        for (int j = 0; j < this.ResourceList.Count; j++)
                        {
                            string resourceId = this.resourceList[j].ResourceId;
                            if (resourceId == resId)
                            {
                                Bud_ConsTaskRes res4 = (from ctr in entities.Bud_ConsTaskRes
                                                        where (ctr.Res_Resource.ResourceId == resourceId) && (ctr.Bud_ConsTask.ConsTaskId == this.Id)
                                                        select ctr).FirstOrDefault <Bud_ConsTaskRes>();
                                if (res4 != null)
                                {
                                    if (num > 1M)
                                    {
                                        res4.Quantity           = num4;
                                        res4.AccountingQuantity = new decimal?(num4);
                                    }
                                    else
                                    {
                                        res4.Quantity           = num * num4;
                                        res4.AccountingQuantity = new decimal?(num * num4);
                                    }
                                }
                            }
                        }
                    }
                }
                entities.SaveChanges();
            }
        }
Exemplo n.º 2
0
        public int ConverBudTaskList(string[] colArray, string inputUser, List <string> errors, string IsWBSRelevance)
        {
            int num = 0;
            List <cn.justwin.Domain.BudTask> list     = new List <cn.justwin.Domain.BudTask>();
            IDictionary <string, int>        relation = ExcelUtility.GetRelation(colArray);
            List <string> orderNumberByLayer          = new List <string>();

            try
            {
                this.ParseTaskTable(relation);
                List <int> layerList = new List <int>();
                if (this.rankIndex == -1)
                {
                    List <string> codeList = this.GetCodeList();
                    layerList = this.GetLayersByCode(codeList);
                }
                else
                {
                    layerList = this.GetLayers();
                }
                orderNumberByLayer = this.GetOrderNumberByLayer(layerList);
            }
            catch (Exception exception)
            {
                errors.Add(exception.Message);
            }
            string   code        = string.Empty;
            string   name        = string.Empty;
            string   unit        = string.Empty;
            decimal  quantity    = 0M;
            decimal  num3        = 0M;
            decimal  num4        = 0M;
            DateTime?startDate   = null;
            DateTime?endDate     = null;
            string   note        = string.Empty;
            string   orderNumber = cn.justwin.Domain.BudTask.GetOrderNumber(this.prjId, this.taskId);
            string   str6        = string.Empty;
            int      num5        = 0;
            string   str7        = string.Empty;
            string   str8        = string.Empty;

            for (int i = this.startIndex; i < this.taskTable.Rows.Count; i++)
            {
                bool    flag = true;
                DataRow row  = this.taskTable.Rows[i];
                code = (row[this.codeIndex] == null) ? "" : row[this.codeIndex].ToString();
                string item = string.Empty;
                name     = (row[this.nameIndex] == null) ? "" : row[this.nameIndex].ToString();
                quantity = 0M;
                if (this.quantityIndex != -1)
                {
                    try
                    {
                        string str10 = row[this.quantityIndex].ToString().Trim();
                        if (!string.IsNullOrEmpty(str10))
                        {
                            quantity = decimal.Parse(str10);
                        }
                    }
                    catch
                    {
                        item = "在您的Excel中:编码" + code + ",工程量存在非有效的数字,请修改!";
                        errors.Add(item);
                        flag = false;
                    }
                }
                if (IsWBSRelevance == "0")
                {
                    if (this.unitPriceIndex != -1)
                    {
                        try
                        {
                            string str11 = row[this.unitPriceIndex].ToString().Trim();
                            if (!string.IsNullOrEmpty(str11))
                            {
                                num3 = decimal.Parse(str11);
                            }
                        }
                        catch
                        {
                            item = "在您的Excel中:编码" + code + ",综合单价存在非有效的数字,请修改!";
                            errors.Add(item);
                            flag = false;
                        }
                    }
                    if (this.totalIndex != -1)
                    {
                        try
                        {
                            num4 = quantity * num3;
                        }
                        catch
                        {
                            item = "在您的Excel中:编码" + code + ",综合单价存在非有效的数字,请修改!";
                            errors.Add(item);
                            flag = false;
                        }
                    }
                }
                unit = string.Empty;
                if (this.unitIndex != -1)
                {
                    unit = row[this.unitIndex].ToString();
                }
                if (this.startDateIndex != -1)
                {
                    try
                    {
                        string str12 = row[this.startDateIndex].ToString().Trim();
                        if (!string.IsNullOrEmpty(str12))
                        {
                            startDate = new DateTime?(Convert.ToDateTime(str12));
                        }
                        else
                        {
                            startDate = null;
                        }
                    }
                    catch
                    {
                        item = "在您的Excel中:编码" + code + ",存在非有效时间类型,请修改!";
                        errors.Add(item);
                        flag = false;
                    }
                }
                if (this.endDateIndex != -1)
                {
                    try
                    {
                        string str13 = row[this.endDateIndex].ToString();
                        if (!string.IsNullOrEmpty(str13))
                        {
                            endDate = new DateTime?(Convert.ToDateTime(str13));
                        }
                        else
                        {
                            endDate = null;
                        }
                    }
                    catch
                    {
                        item = "在您的Excel中:编码" + code + ",存在非有效时间类型,请修改!";
                        errors.Add(item);
                        flag = false;
                    }
                }
                if (this.noteIndex != -1)
                {
                    note = row[this.noteIndex].ToString();
                }
                if (this.constructionPeriodIndex != -1)
                {
                    try
                    {
                        num5 = Convert.ToInt32(row[this.constructionPeriodIndex]);
                    }
                    catch
                    {
                    }
                }
                if (this.featureDescriptionIndex != -1)
                {
                    str7 = row[this.featureDescriptionIndex].ToString();
                }
                if (row.Table.Columns.Contains("序号"))
                {
                    str8 = row["序号"].ToString();
                }
                if (!flag)
                {
                    item = "在您的Excel中:编码" + code + ",存在错误数据导致其子节点不能导入!";
                    errors.Add(item);
                    int    num7  = 0;
                    string str14 = orderNumberByLayer[i];
                    for (int j = i + 1; j < orderNumberByLayer.Count; j++)
                    {
                        if (orderNumberByLayer[j].StartsWith(str14))
                        {
                            num7++;
                        }
                    }
                    i += num7;
                }
                else
                {
                    num++;
                    string id                      = Guid.NewGuid().ToString();
                    string parentTaskId            = (this.taskId == "") ? null : this.taskId;
                    cn.justwin.Domain.BudTask task = null;
                    if (IsWBSRelevance == "1")
                    {
                        decimal?unitPrice = null;
                        decimal?total     = null;
                        task = cn.justwin.Domain.BudTask.Create(id, parentTaskId, null, this.prjId, code, name, unit, quantity, startDate, endDate, true, note, inputUser, DateTime.Now, unitPrice, total);
                    }
                    else
                    {
                        task = cn.justwin.Domain.BudTask.Create(id, parentTaskId, null, this.prjId, code, name, unit, quantity, startDate, endDate, true, note, inputUser, DateTime.Now, new decimal?(num3), new decimal?(num4));
                    }
                    string str17 = orderNumberByLayer[i].Substring(3);
                    if (string.IsNullOrEmpty(str17))
                    {
                        if (i > this.startIndex)
                        {
                            orderNumber = cn.justwin.Domain.BudTask.GetOrderNumber(this.prjId, this.taskId);
                        }
                        task.OrderNumber = orderNumber;
                    }
                    else
                    {
                        task.OrderNumber = orderNumber + str17;
                    }
                    if (i > 0)
                    {
                        int count = list.Count;
                        if (count > 0)
                        {
                            if ((orderNumberByLayer[i].Length - str6.Length) == 3)
                            {
                                task.ParentId = list[count - 1].Id;
                            }
                            else if ((orderNumberByLayer[i].Length - str6.Length) == 0)
                            {
                                task.ParentId = list[count - 1].ParentId;
                            }
                            else
                            {
                                int length = orderNumberByLayer[i].Length;
                                if (length == 3)
                                {
                                    task.ParentId = list[0].ParentId;
                                }
                                else if (length > 3)
                                {
                                    int differOrderNumber = list[0].OrderNumber.Length - orderNumberByLayer[0].Length;
                                    int num10             = list.FindLastIndex(t => t.OrderNumber.Length == (length + differOrderNumber));
                                    task.ParentId = list[num10].ParentId;
                                }
                            }
                        }
                    }
                    str6 = orderNumberByLayer[i];
                    list.Add(task);
                    cn.justwin.Domain.Entities.BudTask task2 = null;
                    BudTaskService service = new BudTaskService();
                    task2 = new cn.justwin.Domain.Entities.BudTask {
                        TaskId             = task.Id,
                        ParentId           = task.ParentId,
                        OrderNumber        = task.OrderNumber,
                        PrjId              = task.Prj,
                        InputUser          = task.InputUser,
                        InputDate          = task.InputDate,
                        IsValid            = true,
                        Version            = 1,
                        Modified           = null,
                        TaskCode           = task.Code,
                        TaskName           = task.Name,
                        StartDate          = task.StartDate,
                        EndDate            = task.EndDate,
                        Quantity           = new decimal?(task.Quantity),
                        UnitPrice          = task.UnitPrice,
                        Total              = task.Total,
                        Unit               = task.Unit,
                        Note               = task.Note,
                        ConstructionPeriod = new int?(num5),
                        FeatureDescription = str7,
                        TaskType           = "",
                        Total2             = 0
                    };
                    service.Add(task2);
                    if (!string.IsNullOrEmpty(str8))
                    {
                        this.AddSerialNoAndTaskId(str8, task.Id);
                    }
                    else
                    {
                        this.AddCodeAndTaskId(task.Code, task.Id);
                    }
                }
            }
            return(num);
        }