using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Text;


namespace CallCenterApi.BLL
{
    /// <summary>
    ///文章类别表
    /// </summary>
    public partial class article_category
    {
        //  private readonly Model.sysconfig sysConfig = new BLL.sysconfig().loadConfig(); //获得系统配置信息
        private readonly DAL.article_category dal;

        public article_category()
        {
            dal = new DAL.article_category();
        }

        #region 基本方法================================
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int id)
        {
            return dal.Exists(id);
        }

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

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

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

        /// <summary>
        /// 删除多条数据
        /// </summary>
        public bool DeleteBatch(string where)
        {
            return dal.DeleteBatch(where);
        }


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

        /// <summary>
        /// 取得所有类别列表
        /// </summary>
        /// <param name="parent_id">父ID</param>
        /// <param name="channel_id">频道ID</param>
        /// <returns>DataTable</returns>
        public DataTable GetList(int parent_id)
        {
            return dal.GetList(parent_id);
        }

        /// <summary>
        /// 取得该频道下所有类别列表
        /// </summary>
        /// <param name="parent_id">父ID</param>
        /// <param name="channel_name">频道名称</param>
        /// <returns>DataTable</returns>
        public DataTable GetList(int parent_id, string channel_name)
        {
            //int channel_id = new BLL.site_channel().GetChannelId(channel_name);
            return dal.GetList(parent_id);
        }

        public List<Model.article_category> DataTableToList(DataTable dt)
        {
            List<Model.article_category> list = new List<Model.article_category>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                CallCenterApi.Model.article_category model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Model.article_category();
                    if (dt.Rows[n]["id"] != null && dt.Rows[n]["id"].ToString() != "")
                    {
                        model.id = int.Parse(dt.Rows[n]["id"].ToString());
                    }
                    if (dt.Rows[n]["parentid"] != null && dt.Rows[n]["parentid"].ToString() != "")
                    {
                        model.parentid = int.Parse(dt.Rows[n]["parentid"].ToString());
                    }
                    if (dt.Rows[n]["title"] != null && dt.Rows[n]["title"].ToString() != "")
                    {
                        model.title = dt.Rows[n]["title"].ToString();
                    }
                    if (dt.Rows[n]["sort"] != null && dt.Rows[n]["sort"].ToString() != "")
                    {
                        model.sort = int.Parse(dt.Rows[n]["sort"].ToString());
                    }
                    if (dt.Rows[n]["status"] != null && dt.Rows[n]["status"].ToString() != "")
                    {
                        model.status = int.Parse(dt.Rows[n]["status"].ToString());
                    }
                    if (dt.Columns.Contains("parenttitle"))
                    {
                        if (dt.Rows[n]["parenttitle"] != null && dt.Rows[n]["parenttitle"].ToString() != "")
                        {
                            model.parenttitle = dt.Rows[n]["parenttitle"].ToString();
                        }
                    }
                    list.Add(model);
                }
            }
            return list;
        }
        #endregion

        #region 扩展方法================================
        /// <summary>
        /// 取得指定类别下的列表(一层)
        /// </summary>
        /// <param name="top">显示条数</param>
        /// <param name="parent_id">父ID</param>
        /// <param name="channel_id">频道ID</param>
        /// <returns>DataTable</returns>
        public DataTable GetChildList(int top, int parent_id, int channel_id)
        {
            return dal.GetChildList(top, parent_id);
        }

        /// <summary>
        /// 取得该频道指定类别下的列表
        /// </summary>
        /// <param name="parent_id"></param>
        /// <param name="channel_name"></param>
        /// <returns></returns>
        public DataTable GetChildList(int top, int parent_id, string channel_name)
        {
            // int channel_id = new BLL.site_channel().GetChannelId(channel_name);
            return dal.GetChildList(top, parent_id);
        }

        /// <summary>
        /// 返回类别名称
        /// </summary>
        public string GetTitle(int id)
        {
            return dal.GetTitle(id);
        }

        /// <summary>
        /// 返回父节点的ID
        /// </summary>
        public int GetParentId(int id)
        {
            return dal.GetParentId(id);
        }

        /// <summary>
        /// 修改一列数据
        /// </summary>
        public bool UpdateField(int id, string strValue)
        {
            return dal.UpdateField(id, strValue);
        }
        #endregion
    }
}