using System.Collections.Generic;
using Stat.DBUtility;
namespace Stat.SQLServerDAL
{
    /// <summary>
    /// 分页
    /// </summary>
    class WebsitePageIndex : IDAL.IWebsitePageIndex
    {

        /// <summary>
        /// 获取列表（本次没有分页功能）
        /// </summary>
        public IList<global::Stat.Model.WebSites> GetList(ref global::Stat.Model.PageInfo pageInfo, global::Stat.Model.SearchInfo searchInfo)
        {
            searchInfo.UserPower = searchInfo.UserPower == null ? "0" : searchInfo.UserPower;
            searchInfo.UserPower = searchInfo.UserPower.Length == 0 ? "0" : searchInfo.UserPower;

            string strYear = "Stat_ViewDay_" + System.DateTime.Now.AddDays(-1).Year;



            string table = "Stat_WebSites as a left join " + strYear + " as b on (a.WebId=b.WebId AND b.vDate='" + System.DateTime.Now.AddDays(-1).ToShortDateString() + "')";
            string fildes = "a.*,b.pvCount AS YdPvCount,b.ipCount as YdIpCount";

            string sqlWhere = "a.webid in(" + searchInfo.UserPower + ")";
            int recordCount = 0;

            IList<global::Stat.Model.WebSites> dt = WebSites.GetList(JPageIndex.ProGetList.GetFromDataTable(table, fildes, sqlWhere, "b.pvCount", 1, pageInfo.PageSize, 1, ref recordCount, "Stat_PageIndex", SqlHelper.ConnectionStringMaster));

            pageInfo.RecordCount = recordCount;

            return dt;

        }


        public IList<global::Stat.Model.WebSites> GetInSearch(ref global::Stat.Model.PageInfo pageInfo, global::Stat.Model.SearchInfo searchInfo)
        {
            string sqlWhere = "1=1";

            if (searchInfo.KeyWord != null && searchInfo.KeyWord.Length > 0)
            {
                sqlWhere += " and (WebName like '%" + searchInfo.KeyWord + "%' or WebUrl like '%" + searchInfo.KeyWord + "%')";
            }            
            int recordCount = 0;
            IList<global::Stat.Model.WebSites> dt = WebSites.GetList(JPageIndex.ProGetList.GetFromDataTable("Stat_WebSites", "*", sqlWhere, "WebId", 0, pageInfo.PageSize, pageInfo.PageIndex, ref recordCount, "Stat_PageIndex",SqlHelper.ConnectionStringMaster));

            pageInfo.RecordCount = recordCount;

            return dt;
        }


    }
}
