Exemple #1
0
        /// <summary>
        /// 发布流程模板
        /// </summary>
        public JsonResult PublishWorkflow(WorkflowTemplateViewModel model)
        {
            return(ExecuteFunctionRun(() =>
            {
                DraftWorkflowTemplate DraftWorkflowTemplate = ReadRequestWorkflowTemplate(model);
                if (DraftWorkflowTemplate == null)
                {
                    return Json(new { Result = false, Errors = new List <string>()
                                      {
                                          "Designer.WorkflowHandler_Msg1"
                                      } });
                }

                string WorkflowCode = DraftWorkflowTemplate.WorkflowCode;
                WorkflowClause Clause = this.Engine.WorkflowManager.GetClause(WorkflowCode);
                if (Clause == null)
                {
                    return Json(new { Result = false, Errors = new List <string>()
                                      {
                                          "Designer.WorkflowHandler_Msg2"
                                      } });
                }
                DraftWorkflowTemplate.BizObjectSchemaCode = Clause.BizSchemaCode;

                // 先保存流程模板
                if (!this.Engine.WorkflowManager.SaveDraftTemplate(this.UserValidator.UserID, DraftWorkflowTemplate))
                {
                    return Json(new { Result = false, Errors = new List <string>()
                                      {
                                          "Designer.WorkflowHandler_Msg3"
                                      } });
                }

                OThinker.H3.DataModel.BizObjectSchema schema = this.Engine.BizObjectManager.GetPublishedSchema(Clause.BizSchemaCode);
                OThinker.H3.ValidationResult ValidationResult = DraftWorkflowTemplate.Validate(schema);

                if (!ValidationResult.Valid)
                {
                    return Json(ValidationResult);
                }

                PublishResult PublishResult = this.Engine.WorkflowManager.RegisterWorkflow(this.UserValidator.UserID, DraftWorkflowTemplate.WorkflowCode, true);

                if (PublishResult.Result == (long)OThinker.H3.ErrorCode.SUCCESS)
                {
                    return Json(new { Result = true, Message = new List <string>()
                                      {
                                          "流程发布成功:当前版本号: " + PublishResult.RegisteredVersion.ToString()
                                      } });
                }
                else
                {
                    return Json(new { Result = false, Errors = PublishResult.Errors });
                }
            }));
        }
        /// <summary>
        /// 结束工作任务
        /// </summary>
        /// <param name="MvcPost">MVC表单传递过来的值</param>
        /// <param name="Approval">审核结果</param>
        /// <param name="ActionEventType">事件类型</param>
        /// <param name="ActionButtonType">按钮类型</param>
        public void ForwardWorkItem(
            List <DataItemParam> paramList, string code, string schemaCode, string instanceId, string workItemCode)
        {
            OThinker.H3.Instance.InstanceContext  ic     = this.Engine.InstanceManager.GetInstanceContext(instanceId);
            OThinker.H3.DataModel.BizObjectSchema schema = this.Engine.BizObjectManager.GetPublishedSchema(schemaCode);
            OThinker.H3.DataModel.BizObject       bo     = new OThinker.H3.DataModel.BizObject(Engine, schema, code);
            OThinker.H3.WorkItem.WorkItem         item   = this.Engine.WorkItemManager.GetWorkItem(workItemCode);


            bo.ObjectID = ic.BizObjectId;
            bo.Load();//装载流程数据;

            if (paramList != null)
            {
                // 这里可以在创建流程的时候赋值
                foreach (DataItemParam param in paramList)
                {
                    if (bo.Schema.ContainsField(param.ItemName))
                    {
                        bo[param.ItemName] = param.ItemValue;
                    }
                }
            }

            bo.Update();

            if (!string.IsNullOrEmpty(workItemCode))
            {
                // 结束工作项
                this.Engine.WorkItemManager.FinishWorkItem(
                    workItemCode,
                    code,
                    OThinker.H3.WorkItem.AccessPoint.ExternalSystem,
                    null,
                    OThinker.Data.BoolMatchValue.True,
                    string.Empty,
                    null,
                    OThinker.H3.WorkItem.ActionEventType.Forward,
                    (int)OThinker.H3.Controllers.SheetButtonType.Submit);

                // 需要通知实例事件管理器结束事件
                Messages.AsyncEndMessage endMessage = new OThinker.H3.Messages.AsyncEndMessage(
                    Messages.MessageEmergencyType.Normal,
                    instanceId,
                    item.ActivityCode,
                    item.TokenId,
                    OThinker.Data.BoolMatchValue.True,
                    false,
                    OThinker.Data.BoolMatchValue.True,
                    true,
                    null);
                this.Engine.InstanceManager.SendMessage(endMessage);
            }
        }
 private OThinker.H3.DataModel.BizObjectSchema GetSchema(string schemaCode)
 {
     OThinker.H3.DataModel.BizObjectSchema schema = null;
     if (!Schemas.ContainsKey(schemaCode))
     {
         schema = this.Engine.BizObjectManager.GetPublishedSchema(schemaCode);
         Schemas.Add(schemaCode, schema);
     }
     else
     {
         schema = Schemas[schemaCode];
     }
     return(schema);
 }
        /// <summary>
        /// 给工作项添加审批意见
        /// </summary>
        /// <param name="item">工作项</param>
        /// <param name="approval">审批结果</param>
        /// <param name="commentText">审批意见</param>
        private void AppendComment(OThinker.H3.Instance.InstanceContext Instance, OThinker.H3.WorkItem.WorkItem item, OThinker.Data.BoolMatchValue approval, string commentText)
        {
            // 添加一个审批意见
            WorkflowTemplate.PublishedWorkflowTemplate workflow = this.Engine.WorkflowManager.GetPublishedTemplate(
                item.WorkflowCode,
                item.WorkflowVersion);
            // 审批字段
            string approvalDataItem = null;

            if (workflow != null)
            {
                OThinker.H3.DataModel.BizObjectSchema schema = this.Engine.BizObjectManager.GetPublishedSchema(item.WorkflowCode);
                approvalDataItem = workflow.GetDefaultCommentDataItem(schema, item.ActivityCode);
            }
            if (approvalDataItem != null)
            {
                // 创建审批
                OThinker.H3.Data.Comment comment = new Data.Comment();
                comment.Activity            = item.ActivityCode;
                comment.Approval            = approval;
                comment.CreatedTime         = System.DateTime.Now;
                comment.DataField           = approvalDataItem;
                comment.InstanceId          = item.InstanceId;
                comment.BizObjectId         = Instance.BizObjectId;
                comment.BizObjectSchemaCode = Instance.BizObjectSchemaCode;
                comment.OUName   = this.Engine.Organization.GetName(this.Engine.Organization.GetParent(item.Participant));
                comment.Text     = commentText;
                comment.TokenId  = item.TokenId;
                comment.UserID   = item.Participant;
                comment.UserName = item.ParticipantName;

                // 设置用户的默认签章
                Organization.Signature[] signs = this.Engine.Organization.GetSignaturesByUnit(item.Participant);
                if (signs != null && signs.Length > 0)
                {
                    foreach (Organization.Signature sign in signs)
                    {
                        if (sign.IsDefault)
                        {
                            comment.SignatureId = sign.ObjectID;
                            break;
                        }
                    }
                }
                this.Engine.BizObjectManager.AddComment(comment);
            }
        }
        /// <summary>
        /// 解析参数
        /// </summary>
        /// <param name="parentId">所属数据模型ID</param>
        /// <param name="schemaCode">主数据编码</param>
        /// <param name="method">方法名称</param>
        /// <returns></returns>
        private bool ParseParam(string parentId, string schemaCode, string method)
        {
            this.ParentID       = parentId;
            this.SchemaCode     = schemaCode;
            this.SelectedMethod = method;
            if (!string.IsNullOrEmpty(SchemaCode))
            {
                this.Schema = this.Engine.BizObjectManager.GetDraftSchema(SchemaCode);
            }

            if (this.Schema == null)
            {
                return(false);
            }
            if (!string.IsNullOrWhiteSpace(this.SelectedMethod))
            {
                this.Method = this.Schema.GetMethod(SelectedMethod);
            }
            return(true);
        }
