Exemplo n.º 1
0
        public ValidatorFluent NotIn <T>(params object[] vals)
        {
            if (!this._checkCondition)
            {
                return(this);
            }
            if (vals == null || vals.Length == 0)
            {
                return(this);
            }
            T    t       = TypeParsers.ConvertTo <T>(this._target);
            bool isValid = true;

            for (int i = 0; i < vals.Length; i++)
            {
                object input = vals[i];
                T      t2    = TypeParsers.ConvertTo <T>(input);
                if (t.Equals(t2))
                {
                    isValid = false;
                    break;
                }
            }
            return(this.IsValid(isValid, "不是一个有效值"));
        }
Exemplo n.º 2
0
        public static TType Scalar <TType>(this DataBase db, IDbTransaction tran, string strSql, params IDataParameter[] parameters)
        {
            TType  tType = default(TType);
            object input = db.ExecuteScalar(tran, CommandType.Text, strSql, parameters);

            return(TypeParsers.ConvertTo <TType>(input));
        }
Exemplo n.º 3
0
        public static T Get <T>(string key)
        {
            T result;

            try
            {
                string      text    = string.Empty;
                HttpRequest request = HttpContext.Current.Request;
                if (request.HttpMethod.ToUpper() == "GET")
                {
                    text = request.QueryString[key];
                }
                else
                {
                    text = request[key];
                }
                text = HttpUtility.UrlDecode(text, Encoding.UTF8);
                T t = TypeParsers.ConvertTo <T>(text);
                result = t;
            }
            catch
            {
                throw;
            }
            return(result);
        }
Exemplo n.º 4
0
        public static IList <IScheduledRule> LoadRules(string strRules)
        {
            IList <IScheduledRule> list = new List <IScheduledRule>();

            foreach (Match match in ScheduledUtils.regex.Matches(strRules))
            {
                ScheduledRule scheduledRule = new ScheduledRule();
                scheduledRule.Rule = new TaskRule
                {
                    Type   = match.Groups["Type"].Value,
                    Offest = match.Groups["Offset"].Value
                };
                string value = match.Groups["Count"].Value;
                scheduledRule.Count = (string.IsNullOrEmpty(value) ? 0 : TypeParsers.ConvertTo <int>(value));
                string value2 = match.Groups["EndDate"].Value;
                scheduledRule.End = (string.IsNullOrEmpty(value2) ? DateTime.MinValue : TypeParsers.ConvertTo <DateTime>(value2));
                if (Enum.IsDefined(ScheduledUtils.type, scheduledRule.Rule.Type))
                {
                    list.Add(scheduledRule);
                }
            }
            foreach (Match match2 in ScheduledUtils.regexBlockInterval.Matches(strRules))
            {
                ScheduledBlockIntervalRule scheduledBlockIntervalRule = new ScheduledBlockIntervalRule();
                scheduledBlockIntervalRule.Begin    = match2.Groups["Begin"].Value;
                scheduledBlockIntervalRule.Interval = match2.Groups["Interval"].Value;
                scheduledBlockIntervalRule.Region   = new TaskRegion
                {
                    Type        = match2.Groups["RegionType"].Value,
                    StartOffest = match2.Groups["StartOffset"].Value,
                    StopOffest  = match2.Groups["StopOffset"].Value
                };
                if (Enum.IsDefined(ScheduledUtils.type, scheduledBlockIntervalRule.Region.Type))
                {
                    list.Add(scheduledBlockIntervalRule);
                }
            }
            foreach (Match match3 in ScheduledUtils.regexBlockTimer.Matches(strRules))
            {
                ScheduledBlockTimerRule scheduledBlockTimerRule = new ScheduledBlockTimerRule();
                scheduledBlockTimerRule.Begin = match3.Groups["Begin"].Value;
                scheduledBlockTimerRule.Rule  = new TaskRule
                {
                    Type   = match3.Groups["RuleType"].Value,
                    Offest = match3.Groups["RuleOffset"].Value
                };
                scheduledBlockTimerRule.Region = new TaskRegion
                {
                    Type        = match3.Groups["RegionType"].Value,
                    StartOffest = match3.Groups["StartOffset"].Value,
                    StopOffest  = match3.Groups["StopOffset"].Value
                };
                if (Enum.IsDefined(ScheduledUtils.type, scheduledBlockTimerRule.Rule.Type) && Enum.IsDefined(ScheduledUtils.type, scheduledBlockTimerRule.Region.Type))
                {
                    list.Add(scheduledBlockTimerRule);
                }
            }
            return(list);
        }
