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;
using System.Data.OleDb;

public partial class chatlogin : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //页面加载事件
        lblnum.Text = Application["mcount"].ToString();
        if (!IsPostBack)
        {
            if (Request.Cookies["ckname"] != null)
            {
                txtname.Text = Request.Cookies["ckname"].Value;
            }
        }
    }
    protected void btnlogin_Click(object sender, EventArgs e)
    {
        //用户登录单击事件
        string uname = txtname.Text.Trim();
        string upwd = txtpwd.Text.Trim();
        string strcon = System.Configuration.ConfigurationManager.AppSettings["strcon"].ToString();
        OleDbConnection conn = new OleDbConnection(strcon);
        string sql0 = "select count(*) from chatmem where mname='"+uname.ToLower()+"' and mpwd='"+upwd.ToLower()+"'";
        conn.Open();
        OleDbCommand ocmd = new OleDbCommand(sql0, conn);
        if (Convert.ToInt32(ocmd.ExecuteScalar()) > 0)
        {
            //判断用户是否选择“记住我的信息”复选项
            if (ckbrem.Checked)
            {
                //保存用户Cookie信息
                Response.Cookies["ckname"].Value = uname;
                Response.Cookies["ckname"].Expires = DateTime.Now.AddDays(15);
            }
            //保存用户名Session信息
            Session["uname"] = uname;
            Application["userlist"] += "," + uname;
            Response.Redirect("chatmain.aspx");
        }
        else
        {
            Response.Write("<script>alert('用户信息不正确！');</script>");
        }
    }
    protected void btncancel_Click(object sender, EventArgs e)
    {
        //取消单击事件
        Response.AddHeader("Refresh", "0");
    }
}
