⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 errol.aspx.cs

📁 一个 用Ajax实现聊天室的简单例子 不全的地方指点
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ChatBLL;
using ChatModel;

public partial class Errol : System.Web.UI.Page
{
    UserService usc = new UserService();
    int userID = 0;  


    protected void Page_Load(object sender, EventArgs e)
    {
        userID=Convert.ToInt32(Session["userID"]);
        if (!IsPostBack)
        {
            ViewState["face"] = 1;
            if (userID == 0)  //新用户
            {
                imgSelect.ImageUrl = "~/Face/" + ViewState["face"].ToString() + ".bmp";
                lblTitle.Text = "注册新用户";
            }

            else  //修改用户
            {
                txtUser.Enabled = false;
                lblTitle.Text = "修改资料";
                setControl();
            }
        }
    }

    //赋值给控键
    void setControl()
    {
        User us = usc.getUserByID(userID);
        txtUser.Text = us.userName;
        txtName.Text = us.name;
        txtPass.Text = us.password;
        txtAffirmPass.Text = us.password;
        if ("男".Equals(us.sex))
            rblSex.SelectedValue = "男";
        else
            rblSex.SelectedValue = "女";
        txtAddress.Text = us.address;
        txtPhone.Text = us.phone;
        txtEmail.Text = us.mail;
        imgSelect.ImageUrl = "~/Face/" + us.face.ToString() + ".bmp";
    }

    //将控键赋值给User类
    User setUser()
    {
        User us = new User();
        us.ID = userID;
        us.userName = txtUser.Text;
        us.password = txtPass.Text;
        us.name = txtName.Text;
        us.sex = rblSex.SelectedValue;
        us.face = Convert.ToInt32(ViewState["face"]);
        us.address = txtAddress.Text;
        us.phone = txtPhone.Text;
        us.mail = txtEmail.Text;
        return us;
    }

    //选择头像
    protected void imgSelect_Click(object sender, ImageClickEventArgs e)
    {
        dlFace.DataSource = usc.getAllFace();
        dlFace.DataBind();
        divFace.Style.Add("display", "block");  //显示层
    }

    //头像的路径
    public string getUrl(object obj)
    {
        string url ="~/Face/" + obj.ToString() + ".bmp";
        return url;
    }

    //选择后的头像
    protected void dlFace_ItemCommand(object source, DataListCommandEventArgs e)
    {
        int n = e.Item.ItemIndex; 
        dlFace.Items[n].BackColor = System.Drawing.Color.Red;  //选中标记
        ViewState["face"] = dlFace.DataKeys[n].ToString();  //选中的头像
        imgSelect.ImageUrl = "~/Face/" + ViewState["face"].ToString() + ".bmp";
        divFace.Style.Add("display", "none");  //隐藏层
    }

    //用户名是否重复
    protected void txtUser_TextChanged(object sender, EventArgs e)
    {
        bool flag = usc.isRepeat(txtUser.Text);
        if (flag)
            lblError.Text = "用户名重复";
        else
            lblError.Text = "";
    }


    protected void btnAccept_Click(object sender, ImageClickEventArgs e)
    {
        User us = setUser();
        if (userID == 0)
            usc.addUser(us);
        else
        {
            usc.updUser(us);
            Response.Redirect("Chat.aspx");
        }

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -