예제 #1
0
        private string GetScopeSql(string orgIDs, string roleIDs)
        {
            string field = string.Format("S_A_User.ID,S_A_User.Code,case when '{0}'='EN' then isnull(S_A_User.NameEN,S_A_User.Name) else S_A_User.Name end as Name,S_A_User.SortIndex, WorkNo,Sex,Phone,MobilePhone,Email,Address,PrjID,PrjName,DeptID,DeptFullID,DeptName,RTX,FullID", FormulaHelper.GetCurrentLGID());

            if (string.IsNullOrWhiteSpace(orgIDs) && string.IsNullOrWhiteSpace(roleIDs))
            {
                return(string.Format("select {0} from S_A_User join S_A__OrgUser on UserID=S_A_User.ID join S_A_Org on S_A_Org.ID=OrgID where S_A_User.IsDeleted<>'1'", field));
            }
            else if (string.IsNullOrWhiteSpace(roleIDs) == true)
            {
                string orgStr = "";
                if (!string.IsNullOrEmpty(orgIDs) && ConfigurationManager.AppSettings.AllKeys.Contains("UserSelectOnlyCurrent") && ConfigurationManager.AppSettings["UserSelectOnlyCurrent"].ToLower().Equals("true"))
                {
                    orgStr = string.Format(" and DeptID in ('{0}') ", orgIDs.Replace(",", "','"));
                }
                else
                {
                    orgStr = string.Format(" and OrgID in('{0}')", orgIDs.Replace(",", "','"));
                }

                return(string.Format("select {1} from S_A_User join S_A__OrgUser on UserID=S_A_User.ID join S_A_Org on S_A_Org.ID=OrgID where S_A_User.IsDeleted<>'1' {0} ", orgStr, field));
            }
            else
            {
                string userIDs = FormulaHelper.GetService <IRoleService>().GetUserIDsInRoles(roleIDs, orgIDs);
                //2018-1-30 剥离项目角色选人功能
                var prjRoleUser = PrjRoleExt.GetRoleUserIDs(roleIDs, orgIDs);
                if (!string.IsNullOrEmpty(prjRoleUser))
                {
                    userIDs = (prjRoleUser + "," + userIDs).Trim(',');
                }

                //Oracle的in查询长度不能超过1000
                var arr = userIDs.Split(',');
                string where = "";
                var i = 0;
                while (i * 1000 < arr.Length)
                {
                    where += string.Format(" or S_A_User.ID in('{0}')", string.Join("','", arr.Skip(i * 1000).Take(1000)));
                    i++;
                }
                where = where.Substring(4);
                string sql = string.Format("select {1} from S_A_User join S_A__OrgUser on UserID=S_A_User.ID join S_A_Org on S_A_Org.ID=OrgID where S_A_User.IsDeleted<>'1' and {0}", where, field);
                return(sql);
            }
        }
예제 #2
0
        public JsonResult TestGetUsers(string roleIDs, string orgIDs)
        {
            IRoleService roleService = FormulaHelper.GetService <IRoleService>();
            IUserService userService = FormulaHelper.GetService <IUserService>();

            string userIDs = roleService.GetUserIDsInRoles(roleIDs, orgIDs);
            //2018-1-30 剥离项目角色选人功能
            var prjRoleUser = PrjRoleExt.GetRoleUserIDs(roleIDs, orgIDs);

            if (!string.IsNullOrEmpty(prjRoleUser))
            {
                userIDs = (prjRoleUser + "," + userIDs).Trim(',');
            }

            string userNames = userService.GetUserNames(userIDs);

            return(Json(new { UserIDs = userIDs, UserNames = userNames }));
        }
