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 System.Data.SqlClient;

public partial class master : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
                
        SqlConnection conn = new SqlConnection("Server=localhost\\SQLEXPRESS;database=bbs;Integrated security=true");
        if (Session["userid"] != null && Session["username"] != null)
        {
            username.Text = Session["username"].ToString();
            lastlogin.Text = Session["lastlogin"].ToString();
            string strsql = "select * from class,banzhu where class.id = banzhu.classid and userid='" + 
                Session["userid"].ToString() + "'";
            SqlCommand myComm = new SqlCommand(strsql, conn);
            conn.Open();
            SqlDataReader myReader = myComm.ExecuteReader();
            if (myReader.HasRows)
            {
                status.Text = "担任的社区版主";
                string strStatus = "<ul>\n";
                int i=1;
                while (myReader.Read())
                {
                    string classname = myReader["classname"].ToString();
                    System.IO.StringWriter urlClass = new System.IO.StringWriter();
                    Server.UrlEncode(classname, urlClass);
                    strStatus += "<li><a href='Manager.aspx?class="+urlClass+"'>" + classname + "</a></li>";
                    string banzhu = "banzhu" + i;
                    Session[banzhu] = classname;
                    i++;
                }
                strStatus += "</ul>";
                Session["banzhu"] = i.ToString();
                shenfen.InnerHtml = strStatus;
            }
            else
            {
                status.Text= "您是普通会员!";
            }
            myReader.Close();
            strsql = "select * from [user] where userid ='" + Session["userid"].ToString() + "'";
            myComm.CommandText = strsql;
            myReader = myComm.ExecuteReader();
            myReader.Read();
            blognum.Text = myReader["blognum"].ToString();
            myReader.Close();
            conn.Close();
            myArticle.NavigateUrl = "article.aspx?my=" + Session["userid"].ToString();
            addArticle.NavigateUrl = "articleEdit.aspx?action=add";
        }
        string sql = "select * from class";
        SqlCommand Comm = new SqlCommand(sql, conn);
        conn.Open();
        SqlDataReader Reader = Comm.ExecuteReader();
        if (Reader.HasRows)
        {
            string str = "<ul>\n";
            while (Reader.Read())
            {
                string classname = Reader["classname"].ToString();
                System.IO.StringWriter urlname = new System.IO.StringWriter();
                Server.UrlEncode(classname, urlname);
                str += "<li><a href='article.aspx?class=" +urlname.ToString() + "'>" + classname + "</a></li>\n";
            }
            str += "</ul>";
            online.InnerHtml = str;
            Reader.Close(); 
        }
        else
        {
            online.InnerHtml = "<span style='text-indent:5px'>没有论坛分区</span>";
        }
        conn.Close();
    }
}
