/// <summary> /// 增加dal访问 /// </summary> /// <param name="wfTemplateData">dal访问对象实体</param> public static bool Add(WfTemplateDataEntity entity) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into WF_TemplateData ("); strSql.Append(" TemplateID, TemplateName, TemplateEdition, TemplateData, CreateTime, Creater, IsEnable, TemplateType, IsDeleted, ModifyTime, ModifyPerson, BusinessType,StartDeptLevel,DepartmentID)"); strSql.Append(" values ( "); strSql.Append("@TemplateID, @TemplateName, @TemplateEdition, @TemplateData, @CreateTime, @Creater, @IsEnable, @TemplateType, @IsDeleted, @ModifyTime, @ModifyPerson, @BusinessType,@StartDeptLevel,@DepartmentID)"); SqlParameter[] parameters = { new SqlParameter("@TemplateID", SqlDbType.UniqueIdentifier), new SqlParameter("@TemplateName", SqlDbType.NVarChar), new SqlParameter("@TemplateEdition", SqlDbType.VarChar), new SqlParameter("@TemplateData", SqlDbType.NVarChar), new SqlParameter("@CreateTime", SqlDbType.DateTime), new SqlParameter("@Creater", SqlDbType.UniqueIdentifier), new SqlParameter("@IsEnable", SqlDbType.Bit), new SqlParameter("@TemplateType", SqlDbType.VarChar), new SqlParameter("@IsDeleted", SqlDbType.Bit), new SqlParameter("@ModifyTime", SqlDbType.DateTime), new SqlParameter("@ModifyPerson", SqlDbType.UniqueIdentifier), new SqlParameter("@BusinessType", SqlDbType.VarChar), new SqlParameter("@StartDeptLevel", SqlDbType.Int) , new SqlParameter("@DepartmentID", SqlDbType.VarChar) }; int i = 0; parameters[i++].Value = entity.TemplateID; parameters[i++].Value = entity.TemplateName; parameters[i++].Value = entity.TemplateVersion; parameters[i++].Value = entity.TemplateData; if (entity.CreateTime == DateTime.MinValue) entity.CreateTime = (DateTime)SqlDateTime.MinValue; parameters[i++].Value = entity.CreateTime; parameters[i++].Value = entity.Creater; parameters[i++].Value = entity.IsEnable; parameters[i++].Value = entity.TemplateType; parameters[i++].Value = entity.IsDeleted; if (entity.ModifyTime == DateTime.MinValue) entity.ModifyTime = (DateTime)SqlDateTime.MinValue; parameters[i++].Value = entity.ModifyTime; parameters[i++].Value = entity.ModifyPerson; parameters[i++].Value = entity.BusinessType; parameters[i++].Value = entity.StartDeptLevel; return DataHelper.ExecuteNoneQuery(strSql.ToString(), parameters) > 0; }
public SaveResult SaveWfTemplateXml(string xmlBase64) { try { var result = new SaveResult(); if (string.IsNullOrEmpty(xmlBase64)) { result.Result = false; result.Message = "输入字符串为空!"; return result; } var template = new WfTemplateDataEntity(); template.Creater = Guid.Empty; template.CreateTime = DateTime.Now; template.TemplateData = xmlBase64; var xElement = WorkFlowFromXml.GetXElementFromXml(Convert.FromBase64String(xmlBase64)); using (TransactionScope scope = new TransactionScope()) { var wf = WfTemplateDataBusiness.GetWfTemplateDataByTemplateID( new Guid(WorkFlowFromXml.GetXElementAttribute(xElement, "UniqueID"))); if (wf != null) //对已有模板的修改 { if (wf.IsEnable) //启用中的模板不允许修改 { result.Result = false; result.Message = "该模板正在启用中,不允许修改!"; return result; } else { WfTemplateDataBusiness.DeleteByPrimaryKey(wf.TemplateID); } } template.TemplateID = Guid.NewGuid(); template.TemplateName = WorkFlowFromXml.GetXElementAttribute(xElement, "Name"); template.TemplateVersion = WorkFlowFromXml.GetXElementAttribute(xElement, "Version"); template.BusinessType = WorkFlowFromXml.GetXElementAttribute(xElement, "BusinessType"); template.TemplateType = "xmlTemplate"; var wftemplate = new WfTemplateDataEntity(template.TemplateID, template.TemplateName, template.TemplateVersion, template.TemplateData, template.CreateTime, template.Creater, template.IsEnable, template.TemplateType, template.IsDeleted, template.ModifyTime, template.ModifyPerson, template.BusinessType, template.StartDeptLevel, template.DepartmentId); var workflow = WorkFlowFromXml.GetWfXamlFromXml(xElement, wftemplate); template.StartDeptLevel = wftemplate.StartDeptLevel; workflow.TemplateType = "xamlTemplate"; WfTemplateDataBusiness.Add(template); WfTemplateDataBusiness.Add(workflow); scope.Complete(); result.Result = true; result.Message = "成功!"; return result; } } catch (Exception exception) { var info = new ErrorInfo { Message = "保存模板出现错误:" + exception.Message }; LogWritter.WriteSystemExceptionLog(exception); throw new FaultException<ErrorInfo>(info, info.Message); } }
/// <summary> /// 获取实体信息 /// </summary> /// <param name="row">数据行</param> /// <returns></returns> private static WfTemplateDataEntity GetEntity(DataRow row) { WfTemplateDataEntity entity = new WfTemplateDataEntity(); entity.TemplateID = Guid.Parse(row["TemplateID"].ToString()); entity.TemplateName = row["TemplateName"].ToString(); entity.TemplateVersion = row["TemplateEdition"].ToString(); entity.TemplateData = row["TemplateData"].ToString(); if (row["CreateTime"] != DBNull.Value) entity.CreateTime = Convert.ToDateTime(row["CreateTime"]); entity.Creater = Guid.Parse(row["Creater"].ToString()); entity.IsEnable = Convert.ToBoolean(row["IsEnable"]); entity.TemplateType = row["TemplateType"].ToString(); entity.IsDeleted = Convert.ToBoolean(row["IsDeleted"]); if (row["ModifyTime"] != DBNull.Value) entity.ModifyTime = Convert.ToDateTime(row["ModifyTime"]); entity.ModifyPerson = Guid.Parse(row["ModifyPerson"].ToString()); entity.BusinessType = row["BusinessType"].ToString(); entity.StartDeptLevel = Convert.ToInt32(row["StartDeptLevel"]); entity.DepartmentId = row["DepartmentID"].ToString(); return entity; }
/// <summary> /// 更新dal访问 /// </summary> /// <param name="wF_TemplateData">dal访问</param> /// <returns>bool</returns> public static bool UpdateWfTemplateData(WfTemplateDataEntity entity) { StringBuilder strSql = new StringBuilder(); strSql.Append("update WF_TemplateData set "); strSql.Append("TemplateID = @TemplateID, "); strSql.Append("TemplateName = @TemplateName, "); strSql.Append("TemplateEdition = @TemplateEdition, "); strSql.Append("TemplateData = @TemplateData, "); strSql.Append("CreateTime = @CreateTime, "); strSql.Append("Creater = @Creater, "); strSql.Append("IsEnable = @IsEnable, "); strSql.Append("TemplateType = @TemplateType, "); strSql.Append("IsDeleted = @IsDeleted, "); strSql.Append("ModifyTime = @ModifyTime, "); strSql.Append("ModifyPerson = @ModifyPerson, "); strSql.Append("BusinessType = @BusinessType, "); strSql.Append("StartDeptLevel = @StartDeptLevel, "); strSql.Append("DepartmentID = @DepartmentID "); strSql.Append(" where "); strSql.Append(" TemplateID = @TemplateID "); SqlParameter[] parameters = { new SqlParameter("@TemplateID", SqlDbType.UniqueIdentifier), new SqlParameter("@TemplateName", SqlDbType.NVarChar), new SqlParameter("@TemplateEdition", SqlDbType.VarChar), new SqlParameter("@TemplateData", SqlDbType.NVarChar), new SqlParameter("@CreateTime", SqlDbType.DateTime), new SqlParameter("@Creater", SqlDbType.UniqueIdentifier), new SqlParameter("@IsEnable", SqlDbType.Bit), new SqlParameter("@TemplateType", SqlDbType.VarChar), new SqlParameter("@IsDeleted", SqlDbType.Bit), new SqlParameter("@ModifyTime", SqlDbType.DateTime), new SqlParameter("@ModifyPerson", SqlDbType.UniqueIdentifier), new SqlParameter("@BusinessType", SqlDbType.VarChar), new SqlParameter("@StartDeptLevel", SqlDbType.Int), new SqlParameter("@DepartmentID", SqlDbType.VarChar) }; int i = 0; parameters[i++].Value = entity.TemplateID; parameters[i++].Value = entity.TemplateName; parameters[i++].Value = entity.TemplateVersion; parameters[i++].Value = entity.TemplateData; if (entity.CreateTime == DateTime.MinValue) entity.CreateTime = (DateTime)SqlDateTime.MinValue; parameters[i++].Value = entity.CreateTime; parameters[i++].Value = entity.Creater; parameters[i++].Value = entity.IsEnable; parameters[i++].Value = entity.TemplateType; parameters[i++].Value = entity.IsDeleted; if (entity.ModifyTime == DateTime.MinValue) entity.ModifyTime = (DateTime)SqlDateTime.MinValue; parameters[i++].Value = entity.ModifyTime; parameters[i++].Value = entity.ModifyPerson; parameters[i++].Value = entity.BusinessType; parameters[i++].Value = entity.StartDeptLevel; parameters[i++].Value = entity.DepartmentId; return DataHelper.ExecuteNoneQuery(strSql.ToString(), parameters) > 0; }
public static WfTemplateDataEntity GetWfXamlFromXml(XElement xElement, WfTemplateDataEntity wfTemplateDataEntity) { try { IEnumerable<XElement> wfslElements = from item in xElement.Descendants("WFSLElement") select item; var templateId = new Guid(GetXElementAttribute(xElement, "UniqueID")); var templateName = GetXElementAttribute(xElement, "Name"); var startXmlNode = GetXmlNode(wfslElements, "WFSLElementType", "WFSLStart"); var firstXmlNode = GetXmlNode(wfslElements, "UniqueID", GetXElementAttribute(startXmlNode, "NextNodeID")); var firstStateName = GetXElementAttribute(firstXmlNode, "Title"); var firstStateGuid = GetXElementAttribute(firstXmlNode, "UniqueID"); var startDeptLevel = GetXElementAttribute(firstXmlNode, "DealDeptLevel"); var firstWfNode = GetStartNode(firstStateName, firstStateGuid, firstXmlNode); var resultListNodes = new Dictionary<string, FlowNode> { { GetXElementAttribute(firstXmlNode, "UniqueID"), firstWfNode } }; SaveStateInfo(firstXmlNode, templateId, true); if (!string.IsNullOrEmpty(GetXElementAttribute(firstXmlNode, "DealWayName"))) { var dealWayType = 0; IEnumerable<XElement> result = from s in wfslElements where s.Attribute("Title").Value == firstXmlNode.Attribute("DealWayName").Value && s.Attribute("PointStateId").Value == firstXmlNode.Attribute("NextNodeID").Value select s; if (result != null) { int.TryParse(GetXElementAttribute(result.ToList<XElement>()[0], "DealWayType"), out dealWayType); } SaveDealWay(new Guid(firstStateGuid), Guid.NewGuid(), GetXElementAttribute(firstXmlNode, "DealWayName"), firstXmlNode, templateId, dealWayType); } var num = GetNextNode(wfslElements, firstXmlNode, firstWfNode, ref resultListNodes, templateId); var activityBuilder = GetActivityBuilder(templateName, firstWfNode, resultListNodes, num); var xamlString = GetXamlString(activityBuilder); var xamlbase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(xamlString)); wfTemplateDataEntity.TemplateID = templateId; wfTemplateDataEntity.TemplateData = xamlbase64; wfTemplateDataEntity.StartDeptLevel = string.IsNullOrEmpty(startDeptLevel) ? 0 : Convert.ToInt32(startDeptLevel); return wfTemplateDataEntity; } catch (Exception ex) { LogWritter.WriteSystemExceptionLog(ex); throw new Exception("读取流程模板xml文件出现错误:" + ex.Message); } }