/// <summary>
        /// 获取设计后的表单URL地址
        /// </summary>
        /// <param name="Page"></param>
        /// <param name="Sheet"></param>
        /// <returns></returns>
        public string GetDesignerSheetAddress(BizSheet Sheet)
        {
            // 表单文件名称
            string sheetAddress   = Sheet.SheetAddress == string.Empty ? Sheet.SheetCode + ".aspx" : Sheet.SheetAddress;
            string sheetDirectory = "Sheets/" + AppUtility.Engine.EngineConfig.Code + "/" + Sheet.BizObjectSchemaCode;

            // 表单存储路径
            sheetAddress = Path.Combine(sheetDirectory, sheetAddress);
            // 获取完整的表单路径
            string sheetAddressFullPath = Path.Combine(Server.MapPath("."), sheetAddress);

            bool created = false;

            if (!System.IO.File.Exists(sheetAddressFullPath))
            {
                if (!Directory.Exists(Path.Combine(Server.MapPath("."), sheetDirectory)))
                {
                    Directory.CreateDirectory(Path.Combine(Server.MapPath("."), sheetDirectory));
                }
                created = true;
            }
            else
            {
                FileInfo f = new FileInfo(sheetAddressFullPath);
                if (f.LastWriteTime < Sheet.LastModifiedTime)
                {
                    created = true;
                }
            }

            if (created)
            {
                // 生成文件
                string cs   = Sheet.CodeContent;
                string aspx = string.Empty;
                if (cs == string.Empty)
                {
                    cs = GetCSharpCode(AppUtility.Engine.EngineConfig.Code, Sheet.SheetCode);
                }
                if (Sheet.IsMVC)
                {
                    aspx = GetMvcSheetAspx(AppUtility.Engine.EngineConfig.Code, Sheet.SheetCode, Sheet.RuntimeContent, Sheet.Javascript);
                }
                //else
                //{
                //    aspx = GetSheetAspx(AppUtility.Engine.EngineConfig.Code, Sheet.SheetCode, Sheet.RuntimeContent, Sheet.Javascript);
                //}

                using (StreamWriter sw = new StreamWriter(sheetAddressFullPath, false, Encoding.UTF8))
                {
                    sw.Write(aspx);
                }
                using (StreamWriter sw = new StreamWriter(sheetAddressFullPath + ".cs", false, Encoding.UTF8))
                {
                    sw.Write(cs);
                }
            }

            return(sheetAddress);
        }
