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;

public partial class LogDetail : System.Web.UI.Page
{
    private string blogerName = string.Empty;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            if (Session["UserName"].ToString() != "") // 用户登录
            {
                this.LinkButton2.Visible = false;
                this.LinkButton3.Visible = false;
                this.Label1.Visible = true;
                this.Label2.Visible = true;
                this.LoginName1.Visible = true;
                this.Button1.Visible = true;
                this.TxtAu.Text = Session["UserName"].ToString();
            }
            else
            {
                this.LinkButton2.Visible = true;
                this.LinkButton3.Visible = true;
                this.Label2.Visible = false;
                this.Label1.Visible = false;
                this.LoginName1.Visible = false;
                this.Button1.Visible = false;
                this.TxtAu.Text = "4U博友";
            }

            WebCount wc = new WebCount();
            int Id = int.Parse(Request["log_id"]);
            wc.ForCount(Id);
        }

        DataSourceSelectArguments args = new DataSourceSelectArguments();
        this.blogerName = ((DataView)this.SqlDataSource4.Select(args)).Table.Rows[0]["bloger_name"].ToString();
    }
    protected void SqlDataSource3_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
    {
        e.Command.Parameters["@bloger_name"].Value = Request["bb"];
    }
    protected void SqlDataSource2_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
    {

    }
    protected void SqlDataSource1_Inserting(object sender, SqlDataSourceCommandEventArgs e)
    {
        e.Command.Parameters["@log_id"].Value = Request["log_id"];
        e.Command.Parameters["@contents"].Value = this.Txtcont.Text;
        e.Command.Parameters["@author"].Value = this.TxtAu.Text;
        e.Command.Parameters["@pub_date"].Value = DateTime.Now;
    }
    protected void BtnPub_Click(object sender, EventArgs e)
    {
        SqlDataSource1.Insert();
        this.Txtcont.Text = "";
        this.DataList1.DataBind();
        
    }
    protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
    {
        e.Command.Parameters["@log_id"].Value = Request["log_id"];
    }
    protected void SqlDataSource4_Selected(object sender, SqlDataSourceStatusEventArgs e)
    {
        DataSourceSelectArguments args = new DataSourceSelectArguments();
        this.SqlDataSource5.Select(args);
    }
    protected void SqlDataSource5_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
    {
        e.Command.Parameters["@bloger_name"].Value = this.blogerName;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string userName = Session["UserName"].ToString();
        if (Roles.IsUserInRole(userName, "Admin"))
        {
            Response.Redirect("~/Admin/CollegeManage.aspx");
        }
        else if (Roles.IsUserInRole(userName, "Bloger"))
        {
            Response.Redirect("~/Bloger/BlogManage/BlogConfig.aspx");
        }
        else if (Roles.IsUserInRole(userName, "Register"))
        {
            Response.Redirect("~/Register/RegisterManage.aspx");
        }
    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("~/LogView.aspx?bb=" + Request["bb"]);
    }
}