Exemple #6
0
        /// <summary>
        /// 验证流程模板是否合法
        /// </summary>
        /// <param name="DraftWorkflowTemplate"></param>
        /// <returns></returns>
        public JsonResult ValidateWorkflow(WorkflowTemplateViewModel model)
        {
            return(ExecuteFunctionRun(() =>
            {
                DraftWorkflowTemplate DraftWorkflowTemplate = ReadRequestWorkflowTemplate(model);
                if (DraftWorkflowTemplate != null)
                {
                    OThinker.H3.DataModel.BizObjectSchema schema = this.Engine.BizObjectManager.GetPublishedSchema(DraftWorkflowTemplate.BizObjectSchemaCode);
                    OThinker.H3.ValidationResult ValidationResult = DraftWorkflowTemplate.Validate(schema);

                    return Json(new { Result = ValidationResult.Valid, Errors = ValidationResult.Errors, Warnings = ValidationResult.Warnings });
                }
                else
                {
                    var result = new { Result = false, Errors = new List <string>()
                                       {
                                           "Designer.WorkflowHandler_Msg0"
                                       } };
                    return Json(result);
                }
            }));
        }
        /// <summary>
        /// 保存表单数据
        /// </summary>
        /// <param name="workItem"></param>
        /// <param name="user"></param>
        /// <param name="boolMatchValue"></param>
        /// <param name="paramValues"></param>
        private void SaveBizObject(OThinker.H3.WorkItem.WorkItem workItem, OThinker.Organization.User user, OThinker.Data.BoolMatchValue boolMatchValue, List<DataItemParam> paramValues)
        {
            Instance.InstanceContext InstanceContext = this.Engine.InstanceManager.GetInstanceContext(workItem.InstanceId);
            string bizObjectId = InstanceContext == null ? string.Empty : InstanceContext.BizObjectId;
            OThinker.H3.DataModel.BizObjectSchema schema = this.Engine.BizObjectManager.GetPublishedSchema(InstanceContext.BizObjectSchemaCode);
            OThinker.H3.DataModel.BizObject bo = new OThinker.H3.DataModel.BizObject(this.Engine, schema, workItem.Participant);
            bo.ObjectID = bizObjectId;
            bo.Load();

            // 设置数据项的值
            foreach (DataItemParam param in paramValues)
            {
                OThinker.H3.DataModel.PropertySchema property = schema.GetProperty(param.ItemName);
                if (property.LogicType == DataLogicType.Comment)
                {// 审核意见
                    CommentParam comment = JSSerializer.Deserialize<CommentParam>(param.ItemValue + string.Empty);
                    this.Engine.BizObjectManager.AddComment(new Comment()
                    {
                        BizObjectId = bo.ObjectID,
                        BizObjectSchemaCode = schema.SchemaCode,
                        InstanceId = workItem.InstanceId,
                        TokenId = workItem.TokenId,
                        Approval = boolMatchValue,
                        Activity = workItem.ActivityCode,
                        DataField = property.Name,
                        UserID = user.ObjectID,
                        SignatureId = comment.SignatureId,
                        Text = comment.Text
                    });
                }
                else
                {
                    this.SetItemValue(bo, property, param.ItemValue);
                }
            }

            bo.Update();
        }
        private void AppendComment(WorkItem.WorkItem Item, OThinker.Data.BoolMatchValue Approval, string Comment)
        {
            WorkflowTemplate.PublishedWorkflowTemplate workflow = GetWorkflowTemplate(Item.WorkflowCode, Item.WorkflowVersion);
            // 审批字段
            string approvalDataItem = null;

            if (workflow != null)
            {
                PublishedWorkflowTemplate             workflowTemplate = this.Engine.WorkflowManager.GetPublishedTemplate(Item.WorkflowCode, Item.WorkflowVersion);
                OThinker.H3.DataModel.BizObjectSchema schema           = GetSchema(workflowTemplate.BizObjectSchemaCode);
                approvalDataItem = workflow.GetDefaultCommentDataItem(schema, Item.ActivityCode);
            }
            if (approvalDataItem != null)
            {
                // 创建审批
                //TODO:此处待修改,Item.BizObjectId不存在,通过 OT_InstanceContext获取
                Instance.InstanceContext InstanceContext = this.Engine.InstanceManager.GetInstanceContext(Item.InstanceId);
                string BizObjectId = InstanceContext == null ? string.Empty : InstanceContext.BizObjectId;

                Data.Comment comment = new Data.Comment();
                comment.Activity    = Item.ActivityCode;
                comment.Approval    = Approval;
                comment.CreatedTime = System.DateTime.Now;
                comment.DataField   = approvalDataItem;
                comment.InstanceId  = Item.InstanceId;
                comment.OUName      = this.Engine.Organization.GetName(this.Engine.Organization.GetParent(Item.Participant));
                comment.Text        = Comment;
                comment.TokenId     = Item.TokenId;
                comment.UserID      = Item.Participant;
                comment.UserName    = Item.ParticipantName;
                //comment.BizObjectId = Item.BizObjectId;
                comment.BizObjectId         = BizObjectId;
                comment.BizObjectSchemaCode = Item.WorkflowCode;
                this.Engine.BizObjectManager.AddComment(comment);
            }
        }