Esempio n. 2
0
 /// <summary>
 /// 获取打印表单的URL地址
 /// </summary>
 /// <param name="Sheet"></param>
 /// <param name="WorkItemID"></param>
 /// <returns></returns>
 public static string GetPrintSheetUrl(BizSheet Sheet, string WorkItemID, string InstanceId)
 {
     if (!string.IsNullOrEmpty(Sheet.PrintModel))
     {
         return(System.IO.Path.Combine(PortalRootForUrl, "SheetPrint.aspx").Replace('\\', '/') + "?" +
                "InstanceId=" + InstanceId + "&" +
                "WorkItemID=" + WorkItemID + "&" +
                "Mode=Print" + "&" +
                "SheetCode=" + Sheet.SheetCode);
     }
     else if (!string.IsNullOrEmpty(Sheet.PrintSheetAddress))
     {
         string url = string.Empty;
         if (Sheet.PrintSheetAddress.StartsWith("~/"))
         {
             url = Sheet.PrintSheetAddress;
         }
         else
         {
             url = System.IO.Path.Combine(PortalRootForUrl, Sheet.PrintSheetAddress).Replace('\\', '/');
         }
         return(url + "?" +
                "WorkItemID=" + WorkItemID + "&" +
                "Mode=Print" + "&" +
                "SheetCode=" + Sheet.SheetCode);
     }
     return(string.Empty);
 }
        public string GetViewSheetUrl(
            WorkItem.WorkItem WorkItem,
            BizSheet Sheet,
            SheetMode SheetMode,
            bool IsMobile)
        {
            string baseUrl = GetSheetBaseUrl(SheetMode.View, IsMobile, Sheet);

            baseUrl += SheetEnviroment.Param_Mode + "=" + SheetMode + "&";
            baseUrl += SheetEnviroment.Param_WorkItemID + "=" + WorkItem.WorkItemID + "&";
            return(baseUrl);
        }
 public JsonResult GetWorkSheet(string id, string parentId, string parentCode)
 {
     return(ExecuteFunctionRun(() =>
     {
         ActionResult result = new ActionResult();
         string root = this.Engine.FunctionAclManager.GetFunctionNode(parentId).DisplayName;
         if (string.IsNullOrEmpty(id))
         {
             WorkSheetViewModel model = new WorkSheetViewModel()
             {
                 SortKey = "1",
                 Type = "true",
                 Root = root,
                 isMobileAdd = true,
                 isPrintAdd = true,
                 ParentCode = parentCode,
                 ParentId = parentId
             };
             result.Extend = model;
         }
         else
         {
             BizSheet workflowSheet = this.Engine.BizSheetManager.GetBizSheetByID(id);
             WorkSheetViewModel model = new WorkSheetViewModel()
             {
                 SortKey = "1",
                 Type = (workflowSheet.SheetType == SheetType.DefaultSheet).ToString().ToLower(),
                 Root = root,
                 isMobileAdd = string.IsNullOrEmpty(workflowSheet.MobileSheetAddress),
                 isPrintAdd = string.IsNullOrEmpty(workflowSheet.PrintSheetAddress),
                 ParentCode = parentCode,
                 ParentId = parentId,
                 ObjectID = workflowSheet.ObjectID,
                 Code = workflowSheet.SheetCode,
                 MobileAdd = workflowSheet.MobileSheetAddress,
                 PrintAdd = workflowSheet.PrintSheetAddress,
                 Name = workflowSheet.DisplayName,
                 PCAdd = workflowSheet.SheetAddress
             };
             result.Extend = model;
         }
         return Json(result, JsonRequestBehavior.AllowGet);
     }));
 }
        /// <summary>
        /// 获取待办任务的链接地址
        /// </summary>
        /// <param name="WorkItem"></param>
        /// <param name="Sheet"></param>
        /// <param name="IsMobile"></param>
        /// <returns></returns>
        public string GetWorkSheetUrl(
            WorkItem.WorkItem WorkItem,
            BizSheet Sheet,
            bool IsMobile)
        {
            if (WorkItem == null)
            {
                return(null);
            }
            string baseUrl = string.Empty;

            baseUrl  = GetSheetBaseUrl(SheetMode.Work, IsMobile, Sheet);
            baseUrl += SheetEnviroment.Param_Mode + "=" + SheetMode.Work + "&";
            if (WorkItem != null)
            {
                baseUrl += SheetEnviroment.Param_WorkItemID + "=" + WorkItem.WorkItemID + "&";
            }
            return(baseUrl);
        }
        public string GetSheetBaseUrl(SheetMode SheetMode, bool IsMobile, BizSheet Sheet)
        {
            string baseUrl = null;

            switch (Sheet.SheetType)
            {
            case SheetType.None:
                baseUrl = null;
                break;

            case SheetType.DefaultSheet:
                baseUrl = this.GetDefaultSheetUrl(Sheet, IsMobile);
                break;

            case SheetType.CustomSheet:
                string sheetUrl = GetWorkItemSheet(IsMobile, SheetMode, Sheet.MobileSheetAddress, Sheet.SheetAddress, Sheet.PrintSheetAddress);
                if (sheetUrl.LastIndexOf("?") == -1)
                {
                    // url的形式应该是http://.../page1.aspx
                    baseUrl = sheetUrl + "?";
                }
                else if (sheetUrl.LastIndexOf("?") == sheetUrl.Length - 1 ||
                         sheetUrl.LastIndexOf("&") == sheetUrl.Length - 1)
                {
                    // url的形式应该是http://.../page1.aspx?
                    // url的形式应该是http://.../page1.aspx?param1=value1&
                    baseUrl = sheetUrl;
                }
                else
                {
                    // url的形式应该是http://.../page1.aspx?param1=value1
                    baseUrl = sheetUrl + "&";
                }
                break;

            default:
                throw new NotImplementedException();
            }
            return(baseUrl);
        }
        /// <summary>
        /// 获取默认表单URL
        /// </summary>
        /// <param name="Page"></param>
        /// <returns></returns>
        private string GetDefaultSheetUrl(BizSheet Sheet)
        {
            string SheetUrl = string.Empty;

            if (Sheet.EnabledCode)
            {
                SheetUrl = System.IO.Path.Combine(this.PortalRoot, GetDesignerSheetAddress(Sheet));
            }
            else
            {
                if (Sheet.IsMVC)
                {
                    SheetUrl = System.IO.Path.Combine(this.PortalRoot, "MvcDefaultSheet.aspx").Replace('\\', '/');
                }
                else
                {
                    SheetUrl = System.IO.Path.Combine(this.PortalRoot, "DefaultSheet.aspx").Replace('\\', '/');
                }
            }
            SheetUrl += "?";// +Param_SheetCode + "=" + Sheet.SheetCode + "&";
            return(SheetUrl);
        }
