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

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

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

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


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(HaTeam.Dd.Model.Dd_Suggest model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into Dd_Suggest(");
			strSql.Append("User_ID,Suggest_Content,Suggest_Guid,Suggest_Datetime,Suggest_UpDatetime,Suggest_Verify,Suggest_Lock,Suggest_State,Suggest_Delete,Suggest_Count,Suggest_Order,Suggest_Remark)");
			strSql.Append(" values (");
			strSql.Append("@User_ID,@Suggest_Content,@Suggest_Guid,@Suggest_Datetime,@Suggest_UpDatetime,@Suggest_Verify,@Suggest_Lock,@Suggest_State,@Suggest_Delete,@Suggest_Count,@Suggest_Order,@Suggest_Remark)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@User_ID", SqlDbType.Int,4),
					new SqlParameter("@Suggest_Content", SqlDbType.NVarChar,1000),
					new SqlParameter("@Suggest_Guid", SqlDbType.NChar,36),
					new SqlParameter("@Suggest_Datetime", SqlDbType.DateTime),
					new SqlParameter("@Suggest_UpDatetime", SqlDbType.DateTime),
					new SqlParameter("@Suggest_Verify", SqlDbType.Int,4),
					new SqlParameter("@Suggest_Lock", SqlDbType.Int,4),
					new SqlParameter("@Suggest_State", SqlDbType.Int,4),
					new SqlParameter("@Suggest_Delete", SqlDbType.Int,4),
					new SqlParameter("@Suggest_Count", SqlDbType.Int,4),
					new SqlParameter("@Suggest_Order", SqlDbType.Int,4),
					new SqlParameter("@Suggest_Remark", SqlDbType.NText)};
			parameters[0].Value = model.User_ID;
			parameters[1].Value = model.Suggest_Content;
			parameters[2].Value = model.Suggest_Guid;
			parameters[3].Value = model.Suggest_Datetime;
			parameters[4].Value = model.Suggest_UpDatetime;
			parameters[5].Value = model.Suggest_Verify;
			parameters[6].Value = model.Suggest_Lock;
			parameters[7].Value = model.Suggest_State;
			parameters[8].Value = model.Suggest_Delete;
			parameters[9].Value = model.Suggest_Count;
			parameters[10].Value = model.Suggest_Order;
			parameters[11].Value = model.Suggest_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_Suggest model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update Dd_Suggest set ");
			strSql.Append("User_ID=@User_ID,");
			strSql.Append("Suggest_Content=@Suggest_Content,");
			strSql.Append("Suggest_Guid=@Suggest_Guid,");
			strSql.Append("Suggest_Datetime=@Suggest_Datetime,");
			strSql.Append("Suggest_UpDatetime=@Suggest_UpDatetime,");
			strSql.Append("Suggest_Verify=@Suggest_Verify,");
			strSql.Append("Suggest_Lock=@Suggest_Lock,");
			strSql.Append("Suggest_State=@Suggest_State,");
			strSql.Append("Suggest_Delete=@Suggest_Delete,");
			strSql.Append("Suggest_Count=@Suggest_Count,");
			strSql.Append("Suggest_Order=@Suggest_Order,");
			strSql.Append("Suggest_Remark=@Suggest_Remark");
			strSql.Append(" where Suggest_ID=@Suggest_ID");
			SqlParameter[] parameters = {
					new SqlParameter("@User_ID", SqlDbType.Int,4),
					new SqlParameter("@Suggest_Content", SqlDbType.NVarChar,1000),
					new SqlParameter("@Suggest_Guid", SqlDbType.NChar,36),
					new SqlParameter("@Suggest_Datetime", SqlDbType.DateTime),
					new SqlParameter("@Suggest_UpDatetime", SqlDbType.DateTime),
					new SqlParameter("@Suggest_Verify", SqlDbType.Int,4),
					new SqlParameter("@Suggest_Lock", SqlDbType.Int,4),
					new SqlParameter("@Suggest_State", SqlDbType.Int,4),
					new SqlParameter("@Suggest_Delete", SqlDbType.Int,4),
					new SqlParameter("@Suggest_Count", SqlDbType.Int,4),
					new SqlParameter("@Suggest_Order", SqlDbType.Int,4),
					new SqlParameter("@Suggest_Remark", SqlDbType.NText),
					new SqlParameter("@Suggest_ID", SqlDbType.Int,4)};
			parameters[0].Value = model.User_ID;
			parameters[1].Value = model.Suggest_Content;
			parameters[2].Value = model.Suggest_Guid;
			parameters[3].Value = model.Suggest_Datetime;
			parameters[4].Value = model.Suggest_UpDatetime;
			parameters[5].Value = model.Suggest_Verify;
			parameters[6].Value = model.Suggest_Lock;
			parameters[7].Value = model.Suggest_State;
			parameters[8].Value = model.Suggest_Delete;
			parameters[9].Value = model.Suggest_Count;
			parameters[10].Value = model.Suggest_Order;
			parameters[11].Value = model.Suggest_Remark;
			parameters[12].Value = model.Suggest_ID;

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

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

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


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public HaTeam.Dd.Model.Dd_Suggest GetModel(int Suggest_ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 Suggest_ID,User_ID,Suggest_Content,Suggest_Guid,Suggest_Datetime,Suggest_UpDatetime,Suggest_Verify,Suggest_Lock,Suggest_State,Suggest_Delete,Suggest_Count,Suggest_Order,Suggest_Remark from Dd_Suggest ");
			strSql.Append(" where Suggest_ID=@Suggest_ID");
			SqlParameter[] parameters = {
					new SqlParameter("@Suggest_ID", SqlDbType.Int,4)
};
			parameters[0].Value = Suggest_ID;

			HaTeam.Dd.Model.Dd_Suggest model=new HaTeam.Dd.Model.Dd_Suggest();
            DataSet ds = DbHelperSQL.GetDataSet(strSql.ToString(), parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["Suggest_ID"].ToString()!="")
				{
					model.Suggest_ID=int.Parse(ds.Tables[0].Rows[0]["Suggest_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]["Suggest_Content"]!=null)
				{
				model.Suggest_Content=ds.Tables[0].Rows[0]["Suggest_Content"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Suggest_Guid"]!=null)
				{
				model.Suggest_Guid=ds.Tables[0].Rows[0]["Suggest_Guid"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Suggest_Datetime"].ToString()!="")
				{
					model.Suggest_Datetime=DateTime.Parse(ds.Tables[0].Rows[0]["Suggest_Datetime"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Suggest_UpDatetime"].ToString()!="")
				{
					model.Suggest_UpDatetime=DateTime.Parse(ds.Tables[0].Rows[0]["Suggest_UpDatetime"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Suggest_Verify"].ToString()!="")
				{
					model.Suggest_Verify=int.Parse(ds.Tables[0].Rows[0]["Suggest_Verify"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Suggest_Lock"].ToString()!="")
				{
					model.Suggest_Lock=int.Parse(ds.Tables[0].Rows[0]["Suggest_Lock"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Suggest_State"].ToString()!="")
				{
					model.Suggest_State=int.Parse(ds.Tables[0].Rows[0]["Suggest_State"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Suggest_Delete"].ToString()!="")
				{
					model.Suggest_Delete=int.Parse(ds.Tables[0].Rows[0]["Suggest_Delete"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Suggest_Count"].ToString()!="")
				{
					model.Suggest_Count=int.Parse(ds.Tables[0].Rows[0]["Suggest_Count"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Suggest_Order"].ToString()!="")
				{
					model.Suggest_Order=int.Parse(ds.Tables[0].Rows[0]["Suggest_Order"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Suggest_Remark"]!=null)
				{
				model.Suggest_Remark=ds.Tables[0].Rows[0]["Suggest_Remark"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select Suggest_ID,User_ID,Suggest_Content,Suggest_Guid,Suggest_Datetime,Suggest_UpDatetime,Suggest_Verify,Suggest_Lock,Suggest_State,Suggest_Delete,Suggest_Count,Suggest_Order,Suggest_Remark ");
			strSql.Append(" FROM Dd_Suggest ");
			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(" Suggest_ID,User_ID,Suggest_Content,Suggest_Guid,Suggest_Datetime,Suggest_UpDatetime,Suggest_Verify,Suggest_Lock,Suggest_State,Suggest_Delete,Suggest_Count,Suggest_Order,Suggest_Remark ");
			strSql.Append(" FROM Dd_Suggest ");
			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_Suggest";
			parameters[1].Value = "Suggest_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
	}
}

