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

namespace SK.MemberDAL
{
	/// <summary>
	/// LeaveWord 的摘要说明。
	/// </summary>
	public class LeaveWord
	{
		public LeaveWord()
		{
			//
			// TODO: 在此处添加构造函数逻辑
			//
		}
		public void Add(object TrueName,object Sex,object Tel,object Email,object Body)
		{
			SqlParameter[] oParms =new SqlParameter[]{
														 new SqlParameter("@TrueName",TrueName),
														 new SqlParameter("@Sex",Sex),
														 new SqlParameter("@Tel",Tel),
														 new SqlParameter("@Email",Email),
														 new SqlParameter("@Body",Body)
			};
			

			SqlHelper.ExecuteScalar(Data.ConnString,CommandType.Text,"insert into LeaveWord(TrueName,Sex,Tel,Email,Body,SubmitTime) values(@TrueName,@Sex,@Tel,@Email,@Body,getdate())",oParms);
		}
		public int List_Count(object Keyword)
		{
			/*SqlParameter[] oParms =new SqlParameter[]{
														 new SqlParameter("@Keyword",Keyword),
			};*/
			SqlParameter[] oParms =new SqlParameter[1];
			oParms[0] = new SqlParameter("@Keyword",Keyword);
			return Convert.ToInt32(SqlHelper.ExecuteScalar(Data.ConnString,CommandType.Text,"select count(LeaveWordID) from LeaveWord where Body like '%"+@Keyword+"%'",oParms));
		}
		public DataSet List(int PageSize,int PageIndex,string Keyword)
		{
			SqlParameter[] oParms =new SqlParameter[1];
			oParms[0] = new SqlParameter("@Keyword",Keyword);
			/*SqlParameter[] oParms =new SqlParameter[]{
														 new SqlParameter("@Keyword",Keyword),
													 };*/
			
			return SqlHelper.ExecuteDataset(Data.ConnString,CommandType.Text,"select top "+PageSize+" LeaveWordID ,TrueName,Case Sex when 0 then '男' when 1 then '女' end as Sex,Tel,Email,Body,SubmitTime from LeaveWord where Body like '%"+@Keyword+"%' and LeaveWordID not in(select top "+(PageIndex-1)*PageSize+" LeaveWordID from LeaveWord where Body like '%"+@Keyword+"%' order by SubmitTime desc) order by SubmitTime desc",oParms);
		}
		public void Delete(object LeaveWordID)
		{
			SqlParameter[] oParms =new SqlParameter[]{
														 new SqlParameter("@LeaveWordID",LeaveWordID),
			};
			SqlHelper.ExecuteNonQuery(Data.ConnString,CommandType.Text,"delete LeaveWord where LeaveWordID=@LeaveWordID",oParms);
		}
	}
}
