Пример #1
0
        private IEnumerable <string> GetColumnOperators(CColumn column)
        {
            var list = new List <string>();

            string opString = string.Empty;

            switch (GetMappingType(column.DbType.ToString()).ToString())
            {
            case "System.DateTime":
            case "System.Int16":
            case "System.Int32":
            case "System.Int64":
            case "System.Double":
                opString = "=,<>,>,>=,<,<=,IS,IS NOT";
                break;

            case "System.Boolean":
                opString = "=,<>,IS,IS NOT";
                break;

            default:
                opString = "=,<>,LIKE,IS,IS NOT";
                break;
            }

            foreach (string op in opString.Split(new char[] { ',' }))
            {
                if (!list.Contains(op))
                {
                    list.Add(op);
                }
            }

            return(list);
        }
Пример #2
0
        public static string DefaultValue(this CColumn col, string defaultValue = "")
        {
            if (!string.IsNullOrEmpty(defaultValue))
            {
                return(defaultValue);
            }

            var value = "NULL";

            switch (col.DbType)
            {
            case eDbType.@bool:
            case eDbType.bit:
                return("0");

            case eDbType.binary:
            case eDbType.varbinary:
            case eDbType.sql_variant:
            case eDbType.image:
                return("0x0");

            case eDbType.@int:
            case eDbType.@long:
            case eDbType.@decimal:
            case eDbType.real:
            case eDbType.money:
            case eDbType.smallmoney:
            case eDbType.tinyint:
            case eDbType.@float:
            case eDbType.bigint:
            case eDbType.numeric:
            case eDbType.smallint:
                return(default(Int32).ToString());

            case eDbType.@string:
            case eDbType.varchar:
            case eDbType.nvarchar:
            case eDbType.@char:
            case eDbType.text:
            case eDbType.xml:
            case eDbType.ntext:
            case eDbType.nchar:
                return(string.Empty);

            case eDbType.date:
            case eDbType.datetime:
            case eDbType.datetime2:
            case eDbType.datetimeoffset:
            case eDbType.time:
            case eDbType.timestamp:
                return(DateTime.UtcNow.ToString("yyyy-mm-dd"));

            case eDbType.guid:
            case eDbType.uniqueidentifier:
                return(Guid.Empty.ToString());
            }

            return(value);
        }
Пример #3
0
        public static string QuoteParam(this CColumn col, string quoteChar = "'")
        {
            if (col.DbType.IsString())
            {
                return($"'@{col.name.UnQuoteName()}'");
            }

            return($"@{col.name.UnQuoteName()}");
        }
Пример #4
0
 public static object GetDefaultValue(this CColumn column, string @operator, string defaultValue = "")
 {
     if (@operator.ToLower().StartsWith("is"))
     {
         return("NULL");
     }
     else if (@operator.ToLower().StartsWith("like"))
     {
         return("'%" + column.DefaultValue(defaultValue) + "%'");
     }
     else
     {
         return(column.DbType.IsString()
             ? column.DefaultValue(defaultValue).ToString().QuoteName("'", "'")
             : column.DefaultValue(defaultValue));
     }
 }