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

namespace SK.MemberDAL
{
	/// <summary>
	/// Monthly 的摘要说明。
	/// </summary>
	public class Monthly
	{
		public Monthly()
		{
			//
			// TODO: 在此处添加构造函数逻辑
			//
		}
		/*public void Add(object MemberID,object ProductID,object ExpiredTime)
		{
			SqlParameter[] oParms = new SqlParameter[3];
			oParms[0] = new SqlParameter("@MemberID",MemberID);
			oParms[1] = new SqlParameter("@ProductID",ProductID);
			oParms[2] = new SqlParameter("@ExpiredTime",ExpiredTime);

			SqlHelper.ExecuteNonQuery(Data.ConnString,CommandType.Text,"insert 
		}*/
		public DataRow Info_ProductID(object MemberID,object ProductID)
		{
			SqlParameter[] oParms = new SqlParameter[2];
			oParms[0] = new SqlParameter("@MemberID",MemberID);
			oParms[1] = new SqlParameter("@ProductID",ProductID);

			using(DataSet ds = SqlHelper.ExecuteDataset(Data.ConnString,CommandType.Text,"select * from Monthly where MemberID=@MemberID and ProductID=@ProductID",oParms))
			{
				if(ds.Tables[0].Rows.Count>0)
					return ds.Tables[0].Rows[0];
				else
					return null;
			}
		}
		public void Update(object MemberID,object ProductID,object ExpiredTime)
		{
			string spName;
			SqlParameter[] oParms;
			spName = "Monthly_Update";
			oParms = SqlHelperParameterCache.GetSpParameterSet(Data.ConnString, spName);
			oParms[0].Value=MemberID;
			oParms[1].Value=ProductID;
			oParms[2].Value=ExpiredTime;
			
			SqlHelper.ExecuteScalar(Data.ConnString, spName, oParms);
		}
		public DataSet List_MemberID(object MemberID)
		{
			SqlParameter[] oParms = new SqlParameter[1];
			oParms[0] = new SqlParameter("@MemberID",MemberID);

			return SqlHelper.ExecuteDataset(Data.ConnString,CommandType.Text,"select a.*,b.ProductName from Monthly a LEFT JOIN Product b ON a.ProductID=b.ProductID where a.MemberID=@MemberID and ExpiredTime>getdate()",oParms);
		}
		public bool Expired(object MemberID,object ProductID)
		{
			SqlParameter[] oParms = new SqlParameter[2];
			oParms[0] = new SqlParameter("@MemberID",MemberID);
			oParms[1] = new SqlParameter("@ProductID",ProductID);

			return Convert.ToInt32(SqlHelper.ExecuteScalar(Data.ConnString,CommandType.Text,"select Count(*) from Monthly where ProductID=@ProductID and MemberID=@MemberID and ExpiredTime>getdate()",oParms))==0;
		}
	}
}
