asp.net 右下角弹出新提醒信息提示框

来源:互联网 发布:超市收银软件多少钱 编辑:程序博客网 时间:2024/05/17 06:16

asp.net 开发信息系统,无论是OA或者是其它业务系统中,都会用到新信息提醒功能,特此将方案跟大家分享一下。先上一图给大家看一看:


优点:1)、该新消息弹出提示框样式算是比较不错的,个人认为。

           2)、弹出框内的信息内容、提醒的个数、点击链接页面都封装在PopMessage.js中,你无须修改。

           3)、使用简单,你只要根据你的需要修改PopMessageHandler.ashx,获取你需要提醒的数据即可。

           4)、页面引用简单,易懂。


下面讲述实现过程:

1、在你的Web项目中根目录中添加Common文件夹,里面包括图片、js脚本和一般处理函数,请点击下载:http://download.csdn.net/detail/taomanman/8338479

这个目录结构如下:


2、根据你的需要修改PopMessageHandler.ashx文件,现将代码罗列出来,你需要根据你的实际业务逻辑进行修改:

<%@ WebHandler Language="C#" Class="PopMessageHandler" %>using System;using System.Data;using System.Text;using System.Web;using System.Web.SessionState;using System.Web.Script.Serialization;public class PopMessageHandler : IHttpHandler, IRequiresSessionState{    /// <summary>    /// 待办任务总数    /// </summary>    int totalTaskCount = 0;    public void ProcessRequest(HttpContext context)    {        try        {            context.Response.ContentType = "text/plain";            //获取任务数据            string strSQL = "select * from v_getTipsCount";             DataSet ds = SqlHelper.ExecuteDataSet(SqlHelper.LocalSqlServer, strSQL);            if (ds != null)            {                if (ds.Tables[0].Rows.Count > 0)                {                    DataTable dt = ds.Tables[0];                    int count1 = int.Parse(dt.Rows[0]["count1"].ToString());                    int count2 = int.Parse(dt.Rows[0]["count2"].ToString());                    int count3 = int.Parse(dt.Rows[0]["count3"].ToString());                    int count4 = int.Parse(dt.Rows[0]["count4"].ToString());                    int count5 = int.Parse(dt.Rows[0]["count5"].ToString());                    totalTaskCount = count1 + count2 + count3 + count4 + count5;                    if (totalTaskCount > 0)                    {                        var testData = new object[] {                            new {                                description = "新增人员数提醒-新增审核通过数提醒-减员人数提醒-服务费新增数提醒-过期未交费数提醒",                                count= count1.ToString()+"-"+ count2.ToString() +"-"+count3.ToString()+"-"+ count4.ToString() +"-"+count5.ToString(),                                href="PersonnelManagement/PersonnelList.aspx" +"-"+"PersonnelManagement/PersonnelList.aspx"+"-"+"PersonnelManagement/ReducePersonnelList.aspx"+"-"+"PersonnelManagement/PersonnelFeeList.aspx"+"-"+"FinancialManagement/FinanceRecord.aspx"                            },                       };                        JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();                        //执行序列化                        context.Response.Write(jsonSerializer.Serialize(testData));                    }                }            }        }        catch (Exception e)        {                    }    }    public bool IsReusable    {        get        {            return false;        }    }}


3、在你系统的主页面中添加js引用、html元素和js函数,如下,当然jquery.js也要添加,下面代码中就不写了,注意要添加哦:

<title>asp.net右下角弹出信息提醒框示例</title>    <script src="js/jquery-1.4.2.min.js" type="text/javascript"></script>    <script src="Common/PopMessage/PopMessage.js" type="text/javascript"></script>    <script type="text/javascript">        function resizediv() {            var mainH =  $(window).height();            document.getElementById("mainIframe").style.height = mainH - 30 + "px";        }        window.onload = resizediv;        window.onresize = resizediv;        //弹出消息提醒框          var pop;        function popMessage() {            pop = new PopMessage();            //当有提醒时,每隔5秒出现一次,当没有需要提醒的消息时,提醒框不会出现              pop.show(5000, "mainIframe");        }        $(function () {            resizediv();            //页面初始加载时执行弹出框              popMessage();        });   </script>


网页中使用iframe来作为页面的容器,如下:

      

<iframe id="mainIframe" name="mainIframe" height="100%" width="100%" src="main.aspx" frameborder="0"></iframe> 



4、完成以后的效果如下图:

点击蓝色部分,可以直接跳转到对应要处理的页面。


源码下载地址:

http://download.csdn.net/detail/taomanman/8342083


===========================================================================

如果觉得对您有帮助,微信扫一扫支持一下:






2 0
原创粉丝点击