温馨提示:代码在线浏览功能只能做为源码浏览参考,不能展示项目的全部,如果想更进一步了解该代码请下载:NChat简易聊天室源码(.Net 3.5,LINQ,AJAX)
当前文件路径:NChat/Web/Room.aspx.cs

1using System; 2
using System.Collections; 3
using System.Configuration; 4
using System.Data; 5
using System.Linq; 6
using System.Web; 7
using System.Web.Security; 8
using System.Web.UI; 9
using System.Web.UI.HtmlControls; 10
using System.Web.UI.WebControls; 11
using System.Web.UI.WebControls.WebParts; 12
using System.Xml.Linq; 13
14
using DB = NChart.DBHelper; 15
using System.Collections.Generic; 16
using NChat.Common; 17
//该源码下载自www.51aspx.com(51aspx.com) 18
19
namespace NChat.Web 20
{ 21
public partial class Room : System.Web.UI.Page 22
{ 23
DB::User u; 24
protected void Page_Load(object sender, EventArgs e) 25
{ 26
if (Session.Count > 0 && Session["SUser"] != null) 27
{ 28
u = (DB::User)Session["SUser"]; 29
if (u.ID < 1) 30
{ 31
Session.RemoveAll(); 32
Response.Redirect("Default.aspx"); 33
} 34
} 35
else 36
Response.Redirect("Default.aspx"); 37
38
if (!Page.IsPostBack) 39
{ 40
StaticHelper.OnlineUserClear(); 41
ListInit(); 42
} 43
} 44
45
protected void Button1_Click(object sender, EventArgs e) 46
{ 47
StaticHelper.ActiveUserUpdate(new ActiveUserModel(u.Name, DateTime.Now)); 48
if (!string.IsNullOrEmpty(TextBox1.Text)) 49
{ 50
string msg = TextBox1.Text.Trim(); 51
msg = msg.Replace("|", "&{/}$"); 52
string to = "大家"; 53
if (UserList.SelectedItem != null && !string.IsNullOrEmpty(UserList.SelectedItem.Text)) 54
{ 55
to = UserList.SelectedItem.Text; 56
UserList.SelectedItem.Selected = false; 57
} 58
msg = u.Name + "|" + to + "|" + msg; 59
StaticHelper.MsgListAdd(msg); 60
61
TextBox1.Text = ""; 62
} 63
} 64
65
protected void Timer1_Tick(object sender, EventArgs e) 66
{ 67
IEnumerable<string> list = StaticHelper.MsgList(u.ID); 68
69
foreach (var item in list) 70
{ 71
string[] items = item.Split('|'); 72
items[2] = items[2].Replace("&{/}$", "|"); 73
if (items[1] == u.Name || items[1] == "大家" || items[0] == u.Name) 74
{ 75
if (items[0] == u.Name) 76
items[0] = "<font color=\"blue\">你</font>"; 77
if (items[1] == u.Name) 78
items[1] = "<font color=\"blue\">你</font>"; 79
MsgText.Text = "<strong>" + items[0] + "</strong>对<strong>" + items[1] + "</strong>说:" + items[2] + "<br/>" + MsgText.Text; 80
} 81
} 82
} 83
84
protected void Timer2_Tick(object sender, EventArgs e) 85
{ 86
if (!StaticHelper.UserListStatic.Contains(u.Name)) 87
Session.RemoveAll(); 88
89
ListInit(); 90
} 91
92
void ListInit() 93
{ 94
UserList.Items.Clear(); 95
UserList.Items.Add("大家"); 96
foreach (var item in StaticHelper.UserListStatic) 97
{ 98
//string temp = "<a href=\"javascript:;\" onserverclick=\"BulletedList1_Click\" runat=\"server\">" + item + "</a>"; 99
UserList.Items.Add(item); 100
} 101
} 102
103
104
protected void UserList_SelectedIndexChanged(object sender, EventArgs e) 105
{ 106
//CheckBoxList list = (CheckBoxList)sender; 107
//if (list.SelectedItem != null) 108
// DropDownListAdd(list.SelectedItem.Text); 109
} 110
} 111
} 112





}
}