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

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

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

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


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(HaTeam.Dd.Model.Dd_Reprint model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into Dd_Reprint(");
			strSql.Append("Reprint_ArticleID,Reprint_type,Reprint_UserID,Reprint_CopyFrom,Reprint_OriginID,Reprint_Guid,Reprint_Datetime,Reprint_UpDatetime,Reprint_Verify,Reprint_Lock,Reprint_State,Reprint_Delete,Reprint_Count,Reprint_Order,Reprint_Remark)");
			strSql.Append(" values (");
			strSql.Append("@Reprint_ArticleID,@Reprint_type,@Reprint_UserID,@Reprint_CopyFrom,@Reprint_OriginID,@Reprint_Guid,@Reprint_Datetime,@Reprint_UpDatetime,@Reprint_Verify,@Reprint_Lock,@Reprint_State,@Reprint_Delete,@Reprint_Count,@Reprint_Order,@Reprint_Remark)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@Reprint_ArticleID", SqlDbType.Int,4),
					new SqlParameter("@Reprint_type", SqlDbType.Int,4),
					new SqlParameter("@Reprint_UserID", SqlDbType.Int,4),
					new SqlParameter("@Reprint_CopyFrom", SqlDbType.Int,4),
					new SqlParameter("@Reprint_OriginID", SqlDbType.Int,4),
					new SqlParameter("@Reprint_Guid", SqlDbType.NChar,36),
					new SqlParameter("@Reprint_Datetime", SqlDbType.DateTime),
					new SqlParameter("@Reprint_UpDatetime", SqlDbType.DateTime),
					new SqlParameter("@Reprint_Verify", SqlDbType.Int,4),
					new SqlParameter("@Reprint_Lock", SqlDbType.Int,4),
					new SqlParameter("@Reprint_State", SqlDbType.Int,4),
					new SqlParameter("@Reprint_Delete", SqlDbType.Int,4),
					new SqlParameter("@Reprint_Count", SqlDbType.Int,4),
					new SqlParameter("@Reprint_Order", SqlDbType.Int,4),
					new SqlParameter("@Reprint_Remark", SqlDbType.NText)};
			parameters[0].Value = model.Reprint_ArticleID;
			parameters[1].Value = model.Reprint_type;
			parameters[2].Value = model.Reprint_UserID;
			parameters[3].Value = model.Reprint_CopyFrom;
			parameters[4].Value = model.Reprint_OriginID;
			parameters[5].Value = model.Reprint_Guid;
			parameters[6].Value = model.Reprint_Datetime;
			parameters[7].Value = model.Reprint_UpDatetime;
			parameters[8].Value = model.Reprint_Verify;
			parameters[9].Value = model.Reprint_Lock;
			parameters[10].Value = model.Reprint_State;
			parameters[11].Value = model.Reprint_Delete;
			parameters[12].Value = model.Reprint_Count;
			parameters[13].Value = model.Reprint_Order;
			parameters[14].Value = model.Reprint_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_Reprint model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update Dd_Reprint set ");
			strSql.Append("Reprint_ArticleID=@Reprint_ArticleID,");
			strSql.Append("Reprint_type=@Reprint_type,");
			strSql.Append("Reprint_UserID=@Reprint_UserID,");
			strSql.Append("Reprint_CopyFrom=@Reprint_CopyFrom,");
			strSql.Append("Reprint_OriginID=@Reprint_OriginID,");
			strSql.Append("Reprint_Guid=@Reprint_Guid,");
			strSql.Append("Reprint_Datetime=@Reprint_Datetime,");
			strSql.Append("Reprint_UpDatetime=@Reprint_UpDatetime,");
			strSql.Append("Reprint_Verify=@Reprint_Verify,");
			strSql.Append("Reprint_Lock=@Reprint_Lock,");
			strSql.Append("Reprint_State=@Reprint_State,");
			strSql.Append("Reprint_Delete=@Reprint_Delete,");
			strSql.Append("Reprint_Count=@Reprint_Count,");
			strSql.Append("Reprint_Order=@Reprint_Order,");
			strSql.Append("Reprint_Remark=@Reprint_Remark");
			strSql.Append(" where Reprint_ID=@Reprint_ID");
			SqlParameter[] parameters = {
					new SqlParameter("@Reprint_ArticleID", SqlDbType.Int,4),
					new SqlParameter("@Reprint_type", SqlDbType.Int,4),
					new SqlParameter("@Reprint_UserID", SqlDbType.Int,4),
					new SqlParameter("@Reprint_CopyFrom", SqlDbType.Int,4),
					new SqlParameter("@Reprint_OriginID", SqlDbType.Int,4),
					new SqlParameter("@Reprint_Guid", SqlDbType.NChar,36),
					new SqlParameter("@Reprint_Datetime", SqlDbType.DateTime),
					new SqlParameter("@Reprint_UpDatetime", SqlDbType.DateTime),
					new SqlParameter("@Reprint_Verify", SqlDbType.Int,4),
					new SqlParameter("@Reprint_Lock", SqlDbType.Int,4),
					new SqlParameter("@Reprint_State", SqlDbType.Int,4),
					new SqlParameter("@Reprint_Delete", SqlDbType.Int,4),
					new SqlParameter("@Reprint_Count", SqlDbType.Int,4),
					new SqlParameter("@Reprint_Order", SqlDbType.Int,4),
					new SqlParameter("@Reprint_Remark", SqlDbType.NText),
					new SqlParameter("@Reprint_ID", SqlDbType.Int,4)};
			parameters[0].Value = model.Reprint_ArticleID;
			parameters[1].Value = model.Reprint_type;
			parameters[2].Value = model.Reprint_UserID;
			parameters[3].Value = model.Reprint_CopyFrom;
			parameters[4].Value = model.Reprint_OriginID;
			parameters[5].Value = model.Reprint_Guid;
			parameters[6].Value = model.Reprint_Datetime;
			parameters[7].Value = model.Reprint_UpDatetime;
			parameters[8].Value = model.Reprint_Verify;
			parameters[9].Value = model.Reprint_Lock;
			parameters[10].Value = model.Reprint_State;
			parameters[11].Value = model.Reprint_Delete;
			parameters[12].Value = model.Reprint_Count;
			parameters[13].Value = model.Reprint_Order;
			parameters[14].Value = model.Reprint_Remark;
			parameters[15].Value = model.Reprint_ID;

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

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

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


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public HaTeam.Dd.Model.Dd_Reprint GetModel(int Reprint_ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 Reprint_ID,Reprint_ArticleID,Reprint_type,Reprint_UserID,Reprint_CopyFrom,Reprint_OriginID,Reprint_Guid,Reprint_Datetime,Reprint_UpDatetime,Reprint_Verify,Reprint_Lock,Reprint_State,Reprint_Delete,Reprint_Count,Reprint_Order,Reprint_Remark from Dd_Reprint ");
			strSql.Append(" where Reprint_ID=@Reprint_ID");
			SqlParameter[] parameters = {
					new SqlParameter("@Reprint_ID", SqlDbType.Int,4)
};
			parameters[0].Value = Reprint_ID;

			HaTeam.Dd.Model.Dd_Reprint model=new HaTeam.Dd.Model.Dd_Reprint();
			DataSet ds=DbHelperSQL.GetDataSet(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["Reprint_ID"].ToString()!="")
				{
					model.Reprint_ID=int.Parse(ds.Tables[0].Rows[0]["Reprint_ID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Reprint_ArticleID"].ToString()!="")
				{
					model.Reprint_ArticleID=int.Parse(ds.Tables[0].Rows[0]["Reprint_ArticleID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Reprint_type"].ToString()!="")
				{
					model.Reprint_type=int.Parse(ds.Tables[0].Rows[0]["Reprint_type"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Reprint_UserID"].ToString()!="")
				{
					model.Reprint_UserID=int.Parse(ds.Tables[0].Rows[0]["Reprint_UserID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Reprint_CopyFrom"].ToString()!="")
				{
					model.Reprint_CopyFrom=int.Parse(ds.Tables[0].Rows[0]["Reprint_CopyFrom"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Reprint_OriginID"].ToString()!="")
				{
					model.Reprint_OriginID=int.Parse(ds.Tables[0].Rows[0]["Reprint_OriginID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Reprint_Guid"]!=null)
				{
				model.Reprint_Guid=ds.Tables[0].Rows[0]["Reprint_Guid"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Reprint_Datetime"].ToString()!="")
				{
					model.Reprint_Datetime=DateTime.Parse(ds.Tables[0].Rows[0]["Reprint_Datetime"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Reprint_UpDatetime"].ToString()!="")
				{
					model.Reprint_UpDatetime=DateTime.Parse(ds.Tables[0].Rows[0]["Reprint_UpDatetime"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Reprint_Verify"].ToString()!="")
				{
					model.Reprint_Verify=int.Parse(ds.Tables[0].Rows[0]["Reprint_Verify"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Reprint_Lock"].ToString()!="")
				{
					model.Reprint_Lock=int.Parse(ds.Tables[0].Rows[0]["Reprint_Lock"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Reprint_State"].ToString()!="")
				{
					model.Reprint_State=int.Parse(ds.Tables[0].Rows[0]["Reprint_State"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Reprint_Delete"].ToString()!="")
				{
					model.Reprint_Delete=int.Parse(ds.Tables[0].Rows[0]["Reprint_Delete"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Reprint_Count"].ToString()!="")
				{
					model.Reprint_Count=int.Parse(ds.Tables[0].Rows[0]["Reprint_Count"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Reprint_Order"].ToString()!="")
				{
					model.Reprint_Order=int.Parse(ds.Tables[0].Rows[0]["Reprint_Order"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Reprint_Remark"]!=null)
				{
				model.Reprint_Remark=ds.Tables[0].Rows[0]["Reprint_Remark"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select Reprint_ID,Reprint_ArticleID,Reprint_type,Reprint_UserID,Reprint_CopyFrom,Reprint_OriginID,Reprint_Guid,Reprint_Datetime,Reprint_UpDatetime,Reprint_Verify,Reprint_Lock,Reprint_State,Reprint_Delete,Reprint_Count,Reprint_Order,Reprint_Remark ");
			strSql.Append(" FROM Dd_Reprint ");
			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(" Reprint_ID,Reprint_ArticleID,Reprint_type,Reprint_UserID,Reprint_CopyFrom,Reprint_OriginID,Reprint_Guid,Reprint_Datetime,Reprint_UpDatetime,Reprint_Verify,Reprint_Lock,Reprint_State,Reprint_Delete,Reprint_Count,Reprint_Order,Reprint_Remark ");
			strSql.Append(" FROM Dd_Reprint ");
			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_Reprint";
			parameters[1].Value = "Reprint_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
	}
}

