using System.Data;
using System.Data.SqlClient;
using Stat.DBUtility;
using System;

namespace Stat.SQLServerDAL
{
    class IP : IDAL.IIP
    {
        #region IIP 成员

        public System.Data.DataTable Get(string IP)
        {
            SqlParameter parm = new SqlParameter("@IPNO", SqlDbType.BigInt);
            parm.Value = GetIPno(IP);
            return SqlHelper.ExecuteDataTable(SqlHelper.ConnectionStringMaster, CommandType.StoredProcedure, "Stat_IpLoadByIPNO", parm);
        }

        #endregion
        /// <summary>
        ///  获取 IP 对应 编号
        /// </summary>
        /// <param name="ip"></param>
        /// <returns></returns>
        private static Int64 GetIPno(string ip)
        {
            string[] IPArr = ip.Split('.');

            long UserIP = 256 * 256 * 256 * long.Parse(IPArr[0]) + 256 * 256 * long.Parse(IPArr[1]) + 256 * long.Parse(IPArr[2]) + long.Parse(IPArr[3]);

            return UserIP;
        }

    }
}
