using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Spaces;
using Spaces.Controls;
public partial class Manage_UserStatistics : ManagePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
    
        if (!IsPostBack)
            BindStatus();
    }

    private void BindStatus()
    {
     
        DataRow dr =SpacesDataProvider.Instance().GetDataRow(GetSql());

        txtAccount.Text = "" + Request.QueryString["Account"];
        txtPostCount.Text = string.Format("{0}篇",dr["postCount"]);
        txtPostHitCount.Text = string.Format("{0}篇", dr["postHitCount"]);
        txtCommentCount.Text = string.Format("{0}篇", dr["CommentCount"]);
        txtDirectoryCount.Text = string.Format("{0}个", dr["DirCount"]);
        txtFileCount.Text = string.Format("{0}个", dr["FileCount"]);
        if (dr["SpaceSize"]!=DBNull.Value)
        txtFileSize.Text = string.Format("{0}", Utils.FormatSpaceSize(Convert.ToInt64(dr["SpaceSize"])));
        txtBlogCategoryCount.Text = string.Format("{0}个", dr["BlogCategoryCount"]);
        txtLinkCount.Text = string.Format("{0}个", dr["LinkCount"]);
        txtListCount.Text = string.Format("{0}个", dr["ListCount"]);
    }

    private string GetSql()
    {
         string account=Request.QueryString["Account"];
        UserConfig uc=Users.GetUserConfig(account);
        string sql = string.Empty;
        string db = Config.GetConfig().DefaultProvider;
        switch (db)
        { 
            case "Access":
                sql = @" select (select count(ID) from blog_Content where  blogID={1} and postType=1) as postCount,
(select sum(webCount)+sum(AggCount) from blog_Content where  blogID={1} and postType=1) as postHitCount,
(select count(ID) from blog_Content where  blogID={1} and postType<>1) as CommentCount,
(SELECT count([DirectoryID])  FROM [NetDisk_Directory] where account='{0}') as DirCount,
(SELECT count(r.[FileID])  FROM [NetDisk_Directory] d inner Join NetDisk_Resource r on d.DirectoryID=r.DirectoryID where d.account='{0}') as FileCount,
(SELECT sum(r.[FileSize])  FROM [NetDisk_Directory] d inner Join NetDisk_Resource r on d.DirectoryID=r.DirectoryID where d.account='{0}') as SpaceSize,
(SELECT count([CategoryID])  FROM [blog_Categories] where blogid={1}) as BlogCategoryCount,
(select count(LinkID) from [User_Links] where Account='{0}' ) as LinkCount,
(select count(ID) from [User_List] where Account='{0}') as ListCount from [tbl_Admin] ";
                sql = string.Format(sql,account,uc.BlogID);
                break;
            case "SqlServer":
                sql = @" select (select count(ID) from blog_Content where  blogID={1} and postType=1) as postCount,
(select sum(webCount)+sum(AggCount) from view_Content where  blogID={1} and postType=1) as postHitCount,
(select count(ID) from blog_Content where  blogID={1} and postType<>1) as CommentCount,
(SELECT count([DirectoryID])  FROM [NetDisk_Directory] where account='{0}') as DirCount,
(SELECT count(r.[FileID])  FROM [NetDisk_Directory] d inner Join NetDisk_Resource r on d.DirectoryID=r.DirectoryID where d.account='{0}') as FileCount,
(SELECT sum(r.[FileSize])  FROM [NetDisk_Directory] d inner Join NetDisk_Resource r on d.DirectoryID=r.DirectoryID where d.account='{0}') as SpaceSize,
(SELECT count([CategoryID])  FROM [blog_Categories] where blogid={1}) as BlogCategoryCount,
(select count(LinkID) from [User_Links] where Account='{0}' ) as LinkCount,
(select count(ID) from [User_List] where Account='{0}') as ListCount";
                sql = string.Format(sql, account, uc.BlogID);
                break;
            case "MySql":
                sql = @"   select (select count(ID) from blog_Content where  blogID={1} and postType=1) as postCount,
(select sum(webCount)+sum(AggCount) from blog_Content where  blogID={1} and postType=1) as postHitCount,
(select count(ID) from blog_Content where  blogID={1} and postType<>1) as CommentCount,
(SELECT count(`DirectoryID`)  FROM `NetDisk_Directory` where account='{0}') as DirCount,
(SELECT count(r.`FileID`)  FROM `NetDisk_Directory` d inner Join NetDisk_Resource r on d.DirectoryID=r.DirectoryID where d.account='{0}') as FileCount,
(SELECT sum(r.`FileSize`)  FROM `NetDisk_Directory` d inner Join NetDisk_Resource r on d.DirectoryID=r.DirectoryID where d.account='{0}') as SpaceSize,
(SELECT count(`CategoryID`)  FROM `blog_Categories` where blogid={1}) as BlogCategoryCount,
(select count(LinkID) from `User_Links` where Account='{0}' ) as LinkCount,
(select count(ID) from `User_List` where Account='{0}') as ListCount";
                sql = string.Format(sql, account, uc.BlogID);
                break;
        }
        return sql;
    }
}
