public static void SaveTemplate(List <string> lsttaskIds, string templateId, string saveNodeId, string inputUser) { if (!string.IsNullOrEmpty(saveNodeId) && (((GetById(saveNodeId, templateId) == null) ? 0 : 1) == 0)) { throw new Exception("你选择的根节点不存在,请刷新查看!"); } bool flag2 = true; List <string> orderNumberList = new List <string>(); orderNumberList = BudTask.GetOrderNumberById(lsttaskIds); if (lsttaskIds.Count > 1) { flag2 = BudTask.IsStructured(orderNumberList); } List <BudTask> list2 = null; int length = 0; string start = string.Empty; if (flag2) { list2 = BudTask.ChangeId(lsttaskIds); start = GetNextOrderNumber(templateId, saveNodeId); length = orderNumberList.Min <string>((System.Func <string, int>)(m => m.Length)); } int num2 = 0; foreach (string str2 in lsttaskIds) { BudTask task = null; if (flag2) { task = list2[num2]; } else { task = BudTask.GetById(str2); task.Id = Guid.NewGuid().ToString(); } string id = task.Id; string parentId = string.Empty; if (flag2) { parentId = task.ParentId; } else { parentId = saveNodeId; } cn.justwin.Domain.BudTemplate byId = cn.justwin.Domain.BudTemplate.GetById(templateId); BudTemplateItem budTemplateItem = Create(id, parentId, byId, task.Code, task.Name, task.Unit, task.Quantity, task.UnitPrice, task.Note, ""); if (flag2) { if (task.OrderNumber.Length == length) { start = GetNextOrderNumber(templateId, saveNodeId); budTemplateItem.ParentId = (saveNodeId == "") ? null : saveNodeId; } budTemplateItem.OrderNumber = GetNewOrderNumber(start, task.OrderNumber, length); } Add(budTemplateItem); List <TaskResource> list3 = BudTask.GetResourcesByTaskId(str2).ToList <TaskResource>(); if (list3.Count > 0) { foreach (TaskResource resource in list3) { budTemplateItem.AddResource(resource.Resource, budTemplateItem.Quantity, resource.Price, inputUser, DateTime.Now, "add", 0M); AddResource(budTemplateItem); } } num2++; } }