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

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

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

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


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(HaTeam.Dd.Model.Dd_User model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into Dd_User(");
			strSql.Append("User_BlogName,User_Email,User_OriginPsw,User_Passwd,User_Attetion,User_ActivCondition,User_HeadPhoto,User_BlackList,User_LikeArticle,User_Guid,User_Datetime,User_UpDatetime,User_Verify,User_Lock,User_State,User_Delete,User_Count,User_Order,User_Remark)");
			strSql.Append(" values (");
			strSql.Append("@User_BlogName,@User_Email,@User_OriginPsw,@User_Passwd,@User_Attetion,@User_ActivCondition,@User_HeadPhoto,@User_BlackList,@User_LikeArticle,@User_Guid,@User_Datetime,@User_UpDatetime,@User_Verify,@User_Lock,@User_State,@User_Delete,@User_Count,@User_Order,@User_Remark)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@User_BlogName", SqlDbType.NVarChar,50),
					new SqlParameter("@User_Email", SqlDbType.NVarChar,50),
					new SqlParameter("@User_OriginPsw", SqlDbType.NVarChar,50),
					new SqlParameter("@User_Passwd", SqlDbType.NVarChar,50),
					new SqlParameter("@User_Attetion", SqlDbType.NVarChar,1000),
					new SqlParameter("@User_ActivCondition", SqlDbType.Int,4),
					new SqlParameter("@User_HeadPhoto", SqlDbType.NVarChar,100),
					new SqlParameter("@User_BlackList", SqlDbType.NVarChar,1000),
					new SqlParameter("@User_LikeArticle", SqlDbType.NVarChar,1000),
					new SqlParameter("@User_Guid", SqlDbType.NChar,36),
					new SqlParameter("@User_Datetime", SqlDbType.DateTime),
					new SqlParameter("@User_UpDatetime", SqlDbType.DateTime),
					new SqlParameter("@User_Verify", SqlDbType.Int,4),
					new SqlParameter("@User_Lock", SqlDbType.Int,4),
					new SqlParameter("@User_State", SqlDbType.Int,4),
					new SqlParameter("@User_Delete", SqlDbType.Int,4),
					new SqlParameter("@User_Count", SqlDbType.Int,4),
					new SqlParameter("@User_Order", SqlDbType.Int,4),
					new SqlParameter("@User_Remark", SqlDbType.NText)};
			parameters[0].Value = model.User_BlogName;
			parameters[1].Value = model.User_Email;
			parameters[2].Value = model.User_OriginPsw;
			parameters[3].Value = model.User_Passwd;
			parameters[4].Value = model.User_Attetion;
			parameters[5].Value = model.User_ActivCondition;
			parameters[6].Value = model.User_HeadPhoto;
			parameters[7].Value = model.User_BlackList;
			parameters[8].Value = model.User_LikeArticle;
			parameters[9].Value = model.User_Guid;
			parameters[10].Value = model.User_Datetime;
			parameters[11].Value = model.User_UpDatetime;
			parameters[12].Value = model.User_Verify;
			parameters[13].Value = model.User_Lock;
			parameters[14].Value = model.User_State;
			parameters[15].Value = model.User_Delete;
			parameters[16].Value = model.User_Count;
			parameters[17].Value = model.User_Order;
			parameters[18].Value = model.User_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_User model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update Dd_User set ");
			strSql.Append("User_BlogName=@User_BlogName,");
			strSql.Append("User_Email=@User_Email,");
			strSql.Append("User_OriginPsw=@User_OriginPsw,");
			strSql.Append("User_Passwd=@User_Passwd,");
			strSql.Append("User_Attetion=@User_Attetion,");
			strSql.Append("User_ActivCondition=@User_ActivCondition,");
			strSql.Append("User_HeadPhoto=@User_HeadPhoto,");
			strSql.Append("User_BlackList=@User_BlackList,");
			strSql.Append("User_LikeArticle=@User_LikeArticle,");
			strSql.Append("User_Guid=@User_Guid,");
			strSql.Append("User_Datetime=@User_Datetime,");
			strSql.Append("User_UpDatetime=@User_UpDatetime,");
			strSql.Append("User_Verify=@User_Verify,");
			strSql.Append("User_Lock=@User_Lock,");
			strSql.Append("User_State=@User_State,");
			strSql.Append("User_Delete=@User_Delete,");
			strSql.Append("User_Count=@User_Count,");
			strSql.Append("User_Order=@User_Order,");
			strSql.Append("User_Remark=@User_Remark");
			strSql.Append(" where User_ID=@User_ID");
			SqlParameter[] parameters = {
					new SqlParameter("@User_BlogName", SqlDbType.NVarChar,50),
					new SqlParameter("@User_Email", SqlDbType.NVarChar,50),
					new SqlParameter("@User_OriginPsw", SqlDbType.NVarChar,50),
					new SqlParameter("@User_Passwd", SqlDbType.NVarChar,50),
					new SqlParameter("@User_Attetion", SqlDbType.NVarChar,1000),
					new SqlParameter("@User_ActivCondition", SqlDbType.Int,4),
					new SqlParameter("@User_HeadPhoto", SqlDbType.NVarChar,100),
					new SqlParameter("@User_BlackList", SqlDbType.NVarChar,1000),
					new SqlParameter("@User_LikeArticle", SqlDbType.NVarChar,1000),
					new SqlParameter("@User_Guid", SqlDbType.NChar,36),
					new SqlParameter("@User_Datetime", SqlDbType.DateTime),
					new SqlParameter("@User_UpDatetime", SqlDbType.DateTime),
					new SqlParameter("@User_Verify", SqlDbType.Int,4),
					new SqlParameter("@User_Lock", SqlDbType.Int,4),
					new SqlParameter("@User_State", SqlDbType.Int,4),
					new SqlParameter("@User_Delete", SqlDbType.Int,4),
					new SqlParameter("@User_Count", SqlDbType.Int,4),
					new SqlParameter("@User_Order", SqlDbType.Int,4),
					new SqlParameter("@User_Remark", SqlDbType.NText),
					new SqlParameter("@User_ID", SqlDbType.Int,4)};
			parameters[0].Value = model.User_BlogName;
			parameters[1].Value = model.User_Email;
			parameters[2].Value = model.User_OriginPsw;
			parameters[3].Value = model.User_Passwd;
			parameters[4].Value = model.User_Attetion;
			parameters[5].Value = model.User_ActivCondition;
			parameters[6].Value = model.User_HeadPhoto;
			parameters[7].Value = model.User_BlackList;
			parameters[8].Value = model.User_LikeArticle;
			parameters[9].Value = model.User_Guid;
			parameters[10].Value = model.User_Datetime;
			parameters[11].Value = model.User_UpDatetime;
			parameters[12].Value = model.User_Verify;
			parameters[13].Value = model.User_Lock;
			parameters[14].Value = model.User_State;
			parameters[15].Value = model.User_Delete;
			parameters[16].Value = model.User_Count;
			parameters[17].Value = model.User_Order;
			parameters[18].Value = model.User_Remark;
			parameters[19].Value = model.User_ID;

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

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

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


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public HaTeam.Dd.Model.Dd_User GetModel(int User_ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 User_ID,User_BlogName,User_Email,User_OriginPsw,User_Passwd,User_Attetion,User_ActivCondition,User_HeadPhoto,User_BlackList,User_LikeArticle,User_Guid,User_Datetime,User_UpDatetime,User_Verify,User_Lock,User_State,User_Delete,User_Count,User_Order,User_Remark from Dd_User ");
			strSql.Append(" where User_ID=@User_ID");
			SqlParameter[] parameters = {
					new SqlParameter("@User_ID", SqlDbType.Int,4)
};
			parameters[0].Value = User_ID;

			HaTeam.Dd.Model.Dd_User model=new HaTeam.Dd.Model.Dd_User();
            DataSet ds = DbHelperSQL.GetDataSet(strSql.ToString(), parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["User_ID"].ToString()!="")
				{
					model.User_ID=int.Parse(ds.Tables[0].Rows[0]["User_ID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["User_BlogName"]!=null)
				{
				model.User_BlogName=ds.Tables[0].Rows[0]["User_BlogName"].ToString();
				}
				if(ds.Tables[0].Rows[0]["User_Email"]!=null)
				{
				model.User_Email=ds.Tables[0].Rows[0]["User_Email"].ToString();
				}
				if(ds.Tables[0].Rows[0]["User_OriginPsw"]!=null)
				{
				model.User_OriginPsw=ds.Tables[0].Rows[0]["User_OriginPsw"].ToString();
				}
				if(ds.Tables[0].Rows[0]["User_Passwd"]!=null)
				{
				model.User_Passwd=ds.Tables[0].Rows[0]["User_Passwd"].ToString();
				}
				if(ds.Tables[0].Rows[0]["User_Attetion"]!=null)
				{
				model.User_Attetion=ds.Tables[0].Rows[0]["User_Attetion"].ToString();
				}
				if(ds.Tables[0].Rows[0]["User_ActivCondition"].ToString()!="")
				{
					model.User_ActivCondition=int.Parse(ds.Tables[0].Rows[0]["User_ActivCondition"].ToString());
				}
				if(ds.Tables[0].Rows[0]["User_HeadPhoto"]!=null)
				{
				model.User_HeadPhoto=ds.Tables[0].Rows[0]["User_HeadPhoto"].ToString();
				}
				if(ds.Tables[0].Rows[0]["User_BlackList"]!=null)
				{
				model.User_BlackList=ds.Tables[0].Rows[0]["User_BlackList"].ToString();
				}
				if(ds.Tables[0].Rows[0]["User_LikeArticle"]!=null)
				{
				model.User_LikeArticle=ds.Tables[0].Rows[0]["User_LikeArticle"].ToString();
				}
				if(ds.Tables[0].Rows[0]["User_Guid"]!=null)
				{
				model.User_Guid=ds.Tables[0].Rows[0]["User_Guid"].ToString();
				}
				if(ds.Tables[0].Rows[0]["User_Datetime"].ToString()!="")
				{
					model.User_Datetime=DateTime.Parse(ds.Tables[0].Rows[0]["User_Datetime"].ToString());
				}
				if(ds.Tables[0].Rows[0]["User_UpDatetime"].ToString()!="")
				{
					model.User_UpDatetime=DateTime.Parse(ds.Tables[0].Rows[0]["User_UpDatetime"].ToString());
				}
				if(ds.Tables[0].Rows[0]["User_Verify"].ToString()!="")
				{
					model.User_Verify=int.Parse(ds.Tables[0].Rows[0]["User_Verify"].ToString());
				}
				if(ds.Tables[0].Rows[0]["User_Lock"].ToString()!="")
				{
					model.User_Lock=int.Parse(ds.Tables[0].Rows[0]["User_Lock"].ToString());
				}
				if(ds.Tables[0].Rows[0]["User_State"].ToString()!="")
				{
					model.User_State=int.Parse(ds.Tables[0].Rows[0]["User_State"].ToString());
				}
				if(ds.Tables[0].Rows[0]["User_Delete"].ToString()!="")
				{
					model.User_Delete=int.Parse(ds.Tables[0].Rows[0]["User_Delete"].ToString());
				}
				if(ds.Tables[0].Rows[0]["User_Count"].ToString()!="")
				{
					model.User_Count=int.Parse(ds.Tables[0].Rows[0]["User_Count"].ToString());
				}
				if(ds.Tables[0].Rows[0]["User_Order"].ToString()!="")
				{
					model.User_Order=int.Parse(ds.Tables[0].Rows[0]["User_Order"].ToString());
				}
				if(ds.Tables[0].Rows[0]["User_Remark"]!=null)
				{
				model.User_Remark=ds.Tables[0].Rows[0]["User_Remark"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select User_ID,User_BlogName,User_Email,User_OriginPsw,User_Passwd,User_Attetion,User_ActivCondition,User_HeadPhoto,User_BlackList,User_LikeArticle,User_Guid,User_Datetime,User_UpDatetime,User_Verify,User_Lock,User_State,User_Delete,User_Count,User_Order,User_Remark ");
			strSql.Append(" FROM Dd_User ");
			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(" User_ID,User_BlogName,User_Email,User_OriginPsw,User_Passwd,User_Attetion,User_ActivCondition,User_HeadPhoto,User_BlackList,User_LikeArticle,User_Guid,User_Datetime,User_UpDatetime,User_Verify,User_Lock,User_State,User_Delete,User_Count,User_Order,User_Remark ");
			strSql.Append(" FROM Dd_User ");
			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_User";
			parameters[1].Value = "User_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
	}
}

