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

📄 chatroom.aspx.cs

📁 this is the file to chat in web
💻 CS
字号:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
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;
[AjaxPro.AjaxNamespace("AjaxProChat")]
public partial class chatroom : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //note the initialization code for the framework AjaxPro.NET
        // Register Ajax.NET methods from this class
        AjaxPro.Utility.RegisterTypeForAjax(typeof(chatroom));

    }
    /// <summary>
    /// Get the recent messages
    /// </summary>
    /// <param name="strUsername">Username</param>
    /// <returns>the DataSet of the recent messages</returns>
    [AjaxPro.AjaxMethod]
    public  DataSet GetRecentMsg(string strUsername)
    {
        //the returned DataSet
        DataSet ds = new DataSet();

        //the data connection
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["msn_Data_ConnStr"].ConnectionString);

        // SQL command
        SqlCommand cmd = conn.CreateCommand();
        cmd.CommandText = string.Format(
            "GetRecentMsg '{0}','{1}', {2}",
            User.Identity.Name, strUsername, 8);

        //data adapter definition
        SqlDataAdapter da = new SqlDataAdapter(cmd);

        try
        {
            //fill in the messages
            da.Fill(ds);
        }
        catch (SqlException)
        {
        }
        finally
        {
            // close the connection
            conn.Close();
        }

        return ds;
    }

    /// <summary>
    /// Send messages
    /// </summary>
    /// <param name="strUsername">Username</param>
    /// <param name="strContent">Content</param>
    [AjaxPro.AjaxMethod]
    public  void SendMessage(string strUsername, string strContent)
    {
        // the data connection
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["msn_Data_ConnStr"].ConnectionString);

        // SQL command
        SqlCommand cmd = conn.CreateCommand();
        cmd.CommandText = string.Format("SendMessage '{0}','{1}', '{2}'",
            User.Identity.Name, strUsername, strContent);

        try
        {
            // open the data connection
            conn.Open();

            // execute the SQL command
            cmd.ExecuteNonQuery();
        }
        catch (SqlException)
        {
        }
        finally
        {
            //close the connection
            conn.Close();
        }
    }

    /// <summary>
    ///obtain new messages
    /// </summary>
    /// <returns>the DataSet of the new messages</returns>
    [AjaxPro.AjaxMethod]
    public DataSet chatroomGetNewMessage()
    {
        // returned dataset
        DataSet ds = new DataSet();

        //data connection
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["msn_Data_ConnStr"].ConnectionString);

        // SQL command
        SqlCommand cmd = conn.CreateCommand();
        cmd.CommandText = string.Format("GetNewMessage '{0}'", User.Identity.Name);

        // data adapter
        SqlDataAdapter da = new SqlDataAdapter(cmd);

        try
        {
            // fill messages data into DataSet
            da.Fill(ds);
        }
        catch (SqlException)
        {
        }
        finally
        {
            //close the connection
            conn.Close();
        }

        return ds;
    }

}

⌨️ 快捷键说明

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