Exemple #9
0
        /// <summary>
        /// 提交工作项
        /// </summary>
        /// <param name="workflowCode"></param>
        /// <param name="instanceId"></param>
        /// <param name="workItemId"></param>
        /// <param name="approval"></param>
        /// <param name="commentText"></param>
        /// <param name="userId"></param>
        /// <param name="values"></param>
        /// <returns></returns>
        private BPMServiceResult SubmitItem(string workflowCode, string instanceId, string workItemId, OThinker.Data.BoolMatchValue approval, string commentText, string userId, List <DataItemParam> values)
        {
            BPMServiceResult result = new BPMServiceResult();

            try
            {
                string user = GetUserIDByCode(userId);
                if (user == null)
                {
                    return(new BPMServiceResult(false, "流程启动失败,用户{" + userId + "}不存在。"));
                }
                OThinker.H3.WorkflowTemplate.PublishedWorkflowTemplate workflowTemplate = Engine.WorkflowManager.GetDefaultWorkflow(workflowCode);
                InstanceContext ic = Engine.InstanceManager.GetInstanceContext(instanceId);
                if (ic == null)
                {
                    return(new BPMServiceResult(false, "InstanceID错误,此ID在H3系统中不存在,请检查"));
                }
                OThinker.H3.DataModel.BizObjectSchema schema = Engine.BizObjectManager.GetPublishedSchema(workflowTemplate.BizObjectSchemaCode);
                OThinker.H3.DataModel.BizObject       bo     = new OThinker.H3.DataModel.BizObject(Engine.Organization, Engine.MetadataRepository, Engine.BizObjectManager, null, schema, user);
                bo.ObjectID = ic.BizObjectId;
                bo.Load();
                foreach (DataItemParam value in values)
                {
                    OThinker.H3.DataModel.PropertySchema property = schema.GetProperty(value.ItemName);
                    if (property.LogicType == OThinker.H3.Data.DataLogicType.BizObjectArray)
                    {
                        var t = new List <OThinker.H3.DataModel.BizObject>();
                        foreach (List <DataItemParam> list in (IEnumerable)value.ItemValue)
                        {
                            var m = new OThinker.H3.DataModel.BizObject(Engine.Organization, Engine.MetadataRepository, Engine.BizObjectManager, null, property.ChildSchema, bo.OwnerId);
                            foreach (DataItemParam dataItem in list)
                            {
                                if (m.Schema.ContainsField(dataItem.ItemName))
                                {
                                    m.SetValue(dataItem.ItemName, dataItem.ItemValue);
                                }
                            }
                            t.Add(m);
                        }
                        bo[value.ItemName] = t.ToArray();
                    }
                    else if (bo.Schema.ContainsField(value.ItemName))
                    {
                        bo[value.ItemName] = value.ItemValue;
                    }
                }
                bo.Update();
                // 获取工作项
                OThinker.H3.WorkItem.WorkItem        item     = Engine.WorkItemManager.GetWorkItem(workItemId);
                OThinker.H3.Instance.InstanceContext instance = Engine.InstanceManager.GetInstanceContext(item.InstanceId);
                // 结束工作项
                Engine.WorkItemManager.FinishWorkItem(item.ObjectID, userId, OThinker.H3.WorkItem.AccessPoint.ExternalSystem, null, approval,
                                                      commentText, null, OThinker.H3.WorkItem.ActionEventType.Forward, (int)OThinker.H3.Controllers.SheetButtonType.Submit);
                // 需要通知实例事件管理器结束事件
                OThinker.H3.Messages.AsyncEndMessage endMessage = new OThinker.H3.Messages.AsyncEndMessage(OThinker.H3.Messages.MessageEmergencyType.Normal,
                                                                                                           item.InstanceId, item.ActivityCode, item.TokenId, approval, false, approval, true, null);
                Engine.InstanceManager.SendMessage(endMessage);
                result = new BPMServiceResult(true, "", null, "流程实例启动成功!", "");
            }
            catch (Exception ex)
            {
                result = new BPMServiceResult(false, "流程实例启动失败!错误:" + ex.Message);
            }
            return(result);
        }
        public RestfulResult StartWorkflow_Base(string USER_CODE, string WORKFLOW_CODE, bool FINISH_START, string INSTANCE_ID, string PARAM_VALUES)
        {
            Engine.LogWriter.Write("Restful 服务,方法:StartWorkflow,参数:USER_CODE-->" + USER_CODE + ",WORKFLOW_CODE-->" + WORKFLOW_CODE + ",FINISH_START-->" + FINISH_START + ",INSTANCE_ID-->" + INSTANCE_ID + ",PARAM_VALUES-->" + JsonConvert.SerializeObject(PARAM_VALUES));
            RestfulResult result = new RestfulResult();
            Dictionary <string, object> listParams = JsonConvert.DeserializeObject <Dictionary <string, object> >(PARAM_VALUES);
            string workItemID, keyItem, errorMessage;

            workItemID = keyItem = errorMessage = string.Empty;
            try
            {
                #region 参数校验
                OThinker.H3.WorkflowTemplate.PublishedWorkflowTemplate workflowTemplate = this.Engine.WorkflowManager.GetDefaultWorkflow(WORKFLOW_CODE);
                if (workflowTemplate == null)
                {
                    result.INSTANCE_ID   = "";
                    result.MESSAGE       = "流程模板不存在,模板编码:" + WORKFLOW_CODE + "。";
                    result.STATUS        = "0";
                    result.WORKFLOW_CODE = WORKFLOW_CODE;
                    result.USER_CODE     = USER_CODE;
                    return(result);
                }
                // 查找流程发起人
                OThinker.Organization.User user = this.Engine.Organization.GetUserByCode(USER_CODE);
                if (user == null)
                {
                    result.INSTANCE_ID   = "";
                    result.MESSAGE       = "用户{" + USER_CODE + "}不存在。";
                    result.STATUS        = "0";
                    result.WORKFLOW_CODE = WORKFLOW_CODE;
                    result.USER_CODE     = USER_CODE;
                    return(result);
                }
                #endregion

                #region 流程实例ID为空:发起新流程
                if (string.IsNullOrEmpty(INSTANCE_ID))
                {
                    OThinker.H3.DataModel.BizObjectSchema schema = this.Engine.BizObjectManager.GetPublishedSchema(workflowTemplate.BizObjectSchemaCode);
                    OThinker.H3.DataModel.BizObject       bo     = new OThinker.H3.DataModel.BizObject(
                        this.Engine.Organization,
                        this.Engine.MetadataRepository,
                        this.Engine.BizObjectManager,
                        null,
                        schema,
                        user.ObjectID,
                        user.ParentID);

                    if (listParams != null)
                    {
                        // 这里可以在创建流程的时候赋值
                        foreach (KeyValuePair <string, object> param in listParams)
                        {
                            OThinker.H3.DataModel.PropertySchema property = schema.GetProperty(param.Key);
                            if (property == null)
                            {
                                continue;
                            }
                            SetItemValue(bo, property, param.Value);
                        }
                    }

                    bo.Create();

                    // 创建流程实例
                    string InstanceId = this.Engine.InstanceManager.CreateInstance(
                        bo.ObjectID,
                        workflowTemplate.WorkflowCode,
                        workflowTemplate.WorkflowVersion,
                        null,
                        null,
                        user.UnitID,
                        null,
                        false,
                        InstanceContext.UnspecifiedID,
                        null,
                        Token.UnspecifiedID);

                    if (listParams != null)
                    {
                        // 这里可以在创建流程的时候赋值
                        foreach (KeyValuePair <string, object> param in listParams)
                        {
                            OThinker.H3.DataModel.PropertySchema property = schema.GetProperty(param.Key);
                            if (property == null)
                            {
                                continue;
                            }
                            if (property.LogicType == DataLogicType.Comment)
                            {// 审核意见
                                CommentParam comment = JsonConvert.DeserializeObject <CommentParam>(JsonConvert.SerializeObject(param.Value));
                                this.Engine.BizObjectManager.AddComment(new Comment()
                                {
                                    BizObjectId         = bo.ObjectID,
                                    BizObjectSchemaCode = schema.SchemaCode,
                                    InstanceId          = InstanceId,
                                    Activity            = workflowTemplate.StartActivityCode,
                                    TokenId             = 1,
                                    Approval            = OThinker.Data.BoolMatchValue.True,
                                    DataField           = property.Name,
                                    UserID      = user.ObjectID,
                                    UserName    = user.Name,
                                    SignatureId = comment.SignatureId,
                                    Text        = comment.Text
                                });
                            }
                        }
                    }

                    // 启动流程的消息
                    OThinker.H3.Messages.StartInstanceMessage startInstanceMessage
                        = new OThinker.H3.Messages.StartInstanceMessage(
                              MessageEmergencyType.Normal,
                              InstanceId,
                              workItemID,
                              null,
                              PriorityType.Normal,
                              FINISH_START,
                              null,
                              false,
                              OThinker.H3.Instance.Token.UnspecifiedID,
                              null);
                    Engine.InstanceManager.SendMessage(startInstanceMessage);

                    result.INSTANCE_ID   = InstanceId;
                    result.MESSAGE       = "流程实例启动成功!";
                    result.BIZOBJECTID   = bo.ObjectID;
                    result.STATUS        = "2";
                    result.WORKFLOW_CODE = WORKFLOW_CODE;
                    result.USER_CODE     = USER_CODE;
                }
                #endregion

                #region 流程实例ID不为空:更新流程数据;
                else
                {
                    InstanceContext ic = this.Engine.InstanceManager.GetInstanceContext(INSTANCE_ID);
                    if (ic == null)
                    {
                        result.INSTANCE_ID   = INSTANCE_ID;
                        result.MESSAGE       = "InstanceID错误,此ID在H3系统中不存在,请检查";
                        result.STATUS        = "0";
                        result.WORKFLOW_CODE = WORKFLOW_CODE;
                        result.USER_CODE     = USER_CODE;
                        return(result);
                    }

                    OThinker.H3.DataModel.BizObjectSchema schema = this.Engine.BizObjectManager.GetPublishedSchema(workflowTemplate.BizObjectSchemaCode);
                    OThinker.H3.DataModel.BizObject       bo     = new OThinker.H3.DataModel.BizObject(
                        this.Engine.Organization,
                        this.Engine.MetadataRepository,
                        this.Engine.BizObjectManager,
                        null,
                        schema,
                        user.ObjectID,
                        user.ParentID);

                    bo.ObjectID = ic.BizObjectId;
                    bo.Load();//装载流程数据;

                    if (listParams != null)
                    {
                        // 这里可以在创建流程的时候赋值
                        foreach (KeyValuePair <string, object> param in listParams)
                        {
                            OThinker.H3.DataModel.PropertySchema property = schema.GetProperty(param.Key);
                            if (property == null)
                            {
                                continue;
                            }
                            SetItemValue(bo, property, param.Value);
                        }
                    }

                    bo.Update();
                    #region 提交当前任务,往下流转
                    if (FINISH_START)
                    {
                        string sql = "SELECT ObjectID FROM OT_WorkItem WHERE InstanceId='{0}' ORDER BY TokenId desc";
                        sql = string.Format(sql, INSTANCE_ID);
                        string workItemId = this.Engine.EngineConfig.CommandFactory.CreateCommand().ExecuteScalar(sql) + string.Empty;
                        if (workItemId != "")
                        {
                            // 获取工作项
                            OThinker.H3.WorkItem.WorkItem item = this.Engine.WorkItemManager.GetWorkItem(workItemId);

                            // 结束工作项
                            this.Engine.WorkItemManager.FinishWorkItem(
                                item.ObjectID,
                                user.UnitID,
                                OThinker.H3.WorkItem.AccessPoint.ExternalSystem,
                                null,
                                OThinker.Data.BoolMatchValue.True,
                                string.Empty,
                                null,
                                OThinker.H3.WorkItem.ActionEventType.Forward,
                                11);

                            // 需要通知实例事件管理器结束事件
                            AsyncEndMessage endMessage = new OThinker.H3.Messages.AsyncEndMessage(
                                MessageEmergencyType.Normal,
                                item.InstanceId,
                                item.ActivityCode,
                                item.TokenId,
                                OThinker.Data.BoolMatchValue.True,
                                false,
                                OThinker.Data.BoolMatchValue.True,
                                true,
                                null);
                            this.Engine.InstanceManager.SendMessage(endMessage);
                        }
                    }
                    #endregion

                    result.INSTANCE_ID   = INSTANCE_ID;
                    result.MESSAGE       = "流程实例启动成功!(更新数据项的值)";
                    result.BIZOBJECTID   = ic.BizObjectId;
                    result.STATUS        = "2";
                    result.WORKFLOW_CODE = WORKFLOW_CODE;
                    result.USER_CODE     = USER_CODE;
                }
                #endregion
            }
            catch (Exception ex)
            {
                result               = new RestfulResult();
                result.INSTANCE_ID   = "";
                result.BIZOBJECTID   = "";
                result.MESSAGE       = "接口异常:" + ex.ToString();
                result.STATUS        = "0";
                result.WORKFLOW_CODE = WORKFLOW_CODE;
                result.USER_CODE     = USER_CODE;
            }
            return(result);
        }
        public System.Web.Mvc.ActionResult StartWorkflow(string appId, string pwd, string userCode, string workflowCode,
            bool finishStart, string paramValues)
        {
            BPMServiceResult result = new BPMServiceResult();

            List<DataItemParam> listParams = JSSerializer.Deserialize<List<DataItemParam>>(paramValues);
            string workItemID, keyItem, errorMessage;
            workItemID = keyItem = errorMessage = string.Empty;

            try
            {
                OThinker.H3.WorkflowTemplate.PublishedWorkflowTemplate workflowTemplate = this.Engine.WorkflowManager.GetDefaultWorkflow(workflowCode);
                if (workflowTemplate == null)
                {
                    result = new BPMServiceResult(false, "流程模板不存在,模板编码:" + workflowCode + "。");
                    return Json(result);
                }
                // 查找流程发起人
                OThinker.Organization.User user = this.Engine.Organization.GetUserByCode(userCode) as OThinker.Organization.User;
                if (user == null)
                {
                    result = new BPMServiceResult(false, "用户{" + userCode + "}不存在。");
                    return Json(result);
                }

                OThinker.H3.DataModel.BizObjectSchema schema = this.Engine.BizObjectManager.GetPublishedSchema(workflowTemplate.BizObjectSchemaCode);
                OThinker.H3.DataModel.BizObject bo = new OThinker.H3.DataModel.BizObject(
                    this.Engine.Organization,
                    this.Engine.MetadataRepository,
                    this.Engine.BizObjectManager,
                    null,
                    schema,
                    user.ObjectID,
                    user.ParentID);

                if (listParams != null)
                {
                    // 这里可以在创建流程的时候赋值
                    foreach (DataItemParam param in listParams)
                    {
                        OThinker.H3.DataModel.PropertySchema property = schema.GetProperty(param.ItemName);
                        if (property == null) continue;
                        SetItemValue(bo, property, param.ItemValue);
                    }
                }


                bo.Create();

                // 创建流程实例
                string InstanceId = this.Engine.InstanceManager.CreateInstance(
                     bo.ObjectID,
                     workflowTemplate.WorkflowCode,
                     workflowTemplate.WorkflowVersion,
                     null,
                     null,
                     user.UnitID,
                     null,
                     false,
                     InstanceContext.UnspecifiedID,
                     null,
                     Token.UnspecifiedID);

                if (listParams != null)
                {
                    // 这里可以在创建流程的时候赋值
                    foreach (DataItemParam param in listParams)
                    {
                        OThinker.H3.DataModel.PropertySchema property = schema.GetProperty(param.ItemName);
                        if (property == null) continue;
                        if (property.LogicType == DataLogicType.Comment)
                        {// 审核意见
                            CommentParam comment = JSSerializer.Deserialize<CommentParam>(param.ItemValue + string.Empty);
                            this.Engine.BizObjectManager.AddComment(new Comment()
                            {
                                BizObjectId = bo.ObjectID,
                                BizObjectSchemaCode = schema.SchemaCode,
                                InstanceId = InstanceId,
                                Activity = workflowTemplate.StartActivityCode,
                                TokenId = 1,
                                Approval = OThinker.Data.BoolMatchValue.True,
                                DataField = property.Name,
                                UserID = user.ObjectID,
                                SignatureId = comment.SignatureId,
                                Text = comment.Text
                            });
                        }
                    }
                }

                // 启动流程的消息
                OThinker.H3.Messages.StartInstanceMessage startInstanceMessage
                    = new OThinker.H3.Messages.StartInstanceMessage(
                        MessageEmergencyType.Normal,
                        InstanceId,
                        workItemID,
                        null,
                        PriorityType.Normal,
                        true,
                        null,
                        false,
                        OThinker.H3.Instance.Token.UnspecifiedID,
                        null);
                Engine.InstanceManager.SendMessage(startInstanceMessage);
                result = new BPMServiceResult(true, InstanceId, workItemID, "流程实例启动成功!", string.Empty);
            }
            catch (Exception ex)
            {
                result = new BPMServiceResult(false, ex.ToString());
            }
            return Json(result, JsonRequestBehavior.AllowGet);
        }
        public bool startWorkflow(
            string workflowCode,
            string userCode,
            bool finishStart,
            List <DataItemParam> paramValues)
        {
            //ValidateSoapHeader();
            string workItemID, keyItem, errorMessage;

            workItemID = keyItem = errorMessage = string.Empty;


            try
            {
                // 获取模板
                OThinker.H3.WorkflowTemplate.PublishedWorkflowTemplateHeader workflowTemplate = GetWorkflowTemplate(workflowCode);
                if (workflowTemplate == null)
                {
                    return(false);
                }
                // 查找流程发起人
                OThinker.Organization.User user = this.Engine.Organization.GetUserByCode(userCode) as Organization.User;
                if (user == null)
                {
                    return(false);
                }

                OThinker.H3.DataModel.BizObjectSchema schema = this.Engine.BizObjectManager.GetPublishedSchema(workflowTemplate.BizObjectSchemaCode);
                OThinker.H3.DataModel.BizObject       bo     = new DataModel.BizObject(
                    this.Engine.Organization,
                    this.Engine.MetadataRepository,
                    this.Engine.BizObjectManager,
                    this.Engine.BizBus,
                    schema,
                    OThinker.Organization.User.AdministratorID,
                    OThinker.Organization.OrganizationUnit.DefaultRootID);

                if (paramValues != null)
                {
                    // 这里可以在创建流程的时候赋值
                    //foreach (DataItemParam param in paramValues)
                    //{

                    //    if (bo.Schema.ContainsField(param.ItemName))
                    //    {
                    //        bo[param.ItemName] = param.ItemValue;
                    //    }
                    //}
                    List <OThinker.H3.DataModel.BizObject> details = null;
                    foreach (DataItemParam param in paramValues)
                    {
                        if (!(details != null && details.Count > 0 && details[0].Schema.SchemaCode == param.ItemName))
                        {
                            details = new List <OThinker.H3.DataModel.BizObject>();
                        }
                        OThinker.H3.DataModel.PropertySchema property = schema.GetProperty(param.ItemName);
                        if (property == null)
                        {
                            continue;
                        }
                        SetItemValue(bo, property, param.ItemValue, details, param.ItemName);
                    }
                }

                bo.Create();

                // 创建流程实例
                string InstanceId = this.Engine.InstanceManager.CreateInstance(
                    bo.ObjectID,
                    workflowTemplate.WorkflowCode,
                    workflowTemplate.WorkflowVersion,
                    null,
                    null,
                    user.UnitID,
                    null,
                    false,
                    Instance.InstanceContext.UnspecifiedID,
                    null,
                    Instance.Token.UnspecifiedID);

                // 设置紧急程度为普通
                OThinker.H3.Messages.MessageEmergencyType emergency = Messages.MessageEmergencyType.Normal;
                // 这里也可以在启动流程的时候赋值
                Dictionary <string, object> paramTables = new Dictionary <string, object>();

                // 启动流程的消息
                OThinker.H3.Messages.StartInstanceMessage startInstanceMessage
                    = new OThinker.H3.Messages.StartInstanceMessage(
                          emergency,
                          InstanceId,
                          null,
                          paramTables,
                          Instance.PriorityType.Normal,
                          true,
                          null,
                          false,
                          OThinker.H3.Instance.Token.UnspecifiedID,
                          null);
                Engine.InstanceManager.SendMessage(startInstanceMessage);
            }
            catch (Exception ex)
            {
                return(false);
            }
            return(true);
        }
