using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using Stat.DBUtility;
namespace Stat.SQLServerDAL
{
    class ViewDomain : IDAL.IViewDomain
    {

        private const string PARM_WEBID = "@Webid";
        private const string PARM_CELLS = "@Cells";
        private const string PARM_T1 = "@t1";
        private const string PARM_T2 = "@t2";
        private const string PARM_Domain = "@Domain";
        private const string PARM_TABLENAME = "@TableName";


        #region IViewDomain 成员
        /// <summary>
        /// 
        /// </summary>
        /// <param name="model"></param>
        /// <returns>Juju 2011-10-27</returns>
        public List<Model.StatItem> GetList(Stat.Model.StatInfo model)
        {
            model.TableName = "ViewDomain";
            model.Cells = "Domain,pvCount,ipCount,uvCount,nuvCount,timCount,otimCount,vYear,vMonth,vDay";
            return StatItem.GetList(Common.GetViewItemData(model), "Domain", 1);
        }

        #endregion

        #region IViewOnClick 成员 ：来路域名
        /// <summary>
        /// 
        /// </summary>
        /// <param name="model"></param>
        /// <returns>Juju 2011-10-27</returns>
        public List<Model.ViewItem_String> GetItem(global::Stat.Model.StatInfo model)
        {
            model.TableName = "View_" + model.StartTime.Year + "_" + model.StartTime.Month + "_" + model.StartTime.Day;
            model.Cells = "top 20000 [id],SoId,[domain],IP,Mac,ViewTime,View_Alone";
            return ViewItems.GetString.GetList(GetViewClickWithDomain(model), "domain");
        }
        #endregion

        /// <summary>
        /// 
        /// </summary>
        /// <remarks>Juju 2011-10-27</remarks>
        private DataTable GetViewClickWithDomain(global::Stat.Model.StatInfo model)
        {
            SqlParameter[] parms = SetParmeters(model.WebID, model.TableName, model.Cells);
            return SqlHelper.ExecuteDataTable(SqlHelper.ConnectionStringGather(model.GatherID), CommandType.StoredProcedure, "[Stat_ViewClickLoadDomainByWebid]", parms);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="webid"></param>
        /// <param name="tableName"></param>
        /// <param name="Cells"></param>
        /// <returns>juju 2011-10-27</returns>
        private static SqlParameter[] SetParmeters(int webid, string tableName, string Cells)
        {
            SqlParameter[] parms = new SqlParameter[] {
            new SqlParameter(PARM_WEBID, SqlDbType.Int),
            new SqlParameter(PARM_CELLS, SqlDbType.NVarChar),
            new SqlParameter(PARM_TABLENAME, SqlDbType.NVarChar),
           //new SqlParameter(PARM_T1, SqlDbType.DateTime),
            //new SqlParameter(PARM_T2, SqlDbType.DateTime),
            //new SqlParameter(PARM_Domain, SqlDbType.NVarChar)
            };
            parms[0].Value = webid;
            parms[1].Value = Cells;
            parms[2].Value = tableName;
            //parms[3].Value = t1;
            //parms[4].Value = t2;
            //parms[5].Value = domain;

            return parms;
        }
    }
}
