protected void btnSaveTemplate_Click(object sender, System.EventArgs e) { bool flag = base.Request["saveAs"] != null; if (flag) { this.strJS.Append("alert('系统提示:\\n已保存为新模板,不能重复保存!');"); } else { string text = (this.Session["taskIds"] == null) ? "" : this.Session["taskIds"].ToString(); if (!string.IsNullOrEmpty(text)) { System.Collections.Generic.List <string> list = new System.Collections.Generic.List <string>(); if (text.Contains("[")) { list = JsonHelper.GetListFromJson(text); } else { list.Add(text); } BudTask.GetOrderNumberById(list); this.hdtemplateName.Value.Trim(); string empty = string.Empty; this.AddTemplate(ref empty); string inputUser = PageHelper.QueryUser(this, base.UserCode); BudTemplateItem.SaveTemplate(list, empty, "", inputUser); this.strJS.Append("alert('系统提示:\\n保存成功!');"); this.strJS.Append(string.Concat(new string[] { "location='SelectTemplate.aspx?type=", this.ddlType.SelectedValue, "&template=", empty, "&saveAs=1';" })); this.ViewState["saveAs"] = true; this.btnSaveAs.Disabled = true; } } base.RegisterScript(this.strJS.ToString()); }
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++; } }