Beispiel #1
0
        /// <summary>
        /// 获取所有记录总数
        /// </summary>
        /// <param name="condition">查询条件(不包含WHERE和第一个AND)</param>
        /// <param name="days">最近多少天</param>
        /// <param name="currentWeek">当周</param>
        /// <param name="currentMonth">当月</param>
        /// <param name="currentQuarter">当季</param>
        /// <param name="currentYear">当年</param>
        /// <param name="startTime">开始时间</param>
        /// <param name="endTime">结束时间</param>
        /// <returns>总数</returns>
        public virtual int GetTotalCount(string condition = null, int days = 0, bool currentWeek = false, bool currentMonth = false, bool currentQuarter = false, bool currentYear = false, string startTime = null, string endTime = null)
        {
            var sb = Pool.StringBuilder.Get().Append(" 1 = 1");

            if (!string.IsNullOrEmpty(condition))
            {
                sb.Append(" AND " + condition);
            }
            if (days > 0)
            {
                sb.Append(" AND (DATEADD(d, " + days + ", " + BaseUtil.FieldCreateTime + ") > " + DbHelper.GetDbNow() + ")");
            }
            if (currentWeek)
            {
                sb.Append(" AND DATEDIFF(ww," + BaseUtil.FieldCreateTime + "," + DbHelper.GetDbNow() + ") = 0");
            }
            if (currentMonth)
            {
                sb.Append(" AND DATEDIFF(mm," + BaseUtil.FieldCreateTime + "," + DbHelper.GetDbNow() + ") = 0");
            }
            if (currentQuarter)
            {
                sb.Append(" AND DATEDIFF(qq," + BaseUtil.FieldCreateTime + "," + DbHelper.GetDbNow() + ") = 0");
            }
            if (currentYear)
            {
                sb.Append(" AND DATEDIFF(yy," + BaseUtil.FieldCreateTime + "," + DbHelper.GetDbNow() + ") = 0");
            }
            if (ValidateUtil.IsDateTime(startTime))
            {
                sb.Append(" AND " + BaseUtil.FieldCreateTime + " >= " + startTime + ")");
            }
            if (ValidateUtil.IsDateTime(endTime))
            {
                sb.Append(" AND " + BaseUtil.FieldCreateTime + " < " + endTime + ")");
            }
            sb.Replace(" 1 = 1 AND ", "");
            return(DbUtil.Count(DbHelper, CurrentTableName, condition: sb.Put()));
        }