Example #1
0
        public static Type ConvertSysDataTypeToType(SysDataType type)
        {
            switch (type)
            {
            case SysDataType.Binary:
            case SysDataType.Blob:
                return(typeof(byte[]));

            case SysDataType.Bit:
                return(typeof(bool));

            case SysDataType.Byte:
                return(typeof(byte));

            case SysDataType.Date:
            case SysDataType.DateTime:
                return(typeof(DateTime));

            case SysDataType.Decimal:
            case SysDataType.Money:
                return(typeof(decimal));

            case SysDataType.Double:
                return(typeof(double));

            case SysDataType.Guid:
                return(typeof(Guid));

            case SysDataType.Int:
                return(typeof(int));

            case SysDataType.Long:
                return(typeof(long));

            case SysDataType.Short:
                return(typeof(short));

            case SysDataType.String:
            case SysDataType.Text:
            case SysDataType.Xml:
                return(typeof(string));
            }
            return(typeof(string));
        }
Example #2
0
        public static IEnumerable <TSource> SourceRowWhere <TSource, TResult>(this IEnumerable <TSource> source, DataRow row, string proName,
                                                                              Expression <Func <TSource, TResult> > selector, SysDataType sysDataType = SysDataType.None)
        {
            source = source.ToList();
            //datarow 里面的优先级最高
            //然后是 sysDataType
            //然后才是 实体类
            if (row.Table.Columns.Contains(proName))
            {
                //if (sysDataType == SysDataType.None)
                //{
                //    sysDataType = DataTypeUtil.ConvertTypeToSysDataType(typeof(TResult));
                //}
                switch (sysDataType)
                {
                case SysDataType.None:
                    string postValue = row[proName].ToString();
                    if (postValue.IsEmpty())
                    {
                        return(source);
                    }
                    string[] postValues = postValue.Split(',');
                    return(source.Where(a =>
                    {
                        string beanValue = selector.Compile()(a).Value <string>() ?? "";
                        //if()
                        var _count = postValues.Where(b => beanValue.Equals(b)).Count();
                        return _count > 0;
                    }
                                        ));

                // break;
                case SysDataType.String:
                    string postValue2 = row[proName].ToString();
                    if (postValue2.IsEmpty())
                    {
                        return(source);
                    }
                    string[] postValues2 = postValue2.Split(',');
                    return(source.Where(a =>
                    {
                        string beanValue = selector.Compile()(a).Value <string>() ?? "";
                        //if()
                        var _count = postValues2.Where(b => beanValue.Contains(b)).Count();
                        return _count > 0;
                    }
                                        ));

                //  break;
                case SysDataType.Date:
                case SysDataType.DateTime:
                    DateTime postTime = row[proName].Value <DateTime>();
                    if (postTime == default(DateTime))
                    {
                        return(source);
                    }
                    if (proName.EndsWith("_END"))
                    {
                        return(source.Where(a =>
                        {
                            DateTime beanTime = selector.Compile()(a).Value <DateTime>();
                            return beanTime < postTime.AddDays(1);
                        }
                                            ));
                    }
                    else
                    {
                        return(source.Where(a =>
                        {
                            DateTime beanTime = selector.Compile()(a).Value <DateTime>();
                            return beanTime > postTime;
                        }
                                            ));
                    }

                default:
                    int postInt = row[proName].Value <int>();
                    // TResult _where = selector.Compile();
                    if (postInt == 0)
                    {
                        return(source);
                    }
                    return(source.Where(a =>
                    {
                        int beanInt = selector.Compile()(a).Value <int>();
                        return postInt == beanInt;
                    }
                                        ));
                }
            }
            return(source);
        }
Example #3
0
        public static DbType ConvertSysDataTypeToDbType(SysDataType type)
        {
            DbType result = DbType.AnsiString;

            switch (type)
            {
            case SysDataType.String:
            case SysDataType.Text:
                result = DbType.AnsiString;
                break;

            case SysDataType.Int:
                result = DbType.Int32;
                break;

            case SysDataType.Date:
                result = DbType.Date;
                break;

            case SysDataType.DateTime:
                result = DbType.DateTime;
                break;

            case SysDataType.Double:
                result = DbType.Double;
                break;

            case SysDataType.Money:
                result = DbType.Currency;
                break;

            case SysDataType.Blob:
            case SysDataType.Binary:
                result = DbType.Binary;
                break;

            case SysDataType.Guid:
                result = DbType.Guid;
                break;

            case SysDataType.Xml:
                result = DbType.AnsiString;
                break;

            case SysDataType.Bit:
                result = DbType.Boolean;
                break;

            case SysDataType.Byte:
                result = DbType.Byte;
                break;

            case SysDataType.Short:
                result = DbType.Int16;
                break;

            case SysDataType.Long:
                result = DbType.Int64;
                break;

            case SysDataType.Decimal:
                result = DbType.Decimal;
                break;
            }
            return(result);
        }