using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using HySoft.DBUtility;//Please add references
namespace HySoft.BaseCallCenter.DAL
{
	/// <summary>
	/// 数据访问类:T_Call_Blacklist
	/// </summary>
	public partial class T_Call_Blacklist
	{
		public T_Call_Blacklist()
		{}
		#region  BasicMethod

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

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

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


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(HySoft.BaseCallCenter.Model.T_Call_Blacklist model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into T_Call_Blacklist(");
			strSql.Append("F_CallId,F_TelPhone,F_BlackType,F_SetTime,F_RemoveTime,F_Describe,F_UserId,F_InterceptNum,F_IsDelete)");
			strSql.Append(" values (");
			strSql.Append("@F_CallId,@F_TelPhone,@F_BlackType,@F_SetTime,@F_RemoveTime,@F_Describe,@F_UserId,@F_InterceptNum,@F_IsDelete)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@F_CallId", SqlDbType.VarChar,50),
					new SqlParameter("@F_TelPhone", SqlDbType.NVarChar,20),
					new SqlParameter("@F_BlackType", SqlDbType.Int,4),
					new SqlParameter("@F_SetTime", SqlDbType.DateTime),
					new SqlParameter("@F_RemoveTime", SqlDbType.DateTime),
					new SqlParameter("@F_Describe", SqlDbType.NVarChar,1000),
					new SqlParameter("@F_UserId", SqlDbType.Int,4),
					new SqlParameter("@F_InterceptNum", SqlDbType.Int,4),
					new SqlParameter("@F_IsDelete", SqlDbType.Bit,1)};
			parameters[0].Value = model.F_CallId;
			parameters[1].Value = model.F_TelPhone;
			parameters[2].Value = model.F_BlackType;
			parameters[3].Value = model.F_SetTime;
			parameters[4].Value = model.F_RemoveTime;
			parameters[5].Value = model.F_Describe;
			parameters[6].Value = model.F_UserId;
			parameters[7].Value = model.F_InterceptNum;
			parameters[8].Value = model.F_IsDelete;

			object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(HySoft.BaseCallCenter.Model.T_Call_Blacklist model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update T_Call_Blacklist set ");
			strSql.Append("F_CallId=@F_CallId,");
			strSql.Append("F_TelPhone=@F_TelPhone,");
			strSql.Append("F_BlackType=@F_BlackType,");
			strSql.Append("F_SetTime=@F_SetTime,");
			strSql.Append("F_RemoveTime=@F_RemoveTime,");
			strSql.Append("F_Describe=@F_Describe,");
			strSql.Append("F_UserId=@F_UserId,");
			strSql.Append("F_InterceptNum=@F_InterceptNum,");
			strSql.Append("F_IsDelete=@F_IsDelete");
			strSql.Append(" where F_BlackId=@F_BlackId");
			SqlParameter[] parameters = {
					new SqlParameter("@F_CallId", SqlDbType.VarChar,50),
					new SqlParameter("@F_TelPhone", SqlDbType.NVarChar,20),
					new SqlParameter("@F_BlackType", SqlDbType.Int,4),
					new SqlParameter("@F_SetTime", SqlDbType.DateTime),
					new SqlParameter("@F_RemoveTime", SqlDbType.DateTime),
					new SqlParameter("@F_Describe", SqlDbType.NVarChar,1000),
					new SqlParameter("@F_UserId", SqlDbType.Int,4),
					new SqlParameter("@F_InterceptNum", SqlDbType.Int,4),
					new SqlParameter("@F_IsDelete", SqlDbType.Bit,1),
					new SqlParameter("@F_BlackId", SqlDbType.Int,4)};
			parameters[0].Value = model.F_CallId;
			parameters[1].Value = model.F_TelPhone;
			parameters[2].Value = model.F_BlackType;
			parameters[3].Value = model.F_SetTime;
			parameters[4].Value = model.F_RemoveTime;
			parameters[5].Value = model.F_Describe;
			parameters[6].Value = model.F_UserId;
			parameters[7].Value = model.F_InterceptNum;
			parameters[8].Value = model.F_IsDelete;
			parameters[9].Value = model.F_BlackId;

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

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

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string F_BlackIdlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_Call_Blacklist ");
			strSql.Append(" where F_BlackId in ("+F_BlackIdlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public HySoft.BaseCallCenter.Model.T_Call_Blacklist GetModel(int F_BlackId)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 F_BlackId,F_CallId,F_TelPhone,F_BlackType,F_SetTime,F_RemoveTime,F_Describe,F_UserId,F_InterceptNum,F_IsDelete from T_Call_Blacklist ");
			strSql.Append(" where F_BlackId=@F_BlackId");
			SqlParameter[] parameters = {
					new SqlParameter("@F_BlackId", SqlDbType.Int,4)
			};
			parameters[0].Value = F_BlackId;

			HySoft.BaseCallCenter.Model.T_Call_Blacklist model=new HySoft.BaseCallCenter.Model.T_Call_Blacklist();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public HySoft.BaseCallCenter.Model.T_Call_Blacklist DataRowToModel(DataRow row)
		{
			HySoft.BaseCallCenter.Model.T_Call_Blacklist model=new HySoft.BaseCallCenter.Model.T_Call_Blacklist();
			if (row != null)
			{
				if(row["F_BlackId"]!=null && row["F_BlackId"].ToString()!="")
				{
					model.F_BlackId=int.Parse(row["F_BlackId"].ToString());
				}
				if(row["F_CallId"]!=null)
				{
					model.F_CallId=row["F_CallId"].ToString();
				}
				if(row["F_TelPhone"]!=null)
				{
					model.F_TelPhone=row["F_TelPhone"].ToString();
				}
				if(row["F_BlackType"]!=null && row["F_BlackType"].ToString()!="")
				{
					model.F_BlackType=int.Parse(row["F_BlackType"].ToString());
				}
				if(row["F_SetTime"]!=null && row["F_SetTime"].ToString()!="")
				{
					model.F_SetTime=DateTime.Parse(row["F_SetTime"].ToString());
				}
				if(row["F_RemoveTime"]!=null && row["F_RemoveTime"].ToString()!="")
				{
					model.F_RemoveTime=DateTime.Parse(row["F_RemoveTime"].ToString());
				}
				if(row["F_Describe"]!=null)
				{
					model.F_Describe=row["F_Describe"].ToString();
				}
				if(row["F_UserId"]!=null && row["F_UserId"].ToString()!="")
				{
					model.F_UserId=int.Parse(row["F_UserId"].ToString());
				}
				if(row["F_InterceptNum"]!=null && row["F_InterceptNum"].ToString()!="")
				{
					model.F_InterceptNum=int.Parse(row["F_InterceptNum"].ToString());
				}
				if(row["F_IsDelete"]!=null && row["F_IsDelete"].ToString()!="")
				{
					if((row["F_IsDelete"].ToString()=="1")||(row["F_IsDelete"].ToString().ToLower()=="true"))
					{
						model.F_IsDelete=true;
					}
					else
					{
						model.F_IsDelete=false;
					}
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select F_BlackId,F_CallId,F_TelPhone,F_BlackType,F_SetTime,F_RemoveTime,F_Describe,F_UserId,F_InterceptNum,F_IsDelete ");
			strSql.Append(" FROM T_Call_Blacklist ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(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(" F_BlackId,F_CallId,F_TelPhone,F_BlackType,F_SetTime,F_RemoveTime,F_Describe,F_UserId,F_InterceptNum,F_IsDelete ");
			strSql.Append(" FROM T_Call_Blacklist ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM T_Call_Blacklist ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.F_BlackId desc");
			}
			strSql.Append(")AS Row, T.*  from T_Call_Blacklist T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(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 = "T_Call_Blacklist";
			parameters[1].Value = "F_BlackId";
			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  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

