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

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

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

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


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(HaTeam.Dd.Model.Dd_Video model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into Dd_Video(");
			strSql.Append("User_ID,Video_Address,Video_Radiourl,Video_Imageurl,Video_Description,Video_Tag,Video_OriginId,Video_PublishMode,Video_PutTop,Video_Fever,Video_Guid,Video_Datetime,Video_UpDatetime,Video_Verify,Video_Lock,Video_State,Video_Delete,Video_Count,Video_Order,Video_Remark)");
			strSql.Append(" values (");
			strSql.Append("@User_ID,@Video_Address,@Video_Radiourl,@Video_Imageurl,@Video_Description,@Video_Tag,@Video_OriginId,@Video_PublishMode,@Video_PutTop,@Video_Fever,@Video_Guid,@Video_Datetime,@Video_UpDatetime,@Video_Verify,@Video_Lock,@Video_State,@Video_Delete,@Video_Count,@Video_Order,@Video_Remark)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@User_ID", SqlDbType.Int,4),
					new SqlParameter("@Video_Address", SqlDbType.NVarChar,100),
					new SqlParameter("@Video_Radiourl", SqlDbType.NVarChar,100),
					new SqlParameter("@Video_Imageurl", SqlDbType.NVarChar,150),
					new SqlParameter("@Video_Description", SqlDbType.NVarChar,1000),
					new SqlParameter("@Video_Tag", SqlDbType.VarChar,100),
					new SqlParameter("@Video_OriginId", SqlDbType.Int,4),
					new SqlParameter("@Video_PublishMode", SqlDbType.Int,4),
					new SqlParameter("@Video_PutTop", SqlDbType.Bit,1),
					new SqlParameter("@Video_Fever", SqlDbType.Int,4),
					new SqlParameter("@Video_Guid", SqlDbType.NChar,36),
					new SqlParameter("@Video_Datetime", SqlDbType.DateTime),
					new SqlParameter("@Video_UpDatetime", SqlDbType.DateTime),
					new SqlParameter("@Video_Verify", SqlDbType.Int,4),
					new SqlParameter("@Video_Lock", SqlDbType.Int,4),
					new SqlParameter("@Video_State", SqlDbType.Int,4),
					new SqlParameter("@Video_Delete", SqlDbType.Int,4),
					new SqlParameter("@Video_Count", SqlDbType.Int,4),
					new SqlParameter("@Video_Order", SqlDbType.Int,4),
					new SqlParameter("@Video_Remark", SqlDbType.NText)};
			parameters[0].Value = model.User_ID;
			parameters[1].Value = model.Video_Address;
			parameters[2].Value = model.Video_Radiourl;
			parameters[3].Value = model.Video_Imageurl;
			parameters[4].Value = model.Video_Description;
			parameters[5].Value = model.Video_Tag;
			parameters[6].Value = model.Video_OriginId;
			parameters[7].Value = model.Video_PublishMode;
			parameters[8].Value = model.Video_PutTop;
			parameters[9].Value = model.Video_Fever;
			parameters[10].Value = model.Video_Guid;
			parameters[11].Value = model.Video_Datetime;
			parameters[12].Value = model.Video_UpDatetime;
			parameters[13].Value = model.Video_Verify;
			parameters[14].Value = model.Video_Lock;
			parameters[15].Value = model.Video_State;
			parameters[16].Value = model.Video_Delete;
			parameters[17].Value = model.Video_Count;
			parameters[18].Value = model.Video_Order;
			parameters[19].Value = model.Video_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_Video model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update Dd_Video set ");
			strSql.Append("User_ID=@User_ID,");
			strSql.Append("Video_Address=@Video_Address,");
			strSql.Append("Video_Radiourl=@Video_Radiourl,");
			strSql.Append("Video_Imageurl=@Video_Imageurl,");
			strSql.Append("Video_Description=@Video_Description,");
			strSql.Append("Video_Tag=@Video_Tag,");
			strSql.Append("Video_OriginId=@Video_OriginId,");
			strSql.Append("Video_PublishMode=@Video_PublishMode,");
			strSql.Append("Video_PutTop=@Video_PutTop,");
			strSql.Append("Video_Fever=@Video_Fever,");
			strSql.Append("Video_Guid=@Video_Guid,");
			strSql.Append("Video_Datetime=@Video_Datetime,");
			strSql.Append("Video_UpDatetime=@Video_UpDatetime,");
			strSql.Append("Video_Verify=@Video_Verify,");
			strSql.Append("Video_Lock=@Video_Lock,");
			strSql.Append("Video_State=@Video_State,");
			strSql.Append("Video_Delete=@Video_Delete,");
			strSql.Append("Video_Count=@Video_Count,");
			strSql.Append("Video_Order=@Video_Order,");
			strSql.Append("Video_Remark=@Video_Remark");
			strSql.Append(" where Video_ID=@Video_ID");
			SqlParameter[] parameters = {
					new SqlParameter("@User_ID", SqlDbType.Int,4),
					new SqlParameter("@Video_Address", SqlDbType.NVarChar,100),
					new SqlParameter("@Video_Radiourl", SqlDbType.NVarChar,100),
					new SqlParameter("@Video_Imageurl", SqlDbType.NVarChar,150),
					new SqlParameter("@Video_Description", SqlDbType.NVarChar,1000),
					new SqlParameter("@Video_Tag", SqlDbType.VarChar,100),
					new SqlParameter("@Video_OriginId", SqlDbType.Int,4),
					new SqlParameter("@Video_PublishMode", SqlDbType.Int,4),
					new SqlParameter("@Video_PutTop", SqlDbType.Bit,1),
					new SqlParameter("@Video_Fever", SqlDbType.Int,4),
					new SqlParameter("@Video_Guid", SqlDbType.NChar,36),
					new SqlParameter("@Video_Datetime", SqlDbType.DateTime),
					new SqlParameter("@Video_UpDatetime", SqlDbType.DateTime),
					new SqlParameter("@Video_Verify", SqlDbType.Int,4),
					new SqlParameter("@Video_Lock", SqlDbType.Int,4),
					new SqlParameter("@Video_State", SqlDbType.Int,4),
					new SqlParameter("@Video_Delete", SqlDbType.Int,4),
					new SqlParameter("@Video_Count", SqlDbType.Int,4),
					new SqlParameter("@Video_Order", SqlDbType.Int,4),
					new SqlParameter("@Video_Remark", SqlDbType.NText),
					new SqlParameter("@Video_ID", SqlDbType.Int,4)};
			parameters[0].Value = model.User_ID;
			parameters[1].Value = model.Video_Address;
			parameters[2].Value = model.Video_Radiourl;
			parameters[3].Value = model.Video_Imageurl;
			parameters[4].Value = model.Video_Description;
			parameters[5].Value = model.Video_Tag;
			parameters[6].Value = model.Video_OriginId;
			parameters[7].Value = model.Video_PublishMode;
			parameters[8].Value = model.Video_PutTop;
			parameters[9].Value = model.Video_Fever;
			parameters[10].Value = model.Video_Guid;
			parameters[11].Value = model.Video_Datetime;
			parameters[12].Value = model.Video_UpDatetime;
			parameters[13].Value = model.Video_Verify;
			parameters[14].Value = model.Video_Lock;
			parameters[15].Value = model.Video_State;
			parameters[16].Value = model.Video_Delete;
			parameters[17].Value = model.Video_Count;
			parameters[18].Value = model.Video_Order;
			parameters[19].Value = model.Video_Remark;
			parameters[20].Value = model.Video_ID;

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

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

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


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public HaTeam.Dd.Model.Dd_Video GetModel(int Video_ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 Video_ID,User_ID,Video_Address,Video_Radiourl,Video_Imageurl,Video_Description,Video_Tag,Video_OriginId,Video_PublishMode,Video_PutTop,Video_Fever,Video_Guid,Video_Datetime,Video_UpDatetime,Video_Verify,Video_Lock,Video_State,Video_Delete,Video_Count,Video_Order,Video_Remark from Dd_Video ");
			strSql.Append(" where Video_ID=@Video_ID");
			SqlParameter[] parameters = {
					new SqlParameter("@Video_ID", SqlDbType.Int,4)
};
			parameters[0].Value = Video_ID;

			HaTeam.Dd.Model.Dd_Video model=new HaTeam.Dd.Model.Dd_Video();
			DataSet ds=DbHelperSQL.GetDataSet(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["Video_ID"].ToString()!="")
				{
					model.Video_ID=int.Parse(ds.Tables[0].Rows[0]["Video_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]["Video_Address"]!=null)
				{
				model.Video_Address=ds.Tables[0].Rows[0]["Video_Address"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Video_Radiourl"]!=null)
				{
				model.Video_Radiourl=ds.Tables[0].Rows[0]["Video_Radiourl"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Video_Imageurl"]!=null)
				{
				model.Video_Imageurl=ds.Tables[0].Rows[0]["Video_Imageurl"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Video_Description"]!=null)
				{
				model.Video_Description=ds.Tables[0].Rows[0]["Video_Description"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Video_Tag"]!=null)
				{
				model.Video_Tag=ds.Tables[0].Rows[0]["Video_Tag"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Video_OriginId"].ToString()!="")
				{
					model.Video_OriginId=int.Parse(ds.Tables[0].Rows[0]["Video_OriginId"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Video_PublishMode"].ToString()!="")
				{
					model.Video_PublishMode=int.Parse(ds.Tables[0].Rows[0]["Video_PublishMode"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Video_PutTop"].ToString()!="")
				{
					if((ds.Tables[0].Rows[0]["Video_PutTop"].ToString()=="1")||(ds.Tables[0].Rows[0]["Video_PutTop"].ToString().ToLower()=="true"))
					{
						model.Video_PutTop=true;
					}
					else
					{
						model.Video_PutTop=false;
					}
				}
				if(ds.Tables[0].Rows[0]["Video_Fever"].ToString()!="")
				{
					model.Video_Fever=int.Parse(ds.Tables[0].Rows[0]["Video_Fever"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Video_Guid"]!=null)
				{
				model.Video_Guid=ds.Tables[0].Rows[0]["Video_Guid"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Video_Datetime"].ToString()!="")
				{
					model.Video_Datetime=DateTime.Parse(ds.Tables[0].Rows[0]["Video_Datetime"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Video_UpDatetime"].ToString()!="")
				{
					model.Video_UpDatetime=DateTime.Parse(ds.Tables[0].Rows[0]["Video_UpDatetime"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Video_Verify"].ToString()!="")
				{
					model.Video_Verify=int.Parse(ds.Tables[0].Rows[0]["Video_Verify"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Video_Lock"].ToString()!="")
				{
					model.Video_Lock=int.Parse(ds.Tables[0].Rows[0]["Video_Lock"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Video_State"].ToString()!="")
				{
					model.Video_State=int.Parse(ds.Tables[0].Rows[0]["Video_State"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Video_Delete"].ToString()!="")
				{
					model.Video_Delete=int.Parse(ds.Tables[0].Rows[0]["Video_Delete"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Video_Count"].ToString()!="")
				{
					model.Video_Count=int.Parse(ds.Tables[0].Rows[0]["Video_Count"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Video_Order"].ToString()!="")
				{
					model.Video_Order=int.Parse(ds.Tables[0].Rows[0]["Video_Order"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Video_Remark"]!=null)
				{
				model.Video_Remark=ds.Tables[0].Rows[0]["Video_Remark"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select Video_ID,User_ID,Video_Address,Video_Radiourl,Video_Imageurl,Video_Description,Video_Tag,Video_OriginId,Video_PublishMode,Video_PutTop,Video_Fever,Video_Guid,Video_Datetime,Video_UpDatetime,Video_Verify,Video_Lock,Video_State,Video_Delete,Video_Count,Video_Order,Video_Remark ");
			strSql.Append(" FROM Dd_Video ");
			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(" Video_ID,User_ID,Video_Address,Video_Radiourl,Video_Imageurl,Video_Description,Video_Tag,Video_OriginId,Video_PublishMode,Video_PutTop,Video_Fever,Video_Guid,Video_Datetime,Video_UpDatetime,Video_Verify,Video_Lock,Video_State,Video_Delete,Video_Count,Video_Order,Video_Remark ");
			strSql.Append(" FROM Dd_Video ");
			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_Video";
			parameters[1].Value = "Video_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
	}
}

