订单提醒功能

 

  //五秒刷新数据库,有新订单提醒
        if (!GetMessageCount) {

            var GetMessageCount = {};
        }

        $(document).ready(
        function () {
            //GetMessageCount.FindMessage();
            go();//计时器
        }
        );

        GetMessageCount.FindMessage = function () {
            $.ajax({
                //处理ajax请求
                type: "get",
                dataType: "json",
                url: "ajaxMesg.ashx",
                cache: false,
                success: function (response) {
                    //alert(response.MerchantName);
                    if (response.Num != 0) {
                        //alert(response.Num);
                        var context = "你有" + response.Num + "条新订单";
                        stop();
                        ymPrompt.alert({ message: context, title: '订单提醒', handler: myFun, btn: ['OK'], okTxt: ' 详   情 ', autoClose: true, winPos: 'rb', useSlide: true, slideCfg: { increment: 0.1, interval: 100} });   //这里是使用的一个 第三方 控件 可以在我网上找到!
                    }
                },
                error: function (data) {
                    alert("加载失败");
                }
            });
            //每隔5 秒递归调用一次,刷新未读短信数目
//            show();


        }  
        //开始计时

        var timerID;
        var time = 0;
        function show() {
            time++;
            //alert('time:' + time + '  timerID:' + timerID);
            timerID = setTimeout("show(" + time + ")", 5000);

            if (time > 10)  //n * (5000/1000)
            {
                //alert('>200):' + time);
                time = 0;
                GetMessageCount.FindMessage(); //核心语句
            }
        }
        //暂停
        function stop() {
            window.clearTimeout(timerID);
        }
        //继续
        function go() {
            window.clearTimeout(timerID);
            show();
        }

        function myFun(tp) {
            if (tp == 'ok') {
                addTab('发货订单查看', 'StoreMange/SentGoodsCheck.aspx', 'icon icon-nav', true)
            }
            go();
        }

 

//引用一般处理程序,使用IRequiresSessionState  这个接口

//必须有using System.Web.SessionState; 这个命名空间!

 public class ajaxMesg : IHttpHandler, IRequiresSessionState
    {
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string sql = "";
            string num = "";
            int number = 0;
            using (SqlConnection con = new SqlConnection(SqlHelper.ConnectionString))
            {
                con.Open();
                PageBase pb = new PageBase(); //记录当前登录用户的类
                
                string userId = pb.UserId; //获取当前登录用户Id
                string sqll = string.Format("select count(Name) from dbo.PUB_User"
                                + " where UserID = '{0}' and IsView = '0'", userId);

                SqlCommand cmd = new SqlCommand();
                cmd.Connection = con;

                cmd.CommandText = sqll;
                number = Convert.ToInt32(cmd.ExecuteScalar().ToString());
                //以上是判断那些人可以提醒!
            }
            if (number > 0)
            {
                using (SqlConnection con = new SqlConnection(SqlHelper.ConnectionString))
                {
                    con.Open();
                    sql = "select count(*) as Num from Match_SendGood where RemindOrNot='0'";

                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection = con;
                    cmd.CommandText = sql;

                    num = "{\"Num\":\"" + cmd.ExecuteScalar().ToString() + "\"}";
                }
                context.Response.Write(num);
                //提醒的内容
            }
            else
            {
                num = "{\"Num\":\"" + "0" + "\"}";
                context.Response.Write(num);
            }
        }

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章