protected void btnImport_Click(object sender, System.EventArgs e) { this.taskArray = this.hfldExcelColumns.Value.Split(new char[] { ',' }); this.resourceArray = this.hfldResource.Value.Split(new char[] { ',' }); this.hfldExcelColumns.Value = string.Empty; this.hfldResource.Value = string.Empty; if (this.ViewState["ExcelName"] != null && !string.IsNullOrEmpty(this.ViewState["ExcelName"].ToString())) { bool flag = true; if (string.IsNullOrEmpty(this.taskId)) { this.dtWBS = (this.ViewState["dtwbs"] as DataTable); if (this.dtWBS.Rows.Count > 0) { if (this.hfldIsWBSRelevance.Value == "1") { Project.CoverVersion(this.prjId); } else { Project.CoverVersionNew(this.prjId, this.version); } } } else { flag = (BudTask.GetById(this.taskId) != null); } if (flag) { BudTaskServices budTaskServices = new BudTaskServices(this.taskId, this.prjId, this.version, this.dtWBS); bool flag2 = false; System.Collections.Generic.IDictionary <string, int> relation = ExcelUtility.GetRelation(this.taskArray); int num = -1; int num2 = -1; string str = string.Empty; if (relation.Keys.Contains("TaskCode")) { num2 = relation["TaskCode"]; } if (relation.Keys.Contains("SerialNo")) { num = relation["SerialNo"]; } if (num != -1) { str = this.dtWBS.Columns[num].ColumnName; this.dtWBS.DefaultView.Sort = str + " DESC"; for (int i = 1; i < this.dtWBS.Rows.Count; i++) { if (this.dtWBS.Rows[i][num].ToString().Trim() == this.dtWBS.Rows[i - 1][num].ToString().Trim()) { flag2 = true; break; } } } else { if (num2 != -1) { str = this.dtWBS.Columns[num2].ColumnName; this.dtWBS.DefaultView.Sort = str + " DESC"; for (int j = 1; j < this.dtWBS.Rows.Count; j++) { if (this.dtWBS.Rows[j][num2].ToString().Trim() == this.dtWBS.Rows[j - 1][num2].ToString().Trim()) { flag2 = true; break; } } } } if (flag2) { base.RegisterScript("top.ui.alert('导入失败!\\n导入的Excel中有节点的任务编码出现重复,请修改!');"); return; } if (num == -1 && num2 != -1) { foreach (DataRow dataRow in this.dtWBS.Rows) { string code = (dataRow[num2] == null) ? "" : dataRow[num2].ToString(); flag2 = BudTask.CheckCode(code, this.prjId); if (flag2) { break; } } } if (flag2) { base.RegisterScript("top.ui.alert('导入失败!\\n导入的Excel中有节点的任务编码与已有的节点出现重复,请修改!');"); base.RegisterScript("top.ui._BudgetPlaitList.location.href = top.ui._BudgetPlaitList.location.href;"); return; } this.inputUser = PageHelper.QueryUser(this, base.UserCode); int num3 = budTaskServices.ConverBudTaskList(this.taskArray, this.inputUser, this.errors, this.hfldIsWBSRelevance.Value); this.AddResource(); string text = "成功"; if (num3 == 0) { text = "失败"; } string text2 = string.Empty; if (this.errors.Count > 0) { this.ViewState["errors"] = this.errors; this.ShowErrors(); text2 = "\\n部分节点导入失败,详见“警告信息”!"; base.RegisterScript(string.Concat(new string[] { "top.ui.show('Excel导入", text, "!", text2, "');" })); return; } base.RegisterScript("top.ui._BudgetPlaitList.location.href = top.ui._BudgetPlaitList.location.href;"); base.RegisterScript(string.Concat(new string[] { "top.ui.show('Excel导入", text, "!", text2, "');" })); base.RegisterScript("top.ui.closeTab();"); return; } else { base.RegisterScript("top.ui.alert('Excel导入失败!\\n你选择要导入的上级节点已不存在!');"); base.RegisterScript("top.ui._BudgetPlaitList.location.href = top.ui._BudgetPlaitList.location.href;"); } } }
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()); }