using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using Stat.DBUtility;
namespace Stat.SQLServerDAL
{
    /// <summary>
    /// 基础表数据
    /// </summary>
    class ViewClick : IDAL.IViewClick
    {
        private const string PARM_WEBID = "@webid";
        private const string PARM_CELLS = "@Cells";
        private const string PARM_TABLE_NAME = "@TableName";
        private const string PARM_HOUR = "@Hour";
        /// <summary>
        /// 
        /// </summary>
        /// <param name="model"></param>
        /// <returns>bY Juju 2011-10-27</returns>
        public List<Model.ViewItem_Int> GetListByGeqHour(Model.StatInfo model)
        {
            SqlParameter[] parms = new SqlParameter[] {             
                new SqlParameter(PARM_WEBID, SqlDbType.Int),
                new SqlParameter(PARM_CELLS, SqlDbType.NVarChar),
                new SqlParameter(PARM_TABLE_NAME, SqlDbType.NVarChar),
                new SqlParameter(PARM_HOUR, SqlDbType.Int)
            };
            parms[0].Value = model.WebID;
            parms[1].Value = "top 30000 id,ip,mac,View_Alone,vDay,vHour";
            parms[2].Value = "View_" + model.StartTime.Year + "_" + model.StartTime.Month + "_" + model.StartTime.Day;
            parms[3].Value = model.Hour;

            DataTable dt = SqlHelper.ExecuteDataTable(SqlHelper.ConnectionStringGather(model.GatherID), CommandType.StoredProcedure, "Stat_ViewClickLoadByGeqHour", parms);

            return ViewItems.GetInt.GetList(dt, "vHour");

        }


        public int GetTotal(Model.StatInfo model)
        {
            SqlParameter[] parms = new SqlParameter[] {             
                new SqlParameter(PARM_WEBID, SqlDbType.Int),  
                new SqlParameter(PARM_TABLE_NAME, SqlDbType.NVarChar)  
            };
            parms[0].Value = model.WebID;
            parms[1].Value = "View_" + model.StartTime.Year + "_" + model.StartTime.Month + "_" + model.StartTime.Day;


            object obj = SqlHelper.ExecuteScalar(SqlHelper.ConnectionStringGather(model.GatherID), CommandType.StoredProcedure, "Stat_ViewDataLoadCountByWebid", parms);

            if (null == obj)
                return 0;
            else
                return int.Parse(obj.ToString());

        }


        public List<Model.ViewItem_Int> GetList(Model.StatInfo model)
        {
            throw new System.NotImplementedException();
        }
    }
}