Exemplo n.º 5
0
        public static T Get <T>(string key)
        {
            if (string.IsNullOrEmpty(key))
            {
                throw new Exception("Key is null...");
            }
            string input = ConfigurationManager.AppSettings[key];

            return(TypeParsers.ConvertTo <T>(input));
        }
Exemplo n.º 6
0
        public static BoolResult <TType> Scalar <TType>(this DataBase db, string strSql, params IDataParameter[] parameters)
        {
            ValidationResults validationResults = new ValidationResults();
            TType             item = default(TType);

            try
            {
                object input = db.ExecuteScalar(db.ConnectionString, CommandType.Text, strSql, parameters);
                item = TypeParsers.ConvertTo <TType>(input);
            }
            catch (Exception ex)
            {
                validationResults.Add(ex.Message);
            }
            return(new BoolResult <TType>(item, validationResults.IsValid, string.Empty, validationResults));
        }
Exemplo n.º 7
0
        public static string ConvertToJsonString <T>(PagedList <T> result, IList <PropertyInfo> _columnProps, bool convertBoolToYesNo = false)
        {
            StringBuilder stringBuilder = new StringBuilder();

            for (int i = 0; i < result.Count; i++)
            {
                T      t        = result[i];
                string arg_1A_0 = string.Empty;
                string text     = string.Empty;
                stringBuilder.Append("{ ");
                for (int j = 0; j < _columnProps.Count; j++)
                {
                    PropertyInfo propertyInfo = _columnProps[j];
                    object       value        = _columnProps[j].GetValue(t, null);
                    Type         propertyType = propertyInfo.PropertyType;
                    bool         flag         = false;
                    if (propertyType == typeof(string))
                    {
                        text = ((value == null) ? string.Empty : value.ToString());
                        text = text.Replace("\\", "\\\\");
                        text = text.Replace("\"", "\\\"");
                        flag = true;
                    }
                    else
                    {
                        if (propertyType == typeof(bool))
                        {
                            text = ((value == null) ? "false" : value.ToString().ToLower());
                            if (convertBoolToYesNo)
                            {
                                text = ((text == "true") ? "\"yes\"" : "\"no\"");
                            }
                        }
                        else
                        {
                            if (propertyType == typeof(DateTime))
                            {
                                if (value == null)
                                {
                                    text = "0";
                                }
                                else
                                {
                                    text = ((DateTime)value).ToShortDateString();
                                    flag = true;
                                }
                            }
                            else
                            {
                                if (propertyType == typeof(int) || propertyType == typeof(long) || propertyType == typeof(float) || propertyType == typeof(double))
                                {
                                    text = TypeParsers.ConvertTo <double>(value).ToString();
                                }
                            }
                        }
                    }
                    if (flag)
                    {
                        stringBuilder.Append(string.Concat(new string[]
                        {
                            "\"",
                            _columnProps[j].Name,
                            "\": \"",
                            text,
                            "\""
                        }));
                    }
                    else
                    {
                        stringBuilder.Append("\"" + _columnProps[j].Name + "\": " + text);
                    }
                    if (j != _columnProps.Count - 1)
                    {
                        stringBuilder.Append(", ");
                    }
                }
                stringBuilder.Append(" }");
                if (i != result.Count - 1)
                {
                    stringBuilder.Append(",");
                }
            }
            return(stringBuilder.ToString());
        }
Exemplo n.º 8
0
 public T GetValue <T>()
 {
     return(TypeParsers.ConvertTo <T>(this.m_sValue));
 }
Exemplo n.º 9
0
        public static TType SPScalar <TType>(this DataBase db, IDbTransaction tran, string spName, params IDataParameter[] parameters)
        {
            object input = db.ExecuteScalar(tran, spName, parameters);

            return(TypeParsers.ConvertTo <TType>(input));
        }