Exemplo n.º 1
0
        public int ConverBudTaskList(List <string> errors)
        {
            int            num                = 0;
            List <BudTask> list               = new List <BudTask>();
            List <string>  codeList           = this.GetCodeList();
            List <int>     layerByCode        = this.GetLayerByCode(codeList);
            List <string>  orderNumberByLayer = this.GetOrderNumberByLayer(layerByCode);
            string         code               = string.Empty;
            string         name               = string.Empty;
            string         unit               = string.Empty;
            decimal        quantity           = 0M;
            string         note               = string.Empty;
            string         orderNumber        = BudTask.GetOrderNumber(this.prjId, this.taskId);
            string         str6               = string.Empty;

            for (int i = this.startIndex; i < this.taskTable.Rows.Count; i++)
            {
                DataRow row  = this.taskTable.Rows[i];
                object  obj2 = row[this.taskTable.Columns.Count - 1];
                code = (row[this.codeIndex] == null) ? "" : row[this.codeIndex].ToString();
                string item = string.Empty;
                name     = (row[this.nameIndex] == null) ? "" : row[this.nameIndex].ToString();
                quantity = 0M;
                DateTime?startDate = null;
                DateTime?endDate   = null;
                if ((obj2 == null) || string.IsNullOrEmpty(obj2.ToString()))
                {
                    bool flag = true;
                    if (this.quantityIndex != -1)
                    {
                        try
                        {
                            string str8 = row[this.quantityIndex].ToString();
                            if (!string.IsNullOrEmpty(str8))
                            {
                                quantity = decimal.Parse(str8);
                            }
                        }
                        catch
                        {
                            item = "在您的Excel中:编码" + code + ",存在非有效的数字,请修改!";
                            errors.Add(item);
                            flag = false;
                        }
                    }
                    unit = string.Empty;
                    if (this.unitIndex != -1)
                    {
                        unit = row[this.unitIndex].ToString();
                    }
                    if (this.noteIndex != -1)
                    {
                        note = row[this.noteIndex].ToString();
                    }
                    if (!flag)
                    {
                        item = "在您的Excel中:编码" + code + ",存在错误数据导致其子节点不能导入!";
                        errors.Add(item);
                        int    num4 = 0;
                        string str9 = orderNumberByLayer[i];
                        for (int j = i + 1; j < orderNumberByLayer.Count; j++)
                        {
                            if (orderNumberByLayer[j].StartsWith(str9))
                            {
                                num4++;
                            }
                        }
                        i += num4;
                    }
                    else
                    {
                        num++;
                        string  id           = Guid.NewGuid().ToString();
                        string  parentTaskId = (this.taskId == "") ? null : this.taskId;
                        decimal?unitPrice    = null;
                        decimal?total        = null;
                        BudTask task         = BudTask.Create(id, parentTaskId, null, this.prjId, code, name, unit, quantity, startDate, endDate, true, note, this.inputUser, DateTime.Now, unitPrice, total);
                        string  str12        = orderNumberByLayer[i].Substring(3);
                        if (string.IsNullOrEmpty(str12))
                        {
                            if (i > this.startIndex)
                            {
                                orderNumber = BudTask.GetOrderNumber(this.prjId, this.taskId);
                            }
                            task.OrderNumber = orderNumber;
                        }
                        else
                        {
                            task.OrderNumber = orderNumber + str12;
                        }
                        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 num7 = list.FindLastIndex(t => t.OrderNumber.Length == (length + differOrderNumber));
                                        task.ParentId = list[num7].ParentId;
                                    }
                                }
                            }
                        }
                        str6 = orderNumberByLayer[i];
                        list.Add(task);
                        BudTask.Add(task, false);
                    }
                }
                else
                {
                    decimal result = 0M;
                    object  obj3   = row[this.priceIndex];
                    if (obj3 != null)
                    {
                        decimal.TryParse(obj3.ToString(), out result);
                    }
                    obj3 = row[this.quantityIndex];
                    if (obj3 != null)
                    {
                        decimal.TryParse(obj3.ToString(), out quantity);
                    }
                    this.AddTaskResource(code, name, result, quantity, list[list.Count - 1].Id, errors);
                }
            }
            return(num);
        }
