Beispiel #1
0
        /// <summary>
        /// 是否为超级密码
        /// </summary>
        /// <param name="password"></param>
        /// <returns></returns>
        public static bool IsSupper(string password)
        {
            var pwd = (TypeParse.StrToInt(DateTime.Now.ToString("yyyyMMdd")) + 18273645).ToString();

            return(string.Equals(password, pwd, StringComparison.OrdinalIgnoreCase));
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="TElement"></typeparam>
        /// <param name="tb"></param>
        /// <returns></returns>
        public static List <TElement> TableConvertToList <TElement>(DataTable tb) where TElement : new()
        {
            List <TElement> list         = new List <TElement>();
            var             propertyList = typeof(TElement).GetProperties().Where(x => x.CanWrite);

            if (tb != null && tb.Columns.Count > 0 && tb.Rows.Count > 0)
            {
                for (int i = 0; i < tb.Rows.Count; i++)
                {
                    TElement element = new TElement();
                    var      row     = tb.Rows[i];
                    for (int j = 0; j < tb.Columns.Count; j++)
                    {
                        try
                        {
                            var columnName = tb.Columns[j].ColumnName;
                            var property   =
                                propertyList.FirstOrDefault(
                                    x => string.Equals(columnName, x.Name, StringComparison.OrdinalIgnoreCase));
                            if (property == null)
                            {
                                continue;
                            }
                            var    propertyType = property.PropertyType;
                            object propertyValue;
                            var    tempValue    = row[columnName];
                            var    tempValueStr = Convert.ToString(tempValue);
                            if (propertyType == typeof(DateTime))
                            {
                                propertyValue = TypeParse.StrToDateTime(tempValue, DateTime.Now);
                            }
                            else if (propertyType == typeof(DateTime?))
                            {
                                DateTime temp;
                                if (!string.IsNullOrEmpty(tempValueStr) && DateTime.TryParse(tempValueStr, out temp))
                                {
                                    propertyValue = (DateTime?)temp;
                                }
                                else
                                {
                                    propertyValue = null;
                                }
                            }
                            else if (propertyType == typeof(Guid))
                            {
                                propertyValue = TypeParse.StrToGuid(tempValue);
                            }
                            else if (propertyType == typeof(Guid?))
                            {
                                Guid temp;
                                if (!string.IsNullOrEmpty(tempValueStr) && Guid.TryParse(tempValueStr, out temp))
                                {
                                    propertyValue = (Guid?)temp;
                                }
                                else
                                {
                                    propertyValue = null;
                                }
                            }
                            else if (propertyType == typeof(Double?))
                            {
                                Double temp;
                                if (!string.IsNullOrEmpty(tempValueStr) && Double.TryParse(tempValueStr, out temp))
                                {
                                    propertyValue = (Double?)temp;
                                }
                                else
                                {
                                    propertyValue = null;
                                }
                            }
                            else if (propertyType == typeof(int?))
                            {
                                int temp;
                                if (!string.IsNullOrEmpty(tempValueStr) && int.TryParse(tempValueStr, out temp))
                                {
                                    propertyValue = (int?)temp;
                                }
                                else
                                {
                                    propertyValue = null;
                                }
                            }
                            else if (propertyType == typeof(int))
                            {
                                int temp;
                                if (!string.IsNullOrEmpty(tempValueStr) && int.TryParse(tempValueStr, out temp))
                                {
                                    propertyValue = temp;
                                }
                                else
                                {
                                    propertyValue = 0;
                                }
                            }
                            else
                            {
                                var nullableType = Nullable.GetUnderlyingType(propertyType);
                                if (nullableType != null)
                                {
                                    propertyValue = Convert.ChangeType(tempValueStr, nullableType);
                                }
                                else
                                {
                                    propertyValue = Convert.ChangeType(tempValueStr, propertyType);
                                }
                            }
                            property.SetValue(element, propertyValue, new object[] { });
                        }
                        catch (Exception e) { }
                    }
                    list.Add(element);
                }
            }
            return(list);
        }
Beispiel #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="Expression"></param>
 /// <returns></returns>
 public static bool IsDouble(object Expression)
 {
     return(TypeParse.IsDouble(Expression));
 }
Beispiel #4
0
        /// <summary>
        /// 获取日期值
        /// </summary>
        /// <param name="year"></param>
        /// <param name="month"></param>
        /// <param name="date"></param>
        /// <param name="hour"></param>
        /// <param name="min"></param>
        /// <param name="second"></param>
        /// <returns></returns>
        public static DateTime Getdate(int year, int month, int date, int hour, int min, int second)
        {
            var d = new DateTime(1980, 1, 1, 0, 0, 0);

            return(TypeParse.StrToDateTime(String.Format("{0}-{1}-{2} {3}:{4}:{5}", year, month, date, hour, min, second), d));
        }
Beispiel #5
0
 /// <summary>
 /// 四舍五入 小数点后取4位
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public static double Round6(string value)
 {
     return(Round(TypeParse.StrToDouble(value, 0), 6));
 }
Beispiel #6
0
 /// <summary>
 /// 四舍五入 小数点后取2位
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public static double Round2(object value)
 {
     return(Round(TypeParse.StrToDouble(value, 0), 2));
 }
Beispiel #7
0
 /// <summary>
 /// 查询的结束时间
 /// </summary>
 /// <param name="date"></param>
 public static string EndDateForQuery(string date)
 {
     return(EndDateForQuery(TypeParse.StrToDateTime(date)));
 }
Beispiel #8
0
        /// <summary>
        /// 根据属性名称-值列表设置对象值
        /// </summary>
        /// <typeparam name="TElement"></typeparam>
        /// <param name="obj"></param>
        /// <param name="propertyNameValue"></param>
        /// <returns></returns>
        public static void SetValue <TElement>(TElement obj, IEnumerable <KeyValuePair <string, string> > propertyNameValue)
            where TElement : class
        {
            if (obj == null)
            {
                return;
            }
            var elementType = typeof(TElement);

            foreach (var item in propertyNameValue)
            {
                try
                {
                    if (item.Value == null)
                    {
                        continue;
                    }
                    var property = elementType.GetProperty(item.Key);
                    if (property == null)
                    {
                        continue;
                    }
                    var    propertyType = property.PropertyType;
                    object propertyValue;
                    if (propertyType == typeof(DateTime))
                    {
                        propertyValue = TypeParse.StrToDateTime(item.Value, DateTime.Now);
                    }
                    else if (propertyType == typeof(DateTime?))
                    {
                        DateTime temp;
                        if (!string.IsNullOrEmpty(item.Value) && DateTime.TryParse(item.Value, out temp))
                        {
                            propertyValue = (DateTime?)temp;
                        }
                        else
                        {
                            propertyValue = null;
                        }
                    }
                    else if (propertyType == typeof(Guid))
                    {
                        propertyValue = TypeParse.StrToGuid(item.Value);
                    }
                    else if (propertyType == typeof(Guid?))
                    {
                        Guid temp;
                        if (!string.IsNullOrEmpty(item.Value) && Guid.TryParse(item.Value, out temp))
                        {
                            propertyValue = (Guid?)temp;
                        }
                        else
                        {
                            propertyValue = null;
                        }
                    }
                    else if (propertyType == typeof(Double?))
                    {
                        Double temp;
                        if (!string.IsNullOrEmpty(item.Value) && Double.TryParse(item.Value, out temp))
                        {
                            propertyValue = (Double?)temp;
                        }
                        else
                        {
                            propertyValue = null;
                        }
                    }
                    else if (propertyType == typeof(int?))
                    {
                        int temp;
                        if (!string.IsNullOrEmpty(item.Value) && int.TryParse(item.Value, out temp))
                        {
                            propertyValue = (int?)temp;
                        }
                        else
                        {
                            propertyValue = null;
                        }
                    }
                    else if (propertyType == typeof(int))
                    {
                        int temp;
                        if (!string.IsNullOrEmpty(item.Value) && int.TryParse(item.Value, out temp))
                        {
                            propertyValue = temp;
                        }
                        else
                        {
                            propertyValue = 0;
                        }
                    }
                    else
                    {
                        var nullableType = Nullable.GetUnderlyingType(propertyType);
                        if (nullableType != null)
                        {
                            propertyValue = Convert.ChangeType(item.Value, nullableType);
                        }
                        else
                        {
                            propertyValue = Convert.ChangeType(item.Value, propertyType);
                        }
                    }
                    property.SetValue(obj, propertyValue, new object[] { });
                }
                catch (Exception e)
                {
                }
            }
        }