zoukankan      html  css  js  c++  java
  • 在线聊天.NET源码 即时

    外部的JS引用进来。搜家居项目里有

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="0test.aspx.cs" Inherits="Stores._0test"
        ValidateRequest="false" %>
        
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>聊天窗口</title>
        <script src="http://ayue05.blog.163.com/blog/Scripts/jquery-1.3.2.min.js" type="text/javascript"></script>
        <script type="text/javascript" src="http://ayue05.blog.163.com/blog/Scripts/jquery.uploadify.v2.1.4-OL.js" charset="GB2312"></script>
        <link type="text/css" rel="Stylesheet" href="http://ayue05.blog.163.com/blog/ScreenCapture/ScreenCapture.css"/>
        <link type="text/css" rel="stylesheet" href="http://ayue05.blog.163.com/blog/css/ui-lightness/jquery-ui-1.8.11.custom.css" />
        <script type="text/javascript" src="http://ayue05.blog.163.com/blog/js/jquery.min.js"></script>
        <script type="text/javascript" src="http://ayue05.blog.163.com/blog/js/jquery-ui-1.8.11.custom.min.js"></script>
        <script type="text/javascript" src="http://ayue05.blog.163.com/blog/ScreenCapture/ScreenCapture.js" charset="utf-8"></script>
        <script type="text/javascript" src="http://ayue05.blog.163.com/blog/fckeditor/fckeditor.js" charset="utf-8"></script>
        <script type="text/javascript" src="http://qzonestyle.gtimg.cn/qzone/openapi/qc_loader.js" charset="utf-8"></script>
        <script type="text/javascript">
            function removeHTMLTag(str) {
                str = str.replace(/</?[^>]*>/g, ''); //去除HTML tag
                str = str.replace(/[ | ]*
    /g, '
    '); //去除行尾空白
                //str = str.replace(/
    [s| | ]*
    /g,'
    '); //去除多余空行
                str = str.replace(/ /ig, ''); //去掉 
                str = str.replace(/s/g, ''); //去掉空格
                return str;
            }
        </script>
        <script type="text/javascript">
            //读取文件的值,赋值给DIV 开始
            var sh;
            sh = setInterval(function () {
                //$("#ChatBase").load(location.href + " #ChatBase>*", "");//一直刷新某一容器,如DIV,等
                
                var seleMid = " ";
                $.ajax({
                    type: "POST",
                    contentType: "application/json",
                    url: "Resources/0.asmx/GetShopAllwaysCategory",
                    dataType: "json",
                    data: "{mid:'" + seleMid + "'}",
                    success: function callBack(result) {
                        //判断读取的值是否和页面显示的值一样。不一样则修改。一样则页面值为静态不刷新
                        var index = removeHTMLTag($("#refresh").text()); //获取DIV页面上的值
                        var indexHTML = removeHTMLTag(result.d.toString()); //获取读取的值,并过虑HTML标签
                        //alert("---" + result.d.toString());
                        //alert(index);
                        if (index != indexHTML) {
                            $("#refresh").html(result.d);
                            msg_end.scrollIntoView();
                        }
                    }
                });
                //一直调用页面鼠标移动方法,确保图片及时显示
                //editor_keydown();
                //var obj = document.getElementById("body1");
                //obj.attachEvent("onmousemove", editor_keydown);
            }, 100);
            //读取文件的值,赋值给DIV 结束
    
            //提交
            function sub() {
                var cont = ""; // $("#refresh").text();
                //var str1 = $("#txt2").val();
                var str2 = $("#hdid").val();
    
                var oEditor = FCKeditorAPI.GetInstance("txt2");
                var str1 = oEditor.GetXHTML(true);
    
                $.ajax({
                    type: "POST",
                    contentType: "application/json",
                    url: "Resources/subChat.asmx/subchat",
                    data: "{cont:'" + cont + "',name1:'" + str1 + "',name2:'" + str2 + "'}",
                    dataType: 'json',
                    success: function (result) {
                        if (result.d == "success") {
                            //alert("发送成功!");
                            //var txt1 = document.getElementById("txt2");
                            //                        txt1.value = "";
                            //                        txt1.focus();
                            var oEditor = FCKeditorAPI.GetInstance("txt2");
                            oEditor.SetHTML("");
                            oEditor.Focus();
                        } else {
                            alert("发送失败!");
                        }
                    }
                });
            }
    
            //离开页面后的事件        
            function closethis() {
                //改变文件状态为0.参数txtRefreshTo0是要存入数据库的值,从文件里直接读取,如果传参,字符太长
                var txtRefreshTo0 = "";// $("#refresh").text();
                $.ajax({
                    type: "POST",
                    contentType: "application/json",
                    url: "Resources/set0.asmx/setTo0",
                    dataType: "json",
                    data: "{mid:'" + txtRefreshTo0 + "'}",
                    success: function callBack(result) {
                        if (result.d == "success") {
                            window.close();
                        }
                    }
                });
            } 
    
            //传图片
            function sltPdt() {
                var str2 = $("#hdid").val();
                showModalDialog("0upImg.aspx?id=" + str2, window, "dialogHeight:100px;dialogWidth:305px;center:yes;help:no;status:no;scroll:no;");
            }
            //传文件
            function sltPdtFile() {
                var str2 = $("#hdid").val();
                showModalDialog("0upFile.aspx?id=" + str2, window, "dialogHeight:100px;dialogWidth:305px;center:yes;help:no;status:no;scroll:no;");
            }
    
            
        </script>
    </head>
    <%--页面关闭时候,在新页面把数据存入数据库  οnbefοreunlοad="return CloseEvent();" οnunlοad="UnLoadEvent()" οnunlοad="close(event)"  --%>
    <body id="body1"  style=" 100%; height:100%;" οnunlοad="closethis()" οnmοusemοve="editor_keydown()" >
    
    <div>
    <div style=" float:left;">
        <div style=" 100%;">
            <div id="ChatBase" style="left: 10px; top: 10px;  400px; height: 400px; overflow-y: scroll;
                overflow-x: hidden; border: solid 2px #006699; background-color: #fff;">
                <div id="refresh" style="margin: 0px; padding: 5px;  380px; overflow: hidden;">
                    <%=cont %>
                </div>
                <%--<%=cont %>--%>
                <%--定位到最底部--%>
                <div id="msg_end" style="height: 0px; overflow: hidden">
                </div>
            </div>
        </div>
        
        <%--工具栏开始--%>
        <div id="divTool" style=" 400px; border: outset 2px #006699; border-top: 0;
            height: 22px; line-height: 22px;">
            <div οnclick="sltPdt();" style="cursor: pointer; font-size: 12px; float:left;">
                  <img alt="选择图片" src="http://ayue05.blog.163.com/blog/img/v-12-img/z_22.gif" style="margin-right: 3px;" />图片</div>
                <div οnclick="sltPdtFile();" style="cursor: pointer; font-size: 12px; float:left;">
                  <img alt="选择文件" src="http://ayue05.blog.163.com/blog/img/v-12-img/z_23.gif" style="margin-right: 3px;" />文件</div>
                <div style="cursor: pointer; font-size: 12px; float:left;">
                  <%--<asp:Button ID="Button1" runat="server" Text=" 截图 " οnclick="Button1_Click" />--%>
                
                </div>
        </div>
        <%--工具栏结束--%>
        <div  style="margin-top: 10px;">
            <textarea cols="1" rows="1" id="txt2" name="txt2" style=" 400px; height: 60px;"  ></textarea>
            
            <script type="text/javascript" language="javascript">
                var scpMgr = new CaptureManager();
                //http://www.ncmem.com/products/screencapture/demo/upload.aspx,如果不是这个域名。可能出现域名未授权现象
                //scpMgr.Config["PostUrl"] = "http://192.168.0.100/market/asp.net/upload.aspx";
                scpMgr.Config["PostUrl"] = "http://www.ncmem.com/products/screencapture/demo/upload.aspx"; 
    
                var oFCKeditor = new FCKeditor('txt2');
    
                oFCKeditor.BasePath = "fckeditor/";
                oFCKeditor.ToolbarSet = 'Basic';
                oFCKeditor.Width = "400";
                oFCKeditor.Height = "200";
                oFCKeditor.ReplaceTextarea();
    
                function FCKeditor_OnComplete(editorInstance) {
    
                    scpMgr.Init(editorInstance); //初始化
                    //var oEditor = FCKeditorAPI.GetInstance("txt2");onkeydown
                    editorInstance.EditorDocument.attachEvent("onmousemove", editor_keydown);
                }
                function editor_keydown() {
    
                    
                    var oEditor = FCKeditorAPI.GetInstance("txt2");
                    var str1 = oEditor.GetXHTML(true);
                    if (str1.indexOf('src="/upload') > 0) {
                        str1 = str1.replace('src="/upload', 'src="http://www.ncmem.com/upload');
    //alert(str1);
                    oEditor.EditorDocument.body.innerHTML = str1; 
                    }
                    
                    
                    
                    
    
                }
                
    
        </script>
            
        </div>
        <div style=" 400px; height: 30px;"  >
        <div id="subdiv" style="cursor: pointer;  50px; height: 25px; text-align: center; line-height: 25px;
                border: outset 2px gray; margin-left: 135px; margin-top:5px; float:left; "  οnclick="sub()" >
                提 交
            </div>
            <div id="Div1" style="cursor: pointer;  50px; height: 25px; text-align: center; line-height: 25px;
                border: outset 2px gray; margin-left: 15px; margin-top:5px; float:left; "  οnclick="closethis()">
                关 闭
            </div>
            </div>
    
            <div style=" 400px; margin-top:10px; font-size:12px; color:#555; text-align:center;  "  >
            小提示:ctrl+回车可快速提交哦
            </div>
            <form id="form1" runat="server">
        <input id="hdid" type="hidden" runat="server" value=""  />
        </form>
        </div>
        <div style=" float:left; display:none;">
        客户IP为:<%=ip %>
        </div>
        </div>
        
    </body>
    </html>
    




    CS.文件

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.IO;
    using System.Net;
    using System.Net.Sockets;
    using System.Text;
    
    namespace Stores
    {
        public partial class _0test : System.Web.UI.Page
        {
            protected string cont = "";
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
    
                    string temp = HttpContext.Current.Server.MapPath("~/1.htm");
                    StreamReader sr = null;
                    Encoding code = Encoding.GetEncoding("gb2312");
                    sr = new StreamReader(temp, code);
                    cont = sr.ReadToEnd().ToString().Trim(); // 读取文件
                    
                    sr.Close();
                }
            }
            protected void Button1_Click(object sender, EventArgs e)
            {
                string temp = HttpContext.Current.Server.MapPath("~/1.htm");
                StreamReader sr = null;
                Encoding code = Encoding.GetEncoding("gb2312");
                sr = new StreamReader(temp, code);
                string str1 = sr.ReadToEnd(); // 读取文件
                sr.Close();
                //string str1 = txt1.Text.ToString().Trim();
                string str2 = txt2.Text.ToString().Trim();
                txt2.Text = "";
                if (WriteFile(str1,str2))
                    {
                        string err = "更新成功";
                    }
                    else
                    {
                        string err = "生成HTML出错!";
                    }
                
                
            }
            public bool WriteFile(string str1, string str2)
            {
    
                //string path = HttpContext.Current.Server.MapPath("~/");
                Encoding code = Encoding.GetEncoding("gb2312");
                // 读取模板文件
                string temp = HttpContext.Current.Server.MapPath("~/1.htm");
                //StreamReader sr = null;
                StreamWriter sw = null;
                string str = "";
                //try
                //{
                //    sr = new StreamReader(temp, code);
                //    str = sr.ReadToEnd(); // 读取文件
                //}
                //catch (Exception exp)
                //{
                //    HttpContext.Current.Response.Write(exp.Message);
                //    HttpContext.Current.Response.End();
                //    sr.Close();
                //}
    
                // 替换内容
                // 这时,模板文件已经读入到名称为str的变量中了
                //str = str.Replace("ShowArticle", strText); //模板页中的ShowArticle
                //string htmlfilename = DateTime.Now.ToString("yyyyMMddHHmmss") + ".htm";//以当前日期为标题另存为一个静态页面,防止页面重复
                //str = str.Replace("str1", str1 + "
    
    " + str2);
                str = str1 + "</br>" + str2 + "</br>";
                //str = str.Replace("str2", str2);
                // 写文件
                try
                {
                    sw = new StreamWriter(temp, false, code);
                    sw.Write(str);
                    sw.Flush();
                }
                catch (Exception ex)
                {
                    HttpContext.Current.Response.Write(ex.Message);
                    HttpContext.Current.Response.End();
                }
                finally
                {
                    sw.Close();
                }
                return true;
            }
    
    
        }
    }


  • 相关阅读:
    数组中只出现一次的数字
    平衡二叉树
    二叉树的深度
    数字在排序数组中出现的次数
    数组中的逆序对
    第一个只出现一次的字符位置
    丑数
    把数组排成最小的数/1038. Recover the Smallest Number
    python系统编程(十一)
    python系统编程(十)
  • 原文地址:https://www.cnblogs.com/wybshyy/p/13783809.html
Copyright © 2011-2022 走看看