/// <summary> /// 保存流程模板 /// </summary> void SaveWorkflow() { WorkflowTemplate workflowTemplate = ReadRequestWorkflowTemplate(); XMLHelper xmlHelper = new XMLHelper(); XmlDocument xmlDocument = xmlHelper.CreateXmlRoot("Workflow"); Type type = typeof(WorkflowTemplate); PropertyInfo[] props = type.GetProperties(); foreach (var item in props) { switch (item.Name) { case "Activities": xmlHelper.CreatXmlNode("Workflow", "Activities", ""); foreach (var activtyItem in workflowTemplate.Activities) { XmlElement activtyEle = xmlDocument.CreateElement(((ActivityType)activtyItem.ActivityType) + string.Empty + "Activity"); activtyEle.AppendChild(XMLHelper.CreateXmlNode(xmlDocument, "ActivityType", ((ActivityType)activtyItem.ActivityType) + string.Empty)); activtyEle.AppendChild(XMLHelper.CreateXmlNode(xmlDocument, "Text", activtyItem.DisplayName)); activtyEle.AppendChild(XMLHelper.CreateXmlNode(xmlDocument, "ActivityCode", activtyItem.ActivityCode)); activtyEle.AppendChild(XMLHelper.CreateXmlNode(xmlDocument, "SortKey", activtyItem.SortKey + string.Empty)); activtyEle.AppendChild(XMLHelper.CreateXmlNode(xmlDocument, "Description", activtyItem.Description)); activtyEle.AppendChild(XMLHelper.CreateXmlNode(xmlDocument, "Height", activtyItem.Height + string.Empty)); activtyEle.AppendChild(XMLHelper.CreateXmlNode(xmlDocument, "Width", activtyItem.Width + string.Empty)); activtyEle.AppendChild(XMLHelper.CreateXmlNode(xmlDocument, "X", activtyItem.X + string.Empty)); activtyEle.AppendChild(XMLHelper.CreateXmlNode(xmlDocument, "Y", activtyItem.Y + string.Empty)); activtyEle.AppendChild(XMLHelper.CreateXmlNode(xmlDocument, "FontSize", activtyItem.FontSize + string.Empty)); activtyEle.AppendChild(XMLHelper.CreateXmlNode(xmlDocument, "Brush", activtyItem.FontColor)); activtyEle.AppendChild(XMLHelper.CreateXmlNode(xmlDocument, "EntryCondition", activtyItem.EntryCondition)); activtyEle.AppendChild(XMLHelper.CreateXmlNode(xmlDocument, "ID", activtyItem.ID + string.Empty)); activtyEle.AppendChild(XMLHelper.CreateXmlNode(xmlDocument, "Participants", activtyItem.Participants + string.Empty)); xmlDocument.SelectSingleNode("Workflow").SelectSingleNode("Activities").AppendChild(activtyEle); } break; case "Rules": xmlHelper.CreatXmlNode("Workflow", "Rules", ""); foreach (var ruleItem in workflowTemplate.Rules) { XmlElement rule = xmlDocument.CreateElement("Rule"); rule.AppendChild(XMLHelper.CreateXmlNode(xmlDocument, "Text", ruleItem.DisplayName)); rule.AppendChild(XMLHelper.CreateXmlNode(xmlDocument, "PreActivityCode", ruleItem.PreActivityCode)); rule.AppendChild(XMLHelper.CreateXmlNode(xmlDocument, "PostActivityCode", ruleItem.PostActivityCode)); rule.AppendChild(XMLHelper.CreateXmlNode(xmlDocument, "UtilizeElse", ruleItem.UtilizeElse + string.Empty)); rule.AppendChild(XMLHelper.CreateXmlNode(xmlDocument, "Formula", ruleItem.Formula)); rule.AppendChild(XMLHelper.CreateXmlNode(xmlDocument, "FontSize", ruleItem.FontSize + string.Empty)); rule.AppendChild(XMLHelper.CreateXmlNode(xmlDocument, "FontColor", ruleItem.FontColor)); rule.AppendChild(XMLHelper.CreateXmlNode(xmlDocument, "ID", ruleItem.ID)); XmlElement pointEle = xmlDocument.CreateElement("Points"); foreach (var pointItem in ruleItem.Points) { pointEle.AppendChild(XMLHelper.CreateXmlNode(xmlDocument, "Point", pointItem)); } rule.AppendChild(pointEle); xmlDocument.SelectSingleNode("Workflow").SelectSingleNode("Rules").AppendChild(rule); } break; case "WorkflowCode": case "InstanceName": case "Creator": case "ModifiedBy": case "CreatedTime": case "ModifiedTime": case "Description": case "Height": case "Width": case "BizObjectSchemaCode": xmlHelper.CreatXmlNode("Workflow", item.Name, item.GetValue(workflowTemplate) + string.Empty); break; default: break; } } string content = xmlDocument.InnerXml; List <OT_WorkflowTemplate> modelList = DapperHelper.CreateInstance().SimpleQuery <OT_WorkflowTemplate>(@"SELECT [ObjectID] ,[Content] ,[Creator] ,[ModifiedBy] ,[CreatedTime] ,[ModifiedTime] ,[WorkflowCode] ,[BizObjectSchemaCode] ,[ParentObjectID] ,[ParentPropertyName] ,[ParentIndex],ProcessName FROM [Work6-OA].[dbo].[OT_WorkflowTemplate] where WorkflowCode='" + workflowTemplate.WorkflowCode + "'"); OT_WorkflowTemplate model = modelList[0]; model.Content = content; int updateCount = DapperHelper.CreateInstance().UpdateTable <OT_WorkflowTemplate>("OT_WorkflowTemplate", model); if (updateCount > 0) { WriteResponse(true, null, null); } else { WriteResponse(false, null, null); } }