示例#1
0
        public JsonResult GetParticipants(string ActivityCode, string InstanceID)
        {
            return(ExecuteFunctionRun(() =>
            {
                if (!string.IsNullOrEmpty(ActivityCode) && !string.IsNullOrEmpty(InstanceID))
                {
                    //流程
                    Instance.InstanceContext InstanceContext = this.Engine.InstanceManager.GetInstanceContext(InstanceID);
                    if (InstanceContext != null)
                    {
                        //流程模板
                        WorkflowTemplate.PublishedWorkflowTemplate Template = this.Engine.WorkflowManager.GetPublishedTemplate(
                            InstanceContext.WorkflowCode,
                            InstanceContext.WorkflowVersion);
                        if (Template != null)
                        {
                            //活动信息
                            ClientActivityBase Activity = Template.GetActivityByCode(ActivityCode) as ClientActivityBase;

                            OThinker.H3.Instance.InstanceData InstanceData = new Instance.InstanceData(this.Engine, InstanceID, null);

                            string[] ParticipantIDs = Activity.ParseParticipants(InstanceData, this.Engine.Organization);
                            OThinker.Organization.Unit[] ParticipantUsers = this.Engine.Organization.GetUnits(ParticipantIDs).ToArray();

                            if (ParticipantUsers != null)
                            {
                                List <object> ParticipantUserNames = new List <object>();
                                foreach (OThinker.Organization.Unit u in ParticipantUsers)
                                {
                                    if (u != null && u.UnitType == OThinker.Organization.UnitType.User)
                                    {
                                        OThinker.Organization.User user = (OThinker.Organization.User)u;
                                        ParticipantUserNames.Add(new
                                        {
                                            Name = user.Name,
                                            Code = user.Code,
                                            ObjectID = user.ObjectID
                                        });
                                        //ParticipantUserNames.Add(u.Name + "[" + u.Code + "]");
                                    }
                                }
                                return Json(ParticipantUserNames, JsonRequestBehavior.AllowGet);
                            }
                        }
                    }
                }

                return Json(new string[] { }, JsonRequestBehavior.AllowGet);
            }));
        }
