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

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

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

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


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(HaTeam.Dd.Model.Dd_Music model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into Dd_Music(");
			strSql.Append("User_ID,Music_Address,Music_Description,Music_Tag,Music_OriginId,Music_PublishMode,Music_PutTop,Music_Fever,Music_Guid,Music_Datetime,Music_UpDatetime,Music_Verify,Music_Lock,Music_State,Music_Delete,Music_Count,Music_Order,Music_Remark)");
			strSql.Append(" values (");
			strSql.Append("@User_ID,@Music_Address,@Music_Description,@Music_Tag,@Music_OriginId,@Music_PublishMode,@Music_PutTop,@Music_Fever,NEWID(),@Music_Datetime,@Music_UpDatetime,@Music_Verify,@Music_Lock,@Music_State,@Music_Delete,@Music_Count,@Music_Order,@Music_Remark)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@User_ID", SqlDbType.Int,4),
					new SqlParameter("@Music_Address", SqlDbType.NVarChar,1000),
					new SqlParameter("@Music_Description", SqlDbType.NVarChar,1000),
					new SqlParameter("@Music_Tag", SqlDbType.VarChar,100),
					new SqlParameter("@Music_OriginId", SqlDbType.Int,4),
					new SqlParameter("@Music_PublishMode", SqlDbType.Int,4),
					new SqlParameter("@Music_PutTop", SqlDbType.Bit,1),
					new SqlParameter("@Music_Fever", SqlDbType.Int,4),
					new SqlParameter("@Music_Guid", SqlDbType.NChar,36),
					new SqlParameter("@Music_Datetime", SqlDbType.DateTime),
					new SqlParameter("@Music_UpDatetime", SqlDbType.DateTime),
					new SqlParameter("@Music_Verify", SqlDbType.Int,4),
					new SqlParameter("@Music_Lock", SqlDbType.Int,4),
					new SqlParameter("@Music_State", SqlDbType.Int,4),
					new SqlParameter("@Music_Delete", SqlDbType.Int,4),
					new SqlParameter("@Music_Count", SqlDbType.Int,4),
					new SqlParameter("@Music_Order", SqlDbType.Int,4),
					new SqlParameter("@Music_Remark", SqlDbType.NText)};
			parameters[0].Value = model.User_ID;
			parameters[1].Value = model.Music_Address;
			parameters[2].Value = model.Music_Description;
			parameters[3].Value = model.Music_Tag;
			parameters[4].Value = model.Music_OriginId;
			parameters[5].Value = model.Music_PublishMode;
			parameters[6].Value = model.Music_PutTop;
			parameters[7].Value = model.Music_Fever;
			parameters[8].Value = model.Music_Guid;
			parameters[9].Value = model.Music_Datetime;
			parameters[10].Value = model.Music_UpDatetime;
			parameters[11].Value = model.Music_Verify;
			parameters[12].Value = model.Music_Lock;
			parameters[13].Value = model.Music_State;
			parameters[14].Value = model.Music_Delete;
			parameters[15].Value = model.Music_Count;
			parameters[16].Value = model.Music_Order;
			parameters[17].Value = model.Music_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_Music model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update Dd_Music set ");
			strSql.Append("User_ID=@User_ID,");
			strSql.Append("Music_Address=@Music_Address,");
			strSql.Append("Music_Description=@Music_Description,");
			strSql.Append("Music_Tag=@Music_Tag,");
			strSql.Append("Music_OriginId=@Music_OriginId,");
			strSql.Append("Music_PublishMode=@Music_PublishMode,");
			strSql.Append("Music_PutTop=@Music_PutTop,");
			strSql.Append("Music_Fever=@Music_Fever,");
			strSql.Append("Music_Guid=@Music_Guid,");
			strSql.Append("Music_Datetime=@Music_Datetime,");
			strSql.Append("Music_UpDatetime=@Music_UpDatetime,");
			strSql.Append("Music_Verify=@Music_Verify,");
			strSql.Append("Music_Lock=@Music_Lock,");
			strSql.Append("Music_State=@Music_State,");
			strSql.Append("Music_Delete=@Music_Delete,");
			strSql.Append("Music_Count=@Music_Count,");
			strSql.Append("Music_Order=@Music_Order,");
			strSql.Append("Music_Remark=@Music_Remark");
			strSql.Append(" where Music_ID=@Music_ID");
			SqlParameter[] parameters = {
					new SqlParameter("@User_ID", SqlDbType.Int,4),
					new SqlParameter("@Music_Address", SqlDbType.NVarChar,1000),
					new SqlParameter("@Music_Description", SqlDbType.NVarChar,1000),
					new SqlParameter("@Music_Tag", SqlDbType.VarChar,100),
					new SqlParameter("@Music_OriginId", SqlDbType.Int,4),
					new SqlParameter("@Music_PublishMode", SqlDbType.Int,4),
					new SqlParameter("@Music_PutTop", SqlDbType.Bit,1),
					new SqlParameter("@Music_Fever", SqlDbType.Int,4),
					new SqlParameter("@Music_Guid", SqlDbType.NChar,36),
					new SqlParameter("@Music_Datetime", SqlDbType.DateTime),
					new SqlParameter("@Music_UpDatetime", SqlDbType.DateTime),
					new SqlParameter("@Music_Verify", SqlDbType.Int,4),
					new SqlParameter("@Music_Lock", SqlDbType.Int,4),
					new SqlParameter("@Music_State", SqlDbType.Int,4),
					new SqlParameter("@Music_Delete", SqlDbType.Int,4),
					new SqlParameter("@Music_Count", SqlDbType.Int,4),
					new SqlParameter("@Music_Order", SqlDbType.Int,4),
					new SqlParameter("@Music_Remark", SqlDbType.NText),
					new SqlParameter("@Music_ID", SqlDbType.Int,4)};
			parameters[0].Value = model.User_ID;
			parameters[1].Value = model.Music_Address;
			parameters[2].Value = model.Music_Description;
			parameters[3].Value = model.Music_Tag;
			parameters[4].Value = model.Music_OriginId;
			parameters[5].Value = model.Music_PublishMode;
			parameters[6].Value = model.Music_PutTop;
			parameters[7].Value = model.Music_Fever;
			parameters[8].Value = model.Music_Guid;
			parameters[9].Value = model.Music_Datetime;
			parameters[10].Value = model.Music_UpDatetime;
			parameters[11].Value = model.Music_Verify;
			parameters[12].Value = model.Music_Lock;
			parameters[13].Value = model.Music_State;
			parameters[14].Value = model.Music_Delete;
			parameters[15].Value = model.Music_Count;
			parameters[16].Value = model.Music_Order;
			parameters[17].Value = model.Music_Remark;
			parameters[18].Value = model.Music_ID;

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

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

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


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public HaTeam.Dd.Model.Dd_Music GetModel(int Music_ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 Music_ID,User_ID,Music_Address,Music_Description,Music_Tag,Music_OriginId,Music_PublishMode,Music_PutTop,Music_Fever,Music_Guid,Music_Datetime,Music_UpDatetime,Music_Verify,Music_Lock,Music_State,Music_Delete,Music_Count,Music_Order,Music_Remark from Dd_Music ");
			strSql.Append(" where Music_ID=@Music_ID");
			SqlParameter[] parameters = {
					new SqlParameter("@Music_ID", SqlDbType.Int,4)
};
			parameters[0].Value = Music_ID;

			HaTeam.Dd.Model.Dd_Music model=new HaTeam.Dd.Model.Dd_Music();
			DataSet ds=DbHelperSQL.GetDataSet(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["Music_ID"].ToString()!="")
				{
					model.Music_ID=int.Parse(ds.Tables[0].Rows[0]["Music_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]["Music_Address"]!=null)
				{
				model.Music_Address=ds.Tables[0].Rows[0]["Music_Address"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Music_Description"]!=null)
				{
				model.Music_Description=ds.Tables[0].Rows[0]["Music_Description"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Music_Tag"]!=null)
				{
				model.Music_Tag=ds.Tables[0].Rows[0]["Music_Tag"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Music_OriginId"].ToString()!="")
				{
					model.Music_OriginId=int.Parse(ds.Tables[0].Rows[0]["Music_OriginId"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Music_PublishMode"].ToString()!="")
				{
					model.Music_PublishMode=int.Parse(ds.Tables[0].Rows[0]["Music_PublishMode"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Music_PutTop"].ToString()!="")
				{
					if((ds.Tables[0].Rows[0]["Music_PutTop"].ToString()=="1")||(ds.Tables[0].Rows[0]["Music_PutTop"].ToString().ToLower()=="true"))
					{
						model.Music_PutTop=true;
					}
					else
					{
						model.Music_PutTop=false;
					}
				}
				if(ds.Tables[0].Rows[0]["Music_Fever"].ToString()!="")
				{
					model.Music_Fever=int.Parse(ds.Tables[0].Rows[0]["Music_Fever"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Music_Guid"]!=null)
				{
				model.Music_Guid=ds.Tables[0].Rows[0]["Music_Guid"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Music_Datetime"].ToString()!="")
				{
					model.Music_Datetime=DateTime.Parse(ds.Tables[0].Rows[0]["Music_Datetime"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Music_UpDatetime"].ToString()!="")
				{
					model.Music_UpDatetime=DateTime.Parse(ds.Tables[0].Rows[0]["Music_UpDatetime"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Music_Verify"].ToString()!="")
				{
					model.Music_Verify=int.Parse(ds.Tables[0].Rows[0]["Music_Verify"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Music_Lock"].ToString()!="")
				{
					model.Music_Lock=int.Parse(ds.Tables[0].Rows[0]["Music_Lock"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Music_State"].ToString()!="")
				{
					model.Music_State=int.Parse(ds.Tables[0].Rows[0]["Music_State"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Music_Delete"].ToString()!="")
				{
					model.Music_Delete=int.Parse(ds.Tables[0].Rows[0]["Music_Delete"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Music_Count"].ToString()!="")
				{
					model.Music_Count=int.Parse(ds.Tables[0].Rows[0]["Music_Count"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Music_Order"].ToString()!="")
				{
					model.Music_Order=int.Parse(ds.Tables[0].Rows[0]["Music_Order"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Music_Remark"]!=null)
				{
				model.Music_Remark=ds.Tables[0].Rows[0]["Music_Remark"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select Music_ID,User_ID,Music_Address,Music_Description,Music_Tag,Music_OriginId,Music_PublishMode,Music_PutTop,Music_Fever,Music_Guid,Music_Datetime,Music_UpDatetime,Music_Verify,Music_Lock,Music_State,Music_Delete,Music_Count,Music_Order,Music_Remark ");
			strSql.Append(" FROM Dd_Music ");
			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(" Music_ID,User_ID,Music_Address,Music_Description,Music_Tag,Music_OriginId,Music_PublishMode,Music_PutTop,Music_Fever,Music_Guid,Music_Datetime,Music_UpDatetime,Music_Verify,Music_Lock,Music_State,Music_Delete,Music_Count,Music_Order,Music_Remark ");
			strSql.Append(" FROM Dd_Music ");
			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_Music";
			parameters[1].Value = "Music_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
	}
}

