Пример #1
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());
    }