using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using DotNet.FrameWork.Data;
namespace HaTeam.Dd.DAL
{
	/// <summary>
	/// 数据访问类:Dd_Like
	/// </summary>
	public partial class Dd_Like
	{
		public Dd_Like()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperSQL.GetMaxID("Like_ID", "Dd_Like"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int Like_ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from Dd_Like");
			strSql.Append(" where Like_ID=@Like_ID");
			SqlParameter[] parameters = {
					new SqlParameter("@Like_ID", SqlDbType.Int,4)
};
			parameters[0].Value = Like_ID;

            return DbHelperSQL.GetExists(strSql.ToString(), parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(HaTeam.Dd.Model.Dd_Like model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into Dd_Like(");
			strSql.Append("Like_TypeID,Like_ArticleID,Like_UserID,Like_Guid,Like_Datetime,Like_UpDatetime,Like_Verify,Like_Lock,Like_State,Like_Delete,Like_Count,Like_Order,Like_Remark)");
			strSql.Append(" values (");
			strSql.Append("@Like_TypeID,@Like_ArticleID,@Like_UserID,@Like_Guid,@Like_Datetime,@Like_UpDatetime,@Like_Verify,@Like_Lock,@Like_State,@Like_Delete,@Like_Count,@Like_Order,@Like_Remark)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@Like_TypeID", SqlDbType.Int,4),
					new SqlParameter("@Like_ArticleID", SqlDbType.Int,4),
					new SqlParameter("@Like_UserID", SqlDbType.Int,4),
					new SqlParameter("@Like_Guid", SqlDbType.NChar,36),
					new SqlParameter("@Like_Datetime", SqlDbType.DateTime),
					new SqlParameter("@Like_UpDatetime", SqlDbType.DateTime),
					new SqlParameter("@Like_Verify", SqlDbType.Int,4),
					new SqlParameter("@Like_Lock", SqlDbType.Int,4),
					new SqlParameter("@Like_State", SqlDbType.Int,4),
					new SqlParameter("@Like_Delete", SqlDbType.Int,4),
					new SqlParameter("@Like_Count", SqlDbType.Int,4),
					new SqlParameter("@Like_Order", SqlDbType.Int,4),
					new SqlParameter("@Like_Remark", SqlDbType.NText)};
			parameters[0].Value = model.Like_TypeID;
			parameters[1].Value = model.Like_ArticleID;
			parameters[2].Value = model.Like_UserID;
			parameters[3].Value = model.Like_Guid;
			parameters[4].Value = model.Like_Datetime;
			parameters[5].Value = model.Like_UpDatetime;
			parameters[6].Value = model.Like_Verify;
			parameters[7].Value = model.Like_Lock;
			parameters[8].Value = model.Like_State;
			parameters[9].Value = model.Like_Delete;
			parameters[10].Value = model.Like_Count;
			parameters[11].Value = model.Like_Order;
			parameters[12].Value = model.Like_Remark;

			object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(HaTeam.Dd.Model.Dd_Like model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update Dd_Like set ");
			strSql.Append("Like_TypeID=@Like_TypeID,");
			strSql.Append("Like_ArticleID=@Like_ArticleID,");
			strSql.Append("Like_UserID=@Like_UserID,");
			strSql.Append("Like_Guid=@Like_Guid,");
			strSql.Append("Like_Datetime=@Like_Datetime,");
			strSql.Append("Like_UpDatetime=@Like_UpDatetime,");
			strSql.Append("Like_Verify=@Like_Verify,");
			strSql.Append("Like_Lock=@Like_Lock,");
			strSql.Append("Like_State=@Like_State,");
			strSql.Append("Like_Delete=@Like_Delete,");
			strSql.Append("Like_Count=@Like_Count,");
			strSql.Append("Like_Order=@Like_Order,");
			strSql.Append("Like_Remark=@Like_Remark");
			strSql.Append(" where Like_ID=@Like_ID");
			SqlParameter[] parameters = {
					new SqlParameter("@Like_TypeID", SqlDbType.Int,4),
					new SqlParameter("@Like_ArticleID", SqlDbType.Int,4),
					new SqlParameter("@Like_UserID", SqlDbType.Int,4),
					new SqlParameter("@Like_Guid", SqlDbType.NChar,36),
					new SqlParameter("@Like_Datetime", SqlDbType.DateTime),
					new SqlParameter("@Like_UpDatetime", SqlDbType.DateTime),
					new SqlParameter("@Like_Verify", SqlDbType.Int,4),
					new SqlParameter("@Like_Lock", SqlDbType.Int,4),
					new SqlParameter("@Like_State", SqlDbType.Int,4),
					new SqlParameter("@Like_Delete", SqlDbType.Int,4),
					new SqlParameter("@Like_Count", SqlDbType.Int,4),
					new SqlParameter("@Like_Order", SqlDbType.Int,4),
					new SqlParameter("@Like_Remark", SqlDbType.NText),
					new SqlParameter("@Like_ID", SqlDbType.Int,4)};
			parameters[0].Value = model.Like_TypeID;
			parameters[1].Value = model.Like_ArticleID;
			parameters[2].Value = model.Like_UserID;
			parameters[3].Value = model.Like_Guid;
			parameters[4].Value = model.Like_Datetime;
			parameters[5].Value = model.Like_UpDatetime;
			parameters[6].Value = model.Like_Verify;
			parameters[7].Value = model.Like_Lock;
			parameters[8].Value = model.Like_State;
			parameters[9].Value = model.Like_Delete;
			parameters[10].Value = model.Like_Count;
			parameters[11].Value = model.Like_Order;
			parameters[12].Value = model.Like_Remark;
			parameters[13].Value = model.Like_ID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int Like_ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from Dd_Like ");
			strSql.Append(" where Like_ID=@Like_ID");
			SqlParameter[] parameters = {
					new SqlParameter("@Like_ID", SqlDbType.Int,4)
};
			parameters[0].Value = Like_ID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string Like_IDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from Dd_Like ");
			strSql.Append(" where Like_ID in ("+Like_IDlist + ")  ");
			int rows=DbHelperSQL.ExecuteSqlInt(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public HaTeam.Dd.Model.Dd_Like GetModel(int Like_ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 Like_ID,Like_TypeID,Like_ArticleID,Like_UserID,Like_Guid,Like_Datetime,Like_UpDatetime,Like_Verify,Like_Lock,Like_State,Like_Delete,Like_Count,Like_Order,Like_Remark from Dd_Like ");
			strSql.Append(" where Like_ID=@Like_ID");
			SqlParameter[] parameters = {
					new SqlParameter("@Like_ID", SqlDbType.Int,4)
};
			parameters[0].Value = Like_ID;

			HaTeam.Dd.Model.Dd_Like model=new HaTeam.Dd.Model.Dd_Like();
			DataSet ds=DbHelperSQL.GetDataSet(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["Like_ID"].ToString()!="")
				{
					model.Like_ID=int.Parse(ds.Tables[0].Rows[0]["Like_ID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Like_TypeID"].ToString()!="")
				{
					model.Like_TypeID=int.Parse(ds.Tables[0].Rows[0]["Like_TypeID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Like_ArticleID"].ToString()!="")
				{
					model.Like_ArticleID=int.Parse(ds.Tables[0].Rows[0]["Like_ArticleID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Like_UserID"].ToString()!="")
				{
					model.Like_UserID=int.Parse(ds.Tables[0].Rows[0]["Like_UserID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Like_Guid"]!=null)
				{
				model.Like_Guid=ds.Tables[0].Rows[0]["Like_Guid"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Like_Datetime"].ToString()!="")
				{
					model.Like_Datetime=DateTime.Parse(ds.Tables[0].Rows[0]["Like_Datetime"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Like_UpDatetime"].ToString()!="")
				{
					model.Like_UpDatetime=DateTime.Parse(ds.Tables[0].Rows[0]["Like_UpDatetime"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Like_Verify"].ToString()!="")
				{
					model.Like_Verify=int.Parse(ds.Tables[0].Rows[0]["Like_Verify"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Like_Lock"].ToString()!="")
				{
					model.Like_Lock=int.Parse(ds.Tables[0].Rows[0]["Like_Lock"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Like_State"].ToString()!="")
				{
					model.Like_State=int.Parse(ds.Tables[0].Rows[0]["Like_State"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Like_Delete"].ToString()!="")
				{
					model.Like_Delete=int.Parse(ds.Tables[0].Rows[0]["Like_Delete"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Like_Count"].ToString()!="")
				{
					model.Like_Count=int.Parse(ds.Tables[0].Rows[0]["Like_Count"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Like_Order"].ToString()!="")
				{
					model.Like_Order=int.Parse(ds.Tables[0].Rows[0]["Like_Order"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Like_Remark"]!=null)
				{
				model.Like_Remark=ds.Tables[0].Rows[0]["Like_Remark"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select Like_ID,Like_TypeID,Like_ArticleID,Like_UserID,Like_Guid,Like_Datetime,Like_UpDatetime,Like_Verify,Like_Lock,Like_State,Like_Delete,Like_Count,Like_Order,Like_Remark ");
			strSql.Append(" FROM Dd_Like ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.GetDataSet(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" Like_ID,Like_TypeID,Like_ArticleID,Like_UserID,Like_Guid,Like_Datetime,Like_UpDatetime,Like_Verify,Like_Lock,Like_State,Like_Delete,Like_Count,Like_Order,Like_Remark ");
			strSql.Append(" FROM Dd_Like ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.GetDataSet(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "Dd_Like";
			parameters[1].Value = "Like_ID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

