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

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

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

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


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(HaTeam.Dd.Model.Dd_Attention model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into Dd_Attention(");
			strSql.Append("Attention_UerID,Attented_By_user,Attention_BlackList,Attention_Guid,Attention_Datetime,Attention_UpDatetime,Attention_Verify,Attention_Lock,Attention_State,Attention_Delete,Attention_Count,Attention_Order,Attention_Remark)");
			strSql.Append(" values (");
			strSql.Append("@Attention_UerID,@Attented_By_user,@Attention_BlackList,@Attention_Guid,@Attention_Datetime,@Attention_UpDatetime,@Attention_Verify,@Attention_Lock,@Attention_State,@Attention_Delete,@Attention_Count,@Attention_Order,@Attention_Remark)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@Attention_UerID", SqlDbType.Int,4),
					new SqlParameter("@Attented_By_user", SqlDbType.Int,4),
					new SqlParameter("@Attention_BlackList", SqlDbType.Int,4),
					new SqlParameter("@Attention_Guid", SqlDbType.NChar,36),
					new SqlParameter("@Attention_Datetime", SqlDbType.DateTime),
					new SqlParameter("@Attention_UpDatetime", SqlDbType.DateTime),
					new SqlParameter("@Attention_Verify", SqlDbType.Int,4),
					new SqlParameter("@Attention_Lock", SqlDbType.Int,4),
					new SqlParameter("@Attention_State", SqlDbType.Int,4),
					new SqlParameter("@Attention_Delete", SqlDbType.Int,4),
					new SqlParameter("@Attention_Count", SqlDbType.Int,4),
					new SqlParameter("@Attention_Order", SqlDbType.Int,4),
					new SqlParameter("@Attention_Remark", SqlDbType.NText)};
			parameters[0].Value = model.Attention_UerID;
			parameters[1].Value = model.Attented_By_user;
			parameters[2].Value = model.Attention_BlackList;
			parameters[3].Value = model.Attention_Guid;
			parameters[4].Value = model.Attention_Datetime;
			parameters[5].Value = model.Attention_UpDatetime;
			parameters[6].Value = model.Attention_Verify;
			parameters[7].Value = model.Attention_Lock;
			parameters[8].Value = model.Attention_State;
			parameters[9].Value = model.Attention_Delete;
			parameters[10].Value = model.Attention_Count;
			parameters[11].Value = model.Attention_Order;
			parameters[12].Value = model.Attention_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_Attention model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update Dd_Attention set ");
			strSql.Append("Attention_UerID=@Attention_UerID,");
			strSql.Append("Attented_By_user=@Attented_By_user,");
			strSql.Append("Attention_BlackList=@Attention_BlackList,");
			strSql.Append("Attention_Guid=@Attention_Guid,");
			strSql.Append("Attention_Datetime=@Attention_Datetime,");
			strSql.Append("Attention_UpDatetime=@Attention_UpDatetime,");
			strSql.Append("Attention_Verify=@Attention_Verify,");
			strSql.Append("Attention_Lock=@Attention_Lock,");
			strSql.Append("Attention_State=@Attention_State,");
			strSql.Append("Attention_Delete=@Attention_Delete,");
			strSql.Append("Attention_Count=@Attention_Count,");
			strSql.Append("Attention_Order=@Attention_Order,");
			strSql.Append("Attention_Remark=@Attention_Remark");
			strSql.Append(" where Attention_ID=@Attention_ID");
			SqlParameter[] parameters = {
					new SqlParameter("@Attention_UerID", SqlDbType.Int,4),
					new SqlParameter("@Attented_By_user", SqlDbType.Int,4),
					new SqlParameter("@Attention_BlackList", SqlDbType.Int,4),
					new SqlParameter("@Attention_Guid", SqlDbType.NChar,36),
					new SqlParameter("@Attention_Datetime", SqlDbType.DateTime),
					new SqlParameter("@Attention_UpDatetime", SqlDbType.DateTime),
					new SqlParameter("@Attention_Verify", SqlDbType.Int,4),
					new SqlParameter("@Attention_Lock", SqlDbType.Int,4),
					new SqlParameter("@Attention_State", SqlDbType.Int,4),
					new SqlParameter("@Attention_Delete", SqlDbType.Int,4),
					new SqlParameter("@Attention_Count", SqlDbType.Int,4),
					new SqlParameter("@Attention_Order", SqlDbType.Int,4),
					new SqlParameter("@Attention_Remark", SqlDbType.NText),
					new SqlParameter("@Attention_ID", SqlDbType.Int,4)};
			parameters[0].Value = model.Attention_UerID;
			parameters[1].Value = model.Attented_By_user;
			parameters[2].Value = model.Attention_BlackList;
			parameters[3].Value = model.Attention_Guid;
			parameters[4].Value = model.Attention_Datetime;
			parameters[5].Value = model.Attention_UpDatetime;
			parameters[6].Value = model.Attention_Verify;
			parameters[7].Value = model.Attention_Lock;
			parameters[8].Value = model.Attention_State;
			parameters[9].Value = model.Attention_Delete;
			parameters[10].Value = model.Attention_Count;
			parameters[11].Value = model.Attention_Order;
			parameters[12].Value = model.Attention_Remark;
			parameters[13].Value = model.Attention_ID;

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

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

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


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public HaTeam.Dd.Model.Dd_Attention GetModel(int Attention_ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 Attention_ID,Attention_UerID,Attented_By_user,Attention_BlackList,Attention_Guid,Attention_Datetime,Attention_UpDatetime,Attention_Verify,Attention_Lock,Attention_State,Attention_Delete,Attention_Count,Attention_Order,Attention_Remark from Dd_Attention ");
			strSql.Append(" where Attention_ID=@Attention_ID");
			SqlParameter[] parameters = {
					new SqlParameter("@Attention_ID", SqlDbType.Int,4)
};
			parameters[0].Value = Attention_ID;

			HaTeam.Dd.Model.Dd_Attention model=new HaTeam.Dd.Model.Dd_Attention();
            DataSet ds = DbHelperSQL.GetDataSet(strSql.ToString(), parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["Attention_ID"].ToString()!="")
				{
					model.Attention_ID=int.Parse(ds.Tables[0].Rows[0]["Attention_ID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Attention_UerID"].ToString()!="")
				{
					model.Attention_UerID=int.Parse(ds.Tables[0].Rows[0]["Attention_UerID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Attented_By_user"].ToString()!="")
				{
					model.Attented_By_user=int.Parse(ds.Tables[0].Rows[0]["Attented_By_user"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Attention_BlackList"].ToString()!="")
				{
					model.Attention_BlackList=int.Parse(ds.Tables[0].Rows[0]["Attention_BlackList"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Attention_Guid"]!=null)
				{
				model.Attention_Guid=ds.Tables[0].Rows[0]["Attention_Guid"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Attention_Datetime"].ToString()!="")
				{
					model.Attention_Datetime=DateTime.Parse(ds.Tables[0].Rows[0]["Attention_Datetime"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Attention_UpDatetime"].ToString()!="")
				{
					model.Attention_UpDatetime=DateTime.Parse(ds.Tables[0].Rows[0]["Attention_UpDatetime"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Attention_Verify"].ToString()!="")
				{
					model.Attention_Verify=int.Parse(ds.Tables[0].Rows[0]["Attention_Verify"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Attention_Lock"].ToString()!="")
				{
					model.Attention_Lock=int.Parse(ds.Tables[0].Rows[0]["Attention_Lock"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Attention_State"].ToString()!="")
				{
					model.Attention_State=int.Parse(ds.Tables[0].Rows[0]["Attention_State"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Attention_Delete"].ToString()!="")
				{
					model.Attention_Delete=int.Parse(ds.Tables[0].Rows[0]["Attention_Delete"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Attention_Count"].ToString()!="")
				{
					model.Attention_Count=int.Parse(ds.Tables[0].Rows[0]["Attention_Count"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Attention_Order"].ToString()!="")
				{
					model.Attention_Order=int.Parse(ds.Tables[0].Rows[0]["Attention_Order"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Attention_Remark"]!=null)
				{
				model.Attention_Remark=ds.Tables[0].Rows[0]["Attention_Remark"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select Attention_ID,Attention_UerID,Attented_By_user,Attention_BlackList,Attention_Guid,Attention_Datetime,Attention_UpDatetime,Attention_Verify,Attention_Lock,Attention_State,Attention_Delete,Attention_Count,Attention_Order,Attention_Remark ");
			strSql.Append(" FROM Dd_Attention ");
			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(" Attention_ID,Attention_UerID,Attented_By_user,Attention_BlackList,Attention_Guid,Attention_Datetime,Attention_UpDatetime,Attention_Verify,Attention_Lock,Attention_State,Attention_Delete,Attention_Count,Attention_Order,Attention_Remark ");
			strSql.Append(" FROM Dd_Attention ");
			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_Attention";
			parameters[1].Value = "Attention_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
	}
}