示例#2
0
        /// <summary>
        /// 打开流程表单
        /// </summary>
        /// <param name="paramString"></param>
        /// <returns></returns>
        public JsonResult InstanceSheets(string paramString)
        {
            return(ExecuteFunctionRun(() =>
            {
                ActionResult result = new ActionResult(false, "");
                Dictionary <string, string> dicParams = JsonConvert.DeserializeObject <Dictionary <string, string> >(paramString);
                bool isMobile = false;
                foreach (string key in dicParams.Keys)
                {
                    if (key == Param_InstanceId)
                    {
                        InstanceID = dicParams[key]; continue;
                    }
                    if (key == Param_IsMobile)
                    {
                        bool.TryParse(dicParams[key], out isMobile);
                        IsMobile = isMobile;
                        continue;
                    }
                }

                if (InstanceContext == null)
                {
                    result.Message = "InstanceSheets_InstanceNotExist";
                    return Json(result, JsonRequestBehavior.AllowGet);
                }

                // 获取流程模板信息
                WorkflowTemplate.PublishedWorkflowTemplate workflow = this.Engine.WorkflowManager.GetPublishedTemplate(InstanceContext.WorkflowCode, InstanceContext.WorkflowVersion);
                if (workflow == null)
                {
                    result.Message = "InstanceSheets_WorkflowNotExist";
                    return Json(result, JsonRequestBehavior.AllowGet);
                }

                //WorkflowVersion,InstanceID,UserID
                DataTable dtWorkItem = this.GetItemTable(InstanceID);
                string activity, sheetCode;
                Dictionary <string, string> sheetWorkItemIds = new Dictionary <string, string>();
                //当前用户参与过流程时,则打开参与过的流程表单,否则打开系统流程表单
                if (dtWorkItem != null && dtWorkItem.Rows.Count > 0)
                {
                    foreach (DataRow row in dtWorkItem.Rows)
                    {
                        activity = row[WorkItem.WorkItem.PropertyName_ActivityCode] + string.Empty;
                        sheetCode = this.GetSheetCodeByActivity(((WorkflowTemplate.ClientActivity)workflow.GetActivityByCode(activity)));
                        if (!sheetWorkItemIds.ContainsKey(sheetCode))
                        {
                            sheetWorkItemIds.Add(sheetCode, row[WorkItem.WorkItem.PropertyName_ObjectID].ToString());
                        }
                    }
                }
                else
                { // 管理员,未参与过流程
                    foreach (WorkflowTemplate.Activity act in workflow.Activities)
                    {
                        if (act is WorkflowTemplate.ClientActivity)
                        {
                            sheetCode = this.GetSheetCodeByActivity(((WorkflowTemplate.ClientActivity)act));
                            if (!string.IsNullOrEmpty(sheetCode) && !sheetWorkItemIds.ContainsKey(sheetCode))
                            {
                                sheetWorkItemIds.Add(sheetCode, string.Empty);
                            }
                        }
                    }
                }
                if (sheetWorkItemIds.Count == 0)
                {
                    Instance.InstanceContext instanceContext = InstanceContext;
                    if (instanceContext != null)
                    {
                        // 未参与过流程,并且未设置默认表单,那么再获取默认表单
                        Sheet.BizSheet[] sheets = this.Engine.BizSheetManager.GetBizSheetBySchemaCode(instanceContext.BizObjectSchemaCode);
                        if (sheets != null && sheets.Length > 0)
                        {
                            foreach (Sheet.BizSheet sheet in sheets)
                            {
                                if (!string.IsNullOrEmpty(sheet.SheetCode) && !sheetWorkItemIds.ContainsKey(sheet.SheetCode))
                                {
                                    sheetWorkItemIds.Add(sheet.SheetCode, string.Empty);
                                }
                            }
                        }
                    }
                }
                WorkItem.WorkItem workItem = null;
                WorkItem.CirculateItem circulateItem = null;
                string url, workItemId;
                List <ListUrl> ListUrl = new List <ListUrl>();
                foreach (string key in sheetWorkItemIds.Keys)
                {
                    Sheet.BizSheet sheet = this.Engine.BizSheetManager.GetBizSheetByCode(key);
                    workItemId = sheetWorkItemIds[key];
                    if (workItemId == string.Empty)
                    {
                        url = this.GetViewSheetUrl(
                            sheet,
                            InstanceID,
                            SheetMode.View,
                            IsMobile);
                    }
                    else
                    {
                        workItem = this.Engine.WorkItemManager.GetWorkItem(workItemId);
                        if (workItem != null)
                        {
                            url = this.GetViewSheetUrl(
                                workItem,
                                sheet,
                                SheetMode.View,
                                this.IsMobile);
                        }
                        else
                        {
                            circulateItem = this.Engine.WorkItemManager.GetCirculateItem(workItemId);
                            if (circulateItem == null)
                            {
                                continue;
                            }
                            url = this.GetViewSheetUrl(
                                circulateItem,
                                sheet,
                                SheetMode.View,
                                this.IsMobile);
                        }
                    }
                    // 处理缓存
                    DateTime t = DateTime.Now;
                    url += "&T=" + t.ToString("HHmmss");
                    //只有一个表单直接跳转打开
                    if (sheetWorkItemIds.Count == 1)
                    {
                        result.Success = true;
                        result.Message = url;
                        result.Extend = "Redirect";
                        return Json(result, JsonRequestBehavior.AllowGet);
                    }
                    else //多个表单在界面上呈现连接选择打开
                    {
                        ListUrl.Add(new ListUrl
                        {
                            Title = "InstanceSheets_Sheet",
                            Text = string.Format("{0}[{1}]", sheet.DisplayName, key),
                            Url = url
                        });
                    }
                }
                result.Success = true;
                result.Message = "MultiSheets";
                result.Extend = ListUrl;
                return Json(result, JsonRequestBehavior.AllowGet);
            }));
        }