using System;
using System.Data;
using System.Collections.Generic;
using DotNet.FrameWork.Data;
using HaTeam.Dd.Model;
namespace HaTeam.Dd.BLL
{
	/// <summary>
	/// Dd_Link
	/// </summary>
	public partial class Dd_Link
	{
		private readonly HaTeam.Dd.DAL.Dd_Link dal=new HaTeam.Dd.DAL.Dd_Link();
		public Dd_Link()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
			return dal.GetMaxId();
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int Link_ID)
		{
			return dal.Exists(Link_ID);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int  Add(HaTeam.Dd.Model.Dd_Link model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(HaTeam.Dd.Model.Dd_Link model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int Link_ID)
		{
			
			return dal.Delete(Link_ID);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string Link_IDlist )
		{
			return dal.DeleteList(Link_IDlist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public HaTeam.Dd.Model.Dd_Link GetModel(int Link_ID)
		{
			
			return dal.GetModel(Link_ID);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public HaTeam.Dd.Model.Dd_Link GetModelByCache(int Link_ID)
		{
			
			string CacheKey = "Dd_LinkModel-" + Link_ID;
			object objModel = DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(Link_ID);
					if (objModel != null)
					{
						int ModelCache = ConfigHelper.GetConfigInt("ModelCache");
						DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (HaTeam.Dd.Model.Dd_Link)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<HaTeam.Dd.Model.Dd_Link> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<HaTeam.Dd.Model.Dd_Link> DataTableToList(DataTable dt)
		{
			List<HaTeam.Dd.Model.Dd_Link> modelList = new List<HaTeam.Dd.Model.Dd_Link>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				HaTeam.Dd.Model.Dd_Link model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new HaTeam.Dd.Model.Dd_Link();
					if(dt.Rows[n]["Link_ID"].ToString()!="")
					{
						model.Link_ID=int.Parse(dt.Rows[n]["Link_ID"].ToString());
					}
					if(dt.Rows[n]["User_ID"].ToString()!="")
					{
						model.User_ID=int.Parse(dt.Rows[n]["User_ID"].ToString());
					}
					model.Link_Title=dt.Rows[n]["Link_Title"].ToString();
					model.Link_Address=dt.Rows[n]["Link_Address"].ToString();
					model.Link_Description=dt.Rows[n]["Link_Description"].ToString();
					model.Link_Tag=dt.Rows[n]["Link_Tag"].ToString();
					if(dt.Rows[n]["Link_OriginId"].ToString()!="")
					{
						model.Link_OriginId=int.Parse(dt.Rows[n]["Link_OriginId"].ToString());
					}
					if(dt.Rows[n]["Link_PublishMode"].ToString()!="")
					{
						model.Link_PublishMode=int.Parse(dt.Rows[n]["Link_PublishMode"].ToString());
					}
					if(dt.Rows[n]["Link_PutTop"].ToString()!="")
					{
						if((dt.Rows[n]["Link_PutTop"].ToString()=="1")||(dt.Rows[n]["Link_PutTop"].ToString().ToLower()=="true"))
						{
						model.Link_PutTop=true;
						}
						else
						{
							model.Link_PutTop=false;
						}
					}
					if(dt.Rows[n]["Link_Fever"].ToString()!="")
					{
						model.Link_Fever=int.Parse(dt.Rows[n]["Link_Fever"].ToString());
					}
					model.Link_Guid=dt.Rows[n]["Link_Guid"].ToString();
					if(dt.Rows[n]["Link_Datetime"].ToString()!="")
					{
						model.Link_Datetime=DateTime.Parse(dt.Rows[n]["Link_Datetime"].ToString());
					}
					if(dt.Rows[n]["Link_UpDatetime"].ToString()!="")
					{
						model.Link_UpDatetime=DateTime.Parse(dt.Rows[n]["Link_UpDatetime"].ToString());
					}
					if(dt.Rows[n]["Link_Verify"].ToString()!="")
					{
						model.Link_Verify=int.Parse(dt.Rows[n]["Link_Verify"].ToString());
					}
					if(dt.Rows[n]["Link_Lock"].ToString()!="")
					{
						model.Link_Lock=int.Parse(dt.Rows[n]["Link_Lock"].ToString());
					}
					if(dt.Rows[n]["Link_State"].ToString()!="")
					{
						model.Link_State=int.Parse(dt.Rows[n]["Link_State"].ToString());
					}
					if(dt.Rows[n]["Link_Delete"].ToString()!="")
					{
						model.Link_Delete=int.Parse(dt.Rows[n]["Link_Delete"].ToString());
					}
					if(dt.Rows[n]["Link_Count"].ToString()!="")
					{
						model.Link_Count=int.Parse(dt.Rows[n]["Link_Count"].ToString());
					}
					if(dt.Rows[n]["Link_Order"].ToString()!="")
					{
						model.Link_Order=int.Parse(dt.Rows[n]["Link_Order"].ToString());
					}
					model.Link_Remark=dt.Rows[n]["Link_Remark"].ToString();
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  Method
	}
}

