using System;
using System.Data;
using System.Data.SqlClient;
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 student : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //数据库的连接
            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = "Data Source=.;Initial Catalog=usersinfo;Integrated Security=SSPI";
            //存储过程实例化
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            //选出符合SQL语句执行后的列的全部结果
            cmd.CommandText = "select * from users where uid = @id";
            cmd.Parameters.Add(new SqlParameter("@id", SqlDbType.VarChar, 50));
            cmd.Parameters["@id"].Value = Session["uid"].ToString();
            conn.Open();
            //读取1行记录
            SqlDataReader dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                Label1.Text = dr[0].ToString();
                Label2.Text = dr[1].ToString();
                Label3.Text = dr[2].ToString();
                Label4.Text = dr[3].ToString();
                Label5.Text = dr[4].ToString();
                Label6.Text = dr[5].ToString();
                Label7.Text = dr[7].ToString();
                TextBox1.Text = dr[8].ToString();
                TextBox2.Text = dr[9].ToString();
                TextBox3.Text = dr[10].ToString();
            }
            conn.Close();
        }
        
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection conn = new SqlConnection();
        conn.ConnectionString = "Data Source=.;Initial Catalog=usersinfo;Integrated Security=SSPI";
        conn.Open();
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = conn;
        cmd.CommandText = "update users set uaddress='" + TextBox1.Text + "',uphone='" + TextBox2.Text + "',uemail='" + TextBox3.Text + "' where uid='" + Session["uid"].ToString() + "'";
        int i = cmd.ExecuteNonQuery();
        if (i == 0)
        {
            Response.Write("<script language='javascript'>alert('修改信息失败!');window.location.href='admin.aspx';</script>");
        }
        else
        {
            Response.Write("<script language='javascript'>alert('修改信息成功!');window.location.href='admin.aspx';</script>");
        }
        conn.Close();
    }
}