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 Register_RegisterManage : System.Web.UI.Page
{
    private string userName;    // 保存用户名

    protected void Page_Load(object sender, EventArgs e)
    {
        this.userName = this.User.Identity.Name;    // 获得当前用户名
    }

    protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
    {
        e.Command.Parameters["@bloger_name"].Value = this.userName;
    }
    
    protected void InsertButton_Click(object sender, EventArgs e)
    {


        this.SqlDataSource1.Insert();

    }

    protected void SqlDataSource1_Inserting(object sender, SqlDataSourceCommandEventArgs e)
    {
        if (IsPostBack)
        {            
            Control myControl1 = this.FormView1.FindControl("DropDownList1");
            e.Command.Parameters["@college_id"].Value = int.Parse(((DropDownList)myControl1).SelectedValue);
            e.Command.Parameters["@bloger_name"].Value = this.userName;
        }
    }
    protected void FormView1_DataBound(object sender, EventArgs e)
    {
        if (this.FormView1.DataItemCount > 0)
        {
            this.FormView1.ChangeMode(FormViewMode.Edit);
        }
        else
        {
            this.FormView1.ChangeMode(FormViewMode.Insert);
        }
    }
    protected void SqlDataSource1_Updating(object sender, SqlDataSourceCommandEventArgs e)
    {
        if (IsPostBack)
        {
            Control myControl1 = this.FormView1.FindControl("DropDownList2");
            
            e.Command.Parameters["@college_id"].Value = int.Parse(((DropDownList)myControl1).SelectedValue);

            e.Command.Parameters["@original_bloger_name"].Value = this.userName;
        }
    }
    protected void InsertButton_Click1(object sender, EventArgs e)
    {
        Control myControl1 = this.FormView1.FindControl("DropDownList1");
        int id = int.Parse(((DropDownList)myControl1).SelectedValue);
        BlogerCount bc = new BlogerCount();
        bc.ForCount(id);

        Response.Write("<script>alert('信息已提交，请等待管理员审核。')</script>");
               
    }
    protected void FormView1_PageIndexChanging(object sender, FormViewPageEventArgs e)
    {

    }

}
