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

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

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

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


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(HaTeam.Dd.Model.Dd_Reply model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into Dd_Reply(");
			strSql.Append("Reply_UserID,Reply_Content,Reply_ArticleID,Reply_Type,Reply_Guid,Reply_Datetime,Reply_UpDatetime,Reply_Verify,Reply_Lock,Reply_State,Reply_Delete,Reply_Count,Reply_Order,Reply_Remark)");
			strSql.Append(" values (");
			strSql.Append("@Reply_UserID,@Reply_Content,@Reply_ArticleID,@Reply_Type,@Reply_Guid,@Reply_Datetime,@Reply_UpDatetime,@Reply_Verify,@Reply_Lock,@Reply_State,@Reply_Delete,@Reply_Count,@Reply_Order,@Reply_Remark)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@Reply_UserID", SqlDbType.Int,4),
					new SqlParameter("@Reply_Content", SqlDbType.NVarChar,200),
					new SqlParameter("@Reply_ArticleID", SqlDbType.Char,12),
					new SqlParameter("@Reply_Type", SqlDbType.Int,4),
					new SqlParameter("@Reply_Guid", SqlDbType.NChar,36),
					new SqlParameter("@Reply_Datetime", SqlDbType.DateTime),
					new SqlParameter("@Reply_UpDatetime", SqlDbType.DateTime),
					new SqlParameter("@Reply_Verify", SqlDbType.Int,4),
					new SqlParameter("@Reply_Lock", SqlDbType.Int,4),
					new SqlParameter("@Reply_State", SqlDbType.Int,4),
					new SqlParameter("@Reply_Delete", SqlDbType.Int,4),
					new SqlParameter("@Reply_Count", SqlDbType.Int,4),
					new SqlParameter("@Reply_Order", SqlDbType.Int,4),
					new SqlParameter("@Reply_Remark", SqlDbType.NText)};
			parameters[0].Value = model.Reply_UserID;
			parameters[1].Value = model.Reply_Content;
			parameters[2].Value = model.Reply_ArticleID;
			parameters[3].Value = model.Reply_Type;
			parameters[4].Value = model.Reply_Guid;
			parameters[5].Value = model.Reply_Datetime;
			parameters[6].Value = model.Reply_UpDatetime;
			parameters[7].Value = model.Reply_Verify;
			parameters[8].Value = model.Reply_Lock;
			parameters[9].Value = model.Reply_State;
			parameters[10].Value = model.Reply_Delete;
			parameters[11].Value = model.Reply_Count;
			parameters[12].Value = model.Reply_Order;
			parameters[13].Value = model.Reply_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_Reply model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update Dd_Reply set ");
			strSql.Append("Reply_UserID=@Reply_UserID,");
			strSql.Append("Reply_Content=@Reply_Content,");
			strSql.Append("Reply_ArticleID=@Reply_ArticleID,");
			strSql.Append("Reply_Type=@Reply_Type,");
			strSql.Append("Reply_Guid=@Reply_Guid,");
			strSql.Append("Reply_Datetime=@Reply_Datetime,");
			strSql.Append("Reply_UpDatetime=@Reply_UpDatetime,");
			strSql.Append("Reply_Verify=@Reply_Verify,");
			strSql.Append("Reply_Lock=@Reply_Lock,");
			strSql.Append("Reply_State=@Reply_State,");
			strSql.Append("Reply_Delete=@Reply_Delete,");
			strSql.Append("Reply_Count=@Reply_Count,");
			strSql.Append("Reply_Order=@Reply_Order,");
			strSql.Append("Reply_Remark=@Reply_Remark");
			strSql.Append(" where Reply_ID=@Reply_ID");
			SqlParameter[] parameters = {
					new SqlParameter("@Reply_UserID", SqlDbType.Int,4),
					new SqlParameter("@Reply_Content", SqlDbType.NVarChar,200),
					new SqlParameter("@Reply_ArticleID", SqlDbType.Char,12),
					new SqlParameter("@Reply_Type", SqlDbType.Int,4),
					new SqlParameter("@Reply_Guid", SqlDbType.NChar,36),
					new SqlParameter("@Reply_Datetime", SqlDbType.DateTime),
					new SqlParameter("@Reply_UpDatetime", SqlDbType.DateTime),
					new SqlParameter("@Reply_Verify", SqlDbType.Int,4),
					new SqlParameter("@Reply_Lock", SqlDbType.Int,4),
					new SqlParameter("@Reply_State", SqlDbType.Int,4),
					new SqlParameter("@Reply_Delete", SqlDbType.Int,4),
					new SqlParameter("@Reply_Count", SqlDbType.Int,4),
					new SqlParameter("@Reply_Order", SqlDbType.Int,4),
					new SqlParameter("@Reply_Remark", SqlDbType.NText),
					new SqlParameter("@Reply_ID", SqlDbType.Int,4)};
			parameters[0].Value = model.Reply_UserID;
			parameters[1].Value = model.Reply_Content;
			parameters[2].Value = model.Reply_ArticleID;
			parameters[3].Value = model.Reply_Type;
			parameters[4].Value = model.Reply_Guid;
			parameters[5].Value = model.Reply_Datetime;
			parameters[6].Value = model.Reply_UpDatetime;
			parameters[7].Value = model.Reply_Verify;
			parameters[8].Value = model.Reply_Lock;
			parameters[9].Value = model.Reply_State;
			parameters[10].Value = model.Reply_Delete;
			parameters[11].Value = model.Reply_Count;
			parameters[12].Value = model.Reply_Order;
			parameters[13].Value = model.Reply_Remark;
			parameters[14].Value = model.Reply_ID;

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

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

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


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public HaTeam.Dd.Model.Dd_Reply GetModel(int Reply_ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 Reply_ID,Reply_UserID,Reply_Content,Reply_ArticleID,Reply_Type,Reply_Guid,Reply_Datetime,Reply_UpDatetime,Reply_Verify,Reply_Lock,Reply_State,Reply_Delete,Reply_Count,Reply_Order,Reply_Remark from Dd_Reply ");
			strSql.Append(" where Reply_ID=@Reply_ID");
			SqlParameter[] parameters = {
					new SqlParameter("@Reply_ID", SqlDbType.Int,4)
};
			parameters[0].Value = Reply_ID;

			HaTeam.Dd.Model.Dd_Reply model=new HaTeam.Dd.Model.Dd_Reply();
			DataSet ds=DbHelperSQL.GetDataSet(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["Reply_ID"].ToString()!="")
				{
					model.Reply_ID=int.Parse(ds.Tables[0].Rows[0]["Reply_ID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Reply_UserID"].ToString()!="")
				{
					model.Reply_UserID=int.Parse(ds.Tables[0].Rows[0]["Reply_UserID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Reply_Content"]!=null)
				{
				model.Reply_Content=ds.Tables[0].Rows[0]["Reply_Content"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Reply_ArticleID"]!=null)
				{
				model.Reply_ArticleID=ds.Tables[0].Rows[0]["Reply_ArticleID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Reply_Type"].ToString()!="")
				{
					model.Reply_Type=int.Parse(ds.Tables[0].Rows[0]["Reply_Type"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Reply_Guid"]!=null)
				{
				model.Reply_Guid=ds.Tables[0].Rows[0]["Reply_Guid"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Reply_Datetime"].ToString()!="")
				{
					model.Reply_Datetime=DateTime.Parse(ds.Tables[0].Rows[0]["Reply_Datetime"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Reply_UpDatetime"].ToString()!="")
				{
					model.Reply_UpDatetime=DateTime.Parse(ds.Tables[0].Rows[0]["Reply_UpDatetime"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Reply_Verify"].ToString()!="")
				{
					model.Reply_Verify=int.Parse(ds.Tables[0].Rows[0]["Reply_Verify"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Reply_Lock"].ToString()!="")
				{
					model.Reply_Lock=int.Parse(ds.Tables[0].Rows[0]["Reply_Lock"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Reply_State"].ToString()!="")
				{
					model.Reply_State=int.Parse(ds.Tables[0].Rows[0]["Reply_State"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Reply_Delete"].ToString()!="")
				{
					model.Reply_Delete=int.Parse(ds.Tables[0].Rows[0]["Reply_Delete"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Reply_Count"].ToString()!="")
				{
					model.Reply_Count=int.Parse(ds.Tables[0].Rows[0]["Reply_Count"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Reply_Order"].ToString()!="")
				{
					model.Reply_Order=int.Parse(ds.Tables[0].Rows[0]["Reply_Order"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Reply_Remark"]!=null)
				{
				model.Reply_Remark=ds.Tables[0].Rows[0]["Reply_Remark"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select Reply_ID,Reply_UserID,Reply_Content,Reply_ArticleID,Reply_Type,Reply_Guid,Reply_Datetime,Reply_UpDatetime,Reply_Verify,Reply_Lock,Reply_State,Reply_Delete,Reply_Count,Reply_Order,Reply_Remark ");
			strSql.Append(" FROM Dd_Reply ");
			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(" Reply_ID,Reply_UserID,Reply_Content,Reply_ArticleID,Reply_Type,Reply_Guid,Reply_Datetime,Reply_UpDatetime,Reply_Verify,Reply_Lock,Reply_State,Reply_Delete,Reply_Count,Reply_Order,Reply_Remark ");
			strSql.Append(" FROM Dd_Reply ");
			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_Reply";
			parameters[1].Value = "Reply_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
	}
}

