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);
        }
        /// <summary>
        /// 保存数据模板导入数据到数据库
        /// </summary>
        /// <param name="dt">要保存的数据表</param>
        /// <returns>保存结果</returns>
        public ActionResult SaveUploadBizMasterData(DataTable dt)
        {
            ActionResult result = new ActionResult();

            if (dt != null && dt.Rows.Count > 0)
            {
                try
                {
                    List <string> columNames = new List <string>();
                    List <string> fields     = new List <string>();
                    foreach (DataColumn c in dt.Columns)
                    {
                        columNames.Add(c.ColumnName);
                    }
                    BizObjectSchema[] schemas = this.Engine.BizObjectManager.GetPublishedSchemas();
                    foreach (DataRow r in dt.Rows)
                    {
                        DataModel.BizObject bo = new DataModel.BizObject(
                            this.Engine.Organization,
                            this.Engine.MetadataRepository,
                            this.Engine.BizObjectManager,
                            null,        //bizBus
                            this.PublishedSchema,
                            this.UserValidator.UserID,
                            this.UserValidator.User.ParentID);
                        bool success = true;
                        foreach (string columName in columNames)
                        {
                            if (bo.Schema.GetField(columName) != null)
                            {
                                bo[columName] = r[columName];
                            }
                            else
                            {
                                if (!fields.Contains(columName))
                                {
                                    fields.Add(columName);
                                    success = false;
                                }
                            }
                        }
                        if (success)
                        {
                            bo.Create();
                        }
                    }
                    if (fields.Count > 0)
                    {
                        List <string> errors = new List <string>();
                        foreach (string field in fields.ToArray())
                        {
                            errors.Add(field);
                            //faileds += field + "、";
                        }
                        result.Success = false;
                        result.Message = "EditBizObjectSchema.Msg15";//MasterData_Mssg15
                        result.Extend  = errors;
                    }
                    else
                    {
                        result.Success = true;
                        result.Message = "EditBizObjectSchema.Msg9";//MasterData_Mssg9
                        //this.CloseCurrentDialog();
                        //RegisterScriptManager("CloseCurrentDialog", "setTimeout('CloseCurrentDialog()', 2000)");
                    }
                }
                catch (Exception e)
                {
                    result.Success = false;
                    result.Message = "EditBizObjectSchema.Msg7";//7
                    result.Extend  = e.Message;
                }
            }
            else
            {
                result.Success = false;
                result.Message = "EditBizObjectSchema.Msg17";//17
            }
            return(result);
        }
Exemple #3
0
        /// <summary>
        /// 验证权限
        /// </summary>
        /// <param name="UserValidator"></param>
        /// <param name="SheetDataType"></param>
        /// <param name="IsOriginateMode"></param>
        /// <param name="SchemaCode"></param>
        /// <param name="BizObject"></param>
        /// <param name="SheetMode"></param>
        /// <param name="WorkflowCode"></param>
        /// <param name="WorkItem"></param>
        /// <param name="InstanceContext"></param>
        /// <returns></returns>
        public static bool ValidateAuthorization(
            UserValidator UserValidator,
            SheetDataType SheetDataType,
            bool IsOriginateMode,
            string SchemaCode,
            DataModel.BizObject BizObject,
            SheetMode SheetMode,
            string WorkflowCode,
            WorkItem.WorkItem WorkItem,
            WorkItem.CirculateItem CirculateItem,
            Instance.InstanceContext InstanceContext)
        {
            if (UserValidator.ValidateAdministrator())
            {
                return(true);
            }
            // 业务对象表单
            else if (SheetDataType == SheetDataType.BizObject)
            {
                if (IsOriginateMode)
                {
                    return(UserValidator.ValidateBizObjectAdd(SchemaCode, null, UserValidator.UserID));
                }
                else
                {
                    if (UserValidator.ValidateOrgAdmin(BizObject.OwnerId))
                    {
                        return(true);
                    }
                    return(UserValidator.ValidateBizObjectAdmin(SchemaCode, null, BizObject.OwnerId));
                }
            }
            else
            {
                switch (SheetMode)
                {
                case SheetMode.Originate:
                    return(UserValidator.ValidateCreateInstance(WorkflowCode));

                case SheetMode.View:
                case SheetMode.Print:
                    if (WorkItem != null &&
                        ValidateWorkItemAuth(WorkItem, UserValidator, UserValidator.Engine.AgencyManager))
                    {
                        return(true);
                    }
                    else if (CirculateItem != null && ValidateCirculateItemAuth(CirculateItem, UserValidator))
                    {
                        return(true);
                    }
                    else if (UserValidator.ValidateWFInsView(WorkflowCode, InstanceContext.Originator))
                    {
                        // 是否允许查看这个流程模板的所有实例
                        return(true);
                    }
                    else
                    {
                        // 判定用户是否参与过流程实例
                        string[] workItems = UserValidator.Engine.Query.QueryWorkItems(
                            new string[] { InstanceContext.InstanceId },
                            new string[] { UserValidator.UserID },
                            DateTime.Now.AddYears(-100),
                            DateTime.Now.AddDays(1),
                            H3.WorkItem.WorkItemState.Unspecified,
                            OThinker.H3.WorkItem.WorkItem.NullWorkItemID);
                        if (workItems != null && workItems.Length > 0)
                        {
                            return(true);
                        }
                        return(false);
                    }

                case SheetMode.Work:
                    if (WorkItem != null)
                    {
                        return(ValidateWorkItemAuth(WorkItem, UserValidator, UserValidator.Engine.AgencyManager));
                    }
                    else
                    {
                        return(ValidateCirculateItemAuth(CirculateItem, UserValidator));
                    }

                default:
                    throw new NotImplementedException();
                }
            }
        }
Exemple #4
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));
        }