protected void btnLogin_Click(object sender, EventArgs e) { Application.Lock(); int P_int_num; //在线人数 string P_str_name; //登录用户 string P_str_names; //已在线的用户名 string[] P_str_user; //用户在线数组 P_int_num = int.Parse(Application["userNum"].ToString()); if (TextBox1.Text == "") { Response.Write("<script>alert('用户名不能为空')</script>"); TextBox1.Focus(); } else { P_str_name = TextBox1.Text.Trim(); P_str_names = Application["user"].ToString(); P_str_user = P_str_names.Split(','); for (int i = 0; i <= P_int_num - 1; i++) { if (P_str_name == P_str_user[i].Trim()) { int P_int_judge = 1; Response.Redirect("Login.aspx?value=" + P_int_judge); } } if (P_int_num == 0) { Application["user"] = P_str_name.ToString(); } else { Application["user"] = Application["user"] + "," + P_str_name.ToString(); } P_int_num += 1; Application["userNum"] = P_int_num; Session["userName"] = TextBox1.Text.Trim(); Application.UnLock(); Response.Redirect("Default.aspx"); } }
protected void Timer1_Tick(object sender, EventArgs e) { txtContent.Text = ""; int P_int_current = Convert.ToInt32(Application["current"]); //current当前聊天记录的总数 ArrayList ItemList = new ArrayList(); Application.Lock(); string P_str_names; //已在线的用户名 string[] P_str_user; //用户在线数组 int P_int_num = Convert.ToInt32(Application["userNum"]); P_str_names = Application["user"].ToString();//用户名, 其实是一个以 , 分割的字符串的组织形式 P_str_user = P_str_names.Split(','); for (int i = (P_int_num - 1); i >= 0; i--) { if (P_str_user[i].ToString() != "") { ItemList.Add(P_str_user[i].ToString()); } } lbList.DataSource = ItemList; lbList.DataBind(); //绑定用户名 string P_str_chats = Application["chats"].ToString(); string[] P_str_chat = P_str_chats.Split(','); //往文本框中写入聊天记录 for (int i = P_str_chat.Length - 1; i >= 0; i--) { if (P_int_current == 0) { txtContent.Text = P_str_chat[i].ToString(); } else { txtContent.Text = txtContent.Text + "\n" + P_str_chat[i].ToString(); } } Application.UnLock(); UpdatePanel1.Update(); //UpdatePanel用来实现局部更新 }
protected void Page_Load(object sender, EventArgs e) { Label2.Text = DateTime.Now.ToString(); int P_int_current = Convert.ToInt32(Application["Current"]); Application.Lock(); string P_str_chats = Application["Chats"].ToString(); string[] P_str_chat = P_str_chats.Split(','); for (int i = P_str_chat.Length - 1; i >= 0; i--) { if (P_int_current == 0) { this.txtContex.Text = P_str_chat[i].ToString(); } else { txtContex.Text = txtContex.Text + "\n" + P_str_chat[i].ToString(); } } ArrayList ItemList = new ArrayList(); string P_str_names; //已在线的用户名 string[] P_str_user; //用户在线数组 int P_int_num = Convert.ToInt32(Application["userNum"]); P_str_names = Application["user"].ToString(); P_str_user = P_str_names.Split(','); for (int i = (P_int_num - 1); i >= 0; i--) { if (P_str_user[i].ToString() != "") { ItemList.Add(P_str_user[i].ToString()); } } lbList.DataSource = ItemList; lbList.DataBind(); Application.UnLock(); }
protected void Page_Load(object sender, EventArgs e) { ArrayList ItemList = new ArrayList(); Application.Lock(); string P_str_names; //已在线的用户名 string[] P_str_user; //用户在线数组 int P_int_num = Convert.ToInt32(Application["userNum"]); P_str_names = Application["user"].ToString(); P_str_user = P_str_names.Split(','); for (int i = (P_int_num - 1); i >= 0; i--) { if (P_str_user[i].ToString() != "") { ItemList.Add(P_str_user[i].ToString()); } } lbList.DataSource = ItemList; lbList.DataBind(); Application.UnLock(); }
protected void Button1_Click(object sender, EventArgs e) { string strsql_query = ""; if (IDBox.Text != string.Empty && passwdBox.Text != string.Empty) { string ID2 = IDBox.Text.Trim().ToString(); string passwd = passwdBox.Text.Trim().ToString(); string strcon = "Data Source=(local);Initial Catalog=课设;Integrated Security=True"; SqlConnection conn = new SqlConnection(strcon); conn.Open(); if (stuButton.Checked) { strsql_query = string.Format("select * from Tb_SLogin where Sno='{0}' and Spassword='******'", ID2, passwd); } else if (adminButton.Checked) { strsql_query = string.Format("select * from Tb_Admin where id='{0}' and Password='******'", ID2, passwd); } SqlCommand cmd_query = new SqlCommand(strsql_query, conn); SqlDataReader dr = cmd_query.ExecuteReader(); if (dr.HasRows) { dr.Read(); if (stuButton.Checked) { Login.name = dr["Sname"].ToString(); welcome = "欢迎 " + name + " 同学登录本系统"; Session["name"] = name; } else if (adminButton.Checked) { Login.name = dr["id"].ToString(); } dr.Close(); if (stuButton.Checked) { Session["pass"] = passwd; Session["IDnew"] = ID2; Response.Write(welcome); // MessageBox.Show(welcome); Application.Lock(); int P_int_num; //在线人数 string P_str_name; //登录用户 string P_str_names; //已在线的用户名 string[] P_str_user; //用户在线数组 P_int_num = int.Parse(Application["userNum"].ToString()); P_str_name = IDBox.Text.Trim(); P_str_names = Application["user"].ToString(); P_str_user = P_str_names.Split(','); for (int i = 0; i <= P_int_num - 1; i++) { if (P_str_name == P_str_user[i].Trim()) { int P_int_judge = 1; Response.Redirect("Login.aspx?value=" + P_int_judge); } } if (P_int_num == 0) { Application["user"] = P_str_name.ToString(); } else { Application["user"] = Application["user"] + "," + P_str_name.ToString(); } P_int_num += 1; Application["userNum"] = P_int_num; Session["userName"] = IDBox.Text.Trim(); Application.UnLock(); Response.Redirect("StudentPage.aspx"); } else { //adminPage main = new adminPage(); // main.Show(); Response.Redirect("AdminPage.aspx"); } Visible = false; } else { Response.Write("<script>alert('用户名或密码错误')</script>"); // MessageBox.Show("用户名或密码错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); passwdBox.Focus(); } } else { Response.Write("<script>alert('用户名或密码不能为空')</script>"); //MessageBox.Show("用户名或密码不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } }