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

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

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

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


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(HaTeam.Dd.Model.Dd_Text model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into Dd_Text(");
			strSql.Append("User_ID,Text_Title,Text_Content,Text_Tag,Text_OriginId,Text_PublishMode,Text_PutTop,Text_Fever,Text_Guid,Text_Datetime,Text_UpDatetime,Text_Verify,Text_Lock,Text_State,Text_Delete,Text_Count,Text_Order,Text_Remark,Text_Empty)");
			strSql.Append(" values (");
			strSql.Append("@User_ID,@Text_Title,@Text_Content,@Text_Tag,@Text_OriginId,@Text_PublishMode,@Text_PutTop,@Text_Fever,@Text_Guid,@Text_Datetime,@Text_UpDatetime,@Text_Verify,@Text_Lock,@Text_State,@Text_Delete,@Text_Count,@Text_Order,@Text_Remark,@Text_Empty)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@User_ID", SqlDbType.Int,4),
					new SqlParameter("@Text_Title", SqlDbType.NVarChar,50),
					new SqlParameter("@Text_Content", SqlDbType.NVarChar,4000),
					new SqlParameter("@Text_Tag", SqlDbType.NVarChar,100),
					new SqlParameter("@Text_OriginId", SqlDbType.Int,4),
					new SqlParameter("@Text_PublishMode", SqlDbType.Int,4),
					new SqlParameter("@Text_PutTop", SqlDbType.Bit,1),
					new SqlParameter("@Text_Fever", SqlDbType.Int,4),
					new SqlParameter("@Text_Guid", SqlDbType.NChar,36),
					new SqlParameter("@Text_Datetime", SqlDbType.DateTime),
					new SqlParameter("@Text_UpDatetime", SqlDbType.DateTime),
					new SqlParameter("@Text_Verify", SqlDbType.Int,4),
					new SqlParameter("@Text_Lock", SqlDbType.Int,4),
					new SqlParameter("@Text_State", SqlDbType.Int,4),
					new SqlParameter("@Text_Delete", SqlDbType.Int,4),
					new SqlParameter("@Text_Count", SqlDbType.Int,4),
					new SqlParameter("@Text_Order", SqlDbType.Int,4),
					new SqlParameter("@Text_Remark", SqlDbType.NText),
					new SqlParameter("@Text_Empty", SqlDbType.NVarChar,50)};
			parameters[0].Value = model.User_ID;
			parameters[1].Value = model.Text_Title;
			parameters[2].Value = model.Text_Content;
			parameters[3].Value = model.Text_Tag;
			parameters[4].Value = model.Text_OriginId;
			parameters[5].Value = model.Text_PublishMode;
			parameters[6].Value = model.Text_PutTop;
			parameters[7].Value = model.Text_Fever;
			parameters[8].Value = model.Text_Guid;
			parameters[9].Value = model.Text_Datetime;
			parameters[10].Value = model.Text_UpDatetime;
			parameters[11].Value = model.Text_Verify;
			parameters[12].Value = model.Text_Lock;
			parameters[13].Value = model.Text_State;
			parameters[14].Value = model.Text_Delete;
			parameters[15].Value = model.Text_Count;
			parameters[16].Value = model.Text_Order;
			parameters[17].Value = model.Text_Remark;
			parameters[18].Value = model.Text_Empty;

			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_Text model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update Dd_Text set ");
			strSql.Append("User_ID=@User_ID,");
			strSql.Append("Text_Title=@Text_Title,");
			strSql.Append("Text_Content=@Text_Content,");
			strSql.Append("Text_Tag=@Text_Tag,");
			strSql.Append("Text_OriginId=@Text_OriginId,");
			strSql.Append("Text_PublishMode=@Text_PublishMode,");
			strSql.Append("Text_PutTop=@Text_PutTop,");
			strSql.Append("Text_Fever=@Text_Fever,");
			strSql.Append("Text_Guid=@Text_Guid,");
			strSql.Append("Text_Datetime=@Text_Datetime,");
			strSql.Append("Text_UpDatetime=@Text_UpDatetime,");
			strSql.Append("Text_Verify=@Text_Verify,");
			strSql.Append("Text_Lock=@Text_Lock,");
			strSql.Append("Text_State=@Text_State,");
			strSql.Append("Text_Delete=@Text_Delete,");
			strSql.Append("Text_Count=@Text_Count,");
			strSql.Append("Text_Order=@Text_Order,");
			strSql.Append("Text_Remark=@Text_Remark,");
			strSql.Append("Text_Empty=@Text_Empty");
			strSql.Append(" where Text_ID=@Text_ID");
			SqlParameter[] parameters = {
					new SqlParameter("@User_ID", SqlDbType.Int,4),
					new SqlParameter("@Text_Title", SqlDbType.NVarChar,50),
					new SqlParameter("@Text_Content", SqlDbType.NVarChar,4000),
					new SqlParameter("@Text_Tag", SqlDbType.NVarChar,100),
					new SqlParameter("@Text_OriginId", SqlDbType.Int,4),
					new SqlParameter("@Text_PublishMode", SqlDbType.Int,4),
					new SqlParameter("@Text_PutTop", SqlDbType.Bit,1),
					new SqlParameter("@Text_Fever", SqlDbType.Int,4),
					new SqlParameter("@Text_Guid", SqlDbType.NChar,36),
					new SqlParameter("@Text_Datetime", SqlDbType.DateTime),
					new SqlParameter("@Text_UpDatetime", SqlDbType.DateTime),
					new SqlParameter("@Text_Verify", SqlDbType.Int,4),
					new SqlParameter("@Text_Lock", SqlDbType.Int,4),
					new SqlParameter("@Text_State", SqlDbType.Int,4),
					new SqlParameter("@Text_Delete", SqlDbType.Int,4),
					new SqlParameter("@Text_Count", SqlDbType.Int,4),
					new SqlParameter("@Text_Order", SqlDbType.Int,4),
					new SqlParameter("@Text_Remark", SqlDbType.NText),
					new SqlParameter("@Text_Empty", SqlDbType.NVarChar,50),
					new SqlParameter("@Text_ID", SqlDbType.Int,4)};
			parameters[0].Value = model.User_ID;
			parameters[1].Value = model.Text_Title;
			parameters[2].Value = model.Text_Content;
			parameters[3].Value = model.Text_Tag;
			parameters[4].Value = model.Text_OriginId;
			parameters[5].Value = model.Text_PublishMode;
			parameters[6].Value = model.Text_PutTop;
			parameters[7].Value = model.Text_Fever;
			parameters[8].Value = model.Text_Guid;
			parameters[9].Value = model.Text_Datetime;
			parameters[10].Value = model.Text_UpDatetime;
			parameters[11].Value = model.Text_Verify;
			parameters[12].Value = model.Text_Lock;
			parameters[13].Value = model.Text_State;
			parameters[14].Value = model.Text_Delete;
			parameters[15].Value = model.Text_Count;
			parameters[16].Value = model.Text_Order;
			parameters[17].Value = model.Text_Remark;
			parameters[18].Value = model.Text_Empty;
			parameters[19].Value = model.Text_ID;

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

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

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


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public HaTeam.Dd.Model.Dd_Text GetModel(int Text_ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 Text_ID,User_ID,Text_Title,Text_Content,Text_Tag,Text_OriginId,Text_PublishMode,Text_PutTop,Text_Fever,Text_Guid,Text_Datetime,Text_UpDatetime,Text_Verify,Text_Lock,Text_State,Text_Delete,Text_Count,Text_Order,Text_Remark,Text_Empty from Dd_Text ");
			strSql.Append(" where Text_ID=@Text_ID");
			SqlParameter[] parameters = {
					new SqlParameter("@Text_ID", SqlDbType.Int,4)
};
			parameters[0].Value = Text_ID;

			HaTeam.Dd.Model.Dd_Text model=new HaTeam.Dd.Model.Dd_Text();
            DataSet ds = DbHelperSQL.GetDataSet(strSql.ToString(), parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["Text_ID"].ToString()!="")
				{
					model.Text_ID=int.Parse(ds.Tables[0].Rows[0]["Text_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]["Text_Title"]!=null)
				{
				model.Text_Title=ds.Tables[0].Rows[0]["Text_Title"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Text_Content"]!=null)
				{
				model.Text_Content=ds.Tables[0].Rows[0]["Text_Content"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Text_Tag"]!=null)
				{
				model.Text_Tag=ds.Tables[0].Rows[0]["Text_Tag"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Text_OriginId"].ToString()!="")
				{
					model.Text_OriginId=int.Parse(ds.Tables[0].Rows[0]["Text_OriginId"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Text_PublishMode"].ToString()!="")
				{
					model.Text_PublishMode=int.Parse(ds.Tables[0].Rows[0]["Text_PublishMode"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Text_PutTop"].ToString()!="")
				{
					if((ds.Tables[0].Rows[0]["Text_PutTop"].ToString()=="1")||(ds.Tables[0].Rows[0]["Text_PutTop"].ToString().ToLower()=="true"))
					{
						model.Text_PutTop=true;
					}
					else
					{
						model.Text_PutTop=false;
					}
				}
				if(ds.Tables[0].Rows[0]["Text_Fever"].ToString()!="")
				{
					model.Text_Fever=int.Parse(ds.Tables[0].Rows[0]["Text_Fever"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Text_Guid"]!=null)
				{
				model.Text_Guid=ds.Tables[0].Rows[0]["Text_Guid"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Text_Datetime"].ToString()!="")
				{
					model.Text_Datetime=DateTime.Parse(ds.Tables[0].Rows[0]["Text_Datetime"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Text_UpDatetime"].ToString()!="")
				{
					model.Text_UpDatetime=DateTime.Parse(ds.Tables[0].Rows[0]["Text_UpDatetime"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Text_Verify"].ToString()!="")
				{
					model.Text_Verify=int.Parse(ds.Tables[0].Rows[0]["Text_Verify"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Text_Lock"].ToString()!="")
				{
					model.Text_Lock=int.Parse(ds.Tables[0].Rows[0]["Text_Lock"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Text_State"].ToString()!="")
				{
					model.Text_State=int.Parse(ds.Tables[0].Rows[0]["Text_State"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Text_Delete"].ToString()!="")
				{
					model.Text_Delete=int.Parse(ds.Tables[0].Rows[0]["Text_Delete"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Text_Count"].ToString()!="")
				{
					model.Text_Count=int.Parse(ds.Tables[0].Rows[0]["Text_Count"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Text_Order"].ToString()!="")
				{
					model.Text_Order=int.Parse(ds.Tables[0].Rows[0]["Text_Order"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Text_Remark"]!=null)
				{
				model.Text_Remark=ds.Tables[0].Rows[0]["Text_Remark"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Text_Empty"]!=null)
				{
				model.Text_Empty=ds.Tables[0].Rows[0]["Text_Empty"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select Text_ID,User_ID,Text_Title,Text_Content,Text_Tag,Text_OriginId,Text_PublishMode,Text_PutTop,Text_Fever,Text_Guid,Text_Datetime,Text_UpDatetime,Text_Verify,Text_Lock,Text_State,Text_Delete,Text_Count,Text_Order,Text_Remark,Text_Empty ");
			strSql.Append(" FROM Dd_Text ");
			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(" Text_ID,User_ID,Text_Title,Text_Content,Text_Tag,Text_OriginId,Text_PublishMode,Text_PutTop,Text_Fever,Text_Guid,Text_Datetime,Text_UpDatetime,Text_Verify,Text_Lock,Text_State,Text_Delete,Text_Count,Text_Order,Text_Remark,Text_Empty ");
			strSql.Append(" FROM Dd_Text ");
			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_Text";
			parameters[1].Value = "Text_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
	}
}

