using System;
using System.Collections.Generic;

namespace Stat.SQLServerDAL.ViewItems
{
    public class GetString
    {
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static List<Model.ViewItem_String> GetList(System.Data.DataTable table, string cellName)
        {
            List<Model.ViewItem_String> list = new List<Model.ViewItem_String>();
            if (table != null)
            {
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    list.Add(GetModel(table.Rows[i], cellName));
                }
            }
            return list;
        }
        /// <summary>
        /// 将记录集转为实体类
        /// </summary>
        /// <param name="dr">记录集</param> 
        /// <returns></returns>
        private static Model.ViewItem_String GetModel(System.Data.DataRow dr, string cellName)
        {
            Model.ViewItem_String model = new Model.ViewItem_String();
            if (dr.Table.Columns.Contains("id") && !Convert.IsDBNull(dr["id"])) model.id = Convert.ToInt32(dr["id"]); // id
            if (dr.Table.Columns.Contains(cellName) && !Convert.IsDBNull(dr[cellName])) model.ItemName = dr[cellName].ToString(); // ItemName             
            if (dr.Table.Columns.Contains("View_Alone") && !Convert.IsDBNull(dr["View_Alone"])) model.View_Alone = Convert.ToInt32(dr["View_Alone"]); // View_Alone     
            if (dr.Table.Columns.Contains("ip") && !Convert.IsDBNull(dr["ip"])) model.ip = dr["ip"].ToString(); ; // ip
            if (dr.Table.Columns.Contains("mac") && !Convert.IsDBNull(dr["mac"])) model.mac = dr["mac"].ToString(); ; // mac
            if (dr.Table.Columns.Contains("Soid") && !Convert.IsDBNull(dr["Soid"])) model.Soid = Convert.ToInt32(dr["Soid"]); ; // Soid
            return model;
        }
    }
}