using System;
using System.Collections.Generic;

namespace Stat.BLL
{
    /// <summary>
    /// 
    /// </summary>
    public class DataList
    {
        /// <summary>
        /// 搜索引擎
        /// </summary>
        ///<param name="row"></param>
        /// <returns></returns>
        private static Model.StatItem GetEngine(System.Data.DataRow row)
        {
            Model.StatItem model = new Model.StatItem();
            if (row != null)
            {
                if (row.Table.Columns.Count > 0 && !Convert.IsDBNull(row[0])) model.ID = Convert.ToInt32(row[0]);
                if (row.Table.Columns.Count > 1 && !Convert.IsDBNull(row[1])) model.Name = Convert.ToString(row[1]);
                if (row.Table.Columns.Count > 2 && !Convert.IsDBNull(row[2])) model.KeyCount = Convert.ToInt32(row[2]);
                if (row.Table.Columns.Count > 3 && !Convert.IsDBNull(row[3])) model.PvCount = Convert.ToInt32(row[3]);
                if (row.Table.Columns.Count > 4 && !Convert.IsDBNull(row[4])) model.IpCount = Convert.ToInt32(row[4]);
                if (row.Table.Columns.Count > 5 && !Convert.IsDBNull(row[5])) model.UvCount = Convert.ToInt32(row[5]);
                if (row.Table.Columns.Count > 6 && !Convert.IsDBNull(row[6])) model.PerPV = Convert.ToDouble(row[6]);
                if (row.Table.Columns.Count > 7 && !Convert.IsDBNull(row[7])) model.Percent = Convert.ToDouble(row[7]); 

            }
            return model;
        }
        /// <summary>
        /// 搜索引擎
        /// </summary>
        /// <param name="table"></param>
        /// <returns></returns>
        internal static IList<Model.StatItem> GetEngine(System.Data.DataTable table)
        {
            List<Model.StatItem> list = new List<Model.StatItem>();
            if (table != null)
            {
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    list.Add(GetEngine(table.Rows[i]));
                }
            }
            return list;
        }
    }
}