Esempio n. 8
0
        public JsonResult StartInstance(string paramString)
        {
            ActionResult result = new ActionResult(false, "");
            Dictionary <string, string> dicParams = JsonConvert.DeserializeObject <Dictionary <string, string> >(paramString);
            string WorkflowCode = string.Empty, SchemaCode = string.Empty, InstanceName = string.Empty; int WorkflowVersion = WorkflowTemplate.WorkflowDocument.NullWorkflowVersion; bool IsMobile = false;
            string SheetCode = string.Empty; string LoginName = string.Empty; string MobileToken = string.Empty;
            string WechatCode = string.Empty; string EngineCode = string.Empty;
            Dictionary <string, string> dicOtherParams = new Dictionary <string, string>();

            //读取URL参数
            foreach (string key in dicParams.Keys)
            {
                if (key == Param_WorkflowCode)
                {
                    WorkflowCode = dicParams[key]; continue;
                }
                if (key == Param_SchemaCode)
                {
                    SchemaCode = dicParams[key]; continue;
                }
                if (key == Param_WorkflowVersion)
                {
                    int.TryParse(dicParams[key], out WorkflowVersion); continue;
                }
                if (key == Param_IsMobile)
                {
                    bool.TryParse(dicParams[key], out IsMobile); continue;
                }
                if (key == Param_SheetCode)
                {
                    SheetCode = dicParams[key]; continue;
                }
                if (key == Param_InstanceName)
                {
                    InstanceName = dicParams[key]; continue;
                }
                if (key.ToLower() == "loginname")
                {
                    LoginName = dicParams[key]; continue;
                }
                if (key.ToLower() == "mobiletoken")
                {
                    MobileToken = dicParams[key]; continue;
                }
                if (key.ToLower() == "code")
                {
                    WechatCode = dicParams[key];
                }
                if (key.ToLower() == "state")
                {
                    EngineCode = dicParams[key];
                }
                dicOtherParams.Add(key, dicParams[key]);
            }
            //TODO:微信不需要做单点登录
            ////实现微信单点登录
            //if (!string.IsNullOrEmpty(WechatCode) && !string.IsNullOrEmpty(EngineCode)
            //    && System.Web.HttpContext.Current.Session[Sessions.GetUserValidator()] != null)
            //{
            //    IsMobile = true;
            //    UserValidatorFactory.LoginAsWeChat(EngineCode, WechatCode);
            //}
            //APP打开表单验证
            if (!string.IsNullOrEmpty(LoginName) && !string.IsNullOrEmpty(MobileToken) && this.UserValidator == null)
            {
                if (!SSOopenSheet(LoginName, MobileToken))
                {
                    result = new ActionResult(false, "登录超时!", null, ExceptionCode.NoAuthorize);
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }
            }
            else if (this.UserValidator == null)
            {
                result = new ActionResult(false, "登录超时!", null, ExceptionCode.NoAuthorize);
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            //计算 WorkflowCode
            if (WorkflowCode == string.Empty && !string.IsNullOrEmpty(SchemaCode))
            {
                WorkflowClause[] clauses = this.Engine.WorkflowManager.GetClausesBySchemaCode(SchemaCode);
                if (clauses != null)
                {
                    foreach (WorkflowClause clause in clauses)
                    {
                        if (clause.DefaultVersion > 0)
                        {
                            WorkflowCode = clause.WorkflowCode;
                        }
                    }
                }
            }
            //流程版本号
            if (WorkflowVersion == WorkflowTemplate.WorkflowDocument.NullWorkflowVersion || WorkflowVersion == 0)
            {
                WorkflowVersion = this.Engine.WorkflowManager.GetWorkflowDefaultVersion(WorkflowCode);
            }

            //流程优先级
            OThinker.H3.Instance.PriorityType Priority = OThinker.H3.Instance.PriorityType.Normal;
            if (dicParams.ContainsKey(Param_Priority))
            {
                string strPriority = dicParams[Param_Priority];

                Priority = (OThinker.H3.Instance.PriorityType)Enum.Parse(typeof(OThinker.H3.Instance.PriorityType), strPriority);
            }

            try
            {
                if (string.IsNullOrEmpty(WorkflowCode))
                {
                    result.Message = "StartInstance.StartInstance_Msg0";
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }
                // 获得工作流模板
                PublishedWorkflowTemplate workflow = this.Engine.WorkflowManager.GetPublishedTemplate(WorkflowCode, WorkflowVersion);
                if (workflow == null)
                {
                    result.Message = "StartInstance.StartInstance_Msg1";
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }
                DataModel.BizObjectSchema schema = this.Engine.BizObjectManager.GetPublishedSchema(workflow.BizObjectSchemaCode);
                // 开始节点
                ClientActivity startActivity = null;
                // 开始的表单
                BizSheet startSheet = null;
                System.Text.StringBuilder instanceParamBuilder = new System.Text.StringBuilder();
                if (dicOtherParams.Count > 0)
                {
                    foreach (string key in dicOtherParams.Keys)
                    {
                        instanceParamBuilder.Append(string.Format("&{0}={1}", key, dicOtherParams[key]));
                    }
                }

                startActivity = workflow.GetActivityByCode(workflow.StartActivityCode) as ClientActivity;
                if (!string.IsNullOrEmpty(SheetCode))
                {
                    startSheet = this.Engine.BizSheetManager.GetBizSheetByCode(SheetCode);
                }
                if (startSheet == null)
                {
                    if (!string.IsNullOrEmpty(startActivity.SheetCode))
                    {
                        startSheet = this.Engine.BizSheetManager.GetBizSheetByCode(startActivity.SheetCode);
                    }
                    else
                    {
                        BizSheet[] sheets = this.Engine.BizSheetManager.GetBizSheetBySchemaCode(workflow.BizObjectSchemaCode);
                        if (sheets != null && sheets.Length > 0)
                        {
                            startSheet = sheets[0];
                        }
                    }
                }

                if (workflow.StartWithSheet &&
                    startActivity != null &&
                    startSheet != null)
                {
                    string url = this.GetSheetBaseUrl(
                        SheetMode.Originate,
                        IsMobile,
                        startSheet);
                    url = url +
                          SheetEnviroment.Param_Mode + "=" + SheetMode.Originate + "&" +
                          Param_WorkflowCode + "=" + System.Web.HttpUtility.UrlEncode(workflow.WorkflowCode) + "&" +
                          Param_WorkflowVersion + "=" + workflow.WorkflowVersion +
                          //(string.IsNullOrEmpty(SheetCode)?"":("&"+Param_SheetCode+"="+SheetCode))+
                          (instanceParamBuilder.Length == 0 ? string.Empty : ("&" + instanceParamBuilder.ToString()));
                    //URL
                    result.Message = url;
                }
                else
                {
                    // 发起流程
                    string instanceId = Guid.NewGuid().ToString().ToLower();
                    string workItemId = null;
                    string error      = null;
                    OThinker.H3.DataModel.BizObject bo = new DataModel.BizObject(this.UserValidator.Engine, schema, this.UserValidator.UserID);
                    bo.Create();

                    if (!SheetUtility.OriginateInstance(
                            this.Engine,
                            bo.ObjectID,
                            workflow,
                            schema,
                            ref instanceId,
                            this.UserValidator.UserID,
                            null,
                            null,
                            OThinker.H3.Instance.PriorityType.Unspecified,
                            null,
                            null,
                            null,
                            ref workItemId,
                            ref error, false))
                    {
                        result.Message = error;
                    }
                    string startInstanceUrl = this.GetInstanceUrl(instanceId, workItemId);
                    startInstanceUrl += (instanceParamBuilder.Length == 0 ? null : ("&" + instanceParamBuilder.ToString()));
                    result.Message    = startInstanceUrl;
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                return(Json(result, JsonRequestBehavior.AllowGet));
            }

            result.Success = true;
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public BizSheet GetWorkItemSheet(WorkItem.WorkItem CurrentWorkItem)
        {
            BizSheet workItemSheet = this.Engine.BizSheetManager.GetBizSheetByCode(CurrentWorkItem.SheetCode);

            return(workItemSheet);
        }
        public JsonResult WorkItemDetail(string paramString)
        {
            return(ExecuteFunctionRun(() =>
            {
                ActionResult result = new ActionResult(false, "");
                Dictionary <string, string> dicParams = JsonConvert.DeserializeObject <Dictionary <string, string> >(paramString);

                string strMode = string.Empty, WorkItemID = string.Empty, strIsMobile = string.Empty,
                state = string.Empty;
                Dictionary <string, string> dicOtherParams = new Dictionary <string, string>();
                //读取URL参数
                foreach (string key in dicParams.Keys)
                {
                    if (key == Param_Mode)
                    {
                        strMode = dicParams[key]; continue;
                    }
                    if (key == Param_WorkItemID)
                    {
                        WorkItemID = dicParams[key]; continue;
                    }
                    if (key == Param_IsMobile)
                    {
                        strIsMobile = dicParams[key]; continue;
                    }
                    if (key == "state")
                    {
                        state = dicParams["state"]; continue;
                    }
                    dicOtherParams.Add(key, dicParams[key]);
                }
                //Work、View。。。
                SheetMode Mode = this.GetSheetMode(strMode, WorkItemID);
                //WorkItem
                WorkItem.WorkItem CurrentWorkItem = this.GetCurrentWorkItem(WorkItemID);
                //获取工作任务的表单对象
                BizSheet WorkItemSheet = this.GetWorkItemSheet(CurrentWorkItem);
                bool IsMobile = this.IsMobile(strIsMobile, state);

                // 解析Url地址
                if (Mode == SheetMode.Work)
                {
                    url = this.GetWorkSheetUrl(CurrentWorkItem, WorkItemSheet, IsMobile);
                }
                else
                {
                    url = this.GetViewSheetUrl(CurrentWorkItem, WorkItemSheet, Mode, IsMobile);
                }
                // 将其中的数据参数做转换
                InstanceData InstanceData = this.GetInstanceData(CurrentWorkItem);
                if (url.Contains(OThinker.H3.Math.Variant.VariablePrefix.ToString()))
                {
                    url = InstanceData.ParseText(url);
                }
                // 处理缓存
                DateTime t = DateTime.Now;
                DateTime.TryParse(InstanceData.BizObject[OThinker.Organization.Unit.PropertyName_ModifiedTime] + string.Empty, out t);
                url += "&T=" + t.ToString("HHmmss") + WorkItemID.Substring(0, 8);
                if (Mode == SheetMode.Print)
                {
                    url += "Print";
                }
                result.Success = true;
                result.Message = url;
                return Json(result);
            }));
        }
 /// <summary>
 /// 获取默认表单URL
 /// </summary>
 /// <param name="Page"></param>
 /// <returns></returns>
 private string GetDefaultSheetUrl(BizSheet Sheet, bool isMobile)
 {
     return(GetDefaultSheetUrl(Sheet) + (isMobile ? "IsMobile=" + isMobile + "&" : ""));
 }
Esempio n. 12
0
        /// <summary>
        /// 读取导入的XML文件
        /// </summary>
        /// <param name="mapPath"></param>
        private void ReadXmlFile(WorkflowPackageImportViewModel model)
        {
            //从服务器加载
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(Session[model.XMLString].ToString());
            XmlElement BizWorkflowPackage = xmlDoc.DocumentElement;//根节点

            //流程包编码、名称
            PackageCode = BizWorkflowPackage.GetElementsByTagName("PackageCode")[0].InnerXml;
            PackageName = BizWorkflowPackage.GetElementsByTagName("PackageName")[0].InnerXml;
            //流程包
            XmlNodeList packageNodes = BizWorkflowPackage.GetElementsByTagName("FunctionNode");

            if (packageNodes != null && packageNodes.Count > 0)
            {
                XmlNode openNewWindow = packageNodes[0].SelectSingleNode("OpenNewWindow");
                if (openNewWindow != null)
                {
                    openNewWindow.InnerText = openNewWindow.InnerText.ToLower();
                }
                package            = Convertor.XmlToObject(typeof(FunctionNode), packageNodes[0].OuterXml) as FunctionNode;
                package.ParentCode = model.ParentCode;
            }

            //数据模型
            XmlNodeList bizObjectSchemaNodes = BizWorkflowPackage.GetElementsByTagName("BizObjectSchema");

            if (bizObjectSchemaNodes != null && bizObjectSchemaNodes.Count > 0)
            {
                BizObjectSchema = (DataModel.BizObjectSchema)Convertor.XmlToObject(typeof(DataModel.BizObjectSchema), bizObjectSchemaNodes[0].OuterXml);
                //监听实例
                XmlNodeList bizListenerPolicyNodes = BizWorkflowPackage.GetElementsByTagName("BizListenerPolicy");
                if (bizListenerPolicyNodes != null && bizListenerPolicyNodes.Count > 0)
                {
                    bizListenerPolicy = Convertor.XmlToObject(typeof(BizListenerPolicy), bizListenerPolicyNodes[0].OuterXml) as BizListenerPolicy;
                }
                //定时作业
                XmlNodeList scheduleInvokerNodes = BizWorkflowPackage.GetElementsByTagName("ScheduleInvokers");
                if (scheduleInvokerNodes != null && scheduleInvokerNodes.Count > 0)
                {
                    scheduleInvokerList = new List <ScheduleInvoker>();
                    foreach (XmlNode scheduleInvoker in scheduleInvokerNodes[0].ChildNodes)
                    {
                        scheduleInvokerList.Add(Convertor.XmlToObject(typeof(ScheduleInvoker), scheduleInvoker.OuterXml) as ScheduleInvoker);
                    }
                }
                //查询列表
                XmlNodeList bizQueryNodes = BizWorkflowPackage.GetElementsByTagName("BizQueries");
                if (bizQueryNodes != null && bizQueryNodes.Count > 0)
                {
                    bizQueryList = new List <BizQuery>();
                    foreach (XmlNode query in bizQueryNodes[0].ChildNodes)
                    {
                        bizQueryList.Add(Convertor.XmlToObject(typeof(BizQuery), query.OuterXml) as BizQuery);
                    }
                }
            }

            //流程表单
            XmlNode     SheetRoot = BizWorkflowPackage.GetElementsByTagName("BizSheets")[0];
            XmlNodeList Sheets    = ((XmlElement)SheetRoot).GetElementsByTagName("BizSheet");

            BizSheets = new List <BizSheet>();
            foreach (XmlNode node in Sheets)
            {
                BizSheet sheet = (BizSheet)Convertor.XmlToObject(typeof(BizSheet), node.OuterXml);
                if (sheet.SheetType == SheetType.DefaultSheet)
                {//清空默认表单
                    sheet.SheetAddress = string.Empty;
                }
                var BizSheetModel = (BizSheet)Convertor.XmlToObject(typeof(BizSheet), node.OuterXml);
                //处理旧版本的默认表单的发起时间绑定字段是OriginateDate 而新版本的是OriginateTime 做兼容处理
                if (BizSheetModel.DesignModeContent != null)
                {
                    BizSheetModel.DesignModeContent = BizSheetModel.DesignModeContent.Replace(@"OriginateDate", "OriginateTime");
                }
                if (BizSheetModel.RuntimeContent != null)
                {
                    BizSheetModel.RuntimeContent = BizSheetModel.RuntimeContent.Replace(@"OriginateDate", "OriginateTime");
                }


                BizSheets.Add(BizSheetModel);
            }

            //流程模板
            XmlNode     TemplateRoot = BizWorkflowPackage.GetElementsByTagName("WorkflowTemplates")[0];
            XmlNodeList Templates    = ((XmlElement)TemplateRoot).GetElementsByTagName("WorkflowTemplate");

            if (Templates.Count > 0)
            {
                WorkflowTemplates = new List <DraftWorkflowTemplate>();
                foreach (XmlNode node in Templates)
                {
                    DraftWorkflowTemplate draftWorkflowTemplate = new DraftWorkflowTemplate(((XmlElement)node).GetElementsByTagName("WorkflowDocument")[0].OuterXml);
                    WorkflowNames.Add(draftWorkflowTemplate.WorkflowCode, ((XmlElement)node).GetElementsByTagName("WorkflowTemplateName")[0].InnerXml);
                    WorkflowTemplates.Add(draftWorkflowTemplate);
                }
                //流程模拟
                XmlNode     SimulationRoot  = BizWorkflowPackage.GetElementsByTagName("Simulations")[0];
                XmlNodeList SimulationNodes = ((XmlElement)SimulationRoot).GetElementsByTagName("InstanceSimulation");
                this.Simulations = new List <InstanceSimulation>();
                foreach (XmlNode simulation in SimulationNodes)
                {
                    this.Simulations.Add((InstanceSimulation)Convertor.XmlToObject(typeof(InstanceSimulation), simulation.OuterXml));
                }

                XmlNodeList clauseNodes = BizWorkflowPackage.GetElementsByTagName("WorkflowClause");
                if (clauseNodes != null && clauseNodes.Count > 0)
                {
                    foreach (XmlNode clauseNode in clauseNodes)
                    {
                        this.clauses.Add((WorkflowClause)Convertor.XmlToObject(typeof(WorkflowClause), clauseNode.OuterXml));
                    }
                }
            }
        }
Esempio n. 13
0
        /// <summary>
        /// 导入模板
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public JsonResult Import(string formData)
        {
            return(ExecuteFunctionRun(() =>
            {
                WorkflowPackageImportViewModel model = new WorkflowPackageImportViewModel();
                model = JsonConvert.DeserializeObject <WorkflowPackageImportViewModel>(formData);

                ReadXmlFile(model);
                ActionResult result = new ActionResult(false, "");
                if (package == null)
                {
                    result.Message = "WorkflowPackageImport.PackageImportHandler_Mssg1";

                    return Json(result);
                }

                #region 将界面修改的code更新到导入的实体中

                if (model.QueryList != null && model.QueryList.Count > 0)
                {
                    int index = 0;
                    foreach (ItemDetail item in model.QueryList)
                    {
                        this.bizQueryList.ForEach(i => { if (i.QueryCode == item.OldCode)
                                                         {
                                                             i.QueryCode = item.Code;
                                                         }
                                                  });
                    }
                }

                //
                if (model.WorkflowPackage != null)
                {
                    this.PackageCode = this.package.Code = this.BizObjectSchema.SchemaCode = model.WorkflowPackage.Code;
                    //更新流程模板对象的数据模型编码
                    this.WorkflowTemplates.ForEach(i => i.BizObjectSchemaCode = model.WorkflowPackage.Code);
                    this.clauses.ForEach(i => i.BizSchemaCode = model.WorkflowPackage.Code);
                    //更新表单对象的数据模型编码
                    this.BizSheets.ForEach(i => i.BizObjectSchemaCode = model.WorkflowPackage.Code);
                    //更新数据模型中子对象的数据模型code
                    if (scheduleInvokerList != null)
                    {
                        scheduleInvokerList.ForEach(i => i.SchemaCode = model.WorkflowPackage.Code);
                    }
                    if (bizQueryList != null)
                    {
                        bizQueryList.ForEach(i => i.SchemaCode = model.WorkflowPackage.Code);
                    }
                }

                //
                if (model.BizSheets != null && model.BizSheets.Count > 0)
                {
                    foreach (ItemDetail item in model.BizSheets)
                    {
                        this.BizSheets.ForEach(i => { if (i.SheetCode == item.OldCode)
                                                      {
                                                          i.SheetCode = item.Code;
                                                      }
                                               });
                    }
                }
                //流程模板
                if (model.WorkFlows != null)
                {
                    foreach (ItemDetail im in model.WorkFlows)
                    {
                        if (im.OldCode != im.Code)
                        {
                            this.WorkflowTemplates.ForEach(i => { if (i.WorkflowCode == im.OldCode)
                                                                  {
                                                                      i.WorkflowCode = im.Code;
                                                                  }
                                                           });
                            this.Simulations.ForEach(i => { if (i.WorkflowCode == im.OldCode)
                                                            {
                                                                i.WorkflowCode = im.Code;
                                                            }
                                                     });
                            this.clauses.ForEach(i => { if (i.WorkflowCode == im.OldCode)
                                                        {
                                                            i.WorkflowCode = im.Code;
                                                        }
                                                 });

                            WorkflowNames.Add(im.Code, WorkflowNames[im.OldCode]);
                            WorkflowNames.Remove(im.OldCode);
                        }
                    }
                }

                #endregion

                #region 处理脏数据:是否序列化,ObjectID
                bool isCover = model.IsCover;
                //bool.TryParse(model.IsCover, out isCover);
                //查询
                foreach (BizQuery query in this.bizQueryList)
                {
                    //BizQuery serverQuery = this.Engine.BizObjectManager.GetBizQuery(query.QueryCode);
                    //if (serverQuery == null)
                    //{
                    query.Serialized = false;
                    query.ObjectID = Guid.NewGuid().ToString();

                    if (query.Columns != null)
                    {
                        foreach (BizQueryColumn c in query.Columns)
                        {
                            c.ObjectID = Guid.NewGuid().ToString();
                            c.Serialized = false;
                        }
                    }

                    if (query.BizActions != null)
                    {
                        foreach (BizQueryAction a in query.BizActions)
                        {
                            a.ObjectID = Guid.NewGuid().ToString();
                            a.Serialized = false;
                        }
                    }

                    if (query.QueryItems != null)
                    {
                        foreach (BizQueryItem i in query.QueryItems)
                        {
                            i.ObjectID = Guid.NewGuid().ToString();
                            i.Serialized = false;
                        }
                    }
                    //}
                    //else if (isCover)
                    //{
                    //    query.ObjectID = serverQuery.ObjectID;
                    //}
                }

                //定时作业
                foreach (var scheduleInvoker in scheduleInvokerList)
                {
                    scheduleInvoker.ObjectID = Guid.NewGuid().ToString();
                    scheduleInvoker.Serialized = false;
                }

                //表单
                foreach (BizSheet sheet in this.BizSheets)
                {
                    BizSheet serverSheet = this.Engine.BizSheetManager.GetBizSheetByCode(sheet.SheetCode);
                    if (serverSheet == null)
                    {
                        sheet.Serialized = false;
                        sheet.ObjectID = Guid.NewGuid().ToString();
                    }
                    else if (isCover)
                    {
                        sheet.ObjectID = serverSheet.ObjectID;
                    }
                }

                //流程模拟
                foreach (InstanceSimulation s in this.Simulations)
                {
                    s.Serialized = false;
                    s.ObjectID = Guid.NewGuid().ToString();
                }

                #endregion

                string resultStr = string.Empty;
                bool result2 = this.Engine.AppPackageManager.ImportAppPackage(
                    this.UserValidator.UserID,
                    model.ParentCode,
                    this.PackageCode,
                    this.PackageName,
                    this.BizObjectSchema,
                    this.bizListenerPolicy,
                    this.bizQueryList,
                    this.scheduleInvokerList,
                    this.BizSheets,
                    this.WorkflowTemplates,
                    WorkflowNames,
                    //this.Simulations,
                    isCover,
                    out resultStr);
                if (result2)
                {
                    result.Success = true;
                    result.Message = "msgGlobalString.ImportSucceed";
                }
                else
                {
                    result.Message = resultStr;
                }
                return Json(result, JsonRequestBehavior.AllowGet);
            }));
        }
        public JsonResult SaveWorkSheet(WorkSheetViewModel model)
        {
            return(ExecuteFunctionRun(() =>
            {
                ActionResult result = new ActionResult();

                if (!Boolean.Parse(model.Type) && string.IsNullOrWhiteSpace(model.PCAdd.Trim()))
                {
                    result.Success = false;
                    result.Message = "WorkSheetEdit.Required";
                    return Json(result, JsonRequestBehavior.AllowGet);
                }

                //校验编码,不能以数字开始
                System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("^[a-zA-Z\\u4e00-\\u9fa5][0-9a-zA-Z\\u4e00-\\u9fa5_]*$");
                if (!regex.Match(model.Code).Success)
                {
                    result.Success = false;
                    result.Message = "WorkSheetEdit.Msg";
                    return Json(result, JsonRequestBehavior.AllowGet);
                }

                int sortKey;
                Int32.TryParse(model.SortKey, out sortKey);
                result.Success = false;
                SheetType sheetType = Boolean.Parse(model.Type) ? SheetType.DefaultSheet : SheetType.CustomSheet;

                BizObjectSchema schema = this.Engine.BizObjectManager.GetDraftSchema(model.ParentCode);
                string bizObjectSchemaCode = model.ParentCode;
                if (schema != null && schema.IsQuotePacket)
                {
                    bizObjectSchemaCode = schema.BindPacket;
                }
                if (string.IsNullOrEmpty(model.ObjectID))
                {
                    BizSheet workflowSheet = new BizSheet(
                        model.ParentId,
                        model.Code.Trim(),
                        model.Name.Trim(),
                        sheetType,
                        Boolean.Parse(model.Type) ? "" : model.PCAdd.Trim(),
                        !model.isMobileAdd ? model.MobileAdd : "");
                    workflowSheet.PrintSheetAddress = !model.isPrintAdd ? model.PrintAdd : "";
                    workflowSheet.BizObjectSchemaCode = bizObjectSchemaCode;
                    if (bizObjectSchemaCode != model.ParentCode)
                    {
                        workflowSheet.OwnSchemaCode = model.ParentCode;
                    }
                    //流程共享包,共享表单
                    if (schema.IsShared)
                    {
                        workflowSheet.IsShared = true;
                    }
                    result.Success = this.Engine.BizSheetManager.AddBizSheet(workflowSheet);
                }
                else
                {
                    BizSheet workflowSheet = this.Engine.BizSheetManager.GetBizSheetByID(model.ObjectID);
                    workflowSheet.DisplayName = model.Name.Trim();
                    workflowSheet.SheetAddress = Boolean.Parse(model.Type) ? "" : model.PCAdd.Trim();
                    workflowSheet.SheetType = sheetType;
                    workflowSheet.MobileSheetAddress = !model.isMobileAdd ? model.MobileAdd : "";
                    workflowSheet.PrintSheetAddress = !model.isPrintAdd ? model.PrintAdd : "";
                    result.Success = this.Engine.BizSheetManager.UpdateBizSheet(workflowSheet);
                }
                return Json(result, JsonRequestBehavior.AllowGet);
            }));
        }