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

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

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

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


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(HaTeam.Dd.Model.Dd_Picture model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into Dd_Picture(");
			strSql.Append("User_ID,Picture_Address,Picture_Discription,Picture_Tag,Picture_OriginId,Picture_PublishMode,Picture_PutTop,Picture_Fever,Picture_Guid,Picture_Datetime,Picture_UpDatetime,Picture_Verify,Picture_Lock,Picture_State,Picture_Delete,Picture_Count,Picture_Order,Picture_Remark,Picture_Empty)");
			strSql.Append(" values (");
			strSql.Append("@User_ID,@Picture_Address,@Picture_Discription,@Picture_Tag,@Picture_OriginId,@Picture_PublishMode,@Picture_PutTop,@Picture_Fever,@Picture_Guid,@Picture_Datetime,@Picture_UpDatetime,@Picture_Verify,@Picture_Lock,@Picture_State,@Picture_Delete,@Picture_Count,@Picture_Order,@Picture_Remark,@Picture_Empty)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@User_ID", SqlDbType.Int,4),
					new SqlParameter("@Picture_Address", SqlDbType.NVarChar,1000),
					new SqlParameter("@Picture_Discription", SqlDbType.NVarChar,1000),
					new SqlParameter("@Picture_Tag", SqlDbType.VarChar,100),
					new SqlParameter("@Picture_OriginId", SqlDbType.Int,4),
					new SqlParameter("@Picture_PublishMode", SqlDbType.Int,4),
					new SqlParameter("@Picture_PutTop", SqlDbType.Bit,1),
					new SqlParameter("@Picture_Fever", SqlDbType.Int,4),
					new SqlParameter("@Picture_Guid", SqlDbType.NChar,36),
					new SqlParameter("@Picture_Datetime", SqlDbType.DateTime),
					new SqlParameter("@Picture_UpDatetime", SqlDbType.DateTime),
					new SqlParameter("@Picture_Verify", SqlDbType.Int,4),
					new SqlParameter("@Picture_Lock", SqlDbType.Int,4),
					new SqlParameter("@Picture_State", SqlDbType.Int,4),
					new SqlParameter("@Picture_Delete", SqlDbType.Int,4),
					new SqlParameter("@Picture_Count", SqlDbType.Int,4),
					new SqlParameter("@Picture_Order", SqlDbType.Int,4),
					new SqlParameter("@Picture_Remark", SqlDbType.NText),
					new SqlParameter("@Picture_Empty", SqlDbType.NVarChar,50)};
			parameters[0].Value = model.User_ID;
			parameters[1].Value = model.Picture_Address;
			parameters[2].Value = model.Picture_Discription;
			parameters[3].Value = model.Picture_Tag;
			parameters[4].Value = model.Picture_OriginId;
			parameters[5].Value = model.Picture_PublishMode;
			parameters[6].Value = model.Picture_PutTop;
			parameters[7].Value = model.Picture_Fever;
			parameters[8].Value = model.Picture_Guid;
			parameters[9].Value = model.Picture_Datetime;
			parameters[10].Value = model.Picture_UpDatetime;
			parameters[11].Value = model.Picture_Verify;
			parameters[12].Value = model.Picture_Lock;
			parameters[13].Value = model.Picture_State;
			parameters[14].Value = model.Picture_Delete;
			parameters[15].Value = model.Picture_Count;
			parameters[16].Value = model.Picture_Order;
			parameters[17].Value = model.Picture_Remark;
			parameters[18].Value = model.Picture_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_Picture model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update Dd_Picture set ");
			strSql.Append("User_ID=@User_ID,");
			strSql.Append("Picture_Address=@Picture_Address,");
			strSql.Append("Picture_Discription=@Picture_Discription,");
			strSql.Append("Picture_Tag=@Picture_Tag,");
			strSql.Append("Picture_OriginId=@Picture_OriginId,");
			strSql.Append("Picture_PublishMode=@Picture_PublishMode,");
			strSql.Append("Picture_PutTop=@Picture_PutTop,");
			strSql.Append("Picture_Fever=@Picture_Fever,");
			strSql.Append("Picture_Guid=@Picture_Guid,");
			strSql.Append("Picture_Datetime=@Picture_Datetime,");
			strSql.Append("Picture_UpDatetime=@Picture_UpDatetime,");
			strSql.Append("Picture_Verify=@Picture_Verify,");
			strSql.Append("Picture_Lock=@Picture_Lock,");
			strSql.Append("Picture_State=@Picture_State,");
			strSql.Append("Picture_Delete=@Picture_Delete,");
			strSql.Append("Picture_Count=@Picture_Count,");
			strSql.Append("Picture_Order=@Picture_Order,");
			strSql.Append("Picture_Remark=@Picture_Remark,");
			strSql.Append("Picture_Empty=@Picture_Empty");
			strSql.Append(" where Picture_ID=@Picture_ID");
			SqlParameter[] parameters = {
					new SqlParameter("@User_ID", SqlDbType.Int,4),
					new SqlParameter("@Picture_Address", SqlDbType.NVarChar,1000),
					new SqlParameter("@Picture_Discription", SqlDbType.NVarChar,1000),
					new SqlParameter("@Picture_Tag", SqlDbType.VarChar,100),
					new SqlParameter("@Picture_OriginId", SqlDbType.Int,4),
					new SqlParameter("@Picture_PublishMode", SqlDbType.Int,4),
					new SqlParameter("@Picture_PutTop", SqlDbType.Bit,1),
					new SqlParameter("@Picture_Fever", SqlDbType.Int,4),
					new SqlParameter("@Picture_Guid", SqlDbType.NChar,36),
					new SqlParameter("@Picture_Datetime", SqlDbType.DateTime),
					new SqlParameter("@Picture_UpDatetime", SqlDbType.DateTime),
					new SqlParameter("@Picture_Verify", SqlDbType.Int,4),
					new SqlParameter("@Picture_Lock", SqlDbType.Int,4),
					new SqlParameter("@Picture_State", SqlDbType.Int,4),
					new SqlParameter("@Picture_Delete", SqlDbType.Int,4),
					new SqlParameter("@Picture_Count", SqlDbType.Int,4),
					new SqlParameter("@Picture_Order", SqlDbType.Int,4),
					new SqlParameter("@Picture_Remark", SqlDbType.NText),
					new SqlParameter("@Picture_Empty", SqlDbType.NVarChar,50),
					new SqlParameter("@Picture_ID", SqlDbType.Int,4)};
			parameters[0].Value = model.User_ID;
			parameters[1].Value = model.Picture_Address;
			parameters[2].Value = model.Picture_Discription;
			parameters[3].Value = model.Picture_Tag;
			parameters[4].Value = model.Picture_OriginId;
			parameters[5].Value = model.Picture_PublishMode;
			parameters[6].Value = model.Picture_PutTop;
			parameters[7].Value = model.Picture_Fever;
			parameters[8].Value = model.Picture_Guid;
			parameters[9].Value = model.Picture_Datetime;
			parameters[10].Value = model.Picture_UpDatetime;
			parameters[11].Value = model.Picture_Verify;
			parameters[12].Value = model.Picture_Lock;
			parameters[13].Value = model.Picture_State;
			parameters[14].Value = model.Picture_Delete;
			parameters[15].Value = model.Picture_Count;
			parameters[16].Value = model.Picture_Order;
			parameters[17].Value = model.Picture_Remark;
			parameters[18].Value = model.Picture_Empty;
			parameters[19].Value = model.Picture_ID;

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

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

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


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public HaTeam.Dd.Model.Dd_Picture GetModel(int Picture_ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 Picture_ID,User_ID,Picture_Address,Picture_Discription,Picture_Tag,Picture_OriginId,Picture_PublishMode,Picture_PutTop,Picture_Fever,Picture_Guid,Picture_Datetime,Picture_UpDatetime,Picture_Verify,Picture_Lock,Picture_State,Picture_Delete,Picture_Count,Picture_Order,Picture_Remark,Picture_Empty from Dd_Picture ");
			strSql.Append(" where Picture_ID=@Picture_ID");
			SqlParameter[] parameters = {
					new SqlParameter("@Picture_ID", SqlDbType.Int,4)
};
			parameters[0].Value = Picture_ID;

			HaTeam.Dd.Model.Dd_Picture model=new HaTeam.Dd.Model.Dd_Picture();
			DataSet ds=DbHelperSQL.GetDataSet(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["Picture_ID"].ToString()!="")
				{
					model.Picture_ID=int.Parse(ds.Tables[0].Rows[0]["Picture_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]["Picture_Address"]!=null)
				{
				model.Picture_Address=ds.Tables[0].Rows[0]["Picture_Address"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Picture_Discription"]!=null)
				{
				model.Picture_Discription=ds.Tables[0].Rows[0]["Picture_Discription"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Picture_Tag"]!=null)
				{
				model.Picture_Tag=ds.Tables[0].Rows[0]["Picture_Tag"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Picture_OriginId"].ToString()!="")
				{
					model.Picture_OriginId=int.Parse(ds.Tables[0].Rows[0]["Picture_OriginId"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Picture_PublishMode"].ToString()!="")
				{
					model.Picture_PublishMode=int.Parse(ds.Tables[0].Rows[0]["Picture_PublishMode"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Picture_PutTop"].ToString()!="")
				{
					if((ds.Tables[0].Rows[0]["Picture_PutTop"].ToString()=="1")||(ds.Tables[0].Rows[0]["Picture_PutTop"].ToString().ToLower()=="true"))
					{
						model.Picture_PutTop=true;
					}
					else
					{
						model.Picture_PutTop=false;
					}
				}
				if(ds.Tables[0].Rows[0]["Picture_Fever"].ToString()!="")
				{
					model.Picture_Fever=int.Parse(ds.Tables[0].Rows[0]["Picture_Fever"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Picture_Guid"]!=null)
				{
				model.Picture_Guid=ds.Tables[0].Rows[0]["Picture_Guid"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Picture_Datetime"].ToString()!="")
				{
					model.Picture_Datetime=DateTime.Parse(ds.Tables[0].Rows[0]["Picture_Datetime"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Picture_UpDatetime"].ToString()!="")
				{
					model.Picture_UpDatetime=DateTime.Parse(ds.Tables[0].Rows[0]["Picture_UpDatetime"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Picture_Verify"].ToString()!="")
				{
					model.Picture_Verify=int.Parse(ds.Tables[0].Rows[0]["Picture_Verify"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Picture_Lock"].ToString()!="")
				{
					model.Picture_Lock=int.Parse(ds.Tables[0].Rows[0]["Picture_Lock"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Picture_State"].ToString()!="")
				{
					model.Picture_State=int.Parse(ds.Tables[0].Rows[0]["Picture_State"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Picture_Delete"].ToString()!="")
				{
					model.Picture_Delete=int.Parse(ds.Tables[0].Rows[0]["Picture_Delete"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Picture_Count"].ToString()!="")
				{
					model.Picture_Count=int.Parse(ds.Tables[0].Rows[0]["Picture_Count"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Picture_Order"].ToString()!="")
				{
					model.Picture_Order=int.Parse(ds.Tables[0].Rows[0]["Picture_Order"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Picture_Remark"]!=null)
				{
				model.Picture_Remark=ds.Tables[0].Rows[0]["Picture_Remark"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Picture_Empty"]!=null)
				{
				model.Picture_Empty=ds.Tables[0].Rows[0]["Picture_Empty"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select Picture_ID,User_ID,Picture_Address,Picture_Discription,Picture_Tag,Picture_OriginId,Picture_PublishMode,Picture_PutTop,Picture_Fever,Picture_Guid,Picture_Datetime,Picture_UpDatetime,Picture_Verify,Picture_Lock,Picture_State,Picture_Delete,Picture_Count,Picture_Order,Picture_Remark,Picture_Empty ");
			strSql.Append(" FROM Dd_Picture ");
			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(" Picture_ID,User_ID,Picture_Address,Picture_Discription,Picture_Tag,Picture_OriginId,Picture_PublishMode,Picture_PutTop,Picture_Fever,Picture_Guid,Picture_Datetime,Picture_UpDatetime,Picture_Verify,Picture_Lock,Picture_State,Picture_Delete,Picture_Count,Picture_Order,Picture_Remark,Picture_Empty ");
			strSql.Append(" FROM Dd_Picture ");
			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_Picture";
			parameters[1].Value = "Picture_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
	}
}

