?? userinfo.aspx.cs
字號:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace TestOnline
{
/// <summary>
/// userInfo 的摘要說明。
/// </summary>
public class userInfo : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lbl_stuId;
protected System.Web.UI.WebControls.Label lbl_stuName;
protected System.Web.UI.WebControls.DropDownList ddl_course;
protected System.Web.UI.WebControls.ImageButton ImageButton1;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.ImageButton ImageButton3;
protected System.Web.UI.WebControls.Label lbl_noResult;
protected System.Web.UI.WebControls.TextBox tbx_oldPwd;
protected System.Web.UI.WebControls.TextBox tbx_newPwd1;
protected System.Web.UI.WebControls.TextBox tbx_newPwd2;
protected System.Web.UI.WebControls.ImageButton Ibtn_ok;
protected System.Web.UI.WebControls.Label lbl_name;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此處放置用戶代碼以初始化頁面
if(Session["stuId"]==null)
Response.Redirect("login.aspx");
else
{
if(!Page.IsPostBack)
{BindGrid();
string stuId=Convert.ToString(Session["stuId"]);
lbl_stuId.Text=stuId;
string stuName=(new projClass()).getUserName(stuId);
lbl_stuName.Text=stuName;
DataSet ds=new DataSet();
ds=(new projClass()).getCourses();
foreach(DataRow row in ds.Tables[0].Rows)
{
ddl_course.Items.Add(row["courseName"].ToString());
}
}
}
}
#region Web 窗體設計器生成的代碼
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 該調用是 ASP.NET Web 窗體設計器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內容。
/// </summary>
private void InitializeComponent()
{
this.ImageButton3.Click += new System.Web.UI.ImageClickEventHandler(this.ImageButton3_Click);
this.ImageButton1.Click += new System.Web.UI.ImageClickEventHandler(this.ImageButton1_Click);
this.DataGrid1.SelectedIndexChanged += new System.EventHandler(this.DataGrid1_SelectedIndexChanged);
this.Ibtn_ok.Click += new System.Web.UI.ImageClickEventHandler(this.Ibtn_ok_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
void BindGrid()
{ string stuId=Convert.ToString(Session["stuId"]);
DataSet ds=new DataSet();
ds=(new projClass()).getStuScore(stuId);
DataTable dt=ds.Tables["stuInfo"];
DataView dv=new DataView(dt);
DataGrid1.DataSource=dv;
int count=dv.Count;
if(count==0)
{
lbl_noResult.Visible=true;
DataGrid1.Visible=false;
}
DataGrid1.DataBind();
}
private void ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
string stuId=Convert.ToString(Session["stuId"]);
string courseName=ddl_course.SelectedItem.Text.Trim();
string courseId=(new projClass()).getCourseIdAsCourseName(courseName);
bool ifTest=(new projClass()).getIfTest(courseId);
if(ifTest)
{
int count=(new projClass()).ifCourseHasTest(stuId,courseId);
if(count==0)
{
Session["courseId"]=courseId;
Response.Redirect("createTest.aspx?"+courseId+"&"+stuId);
}
else
Response.Write("<script>alert(\"該科目您已經考試過了,不能再次考試!\");</script>");
}else Response.Write("<script>alert(\"該科目目前不能考試!請聯系管理員開通考試!\");</script>");
}
private void ImageButton3_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
Session["stuId"]=null;
// Session.RemoveAll();
Response.Redirect("login.aspx");
}
private void Ibtn_ok_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
string stuId=Convert.ToString(Session["stuId"]);
string stuPwd=tbx_oldPwd.Text;
string newPwd1=tbx_newPwd1.Text;
string newPwd2=tbx_newPwd2.Text;
if(newPwd1==""||newPwd2=="")
Response.Write("<script>alert(\"密碼不能為空\");</script>");
else
{
int count=(new projClass()).getUser(stuId,stuPwd);
if(count==0)
{
Response.Write("<script>alert(\"密碼錯誤!請重新輸入\");</script>");
}
else
{
if(!newPwd1.Equals(newPwd2))
Response.Write("<script>alert(\"兩次密碼不一致!請重新輸入!\");</script>");
else
{
int count1=(new projClass()).updateStuPwd(stuId,newPwd1);
if(count1==1)
Response.Write("<script>alert(\"密碼修改成功!\");</script>");
else Response.Write("<script>alert(\"更新失敗!\");</script>");
}
}
}
}
private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -