/// <summary>取得数据库名称</summary>
        /// <param name="tableName">数据表</param>
        /// <returns>数据库名称</returns>
        private string GetTableDescription(string databaseName, string ownerName, string tableName)
        {
            GenericSqlCommand command = new GenericSqlCommand(connectionString, PROVIDER_NAME);

            string commandText = string.Format("SHOW TABLE STATUS FROM {0}", databaseName);

            var table = command.ExecuteQueryForDataTable(commandText);

            foreach (DataRow row in table.Rows)
            {
                if (row["Name"].ToString() == tableName)
                {
                    // 输出注释信息
                    string comment = row["Comment"].ToString();

                    if (comment.IndexOf(';') == -1)
                    {
                        return(string.Empty);
                    }

                    return(comment.Substring(0, comment.IndexOf(';')));
                }
            }

            return(string.Empty);
        }
        /// <summary>移除实体对象的权限信息</summary>
        /// <param name="command">通用SQL命令对象</param>
        /// <param name="scopeTableName">数据表的名称</param>
        /// <param name="entityId">实体标识</param>
        /// <param name="entityClassName">实体类名称</param>
        /// <param name="authorityName">权限名称</param>
        /// <param name="scopeText">权限范围的文本</param>
        public void AddAuthorizationScopeObjects(GenericSqlCommand command, string scopeTableName, string entityId, string entityClassName, string authorityName, string scopeText)
        {
            Dictionary <string, object> args = new Dictionary <string, object>();

            AuthorityInfo authority = AuthorityContext.Instance.AuthorityService[authorityName];

            args.Add("ScopeTableName", scopeTableName);
            args.Add("EntityId", entityId);
            args.Add("EntityClassName", entityClassName);
            args.Add("AuthorityId", authority.Id);
            args.Add("AuthorizationObjectType", string.Empty);
            args.Add("AuthorizationObjectId", string.Empty);

            string[] list = scopeText.Split(new char[] { ';', ',' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (string item in list)
            {
                string[] keys = item.Split('#');

                args["AuthorizationObjectType"] = keys[0].ToString().Substring(0, 1).ToUpper() + keys[0].ToString().Substring(1);
                args["AuthorizationObjectId"]   = keys[1].ToString();

                if (!string.IsNullOrEmpty(args["AuthorizationObjectType"].ToString()) && !string.IsNullOrEmpty(args["AuthorizationObjectId"].ToString()))
                {
                    string commandText = this.ibatisMapper.QueryForCommandText(StringHelper.ToProcedurePrefix(string.Format("{0}_AddAuthorizationScopeObject", tableName)), args);

                    command.ExecuteNonQuery(commandText);
                }
            }
        }
        /// <summary>取得数据库名称</summary>
        /// <param name="tableName">数据表</param>
        /// <returns>数据库名称</returns>
        public DataColumnSchemaCollection GetColumns(string databaseName, string ownerName, string tableName)
        {
            DataColumnSchemaCollection list = new DataColumnSchemaCollection();

            GenericSqlCommand command = new GenericSqlCommand(connectionString, "SQLite");

            string commandText = string.Format("SHOW FULL FIELDS FROM {1} FROM {0}", databaseName, tableName);

            var table = command.ExecuteQueryForDataTable(commandText);

            foreach (DataRow row in table.Rows)
            {
                DataColumnSchema item = new DataColumnSchema();

                // 名称
                item.Name = row["Field"].ToString();
                // 数据类型
                item.Type = SetDataType(row["Type"].ToString());
                // 原生数据类型
                item.NativeType = row["Type"].ToString();
                // 是否允许为空
                item.Nullable = (row["Null"].ToString() == "NO") ? false : true;
                // 默认值
                item.DefaultValue = row["Default"].ToString();
                // 注释
                item.Description = row["Comment"].ToString();

                list.Add(item);
            }

            return(list);
        }
        /// <summary>判断授权对象是否拥有实体对象的权限信息</summary>
        /// <param name="command">通用SQL命令对象</param>
        /// <param name="scopeTableName">数据表的名称</param>
        /// <param name="entityId">实体标识</param>
        /// <param name="entityClassName">实体类名称</param>
        /// <param name="authorityName">权限名称</param>
        /// <param name="authorizationObjectType">授权对象类型</param>
        /// <param name="authorizationObjectId">授权对象标识</param>
        /// <returns>布尔值</returns>
        public bool HasAuthority(GenericSqlCommand command, string scopeTableName, string entityId, string entityClassName, string authorityName, string authorizationObjectType, string authorizationObjectId)
        {
            Dictionary <string, object> args = new Dictionary <string, object>();

            AuthorityInfo authority = AuthorityContext.Instance.AuthorityService[authorityName];

            args.Add("ScopeTableName", scopeTableName);
            args.Add("EntityId", entityId);
            args.Add("EntityClassName", entityClassName);
            args.Add("AuthorityId", authority.Id);
            args.Add("AuthorizationObjectType", authorizationObjectType);
            args.Add("AuthorizationObjectId", authorizationObjectId);

            string commandText = null;

            if (authorizationObjectType == "Account")
            {
                commandText = this.ibatisMapper.QueryForCommandText(StringHelper.ToProcedurePrefix(string.Format("{0}_HasAuthorityWithAccount", tableName)), args);
            }
            else
            {
                commandText = this.ibatisMapper.QueryForCommandText(StringHelper.ToProcedurePrefix(string.Format("{0}_HasAuthorityWithAccount", tableName)), args);
            }

            return(((int)command.ExecuteScalar(commandText) == 0) ? false : true);
        }
Exemple #5
0
        /// <summary>
        /// 取得数据库名称
        /// </summary>
        /// <param name="tableName">数据表</param>
        /// <returns>数据库名称</returns>
        public DataColumnSchemaCollection GetPrimaryKeyColumns(string databaseName, string ownerName, string tableName)
        {
            DataColumnSchemaCollection list = new DataColumnSchemaCollection();

            GenericSqlCommand command = new GenericSqlCommand(connectionString, "OracleClient");

            string commandText = string.Format(@"
select cu.* 
  from user_cons_columns cu, user_constraints au 
 where cu.constraint_name = au.constraint_name 
   and au.constraint_type = 'P' 
   and au.table_name = '{0}' ", tableName);

            var table = command.ExecuteQueryForDataTable(commandText);

            foreach (DataRow row in table.Rows)
            {
                DataColumnSchema item = new DataColumnSchema();

                item.Name = row["column_name"].ToString();

                list.Add(item);
            }

            return(list);
        }
Exemple #6
0
        static string GenerateApplicationErrorScript(Options options)
        {
            GenericSqlCommand command = new GenericSqlCommand("ConnectionString");

            DataTable table = command.ExecuteQueryForDataTable(" SELECT * FROM tb_Application_Error WHERE ApplicationId IN ( SELECT Id FROM tb_Application WHERE ApplicationName = '" + options.ApplicationName + "' ) ORDER BY ParentId, OrderId ");

            return(SqlScriptHelper.GenerateDateTableScript("", "tb_Application_Error", table));
        }
Exemple #7
0
        static string GenerateApplicationMenuScopeScript(Options options)
        {
            GenericSqlCommand command = new GenericSqlCommand("ConnectionString");

            DataTable table = command.ExecuteQueryForDataTable(" SELECT * FROM tb_Application_Menu_Scope WHERE EntityId IN ( SELECT Id FROM tb_Application_Menu WHERE ApplicationId IN ( SELECT Id FROM tb_Application WHERE ApplicationName = '" + options.ApplicationName + "' ) ) ORDER BY EntityId, AuthorizationObjectType ");

            return(SqlScriptHelper.GenerateDateTableScript("", "tb_Application_Menu_Scope", table));
        }
Exemple #8
0
        static string FindApplicationDisplayName(string applicationName)
        {
            GenericSqlCommand command = new GenericSqlCommand("ConnectionString");

            object result = command.ExecuteScalar(" SELECT ApplicationDisplayName FROM tb_Application WHERE ApplicationName = '" + applicationName + "' ");

            return(result == null ? string.Empty : result.ToString());
        }
Exemple #9
0
        static string GenerateApplicationScript(Options options)
        {
            GenericSqlCommand command = new GenericSqlCommand("ConnectionString");

            DataTable table = command.ExecuteQueryForDataTable(" SELECT * FROM tb_Application WHERE ApplicationName = '" + options.ApplicationName + "' ");

            return(SqlScriptHelper.GenerateDateTableScript("", "tb_Application", table));
        }
        /// <summary>
        /// 取得数据库名称
        /// </summary>
        /// <returns>数据库名称</returns>
        public string GetDatabaseName()
        {
            GenericSqlCommand command = new GenericSqlCommand(connectionString, "SQLite");

            string commandText = "select database()";

            var result = command.ExecuteScalar(commandText);

            return(result == null ? string.Empty : result.ToString());
        }
        /// <summary>配置实体对象的权限信息</summary>
        /// <param name="command">通用SQL命令对象</param>
        /// <param name="scopeTableName">数据表的名称</param>
        /// <param name="entityId">实体标识</param>
        /// <param name="entityClassName">实体类名称</param>
        /// <param name="authorityName">权限名称</param>
        /// <param name="scopeText">权限范围的文本</param>
        public void BindAuthorizationScopeObjects(GenericSqlCommand command, string scopeTableName, string entityId, string entityClassName, string authorityName, string scopeText)
        {
            if (!string.IsNullOrEmpty(entityId) && !string.IsNullOrEmpty(authorityName))
            {
                // 移除权限信息
                this.RemoveAuthorizationScopeObjects(command, scopeTableName, entityId, entityClassName, authorityName);

                // 添加权限信息
                this.AddAuthorizationScopeObjects(command, scopeTableName, entityId, entityClassName, authorityName, scopeText);
            }
        }
Exemple #12
0
        /// <summary>根据类别标识成数字编码</summary>
        /// <param name="command">通用SQL命令对象</param>
        /// <param name="entityTableName">实体数据表</param>
        /// <param name="entityCategoryTableName">实体类别数据表</param>
        /// <param name="entityCategoryId">实体类别标识</param>
        /// <param name="expression">规则表达式</param>
        /// <returns>数字编码</returns>
        public string GenerateCodeByCategoryId(GenericSqlCommand command, string entityTableName, string entityCategoryTableName, string entityCategoryId, string expression)
        {
            Dictionary <string, object> args = new Dictionary <string, object>();

            args.Add("EntityCategoryTableName", entityCategoryTableName);
            args.Add("EntityCategoryId", entityCategoryId);

            string commandText = this.ibatisMapper.QueryForCommandText(StringHelper.ToProcedurePrefix(string.Format("{0}_GetPrefixCodeByCategoryId", tableName)), args);

            string prefixCode = (string)command.ExecuteScalar(commandText);

            return(GenerateCodeByPrefixCode(entityTableName, prefixCode, expression));
        }
Exemple #13
0
        /// <summary>
        /// 取得数据库名称
        /// </summary>
        /// <param name="tableName">数据表</param>
        /// <returns>数据库名称</returns>
        public DataColumnSchemaCollection GetColumns(string databaseName, string ownerName, string tableName)
        {
            DataColumnSchemaCollection list = new DataColumnSchemaCollection();

            GenericSqlCommand command = new GenericSqlCommand(connectionString, "OracleClient");

            string commandText = string.Format(@"
select column_id, 
       column_name, 
       data_type, 
       data_length, 
       data_precision, 
       data_scale, 
       nullable,
       data_default 
  from user_tab_columns 
 where table_name = '{0}' 
 order by column_id", tableName);

            var table = command.ExecuteQueryForDataTable(commandText);

            foreach (DataRow row in table.Rows)
            {
                DataColumnSchema item = new DataColumnSchema();

                item.Name = row["column_name"].ToString().ToLower();

                item.Type = SetDataType(row["data_type"].ToString());

                item.Nullable = (row["nullable"].ToString() == "N") ? false : true;

                switch (item.Type)
                {
                case DbType.String:
                    item.Length = (row["data_length"] == DBNull.Value) ? 0 : Convert.ToInt32(row["data_length"].ToString());
                    break;

                case DbType.Decimal:
                    // item.Precision = (dr["Precision"] == DBNull.Value) ? (byte)0 : (byte)dr["Precision"];
                    // item.Scale = (dr["Scale"] == DBNull.Value) ? 0 : (int)dr["Scale"];
                    break;

                default:
                    break;
                }

                list.Add(item);
            }

            return(list);
        }
        /// <summary>移除实体对象的权限信息</summary>
        /// <param name="command">通用SQL命令对象</param>
        /// <param name="scopeTableName">数据表的名称</param>
        /// <param name="entityId">实体标识</param>
        /// <param name="entityClassName">实体类名称</param>
        /// <param name="authorityName">权限名称</param>
        public void RemoveAuthorizationScopeObjects(GenericSqlCommand command, string scopeTableName, string entityId, string entityClassName, string authorityName)
        {
            Dictionary <string, object> args = new Dictionary <string, object>();

            AuthorityInfo authority = AuthorityContext.Instance.AuthorityService[authorityName];

            args.Add("ScopeTableName", scopeTableName);
            args.Add("EntityId", entityId);
            args.Add("EntityClassName", entityClassName);
            args.Add("AuthorityId", authority.Id);

            string commandText = this.ibatisMapper.QueryForCommandText(StringHelper.ToProcedurePrefix(string.Format("{0}_RemoveAuthorizationScopeObjects", tableName)), args);

            command.ExecuteNonQuery(commandText);
        }
Exemple #15
0
        /// <summary>根据前缀生成数字编码</summary>
        /// <param name="command">通用SQL命令对象</param>
        /// <param name="entityTableName">实体数据表</param>
        /// <param name="prefixCode">前缀编号</param>
        /// <param name="expression">规则表达式</param>
        /// <returns>数字编码</returns>
        public string GenerateCodeByPrefixCode(GenericSqlCommand command, string entityTableName, string prefixCode, string expression)
        {
            // 获取前缀
            string prefix = DigitalNumberScript.RunPrefixScript(expression, prefixCode.ToUpper(), DateTime.Now);

            // 根据前缀信息查询当前最大的编号
            Dictionary <string, object> args = new Dictionary <string, object>();

            args.Add("EntityTableName", entityTableName);
            args.Add("Prefix", prefix);

            string commandText = this.ibatisMapper.QueryForCommandText(StringHelper.ToProcedurePrefix(string.Format("{0}_GetMaxSeedByPrefix", tableName)), args);

            int seed = Convert.ToInt32(command.ExecuteScalar(commandText));

            return(DigitalNumberScript.RunScript(expression, prefixCode, DateTime.Now, ref seed));
        }
        /// <summary>根据类别标识成数字编码</summary>
        /// <param name="command">通用SQL命令对象</param>
        /// <param name="entityTableName">实体数据表</param>
        /// <param name="entityCategoryTableName">实体类别数据表</param>
        /// <param name="entityCategoryId">实体类别标识</param>
        /// <param name="expression">规则表达式</param>
        /// <returns>数字编码</returns>
        public string GenerateCodeByCategoryId(GenericSqlCommand command, string entityTableName, string entityCategoryTableName, string entityCategoryId, string expression)
        {
            string code = string.Empty;

            int count = 0;

            // 有可能生成编号失败,所以 while。
            while (string.IsNullOrEmpty(code))
            {
                code = this.provider.GenerateCodeByCategoryId(command, entityTableName, entityCategoryTableName, entityCategoryId, expression);

                if (count++ > 10)
                {
                    break;
                }
            }

            return(code);
        }
Exemple #17
0
        /// <summary>查询实体对象的权限范围的文本</summary>
        /// <param name="command">通用SQL命令对象</param>
        /// <param name="scopeTableName">数据表的名称</param>
        /// <param name="entityId">实体标识</param>
        /// <param name="entityClassName">实体类名称</param>
        /// <param name="authorityName">权限名称</param>
        /// <returns></returns>
        public string GetAuthorizationScopeObjectText(GenericSqlCommand command, string scopeTableName, string entityId, string entityClassName, string authorityName)
        {
            StringBuilder outString = new StringBuilder();

            IList <MembershipAuthorizationScopeObject> authorizationScopeObjects = this.GetAuthorizationScopeObjects(command, scopeTableName, entityId, entityClassName, authorityName);

            foreach (MembershipAuthorizationScopeObject authorizationScopeObject in authorizationScopeObjects)
            {
                if (!string.IsNullOrEmpty(authorizationScopeObject.AuthorizationObjectType) &&
                    !string.IsNullOrEmpty(authorizationScopeObject.AuthorizationObjectId))
                {
                    outString.AppendFormat("{0}#{1}#{2};",
                                           authorizationScopeObject.AuthorizationObjectType.ToLower(),
                                           authorizationScopeObject.AuthorizationObjectId,
                                           authorizationScopeObject.AuthorizationObjectDescription);
                }
            }

            return(outString.ToString());
        }
        /// <summary>查询数据库中表的外键字段信息</summary>
        /// <param name="databaseName">数据库</param>
        /// <param name="ownerName">所有者</param>
        /// <param name="tableName">表名</param>
        /// <returns>外键字段信息集合</returns>
        public DataColumnSchemaCollection GetForeignKeyColumns(string databaseName, string ownerName, string tableName)
        {
            DataColumnSchemaCollection list = new DataColumnSchemaCollection();

            GenericSqlCommand command = new GenericSqlCommand(connectionString, "SQLite");

            string commandText = string.Format("SHOW FULL FIELDS FROM {1} FROM {0} WHERE `Key`='MUL'", databaseName, tableName);

            var table = command.ExecuteQueryForDataTable(commandText);

            foreach (DataRow row in table.Rows)
            {
                DataColumnSchema item = new DataColumnSchema();

                item.Name = row["Field"].ToString();

                list.Add(item);
            }

            return(list);
        }
Exemple #19
0
 /// <summary>查询实体对象的权限信息</summary>
 /// <param name="command">通用SQL命令对象</param>
 /// <param name="scopeTableName">数据表的名称</param>
 /// <param name="entityId">实体标识</param>
 /// <param name="entityClassName">实体类名称</param>
 /// <param name="authorityName">权限名称</param>
 /// <returns></returns>
 public IList <MembershipAuthorizationScopeObject> GetAuthorizationScopeObjects(GenericSqlCommand command, string scopeTableName, string entityId, string entityClassName, string authorityName)
 {
     return(provider.GetAuthorizationScopeObjects(command, scopeTableName, entityId, entityClassName, authorityName));
 }
        // -------------------------------------------------------
        // 保存 删除
        // -------------------------------------------------------

        #region 函数:Save(BugInfo param)
        /// <summary>保存记录</summary>
        /// <param name="param">BugInfo 实例详细信息</param>
        /// <param name="message">数据库操作返回的相关信息</param>
        /// <returns>BugInfo 实例详细信息</returns>
        public BugInfo Save(BugInfo param)
        {
            if (string.IsNullOrEmpty(param.Id))
            {
                throw new Exception("实例标识不能为空。");
            }

            bool isNewObject = !this.IsExist(param.Id);

            BugInfo originalObject = isNewObject ? null : this.FindOne(param.Id);

            string methodName = isNewObject ? "新增" : "编辑";

            if (isNewObject)
            {
                IAccountInfo account = KernelContext.Current.User;

                param.AccountId   = account.Id;
                param.AccountName = account.Name;
            }

            // 指派问题负责人
            if (string.IsNullOrEmpty(param.AssignToAccountId))
            {
                param.AssignToAccountName = string.Empty;
            }
            else
            {
                param.AssignToAccountName = MembershipManagement.Instance.AccountService[param.AssignToAccountId].Name;
            }

            // 生成问题编号
            if (string.IsNullOrEmpty(param.Code))
            {
                string code = string.Empty;

                // 所属类别信息
                ApplicationInfo application = AppsContext.Instance.ApplicationService[BugConfiguration.ApplicationName];

                // 编号的相关实体数据表
                string entityTableName = BugConfigurationView.Instance.DigitalNumberEntityTableName;

                // 编号的前缀编码
                string prefixCode = BugConfigurationView.Instance.DigitalNumberPrefixCodeRule
                                    .Replace("{ApplicationPinYin}", application.PinYin);

                // 编号的自增流水号长度
                int incrementCodeLength = BugConfigurationView.Instance.DigitalNumberIncrementCodeLength;

                GenericSqlCommand command = this.provider.CreateGenericSqlCommand();

                code = DigitalNumberContext.GenerateDateCodeByPrefixCode(command, entityTableName, prefixCode, incrementCodeLength);

                param.Code = code.ToUpper();
            }

            // 过滤 Cross Site Script
            param = StringHelper.ToSafeXSS <BugInfo>(param);

            this.provider.Save(param);

            param = this.FindOne(param.Id);

            if (isNewObject)
            {
                originalObject = param;
            }

            // 记录问题状态信息
            BugHistoryInfo history = new BugHistoryInfo();

            history.Id    = StringHelper.ToGuid();
            history.BugId = param.Id;

            if (isNewObject)
            {
                // 0.新问题 | 1.确认中 | 2.处理中 | 3.已解决 | 4.已关闭
                history.FromStatus = 0;
                history.ToStatus   = 0;

                BugContext.Instance.BugHistoryService.Save(history);
            }
            else
            {
                history.FromStatus = (param.Properties["FromStatus"] == null) ? 0 : Convert.ToInt32(param.Properties["FromStatus"].ToString());
                history.ToStatus   = param.Status;

                if (history.FromStatus != history.ToStatus)
                {
                    BugContext.Instance.BugHistoryService.Save(history);
                }
            }

            // 发送邮件提醒
            // 新问题状态发送给负责人, 已解决状态发送给提交人
            if (BugConfigurationView.Instance.SendMailAlert == "ON"
                // && isNewObject || (param.ModifiedDate.AddHours(2) > originalObject.ModifiedDate)
                && (param.Status == 0 || param.Status == 3))
            {
                if (isNewObject || (param.Status != originalObject.Status || param.AssignToAccountId != originalObject.AssignToAccountId))
                {
                    string mailTo, mailSubject, mailBody;

                    IMemberInfo member = null;

                    if (param.Status == 3)
                    {
                        // 已解决的问题, 发邮件通知提交人
                        member = MembershipManagement.Instance.MemberService.FindOneByAccountId(param.AccountId);
                    }
                    else
                    {
                        member = MembershipManagement.Instance.MemberService.FindOneByAccountId(param.AssignToAccountId);
                    }

                    if (member != null && !string.IsNullOrEmpty(member.Email))
                    {
                        VelocityContext context = new VelocityContext();

                        // 加载当前实体数据信息
                        context.Put("kernelConfiguration", KernelConfigurationView.Instance);
                        // 加载当前实体数据信息
                        context.Put("param", param);

                        mailTo = member.Email;

                        mailSubject = mailBody = string.Empty;

                        if (param.Status == 0)
                        {
                            // 0.新的问题
                            mailSubject = "您有一个新问题【" + param.Title + "】,等待处理。";

                            mailBody = VelocityManager.Instance.ParseTemplateVirtualPath(context, "/resources/email/Bug/bugzilla-new-mail.vm");
                        }
                        else if (param.Status == 3)
                        {
                            // 3.已解决
                            mailSubject = param.AssignToAccountId + "已将问题【" + param.Title + "】解决,请确认。";

                            mailBody = VelocityManager.Instance.ParseTemplateVirtualPath(context, "/resources/email/Bug/bugzilla-resolved-mail.vm");
                        }

                        EmailClientContext.Instance.Send(mailTo, mailSubject, mailBody, EmailFormat.Html);
                    }
                }
            }

            return(param);
        }
Exemple #21
0
 /// <summary>判断授权对象是否拥有实体对象的权限信息</summary>
 /// <param name="command">通用SQL命令对象</param>
 /// <param name="scopeTableName">数据表的名称</param>
 /// <param name="entityId">实体标识</param>
 /// <param name="entityClassName">实体类名称</param>
 /// <param name="authorityName">权限名称</param>
 /// <param name="authorizationObjectType">授权对象类型</param>
 /// <param name="authorizationObjectId">授权对象标识</param>
 /// <returns>布尔值</returns>
 public bool HasAuthority(GenericSqlCommand command, string scopeTableName, string entityId, string entityClassName, string authorityName, string authorizationObjectType, string authorizationObjectId)
 {
     return(provider.HasAuthority(command, scopeTableName, entityId, entityClassName, authorityName, authorizationObjectType, authorizationObjectId));
 }
Exemple #22
0
 /// <summary>配置实体对象的权限信息</summary>
 /// <param name="command">通用SQL命令对象</param>
 /// <param name="scopeTableName">数据表的名称</param>
 /// <param name="entityId">实体标识</param>
 /// <param name="entityClassName">实体类名称</param>
 /// <param name="authorityName">权限名称</param>
 /// <param name="scopeText">权限范围的文本</param>
 public void BindAuthorizationScopeObjects(GenericSqlCommand command, string scopeTableName, string entityId, string entityClassName, string authorityName, string scopeText)
 {
     provider.BindAuthorizationScopeObjects(command, scopeTableName, entityId, entityClassName, authorityName, scopeText);
 }
        /// <summary></summary>
        public override string ParseHtml()
        {
            try
            {
                string widgetRuntimeId = StringHelper.ToGuid();

                VelocityContext context = new VelocityContext();

                context.Put("widgetRuntimeId", widgetRuntimeId);

                context.Put("height", (this.Height == 0 ? "height:auto;" : "height:" + this.Height + "px;"));
                context.Put("width", (this.Width == 0 ? "width:auto;" : "width:" + this.Width + "px;"));

                // 设置最大行数
                int maxRowCount;

                int.TryParse(this.options["maxRowCount"], out maxRowCount);

                if (maxRowCount < 1)
                {
                    maxRowCount = 1;
                }

                if (maxRowCount > 100)
                {
                    maxRowCount = 100;
                }

                string tableName    = this.options["tableName"].ToString();
                string tableColumns = this.options["tableColumns"].ToString();

                string url = this.options["url"].ToString();

                if (string.IsNullOrEmpty(tableName))
                {
                    context.Put("widgetHtml", "请配置相关数据");
                }
                else
                {
                    var connection = KernelConfigurationView.Instance.ConnectionPlugin;

                    string commandText = null;

                    if (connection.Provider == "MySql")
                    {
                        commandText = " SELECT " + tableColumns + " FROM " + this.options["tableName"] + " ORDER BY   " + this.options["orderBy"] + " LIMIT " + maxRowCount;
                    }
                    else
                    {
                        commandText = " SELECT TOP " + maxRowCount + " " + tableColumns + " FROM " + this.options["tableName"] + " ORDER BY   " + this.options["orderBy"];
                    }

                    GenericSqlCommand command = new GenericSqlCommand(connection.ConnectionString, connection.Provider);

                    DataTable table = command.ExecuteQueryForDataTable(StringHelper.ToSafeSQL(commandText));

                    StringBuilder outString = new StringBuilder();

                    outString.Append("<div style=\"padding:0 10px 10px 10px;\" >");

                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        outString.Append("<div style=\"padding:10px 0 0 0 ;\" ><a href=\"" + string.Format(url, table.Rows[i][0].ToString()) + "\" target=\"_blank\" >" + HttpUtility.HtmlEncode(table.Rows[i][1].ToString()) + "</a></div>");
                    }

                    outString.Append("</div>");

                    context.Put("widgetHtml", outString.ToString());
                }

                return(VelocityManager.Instance.Merge(context, "themes/" + WebConfigurationView.Instance.ThemeName + "/widgets/general.vm"));
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Exemple #24
0
 /// <summary>判断授权对象是否拥有实体对象的权限信息</summary>
 /// <param name="command">通用SQL命令对象</param>
 /// <param name="scopeTableName">数据表的名称</param>
 /// <param name="entityId">实体标识</param>
 /// <param name="entityClassName">实体类名称</param>
 /// <param name="authorityName">权限名称</param>
 /// <param name="account">帐号信息</param>
 /// <returns>布尔值</returns>
 public bool HasAuthority(GenericSqlCommand command, string scopeTableName, string entityId, string entityClassName, string authorityName, IAccountInfo account)
 {
     return(provider.HasAuthority(command, scopeTableName, entityId, entityClassName, authorityName, account));
 }
        /// <summary>分析判断条件SQL</summary>
        /// <param name="sql">SQL语句</param>
        /// <param name="args">参数</param>
        /// <returns>判断条件是否成立</returns>
        public bool AnalyzeConditionSQL(string sql, Dictionary <string, string> args)
        {
            GenericSqlCommand command = new GenericSqlCommand(this.ibatisMapper.DataSource.ConnectionString, this.ibatisMapper.DataSource.DbProvider.Name);

            return((command.ExecuteScalar(CommandType.Text, StringHelper.ToSafeSQL(sql)).ToString() == "0") ? true : false);
        }
        /// <summary>查询应用的权限信息</summary>
        /// <param name="command">通用SQL命令对象</param>
        /// <param name="scopeTableName">数据表的名称</param>
        /// <param name="entityId">实体标识</param>
        /// <param name="entityClassName">实体类名称</param>
        /// <param name="authorityName">权限名称</param>
        /// <returns></returns>
        public IList <MembershipAuthorizationScopeObject> GetAuthorizationScopeObjects(GenericSqlCommand command, string scopeTableName, string entityId, string entityClassName, string authorityName)
        {
            if (string.IsNullOrEmpty(entityId))
            {
                new Exception("实体对象的标识不允许为空。");
            }

            string scopeText = null;

            Dictionary <string, object> args = new Dictionary <string, object>();

            AuthorityInfo authority = AuthorityContext.Instance.AuthorityService[authorityName];

            args.Add("ScopeTableName", scopeTableName);
            args.Add("EntityId", entityId);
            args.Add("EntityClassName", entityClassName);
            args.Add("AuthorityId", authority.Id);

            string commandText = this.ibatisMapper.QueryForCommandText(StringHelper.ToProcedurePrefix(string.Format("{0}_GetAuthorizationScopeObjects", tableName)), args);

            DataTable table = command.ExecuteQueryForDataTable(commandText);

            foreach (DataRow row in table.Rows)
            {
                scopeText += row["AuthorizationObjectType"] + "#" + row["AuthorizationObjectId"] + "#" + row["AuthorizationObjectName"] + ";";
            }

            IList <MembershipAuthorizationScopeObject> list = MembershipAuthorizationScopeManagement.GetAuthorizationScopeObjects(scopeText);

            return(list);
        }
Exemple #27
0
        public string Generate()
        {
            StringBuilder outString = new StringBuilder();

            // 执行依赖任务
            if (!string.IsNullOrEmpty(task.Depends))
            {
                string[] depends = task.Depends.Split(',');

                foreach (string depend in depends)
                {
                    // 任务不能自身依赖 避免发生循环引用
                    if (depend == task.Name)
                    {
                        continue;
                    }

                    DataDumpTask dependTask = DataDumpConfiguration.Instance.Tasks[depend];

                    // 重写依赖任务的参数选项和输出数据库类型
                    dependTask.Options      = task.Options;
                    dependTask.OutputDbType = task.OutputDbType;

                    IDataDumpProvider dependProvider = (IDataDumpProvider)KernelContext.CreateObject(dependTask.DataDumpProvider);

                    dependProvider.Init(dependTask);

                    outString.AppendLine(dependProvider.Generate());
                }
            }

            // 执行任务
            string comment, result;

            foreach (TaskStatement statement in task.Statements)
            {
                comment = null;
                result  = null;

                if (!string.IsNullOrEmpty(statement.Description))
                {
                    string[] descriptionLines = statement.Description.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);

                    foreach (string descriptionLine in descriptionLines)
                    {
                        if (!string.IsNullOrEmpty(descriptionLine.Trim()))
                        {
                            comment += "-- " + descriptionLine.Trim() + Environment.NewLine;
                        }
                    }
                }

                GenericSqlCommand command = new GenericSqlCommand(task.DataSourceName);

                string sql = statement.Sql;

                foreach (KeyValuePair <string, string> option in options)
                {
                    sql = sql.Replace("$" + option.Key + "$", option.Value);
                }

                DataTable table = command.ExecuteQueryForDataTable(sql);

                if (table.Rows.Count == 0)
                {
                    continue;
                }

                result = SqlScriptHelper.GenerateDateTableScript(task.OutputDbType, statement.DestTable, table);

                outString.Append(comment);
                outString.AppendLine(result);
            }

            return(outString.ToString());
        }
 /// <summary>根据自定义的编号前缀生成的流水编号</summary>
 public static string GenerateDateCodeByCategoryId(GenericSqlCommand command, string entityTableName, string entityCategoryTableName, string entityCategoryId, int incrementCodeLength)
 {
     return(Instance.DigitalNumberService.GenerateCodeByCategoryId(command, entityTableName, entityCategoryTableName, entityCategoryId, "{prefix}{date}{code:" + incrementCodeLength + "}"));
 }
 /// <summary>根据自定义的编号前缀生成日期流水编号</summary>
 public static string GenerateDateCodeByPrefixCode(GenericSqlCommand command, string entityTableName, string prefixCode)
 {
     return(Instance.DigitalNumberService.GenerateCodeByPrefixCode(command, entityTableName, prefixCode, "{prefix}{date}{code}"));
 }