using System;
using System.Data;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;

namespace SK.MemberDAL
{
	/// <summary>
	/// Country 的摘要说明。
	/// </summary>
	public class Country
	{
		public Country()
		{
			//
			// TODO: 在此处添加构造函数逻辑
			//
		}
		public DataSet List()
		{
			return SqlHelper.ExecuteDataset(Data.ConnString,CommandType.Text,"select * from Country");
		}
		public void Add(object CountryName)
		{
			SqlParameter[] oParms = new SqlParameter[1];
			oParms[0] = new SqlParameter("@CountryName",CountryName);

			SqlHelper.ExecuteNonQuery(Data.ConnString,CommandType.Text,"insert into Country(CountryName) values(@CountryName)",oParms);
		}
		public DataRow Info(object CountryID)
		{
			SqlParameter[] oParms = new SqlParameter[1];
			oParms[0] = new SqlParameter("@CountryID",CountryID);

			using(DataSet ds = SqlHelper.ExecuteDataset(Data.ConnString,CommandType.Text,"select * from Country where CountryID=@CountryID",oParms))
			{
				if(ds.Tables[0].Rows.Count>0)
					return ds.Tables[0].Rows[0];
				else
					return null;
			}
		}
		public void Delete(object CountryID)
		{
			string spName;
			SqlParameter[] oParms;
			spName = "Country_Delete";
			oParms = SqlHelperParameterCache.GetSpParameterSet(Data.ConnString, spName);
			oParms[0].Value=CountryID;
			
			SqlHelper.ExecuteNonQuery(Data.ConnString, spName, oParms);
		}
		public void Update(object CountryID,object CountryName)
		{
			SqlParameter[] oParms = new SqlParameter[2];
			oParms[0] = new SqlParameter("@CountryID",CountryID);
			oParms[1] = new SqlParameter("@CountryName",CountryName);

			SqlHelper.ExecuteNonQuery(Data.ConnString,CommandType.Text,"update Country set CountryName=@CountryName where CountryID=@CountryID",oParms);
		}
	}
}
