public static string DateTimeFormatStrLine(string date)
        {
            DateTime dbNow = CommonUtil.GetDBDateTime();
            string   year  = dbNow.Year.ToString();
            string   month = dbNow.Month.ToString();
            string   day   = dbNow.Day.ToString();

            if (date.Trim().Length == RegexConsts.DATE_FORMAT_DAY.Length && (date.IndexOf("-") < 0 && date.IndexOf("/") < 0))
            {
                year  = TryConvertUtil.ToInt(date.Substring(0, 4), dbNow.Year).ToString();
                month = TryConvertUtil.ToInt(date.Substring(4, 2), dbNow.Month).ToString().PadLeft(2, '0');
                day   = TryConvertUtil.ToInt(date.Substring(6, 2), dbNow.Day).ToString().PadLeft(2, '0');

                return(string.Format("{0}-{1}-{2} 00:00:00", year, month, day));
            }
            else if (date.Trim().Length == RegexConsts.TIME_FORMAT_SECOND.Length && (date.IndexOf("-") < 0 && date.IndexOf("/") < 0 && date.IndexOf(":") < 0))
            {
                year  = TryConvertUtil.ToInt(date.Substring(0, 4), dbNow.Year).ToString();
                month = TryConvertUtil.ToInt(date.Substring(4, 2), dbNow.Month).ToString().PadLeft(2, '0');
                day   = TryConvertUtil.ToInt(date.Substring(6, 2), dbNow.Day).ToString().PadLeft(2, '0');
                string hour   = TryConvertUtil.ToInt(date.Substring(8, 2), dbNow.Hour).ToString().PadLeft(2, '0');
                string minute = TryConvertUtil.ToInt(date.Substring(10, 2), dbNow.Minute).ToString().PadLeft(2, '0');
                string second = TryConvertUtil.ToInt(date.Substring(12, 2), dbNow.Second).ToString().PadLeft(2, '0');

                return(string.Format("{0}-{1}-{2} {3}:{4}:{5}", year, month, day, hour, minute, second));
            }
            else
            {
                return(TryConvertUtil.ToDateTime(date, dbNow).ToString("yyyy-MM-dd HH:mm:ss"));
            }
        }
        public static TResult ToModel <TResult>(this DataRow row) where TResult : class, new()
        {
            if (row == null)
            {
                return(null);
            }

            DataTable dt = row.Table;
            //创建一个属性的列表
            List <PropertyInfo> prlist = new List <PropertyInfo>();
            //获取TResult的类型实例  反射的入口
            Type t = typeof(TResult);

            //获得TResult 的所有的Public 属性 并找出TResult属性和DataTable的列名称相同的属性(PropertyInfo) 并加入到属性列表
            Array.ForEach <PropertyInfo>(t.GetProperties(), p => { if (dt.Columns.IndexOf(p.Name) != -1)
                                                                   {
                                                                       prlist.Add(p);
                                                                   }
                                         });
            //创建返回的集合
            List <TResult> oblist = new List <TResult>();

            //创建TResult的实例
            TResult ob = new TResult();

            //找到对应的数据  并赋值
            prlist.ForEach(p =>
            {
                if (row[p.Name] != DBNull.Value)
                {
                    Type dataType = row[p.Name].GetType();
                    switch (dataType.Name)
                    {
                    case "MySqlDateTime":
                        p.SetValue(ob, TryConvertUtil.ToDateTime(row[p.Name]), null);
                        break;

                    default:
                        p.SetValue(ob, row[p.Name], null);
                        break;
                    }
                }
            });

            //放入到返回的集合中.
            return(ob);
        }
 public static string DateTimeFormatLine(string date)
 {
     return(TryConvertUtil.ToDateTime(date, CommonUtil.GetDBDateTime()).ToString("yyyy-MM-dd"));
 }
 /// <summary>
 /// 日期格式化,转换失败则返回当前日期
 /// </summary>
 /// <param name="date"></param>
 /// <returns></returns>
 public static string DateTimeFormat(string date)
 {
     return(TryConvertUtil.ToDateTime(date, CommonUtil.GetDBDateTime()).ToString("yyyy年MM月dd日"));
 }
 /// <summary>
 /// 获得数据库服务器当前的日期和时间
 /// </summary>
 /// <returns>数据库服务器当前的日期和时间</returns>
 public static DateTime GetDBDateTime()
 {
     return(TryConvertUtil.ToDateTime(DbUtil.DataManager.Current.IData.ExecuteScalar("SELECT NOW()")));
 }
        public static List <TResult> ToList <TResult>(this DataTable dt) where TResult : class, new()
        {
            if (dt == null)
            {
                return(null);
            }

            //创建一个属性的列表
            List <PropertyInfo> prlist = new List <PropertyInfo>();
            //获取TResult的类型实例  反射的入口
            Type t = typeof(TResult);

            //获得TResult 的所有的Public 属性 并找出TResult属性和DataTable的列名称相同的属性(PropertyInfo) 并加入到属性列表
            Array.ForEach <PropertyInfo>(t.GetProperties(), p => { if (dt.Columns.IndexOf(p.Name) != -1)
                                                                   {
                                                                       prlist.Add(p);
                                                                   }
                                         });
            //创建返回的集合
            List <TResult> oblist = new List <TResult>();

            foreach (DataRow row in dt.Rows)
            {
                //创建TResult的实例
                TResult ob = new TResult();
                //找到对应的数据  并赋值
                prlist.ForEach(p =>
                {
                    if (row[p.Name] != DBNull.Value)
                    {
                        Type dataType = row[p.Name].GetType();
                        switch (dataType.Name)
                        {
                        case "MySqlDateTime":
                            p.SetValue(ob, TryConvertUtil.ToDateTime(row[p.Name]), null);
                            break;

                        case "Int64":
                        case "Int32":
                            {
                                if (p.PropertyType == typeof(bool))
                                {
                                    p.SetValue(ob, TryConvertUtil.ToInt(row[p.Name]) == 1, null);
                                }
                                else
                                {
                                    p.SetValue(ob, TryConvertUtil.ToInt(row[p.Name]), null);
                                }
                                break;
                            }

                        default:
                            p.SetValue(ob, row[p.Name], null);
                            break;
                        }
                    }
                });
                //放入到返回的集合中.
                oblist.Add(ob);
            }
            return(oblist);
        }