using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Data.Common;
using System.Data;

namespace Fm.Bussiness
{
    public class Comments
    {
        /// <summary>
        /// 获取评论楼层
        /// </summary>
        /// <param name="com"></param>
        /// <returns></returns>
        public int GetLou(Fm.EntityClass.Comments com)
        {
            int lou =1;
            public_select ps = new public_select();
            DataView dv = ps.Getps("Fm_comment","max(lou) as amount,count(lou) as num","docid="+com.docid+"");
            if (dv.Count > 0)
            {
                if (int.Parse(dv[0]["num"].ToString())>0)
                {
                    lou = int.Parse(dv[0]["amount"].ToString()) + 1;
                }
            }
            return lou;
        }
        /// <summary>
        /// 新评论添加
        /// </summary>
        /// <param name="com"></param>
        /// <returns></returns>
        public Boolean CommentAdd(Fm.EntityClass.Comments com)
        {
            String sqlstr = "insert into Fm_comment(username,content,writetime,docid,ip,lou,support,against) values('"+com.username+"','"+com.content+"','"+com.writetime.ToString()+"',"+com.docid+",'"+com.ip+"',"+com.lou+","+com.support+","+com.against+")";
            DbCommand db = DataAccess.DataAccess.db.GetSqlStringCommand(sqlstr);
            return DataAccess.DataAccess.GetData.Query<DbCommand>(db);

        }
        /// <summary>
        /// 评论的删除(按照评论ID删除)
        /// </summary>
        /// <param name="com"></param>
        /// <returns></returns>
        public Boolean CommentDel(Fm.EntityClass.Comments com)
        {
            DbCommand db = DataAccess.DataAccess.db.GetSqlStringCommand("delete from Fm_comment where comid="+com.comid+"");
            return DataAccess.DataAccess.GetData.Query<DbCommand>(db);
        }
        /// <summary>
        /// 评论的删除(按照文章ID删除)
        /// </summary>
        /// <param name="com"></param>
        /// <returns></returns>
        public Boolean CommentDelToDoc(Fm.EntityClass.Comments com)
        {
            DbCommand db = DataAccess.DataAccess.db.GetSqlStringCommand("delete from Fm_comment where docid=" + com.docid + "");
            return DataAccess.DataAccess.GetData.Query<DbCommand>(db);
        }
    }
}
