using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class chatmain : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //判断页面是否为第1次加载
        if (!IsPostBack)
        {
            //判断用户是否登录
            if (Session["uname"] != null)
            {
                lblname.Text = Session["uname"].ToString() + " 对";
                //用于显示当前在线用户昵称信息
                string[] userlist = Application["userlist"].ToString().Split(',');
                for (int i = 0; i < userlist.Length; i++)
                {
                    ddluser.Items.Add(userlist[i]);
                }
                //显示聊天内容
                lblchat.Text = Application["chatcon"].ToString();
            }
            else
            {
                Response.Redirect("chatlogin.aspx");
            }
        }
    }
    protected void btnsend_Click(object sender, EventArgs e)
    {
        string user = Session["uname"].ToString();
        string touser = ddluser.SelectedValue;
        //采用加锁机制，更新Application对象内容
        Application.Lock();
        Application["chatcon"] += "<br>" + user + "对" + touser + "说：" + txtme.Text;
        Application.UnLock();
        lblchat.Text = Application["chatcon"].ToString();
    }
}
