Ejemplo n.º 1
0
        /// <summary>
        /// 获取当前请求中的表单数据,如果没有该表单项,将返回传入的默认值
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key">表单名</param>
        /// <param name="method">数据提交方法</param>
        /// <param name="defaultValue">默认值</param>
        /// <returns></returns>
        public T[] GetList <T>(string key, Method method, T[] defaultValue) where T : struct
        {
            string value = GetValue(key, method);

            if (string.IsNullOrEmpty(value))
            {
                return(defaultValue);
            }

            using (ErrorScope es = new ErrorScope())
            {
                string[] strings = value.Split(',');
                T[]      results = new T[strings.Length];

                for (int i = 0; i < strings.Length; i++)
                {
                    string tempValue = strings[i];
                    if (tempValue == string.Empty)
                    {
                        continue;
                    }
                    T result;
                    if (StringUtil.TryParse <T>(tempValue, out result))
                    {
                        results[i] = result;
                    }
                    else
                    {
                        es.IgnoreError <ErrorInfo>();
                        return(new T[0]);
                    }
                }
                return(results);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取当前请求中的表单数据,如果没有该表单项,将返回传入的默认值
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key">表单名</param>
        /// <param name="method">数据提交方法</param>
        /// <param name="defaultValue">默认值</param>
        /// <returns></returns>
        public T Get <T>(string key, Method method, T defaultValue) where T : struct
        {
            string value = GetValue(key, method);

            if (value == null)
            {
                return(defaultValue);
            }

            using (ErrorScope es = new ErrorScope())
            {
                T result;

                if (StringUtil.TryParse <T>(value, out result))
                {
                    /*用户时间转数据库服务器时间*/
                    if (typeof(T) == typeof(DateTime))
                    {
                        DateTime dateTime = (DateTime)(object)result;
                        dateTime.AddHours(-UserBO.Instance.GetUserTimeDiffrence(User.Current));
                        return((T)(object)dateTime);
                    }
                    /*  */
                    return(result);
                }
                else
                {
                    es.IgnoreError <ErrorInfo>();
                    return(defaultValue);
                }
            }
        }
Ejemplo n.º 3
0
        public static T TryParse <T>(string value)
        {
            using (ErrorScope es = new ErrorScope())
            {
                T result = StringUtil.TryParse <T>(value);

                es.IgnoreError <ErrorInfo>();

                return(result);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 获取当前请求中的表单数据,如果没有该表单项,将返回null
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key">表单名</param>
        /// <param name="method">数据提交方法</param>
        /// <returns></returns>
        public Nullable <T> Get <T>(string key, Method method) where T : struct
        {
            string value = null;

            if (method == Method.Post || method == Method.All)
            {
                value = GetForm(key);
            }

            if (method == Method.Get || (method == Method.All && value == null))
            {
                value = GetQueryString(key);
            }

            if (value == null)
            {
                return(null);
            }


            using (ErrorScope es = new ErrorScope())
            {
                T result;

                if (StringUtil.TryParse <T>(value, out result))
                {
                    //用户时间转数据库服务器时间
                    if (typeof(T) == typeof(DateTime))
                    {
                        DateTime dateTime = (DateTime)(object)result;
                        dateTime.AddHours(0 - UserBO.Instance.GetUserTimeDiffrence(User.Current));
                        return((T)(object)dateTime);
                    }

                    return(result);
                }
                else
                {
                    es.IgnoreError <ErrorInfo>();
                    return(null);
                }
            }
        }