예제 #3
0
        private string GetScopeSql(string orgIDs, string roleIDs)
        {
            string field  = string.Format("S_A_User.ID,S_A_User.Code,case when '{0}'='EN' then isnull(S_A_User.NameEN,S_A_User.Name) else S_A_User.Name end as Name,S_A_User.SortIndex, WorkNo,Sex,Phone,MobilePhone,Email,Address,PrjID,PrjName,DeptID,DeptFullID,DeptName,RTX,FullID", FormulaHelper.GetCurrentLGID());
            var    result = string.Empty;

            if (string.IsNullOrWhiteSpace(orgIDs) && string.IsNullOrWhiteSpace(roleIDs))
            {
                result = string.Format("select {0} from S_A_User join S_A__OrgUser on UserID=S_A_User.ID join S_A_Org on S_A_Org.ID=OrgID where S_A_User.IsDeleted<>'1'", field);
            }
            else if (string.IsNullOrWhiteSpace(roleIDs) == true)
            {
                string orgStr = "";
                if (!string.IsNullOrEmpty(orgIDs) && ConfigurationManager.AppSettings.AllKeys.Contains("UserSelectOnlyCurrent") && ConfigurationManager.AppSettings["UserSelectOnlyCurrent"].ToLower().Equals("true"))
                {
                    orgStr = string.Format(" and DeptID in ('{0}') ", orgIDs.Replace(",", "','"));
                }
                else
                {
                    orgStr = string.Format(" and OrgID in('{0}')", orgIDs.Replace(",", "','"));
                }

                result = string.Format("select {1} from S_A_User join S_A__OrgUser on UserID=S_A_User.ID join S_A_Org on S_A_Org.ID=OrgID where S_A_User.IsDeleted<>'1' {0} ", orgStr, field);
            }
            else
            {
                string userIDs = FormulaHelper.GetService <IRoleService>().GetUserIDsInRoles(roleIDs, orgIDs);
                //2018-1-30 剥离项目角色选人功能
                var prjRoleUser = PrjRoleExt.GetRoleUserIDs(roleIDs, orgIDs);
                if (!string.IsNullOrEmpty(prjRoleUser))
                {
                    userIDs = (prjRoleUser + "," + userIDs).Trim(',');
                }

                //Oracle的in查询长度不能超过1000
                var arr = userIDs.Split(',');
                string where = "";
                var i = 0;
                while (i * 1000 < arr.Length)
                {
                    where += string.Format(" or S_A_User.ID in('{0}')", string.Join("','", arr.Skip(i * 1000).Take(1000)));
                    i++;
                }
                where  = where.Substring(4);
                result = string.Format("select {1} from S_A_User join S_A__OrgUser on UserID=S_A_User.ID join S_A_Org on S_A_Org.ID=OrgID where S_A_User.IsDeleted<>'1' and {0}", where, field);
            }
            if (ConfigurationManager.AppSettings.AllKeys.Contains("UserAptitude") && ConfigurationManager.AppSettings["UserAptitude"].ToLower().Equals("true"))
            {
                //启用资质
                var    projectInfoID = this.GetQueryString("ProjectInfoID");
                var    projectLevel  = this.GetQueryString("ProjectLevel");
                var    projectClass  = this.GetQueryString("ProjectClass");
                string hrBaseName    = SQLHelper.CreateSqlHelper(ConnEnum.HR).DbName;
                var    aptitudeSql   = @"select distinct UserID,UserName,Major MajorValue,Position RoleCode from {0}..S_D_UserAptitude where Major!='Project' {1}
union
select distinct UserID,UserName,Major MajorValue,Position RoleCode from {0}..S_D_UserAptitudeApply where Major!='Project' {2}";
                var    userAptString = " and ProjectClass='" + projectClass + "' and AptitudeLevel>=" + projectLevel;
                aptitudeSql = string.Format(aptitudeSql, hrBaseName, userAptString, userAptString + " and ProjectInfoID='" + projectInfoID + "'");
                result      = string.Format(@"select UserDt.*,AptDt.MajorValue,AptDt.RoleCode,majorDef.Name MajorName,roleDef.RoleName from ({0}) UserDt 
                left join ({1}) AptDt on AptDt.UserID = UserDt.ID and AptDt.RoleCode!='Project'
                left join {2}..S_D_WBSAttrDefine majorDef on majorDef.Type='Major' and majorDef.Code = AptDt.MajorValue
                left join {2}..S_D_RoleDefine roleDef on roleDef.RoleCode = AptDt.RoleCode
                where aptDt.RoleCode is not null", result, aptitudeSql, SQLHelper.CreateSqlHelper(ConnEnum.InfrasBaseConfig).DbName);
            }
            return(result);
        }
예제 #4
0
        List <Dictionary <string, object> > getUser(DataRow defineRow, DataRow projectInfo, DataRow dataSourceRow)
        {
            var result  = new List <Dictionary <string, object> >();
            var userIDs = string.Empty;

            if (defineRow["UserIDs"] != null && defineRow["UserIDs"] != DBNull.Value && !String.IsNullOrEmpty(defineRow["UserIDs"].ToString()))
            {
                userIDs = defineRow["UserIDs"].ToString();
            }
            else if (!String.IsNullOrEmpty(defineRow["UserIDsFromField"].ToString()))
            {
                if (projectInfo.Table.Columns.Contains(defineRow["UserIDsFromField"].ToString()))
                {
                    if (projectInfo[defineRow["UserIDsFromField"].ToString()] != null &&
                        projectInfo[defineRow["UserIDsFromField"].ToString()] != DBNull.Value &&
                        !String.IsNullOrEmpty(projectInfo[defineRow["UserIDsFromField"].ToString()].ToString()))
                    {
                        userIDs = projectInfo[defineRow["UserIDsFromField"].ToString()].ToString();
                    }
                }
                else if (dataSourceRow.Table.Columns.Contains(defineRow["UserIDsFromField"].ToString()))
                {
                    if (dataSourceRow[defineRow["UserIDsFromField"].ToString()] != null &&
                        dataSourceRow[defineRow["UserIDsFromField"].ToString()] != DBNull.Value &&
                        !String.IsNullOrEmpty(dataSourceRow[defineRow["UserIDsFromField"].ToString()].ToString()))
                    {
                        userIDs = dataSourceRow[defineRow["UserIDsFromField"].ToString()].ToString();
                    }
                }
            }
            else if (defineRow["RoleIDs"] != null && defineRow["RoleIDs"] != DBNull.Value && !String.IsNullOrEmpty(defineRow["RoleIDs"].ToString()))
            {
                var orgID = "";
                if (defineRow["OrgIDs"] != null && defineRow["OrgIDs"] != DBNull.Value && !String.IsNullOrEmpty(defineRow["OrgIDs"].ToString()))
                {
                    orgID = defineRow["OrgIDs"].ToString();
                }
                if (String.IsNullOrEmpty(orgID) && defineRow["OrgIDFromField"] != null && defineRow["OrgIDFromField"] != DBNull.Value && !String.IsNullOrEmpty(defineRow["OrgIDFromField"].ToString()))
                {
                    if (projectInfo.Table.Columns.Contains(defineRow["OrgIDFromField"].ToString()) && projectInfo[defineRow["OrgIDFromField"].ToString()] != null && projectInfo[defineRow["OrgIDFromField"].ToString()] != DBNull.Value)
                    {
                        orgID = projectInfo[defineRow["OrgIDFromField"].ToString()].ToString();
                    }
                }
                userIDs = UserService.GetUserIDsInRoles(defineRow["RoleIDs"].ToString(), orgID);
                var prjRoleUser = PrjRoleExt.GetRoleUserIDs(defineRow["RoleIDs"].ToString(), orgID);
                if (!string.IsNullOrEmpty(prjRoleUser))
                {
                    userIDs = (prjRoleUser + "," + userIDs).Trim(',');
                }
            }
            else if (defineRow["RoleIDsFromField"] != null && defineRow["RoleIDsFromField"] != DBNull.Value && !String.IsNullOrEmpty(defineRow["RoleIDsFromField"].ToString()))
            {
                var roleID = "";
                if (projectInfo.Table.Columns.Contains(defineRow["RoleIDsFromField"].ToString()) && projectInfo[defineRow["RoleIDsFromField"].ToString()] != null && projectInfo[defineRow["RoleIDsFromField"].ToString()] != DBNull.Value)
                {
                    roleID = projectInfo[defineRow["RoleIDsFromField"].ToString()].ToString();
                }
                else if (dataSourceRow.Table.Columns.Contains(defineRow["RoleIDsFromField"].ToString()))
                {
                    roleID = dataSourceRow[defineRow["RoleIDsFromField"].ToString()].ToString();
                }
                if (!String.IsNullOrEmpty(roleID))
                {
                    var orgID = "";
                    if (defineRow["OrgIDs"] != null && defineRow["OrgIDs"] != DBNull.Value && !String.IsNullOrEmpty(defineRow["OrgIDs"].ToString()))
                    {
                        orgID = defineRow["OrgIDs"].ToString();
                    }
                    if (String.IsNullOrEmpty(orgID) && defineRow["OrgIDFromField"] != null && defineRow["OrgIDFromField"] != DBNull.Value && !String.IsNullOrEmpty(defineRow["OrgIDFromField"].ToString()))
                    {
                        if (projectInfo.Table.Columns.Contains(defineRow["OrgIDFromField"].ToString()) && projectInfo[defineRow["OrgIDFromField"].ToString()] != null && projectInfo[defineRow["OrgIDFromField"].ToString()] != DBNull.Value)
                        {
                            orgID = projectInfo[defineRow["OrgIDFromField"].ToString()].ToString();
                        }
                        else if (dataSourceRow.Table.Columns.Contains(defineRow["OrgIDFromField"].ToString()))
                        {
                            orgID = dataSourceRow[defineRow["OrgIDFromField"].ToString()].ToString();
                        }
                    }
                    userIDs = UserService.GetUserIDsInRoles(defineRow["RoleIDs"].ToString(), orgID);
                }
            }

            if (!String.IsNullOrEmpty(userIDs))
            {
                var userNames = UserService.GetUserNames(userIDs).Split(',');
                if (userIDs.Split(',').Length == userNames.Length)
                {
                    for (int i = 0; i < userIDs.Split(',').Length; i++)
                    {
                        var dic = new Dictionary <string, object>();
                        dic.SetValue("UserID", userIDs.Split(',')[i]);
                        dic.SetValue("UserName", userNames[i]);
                        result.Add(dic);
                    }
                }
            }
            return(result);
        }
예제 #5
0
        public void SendMsg(S_WF_InsTaskExec taskExec, string execComment, string nextUserIDs, string nextUserNames)
        {
            try
            {
                string msg = "";

                #region 生成消息
                string tmpl = this.MsgTmpl;
                Regex  reg  = new Regex("\\{[0-9a-zA-Z_\u4e00-\u9faf]*\\}");
                msg = reg.Replace(tmpl, (Match m) =>
                {
                    string value = m.Value.Trim('{', '}');

                    //先替换表单字段
                    if (taskExec.S_WF_InsFlow.FormDic.ContainsKey(value))
                    {
                        return(taskExec.S_WF_InsFlow.FormDic[value]);
                    }

                    switch (value)
                    {
                    case "TaskName":
                        return(taskExec.S_WF_InsTask.TaskName);

                    case "FlowName":
                        return(taskExec.S_WF_InsFlow.FlowName);

                    case "RoutingName":
                        return(this.Name);

                    case "TaskUserID":
                        return(taskExec.TaskUserID);

                    case "TaskUserName":
                        return(taskExec.TaskUserName);

                    case "ExecUserID":
                        return(taskExec.ExecUserID);

                    case "ExecUserName":
                        return(taskExec.ExecUserName);

                    case "ExecTime":
                        return(DateTime.Now.ToString());

                    case "ExecComment":
                        return(execComment);

                    case "NextUserIDs":
                        return(nextUserIDs);

                    case "NextUserNames":
                        return(nextUserNames);

                    case "NextStepCode":
                        return(this.S_WF_InsDefFlow.S_WF_InsDefStep.SingleOrDefault(c => c.ID == this.EndID).Code);

                    case "NextStepName":
                        return(this.S_WF_InsDefFlow.S_WF_InsDefStep.SingleOrDefault(c => c.ID == this.EndID).Name);

                    case "StepCode":
                        return(this.S_WF_InsDefStep.Code);

                    case "StepName":
                        return(this.S_WF_InsDefStep.Name);

                    default:
                        return(m.Value);
                    }
                });

                #endregion

                if (msg == "")
                {
                    return;
                }

                List <string> userIdList = new List <string>();

                var entities = FormulaHelper.GetEntities <WorkflowEntities>();
                var flow     = taskExec.S_WF_InsFlow;

                //给指定人发消息
                if (!string.IsNullOrEmpty(this.MsgUserIDs))
                {
                    userIdList.AddRange(this.MsgUserIDs.Split(','));
                }


                //环节任务执行人
                if (!string.IsNullOrEmpty(this.MsgUserIDsFromStepExec))
                {
                    foreach (string stepId in this.MsgUserIDsFromStepExec.Split(','))
                    {
                        var task = flow.S_WF_InsTask.LastOrDefault(c => c.InsDefStepID == stepId);
                        if (task == null)
                        {
                            throw new Exception("发送消息配置错误");
                        }
                        foreach (var item in task.S_WF_InsTaskExec)
                        {
                            userIdList.Add(item.ExecUserID);
                        }
                    }
                }
                //环节任务接收人
                if (!string.IsNullOrEmpty(this.MsgUserIDsFromStep))
                {
                    foreach (string stepId in this.MsgUserIDsFromStep.Split(','))
                    {
                        var task = flow.S_WF_InsTask.LastOrDefault(c => c.InsDefStepID == this.MsgUserIDsFromStep);
                        if (task == null)
                        {
                            throw new Exception("发送消息配置错误");
                        }
                        userIdList.AddRange(task.TaskUserIDs.Split(','));
                    }
                }
                //环节任务发送人
                if (!string.IsNullOrEmpty(this.MsgUserIDsFromStepSender))
                {
                    foreach (string stepId in this.MsgUserIDsFromStepSender.Split(','))
                    {
                        var task = flow.S_WF_InsTask.LastOrDefault(c => c.InsDefStepID == this.MsgUserIDsFromStepSender);
                        if (task == null)
                        {
                            throw new Exception("发送消息配置错误");
                        }
                        userIdList.AddRange(task.SendTaskUserIDs.Split(','));
                    }
                }
                //取自字段
                if (!string.IsNullOrEmpty(this.MsgUserIDsFromField))
                {
                    userIdList.AddRange(flow.FormDic[this.MsgUserIDsFromField].Split(','));
                }

                #region 指定组织、角色

                string orgIDs  = this.MsgOrgIDs;
                string roleIDs = this.MsgRoleIDs;

                if (string.IsNullOrEmpty(orgIDs) && !string.IsNullOrEmpty(this.MsgOrgIDsFromField))
                {
                    orgIDs = flow.FormDic[this.MsgOrgIDsFromField];
                }
                if (string.IsNullOrEmpty(roleIDs) && !string.IsNullOrEmpty(this.MsgRoleIDsFromField))
                {
                    roleIDs = flow.FormDic[this.MsgRoleIDsFromField];
                }

                if (!string.IsNullOrEmpty(this.MsgOrgIDFromUser) && string.IsNullOrEmpty(orgIDs))
                {
                    var user = FormulaHelper.GetUserInfo();
                    orgIDs = user.UserOrgID;
                }


                if (!string.IsNullOrEmpty(roleIDs))
                {
                    IRoleService roleService = FormulaHelper.GetService <IRoleService>();
                    string       userIDs     = roleService.GetUserIDsInRoles(roleIDs, orgIDs);

                    //2018-1-30 剥离项目角色选人功能
                    var prjRoleUser = PrjRoleExt.GetRoleUserIDs(roleIDs, orgIDs);
                    if (!string.IsNullOrEmpty(prjRoleUser))
                    {
                        userIDs = (prjRoleUser + "," + userIDs).Trim(',');
                    }

                    userIdList.AddRange(userIDs.Split(','));
                }
                else if (!string.IsNullOrEmpty(orgIDs))
                {
                    IOrgService orgService = FormulaHelper.GetService <IOrgService>();
                    string      userIDs    = orgService.GetUserIDsInOrgs(orgIDs);
                    userIdList.AddRange(userIDs.Split(','));
                }

                #endregion

                if (this.MsgSendToTaskUser == "1")
                {
                    userIdList.AddRange(nextUserIDs.Split(','));
                }


                IUserService    userService  = FormulaHelper.GetService <IUserService>();
                IMessageService msgService   = FormulaHelper.GetService <IMessageService>();
                string          resutUserIDs = string.Join(",", userIdList.Distinct());
                resutUserIDs = resutUserIDs.Trim(' ', ',');
                string resultUserNames = userService.GetUserNames(resutUserIDs);

                var msgType = Config.MsgType.Normal;
                if (!string.IsNullOrEmpty(this.MsgType))
                {
                    msgType = (MsgType)Enum.Parse(typeof(Config.MsgType), this.MsgType);
                }

                string url = this.S_WF_InsDefFlow.FormUrl;
                if (url.Contains("?"))
                {
                    url += "&";
                }
                else
                {
                    url += "?";
                }
                url += "FuncType=View&ID=" + taskExec.S_WF_InsFlow.FormInstanceID;

                msgService.SendMsg(msg, msg, url, "", resutUserIDs, resultUserNames, null, MsgReceiverType.UserType, msgType);
            }
            catch (Exception ex)
            {
                throw new FlowException(ex.Message);
            }
        }
예제 #6
0
        private void StartFlowExe(Dictionary <string, object> logicDef)
        {
            var settings = logicDef.GetValue("Settings");

            if (String.IsNullOrEmpty(settings))
            {
                return;
            }
            var    settingDic     = JsonHelper.ToObject(settings);
            var    wfEntities     = FormulaHelper.GetEntities <WorkflowEntities>();
            var    defFlow        = wfEntities.S_WF_DefFlow.Find(settingDic.GetValue("FlowID"));
            string startTaskDefID = settingDic.GetValue("StartTaskID");

            if (defFlow == null)
            {
                throw new BusinessException("没有找到ID为【" + settingDic.GetValue("FlowID") + "】的流程定义,无法在流程执行过程中启动其他流程");
            }

            #region 确认表单定义对象
            var formCode     = String.IsNullOrEmpty(settingDic.GetValue("FormCode")) ? defFlow.Code : settingDic.GetValue("FormCode");
            var baseEntities = FormulaHelper.GetEntities <Base.Logic.Domain.BaseEntities>();
            var tmplForm     = baseEntities.S_UI_Form.FirstOrDefault(c => c.Code == formCode);
            #endregion

            var defStep = defFlow.S_WF_DefStep.FirstOrDefault(c => c.ID == startTaskDefID);
            if (defStep == null)
            {
                throw new BusinessException("没有找到指定的定义实例,无法启动工作流");
            }

            var user = FormulaHelper.GetUserInfo();

            #region 默认创建数据实例
            string sql            = "select * from {0} where ID='{1}'";
            var    flowIns        = this.S_WF_InsDefFlow.S_WF_InsFlow.FirstOrDefault();
            var    orialDt        = SQLHelper.CreateSqlHelper(this.S_WF_InsDefFlow.ConnName).ExecuteDataTable(String.Format(sql, this.S_WF_InsDefFlow.TableName, flowIns.FormInstanceID));
            var    orialDic       = new Dictionary <string, object>();
            var    formInstanceID = FormulaHelper.CreateGuid();
            var    dic            = new Dictionary <string, object>();
            dic.SetValue("CreateUserID", user.UserID);
            dic.SetValue("CreateUser", user.UserName);
            dic.SetValue("OrgID", user.UserOrgID);
            if (settingDic.ContainsKey("DataFormat") && settingDic["DataFormat"] != null)
            {
                var dataFormat = new List <Dictionary <string, object> >();
                if (settingDic["DataFormat"] is List <Dictionary <string, object> > || settingDic["DataFormat"] is Array)
                {
                    dataFormat = settingDic["DataFormat"] as List <Dictionary <string, object> >;
                }
                else if (!String.IsNullOrEmpty(settingDic.GetValue("DataFormat")))
                {
                    dataFormat = JsonHelper.ToList(settingDic.GetValue("DataFormat"));
                }

                #region 根据表单自定义配置来设定默认值
                if (tmplForm != null)
                {
                    var uiFO = FormulaHelper.CreateFO <Base.Logic.BusinessFacade.UIFO>();
                    Dictionary <string, DataTable> defaultValueRows = uiFO.GetDefaultValueDic(tmplForm.DefaultValueSettings, orialDt.Rows[0]);
                    var items = JsonHelper.ToObject <List <Base.Logic.Model.UI.Form.FormItem> >(tmplForm.Items);
                    items.Where(c => !string.IsNullOrEmpty(c.DefaultValue)).ToList().ForEach(d =>
                    {
                        if (d.ItemType == "SubTable")
                        {
                            //子表
                            dic.SetValue(d.Code, uiFO.GetDefaultValue(d.Code, d.DefaultValue, defaultValueRows));
                        }
                        else if ((d.ItemType == "ButtonEdit" || d.ItemType == "ComboBox") && d.DefaultValue.Split(',').Count() == 2)
                        {
                            //键值控件
                            string v1 = uiFO.GetDefaultValue(d.Code, d.DefaultValue.Split(',')[0], defaultValueRows);
                            string v2 = uiFO.GetDefaultValue(d.Code, d.DefaultValue.Split(',')[1], defaultValueRows);
                            if (!string.IsNullOrEmpty(v1) && v1.Contains('{') == false)
                            {
                                dic.SetValue(d.Code, v1);
                            }
                            if (!string.IsNullOrEmpty(v2) && v2.Contains('{') == false)
                            {
                                var fieldName = "";
                                if (Config.Constant.IsOracleDb)
                                {
                                    fieldName = d.Code + "NAME";
                                    if (!String.IsNullOrWhiteSpace(d.Settings))
                                    {
                                        var fieldSettings = JsonHelper.ToObject(d.Settings);
                                        var txtName       = fieldSettings.GetValue("textName");
                                        if (!String.IsNullOrEmpty(txtName))
                                        {
                                            fieldName = txtName;
                                        }
                                    }
                                }
                                else
                                {
                                    fieldName = d.Code + "Name";
                                    if (!String.IsNullOrWhiteSpace(d.Settings))
                                    {
                                        var fieldSettings = JsonHelper.ToObject(d.Settings);
                                        var txtName       = fieldSettings.GetValue("textName");
                                        if (!String.IsNullOrEmpty(txtName))
                                        {
                                            fieldName = txtName;
                                        }
                                    }
                                }
                                dic.SetValue(fieldName, v2);
                            }
                        }
                        else
                        {
                            //单值控件
                            string v = uiFO.GetDefaultValue(d.Code, d.DefaultValue, defaultValueRows);
                            if (!string.IsNullOrEmpty(v) && v.Contains('{') == false)
                            {
                                dic.SetValue(d.Code, v);
                            }
                        }
                    });
                }
                #endregion

                #region 设置当前表单内的默认值
                if (orialDt.Rows.Count > 0)
                {
                    var sourceRow = orialDt.Rows[0];
                    orialDic = FormulaHelper.DataRowToDic(sourceRow);
                    var fillFields = dataFormat.Where(c => !String.IsNullOrEmpty(c.GetValue("DefaultValue"))).ToList();
                    foreach (var field in fillFields)
                    {
                        Regex  reg             = new Regex("\\{[0-9a-zA-Z_\\.]*\\}");
                        string defaultValueDef = field.GetValue("DefaultValue");
                        string result          = reg.Replace(defaultValueDef, (Match m) =>
                        {
                            string value = m.Value.Trim('{', '}');
                            if (sourceRow != null && sourceRow.Table.Columns.Contains(value))
                            {
                                return(sourceRow[value].ToString());
                            }
                            switch (value)
                            {
                            case Formula.Constant.CurrentUserID:
                                return(user.UserID);

                            case Formula.Constant.CurrentUserName:
                                return(user.UserName);

                            case Formula.Constant.CurrentUserOrgID:
                                return(user.UserOrgID);

                            case Formula.Constant.CurrentUserOrgCode:
                                return(user.UserOrgCode);

                            case Formula.Constant.CurrentUserOrgName:
                                return(user.UserOrgName);

                            case Formula.Constant.CurrentUserPrjID:
                                return(user.UserPrjID);

                            case Formula.Constant.CurrentUserPrjName:
                                return(user.UserPrjName);

                            case "CurrentUserCorpID":
                                return(user.UserCompanyID);

                            case "CurrentUserCorpName":
                                return(user.UserCompanyName);

                            case "CurrentTime":
                                return(DateTime.Now.ToString());

                            case "CurrentDate":
                                return(DateTime.Now.Date.ToString("yyyy-MM-dd"));

                            case "CurrentYear":
                                return(DateTime.Now.Year.ToString());

                            case "CurrentMonth":
                                return(DateTime.Now.Month.ToString());

                            case "CurrentQuarter":
                                return(((DateTime.Now.Month + 2) / 3).ToString());

                            case "CurrentUserOrgFullID":
                                return(user.UserFullOrgID);

                            default:
                                return("");
                            }
                        });
                        dic.SetValue(field.GetValue("ColumnName"), result);
                    }
                }
                #endregion
            }
            var db = SQLHelper.CreateSqlHelper(defFlow.ConnName);
            dic.InsertDB(db, defFlow.TableName, formInstanceID);
            #endregion

            int maxReceiverCount = 50;
            if (!string.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["Flow_ReceiverCount"]))
            {
                maxReceiverCount = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["Flow_ReceiverCount"]);
            }

            #region 获取工作流环节的指定执行人
            var userIDs = settingDic.GetValue("UserIDs");
            if (String.IsNullOrEmpty(userIDs))
            {
                userIDs = orialDic.GetValue(settingDic.GetValue("UserIDsFromField"));
            }
            if (String.IsNullOrEmpty(userIDs))
            {
                var roleIDs = settingDic.GetValue("RoleIDs");
                var orgIDs  = settingDic.GetValue("OrgIDs");
                if (String.IsNullOrEmpty(roleIDs))
                {
                    roleIDs = orialDic.GetValue(settingDic.GetValue("RoleIDsFromField"));
                }
                if (String.IsNullOrEmpty(orgIDs))
                {
                    orgIDs = orialDic.GetValue(settingDic.GetValue("OrgIDFromField"));
                }
                if (!string.IsNullOrEmpty(roleIDs))
                {
                    userIDs = FormulaHelper.GetService <IRoleService>().GetUserIDsInRoles(roleIDs, orgIDs);
                    var prjRoleUser = PrjRoleExt.GetRoleUserIDs(roleIDs, orgIDs);
                    if (!string.IsNullOrEmpty(prjRoleUser))
                    {
                        userIDs = (prjRoleUser + "," + userIDs).Trim(',');
                    }
                }
                else
                {
                    userIDs = FormulaHelper.GetService <IOrgService>().GetUserIDsInOrgs(orgIDs);
                }
            }
            if (String.IsNullOrEmpty(userIDs))
            {
                throw new BusinessValidationException("没有找到环节执行人员,无法启动流程");
            }
            if (userIDs.Split(',').Length > maxReceiverCount)
            {
                throw new FlowException("任务执行人不能超过" + maxReceiverCount + "个");
            }
            #endregion

            var fo = FormulaHelper.CreateFO <Workflow.Logic.BusinessFacade.FlowFO>();

            var insDefFlow = defFlow.GetInsDefFlow();
            var insFlow    = insDefFlow.CreateFlow(formInstanceID, user.UserID, user.UserName);

            //获取流程定义实例首环节
            string          Inital = StepTaskType.Inital.ToString();
            S_WF_InsDefStep insDefStep = null; bool startWithInital = false;
            var             insStartStep = insDefFlow.S_WF_InsDefStep.Where(c => c.Type == Inital).SingleOrDefault();
            if (insStartStep.DefStepID == startTaskDefID)
            {
                insDefStep      = insStartStep;
                startWithInital = true;
            }
            else
            {
                var stepIds = insStartStep.S_WF_InsDefRouting.Select(c => c.EndID);
                insDefStep = insDefFlow.S_WF_InsDefStep.Where(c => stepIds.Contains(c.ID) && c.DefStepID == startTaskDefID).FirstOrDefault();
            }
            if (insDefStep == null)
            {
                throw new BusinessException("没有找到指定的定义实例,无法启动工作流");
            }
            //创建首环节任务
            var startUserID = userIDs.Split(',')[0];
            var insTask     = insStartStep.CreateTask(insFlow, null, null, startUserID, FormulaHelper.GetService <IUserService>().GetUserNames(startUserID), "", "", "");
            //创建任务执行明细
            var taskExec = insTask.CreateTaskExec().FirstOrDefault();
            if (!startWithInital)
            {
                var insDefRouting = insStartStep.S_WF_InsDefRouting.Where(c => c.EndID == insDefStep.ID).FirstOrDefault();
                fo.ExecTask(taskExec.ID, insDefRouting.Code, userIDs, UserNames, "");
            }
        }