Exemple #13
0
        /// <summary>
        /// 启动流程实例
        /// </summary>
        /// <param name="workflowCode"></param>
        /// <param name="userCode"></param>
        /// <param name="finishStart"></param>
        /// <param name="paramValues"></param>
        /// <returns></returns>
        public BPMServiceResult StartWorkflow(string workflowCode, string userCode, bool finishStart, List <DataItemParam> paramValues)
        {
            //ValidateSoapHeader();
            BPMServiceResult result = new BPMServiceResult();

            try
            {
                // 获取模板
                OThinker.H3.WorkflowTemplate.PublishedWorkflowTemplateHeader workflowTemplate = GetWorkflowTemplate(workflowCode);
                if (workflowTemplate == null)
                {
                    return(new BPMServiceResult(false, "流程启动失败,流程模板不存在,模板编码:" + workflowCode + "。"));
                }
                // 查找流程发起人
                //OThinker.Organization.User user = Engine.Organization.GetUnitByCode(userCode) as Organization.User;
                string user = GetUserIDByCode(userCode);
                if (user == null)
                {
                    return(new BPMServiceResult(false, "流程启动失败,用户{" + userCode + "}不存在。"));
                }
                OThinker.H3.DataModel.BizObjectSchema schema = Engine.BizObjectManager.GetPublishedSchema(workflowTemplate.BizObjectSchemaCode);
                OThinker.H3.DataModel.BizObject       bo     = new OThinker.H3.DataModel.BizObject(Engine.Organization, Engine.MetadataRepository, Engine.BizObjectManager, null, schema, user);
                if (paramValues != null)
                {
                    // 这里可以在创建流程的时候赋值
                    foreach (DataItemParam param in paramValues)
                    {
                        if (bo.Schema.GetProperty(param.ItemName).LogicType == OThinker.H3.Data.DataLogicType.BizObjectArray)
                        {
                            var t = new List <OThinker.H3.DataModel.BizObject>();
                            foreach (List <DataItemParam> list in (IEnumerable)param.ItemValue)
                            {
                                var m = new OThinker.H3.DataModel.BizObject(Engine.Organization, Engine.MetadataRepository, Engine.BizObjectManager, null, schema.Fields.FirstOrDefault(x => x.ChildSchemaCode == param.ItemName).Schema, user);
                                foreach (DataItemParam item in list)
                                {
                                    if (m.Schema.ContainsField(item.ItemName))
                                    {
                                        m.SetValue(item.ItemName, item.ItemValue);
                                    }
                                }
                                t.Add(m);
                            }
                            bo[param.ItemName] = t.ToArray();
                        }
                        else if (bo.Schema.ContainsField(param.ItemName))
                        {
                            bo[param.ItemName] = param.ItemValue;
                        }
                    }
                }
                bo.Create();
                // 创建流程实例
                //string InstanceId = this.Engine.InstanceManager.CreateInstance(bo.ObjectID,workflowTemplate.WorkflowCode,workflowTemplate.WorkflowVersion,
                //    null,null,user,null, null, false, OThinker.H3.Instance.InstanceContext.UnspecifiedID,null,OThinker.H3.Instance.Token.UnspecifiedID);
                string InstanceId = this.Engine.InstanceManager.CreateInstanceByDefault(bo.ObjectID, workflowTemplate.WorkflowCode, null, user);
                // 设置紧急程度为普通
                OThinker.H3.Messages.MessageEmergencyType emergency = OThinker.H3.Messages.MessageEmergencyType.Normal;
                // 这里也可以在启动流程的时候赋值
                Dictionary <string, object> paramTables = new Dictionary <string, object>();
                // 启动流程的消息
                OThinker.H3.Messages.StartInstanceMessage startInstanceMessage = new OThinker.H3.Messages.StartInstanceMessage(emergency,
                                                                                                                               InstanceId, null, paramTables, OThinker.H3.Instance.PriorityType.Normal, true, null, false,
                                                                                                                               OThinker.H3.Instance.Token.UnspecifiedID, null);
                Engine.InstanceManager.SendMessage(startInstanceMessage);
                result = new BPMServiceResult(true, InstanceId, null, "流程实例启动成功!", "");
            }
            catch (Exception ex)
            {
                result = new BPMServiceResult(false, "流程实例启动失败!错误:" + ex.Message);
            }
            return(result);
        }
        public bool ReturnItem(string userId, string workItemId, string activityCode, string SchemaCode, double xbzjye, string state, DateTime bzjyedysj, string userName, string PassState, double yzzfbzj)
        {
            Organization.User user = this.Engine.Organization.GetUnit(userId) as Organization.User;
            if (user == null)
            {
                return(false);
            }
            // 获取工作项

            OThinker.H3.DataModel.BizObjectSchema schema  = this.Engine.BizObjectManager.GetPublishedSchema(SchemaCode);
            OThinker.H3.WorkItem.WorkItem         item    = this.Engine.WorkItemManager.GetWorkItem(workItemId);
            OThinker.H3.Instance.InstanceContext  context = this.Engine.InstanceManager.GetInstanceContext(item.InstanceId);
            OThinker.H3.DataModel.BizObject       bo      = new OThinker.H3.DataModel.BizObject(Engine, schema, userId);
            bo.ObjectID = context.BizObjectId;
            bo.Load();                            //装载流程数据;

            if (bo.Schema.ContainsField("BZJYE")) //保证金余额
            {
                bo["BZJYE"] = xbzjye;
            }
            if (bo.Schema.ContainsField("LCZT"))
            {
                bo["LCZT"] = state;
            }
            if (bo.Schema.ContainsField("BZJYEDYSJ"))
            {
                bo["BZJYEDYSJ"] = bzjyedysj;
            }
            if (bo.Schema.ContainsField("CWCLR"))
            {
                bo["CWCLR"] = userName;
            }
            if (bo.Schema.ContainsField("CWSPRID"))
            {
                bo["CWSPRID"] = userId;
            }
            //this.AppendComment(item.InstanceId, item, OThinker.Data.BoolMatchValue.Unspecified, "现保证金余额x钱,应再支付X保证金");



            // 结束工作项
            if (PassState == "TG")
            {//财务通过
                this.Engine.WorkItemManager.FinishWorkItem(
                    item.ObjectID,
                    user.ObjectID,
                    H3.WorkItem.AccessPoint.ExternalSystem,
                    null,
                    OThinker.Data.BoolMatchValue.True,
                    string.Empty,
                    null,
                    H3.WorkItem.ActionEventType.Backward,
                    (int)OThinker.H3.Controllers.SheetButtonType.Return);

                if (bo.Schema.ContainsField("CWSPYJDX"))
                {
                    bo["CWSPYJDX"] = "通过";
                }

                this.AppendComment(context, item, OThinker.Data.BoolMatchValue.True, "通过");//财务部通过后,显示通过
            }
            else
            {//财务驳回
                this.Engine.WorkItemManager.FinishWorkItem(
                    item.ObjectID,
                    user.ObjectID,
                    H3.WorkItem.AccessPoint.ExternalSystem,
                    null,
                    OThinker.Data.BoolMatchValue.False,
                    string.Empty,
                    null,
                    H3.WorkItem.ActionEventType.Backward,
                    (int)OThinker.H3.Controllers.SheetButtonType.Return);
                var info = "现保证金余额" + string.Format("{0:N2}", xbzjye) + "元,应再支付" + string.Format("{0:N2}", yzzfbzj) + "保证金";
                this.AppendComment(context, item, OThinker.Data.BoolMatchValue.False, info);

                if (bo.Schema.ContainsField("CWSPYJDX"))
                {
                    bo["CWSPYJDX"] = "驳回";
                }

                try
                {
                    MessageClass ms = new MessageClass();

                    string    sql = @"select distinct a.PARTICIPANT,b.code, d.objectid  , d.code jxsuserCode, e.JXS,e.JXSCODE from Ot_Workitemfinished  a
join Ot_User b on a.PARTICIPANT = b.objectid 
join Ot_Instancecontext c on c.objectid = a.instanceid 
join OT_User d on d.objectid = c.ORIGINATOR 
join I_DealerLoan e on e.objectid = c.bizobjectid
where   ACTIVITYCODE='Activity3' and c.workFlowCode = 'DealerLoan' and instanceid='" + item.InstanceId + "'";
                    DataTable dt  = OThinker.H3.Controllers.AppUtility.Engine.EngineConfig.CommandFactory.CreateCommand().ExecuteDataTable(sql);

                    string msstr1 = dt.Rows[0]["JXS"].ToString() + "(" + dt.Rows[0]["JXSCODE"].ToString() + ") 还需要支付<font color=\"red\">" + string.Format("{0:N2}", yzzfbzj) + "</font> 元 保证金金额才可以进行本次贷款申请,现保证金账户余额 " + string.Format("{0:N2}", xbzjye) + " 元";

                    string msstr2 = "您的账户还需要支付<font color=\"red\">" + string.Format("{0:N2}", yzzfbzj) + "</font> 元 保证金金额才可以进行本次贷款申请,现保证金账户余额 " + string.Format("{0:N2}", xbzjye) + "元";

                    if (dt != null && dt.Rows != null && dt.Rows.Count > 0)
                    {
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            ms.InsertMSG(dt.Rows[i]["PARTICIPANT"].ToString(), dt.Rows[i]["code"].ToString(), msstr1, true, 0, "");
                        }
                    }

                    ms.InsertMSG(dt.Rows[0]["objectid"].ToString(), dt.Rows[0]["jxsCode"].ToString(), msstr2, false, 0, "");
                }
                catch (Exception e)
                {
                }
            }

            bo.Update();
            // 准备触发后面Activity的消息
            OThinker.H3.Messages.ActivateActivityMessage activateMessage
                = new OThinker.H3.Messages.ActivateActivityMessage(
                      OThinker.H3.Messages.MessageEmergencyType.Normal,
                      item.InstanceId,
                      activityCode,
                      OThinker.H3.Instance.Token.UnspecifiedID,
                      null,
                      new int[] { item.TokenId },
                      false,
                      H3.WorkItem.ActionEventType.Backward);

            // 通知该Activity已经完成
            OThinker.H3.Messages.AsyncEndMessage endMessage =
                new OThinker.H3.Messages.AsyncEndMessage(
                    OThinker.H3.Messages.MessageEmergencyType.Normal,
                    item.InstanceId,
                    item.ActivityCode,
                    item.TokenId,
                    OThinker.Data.BoolMatchValue.False,
                    true,
                    OThinker.Data.BoolMatchValue.False,
                    false,
                    activateMessage);
            this.Engine.InstanceManager.SendMessage(endMessage);



            return(true);
        }
        /// <summary>
        /// 结束工作任务
        /// </summary>
        public void ENDWorkItem(string UpdateUserId, string schemaCode, string workItemID, string STATE)
        {
            OThinker.H3.WorkItem.WorkItem item = this.Engine.WorkItemManager.GetWorkItem(workItemID);

            if (!string.IsNullOrEmpty(schemaCode))
            {
                OThinker.H3.DataModel.BizObjectSchema schema = this.Engine.BizObjectManager.GetPublishedSchema(schemaCode);
                OThinker.H3.DataModel.BizObject       bo     = new OThinker.H3.DataModel.BizObject(Engine, schema, UpdateUserId);

                OThinker.H3.Instance.InstanceContext ic = this.Engine.InstanceManager.GetInstanceContext(item.InstanceId);

                if (!string.IsNullOrEmpty(workItemID))
                {
                    bo.ObjectID = ic.BizObjectId;
                    bo.Load();//装载流程数据;

                    if (!string.IsNullOrEmpty(STATE))
                    {
                        if (bo.Schema.ContainsField("LCZT"))
                        {
                            bo["LCZT"] = STATE;
                        }
                        if (bo.Schema.ContainsField("OperationStates"))
                        {
                            bo["OperationStates"] = STATE;
                        }
                        if (bo.Schema.ContainsField("states"))
                        {
                            bo["states"] = STATE;
                        }
                    }

                    bo.Update();
                }
            }

            // 结束工作项
            this.Engine.WorkItemManager.FinishWorkItem(
                workItemID,
                UpdateUserId,
                OThinker.H3.WorkItem.AccessPoint.ExternalSystem,
                null,
                OThinker.Data.BoolMatchValue.True,
                string.Empty,
                null,
                OThinker.H3.WorkItem.ActionEventType.Forward,
                (int)OThinker.H3.Controllers.SheetButtonType.Submit);

            // 需要通知实例事件管理器结束事件
            Messages.AsyncEndMessage endMessage = new OThinker.H3.Messages.AsyncEndMessage(
                Messages.MessageEmergencyType.Normal,
                item.InstanceId,
                item.ActivityCode,
                item.TokenId,
                OThinker.Data.BoolMatchValue.True,
                false,
                OThinker.Data.BoolMatchValue.True,
                true,
                null);
            this.Engine.InstanceManager.SendMessage(endMessage);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="SimulationID"></param>
        /// <param name="SimulationToken"></param>
        /// <param name="SchemaCode">流程编码</param>
        /// <returns></returns>
        private object LoadInstances(string SimulationID, string SimulationToken, string SchemaCode)
        {
            if (string.IsNullOrEmpty(SimulationID))
            {
                return(null);
            }
            InstanceSimulation Simulation = this.Engine.SimulationManager.GetSimulation(SimulationID);

            if (Simulation == null || Simulation.NextBatchNo <= InstanceSimulationLog.InitialBatchNo)
            {
                return(null);
            }

            //根据流程编码查找SchemaCode
            string bizChemaCode = this.Engine.WorkflowManager.GetClause(SchemaCode).BizSchemaCode;
            //查看批次号
            int SimulationTokenID = 0;

            int.TryParse(SimulationToken + string.Empty, out SimulationTokenID);
            if (SimulationTokenID <= InstanceSimulationLog.InitialBatchNo || SimulationTokenID >= Simulation.NextBatchNo)
            {
                SimulationTokenID = Simulation.NextBatchNo - 1;
            }
            object    gridData      = null;
            DataTable InstanceTable = this.Engine.EngineConfig.CommandFactory.CreateCommand().ExecuteDataTable(
                " SELECT "
                + "A." + InstanceSimulationLog.PropertyName_DataItemsSummary
                + ",B." + InstanceContext.C_ObjectID
                + ",B." + InstanceContext.PropertyName_Originator
                + ",B." + InstanceContext.PropertyName_InstanceName
                + ",B." + InstanceContext.PropertyName_State
                + " FROM " + InstanceSimulationLog.TableName + " A JOIN " + InstanceContext.TableName + " B "
                + " ON A." + InstanceSimulationLog.PropertyName_InstanceId + "=B." + InstanceContext.C_ObjectID
                + " WHERE A." + InstanceSimulationLog.PropertyName_SimulationID + "='" + SimulationID + "'"
                + " AND A." + InstanceSimulationLog.PropertyName_BatchNo + "=" + SimulationTokenID + " ");

            if (InstanceTable != null && InstanceTable.Rows.Count > 0)
            {
                //一次获取所有用户
                List <string> lstUserIDs = new List <string>();
                foreach (DataRow row in InstanceTable.Rows)
                {
                    lstUserIDs.Add(row[InstanceContext.PropertyName_Originator] + string.Empty);
                }
                OThinker.Organization.Unit[] Units = this.Engine.Organization.GetUnits(lstUserIDs.ToArray()).ToArray();
                //<UserID,UserName>
                Dictionary <string, string> DicUnits = new Dictionary <string, string>();
                if (Units != null)
                {
                    foreach (OThinker.Organization.Unit u in Units)
                    {
                        if (!DicUnits.ContainsKey(u.ObjectID))
                        {
                            DicUnits.Add(u.ObjectID, u.Name);
                        }
                    }
                }

                //输出到前台的表格数据
                List <object> InstanceObjs = new List <object>();
                foreach (DataRow row in InstanceTable.Rows)
                {
                    string DataItemsSummary = row[InstanceSimulationLog.PropertyName_DataItemsSummary] + string.Empty;

                    string instanceId = row[InstanceContext.C_ObjectID] + string.Empty;
                    Dictionary <string, string>           NameValues = InstanceSimulationLog.DeserializeItemSummary(DataItemsSummary);
                    OThinker.H3.DataModel.BizObjectSchema schema     = this.Engine.BizObjectManager.GetPublishedSchema(bizChemaCode);
                    Dictionary <string, string>           ItemValues = new Dictionary <string, string>();
                    List <string> participants = new List <string>();
                    foreach (string key in NameValues.Keys)
                    {
                        OThinker.H3.DataModel.FieldSchema field = schema.GetField(key);
                        if (field != null && (field.LogicType == OThinker.H3.Data.DataLogicType.SingleParticipant || field.LogicType == OThinker.H3.Data.DataLogicType.MultiParticipant))
                        {
                            participants.Add(NameValues[key]);
                        }
                    }
                    OThinker.Organization.Unit[] units = this.Engine.Organization.GetUnits(participants.ToArray()).ToArray();
                    Dictionary <string, string>  names = new Dictionary <string, string>();
                    foreach (OThinker.Organization.Unit unit in units)
                    {
                        if (!names.ContainsKey(unit.ObjectID))
                        {
                            names.Add(unit.ObjectID, unit.Name);
                        }
                    }
                    foreach (string key in NameValues.Keys)
                    {
                        OThinker.H3.DataModel.FieldSchema field = schema.GetField(key);
                        if (field != null && (field.LogicType == OThinker.H3.Data.DataLogicType.SingleParticipant || field.LogicType == OThinker.H3.Data.DataLogicType.MultiParticipant))
                        {
                            if (names.ContainsKey(NameValues[key]))
                            {
                                ItemValues.Add(key, names[NameValues[key]]);
                            }
                        }
                        else
                        {
                            ItemValues.Add(key, NameValues[key]);
                        }
                    }
                    InstanceObjs.Add(new
                    {
                        ObjectID     = instanceId,
                        Originator   = DicUnits.ContainsKey(row[InstanceContext.PropertyName_Originator] + string.Empty) ? DicUnits[row[InstanceContext.PropertyName_Originator] + string.Empty] : "",
                        InstanceName = row[InstanceContext.PropertyName_InstanceName] + string.Empty,
                        State        = "InstanceState.InstanceState_" + Enum.Parse(typeof(InstanceState), row[InstanceContext.PropertyName_State] + string.Empty).ToString(),
                        Url          = this.GetInstanceUrl(instanceId, "", DateTime.Now.ToString("yyyyMMddHHmmss")),
                        DataItems    = ItemValues
                    });
                }
                gridData = CreateLigerUIGridData(InstanceObjs.ToArray());
            }

            if (gridData == null)
            {
                gridData = new { Rows = new object[] { }, Total = 0 };
            }
            var data = new
            {
                SimulationName = Simulation.InstanceName,
                Instances      = gridData
            };

            return(data);
        }