验证中...
8月18日(周六)成都源创会火热报名中,四位一线行业大牛与你面对面,探讨区块链技术热潮下的冷思考。
语言: ASP
分类: Web开发技术
最后更新于 2018-05-27 13:56
片段 1 片段 2 片段 3 片段 4
现在还有一些问题,比如说退出聊天室之后用户名不知道怎么从列表里删除,发消息不能换行,发完消息之后光标不会停在输入消息的框里
原始数据 复制代码
//登录界面
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
public partial class login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
string name = Request.Form["TextBox1"];
string pwd = Request.Form["TextBox2"];
}
else
{
if (CheckBox1.Checked && Request.Cookies["name"].Value != "" && Request.Cookies["pwd"].Value != null)
{
string name = Request.Cookies["name"].Value.ToString();
string pwd = Request.Cookies["pwd"].Value.ToString();
DataSet dt2 = SqlHelper.ExecuteDataset(CommandType.Text, "select * from [abc].[dbo].[Table_3] where Name='" + name + "'and Pwd='" + pwd + "'");
if (dt2.Tables[0].Rows.Count > 0)
{
Response.Cookies["name"].Expires = DateTime.Now;
Response.Cookies["pwd"].Expires = DateTime.Now;
Response.Write("<script>alert('登录成功!');location.href='modify2.aspx';</script>");
}
else
{
Response.Cookies["name"].Expires = DateTime.Now.AddDays(-1);
Response.Cookies["pwd"].Expires = DateTime.Now.AddDays(-1);
}
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string name = TextBox1.Text;
string pwd = TextBox2.Text;
DataSet dt = SqlHelper.ExecuteDataset(CommandType.Text, "select * from [abc].[dbo].[Table_3] where Name='" + name + "'");
if (dt.Tables[0].Rows.Count == 0)
{
Response.Write("<script>alert('用户名不存在!')</script>");
return;
}
DataSet dt2 = SqlHelper.ExecuteDataset(CommandType.Text, "select * from [abc].[dbo].[Table_3] where Name='" + name + "'and Pwd='" + pwd + "'");
if (dt2.Tables[0].Rows.Count == 0)
{
Response.Write("<script>alert('密码错误!')</script>");
return;
}
else
{
Session["a"] = name;
Response.Write("<script>alert('登录成功!');location.href='room2.aspx';</script>");
return;
}
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
Response.Redirect("register.aspx");
return;
}
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
}
}
//gloabal界面
<%@ Application Language="C#" %>
<script runat="server">
void Application_Start(object sender, EventArgs e)
{
// 在应用程序启动时运行的代码
string user = "";
Application["user"] = null;
Application["num"] = 0;//聊天记录的数量
string chats = Convert.ToString(Application["chats"]);
}
void Application_End(object sender, EventArgs e)
{
// 在应用程序关闭时运行的代码
Application["user"] = "";
Application["chats"] = "";
}
void Application_Error(object sender, EventArgs e)
{
// 在出现未处理的错误时运行的代码
}
void Session_Start(object sender, EventArgs e)
{
// 在新会话启动时运行的代码
}
void Session_End(object sender, EventArgs e)
{
// 在会话结束时运行的代码。
// 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为
// InProc 时,才会引发 Session_End 事件。如果会话模式设置为 StateServer
// 或 SQLServer,则不引发该事件。
}
</script>
//聊天室代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class room2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Application.UnLock();
string user = Session["a"].ToString();
Application["user"] += user;
TextBox3.Text = Application["user"].ToString();
Application.Lock();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Application.UnLock();
if (TextBox2.Text == null)
{
Response.Write("<script>alert('空!')</script>");
return;
}
else
{
int num = (int)Application["num"];
if (num == 0 || num >= 20)
{
num = 0;
Application["chats"] = Session["a"].ToString() + " " + DateTime.Now.ToLongTimeString() + " " + TextBox2.Text;
}
else
{
Application["chats"] += Session["a"].ToString() + " " + DateTime.Now.ToLongTimeString() + " " + TextBox2.Text;
}
num++;
Application["num"] = num;
TextBox1.Text = Application["chats"].ToString() + "\r";
TextBox2.Text = "";
}
Application.Lock();
}
protected void Button2_Click(object sender, EventArgs e)
{
Application.UnLock();
//string user = Session["a"].ToString();
Session["a"] = null;
Application["chats"] = null;
Application.Lock();
Response.Redirect("login.aspx");
}
}
屏幕截图(49).png
屏幕截图(50).png
屏幕截图(51).png

评论列表( 0 )

你可以在登录后,发表评论