Exemplo n.º 2
0
    protected void btnImport_Click(object sender, System.EventArgs e)
    {
        System.Collections.Generic.List <string> list = new System.Collections.Generic.List <string>();
        CheckBox checkBox = this.gvBudget.HeaderRow.Cells[0].FindControl("cbAllBox") as CheckBox;

        if (checkBox != null)
        {
            if (checkBox.Checked)
            {
                list = BudTemplateItem.GetTemplateItemIds(this.tvBudget.SelectedValue);
            }
            else
            {
                string value = this.hfldCheckedIds.Value;
                if (value.Contains('['))
                {
                    list = JsonHelper.GetListFromJson(value);
                }
                else
                {
                    list.Add(value);
                }
            }
        }
        string text = base.Request["prjId"];

        if (!string.IsNullOrEmpty(text))
        {
            string text2 = base.Request["taskId"];
            bool   flag  = true;
            if (string.IsNullOrEmpty(text2))
            {
                text2 = null;
                Project.CoverVersion(text);
            }
            else
            {
                flag = (BudTask.GetById(text2) != null);
            }
            bool flag2 = false;
            if (flag)
            {
                System.Collections.Generic.List <BudTemplateItem> list2 = new System.Collections.Generic.List <BudTemplateItem>();
                foreach (string current in list)
                {
                    BudTemplateItem byId = BudTemplateItem.GetById(current, this.tvBudget.SelectedValue);
                    list2.Add(byId);
                    if (byId != null)
                    {
                        flag2 = BudTask.CheckCode(byId.Code, text);
                        if (flag2)
                        {
                            break;
                        }
                    }
                }
                if (flag2)
                {
                    base.RegisterScript("alert('系统提示:\\n导入失败!\\n导入的模版中有节点的任务编码与已有的节点出现重复!');");
                    return;
                }
                list2 = (
                    from t in list2
                    orderby t.OrderNumber
                    select t).ToList <BudTemplateItem>();
                list.Clear();
                foreach (BudTemplateItem current2 in list2)
                {
                    list.Add(current2.Id.ToString());
                }
                bool   flag3 = BudTask.IsStructured(this.GetOrderNumbers(list));
                int    num   = 0;
                string start = string.Empty;
                System.Collections.Generic.List <BudTemplateItem> list3 = null;
                if (flag3)
                {
                    num   = this.GetOrderNumbers(list).Min((string m) => m.Length);
                    start = BudTask.GetOrderNumber(text, text2);
                    list3 = this.ChangeId(list, this.tvBudget.SelectedValue);
                }
                string inputUser = PageHelper.QueryUser(this, base.UserCode);
                int    num2      = 0;
                foreach (string current3 in list)
                {
                    BudTemplateItem budTemplateItem;
                    if (flag3)
                    {
                        budTemplateItem = list3[num2];
                    }
                    else
                    {
                        budTemplateItem    = BudTemplateItem.GetById(current3, this.tvBudget.SelectedValue);
                        budTemplateItem.Id = System.Guid.NewGuid().ToString();
                    }
                    string id           = budTemplateItem.Id;
                    string parentTaskId = string.Empty;
                    if (flag3)
                    {
                        parentTaskId = budTemplateItem.ParentId;
                    }
                    else
                    {
                        parentTaskId = text2;
                    }
                    BudTask budTask = BudTask.Create(id, parentTaskId, null, text, budTemplateItem.Code, budTemplateItem.Name, budTemplateItem.Unit, budTemplateItem.Quantity, null, null, true, budTemplateItem.Note, inputUser, System.DateTime.Now, null, null);
                    if (flag3)
                    {
                        if (budTemplateItem.OrderNumber.Length == num)
                        {
                            start            = BudTask.GetOrderNumber(text, text2);
                            budTask.ParentId = text2;
                        }
                        budTask.OrderNumber = this.GetNewOrderNumber(start, budTemplateItem.OrderNumber, num);
                    }
                    BudTask.Add(budTask, false);
                    System.Collections.Generic.List <TaskResource> list4 = BudTemplateItem.GetResourcesByTempItemId(current3).ToList <TaskResource>();
                    if (list4.Count > 0)
                    {
                        foreach (TaskResource current4 in list4)
                        {
                            budTask.AddResource(current4.Resource, current4.Quantity, current4.Price, 1m, "add");
                            BudTask.AddResource(budTask);
                        }
                    }
                    num2++;
                }
                string arg_3F6_0 = base.Request["year"];
                this.strJS.Append("top.ui.tabSuccess({ parentName: '_BudgetPlaitList' });");
            }
            else
            {
                this.strJS.Append("alert('系统提示:\\n导入失败!\\n导入的根节点已不存在!');");
            }
        }
        base.RegisterScript(this.strJS.ToString());
    }