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

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

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

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


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(HaTeam.Dd.Model.Dd_Link model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into Dd_Link(");
			strSql.Append("User_ID,Link_Title,Link_Address,Link_Description,Link_Tag,Link_OriginId,Link_PublishMode,Link_PutTop,Link_Fever,Link_Guid,Link_Datetime,Link_UpDatetime,Link_Verify,Link_Lock,Link_State,Link_Delete,Link_Count,Link_Order,Link_Remark)");
			strSql.Append(" values (");
			strSql.Append("@User_ID,@Link_Title,@Link_Address,@Link_Description,@Link_Tag,@Link_OriginId,@Link_PublishMode,@Link_PutTop,@Link_Fever,@Link_Guid,@Link_Datetime,@Link_UpDatetime,@Link_Verify,@Link_Lock,@Link_State,@Link_Delete,@Link_Count,@Link_Order,@Link_Remark)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@User_ID", SqlDbType.Int,4),
					new SqlParameter("@Link_Title", SqlDbType.NVarChar,30),
					new SqlParameter("@Link_Address", SqlDbType.NVarChar,100),
					new SqlParameter("@Link_Description", SqlDbType.NVarChar,1000),
					new SqlParameter("@Link_Tag", SqlDbType.VarChar,100),
					new SqlParameter("@Link_OriginId", SqlDbType.Int,4),
					new SqlParameter("@Link_PublishMode", SqlDbType.Int,4),
					new SqlParameter("@Link_PutTop", SqlDbType.Bit,1),
					new SqlParameter("@Link_Fever", SqlDbType.Int,4),
					new SqlParameter("@Link_Guid", SqlDbType.NChar,36),
					new SqlParameter("@Link_Datetime", SqlDbType.DateTime),
					new SqlParameter("@Link_UpDatetime", SqlDbType.DateTime),
					new SqlParameter("@Link_Verify", SqlDbType.Int,4),
					new SqlParameter("@Link_Lock", SqlDbType.Int,4),
					new SqlParameter("@Link_State", SqlDbType.Int,4),
					new SqlParameter("@Link_Delete", SqlDbType.Int,4),
					new SqlParameter("@Link_Count", SqlDbType.Int,4),
					new SqlParameter("@Link_Order", SqlDbType.Int,4),
					new SqlParameter("@Link_Remark", SqlDbType.NText)};
			parameters[0].Value = model.User_ID;
			parameters[1].Value = model.Link_Title;
			parameters[2].Value = model.Link_Address;
			parameters[3].Value = model.Link_Description;
			parameters[4].Value = model.Link_Tag;
			parameters[5].Value = model.Link_OriginId;
			parameters[6].Value = model.Link_PublishMode;
			parameters[7].Value = model.Link_PutTop;
			parameters[8].Value = model.Link_Fever;
			parameters[9].Value = model.Link_Guid;
			parameters[10].Value = model.Link_Datetime;
			parameters[11].Value = model.Link_UpDatetime;
			parameters[12].Value = model.Link_Verify;
			parameters[13].Value = model.Link_Lock;
			parameters[14].Value = model.Link_State;
			parameters[15].Value = model.Link_Delete;
			parameters[16].Value = model.Link_Count;
			parameters[17].Value = model.Link_Order;
			parameters[18].Value = model.Link_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_Link model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update Dd_Link set ");
			strSql.Append("User_ID=@User_ID,");
			strSql.Append("Link_Title=@Link_Title,");
			strSql.Append("Link_Address=@Link_Address,");
			strSql.Append("Link_Description=@Link_Description,");
			strSql.Append("Link_Tag=@Link_Tag,");
			strSql.Append("Link_OriginId=@Link_OriginId,");
			strSql.Append("Link_PublishMode=@Link_PublishMode,");
			strSql.Append("Link_PutTop=@Link_PutTop,");
			strSql.Append("Link_Fever=@Link_Fever,");
			strSql.Append("Link_Guid=@Link_Guid,");
			strSql.Append("Link_Datetime=@Link_Datetime,");
			strSql.Append("Link_UpDatetime=@Link_UpDatetime,");
			strSql.Append("Link_Verify=@Link_Verify,");
			strSql.Append("Link_Lock=@Link_Lock,");
			strSql.Append("Link_State=@Link_State,");
			strSql.Append("Link_Delete=@Link_Delete,");
			strSql.Append("Link_Count=@Link_Count,");
			strSql.Append("Link_Order=@Link_Order,");
			strSql.Append("Link_Remark=@Link_Remark");
			strSql.Append(" where Link_ID=@Link_ID");
			SqlParameter[] parameters = {
					new SqlParameter("@User_ID", SqlDbType.Int,4),
					new SqlParameter("@Link_Title", SqlDbType.NVarChar,30),
					new SqlParameter("@Link_Address", SqlDbType.NVarChar,100),
					new SqlParameter("@Link_Description", SqlDbType.NVarChar,1000),
					new SqlParameter("@Link_Tag", SqlDbType.VarChar,100),
					new SqlParameter("@Link_OriginId", SqlDbType.Int,4),
					new SqlParameter("@Link_PublishMode", SqlDbType.Int,4),
					new SqlParameter("@Link_PutTop", SqlDbType.Bit,1),
					new SqlParameter("@Link_Fever", SqlDbType.Int,4),
					new SqlParameter("@Link_Guid", SqlDbType.NChar,36),
					new SqlParameter("@Link_Datetime", SqlDbType.DateTime),
					new SqlParameter("@Link_UpDatetime", SqlDbType.DateTime),
					new SqlParameter("@Link_Verify", SqlDbType.Int,4),
					new SqlParameter("@Link_Lock", SqlDbType.Int,4),
					new SqlParameter("@Link_State", SqlDbType.Int,4),
					new SqlParameter("@Link_Delete", SqlDbType.Int,4),
					new SqlParameter("@Link_Count", SqlDbType.Int,4),
					new SqlParameter("@Link_Order", SqlDbType.Int,4),
					new SqlParameter("@Link_Remark", SqlDbType.NText),
					new SqlParameter("@Link_ID", SqlDbType.Int,4)};
			parameters[0].Value = model.User_ID;
			parameters[1].Value = model.Link_Title;
			parameters[2].Value = model.Link_Address;
			parameters[3].Value = model.Link_Description;
			parameters[4].Value = model.Link_Tag;
			parameters[5].Value = model.Link_OriginId;
			parameters[6].Value = model.Link_PublishMode;
			parameters[7].Value = model.Link_PutTop;
			parameters[8].Value = model.Link_Fever;
			parameters[9].Value = model.Link_Guid;
			parameters[10].Value = model.Link_Datetime;
			parameters[11].Value = model.Link_UpDatetime;
			parameters[12].Value = model.Link_Verify;
			parameters[13].Value = model.Link_Lock;
			parameters[14].Value = model.Link_State;
			parameters[15].Value = model.Link_Delete;
			parameters[16].Value = model.Link_Count;
			parameters[17].Value = model.Link_Order;
			parameters[18].Value = model.Link_Remark;
			parameters[19].Value = model.Link_ID;

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

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

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


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public HaTeam.Dd.Model.Dd_Link GetModel(int Link_ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 Link_ID,User_ID,Link_Title,Link_Address,Link_Description,Link_Tag,Link_OriginId,Link_PublishMode,Link_PutTop,Link_Fever,Link_Guid,Link_Datetime,Link_UpDatetime,Link_Verify,Link_Lock,Link_State,Link_Delete,Link_Count,Link_Order,Link_Remark from Dd_Link ");
			strSql.Append(" where Link_ID=@Link_ID");
			SqlParameter[] parameters = {
					new SqlParameter("@Link_ID", SqlDbType.Int,4)
};
			parameters[0].Value = Link_ID;

			HaTeam.Dd.Model.Dd_Link model=new HaTeam.Dd.Model.Dd_Link();
			DataSet ds=DbHelperSQL.GetDataSet(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["Link_ID"].ToString()!="")
				{
					model.Link_ID=int.Parse(ds.Tables[0].Rows[0]["Link_ID"].ToString());
				}
				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]["Link_Title"]!=null)
				{
				model.Link_Title=ds.Tables[0].Rows[0]["Link_Title"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Link_Address"]!=null)
				{
				model.Link_Address=ds.Tables[0].Rows[0]["Link_Address"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Link_Description"]!=null)
				{
				model.Link_Description=ds.Tables[0].Rows[0]["Link_Description"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Link_Tag"]!=null)
				{
				model.Link_Tag=ds.Tables[0].Rows[0]["Link_Tag"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Link_OriginId"].ToString()!="")
				{
					model.Link_OriginId=int.Parse(ds.Tables[0].Rows[0]["Link_OriginId"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Link_PublishMode"].ToString()!="")
				{
					model.Link_PublishMode=int.Parse(ds.Tables[0].Rows[0]["Link_PublishMode"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Link_PutTop"].ToString()!="")
				{
					if((ds.Tables[0].Rows[0]["Link_PutTop"].ToString()=="1")||(ds.Tables[0].Rows[0]["Link_PutTop"].ToString().ToLower()=="true"))
					{
						model.Link_PutTop=true;
					}
					else
					{
						model.Link_PutTop=false;
					}
				}
				if(ds.Tables[0].Rows[0]["Link_Fever"].ToString()!="")
				{
					model.Link_Fever=int.Parse(ds.Tables[0].Rows[0]["Link_Fever"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Link_Guid"]!=null)
				{
				model.Link_Guid=ds.Tables[0].Rows[0]["Link_Guid"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Link_Datetime"].ToString()!="")
				{
					model.Link_Datetime=DateTime.Parse(ds.Tables[0].Rows[0]["Link_Datetime"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Link_UpDatetime"].ToString()!="")
				{
					model.Link_UpDatetime=DateTime.Parse(ds.Tables[0].Rows[0]["Link_UpDatetime"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Link_Verify"].ToString()!="")
				{
					model.Link_Verify=int.Parse(ds.Tables[0].Rows[0]["Link_Verify"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Link_Lock"].ToString()!="")
				{
					model.Link_Lock=int.Parse(ds.Tables[0].Rows[0]["Link_Lock"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Link_State"].ToString()!="")
				{
					model.Link_State=int.Parse(ds.Tables[0].Rows[0]["Link_State"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Link_Delete"].ToString()!="")
				{
					model.Link_Delete=int.Parse(ds.Tables[0].Rows[0]["Link_Delete"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Link_Count"].ToString()!="")
				{
					model.Link_Count=int.Parse(ds.Tables[0].Rows[0]["Link_Count"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Link_Order"].ToString()!="")
				{
					model.Link_Order=int.Parse(ds.Tables[0].Rows[0]["Link_Order"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Link_Remark"]!=null)
				{
				model.Link_Remark=ds.Tables[0].Rows[0]["Link_Remark"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select Link_ID,User_ID,Link_Title,Link_Address,Link_Description,Link_Tag,Link_OriginId,Link_PublishMode,Link_PutTop,Link_Fever,Link_Guid,Link_Datetime,Link_UpDatetime,Link_Verify,Link_Lock,Link_State,Link_Delete,Link_Count,Link_Order,Link_Remark ");
			strSql.Append(" FROM Dd_Link ");
			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(" Link_ID,User_ID,Link_Title,Link_Address,Link_Description,Link_Tag,Link_OriginId,Link_PublishMode,Link_PutTop,Link_Fever,Link_Guid,Link_Datetime,Link_UpDatetime,Link_Verify,Link_Lock,Link_State,Link_Delete,Link_Count,Link_Order,Link_Remark ");
			strSql.Append(" FROM Dd_Link ");
			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_Link";
			parameters[1].Value = "Link_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
	}
}

