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

namespace Fm.Bussiness
{
    public class Files
    {
        /// <summary>
        /// 文件添加
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        public Boolean ADD(Fm.EntityClass.File file)
        {
            string sqlstr = "insert into Fm_file(Uid,Title,Tags,FileSize,Filetype,Sharetime,Downloads,Sharetype,Shareurl,Intro,Path,Points,Thumbnail) values";
            sqlstr = sqlstr + "("+file.Uid+",'"+file.Title+"','"+file.Tags+"','"+file.FileSize+"','"+file.Filetype+"','"+file.Sharetime.ToShortDateString()+"',"+file.downloads+",'"+file.Sharetype+"','"+file.Shareurl+"','"+file.Intro+"','"+file.Path+"',"+file.Points+",'"+file.thumbnail+"')";
            DbCommand db = DataAccess.DataAccess.db.GetSqlStringCommand(sqlstr);
            return DataAccess.DataAccess.GetData.Query<DbCommand>(db);
            
        }
        /// <summary>
        /// 文件修改
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        public Boolean Update(Fm.EntityClass.File file)
        {
            string sqlstr = "update Fm_file set Uid=" + file.Uid + ",Title='" + file.Title + "',Tags='" + file.Tags + "',FileSize='" + file.FileSize + "',Filetype='" + file.Filetype + "',Sharetime='" + file.Sharetime.ToShortDateString() + "',Downloads=" + file.downloads + ",Sharetype='" + file.Sharetype + "',Shareurl='" + file.Shareurl + "',Intro='" + file.Intro + "',Path='" + file.Path + "',Points=" + file.Points + ",Thumbnail='" + file.thumbnail + "'";
            sqlstr = sqlstr + " where Fid="+file.Fid+"";
            DbCommand db = DataAccess.DataAccess.db.GetSqlStringCommand(sqlstr);
            return DataAccess.DataAccess.GetData.Query<DbCommand>(db);
        }
        /// <summary>
        /// 文件删除
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        public Boolean Delete(Fm.EntityClass.File file)
        {
            string sqlstr = "delete from Fm_file where Fid="+file.Fid+"";
            DbCommand db = DataAccess.DataAccess.db.GetSqlStringCommand(sqlstr);
            return DataAccess.DataAccess.GetData.Query<DbCommand>(db);
        }
    }
}
