using System.Data;
using System.Data.SqlClient;
using System;
using Stat.DBUtility;
namespace Stat.SQLServerDAL
{
    public class Common : IDAL.ICommon
    {
        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_TABLENAME = "@TableName";

        #region ：Methods
        /// <summary>
        /// 获取项数据
        /// </summary>
        /// <param name="webid"></param>
        /// <param name="tableName">表名的标识部分</param>
        /// <param name="Cells"></param>
        /// <param name="t1"></param>
        /// <param name="t2"></param>
        /// <returns></returns>
        internal static DataTable GetViewItemData(int webid, string tableName, string Cells, DateTime t1, DateTime t2)
        {
            SqlParameter[] parms = SetParmeters(webid, tableName, Cells, t1, t2);
            return SqlHelper.ExecuteDataTable(SqlHelper.ConnectionStringMaster, CommandType.StoredProcedure, "Stat_ViewItemDataLoadAllByWebid", parms);
        }
        /// <summary>
        /// 获取项数据
        /// </summary>
        /// <param name="model">Stat.Model.StatInfo</param>
        internal static DataTable GetViewItemData(Stat.Model.StatInfo model)
        {
            SqlParameter[] parms = SetParmeters(model.WebID, model.TableName, model.Cells, model.StartTime, model.EndTime);
            return SqlHelper.ExecuteDataTable(SqlHelper.ConnectionStringMaster, CommandType.StoredProcedure, "Stat_ViewItemDataLoadAllByWebid", parms);
        }
















        #endregion

        #region ：Set Parmeters


        private static SqlParameter[] SetParmeters(int webid, string tableName, string Cells, DateTime t1, DateTime t2)
        {
            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)
            };
            parms[0].Value = webid;
            parms[1].Value = Cells;
            parms[2].Value = tableName;
            parms[3].Value = t1;
            parms[4].Value = t2;
            return parms;
        }

        #endregion
    }
}
